1 /*
2 * Author: William Chia-Wei Cheng (bill.cheng@acm.org)
3 *
4 * Copyright (C) 2001-2009, William Chia-Wei Cheng.
5 *
6 * This file may be distributed under the terms of the Q Public License
7 * as defined by Trolltech AS of Norway and appearing in the file
8 * LICENSE.QPL included in the packaging of this file.
9 *
10 * THIS FILE IS PROVIDED AS IS WITH NO WARRANTY OF ANY KIND, INCLUDING
11 * THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
12 * PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
13 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
14 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
16 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 * @(#)$Header: /mm2/home/cvs/bc-src/tgif/markup.c,v 1.6 2011/05/16 16:21:58 william Exp $
19 */
20
21 #define _INCLUDE_FROM_MARKUP_C_
22
23 #include "tgifdefs.h"
24
25 #include "file.e"
26 #include "http.e"
27 #include "markup.e"
28 #include "msg.e"
29 #include "setup.e"
30 #include "util.e"
31
32 int cmdLineParseHtml=FALSE;
33
34 static int parseHtml=FALSE;
35
36 /* ===================== Parse Routines ===================== */
37
38 static
DumpHtmlBuf(in_tag,psz_start)39 int DumpHtmlBuf(in_tag, psz_start)
40 int in_tag;
41 char *psz_start;
42 {
43 int last_ch_is_lf=FALSE;
44 char *psz=NULL;
45
46 if (in_tag) {
47 for (psz=psz_start; *psz != '\0'; psz++) {
48 switch (*psz) {
49 case '\r':
50 if (psz[1] == '\n') {
51 psz++;
52 }
53 printf("\n");
54 last_ch_is_lf = TRUE;
55 break;
56 case '\n':
57 printf("\n");
58 last_ch_is_lf = TRUE;
59 break;
60 default:
61 fputc(*psz, stdout);
62 last_ch_is_lf = FALSE;
63 break;
64 }
65 }
66 } else {
67 for (psz=psz_start; *psz != '\0'; psz++) {
68 switch (*psz) {
69 case '\r':
70 if (psz[1] == '\n') {
71 psz++;
72 }
73 printf("\n");
74 last_ch_is_lf = TRUE;
75 break;
76 case '\n':
77 printf("\n");
78 last_ch_is_lf = TRUE;
79 break;
80 default:
81 fputc(*psz, stdout);
82 last_ch_is_lf = FALSE;
83 break;
84 }
85 }
86 }
87 if (!last_ch_is_lf) {
88 printf("\n");
89 }
90 return TRUE;
91 }
92
93 static
DoParseMarkUpFile(buf)94 int DoParseMarkUpFile(buf)
95 char *buf;
96 {
97 int in_tag=FALSE; /* TRUE if inside a tag (and looking for '>') */
98 char *psz_start=buf;
99
100 in_tag = (*psz_start == '<');
101 while (psz_start != NULL && *psz_start != '\0') {
102 char *psz=NULL, saved_ch='\0';
103
104 if (in_tag) {
105 if ((psz=strchr(psz_start, '>')) == NULL) break;
106
107 saved_ch = (*(++psz));
108 *psz = '\0';
109 DumpHtmlBuf(in_tag, psz_start);
110 *psz = saved_ch;
111 in_tag = FALSE;
112 } else {
113 if ((psz=strchr(psz_start, '<')) == NULL) break;
114
115 *psz = '\0';
116 DumpHtmlBuf(in_tag, psz_start);
117 *psz = '<';
118 in_tag = TRUE;
119 }
120 psz_start = psz;
121 }
122 if (psz_start != NULL) {
123 DumpHtmlBuf(in_tag, psz_start);
124 }
125 printf("\n");
126 fflush(stdout);
127
128 return TRUE;
129 }
130
ParseMarkUpFile(buf,buf_sz,pn_html,psz_content_type)131 int ParseMarkUpFile(buf, buf_sz, pn_html, psz_content_type)
132 char *buf, *psz_content_type;
133 int buf_sz, *pn_html;
134 {
135 if (parseHtml) {
136 if (*pn_html || *buf == '>') {
137 if (!DoParseMarkUpFile(buf)) {
138 }
139 }
140 }
141 return TRUE;
142 }
143
144 /* ===================== Init & CleanUp Routines ===================== */
145
CleanUpHtml()146 void CleanUpHtml()
147 {
148 }
149
InitHtml()150 int InitHtml()
151 {
152 parseHtml = FALSE;
153 if (!PRTGIF || cmdLineOpenDisplay) {
154 char *c_ptr=FALSE;
155
156 if ((c_ptr=XGetDefault(mainDisplay, TOOL_NAME, "ParseHtml")) !=
157 NULL && UtilStrICmp(c_ptr, "true") == 0) {
158 parseHtml = TRUE;
159 }
160 }
161 if (PRTGIF && cmdLineParseHtml) {
162 parseHtml = TRUE;
163 }
164 return TRUE;
165 }
166
167