diff options
-rw-r--r-- | argv.c | 126 | ||||
-rw-r--r-- | macro.c | 40 | ||||
-rw-r--r-- | mdoc.c | 36 | ||||
-rw-r--r-- | private.h | 8 | ||||
-rw-r--r-- | validate.c | 9 |
5 files changed, 165 insertions, 54 deletions
@@ -44,11 +44,133 @@ static int parse_multi(struct mdoc *, int, static int postparse(struct mdoc *, int, const struct mdoc_arg *, int); +#define ARGS_QUOTED (1 << 0) +#define ARGS_DELIM (1 << 1) +#define ARGS_TABSEP (1 << 2) + +static int mdoc_argflags[MDOC_MAX] = { + 0, /* \" */ + 0, /* Dd */ + 0, /* Dt */ + 0, /* Os */ + 0, /* Sh */ + 0, /* Ss */ + ARGS_DELIM, /* Pp */ + ARGS_DELIM, /* D1 */ + ARGS_DELIM, /* Dl */ + 0, /* Bd */ + 0, /* Ed */ + 0, /* Bl */ + 0, /* El */ + ARGS_DELIM, /* It */ + ARGS_DELIM, /* Ad */ + ARGS_DELIM, /* An */ + ARGS_DELIM, /* Ar */ + ARGS_QUOTED, /* Cd */ + ARGS_DELIM, /* Cm */ + ARGS_DELIM, /* Dv */ + ARGS_DELIM, /* Er */ + ARGS_DELIM, /* Ev */ + 0, /* Ex */ + ARGS_DELIM | ARGS_QUOTED, /* Fa */ + 0, /* Fd */ + ARGS_DELIM, /* Fl */ + ARGS_DELIM | ARGS_QUOTED, /* Fn */ + ARGS_DELIM | ARGS_QUOTED, /* Ft */ + ARGS_DELIM, /* Ic */ + 0, /* In */ + ARGS_DELIM, /* Li */ + 0, /* Nd */ + ARGS_DELIM, /* Nm */ + ARGS_DELIM, /* Op */ + 0, /* Ot */ + ARGS_DELIM, /* Pa */ + 0, /* Rv */ + ARGS_DELIM, /* St */ + ARGS_DELIM, /* Va */ + ARGS_DELIM, /* Vt */ + ARGS_DELIM, /* Xr */ + ARGS_QUOTED, /* %A */ + ARGS_QUOTED, /* %B */ + ARGS_QUOTED, /* %D */ + ARGS_QUOTED, /* %I */ + ARGS_QUOTED, /* %J */ + ARGS_QUOTED, /* %N */ + ARGS_QUOTED, /* %O */ + ARGS_QUOTED, /* %P */ + ARGS_QUOTED, /* %R */ + ARGS_QUOTED, /* %T */ + ARGS_QUOTED, /* %V */ + ARGS_DELIM, /* Ac */ + 0, /* Ao */ + ARGS_DELIM, /* Aq */ + ARGS_DELIM, /* At */ + ARGS_DELIM, /* Bc */ + 0, /* Bf */ + 0, /* Bo */ + ARGS_DELIM, /* Bq */ + ARGS_DELIM, /* Bsx */ + ARGS_DELIM, /* Bx */ + 0, /* Db */ + ARGS_DELIM, /* Dc */ + 0, /* Do */ + ARGS_DELIM, /* Dq */ + ARGS_DELIM, /* Ec */ + 0, /* Ef */ + ARGS_DELIM, /* Em */ + 0, /* Eo */ + ARGS_DELIM, /* Fx */ + ARGS_DELIM, /* Ms */ + ARGS_DELIM, /* No */ + ARGS_DELIM, /* Ns */ + ARGS_DELIM, /* Nx */ + ARGS_DELIM, /* Ox */ + ARGS_DELIM, /* Pc */ + ARGS_DELIM, /* Pf */ + 0, /* Po */ + ARGS_DELIM, /* Pq */ + ARGS_DELIM, /* Qc */ + ARGS_DELIM, /* Ql */ + 0, /* Qo */ + ARGS_DELIM, /* Qq */ + 0, /* Re */ + 0, /* Rs */ + ARGS_DELIM, /* Sc */ + 0, /* So */ + ARGS_DELIM, /* Sq */ + 0, /* Sm */ + ARGS_DELIM, /* Sx */ + ARGS_DELIM, /* Sy */ + ARGS_DELIM, /* Tn */ + ARGS_DELIM, /* Ux */ + ARGS_DELIM, /* Xc */ + 0, /* Xo */ + 0, /* Fo */ + 0, /* Fc */ + 0, /* Oo */ + ARGS_DELIM, /* Oc */ + 0, /* Bk */ + 0, /* Ek */ + 0, /* Bt */ + 0, /* Hf */ + 0, /* Fr */ + 0, /* Ud */ +}; + int -mdoc_args(struct mdoc *mdoc, int line, int *pos, char *buf, int fl, char **v) +mdoc_args(struct mdoc *mdoc, int line, + int *pos, char *buf, int tok, char **v) { - int i; + int i, fl; + struct mdoc_node *n; + + fl = 0 == tok ? 0 : mdoc_argflags[tok]; + if (MDOC_It == tok) { + n = mdoc->last->parent; + /* FIXME: scan for ARGS_TABSEP. */ + + } if (0 == buf[*pos]) return(ARGS_EOLN); @@ -512,7 +512,7 @@ macro_scoped_close(MACRO_PROT_ARGS) flushed = 1; } - c = mdoc_args(mdoc, line, pos, buf, ARGS_DELIM, &p); + c = mdoc_args(mdoc, line, pos, buf, tok, &p); if (ARGS_ERROR == c) return(0); if (ARGS_PUNCT == c) @@ -574,7 +574,7 @@ macro_scoped_close(MACRO_PROT_ARGS) int macro_text(MACRO_PROT_ARGS) { - int la, lastpunct, c, w, fl, argc; + int la, lastpunct, c, w, argc; struct mdoc_arg argv[MDOC_LINEARG_MAX]; char *p; @@ -610,14 +610,10 @@ macro_text(MACRO_PROT_ARGS) mdoc->next = MDOC_NEXT_CHILD; - fl = ARGS_DELIM; - if (MDOC_QUOTABLE & mdoc_macros[tok].flags) - fl |= ARGS_QUOTED; - lastpunct = 0; for (;;) { la = *pos; - w = mdoc_args(mdoc, line, pos, buf, fl, &p); + w = mdoc_args(mdoc, line, pos, buf, tok, &p); if (ARGS_ERROR == w) { mdoc_argv_free(argc, argv); return(0); @@ -707,7 +703,7 @@ macro_text(MACRO_PROT_ARGS) int macro_scoped(MACRO_PROT_ARGS) { - int c, lastarg, argc, fl; + int c, lastarg, argc; struct mdoc_arg argv[MDOC_LINEARG_MAX]; char *p; @@ -767,13 +763,9 @@ macro_scoped(MACRO_PROT_ARGS) return(0); mdoc->next = MDOC_NEXT_CHILD; - fl = ARGS_DELIM; - if (MDOC_TABSEP & mdoc_macros[tok].flags) - fl |= ARGS_TABSEP; - for (;;) { lastarg = *pos; - c = mdoc_args(mdoc, line, pos, buf, fl, &p); + c = mdoc_args(mdoc, line, pos, buf, tok, &p); if (ARGS_ERROR == c) return(0); @@ -781,10 +773,14 @@ macro_scoped(MACRO_PROT_ARGS) break; if (ARGS_EOLN == c) break; + + /* FIXME: if .It -column, the lookup must be for a + * sub-line component. BLAH. */ if (-1 == (c = lookup(mdoc, line, lastarg, tok, p))) return(0); - else if (MDOC_MAX == c) { + + if (MDOC_MAX == c) { if ( ! mdoc_word_alloc(mdoc, line, lastarg, p)) return(0); mdoc->next = MDOC_NEXT_SIBLING; @@ -795,7 +791,7 @@ macro_scoped(MACRO_PROT_ARGS) return(0); break; } - + if ( ! rewind_subblock(MDOC_HEAD, mdoc, tok, line, ppos)) return(0); if (1 == ppos && ! append_delims(mdoc, line, pos, buf)) @@ -850,7 +846,7 @@ macro_scoped_line(MACRO_PROT_ARGS) lastarg = ppos; for (;;) { lastarg = *pos; - c = mdoc_args(mdoc, line, pos, buf, ARGS_DELIM, &p); + c = mdoc_args(mdoc, line, pos, buf, tok, &p); if (ARGS_ERROR == c) return(0); @@ -946,7 +942,7 @@ macro_constant_scoped(MACRO_PROT_ARGS) mdoc->next = MDOC_NEXT_CHILD; } - c = mdoc_args(mdoc, line, pos, buf, ARGS_DELIM, &p); + c = mdoc_args(mdoc, line, pos, buf, tok, &p); if (ARGS_ERROR == c) return(0); if (ARGS_PUNCT == c) @@ -1074,7 +1070,7 @@ macro_constant_delimited(MACRO_PROT_ARGS) flushed = 1; } - c = mdoc_args(mdoc, line, pos, buf, ARGS_DELIM, &p); + c = mdoc_args(mdoc, line, pos, buf, tok, &p); if (ARGS_ERROR == c) return(0); if (ARGS_PUNCT == c) @@ -1120,7 +1116,7 @@ macro_constant_delimited(MACRO_PROT_ARGS) int macro_constant(MACRO_PROT_ARGS) { - int c, w, la, argc, fl; + int c, w, la, argc; struct mdoc_arg argv[MDOC_LINEARG_MAX]; char *p; @@ -1154,13 +1150,9 @@ macro_constant(MACRO_PROT_ARGS) mdoc->next = MDOC_NEXT_CHILD; - fl = 0; - if (MDOC_QUOTABLE & mdoc_macros[tok].flags) - fl = ARGS_QUOTED; - for (;;) { la = *pos; - w = mdoc_args(mdoc, line, pos, buf, fl, &p); + w = mdoc_args(mdoc, line, pos, buf, tok, &p); if (ARGS_ERROR == w) return(0); if (ARGS_EOLN == w) @@ -105,21 +105,21 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { { macro_scoped_close, MDOC_EXPLICIT }, /* Ed */ { macro_scoped, MDOC_EXPLICIT }, /* Bl */ { macro_scoped_close, MDOC_EXPLICIT }, /* El */ - { macro_scoped, MDOC_PARSED | MDOC_TABSEP}, /* It */ + { macro_scoped, MDOC_PARSED }, /* It */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ad */ { macro_text, MDOC_PARSED }, /* An */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ar */ - { macro_constant, MDOC_QUOTABLE }, /* Cd */ + { macro_constant, 0 }, /* Cd */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Cm */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Dv */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Er */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ev */ { macro_constant, 0 }, /* Ex */ - { macro_text, MDOC_CALLABLE | MDOC_QUOTABLE | MDOC_PARSED }, /* Fa */ + { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Fa */ { macro_constant, 0 }, /* Fd */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Fl */ - { macro_text, MDOC_CALLABLE | MDOC_QUOTABLE | MDOC_PARSED }, /* Fn */ - { macro_text, MDOC_PARSED | MDOC_QUOTABLE }, /* Ft */ + { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Fn */ + { macro_text, MDOC_PARSED }, /* Ft */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ic */ { macro_constant, 0 }, /* In */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Li */ @@ -134,17 +134,17 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Va */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Vt */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Xr */ - { macro_constant, MDOC_QUOTABLE }, /* %A */ - { macro_constant, MDOC_QUOTABLE }, /* %B */ - { macro_constant, MDOC_QUOTABLE }, /* %D */ - { macro_constant, MDOC_QUOTABLE }, /* %I */ - { macro_constant, MDOC_QUOTABLE }, /* %J */ - { macro_constant, MDOC_QUOTABLE }, /* %N */ - { macro_constant, MDOC_QUOTABLE }, /* %O */ - { macro_constant, MDOC_QUOTABLE }, /* %P */ - { macro_constant, MDOC_QUOTABLE }, /* %R */ - { macro_constant, MDOC_QUOTABLE }, /* %T */ - { macro_constant, MDOC_QUOTABLE }, /* %V */ + { macro_constant, 0 }, /* %A */ + { macro_constant, 0 }, /* %B */ + { macro_constant, 0 }, /* %D */ + { macro_constant, 0 }, /* %I */ + { macro_constant, 0 }, /* %J */ + { macro_constant, 0 }, /* %N */ + { macro_constant, 0 }, /* %O */ + { macro_constant, 0 }, /* %P */ + { macro_constant, 0 }, /* %R */ + { macro_constant, 0 }, /* %T */ + { macro_constant, 0 }, /* %V */ { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Ac */ { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Ao */ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Aq */ @@ -190,9 +190,9 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Xc */ { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Xo */ /* XXX - .Fo supposed to be (but isn't) callable. */ - { macro_scoped, MDOC_EXPLICIT | MDOC_PARSED }, /* Fo */ + { macro_scoped, MDOC_EXPLICIT }, /* Fo */ /* XXX - .Fc supposed to be (but isn't) callable. */ - { macro_scoped_close, MDOC_EXPLICIT | MDOC_PARSED }, /* Fc */ + { macro_scoped_close, MDOC_EXPLICIT }, /* Fc */ { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Oo */ { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Oc */ { macro_scoped, MDOC_EXPLICIT }, /* Bk */ @@ -60,9 +60,7 @@ struct mdoc_macro { #define MDOC_CALLABLE (1 << 0) #define MDOC_PARSED (1 << 1) #define MDOC_EXPLICIT (1 << 2) -#define MDOC_QUOTABLE (1 << 3) -#define MDOC_PROLOGUE (1 << 4) -#define MDOC_TABSEP (1 << 5) +#define MDOC_PROLOGUE (1 << 3) }; #define mdoc_nwarn(mdoc, node, type, fmt, ...) \ @@ -159,10 +157,6 @@ int mdoc_args(struct mdoc *, int, #define ARGS_PUNCT (2) #define ARGS_QWORD (3) -#define ARGS_QUOTED (1 << 0) -#define ARGS_DELIM (1 << 1) -#define ARGS_TABSEP (1 << 2) - int xstrlcats(char *, const struct mdoc_node *, size_t); int xstrlcat(char *, const char *, size_t); int xstrlcpy(char *, const char *, size_t); @@ -137,6 +137,9 @@ static v_post posts_at[] = { post_at, NULL }; static v_post posts_xr[] = { eerr_ge1, eerr_le2, post_xr, NULL }; static v_post posts_nm[] = { post_nm, NULL }; static v_post posts_bf[] = { herr_le1, post_bf, NULL }; +static v_post posts_rs[] = { herr_eq0, bwarn_ge1, NULL }; +static v_post posts_fo[] = { bwarn_ge1, NULL }; +static v_post posts_bk[] = { herr_eq0, bwarn_ge1, NULL }; /* Per-macro pre- and post-child-check routine collections. */ @@ -228,7 +231,7 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Qo */ { NULL, posts_wline }, /* Qq */ { NULL, NULL }, /* Re */ - { NULL, NULL }, /* Rs */ + { NULL, posts_rs }, /* Rs */ { NULL, NULL }, /* Sc */ { NULL, NULL }, /* So */ { NULL, posts_wline }, /* Sq */ @@ -239,11 +242,11 @@ const struct valids mdoc_valids[MDOC_MAX] = { { NULL, NULL }, /* Ux */ { NULL, NULL }, /* Xc */ { NULL, NULL }, /* Xo */ - { NULL, NULL }, /* Fo */ + { NULL, posts_fo }, /* Fo */ { NULL, NULL }, /* Fc */ { NULL, NULL }, /* Oo */ { NULL, NULL }, /* Oc */ - { NULL, NULL }, /* Bk */ + { NULL, posts_bk }, /* Bk */ { NULL, NULL }, /* Ek */ { NULL, posts_notext }, /* Bt */ { NULL, NULL }, /* Hf */ |