diff options
-rw-r--r-- | mdocml.1 | 10 | ||||
-rw-r--r-- | roff.c | 130 | ||||
-rw-r--r-- | validate.c | 24 |
3 files changed, 109 insertions, 55 deletions
@@ -29,8 +29,8 @@ dictated by The only current output filter is .Ar validate , the default. The arguments are as follows: -.Bl -tag -width "\-o outfile" -.It Fl o Ar outfile +.Bl -tag -width "\-o outfile," +.It Sq Fl o Ar outfile , Place output in .Ar outfile , which may be @@ -42,7 +42,7 @@ Read input from which may be .Qq \- for standard input. The default is standard input. -.It Fl v +.It Fl v Print messages (output depends on filter). .It Fl W Print warnings (output depends on filter). @@ -53,6 +53,10 @@ The validate filter, specified by is the default filter. It produces no output, so specifying .Fl o Ar outfile results in an empty file. +.Qq Op Op Fl a ) , Fl b , +.Bf Em +.Qq Op Op Fl a ) , Fl b , +.Ef .\" The following requests should be uncommented and used where appropriate. .\" This next request is for sections 2, 3, and 9 function return values only. .\" .Sh RETURN VALUES @@ -72,7 +72,6 @@ struct rofftok { #define ROFF_CALLABLE (1 << 1) /* "Callable". */ #define ROFF_QUOTES (1 << 2) /* Quoted args. */ #define ROFF_SHALLOW (1 << 3) /* Nesting block. */ -#define ROFF_PUNCT (1 << 4) }; struct roffarg { @@ -191,33 +190,33 @@ static const struct rofftok tokens[ROFF_MAX] = { { roff_layout, roffarg_Bl, NULL, roffchild_Bl, 0, ROFF_LAYOUT, 0 }, /* Bl */ { roff_close, NULL, roffparent_El, NULL, ROFF_Bl, ROFF_LAYOUT, 0 }, /* El */ { roff_layout, NULL, roffparent_It, NULL, ROFF_It, ROFF_LAYOUT, ROFF_SHALLOW }, /* It */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Ad */ - { roff_text, roffarg_An, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_PUNCT }, /* An */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Ar */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ad */ /* FIXME */ + { roff_text, roffarg_An, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* An */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ar */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_QUOTES }, /* Cd */ /* XXX man.4 only */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Cm */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Dv */ /* XXX needs arg */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Er */ /* XXX needs arg */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Ev */ /* XXX needs arg */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Dv */ /* XXX needs arg */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Er */ /* XXX needs arg */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ev */ /* XXX needs arg */ { roff_text, roffarg_Ex, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Ex */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Fa */ /* XXX needs arg */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Fa */ /* XXX needs arg */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Fd */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Fl */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Fn */ /* XXX needs arg */ /* FIXME */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_PUNCT }, /* Ft */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Ic */ /* XXX needs arg */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Fl */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Fn */ /* XXX needs arg */ /* FIXME */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Ft */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ic */ /* XXX needs arg */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* In */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Li */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Li */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_QUOTES }, /* Nd */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Nm */ /* FIXME */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Op */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Nm */ /* FIXME */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Op */ { NULL, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Ot */ /* XXX deprecated */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Pa */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Pa */ { roff_text, roffarg_Rv, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Rv */ { roff_text, roffarg_St, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* St */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Va */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Vt */ /* XXX needs arg */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Xr */ /* XXX needs arg */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Va */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Vt */ /* XXX needs arg */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Xr */ /* XXX needs arg */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* %A */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE}, /* %B */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* %D */ @@ -237,22 +236,22 @@ static const struct rofftok tokens[ROFF_MAX] = { { NULL, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Bf */ /* FIXME */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Bo */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Bq */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_PUNCT }, /* Bsx */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_PUNCT }, /* Bx */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Bsx */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Bx */ {roff_special, NULL, NULL, NULL, 0, ROFF_SPECIAL, 0 }, /* Db */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Dc */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Do */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Dq */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ec */ { NULL, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Ef */ /* FIXME */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Em */ /* XXX needs arg */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Em */ /* XXX needs arg */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Eo */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_PUNCT }, /* Fx */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_PUNCT }, /* Ms */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Fx */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Ms */ { NULL, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* No */ { NULL, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Ns */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_PUNCT }, /* Nx */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_PUNCT }, /* Ox */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Nx */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Ox */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Pc */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Pf */ { roff_text, NULL, NULL, NULL, 0, ROFF_LAYOUT, ROFF_PARSED | ROFF_CALLABLE }, /* Po */ @@ -268,9 +267,9 @@ static const struct rofftok tokens[ROFF_MAX] = { { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Sq */ {roff_special, NULL, NULL, NULL, 0, ROFF_SPECIAL, 0 }, /* Sm */ { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Sx */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Sy */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE | ROFF_PUNCT }, /* Tn */ - { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_PUNCT }, /* Ux */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Sy */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Tn */ + { roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Ux */ { NULL, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Xc */ { NULL, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Xo */ { roff_layout, NULL, NULL, roffchild_Fo, 0, ROFF_LAYOUT, 0 }, /* Fo */ @@ -697,6 +696,50 @@ rofffindtok(const char *buf) } +#if notyet +static int +roffispunct(const char *p) +{ + + if (0 == *p) + return(0); + if (0 != *(p + 1)) + return(0); + + switch (*p) { + case('{'): + /* FALLTHROUGH */ + case('.'): + /* FALLTHROUGH */ + case(','): + /* FALLTHROUGH */ + case(';'): + /* FALLTHROUGH */ + case(':'): + /* FALLTHROUGH */ + case('?'): + /* FALLTHROUGH */ + case('!'): + /* FALLTHROUGH */ + case('('): + /* FALLTHROUGH */ + case(')'): + /* FALLTHROUGH */ + case('['): + /* FALLTHROUGH */ + case(']'): + /* FALLTHROUGH */ + case('}'): + return(1); + default: + break; + } + + return(0); +} +#endif + + static int rofffindcallable(const char *name) { @@ -1012,20 +1055,27 @@ roff_text(ROFFCALL_ARGS) } while (*argv) { - if (ROFF_MAX != (c = rofffindcallable(*argv))) { - if (NULL == tokens[c].cb) { - roff_err(tree, *argv, "unsupported " - "macro `%s'", - toknames[c]); - return(0); - } - if ( ! (*tokens[c].cb)(c, tree, - argv, ROFF_ENTER)) + if (ROFF_MAX == (c = rofffindcallable(*argv))) { + if ( ! (*tree->cb.roffdata)(tree->arg, *argv++)) return(0); - break; + continue; } - if ( ! (*tree->cb.roffdata)(tree->arg, *argv++)) + + /* + * A sub-command has been found. Execute it and + * discontinue parsing for arguments. + */ + + if (NULL == tokens[c].cb) { + roff_err(tree, *argv, "unsupported macro `%s'", + toknames[c]); + return(0); + } + + if ( ! (*tokens[c].cb)(c, tree, argv, ROFF_ENTER)) return(0); + + break; } return((*tree->cb.roffout)(tree->arg, tok)); @@ -94,9 +94,12 @@ mbuf_newline(struct md_valid *p) static int mbuf_data(struct md_valid *p, char *buf) { + int space; size_t sz; char *bufp; + space = 1; /* FIXME */ + assert(p->mbuf); assert(0 != p->indent); @@ -133,10 +136,7 @@ mbuf_data(struct md_valid *p, char *buf) continue; } - if ( ! md_buf_putchar(p->mbuf, ' ')) - return(0); - - p->pos += sz + 1; + p->pos += sz; continue; } @@ -145,14 +145,14 @@ mbuf_data(struct md_valid *p, char *buf) return(0); if ( ! mbuf_indent(p)) return(0); - } + } else if (space) + if ( ! md_buf_putchar(p->mbuf, ' ')) + return(0); if ( ! md_buf_putstring(p->mbuf, bufp)) return(0); - if ( ! md_buf_putchar(p->mbuf, ' ')) - return(0); - p->pos += sz + 1; + p->pos += sz + (space ? 1 : 0); } return(1); @@ -334,14 +334,14 @@ roffin(void *arg, int tok, int *argcp, char **argvp) if (0 == p->pos && ! mbuf_indent(p)) return(0); - if ( ! md_buf_putstring(p->mbuf, "<")) + if ( ! md_buf_putstring(p->mbuf, " <")) return(0); if ( ! md_buf_putstring(p->mbuf, toknames[tok])) return(0); if ( ! md_buf_putstring(p->mbuf, ">")) return(0); - p->pos += strlen(toknames[tok]) + 2; + p->pos += strlen(toknames[tok]) + 3; return(1); } @@ -362,10 +362,10 @@ roffout(void *arg, int tok) return(0); if ( ! md_buf_putstring(p->mbuf, toknames[tok])) return(0); - if ( ! md_buf_putstring(p->mbuf, "> ")) + if ( ! md_buf_putstring(p->mbuf, ">")) return(0); - p->pos += strlen(toknames[tok]) + 3; + p->pos += strlen(toknames[tok]) + 2; return(1); } |