-
Benoit Favre authoredBenoit Favre authored
rocio_slu.cc 2.65 KiB
/* SLU for Rocio XML */
/* FRED 0215 */
#include "librocio_slu.h"
#define TailleLigne 80000
#define MAX_FIELD 60000
int main(int argc, char **argv)
{
int nb,prevn;
char ch[TailleLigne],*chfileword,*chfileaction,*chfilemodel,*chfileclean,*prevword;
prevn=0; prevword=NULL;
chfileword=chfileaction=chfilemodel=chfileclean=NULL;
if (argc>1)
for(nb=1;nb<argc;nb++)
if (!strcmp(argv[nb],"-word")) { if (nb+1==argc) ERREUR("must have a value after argument;",argv[nb]); chfileword=argv[++nb]; }
else
if (!strcmp(argv[nb],"-action")) { if (nb+1==argc) ERREUR("must have a value after argument;",argv[nb]); chfileaction=argv[++nb]; }
else
if (!strcmp(argv[nb],"-fstmodel")) { if (nb+1==argc) ERREUR("must have a value after argument;",argv[nb]); chfilemodel=argv[++nb]; }
else
if (!strcmp(argv[nb],"-fstclean")) { if (nb+1==argc) ERREUR("must have a value after argument;",argv[nb]); chfileclean=argv[++nb]; }
else
if (!strcmp(argv[nb],"-prevn")) { if (nb+1==argc) ERREUR("must have a value after argument;",argv[nb]); if (sscanf(argv[++nb],"%d",&prevn)!=1) ERREUR("bad value:",argv[nb]); }
else
if (!strcmp(argv[nb],"-prevword")) { if (nb+1==argc) ERREUR("must have a value after argument;",argv[nb]); prevword=argv[++nb]; }
else
if (!strcmp(argv[nb],"-h"))
{
fprintf(stderr,"Syntax: %s [-h] -word <file> -action <file> -fstmodel <file> -fstclean <file> [-prevn <int>][-prevword <string>]\n",argv[0]);
exit(0);
}
else ERREUR("unknown option:",argv[nb]);
if ((!chfileword)||(!chfileaction)||(!chfilemodel)||(!chfileclean)) ERREUR("bad syntax, check '-h'","");
// init
slu_t* slu = init_slu(chfileword, chfileaction, chfilemodel, chfileclean);
// read words from stdin
char* words[MAX_FIELD];
int num_words = 0;
while (fgets(ch,TailleLigne,stdin))
{
for (words[num_words++]=strtok(ch," \t\n\r");(num_words<MAX_FIELD)&& NULL != (words[num_words]=strtok(NULL," \t\n\r")); num_words++) ;
if (num_words==MAX_FIELD) ERREUR("cste MAX_FIELD too small","");
}
fprintf(stderr, "%d words read from stdin\n", num_words);
// run them through system
run_slu(slu, words, num_words, prevn, prevword);
free_slu(slu);
exit(0);
}