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