1: /******************************************************************************
2: ezht - Copyright (C) 2004 Tradcrafts
3: This file is part of the ezht.
4:
5: ezht is free software; you can redistribute it and/or modify
6: it under the terms of the GNU General Public License as published by the
7: Free Software Foundation; either version 2 of the License, or (at your
8: option) any later version.
9:
10: ezht is distributed in the hope that it will be useful, but
11: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13: more details.
14:
15: You should have received a copy of the GNU General Public License along with
16: this program; see the file COPYING. If not, write to the Free Software
17: Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18: ******************************************************************************/
19:
20:
21: #ifndef _READER_H_
22: #define _READER_H_
23:
24: #include <stdio.h>
25: #include <deque>
26: #include <string>
27: #include <vector>
28:
29: class Reader;
30: extern Reader reader;
31:
32: #define READOPT_INCLUDE_HTML 0x01
33: #define READOPT_INCLUDE_TEXT 0x02
34: #define READOPT_TEXTMODE 0x04
35: #define READOPT_INCLUDE_NUMBERED 0x08
36:
37: #define READER_INCLUDE_BEGIN "\xff\xffIncludeBegin\xff\xff"
38: #define READER_INCLUDE_END "\xff\xffIncludeEnd\xff\xff"
39:
40: class fileinfo_t
41: {
42: public:
43: int readopt;
44: int linenum;
45: std::string fnam;
46: std::string header;
47: std::string footer;
48:
49: bool need_head_signal;
50: bool need_foot_signal;
51:
52: std::deque<char> buf;
53: std::deque<char>::iterator buf_pnt;
54:
55: fileinfo_t(std::string _fname, int _readopt){
56: fnam = _fname;
57: readopt = _readopt;
58: linenum = 0;
59:
60: need_head_signal = need_foot_signal = false;
61: }
62:
63: fileinfo_t(const fileinfo_t& src){
64: fnam = src.fnam;
65: readopt = src.readopt;
66: linenum = src.linenum;
67:
68: need_head_signal = src.need_head_signal;
69: need_foot_signal = src.need_foot_signal;
70: }
71:
72: ~fileinfo_t(){
73: }
74:
75: };
76:
77: class Reader
78: {
79: enum{ MAX_LINE_LEN = 65536 };
80: std::deque<fileinfo_t> infoque;
81:
82: int sourcemode_columns;
83: int sourcemode_line_cnt;
84:
85: void set_sourcemode_columns();
86: std::string sourcemode_linenumber();
87:
88: int get();
89: void rewind();
90:
91: public:
92:
93: enum{ Err=-2, End=-1};
94:
95: Reader();
96:
97: ~Reader();
98:
99: void set_current_readopt(int opt);
100:
101: bool open(const char *fnam,int opt=0,const char *filter=NULL);
102: void set_current_header(const char *header);
103: void set_current_footer(const char *footer);
104: void set_textmode();
105:
106: int read_line(std::string &buf);
107:
108: const char* get_fnam();
109: int get_linenum();
110:
111: std::string number_info();
112: };
113:
114: const char * getline(bool accept_terminator=false);
115: int parse(const char *line,std::vector<std::string> &vec);
116:
117: void reader_tempfile_delete();
118:
119:
120: #endif
121: