-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathman2html.c
1055 lines (960 loc) · 17.1 KB
/
man2html.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
char inbuf[BUFSIZ];
typedef struct myfp {
struct myfp *prev;
FILE *fp;
} myfp;
typedef int macro_f(char *txt);
typedef struct bv {
int len;
char *val;
} bv;
myfp *Fin;
bv infile;
typedef enum fonts { Roman, Italic, Bold, Fixed, Small } fontt;
typedef struct macro_s {
bv name;
macro_f *func;
} macro_t;
#define BVC(x) { sizeof(x)-1, x }
macro_f title, section, bold, boldital, boldrom, ital, italbold, italrom;
macro_f rombold, romital, smbold, small;
macro_f deftab, hangpar, inpar, newpar, pardist, undent, indent, subsec;
macro_f tagpar, comment, eol, ftfont, indent2;
macro_f fixw, boldfixw, fixwbold, fixwital, fixwrom, italfixw, romfixw;
macro_f nofmt, dofmt, errpunct, noop, table, source;
#define IS_DL 1
#define IS_UL 2
#define IS_IL 3
#define IS_NL 4
#define IS_NF 5
int indents[16];
int curind;
int wrap_nl;
char mysec;
#define SIND "ul"
macro_t macs[] = {
{ BVC("TH"), title },
{ BVC("SH"), section },
{ BVC("SS"), subsec },
{ BVC("SM"), small },
{ BVC("SB"), smbold },
{ BVC("BC"), boldfixw },
{ BVC("BI"), boldital },
{ BVC("BR"), boldrom },
{ BVC("B"), bold },
{ BVC("CB"), fixwbold },
{ BVC("CI"), fixwital },
{ BVC("CR"), fixwrom },
{ BVC("CD"), fixwrom },
{ BVC("CT"), italrom },
{ BVC("C"), fixw },
{ BVC("IB"), italbold },
{ BVC("IC"), italfixw },
{ BVC("IP"), inpar },
{ BVC("IR"), italrom },
{ BVC("IX"), noop },
{ BVC("I"), ital },
{ BVC("RB"), rombold },
{ BVC("RC"), romfixw },
{ BVC("RI"), romital },
{ BVC("DT"), deftab },
{ BVC("HP"), hangpar },
{ BVC("LP"), newpar },
{ BVC("PD"), pardist },
{ BVC("PP"), newpar },
{ BVC("P"), newpar },
{ BVC("RE"), undent },
{ BVC("RS"), indent },
{ BVC("TP"), tagpar },
{ BVC("EM"), italrom },
{ BVC("ER"), errpunct },
{ BVC("EV"), fixwrom },
{ BVC("GT"), boldrom },
{ BVC("KC"), boldrom },
{ BVC("RV"), fixwrom },
{ BVC("SC"), fixwrom },
{ BVC("br"), eol },
{ BVC("sp"), eol },
{ BVC("in"), indent2 },
{ BVC("nf"), nofmt },
{ BVC("fi"), dofmt },
{ BVC("ft"), ftfont },
{ BVC("TA"), noop },
{ BVC("TS"), table },
{ BVC("so"), source },
{ BVC("ds"), noop },
{ BVC("hy"), noop }, /* hyphenation */
{ BVC("\\\""), comment },
{ BVC("lf"), comment }, /* set input line number to N and filename to file */
{ {0,NULL}, NULL }
};
fontt fstk[2];
macro_f arg, fontx, str, chr, num, over, fsize, nobreak;
macro_t escs[] = {
/* { BVC("$"), arg }, */
{ BVC("c"), nobreak },
{ BVC("f"), fontx },
{ BVC("*"), str },
{ BVC("("), chr },
{ BVC("n"), num },
{ BVC("o"), over },
{ BVC("s"), fsize },
{ {0,NULL}, NULL }
};
typedef struct spchar {
int c;
char *txt;
} spchar;
typedef struct trchar {
char *chr;
char *txt;
} trchar;
spchar spccs[] = {
{'\\', "\\"},
{'e', "\\"},
{'\'', "´"},
{'`', "`"},
{'-', "−"},
{'.', "."},
{' ', " "},
{'0', " "}, /* digit space */
{'|', " "}, /* 1/6 em space, was   */
{'^', ""},
{'&', ""}, /* zero-width space */
{'%', "ߚ"}, /* hyphen */
{'t', "	"}, /* tab */
{0, NULL}
};
trchar trccs[] = {
{ "em", "—" },
{ "hy", "-" },
{ "bu", "•" },
{ "sq", "a0;" }, /* black square */
{ "ru", "_" },
{ "14", "¼"},
{ "12", "½"},
{ "34", "¾"},
{ "de", "°" },
{ "dg", "†" },
{ "fm", "′" },
{ "ct", "¢" },
{ "rg", "®" },
{ "co", "©"},
{ "ff", "&#fb00;" },
{ "fi", "&#fb01;" },
{ "fl", "&#fb02;" },
{ "Fi", "&#fb03;" },
{ "pl", "+" },
{ "mi", "−" },
{ "eq", "=" },
{ "**", "*" },
{ "sc", "§" },
{ "aa", "´" },
{ "ga", "`" },
{ "ul", "_" },
{ "sl", "slash" },
{ "*a", "α" },
{ "*b", "β" },
{ "*g", "γ" },
{ "*d", "δ" },
{ "*e", "&epsilon" },
{ "*z", "ζ" },
{ "*y", "η" },
{ "*h", "θ" },
{ "*i", "ι" },
{ "*k", "κ" },
{ "*l", "λ" },
{ "*m", "μ" },
{ "*n", "ν" },
{ "*c", "ξ" },
{ "*o", "ο" },
{ "*p", "π" },
{ "*r", "ρ" },
{ "*s", "σ" },
{ "ts", "ς" },
{ "*t", "τ" },
{ "*u", "υ" },
{ "*f", "φ" },
{ "*x", "χ" },
{ "*q", "ψ" },
{ "*w", "ω" },
{ "*A", "Α" },
{ "*B", "Β" },
{ "*G", "Γ" },
{ "*D", "Δ" },
{ "*E", "Ε" },
{ "*Z", "Ζ" },
{ "*Y", "Η" },
{ "*H", "Θ" },
{ "*I", "Ι" },
{ "*K", "Κ" },
{ "*L", "Λ" },
{ "*M", "Μ" },
{ "*N", "Ν" },
{ "*C", "Ξ" },
{ "*O", "Ο" },
{ "*P", "Π" },
{ "*R", "Ρ" },
{ "*S", "Σ" },
{ "*T", "Τ" },
{ "*U", "Υ" },
{ "*F", "Φ" },
{ "*X", "Χ" },
{ "*Q", "Ψ" },
{ "*O", "Ω" },
{ "sr", "√" },
{ "rn", "‾" },
{ ">=", "≥" },
{ "<=", "≤" },
{ "==", "≡" },
{ "~=", "≅" },
{ "ap", "∼" },
{ "!=", "≠" },
{ "->", "→" },
{ "<-", "←" },
{ "ua", "↑" },
{ "da", "↓" },
{ "mu", "×" },
{ "di", "÷" },
{ "+-", "±" },
{ "cu", "∪" },
{ "ca", "∩" },
{ "sb", "⊂" },
{ "sp", "⊃" },
{ "ib", "⊆" },
{ "ip", "⊇" },
{ "if", "∞" },
{ "pd", "∂" },
{ "gr", "∇" },
{ "no", "¬" },
{ "is", "∫" },
{ "pt", "∝" },
{ "es", "∅" },
{ "mo", "∈" },
{ "br", "|" },
{ "dd", "‡" },
{ "rh", "»" }, /* hand */
{ "lh", "«" },
{ "bs", "Bell" },
{ "or", "∨" },
{ "ci", "O" }, /* circle */
{ "lt", "(" }, /* big curly brackets */
{ "lb", "(" },
{ "rt", ")" },
{ "rb", ")" },
{ "lk", "{" },
{ "rk", "}" },
{ "bv", "|" },
{ "lf", "⌊" },
{ "rf", "⌋" },
{ "lc", "⌈" },
{ "rc", "⌉" },
{ NULL, NULL }
};
/* Standard says up to 6 */
bv words[20];
char *fget2(char *s, int size, myfp *in)
{
char *p;
int c = EOF;
int isquote = 0;
if (!in || !in->fp)
return NULL;
for (p=s; p<s+size-1;)
{
c = getc(in->fp);
if (isquote) {
isquote = 0;
} else if (c == '\\') {
isquote = 1;
}
if (c == EOF || c == '\n')
{
if ( c == '\n' && isquote )
{
p--;
continue;
}
*p = '\0';
if (c == EOF) {
myfp *tmp = in->prev;
fclose(in->fp);
if (tmp) {
in->prev = tmp->prev;
in->fp = tmp->fp;
free(tmp);
continue;
} else {
in->fp = NULL;
}
}
break;
}
*p++ = c;
}
return (p > s || c == '\n') ? p : NULL;
}
int fsize(char *in)
{
int s;
int pl = 0;
if (in[1] == '-')
{
s = in[2];
pl = -1;
} else if (in[1] == '+')
{
s = in[2];
pl = 1;
} else
s = in[1];
if (s == '0')
printf("</font>");
else
printf("<font size=%c%c>", pl > 0 ? '+' : '-', s);
return pl ? 3 : 2;
}
int str(char *in)
{
}
int noop(char *in)
{
return 0;
}
int chr(char *in)
{
trchar *t;
in++;
for (t=trccs; t->chr; t++)
{
if (!strncmp(t->chr, in, 2))
{
printf("%s", t->txt);
break;
}
}
return 3;
}
int num(char *in)
{
}
int over(char *in)
{
}
#define NUM_FNAMS 5
char *fnams[] = { NULL, "i", "b", "tt", "small" };
int fontset(fontt f)
{
if (fstk[0])
{
printf("</%s>", fnams[fstk[0]]);
}
fstk[1] = fstk[0];
fstk[0] = f;
if (f)
{
printf("<%s>", fnams[fstk[0]]);
}
return 0;
}
int fontx(char *in)
{
fontt f;
in++;
if (*in == 'P')
{
f = fstk[1];
} else
{
if (*in == 'I' || *in == '2')
{
f = Italic;
} else if (*in == 'B' || *in == '3')
{
f = Bold;
} else if (*in == 'S' || *in == '4')
{
f = Fixed;
} else
{
f = Roman;
}
}
fontset(f);
return 2;
}
int unfont()
{
if (fstk[0])
{
printf("</%s>", fnams[fstk[0]]);
}
fstk[0] = 0;
}
void output(bv *txt)
{
char *ptr;
macro_t *e;
for (ptr = txt->val; ptr < txt->val+txt->len;ptr++)
{
if (!*ptr)
break;
if (*ptr == '\\')
{
spchar *c;
for (e=escs; e->name.len; e++)
{
if (!strncmp(ptr+1, e->name.val, e->name.len))
{
ptr += e->func(ptr+1);
break;
}
}
if (e->name.len)
continue;
for (c=spccs; c->c; c++)
{
if (ptr[1] == c->c)
{
printf("%s", c->txt);
ptr++;
break;
}
}
if (c->c)
continue;
} else if (*ptr == '<')
{
printf("<");
continue;
} else if (*ptr == '>')
{
printf(">");
continue;
} else if (!strncmp(ptr, "http://", 7))
{
char *p2 = ptr + 7;
int len;
while (isalpha(*p2) || isdigit(*p2) || *p2 == '.' || *p2 == '/' ||
*p2 == '_' || *p2 == '?' || *p2 == '=' )
p2++;
len = p2 - ptr;
printf("<a href=\"%.*s\">%.*s</a>",len,ptr,len,ptr);
ptr = p2;
}
putchar(*ptr);
}
}
void undent1() {
if (indents[curind] == IS_DL)
{
printf("</dl>\n");
curind--;
} else if (indents[curind] == IS_UL)
{
printf("</ul>\n");
curind--;
}
}
void unnest() {
for (;curind >0; curind--)
undent1();
curind = 0;
}
void oneline(bv *txt)
{
macro_t *m;
if (inbuf[0] == '.')
{
int nl = 0;
/* macro */
for (m=macs; m->name.len; m++)
{
if (!strncmp(inbuf+1, m->name.val, m->name.len))
{
/* If ret == 1, new line has already been read */
if ((nl=m->func(inbuf+m->name.len+1)) > 0)
m = macs-1;
else
break;
}
}
if (!m->name.len)
fputs(inbuf, stdout);
if (nl == 2) putchar('\n');
} else {
txt->len = txt->val - inbuf;
txt->val = inbuf;
if (txt->len)
{
output(txt);
} else
{
/* unnest(); */
if (indents[curind] != IS_NF)
printf("<p>"); /* SIND? */
}
putchar('\n');
}
}
#define CMD "/usr/bin/gunzip < %s"
int main(int argc, char *argv[])
{
char *evpath;
bv txt = {0, inbuf};
evpath = getenv("PATH_TRANSLATED");
Fin = malloc(sizeof(*Fin));
Fin->prev = NULL;
if (argc>1)
infile.val = argv[1];
else
infile.val = evpath;
if (infile.val)
{
char *dot;
infile.len = strlen(infile.val);
for (dot = infile.val+infile.len-1; dot>=infile.val;dot--)
if ( *dot == '.' ) break;
if (!strcmp(dot, ".gz"))
{
char *buf = malloc(infile.len+sizeof(CMD));
sprintf(buf, CMD, infile.val);
Fin->fp = popen(buf, "r");
mysec = dot[-1];
}
else
{
mysec = dot[1];
Fin->fp = fopen(infile.val, "r");
}
} else
{
Fin->fp = stdin;
mysec = '0';
}
if (evpath)
printf("Content-Type: text/html\n\n");
printf("<HTML>\n<HEAD>\n");
while(txt.val = fget2(inbuf, sizeof(inbuf), Fin))
oneline(&txt);
printf("</" SIND "></tbody></table></html>\n");
}
int parsewords(char *line)
{
char *ptr;
int esc = 0;
int wc = 0;
int quote = 0;
for (ptr=line; *ptr; ptr++)
{
for(;isspace(*ptr);ptr++);
if (!*ptr)
return wc;
words[wc].val = ptr;
for(;*ptr;ptr++)
{
if (esc)
{
esc = 0;
continue;
}
if (*ptr == '\\')
{
esc = 1;
continue;
}
if (*ptr == '"')
{
if (quote ^= 1)
{
if (words[wc].val == ptr)
words[wc].val++;
} else
{
if (!ptr[1] || isspace(ptr[1]))
{
words[wc].len = ptr - words[wc].val;
wc++;
break;
}
};
continue;
}
if (isspace(*ptr) && !quote)
{
words[wc].len = ptr - words[wc].val;
wc++;
break;
}
}
if (!*ptr)
{
words[wc].len = ptr - words[wc].val;
if (words[wc].len)
wc++;
break;
}
}
return wc;
}
int title(char *in) {
int wc = parsewords(in);
printf("<title>");
output(&words[0]);
printf("(");
output(&words[1]);
printf("): ");
output(&words[4]);
printf("</title></head>\n");
printf("<table>\n<thead>\n");
printf("<tr><td>");
output(&words[0]);
printf("(");
output(&words[1]);
printf(")<td align=\"center\">");
output(&words[4]);
printf("<td align=\"right\">");
output(&words[0]);
printf("(");
output(&words[1]);
printf(")\n</thead>\n");
printf("<tfoot>\n");
printf("<tr><td>");
output(&words[3]);
printf("<td align=\"center\">");
output(&words[2]);
printf("<td align=\"right\">");
output(&words[0]);
printf("(");
output(&words[1]);
printf(")\n</tfoot>\n<tbody><tr><td colspan=\"3\"><br><br><" SIND ">\n");
return 0;
}
int wraptext(char *in, char *beg, char *end)
{
int wc = parsewords(in);
fputs(beg, stdout);
wrap_nl = 1;
if (wc)
{
int i;
for (i=0; i<wc; i++)
{
if (i)
{
putchar(' ');
}
output(&words[i]);
}
} else
{
bv txt;
int c;
c = getc(Fin->fp);
ungetc(c, Fin->fp);
if ( c != '.' ) {
txt.val = fget2(inbuf, sizeof(inbuf), Fin);
txt.len = txt.val - inbuf;
txt.val = inbuf;
output(&txt);
}
}
printf("%s", end);
if (wrap_nl)
putchar('\n');
return 0;
}
int nobreak(char *in)
{
*in = '\0';
wrap_nl = 0;
return 0;
}
int fontpair(char *in, fontt a, fontt b)
{
int i, wc = parsewords(in);
int isref = 0;
if (wc == 2 && words[1].val[0] == '(' &&
words[1].val[2] == ')') {
char *c;
isref = 1;
printf("<a href=\"");
if (words[1].val[1] != mysec)
printf("../man%c/", words[1].val[1]);
for (c=words[0].val; c<words[0].val+words[0].len; c++)
if (*c != '\\') putchar(*c);
printf(".%c\">", words[1].val[1]);
}
for (i=0; i<wc; i++)
{
fontset((i & 1) ? b : a);
output(&words[i]);
unfont();
if (isref && !i)
printf("</a>");
}
putchar('\n');
return 0;
}
int errpunct(char *in)
{
int i, wc = parsewords(in);
char *f;
for (i=0; i<wc; i++)
{
if (!(i&1))
{
putchar('[');
}
output(&words[i]);
if (!(i&1))
{
putchar(']');
}
}
putchar('\n');
}
int section(char *in) {
unnest();
unfont();
return wraptext(in, "</" SIND ">\n\n<h3>", "</h3><" SIND ">");
}
int subsec(char *in) {
unnest();
unfont();
return wraptext(in, "</" SIND ">\n\n<h4>", "</h4><" SIND ">");
}
int bold(char *in) {
unfont();
return wraptext(in, "<b>", "</b>");
}
int boldfixw(char *in) {
return fontpair(in, Bold, Fixed);
}
int boldital(char *in) {
return fontpair(in, Bold, Italic);
}
int boldrom(char *in) {
return fontpair(in, Bold, Roman);
}
int fixw(char *in) {
unfont();
return wraptext(in, "<tt>", "</tt>");
}
int fixwbold(char *in) {
return fontpair(in, Fixed, Bold);
}
int fixwital(char *in) {
return fontpair(in, Fixed, Italic);
}
int fixwrom(char *in) {
return fontpair(in, Fixed, Roman);
}
int ital(char *in) {
unfont();
return wraptext(in, "<i>", "</i>");
}
int italbold(char *in) {
return fontpair(in, Italic, Bold);
}
int italfixw(char *in) {
return fontpair(in, Italic, Fixed);
}
int italrom(char *in) {
return fontpair(in, Italic, Roman);
}
int rombold(char *in) {
return fontpair(in, Roman, Bold);
}
int romfixw(char *in) {
return fontpair(in, Roman, Fixed);
}
int romital(char *in) {
return fontpair(in, Roman, Italic);
}
int smbold(char *in) {
return fontpair(in, Small, Bold);
}
int small(char *in) {
unfont();
return wraptext(in, "<small>", "</small>");
}
int deftab(char *in) {
}
int hangpar(char *in) {
bv txt = {0, inbuf};
undent1();
printf("<p>\n<dl compact><dt>\n");
curind++;
indents[curind] = IS_DL;
txt.val = fget2(inbuf, sizeof(inbuf), Fin);
while (inbuf[0] == '.') {
oneline(&txt);
txt.val = fget2(inbuf, sizeof(inbuf), Fin);
}
printf("<dd>\n");
txt.len = txt.val - inbuf;
txt.val = inbuf;
output(&txt);
if (indents[curind] == IS_NL)
curind--;
return 0;
}
int nofmt(char *in) {
curind++;
indents[curind] = IS_NF;
printf("<pre>\n");
return 0;
}
int dofmt(char *in) {
if (indents[curind] == IS_NF)
curind--;
printf("</pre>\n");
return 0;
}
int tagpar(char *in) {
bv txt = {0, inbuf};
undent1();
curind++;
txt.val = fget2(inbuf, sizeof(inbuf), Fin);
if (!strncmp(inbuf, "\\(bu", 4)) {
indents[curind] = IS_UL;
printf("<p><ul type=\"disc\"><li>\n");
} else
{
indents[curind] = IS_DL;
printf("<p>\n<dl compact><dt>\n");
oneline(&txt);
printf("<dd>\n");
}
return 0;
}
int inpar(char *in) {
int wc = parsewords(in);
undent1();
curind++;
indents[curind] = IS_DL;
printf("<p>\n<dl><dt>\n");
if (wc)
output(words);
printf("<dd>\n");
return 0;
}
int newpar(char *in) {
undent1();
printf("<p>\n");
return 0;
}
int pardist(char *in) {
return 0;
}
int undent(char *in) {
int wc=parsewords(in);
int i = 0;
if (wc)
i = atoi(words[0].val);
if (!i)
i = 1;
for (;i>0;i--)
{
/* close any current DL */
undent1();
if (indents[curind] == IS_IL) {
printf("</ul>\n");
}
curind--;
if (curind <=0)
{
curind = 0;
break;
}
}
return 0;
}
int indent(char *in) {
int id = IS_IL;
if (indents[curind] != IS_DL)
printf("<ul>\n");
else
id = IS_NL;
curind++;
indents[curind] = id;
return 0;
}
int indent2(char *in) {
dofmt(in);
curind++;
indents[curind] = IS_UL;
printf("<ul>\n");
return 0;
}
int comment(char *in) {
int rc = 2;
char *delim = "<!--";
do {
printf("%s%s", delim, in);
if (!fget2(inbuf, sizeof(inbuf), Fin))
{
rc = 0;
break;
}
delim = "\n";
} while (!strncmp(inbuf, ".\\\"", 3));
printf("-->\n");
return rc;
}