regexpmain.c

Go to the documentation of this file.
00001 /* Eliot                                                                     */
00002 /* Copyright (C) 1999  Antoine Fraboulet                                     */
00003 /*                                                                           */
00004 /* This file is part of Eliot.                                               */
00005 /*                                                                           */
00006 /* Eliot is free software; you can redistribute it and/or modify             */
00007 /* it under the terms of the GNU General Public License as published by      */
00008 /* the Free Software Foundation; either version 2 of the License, or         */
00009 /* (at your option) any later version.                                       */
00010 /*                                                                           */
00011 /* Eliot is distributed in the hope that it will be useful,                  */
00012 /* but WITHOUT ANY WARRANTY; without even the implied warranty of            */
00013 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             */
00014 /* GNU General Public License for more details.                              */
00015 /*                                                                           */
00016 /* You should have received a copy of the GNU General Public License         */
00017 /* along with this program; if not, write to the Free Software               */
00018 /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00019 
00020 /**
00021  *  \file   regexpmain.c
00022  *  \brief  Program used to test regexp
00023  *  \author Antoine Fraboulet
00024  *  \date   2005
00025  */
00026 
00027 #include "config.h"
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include <string.h>
00031 
00032 #include "dic.h"
00033 #include "regexp.h"
00034 #include "dic_search.h"
00035 
00036 /********************************************************/
00037 /********************************************************/
00038 /********************************************************/
00039 
00040 const unsigned int all_letter[DIC_LETTERS] =
00041   {
00042     /*                      1  1 1 1 1 1 1 1 1 1 2 2 2  2  2  2  2 */
00043     /* 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 */
00044     /* 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 */
00045        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
00046   };
00047 
00048 const unsigned int vowels[DIC_LETTERS] =
00049   {
00050     /* 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 */
00051        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
00052   };
00053 
00054 const unsigned int consonants[DIC_LETTERS] =
00055   {
00056     /* 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 */
00057        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
00058   };
00059 
00060 void init_letter_lists(struct search_RegE_list_t *list)
00061 {
00062   int i;
00063   memset (list,0,sizeof(*list));
00064   list->minlength = 1;
00065   list->maxlength = 15;
00066   list->valid[0] = 1; // all letters
00067   list->symbl[0] = RE_ALL_MATCH;
00068   list->valid[1] = 1; // vowels
00069   list->symbl[1] = RE_VOWL_MATCH;
00070   list->valid[2] = 1; // consonants
00071   list->symbl[2] = RE_CONS_MATCH;
00072   for(i=0; i < DIC_LETTERS; i++)
00073     {
00074       list->letters[0][i] = all_letter[i];
00075       list->letters[1][i] = vowels[i];
00076       list->letters[2][i] = consonants[i];
00077     }
00078   list->valid[3] = 0; // user defined list 1
00079   list->symbl[3] = RE_USR1_MATCH;
00080   list->valid[4] = 0; // user defined list 2
00081   list->symbl[4] = RE_USR2_MATCH;
00082 }
00083 
00084 /********************************************************/
00085 /********************************************************/
00086 /********************************************************/
00087 void
00088 usage(int argc, char* argv[])
00089 {
00090   fprintf(stderr,"usage: %s dictionary\n",argv[0]);
00091   fprintf(stderr,"   dictionary : path to dawg eliot dictionary\n");
00092 }
00093 
00094 int main(int argc, char* argv[])
00095 {
00096   int i;
00097   Dictionary dic;
00098   char wordlist[RES_REGE_MAX][DIC_WORD_MAX];
00099   char er[200];
00100   strcpy(er,".");
00101   struct search_RegE_list_t list;
00102 
00103   if (argc < 2)
00104     {
00105       usage(argc,argv);
00106     }
00107 
00108   if (Dic_load(&dic,argv[1]))
00109     {
00110       fprintf(stdout,"impossible de lire le dictionnaire\n");
00111       return 1;
00112     }
00113 
00114   while (strcmp(er,""))
00115     {
00116       fprintf(stdout,"**************************************************************\n");
00117       fprintf(stdout,"**************************************************************\n");
00118       fprintf(stdout,"entrer une ER:\n");
00119       fgets(er,sizeof(er),stdin);
00120       /* strip \n */
00121       er[strlen(er) - 1] = '\0';
00122       if (strcmp(er,"") == 0)
00123         break;
00124 
00125       /* automaton */
00126       init_letter_lists(&list);
00127       Dic_search_RegE(dic,er,wordlist,&list);
00128 
00129       fprintf(stdout,"résultat:\n");
00130       for(i=0; i<RES_REGE_MAX && wordlist[i][0]; i++)
00131         {
00132           fprintf(stderr,"%s\n",wordlist[i]);
00133         }
00134     }
00135 
00136   Dic_destroy(dic);
00137   return 0;
00138 }

Generated on Thu Dec 29 02:01:14 2005 for Eliot by  doxygen 1.4.5