Rev 7076 | Rev 8185 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7076 | Rev 7676 | ||
---|---|---|---|
Line 13... | Line 13... | ||
13 | * You should have received a copy of the GNU General Public License |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program; if not, write to the Free Software |
14 | * along with this program; if not, write to the Free Software |
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | */ |
16 | */ |
17 | 17 | ||
18 |
|
18 | /* Interface Plouffe's Inverter to wims */ |
19 | 19 | ||
20 | /*************** Customization: change values hereafter ****************/ |
20 | /*************** Customization: change values hereafter ****************/ |
21 | 21 | ||
22 |
|
22 | /* limit of parameter string */ |
23 | #define parmlim 131072 |
23 | #define parmlim 131072 |
24 |
|
24 | /* Address of Plouffe's Inverter */ |
25 | #define WebPlouffe "<a target=wims_external href=\"http://oldweb.cecm.sfu.ca/cgi-bin/isc/lookup?lookup_type=simple&number=%s\">" |
25 | #define WebPlouffe "<a target=wims_external href=\"http://oldweb.cecm.sfu.ca/cgi-bin/isc/lookup?lookup_type=simple&number=%s\">" |
26 | 26 | ||
27 |
|
27 | /* minimal and maximal lengths of a number to interface */ |
28 | #define Plouffe_min 6 |
28 | #define Plouffe_min 6 |
29 | #define Plouffe_max 22 |
29 | #define Plouffe_max 22 |
30 | 30 | ||
31 | char *langs[]={"en","fr","cn"}; |
31 | char *langs[]={"en","fr","cn"}; |
32 | #define lang_no (sizeof(langs)/sizeof(langs[0])) |
32 | #define lang_no (sizeof(langs)/sizeof(langs[0])) |
Line 47... | Line 47... | ||
47 | { |
47 | { |
48 | char *p; |
48 | char *p; |
49 | int i; |
49 | int i; |
50 | p=getenv("w_module_language"); |
50 | p=getenv("w_module_language"); |
51 | if(p==NULL || *p==0) p=getenv("w_lang"); |
51 | if(p==NULL || *p==0) p=getenv("w_lang"); |
52 | if(p==NULL || *p==0) return 0; |
52 | if(p==NULL || *p==0) return 0; /* English is default */ |
53 | for(i=0;i<lang_no && strcmp(p,langs[i])!=0;i++); |
53 | for(i=0;i<lang_no && strcmp(p,langs[i])!=0;i++); |
54 | if(i<lang_no) return i; else return 0; |
54 | if(i<lang_no) return i; else return 0; |
55 | } |
55 | } |
56 | 56 | ||
57 | int main(int argc,char *argv[]) |
57 | int main(int argc,char *argv[]) |
58 | { |
58 | { |
59 | char *p,*pp,*p2,*p3,*ps,*last; |
59 | char *p,*pp,*p2,*p3,*ps,*last; |
60 | char buf[parmlim]; |
60 | char buf[parmlim]; |
61 | int i,got; |
61 | int i,got; |
62 | 62 | ||
63 | parm=getenv("wims_exec_parm"); |
63 | parm=getenv("wims_exec_parm"); |
64 |
|
64 | /* nothing to do if no parameter */ |
65 | if(parm==NULL || *parm==0) return 0; |
65 | if(parm==NULL || *parm==0) return 0; |
66 | i=strlen(parm); if(i<0 || i>parmlim) { |
66 | i=strlen(parm); if(i<0 || i>parmlim) { |
67 |
|
67 | fprintf(stderr,"Plouffe: parameter too long. \n"); exit(1); |
68 | } |
68 | } |
69 | got=0; |
69 | got=0; |
70 | for(p=last=parm;*p!=0;p++) { |
70 | for(p=last=parm;*p!=0;p++) { |
71 |
|
71 | if(*p=='<') { |
72 |
|
72 | for(;*p!=0 && *p!='>'; p++); |
73 |
|
73 | if(*p==0) p--; |
74 |
|
74 | continue; |
75 |
|
75 | } |
76 |
|
76 | if(!isdigit(*p)) continue; |
77 |
|
77 | for(i=0,pp=p;isdigit(*pp) || *pp=='.';pp++) if(*pp=='.') i++; |
78 |
|
78 | if(i>1) { /* several decimal points. */ |
79 |
|
79 | p=pp-1;continue; |
80 |
|
80 | } |
81 |
|
81 | for(p2=pp-1;p2>=p && (*p2=='.' || *p2=='0');p2--); |
82 |
|
82 | p2++; |
83 |
|
83 | for(i=0,p3=p;p3<p2 && *p3!='.';p3++); |
84 |
|
84 | for(i=0,ps=p;ps<p2 && (*ps=='0' || *ps=='.'); ps++); |
85 |
|
85 | if(p3>=p2 || p2<ps+Plouffe_min) { |
86 |
|
86 | p=pp-1;continue; |
87 |
|
87 | } |
88 |
|
88 | memmove(buf,last,p-last);buf[p-last]=0; |
89 |
|
89 | printf("%s",buf);last=p; |
90 |
|
90 | i=p2-p;if(i>Plouffe_max) i=Plouffe_max; |
91 |
|
91 | memmove(buf,p,i);buf[i]=0; |
92 |
|
92 | printf(WebPlouffe,buf); |
93 |
|
93 | memmove(buf,p,pp-p);buf[pp-p]=0; |
94 |
|
94 | printf("%s</a>",buf);last=pp; |
95 |
|
95 | got=1;p=pp-1; |
96 |
|
96 | continue; |
97 | } |
97 | } |
98 | if(*last!=0) printf("%s",last); |
98 | if(*last!=0) printf("%s",last); |
99 | if(got) printf("%s",post_msg[getlang()]); |
99 | if(got) printf("%s",post_msg[getlang()]); |
100 | return 0; |
100 | return 0; |
101 | } |
101 | } |
102 | 102 |