2004-04-08 09:43:06 +00:00
|
|
|
|
/* Eliot */
|
2005-05-05 23:45:04 +00:00
|
|
|
|
/* Copyright (C) 1999 Antoine Fraboulet */
|
2004-04-08 09:43:06 +00:00
|
|
|
|
/* */
|
2005-05-05 23:45:04 +00:00
|
|
|
|
/* This file is part of Eliot. */
|
|
|
|
|
/* */
|
|
|
|
|
/* Eliot is free software; you can redistribute it and/or modify */
|
2004-04-08 09:43:06 +00: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 19:51:00 +00:00
|
|
|
|
/* Eliot is distributed in the hope that it will be useful, */
|
2004-04-08 09:43:06 +00: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 14:53:42 +00:00
|
|
|
|
/* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
|
2004-04-08 09:43:06 +00:00
|
|
|
|
|
2006-01-01 19:51:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file listdic.c
|
|
|
|
|
* \brief Program used to list a dictionary
|
|
|
|
|
* \author Antoine Fraboulet
|
|
|
|
|
* \date 1999
|
|
|
|
|
*/
|
|
|
|
|
|
2004-04-08 09:43:06 +00:00
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
2006-04-16 11:27:19 +00:00
|
|
|
|
#include <stddef.h>
|
2004-04-08 09:43:06 +00:00
|
|
|
|
#include "dic_internals.h"
|
|
|
|
|
#include "dic.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
print_dic_rec(FILE* out, Dictionary dic, char *buf, char* s, Dawg_edge i)
|
|
|
|
|
{
|
|
|
|
|
if (i.term) /* edge points at a complete word */
|
|
|
|
|
{
|
|
|
|
|
*s = '\0';
|
2005-11-04 20:00:05 +00:00
|
|
|
|
fprintf (out,"%s\n", buf);
|
2004-04-08 09:43:06 +00:00
|
|
|
|
}
|
2005-11-04 20:00:05 +00:00
|
|
|
|
if (i.ptr)
|
2004-04-08 09:43:06 +00:00
|
|
|
|
{ /* Compute index: is it non-zero ? */
|
|
|
|
|
Dawg_edge *p = dic->dawg + i.ptr;
|
|
|
|
|
do { /* for each edge out of this node */
|
|
|
|
|
*s = p->chr + 'a' - 1;
|
2005-11-04 20:00:05 +00:00
|
|
|
|
print_dic_rec (out,dic,buf,s + 1, *p);
|
2004-04-08 09:43:06 +00:00
|
|
|
|
}
|
|
|
|
|
while (!(*p++).last);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-16 11:27:19 +00:00
|
|
|
|
|
2005-11-04 20:00:05 +00:00
|
|
|
|
void
|
2004-04-08 09:43:06 +00:00
|
|
|
|
dic_load(Dictionary* dic, char* filename)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
2005-11-04 20:00:05 +00:00
|
|
|
|
if ((res = Dic_load(dic, filename)) != 0)
|
2004-04-08 09:43:06 +00:00
|
|
|
|
{
|
|
|
|
|
switch (res) {
|
|
|
|
|
case 1: printf("chargement: probl<62>me d'ouverture de %s\n",filename); break;
|
|
|
|
|
case 2: printf("chargement: mauvais en-tete de dictionnaire\n"); break;
|
|
|
|
|
case 3: printf("chargement: probl<62>me 3 d'allocation m<>moire\n"); break;
|
|
|
|
|
case 4: printf("chargement: probl<62>me 4 d'alocation m<>moire\n"); break;
|
|
|
|
|
case 5: printf("chargement: probl<62>me de lecture des arcs du dictionnaire\n"); break;
|
|
|
|
|
default: printf("chargement: probl<62>me non-repertori<72>\n"); break;
|
|
|
|
|
}
|
|
|
|
|
exit(res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-16 11:27:19 +00:00
|
|
|
|
|
2004-04-08 09:43:06 +00:00
|
|
|
|
void
|
|
|
|
|
print_dic_list(char* filename, char* out)
|
|
|
|
|
{
|
|
|
|
|
FILE* fout;
|
|
|
|
|
Dictionary dic;
|
|
|
|
|
static char buf[80];
|
2005-11-04 20:00:05 +00:00
|
|
|
|
|
2004-04-08 09:43:06 +00:00
|
|
|
|
dic_load(&dic,filename);
|
|
|
|
|
|
|
|
|
|
if (strcmp(out,"stdout") == 0)
|
|
|
|
|
print_dic_rec(stdout,dic,buf,buf,dic->dawg[dic->root]);
|
|
|
|
|
else if (strcmp(out,"stderr") == 0)
|
|
|
|
|
print_dic_rec(stderr,dic,buf,buf,dic->dawg[dic->root]);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ((fout = fopen(out,"w")) == NULL)
|
|
|
|
|
return;
|
|
|
|
|
print_dic_rec(fout,dic,buf,buf,dic->dawg[dic->root]);
|
|
|
|
|
fclose(fout);
|
|
|
|
|
}
|
|
|
|
|
Dic_destroy(dic);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
print_header(char* filename)
|
|
|
|
|
{
|
|
|
|
|
Dict_header header;
|
|
|
|
|
|
2006-04-16 11:27:19 +00:00
|
|
|
|
Dic_check_header(&header,filename);
|
|
|
|
|
|
|
|
|
|
#define OO(IDENT) offsetof(Dict_header,IDENT)
|
2004-04-08 09:43:06 +00:00
|
|
|
|
|
|
|
|
|
printf("Dictionary header information\n");
|
2006-04-16 11:27:19 +00:00
|
|
|
|
printf("0x%02x ident : %s\n", OO(ident) ,header.ident);
|
|
|
|
|
printf("0x%02x unused 1 : %6d %06x\n",OO(unused_1) ,header.unused_1 ,header.unused_1);
|
|
|
|
|
printf("0x%02x unused 2 : %6d %06x\n",OO(unused_2) ,header.unused_2 ,header.unused_2);
|
|
|
|
|
printf("0x%02x root : %6d %06x\n",OO(root) ,header.root ,header.root);
|
|
|
|
|
printf("0x%02x words : %6d %06x\n",OO(nwords) ,header.nwords ,header.nwords);
|
|
|
|
|
printf("0x%02x edges used : %6d %06x\n",OO(edgesused) ,header.edgesused ,header.edgesused);
|
|
|
|
|
printf("0x%02x nodes used : %6d %06x\n",OO(nodesused) ,header.nodesused ,header.nodesused);
|
|
|
|
|
printf("0x%02x nodes saved : %6d %06x\n",OO(nodessaved),header.nodessaved,header.nodessaved);
|
|
|
|
|
printf("0x%02x edges saved : %6d %06x\n",OO(edgessaved),header.edgessaved,header.edgessaved);
|
2004-04-08 09:43:06 +00:00
|
|
|
|
printf("\n");
|
2006-04-16 11:27:19 +00:00
|
|
|
|
printf("sizeof(header) = 0x%x (%u)\n", sizeof(header), sizeof(header));
|
2004-04-08 09:43:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-16 11:27:19 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
print_node_hex(Dictionary dic, int i)
|
2004-04-08 09:43:06 +00:00
|
|
|
|
{
|
2006-04-16 11:27:19 +00:00
|
|
|
|
union edge_t {
|
|
|
|
|
Dawg_edge e;
|
|
|
|
|
uint32_t s;
|
|
|
|
|
} ee;
|
|
|
|
|
|
|
|
|
|
ee.e = dic->dawg[i];
|
|
|
|
|
|
|
|
|
|
printf("0x%04x %08x |%4d ptr=%8d t=%d l=%d f=%d chr=%2d (%c)\n",
|
|
|
|
|
i*sizeof(ee), (unsigned int)(ee.s),
|
|
|
|
|
i, ee.e.ptr, ee.e.term, ee.e.last, ee.e.fill, ee.e.chr, ee.e.chr +'a' -1);
|
2004-04-08 09:43:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-16 11:27:19 +00:00
|
|
|
|
|
2004-04-08 09:43:06 +00:00
|
|
|
|
void
|
|
|
|
|
print_dic_hex(char* filename)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
Dictionary dic;
|
|
|
|
|
dic_load(&dic,filename);
|
2005-11-04 20:00:05 +00:00
|
|
|
|
|
2004-04-08 09:43:06 +00:00
|
|
|
|
printf("offs binary structure \n");
|
|
|
|
|
printf("---- -------- | ------------------\n");
|
|
|
|
|
for(i=0; i < (dic->nedges + 1); i++)
|
2006-04-16 11:27:19 +00:00
|
|
|
|
print_node_hex(dic,i);
|
2004-04-08 09:43:06 +00:00
|
|
|
|
Dic_destroy(dic);
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-16 11:27:19 +00:00
|
|
|
|
|
2004-04-08 09:43:06 +00:00
|
|
|
|
void
|
|
|
|
|
usage(char* name)
|
|
|
|
|
{
|
|
|
|
|
printf("usage: %s [-a|-d|-h|-l] dictionnaire\n", name);
|
|
|
|
|
printf(" -a : print all\n");
|
|
|
|
|
printf(" -h : print header\n");
|
|
|
|
|
printf(" -d : print dic in hex\n");
|
|
|
|
|
printf(" -l : print dic word list\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-11-04 20:00:05 +00:00
|
|
|
|
int
|
2004-04-08 09:43:06 +00:00
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
int arg_count;
|
|
|
|
|
int option_print_all = 0;
|
|
|
|
|
int option_print_header = 0;
|
|
|
|
|
int option_print_dic_hex = 0;
|
|
|
|
|
int option_print_dic_list = 0;
|
|
|
|
|
|
2005-12-24 16:49:26 +00:00
|
|
|
|
if (argc < 3)
|
2004-04-08 09:43:06 +00:00
|
|
|
|
{
|
|
|
|
|
usage(argv[0]);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2005-11-04 20:00:05 +00:00
|
|
|
|
|
2004-04-08 09:43:06 +00:00
|
|
|
|
arg_count = 1;
|
|
|
|
|
while(argv[arg_count][0] == '-')
|
|
|
|
|
{
|
|
|
|
|
switch (argv[arg_count][1])
|
|
|
|
|
{
|
|
|
|
|
case 'a': option_print_all = 1; break;
|
|
|
|
|
case 'h': option_print_header = 1; break;
|
|
|
|
|
case 'd': option_print_dic_hex = 1; break;
|
|
|
|
|
case 'l': option_print_dic_list = 1; break;
|
|
|
|
|
default: usage(argv[0]); exit(2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
arg_count++;
|
|
|
|
|
}
|
2005-11-04 20:00:05 +00:00
|
|
|
|
|
2004-04-08 09:43:06 +00:00
|
|
|
|
if (option_print_header || option_print_all)
|
|
|
|
|
{
|
|
|
|
|
print_header(argv[arg_count]);
|
|
|
|
|
}
|
|
|
|
|
if (option_print_dic_hex || option_print_all)
|
|
|
|
|
{
|
|
|
|
|
print_dic_hex(argv[arg_count]);
|
|
|
|
|
}
|
|
|
|
|
if (option_print_dic_list || option_print_all)
|
|
|
|
|
{
|
|
|
|
|
print_dic_list(argv[arg_count],"stdout");
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|