version 1.30, 2009/01/15 15:46:45 |
version 1.33, 2009/01/16 15:58:50 |
Line 99 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
Line 99 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
{ macro_scoped_close, MDOC_EXPLICIT }, /* El */ |
{ macro_scoped_close, MDOC_EXPLICIT }, /* El */ |
{ macro_scoped, MDOC_PARSED | MDOC_TABSEP}, /* It */ |
{ macro_scoped, MDOC_PARSED | MDOC_TABSEP}, /* It */ |
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ad */ |
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ad */ |
{ macro_constant, MDOC_PARSED }, /* An */ |
{ macro_text, MDOC_PARSED }, /* An */ |
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ar */ |
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ar */ |
{ macro_constant, MDOC_QUOTABLE }, /* Cd */ |
{ macro_constant, MDOC_QUOTABLE }, /* Cd */ |
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Cm */ |
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Cm */ |
Line 111 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
Line 111 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
{ macro_constant, 0 }, /* Fd */ |
{ macro_constant, 0 }, /* Fd */ |
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Fl */ |
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Fl */ |
{ macro_text, MDOC_CALLABLE | MDOC_QUOTABLE | MDOC_PARSED }, /* Fn */ |
{ macro_text, MDOC_CALLABLE | MDOC_QUOTABLE | MDOC_PARSED }, /* Fn */ |
{ macro_text, MDOC_PARSED }, /* Ft */ |
{ macro_text, MDOC_PARSED | MDOC_QUOTABLE }, /* Ft */ |
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ic */ |
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ic */ |
{ macro_constant, 0 }, /* In */ |
{ macro_constant, 0 }, /* In */ |
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Li */ |
{ macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Li */ |
Line 162 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
Line 162 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
{ macro_constant_delimited, MDOC_PARSED }, /* Nx */ |
{ macro_constant_delimited, MDOC_PARSED }, /* Nx */ |
{ macro_constant_delimited, MDOC_PARSED }, /* Ox */ |
{ macro_constant_delimited, MDOC_PARSED }, /* Ox */ |
{ macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Pc */ |
{ macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Pc */ |
{ macro_constant, MDOC_PARSED }, /* Pf */ |
{ macro_constant_delimited, MDOC_PARSED }, /* Pf */ |
{ macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Po */ |
{ macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Po */ |
{ macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Pq */ |
{ macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Pq */ |
{ macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Qc */ |
{ macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Qc */ |
Line 241 mdoc_alloc(void *data, const struct mdoc_cb *cb) |
|
Line 241 mdoc_alloc(void *data, const struct mdoc_cb *cb) |
|
p = xcalloc(1, sizeof(struct mdoc)); |
p = xcalloc(1, sizeof(struct mdoc)); |
|
|
p->data = data; |
p->data = data; |
(void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb)); |
if (cb) |
|
(void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb)); |
|
|
p->last = xcalloc(1, sizeof(struct mdoc_node)); |
p->last = xcalloc(1, sizeof(struct mdoc_node)); |
p->last->type = MDOC_ROOT; |
p->last->type = MDOC_ROOT; |
Line 288 mdoc_parseln(struct mdoc *mdoc, int line, char *buf) |
|
Line 289 mdoc_parseln(struct mdoc *mdoc, int line, char *buf) |
|
mdoc->next = MDOC_NEXT_SIBLING; |
mdoc->next = MDOC_NEXT_SIBLING; |
return(1); |
return(1); |
} |
} |
return(mdoc_perr(mdoc, line, 0, ERR_SYNTAX_NOTEXT)); |
return(mdoc_perr(mdoc, line, 0, "text disallowed")); |
} |
} |
|
|
if (buf[1] && '\\' == buf[1]) |
if (buf[1] && '\\' == buf[1]) |
Line 301 mdoc_parseln(struct mdoc *mdoc, int line, char *buf) |
|
Line 302 mdoc_parseln(struct mdoc *mdoc, int line, char *buf) |
|
|
|
if (i == (int)sizeof(tmp)) { |
if (i == (int)sizeof(tmp)) { |
mdoc->flags |= MDOC_HALT; |
mdoc->flags |= MDOC_HALT; |
return(mdoc_perr(mdoc, line, 1, ERR_MACRO_NOTSUP)); |
return(mdoc_perr(mdoc, line, 1, "unknown macro")); |
} else if (i <= 2) { |
} else if (i <= 2) { |
mdoc->flags |= MDOC_HALT; |
mdoc->flags |= MDOC_HALT; |
return(mdoc_perr(mdoc, line, 1, ERR_MACRO_NOTSUP)); |
return(mdoc_perr(mdoc, line, 1, "unknown macro")); |
} |
} |
|
|
i--; |
i--; |
Line 314 mdoc_parseln(struct mdoc *mdoc, int line, char *buf) |
|
Line 315 mdoc_parseln(struct mdoc *mdoc, int line, char *buf) |
|
|
|
if (MDOC_MAX == (c = mdoc_find(mdoc, tmp))) { |
if (MDOC_MAX == (c = mdoc_find(mdoc, tmp))) { |
mdoc->flags |= MDOC_HALT; |
mdoc->flags |= MDOC_HALT; |
return(mdoc_perr(mdoc, line, 1, ERR_MACRO_NOTSUP)); |
return(mdoc_perr(mdoc, line, 1, "unknown macro")); |
} |
} |
|
|
while (buf[i] && isspace(buf[i])) |
while (buf[i] && isspace(buf[i])) |
Line 329 mdoc_parseln(struct mdoc *mdoc, int line, char *buf) |
|
Line 330 mdoc_parseln(struct mdoc *mdoc, int line, char *buf) |
|
|
|
|
|
void |
void |
mdoc_msg(struct mdoc *mdoc, const char *fmt, ...) |
mdoc_vmsg(struct mdoc *mdoc, int ln, int pos, const char *fmt, ...) |
{ |
{ |
struct mdoc_node *n; |
|
va_list ap; |
|
char buf[256]; |
char buf[256]; |
|
va_list ap; |
|
|
if (NULL == mdoc->cb.mdoc_msg) |
if (NULL == mdoc->cb.mdoc_msg) |
return; |
return; |
|
|
n = mdoc->last; |
|
assert(n); |
|
|
|
va_start(ap, fmt); |
va_start(ap, fmt); |
(void)vsnprintf(buf, sizeof(buf), fmt, ap); |
(void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); |
va_end(ap); |
va_end(ap); |
|
(*mdoc->cb.mdoc_msg)(mdoc->data, ln, pos, buf); |
(*mdoc->cb.mdoc_msg)(mdoc->data, n->line, n->pos, buf); |
|
} |
} |
|
|
|
|
int |
int |
mdoc_perr(struct mdoc *mdoc, |
mdoc_verr(struct mdoc *mdoc, int ln, int pos, |
int line, int pos, enum mdoc_err type) |
const char *fmt, ...) |
{ |
{ |
|
char buf[256]; |
|
va_list ap; |
|
|
if (NULL == mdoc->cb.mdoc_err) |
if (NULL == mdoc->cb.mdoc_err) |
return(0); |
return(0); |
return((*mdoc->cb.mdoc_err)(mdoc->data, line, pos, type)); |
|
|
va_start(ap, fmt); |
|
(void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); |
|
va_end(ap); |
|
return((*mdoc->cb.mdoc_err)(mdoc->data, ln, pos, buf)); |
} |
} |
|
|
|
|
int |
int |
mdoc_pwarn(struct mdoc *mdoc, |
mdoc_vwarn(struct mdoc *mdoc, int ln, int pos, |
int line, int pos, enum mdoc_warn type) |
enum mdoc_warn type, const char *fmt, ...) |
{ |
{ |
|
char buf[256]; |
|
va_list ap; |
|
|
if (NULL == mdoc->cb.mdoc_warn) |
if (NULL == mdoc->cb.mdoc_warn) |
return(0); |
return(0); |
return((*mdoc->cb.mdoc_warn)(mdoc->data, line, pos, type)); |
|
|
va_start(ap, fmt); |
|
(void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap); |
|
va_end(ap); |
|
return((*mdoc->cb.mdoc_warn)(mdoc->data, ln, pos, type, buf)); |
} |
} |
|
|
|
|
Line 376 mdoc_macro(struct mdoc *mdoc, int tok, |
|
Line 384 mdoc_macro(struct mdoc *mdoc, int tok, |
|
int ln, int ppos, int *pos, char *buf) |
int ln, int ppos, int *pos, char *buf) |
{ |
{ |
|
|
|
assert(mdoc_macros[tok].fp); |
|
|
if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) && |
if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) && |
SEC_PROLOGUE == mdoc->sec_lastn) |
SEC_PROLOGUE == mdoc->sec_lastn) |
return(mdoc_perr(mdoc, ln, ppos, ERR_SEC_PROLOGUE)); |
return(mdoc_perr(mdoc, ln, ppos, "macro disallowed in document prologue")); |
|
|
if (NULL == (mdoc_macros[tok].fp)) |
|
return(mdoc_perr(mdoc, ln, ppos, ERR_MACRO_NOTSUP)); |
|
|
|
if (1 != ppos && ! (MDOC_CALLABLE & mdoc_macros[tok].flags)) |
if (1 != ppos && ! (MDOC_CALLABLE & mdoc_macros[tok].flags)) |
return(mdoc_perr(mdoc, ln, ppos, ERR_MACRO_NOTCALL)); |
return(mdoc_perr(mdoc, ln, ppos, "macro not callable")); |
|
|
return((*mdoc_macros[tok].fp)(mdoc, tok, ln, ppos, pos, buf)); |
return((*mdoc_macros[tok].fp)(mdoc, tok, ln, ppos, pos, buf)); |
} |
} |
|
|