1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2009 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <idzebra/util.h>
36 static const char *inf_name;
43 read_rules (struct DFA *dfap),
49 static void prep (char **s)
51 static char expr_buf[MAXLINE+1];
63 static char *read_line (void)
65 static char linebuf[MAXLINE+1];
67 return fgets (linebuf, MAXLINE, inf);
70 static void read_defs (void)
73 while ((s=read_line()))
75 if (*s == '%' && s[1] == '%')
77 else if (*s == '\0' || isspace (*s))
80 error ("missing rule section");
83 static void read_rules (struct DFA *dfa)
90 fputs ("\n#ifndef YY_BREAK\n#define YY_BREAK break;\n#endif\n", outf);
91 fputs ("void lexact (int no)\n{\n", outf);
92 fputs ( "\tswitch (no)\n\t{\n", outf);
93 while ((s=read_line()))
95 if (*s == '%' && s[1] == '%')
97 else if (*s == '\0' || isspace (*s))
98 /* copy rest of line to output */
102 /* preprocess regular expression */
104 /* now parse regular expression */
106 i = dfa_parse (dfa, &sc);
109 fprintf (stderr, "%s #%d: regular expression syntax error\n",
117 fputs ("\t\tYY_BREAK\n", outf);
119 fprintf (outf, "\tcase %d:\n#line %d\n\t\t", no, line_no);
121 while (*sc == '\t' || *sc == ' ')
126 fputs ("\tYY_BREAK\n\t}\n}\n", outf);
128 error ("no regular expressions in rule section");
131 static void read_tail (void)
134 while ((s=read_line()))
138 int read_file (const char *s, struct DFA *dfa)
141 if (!(inf=fopen (s,"r")))
143 error ("cannot open `%s'", s);
147 if (!(outf=fopen ("lex.yy.c", "w")))
149 error ("cannot open `%s'", "lex.yy.c");
167 * c-file-style: "Stroustrup"
168 * indent-tabs-mode: nil
170 * vim: shiftwidth=4 tabstop=8 expandtab