Mercurial > routeflapper
annotate src/tokenizer.h @ 8:69a5dcf953df default tip
routeflapper runs as root to read the log files
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 04 Sep 2014 08:57:50 -0700 |
parents | 180d26aa2a17 |
children |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Copyright (c) 2007 Carl Byington - 510 Software Group, released under | |
4 the GPL version 3 or any later version at your choice available at | |
5 http://www.gnu.org/licenses/gpl-3.0.txt | |
6 | |
7 */ | |
8 | |
9 using namespace std; | |
10 | |
11 struct ltstr { | |
4
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
12 bool operator()(const char* s1, const char* s2) const { |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
13 return strcmp(s1, s2) < 0; |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
14 } |
0 | 15 }; |
16 | |
4
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
17 typedef list<ifstream *> stream_list; |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
18 typedef list<const char *> string_list; |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
19 typedef set<const char *, ltstr> string_set; |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
20 typedef list<int> line_list; |
0 | 21 |
22 class TOKEN { | |
4
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
23 stream_list streams; |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
24 string_list filenames; |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
25 string_set filenamess; |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
26 line_list linenumbers; |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
27 string_list pending_tokens; |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
28 string_set *include_files; |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
29 bool pushed; |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
30 u_char pushed_char; |
0 | 31 |
4
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
32 void pop(); |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
33 bool next_char(u_char &c); |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
34 void push_char(u_char c); |
0 | 35 |
36 public: | |
4
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
37 TOKEN(const char *fn, string_set *includes); |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
38 ~TOKEN(); |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
39 bool include(const char *fn); |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
40 const char *next(); // return next token |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
41 int nextint(); |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
42 void skipeol(); // skip to eol |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
43 void push(const char *token) {pending_tokens.push_front(token);}; |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
44 const char *cur_fn() {return filenames.empty() ? "" : filenames.front();}; |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
45 int cur_line() {return linenumbers.empty() ? 0 : linenumbers.front();}; |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
46 void token_error(const char *err); |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
47 void token_error(const char *fmt, int d, const char *s); |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
48 void token_error(const char *fmt, const char *t, const char *h); |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
49 void token_error(const char *want, const char *have); |
180d26aa2a17
Fedora 9 compile and const correctness.
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
50 void token_error(); |
0 | 51 }; |
52 |