5 static int eatspc
; /* jump space chars */
6 static int gotnl
; /* last output char was a space */
7 static int inblk
; /* inside a block */
9 static void troff_doc_beg(struct doc
*doc
)
13 static void troff_doc_end(struct doc
*doc
)
17 static void troff_put(struct doc
*doc
, char *s
)
26 while (*s
== ' ' || *s
== '\t' || *s
== '\n')
29 doc_write(doc
, "\\&");
32 while (gotnl
&& *s
== '\n')
35 char *r
= strchr(s
, '\n');
36 r
= r
? r
+ 1 : strchr(s
, '\0');
37 doc_memcat(doc
, s
, r
- s
);
42 gotnl
= s
[-1] == '\n';
45 static void troff_head_beg(struct doc
*doc
, int level
)
49 troff_put(doc
, ".NH 1\n");
52 troff_put(doc
, ".NH 2\n");
55 troff_put(doc
, ".SH\n");
59 static void troff_head_end(struct doc
*doc
, int level
)
63 static void troff_par_beg(struct doc
*doc
)
65 troff_put(doc
, ".PP\n");
68 static void troff_par_end(struct doc
*doc
)
72 static void troff_list_beg(struct doc
*doc
)
77 static void troff_list_end(struct doc
*doc
)
81 static void troff_item_beg(struct doc
*doc
)
83 troff_put(doc
, ".IP \\(bu\n");
87 static void troff_item_end(struct doc
*doc
)
91 static void troff_block_beg(struct doc
*doc
, char *beg
, int block
)
98 static void troff_block_end(struct doc
*doc
, char *end
, int block
)
101 troff_put(doc
, "\n");
105 static void troff_put_txt(struct doc
*doc
, char *s
, int marker
)
109 troff_put(doc
, "\\fB");
111 troff_put(doc
, "\\fP");
117 troff_put(doc
, "\n.[]\n");
119 troff_put(doc
, "\n.][\n");
123 troff_put(doc
, "\n.FS\n");
125 troff_put(doc
, "\n.FE\n");
138 static void troff_table_beg(struct doc
*doc
, int columns
)
141 troff_put(doc
, ".TS\n");
142 troff_put(doc
, "allbox;\n");
143 for (i
= 0; i
< columns
; i
++)
144 troff_put(doc
, "c ");
145 troff_put(doc
, ".\n");
148 static void troff_table_end(struct doc
*doc
)
150 troff_put(doc
, ".TE\n");
153 /* a hack to identify the first entry in each row */
156 static void troff_row_beg(struct doc
*doc
)
161 static void troff_row_end(struct doc
*doc
)
163 troff_put(doc
, "\n");
166 static void troff_entry_beg(struct doc
*doc
)
169 troff_put(doc
, "\t");
170 troff_put(doc
, "T{\n");
173 static void troff_entry_end(struct doc
*doc
)
175 troff_put(doc
, "\nT}");
178 struct fmt_ops troff_ops
= {
179 .doc_beg
= troff_doc_beg
,
180 .doc_end
= troff_doc_end
,
181 .head_beg
= troff_head_beg
,
182 .head_end
= troff_head_end
,
183 .par_beg
= troff_par_beg
,
184 .par_end
= troff_par_end
,
185 .list_beg
= troff_list_beg
,
186 .list_end
= troff_list_end
,
187 .item_beg
= troff_item_beg
,
188 .item_end
= troff_item_end
,
189 .table_beg
= troff_table_beg
,
190 .table_end
= troff_table_end
,
191 .row_beg
= troff_row_beg
,
192 .row_end
= troff_row_end
,
193 .entry_beg
= troff_entry_beg
,
194 .entry_end
= troff_entry_end
,
195 .block_beg
= troff_block_beg
,
196 .block_end
= troff_block_end
,
198 .put_txt
= troff_put_txt