version 1.12, 2008/11/27 16:54:58 |
version 1.18, 2008/11/29 16:11:42 |
|
|
|
|
/* FIXME: NAME section needs specific elements. */ |
/* FIXME: NAME section needs specific elements. */ |
|
|
|
/* FIXME: don't print Os, just do roffbegin. */ |
|
|
#define ROFF_MAXARG 32 |
#define ROFF_MAXARG 32 |
|
|
enum roffd { |
enum roffd { |
|
|
|
|
#define ROFFCALL_ARGS \ |
#define ROFFCALL_ARGS \ |
int tok, struct rofftree *tree, \ |
int tok, struct rofftree *tree, \ |
const char *argv[], enum roffd type |
char *argv[], enum roffd type |
|
|
struct rofftree; |
struct rofftree; |
|
|
|
|
struct roffnode { |
struct roffnode { |
int tok; /* Token id. */ |
int tok; /* Token id. */ |
struct roffnode *parent; /* Parent (or NULL). */ |
struct roffnode *parent; /* Parent (or NULL). */ |
size_t line; /* Parsed at line. */ |
|
}; |
}; |
|
|
struct rofftree { |
struct rofftree { |
struct roffnode *last; /* Last parsed node. */ |
struct roffnode *last; /* Last parsed node. */ |
time_t date; /* `Dd' results. */ |
|
char *cur; |
char *cur; |
|
|
|
time_t date; /* `Dd' 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. */ |
char section[64]; /* `Dt' results. */ |
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: if we had prev ptrs, this wouldn't be necessary. */ |
|
#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 md_mbuf *mbuf; /* Output (or NULL). */ |
|
const struct md_args *args; /* Global args. */ |
struct roffcb cb; |
const struct md_rbuf *rbuf; /* Input. */ |
void *arg; |
const struct roffcb *cb; |
|
}; |
}; |
|
|
static int roff_Dd(ROFFCALL_ARGS); |
static int roff_Dd(ROFFCALL_ARGS); |
Line 115 static int roff_close(ROFFCALL_ARGS); |
|
Line 116 static int roff_close(ROFFCALL_ARGS); |
|
static int roff_special(ROFFCALL_ARGS); |
static int roff_special(ROFFCALL_ARGS); |
|
|
static struct roffnode *roffnode_new(int, struct rofftree *); |
static struct roffnode *roffnode_new(int, struct rofftree *); |
static void roffnode_free(int, struct rofftree *); |
static void roffnode_free(struct rofftree *); |
|
|
static void roff_warn(const struct rofftree *, |
static void roff_warn(const struct rofftree *, |
const char *, char *, ...); |
const char *, char *, ...); |
Line 130 static int roffargs(const struct rofftree *, |
|
Line 131 static int roffargs(const struct rofftree *, |
|
int, char *, char **); |
int, char *, char **); |
static int roffargok(int, int); |
static int roffargok(int, int); |
static int roffnextopt(const struct rofftree *, |
static int roffnextopt(const struct rofftree *, |
int, const char ***, char **); |
int, char ***, char **); |
static int roffparse(struct rofftree *, char *, size_t); |
static int roffparse(struct rofftree *, char *); |
static int textparse(const struct rofftree *, |
static int textparse(const struct rofftree *, char *); |
const char *, size_t); |
|
|
|
|
|
static const int roffarg_An[] = { ROFF_Split, ROFF_Nosplit, |
static const int roffarg_An[] = { ROFF_Split, ROFF_Nosplit, |
Line 175 static const int roffparent_It[] = { ROFF_Bl, ROFF_It, |
|
Line 175 static const int roffparent_It[] = { ROFF_Bl, ROFF_It, |
|
static const int roffparent_Re[] = { ROFF_Rs, ROFF_MAX }; |
static const int roffparent_Re[] = { ROFF_Rs, ROFF_MAX }; |
|
|
/* Table of all known tokens. */ |
/* Table of all known tokens. */ |
static const struct rofftok tokens[ROFF_MAX] = |
static const struct rofftok tokens[ROFF_MAX] = { |
{ |
|
{roff_comment, NULL, NULL, NULL, 0, ROFF_COMMENT, 0 }, /* \" */ |
{roff_comment, NULL, NULL, NULL, 0, ROFF_COMMENT, 0 }, /* \" */ |
{ roff_Dd, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Dd */ |
{ roff_Dd, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Dd */ |
{ roff_Dt, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Dt */ |
{ roff_Dt, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Dt */ |
Line 236 static const struct rofftok tokens[ROFF_MAX] = |
|
Line 235 static const struct rofftok tokens[ROFF_MAX] = |
|
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Bc */ |
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Bc */ |
{ NULL, NULL, NULL, NULL, 0, ROFF_TEXT, 0 }, /* Bf */ /* FIXME */ |
{ 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 }, /* Bo */ |
{ NULL, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Bq */ |
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Bq */ |
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Bsx */ |
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Bsx */ |
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Bx */ |
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Bx */ |
{roff_special, NULL, NULL, NULL, 0, ROFF_SPECIAL, 0 }, /* Db */ |
{roff_special, NULL, NULL, NULL, 0, ROFF_SPECIAL, 0 }, /* Db */ |
Line 273 static const struct rofftok tokens[ROFF_MAX] = |
|
Line 272 static const struct rofftok tokens[ROFF_MAX] = |
|
{ roff_text, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED }, /* Ux */ |
{ 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 }, /* Xc */ |
{ NULL, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Xo */ |
{ NULL, NULL, NULL, NULL, 0, ROFF_TEXT, ROFF_PARSED | ROFF_CALLABLE }, /* Xo */ |
{ roff_layout, NULL, NULL, NULL, 0, ROFF_LAYOUT, 0 }, /* Fo */ |
{ roff_layout, NULL, NULL, roffchild_Fo, 0, ROFF_LAYOUT, 0 }, /* Fo */ |
{ roff_close, NULL, roffparent_Fc, NULL, ROFF_Fo, ROFF_LAYOUT, 0 }, /* Fc */ |
{ roff_close, NULL, roffparent_Fc, NULL, ROFF_Fo, ROFF_LAYOUT, 0 }, /* Fc */ |
{ roff_layout, NULL, NULL, NULL, 0, ROFF_LAYOUT, 0 }, /* Oo */ |
{ roff_layout, NULL, NULL, roffchild_Oo, 0, ROFF_LAYOUT, 0 }, /* Oo */ |
{ roff_close, NULL, roffparent_Oc, NULL, ROFF_Oo, ROFF_LAYOUT, 0 }, /* Oc */ |
{ roff_close, NULL, roffparent_Oc, NULL, ROFF_Oo, ROFF_LAYOUT, 0 }, /* Oc */ |
{ roff_layout, roffarg_Bk, NULL, NULL, 0, ROFF_LAYOUT, 0 }, /* Bk */ |
{ roff_layout, roffarg_Bk, NULL, NULL, 0, ROFF_LAYOUT, 0 }, /* Bk */ |
{ roff_close, NULL, NULL, NULL, ROFF_Bk, ROFF_LAYOUT, 0 }, /* Ek */ |
{ roff_close, NULL, NULL, NULL, ROFF_Bk, ROFF_LAYOUT, 0 }, /* Ek */ |
}; |
}; |
|
|
/* Table of all known token arguments. */ |
/* Table of all known token arguments. */ |
static const int tokenargs[ROFF_ARGMAX] = |
static const int tokenargs[ROFF_ARGMAX] = { |
{ |
|
0, 0, 0, 0, |
0, 0, 0, 0, |
0, ROFF_VALUE, ROFF_VALUE, 0, |
0, ROFF_VALUE, ROFF_VALUE, 0, |
0, 0, 0, 0, |
0, 0, 0, 0, |
0, 0, 0, 0, |
0, 0, 0, 0, |
|
0, 0, ROFF_VALUE, 0, |
0, 0, 0, 0, |
0, 0, 0, 0, |
0, 0, 0, 0, |
0, 0, 0, 0, |
0, 0, 0, 0, |
0, 0, 0, 0, |
Line 298 static const int tokenargs[ROFF_ARGMAX] = |
|
Line 297 static const int tokenargs[ROFF_ARGMAX] = |
|
0, 0, 0, 0, |
0, 0, 0, 0, |
0, 0, 0, 0, |
0, 0, 0, 0, |
0, 0, 0, 0, |
0, 0, 0, 0, |
0, 0, 0, 0, |
|
}; |
}; |
|
|
const char *const toknamesp[ROFF_MAX] = |
const char *const toknamesp[ROFF_MAX] = { |
{ |
|
"\\\"", "Dd", "Dt", "Os", |
"\\\"", "Dd", "Dt", "Os", |
"Sh", "Ss", "Pp", "D1", |
"Sh", "Ss", "Pp", "D1", |
"Dl", "Bd", "Ed", "Bl", |
"Dl", "Bd", "Ed", "Bl", |
Line 331 const char *const toknamesp[ROFF_MAX] = |
|
Line 328 const char *const toknamesp[ROFF_MAX] = |
|
"Bk", "Ek", |
"Bk", "Ek", |
}; |
}; |
|
|
const char *const tokargnamesp[ROFF_ARGMAX] = |
const char *const tokargnamesp[ROFF_ARGMAX] = { |
{ |
|
"split", "nosplit", "ragged", |
"split", "nosplit", "ragged", |
"unfilled", "literal", "file", |
"unfilled", "literal", "file", |
"offset", "bullet", "dash", |
"offset", "bullet", "dash", |
Line 355 const char *const tokargnamesp[ROFF_ARGMAX] = |
|
Line 351 const char *const tokargnamesp[ROFF_ARGMAX] = |
|
"svid4", "filled", "words", |
"svid4", "filled", "words", |
}; |
}; |
|
|
|
|
const char *const *toknames = toknamesp; |
const char *const *toknames = toknamesp; |
const char *const *tokargnames = tokargnamesp; |
const char *const *tokargnames = tokargnamesp; |
|
|
Line 363 const char *const *tokargnames = tokargnamesp; |
|
Line 358 const char *const *tokargnames = tokargnamesp; |
|
int |
int |
roff_free(struct rofftree *tree, int flush) |
roff_free(struct rofftree *tree, int flush) |
{ |
{ |
int error; |
int error, t; |
|
struct roffnode *n; |
|
|
assert(tree->mbuf); |
error = 0; |
|
|
if ( ! flush) |
if ( ! flush) |
tree->mbuf = NULL; |
goto end; |
|
|
/* LINTED */ |
error = 1; |
while (tree->last) |
|
if ( ! (*tokens[tree->last->tok].cb) |
|
(tree->last->tok, tree, NULL, ROFF_EXIT)) |
|
/* Disallow flushing. */ |
|
tree->mbuf = NULL; |
|
|
|
error = tree->mbuf ? 0 : 1; |
if (ROFF_PRELUDE & tree->state) { |
|
roff_warn(tree, NULL, "prelude never finished"); |
|
goto end; |
|
} |
|
|
if (tree->mbuf && (ROFF_PRELUDE & tree->state)) { |
for (n = tree->last; n->parent; n = n->parent) { |
/*roff_warn(tree, "prelude never finished");*/ |
if (0 != tokens[n->tok].ctx) |
error = 1; |
continue; |
|
roff_warn(tree, NULL, "closing explicit scope `%s'", |
|
toknames[n->tok]); |
|
goto end; |
} |
} |
|
|
|
while (tree->last) { |
|
t = tree->last->tok; |
|
if ( ! (*tokens[t].cb)(t, tree, NULL, ROFF_EXIT)) |
|
goto end; |
|
} |
|
|
|
error = 0; |
|
|
|
end: |
|
|
|
while (tree->last) |
|
roffnode_free(tree); |
|
|
free(tree); |
free(tree); |
|
|
return(error ? 0 : 1); |
return(error ? 0 : 1); |
} |
} |
|
|
|
|
struct rofftree * |
struct rofftree * |
roff_alloc(const struct md_args *args, struct md_mbuf *out, |
roff_alloc(const struct roffcb *cb, void *args) |
const struct md_rbuf *in, const struct roffcb *cb) |
|
{ |
{ |
struct rofftree *tree; |
struct rofftree *tree; |
|
|
|
assert(args); |
|
assert(cb); |
|
|
if (NULL == (tree = calloc(1, sizeof(struct rofftree)))) |
if (NULL == (tree = calloc(1, sizeof(struct rofftree)))) |
err(1, "calloc"); |
err(1, "calloc"); |
|
|
tree->state = ROFF_PRELUDE; |
tree->state = ROFF_PRELUDE; |
tree->args = args; |
tree->arg = args; |
tree->mbuf = out; |
|
tree->rbuf = in; |
|
tree->cb = cb; |
|
|
|
|
(void)memcpy(&tree->cb, cb, sizeof(struct roffcb)); |
|
|
return(tree); |
return(tree); |
} |
} |
|
|
|
|
int |
int |
roff_engine(struct rofftree *tree, char *buf, size_t sz) |
roff_engine(struct rofftree *tree, char *buf) |
{ |
{ |
|
|
tree->cur = buf; |
tree->cur = buf; |
|
assert(buf); |
|
|
if (0 == sz) { |
if (0 == *buf) { |
roff_warn(tree, buf, "blank line"); |
roff_warn(tree, buf, "blank line"); |
return(0); |
return(0); |
} else if ('.' != *buf) |
} else if ('.' != *buf) |
return(textparse(tree, buf, sz)); |
return(textparse(tree, buf)); |
|
|
return(roffparse(tree, buf, sz)); |
return(roffparse(tree, buf)); |
} |
} |
|
|
|
|
static int |
static int |
textparse(const struct rofftree *tree, const char *buf, size_t sz) |
textparse(const struct rofftree *tree, char *buf) |
{ |
{ |
|
|
/* Print text. */ |
return((*tree->cb.roffdata)(tree->arg, buf)); |
return(1); |
|
} |
} |
|
|
|
|
Line 451 roffargs(const struct rofftree *tree, |
|
Line 464 roffargs(const struct rofftree *tree, |
|
while (*buf && '\"' != *buf) |
while (*buf && '\"' != *buf) |
buf++; |
buf++; |
if (0 == *buf) { |
if (0 == *buf) { |
roff_err(tree, p, argv[i], "unclosed " |
roff_err(tree, argv[i], "unclosed " |
"quote in argument " |
"quote in argument " |
"list for `%s'", |
"list for `%s'", |
toknames[tok]); |
toknames[tok]); |
Line 471 roffargs(const struct rofftree *tree, |
|
Line 484 roffargs(const struct rofftree *tree, |
|
|
|
assert(i > 0); |
assert(i > 0); |
if (ROFF_MAXARG == i && *buf) { |
if (ROFF_MAXARG == i && *buf) { |
roff_err(tree, p, p, "too many arguments for `%s'", toknames |
roff_err(tree, p, "too many arguments for `%s'", toknames |
[tok]); |
[tok]); |
return(0); |
return(0); |
} |
} |
Line 498 roffscan(int tok, const int *tokv) |
|
Line 511 roffscan(int tok, const int *tokv) |
|
|
|
|
|
static int |
static int |
roffparse(struct rofftree *tree, char *buf, size_t sz) |
roffparse(struct rofftree *tree, char *buf) |
{ |
{ |
int tok, t; |
int tok, t; |
struct roffnode *n; |
struct roffnode *n; |
char *argv[ROFF_MAXARG]; |
char *argv[ROFF_MAXARG]; |
const char **argvp; |
char **argvp; |
|
|
assert(sz > 0); |
|
|
|
if (ROFF_MAX == (tok = rofffindtok(buf + 1))) { |
if (ROFF_MAX == (tok = rofffindtok(buf + 1))) { |
roff_err(tree, buf + 1, "bogus line macro"); |
roff_err(tree, buf + 1, "bogus line macro"); |
return(0); |
return(0); |
Line 520 roffparse(struct rofftree *tree, char *buf, size_t sz) |
|
Line 531 roffparse(struct rofftree *tree, char *buf, size_t sz) |
|
if ( ! roffargs(tree, tok, buf, argv)) |
if ( ! roffargs(tree, tok, buf, argv)) |
return(0); |
return(0); |
|
|
argvp = (const char **)argv; |
argvp = (char **)argv; |
|
|
/* |
/* |
* Prelude macros break some assumptions, so branch now. |
* Prelude macros break some assumptions, so branch now. |
Line 540 roffparse(struct rofftree *tree, char *buf, size_t sz) |
|
Line 551 roffparse(struct rofftree *tree, char *buf, size_t sz) |
|
*/ |
*/ |
|
|
if ( ! roffscan(tree->last->tok, tokens[tok].parents)) { |
if ( ! roffscan(tree->last->tok, tokens[tok].parents)) { |
warnx("%s: invalid parent `%s' for `%s' (line %zu)", |
roff_err(tree, *argvp, "`%s' has invalid parent `%s'", |
tree->rbuf->name, |
toknames[tok], |
toknames[tree->last->tok], |
toknames[tree->last->tok]); |
toknames[tok], tree->rbuf->line); |
|
return(0); |
return(0); |
} |
} |
|
|
if ( ! roffscan(tok, tokens[tree->last->tok].children)) { |
if ( ! roffscan(tok, tokens[tree->last->tok].children)) { |
warnx("%s: invalid child `%s' for `%s' (line %zu)", |
roff_err(tree, *argvp, "`%s' is invalid child of `%s'", |
tree->rbuf->name, toknames[tok], |
toknames[tok], |
toknames[tree->last->tok], |
toknames[tree->last->tok]); |
tree->rbuf->line); |
|
return(0); |
return(0); |
} |
} |
|
|
Line 632 roffparse(struct rofftree *tree, char *buf, size_t sz) |
|
Line 641 roffparse(struct rofftree *tree, char *buf, size_t sz) |
|
assert(tree->last); |
assert(tree->last); |
assert(tok != tokens[tok].ctx && 0 != tokens[tok].ctx); |
assert(tok != tokens[tok].ctx && 0 != tokens[tok].ctx); |
|
|
|
/* LINTED */ |
do { |
do { |
t = tree->last->tok; |
t = tree->last->tok; |
if ( ! (*tokens[t].cb)(t, tree, NULL, ROFF_EXIT)) |
if ( ! (*tokens[t].cb)(t, tree, NULL, ROFF_EXIT)) |
Line 706 roffnode_new(int tokid, struct rofftree *tree) |
|
Line 716 roffnode_new(int tokid, struct rofftree *tree) |
|
if (NULL == (p = malloc(sizeof(struct roffnode)))) |
if (NULL == (p = malloc(sizeof(struct roffnode)))) |
err(1, "malloc"); |
err(1, "malloc"); |
|
|
p->line = tree->rbuf->line; |
|
p->tok = tokid; |
p->tok = tokid; |
p->parent = tree->last; |
p->parent = tree->last; |
tree->last = p; |
tree->last = p; |
Line 732 roffargok(int tokid, int argid) |
|
Line 741 roffargok(int tokid, int argid) |
|
|
|
|
|
static void |
static void |
roffnode_free(int tokid, struct rofftree *tree) |
roffnode_free(struct rofftree *tree) |
{ |
{ |
struct roffnode *p; |
struct roffnode *p; |
|
|
assert(tree->last); |
assert(tree->last); |
assert(tree->last->tok == tokid); |
|
|
|
p = tree->last; |
p = tree->last; |
tree->last = tree->last->parent; |
tree->last = tree->last->parent; |
Line 747 roffnode_free(int tokid, struct rofftree *tree) |
|
Line 755 roffnode_free(int tokid, struct rofftree *tree) |
|
|
|
static int |
static int |
roffnextopt(const struct rofftree *tree, int tok, |
roffnextopt(const struct rofftree *tree, int tok, |
const char ***in, char **val) |
char ***in, char **val) |
{ |
{ |
const char *arg, **argv; |
char *arg, **argv; |
int v; |
int v; |
|
|
*val = NULL; |
*val = NULL; |
Line 856 roff_Os(ROFFCALL_ARGS) |
|
Line 864 roff_Os(ROFFCALL_ARGS) |
|
{ |
{ |
|
|
if (ROFF_EXIT == type) { |
if (ROFF_EXIT == type) { |
assert(ROFF_PRELUDE_Os & tree->state); |
roffnode_free(tree); |
return(roff_layout(tok, tree, argv, type)); |
return((*tree->cb.rofftail)(tree->arg)); |
} else if (ROFF_BODY & tree->state) { |
} else if (ROFF_BODY & tree->state) { |
assert( ! (ROFF_PRELUDE & tree->state)); |
assert( ! (ROFF_PRELUDE & tree->state)); |
assert(ROFF_PRELUDE_Os & tree->state); |
assert(ROFF_PRELUDE_Os & tree->state); |
Line 879 roff_Os(ROFFCALL_ARGS) |
|
Line 887 roff_Os(ROFFCALL_ARGS) |
|
|
|
assert(NULL == tree->last); |
assert(NULL == tree->last); |
|
|
return(roff_layout(tok, tree, argv, type)); |
if (NULL == roffnode_new(tok, tree)) |
|
return(0); |
|
|
|
return((*tree->cb.roffhead)(tree->arg)); |
} |
} |
|
|
|
|
Line 897 roff_layout(ROFFCALL_ARGS) |
|
Line 908 roff_layout(ROFFCALL_ARGS) |
|
} |
} |
|
|
if (ROFF_EXIT == type) { |
if (ROFF_EXIT == type) { |
roffnode_free(tok, tree); |
roffnode_free(tree); |
return((*tree->cb->roffblkout)(tok)); |
return((*tree->cb.roffblkout)(tree->arg, tok)); |
} |
} |
|
|
i = 0; |
i = 0; |
Line 920 roff_layout(ROFFCALL_ARGS) |
|
Line 931 roff_layout(ROFFCALL_ARGS) |
|
if (NULL == roffnode_new(tok, tree)) |
if (NULL == roffnode_new(tok, tree)) |
return(0); |
return(0); |
|
|
if ( ! (*tree->cb->roffin)(tok, argcp, argvp)) |
if ( ! (*tree->cb.roffblkin)(tree->arg, tok, argcp, argvp)) |
return(0); |
return(0); |
|
|
if ( ! (ROFF_PARSED & tokens[tok].flags)) { |
if (NULL == *argv) |
|
return(1); |
|
|
/* TODO: print all tokens. */ |
if ( ! (*tree->cb.roffin)(tree->arg, tok, argcp, argvp)) |
|
return(0); |
|
|
if ( ! ((*tree->cb->roffout)(tok))) |
if ( ! (ROFF_PARSED & tokens[tok].flags)) { |
return(0); |
while (*argv) { |
return((*tree->cb->roffblkin)(tok)); |
if ( ! (*tree->cb.roffdata)(tree->arg, *argv++)) |
|
return(0); |
|
} |
|
return((*tree->cb.roffout)(tree->arg, tok)); |
} |
} |
|
|
while (*argv) { |
while (*argv) { |
Line 940 roff_layout(ROFFCALL_ARGS) |
|
Line 956 roff_layout(ROFFCALL_ARGS) |
|
toknames[c]); |
toknames[c]); |
return(0); |
return(0); |
} |
} |
if ( ! (*tokens[c].cb)(c, tree, |
if ( ! (*tokens[c].cb)(c, tree, argv, ROFF_ENTER)) |
argv, ROFF_ENTER)) |
|
return(0); |
return(0); |
|
break; |
} |
} |
|
|
/* TODO: print token. */ |
assert(tree->arg); |
|
if ( ! (*tree->cb.roffdata)(tree->arg, *argv++)) |
argv++; |
return(0); |
} |
} |
|
|
if ( ! ((*tree->cb->roffout)(tok))) |
return((*tree->cb.roffout)(tree->arg, tok)); |
return(0); |
|
|
|
return((*tree->cb->roffblkin)(tok)); |
|
} |
} |
|
|
|
|
Line 986 roff_text(ROFFCALL_ARGS) |
|
Line 999 roff_text(ROFFCALL_ARGS) |
|
argcp[i] = ROFF_ARGMAX; |
argcp[i] = ROFF_ARGMAX; |
argvp[i] = NULL; |
argvp[i] = NULL; |
|
|
if ( ! (*tree->cb->roffin)(tok, argcp, argvp)) |
if ( ! (*tree->cb.roffin)(tree->arg, tok, argcp, argvp)) |
return(0); |
return(0); |
|
|
if ( ! (ROFF_PARSED & tokens[tok].flags)) { |
if ( ! (ROFF_PARSED & tokens[tok].flags)) { |
|
while (*argv) { |
/* TODO: print all tokens. */ |
if ( ! (*tree->cb.roffdata)(tree->arg, *argv++)) |
|
return(0); |
return((*tree->cb->roffout)(tok)); |
} |
|
return((*tree->cb.roffout)(tree->arg, tok)); |
} |
} |
|
|
while (*argv) { |
while (*argv) { |
Line 1007 roff_text(ROFFCALL_ARGS) |
|
Line 1021 roff_text(ROFFCALL_ARGS) |
|
if ( ! (*tokens[c].cb)(c, tree, |
if ( ! (*tokens[c].cb)(c, tree, |
argv, ROFF_ENTER)) |
argv, ROFF_ENTER)) |
return(0); |
return(0); |
|
break; |
} |
} |
|
if ( ! (*tree->cb.roffdata)(tree->arg, *argv++)) |
/* TODO: print token. */ |
return(0); |
|
|
argv++; |
|
} |
} |
|
|
return((*tree->cb->roffout)(tok)); |
return((*tree->cb.roffout)(tree->arg, tok)); |
} |
} |
|
|
|
|
|
|
roff_special(ROFFCALL_ARGS) |
roff_special(ROFFCALL_ARGS) |
{ |
{ |
|
|
return((*tree->cb->roffspecial)(tok)); |
return((*tree->cb.roffspecial)(tree->arg, tok)); |
} |
} |
|
|
|
|
Line 1055 roff_warn(const struct rofftree *tree, const char *pos |
|
Line 1068 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->args, ROFF_WARN, tree->cur, pos, |
(*tree->cb.roffmsg)(tree->arg, |
tree->rbuf->name, tree->rbuf->line, buf); |
ROFF_WARN, tree->cur, pos, buf); |
} |
} |
|
|
|
|
Line 1070 roff_err(const struct rofftree *tree, const char *pos, |
|
Line 1083 roff_err(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->args, ROFF_ERROR, tree->cur, pos, |
(*tree->cb.roffmsg)(tree->arg, |
tree->rbuf->name, tree->rbuf->line, buf); |
ROFF_ERROR, tree->cur, pos, buf); |
} |
} |