version 1.71, 2010/05/15 21:53:11 |
version 1.72, 2010/05/15 22:22:51 |
Line 50 struct roffnode { |
|
Line 50 struct roffnode { |
|
}; |
}; |
|
|
#define ROFF_ARGS struct roff *r, /* parse ctx */ \ |
#define ROFF_ARGS struct roff *r, /* parse ctx */ \ |
|
enum rofft tok, /* tok of macro */ \ |
char **bufp, /* input buffer */ \ |
char **bufp, /* input buffer */ \ |
size_t *szp, /* size of input buffer */ \ |
size_t *szp, /* size of input buffer */ \ |
int ln, /* parse line */ \ |
int ln, /* parse line */ \ |
|
|
roffproc new; /* root of stack (type = ROFF_MAX) */ |
roffproc new; /* root of stack (type = ROFF_MAX) */ |
}; |
}; |
|
|
static enum rofferr roff_ignore(ROFF_ARGS); |
|
static enum rofferr roff_new_close(ROFF_ARGS); |
static enum rofferr roff_new_close(ROFF_ARGS); |
static enum rofferr roff_new_ig(ROFF_ARGS); |
static enum rofferr roff_new_ig(ROFF_ARGS); |
static enum rofferr roff_sub_ig(ROFF_ARGS); |
static enum rofferr roff_sub_ig(ROFF_ARGS); |
|
|
const struct roffmac roffs[ROFF_MAX] = { |
const struct roffmac roffs[ROFF_MAX] = { |
{ "de", NULL, roff_ignore }, |
{ "de", roff_sub_ig, roff_new_ig }, |
{ "dei", NULL, roff_ignore }, |
{ "dei", roff_sub_ig, roff_new_ig }, |
{ "am", NULL, roff_ignore }, |
{ "am", roff_sub_ig, roff_new_ig }, |
{ "ami", NULL, roff_ignore }, |
{ "ami", roff_sub_ig, roff_new_ig }, |
{ "ig", roff_sub_ig, roff_new_ig }, |
{ "ig", roff_sub_ig, roff_new_ig }, |
{ ".", NULL, roff_new_close }, |
{ ".", NULL, roff_new_close }, |
}; |
}; |
Line 199 roff_parseln(struct roff *r, int ln, char **bufp, size |
|
Line 199 roff_parseln(struct roff *r, int ln, char **bufp, size |
|
*/ |
*/ |
t = r->last->tok; |
t = r->last->tok; |
assert(roffs[t].sub); |
assert(roffs[t].sub); |
return((*roffs[t].sub)(r, bufp, szp, ln, 0)); |
return((*roffs[t].sub)(r, t, bufp, szp, ln, 0)); |
} else if ('.' != (*bufp)[0] && NULL == r->last) |
} else if ('.' != (*bufp)[0] && NULL == r->last) |
/* Return when in free text without a context. */ |
/* Return when in free text without a context. */ |
return(ROFF_CONT); |
return(ROFF_CONT); |
Line 210 roff_parseln(struct roff *r, int ln, char **bufp, size |
|
Line 210 roff_parseln(struct roff *r, int ln, char **bufp, size |
|
return(ROFF_CONT); |
return(ROFF_CONT); |
|
|
assert(roffs[t].new); |
assert(roffs[t].new); |
return((*roffs[t].new)(r, bufp, szp, ln, ppos)); |
return((*roffs[t].new)(r, t, bufp, szp, ln, ppos)); |
} |
} |
|
|
|
|
Line 257 roff_parse(const char *buf, int *pos) |
|
Line 257 roff_parse(const char *buf, int *pos) |
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static enum rofferr |
static enum rofferr |
roff_ignore(ROFF_ARGS) |
|
{ |
|
|
|
return(ROFF_IGN); |
|
} |
|
|
|
|
|
/* ARGSUSED */ |
|
static enum rofferr |
|
roff_sub_ig(ROFF_ARGS) |
roff_sub_ig(ROFF_ARGS) |
{ |
{ |
int i, j; |
int i, j; |
Line 276 roff_sub_ig(ROFF_ARGS) |
|
Line 267 roff_sub_ig(ROFF_ARGS) |
|
return(ROFF_IGN); |
return(ROFF_IGN); |
|
|
if (r->last->end) { |
if (r->last->end) { |
/* |
|
* Allow a macro to break us, if we've defined a special |
|
* one for the case. Old groff didn't allow spaces to |
|
* buffer the macro, but new groff does. Whee! |
|
*/ |
|
i = ppos + 1; |
i = ppos + 1; |
|
|
while ((*bufp)[i] && ' ' == (*bufp)[i]) |
while ((*bufp)[i] && ' ' == (*bufp)[i]) |
i++; |
i++; |
|
|
if ('\0' == (*bufp)[i]) |
|
return(ROFF_IGN); |
|
|
|
for (j = 0; r->last->end[j]; i++, j++) |
for (j = 0; r->last->end[j]; i++, j++) |
if ((*bufp)[i] != r->last->end[j]) |
if ((*bufp)[i] != r->last->end[j]) |
return(ROFF_IGN); |
return(ROFF_IGN); |
Line 299 roff_sub_ig(ROFF_ARGS) |
|
Line 283 roff_sub_ig(ROFF_ARGS) |
|
|
|
while (' ' == (*bufp)[i]) |
while (' ' == (*bufp)[i]) |
i++; |
i++; |
|
|
} else if (ROFF_close != roff_parse(*bufp, &i)) |
} else if (ROFF_close != roff_parse(*bufp, &i)) |
return(ROFF_IGN); |
return(ROFF_IGN); |
|
|
/* |
|
* Pop off the ignoring context and warn if we're going to lose |
|
* any of our remaining arguments. |
|
*/ |
|
|
|
roffnode_pop(r); |
roffnode_pop(r); |
|
|
if ('\0' == (*bufp)[i]) |
if ('\0' == (*bufp)[i]) |
Line 323 static enum rofferr |
|
Line 303 static enum rofferr |
|
roff_new_close(ROFF_ARGS) |
roff_new_close(ROFF_ARGS) |
{ |
{ |
|
|
/* |
|
if ( ! (*r->msg)(MANDOCERR_NOSCOPE, r->data, ln, ppos, NULL)) |
if ( ! (*r->msg)(MANDOCERR_NOSCOPE, r->data, ln, ppos, NULL)) |
return(ROFF_ERR); |
return(ROFF_ERR); |
*/ |
|
return(ROFF_IGN); |
return(ROFF_IGN); |
} |
} |
|
|
Line 337 roff_new_ig(ROFF_ARGS) |
|
Line 316 roff_new_ig(ROFF_ARGS) |
|
{ |
{ |
int i; |
int i; |
|
|
if ( ! roffnode_push(r, ROFF_ig, ln, ppos)) |
if ( ! roffnode_push(r, tok, ln, ppos)) |
return(ROFF_ERR); |
return(ROFF_ERR); |
|
|
|
if (ROFF_ig != tok) { |
|
while ((*bufp)[ppos] && ' ' != (*bufp)[ppos]) |
|
ppos++; |
|
while (' ' == (*bufp)[ppos]) |
|
ppos++; |
|
} |
|
|
i = (int)ppos; |
i = (int)ppos; |
|
|
while ((*bufp)[i] && ' ' != (*bufp)[i]) |
while ((*bufp)[i] && ' ' != (*bufp)[i]) |
i++; |
i++; |
|
|
if (i == (int)ppos) |
if (i == (int)ppos) |
return(ROFF_IGN); |
return(ROFF_IGN); |
|
|
if ((*bufp)[i]) |
if ((*bufp)[i]) |
if ( ! (*r->msg)(MANDOCERR_ARGSLOST, r->data, ln, i, NULL)) |
if ( ! (*r->msg)(MANDOCERR_ARGSLOST, r->data, ln, i, NULL)) |
return(ROFF_ERR); |
return(ROFF_ERR); |
|
|
/* |
/* |
* If `.ig' has arguments, the first argument (up to the next |
* If the macro has arguments, the first argument (up to the |
* whitespace) is interpreted as an argument marking the macro |
* next whitespace) is interpreted as an argument marking the |
* close. Thus, `.ig foo' will close at `.foo'. |
* macro close. Thus, `.ig foo' will close at `.foo'. |
* |
* |
* NOTE: the closing macro `.foo' in the above case is not |
* NOTE: the closing macro `.foo' in the above case is not |
* allowed to have leading spaces with old groff! Thus `.foo' |
* allowed to have leading spaces with old groff! Thus `.foo' |