diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | libmdoc.h | 20 | ||||
-rw-r--r-- | mdoc.7 | 7 | ||||
-rw-r--r-- | mdoc.c | 22 | ||||
-rw-r--r-- | mdoc.h | 251 | ||||
-rw-r--r-- | mdoc_action.c | 3 | ||||
-rw-r--r-- | mdoc_argv.c | 13 | ||||
-rw-r--r-- | mdoc_hash.c | 4 | ||||
-rw-r--r-- | mdoc_macro.c | 67 | ||||
-rw-r--r-- | mdoc_validate.c | 4 |
10 files changed, 222 insertions, 171 deletions
@@ -13,7 +13,7 @@ INSTALL_MAN = $(INSTALL_DATA) VERSION = 1.9.21 VDATE = 31 March 2010 -VFLAGS = -DVERSION="\"$(VERSION)\"" -DHAVE_CONFIG_H +VFLAGS = -DVERSION="\"$(VERSION)\"" -DHAVE_CONFIG_H -DUGLY WFLAGS = -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Wwrite-strings CFLAGS += -g $(VFLAGS) $(WFLAGS) #CFLAGS += -DOSNAME="\"OpenBSD 4.5\"" @@ -96,8 +96,8 @@ enum merr { MERRMAX }; -#define MACRO_PROT_ARGS struct mdoc *m, int tok, int line, \ - int ppos, int *pos, char *buf +#define MACRO_PROT_ARGS struct mdoc *m, enum mdoct tok, \ + int line, int ppos, int *pos, char *buf struct mdoc_macro { int (*fp)(MACRO_PROT_ARGS); @@ -131,16 +131,16 @@ int mdoc_macro(MACRO_PROT_ARGS); int mdoc_word_alloc(struct mdoc *, int, int, const char *); int mdoc_elem_alloc(struct mdoc *, int, int, - int, struct mdoc_arg *); + enum mdoct, struct mdoc_arg *); int mdoc_block_alloc(struct mdoc *, int, int, - int, struct mdoc_arg *); -int mdoc_head_alloc(struct mdoc *, int, int, int); -int mdoc_tail_alloc(struct mdoc *, int, int, int); -int mdoc_body_alloc(struct mdoc *, int, int, int); + enum mdoct, struct mdoc_arg *); +int mdoc_head_alloc(struct mdoc *, int, int, enum mdoct); +int mdoc_tail_alloc(struct mdoc *, int, int, enum mdoct); +int mdoc_body_alloc(struct mdoc *, int, int, enum mdoct); void mdoc_node_free(struct mdoc_node *); void mdoc_node_freelist(struct mdoc_node *); void mdoc_hash_init(void); -int mdoc_hash_find(const char *); +enum mdoct mdoc_hash_find(const char *); int mdoc_iscdelim(char); int mdoc_isdelim(const char *); size_t mdoc_isescape(const char *); @@ -160,7 +160,7 @@ int mdoc_valid_post(struct mdoc *); int mdoc_action_pre(struct mdoc *, const struct mdoc_node *); int mdoc_action_post(struct mdoc *); -int mdoc_argv(struct mdoc *, int, int, +int mdoc_argv(struct mdoc *, int, enum mdoct, struct mdoc_arg **, int *, char *); #define ARGV_ERROR (-1) #define ARGV_EOLN (0) @@ -168,7 +168,7 @@ int mdoc_argv(struct mdoc *, int, int, #define ARGV_WORD (2) void mdoc_argv_free(struct mdoc_arg *); int mdoc_args(struct mdoc *, int, - int *, char *, int, char **); + int *, char *, enum mdoct, char **); int mdoc_zargs(struct mdoc *, int, int *, char *, int, char **); #define ARGS_DELIM (1 << 1) /* See args(). */ @@ -1927,7 +1927,14 @@ and .Sx \&Va . . .Ss \&Xc +Close a scope opened by +.Sx \&Xo . +. .Ss \&Xo +Open an extension scope. This macro originally existed to extend the +9-argument limit of troff; since this limit has been lifted, the macro +has been deprecated. +. .Ss \&Xr Link to another manual .Pq Qq cross-reference . @@ -143,7 +143,7 @@ const char * const *mdoc_argnames = __mdoc_argnames; static void mdoc_free1(struct mdoc *); static void mdoc_alloc1(struct mdoc *); static struct mdoc_node *node_alloc(struct mdoc *, int, int, - int, enum mdoc_type); + enum mdoct, enum mdoc_type); static int node_append(struct mdoc *, struct mdoc_node *); static int parsetext(struct mdoc *, int, char *); @@ -341,9 +341,11 @@ mdoc_err(struct mdoc *m, int line, int pos, int iserr, enum merr type) int -mdoc_macro(struct mdoc *m, int tok, +mdoc_macro(struct mdoc *m, enum mdoct tok, int ln, int pp, int *pos, char *buf) { + + assert(tok < MDOC_MAX); /* * If we're in the prologue, deny "body" macros. Similarly, if * we're in the body, deny prologue calls. @@ -424,8 +426,8 @@ node_append(struct mdoc *mdoc, struct mdoc_node *p) static struct mdoc_node * -node_alloc(struct mdoc *m, int line, - int pos, int tok, enum mdoc_type type) +node_alloc(struct mdoc *m, int line, int pos, + enum mdoct tok, enum mdoc_type type) { struct mdoc_node *p; @@ -434,15 +436,13 @@ node_alloc(struct mdoc *m, int line, p->line = line; p->pos = pos; p->tok = tok; - if (MDOC_TEXT != (p->type = type)) - assert(p->tok >= 0); return(p); } int -mdoc_tail_alloc(struct mdoc *m, int line, int pos, int tok) +mdoc_tail_alloc(struct mdoc *m, int line, int pos, enum mdoct tok) { struct mdoc_node *p; @@ -455,7 +455,7 @@ mdoc_tail_alloc(struct mdoc *m, int line, int pos, int tok) int -mdoc_head_alloc(struct mdoc *m, int line, int pos, int tok) +mdoc_head_alloc(struct mdoc *m, int line, int pos, enum mdoct tok) { struct mdoc_node *p; @@ -471,7 +471,7 @@ mdoc_head_alloc(struct mdoc *m, int line, int pos, int tok) int -mdoc_body_alloc(struct mdoc *m, int line, int pos, int tok) +mdoc_body_alloc(struct mdoc *m, int line, int pos, enum mdoct tok) { struct mdoc_node *p; @@ -485,7 +485,7 @@ mdoc_body_alloc(struct mdoc *m, int line, int pos, int tok) int mdoc_block_alloc(struct mdoc *m, int line, int pos, - int tok, struct mdoc_arg *args) + enum mdoct tok, struct mdoc_arg *args) { struct mdoc_node *p; @@ -502,7 +502,7 @@ mdoc_block_alloc(struct mdoc *m, int line, int pos, int mdoc_elem_alloc(struct mdoc *m, int line, int pos, - int tok, struct mdoc_arg *args) + enum mdoct tok, struct mdoc_arg *args) { struct mdoc_node *p; @@ -27,128 +27,130 @@ /* What follows is a list of ALL possible macros. */ -#define MDOC_Ap 0 -#define MDOC_Dd 1 -#define MDOC_Dt 2 -#define MDOC_Os 3 -#define MDOC_Sh 4 -#define MDOC_Ss 5 -#define MDOC_Pp 6 -#define MDOC_D1 7 -#define MDOC_Dl 8 -#define MDOC_Bd 9 -#define MDOC_Ed 10 -#define MDOC_Bl 11 -#define MDOC_El 12 -#define MDOC_It 13 -#define MDOC_Ad 14 -#define MDOC_An 15 -#define MDOC_Ar 16 -#define MDOC_Cd 17 -#define MDOC_Cm 18 -#define MDOC_Dv 19 -#define MDOC_Er 20 -#define MDOC_Ev 21 -#define MDOC_Ex 22 -#define MDOC_Fa 23 -#define MDOC_Fd 24 -#define MDOC_Fl 25 -#define MDOC_Fn 26 -#define MDOC_Ft 27 -#define MDOC_Ic 28 -#define MDOC_In 29 -#define MDOC_Li 30 -#define MDOC_Nd 31 -#define MDOC_Nm 32 -#define MDOC_Op 33 -#define MDOC_Ot 34 -#define MDOC_Pa 35 -#define MDOC_Rv 36 -#define MDOC_St 37 -#define MDOC_Va 38 -#define MDOC_Vt 39 -#define MDOC_Xr 40 -#define MDOC__A 41 -#define MDOC__B 42 -#define MDOC__D 43 -#define MDOC__I 44 -#define MDOC__J 45 -#define MDOC__N 46 -#define MDOC__O 47 -#define MDOC__P 48 -#define MDOC__R 49 -#define MDOC__T 50 -#define MDOC__V 51 -#define MDOC_Ac 52 -#define MDOC_Ao 53 -#define MDOC_Aq 54 -#define MDOC_At 55 -#define MDOC_Bc 56 -#define MDOC_Bf 57 -#define MDOC_Bo 58 -#define MDOC_Bq 59 -#define MDOC_Bsx 60 -#define MDOC_Bx 61 -#define MDOC_Db 62 -#define MDOC_Dc 63 -#define MDOC_Do 64 -#define MDOC_Dq 65 -#define MDOC_Ec 66 -#define MDOC_Ef 67 -#define MDOC_Em 68 -#define MDOC_Eo 69 -#define MDOC_Fx 70 -#define MDOC_Ms 71 -#define MDOC_No 72 -#define MDOC_Ns 73 -#define MDOC_Nx 74 -#define MDOC_Ox 75 -#define MDOC_Pc 76 -#define MDOC_Pf 77 -#define MDOC_Po 78 -#define MDOC_Pq 79 -#define MDOC_Qc 80 -#define MDOC_Ql 81 -#define MDOC_Qo 82 -#define MDOC_Qq 83 -#define MDOC_Re 84 -#define MDOC_Rs 85 -#define MDOC_Sc 86 -#define MDOC_So 87 -#define MDOC_Sq 88 -#define MDOC_Sm 89 -#define MDOC_Sx 90 -#define MDOC_Sy 91 -#define MDOC_Tn 92 -#define MDOC_Ux 93 -#define MDOC_Xc 94 -#define MDOC_Xo 95 -#define MDOC_Fo 96 -#define MDOC_Fc 97 -#define MDOC_Oo 98 -#define MDOC_Oc 99 -#define MDOC_Bk 100 -#define MDOC_Ek 101 -#define MDOC_Bt 102 -#define MDOC_Hf 103 -#define MDOC_Fr 104 -#define MDOC_Ud 105 -#define MDOC_Lb 106 -#define MDOC_Lp 107 -#define MDOC_Lk 108 -#define MDOC_Mt 109 -#define MDOC_Brq 110 -#define MDOC_Bro 111 -#define MDOC_Brc 112 -#define MDOC__C 113 -#define MDOC_Es 114 -#define MDOC_En 115 -#define MDOC_Dx 116 -#define MDOC__Q 117 -#define MDOC_br 118 -#define MDOC_sp 119 -#define MDOC__U 120 -#define MDOC_MAX 121 +enum mdoct { + MDOC_Ap = 0, + MDOC_Dd, + MDOC_Dt, + MDOC_Os, + MDOC_Sh, + MDOC_Ss, + MDOC_Pp, + MDOC_D1, + MDOC_Dl, + MDOC_Bd, + MDOC_Ed, + MDOC_Bl, + MDOC_El, + MDOC_It, + MDOC_Ad, + MDOC_An, + MDOC_Ar, + MDOC_Cd, + MDOC_Cm, + MDOC_Dv, + MDOC_Er, + MDOC_Ev, + MDOC_Ex, + MDOC_Fa, + MDOC_Fd, + MDOC_Fl, + MDOC_Fn, + MDOC_Ft, + MDOC_Ic, + MDOC_In, + MDOC_Li, + MDOC_Nd, + MDOC_Nm, + MDOC_Op, + MDOC_Ot, + MDOC_Pa, + MDOC_Rv, + MDOC_St, + MDOC_Va, + MDOC_Vt, + MDOC_Xr, + MDOC__A, + MDOC__B, + MDOC__D, + MDOC__I, + MDOC__J, + MDOC__N, + MDOC__O, + MDOC__P, + MDOC__R, + MDOC__T, + MDOC__V, + MDOC_Ac, + MDOC_Ao, + MDOC_Aq, + MDOC_At, + MDOC_Bc, + MDOC_Bf, + MDOC_Bo, + MDOC_Bq, + MDOC_Bsx, + MDOC_Bx, + MDOC_Db, + MDOC_Dc, + MDOC_Do, + MDOC_Dq, + MDOC_Ec, + MDOC_Ef, + MDOC_Em, + MDOC_Eo, + MDOC_Fx, + MDOC_Ms, + MDOC_No, + MDOC_Ns, + MDOC_Nx, + MDOC_Ox, + MDOC_Pc, + MDOC_Pf, + MDOC_Po, + MDOC_Pq, + MDOC_Qc, + MDOC_Ql, + MDOC_Qo, + MDOC_Qq, + MDOC_Re, + MDOC_Rs, + MDOC_Sc, + MDOC_So, + MDOC_Sq, + MDOC_Sm, + MDOC_Sx, + MDOC_Sy, + MDOC_Tn, + MDOC_Ux, + MDOC_Xc, + MDOC_Xo, + MDOC_Fo, + MDOC_Fc, + MDOC_Oo, + MDOC_Oc, + MDOC_Bk, + MDOC_Ek, + MDOC_Bt, + MDOC_Hf, + MDOC_Fr, + MDOC_Ud, + MDOC_Lb, + MDOC_Lp, + MDOC_Lk, + MDOC_Mt, + MDOC_Brq, + MDOC_Bro, + MDOC_Brc, + MDOC__C, + MDOC_Es, + MDOC_En, + MDOC_Dx, + MDOC__Q, + MDOC_br, + MDOC_sp, + MDOC__U, + MDOC_MAX +}; /* What follows is a list of ALL possible macro arguments. */ @@ -253,7 +255,7 @@ struct mdoc_node { int nchild; int line; int pos; - int tok; + enum mdoct tok; int flags; #define MDOC_VALID (1 << 0) #define MDOC_ACTED (1 << 1) @@ -261,6 +263,9 @@ struct mdoc_node { enum mdoc_sec sec; struct mdoc_arg *args; /* BLOCK/ELEM */ +#ifdef UGLY + struct mdoc_node *pending; /* BLOCK */ +#endif struct mdoc_node *head; /* BLOCK */ struct mdoc_node *body; /* BLOCK */ struct mdoc_node *tail; /* BLOCK */ diff --git a/mdoc_action.c b/mdoc_action.c index dfe2aafc..c6cce90e 100644 --- a/mdoc_action.c +++ b/mdoc_action.c @@ -647,7 +647,8 @@ static int post_bl_width(POST_ARGS) { size_t width; - int i, tok; + int i; + enum mdoct tok; char buf[NUMSIZ]; char *p; diff --git a/mdoc_argv.c b/mdoc_argv.c index 9ad6a00a..b61c8b9a 100644 --- a/mdoc_argv.c +++ b/mdoc_argv.c @@ -44,7 +44,7 @@ #define MULTI_STEP 5 -static int argv_a2arg(int, const char *); +static int argv_a2arg(enum mdoct, const char *); static int args(struct mdoc *, int, int *, char *, int, char **); static int argv(struct mdoc *, int, @@ -218,7 +218,7 @@ static int mdoc_argflags[MDOC_MAX] = { * one mandatory value, an optional single value, or no value. */ int -mdoc_argv(struct mdoc *m, int line, int tok, +mdoc_argv(struct mdoc *m, int line, enum mdoct tok, struct mdoc_arg **v, int *pos, char *buf) { char *p, sv; @@ -330,13 +330,14 @@ mdoc_zargs(struct mdoc *m, int line, int *pos, int -mdoc_args(struct mdoc *m, int line, - int *pos, char *buf, int tok, char **v) +mdoc_args(struct mdoc *m, int line, int *pos, + char *buf, enum mdoct tok, char **v) { int fl, c, i; struct mdoc_node *n; - fl = (0 == tok) ? 0 : mdoc_argflags[tok]; + assert(tok && tok < MDOC_MAX); + fl = mdoc_argflags[tok]; if (MDOC_It != tok) return(args(m, line, pos, buf, fl, v)); @@ -552,7 +553,7 @@ args(struct mdoc *m, int line, int *pos, static int -argv_a2arg(int tok, const char *p) +argv_a2arg(enum mdoct tok, const char *p) { /* diff --git a/mdoc_hash.c b/mdoc_hash.c index 871000fc..ce9e3ce3 100644 --- a/mdoc_hash.c +++ b/mdoc_hash.c @@ -61,7 +61,7 @@ mdoc_hash_init(void) } } -int +enum mdoct mdoc_hash_find(const char *p) { int major, i, j; @@ -85,7 +85,7 @@ mdoc_hash_find(const char *p) if (UCHAR_MAX == (i = table[major + j])) break; if (0 == strcmp(p, mdoc_macronames[i])) - return(i); + return((enum mdoct)i); } return(MDOC_MAX); diff --git a/mdoc_macro.c b/mdoc_macro.c index d47bcc12..97bda380 100644 --- a/mdoc_macro.c +++ b/mdoc_macro.c @@ -42,13 +42,13 @@ static int blk_exp_close(MACRO_PROT_ARGS); static int blk_part_imp(MACRO_PROT_ARGS); static int phrase(struct mdoc *, int, int, char *); -static int rew_dohalt(int, enum mdoc_type, +static int rew_dohalt(enum mdoct, enum mdoc_type, const struct mdoc_node *); -static int rew_alt(int); -static int rew_dobreak(int, const struct mdoc_node *); -static int rew_elem(struct mdoc *, int); +static enum mdoct rew_alt(enum mdoct); +static int rew_dobreak(enum mdoct, const struct mdoc_node *); +static int rew_elem(struct mdoc *, enum mdoct); static int rew_sub(enum mdoc_type, struct mdoc *, - int, int, int); + enum mdoct, int, int); static int rew_last(struct mdoc *, const struct mdoc_node *); static int append_delims(struct mdoc *, int, int *, char *); @@ -318,8 +318,8 @@ rew_last(struct mdoc *mdoc, const struct mdoc_node *to) * Return the opening macro of a closing one, e.g., `Ec' has `Eo' as its * matching pair. */ -static int -rew_alt(int tok) +static enum mdoct +rew_alt(enum mdoct tok) { switch (tok) { case (MDOC_Ac): @@ -369,7 +369,8 @@ rew_alt(int tok) * The scope-closing and so on occurs in the various rew_* routines. */ static int -rew_dohalt(int tok, enum mdoc_type type, const struct mdoc_node *p) +rew_dohalt(enum mdoct tok, enum mdoc_type type, + const struct mdoc_node *p) { if (MDOC_ROOT == p->type) @@ -508,7 +509,7 @@ rew_dohalt(int tok, enum mdoc_type type, const struct mdoc_node *p) * REWIND_NOHALT). */ static int -rew_dobreak(int tok, const struct mdoc_node *p) +rew_dobreak(enum mdoct tok, const struct mdoc_node *p) { assert(MDOC_ROOT != p->type); @@ -537,9 +538,10 @@ rew_dobreak(int tok, const struct mdoc_node *p) return(1); break; case (MDOC_Oc): - /* XXX - experimental! */ +#ifdef UGLY if (MDOC_Op == p->tok) return(1); +#endif break; default: break; @@ -555,7 +557,7 @@ rew_dobreak(int tok, const struct mdoc_node *p) static int -rew_elem(struct mdoc *mdoc, int tok) +rew_elem(struct mdoc *mdoc, enum mdoct tok) { struct mdoc_node *n; @@ -571,7 +573,7 @@ rew_elem(struct mdoc *mdoc, int tok) static int rew_sub(enum mdoc_type t, struct mdoc *m, - int tok, int line, int ppos) + enum mdoct tok, int line, int ppos) { struct mdoc_node *n; int c; @@ -595,7 +597,25 @@ rew_sub(enum mdoc_type t, struct mdoc *m, } assert(n); - return(rew_last(m, n)); + if ( ! rew_last(m, n)) + return(0); + +#ifdef UGLY + /* + * The current block extends an enclosing block beyond a line + * break. Now that the current block ends, close the enclosing + * block, too. + */ + if (NULL != (n = n->pending)) { + assert(MDOC_HEAD == n->type); + if ( ! rew_last(m, n)) + return(0); + if ( ! mdoc_body_alloc(m, n->line, n->pos, n->tok)) + return(0); + } +#endif + + return(1); } @@ -861,6 +881,7 @@ blk_full(MACRO_PROT_ARGS) int c, la; struct mdoc_arg *arg; struct mdoc_node *head; /* save of head macro */ + struct mdoc_node *n; char *p; /* Close out prior implicit scope. */ @@ -978,6 +999,21 @@ blk_full(MACRO_PROT_ARGS) if (MDOC_Nd == tok) return(1); +#ifdef UGLY + /* + * If there is an open sub-block requiring explicit close-out, + * postpone switching the current block from head to body until + * the rew_sub() call closing out that sub-block. + */ + for (n = m->last; n && n != head; n = n->parent) { + if (MDOC_EXPLICIT & mdoc_macros[n->tok].flags && + MDOC_BLOCK == n->type) { + n->pending = head; + return(1); + } + } +#endif + /* Close out scopes to remain in a consistent state. */ if ( ! rew_sub(MDOC_HEAD, m, tok, line, ppos)) @@ -1066,16 +1102,17 @@ blk_part_imp(MACRO_PROT_ARGS) body = m->last; } +#ifdef UGLY /* * If we can't rewind to our body, then our scope has already * been closed by another macro (like `Oc' closing `Op'). This * is ugly behaviour nodding its head to OpenBSD's overwhelming - * crufty use of `Op' breakage. XXX: DEPRECATE. + * crufty use of `Op' breakage. */ - for (n = m->last; n; n = n->parent) if (body == n) break; +#endif if (NULL == n && ! mdoc_nwarn(m, body, EIMPBRK)) return(0); diff --git a/mdoc_validate.c b/mdoc_validate.c index d4e6631e..676862fb 100644 --- a/mdoc_validate.c +++ b/mdoc_validate.c @@ -44,7 +44,7 @@ struct valids { v_post *post; }; -static int check_parent(PRE_ARGS, int, enum mdoc_type); +static int check_parent(PRE_ARGS, enum mdoct, enum mdoc_type); static int check_msec(PRE_ARGS, ...); static int check_sec(PRE_ARGS, ...); static int check_stdarg(PRE_ARGS); @@ -547,7 +547,7 @@ check_text(struct mdoc *mdoc, int line, int pos, const char *p) static int -check_parent(PRE_ARGS, int tok, enum mdoc_type t) +check_parent(PRE_ARGS, enum mdoct tok, enum mdoc_type t) { assert(n->parent); |