1 /* $Id: readfile.c,v 1.13 2006-08-14 10:40:08 adam Exp $
2 Copyright (C) 1995-2006
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #include <idzebra/util.h>
39 static const char *inf_name;
46 read_rules (struct DFA *dfap),
52 static void prep (char **s)
54 static char expr_buf[MAXLINE+1];
66 static char *read_line (void)
68 static char linebuf[MAXLINE+1];
70 return fgets (linebuf, MAXLINE, inf);
73 static void read_defs (void)
76 while ((s=read_line()))
78 if (*s == '%' && s[1] == '%')
80 else if (*s == '\0' || isspace (*s))
83 error ("missing rule section");
86 static void read_rules (struct DFA *dfa)
93 fputs ("\n#ifndef YY_BREAK\n#define YY_BREAK break;\n#endif\n", outf);
94 fputs ("void lexact (int no)\n{\n", outf);
95 fputs ( "\tswitch (no)\n\t{\n", outf);
96 while ((s=read_line()))
98 if (*s == '%' && s[1] == '%')
100 else if (*s == '\0' || isspace (*s))
101 /* copy rest of line to output */
105 /* preprocess regular expression */
107 /* now parse regular expression */
109 i = dfa_parse (dfa, &sc);
112 fprintf (stderr, "%s #%d: regular expression syntax error\n",
120 fputs ("\t\tYY_BREAK\n", outf);
122 fprintf (outf, "\tcase %d:\n#line %d\n\t\t", no, line_no);
124 while (*sc == '\t' || *sc == ' ')
129 fputs ("\tYY_BREAK\n\t}\n}\n", outf);
131 error ("no regular expressions in rule section");
134 static void read_tail (void)
137 while ((s=read_line()))
141 int read_file (const char *s, struct DFA *dfa)
144 if (!(inf=fopen (s,"r")))
146 error ("cannot open `%s'", s);
150 if (!(outf=fopen ("lex.yy.c", "w")))
152 error ("cannot open `%s'", "lex.yy.c");
170 * indent-tabs-mode: nil
172 * vim: shiftwidth=4 tabstop=8 expandtab