2005-04-09 21:16:09 +02:00
|
|
|
|
/* Eliot */
|
2005-05-06 01:45:04 +02:00
|
|
|
|
/* Copyright (C) 1999 Antoine Fraboulet */
|
2005-04-09 21:16:09 +02:00
|
|
|
|
/* */
|
2005-05-06 01:45:04 +02:00
|
|
|
|
/* This file is part of Eliot. */
|
|
|
|
|
/* */
|
|
|
|
|
/* Eliot is free software; you can redistribute it and/or modify */
|
2005-04-09 21:16:09 +02:00
|
|
|
|
/* it under the terms of the GNU General Public License as published by */
|
|
|
|
|
/* the Free Software Foundation; either version 2 of the License, or */
|
|
|
|
|
/* (at your option) any later version. */
|
|
|
|
|
/* */
|
2006-01-01 20:51:00 +01:00
|
|
|
|
/* Eliot is distributed in the hope that it will be useful, */
|
2005-04-09 21:16:09 +02:00
|
|
|
|
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
|
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
|
|
|
/* GNU General Public License for more details. */
|
|
|
|
|
/* */
|
|
|
|
|
/* You should have received a copy of the GNU General Public License */
|
|
|
|
|
/* along with this program; if not, write to the Free Software */
|
2005-10-23 16:53:42 +02:00
|
|
|
|
/* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
2005-04-19 18:26:50 +02:00
|
|
|
|
|
2005-11-05 18:56:22 +01:00
|
|
|
|
/**
|
|
|
|
|
* \file regexpmain.c
|
|
|
|
|
* \brief Program used to test regexp
|
|
|
|
|
* \author Antoine Fraboulet
|
|
|
|
|
* \date 2005
|
|
|
|
|
*/
|
|
|
|
|
|
2005-04-09 21:16:09 +02:00
|
|
|
|
#include "config.h"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2005-04-19 18:26:50 +02:00
|
|
|
|
#include "dic.h"
|
2005-04-09 21:16:09 +02:00
|
|
|
|
#include "regexp.h"
|
2005-04-27 19:35:03 +02:00
|
|
|
|
#include "dic_search.h"
|
|
|
|
|
|
|
|
|
|
/********************************************************/
|
|
|
|
|
/********************************************************/
|
|
|
|
|
/********************************************************/
|
2005-04-09 21:16:09 +02:00
|
|
|
|
|
2005-11-04 21:00:05 +01:00
|
|
|
|
const unsigned int all_letter[DIC_LETTERS] =
|
2005-04-19 18:26:50 +02:00
|
|
|
|
{
|
|
|
|
|
/* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 */
|
|
|
|
|
/* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 */
|
|
|
|
|
/* x A B C D E F G H I J K L M N O P Q R S T U V W X Y Z */
|
2005-11-04 21:00:05 +01:00
|
|
|
|
0,1,1,1,1, 1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1, 1, 1, 1, 1
|
2005-04-19 18:26:50 +02:00
|
|
|
|
};
|
|
|
|
|
|
2005-11-04 21:00:05 +01:00
|
|
|
|
const unsigned int vowels[DIC_LETTERS] =
|
2005-04-19 18:26:50 +02:00
|
|
|
|
{
|
|
|
|
|
/* x A B C D E F G H I J K L M N O P Q R S T U V W X Y Z */
|
2005-11-04 21:00:05 +01:00
|
|
|
|
0,1,0,0,0, 1,0,0,0,1,0, 0,0,0,0,1,0,0,0,0,0,1,0, 0, 0, 1, 0
|
2005-04-19 18:26:50 +02:00
|
|
|
|
};
|
|
|
|
|
|
2005-11-04 21:00:05 +01:00
|
|
|
|
const unsigned int consonants[DIC_LETTERS] =
|
2005-04-19 18:26:50 +02:00
|
|
|
|
{
|
|
|
|
|
/* x A B C D E F G H I J K L M N O P Q R S T U V W X Y Z */
|
2005-11-04 21:00:05 +01:00
|
|
|
|
0,0,1,1,1, 0,1,1,1,0,1, 1,1,1,1,0,1,1,1,1,1,0,1, 1, 1, 1, 1
|
2005-04-19 18:26:50 +02:00
|
|
|
|
};
|
2005-04-16 22:55:51 +02:00
|
|
|
|
|
2005-04-27 19:35:03 +02:00
|
|
|
|
void init_letter_lists(struct search_RegE_list_t *list)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
memset (list,0,sizeof(*list));
|
2005-11-05 18:56:22 +01:00
|
|
|
|
list->minlength = 1;
|
|
|
|
|
list->maxlength = 15;
|
2005-04-27 19:35:03 +02:00
|
|
|
|
list->valid[0] = 1; // all letters
|
|
|
|
|
list->symbl[0] = RE_ALL_MATCH;
|
|
|
|
|
list->valid[1] = 1; // vowels
|
|
|
|
|
list->symbl[1] = RE_VOWL_MATCH;
|
|
|
|
|
list->valid[2] = 1; // consonants
|
|
|
|
|
list->symbl[2] = RE_CONS_MATCH;
|
|
|
|
|
for(i=0; i < DIC_LETTERS; i++)
|
|
|
|
|
{
|
|
|
|
|
list->letters[0][i] = all_letter[i];
|
|
|
|
|
list->letters[1][i] = vowels[i];
|
|
|
|
|
list->letters[2][i] = consonants[i];
|
2005-11-04 21:00:05 +01:00
|
|
|
|
}
|
2005-04-27 19:35:03 +02:00
|
|
|
|
list->valid[3] = 0; // user defined list 1
|
|
|
|
|
list->symbl[3] = RE_USR1_MATCH;
|
|
|
|
|
list->valid[4] = 0; // user defined list 2
|
|
|
|
|
list->symbl[4] = RE_USR2_MATCH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/********************************************************/
|
|
|
|
|
/********************************************************/
|
|
|
|
|
/********************************************************/
|
2005-11-05 18:56:22 +01:00
|
|
|
|
void
|
|
|
|
|
usage(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr,"usage: %s dictionary\n",argv[0]);
|
|
|
|
|
fprintf(stderr," dictionary : path to dawg eliot dictionary\n");
|
|
|
|
|
}
|
2005-04-27 19:35:03 +02:00
|
|
|
|
|
2005-04-19 18:26:50 +02:00
|
|
|
|
int main(int argc, char* argv[])
|
2005-04-09 21:16:09 +02:00
|
|
|
|
{
|
2005-04-19 18:26:50 +02:00
|
|
|
|
int i;
|
|
|
|
|
Dictionary dic;
|
|
|
|
|
char wordlist[RES_REGE_MAX][DIC_WORD_MAX];
|
|
|
|
|
char er[200];
|
|
|
|
|
strcpy(er,".");
|
|
|
|
|
struct search_RegE_list_t list;
|
|
|
|
|
|
2005-11-05 18:56:22 +01:00
|
|
|
|
if (argc < 2)
|
|
|
|
|
{
|
|
|
|
|
usage(argc,argv);
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-25 11:17:53 +02:00
|
|
|
|
if (Dic_load(&dic,argv[1]))
|
2005-04-16 22:55:51 +02:00
|
|
|
|
{
|
2005-04-19 18:26:50 +02:00
|
|
|
|
fprintf(stdout,"impossible de lire le dictionnaire\n");
|
2005-04-18 19:40:36 +02:00
|
|
|
|
return 1;
|
2005-04-16 22:55:51 +02:00
|
|
|
|
}
|
2005-04-09 21:16:09 +02:00
|
|
|
|
|
2005-04-19 18:26:50 +02:00
|
|
|
|
while (strcmp(er,""))
|
2005-04-16 22:55:51 +02:00
|
|
|
|
{
|
2005-05-06 01:45:04 +02:00
|
|
|
|
fprintf(stdout,"**************************************************************\n");
|
|
|
|
|
fprintf(stdout,"**************************************************************\n");
|
|
|
|
|
fprintf(stdout,"entrer une ER:\n");
|
2005-04-19 18:26:50 +02:00
|
|
|
|
fgets(er,sizeof(er),stdin);
|
2005-04-16 22:55:51 +02:00
|
|
|
|
/* strip \n */
|
2005-04-19 18:26:50 +02:00
|
|
|
|
er[strlen(er) - 1] = '\0';
|
2005-05-06 01:45:04 +02:00
|
|
|
|
if (strcmp(er,"") == 0)
|
|
|
|
|
break;
|
2005-04-27 19:35:03 +02:00
|
|
|
|
|
2005-04-18 19:40:36 +02:00
|
|
|
|
/* automaton */
|
2005-04-27 19:35:03 +02:00
|
|
|
|
init_letter_lists(&list);
|
2006-01-22 13:23:52 +01:00
|
|
|
|
Dic_search_RegE_inner(dic,er,wordlist,&list);
|
2005-04-27 19:35:03 +02:00
|
|
|
|
|
2005-04-19 18:26:50 +02:00
|
|
|
|
fprintf(stdout,"r<EFBFBD>sultat:\n");
|
|
|
|
|
for(i=0; i<RES_REGE_MAX && wordlist[i][0]; i++)
|
|
|
|
|
{
|
2005-05-06 01:45:04 +02:00
|
|
|
|
fprintf(stderr,"%s\n",wordlist[i]);
|
2005-04-19 18:26:50 +02:00
|
|
|
|
}
|
2005-04-16 22:55:51 +02:00
|
|
|
|
}
|
2005-04-19 18:26:50 +02:00
|
|
|
|
|
|
|
|
|
Dic_destroy(dic);
|
2005-04-09 21:16:09 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|