IDZEBRA  2.1.2
lexer.c
Go to the documentation of this file.
1 /* This file is part of the Zebra server.
2  Copyright (C) Index Data
3 
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
7 version.
8 
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
12 for more details.
13 
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
17 
18 */
19 
20 
21 #if HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24 #include <stdio.h>
25 #include <assert.h>
26 
27 #include <stdlib.h>
28 #include <string.h>
29 #include <stdarg.h>
30 
31 #include <idzebra/util.h>
32 #include <dfa.h>
33 #include "imalloc.h"
34 #include "lexer.h"
35 
36 static char *prog;
37 
38 
39 void error (const char *format, ...)
40 {
41  va_list argptr;
42  va_start (argptr, format);
43  fprintf (stderr, "%s error: ", prog);
44  (void) vfprintf (stderr, format, argptr);
45  putc ('\n', stderr);
46  exit (1);
47 }
48 
49 int ccluse = 0;
50 
51 static int lexer_options (int argc, char **argv)
52 {
53  while (--argc > 0)
54  if (**++argv == '-')
55  while (*++*argv)
56  {
57  switch (**argv)
58  {
59  case 'V':
60  fprintf (stderr, "%s: %s %s\n", prog, __DATE__, __TIME__);
61  continue;
62  case 's':
63  dfa_verbose = 1;
64  continue;
65  case 'c':
66  ccluse = 1;
67  continue;
68  case 'd':
69  switch (*++*argv)
70  {
71  case 's':
72  debug_dfa_tran = 1;
73  break;
74  case 't':
75  debug_dfa_trav = 1;
76  break;
77  case 'f':
79  break;
80  default:
81  --*argv;
82  debug_dfa_tran = 1;
84  debug_dfa_trav = 1;
85  }
86  continue;
87  default:
88  fprintf (stderr, "%s: unknown option `-%s'\n",
89  prog, *argv);
90  return 1;
91  }
92  break;
93  }
94  return 0;
95 }
96 
97 int main (int argc, char **argv)
98 {
99  int i, no = 0;
100  struct DFA *dfa;
101 
102  prog = *argv;
103  dfa = dfa_init ();
104  i = lexer_options (argc, argv);
105  if (i)
106  return i;
107 
108  if (argc < 2)
109  {
110  fprintf (stderr, "usage\n %s [-c] [-V] [-s] [-t] [-d[stf]] file\n",
111  prog);
112  return 1;
113  }
114  else while (--argc > 0)
115  if (**++argv != '-' && **argv)
116  {
117  ++no;
118 
119  i = read_file (*argv, dfa);
120  if (i)
121  return i;
122  dfa_mkstate (dfa);
123 
124 #if MEMDEBUG
125  imemstat();
126 #endif
127  }
128  dfa_delete (&dfa);
129 #if MEMDEBUG
130  imemstat();
131 #endif
132  if (!no)
133  {
134  fprintf (stderr, "%s: no files specified\n", prog);
135  return 2;
136  }
137  return 0;
138 }
139 
140 /*
141  * Local variables:
142  * c-basic-offset: 4
143  * c-file-style: "Stroustrup"
144  * indent-tabs-mode: nil
145  * End:
146  * vim: shiftwidth=4 tabstop=8 expandtab
147  */
148 
struct DFA * dfa_init(void)
Definition: dfa.c:1090
void dfa_mkstate(struct DFA *)
Definition: dfa.c:1146
int read_file(const char *, struct DFA *)
Definition: readfile.c:141
void error(const char *format,...)
Definition: lexer.c:39
int ccluse
Definition: lexer.c:49
void dfa_delete(struct DFA **)
Definition: dfa.c:1156
int main(int argc, char **argv)
Definition: lexer.c:97
int dfa_verbose
Definition: dfa.c:67
int debug_dfa_followpos
Definition: dfa.c:66
int debug_dfa_tran
Definition: dfa.c:65
int debug_dfa_trav
Definition: dfa.c:64
static char * prog
Definition: lexer.c:36
static int lexer_options(int argc, char **argv)
Definition: lexer.c:51
Definition: dfa.h:53