Subversion Repositories wimsdev

Rev

Rev 3718 | Rev 8086 | 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 "errors.c"
  41. #include "lines.c"
  42. #include "basic.c"
  43. #include "extract.c"
  44. #include "type.c"
  45. #include "not.c"
  46.  
  47. struct {
  48.     char *name;
  49.     void (*routine)(void);
  50. } req[]={
  51.     {"cut",             req_cut},
  52.     {"extract",         req_extract},
  53.     {"not",             req_not},
  54.     {"reverse",         req_not},
  55.     {"type",            req_type},
  56. };
  57. int request;
  58. #define reqcnt (sizeof(req)/sizeof(req[0]))
  59.  
  60. void parm()
  61. {
  62.     char *p, *pp;
  63.     for(pp=parmbuf;*pp;pp++) if(*pp=='  ') *pp='\n';
  64.     for(objlinecnt=0,p=parmbuf; *p && objlinecnt<MAX_OBJLINES; p=pp) {
  65.         pp=strchr(p,'\n'); if(pp) *pp++=0; else pp=p+strlen(p);
  66.         strip_trailing_spaces(p);
  67.         objline[objlinecnt]=p; objlinecnt++;
  68.     }
  69.     if(objlinecnt<1) error("Empty input data.");
  70.     logdir=0;
  71.     if((p=wordchr(objline[0],"<"))!=NULL) {
  72.         logdir=-1; ovlstrcpy(p,p+1);
  73.     }
  74.     if((p=wordchr(objline[0],">"))!=NULL) {
  75.         logdir=1; ovlstrcpy(p,p+1);
  76.     }
  77.     p=find_word_start(objline[0]); pp=find_word_end(p); if(*pp) *pp++=0;
  78.     objline[0]=pp;
  79.     for(request=0;request<reqcnt && strcasecmp(req[request].name,p)!=0; request++);
  80.     if(request>=reqcnt) error("Bad request.");
  81.     p=find_word_start(pp); pp=find_word_end(p); if(*pp) *pp++=0;
  82.     objline[0]=pp; reqtype=p;
  83. }
  84.  
  85. int main()
  86. {
  87.     char *p;
  88.     int i;
  89.    
  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.