IDZEBRA 2.2.11
lexer.c
Go to the documentation of this file.
1/* This file is part of the Zebra server.
2 Copyright (C) Index Data
3
4Zebra is free software; you can redistribute it and/or modify it under
5the terms of the GNU General Public License as published by the Free
6Software Foundation; either version 2, or (at your option) any later
7version.
8
9Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10WARRANTY; without even the implied warranty of MERCHANTABILITY or
11FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program; if not, write to the Free Software
16Foundation, 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 <idzebra/version.h>
33#include <dfa.h>
34#include "imalloc.h"
35#include "lexer.h"
36
37static char *prog;
38
39
40void error (const char *format, ...)
41{
42 va_list argptr;
43 va_start (argptr, format);
44 fprintf (stderr, "%s error: ", prog);
45 (void) vfprintf (stderr, format, argptr);
46 putc ('\n', stderr);
47 exit (1);
48}
49
50int ccluse = 0;
51
52static int lexer_options (int argc, char **argv)
53{
54 char version_str[16];
55 zebra_get_version(version_str, NULL);
56 while (--argc > 0)
57 if (**++argv == '-')
58 while (*++*argv)
59 {
60 switch (**argv)
61 {
62 case 'V':
63 fprintf (stderr, "%s: %s\n", prog, version_str);
64 continue;
65 case 's':
66 dfa_verbose = 1;
67 continue;
68 case 'c':
69 ccluse = 1;
70 continue;
71 case 'd':
72 switch (*++*argv)
73 {
74 case 's':
76 break;
77 case 't':
79 break;
80 case 'f':
82 break;
83 default:
84 --*argv;
88 }
89 continue;
90 default:
91 fprintf (stderr, "%s: unknown option `-%s'\n",
92 prog, *argv);
93 return 1;
94 }
95 break;
96 }
97 return 0;
98}
99
100int main (int argc, char **argv)
101{
102 int i, no = 0;
103 struct DFA *dfa;
104
105 prog = *argv;
106 dfa = dfa_init ();
107 i = lexer_options (argc, argv);
108 if (i)
109 return i;
110
111 if (argc < 2)
112 {
113 fprintf (stderr, "usage\n %s [-c] [-V] [-s] [-t] [-d[stf]] file\n",
114 prog);
115 return 1;
116 }
117 else while (--argc > 0)
118 if (**++argv != '-' && **argv)
119 {
120 ++no;
121
122 i = read_file (*argv, dfa);
123 if (i)
124 return i;
125 dfa_mkstate (dfa);
126
127#if MEMDEBUG
128 imemstat();
129#endif
130 }
131 dfa_delete (&dfa);
132#if MEMDEBUG
133 imemstat();
134#endif
135 if (!no)
136 {
137 fprintf (stderr, "%s: no files specified\n", prog);
138 return 2;
139 }
140 return 0;
141}
142
143/*
144 * Local variables:
145 * c-basic-offset: 4
146 * c-file-style: "Stroustrup"
147 * indent-tabs-mode: nil
148 * End:
149 * vim: shiftwidth=4 tabstop=8 expandtab
150 */
151
static char * prog
Definition agrep.c:50
void dfa_mkstate(struct DFA *)
Definition dfa.c:1148
void dfa_delete(struct DFA **)
Definition dfa.c:1158
int debug_dfa_followpos
Definition dfa.c:68
int debug_dfa_trav
Definition dfa.c:66
struct DFA * dfa_init(void)
Definition dfa.c:1092
int dfa_verbose
Definition dfa.c:69
int debug_dfa_tran
Definition dfa.c:67
int main(int argc, char **argv)
Definition lexer.c:100
int ccluse
Definition lexer.c:50
static int lexer_options(int argc, char **argv)
Definition lexer.c:52
void error(const char *format,...)
Definition lexer.c:40
int read_file(const char *, struct DFA *)
Definition readfile.c:141
Definition dfa.h:53
void zebra_get_version(char *version_str, char *sha1_str)
Returns Zebra version and SHA1 ID as generated by Git.
Definition version.c:32