move the tests out of tree
[ctxt.git] / troff.c
blobe04c29da83ef4f392bd0654c3900743b999ae429
1 #include <stdlib.h>
2 #include "ctxt.h"
4 static void troff_doc_beg(struct doc *doc)
8 static void troff_doc_end(struct doc *doc)
12 static void troff_head_beg(struct doc *doc, int level)
14 switch (level) {
15 case 0:
16 doc_write(doc, ".NH 1\n");
17 break;
18 case 1:
19 doc_write(doc, ".NH 2\n");
20 break;
21 default:
22 doc_write(doc, ".SH\n");
26 static void troff_head_end(struct doc *doc, int level)
28 doc_write(doc, "\n");
31 static void troff_par_beg(struct doc *doc)
33 doc_write(doc, ".PP\n");
36 static void troff_par_end(struct doc *doc)
40 static void troff_put(struct doc *doc, char *s)
42 doc_write(doc, s);
45 static void troff_list_beg(struct doc *doc)
49 static void troff_list_end(struct doc *doc)
53 static void troff_item_beg(struct doc *doc)
55 doc_write(doc, ".IP \\(bu\n");
58 static void troff_item_end(struct doc *doc)
60 doc_write(doc, "");
63 static void troff_block_beg(struct doc *doc, char *beg, int block)
65 doc_write(doc, beg);
66 doc_write(doc, "\n");
69 static void troff_block_end(struct doc *doc, char *end, int block)
71 doc_write(doc, end);
72 doc_write(doc, "\n");
75 static void troff_put_txt(struct doc *doc, char *s, int marker)
77 switch(marker) {
78 case M_EMPH:
79 doc_write(doc, "\fB");
80 doc_write(doc, s);
81 doc_write(doc, "\fP");
82 break;
83 case M_RAW:
84 doc_write(doc, s);
85 break;
86 case M_LINK:
87 doc_write(doc, "\n.[\n");
88 doc_write(doc, s);
89 doc_write(doc, "\n.]\n");
90 break;
91 case M_FOOT:
92 doc_write(doc, "\n.FS\n");
93 doc_write(doc, s);
94 doc_write(doc, "\n.FE\n");
95 break;
96 case M_MATH:
97 doc_write(doc, "\n.EQ\n");
98 doc_write(doc, s);
99 doc_write(doc, "\n.EN\n");
100 break;
101 default:
102 troff_put(doc, s);
106 static void troff_table_beg(struct doc *doc, int columns)
108 int i;
109 doc_write(doc, ".TS\n");
110 doc_write(doc, "allbox;\n");
111 for (i = 0; i < columns; i++)
112 doc_write(doc, "c ");
113 doc_write(doc, ".\n");
116 static void troff_table_end(struct doc *doc)
118 doc_write(doc, ".TE\n");
121 /* a hack to identify the first entry in each row */
122 static int entcol;
124 static void troff_row_beg(struct doc *doc)
126 entcol = 0;
129 static void troff_row_end(struct doc *doc)
131 doc_write(doc, "\n");
134 static void troff_entry_beg(struct doc *doc)
136 if (entcol++)
137 doc_write(doc, "\t");
138 doc_write(doc, "T{\n");
141 static void troff_entry_end(struct doc *doc)
143 doc_write(doc, "\nT}");
146 struct fmt_ops troff_ops = {
147 .doc_beg = troff_doc_beg,
148 .doc_end = troff_doc_end,
149 .head_beg = troff_head_beg,
150 .head_end = troff_head_end,
151 .par_beg = troff_par_beg,
152 .par_end = troff_par_end,
153 .list_beg = troff_list_beg,
154 .list_end = troff_list_end,
155 .item_beg = troff_item_beg,
156 .item_end = troff_item_end,
157 .table_beg = troff_table_beg,
158 .table_end = troff_table_end,
159 .row_beg = troff_row_beg,
160 .row_end = troff_row_end,
161 .entry_beg = troff_entry_beg,
162 .entry_end = troff_entry_end,
163 .block_beg = troff_block_beg,
164 .block_end = troff_block_end,
165 .put = troff_put,
166 .put_txt = troff_put_txt