Subversion Repositories wimsdev

Rev

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

  1. /*    Copyright (C) 2002-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. /* Mathematical expression manipulations for WIMS */
  19.  
  20. #include "mathexp.h"
  21. #include "../../Lib/libwims.h"
  22.  
  23. char parmbuf[MAX_LINELEN+1];
  24. char *objline[MAX_OBJLINES];
  25. int objlinecnt, thisobjline, thislinelen;
  26. int expl1, expl2;
  27. char *reqtype;
  28. int logdir, linelogdir;
  29. char *fnd_position;
  30. char *fnd_nextpos;
  31.  
  32. struct {
  33.     char *srcreg;
  34.     regex_t cmpreg;
  35.     int isvar;
  36. } regexchk[MAX_REGEX];
  37. int regexcnt=0;
  38.  
  39. #include "tables.c"
  40. #include "basic.c"
  41. #include "extract.c"
  42. #include "type.c"
  43. #include "not.c"
  44.  
  45. struct {
  46.     char *name;
  47.     void (*routine)(void);
  48. } req[]={
  49.     {"cut",             req_cut},
  50.     {"extract",         req_extract},
  51.     {"not",             req_not},
  52.     {"reverse",         req_not},
  53.     {"type",            req_type},
  54. };
  55. int request;
  56. #define reqcnt (sizeof(req)/sizeof(req[0]))
  57.  
  58. void parm()
  59. {
  60.     char *p, *pp;
  61.     for(pp=parmbuf;*pp;pp++) if(*pp=='  ') *pp='\n';
  62.     for(objlinecnt=0,p=parmbuf; *p && objlinecnt<MAX_OBJLINES; p=pp) {
  63.         pp=strchr(p,'\n'); if(pp) *pp++=0; else pp=p+strlen(p);
  64.         strip_trailing_spaces(p);
  65.         objline[objlinecnt]=p; objlinecnt++;
  66.     }
  67.     if(objlinecnt<1) error("Empty input data.");
  68.     logdir=0;
  69.     if((p=wordchr(objline[0],"<"))!=NULL) {
  70.         logdir=-1; ovlstrcpy(p,p+1);
  71.     }
  72.     if((p=wordchr(objline[0],">"))!=NULL) {
  73.         logdir=1; ovlstrcpy(p,p+1);
  74.     }
  75.     p=find_word_start(objline[0]); pp=find_word_end(p); if(*pp) *pp++=0;
  76.     objline[0]=pp;
  77.     for(request=0;request<reqcnt && strcasecmp(req[request].name,p)!=0; request++);
  78.     if(request>=reqcnt) error("Bad request.");
  79.     p=find_word_start(pp); pp=find_word_end(p); if(*pp) *pp++=0;
  80.     objline[0]=pp; reqtype=p;
  81. }
  82.  
  83. /*void (*string_modify)(char *start, char *bad_beg, char *bad_end, char *good,...)=string_modify1;*/
  84.  
  85. int main()
  86. {
  87.     char *p;
  88.     int i;
  89.     string_modify=string_modify1;
  90.     error1=error; error2=error; error3=error;
  91.     p=getenv("wims_exec_parm");
  92.     if(p==NULL || *p==0) error("No input data.");
  93.     snprintf(parmbuf,sizeof(parmbuf),"%s",p);
  94.     parm();
  95.     req[request].routine();
  96.     for(i=0;i<regexcnt;i++) if(regexchk[i].isvar==0) regfree(&(regexchk[i].cmpreg));
  97.     return 0;
  98. }
  99.  
  100.