Back to index

wims  3.65+svn20090927
Plouffe.c
Go to the documentation of this file.
00001 /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
00002  *
00003  *  This program is free software; you can redistribute it and/or modify
00004  *  it under the terms of the GNU General Public License as published by
00005  *  the Free Software Foundation; either version 2 of the License, or
00006  *  (at your option) any later version.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018        /* Interface Plouffe's Inverter to wims */
00019 
00020 /*************** Customization: change values hereafter ****************/
00021 
00022        /* limit of parameter string */
00023 #define parmlim 131072
00024        /* Address of Plouffe's Inverter */
00025 #define WebPlouffe "<a target=wims_external href=\"http://www.cecm.sfu.ca/cgi-bin/isc/lookup?lookup_type=simple&number=%s\">"
00026 
00027        /* minimal and maximal lengths of a number to interface */
00028 #define Plouffe_min 6
00029 #define Plouffe_max 22
00030 
00031 char *langs[]={"en","fr","cn"};
00032 #define lang_no (sizeof(langs)/sizeof(langs[0]))
00033 
00034 char *post_msg[lang_no]={
00035     " <small>(click on a value to check its meaning in another window)</small> ",
00036     " <small>(cliquez sur une valeur pour voir sa signification dans une autre fen阾re)</small> ",
00037     " <small>(在数字上单击可供你在另一视窗内查阅其意义)</small> "
00038 };
00039 
00040 /***************** Nothing should need change hereafter *****************/
00041 
00042 #include "../wims.h"
00043 
00044 char *parm;
00045 
00046 int getlang(void)
00047 {
00048     char *p;
00049     int i;
00050     p=getenv("w_module_language");
00051     if(p==NULL || *p==0) p=getenv("w_lang");
00052     if(p==NULL || *p==0) return 0; /* English is default */
00053     for(i=0;i<lang_no && strcmp(p,langs[i])!=0;i++);
00054     if(i<lang_no) return i; else return 0;
00055 }
00056 
00057 int main(int argc,char *argv[])
00058 {
00059     char *p,*pp,*p2,*p3,*ps,*last;
00060     char buf[parmlim];
00061     int i,got;
00062     
00063     parm=getenv("wims_exec_parm");
00064        /* nothing to do if no parameter */
00065     if(parm==NULL || *parm==0) return 0;
00066     i=strlen(parm); if(i<0 || i>parmlim) {
00067        fprintf(stderr,"Plouffe: parameter too long. \n"); exit(1);
00068     }
00069     got=0;
00070     for(p=last=parm;*p!=0;p++) {
00071        if(*p=='<') {
00072            for(;*p!=0 && *p!='>'; p++);
00073            if(*p==0) p--;
00074            continue;
00075        }
00076        if(!isdigit(*p)) continue;
00077        for(i=0,pp=p;isdigit(*pp) || *pp=='.';pp++) if(*pp=='.') i++;
00078        if(i>1) {  /* several decimal points. */
00079            p=pp-1;continue;
00080        }
00081        for(p2=pp-1;p2>=p && (*p2=='.' || *p2=='0');p2--);
00082        p2++;
00083        for(i=0,p3=p;p3<p2 && *p3!='.';p3++);
00084        for(i=0,ps=p;ps<p2 && (*ps=='0' || *ps=='.'); ps++);
00085        if(p3>=p2 || p2<ps+Plouffe_min) {
00086            p=pp-1;continue;
00087        }
00088        memmove(buf,last,p-last);buf[p-last]=0;
00089        printf("%s",buf);last=p;
00090        i=p2-p;if(i>Plouffe_max) i=Plouffe_max;
00091        memmove(buf,p,i);buf[i]=0;
00092        printf(WebPlouffe,buf);
00093        memmove(buf,p,pp-p);buf[pp-p]=0;
00094        printf("%s</a>",buf);last=pp;
00095        got=1;p=pp-1;
00096        continue;
00097     }
00098     if(*last!=0) printf("%s",last);
00099     if(got) printf("%s",post_msg[getlang()]);
00100     return 0;    
00101 }
00102