xref: /reactos/sdk/tools/hhpcomp/hhp_reader.h (revision 34593d93)
1 
2 // This file is part of hhpcomp, a free HTML Help Project (*.hhp) compiler.
3 // Copyright (C) 2015  Benedikt Freisen
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 
19 
20 #include <string>
21 #include <map>
22 #include <list>
23 #include <set>
24 
25 using namespace std;  // using 'using' here for convenience
26 
27 class hhp_reader;  // forward declaration
28 
29 class hhp_section
30 {
31 private:
32     string name;
33 
34 public:
35     virtual void process_line(string line) = 0;
36     string get_name();
37     void set_name(string name);
38 };
39 
40 class hhp_pair
41 {
42 private:
43     string key;
44     bool value_has_been_set;
45     string value;
46     bool has_default_value;
47     string default_value;
48 
49 public:
50     hhp_pair(string key, bool has_default_value = false, string default_value = "");
51     void set_value(string value);
52     string get_value();
53     string get_key();
54 };
55 
56 class hhp_key_value_section : public hhp_section
57 {
58 protected:
59     map<string, hhp_pair*> entries;
60 
61     void add_entry(hhp_pair* entry);
62 
63 public:
64     virtual void process_line(string line);
65 };
66 
67 class hhp_options_section : public hhp_key_value_section
68 {
69     friend class hhp_reader;
70 
71 private:
72     hhp_pair* binary_TOC;
73     hhp_pair* binary_index;
74     hhp_pair* compiled_file;
75     hhp_pair* contents_file;
76     hhp_pair* index_file;
77     hhp_pair* autoindex;
78     hhp_pair* defaultwindow;
79     hhp_pair* default_topic;
80     hhp_pair* defaultfont;
81     hhp_pair* language;
82     hhp_pair* title;
83     hhp_pair* createchifile;
84     hhp_pair* compatibility;
85     hhp_pair* errorlogfile;
86     hhp_pair* full_text_search;
87     hhp_pair* display_compile_progress;
88     hhp_pair* display_compile_note;
89     hhp_pair* flat;
90     hhp_pair* full_text_search_stop_list_file;
91 
92 public:
93     hhp_options_section();
94     ~hhp_options_section();
95 };
96 
97 class hhp_files_section : public hhp_section
98 {
99     friend class hhp_reader;
100 
101 private:
102     list<string> filenames;
103 
104 public:
105     hhp_files_section();
106     virtual void process_line(string line);
107 };
108 
109 class hhp_reader
110 {
111 private:
112     string filename;
113     map<string, hhp_section*> sections;
114     hhp_options_section* options;
115     hhp_files_section* files;
116     set<string> unique_file_pathes;
117 
118     void add_section(hhp_section* section);
119     void read();
120     void compute_unique_file_pathes_set();
121 
122 public:
123     hhp_reader(string filename);
124     ~hhp_reader();
125 
126     string get_title_string();
127     string get_contents_file_string();
128     string get_index_file_string();
129     string get_default_topic_string();
130     unsigned int get_language_code();
131     string get_compiled_file_string();
132 
133     set<string>::iterator get_file_pathes_iterator_begin();
134     set<string>::iterator get_file_pathes_iterator_end();
135 };
136 
137