1 |
/* Eliot */ |
/* Eliot */ |
2 |
/* Copyright (C) 1999 antoine.fraboulet */ |
/* Copyright (C) 1999 Antoine Fraboulet */ |
|
/* antoine.fraboulet@free.fr */ |
|
3 |
/* */ |
/* */ |
4 |
/* This program is free software; you can redistribute it and/or modify */ |
/* This file is part of Eliot. */ |
5 |
|
/* */ |
6 |
|
/* Eliot is free software; you can redistribute it and/or modify */ |
7 |
/* it under the terms of the GNU General Public License as published by */ |
/* it under the terms of the GNU General Public License as published by */ |
8 |
/* the Free Software Foundation; either version 2 of the License, or */ |
/* the Free Software Foundation; either version 2 of the License, or */ |
9 |
/* (at your option) any later version. */ |
/* (at your option) any later version. */ |
10 |
/* */ |
/* */ |
11 |
/* This program is distributed in the hope that it will be useful, */ |
/* Elit is distributed in the hope that it will be useful, */ |
12 |
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
13 |
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
14 |
/* GNU General Public License for more details. */ |
/* GNU General Public License for more details. */ |
16 |
/* You should have received a copy of the GNU General Public License */ |
/* You should have received a copy of the GNU General Public License */ |
17 |
/* along with this program; if not, write to the Free Software */ |
/* along with this program; if not, write to the Free Software */ |
18 |
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
19 |
|
|
20 |
/* |
/* |
21 |
* $Id$ |
* $Id$ |
22 |
*/ |
*/ |
38 |
#include "dic_search.h" |
#include "dic_search.h" |
39 |
#include "libdic_a-er.h" /* generated by bison */ |
#include "libdic_a-er.h" /* generated by bison */ |
40 |
#include "scanner.h" /* generated by flex */ |
#include "scanner.h" /* generated by flex */ |
|
|
|
41 |
#include "automaton.h" |
#include "automaton.h" |
42 |
|
|
43 |
|
/* |
44 |
|
* shut down the compiler |
45 |
|
*/ |
46 |
|
static int yy_init_globals (yyscan_t yyscanner ) |
47 |
|
{ |
48 |
|
yy_init_globals(yyscanner); |
49 |
|
return 0; |
50 |
|
} |
51 |
|
|
52 |
/** |
/** |
53 |
* Dic_seel_edgeptr |
* Dic_seel_edgeptr |
433 |
Dawg_edge *edgeptr, |
Dawg_edge *edgeptr, |
434 |
char wordlist[RES_REGE_MAX][DIC_WORD_MAX]) |
char wordlist[RES_REGE_MAX][DIC_WORD_MAX]) |
435 |
{ |
{ |
|
int i; |
|
436 |
int next_state; |
int next_state; |
|
int special_char; |
|
437 |
Dawg_edge *current; |
Dawg_edge *current; |
|
|
|
438 |
/* if we have a valid word we store it */ |
/* if we have a valid word we store it */ |
439 |
if (params->automaton->accept[state] && edgeptr->term) |
if (automaton_get_accept(params->automaton,state) && edgeptr->term) |
440 |
{ |
{ |
441 |
if (params->wordlistlen < params->wordlistlenmax) |
if (params->wordlistlen < params->wordlistlenmax) |
442 |
{ |
{ |
|
#ifdef DEBUG_RE |
|
|
fprintf(stdout,"adding word -%s-\n",params->word); |
|
|
#endif |
|
443 |
strcpy(wordlist[params->wordlistlen++],params->word); |
strcpy(wordlist[params->wordlistlen++],params->word); |
444 |
} |
} |
445 |
} |
} |
|
|
|
446 |
/* we now drive the search by exploring the dictionary */ |
/* we now drive the search by exploring the dictionary */ |
447 |
current = params->dic->dawg + edgeptr->ptr; |
current = params->dic->dawg + edgeptr->ptr; |
448 |
do { |
do { |
449 |
/* the current letter is current->chr */ |
/* the current letter is current->chr */ |
450 |
next_state = params->automaton->Dtrans[state][current->chr]; |
next_state = automaton_get_next_state(params->automaton,state,current->chr); |
451 |
/* 1 : the letter appears in the automaton as is */ |
/* 1 : the letter appears in the automaton as is */ |
452 |
if (params->automaton->marque[next_state]) |
if (next_state) |
453 |
{ |
{ |
|
#ifdef DEBUG_RE_SEARCH |
|
|
fprintf(stderr,"adding letter %c to partial word -%s-\n",current->chr + 'a' - 1,params->word); |
|
|
#endif |
|
454 |
params->word[params->wordlen] = current->chr + 'a' - 1; |
params->word[params->wordlen] = current->chr + 'a' - 1; |
455 |
params->wordlen ++; |
params->wordlen ++; |
456 |
Dic_search_regexp_rec(params,next_state,current,wordlist); |
Dic_search_regexp_rec(params,next_state,current,wordlist); |
457 |
params->wordlen --; |
params->wordlen --; |
458 |
params->word[params->wordlen] = '\0'; |
params->word[params->wordlen] = '\0'; |
459 |
} |
} |
|
|
|
|
/* 2 : we search in user defined list */ |
|
|
for(i=0; i < DIC_SEARCH_REGE_LIST; i++) |
|
|
{ |
|
|
if (params->charlist->valid[i]) |
|
|
{ |
|
|
/* symbol code in automaton */ |
|
|
special_char = params->charlist->symbl[i]; |
|
|
/* next possible state using the extra symbol */ |
|
|
next_state = params->automaton->Dtrans[state][special_char]; |
|
|
|
|
|
/* current->chr is in the list AND next state is valid */ |
|
|
if (params->charlist->letters[i][current->chr] && |
|
|
params->automaton->marque[next_state]) |
|
|
{ |
|
|
#ifdef DEBUG_RE_SEARCH |
|
|
fprintf(stderr,"** special char "); |
|
|
regexp_print_letter(stderr,special_char); |
|
|
fprintf(stderr," resolves to "); |
|
|
regexp_print_letter(stderr,current->chr); |
|
|
fprintf(stderr,"\n"); |
|
|
#endif |
|
|
params->word[params->wordlen] = current->chr + 'a' - 1; |
|
|
params->wordlen ++; |
|
|
Dic_search_regexp_rec(params,next_state,current,wordlist); |
|
|
params->wordlen --; |
|
|
params->word[params->wordlen] = '\0'; |
|
|
} |
|
|
} |
|
|
#ifdef DEBUG_RE |
|
|
else /* params->charlist->valid[i] */ |
|
|
{ |
|
|
special_char = params->charlist->symbl[i]; |
|
|
next_state = params->automaton->Dtrans[state][special_char]; |
|
|
if (params->automaton->marque[next_state] && ! params->charlist->valid[i]) |
|
|
{ |
|
|
fprintf(stderr,"special char "); |
|
|
regexp_print_letter(stderr,special_char); |
|
|
fprintf(stderr," appears in automaton but the list is invalid\n"); |
|
|
} |
|
|
} |
|
|
#endif |
|
|
} |
|
460 |
} while (!(*current++).last); |
} while (!(*current++).last); |
461 |
} |
} |
462 |
|
|
463 |
|
|
464 |
/** |
/** |
465 |
* function prototype for parser generated by bison |
* function prototype for parser generated by bison |
466 |
*/ |
*/ |
513 |
|
|
514 |
if (value) |
if (value) |
515 |
{ |
{ |
516 |
#ifdef DEBUG |
#ifdef DEBUG_FLEX_IS_BROKEN |
517 |
fprintf(stderr,"parser error at pos %d - %d : %s\n", |
fprintf(stderr,"parser error at pos %d - %d : %s\n", |
518 |
report.pos1, report.pos2, report.msg); |
report.pos1, report.pos2, report.msg); |
519 |
#endif |
#endif |
521 |
return ; |
return ; |
522 |
} |
} |
523 |
|
|
|
#ifdef DEBUG_RE |
|
|
fprintf(stderr,"recherche de l'expression %s\n",stringbuf); |
|
|
for(i=0; i < DIC_SEARCH_REGE_LIST; i++) |
|
|
{ |
|
|
if (list->valid[i]) |
|
|
{ |
|
|
int j; |
|
|
fprintf(stderr,"lettres (0x%02x) :",i); |
|
|
for(j=0; j<DIC_LETTERS; j++) |
|
|
if (list->letters[i][j]) |
|
|
{ |
|
|
regexp_print_letter2(stderr,j); |
|
|
} |
|
|
fprintf(stderr,"\n"); |
|
|
} |
|
|
} |
|
|
#endif |
|
|
|
|
524 |
n = 1; |
n = 1; |
525 |
p = 1; |
p = 1; |
526 |
regexp_parcours(root, &p, &n, ptl); |
regexp_parcours(root, &p, &n, ptl); |
528 |
ptl[0] = p - 1; |
ptl[0] = p - 1; |
529 |
|
|
530 |
regexp_possuivante(root,PS); |
regexp_possuivante(root,PS); |
|
regexp_delete_tree(root); |
|
531 |
|
|
532 |
if ((a = automaton_build(root->PP,ptl,PS)) != NULL) |
if ((a = automaton_build(root->PP,ptl,PS,list)) != NULL) |
533 |
{ |
{ |
|
#ifdef DEBUG_RE2 |
|
|
automaton_dump(a,"auto"); |
|
|
#endif |
|
|
|
|
534 |
params.dic = dic; |
params.dic = dic; |
535 |
params.automaton = a; |
params.automaton = a; |
536 |
params.charlist = list; |
params.charlist = list; |
538 |
params.wordlen = 0; |
params.wordlen = 0; |
539 |
params.wordlistlen = 0; |
params.wordlistlen = 0; |
540 |
params.wordlistlenmax = RES_REGE_MAX; |
params.wordlistlenmax = RES_REGE_MAX; |
541 |
Dic_search_regexp_rec(¶ms, a->init, dic->dawg + dic->root, wordlist); |
Dic_search_regexp_rec(¶ms, automaton_get_init(a), dic->dawg + dic->root, wordlist); |
542 |
|
|
543 |
automaton_delete(a); |
automaton_delete(a); |
544 |
} |
} |
545 |
|
regexp_delete_tree(root); |
546 |
} |
} |
547 |
|
|
548 |
/****************************************/ |
/****************************************/ |