version 1.15, 2008/11/28 15:25:49 |
version 1.17, 2008/11/29 14:14:21 |
Line 130 static int roffargs(const struct rofftree *, |
|
Line 130 static int roffargs(const struct rofftree *, |
|
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, const 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 357 const char *const *tokargnames = tokargnamesp; |
|
Line 356 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; |
struct roffnode *n; |
|
|
error = 0; |
error = 0; |
|
|
for (n = tree->last; n->parent; n = n->parent) |
if ( ! flush) |
if (tokens[n->tok].ctx == 0) { |
goto end; |
roff_warn(tree, NULL, "closing explicit scope " |
|
"of `%s'", toknames[n->tok]); |
|
error = 1; |
|
} |
|
|
|
if (0 == error && (ROFF_PRELUDE & tree->state)) { |
error = 1; |
|
|
|
if (ROFF_PRELUDE & tree->state) { |
roff_warn(tree, NULL, "prelude never finished"); |
roff_warn(tree, NULL, "prelude never finished"); |
error = 1; |
goto end; |
|
} |
|
|
|
for (n = tree->last; n->parent; n = n->parent) { |
|
if (0 != tokens[n->tok].ctx) |
|
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; |
|
} |
|
|
|
if ( ! (*tree->cb.rofftail)(tree->arg)) |
|
goto end; |
|
|
|
error = 0; |
|
|
|
end: |
|
|
while (tree->last) |
while (tree->last) |
roffnode_free(tree); |
roffnode_free(tree); |
|
|
free(tree); |
free(tree); |
|
|
return(error ? 0 : 1); |
return(error ? 0 : 1); |
} |
} |
|
|
Line 387 roff_alloc(const struct roffcb *cb, void *args) |
|
Line 406 roff_alloc(const struct roffcb *cb, void *args) |
|
{ |
{ |
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"); |
|
|
Line 395 roff_alloc(const struct roffcb *cb, void *args) |
|
Line 417 roff_alloc(const struct roffcb *cb, void *args) |
|
|
|
(void)memcpy(&tree->cb, cb, sizeof(struct roffcb)); |
(void)memcpy(&tree->cb, cb, sizeof(struct roffcb)); |
|
|
|
if ( ! (*tree->cb.roffhead)(args)) { |
|
free(tree); |
|
return(NULL); |
|
} |
|
|
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 = NULL; |
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 490 roffscan(int tok, const int *tokv) |
|
Line 517 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; |
const 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 937 roff_layout(ROFFCALL_ARGS) |
|
Line 962 roff_layout(ROFFCALL_ARGS) |
|
break; |
break; |
} |
} |
|
|
|
assert(tree->arg); |
if ( ! (*tree->cb.roffdata)(tree->arg, *argv++)) |
if ( ! (*tree->cb.roffdata)(tree->arg, *argv++)) |
return(0); |
return(0); |
} |
} |