[minupdate] whole browsed path

This commit is contained in:
xdrm-brackets 2017-05-15 17:19:29 +02:00
parent 315a8be97a
commit a66ea3fe14
3 changed files with 30 additions and 6 deletions

View File

@ -28,6 +28,7 @@ unsigned int browse(struct Automate* pAutomate, const char* pString, const char
char* pathmem = malloc( sizeof(char) ); // will contain edge number for each dot char* pathmem = malloc( sizeof(char) ); // will contain edge number for each dot
unsigned int* indexmem = malloc( sizeof(unsigned int) ); // will contain offset of @pString for each dot unsigned int* indexmem = malloc( sizeof(unsigned int) ); // will contain offset of @pString for each dot
char* dotmem = malloc( sizeof(char) ); char* dotmem = malloc( sizeof(char) );
pAutomate->path = realloc(pAutomate->path, 1 );
/* [1] For each char /* [1] For each char
=========================================================*/ =========================================================*/
@ -44,6 +45,7 @@ unsigned int browse(struct Automate* pAutomate, const char* pString, const char
c = 0; c = 0;
strIndex = 0; strIndex = 0;
pathmem[0] = 0; pathmem[0] = 0;
pAutomate->path[0] = 0;
while( pAutomate->dCurrent != pAutomate->dFinal && strIndex <= len ){ while( pAutomate->dCurrent != pAutomate->dFinal && strIndex <= len ){
@ -180,6 +182,11 @@ unsigned int browse(struct Automate* pAutomate, const char* pString, const char
indexmem = realloc(indexmem, sizeof(unsigned int) * (c+1) ); indexmem = realloc(indexmem, sizeof(unsigned int) * (c+1) );
dotmem = realloc(dotmem, sizeof(char) * (c+1) ); dotmem = realloc(dotmem, sizeof(char) * (c+1) );
pAutomate->n = c;
pAutomate->path = realloc(pAutomate->path, sizeof(char) * (c+1) );
pAutomate->path[c] = pAutomate->dCurrent;
pathmem[c] = 0; pathmem[c] = 0;
} }
@ -343,6 +350,8 @@ struct Automate createAutomate(const char* pName){
automate.dCurrent = 0; automate.dCurrent = 0;
automate.dFinal = 0; automate.dFinal = 0;
automate.n = 0;
/* [2] First allocation /* [2] First allocation
=========================================================*/ =========================================================*/
automate.dot = malloc( 0 ); automate.dot = malloc( 0 );
@ -350,6 +359,7 @@ struct Automate createAutomate(const char* pName){
automate.redge = malloc( 0 ); automate.redge = malloc( 0 );
automate.ledge = malloc( 0 ); automate.ledge = malloc( 0 );
automate.aedge = malloc( 0 ); automate.aedge = malloc( 0 );
automate.path = malloc( 0 );
automate.name = malloc( strlen(pName) + 1 ); automate.name = malloc( strlen(pName) + 1 );
strcpy(automate.name, pName); strcpy(automate.name, pName);

View File

@ -51,6 +51,9 @@
char steps; // number of steps char steps; // number of steps
char* name; // automate name char* name; // automate name
char* path; // automate path
unsigned int n; // automate path length
}; };

View File

@ -58,6 +58,7 @@ int main(int argc, char* argv[]){
mergeAutomate(&positive, 0); mergeAutomate(&positive, 0);
debug(positive); debug(positive);
// mergeAutomate(&number, 0); // mergeAutomate(&number, 0);
// debug(number); // debug(number);
@ -73,6 +74,16 @@ int main(int argc, char* argv[]){
printf(" (*) in %d steps\n", positive.steps); printf(" (*) in %d steps\n", positive.steps);
printf(" (*) in %.3lf seconds\n\n", (double)(stop-start)/CLOCKS_PER_SEC); printf(" (*) in %.3lf seconds\n\n", (double)(stop-start)/CLOCKS_PER_SEC);
for( c = 0 ; c < positive.n ; c++ ){
if( c > 0 )
printf(" -> ");
printf("q%d", positive.path[c]);
}
printf(" -> q%d\n", positive.dFinal);
exit(0); exit(0);
/* Build RegExp */ /* Build RegExp */
// char regex[40] = "(a([abc](b+a)(b+e)+ahd)*(b+i)c)sd"; // char regex[40] = "(a([abc](b+a)(b+e)+ahd)*(b+i)c)sd";