]>
git.cameronkatri.com Git - mandoc.git/blob - roff.c
1 /* $Id: roff.c,v 1.305 2017/06/06 15:01:04 schwarze Exp $ */
3 * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
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.
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.
20 #include <sys/types.h>
32 #include "mandoc_aux.h"
33 #include "mandoc_ohash.h"
35 #include "libmandoc.h"
39 /* Maximum number of string expansions per line, to break infinite loops. */
40 #define EXPAND_LIMIT 1000
42 /* --- data types --------------------------------------------------------- */
45 * An incredibly-simple string buffer.
48 char *p
; /* nil-terminated buffer */
49 size_t sz
; /* saved strlen(p) */
53 * A key-value roffstr pair as part of a singly-linked list.
58 struct roffkv
*next
; /* next in list */
62 * A single number register as part of a singly-linked list.
71 * Association of request and macro names with token IDs.
79 struct mparse
*parse
; /* parse point */
80 struct roff_man
*man
; /* mdoc or man parser */
81 struct roffnode
*last
; /* leaf of stack */
82 int *rstack
; /* stack of inverted `ie' values */
83 struct ohash
*reqtab
; /* request lookup table */
84 struct roffreg
*regtab
; /* number registers */
85 struct roffkv
*strtab
; /* user-defined strings & macros */
86 struct roffkv
*xmbtab
; /* multi-byte trans table (`tr') */
87 struct roffstr
*xtab
; /* single-byte trans table (`tr') */
88 const char *current_string
; /* value of last called user macro */
89 struct tbl_node
*first_tbl
; /* first table parsed */
90 struct tbl_node
*last_tbl
; /* last table parsed */
91 struct tbl_node
*tbl
; /* current table being parsed */
92 struct eqn_node
*last_eqn
; /* last equation parsed */
93 struct eqn_node
*first_eqn
; /* first equation parsed */
94 struct eqn_node
*eqn
; /* current equation being parsed */
95 int eqn_inline
; /* current equation is inline */
96 int options
; /* parse options */
97 int rstacksz
; /* current size limit of rstack */
98 int rstackpos
; /* position in rstack */
99 int format
; /* current file in mdoc or man format */
100 int argc
; /* number of args of the last macro */
101 char control
; /* control character */
102 char escape
; /* escape character */
106 enum roff_tok tok
; /* type of node */
107 struct roffnode
*parent
; /* up one in stack */
108 int line
; /* parse line */
109 int col
; /* parse col */
110 char *name
; /* node name, e.g. macro name */
111 char *end
; /* end-rules: custom token */
112 int endspan
; /* end-rules: next-line or infty */
113 int rule
; /* current evaluation rule */
116 #define ROFF_ARGS struct roff *r, /* parse ctx */ \
117 enum roff_tok tok, /* tok of macro */ \
118 struct buf *buf, /* input buffer */ \
119 int ln, /* parse line */ \
120 int ppos, /* original pos in buffer */ \
121 int pos, /* current pos in buffer */ \
122 int *offs /* reset offset of buffer data */
124 typedef enum rofferr (*roffproc
)(ROFF_ARGS
);
127 roffproc proc
; /* process new macro */
128 roffproc text
; /* process as child text of macro */
129 roffproc sub
; /* process as child of macro */
131 #define ROFFMAC_STRUCT (1 << 0) /* always interpret */
135 const char *name
; /* predefined input name */
136 const char *str
; /* replacement symbol */
139 #define PREDEF(__name, __str) \
140 { (__name), (__str) },
142 /* --- function prototypes ------------------------------------------------ */
144 static void roffnode_cleanscope(struct roff
*);
145 static void roffnode_pop(struct roff
*);
146 static void roffnode_push(struct roff
*, enum roff_tok
,
147 const char *, int, int);
148 static enum rofferr
roff_block(ROFF_ARGS
);
149 static enum rofferr
roff_block_text(ROFF_ARGS
);
150 static enum rofferr
roff_block_sub(ROFF_ARGS
);
151 static enum rofferr
roff_br(ROFF_ARGS
);
152 static enum rofferr
roff_cblock(ROFF_ARGS
);
153 static enum rofferr
roff_cc(ROFF_ARGS
);
154 static void roff_ccond(struct roff
*, int, int);
155 static enum rofferr
roff_cond(ROFF_ARGS
);
156 static enum rofferr
roff_cond_text(ROFF_ARGS
);
157 static enum rofferr
roff_cond_sub(ROFF_ARGS
);
158 static enum rofferr
roff_ds(ROFF_ARGS
);
159 static enum rofferr
roff_ec(ROFF_ARGS
);
160 static enum rofferr
roff_eo(ROFF_ARGS
);
161 static enum rofferr
roff_eqndelim(struct roff
*, struct buf
*, int);
162 static int roff_evalcond(struct roff
*r
, int, char *, int *);
163 static int roff_evalnum(struct roff
*, int,
164 const char *, int *, int *, int);
165 static int roff_evalpar(struct roff
*, int,
166 const char *, int *, int *, int);
167 static int roff_evalstrcond(const char *, int *);
168 static void roff_free1(struct roff
*);
169 static void roff_freereg(struct roffreg
*);
170 static void roff_freestr(struct roffkv
*);
171 static size_t roff_getname(struct roff
*, char **, int, int);
172 static int roff_getnum(const char *, int *, int *, int);
173 static int roff_getop(const char *, int *, char *);
174 static int roff_getregn(const struct roff
*,
175 const char *, size_t);
176 static int roff_getregro(const struct roff
*,
178 static const char *roff_getstrn(const struct roff
*,
179 const char *, size_t);
180 static int roff_hasregn(const struct roff
*,
181 const char *, size_t);
182 static enum rofferr
roff_insec(ROFF_ARGS
);
183 static enum rofferr
roff_it(ROFF_ARGS
);
184 static enum rofferr
roff_line_ignore(ROFF_ARGS
);
185 static void roff_man_alloc1(struct roff_man
*);
186 static void roff_man_free1(struct roff_man
*);
187 static enum rofferr
roff_manyarg(ROFF_ARGS
);
188 static enum rofferr
roff_nr(ROFF_ARGS
);
189 static enum rofferr
roff_onearg(ROFF_ARGS
);
190 static enum roff_tok
roff_parse(struct roff
*, char *, int *,
192 static enum rofferr
roff_parsetext(struct roff
*, struct buf
*,
194 static enum rofferr
roff_res(struct roff
*, struct buf
*, int, int);
195 static enum rofferr
roff_rm(ROFF_ARGS
);
196 static enum rofferr
roff_rr(ROFF_ARGS
);
197 static void roff_setstr(struct roff
*,
198 const char *, const char *, int);
199 static void roff_setstrn(struct roffkv
**, const char *,
200 size_t, const char *, size_t, int);
201 static enum rofferr
roff_so(ROFF_ARGS
);
202 static enum rofferr
roff_tr(ROFF_ARGS
);
203 static enum rofferr
roff_Dd(ROFF_ARGS
);
204 static enum rofferr
roff_TH(ROFF_ARGS
);
205 static enum rofferr
roff_TE(ROFF_ARGS
);
206 static enum rofferr
roff_TS(ROFF_ARGS
);
207 static enum rofferr
roff_EQ(ROFF_ARGS
);
208 static enum rofferr
roff_EN(ROFF_ARGS
);
209 static enum rofferr
roff_T_(ROFF_ARGS
);
210 static enum rofferr
roff_unsupp(ROFF_ARGS
);
211 static enum rofferr
roff_userdef(ROFF_ARGS
);
213 /* --- constant data ------------------------------------------------------ */
215 #define ROFFNUM_SCALE (1 << 0) /* Honour scaling in roff_getnum(). */
216 #define ROFFNUM_WHITE (1 << 1) /* Skip whitespace in roff_evalnum(). */
218 const char *__roff_name
[MAN_MAX
+ 1] = {
219 "br", "ce", "ft", "ll",
220 "mc", "sp", "ta", "ti",
222 "ab", "ad", "af", "aln",
223 "als", "am", "am1", "ami",
224 "ami1", "as", "as1", "asciify",
225 "backtrace", "bd", "bleedat", "blm",
226 "box", "boxa", "bp", "BP",
227 "break", "breakchar", "brnl", "brp",
229 "cf", "cflags", "ch", "char",
230 "chop", "class", "close", "CL",
231 "color", "composite", "continue", "cp",
232 "cropat", "cs", "cu", "da",
233 "dch", "Dd", "de", "de1",
234 "defcolor", "dei", "dei1", "device",
235 "devicem", "di", "do", "ds",
236 "ds1", "dwh", "dt", "ec",
237 "ecr", "ecs", "el", "em",
238 "EN", "eo", "EP", "EQ",
239 "errprint", "ev", "evc", "ex",
240 "fallback", "fam", "fc", "fchar",
241 "fcolor", "fdeferlig", "feature", "fkern",
242 "fl", "flig", "fp", "fps",
243 "fschar", "fspacewidth", "fspecial", "ftr",
244 "fzoom", "gcolor", "hc", "hcode",
245 "hidechar", "hla", "hlm", "hpf",
246 "hpfa", "hpfcode", "hw", "hy",
247 "hylang", "hylen", "hym", "hypp",
248 "hys", "ie", "if", "ig",
249 "index", "it", "itc", "IX",
250 "kern", "kernafter", "kernbefore", "kernpair",
251 "lc", "lc_ctype", "lds", "length",
252 "letadj", "lf", "lg", "lhang",
253 "linetabs", "lnr", "lnrf", "lpfx",
255 "mediasize", "minss", "mk", "mso",
256 "na", "ne", "nh", "nhychar",
257 "nm", "nn", "nop", "nr",
258 "nrf", "nroff", "ns", "nx",
259 "open", "opena", "os", "output",
260 "padj", "papersize", "pc", "pev",
261 "pi", "PI", "pl", "pm",
262 "pn", "pnr", "po", "ps",
263 "psbb", "pshape", "pso", "ptr",
264 "pvs", "rchar", "rd", "recursionlimit",
265 "return", "rfschar", "rhang", "rj",
266 "rm", "rn", "rnn", "rr",
267 "rs", "rt", "schar", "sentchar",
268 "shc", "shift", "sizes", "so",
269 "spacewidth", "special", "spreadwarn", "ss",
270 "sty", "substring", "sv", "sy",
273 "tm", "tm1", "tmc", "tr",
274 "track", "transchar", "trf", "trimat",
275 "trin", "trnt", "troff", "TS",
276 "uf", "ul", "unformat", "unwatch",
277 "unwatchn", "vpt", "vs", "warn",
278 "warnscale", "watch", "watchlength", "watchn",
279 "wh", "while", "write", "writec",
280 "writem", "xflag", ".", NULL
,
282 "Dd", "Dt", "Os", "Sh",
283 "Ss", "Pp", "D1", "Dl",
284 "Bd", "Ed", "Bl", "El",
285 "It", "Ad", "An", "Ap",
286 "Ar", "Cd", "Cm", "Dv",
287 "Er", "Ev", "Ex", "Fa",
288 "Fd", "Fl", "Fn", "Ft",
289 "Ic", "In", "Li", "Nd",
290 "Nm", "Op", "Ot", "Pa",
291 "Rv", "St", "Va", "Vt",
292 "Xr", "%A", "%B", "%D",
293 "%I", "%J", "%N", "%O",
294 "%P", "%R", "%T", "%V",
295 "Ac", "Ao", "Aq", "At",
296 "Bc", "Bf", "Bo", "Bq",
297 "Bsx", "Bx", "Db", "Dc",
298 "Do", "Dq", "Ec", "Ef",
299 "Em", "Eo", "Fx", "Ms",
300 "No", "Ns", "Nx", "Ox",
301 "Pc", "Pf", "Po", "Pq",
302 "Qc", "Ql", "Qo", "Qq",
303 "Re", "Rs", "Sc", "So",
304 "Sq", "Sm", "Sx", "Sy",
305 "Tn", "Ux", "Xc", "Xo",
306 "Fo", "Fc", "Oo", "Oc",
307 "Bk", "Ek", "Bt", "Hf",
308 "Fr", "Ud", "Lb", "Lp",
309 "Lk", "Mt", "Brq", "Bro",
310 "Brc", "%C", "Es", "En",
311 "Dx", "%Q", "%U", "Ta",
313 "TH", "SH", "SS", "TP",
314 "LP", "PP", "P", "IP",
315 "HP", "SM", "SB", "BI",
316 "IB", "BR", "RB", "R",
317 "B", "I", "IR", "RI",
319 "RE", "RS", "DT", "UC",
321 "OP", "EX", "EE", "UR",
324 const char *const *roff_name
= __roff_name
;
326 static struct roffmac roffs
[TOKEN_NONE
] = {
327 { roff_br
, NULL
, NULL
, 0 }, /* br */
328 { roff_onearg
, NULL
, NULL
, 0 }, /* ce */
329 { roff_onearg
, NULL
, NULL
, 0 }, /* ft */
330 { roff_onearg
, NULL
, NULL
, 0 }, /* ll */
331 { roff_onearg
, NULL
, NULL
, 0 }, /* mc */
332 { roff_onearg
, NULL
, NULL
, 0 }, /* sp */
333 { roff_manyarg
, NULL
, NULL
, 0 }, /* ta */
334 { roff_onearg
, NULL
, NULL
, 0 }, /* ti */
335 { NULL
, NULL
, NULL
, 0 }, /* ROFF_MAX */
336 { roff_unsupp
, NULL
, NULL
, 0 }, /* ab */
337 { roff_line_ignore
, NULL
, NULL
, 0 }, /* ad */
338 { roff_line_ignore
, NULL
, NULL
, 0 }, /* af */
339 { roff_unsupp
, NULL
, NULL
, 0 }, /* aln */
340 { roff_unsupp
, NULL
, NULL
, 0 }, /* als */
341 { roff_block
, roff_block_text
, roff_block_sub
, 0 }, /* am */
342 { roff_block
, roff_block_text
, roff_block_sub
, 0 }, /* am1 */
343 { roff_block
, roff_block_text
, roff_block_sub
, 0 }, /* ami */
344 { roff_block
, roff_block_text
, roff_block_sub
, 0 }, /* ami1 */
345 { roff_ds
, NULL
, NULL
, 0 }, /* as */
346 { roff_ds
, NULL
, NULL
, 0 }, /* as1 */
347 { roff_unsupp
, NULL
, NULL
, 0 }, /* asciify */
348 { roff_line_ignore
, NULL
, NULL
, 0 }, /* backtrace */
349 { roff_line_ignore
, NULL
, NULL
, 0 }, /* bd */
350 { roff_line_ignore
, NULL
, NULL
, 0 }, /* bleedat */
351 { roff_unsupp
, NULL
, NULL
, 0 }, /* blm */
352 { roff_unsupp
, NULL
, NULL
, 0 }, /* box */
353 { roff_unsupp
, NULL
, NULL
, 0 }, /* boxa */
354 { roff_line_ignore
, NULL
, NULL
, 0 }, /* bp */
355 { roff_unsupp
, NULL
, NULL
, 0 }, /* BP */
356 { roff_unsupp
, NULL
, NULL
, 0 }, /* break */
357 { roff_line_ignore
, NULL
, NULL
, 0 }, /* breakchar */
358 { roff_line_ignore
, NULL
, NULL
, 0 }, /* brnl */
359 { roff_br
, NULL
, NULL
, 0 }, /* brp */
360 { roff_line_ignore
, NULL
, NULL
, 0 }, /* brpnl */
361 { roff_unsupp
, NULL
, NULL
, 0 }, /* c2 */
362 { roff_cc
, NULL
, NULL
, 0 }, /* cc */
363 { roff_insec
, NULL
, NULL
, 0 }, /* cf */
364 { roff_line_ignore
, NULL
, NULL
, 0 }, /* cflags */
365 { roff_line_ignore
, NULL
, NULL
, 0 }, /* ch */
366 { roff_unsupp
, NULL
, NULL
, 0 }, /* char */
367 { roff_unsupp
, NULL
, NULL
, 0 }, /* chop */
368 { roff_line_ignore
, NULL
, NULL
, 0 }, /* class */
369 { roff_insec
, NULL
, NULL
, 0 }, /* close */
370 { roff_unsupp
, NULL
, NULL
, 0 }, /* CL */
371 { roff_line_ignore
, NULL
, NULL
, 0 }, /* color */
372 { roff_unsupp
, NULL
, NULL
, 0 }, /* composite */
373 { roff_unsupp
, NULL
, NULL
, 0 }, /* continue */
374 { roff_line_ignore
, NULL
, NULL
, 0 }, /* cp */
375 { roff_line_ignore
, NULL
, NULL
, 0 }, /* cropat */
376 { roff_line_ignore
, NULL
, NULL
, 0 }, /* cs */
377 { roff_line_ignore
, NULL
, NULL
, 0 }, /* cu */
378 { roff_unsupp
, NULL
, NULL
, 0 }, /* da */
379 { roff_unsupp
, NULL
, NULL
, 0 }, /* dch */
380 { roff_Dd
, NULL
, NULL
, 0 }, /* Dd */
381 { roff_block
, roff_block_text
, roff_block_sub
, 0 }, /* de */
382 { roff_block
, roff_block_text
, roff_block_sub
, 0 }, /* de1 */
383 { roff_line_ignore
, NULL
, NULL
, 0 }, /* defcolor */
384 { roff_block
, roff_block_text
, roff_block_sub
, 0 }, /* dei */
385 { roff_block
, roff_block_text
, roff_block_sub
, 0 }, /* dei1 */
386 { roff_unsupp
, NULL
, NULL
, 0 }, /* device */
387 { roff_unsupp
, NULL
, NULL
, 0 }, /* devicem */
388 { roff_unsupp
, NULL
, NULL
, 0 }, /* di */
389 { roff_unsupp
, NULL
, NULL
, 0 }, /* do */
390 { roff_ds
, NULL
, NULL
, 0 }, /* ds */
391 { roff_ds
, NULL
, NULL
, 0 }, /* ds1 */
392 { roff_unsupp
, NULL
, NULL
, 0 }, /* dwh */
393 { roff_unsupp
, NULL
, NULL
, 0 }, /* dt */
394 { roff_ec
, NULL
, NULL
, 0 }, /* ec */
395 { roff_unsupp
, NULL
, NULL
, 0 }, /* ecr */
396 { roff_unsupp
, NULL
, NULL
, 0 }, /* ecs */
397 { roff_cond
, roff_cond_text
, roff_cond_sub
, ROFFMAC_STRUCT
}, /* el */
398 { roff_unsupp
, NULL
, NULL
, 0 }, /* em */
399 { roff_EN
, NULL
, NULL
, 0 }, /* EN */
400 { roff_eo
, NULL
, NULL
, 0 }, /* eo */
401 { roff_unsupp
, NULL
, NULL
, 0 }, /* EP */
402 { roff_EQ
, NULL
, NULL
, 0 }, /* EQ */
403 { roff_line_ignore
, NULL
, NULL
, 0 }, /* errprint */
404 { roff_unsupp
, NULL
, NULL
, 0 }, /* ev */
405 { roff_unsupp
, NULL
, NULL
, 0 }, /* evc */
406 { roff_unsupp
, NULL
, NULL
, 0 }, /* ex */
407 { roff_line_ignore
, NULL
, NULL
, 0 }, /* fallback */
408 { roff_line_ignore
, NULL
, NULL
, 0 }, /* fam */
409 { roff_unsupp
, NULL
, NULL
, 0 }, /* fc */
410 { roff_unsupp
, NULL
, NULL
, 0 }, /* fchar */
411 { roff_line_ignore
, NULL
, NULL
, 0 }, /* fcolor */
412 { roff_line_ignore
, NULL
, NULL
, 0 }, /* fdeferlig */
413 { roff_line_ignore
, NULL
, NULL
, 0 }, /* feature */
414 { roff_line_ignore
, NULL
, NULL
, 0 }, /* fkern */
415 { roff_line_ignore
, NULL
, NULL
, 0 }, /* fl */
416 { roff_line_ignore
, NULL
, NULL
, 0 }, /* flig */
417 { roff_line_ignore
, NULL
, NULL
, 0 }, /* fp */
418 { roff_line_ignore
, NULL
, NULL
, 0 }, /* fps */
419 { roff_unsupp
, NULL
, NULL
, 0 }, /* fschar */
420 { roff_line_ignore
, NULL
, NULL
, 0 }, /* fspacewidth */
421 { roff_line_ignore
, NULL
, NULL
, 0 }, /* fspecial */
422 { roff_line_ignore
, NULL
, NULL
, 0 }, /* ftr */
423 { roff_line_ignore
, NULL
, NULL
, 0 }, /* fzoom */
424 { roff_line_ignore
, NULL
, NULL
, 0 }, /* gcolor */
425 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hc */
426 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hcode */
427 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hidechar */
428 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hla */
429 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hlm */
430 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hpf */
431 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hpfa */
432 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hpfcode */
433 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hw */
434 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hy */
435 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hylang */
436 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hylen */
437 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hym */
438 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hypp */
439 { roff_line_ignore
, NULL
, NULL
, 0 }, /* hys */
440 { roff_cond
, roff_cond_text
, roff_cond_sub
, ROFFMAC_STRUCT
}, /* ie */
441 { roff_cond
, roff_cond_text
, roff_cond_sub
, ROFFMAC_STRUCT
}, /* if */
442 { roff_block
, roff_block_text
, roff_block_sub
, 0 }, /* ig */
443 { roff_unsupp
, NULL
, NULL
, 0 }, /* index */
444 { roff_it
, NULL
, NULL
, 0 }, /* it */
445 { roff_unsupp
, NULL
, NULL
, 0 }, /* itc */
446 { roff_line_ignore
, NULL
, NULL
, 0 }, /* IX */
447 { roff_line_ignore
, NULL
, NULL
, 0 }, /* kern */
448 { roff_line_ignore
, NULL
, NULL
, 0 }, /* kernafter */
449 { roff_line_ignore
, NULL
, NULL
, 0 }, /* kernbefore */
450 { roff_line_ignore
, NULL
, NULL
, 0 }, /* kernpair */
451 { roff_unsupp
, NULL
, NULL
, 0 }, /* lc */
452 { roff_unsupp
, NULL
, NULL
, 0 }, /* lc_ctype */
453 { roff_unsupp
, NULL
, NULL
, 0 }, /* lds */
454 { roff_unsupp
, NULL
, NULL
, 0 }, /* length */
455 { roff_line_ignore
, NULL
, NULL
, 0 }, /* letadj */
456 { roff_insec
, NULL
, NULL
, 0 }, /* lf */
457 { roff_line_ignore
, NULL
, NULL
, 0 }, /* lg */
458 { roff_line_ignore
, NULL
, NULL
, 0 }, /* lhang */
459 { roff_unsupp
, NULL
, NULL
, 0 }, /* linetabs */
460 { roff_unsupp
, NULL
, NULL
, 0 }, /* lnr */
461 { roff_unsupp
, NULL
, NULL
, 0 }, /* lnrf */
462 { roff_unsupp
, NULL
, NULL
, 0 }, /* lpfx */
463 { roff_line_ignore
, NULL
, NULL
, 0 }, /* ls */
464 { roff_unsupp
, NULL
, NULL
, 0 }, /* lsm */
465 { roff_line_ignore
, NULL
, NULL
, 0 }, /* lt */
466 { roff_line_ignore
, NULL
, NULL
, 0 }, /* mediasize */
467 { roff_line_ignore
, NULL
, NULL
, 0 }, /* minss */
468 { roff_line_ignore
, NULL
, NULL
, 0 }, /* mk */
469 { roff_insec
, NULL
, NULL
, 0 }, /* mso */
470 { roff_line_ignore
, NULL
, NULL
, 0 }, /* na */
471 { roff_line_ignore
, NULL
, NULL
, 0 }, /* ne */
472 { roff_line_ignore
, NULL
, NULL
, 0 }, /* nh */
473 { roff_line_ignore
, NULL
, NULL
, 0 }, /* nhychar */
474 { roff_unsupp
, NULL
, NULL
, 0 }, /* nm */
475 { roff_unsupp
, NULL
, NULL
, 0 }, /* nn */
476 { roff_unsupp
, NULL
, NULL
, 0 }, /* nop */
477 { roff_nr
, NULL
, NULL
, 0 }, /* nr */
478 { roff_unsupp
, NULL
, NULL
, 0 }, /* nrf */
479 { roff_line_ignore
, NULL
, NULL
, 0 }, /* nroff */
480 { roff_line_ignore
, NULL
, NULL
, 0 }, /* ns */
481 { roff_insec
, NULL
, NULL
, 0 }, /* nx */
482 { roff_insec
, NULL
, NULL
, 0 }, /* open */
483 { roff_insec
, NULL
, NULL
, 0 }, /* opena */
484 { roff_line_ignore
, NULL
, NULL
, 0 }, /* os */
485 { roff_unsupp
, NULL
, NULL
, 0 }, /* output */
486 { roff_line_ignore
, NULL
, NULL
, 0 }, /* padj */
487 { roff_line_ignore
, NULL
, NULL
, 0 }, /* papersize */
488 { roff_line_ignore
, NULL
, NULL
, 0 }, /* pc */
489 { roff_line_ignore
, NULL
, NULL
, 0 }, /* pev */
490 { roff_insec
, NULL
, NULL
, 0 }, /* pi */
491 { roff_unsupp
, NULL
, NULL
, 0 }, /* PI */
492 { roff_line_ignore
, NULL
, NULL
, 0 }, /* pl */
493 { roff_line_ignore
, NULL
, NULL
, 0 }, /* pm */
494 { roff_line_ignore
, NULL
, NULL
, 0 }, /* pn */
495 { roff_line_ignore
, NULL
, NULL
, 0 }, /* pnr */
496 { roff_line_ignore
, NULL
, NULL
, 0 }, /* po */
497 { roff_line_ignore
, NULL
, NULL
, 0 }, /* ps */
498 { roff_unsupp
, NULL
, NULL
, 0 }, /* psbb */
499 { roff_unsupp
, NULL
, NULL
, 0 }, /* pshape */
500 { roff_insec
, NULL
, NULL
, 0 }, /* pso */
501 { roff_line_ignore
, NULL
, NULL
, 0 }, /* ptr */
502 { roff_line_ignore
, NULL
, NULL
, 0 }, /* pvs */
503 { roff_unsupp
, NULL
, NULL
, 0 }, /* rchar */
504 { roff_line_ignore
, NULL
, NULL
, 0 }, /* rd */
505 { roff_line_ignore
, NULL
, NULL
, 0 }, /* recursionlimit */
506 { roff_unsupp
, NULL
, NULL
, 0 }, /* return */
507 { roff_unsupp
, NULL
, NULL
, 0 }, /* rfschar */
508 { roff_line_ignore
, NULL
, NULL
, 0 }, /* rhang */
509 { roff_line_ignore
, NULL
, NULL
, 0 }, /* rj */
510 { roff_rm
, NULL
, NULL
, 0 }, /* rm */
511 { roff_unsupp
, NULL
, NULL
, 0 }, /* rn */
512 { roff_unsupp
, NULL
, NULL
, 0 }, /* rnn */
513 { roff_rr
, NULL
, NULL
, 0 }, /* rr */
514 { roff_line_ignore
, NULL
, NULL
, 0 }, /* rs */
515 { roff_line_ignore
, NULL
, NULL
, 0 }, /* rt */
516 { roff_unsupp
, NULL
, NULL
, 0 }, /* schar */
517 { roff_line_ignore
, NULL
, NULL
, 0 }, /* sentchar */
518 { roff_line_ignore
, NULL
, NULL
, 0 }, /* shc */
519 { roff_unsupp
, NULL
, NULL
, 0 }, /* shift */
520 { roff_line_ignore
, NULL
, NULL
, 0 }, /* sizes */
521 { roff_so
, NULL
, NULL
, 0 }, /* so */
522 { roff_line_ignore
, NULL
, NULL
, 0 }, /* spacewidth */
523 { roff_line_ignore
, NULL
, NULL
, 0 }, /* special */
524 { roff_line_ignore
, NULL
, NULL
, 0 }, /* spreadwarn */
525 { roff_line_ignore
, NULL
, NULL
, 0 }, /* ss */
526 { roff_line_ignore
, NULL
, NULL
, 0 }, /* sty */
527 { roff_unsupp
, NULL
, NULL
, 0 }, /* substring */
528 { roff_line_ignore
, NULL
, NULL
, 0 }, /* sv */
529 { roff_insec
, NULL
, NULL
, 0 }, /* sy */
530 { roff_T_
, NULL
, NULL
, 0 }, /* T& */
531 { roff_unsupp
, NULL
, NULL
, 0 }, /* tc */
532 { roff_TE
, NULL
, NULL
, 0 }, /* TE */
533 { roff_TH
, NULL
, NULL
, 0 }, /* TH */
534 { roff_line_ignore
, NULL
, NULL
, 0 }, /* tkf */
535 { roff_unsupp
, NULL
, NULL
, 0 }, /* tl */
536 { roff_line_ignore
, NULL
, NULL
, 0 }, /* tm */
537 { roff_line_ignore
, NULL
, NULL
, 0 }, /* tm1 */
538 { roff_line_ignore
, NULL
, NULL
, 0 }, /* tmc */
539 { roff_tr
, NULL
, NULL
, 0 }, /* tr */
540 { roff_line_ignore
, NULL
, NULL
, 0 }, /* track */
541 { roff_line_ignore
, NULL
, NULL
, 0 }, /* transchar */
542 { roff_insec
, NULL
, NULL
, 0 }, /* trf */
543 { roff_line_ignore
, NULL
, NULL
, 0 }, /* trimat */
544 { roff_unsupp
, NULL
, NULL
, 0 }, /* trin */
545 { roff_unsupp
, NULL
, NULL
, 0 }, /* trnt */
546 { roff_line_ignore
, NULL
, NULL
, 0 }, /* troff */
547 { roff_TS
, NULL
, NULL
, 0 }, /* TS */
548 { roff_line_ignore
, NULL
, NULL
, 0 }, /* uf */
549 { roff_line_ignore
, NULL
, NULL
, 0 }, /* ul */
550 { roff_unsupp
, NULL
, NULL
, 0 }, /* unformat */
551 { roff_line_ignore
, NULL
, NULL
, 0 }, /* unwatch */
552 { roff_line_ignore
, NULL
, NULL
, 0 }, /* unwatchn */
553 { roff_line_ignore
, NULL
, NULL
, 0 }, /* vpt */
554 { roff_line_ignore
, NULL
, NULL
, 0 }, /* vs */
555 { roff_line_ignore
, NULL
, NULL
, 0 }, /* warn */
556 { roff_line_ignore
, NULL
, NULL
, 0 }, /* warnscale */
557 { roff_line_ignore
, NULL
, NULL
, 0 }, /* watch */
558 { roff_line_ignore
, NULL
, NULL
, 0 }, /* watchlength */
559 { roff_line_ignore
, NULL
, NULL
, 0 }, /* watchn */
560 { roff_unsupp
, NULL
, NULL
, 0 }, /* wh */
561 { roff_unsupp
, NULL
, NULL
, 0 }, /* while */
562 { roff_insec
, NULL
, NULL
, 0 }, /* write */
563 { roff_insec
, NULL
, NULL
, 0 }, /* writec */
564 { roff_insec
, NULL
, NULL
, 0 }, /* writem */
565 { roff_line_ignore
, NULL
, NULL
, 0 }, /* xflag */
566 { roff_cblock
, NULL
, NULL
, 0 }, /* . */
567 { roff_userdef
, NULL
, NULL
, 0 }
570 /* not currently implemented: Ds em Eq LP Me PP pp Or Rd Sf SH */
571 const char *const __mdoc_reserved
[] = {
572 "Ac", "Ad", "An", "Ao", "Ap", "Aq", "Ar", "At",
573 "Bc", "Bd", "Bf", "Bk", "Bl", "Bo", "Bq",
574 "Brc", "Bro", "Brq", "Bsx", "Bt", "Bx",
575 "Cd", "Cm", "Db", "Dc", "Dd", "Dl", "Do", "Dq",
576 "Dt", "Dv", "Dx", "D1",
577 "Ec", "Ed", "Ef", "Ek", "El", "Em",
578 "En", "Eo", "Er", "Es", "Ev", "Ex",
579 "Fa", "Fc", "Fd", "Fl", "Fn", "Fo", "Fr", "Ft", "Fx",
580 "Hf", "Ic", "In", "It", "Lb", "Li", "Lk", "Lp",
581 "Ms", "Mt", "Nd", "Nm", "No", "Ns", "Nx",
582 "Oc", "Oo", "Op", "Os", "Ot", "Ox",
583 "Pa", "Pc", "Pf", "Po", "Pp", "Pq",
584 "Qc", "Ql", "Qo", "Qq", "Re", "Rs", "Rv",
585 "Sc", "Sh", "Sm", "So", "Sq",
586 "Ss", "St", "Sx", "Sy",
587 "Ta", "Tn", "Ud", "Ux", "Va", "Vt", "Xc", "Xo", "Xr",
588 "%A", "%B", "%C", "%D", "%I", "%J", "%N", "%O",
589 "%P", "%Q", "%R", "%T", "%U", "%V",
593 /* not currently implemented: BT DE DS ME MT PT SY TQ YS */
594 const char *const __man_reserved
[] = {
595 "AT", "B", "BI", "BR", "DT",
596 "EE", "EN", "EQ", "EX", "HP", "I", "IB", "IP", "IR",
597 "LP", "OP", "P", "PD", "PP",
598 "R", "RB", "RE", "RI", "RS", "SB", "SH", "SM", "SS",
599 "TE", "TH", "TP", "TS", "T&", "UC", "UE", "UR",
603 /* Array of injected predefined strings. */
604 #define PREDEFS_MAX 38
605 static const struct predef predefs
[PREDEFS_MAX
] = {
606 #include "predefs.in"
609 static int roffce_lines
; /* number of input lines to center */
610 static struct roff_node
*roffce_node
; /* active request */
611 static int roffit_lines
; /* number of lines to delay */
612 static char *roffit_macro
; /* nil-terminated macro line */
615 /* --- request table ------------------------------------------------------ */
618 roffhash_alloc(enum roff_tok mintok
, enum roff_tok maxtok
)
626 htab
= mandoc_malloc(sizeof(*htab
));
627 mandoc_ohash_init(htab
, 8, offsetof(struct roffreq
, name
));
629 for (tok
= mintok
; tok
< maxtok
; tok
++) {
630 if (roff_name
[tok
] == NULL
)
632 sz
= strlen(roff_name
[tok
]);
633 req
= mandoc_malloc(sizeof(*req
) + sz
+ 1);
635 memcpy(req
->name
, roff_name
[tok
], sz
+ 1);
636 slot
= ohash_qlookup(htab
, req
->name
);
637 ohash_insert(htab
, slot
, req
);
643 roffhash_free(struct ohash
*htab
)
650 for (req
= ohash_first(htab
, &slot
); req
!= NULL
;
651 req
= ohash_next(htab
, &slot
))
658 roffhash_find(struct ohash
*htab
, const char *name
, size_t sz
)
665 req
= ohash_find(htab
, ohash_qlookupi(htab
, name
, &end
));
667 req
= ohash_find(htab
, ohash_qlookup(htab
, name
));
668 return req
== NULL
? TOKEN_NONE
: req
->tok
;
671 /* --- stack of request blocks -------------------------------------------- */
674 * Pop the current node off of the stack of roff instructions currently
678 roffnode_pop(struct roff
*r
)
685 r
->last
= r
->last
->parent
;
692 * Push a roff node onto the instruction stack. This must later be
693 * removed with roffnode_pop().
696 roffnode_push(struct roff
*r
, enum roff_tok tok
, const char *name
,
701 p
= mandoc_calloc(1, sizeof(struct roffnode
));
704 p
->name
= mandoc_strdup(name
);
708 p
->rule
= p
->parent
? p
->parent
->rule
: 0;
713 /* --- roff parser state data management ---------------------------------- */
716 roff_free1(struct roff
*r
)
718 struct tbl_node
*tbl
;
722 while (NULL
!= (tbl
= r
->first_tbl
)) {
723 r
->first_tbl
= tbl
->next
;
726 r
->first_tbl
= r
->last_tbl
= r
->tbl
= NULL
;
728 while (NULL
!= (e
= r
->first_eqn
)) {
729 r
->first_eqn
= e
->next
;
732 r
->first_eqn
= r
->last_eqn
= r
->eqn
= NULL
;
742 roff_freereg(r
->regtab
);
745 roff_freestr(r
->strtab
);
746 roff_freestr(r
->xmbtab
);
747 r
->strtab
= r
->xmbtab
= NULL
;
750 for (i
= 0; i
< 128; i
++)
757 roff_reset(struct roff
*r
)
760 r
->format
= r
->options
& (MPARSE_MDOC
| MPARSE_MAN
);
766 roff_free(struct roff
*r
)
769 roffhash_free(r
->reqtab
);
774 roff_alloc(struct mparse
*parse
, int options
)
778 r
= mandoc_calloc(1, sizeof(struct roff
));
780 r
->reqtab
= roffhash_alloc(0, ROFF_USERDEF
);
781 r
->options
= options
;
782 r
->format
= options
& (MPARSE_MDOC
| MPARSE_MAN
);
788 /* --- syntax tree state data management ---------------------------------- */
791 roff_man_free1(struct roff_man
*man
)
794 if (man
->first
!= NULL
)
795 roff_node_delete(man
, man
->first
);
796 free(man
->meta
.msec
);
799 free(man
->meta
.arch
);
800 free(man
->meta
.title
);
801 free(man
->meta
.name
);
802 free(man
->meta
.date
);
806 roff_man_alloc1(struct roff_man
*man
)
809 memset(&man
->meta
, 0, sizeof(man
->meta
));
810 man
->first
= mandoc_calloc(1, sizeof(*man
->first
));
811 man
->first
->type
= ROFFT_ROOT
;
812 man
->last
= man
->first
;
815 man
->macroset
= MACROSET_NONE
;
816 man
->lastsec
= man
->lastnamed
= SEC_NONE
;
817 man
->next
= ROFF_NEXT_CHILD
;
821 roff_man_reset(struct roff_man
*man
)
825 roff_man_alloc1(man
);
829 roff_man_free(struct roff_man
*man
)
837 roff_man_alloc(struct roff
*roff
, struct mparse
*parse
,
838 const char *defos
, int quick
)
840 struct roff_man
*man
;
842 man
= mandoc_calloc(1, sizeof(*man
));
847 roff_man_alloc1(man
);
852 /* --- syntax tree handling ----------------------------------------------- */
855 roff_node_alloc(struct roff_man
*man
, int line
, int pos
,
856 enum roff_type type
, int tok
)
860 n
= mandoc_calloc(1, sizeof(*n
));
865 n
->sec
= man
->lastsec
;
867 if (man
->flags
& MDOC_SYNOPSIS
)
868 n
->flags
|= NODE_SYNPRETTY
;
870 n
->flags
&= ~NODE_SYNPRETTY
;
871 if (man
->flags
& MDOC_NEWLINE
)
872 n
->flags
|= NODE_LINE
;
873 man
->flags
&= ~MDOC_NEWLINE
;
879 roff_node_append(struct roff_man
*man
, struct roff_node
*n
)
883 case ROFF_NEXT_SIBLING
:
884 if (man
->last
->next
!= NULL
) {
885 n
->next
= man
->last
->next
;
886 man
->last
->next
->prev
= n
;
888 man
->last
->parent
->last
= n
;
891 n
->parent
= man
->last
->parent
;
893 case ROFF_NEXT_CHILD
:
894 if (man
->last
->child
!= NULL
) {
895 n
->next
= man
->last
->child
;
896 man
->last
->child
->prev
= n
;
899 man
->last
->child
= n
;
900 n
->parent
= man
->last
;
912 if (n
->end
!= ENDBODY_NOT
)
924 * Copy over the normalised-data pointer of our parent. Not
925 * everybody has one, but copying a null pointer is fine.
928 n
->norm
= n
->parent
->norm
;
929 assert(n
->parent
->type
== ROFFT_BLOCK
);
933 roff_word_alloc(struct roff_man
*man
, int line
, int pos
, const char *word
)
937 n
= roff_node_alloc(man
, line
, pos
, ROFFT_TEXT
, TOKEN_NONE
);
938 n
->string
= roff_strdup(man
->roff
, word
);
939 roff_node_append(man
, n
);
940 n
->flags
|= NODE_VALID
| NODE_ENDED
;
941 man
->next
= ROFF_NEXT_SIBLING
;
945 roff_word_append(struct roff_man
*man
, const char *word
)
948 char *addstr
, *newstr
;
951 addstr
= roff_strdup(man
->roff
, word
);
952 mandoc_asprintf(&newstr
, "%s %s", n
->string
, addstr
);
956 man
->next
= ROFF_NEXT_SIBLING
;
960 roff_elem_alloc(struct roff_man
*man
, int line
, int pos
, int tok
)
964 n
= roff_node_alloc(man
, line
, pos
, ROFFT_ELEM
, tok
);
965 roff_node_append(man
, n
);
966 man
->next
= ROFF_NEXT_CHILD
;
970 roff_block_alloc(struct roff_man
*man
, int line
, int pos
, int tok
)
974 n
= roff_node_alloc(man
, line
, pos
, ROFFT_BLOCK
, tok
);
975 roff_node_append(man
, n
);
976 man
->next
= ROFF_NEXT_CHILD
;
981 roff_head_alloc(struct roff_man
*man
, int line
, int pos
, int tok
)
985 n
= roff_node_alloc(man
, line
, pos
, ROFFT_HEAD
, tok
);
986 roff_node_append(man
, n
);
987 man
->next
= ROFF_NEXT_CHILD
;
992 roff_body_alloc(struct roff_man
*man
, int line
, int pos
, int tok
)
996 n
= roff_node_alloc(man
, line
, pos
, ROFFT_BODY
, tok
);
997 roff_node_append(man
, n
);
998 man
->next
= ROFF_NEXT_CHILD
;
1003 roff_addeqn(struct roff_man
*man
, const struct eqn
*eqn
)
1005 struct roff_node
*n
;
1007 n
= roff_node_alloc(man
, eqn
->ln
, eqn
->pos
, ROFFT_EQN
, TOKEN_NONE
);
1009 if (eqn
->ln
> man
->last
->line
)
1010 n
->flags
|= NODE_LINE
;
1011 roff_node_append(man
, n
);
1012 man
->next
= ROFF_NEXT_SIBLING
;
1016 roff_addtbl(struct roff_man
*man
, const struct tbl_span
*tbl
)
1018 struct roff_node
*n
;
1020 if (man
->macroset
== MACROSET_MAN
)
1021 man_breakscope(man
, ROFF_TS
);
1022 n
= roff_node_alloc(man
, tbl
->line
, 0, ROFFT_TBL
, TOKEN_NONE
);
1024 roff_node_append(man
, n
);
1025 n
->flags
|= NODE_VALID
| NODE_ENDED
;
1026 man
->next
= ROFF_NEXT_SIBLING
;
1030 roff_node_unlink(struct roff_man
*man
, struct roff_node
*n
)
1033 /* Adjust siblings. */
1036 n
->prev
->next
= n
->next
;
1038 n
->next
->prev
= n
->prev
;
1040 /* Adjust parent. */
1042 if (n
->parent
!= NULL
) {
1043 if (n
->parent
->child
== n
)
1044 n
->parent
->child
= n
->next
;
1045 if (n
->parent
->last
== n
)
1046 n
->parent
->last
= n
->prev
;
1049 /* Adjust parse point. */
1053 if (man
->last
== n
) {
1054 if (n
->prev
== NULL
) {
1055 man
->last
= n
->parent
;
1056 man
->next
= ROFF_NEXT_CHILD
;
1058 man
->last
= n
->prev
;
1059 man
->next
= ROFF_NEXT_SIBLING
;
1062 if (man
->first
== n
)
1067 roff_node_free(struct roff_node
*n
)
1070 if (n
->args
!= NULL
)
1071 mdoc_argv_free(n
->args
);
1072 if (n
->type
== ROFFT_BLOCK
|| n
->type
== ROFFT_ELEM
)
1079 roff_node_delete(struct roff_man
*man
, struct roff_node
*n
)
1082 while (n
->child
!= NULL
)
1083 roff_node_delete(man
, n
->child
);
1084 roff_node_unlink(man
, n
);
1089 deroff(char **dest
, const struct roff_node
*n
)
1094 if (n
->type
!= ROFFT_TEXT
) {
1095 for (n
= n
->child
; n
!= NULL
; n
= n
->next
)
1100 /* Skip leading whitespace. */
1102 for (cp
= n
->string
; *cp
!= '\0'; cp
++) {
1103 if (cp
[0] == '\\' && cp
[1] != '\0' &&
1104 strchr(" %&0^|~", cp
[1]) != NULL
)
1106 else if ( ! isspace((unsigned char)*cp
))
1110 /* Skip trailing backslash. */
1113 if (sz
> 0 && cp
[sz
- 1] == '\\')
1116 /* Skip trailing whitespace. */
1119 if ( ! isspace((unsigned char)cp
[sz
-1]))
1122 /* Skip empty strings. */
1127 if (*dest
== NULL
) {
1128 *dest
= mandoc_strndup(cp
, sz
);
1132 mandoc_asprintf(&cp
, "%s %*s", *dest
, (int)sz
, cp
);
1137 /* --- main functions of the roff parser ---------------------------------- */
1140 * In the current line, expand escape sequences that tend to get
1141 * used in numerical expressions and conditional requests.
1142 * Also check the syntax of the remaining escape sequences.
1145 roff_res(struct roff
*r
, struct buf
*buf
, int ln
, int pos
)
1147 char ubuf
[24]; /* buffer to print the number */
1148 const char *start
; /* start of the string to process */
1149 char *stesc
; /* start of an escape sequence ('\\') */
1150 const char *stnam
; /* start of the name, after "[(*" */
1151 const char *cp
; /* end of the name, e.g. before ']' */
1152 const char *res
; /* the string to be substituted */
1153 char *nbuf
; /* new buffer to copy buf->buf to */
1154 size_t maxl
; /* expected length of the escape name */
1155 size_t naml
; /* actual length of the escape name */
1156 enum mandoc_esc esc
; /* type of the escape sequence */
1157 int inaml
; /* length returned from mandoc_escape() */
1158 int expand_count
; /* to avoid infinite loops */
1159 int npos
; /* position in numeric expression */
1160 int arg_complete
; /* argument not interrupted by eol */
1161 int done
; /* no more input available */
1162 char term
; /* character terminating the escape */
1164 /* Search forward for comments. */
1167 start
= buf
->buf
+ pos
;
1168 for (stesc
= buf
->buf
+ pos
; *stesc
!= '\0'; stesc
++) {
1169 if (stesc
[0] != r
->escape
|| stesc
[1] == '\0')
1172 if (*stesc
!= '"' && *stesc
!= '#')
1174 cp
= strchr(stesc
--, '\0') - 1;
1179 if (*cp
== ' ' || *cp
== '\t')
1180 mandoc_msg(MANDOCERR_SPACE_EOL
, r
->parse
,
1181 ln
, cp
- buf
->buf
, NULL
);
1182 while (stesc
> start
&& stesc
[-1] == ' ')
1191 /* Notice the end of the input. */
1193 if (*stesc
== '\n') {
1199 while (stesc
>= start
) {
1201 /* Search backwards for the next backslash. */
1203 if (*stesc
!= r
->escape
) {
1204 if (*stesc
== '\\') {
1206 buf
->sz
= mandoc_asprintf(&nbuf
, "%s\\e%s",
1207 buf
->buf
, stesc
+ 1) + 1;
1209 stesc
= nbuf
+ (stesc
- buf
->buf
);
1217 /* If it is escaped, skip it. */
1219 for (cp
= stesc
- 1; cp
>= start
; cp
--)
1220 if (*cp
!= r
->escape
)
1223 if ((stesc
- cp
) % 2 == 0) {
1227 } else if (stesc
[1] != '\0') {
1237 /* Decide whether to expand or to check only. */
1253 esc
= mandoc_escape(&cp
, &stnam
, &inaml
);
1254 if (esc
== ESCAPE_ERROR
||
1255 (esc
== ESCAPE_SPECIAL
&&
1256 mchars_spec2cp(stnam
, inaml
) < 0))
1257 mandoc_vmsg(MANDOCERR_ESC_BAD
,
1258 r
->parse
, ln
, (int)(stesc
- buf
->buf
),
1259 "%.*s", (int)(cp
- stesc
), stesc
);
1264 if (EXPAND_LIMIT
< ++expand_count
) {
1265 mandoc_msg(MANDOCERR_ROFFLOOP
, r
->parse
,
1266 ln
, (int)(stesc
- buf
->buf
), NULL
);
1271 * The third character decides the length
1272 * of the name of the string or register.
1273 * Save a pointer to the name.
1300 /* Advance to the end of the name. */
1304 while (maxl
== 0 || naml
< maxl
) {
1306 mandoc_msg(MANDOCERR_ESC_BAD
, r
->parse
,
1307 ln
, (int)(stesc
- buf
->buf
), stesc
);
1311 if (maxl
== 0 && *cp
== term
) {
1315 if (*cp
++ != '\\' || stesc
[1] != 'w') {
1319 switch (mandoc_escape(&cp
, NULL
, NULL
)) {
1320 case ESCAPE_SPECIAL
:
1321 case ESCAPE_UNICODE
:
1322 case ESCAPE_NUMBERED
:
1323 case ESCAPE_OVERSTRIKE
:
1332 * Retrieve the replacement string; if it is
1333 * undefined, resume searching for escapes.
1339 res
= roff_getstrn(r
, stnam
, naml
);
1343 ubuf
[0] = arg_complete
&&
1344 roff_evalnum(r
, ln
, stnam
, &npos
,
1345 NULL
, ROFFNUM_SCALE
) &&
1346 stnam
+ npos
+ 1 == cp
? '1' : '0';
1351 (void)snprintf(ubuf
, sizeof(ubuf
), "%d",
1352 roff_getregn(r
, stnam
, naml
));
1357 /* use even incomplete args */
1358 (void)snprintf(ubuf
, sizeof(ubuf
), "%d",
1364 mandoc_vmsg(MANDOCERR_STR_UNDEF
,
1365 r
->parse
, ln
, (int)(stesc
- buf
->buf
),
1366 "%.*s", (int)naml
, stnam
);
1368 } else if (buf
->sz
+ strlen(res
) > SHRT_MAX
) {
1369 mandoc_msg(MANDOCERR_ROFFLOOP
, r
->parse
,
1370 ln
, (int)(stesc
- buf
->buf
), NULL
);
1374 /* Replace the escape sequence by the string. */
1377 buf
->sz
= mandoc_asprintf(&nbuf
, "%s%s%s",
1378 buf
->buf
, res
, cp
) + 1;
1380 /* Prepare for the next replacement. */
1383 stesc
= nbuf
+ (stesc
- buf
->buf
) + strlen(res
);
1391 * Process text streams.
1394 roff_parsetext(struct roff
*r
, struct buf
*buf
, int pos
, int *offs
)
1400 enum mandoc_esc esc
;
1402 /* Spring the input line trap. */
1404 if (roffit_lines
== 1) {
1405 isz
= mandoc_asprintf(&p
, "%s\n.%s", buf
->buf
, roffit_macro
);
1412 return ROFF_REPARSE
;
1413 } else if (roffit_lines
> 1)
1416 if (roffce_node
!= NULL
&& buf
->buf
[pos
] != '\0') {
1417 if (roffce_lines
< 1) {
1418 r
->man
->last
= roffce_node
;
1419 r
->man
->next
= ROFF_NEXT_SIBLING
;
1426 /* Convert all breakable hyphens into ASCII_HYPH. */
1428 start
= p
= buf
->buf
+ pos
;
1430 while (*p
!= '\0') {
1431 sz
= strcspn(p
, "-\\");
1438 /* Skip over escapes. */
1440 esc
= mandoc_escape((const char **)&p
, NULL
, NULL
);
1441 if (esc
== ESCAPE_ERROR
)
1446 } else if (p
== start
) {
1451 if (isalpha((unsigned char)p
[-1]) &&
1452 isalpha((unsigned char)p
[1]))
1460 roff_parseln(struct roff
*r
, int ln
, struct buf
*buf
, int *offs
)
1464 int pos
; /* parse point */
1465 int spos
; /* saved parse point for messages */
1466 int ppos
; /* original offset in buf->buf */
1467 int ctl
; /* macro line (boolean) */
1471 /* Handle in-line equation delimiters. */
1473 if (r
->tbl
== NULL
&&
1474 r
->last_eqn
!= NULL
&& r
->last_eqn
->delim
&&
1475 (r
->eqn
== NULL
|| r
->eqn_inline
)) {
1476 e
= roff_eqndelim(r
, buf
, pos
);
1477 if (e
== ROFF_REPARSE
)
1479 assert(e
== ROFF_CONT
);
1482 /* Expand some escape sequences. */
1484 e
= roff_res(r
, buf
, ln
, pos
);
1485 if (e
== ROFF_IGN
|| e
== ROFF_APPEND
)
1487 assert(e
== ROFF_CONT
);
1489 ctl
= roff_getcontrol(r
, buf
->buf
, &pos
);
1492 * First, if a scope is open and we're not a macro, pass the
1493 * text through the macro's filter.
1494 * Equations process all content themselves.
1495 * Tables process almost all content themselves, but we want
1496 * to warn about macros before passing it there.
1499 if (r
->last
!= NULL
&& ! ctl
) {
1501 e
= (*roffs
[t
].text
)(r
, t
, buf
, ln
, pos
, pos
, offs
);
1504 assert(e
== ROFF_CONT
);
1507 return eqn_read(&r
->eqn
, ln
, buf
->buf
, ppos
, offs
);
1508 if (r
->tbl
!= NULL
&& ( ! ctl
|| buf
->buf
[pos
] == '\0'))
1509 return tbl_read(r
->tbl
, ln
, buf
->buf
, ppos
);
1511 return roff_parsetext(r
, buf
, pos
, offs
);
1513 /* Skip empty request lines. */
1515 if (buf
->buf
[pos
] == '"') {
1516 mandoc_msg(MANDOCERR_COMMENT_BAD
, r
->parse
,
1519 } else if (buf
->buf
[pos
] == '\0')
1523 * If a scope is open, go to the child handler for that macro,
1524 * as it may want to preprocess before doing anything with it.
1525 * Don't do so if an equation is open.
1530 return (*roffs
[t
].sub
)(r
, t
, buf
, ln
, ppos
, pos
, offs
);
1533 /* No scope is open. This is a new request or macro. */
1536 t
= roff_parse(r
, buf
->buf
, &pos
, ln
, ppos
);
1538 /* Tables ignore most macros. */
1540 if (r
->tbl
!= NULL
&& (t
== TOKEN_NONE
|| t
== ROFF_TS
)) {
1541 mandoc_msg(MANDOCERR_TBLMACRO
, r
->parse
,
1542 ln
, pos
, buf
->buf
+ spos
);
1545 while (buf
->buf
[pos
] != '\0' && buf
->buf
[pos
] != ' ')
1547 while (buf
->buf
[pos
] == ' ')
1549 return tbl_read(r
->tbl
, ln
, buf
->buf
, pos
);
1552 /* For now, let high level macros abort .ce mode. */
1554 if (ctl
&& roffce_node
!= NULL
&&
1555 (t
== TOKEN_NONE
|| t
== ROFF_EQ
|| t
== ROFF_TS
)) {
1556 r
->man
->last
= roffce_node
;
1557 r
->man
->next
= ROFF_NEXT_SIBLING
;
1563 * This is neither a roff request nor a user-defined macro.
1564 * Let the standard macro set parsers handle it.
1567 if (t
== TOKEN_NONE
)
1570 /* Execute a roff request or a user defined macro. */
1572 return (*roffs
[t
].proc
)(r
, t
, buf
, ln
, spos
, pos
, offs
);
1576 roff_endparse(struct roff
*r
)
1580 mandoc_msg(MANDOCERR_BLK_NOEND
, r
->parse
,
1581 r
->last
->line
, r
->last
->col
,
1582 roff_name
[r
->last
->tok
]);
1585 mandoc_msg(MANDOCERR_BLK_NOEND
, r
->parse
,
1586 r
->eqn
->eqn
.ln
, r
->eqn
->eqn
.pos
, "EQ");
1591 mandoc_msg(MANDOCERR_BLK_NOEND
, r
->parse
,
1592 r
->tbl
->line
, r
->tbl
->pos
, "TS");
1598 * Parse a roff node's type from the input buffer. This must be in the
1599 * form of ".foo xxx" in the usual way.
1601 static enum roff_tok
1602 roff_parse(struct roff
*r
, char *buf
, int *pos
, int ln
, int ppos
)
1611 if ('\0' == *cp
|| '"' == *cp
|| '\t' == *cp
|| ' ' == *cp
)
1615 maclen
= roff_getname(r
, &cp
, ln
, ppos
);
1617 t
= (r
->current_string
= roff_getstrn(r
, mac
, maclen
))
1618 ? ROFF_USERDEF
: roffhash_find(r
->reqtab
, mac
, maclen
);
1620 if (t
!= TOKEN_NONE
)
1626 /* --- handling of request blocks ----------------------------------------- */
1629 roff_cblock(ROFF_ARGS
)
1633 * A block-close `..' should only be invoked as a child of an
1634 * ignore macro, otherwise raise a warning and just ignore it.
1637 if (r
->last
== NULL
) {
1638 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, r
->parse
,
1643 switch (r
->last
->tok
) {
1645 /* ROFF_am1 is remapped to ROFF_am in roff_block(). */
1648 /* ROFF_de1 is remapped to ROFF_de in roff_block(). */
1653 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, r
->parse
,
1658 if (buf
->buf
[pos
] != '\0')
1659 mandoc_vmsg(MANDOCERR_ARG_SKIP
, r
->parse
, ln
, pos
,
1660 ".. %s", buf
->buf
+ pos
);
1663 roffnode_cleanscope(r
);
1669 roffnode_cleanscope(struct roff
*r
)
1673 if (--r
->last
->endspan
!= 0)
1680 roff_ccond(struct roff
*r
, int ln
, int ppos
)
1683 if (NULL
== r
->last
) {
1684 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, r
->parse
,
1689 switch (r
->last
->tok
) {
1695 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, r
->parse
,
1700 if (r
->last
->endspan
> -1) {
1701 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, r
->parse
,
1707 roffnode_cleanscope(r
);
1712 roff_block(ROFF_ARGS
)
1718 /* Ignore groff compatibility mode for now. */
1720 if (tok
== ROFF_de1
)
1722 else if (tok
== ROFF_dei1
)
1724 else if (tok
== ROFF_am1
)
1726 else if (tok
== ROFF_ami1
)
1729 /* Parse the macro name argument. */
1731 cp
= buf
->buf
+ pos
;
1732 if (tok
== ROFF_ig
) {
1737 namesz
= roff_getname(r
, &cp
, ln
, ppos
);
1738 iname
[namesz
] = '\0';
1741 /* Resolve the macro name argument if it is indirect. */
1743 if (namesz
&& (tok
== ROFF_dei
|| tok
== ROFF_ami
)) {
1744 if ((name
= roff_getstrn(r
, iname
, namesz
)) == NULL
) {
1745 mandoc_vmsg(MANDOCERR_STR_UNDEF
,
1746 r
->parse
, ln
, (int)(iname
- buf
->buf
),
1747 "%.*s", (int)namesz
, iname
);
1750 namesz
= strlen(name
);
1754 if (namesz
== 0 && tok
!= ROFF_ig
) {
1755 mandoc_msg(MANDOCERR_REQ_EMPTY
, r
->parse
,
1756 ln
, ppos
, roff_name
[tok
]);
1760 roffnode_push(r
, tok
, name
, ln
, ppos
);
1763 * At the beginning of a `de' macro, clear the existing string
1764 * with the same name, if there is one. New content will be
1765 * appended from roff_block_text() in multiline mode.
1768 if (tok
== ROFF_de
|| tok
== ROFF_dei
)
1769 roff_setstrn(&r
->strtab
, name
, namesz
, "", 0, 0);
1774 /* Get the custom end marker. */
1777 namesz
= roff_getname(r
, &cp
, ln
, ppos
);
1779 /* Resolve the end marker if it is indirect. */
1781 if (namesz
&& (tok
== ROFF_dei
|| tok
== ROFF_ami
)) {
1782 if ((name
= roff_getstrn(r
, iname
, namesz
)) == NULL
) {
1783 mandoc_vmsg(MANDOCERR_STR_UNDEF
,
1784 r
->parse
, ln
, (int)(iname
- buf
->buf
),
1785 "%.*s", (int)namesz
, iname
);
1788 namesz
= strlen(name
);
1793 r
->last
->end
= mandoc_strndup(name
, namesz
);
1796 mandoc_vmsg(MANDOCERR_ARG_EXCESS
, r
->parse
,
1797 ln
, pos
, ".%s ... %s", roff_name
[tok
], cp
);
1803 roff_block_sub(ROFF_ARGS
)
1809 * First check whether a custom macro exists at this level. If
1810 * it does, then check against it. This is some of groff's
1811 * stranger behaviours. If we encountered a custom end-scope
1812 * tag and that tag also happens to be a "real" macro, then we
1813 * need to try interpreting it again as a real macro. If it's
1814 * not, then return ignore. Else continue.
1818 for (i
= pos
, j
= 0; r
->last
->end
[j
]; j
++, i
++)
1819 if (buf
->buf
[i
] != r
->last
->end
[j
])
1822 if (r
->last
->end
[j
] == '\0' &&
1823 (buf
->buf
[i
] == '\0' ||
1824 buf
->buf
[i
] == ' ' ||
1825 buf
->buf
[i
] == '\t')) {
1827 roffnode_cleanscope(r
);
1829 while (buf
->buf
[i
] == ' ' || buf
->buf
[i
] == '\t')
1833 if (roff_parse(r
, buf
->buf
, &pos
, ln
, ppos
) !=
1841 * If we have no custom end-query or lookup failed, then try
1842 * pulling it out of the hashtable.
1845 t
= roff_parse(r
, buf
->buf
, &pos
, ln
, ppos
);
1847 if (t
!= ROFF_cblock
) {
1849 roff_setstr(r
, r
->last
->name
, buf
->buf
+ ppos
, 2);
1853 return (*roffs
[t
].proc
)(r
, t
, buf
, ln
, ppos
, pos
, offs
);
1857 roff_block_text(ROFF_ARGS
)
1861 roff_setstr(r
, r
->last
->name
, buf
->buf
+ pos
, 2);
1867 roff_cond_sub(ROFF_ARGS
)
1874 roffnode_cleanscope(r
);
1875 t
= roff_parse(r
, buf
->buf
, &pos
, ln
, ppos
);
1878 * Fully handle known macros when they are structurally
1879 * required or when the conditional evaluated to true.
1882 if (t
!= TOKEN_NONE
&& (rr
|| roffs
[t
].flags
& ROFFMAC_STRUCT
))
1883 return (*roffs
[t
].proc
)(r
, t
, buf
, ln
, ppos
, pos
, offs
);
1886 * If `\}' occurs on a macro line without a preceding macro,
1887 * drop the line completely.
1890 ep
= buf
->buf
+ pos
;
1891 if (ep
[0] == '\\' && ep
[1] == '}')
1894 /* Always check for the closing delimiter `\}'. */
1896 while ((ep
= strchr(ep
, '\\')) != NULL
) {
1897 if (*(++ep
) == '}') {
1899 roff_ccond(r
, ln
, ep
- buf
->buf
- 1);
1904 return rr
? ROFF_CONT
: ROFF_IGN
;
1908 roff_cond_text(ROFF_ARGS
)
1914 roffnode_cleanscope(r
);
1916 ep
= buf
->buf
+ pos
;
1917 while ((ep
= strchr(ep
, '\\')) != NULL
) {
1918 if (*(++ep
) == '}') {
1920 roff_ccond(r
, ln
, ep
- buf
->buf
- 1);
1925 return rr
? ROFF_CONT
: ROFF_IGN
;
1928 /* --- handling of numeric and conditional expressions -------------------- */
1931 * Parse a single signed integer number. Stop at the first non-digit.
1932 * If there is at least one digit, return success and advance the
1933 * parse point, else return failure and let the parse point unchanged.
1934 * Ignore overflows, treat them just like the C language.
1937 roff_getnum(const char *v
, int *pos
, int *res
, int flags
)
1939 int myres
, scaled
, n
, p
;
1946 if (n
|| v
[p
] == '+')
1949 if (flags
& ROFFNUM_WHITE
)
1950 while (isspace((unsigned char)v
[p
]))
1953 for (*res
= 0; isdigit((unsigned char)v
[p
]); p
++)
1954 *res
= 10 * *res
+ v
[p
] - '0';
1961 /* Each number may be followed by one optional scaling unit. */
1965 scaled
= *res
* 65536;
1968 scaled
= *res
* 240;
1971 scaled
= *res
* 240 / 2.54;
1982 scaled
= *res
* 10 / 3;
1988 scaled
= *res
* 6 / 25;
1995 if (flags
& ROFFNUM_SCALE
)
2003 * Evaluate a string comparison condition.
2004 * The first character is the delimiter.
2005 * Succeed if the string up to its second occurrence
2006 * matches the string up to its third occurence.
2007 * Advance the cursor after the third occurrence
2008 * or lacking that, to the end of the line.
2011 roff_evalstrcond(const char *v
, int *pos
)
2013 const char *s1
, *s2
, *s3
;
2017 s1
= v
+ *pos
; /* initial delimiter */
2018 s2
= s1
+ 1; /* for scanning the first string */
2019 s3
= strchr(s2
, *s1
); /* for scanning the second string */
2021 if (NULL
== s3
) /* found no middle delimiter */
2024 while ('\0' != *++s3
) {
2025 if (*s2
!= *s3
) { /* mismatch */
2026 s3
= strchr(s3
, *s1
);
2029 if (*s3
== *s1
) { /* found the final delimiter */
2038 s3
= strchr(s2
, '\0');
2039 else if (*s3
!= '\0')
2046 * Evaluate an optionally negated single character, numerical,
2047 * or string condition.
2050 roff_evalcond(struct roff
*r
, int ln
, char *v
, int *pos
)
2054 int number
, savepos
, wanttrue
;
2056 if ('!' == v
[*pos
]) {
2077 cp
= name
= v
+ ++*pos
;
2078 sz
= roff_getname(r
, &cp
, ln
, *pos
);
2080 return (sz
&& roff_hasregn(r
, name
, sz
)) == wanttrue
;
2086 if (roff_evalnum(r
, ln
, v
, pos
, &number
, ROFFNUM_SCALE
))
2087 return (number
> 0) == wanttrue
;
2088 else if (*pos
== savepos
)
2089 return roff_evalstrcond(v
, pos
) == wanttrue
;
2095 roff_line_ignore(ROFF_ARGS
)
2102 roff_insec(ROFF_ARGS
)
2105 mandoc_msg(MANDOCERR_REQ_INSEC
, r
->parse
,
2106 ln
, ppos
, roff_name
[tok
]);
2111 roff_unsupp(ROFF_ARGS
)
2114 mandoc_msg(MANDOCERR_REQ_UNSUPP
, r
->parse
,
2115 ln
, ppos
, roff_name
[tok
]);
2120 roff_cond(ROFF_ARGS
)
2123 roffnode_push(r
, tok
, NULL
, ln
, ppos
);
2126 * An `.el' has no conditional body: it will consume the value
2127 * of the current rstack entry set in prior `ie' calls or
2130 * If we're not an `el', however, then evaluate the conditional.
2133 r
->last
->rule
= tok
== ROFF_el
?
2134 (r
->rstackpos
< 0 ? 0 : r
->rstack
[r
->rstackpos
--]) :
2135 roff_evalcond(r
, ln
, buf
->buf
, &pos
);
2138 * An if-else will put the NEGATION of the current evaluated
2139 * conditional into the stack of rules.
2142 if (tok
== ROFF_ie
) {
2143 if (r
->rstackpos
+ 1 == r
->rstacksz
) {
2145 r
->rstack
= mandoc_reallocarray(r
->rstack
,
2146 r
->rstacksz
, sizeof(int));
2148 r
->rstack
[++r
->rstackpos
] = !r
->last
->rule
;
2151 /* If the parent has false as its rule, then so do we. */
2153 if (r
->last
->parent
&& !r
->last
->parent
->rule
)
2158 * If there is nothing on the line after the conditional,
2159 * not even whitespace, use next-line scope.
2162 if (buf
->buf
[pos
] == '\0') {
2163 r
->last
->endspan
= 2;
2167 while (buf
->buf
[pos
] == ' ')
2170 /* An opening brace requests multiline scope. */
2172 if (buf
->buf
[pos
] == '\\' && buf
->buf
[pos
+ 1] == '{') {
2173 r
->last
->endspan
= -1;
2175 while (buf
->buf
[pos
] == ' ')
2181 * Anything else following the conditional causes
2182 * single-line scope. Warn if the scope contains
2183 * nothing but trailing whitespace.
2186 if (buf
->buf
[pos
] == '\0')
2187 mandoc_msg(MANDOCERR_COND_EMPTY
, r
->parse
,
2188 ln
, ppos
, roff_name
[tok
]);
2190 r
->last
->endspan
= 1;
2204 /* Ignore groff compatibility mode for now. */
2206 if (tok
== ROFF_ds1
)
2208 else if (tok
== ROFF_as1
)
2212 * The first word is the name of the string.
2213 * If it is empty or terminated by an escape sequence,
2214 * abort the `ds' request without defining anything.
2217 name
= string
= buf
->buf
+ pos
;
2221 namesz
= roff_getname(r
, &string
, ln
, pos
);
2222 if (name
[namesz
] == '\\')
2225 /* Read past the initial double-quote, if any. */
2229 /* The rest is the value. */
2230 roff_setstrn(&r
->strtab
, name
, namesz
, string
, strlen(string
),
2236 * Parse a single operator, one or two characters long.
2237 * If the operator is recognized, return success and advance the
2238 * parse point, else return failure and let the parse point unchanged.
2241 roff_getop(const char *v
, int *pos
, char *res
)
2256 switch (v
[*pos
+ 1]) {
2274 switch (v
[*pos
+ 1]) {
2288 if ('=' == v
[*pos
+ 1])
2300 * Evaluate either a parenthesized numeric expression
2301 * or a single signed integer number.
2304 roff_evalpar(struct roff
*r
, int ln
,
2305 const char *v
, int *pos
, int *res
, int flags
)
2309 return roff_getnum(v
, pos
, res
, flags
);
2312 if ( ! roff_evalnum(r
, ln
, v
, pos
, res
, flags
| ROFFNUM_WHITE
))
2316 * Omission of the closing parenthesis
2317 * is an error in validation mode,
2318 * but ignored in evaluation mode.
2323 else if (NULL
== res
)
2330 * Evaluate a complete numeric expression.
2331 * Proceed left to right, there is no concept of precedence.
2334 roff_evalnum(struct roff
*r
, int ln
, const char *v
,
2335 int *pos
, int *res
, int flags
)
2337 int mypos
, operand2
;
2345 if (flags
& ROFFNUM_WHITE
)
2346 while (isspace((unsigned char)v
[*pos
]))
2349 if ( ! roff_evalpar(r
, ln
, v
, pos
, res
, flags
))
2353 if (flags
& ROFFNUM_WHITE
)
2354 while (isspace((unsigned char)v
[*pos
]))
2357 if ( ! roff_getop(v
, pos
, &operator))
2360 if (flags
& ROFFNUM_WHITE
)
2361 while (isspace((unsigned char)v
[*pos
]))
2364 if ( ! roff_evalpar(r
, ln
, v
, pos
, &operand2
, flags
))
2367 if (flags
& ROFFNUM_WHITE
)
2368 while (isspace((unsigned char)v
[*pos
]))
2385 if (operand2
== 0) {
2386 mandoc_msg(MANDOCERR_DIVZERO
,
2387 r
->parse
, ln
, *pos
, v
);
2394 if (operand2
== 0) {
2395 mandoc_msg(MANDOCERR_DIVZERO
,
2396 r
->parse
, ln
, *pos
, v
);
2403 *res
= *res
< operand2
;
2406 *res
= *res
> operand2
;
2409 *res
= *res
<= operand2
;
2412 *res
= *res
>= operand2
;
2415 *res
= *res
== operand2
;
2418 *res
= *res
!= operand2
;
2421 *res
= *res
&& operand2
;
2424 *res
= *res
|| operand2
;
2427 if (operand2
< *res
)
2431 if (operand2
> *res
)
2441 /* --- register management ------------------------------------------------ */
2444 roff_setreg(struct roff
*r
, const char *name
, int val
, char sign
)
2446 struct roffreg
*reg
;
2448 /* Search for an existing register with the same name. */
2451 while (reg
&& strcmp(name
, reg
->key
.p
))
2455 /* Create a new register. */
2456 reg
= mandoc_malloc(sizeof(struct roffreg
));
2457 reg
->key
.p
= mandoc_strdup(name
);
2458 reg
->key
.sz
= strlen(name
);
2460 reg
->next
= r
->regtab
;
2466 else if ('-' == sign
)
2473 * Handle some predefined read-only number registers.
2474 * For now, return -1 if the requested register is not predefined;
2475 * in case a predefined read-only register having the value -1
2476 * were to turn up, another special value would have to be chosen.
2479 roff_getregro(const struct roff
*r
, const char *name
)
2483 case '$': /* Number of arguments of the last macro evaluated. */
2485 case 'A': /* ASCII approximation mode is always off. */
2487 case 'g': /* Groff compatibility mode is always on. */
2489 case 'H': /* Fixed horizontal resolution. */
2491 case 'j': /* Always adjust left margin only. */
2493 case 'T': /* Some output device is always defined. */
2495 case 'V': /* Fixed vertical resolution. */
2503 roff_getreg(const struct roff
*r
, const char *name
)
2505 struct roffreg
*reg
;
2508 if ('.' == name
[0] && '\0' != name
[1] && '\0' == name
[2]) {
2509 val
= roff_getregro(r
, name
+ 1);
2514 for (reg
= r
->regtab
; reg
; reg
= reg
->next
)
2515 if (0 == strcmp(name
, reg
->key
.p
))
2522 roff_getregn(const struct roff
*r
, const char *name
, size_t len
)
2524 struct roffreg
*reg
;
2527 if ('.' == name
[0] && 2 == len
) {
2528 val
= roff_getregro(r
, name
+ 1);
2533 for (reg
= r
->regtab
; reg
; reg
= reg
->next
)
2534 if (len
== reg
->key
.sz
&&
2535 0 == strncmp(name
, reg
->key
.p
, len
))
2542 roff_hasregn(const struct roff
*r
, const char *name
, size_t len
)
2544 struct roffreg
*reg
;
2547 if ('.' == name
[0] && 2 == len
) {
2548 val
= roff_getregro(r
, name
+ 1);
2553 for (reg
= r
->regtab
; reg
; reg
= reg
->next
)
2554 if (len
== reg
->key
.sz
&&
2555 0 == strncmp(name
, reg
->key
.p
, len
))
2562 roff_freereg(struct roffreg
*reg
)
2564 struct roffreg
*old_reg
;
2566 while (NULL
!= reg
) {
2582 key
= val
= buf
->buf
+ pos
;
2586 keysz
= roff_getname(r
, &val
, ln
, pos
);
2587 if (key
[keysz
] == '\\')
2592 if (sign
== '+' || sign
== '-')
2595 if (roff_evalnum(r
, ln
, val
, NULL
, &iv
, ROFFNUM_SCALE
))
2596 roff_setreg(r
, key
, iv
, sign
);
2604 struct roffreg
*reg
, **prev
;
2608 name
= cp
= buf
->buf
+ pos
;
2611 namesz
= roff_getname(r
, &cp
, ln
, pos
);
2612 name
[namesz
] = '\0';
2617 if (reg
== NULL
|| !strcmp(name
, reg
->key
.p
))
2629 /* --- handler functions for roff requests -------------------------------- */
2638 cp
= buf
->buf
+ pos
;
2639 while (*cp
!= '\0') {
2641 namesz
= roff_getname(r
, &cp
, ln
, (int)(cp
- buf
->buf
));
2642 roff_setstrn(&r
->strtab
, name
, namesz
, NULL
, 0, 0);
2643 if (name
[namesz
] == '\\')
2654 /* Parse the number of lines. */
2656 if ( ! roff_evalnum(r
, ln
, buf
->buf
, &pos
, &iv
, 0)) {
2657 mandoc_msg(MANDOCERR_IT_NONUM
, r
->parse
,
2658 ln
, ppos
, buf
->buf
+ 1);
2662 while (isspace((unsigned char)buf
->buf
[pos
]))
2666 * Arm the input line trap.
2667 * Special-casing "an-trap" is an ugly workaround to cope
2668 * with DocBook stupidly fiddling with man(7) internals.
2672 roffit_macro
= mandoc_strdup(iv
!= 1 ||
2673 strcmp(buf
->buf
+ pos
, "an-trap") ?
2674 buf
->buf
+ pos
: "br");
2681 const char *const *cp
;
2683 if ((r
->options
& (MPARSE_MDOC
| MPARSE_QUICK
)) == 0)
2684 for (cp
= __mdoc_reserved
; *cp
; cp
++)
2685 roff_setstr(r
, *cp
, NULL
, 0);
2688 r
->format
= MPARSE_MDOC
;
2696 const char *const *cp
;
2698 if ((r
->options
& MPARSE_QUICK
) == 0)
2699 for (cp
= __man_reserved
; *cp
; cp
++)
2700 roff_setstr(r
, *cp
, NULL
, 0);
2703 r
->format
= MPARSE_MAN
;
2713 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, r
->parse
,
2715 else if ( ! tbl_end(&r
->tbl
)) {
2717 buf
->buf
= mandoc_strdup(".sp");
2719 return ROFF_REPARSE
;
2729 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, r
->parse
,
2732 tbl_restart(ln
, ppos
, r
->tbl
);
2738 * Handle in-line equation delimiters.
2741 roff_eqndelim(struct roff
*r
, struct buf
*buf
, int pos
)
2744 const char *bef_pr
, *bef_nl
, *mac
, *aft_nl
, *aft_pr
;
2747 * Outside equations, look for an opening delimiter.
2748 * If we are inside an equation, we already know it is
2749 * in-line, or this function wouldn't have been called;
2750 * so look for a closing delimiter.
2753 cp1
= buf
->buf
+ pos
;
2754 cp2
= strchr(cp1
, r
->eqn
== NULL
?
2755 r
->last_eqn
->odelim
: r
->last_eqn
->cdelim
);
2760 bef_pr
= bef_nl
= aft_nl
= aft_pr
= "";
2762 /* Handle preceding text, protecting whitespace. */
2764 if (*buf
->buf
!= '\0') {
2771 * Prepare replacing the delimiter with an equation macro
2772 * and drop leading white space from the equation.
2775 if (r
->eqn
== NULL
) {
2782 /* Handle following text, protecting whitespace. */
2790 /* Do the actual replacement. */
2792 buf
->sz
= mandoc_asprintf(&cp1
, "%s%s%s%s%s%s%s", buf
->buf
,
2793 bef_pr
, bef_nl
, mac
, aft_nl
, aft_pr
, cp2
) + 1;
2797 /* Toggle the in-line state of the eqn subsystem. */
2799 r
->eqn_inline
= r
->eqn
== NULL
;
2800 return ROFF_REPARSE
;
2808 assert(r
->eqn
== NULL
);
2809 e
= eqn_alloc(ppos
, ln
, r
->parse
);
2812 r
->last_eqn
->next
= e
;
2813 e
->delim
= r
->last_eqn
->delim
;
2814 e
->odelim
= r
->last_eqn
->odelim
;
2815 e
->cdelim
= r
->last_eqn
->cdelim
;
2817 r
->first_eqn
= r
->last_eqn
= e
;
2819 r
->eqn
= r
->last_eqn
= e
;
2821 if (buf
->buf
[pos
] != '\0')
2822 mandoc_vmsg(MANDOCERR_ARG_SKIP
, r
->parse
, ln
, pos
,
2823 ".EQ %s", buf
->buf
+ pos
);
2832 mandoc_msg(MANDOCERR_BLK_NOTOPEN
, r
->parse
, ln
, ppos
, "EN");
2839 struct tbl_node
*tbl
;
2842 mandoc_msg(MANDOCERR_BLK_BROKEN
, r
->parse
,
2843 ln
, ppos
, "TS breaks TS");
2847 tbl
= tbl_alloc(ppos
, ln
, r
->parse
);
2850 r
->last_tbl
->next
= tbl
;
2852 r
->first_tbl
= r
->last_tbl
= tbl
;
2854 r
->tbl
= r
->last_tbl
= tbl
;
2859 roff_onearg(ROFF_ARGS
)
2861 struct roff_node
*n
;
2865 if (r
->man
->flags
& (MAN_BLINE
| MAN_ELINE
) &&
2866 (tok
== ROFF_sp
|| tok
== ROFF_ti
))
2867 man_breakscope(r
->man
, tok
);
2869 if (tok
== ROFF_ce
&& roffce_node
!= NULL
) {
2870 r
->man
->last
= roffce_node
;
2871 r
->man
->next
= ROFF_NEXT_SIBLING
;
2874 roff_elem_alloc(r
->man
, ln
, ppos
, tok
);
2877 cp
= buf
->buf
+ pos
;
2879 while (*cp
!= '\0' && *cp
!= ' ')
2884 mandoc_vmsg(MANDOCERR_ARG_EXCESS
,
2885 r
->parse
, ln
, cp
- buf
->buf
,
2886 "%s ... %s", roff_name
[tok
], cp
);
2887 roff_word_alloc(r
->man
, ln
, pos
, buf
->buf
+ pos
);
2890 if (tok
== ROFF_ce
) {
2891 if (r
->man
->last
->tok
== ROFF_ce
) {
2892 roff_word_alloc(r
->man
, ln
, pos
, "1");
2893 r
->man
->last
->flags
|= NODE_NOSRC
;
2896 if (roff_evalnum(r
, ln
, r
->man
->last
->string
, &npos
,
2897 &roffce_lines
, 0) == 0) {
2898 mandoc_vmsg(MANDOCERR_CE_NONUM
,
2899 r
->parse
, ln
, pos
, "ce %s", buf
->buf
+ pos
);
2902 if (roffce_lines
< 1) {
2903 r
->man
->last
= r
->man
->last
->parent
;
2907 roffce_node
= r
->man
->last
->parent
;
2909 n
->flags
|= NODE_VALID
| NODE_ENDED
;
2912 n
->flags
|= NODE_LINE
;
2913 r
->man
->next
= ROFF_NEXT_SIBLING
;
2918 roff_manyarg(ROFF_ARGS
)
2920 struct roff_node
*n
;
2923 roff_elem_alloc(r
->man
, ln
, ppos
, tok
);
2926 for (sp
= ep
= buf
->buf
+ pos
; *sp
!= '\0'; sp
= ep
) {
2927 while (*ep
!= '\0' && *ep
!= ' ')
2931 roff_word_alloc(r
->man
, ln
, sp
- buf
->buf
, sp
);
2934 n
->flags
|= NODE_LINE
| NODE_VALID
| NODE_ENDED
;
2936 r
->man
->next
= ROFF_NEXT_SIBLING
;
2943 if (r
->man
->flags
& (MAN_BLINE
| MAN_ELINE
))
2944 man_breakscope(r
->man
, ROFF_br
);
2945 roff_elem_alloc(r
->man
, ln
, ppos
, ROFF_br
);
2946 if (buf
->buf
[pos
] != '\0')
2947 mandoc_vmsg(MANDOCERR_ARG_SKIP
, r
->parse
, ln
, pos
,
2948 "%s %s", roff_name
[tok
], buf
->buf
+ pos
);
2949 r
->man
->last
->flags
|= NODE_LINE
| NODE_VALID
| NODE_ENDED
;
2950 r
->man
->next
= ROFF_NEXT_SIBLING
;
2961 if (*p
== '\0' || (r
->control
= *p
++) == '.')
2965 mandoc_vmsg(MANDOCERR_ARG_EXCESS
, r
->parse
,
2966 ln
, p
- buf
->buf
, "cc ... %s", p
);
2982 mandoc_vmsg(MANDOCERR_ARG_EXCESS
, r
->parse
,
2983 ln
, p
- buf
->buf
, "ec ... %s", p
);
2992 if (buf
->buf
[pos
] != '\0')
2993 mandoc_vmsg(MANDOCERR_ARG_SKIP
, r
->parse
,
2994 ln
, pos
, "eo %s", buf
->buf
+ pos
);
3001 const char *p
, *first
, *second
;
3003 enum mandoc_esc esc
;
3008 mandoc_msg(MANDOCERR_REQ_EMPTY
, r
->parse
, ln
, ppos
, "tr");
3012 while (*p
!= '\0') {
3016 if (*first
== '\\') {
3017 esc
= mandoc_escape(&p
, NULL
, NULL
);
3018 if (esc
== ESCAPE_ERROR
) {
3019 mandoc_msg(MANDOCERR_ESC_BAD
, r
->parse
,
3020 ln
, (int)(p
- buf
->buf
), first
);
3023 fsz
= (size_t)(p
- first
);
3027 if (*second
== '\\') {
3028 esc
= mandoc_escape(&p
, NULL
, NULL
);
3029 if (esc
== ESCAPE_ERROR
) {
3030 mandoc_msg(MANDOCERR_ESC_BAD
, r
->parse
,
3031 ln
, (int)(p
- buf
->buf
), second
);
3034 ssz
= (size_t)(p
- second
);
3035 } else if (*second
== '\0') {
3036 mandoc_vmsg(MANDOCERR_TR_ODD
, r
->parse
,
3037 ln
, first
- buf
->buf
, "tr %s", first
);
3043 roff_setstrn(&r
->xmbtab
, first
, fsz
,
3048 if (r
->xtab
== NULL
)
3049 r
->xtab
= mandoc_calloc(128,
3050 sizeof(struct roffstr
));
3052 free(r
->xtab
[(int)*first
].p
);
3053 r
->xtab
[(int)*first
].p
= mandoc_strndup(second
, ssz
);
3054 r
->xtab
[(int)*first
].sz
= ssz
;
3065 name
= buf
->buf
+ pos
;
3066 mandoc_vmsg(MANDOCERR_SO
, r
->parse
, ln
, ppos
, "so %s", name
);
3069 * Handle `so'. Be EXTREMELY careful, as we shouldn't be
3070 * opening anything that's not in our cwd or anything beneath
3071 * it. Thus, explicitly disallow traversing up the file-system
3072 * or using absolute paths.
3075 if (*name
== '/' || strstr(name
, "../") || strstr(name
, "/..")) {
3076 mandoc_vmsg(MANDOCERR_SO_PATH
, r
->parse
, ln
, ppos
,
3078 buf
->sz
= mandoc_asprintf(&cp
,
3079 ".sp\nSee the file %s.\n.sp", name
) + 1;
3083 return ROFF_REPARSE
;
3090 /* --- user defined strings and macros ------------------------------------ */
3093 roff_userdef(ROFF_ARGS
)
3095 const char *arg
[9], *ap
;
3097 int expand_count
, i
, ib
, ie
;
3101 * Collect pointers to macro argument strings
3102 * and NUL-terminate them.
3106 cp
= buf
->buf
+ pos
;
3107 for (i
= 0; i
< 9; i
++) {
3111 arg
[i
] = mandoc_getarg(r
->parse
, &cp
, ln
, &pos
);
3117 * Expand macro arguments.
3120 buf
->sz
= strlen(r
->current_string
) + 1;
3121 n1
= n2
= cp
= mandoc_malloc(buf
->sz
);
3122 memcpy(n1
, r
->current_string
, buf
->sz
);
3124 while (*cp
!= '\0') {
3126 /* Scan ahead for the next argument invocation. */
3132 if (*cp
== '*') { /* \\$* inserts all arguments */
3135 } else { /* \\$1 .. \\$9 insert one argument */
3136 ib
= ie
= *cp
- '1';
3137 if (ib
< 0 || ib
> 8)
3143 * Prevent infinite recursion.
3148 else if (++expand_count
> EXPAND_LIMIT
) {
3149 mandoc_msg(MANDOCERR_ROFFLOOP
, r
->parse
,
3150 ln
, (int)(cp
- n1
), NULL
);
3157 * Determine the size of the expanded argument,
3158 * taking escaping of quotes into account.
3161 asz
= ie
> ib
? ie
- ib
: 0; /* for blanks */
3162 for (i
= ib
; i
<= ie
; i
++) {
3163 for (ap
= arg
[i
]; *ap
!= '\0'; ap
++) {
3172 * Determine the size of the rest of the
3173 * unexpanded macro, including the NUL.
3176 rsz
= buf
->sz
- (cp
- n1
) - 3;
3179 * When shrinking, move before
3180 * releasing the storage.
3184 memmove(cp
+ asz
, cp
+ 3, rsz
);
3187 * Resize the storage for the macro
3188 * and readjust the parse pointer.
3192 n2
= mandoc_realloc(n1
, buf
->sz
);
3193 cp
= n2
+ (cp
- n1
);
3197 * When growing, make room
3198 * for the expanded argument.
3202 memmove(cp
+ asz
, cp
+ 3, rsz
);
3205 /* Copy the expanded argument, escaping quotes. */
3208 for (i
= ib
; i
<= ie
; i
++) {
3209 for (ap
= arg
[i
]; *ap
!= '\0'; ap
++) {
3211 memcpy(n2
, "\\(dq", 4);
3222 * Replace the macro invocation
3223 * by the expanded macro.
3230 return buf
->sz
> 1 && buf
->buf
[buf
->sz
- 2] == '\n' ?
3231 ROFF_REPARSE
: ROFF_APPEND
;
3235 roff_getname(struct roff
*r
, char **cpp
, int ln
, int pos
)
3244 /* Read until end of name and terminate it with NUL. */
3245 for (cp
= name
; 1; cp
++) {
3246 if ('\0' == *cp
|| ' ' == *cp
) {
3253 if ('{' == cp
[1] || '}' == cp
[1])
3258 mandoc_vmsg(MANDOCERR_NAMESC
, r
->parse
, ln
, pos
,
3259 "%.*s", (int)(cp
- name
+ 1), name
);
3260 mandoc_escape((const char **)&cp
, NULL
, NULL
);
3264 /* Read past spaces. */
3273 * Store *string into the user-defined string called *name.
3274 * To clear an existing entry, call with (*r, *name, NULL, 0).
3275 * append == 0: replace mode
3276 * append == 1: single-line append mode
3277 * append == 2: multiline append mode, append '\n' after each call
3280 roff_setstr(struct roff
*r
, const char *name
, const char *string
,
3284 roff_setstrn(&r
->strtab
, name
, strlen(name
), string
,
3285 string
? strlen(string
) : 0, append
);
3289 roff_setstrn(struct roffkv
**r
, const char *name
, size_t namesz
,
3290 const char *string
, size_t stringsz
, int append
)
3295 size_t oldch
, newch
;
3297 /* Search for an existing string with the same name. */
3300 while (n
&& (namesz
!= n
->key
.sz
||
3301 strncmp(n
->key
.p
, name
, namesz
)))
3305 /* Create a new string table entry. */
3306 n
= mandoc_malloc(sizeof(struct roffkv
));
3307 n
->key
.p
= mandoc_strndup(name
, namesz
);
3313 } else if (0 == append
) {
3323 * One additional byte for the '\n' in multiline mode,
3324 * and one for the terminating '\0'.
3326 newch
= stringsz
+ (1 < append
? 2u : 1u);
3328 if (NULL
== n
->val
.p
) {
3329 n
->val
.p
= mandoc_malloc(newch
);
3334 n
->val
.p
= mandoc_realloc(n
->val
.p
, oldch
+ newch
);
3337 /* Skip existing content in the destination buffer. */
3338 c
= n
->val
.p
+ (int)oldch
;
3340 /* Append new content to the destination buffer. */
3342 while (i
< (int)stringsz
) {
3344 * Rudimentary roff copy mode:
3345 * Handle escaped backslashes.
3347 if ('\\' == string
[i
] && '\\' == string
[i
+ 1])
3352 /* Append terminating bytes. */
3357 n
->val
.sz
= (int)(c
- n
->val
.p
);
3361 roff_getstrn(const struct roff
*r
, const char *name
, size_t len
)
3363 const struct roffkv
*n
;
3366 for (n
= r
->strtab
; n
; n
= n
->next
)
3367 if (0 == strncmp(name
, n
->key
.p
, len
) &&
3368 '\0' == n
->key
.p
[(int)len
])
3371 for (i
= 0; i
< PREDEFS_MAX
; i
++)
3372 if (0 == strncmp(name
, predefs
[i
].name
, len
) &&
3373 '\0' == predefs
[i
].name
[(int)len
])
3374 return predefs
[i
].str
;
3380 roff_freestr(struct roffkv
*r
)
3382 struct roffkv
*n
, *nn
;
3384 for (n
= r
; n
; n
= nn
) {
3392 /* --- accessors and utility functions ------------------------------------ */
3394 const struct tbl_span
*
3395 roff_span(const struct roff
*r
)
3398 return r
->tbl
? tbl_span(r
->tbl
) : NULL
;
3402 roff_eqn(const struct roff
*r
)
3405 return r
->last_eqn
? &r
->last_eqn
->eqn
: NULL
;
3409 * Duplicate an input string, making the appropriate character
3410 * conversations (as stipulated by `tr') along the way.
3411 * Returns a heap-allocated string with all the replacements made.
3414 roff_strdup(const struct roff
*r
, const char *p
)
3416 const struct roffkv
*cp
;
3420 enum mandoc_esc esc
;
3422 if (NULL
== r
->xmbtab
&& NULL
== r
->xtab
)
3423 return mandoc_strdup(p
);
3424 else if ('\0' == *p
)
3425 return mandoc_strdup("");
3428 * Step through each character looking for term matches
3429 * (remember that a `tr' can be invoked with an escape, which is
3430 * a glyph but the escape is multi-character).
3431 * We only do this if the character hash has been initialised
3432 * and the string is >0 length.
3438 while ('\0' != *p
) {
3439 assert((unsigned int)*p
< 128);
3440 if ('\\' != *p
&& r
->xtab
&& r
->xtab
[(unsigned int)*p
].p
) {
3441 sz
= r
->xtab
[(int)*p
].sz
;
3442 res
= mandoc_realloc(res
, ssz
+ sz
+ 1);
3443 memcpy(res
+ ssz
, r
->xtab
[(int)*p
].p
, sz
);
3447 } else if ('\\' != *p
) {
3448 res
= mandoc_realloc(res
, ssz
+ 2);
3453 /* Search for term matches. */
3454 for (cp
= r
->xmbtab
; cp
; cp
= cp
->next
)
3455 if (0 == strncmp(p
, cp
->key
.p
, cp
->key
.sz
))
3460 * A match has been found.
3461 * Append the match to the array and move
3462 * forward by its keysize.
3464 res
= mandoc_realloc(res
,
3465 ssz
+ cp
->val
.sz
+ 1);
3466 memcpy(res
+ ssz
, cp
->val
.p
, cp
->val
.sz
);
3468 p
+= (int)cp
->key
.sz
;
3473 * Handle escapes carefully: we need to copy
3474 * over just the escape itself, or else we might
3475 * do replacements within the escape itself.
3476 * Make sure to pass along the bogus string.
3479 esc
= mandoc_escape(&p
, NULL
, NULL
);
3480 if (ESCAPE_ERROR
== esc
) {
3482 res
= mandoc_realloc(res
, ssz
+ sz
+ 1);
3483 memcpy(res
+ ssz
, pp
, sz
);
3487 * We bail out on bad escapes.
3488 * No need to warn: we already did so when
3489 * roff_res() was called.
3492 res
= mandoc_realloc(res
, ssz
+ sz
+ 1);
3493 memcpy(res
+ ssz
, pp
, sz
);
3497 res
[(int)ssz
] = '\0';
3502 roff_getformat(const struct roff
*r
)
3509 * Find out whether a line is a macro line or not.
3510 * If it is, adjust the current position and return one; if it isn't,
3511 * return zero and don't change the current position.
3512 * If the control character has been set with `.cc', then let that grain
3514 * This is slighly contrary to groff, where using the non-breaking
3515 * control character when `cc' has been invoked will cause the
3516 * non-breaking macro contents to be printed verbatim.
3519 roff_getcontrol(const struct roff
*r
, const char *cp
, int *ppos
)
3525 if (r
->control
!= '\0' && cp
[pos
] == r
->control
)
3527 else if (r
->control
!= '\0')
3529 else if ('\\' == cp
[pos
] && '.' == cp
[pos
+ 1])
3531 else if ('.' == cp
[pos
] || '\'' == cp
[pos
])
3536 while (' ' == cp
[pos
] || '\t' == cp
[pos
])