Subversion Repositories wimsdev

Rev

Rev 2019 | Rev 7676 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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.  
  18.         /* Interface Plouffe's Inverter to wims */
  19.  
  20. /*************** Customization: change values hereafter ****************/
  21.  
  22.         /* limit of parameter string */
  23. #define parmlim 131072
  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\">"
  26.  
  27.         /* minimal and maximal lengths of a number to interface */
  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]))
  33.  
  34. char *post_msg[lang_no]={
  35.     " <small>(click on a value to check its meaning in another window)</small> ",
  36.     " <small>(cliquez sur une valeur pour voir sa signification dans une autre fen&ecirc;tre)</small> ",
  37.     " <small>(ÔÚÊý×ÖÉϵ¥»÷¿É¹©ÄãÔÚÁíÒ»ÊÓ´°ÄÚ²éÔÄÆäÒâÒå)</small> "
  38. };
  39.  
  40. /***************** Nothing should need change hereafter *****************/
  41.  
  42. #include "../wims.h"
  43.  
  44. char *parm;
  45.  
  46. int getlang(void)
  47. {
  48.     char *p;
  49.     int i;
  50.     p=getenv("w_module_language");
  51.     if(p==NULL || *p==0) p=getenv("w_lang");
  52.     if(p==NULL || *p==0) return 0;      /* English is default */
  53.     for(i=0;i<lang_no && strcmp(p,langs[i])!=0;i++);
  54.     if(i<lang_no) return i; else return 0;
  55. }
  56.  
  57. int main(int argc,char *argv[])
  58. {
  59.     char *p,*pp,*p2,*p3,*ps,*last;
  60.     char buf[parmlim];
  61.     int i,got;
  62.    
  63.     parm=getenv("wims_exec_parm");
  64.         /* nothing to do if no parameter */
  65.     if(parm==NULL || *parm==0) return 0;
  66.     i=strlen(parm); if(i<0 || i>parmlim) {
  67.         fprintf(stderr,"Plouffe: parameter too long. \n"); exit(1);
  68.     }
  69.     got=0;
  70.     for(p=last=parm;*p!=0;p++) {
  71.         if(*p=='<') {
  72.             for(;*p!=0 && *p!='>'; p++);
  73.             if(*p==0) p--;
  74.             continue;
  75.         }
  76.         if(!isdigit(*p)) continue;
  77.         for(i=0,pp=p;isdigit(*pp) || *pp=='.';pp++) if(*pp=='.') i++;
  78.         if(i>1) {  /* several decimal points. */
  79.             p=pp-1;continue;
  80.         }
  81.         for(p2=pp-1;p2>=p && (*p2=='.' || *p2=='0');p2--);
  82.         p2++;
  83.         for(i=0,p3=p;p3<p2 && *p3!='.';p3++);
  84.         for(i=0,ps=p;ps<p2 && (*ps=='0' || *ps=='.'); ps++);
  85.         if(p3>=p2 || p2<ps+Plouffe_min) {
  86.             p=pp-1;continue;
  87.         }
  88.         memmove(buf,last,p-last);buf[p-last]=0;
  89.         printf("%s",buf);last=p;
  90.         i=p2-p;if(i>Plouffe_max) i=Plouffe_max;
  91.         memmove(buf,p,i);buf[i]=0;
  92.         printf(WebPlouffe,buf);
  93.         memmove(buf,p,pp-p);buf[pp-p]=0;
  94.         printf("%s</a>",buf);last=pp;
  95.         got=1;p=pp-1;
  96.         continue;
  97.     }
  98.     if(*last!=0) printf("%s",last);
  99.     if(got) printf("%s",post_msg[getlang()]);
  100.     return 0;    
  101. }
  102.  
  103.