1 /*
2 * Copyright (C) 1991,1992 NEC Corporation.
3 */
4 /*
5 modify from texout.c, by k-chinen@is.aist-nara.ac.jp, 1994
6
7 NOTE:
8 * This module is prototype of HTML ouputting.
9 * HTML can markup. but HTML cannot layout.
10 Therfore this module cannot handle CENTER, RIGHT and SPACE.
11 * HTML cannout handle table and picture directly.
12 Therfore this module cannot handle table and picture with
13 TeX and TROFF outoputting's approach.
14 Then I could not implement it.
15 */
16
17
18
19
20 #ifndef lint
21
22
23 #endif
24
25 #include <stdio.h>
26 #include "plain2.h"
27 #include "picture.h"
28 #include "table.h"
29 #include "macro.h"
30
31
32 struct macDefs htmlMacros[] = {
33 M_DOC_BEGIN, "<HTML>\n",
34 M_DOC_END, "</HTML>\n",
35 M_PLAIN_BEGIN, "<P>\n",
36 M_PLAIN_END, "</P>\n",
37 M_EXAM_BEGIN, "<PRE><TT>\n",
38 M_EXAM_END, "</TT></PRE>\n",
39 M_APDX_BEGIN, "<!-- appendix -->\n",
40 M_APPENDIX, "<!-- appendix section -->\n",
41 M_BLANK, "\n",
42 M_PAGE, "\n<!-- PAGE -->\n",
43 M_NEWLINE, "\n<!-- NEWLINE -->\n",
44 M_CENTER_BEGIN, "<!-- CENTER -->\n",
45 M_CENTER_END, "<!-- end of CENTER -->\n",
46 M_RIGHT_BEGIN, "<!-- RIGHT -->\n",
47 M_RIGHT_END, "<!-- end of RIGHT -->\n",
48 M_INDENT, "<BLOCKQUOTE>\n",
49 M_INDENT0, "</BLOCKQUOTE>\n",
50 M_FOOTN_BEGIN, "",
51 M_FOOTN_END, "",
52 M_REFER_BEGIN, "<A HREF=\"#",
53 M_REFER_END, "\">GO</A>",
54 M_BOLD_BEGIN, "<B>",
55 M_BOLD_END, "</B>",
56 M_INDEX_BEGIN, "",
57 M_INDEX_END, "",
58 M_SECTION_1, "\n<H1>@1</H1>\n",
59 M_SECTION_2, "\n<H2>@1</H2>\n",
60 M_SECTION_3, "\n<H3>@1</H3>\n",
61 M_SECTION_4, "\n<H4>@1</H4>\n",
62 M_SECTION_5, "\n<H5>@1</H5>\n",
63 M_SECTION, "",
64 M_SETSEC_1, "",
65 M_SETSEC_2, "",
66 M_SETSEC_3, "",
67 M_SETSEC_4, "",
68 M_SETSEC_5, "",
69 M_TITLE, "<TITLE>&1</TITLE>\n<H1>&1</H1>\n<EM>&6</EM>\n<PRE>&4\n&3</PRE>\n<HR>",
70 -1, "",
71 };
72
73
74 /*
75 * HTML text output routines
76 */
77
78 struct transTable *htmlTrans;
79 struct transTable *htmlTransM;
80
81 static struct transTable htmlFullTrans[] = {
82 {'<', "<" },
83 {'>', ">" },
84 {'&', "&" },
85 {0,0} };
86 static struct transTable htmlFullTransM[] = {
87 {'<', "<" },
88 {'>', ">" },
89 {'&', "&" },
90 {0,0} };
91
92 static struct transTable htmlHalfTrans[] = {
93 {'<', "<" },
94 {'>', ">" },
95 {'&', "&" },
96 {0,0} };
97
98 static struct transTable htmlHalfTransM[] = {
99 {'<', "<" },
100 {'>', ">" },
101 {'&', "&" },
102 {0,0} };
103
htmlSetTrans(full)104 htmlSetTrans(full)
105 int full;
106 {
107 if (full) {
108 htmlTrans = htmlFullTrans;
109 htmlTransM = htmlFullTransM;
110 }
111 else {
112 htmlTrans = htmlHalfTrans;
113 htmlTransM = htmlHalfTransM;
114 }
115 }
116
117
118 char *
htmlTextQuote(str,quotable)119 htmlTextQuote(str, quotable)
120 char *str;
121 int quotable;
122 {
123 char *s;
124 int len;
125 static char buf[MAX_LINE_LEN];
126
127 if (rawOutput)
128 return str;
129
130 if (!quotable)
131 return textQuote(str, htmlTransM);
132
133 return textQuote(str, htmlTrans);
134 }
135
htmlQuote1(str)136 char *htmlQuote1(str)
137 char *str;
138 {
139 return htmlTextQuote(str, 1);
140 }
141
htmlQuote2(str)142 char *htmlQuote2(str)
143 char *str;
144 {
145 return htmlTextQuote(str, 0);
146 }
147
148
htmlPutLabel(str)149 htmlPutLabel(str)
150 char *str;
151 {
152 printf("<A NAME=\"%s\"> <EM>(here)</EM> </A>", codeCvt(str));
153 }
154
htmlPlain(str,attr,newline)155 htmlPlain(str, attr, newline)
156 char *str;
157 int attr;
158 int newline;
159 {
160 if (attr == IL_RAW || attr == IL_REFERENCE)
161 printf("%s", codeCvt(str));
162 else
163 printf("%s", codeCvt(htmlTextQuote(str, 1)));
164 if (newline)
165 printf("\n");
166 }
167
htmlExample(str)168 htmlExample(str)
169 char *str;
170 {
171 printf("%s\n",textQuote(str, htmlTrans));
172 }
173
174 static int enumLevel = 0;
htmlListBlock(begin,level,ltype,hint)175 htmlListBlock(begin, level, ltype, hint)
176 int begin;
177 int level;
178 int ltype;
179 char hint;
180 {
181 char *lstr;
182 if (begin) {
183 switch (ltype) {
184 case L_BULLET:
185 case L_DASH:
186 printf("<UL>\n");
187 break;
188 case L_DLIST:
189 printf("<DL>\n");
190 break;
191 case L_LROMAN:
192 case L_SROMAN:
193 case L_NUMBER:
194 case L_LALPHA:
195 case L_SALPHA:
196 enumLevel++;
197 printf("<OL>\n");
198 break;
199 default:
200 break;
201 }
202 }
203 else {
204 switch (ltype) {
205 case L_BULLET:
206 case L_DASH:
207 printf("</UL>\n");
208 break;
209 case L_LROMAN:
210 case L_SROMAN:
211 case L_NUMBER:
212 case L_LALPHA:
213 case L_SALPHA:
214 enumLevel--;
215 printf("</OL>\n");
216 break;
217 case L_DLIST:
218 printf("</DL>\n");
219 break;
220 default:
221 break;
222 }
223 }
224 }
225
htmlDlistItem(level,dscr,cont)226 htmlDlistItem(level, dscr, cont)
227 int level;
228 char *dscr;
229 int cont;
230 {
231 printf("<DT><B>%s</B>\n", codeCvt(htmlTextQuote(dscr, 1)));
232 }
233
htmlListItem(level)234 htmlListItem(level)
235 int level;
236 {
237 printf("<LI> ");
238 }
239
htmlRawText(str)240 htmlRawText(str)
241 char *str;
242 {
243 printf("%s\n",codeCvt(str));
244 }
245
htmlSpace(length)246 htmlSpace(length)
247 int length;
248 {
249 /* EMPTY --- I don't know what do here */
250 }
251
htmlFTitle(ft,str,capsule)252 htmlFTitle(ft, str, capsule)
253 int ft;
254 char *str; /* if (str!=NULL) output title */
255 int capsule;
256 {
257 static int figNumber = 1;
258 static int tblNumber = 1;
259 if (crossRefer && capsule) {
260 printf("<B>%s</B>\n", codeCvt(htmlTextQuote(str, 1)));
261 htmlPutLabel(str);
262 }
263 else {
264 printf ("<P>");
265 #ifdef KANJI
266 if (japaneseText) {
267 if (ft == FT_FIGURE)
268 printf ("<B> %s %d.</B>", codeCvt("$B?^(B"), figNumber++);
269
270 else if (ft == FT_TABLE)
271 printf ("<B> %s %d.</B>", codeCvt("$BI=(B"), tblNumber++);
272 }
273 else {
274 #endif
275 if (ft == FT_FIGURE)
276 printf ("<B> Figure %d.</B>", figNumber++);
277 else if (ft == FT_TABLE)
278 printf ("<B> Table %d.</B>", tblNumber++);
279 #ifdef KANJI
280 }
281 #endif
282 printf ("%s\n", codeCvt(htmlTextQuote(str, 1)));
283 }
284 }
285
286 #ifdef PICTURE
287 /*
288 * Driver for HTML(picture) output
289 */
290 static int picLines; /* Number of lines in the block */
291 static int picMinInd; /* Indentation of the region */
292
293 static int htmlVsize;
294 static int htmlUnit;
295
htmlPictureBlock(begin,lines,indent,maxLen)296 htmlPictureBlock(begin, lines, indent, maxLen)
297 int begin;
298 int lines;
299 int indent;
300 int maxLen;
301 {
302 if(htmlOnce) {
303 if(begin)
304 printf("<!-- PICTURE -->\n");
305 }
306 else {
307 if(begin)
308 printf("<!-- PICTURE -->\n");
309 }
310 }
311
312 /* set line width */
htmlLineWidth(style)313 htmlLineWidth(style)
314 int style;
315 {
316 /* */
317 }
318
htmlEllipse(x0,y0,x1,y1,style)319 htmlEllipse(x0, y0, x1, y1, style)
320 int x0, x1, y0, y1;
321 int style;
322 {
323 /* */
324 }
325
326 /*
327 * Draw line
328 * Only ({-1,0,1},{-1,0,1}) direction.
329 */
htmlPicLine(x0,y0,x1,y1,style,vector)330 htmlPicLine(x0, y0, x1, y1, style, vector)
331 int x0, x1, y0, y1;
332 int style;
333 int vector;
334 {
335 /* */
336 }
337
htmlPicArc(x,y,r,dir,style)338 htmlPicArc(x, y, r, dir, style)
339 int x, y, r;
340 enum direction dir;
341 int style;
342 {
343 /* */
344 }
345
htmlPicText(s,xpos,vpos,factor)346 htmlPicText(s, xpos, vpos, factor)
347 char *s;
348 int xpos;
349 int vpos;
350 int factor;
351 {
352 /* */
353 }
354 #endif
355
356
357
htmlTitle(style,haifu,title,shozoku,number,date,name,renraku,special8,special9)358 htmlTitle(style, haifu, title, shozoku, number, date, name, renraku
359 #ifdef TITLE_SPECIAL
360 ,special8, special9
361 #endif
362 )
363 int style;
364 char **haifu;
365 char **title;
366 char **shozoku;
367 char **number;
368 char **date;
369 char **name;
370 char **renraku;
371 #ifdef TITLE_SPECIAL
372 char **special8, **special9;
373 #endif
374 {
375 char **s;
376 if (style == 0) {
377 putMacro(M_TITLE,
378 title, number, date, shozoku, haifu, name, renraku
379 #ifdef TITLE_SPECIAL
380 ,special8, special9
381 #endif
382 );
383 return;
384 }
385 }
386
htmlTable(begin,end,tblp)387 htmlTable(begin, end, tblp)
388 int begin;
389 int end;
390 struct table *tblp;
391 {
392 if(htmlOnce) {
393 if(rawOutput) {
394 int l;
395
396 printf("<PRE>\n");
397 for (l = begin; l < end; l++) {
398 htmlRawText(texts[l]->body);
399 }
400 printf("</PRE>\n");
401 }
402 else {
403 printf("<!-- TABLE -->\n");
404 }
405
406 }
407 else {
408 static int tbl_count=0;
409 printf("\n<!-- plain2:TABLE %05d %d %d -->\n",tbl_count,begin,end);
410
411 if(htmlHere) {
412 printf("<P><IMG SRC=\"TBL%05d.gif\">\n", tbl_count);
413 }
414 else {
415 printf("<P><B><A HREF=\"TBL%05d.gif\">Table here</A></B></P>\n",
416 tbl_count);
417 }
418 tbl_count++;
419 }
420 }
421
htmlCapsule(begin,type,center)422 htmlCapsule(begin, type, center)
423 int begin;
424 int type;
425 int center;
426 {
427 static int count=0;
428 char *typeStr;
429
430 if (crossRefer) {
431 switch (type) {
432 case FT_FIGURE:
433 typeStr = "figure";
434 break;
435 case FT_TABLE:
436 typeStr = "table";
437 break;
438 default:
439 fprintf(stderr, "PANIC(unknown capsule type)\n");
440 exit(2);
441 break;
442 }
443 if (begin) {
444 count++;
445 printf("\n<!-- Start of #%d -->\n",count);
446 }
447 else {
448 printf("\n<!-- End of #%d -->\n",count);
449 }
450 }
451 else /* short paper */ {
452 if (begin) {
453 printf("\n<!-- Start of #%d -->\n",count);
454 }
455 else {
456 printf("\n<!-- End of #%d -->\n",count);
457 }
458 }
459 }
460
htmlComment(begin,end)461 htmlComment(begin, end)
462 int begin;
463 int end;
464 {
465 int l;
466 for (l = begin; l < end; l++) {
467 printf ("<!-- %s -->\n", codeCvt(texts[l]->body));
468 }
469 }
470