]> git.cameronkatri.com Git - mandoc.git/blob - roff.h
Basic implementation of the roff(7) .ti (temporary indent) request.
[mandoc.git] / roff.h
1 /* $Id: roff.h,v 1.48 2017/05/08 15:34:54 schwarze Exp $ */
2 /*
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 struct ohash;
20 struct mdoc_arg;
21 union mdoc_data;
22
23 enum roff_macroset {
24 MACROSET_NONE = 0,
25 MACROSET_MDOC,
26 MACROSET_MAN
27 };
28
29 enum roff_sec {
30 SEC_NONE = 0,
31 SEC_NAME,
32 SEC_LIBRARY,
33 SEC_SYNOPSIS,
34 SEC_DESCRIPTION,
35 SEC_CONTEXT,
36 SEC_IMPLEMENTATION, /* IMPLEMENTATION NOTES */
37 SEC_RETURN_VALUES,
38 SEC_ENVIRONMENT,
39 SEC_FILES,
40 SEC_EXIT_STATUS,
41 SEC_EXAMPLES,
42 SEC_DIAGNOSTICS,
43 SEC_COMPATIBILITY,
44 SEC_ERRORS,
45 SEC_SEE_ALSO,
46 SEC_STANDARDS,
47 SEC_HISTORY,
48 SEC_AUTHORS,
49 SEC_CAVEATS,
50 SEC_BUGS,
51 SEC_SECURITY,
52 SEC_CUSTOM,
53 SEC__MAX
54 };
55
56 enum roff_type {
57 ROFFT_ROOT,
58 ROFFT_BLOCK,
59 ROFFT_HEAD,
60 ROFFT_BODY,
61 ROFFT_TAIL,
62 ROFFT_ELEM,
63 ROFFT_TEXT,
64 ROFFT_TBL,
65 ROFFT_EQN
66 };
67
68 enum roff_tok {
69 ROFF_br = 0,
70 ROFF_ft,
71 ROFF_ll,
72 ROFF_sp,
73 ROFF_ta,
74 ROFF_ti,
75 ROFF_MAX,
76 ROFF_ab,
77 ROFF_ad,
78 ROFF_af,
79 ROFF_aln,
80 ROFF_als,
81 ROFF_am,
82 ROFF_am1,
83 ROFF_ami,
84 ROFF_ami1,
85 ROFF_as,
86 ROFF_as1,
87 ROFF_asciify,
88 ROFF_backtrace,
89 ROFF_bd,
90 ROFF_bleedat,
91 ROFF_blm,
92 ROFF_box,
93 ROFF_boxa,
94 ROFF_bp,
95 ROFF_BP,
96 ROFF_break,
97 ROFF_breakchar,
98 ROFF_brnl,
99 ROFF_brp,
100 ROFF_brpnl,
101 ROFF_c2,
102 ROFF_cc,
103 ROFF_ce,
104 ROFF_cf,
105 ROFF_cflags,
106 ROFF_ch,
107 ROFF_char,
108 ROFF_chop,
109 ROFF_class,
110 ROFF_close,
111 ROFF_CL,
112 ROFF_color,
113 ROFF_composite,
114 ROFF_continue,
115 ROFF_cp,
116 ROFF_cropat,
117 ROFF_cs,
118 ROFF_cu,
119 ROFF_da,
120 ROFF_dch,
121 ROFF_Dd,
122 ROFF_de,
123 ROFF_de1,
124 ROFF_defcolor,
125 ROFF_dei,
126 ROFF_dei1,
127 ROFF_device,
128 ROFF_devicem,
129 ROFF_di,
130 ROFF_do,
131 ROFF_ds,
132 ROFF_ds1,
133 ROFF_dwh,
134 ROFF_dt,
135 ROFF_ec,
136 ROFF_ecr,
137 ROFF_ecs,
138 ROFF_el,
139 ROFF_em,
140 ROFF_EN,
141 ROFF_eo,
142 ROFF_EP,
143 ROFF_EQ,
144 ROFF_errprint,
145 ROFF_ev,
146 ROFF_evc,
147 ROFF_ex,
148 ROFF_fallback,
149 ROFF_fam,
150 ROFF_fc,
151 ROFF_fchar,
152 ROFF_fcolor,
153 ROFF_fdeferlig,
154 ROFF_feature,
155 /* MAN_fi; ignored in mdoc(7) */
156 ROFF_fkern,
157 ROFF_fl,
158 ROFF_flig,
159 ROFF_fp,
160 ROFF_fps,
161 ROFF_fschar,
162 ROFF_fspacewidth,
163 ROFF_fspecial,
164 ROFF_ftr,
165 ROFF_fzoom,
166 ROFF_gcolor,
167 ROFF_hc,
168 ROFF_hcode,
169 ROFF_hidechar,
170 ROFF_hla,
171 ROFF_hlm,
172 ROFF_hpf,
173 ROFF_hpfa,
174 ROFF_hpfcode,
175 ROFF_hw,
176 ROFF_hy,
177 ROFF_hylang,
178 ROFF_hylen,
179 ROFF_hym,
180 ROFF_hypp,
181 ROFF_hys,
182 ROFF_ie,
183 ROFF_if,
184 ROFF_ig,
185 /* MAN_in; ignored in mdoc(7) */
186 ROFF_index,
187 ROFF_it,
188 ROFF_itc,
189 ROFF_IX,
190 ROFF_kern,
191 ROFF_kernafter,
192 ROFF_kernbefore,
193 ROFF_kernpair,
194 ROFF_lc,
195 ROFF_lc_ctype,
196 ROFF_lds,
197 ROFF_length,
198 ROFF_letadj,
199 ROFF_lf,
200 ROFF_lg,
201 ROFF_lhang,
202 ROFF_linetabs,
203 ROFF_lnr,
204 ROFF_lnrf,
205 ROFF_lpfx,
206 ROFF_ls,
207 ROFF_lsm,
208 ROFF_lt,
209 ROFF_mc,
210 ROFF_mediasize,
211 ROFF_minss,
212 ROFF_mk,
213 ROFF_mso,
214 ROFF_na,
215 ROFF_ne,
216 /* MAN_nf; ignored in mdoc(7) */
217 ROFF_nh,
218 ROFF_nhychar,
219 ROFF_nm,
220 ROFF_nn,
221 ROFF_nop,
222 ROFF_nr,
223 ROFF_nrf,
224 ROFF_nroff,
225 ROFF_ns,
226 ROFF_nx,
227 ROFF_open,
228 ROFF_opena,
229 ROFF_os,
230 ROFF_output,
231 ROFF_padj,
232 ROFF_papersize,
233 ROFF_pc,
234 ROFF_pev,
235 ROFF_pi,
236 ROFF_PI,
237 ROFF_pl,
238 ROFF_pm,
239 ROFF_pn,
240 ROFF_pnr,
241 ROFF_po,
242 ROFF_ps,
243 ROFF_psbb,
244 ROFF_pshape,
245 ROFF_pso,
246 ROFF_ptr,
247 ROFF_pvs,
248 ROFF_rchar,
249 ROFF_rd,
250 ROFF_recursionlimit,
251 ROFF_return,
252 ROFF_rfschar,
253 ROFF_rhang,
254 ROFF_rj,
255 ROFF_rm,
256 ROFF_rn,
257 ROFF_rnn,
258 ROFF_rr,
259 ROFF_rs,
260 ROFF_rt,
261 ROFF_schar,
262 ROFF_sentchar,
263 ROFF_shc,
264 ROFF_shift,
265 ROFF_sizes,
266 ROFF_so,
267 ROFF_spacewidth,
268 ROFF_special,
269 ROFF_spreadwarn,
270 ROFF_ss,
271 ROFF_sty,
272 ROFF_substring,
273 ROFF_sv,
274 ROFF_sy,
275 ROFF_T_,
276 ROFF_tc,
277 ROFF_TE,
278 ROFF_TH,
279 ROFF_tkf,
280 ROFF_tl,
281 ROFF_tm,
282 ROFF_tm1,
283 ROFF_tmc,
284 ROFF_tr,
285 ROFF_track,
286 ROFF_transchar,
287 ROFF_trf,
288 ROFF_trimat,
289 ROFF_trin,
290 ROFF_trnt,
291 ROFF_troff,
292 ROFF_TS,
293 ROFF_uf,
294 ROFF_ul,
295 ROFF_unformat,
296 ROFF_unwatch,
297 ROFF_unwatchn,
298 ROFF_vpt,
299 ROFF_vs,
300 ROFF_warn,
301 ROFF_warnscale,
302 ROFF_watch,
303 ROFF_watchlength,
304 ROFF_watchn,
305 ROFF_wh,
306 ROFF_while,
307 ROFF_write,
308 ROFF_writec,
309 ROFF_writem,
310 ROFF_xflag,
311 ROFF_cblock,
312 ROFF_USERDEF,
313 TOKEN_NONE,
314 MDOC_Dd,
315 MDOC_Dt,
316 MDOC_Os,
317 MDOC_Sh,
318 MDOC_Ss,
319 MDOC_Pp,
320 MDOC_D1,
321 MDOC_Dl,
322 MDOC_Bd,
323 MDOC_Ed,
324 MDOC_Bl,
325 MDOC_El,
326 MDOC_It,
327 MDOC_Ad,
328 MDOC_An,
329 MDOC_Ap,
330 MDOC_Ar,
331 MDOC_Cd,
332 MDOC_Cm,
333 MDOC_Dv,
334 MDOC_Er,
335 MDOC_Ev,
336 MDOC_Ex,
337 MDOC_Fa,
338 MDOC_Fd,
339 MDOC_Fl,
340 MDOC_Fn,
341 MDOC_Ft,
342 MDOC_Ic,
343 MDOC_In,
344 MDOC_Li,
345 MDOC_Nd,
346 MDOC_Nm,
347 MDOC_Op,
348 MDOC_Ot,
349 MDOC_Pa,
350 MDOC_Rv,
351 MDOC_St,
352 MDOC_Va,
353 MDOC_Vt,
354 MDOC_Xr,
355 MDOC__A,
356 MDOC__B,
357 MDOC__D,
358 MDOC__I,
359 MDOC__J,
360 MDOC__N,
361 MDOC__O,
362 MDOC__P,
363 MDOC__R,
364 MDOC__T,
365 MDOC__V,
366 MDOC_Ac,
367 MDOC_Ao,
368 MDOC_Aq,
369 MDOC_At,
370 MDOC_Bc,
371 MDOC_Bf,
372 MDOC_Bo,
373 MDOC_Bq,
374 MDOC_Bsx,
375 MDOC_Bx,
376 MDOC_Db,
377 MDOC_Dc,
378 MDOC_Do,
379 MDOC_Dq,
380 MDOC_Ec,
381 MDOC_Ef,
382 MDOC_Em,
383 MDOC_Eo,
384 MDOC_Fx,
385 MDOC_Ms,
386 MDOC_No,
387 MDOC_Ns,
388 MDOC_Nx,
389 MDOC_Ox,
390 MDOC_Pc,
391 MDOC_Pf,
392 MDOC_Po,
393 MDOC_Pq,
394 MDOC_Qc,
395 MDOC_Ql,
396 MDOC_Qo,
397 MDOC_Qq,
398 MDOC_Re,
399 MDOC_Rs,
400 MDOC_Sc,
401 MDOC_So,
402 MDOC_Sq,
403 MDOC_Sm,
404 MDOC_Sx,
405 MDOC_Sy,
406 MDOC_Tn,
407 MDOC_Ux,
408 MDOC_Xc,
409 MDOC_Xo,
410 MDOC_Fo,
411 MDOC_Fc,
412 MDOC_Oo,
413 MDOC_Oc,
414 MDOC_Bk,
415 MDOC_Ek,
416 MDOC_Bt,
417 MDOC_Hf,
418 MDOC_Fr,
419 MDOC_Ud,
420 MDOC_Lb,
421 MDOC_Lp,
422 MDOC_Lk,
423 MDOC_Mt,
424 MDOC_Brq,
425 MDOC_Bro,
426 MDOC_Brc,
427 MDOC__C,
428 MDOC_Es,
429 MDOC_En,
430 MDOC_Dx,
431 MDOC__Q,
432 MDOC__U,
433 MDOC_Ta,
434 MDOC_MAX,
435 MAN_TH,
436 MAN_SH,
437 MAN_SS,
438 MAN_TP,
439 MAN_LP,
440 MAN_PP,
441 MAN_P,
442 MAN_IP,
443 MAN_HP,
444 MAN_SM,
445 MAN_SB,
446 MAN_BI,
447 MAN_IB,
448 MAN_BR,
449 MAN_RB,
450 MAN_R,
451 MAN_B,
452 MAN_I,
453 MAN_IR,
454 MAN_RI,
455 MAN_nf,
456 MAN_fi,
457 MAN_RE,
458 MAN_RS,
459 MAN_DT,
460 MAN_UC,
461 MAN_PD,
462 MAN_AT,
463 MAN_in,
464 MAN_OP,
465 MAN_EX,
466 MAN_EE,
467 MAN_UR,
468 MAN_UE,
469 MAN_MAX
470 };
471
472 enum roff_next {
473 ROFF_NEXT_SIBLING = 0,
474 ROFF_NEXT_CHILD
475 };
476
477 /*
478 * Indicates that a BODY's formatting has ended, but
479 * the scope is still open. Used for badly nested blocks.
480 */
481 enum mdoc_endbody {
482 ENDBODY_NOT = 0,
483 ENDBODY_SPACE /* Is broken: append a space. */
484 };
485
486 struct roff_node {
487 struct roff_node *parent; /* Parent AST node. */
488 struct roff_node *child; /* First child AST node. */
489 struct roff_node *last; /* Last child AST node. */
490 struct roff_node *next; /* Sibling AST node. */
491 struct roff_node *prev; /* Prior sibling AST node. */
492 struct roff_node *head; /* BLOCK */
493 struct roff_node *body; /* BLOCK/ENDBODY */
494 struct roff_node *tail; /* BLOCK */
495 struct mdoc_arg *args; /* BLOCK/ELEM */
496 union mdoc_data *norm; /* Normalized arguments. */
497 char *string; /* TEXT */
498 const struct tbl_span *span; /* TBL */
499 const struct eqn *eqn; /* EQN */
500 int line; /* Input file line number. */
501 int pos; /* Input file column number. */
502 int flags;
503 #define NODE_VALID (1 << 0) /* Has been validated. */
504 #define NODE_ENDED (1 << 1) /* Gone past body end mark. */
505 #define NODE_EOS (1 << 2) /* At sentence boundary. */
506 #define NODE_LINE (1 << 3) /* First macro/text on line. */
507 #define NODE_SYNPRETTY (1 << 4) /* SYNOPSIS-style formatting. */
508 #define NODE_BROKEN (1 << 5) /* Must validate parent when ending. */
509 #define NODE_DELIMO (1 << 6)
510 #define NODE_DELIMC (1 << 7)
511 #define NODE_NOSRC (1 << 8) /* Generated node, not in input file. */
512 #define NODE_NOPRT (1 << 9) /* Shall not print anything. */
513 int prev_font; /* Before entering this node. */
514 int aux; /* Decoded node data, type-dependent. */
515 enum roff_tok tok; /* Request or macro ID. */
516 enum roff_type type; /* AST node type. */
517 enum roff_sec sec; /* Current named section. */
518 enum mdoc_endbody end; /* BODY */
519 };
520
521 struct roff_meta {
522 char *msec; /* Manual section, usually a digit. */
523 char *vol; /* Manual volume title. */
524 char *os; /* Operating system. */
525 char *arch; /* Machine architecture. */
526 char *title; /* Manual title, usually CAPS. */
527 char *name; /* Leading manual name. */
528 char *date; /* Normalized date. */
529 int hasbody; /* Document is not empty. */
530 };
531
532 struct roff_man {
533 struct roff_meta meta; /* Document meta-data. */
534 struct mparse *parse; /* Parse pointer. */
535 struct roff *roff; /* Roff parser state data. */
536 struct ohash *mdocmac; /* Mdoc macro lookup table. */
537 struct ohash *manmac; /* Man macro lookup table. */
538 const char *defos; /* Default operating system. */
539 struct roff_node *first; /* The first node parsed. */
540 struct roff_node *last; /* The last node parsed. */
541 struct roff_node *last_es; /* The most recent Es node. */
542 int quick; /* Abort parse early. */
543 int flags; /* Parse flags. */
544 #define MDOC_LITERAL (1 << 1) /* In a literal scope. */
545 #define MDOC_PBODY (1 << 2) /* In the document body. */
546 #define MDOC_NEWLINE (1 << 3) /* First macro/text in a line. */
547 #define MDOC_PHRASE (1 << 4) /* In a Bl -column phrase. */
548 #define MDOC_PHRASELIT (1 << 5) /* Literal within a phrase. */
549 #define MDOC_FREECOL (1 << 6) /* `It' invocation should close. */
550 #define MDOC_SYNOPSIS (1 << 7) /* SYNOPSIS-style formatting. */
551 #define MDOC_KEEP (1 << 8) /* In a word keep. */
552 #define MDOC_SMOFF (1 << 9) /* Spacing is off. */
553 #define MDOC_NODELIMC (1 << 10) /* Disable closing delimiter handling. */
554 #define MAN_ELINE (1 << 11) /* Next-line element scope. */
555 #define MAN_BLINE (1 << 12) /* Next-line block scope. */
556 #define MDOC_PHRASEQF (1 << 13) /* Quote first word encountered. */
557 #define MDOC_PHRASEQL (1 << 14) /* Quote last word of this phrase. */
558 #define MDOC_PHRASEQN (1 << 15) /* Quote first word of the next phrase. */
559 #define MAN_LITERAL MDOC_LITERAL
560 #define MAN_NEWLINE MDOC_NEWLINE
561 enum roff_macroset macroset; /* Kind of high-level macros used. */
562 enum roff_sec lastsec; /* Last section seen. */
563 enum roff_sec lastnamed; /* Last standard section seen. */
564 enum roff_next next; /* Where to put the next node. */
565 };
566
567 extern const char *const *roff_name;
568
569
570 void deroff(char **, const struct roff_node *);
571 struct ohash *roffhash_alloc(enum roff_tok, enum roff_tok);
572 enum roff_tok roffhash_find(struct ohash *, const char *, size_t);
573 void roffhash_free(struct ohash *);
574 void roff_validate(struct roff_man *);