Changeset: bf4d4354bead for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bf4d4354bead
Modified Files:
        clients/mapiclient/eventparser.c
        clients/mapiclient/eventparser.h
        clients/mapiclient/tachograph.c
Branch: default
Log Message:

Add prereq field for backward chaining


diffs (153 lines):

diff --git a/clients/mapiclient/eventparser.c b/clients/mapiclient/eventparser.c
--- a/clients/mapiclient/eventparser.c
+++ b/clients/mapiclient/eventparser.c
@@ -25,6 +25,8 @@ char *statenames[]= {"","start","done","
 
 char *malarguments[MAXMALARGS];
 int malargtop;
+char *malvariables[MAXMALARGS];
+int malvartop;
 int debug;
 
 void
@@ -35,6 +37,10 @@ clearArguments(void)
        if( malarguments[i])
                free(malarguments[i]);
        malargtop = 0;
+       for(i = 0; i < malvartop; i++)
+       if( malvariables[i])
+               free(malvariables[i]);
+       malvartop = 0;
 }
 
 static void
@@ -42,6 +48,7 @@ parseArguments(char *call)
 {
        int i;
        char  *c = call, *l, ch;
+       char *v;
        
        malargtop = 0;
        if( debug)
@@ -51,14 +58,15 @@ parseArguments(char *call)
                        break;
                if (*c == ',')
                        continue;
-               if (*c == 'X'){
-                       // skip variable
+               if (*c == 'X' || *c == 'A'){
+                       // remember variable in its own structure
+                       v=  c;
                        c= strchr(c,'=');
                        if( c == 0)
                                break;
+                       *c = 0;
+                       malvariables[malvartop++] = strdup(v);
                        c++;
-                       if( debug)
-                               fprintf(stderr,"arg:%s\n",c);
                }
                if (*c== '\\' && *(c+1) =='"'){
                        c++; c++;
@@ -85,9 +93,12 @@ parseArguments(char *call)
                                *l =0;
                }
        }
-       if( debug)
-       for(i=0; i < malargtop; i++)
-               fprintf(stderr,"arg[%d] %s\n",i,malarguments[i]);
+       if( debug){
+               for(i=0; i < malargtop; i++)
+                       fprintf(stderr,"arg[%d] %s\n",i,malarguments[i]);
+               for(i=0; i < malvartop; i++)
+                       fprintf(stderr,"var[%d] %s\n",i,malvariables[i]);
+       }
 }
 int
 eventparser(char *row, EventRecord *ev)
diff --git a/clients/mapiclient/eventparser.h b/clients/mapiclient/eventparser.h
--- a/clients/mapiclient/eventparser.h
+++ b/clients/mapiclient/eventparser.h
@@ -100,6 +100,8 @@ typedef struct  {
 #define MAXMALARGS 1024
 extern char *malarguments[MAXMALARGS];
 extern int malargtop;
+extern char *malvariables[MAXMALARGS];
+extern int malvartop;
 extern int debug;
 
 extern void clearArguments(void);
diff --git a/clients/mapiclient/tachograph.c b/clients/mapiclient/tachograph.c
--- a/clients/mapiclient/tachograph.c
+++ b/clients/mapiclient/tachograph.c
@@ -144,8 +144,12 @@ lng prevprogress =0;
 static FILE *tachofd;
 
 static void resetTachograph(void){
+       int i;
        if (debug)
                fprintf(stderr, "RESET tachograph\n");
+       for(i=0; i < malsize; i++)
+       if( events[i].stmt)
+               free(events[i].stmt);
        malsize= 0;
        malargtop =0;
        currentfunction = 0;
@@ -345,8 +349,8 @@ static void
 update(EventRecord *ev)
 {
        double progress=0;
-       int i;
-       char *qry, *q = 0, *c;
+       int i,j;
+       char *v, *qry, *q = 0, *c;
        int uid = 0,qid = 0;
        char line[BUFSIZ];
  
@@ -434,7 +438,7 @@ update(EventRecord *ev)
                }
                events[ev->pc].state = RUNNING;
                renderCall(line,BUFSIZ, 0, ev->stmt,0);
-               events[ev->pc].stmt = strdup(line);
+               events[ev->pc].stmt = strdup(ev->stmt);
                events[ev->pc].etc = ev->ticks;
                if( ev->pc > lastpc)
                        lastpc = ev->pc;
@@ -446,7 +450,19 @@ update(EventRecord *ev)
                fprintf(tachofd,"\"estimate\": "LLFMT",\n",ev->ticks);
                fprintf(tachofd,"\"stmt\": \"%s\",\n",ev->stmt);
                fprintf(tachofd,"\"beautystmt\": \"%s\",\n",line);
-               fprintf(tachofd,"\"prereq\":[]\n");
+               // collect all input producing PCs
+               fprintf(tachofd,"\"prereq\":[");
+               for( i=0; i < malvartop; i++){
+                       for(j= ev->pc; j>=0;j --){
+                               if(debug)
+                                       fprintf(stderr,"locate %s in 
%s\n",malvariables[i], events[j].stmt);
+                               if(events[j].stmt && (v = 
strstr(events[j].stmt, malvariables[i])) && v < strstr(events[j].stmt,":=")){
+                                       fprintf(tachofd,"%s%d",(i?", ":""), j);
+                                       break;
+                               }
+                       }
+               }
+               fprintf(tachofd,"]\n");
                fprintf(tachofd,"},\n");
                fflush(tachofd);
 
@@ -459,8 +475,6 @@ update(EventRecord *ev)
        }
        /* end the instruction box */
        if (ev->state == DONE ){
-               if( events[ev->pc].stmt)
-                       free(events[ev->pc].stmt);
                        
                fprintf(tachofd,"{\n");
                
fprintf(tachofd,"\"qid\":\"%s\",\n",currentfunction?currentfunction:"");
@@ -474,7 +488,6 @@ update(EventRecord *ev)
                fprintf(tachofd,"},\n");
                fflush(tachofd);
 
-               events[ev->pc].stmt= 0;
                events[ev->pc].state= FINISHED;
                free(ev->stmt);
                if( duration)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to