Back to index

wims  3.65+svn20090927
mathexp.c
Go to the documentation of this file.
00001 /*    Copyright (C) 2002-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        /* Mathematical expression manipulations for WIMS */
00019 
00020 #include "mathexp.h"
00021 #include "../../Lib/libwims.h"
00022 
00023 char parmbuf[MAX_LINELEN+1];
00024 char *objline[MAX_OBJLINES];
00025 int objlinecnt, thisobjline, thislinelen;
00026 int expl1, expl2;
00027 char *reqtype;
00028 int logdir, linelogdir;
00029 char *fnd_position;
00030 char *fnd_nextpos;
00031 
00032 struct {
00033     char *srcreg;
00034     regex_t cmpreg;
00035     int isvar;
00036 } regexchk[MAX_REGEX];
00037 int regexcnt=0;
00038 
00039 #include "tables.c"
00040 #include "errors.c"
00041 #include "lines.c"
00042 #include "basic.c"
00043 #include "extract.c"
00044 #include "type.c"
00045 #include "not.c"
00046 
00047 struct {
00048     char *name;
00049     void (*routine)(void);
00050 } req[]={
00051     {"cut",          req_cut},
00052     {"extract",             req_extract},
00053     {"not",          req_not},
00054     {"reverse",             req_not},
00055     {"type",         req_type},
00056 };
00057 int request;
00058 #define reqcnt (sizeof(req)/sizeof(req[0]))
00059 
00060 void parm()
00061 {
00062     char *p, *pp;
00063     for(pp=parmbuf;*pp;pp++) if(*pp=='    ') *pp='\n';
00064     for(objlinecnt=0,p=parmbuf; *p && objlinecnt<MAX_OBJLINES; p=pp) {
00065        pp=strchr(p,'\n'); if(pp) *pp++=0; else pp=p+strlen(p);
00066        strip_trailing_spaces(p);
00067        objline[objlinecnt]=p; objlinecnt++;
00068     }
00069     if(objlinecnt<1) error("Empty input data.");
00070     logdir=0;
00071     if((p=wordchr(objline[0],"<"))!=NULL) {
00072        logdir=-1; strcpy(p,p+1);
00073     }
00074     if((p=wordchr(objline[0],">"))!=NULL) {
00075        logdir=1; strcpy(p,p+1);
00076     }
00077     p=find_word_start(objline[0]); pp=find_word_end(p); if(*pp) *pp++=0;
00078     objline[0]=pp;
00079     for(request=0;request<reqcnt && strcasecmp(req[request].name,p)!=0; request++);
00080     if(request>=reqcnt) error("Bad request.");
00081     p=find_word_start(pp); pp=find_word_end(p); if(*pp) *pp++=0;
00082     objline[0]=pp; reqtype=p;
00083 }
00084 
00085 int main()
00086 {
00087     char *p;
00088     int i;
00089     
00090     error1=error; error2=error; error3=error;
00091     p=getenv("wims_exec_parm");
00092     if(p==NULL || *p==0) error("No input data.");
00093     snprintf(parmbuf,sizeof(parmbuf),"%s",p);
00094     parm();
00095     req[request].routine();
00096     for(i=0;i<regexcnt;i++) if(regexchk[i].isvar==0) free(&(regexchk[i].cmpreg));
00097     return 0;
00098 }
00099