%{ /* This file is part of Ellinika project. Copyright (C) 2004 Sergey Poznyakoff Ellinika is free software; you can redistribute it and/or modify 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. Ellinika is distributed in the hope that it will be useful, 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 Ellinika; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "trans.h" #include "gram.h" #include char *file_name = NULL; int input_line = 1; void set_location(); #define isws(c) ((c)==' ' || (c)=='\t') %} MWS [ \t]* WS [ \t]+ %% #.*\n input_line++; ^[nN][oO][dD][eE] return NODE; ^[pP][oO][sS] return POS; ^[eE][nN][dD]{MWS} return END; ^[mM][eE][aA][nN][iI][nN][gG] return MEANING; ^[aA][lL][iI][aA][sS] return ALIAS; ^[aA][nN][tT] return ANT; ^[tT][oO][pP][iI][cC] return TOPIC; ^[fF][oO][rR][mM][sS] return FORMS; ^[xX][rR][eE][fF] return XREF; ^[lL][iI][nN][eE]{WS}\"[^\"]+\"{WS}[0-9]+\n set_location(); \n input_line++; {WS}[^\n]+\n { char *p, *q; for (p = yytext + yyleng - 1; p > yytext && isspace(*p); p--) ; p[1] = 0; input_line++; yylval.string = yytext+1; return STRING; } . { fprintf (stderr, "%s:%d: stray character %c\n", file_name, input_line, yytext[0]); exit(1); } %% void set_location() { char *start = strchr(yytext+1, '"'); char *p = strchr(start+1, '"'); int len = p-start-1; free(file_name); file_name = emalloc(len+1); memcpy(file_name, start+1, len); file_name[len] = 0; for (p++; p < yytext+yyleng && isws (*p); p++) ; input_line = strtoul (p, NULL, 0); } char *m4_cmdline; #define DEFAULT_INCLUDE "dict.m4" void make_m4_args (char *m4_bin, RAD_LIST *include_list) { int i, n; size_t len; len = strlen(m4_bin); for (i = 0; i < list_count(include_list); i++) len += 3 + strlen(list_item(include_list, i)); len += 1+strlen(DEFAULT_INCLUDE); len++; m4_cmdline = emalloc(len); n = sprintf(m4_cmdline, "%s ", m4_bin); for (i = 0; i < list_count(include_list); i++) n += sprintf(m4_cmdline+n, "-I%s ", list_item(include_list, i)); n += sprintf(m4_cmdline+n, "%s", DEFAULT_INCLUDE); m4_cmdline[n] = 0; } void open_input(int argc, char **argv) { char *inv; int i, n, len = 0; for (i = 0; i < argc; i++) len += 1 + strlen(argv[i]); inv = emalloc(strlen(m4_cmdline) + len + 1); n = sprintf(inv, "%s", m4_cmdline); for (i = 0; i < argc; i++) n += sprintf(inv+n, " %s", argv[i]); inv[n] = 0; yyin = popen(inv, "r"); if (!yyin) { fprintf(stderr, "cannot execute "); perror(inv); exit(1); } free(inv); } int yywrap() { if (file_name) pclose(yyin); return 1; }