" SET_HWPOS();
"" flush_headwords();
"" BEGIN_HEADWORD("asp", 1);
"" BEGIN_HEADWORD("altname", 0);
"" BEGIN_HEADWORD("decf", 1);
"" BEGIN_HEADWORD("col", 0);
"" BEGIN_HEADWORD("colf", 0);
"" BEGIN_HEADWORD("conjf", 0);
. ;
\n advance_line();
}
{
""[a-zA-Z][a-zA-Z]*">" {
if (yyleng == strlen(endtag) + 3 &&
memcmp(endtag, yytext + 2, yyleng-3) == 0) {
BEGIN(retstate);
obstack_1grow(&stk, 0);
}
}
"<"[a-zA-Z?][a-zA-Z0-9]*"/" {
char const *s = gcide_entity_to_utf8(yytext);
if (s) {
if (strcmp(s, ">") == 0)
dico_log(L_WARN, 0,
_("%s:%u: unknown or illegible character in a headword"),
infile, line);
obstack_grow(&stk, s, strlen(s));
} else
dico_log(L_WARN, 0, _("%s:%u: unrecognized entity: %s"),
infile, line, yytext);
}
"<"[a-zA-Z][^/>]*">" /* ignore tag */;
["*`] ;
"\\'d8" ; /* ignore double vertical bar */
"\\'"{XD}{XD} {
char const *s = gcide_escape_to_utf8(yytext+2);
if (s) {
int len = strlen(s);
obstack_grow(&stk, s, len);
} else {
obstack_grow(&stk, yytext, yyleng);
dico_log(L_WARN, 0,
_("%s:%u: unknown character sequence %s"),
infile, line, yytext);
}
}
[ \t] add_space(&stk);
. obstack_grow(&stk, yytext, yyleng);
\n {
add_space(&stk);
advance_line();
}
}
{
"-->" { BEGIN(INITIAL); }
. ;
\n advance_line();
}
{
"!>" { BEGIN(INITIAL); }
. ;
\n advance_line();
}
%%
int
yywrap(void)
{
flush_headwords();
if (letters[letno] == 0)
return 1;
yy_flex_debug = debug_letters && strchr(debug_letters, letters[letno]);
*suf = letters[letno++];
if (yyin)
fclose(yyin);
if (verbose_option)
dico_log(L_INFO, 0, _("Indexing %s"), infile);
yyin = fopen(infile, "r");
if (!yyin) {
dico_log(L_ERR, errno, _("cannot open file %s"), infile);
exit(EX_NOINPUT);
}
file_position = char_position = headword_position = 0;
line = 1;
return 0;
}
static int inherit_fd;
#include "idxgcide-cli.h"
/* Usage: idxgcide DICTDIR [IDXDIR] */
int
main(int argc, char **argv)
{
int index;
appi18n_init();
dico_set_program_name(argv[0]);
yy_flex_debug = 0;
get_options(argc, argv, &index);
idx_page = malloc(idx_header.ihdr_pagesize);
if (!idx_page) {
DICO_LOG_ERRNO();
exit(EX_UNAVAILABLE);
}
idx_page->ipg_header.hdr.phdr_numentries = 0;
idx_page->ipg_header.hdr.phdr_text_offset = idx_header.ihdr_pagesize / 2;
idx_header.ihdr_maxpageref = idx_header.ihdr_pagesize / 2 /
sizeof(struct gcide_ref);
if (idx_header.ihdr_maxpageref < 1) {
dico_log(L_ERR, 0, _("page size too small"));
exit(EX_USAGE);
}
idx_header.ihdr_maxpageref--;
argc -= index;
argv += index;
if (argc < 1 || argc > 2) {
dico_log(L_ERR, 0, _("bad number of arguments"));
exit(EX_USAGE);
}
dictdir = argv[0];
idxdir = argc == 2 ? argv[1] : dictdir;
infile = dico_full_file_name(dictdir, "CIDE.A");
if (!infile) {
DICO_LOG_MEMERR();
exit(EX_UNAVAILABLE);
}
suf = infile + strlen(infile) - 1;
if (dry_run_option && !inherit_fd)
idxname = "/dev/null";
else
idxname = dico_full_file_name(idxdir, GCIDE_IDX_FILE_NAME);
if (!idxname) {
DICO_LOG_MEMERR();
exit(EX_UNAVAILABLE);
}
if (inherit_fd) {
if (ftruncate(inherit_fd, 0)) {
dico_log(L_ERR, errno, _("cannot truncate index file `%s'"), idxname);
exit(EX_CANTCREAT);
}
idxfile = fdopen(inherit_fd, "w");
} else {
idxfile = fopen(idxname, "w");
}
if (!idxfile) {
dico_log(L_ERR, errno, _("cannot create index file `%s'"), idxname);
exit(EX_CANTCREAT);
}
fseek(idxfile, idx_header.ihdr_pagesize, SEEK_SET);
obstack_init(&stk);
obstack_init(&refstk);
letno = 0;
yywrap();
while (yylex ())
;
flush_refs();
fseek(idxfile, 0, SEEK_SET);
full_write(&idx_header, sizeof(idx_header));
fclose(idxfile);
if (verbose_option)
dico_log(L_INFO, 0,
_("headwords=%lu, definitions=%lu, refs per page=%lu, "
"pages=%lu"),
idx_header.ihdr_num_headwords,
idx_header.ihdr_num_defs,
idx_header.ihdr_maxpageref,
idx_header.ihdr_num_pages);
exit (0);
}
/* Local Variables: */
/* mode: c */
/* eval: (setq buffer-file-coding-system (if window-system 'utf-8 'raw-text-unix)) */
/* End: */