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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
/* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
19 |
|
|
|
/* $Id$ */ |
|
|
|
|
20 |
/** |
/** |
21 |
* \file dic_search.c |
* \file dic_search.c |
22 |
* \brief Dictionary lookup functions |
* \brief Dictionary lookup functions |
340 |
|
|
341 |
|
|
342 |
void |
void |
343 |
Dic_search_cross_rec(struct params_cross_t *params, |
Dic_search_cross_rec(struct params_cross_t *params, |
344 |
char wordlist[RES_CROS_MAX][DIC_WORD_MAX], |
char wordlist[RES_CROS_MAX][DIC_WORD_MAX], |
345 |
Dawg_edge *edgeptr) |
Dawg_edge *edgeptr) |
346 |
{ |
{ |
347 |
Dawg_edge *current = params->dic->dawg + edgeptr->ptr; |
Dawg_edge *current = params->dic->dawg + edgeptr->ptr; |
418 |
int minlength; |
int minlength; |
419 |
int maxlength; |
int maxlength; |
420 |
automaton automaton; |
automaton automaton; |
421 |
struct search_RegE_list_t *charlist; |
struct search_RegE_list_t *charlist; |
422 |
char word[DIC_WORD_MAX]; |
char word[DIC_WORD_MAX]; |
423 |
int wordlen; |
int wordlen; |
424 |
int wordlistlen; |
int wordlistlen; |
426 |
}; |
}; |
427 |
|
|
428 |
void |
void |
429 |
Dic_search_regexp_rec(struct params_regexp_t *params, |
Dic_search_regexp_rec(struct params_regexp_t *params, |
430 |
int state, |
int state, |
431 |
Dawg_edge *edgeptr, |
Dawg_edge *edgeptr, |
432 |
char wordlist[RES_REGE_MAX][DIC_WORD_MAX]) |
char wordlist[RES_REGE_MAX][DIC_WORD_MAX]) |
433 |
{ |
{ |
434 |
int next_state; |
int next_state; |
437 |
if (automaton_get_accept(params->automaton,state) && edgeptr->term) |
if (automaton_get_accept(params->automaton,state) && edgeptr->term) |
438 |
{ |
{ |
439 |
int l = strlen(params->word); |
int l = strlen(params->word); |
440 |
if (params->wordlistlen < params->wordlistlenmax && |
if (params->wordlistlen < params->wordlistlenmax && |
441 |
params->minlength <= l && |
params->minlength <= l && |
442 |
params->maxlength >= l) |
params->maxlength >= l) |
443 |
{ |
{ |
444 |
strcpy(wordlist[params->wordlistlen++],params->word); |
strcpy(wordlist[params->wordlistlen++],params->word); |
445 |
} |
} |
446 |
} |
} |
447 |
/* we now drive the search by exploring the dictionary */ |
/* we now drive the search by exploring the dictionary */ |
448 |
current = params->dic->dawg + edgeptr->ptr; |
current = params->dic->dawg + edgeptr->ptr; |
449 |
do { |
do { |
462 |
} |
} |
463 |
|
|
464 |
|
|
465 |
/** |
/** |
466 |
* function prototype for parser generated by bison |
* function prototype for parser generated by bison |
467 |
*/ |
*/ |
468 |
int regexpparse(yyscan_t scanner, NODE** root, |
int regexpparse(yyscan_t scanner, NODE** root, |
469 |
struct search_RegE_list_t *list, |
struct search_RegE_list_t *list, |
470 |
struct regexp_error_report_t *err); |
struct regexp_error_report_t *err); |
471 |
|
|
475 |
struct search_RegE_list_t *list) |
struct search_RegE_list_t *list) |
476 |
{ |
{ |
477 |
int i,p,n,value; |
int i,p,n,value; |
478 |
int ptl[REGEXP_MAX+1]; |
int ptl[REGEXP_MAX+1]; |
479 |
int PS [REGEXP_MAX+1]; |
int PS [REGEXP_MAX+1]; |
480 |
NODE* root; |
NODE* root; |
481 |
yyscan_t scanner; |
yyscan_t scanner; |
482 |
YY_BUFFER_STATE buf; |
YY_BUFFER_STATE buf; |
517 |
#ifdef DEBUG_FLEX_IS_BROKEN |
#ifdef DEBUG_FLEX_IS_BROKEN |
518 |
fprintf(stderr,"parser error at pos %d - %d : %s\n", |
fprintf(stderr,"parser error at pos %d - %d : %s\n", |
519 |
report.pos1, report.pos2, report.msg); |
report.pos1, report.pos2, report.msg); |
520 |
#endif |
#endif |
521 |
regexp_delete_tree(root); |
regexp_delete_tree(root); |
522 |
return ; |
return ; |
523 |
} |
} |
542 |
params.wordlistlen = 0; |
params.wordlistlen = 0; |
543 |
params.wordlistlenmax = RES_REGE_MAX; |
params.wordlistlenmax = RES_REGE_MAX; |
544 |
Dic_search_regexp_rec(¶ms, automaton_get_init(a), dic->dawg + dic->root, wordlist); |
Dic_search_regexp_rec(¶ms, automaton_get_init(a), dic->dawg + dic->root, wordlist); |
545 |
|
|
546 |
automaton_delete(a); |
automaton_delete(a); |
547 |
} |
} |
548 |
regexp_delete_tree(root); |
regexp_delete_tree(root); |