1 | /* $Id: kHtmlPC.h,v 1.1 1999-09-05 02:53:06 bird Exp $ */
|
---|
2 | /*
|
---|
3 | * kHtmlPC - Special-purpose HTML/SQL preprocessor.
|
---|
4 | *
|
---|
5 | * Copyright (c) 1999 knut st. osmundsen
|
---|
6 | *
|
---|
7 | */
|
---|
8 | #ifndef _kHtmlPC_h_
|
---|
9 | #define _kHtmlPC_h_
|
---|
10 |
|
---|
11 | #define VER_MAJOR 0
|
---|
12 | #define VER_MINOR 1
|
---|
13 |
|
---|
14 | #pragma pack()
|
---|
15 |
|
---|
16 |
|
---|
17 | typedef struct _options
|
---|
18 | {
|
---|
19 | BOOL fDummy;
|
---|
20 | } OPTIONS, *POPTIONS;
|
---|
21 |
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * A base class for all LIFO entries.
|
---|
25 | * @author knut st. osmundsen
|
---|
26 | */
|
---|
27 | class kLIFOEntry
|
---|
28 | {
|
---|
29 | private:
|
---|
30 | kLIFOEntry *pNext; /* private next pointer */
|
---|
31 |
|
---|
32 | public:
|
---|
33 | kLIFOEntry() : pNext(NULL) { }
|
---|
34 | kLIFOEntry *getNext() const { return pNext; }
|
---|
35 | void setNext(kLIFOEntry *pEntry) { pNext = pEntry; }
|
---|
36 | virtual BOOL operator ==(const char *psz) const = 0;
|
---|
37 | };
|
---|
38 |
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Error class.
|
---|
42 | * @purpose Hold a enum for errorcodes and a function which convert errorcodes to text.
|
---|
43 | * @author knut st. osmundsen
|
---|
44 | */
|
---|
45 | class kError
|
---|
46 | {
|
---|
47 | private:
|
---|
48 | static const char *formatMessage(const char *pszMsg);
|
---|
49 |
|
---|
50 | public:
|
---|
51 | enum enmErrors
|
---|
52 | {
|
---|
53 | no_error = 0,
|
---|
54 | /* errors */
|
---|
55 | error_unexpected_end_of_string,
|
---|
56 | error_unexpected_eot,
|
---|
57 | error_invalid_tag_start_char,
|
---|
58 | error_invalid_tagname,
|
---|
59 | error_invalid_tag,
|
---|
60 | error_no_filename,
|
---|
61 | error_unexpected_eof,
|
---|
62 | error_unbalanced_quotes,
|
---|
63 | error_eot_not_found,
|
---|
64 | error_opening_file,
|
---|
65 | error_determing_file_size,
|
---|
66 | error_new_failed,
|
---|
67 | error_reading_file,
|
---|
68 | error_incorrect_number_of_parameters,
|
---|
69 | error_missing_sql,
|
---|
70 | error_invalid_sql_tag,
|
---|
71 | error_opening_output_file,
|
---|
72 | error_graph_to_small,
|
---|
73 | error_graph_type_must_be_specified_before_data,
|
---|
74 | error_data_param_is_missing_value,
|
---|
75 | error_type_param_is_missing_value,
|
---|
76 | error_invalid_type,
|
---|
77 | error_filename_param_is_missing_value,
|
---|
78 | error_width_cx_param_is_missing_value,
|
---|
79 | error_height_cy_param_is_missing_value,
|
---|
80 | error_graph_type_is_missing,
|
---|
81 | error_graph_subtype_is_invalid,
|
---|
82 | error_filename_is_missing,
|
---|
83 | error_no_data,
|
---|
84 | error_invalid_dimentions,
|
---|
85 | error_data_param_is_missing_sql_statement,
|
---|
86 | error_xstart_param_is_missing_value,
|
---|
87 | error_xend_param_is_missing_value,
|
---|
88 | error_ystart_param_is_missing_value,
|
---|
89 | error_yend_param_is_missing_value,
|
---|
90 | error_sql_failed,
|
---|
91 |
|
---|
92 | /* warnings */
|
---|
93 | warning_illegal_string_char = 0x8000,
|
---|
94 | warning_too_many_parameters,
|
---|
95 | warning_unexpected_end_of_string,
|
---|
96 | warning_unexpected_eot,
|
---|
97 | warning_failed_to_open_background_image,
|
---|
98 | warning_failed_to_load_background_image,
|
---|
99 | warning_invalid_sub_type,
|
---|
100 | warning_title_param_is_missing_value,
|
---|
101 | warning_titlex_param_is_missing_value,
|
---|
102 | warning_titley_param_is_missing_value,
|
---|
103 | warning_invalid_parameter,
|
---|
104 | warning_legend_is_not_implemented_yet,
|
---|
105 | warning_failed_to_convert_date,
|
---|
106 | warning_invalid_color_value,
|
---|
107 | warning_to_many_fields_in_data_sql,
|
---|
108 | warning_pie_not_implemented_yet,
|
---|
109 | warning_negative_values_are_not_supported_yet,
|
---|
110 | warning_background_param_is_missing_value,
|
---|
111 | warning_backgroundcolor_is_invalid,
|
---|
112 | warning_backgroundcolor_param_is_missing_value,
|
---|
113 | warning_foregroundcolor_is_invalid,
|
---|
114 | warning_foregroundcolor_param_is_missing_value,
|
---|
115 | warning_axiscolor_is_invalid,
|
---|
116 | warning_axiscolor_param_is_missing_value
|
---|
117 | };
|
---|
118 | static const char *queryDescription(kError::enmErrors enmErrorCd);
|
---|
119 | };
|
---|
120 |
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * Warning Entry, for use with a list template.
|
---|
124 | * @author knut st. osmundsen
|
---|
125 | */
|
---|
126 | class kWarningEntry : public kListEntry
|
---|
127 | {
|
---|
128 | private:
|
---|
129 | kError::enmErrors enmErrorCd;
|
---|
130 |
|
---|
131 | public:
|
---|
132 | kWarningEntry(kError::enmErrors enmErrorCd) : enmErrorCd(enmErrorCd) {};
|
---|
133 | kError::enmErrors getWarningCode(void) { return enmErrorCd; }
|
---|
134 |
|
---|
135 | /* these are here because I didn't have time to implement the kList class */
|
---|
136 | BOOL operator==(const kWarningEntry &entry) const { return FALSE || ! &entry; } /* "|| ..." due to unref param */
|
---|
137 | BOOL operator!=(const kWarningEntry &entry) const { return TRUE || &entry; }
|
---|
138 | BOOL operator< (const kWarningEntry &entry) const { return FALSE || ! &entry; }
|
---|
139 | BOOL operator<=(const kWarningEntry &entry) const { return FALSE || ! &entry; }
|
---|
140 | BOOL operator> (const kWarningEntry &entry) const { return TRUE || &entry; }
|
---|
141 | BOOL operator>=(const kWarningEntry &entry) const { return TRUE || &entry; }
|
---|
142 | };
|
---|
143 |
|
---|
144 |
|
---|
145 | #define TAG_BUFFER_SIZE 1024
|
---|
146 | #define TAG_MAX_PARAMETERS 32
|
---|
147 | /**
|
---|
148 | * Html Tag class.
|
---|
149 | * @purpose Analyse an HTML tag.
|
---|
150 | * @author knut st. osmundsen
|
---|
151 | */
|
---|
152 | class kTag
|
---|
153 | {
|
---|
154 | private:
|
---|
155 | /**@cat Misc data */
|
---|
156 | char szTag[TAG_BUFFER_SIZE];
|
---|
157 |
|
---|
158 | /**@cat Tag data - Tagname */
|
---|
159 | const char *pszTagname;
|
---|
160 |
|
---|
161 | /**@cat Tag data - Parameters */
|
---|
162 | const char *apszParameters[TAG_MAX_PARAMETERS];
|
---|
163 | const char *apszValues[TAG_MAX_PARAMETERS];
|
---|
164 | unsigned long cParameters;
|
---|
165 |
|
---|
166 | /**@cat Warning */
|
---|
167 | kError::enmErrors enmWarning;
|
---|
168 |
|
---|
169 | /**@cat Internal functions */
|
---|
170 | void analyseTag(const char *pszTag) throw(kError::enmErrors);
|
---|
171 | const char *copyTag(char *pszTo, const char *pszFrom) throw(kError::enmErrors);
|
---|
172 | const char *copyParameterName(char *pszTo, const char *pszFrom) throw(kError::enmErrors);
|
---|
173 | const char *copyParameterValue1(char *pszTo, const char *pszFrom) throw(kError::enmErrors);
|
---|
174 | const char *copyParameterValue2(char *pszTo, const char *pszFrom) throw(kError::enmErrors);
|
---|
175 |
|
---|
176 | public:
|
---|
177 | kTag(const char *pszTag) throw(kError::enmErrors);
|
---|
178 | ~kTag(void);
|
---|
179 |
|
---|
180 | /**@cat Gets/Queries */
|
---|
181 | unsigned long getParameterCount(void) const;
|
---|
182 | const char *getTagname(void) const;
|
---|
183 | const char *queryParameter(const char *pszParameter) const;
|
---|
184 | BOOL queryExists(const char *pszParameter) const;
|
---|
185 | const char *queryParameterName(unsigned long ulOrdinal) const;
|
---|
186 | const char *queryParameterValue(unsigned long ulOrdinal) const;
|
---|
187 | BOOL isTag(const char *pszTagname) const;
|
---|
188 |
|
---|
189 | /**@cat Warning */
|
---|
190 | const char *queryWarning(void);
|
---|
191 | };
|
---|
192 |
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * A HTML input file.
|
---|
196 | * @author knut st. osmundsen
|
---|
197 | */
|
---|
198 | class kFileEntry : public kLIFOEntry
|
---|
199 | {
|
---|
200 | private:
|
---|
201 | char szFilename[CCHMAXPATH];
|
---|
202 | char *pszFile;
|
---|
203 | unsigned long cbFile;
|
---|
204 | const kFileEntry *pParent; /* TODO */
|
---|
205 | const char *pszParent; /* TODO */
|
---|
206 |
|
---|
207 | protected:
|
---|
208 | void openAndReadFile(const char *pszFilename) throw (kError::enmErrors);
|
---|
209 |
|
---|
210 | public:
|
---|
211 | kFileEntry(const char *pszFilename) throw (kError::enmErrors);
|
---|
212 | kFileEntry(const kTag &tag, const char *pszParent, const kFileEntry *pParent) throw (kError::enmErrors);
|
---|
213 | virtual ~kFileEntry();
|
---|
214 |
|
---|
215 | long getLineNumber(void) const;
|
---|
216 | const char *getFilename(void) const { return &szFilename[0]; }
|
---|
217 | virtual BOOL operator ==(const char *psz) const { return stricmp(psz, szFilename) == 0; }
|
---|
218 | const char *queryParentPointer(void) const { return pszParent; }
|
---|
219 | const kFileEntry *queryParent(void) const { return pParent; }
|
---|
220 |
|
---|
221 | /** Current pointer */
|
---|
222 | const char *pszCurrent;
|
---|
223 | };
|
---|
224 |
|
---|
225 |
|
---|
226 | /**
|
---|
227 | * Variable Entry.
|
---|
228 | * @author knut st. osmundsen
|
---|
229 | */
|
---|
230 | class kVariableEntry : public kLIFOEntry
|
---|
231 | {
|
---|
232 | private:
|
---|
233 | char *pszName;
|
---|
234 | char *pszValue;
|
---|
235 |
|
---|
236 | public:
|
---|
237 | kVariableEntry(const char *pszName, const char *pszValue);
|
---|
238 | virtual ~kVariableEntry();
|
---|
239 |
|
---|
240 | const char *getValue(void) const { return pszValue; }
|
---|
241 | virtual BOOL operator ==(const char *psz) const { return stricmp(psz, pszName) == 0; }
|
---|
242 | };
|
---|
243 |
|
---|
244 |
|
---|
245 | /**
|
---|
246 | * Simple LIFO2 template class.
|
---|
247 | * Node class must implement:
|
---|
248 | * Node *getNext();
|
---|
249 | * void setNext(Node*);
|
---|
250 | * BOOL operator ==(const char *psz) const;
|
---|
251 | * find(const char *key);
|
---|
252 | * const VariableEntry *find(const char *pszKey) const;
|
---|
253 | * BOOL exists(const VariableEntry *pVariableEntry) const;
|
---|
254 | * @purpose LIFO for SqlEntry objects.
|
---|
255 | * @author knut st. osmundsen
|
---|
256 | */
|
---|
257 | template <class kEntry, class kEntryEntry>
|
---|
258 | class kLIFO2 : public kLIFO<kEntry>
|
---|
259 | {
|
---|
260 | public:
|
---|
261 | virtual const kEntryEntry *findSub(const char *pszKey) const;
|
---|
262 | virtual BOOL existsSub(const kEntryEntry *pEntryEntry) const;
|
---|
263 | };
|
---|
264 |
|
---|
265 |
|
---|
266 | /**
|
---|
267 | * A Sql statement with variables.
|
---|
268 | * @author knut st. osmundsen
|
---|
269 | */
|
---|
270 | class kSqlEntry : public kLIFOEntry
|
---|
271 | {
|
---|
272 | private:
|
---|
273 | kLIFO<kVariableEntry> lifoVariables;
|
---|
274 | char *pszSql; /* Pointer to sql expression. */
|
---|
275 | void *pres; /* MYSQL_RES pointer */
|
---|
276 | unsigned long cRows; /* Number of rows left in the result. */
|
---|
277 | const kFileEntry *pFileEntry; /* Pointer to file node which we are to backtrack to. */
|
---|
278 | const char *pszCurrent; /* Pointer to where in the FileEntry we are to backtrack to. */
|
---|
279 |
|
---|
280 | protected:
|
---|
281 | void dbExecuteQuery(void) throw (kError::enmErrors);
|
---|
282 | BOOL dbFetch(void);
|
---|
283 | void dbFreeResult(void);
|
---|
284 |
|
---|
285 | public:
|
---|
286 | kSqlEntry(); /* dummy */
|
---|
287 | kSqlEntry(const kTag &tag, const char *pszCurrent, const kFileEntry *pFileEntry) throw (kError::enmErrors);
|
---|
288 | virtual ~kSqlEntry();
|
---|
289 |
|
---|
290 | virtual BOOL operator ==(const char *psz) const;
|
---|
291 |
|
---|
292 | /** additional functions */
|
---|
293 | BOOL eof(void) const { return cRows == 0; } /** end of fetch */
|
---|
294 | BOOL fetch(void);
|
---|
295 | const kVariableEntry *find(const char *pszKey) const;
|
---|
296 | BOOL exists(const kVariableEntry *pVariableEntry) const;
|
---|
297 |
|
---|
298 | const kFileEntry *queryFileEntry(void) const { return pFileEntry; }
|
---|
299 | const char *queryBackTrackPos(void) const { return pszCurrent; }
|
---|
300 | static const char *querySqlLastError(void);
|
---|
301 | };
|
---|
302 |
|
---|
303 |
|
---|
304 | /**
|
---|
305 | * Graph Data. One coordinate.
|
---|
306 | * @author knut st. osmundsen
|
---|
307 | */
|
---|
308 | class kGraphData : public kListEntry
|
---|
309 | {
|
---|
310 | public:
|
---|
311 | double rdX;
|
---|
312 | double rdY;
|
---|
313 | char szXDate[11];
|
---|
314 |
|
---|
315 | BOOL operator==(const kGraphData &entry) const;
|
---|
316 | BOOL operator!=(const kGraphData &entry) const;
|
---|
317 | BOOL operator< (const kGraphData &entry) const;
|
---|
318 | BOOL operator<=(const kGraphData &entry) const;
|
---|
319 | BOOL operator> (const kGraphData &entry) const;
|
---|
320 | BOOL operator>=(const kGraphData &entry) const;
|
---|
321 | };
|
---|
322 |
|
---|
323 |
|
---|
324 | /**
|
---|
325 | * Graph Dataset. One set of data.
|
---|
326 | * @author knut st. osmundsen
|
---|
327 | */
|
---|
328 | class kGraphDataSet : public kListEntry
|
---|
329 | {
|
---|
330 | public:
|
---|
331 | kSortedList<kGraphData> listData; /* lines */
|
---|
332 | double rdCount; /* pie */
|
---|
333 | unsigned long ulColor;
|
---|
334 | int clrColor;
|
---|
335 | char * pszLegend;
|
---|
336 | BOOL fXDate;
|
---|
337 | kSortedList<kWarningEntry> *plistWarnings; /* this is really an unsorted list.*/
|
---|
338 |
|
---|
339 | void addWarning(kError::enmErrors enmErrorCd);
|
---|
340 |
|
---|
341 | public:
|
---|
342 | kGraphDataSet() throw(kError::enmErrors);
|
---|
343 | kGraphDataSet(const char *pszSql, int enmTypeCd,
|
---|
344 | kSortedList<kWarningEntry> *plistWarnings) throw(kError::enmErrors);
|
---|
345 | ~kGraphDataSet(void);
|
---|
346 | double maxX(void) const;
|
---|
347 | double minX(void) const;
|
---|
348 | double maxY(void) const;
|
---|
349 | double minY(void) const;
|
---|
350 |
|
---|
351 | /* since i didn't have time to implement an unsorted list, i use a unsorted sorted list.*/
|
---|
352 | BOOL operator==(const kGraphDataSet &entry) const { return FALSE || ! &entry; } /* "|| ..." due to unref param */
|
---|
353 | BOOL operator!=(const kGraphDataSet &entry) const { return TRUE || &entry; }
|
---|
354 | BOOL operator< (const kGraphDataSet &entry) const { return FALSE || ! &entry; }
|
---|
355 | BOOL operator<=(const kGraphDataSet &entry) const { return FALSE || ! &entry; }
|
---|
356 | BOOL operator> (const kGraphDataSet &entry) const { return TRUE || &entry; }
|
---|
357 | BOOL operator>=(const kGraphDataSet &entry) const { return TRUE || &entry; }
|
---|
358 |
|
---|
359 | BOOL operator==(const char *pszText) const
|
---|
360 | { return pszLegend != NULL && pszText != NULL && stricmp(pszLegend, pszText) == 0; }
|
---|
361 | BOOL operator!=(const char *pszText) const
|
---|
362 | { return pszLegend != NULL && pszText != NULL && stricmp(pszLegend, pszText) != 0; }
|
---|
363 | BOOL operator< (const char *pszText) const
|
---|
364 | { return pszLegend != NULL && pszText != NULL && stricmp(pszLegend, pszText) < 0; }
|
---|
365 | BOOL operator<=(const char *pszText) const
|
---|
366 | { return pszLegend != NULL && pszText != NULL && stricmp(pszLegend, pszText) <= 0; }
|
---|
367 | BOOL operator> (const char *pszText) const
|
---|
368 | { return pszLegend != NULL && pszText != NULL && stricmp(pszLegend, pszText) > 0; }
|
---|
369 | BOOL operator>=(const char *pszText) const
|
---|
370 | { return pszLegend != NULL && pszText != NULL && stricmp(pszLegend, pszText) >= 0; }
|
---|
371 |
|
---|
372 | void setColor(const char *pszColor);
|
---|
373 | void setColor(gdImagePtr pGraph);
|
---|
374 | void setLegend(const char *pszLegend);
|
---|
375 |
|
---|
376 | int getColor(void) const { return clrColor; }
|
---|
377 | const char *getLegend(void) const { return pszLegend; }
|
---|
378 | BOOL getXDate(void) const { return fXDate; }
|
---|
379 |
|
---|
380 | friend long _System dbDataSetCallBack(const char *pszValue, const char *pszFieldName, void *pvUser);
|
---|
381 | };
|
---|
382 |
|
---|
383 |
|
---|
384 | /**
|
---|
385 | * Graph.
|
---|
386 | * @author knut st. osmundsen
|
---|
387 | */
|
---|
388 | class kGraph
|
---|
389 | {
|
---|
390 | public:
|
---|
391 | enum enmType { unknown, lines, pie };
|
---|
392 | enum enmSubType { normal };
|
---|
393 |
|
---|
394 | private:
|
---|
395 | gdImagePtr pGraph;
|
---|
396 | kSortedList<kGraphDataSet> listDataSets; /* this should really be an FIFO not a sorted list. */
|
---|
397 | kSortedList<kWarningEntry> listWarnings; /* this is really an unsorted list.*/
|
---|
398 |
|
---|
399 | /**@cat tag data */
|
---|
400 | enmType enmTypeCd;
|
---|
401 | enmSubType enmSubTypeCd;
|
---|
402 | char *pszFilename;
|
---|
403 | char *pszTitle;
|
---|
404 | char *pszTitleX;
|
---|
405 | char *pszTitleY;
|
---|
406 | char *pszBackground;
|
---|
407 | BOOL fLegend;
|
---|
408 | long cX;
|
---|
409 | long cY;
|
---|
410 | double rdStartX, rdEndX; //scale x
|
---|
411 | double rdStartY, rdEndY; //scale y
|
---|
412 | BOOL fXDate;
|
---|
413 | unsigned long ulBGColor;
|
---|
414 | unsigned long ulFGColor;
|
---|
415 | unsigned long ulAxisColor;
|
---|
416 |
|
---|
417 | /**@cat internal data */
|
---|
418 | POINTL ptlOrigo;
|
---|
419 | POINTL ptlYEnd;
|
---|
420 | POINTL ptlXEnd;
|
---|
421 | double rdMaxX, rdMinX;
|
---|
422 | double rdMaxY, rdMinY;
|
---|
423 |
|
---|
424 | /**@cat colors */
|
---|
425 | int clrBackground;
|
---|
426 | int clrForeground;
|
---|
427 | int clrAxis;
|
---|
428 |
|
---|
429 | /**@cat internal function */
|
---|
430 | void analyseTag(const kTag &tag) throw(kError::enmErrors);
|
---|
431 | void fetchData(const char *pszSql) throw(kError::enmErrors);
|
---|
432 | kGraphDataSet *findOrCreateDataSet(const char *pszLegend) throw(kError::enmErrors);
|
---|
433 |
|
---|
434 | void createBaseGraph(void) throw(kError::enmErrors);
|
---|
435 | void drawLines(void) throw(kError::enmErrors);
|
---|
436 | void drawLine(const kGraphDataSet *pDataSet) throw(kError::enmErrors);
|
---|
437 | void drawLegend(void) throw(kError::enmErrors);
|
---|
438 |
|
---|
439 | void destroy(void);
|
---|
440 | void addWarning(kError::enmErrors enmErrorCd);
|
---|
441 |
|
---|
442 | double maxX(void);
|
---|
443 | double minX(void);
|
---|
444 | double maxY(void);
|
---|
445 | double minY(void);
|
---|
446 |
|
---|
447 | unsigned long readColor(const char *pszColor);
|
---|
448 | int setColor(unsigned long ulColor);
|
---|
449 | void setColors(void);
|
---|
450 |
|
---|
451 | public:
|
---|
452 | kGraph(const kTag &tag) throw(kError::enmErrors);
|
---|
453 | ~kGraph(void);
|
---|
454 |
|
---|
455 | kError::enmErrors save(void);
|
---|
456 | unsigned long showWarnings(FILE *phLog, const kFileEntry *pCurFile);
|
---|
457 |
|
---|
458 | /**@cat common functions */
|
---|
459 | static double dateToDbl(const char *pszDate);
|
---|
460 | static BOOL dblToDate(double rdDate, char *pszDate);
|
---|
461 | static BOOL isDate(const char *pszDate);
|
---|
462 |
|
---|
463 | friend long _System dbGraphCallBack(const char *pszValue, const char *pszFieldName, void *pvUser);
|
---|
464 | };
|
---|
465 | #endif /*_kHtmlPC_h_*/
|
---|