Rev 12248 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
10 | reyssat | 1 | /* Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis |
2 | * |
||
3 | * This program is free software; you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation; either version 2 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
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 |
||
15 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
||
16 | */ |
||
17 | |||
7676 | bpr | 18 | /* Interface Plouffe's Inverter to wims */ |
10 | reyssat | 19 | |
20 | /*************** Customization: change values hereafter ****************/ |
||
21 | |||
7676 | bpr | 22 | /* limit of parameter string */ |
10 | reyssat | 23 | #define parmlim 131072 |
7676 | bpr | 24 | /* Address of Plouffe's Inverter */ |
2019 | bpr | 25 | #define WebPlouffe "<a target=wims_external href=\"http://oldweb.cecm.sfu.ca/cgi-bin/isc/lookup?lookup_type=simple&number=%s\">" |
10 | reyssat | 26 | |
7676 | bpr | 27 | /* minimal and maximal lengths of a number to interface */ |
10 | reyssat | 28 | #define Plouffe_min 6 |
29 | #define Plouffe_max 22 |
||
30 | |||
31 | char *langs[]={"en","fr","cn"}; |
||
32 | #define lang_no (sizeof(langs)/sizeof(langs[0])) |
||
12258 | bpr | 33 | #pragma GCC diagnostic push |
34 | #pragma GCC diagnostic ignored "-Winvalid-source-encoding" |
||
10 | reyssat | 35 | char *post_msg[lang_no]={ |
12248 | bpr | 36 | " <small>(click on a value to check its meaning in another window)</small> ", |
37 | " <small>(cliquez sur une valeur pour voir sa signification dans une autre fenêtre)</small> ", |
||
38 | " <small>(在数字上单击可供你在另一视窗内查阅其意义)</small> " |
||
10 | reyssat | 39 | }; |
12258 | bpr | 40 | #pragma GCC diagnostic pop |
10 | reyssat | 41 | /***************** Nothing should need change hereafter *****************/ |
42 | |||
8185 | bpr | 43 | #include "../includes.h" |
10 | reyssat | 44 | |
45 | char *parm; |
||
46 | |||
47 | int getlang(void) |
||
48 | { |
||
12248 | bpr | 49 | char *p; |
50 | int i; |
||
51 | p=getenv("w_module_language"); |
||
52 | if(p==NULL || *p==0) p=getenv("w_lang"); |
||
53 | if(p==NULL || *p==0) return 0; /* English is default */ |
||
54 | for(i=0;i<lang_no && strcmp(p,langs[i])!=0;i++); |
||
55 | if(i<lang_no) return i; else return 0; |
||
10 | reyssat | 56 | } |
57 | |||
58 | int main(int argc,char *argv[]) |
||
59 | { |
||
12248 | bpr | 60 | char *p,*pp,*p2,*p3,*ps,*last; |
61 | char buf[parmlim]; |
||
62 | int i,got; |
||
7676 | bpr | 63 | |
12248 | bpr | 64 | parm=getenv("wims_exec_parm"); |
7676 | bpr | 65 | /* nothing to do if no parameter */ |
12248 | bpr | 66 | if(parm==NULL || *parm==0) return 0; |
67 | i=strlen(parm); if(i<0 || i>parmlim) { |
||
68 | fprintf(stderr,"Plouffe: parameter too long. \n"); exit(1); |
||
69 | } |
||
70 | got=0; |
||
71 | for(p=last=parm;*p!=0;p++) { |
||
72 | if(*p=='<') { |
||
73 | for(;*p!=0 && *p!='>'; p++); |
||
74 | if(*p==0) p--; |
||
7676 | bpr | 75 | continue; |
10 | reyssat | 76 | } |
12248 | bpr | 77 | if(!isdigit(*p)) continue; |
78 | for(i=0,pp=p;isdigit(*pp) || *pp=='.';pp++) if(*pp=='.') i++; |
||
79 | if(i>1) { /* several decimal points. */ |
||
80 | p=pp-1;continue; |
||
81 | } |
||
82 | for(p2=pp-1;p2>=p && (*p2=='.' || *p2=='0');p2--); |
||
83 | p2++; |
||
84 | for(i=0,p3=p;p3<p2 && *p3!='.';p3++); |
||
85 | for(i=0,ps=p;ps<p2 && (*ps=='0' || *ps=='.'); ps++); |
||
86 | if(p3>=p2 || p2<ps+Plouffe_min) { |
||
87 | p=pp-1;continue; |
||
88 | } |
||
89 | memmove(buf,last,p-last);buf[p-last]=0; |
||
90 | printf("%s",buf);last=p; |
||
91 | i=p2-p;if(i>Plouffe_max) i=Plouffe_max; |
||
92 | memmove(buf,p,i);buf[i]=0; |
||
93 | printf(WebPlouffe,buf); |
||
94 | memmove(buf,p,pp-p);buf[pp-p]=0; |
||
95 | printf("%s</a>",buf);last=pp; |
||
96 | got=1;p=pp-1; |
||
97 | continue; |
||
98 | } |
||
99 | if(*last!=0) printf("%s",last); |
||
100 | if(got) printf("%s",post_msg[getlang()]); |
||
101 | return 0; |
||
10 | reyssat | 102 | } |
103 |