Mercurial > dnsbl
comparison src/tokenizer.h @ 214:82886d4dd71f stable-6-0-19
Fixes to compile on Fedora 9 and for const correctness.
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 10 Jun 2008 08:58:42 -0700 |
parents | 44ffef730bc4 |
children | 5209e92b4885 |
comparison
equal
deleted
inserted
replaced
213:44ffef730bc4 | 214:82886d4dd71f |
---|---|
4 the GPL version 3 or any later version at your choice available at | 4 the GPL version 3 or any later version at your choice available at |
5 http://www.gnu.org/licenses/gpl-3.0.txt | 5 http://www.gnu.org/licenses/gpl-3.0.txt |
6 | 6 |
7 */ | 7 */ |
8 | 8 |
9 #ifndef tokenizer_include | |
10 #define tokenizer_include | |
11 | |
12 #include <fstream> | |
13 #include <list> | |
14 #include <set> | |
15 #include <stdio.h> | |
16 #include <ctype.h> | |
17 | |
18 | |
19 using namespace std; | 9 using namespace std; |
20 | 10 |
21 struct ltstr { | 11 struct ltstr { |
22 bool operator()(char* s1, char* s2) const { | 12 bool operator()(const char* s1, const char* s2) const { |
23 return strcmp(s1, s2) < 0; | 13 return strcmp(s1, s2) < 0; |
24 } | 14 } |
25 }; | 15 }; |
26 | 16 |
27 typedef list<ifstream *> stream_list; | 17 typedef list<ifstream *> stream_list; |
28 typedef list<char *> string_list; | 18 typedef list<const char *> string_list; |
29 typedef set<char *, ltstr> string_set; | 19 typedef set<const char *, ltstr> string_set; |
30 typedef list<int> line_list; | 20 typedef list<int> line_list; |
31 | 21 |
32 class TOKEN { | 22 class TOKEN { |
33 stream_list streams; | 23 stream_list streams; |
34 string_list filenames; | 24 string_list filenames; |
35 string_set filenamess; | 25 string_set filenamess; |
42 void pop(); | 32 void pop(); |
43 bool next_char(u_char &c); | 33 bool next_char(u_char &c); |
44 void push_char(u_char c); | 34 void push_char(u_char c); |
45 | 35 |
46 public: | 36 public: |
47 TOKEN(char *fn, string_set *includes); | 37 TOKEN(const char *fn, string_set *includes); |
48 ~TOKEN(); | 38 ~TOKEN(); |
49 bool include(char *fn); | 39 bool include(const char *fn); |
50 char *next(); // return next token | 40 const char *next(); // return next token |
51 int nextint(); | 41 int nextint(); |
52 void skipeol(); // skip to eol | 42 void skipeol(); // skip to eol |
53 void push(char *token) {pending_tokens.push_front(token);}; | 43 void push(const char *token) {pending_tokens.push_front(token);}; |
54 const char *cur_fn() {return filenames.empty() ? "" : filenames.front();}; | 44 const char *cur_fn() {return filenames.empty() ? "" : filenames.front();}; |
55 int cur_line() {return linenumbers.empty() ? 0 : linenumbers.front();}; | 45 int cur_line() {return linenumbers.empty() ? 0 : linenumbers.front();}; |
56 void token_error(const char *err); | 46 void token_error(const char *err); |
57 void token_error(const char *fmt, int d, const char *s); | 47 void token_error(const char *fmt, int d, const char *s); |
58 void token_error(const char *fmt, const char *t, const char *h); | 48 void token_error(const char *fmt, const char *t, const char *h); |
59 void token_error(const char *want, const char *have); | 49 void token_error(const char *want, const char *have); |
60 void token_error(); | 50 void token_error(); |
61 }; | 51 }; |
62 | 52 |
63 #endif |