version 1.50, 2008/12/07 22:40:18 |
version 1.55, 2008/12/09 17:09:12 |
|
|
#include <string.h> |
#include <string.h> |
#include <time.h> |
#include <time.h> |
|
|
#include "libmdocml.h" |
|
#include "private.h" |
#include "private.h" |
#include "roff.h" |
#include "roff.h" |
|
|
/* FIXME: First letters of quoted-text interpreted in rofffindtok. */ |
/* FIXME: First letters of quoted-text interpreted in rofffindtok. */ |
/* FIXME: `No' not implemented. */ |
/* FIXME: `No' not implemented. */ |
/* TODO: warn if Pp occurs before/after Sh etc. (see mdoc.samples). */ |
/* TODO: warn if Pp occurs before/after Sh etc. (see mdoc.samples). */ |
/* TODO: warn about "X section only" macros. */ |
|
/* TODO: warn about empty lists. */ |
/* TODO: warn about empty lists. */ |
/* TODO: (warn) some sections need specific elements. */ |
/* TODO: (warn) some sections need specific elements. */ |
/* TODO: (warn) NAME section has particular order. */ |
/* TODO: (warn) NAME section has particular order. */ |
/* TODO: unify empty-content tags a la <br />. */ |
|
/* TODO: macros with a set number of arguments? */ |
/* TODO: macros with a set number of arguments? */ |
/* TODO: validate Dt macro arguments. */ |
/* TODO: validate Dt macro arguments. */ |
/* FIXME: Bl -diag supposed to ignore callable children. */ |
/* FIXME: Bl -diag supposed to ignore callable children. */ |
/* FIXME: Nm has newline when used in NAME section. */ |
|
|
|
struct roffnode { |
struct roffnode { |
int tok; /* Token id. */ |
int tok; /* Token id. */ |
struct roffnode *parent; /* Parent (or NULL). */ |
struct roffnode *parent; /* Parent (or NULL). */ |
}; |
}; |
|
|
|
enum rofferr { |
|
ERR_ARGEQ1, /* Macro requires arg == 1. */ |
|
ERR_ARGEQ0, /* Macro requires arg == 0. */ |
|
ERR_ARGGE1, /* Macro requires arg >= 1. */ |
|
ERR_ARGGE2, /* Macro requires arg >= 2. */ |
|
ERR_ARGLEN, /* Macro argument too long. */ |
|
ERR_BADARG, /* Macro has bad arg. */ |
|
ERR_ARGMNY, /* Too many macro arguments. */ |
|
ERR_NOTSUP, /* Macro not supported. */ |
|
ERR_DEPREC, /* Macro deprecated. */ |
|
ERR_PR_OOO, /* Prelude macro bad order. */ |
|
ERR_PR_REP, /* Prelude macro repeated. */ |
|
ERR_NOT_PR, /* Not allowed in prelude. */ |
|
WRN_SECORD, /* Sections out-of-order. */ |
|
}; |
|
|
struct rofftree { |
struct rofftree { |
struct roffnode *last; /* Last parsed node. */ |
struct roffnode *last; /* Last parsed node. */ |
char *cur; /* Line start. */ |
char *cur; /* Line start. */ |
Line 57 struct rofftree { |
|
Line 69 struct rofftree { |
|
char name[64]; /* `Nm' results. */ |
char name[64]; /* `Nm' results. */ |
char os[64]; /* `Os' results. */ |
char os[64]; /* `Os' results. */ |
char title[64]; /* `Dt' results. */ |
char title[64]; /* `Dt' results. */ |
char section[64]; /* `Dt' results. */ |
enum roffmsec section; |
char volume[64]; /* `Dt' results. */ |
char volume[64]; /* `Dt' results. */ |
int state; |
int state; |
#define ROFF_PRELUDE (1 << 1) /* In roff prelude. */ |
#define ROFF_PRELUDE (1 << 1) /* In roff prelude. */ /* FIXME: put into asec. */ |
#define ROFF_PRELUDE_Os (1 << 2) /* `Os' is parsed. */ |
#define ROFF_PRELUDE_Os (1 << 2) /* `Os' is parsed. */ |
#define ROFF_PRELUDE_Dt (1 << 3) /* `Dt' is parsed. */ |
#define ROFF_PRELUDE_Dt (1 << 3) /* `Dt' is parsed. */ |
#define ROFF_PRELUDE_Dd (1 << 4) /* `Dd' is parsed. */ |
#define ROFF_PRELUDE_Dd (1 << 4) /* `Dd' is parsed. */ |
#define ROFF_BODY (1 << 5) /* In roff body. */ |
#define ROFF_BODY (1 << 5) /* In roff body. */ |
struct roffcb cb; /* Callbacks. */ |
struct roffcb cb; /* Callbacks. */ |
void *arg; /* Callbacks' arg. */ |
void *arg; /* Callbacks' arg. */ |
|
int csec; /* Current section. */ |
|
int asec; /* Thus-far sections. */ |
}; |
}; |
|
|
static struct roffnode *roffnode_new(int, struct rofftree *); |
static struct roffnode *roffnode_new(int, struct rofftree *); |
static void roffnode_free(struct rofftree *); |
static void roffnode_free(struct rofftree *); |
static void roff_warn(const struct rofftree *, |
static int roff_warn(const struct rofftree *, |
const char *, char *, ...); |
const char *, char *, ...); |
static void roff_err(const struct rofftree *, |
static int roff_warnp(const struct rofftree *, |
|
const char *, int, enum rofferr); |
|
static int roff_err(const struct rofftree *, |
const char *, char *, ...); |
const char *, char *, ...); |
|
static int roff_errp(const struct rofftree *, |
|
const char *, int, enum rofferr); |
static int roffpurgepunct(struct rofftree *, char **); |
static int roffpurgepunct(struct rofftree *, char **); |
static int roffscan(int, const int *); |
static int roffscan(int, const int *); |
static int rofffindtok(const char *); |
static int rofffindtok(const char *); |
static int rofffindarg(const char *); |
static int rofffindarg(const char *); |
static int rofffindcallable(const char *); |
static int rofffindcallable(const char *); |
|
static int roffispunct(const char *); |
|
static int roffchecksec(struct rofftree *, |
|
const char *, int); |
static int roffargs(const struct rofftree *, |
static int roffargs(const struct rofftree *, |
int, char *, char **); |
int, char *, char **); |
static int roffargok(int, int); |
static int roffargok(int, int); |
Line 88 static int roffnextopt(const struct rofftree *, |
|
Line 109 static int roffnextopt(const struct rofftree *, |
|
static int roffparseopts(struct rofftree *, int, |
static int roffparseopts(struct rofftree *, int, |
char ***, int *, char **); |
char ***, int *, char **); |
static int roffcall(struct rofftree *, int, char **); |
static int roffcall(struct rofftree *, int, char **); |
|
static int roffexit(struct rofftree *, int); |
static int roffparse(struct rofftree *, char *); |
static int roffparse(struct rofftree *, char *); |
static int textparse(struct rofftree *, char *); |
static int textparse(struct rofftree *, char *); |
static int roffdata(struct rofftree *, int, char *); |
static int roffdata(struct rofftree *, int, char *); |
Line 119 roff_free(struct rofftree *tree, int flush) |
|
Line 141 roff_free(struct rofftree *tree, int flush) |
|
error = 1; |
error = 1; |
|
|
if (ROFF_PRELUDE & tree->state) { |
if (ROFF_PRELUDE & tree->state) { |
roff_err(tree, NULL, "prelude never finished"); |
(void)roff_err(tree, NULL, "prelude never finished"); |
goto end; |
goto end; |
} |
} else if ( ! (ROFFSec_NAME & tree->asec)) { |
|
(void)roff_err(tree, NULL, "missing `NAME' section"); |
|
goto end; |
|
} else if ( ! (ROFFSec_NMASK & tree->asec)) |
|
(void)roff_warn(tree, NULL, "missing suggested `NAME', " |
|
"`SYNOPSIS', `DESCRIPTION' sections"); |
|
|
for (n = tree->last; n; n = n->parent) { |
for (n = tree->last; n; n = n->parent) { |
if (0 != tokens[n->tok].ctx) |
if (0 != tokens[n->tok].ctx) |
continue; |
continue; |
roff_err(tree, NULL, "closing explicit scope `%s'", |
(void)roff_err(tree, NULL, "closing explicit scope " |
toknames[n->tok]); |
"`%s'", toknames[n->tok]); |
goto end; |
goto end; |
} |
} |
|
|
while (tree->last) { |
while (tree->last) { |
t = tree->last->tok; |
t = tree->last->tok; |
if ( ! (*tokens[t].cb)(t, tree, NULL, ROFF_EXIT)) |
if ( ! roffexit(tree, t)) |
goto end; |
goto end; |
} |
} |
|
|
Line 166 roff_alloc(const struct roffcb *cb, void *args) |
|
Line 193 roff_alloc(const struct roffcb *cb, void *args) |
|
|
|
tree->state = ROFF_PRELUDE; |
tree->state = ROFF_PRELUDE; |
tree->arg = args; |
tree->arg = args; |
|
tree->section = ROFF_MSEC_MAX; |
|
|
(void)memcpy(&tree->cb, cb, sizeof(struct roffcb)); |
(void)memcpy(&tree->cb, cb, sizeof(struct roffcb)); |
|
|
Line 180 roff_engine(struct rofftree *tree, char *buf) |
|
Line 208 roff_engine(struct rofftree *tree, char *buf) |
|
tree->cur = buf; |
tree->cur = buf; |
assert(buf); |
assert(buf); |
|
|
if (0 == *buf) { |
if (0 == *buf) |
roff_err(tree, buf, "blank line"); |
return(roff_err(tree, buf, "blank line")); |
return(0); |
else if ('.' != *buf) |
} else if ('.' != *buf) |
|
return(textparse(tree, buf)); |
return(textparse(tree, buf)); |
|
|
return(roffparse(tree, buf)); |
return(roffparse(tree, buf)); |
Line 197 textparse(struct rofftree *tree, char *buf) |
|
Line 224 textparse(struct rofftree *tree, char *buf) |
|
|
|
/* TODO: literal parsing. */ |
/* TODO: literal parsing. */ |
|
|
if ( ! (ROFF_BODY & tree->state)) { |
if ( ! (ROFF_BODY & tree->state)) |
roff_err(tree, buf, "data not in body"); |
return(roff_err(tree, buf, "data not in body")); |
return(0); |
|
} |
|
|
|
/* LINTED */ |
/* LINTED */ |
while (*buf) { |
while (*buf) { |
Line 256 roffargs(const struct rofftree *tree, |
|
Line 281 roffargs(const struct rofftree *tree, |
|
argv[i] = ++buf; |
argv[i] = ++buf; |
while (*buf && '\"' != *buf) |
while (*buf && '\"' != *buf) |
buf++; |
buf++; |
if (0 == *buf) { |
if (0 == *buf) |
roff_err(tree, argv[i], "unclosed " |
return(roff_err(tree, argv[i], |
"quote in argument " |
"unclosed quote in arg list")); |
"list for `%s'", |
|
toknames[tok]); |
|
return(0); |
|
} |
|
} else { |
} else { |
argv[i] = buf++; |
argv[i] = buf++; |
while (*buf) { |
while (*buf) { |
Line 285 roffargs(const struct rofftree *tree, |
|
Line 306 roffargs(const struct rofftree *tree, |
|
} |
} |
|
|
assert(i > 0); |
assert(i > 0); |
if (ROFF_MAXLINEARG == i && *buf) { |
if (ROFF_MAXLINEARG == i && *buf) |
roff_err(tree, p, "too many arguments for `%s'", toknames |
return(roff_err(tree, p, "too many args")); |
[tok]); |
|
return(0); |
|
} |
|
|
|
argv[i] = NULL; |
argv[i] = NULL; |
return(1); |
return(1); |
Line 323 roffparse(struct rofftree *tree, char *buf) |
|
Line 341 roffparse(struct rofftree *tree, char *buf) |
|
if (0 == strncmp(buf, ".\\\"", 3)) |
if (0 == strncmp(buf, ".\\\"", 3)) |
return(1); |
return(1); |
|
|
if (ROFF_MAX == (tok = rofffindtok(buf + 1))) { |
if (ROFF_MAX == (tok = rofffindtok(buf + 1))) |
roff_err(tree, buf + 1, "bogus line macro"); |
return(roff_err(tree, buf, "bogus line macro")); |
|
else if ( ! roffargs(tree, tok, buf, argv)) |
return(0); |
return(0); |
} else if (NULL == tokens[tok].cb) { |
|
roff_err(tree, buf + 1, "unsupported macro `%s'", |
|
toknames[tok]); |
|
return(0); |
|
} |
|
|
|
assert(ROFF___ != tok); |
|
if ( ! roffargs(tree, tok, buf, argv)) |
|
return(0); |
|
|
|
argvp = (char **)argv; |
argvp = (char **)argv; |
|
|
/* |
/* |
Line 344 roffparse(struct rofftree *tree, char *buf) |
|
Line 354 roffparse(struct rofftree *tree, char *buf) |
|
|
|
if (ROFF_PRELUDE & tree->state) { |
if (ROFF_PRELUDE & tree->state) { |
assert(NULL == tree->last); |
assert(NULL == tree->last); |
return((*tokens[tok].cb)(tok, tree, argvp, ROFF_ENTER)); |
return(roffcall(tree, tok, argvp)); |
} |
} |
|
|
assert(ROFF_BODY & tree->state); |
assert(ROFF_BODY & tree->state); |
Line 355 roffparse(struct rofftree *tree, char *buf) |
|
Line 365 roffparse(struct rofftree *tree, char *buf) |
|
*/ |
*/ |
|
|
if (tree->last && ! roffscan |
if (tree->last && ! roffscan |
(tree->last->tok, tokens[tok].parents)) { |
(tree->last->tok, tokens[tok].parents)) |
roff_err(tree, *argvp, "`%s' has invalid parent `%s'", |
return(roff_err(tree, *argvp, "`%s' has invalid " |
toknames[tok], |
"parent `%s'", toknames[tok], |
toknames[tree->last->tok]); |
toknames[tree->last->tok])); |
return(0); |
|
} |
|
|
|
if (tree->last && ! roffscan |
if (tree->last && ! roffscan |
(tok, tokens[tree->last->tok].children)) { |
(tok, tokens[tree->last->tok].children)) |
roff_err(tree, *argvp, "`%s' is invalid child of `%s'", |
return(roff_err(tree, *argvp, "`%s' has invalid " |
toknames[tok], |
"child `%s'", toknames[tok], |
toknames[tree->last->tok]); |
toknames[tree->last->tok])); |
return(0); |
|
} |
|
|
|
/* |
/* |
* Branch if we're not a layout token. |
* Branch if we're not a layout token. |
*/ |
*/ |
|
|
if (ROFF_LAYOUT != tokens[tok].type) |
if (ROFF_LAYOUT != tokens[tok].type) |
return((*tokens[tok].cb)(tok, tree, argvp, ROFF_ENTER)); |
return(roffcall(tree, tok, argvp)); |
if (0 == tokens[tok].ctx) |
if (0 == tokens[tok].ctx) |
return((*tokens[tok].cb)(tok, tree, argvp, ROFF_ENTER)); |
return(roffcall(tree, tok, argvp)); |
|
|
/* |
/* |
* First consider implicit-end tags, like as follows: |
* First consider implicit-end tags, like as follows: |
Line 408 roffparse(struct rofftree *tree, char *buf) |
|
Line 414 roffparse(struct rofftree *tree, char *buf) |
|
} |
} |
if (tokens[n->tok].ctx == n->tok) |
if (tokens[n->tok].ctx == n->tok) |
continue; |
continue; |
roff_err(tree, *argv, "`%s' breaks `%s' scope", |
return(roff_err(tree, *argv, "`%s' breaks " |
toknames[tok], toknames[n->tok]); |
"scope of prior`%s'", |
return(0); |
toknames[tok], |
|
toknames[n->tok])); |
} |
} |
|
|
/* |
/* |
Line 419 roffparse(struct rofftree *tree, char *buf) |
|
Line 426 roffparse(struct rofftree *tree, char *buf) |
|
*/ |
*/ |
|
|
if (NULL == n) |
if (NULL == n) |
return((*tokens[tok].cb)(tok, tree, argvp, ROFF_ENTER)); |
return(roffcall(tree, tok, argvp)); |
|
|
/* |
/* |
* Close out all intermediary scoped blocks, then hang |
* Close out all intermediary scoped blocks, then hang |
Line 428 roffparse(struct rofftree *tree, char *buf) |
|
Line 435 roffparse(struct rofftree *tree, char *buf) |
|
|
|
do { |
do { |
t = tree->last->tok; |
t = tree->last->tok; |
if ( ! (*tokens[t].cb)(t, tree, NULL, ROFF_EXIT)) |
if ( ! roffexit(tree, t)) |
return(0); |
return(0); |
} while (t != tok); |
} while (t != tok); |
|
|
return((*tokens[tok].cb)(tok, tree, argvp, ROFF_ENTER)); |
return(roffcall(tree, tok, argvp)); |
} |
} |
|
|
/* |
/* |
Line 451 roffparse(struct rofftree *tree, char *buf) |
|
Line 458 roffparse(struct rofftree *tree, char *buf) |
|
if (n->tok != tokens[tok].ctx) { |
if (n->tok != tokens[tok].ctx) { |
if (n->tok == tokens[n->tok].ctx) |
if (n->tok == tokens[n->tok].ctx) |
continue; |
continue; |
roff_err(tree, *argv, "`%s' breaks `%s' scope", |
return(roff_err(tree, *argv, "`%s' breaks " |
toknames[tok], toknames[n->tok]); |
"scope of prior `%s'", |
return(0); |
toknames[tok], |
|
toknames[n->tok])); |
} else |
} else |
break; |
break; |
|
|
|
if (NULL == n) |
|
return(roff_err(tree, *argv, "`%s' has no starting " |
|
"tag `%s'", toknames[tok], |
|
toknames[tokens[tok].ctx])); |
|
|
if (NULL == n) { |
|
roff_err(tree, *argv, "`%s' has no starting tag `%s'", |
|
toknames[tok], |
|
toknames[tokens[tok].ctx]); |
|
return(0); |
|
} |
|
|
|
/* LINTED */ |
/* LINTED */ |
do { |
do { |
t = tree->last->tok; |
t = tree->last->tok; |
if ( ! (*tokens[t].cb)(t, tree, NULL, ROFF_EXIT)) |
if ( ! roffexit(tree, t)) |
return(0); |
return(0); |
} while (t != tokens[tok].ctx); |
} while (t != tokens[tok].ctx); |
|
|
Line 520 rofffindtok(const char *buf) |
|
Line 525 rofffindtok(const char *buf) |
|
|
|
|
|
static int |
static int |
|
roffchecksec(struct rofftree *tree, const char *start, int sec) |
|
{ |
|
int prior; |
|
|
|
switch (sec) { |
|
case(ROFFSec_SYNOP): |
|
if ((prior = ROFFSec_NAME) & tree->asec) |
|
return(1); |
|
break; |
|
case(ROFFSec_DESC): |
|
if ((prior = ROFFSec_SYNOP) & tree->asec) |
|
return(1); |
|
break; |
|
case(ROFFSec_RETVAL): |
|
if ((prior = ROFFSec_DESC) & tree->asec) |
|
return(1); |
|
break; |
|
case(ROFFSec_ENV): |
|
if ((prior = ROFFSec_RETVAL) & tree->asec) |
|
return(1); |
|
break; |
|
case(ROFFSec_FILES): |
|
if ((prior = ROFFSec_ENV) & tree->asec) |
|
return(1); |
|
break; |
|
case(ROFFSec_EX): |
|
if ((prior = ROFFSec_FILES) & tree->asec) |
|
return(1); |
|
break; |
|
case(ROFFSec_DIAG): |
|
if ((prior = ROFFSec_EX) & tree->asec) |
|
return(1); |
|
break; |
|
case(ROFFSec_ERRS): |
|
if ((prior = ROFFSec_DIAG) & tree->asec) |
|
return(1); |
|
break; |
|
case(ROFFSec_SEEALSO): |
|
if ((prior = ROFFSec_ERRS) & tree->asec) |
|
return(1); |
|
break; |
|
case(ROFFSec_STAND): |
|
if ((prior = ROFFSec_SEEALSO) & tree->asec) |
|
return(1); |
|
break; |
|
case(ROFFSec_HIST): |
|
if ((prior = ROFFSec_STAND) & tree->asec) |
|
return(1); |
|
break; |
|
case(ROFFSec_AUTH): |
|
if ((prior = ROFFSec_HIST) & tree->asec) |
|
return(1); |
|
break; |
|
case(ROFFSec_CAVEATS): |
|
if ((prior = ROFFSec_AUTH) & tree->asec) |
|
return(1); |
|
break; |
|
case(ROFFSec_BUGS): |
|
if ((prior = ROFFSec_CAVEATS) & tree->asec) |
|
return(1); |
|
break; |
|
default: |
|
return(1); |
|
} |
|
|
|
return(roff_warnp(tree, start, ROFF_Sh, WRN_SECORD)); |
|
} |
|
|
|
|
|
/* FIXME: move this into literals.c (or similar). */ |
|
static int |
roffispunct(const char *p) |
roffispunct(const char *p) |
{ |
{ |
|
|
Line 628 roffspecial(struct rofftree *tree, int tok, const char |
|
Line 704 roffspecial(struct rofftree *tree, int tok, const char |
|
case (ROFF_At): |
case (ROFF_At): |
if (0 == sz) |
if (0 == sz) |
break; |
break; |
if (0 == strcmp(*ordp, "v6")) |
if (ROFF_ATT_MAX == roff_att(*ordp)) |
break; |
break; |
else if (0 == strcmp(*ordp, "v7")) |
return(roff_errp(tree, *ordp, tok, ERR_BADARG)); |
break; |
|
else if (0 == strcmp(*ordp, "32v")) |
|
break; |
|
else if (0 == strcmp(*ordp, "V.1")) |
|
break; |
|
else if (0 == strcmp(*ordp, "V.4")) |
|
break; |
|
roff_err(tree, start, "invalid `At' arg"); |
|
return(0); |
|
|
|
case (ROFF_Xr): |
case (ROFF_Xr): |
|
if (2 == sz) { |
|
assert(ordp[1]); |
|
if (ROFF_MSEC_MAX != roff_msec(ordp[1])) |
|
break; |
|
if ( ! roff_warn(tree, start, "invalid `%s' manual " |
|
"section", toknames[tok])) |
|
return(0); |
|
} |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
|
|
|
case (ROFF_Sx): |
|
/* FALLTHROUGH*/ |
case (ROFF_Fn): |
case (ROFF_Fn): |
if (0 != sz) |
if (0 != sz) |
break; |
break; |
roff_err(tree, start, "`%s' expects at least " |
return(roff_errp(tree, start, tok, ERR_ARGGE1)); |
"one arg", toknames[tok]); |
|
return(0); |
|
|
|
case (ROFF_Nm): |
case (ROFF_Nm): |
if (0 == sz) { |
if (0 == sz) { |
if (0 == tree->name[0]) { |
if (0 != tree->name[0]) { |
roff_err(tree, start, "`Nm' not set"); |
ordp[0] = tree->name; |
return(0); |
ordp[1] = NULL; |
|
break; |
} |
} |
ordp[0] = tree->name; |
return(roff_err(tree, start, "`Nm' not set")); |
ordp[1] = NULL; |
|
} else if ( ! roffsetname(tree, ordp)) |
} else if ( ! roffsetname(tree, ordp)) |
return(0); |
return(0); |
break; |
break; |
|
|
case (ROFF_Rv): |
case (ROFF_Rv): |
/* FALLTHROUGH*/ |
/* FALLTHROUGH*/ |
case (ROFF_Sx): |
|
/* FALLTHROUGH*/ |
|
case (ROFF_Ex): |
case (ROFF_Ex): |
if (1 == sz) |
if (1 == sz) |
break; |
break; |
roff_err(tree, start, "`%s' expects one arg", |
return(roff_errp(tree, start, tok, ERR_ARGEQ1)); |
toknames[tok]); |
|
return(0); |
|
|
|
case (ROFF_Sm): |
case (ROFF_Sm): |
if (1 != sz) { |
if (1 != sz) |
roff_err(tree, start, "`Sm' expects one arg"); |
return(roff_errp(tree, start, tok, ERR_ARGEQ1)); |
return(0); |
else if (0 == strcmp(ordp[0], "on") || |
} |
0 == strcmp(ordp[0], "off")) |
|
break; |
if (0 != strcmp(ordp[0], "on") && |
return(roff_errp(tree, *ordp, tok, ERR_BADARG)); |
0 != strcmp(ordp[0], "off")) { |
|
roff_err(tree, start, "`Sm' has invalid argument"); |
|
return(0); |
|
} |
|
break; |
|
|
|
case (ROFF_Ud): |
case (ROFF_Ud): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (ROFF_Ux): |
case (ROFF_Ux): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (ROFF_Bt): |
case (ROFF_Bt): |
if (0 != sz) { |
if (0 == sz) |
roff_err(tree, start, "`%s' expects no args", |
break; |
toknames[tok]); |
return(roff_errp(tree, start, tok, ERR_ARGEQ0)); |
return(0); |
|
} |
|
break; |
|
default: |
default: |
break; |
break; |
} |
} |
Line 707 roffspecial(struct rofftree *tree, int tok, const char |
|
Line 771 roffspecial(struct rofftree *tree, int tok, const char |
|
|
|
|
|
static int |
static int |
|
roffexit(struct rofftree *tree, int tok) |
|
{ |
|
|
|
assert(tokens[tok].cb); |
|
return((*tokens[tok].cb)(tok, tree, NULL, ROFF_EXIT)); |
|
} |
|
|
|
|
|
static int |
roffcall(struct rofftree *tree, int tok, char **argv) |
roffcall(struct rofftree *tree, int tok, char **argv) |
{ |
{ |
|
int i; |
|
enum roffmsec c; |
|
|
if (NULL == tokens[tok].cb) { |
if (NULL == tokens[tok].cb) |
roff_err(tree, *argv, "unsupported macro `%s'", |
return(roff_errp(tree, *argv, tok, ERR_NOTSUP)); |
toknames[tok]); |
|
return(0); |
if (tokens[tok].sections && ROFF_MSEC_MAX != tree->section) { |
|
i = 0; |
|
while (ROFF_MSEC_MAX != |
|
(c = tokens[tok].sections[i++])) |
|
if (c == tree->section) |
|
break; |
|
if (ROFF_MSEC_MAX == c) { |
|
if ( ! roff_warn(tree, *argv, "`%s' is not a valid " |
|
"macro in this manual section", |
|
toknames[tok])) |
|
return(0); |
|
} |
} |
} |
if ( ! (*tokens[tok].cb)(tok, tree, argv, ROFF_ENTER)) |
|
return(0); |
return((*tokens[tok].cb)(tok, tree, argv, ROFF_ENTER)); |
return(1); |
|
} |
} |
|
|
|
|
Line 738 roffnextopt(const struct rofftree *tree, int tok, |
|
Line 823 roffnextopt(const struct rofftree *tree, int tok, |
|
return(-1); |
return(-1); |
|
|
if (ROFF_ARGMAX == (v = rofffindarg(arg + 1))) { |
if (ROFF_ARGMAX == (v = rofffindarg(arg + 1))) { |
roff_warn(tree, arg, "argument-like parameter `%s' to " |
if ( ! roff_warn(tree, arg, "argument-like parameter `%s' to " |
"`%s'", arg, toknames[tok]); |
"`%s'", arg, toknames[tok])) |
|
return(ROFF_ARGMAX); |
return(-1); |
return(-1); |
} |
} |
|
|
if ( ! roffargok(tok, v)) { |
if ( ! roffargok(tok, v)) { |
roff_warn(tree, arg, "invalid argument parameter `%s' to " |
if ( ! roff_warn(tree, arg, "invalid argument parameter `%s' to " |
"`%s'", tokargnames[v], toknames[tok]); |
"`%s'", tokargnames[v], toknames[tok])) |
|
return(ROFF_ARGMAX); |
return(-1); |
return(-1); |
} |
} |
|
|
Line 755 roffnextopt(const struct rofftree *tree, int tok, |
|
Line 842 roffnextopt(const struct rofftree *tree, int tok, |
|
*in = ++argv; |
*in = ++argv; |
|
|
if (NULL == *argv) { |
if (NULL == *argv) { |
roff_err(tree, arg, "empty value of `%s' for `%s'", |
(void)roff_err(tree, arg, "empty value of `%s' for `%s'", |
tokargnames[v], toknames[tok]); |
tokargnames[v], toknames[tok]); |
return(ROFF_ARGMAX); |
return(ROFF_ARGMAX); |
} |
} |
Line 829 roff_Dd(ROFFCALL_ARGS) |
|
Line 916 roff_Dd(ROFFCALL_ARGS) |
|
{ |
{ |
time_t t; |
time_t t; |
char *p, buf[32]; |
char *p, buf[32]; |
|
size_t sz; |
|
|
if (ROFF_BODY & tree->state) { |
if (ROFF_BODY & tree->state) { |
assert( ! (ROFF_PRELUDE & tree->state)); |
assert( ! (ROFF_PRELUDE & tree->state)); |
Line 839 roff_Dd(ROFFCALL_ARGS) |
|
Line 927 roff_Dd(ROFFCALL_ARGS) |
|
assert(ROFF_PRELUDE & tree->state); |
assert(ROFF_PRELUDE & tree->state); |
assert( ! (ROFF_BODY & tree->state)); |
assert( ! (ROFF_BODY & tree->state)); |
|
|
if (ROFF_PRELUDE_Dd & tree->state) { |
if (ROFF_PRELUDE_Dd & tree->state) |
roff_err(tree, *argv, "repeated `Dd' in prelude"); |
return(roff_errp(tree, *argv, tok, ERR_PR_REP)); |
return(0); |
if (ROFF_PRELUDE_Dt & tree->state) |
} else if (ROFF_PRELUDE_Dt & tree->state) { |
return(roff_errp(tree, *argv, tok, ERR_PR_OOO)); |
roff_err(tree, *argv, "out-of-order `Dd' in prelude"); |
|
return(0); |
|
} |
|
|
|
assert(NULL == tree->last); |
assert(NULL == tree->last); |
|
|
argv++; |
argv++; |
|
|
|
/* |
|
* This is a bit complex because there are many forms the date |
|
* can be in: it can be simply $Mdocdate$, $Mdocdate <date>$, |
|
* or a raw date. Process accordingly. |
|
*/ |
|
|
if (0 == strcmp(*argv, "$Mdocdate$")) { |
if (0 == strcmp(*argv, "$Mdocdate$")) { |
t = time(NULL); |
t = time(NULL); |
if (NULL == localtime_r(&t, &tree->tm)) |
if (NULL == localtime_r(&t, &tree->tm)) |
Line 859 roff_Dd(ROFFCALL_ARGS) |
|
Line 950 roff_Dd(ROFFCALL_ARGS) |
|
return(1); |
return(1); |
} |
} |
|
|
/* Build this from Mdocdate or raw date. */ |
|
|
|
buf[0] = 0; |
buf[0] = 0; |
p = *argv; |
p = *argv; |
|
sz = sizeof(buf); |
|
|
if (0 != strcmp(*argv, "$Mdocdate:")) { |
if (0 != strcmp(*argv, "$Mdocdate:")) { |
while (*argv) { |
while (*argv) { |
if (strlcat(buf, *argv++, sizeof(buf)) |
if (strlcat(buf, *argv++, sz) < sz) |
< sizeof(buf)) |
|
continue; |
continue; |
roff_err(tree, p, "bad `Dd' date"); |
return(roff_errp(tree, p, tok, ERR_BADARG)); |
return(0); |
|
} |
} |
if (strptime(buf, "%b%d,%Y", &tree->tm)) { |
if (strptime(buf, "%b%d,%Y", &tree->tm)) { |
tree->state |= ROFF_PRELUDE_Dd; |
tree->state |= ROFF_PRELUDE_Dd; |
return(1); |
return(1); |
} |
} |
roff_err(tree, *argv, "bad `Dd' date"); |
return(roff_errp(tree, p, tok, ERR_BADARG)); |
return(0); |
|
} |
} |
|
|
argv++; |
argv++; |
|
|
while (*argv && **argv != '$') { |
while (*argv && **argv != '$') { |
if (strlcat(buf, *argv++, sizeof(buf)) |
if (strlcat(buf, *argv++, sz) >= sz) |
>= sizeof(buf)) { |
return(roff_errp(tree, p, tok, ERR_BADARG)); |
roff_err(tree, p, "bad `Dd' Mdocdate"); |
if (strlcat(buf, " ", sz) >= sz) |
return(0); |
return(roff_errp(tree, p, tok, ERR_BADARG)); |
} |
|
if (strlcat(buf, " ", sizeof(buf)) |
|
>= sizeof(buf)) { |
|
roff_err(tree, p, "bad `Dd' Mdocdate"); |
|
return(0); |
|
} |
|
} |
} |
if (NULL == *argv) { |
|
roff_err(tree, p, "bad `Dd' Mdocdate"); |
|
return(0); |
|
} |
|
|
|
if (NULL == strptime(buf, "%b %d %Y", &tree->tm)) { |
if (NULL == *argv) |
roff_err(tree, *argv, "bad `Dd' Mdocdate"); |
return(roff_errp(tree, p, tok, ERR_BADARG)); |
return(0); |
if (NULL == strptime(buf, "%b %d %Y", &tree->tm)) |
} |
return(roff_errp(tree, p, tok, ERR_BADARG)); |
|
|
tree->state |= ROFF_PRELUDE_Dd; |
tree->state |= ROFF_PRELUDE_Dd; |
return(1); |
return(1); |
Line 912 roff_Dd(ROFFCALL_ARGS) |
|
Line 990 roff_Dd(ROFFCALL_ARGS) |
|
static int |
static int |
roff_Dt(ROFFCALL_ARGS) |
roff_Dt(ROFFCALL_ARGS) |
{ |
{ |
|
size_t sz; |
|
|
if (ROFF_BODY & tree->state) { |
if (ROFF_BODY & tree->state) { |
assert( ! (ROFF_PRELUDE & tree->state)); |
assert( ! (ROFF_PRELUDE & tree->state)); |
Line 922 roff_Dt(ROFFCALL_ARGS) |
|
Line 1001 roff_Dt(ROFFCALL_ARGS) |
|
assert(ROFF_PRELUDE & tree->state); |
assert(ROFF_PRELUDE & tree->state); |
assert( ! (ROFF_BODY & tree->state)); |
assert( ! (ROFF_BODY & tree->state)); |
|
|
if ( ! (ROFF_PRELUDE_Dd & tree->state)) { |
if ( ! (ROFF_PRELUDE_Dd & tree->state)) |
roff_err(tree, *argv, "out-of-order `Dt' in prelude"); |
return(roff_errp(tree, *argv, tok, ERR_PR_OOO)); |
return(0); |
if (ROFF_PRELUDE_Dt & tree->state) |
} else if (ROFF_PRELUDE_Dt & tree->state) { |
return(roff_errp(tree, *argv, tok, ERR_PR_REP)); |
roff_err(tree, *argv, "repeated `Dt' in prelude"); |
|
return(0); |
|
} |
|
|
|
argv++; |
argv++; |
if (NULL == *argv) { |
sz = sizeof(tree->title); |
roff_err(tree, *argv, "`Dt' needs document title"); |
|
return(0); |
|
} else if (strlcpy(tree->title, *argv, sizeof(tree->title)) |
|
>= sizeof(tree->title)) { |
|
roff_err(tree, *argv, "`Dt' document title too long"); |
|
return(0); |
|
} |
|
|
|
|
if (NULL == *argv) |
|
return(roff_errp(tree, *argv, tok, ERR_ARGGE2)); |
|
if (strlcpy(tree->title, *argv, sz) >= sz) |
|
return(roff_errp(tree, *argv, tok, ERR_ARGLEN)); |
|
|
argv++; |
argv++; |
if (NULL == *argv) { |
if (NULL == *argv) |
roff_err(tree, *argv, "`Dt' needs section"); |
return(roff_errp(tree, *argv, tok, ERR_ARGGE2)); |
return(0); |
|
} else if (strlcpy(tree->section, *argv, sizeof(tree->section)) |
|
>= sizeof(tree->section)) { |
|
roff_err(tree, *argv, "`Dt' section too long"); |
|
return(0); |
|
} |
|
|
|
|
if (ROFF_MSEC_MAX == (tree->section = roff_msec(*argv))) |
|
return(roff_errp(tree, *argv, tok, ERR_BADARG)); |
|
|
argv++; |
argv++; |
|
sz = sizeof(tree->volume); |
|
|
if (NULL == *argv) { |
if (NULL == *argv) { |
tree->volume[0] = 0; |
tree->volume[0] = 0; |
} else if (strlcpy(tree->volume, *argv, sizeof(tree->volume)) |
} else if (strlcpy(tree->volume, *argv, sz) >= sz) |
>= sizeof(tree->volume)) { |
return(roff_errp(tree, *argv, tok, ERR_ARGLEN)); |
roff_err(tree, *argv, "`Dt' volume too long"); |
|
return(0); |
|
} |
|
|
|
assert(NULL == tree->last); |
assert(NULL == tree->last); |
tree->state |= ROFF_PRELUDE_Dt; |
tree->state |= ROFF_PRELUDE_Dt; |
Line 969 roff_Dt(ROFFCALL_ARGS) |
|
Line 1039 roff_Dt(ROFFCALL_ARGS) |
|
static int |
static int |
roffsetname(struct rofftree *tree, char **ordp) |
roffsetname(struct rofftree *tree, char **ordp) |
{ |
{ |
|
size_t sz; |
|
|
assert(*ordp); |
assert(*ordp); |
|
|
/* FIXME: not all sections can set this. */ |
/* FIXME: not all sections can set this. */ |
|
|
if (NULL != *(ordp + 1)) { |
if (NULL != *(ordp + 1)) |
roff_err(tree, *ordp, "too many `Nm' args"); |
return(roff_errp(tree, *ordp, ROFF_Nm, ERR_ARGMNY)); |
return(0); |
|
} |
|
|
|
if (strlcpy(tree->name, *ordp, sizeof(tree->name)) |
sz = sizeof(tree->name); |
>= sizeof(tree->name)) { |
if (strlcpy(tree->name, *ordp, sz) >= sz) |
roff_err(tree, *ordp, "`Nm' arg too long"); |
return(roff_errp(tree, *ordp, ROFF_Nm, ERR_ARGLEN)); |
return(0); |
|
} |
|
|
|
return(1); |
return(1); |
} |
} |
|
|
roff_Os(ROFFCALL_ARGS) |
roff_Os(ROFFCALL_ARGS) |
{ |
{ |
char *p; |
char *p; |
|
size_t sz; |
|
|
if (ROFF_BODY & tree->state) { |
if (ROFF_BODY & tree->state) { |
assert( ! (ROFF_PRELUDE & tree->state)); |
assert( ! (ROFF_PRELUDE & tree->state)); |
Line 1049 roff_Os(ROFFCALL_ARGS) |
|
Line 1117 roff_Os(ROFFCALL_ARGS) |
|
|
|
assert(ROFF_PRELUDE & tree->state); |
assert(ROFF_PRELUDE & tree->state); |
if ( ! (ROFF_PRELUDE_Dt & tree->state) || |
if ( ! (ROFF_PRELUDE_Dt & tree->state) || |
! (ROFF_PRELUDE_Dd & tree->state)) { |
! (ROFF_PRELUDE_Dd & tree->state)) |
roff_err(tree, *argv, "out-of-order `Os' in prelude"); |
return(roff_errp(tree, *argv, tok, ERR_PR_OOO)); |
return(0); |
|
} |
|
|
|
tree->os[0] = 0; |
tree->os[0] = 0; |
|
|
p = *++argv; |
p = *++argv; |
|
sz = sizeof(tree->os); |
|
|
while (*argv) { |
while (*argv) |
if (strlcat(tree->os, *argv++, sizeof(tree->os)) |
if (strlcat(tree->os, *argv++, sz) >= sz) |
< sizeof(tree->os)) |
return(roff_errp(tree, p, tok, ERR_ARGLEN)); |
continue; |
|
roff_err(tree, p, "`Os' value too long"); |
|
return(0); |
|
} |
|
|
|
if (0 == tree->os[0]) |
if (0 == tree->os[0]) |
if (strlcpy(tree->os, "LOCAL", sizeof(tree->os)) |
if (strlcpy(tree->os, "LOCAL", sz) >= sz) |
>= sizeof(tree->os)) { |
return(roff_errp(tree, p, tok, ERR_ARGLEN)); |
roff_err(tree, p, "`Os' value too long"); |
|
return(0); |
|
} |
|
|
|
tree->state |= ROFF_PRELUDE_Os; |
tree->state |= ROFF_PRELUDE_Os; |
tree->state &= ~ROFF_PRELUDE; |
tree->state &= ~ROFF_PRELUDE; |
tree->state |= ROFF_BODY; |
tree->state |= ROFF_BODY; |
|
|
|
assert(ROFF_MSEC_MAX != tree->section); |
|
assert(0 != tree->title[0]); |
|
assert(0 != tree->os[0]); |
|
|
assert(NULL == tree->last); |
assert(NULL == tree->last); |
|
|
return((*tree->cb.roffhead)(tree->arg, &tree->tm, |
return((*tree->cb.roffhead)(tree->arg, &tree->tm, |
tree->os, tree->title, tree->section, |
tree->os, tree->title, |
tree->volume)); |
tree->section, tree->volume)); |
} |
} |
|
|
|
|
|
|
roff_layout(ROFFCALL_ARGS) |
roff_layout(ROFFCALL_ARGS) |
{ |
{ |
int i, c, argcp[ROFF_MAXLINEARG]; |
int i, c, argcp[ROFF_MAXLINEARG]; |
char *argvp[ROFF_MAXLINEARG]; |
char *argvp[ROFF_MAXLINEARG], *p; |
|
|
if (ROFF_PRELUDE & tree->state) { |
/* |
roff_err(tree, *argv, "bad `%s' in prelude", |
* The roff_layout function is for multi-line macros. A layout |
toknames[tok]); |
* has a start and end point, which is either declared |
return(0); |
* explicitly or implicitly. An explicit start and end is |
} else if (ROFF_EXIT == type) { |
* embodied by `.Bl' and `.El', with the former being the start |
|
* and the latter being an end. The `.Sh' and `.Ss' tags, on |
|
* the other hand, are implicit. The scope of a layout is the |
|
* space between start and end. Explicit layouts may not close |
|
* out implicit ones and vice versa; implicit layouts may close |
|
* out other implicit layouts. |
|
*/ |
|
|
|
assert( ! (ROFF_CALLABLE & tokens[tok].flags)); |
|
|
|
if (ROFF_PRELUDE & tree->state) |
|
return(roff_errp(tree, *argv, tok, ERR_NOT_PR)); |
|
|
|
if (ROFF_EXIT == type) { |
roffnode_free(tree); |
roffnode_free(tree); |
if ( ! (*tree->cb.roffblkbodyout)(tree->arg, tok)) |
if ( ! (*tree->cb.roffblkbodyout)(tree->arg, tok)) |
return(0); |
return(0); |
Line 1105 roff_layout(ROFFCALL_ARGS) |
|
Line 1182 roff_layout(ROFFCALL_ARGS) |
|
|
|
assert( ! (ROFF_CALLABLE & tokens[tok].flags)); |
assert( ! (ROFF_CALLABLE & tokens[tok].flags)); |
|
|
++argv; |
p = *argv++; |
|
|
if ( ! roffparseopts(tree, tok, &argv, argcp, argvp)) |
if ( ! roffparseopts(tree, tok, &argv, argcp, argvp)) |
return(0); |
return(0); |
Line 1116 roff_layout(ROFFCALL_ARGS) |
|
Line 1193 roff_layout(ROFFCALL_ARGS) |
|
* Layouts have two parts: the layout body and header. The |
* Layouts have two parts: the layout body and header. The |
* layout header is the trailing text of the line macro, while |
* layout header is the trailing text of the line macro, while |
* the layout body is everything following until termination. |
* the layout body is everything following until termination. |
|
* Example: |
|
* |
|
* .It Fl f ) ; |
|
* Bar. |
|
* |
|
* ...Produces... |
|
* |
|
* <block> |
|
* <head> |
|
* <!Fl f!> ; |
|
* </head> |
|
* |
|
* <body> |
|
* Bar. |
|
* </body> |
|
* </block> |
*/ |
*/ |
|
|
if ( ! (*tree->cb.roffblkin)(tree->arg, tok, argcp, |
if ( ! (*tree->cb.roffblkin)(tree->arg, tok, argcp, |
(const char **)argvp)) |
(const char **)argvp)) |
return(0); |
return(0); |
|
|
|
/* +++ Begin run macro-specific hooks over argv. */ |
|
|
|
switch (tok) { |
|
case (ROFF_Sh): |
|
if (NULL == *argv) { |
|
argv--; |
|
return(roff_errp(tree, *argv, tok, ERR_ARGGE1)); |
|
} |
|
|
|
tree->csec = roff_sec((const char **)argv); |
|
|
|
if ( ! (ROFFSec_OTHER & tree->csec) && |
|
tree->asec & tree->csec) |
|
if ( ! roff_warn(tree, *argv, "section repeated")) |
|
return(0); |
|
|
|
if (0 == tree->asec && ! (ROFFSec_NAME & tree->csec)) |
|
return(roff_err(tree, *argv, "`NAME' section " |
|
"must be first")); |
|
if ( ! roffchecksec(tree, *argv, tree->csec)) |
|
return(0); |
|
|
|
tree->asec |= tree->csec; |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
/* --- End run macro-specific hooks over argv. */ |
|
|
if (NULL == *argv) |
if (NULL == *argv) |
return((*tree->cb.roffblkbodyin) |
return((*tree->cb.roffblkbodyin) |
(tree->arg, tok, argcp, |
(tree->arg, tok, argcp, |
Line 1143 roff_layout(ROFFCALL_ARGS) |
|
Line 1267 roff_layout(ROFFCALL_ARGS) |
|
|
|
if ( ! (*tree->cb.roffblkheadout)(tree->arg, tok)) |
if ( ! (*tree->cb.roffblkheadout)(tree->arg, tok)) |
return(0); |
return(0); |
return((*tree->cb.roffblkbodyin) |
return((*tree->cb.roffblkbodyin)(tree->arg, tok, argcp, |
(tree->arg, tok, argcp, |
|
(const char **)argvp)); |
(const char **)argvp)); |
} |
} |
|
|
Line 1187 roff_layout(ROFFCALL_ARGS) |
|
Line 1310 roff_layout(ROFFCALL_ARGS) |
|
|
|
if ( ! roffpurgepunct(tree, argv)) |
if ( ! roffpurgepunct(tree, argv)) |
return(0); |
return(0); |
|
|
if ( ! (*tree->cb.roffblkheadout)(tree->arg, tok)) |
if ( ! (*tree->cb.roffblkheadout)(tree->arg, tok)) |
return(0); |
return(0); |
return((*tree->cb.roffblkbodyin) |
return((*tree->cb.roffblkbodyin)(tree->arg, |
(tree->arg, tok, argcp, |
tok, argcp, (const char **)argvp)); |
(const char **)argvp)); |
|
} |
} |
|
|
|
|
Line 1204 roff_ordered(ROFFCALL_ARGS) |
|
Line 1325 roff_ordered(ROFFCALL_ARGS) |
|
char *ordp[ROFF_MAXLINEARG], *p, |
char *ordp[ROFF_MAXLINEARG], *p, |
*argvp[ROFF_MAXLINEARG]; |
*argvp[ROFF_MAXLINEARG]; |
|
|
if (ROFF_PRELUDE & tree->state) { |
/* |
roff_err(tree, *argv, "`%s' disallowed in prelude", |
* Ordered macros pass their arguments directly to handlers, |
toknames[tok]); |
* instead of considering it free-form text. Thus, the |
return(0); |
* following macro looks as follows: |
} |
* |
|
* .Xr foo 1 ) , |
|
* |
|
* .Xr arg1 arg2 punctuation |
|
*/ |
|
|
|
if (ROFF_PRELUDE & tree->state) |
|
return(roff_errp(tree, *argv, tok, ERR_NOT_PR)); |
|
|
first = (*argv == tree->cur); |
first = (*argv == tree->cur); |
p = *argv++; |
p = *argv++; |
|
ordp[0] = NULL; |
|
|
if ( ! roffparseopts(tree, tok, &argv, argcp, argvp)) |
if ( ! roffparseopts(tree, tok, &argv, argcp, argvp)) |
return(0); |
return(0); |
|
|
if (NULL == *argv) { |
if (NULL == *argv) |
ordp[0] = NULL; |
|
return(roffspecial(tree, tok, p, argcp, |
return(roffspecial(tree, tok, p, argcp, |
(const char **)argvp, 0, ordp)); |
(const char **)argvp, 0, ordp)); |
} |
|
|
|
i = 0; |
i = 0; |
while (*argv && i < ROFF_MAXLINEARG) { |
while (*argv && i < ROFF_MAXLINEARG) { |
Line 1268 roff_text(ROFFCALL_ARGS) |
|
Line 1395 roff_text(ROFFCALL_ARGS) |
|
int i, j, first, c, argcp[ROFF_MAXLINEARG]; |
int i, j, first, c, argcp[ROFF_MAXLINEARG]; |
char *argvp[ROFF_MAXLINEARG]; |
char *argvp[ROFF_MAXLINEARG]; |
|
|
if (ROFF_PRELUDE & tree->state) { |
/* |
roff_err(tree, *argv, "`%s' disallowed in prelude", |
* Text macros are similar to special tokens, except that |
toknames[tok]); |
* arguments are instead flushed as pure data: we're only |
return(0); |
* concerned with the macro and its arguments. Example: |
} |
* |
|
* .Fl v W f ; |
|
* |
|
* ...Produces... |
|
* |
|
* <fl> v W f </fl> ; |
|
*/ |
|
|
|
if (ROFF_PRELUDE & tree->state) |
|
return(roff_errp(tree, *argv, tok, ERR_NOT_PR)); |
|
|
first = (*argv == tree->cur); |
first = (*argv == tree->cur); |
argv++; |
argv++; |
|
|
Line 1290 roff_text(ROFFCALL_ARGS) |
|
Line 1426 roff_text(ROFFCALL_ARGS) |
|
while (*argv) |
while (*argv) |
if ( ! roffdata(tree, i++, *argv++)) |
if ( ! roffdata(tree, i++, *argv++)) |
return(0); |
return(0); |
|
|
return((*tree->cb.roffout)(tree->arg, tok)); |
return((*tree->cb.roffout)(tree->arg, tok)); |
} |
} |
|
|
Line 1312 roff_text(ROFFCALL_ARGS) |
|
Line 1447 roff_text(ROFFCALL_ARGS) |
|
|
|
if ( ! roffcall(tree, c, argv)) |
if ( ! roffcall(tree, c, argv)) |
return(0); |
return(0); |
|
|
if (ROFF_LSCOPE & tokens[tok].flags) |
if (ROFF_LSCOPE & tokens[tok].flags) |
if ( ! (*tree->cb.roffout)(tree->arg, tok)) |
if ( ! (*tree->cb.roffout)(tree->arg, tok)) |
return(0); |
return(0); |
|
|
break; |
break; |
} |
} |
|
|
|
|
roff_depr(ROFFCALL_ARGS) |
roff_depr(ROFFCALL_ARGS) |
{ |
{ |
|
|
roff_err(tree, *argv, "`%s' is deprecated", toknames[tok]); |
return(roff_errp(tree, *argv, tok, ERR_DEPREC)); |
return(0); |
|
} |
} |
|
|
|
|
static void |
static int |
|
roff_warnp(const struct rofftree *tree, const char *pos, |
|
int tok, enum rofferr type) |
|
{ |
|
char *p; |
|
|
|
switch (type) { |
|
case (WRN_SECORD): |
|
p = "section at `%s' out of order"; |
|
break; |
|
default: |
|
abort(); |
|
/* NOTREACHED */ |
|
} |
|
|
|
return(roff_warn(tree, pos, p, toknames[tok])); |
|
} |
|
|
|
|
|
static int |
roff_warn(const struct rofftree *tree, const char *pos, char *fmt, ...) |
roff_warn(const struct rofftree *tree, const char *pos, char *fmt, ...) |
{ |
{ |
va_list ap; |
va_list ap; |
Line 1393 roff_warn(const struct rofftree *tree, const char *pos |
|
Line 1544 roff_warn(const struct rofftree *tree, const char *pos |
|
(void)vsnprintf(buf, sizeof(buf), fmt, ap); |
(void)vsnprintf(buf, sizeof(buf), fmt, ap); |
va_end(ap); |
va_end(ap); |
|
|
(*tree->cb.roffmsg)(tree->arg, |
return((*tree->cb.roffmsg)(tree->arg, |
ROFF_WARN, tree->cur, pos, buf); |
ROFF_WARN, tree->cur, pos, buf)); |
} |
} |
|
|
|
|
static void |
static int |
|
roff_errp(const struct rofftree *tree, const char *pos, |
|
int tok, enum rofferr type) |
|
{ |
|
char *p; |
|
|
|
switch (type) { |
|
case (ERR_ARGEQ1): |
|
p = "`%s' expects exactly one argument"; |
|
break; |
|
case (ERR_ARGEQ0): |
|
p = "`%s' expects exactly zero arguments"; |
|
break; |
|
case (ERR_ARGGE1): |
|
p = "`%s' expects one or more arguments"; |
|
break; |
|
case (ERR_ARGGE2): |
|
p = "`%s' expects two or more arguments"; |
|
break; |
|
case (ERR_BADARG): |
|
p = "invalid argument for `%s'"; |
|
break; |
|
case (ERR_NOTSUP): |
|
p = "macro `%s' is not supported"; |
|
break; |
|
case(ERR_PR_OOO): |
|
p = "prelude macro `%s' is out of order"; |
|
break; |
|
case(ERR_PR_REP): |
|
p = "prelude macro `%s' repeated"; |
|
break; |
|
case(ERR_ARGLEN): |
|
p = "macro argument for `%s' is too long"; |
|
break; |
|
case(ERR_DEPREC): |
|
p = "macro `%s' is deprecated"; |
|
break; |
|
case(ERR_NOT_PR): |
|
p = "macro `%s' disallowed in prelude"; |
|
break; |
|
case(ERR_ARGMNY): |
|
p = "too many arguments for macro `%s'"; |
|
break; |
|
default: |
|
abort(); |
|
/* NOTREACHED */ |
|
} |
|
|
|
return(roff_err(tree, pos, p, toknames[tok])); |
|
} |
|
|
|
|
|
static int |
roff_err(const struct rofftree *tree, const char *pos, char *fmt, ...) |
roff_err(const struct rofftree *tree, const char *pos, char *fmt, ...) |
{ |
{ |
va_list ap; |
va_list ap; |
char buf[128]; |
char buf[128]; |
|
|
va_start(ap, fmt); |
va_start(ap, fmt); |
(void)vsnprintf(buf, sizeof(buf), fmt, ap); |
if (-1 == vsnprintf(buf, sizeof(buf), fmt, ap)) |
|
err(1, "vsnprintf"); |
va_end(ap); |
va_end(ap); |
|
|
(*tree->cb.roffmsg)(tree->arg, |
return((*tree->cb.roffmsg) |
ROFF_ERROR, tree->cur, pos, buf); |
(tree->arg, ROFF_ERROR, tree->cur, pos, buf)); |
} |
} |
|
|