version 1.54, 2009/03/08 12:40:27 |
version 1.63, 2009/03/12 15:55:11 |
Line 38 static int mdoc_node_append(struct mdoc *, |
|
Line 38 static int mdoc_node_append(struct mdoc *, |
|
|
|
static int parsetext(struct mdoc *, int, char *); |
static int parsetext(struct mdoc *, int, char *); |
static int parsemacro(struct mdoc *, int, char *); |
static int parsemacro(struct mdoc *, int, char *); |
|
static int macrowarn(struct mdoc *, int, const char *); |
|
|
|
|
const char *const __mdoc_macronames[MDOC_MAX] = { |
const char *const __mdoc_macronames[MDOC_MAX] = { |
Line 70 const char *const __mdoc_macronames[MDOC_MAX] = { |
|
Line 71 const char *const __mdoc_macronames[MDOC_MAX] = { |
|
"Tn", "Ux", "Xc", "Xo", |
"Tn", "Ux", "Xc", "Xo", |
"Fo", "Fc", "Oo", "Oc", |
"Fo", "Fc", "Oo", "Oc", |
"Bk", "Ek", "Bt", "Hf", |
"Bk", "Ek", "Bt", "Hf", |
"Fr", "Ud", "Lb", |
"Fr", "Ud", "Lb", "Ap", |
|
"Lp", "Lk", "Mt", "Brq", |
|
"Bro", "Brc" |
}; |
}; |
|
|
const char *const __mdoc_argnames[MDOC_ARG_MAX] = { |
const char *const __mdoc_argnames[MDOC_ARG_MAX] = { |
Line 129 mdoc_free(struct mdoc *mdoc) |
|
Line 132 mdoc_free(struct mdoc *mdoc) |
|
|
|
|
|
struct mdoc * |
struct mdoc * |
mdoc_alloc(void *data, const struct mdoc_cb *cb) |
mdoc_alloc(void *data, int pflags, const struct mdoc_cb *cb) |
{ |
{ |
struct mdoc *p; |
struct mdoc *p; |
|
|
Line 142 mdoc_alloc(void *data, const struct mdoc_cb *cb) |
|
Line 145 mdoc_alloc(void *data, const struct mdoc_cb *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; |
p->first = p->last; |
p->first = p->last; |
|
p->pflags = pflags; |
p->next = MDOC_NEXT_CHILD; |
p->next = MDOC_NEXT_CHILD; |
p->htab = mdoc_tokhash_alloc(); |
p->htab = mdoc_tokhash_alloc(); |
|
|
Line 494 parsetext(struct mdoc *mdoc, int line, char *buf) |
|
Line 497 parsetext(struct mdoc *mdoc, int line, char *buf) |
|
} |
} |
|
|
|
|
|
static int |
|
macrowarn(struct mdoc *m, int ln, const char *buf) |
|
{ |
|
if ( ! (MDOC_IGN_MACRO & m->pflags)) |
|
return(mdoc_perr(m, ln, 1, "unknown macro: %s%s", |
|
buf, strlen(buf) > 3 ? "..." : "")); |
|
return(mdoc_pwarn(m, ln, 1, WARN_SYNTAX, |
|
"unknown macro: %s%s", |
|
buf, strlen(buf) > 3 ? "..." : "")); |
|
} |
|
|
|
|
|
|
/* |
/* |
* Parse a macro line, that is, a line beginning with the control |
* Parse a macro line, that is, a line beginning with the control |
* character. |
* character. |
Line 504 parsemacro(struct mdoc *m, int ln, char *buf) |
|
Line 520 parsemacro(struct mdoc *m, int ln, char *buf) |
|
int i, c; |
int i, c; |
char mac[5]; |
char mac[5]; |
|
|
/* Comments are quickly ignored. */ |
/* Comments and empties are quickly ignored. */ |
|
|
|
if (0 == buf[1]) |
|
return(1); |
|
|
|
if (isspace((unsigned char)buf[1])) { |
|
i = 2; |
|
while (buf[i] && isspace((unsigned char)buf[i])) |
|
i++; |
|
if (0 == buf[i]) |
|
return(1); |
|
return(mdoc_perr(m, ln, 1, "invalid syntax")); |
|
} |
|
|
if (buf[1] && '\\' == buf[1]) |
if (buf[1] && '\\' == buf[1]) |
if (buf[2] && '\"' == buf[2]) |
if (buf[2] && '\"' == buf[2]) |
return(1); |
return(1); |
Line 519 parsemacro(struct mdoc *m, int ln, char *buf) |
|
Line 547 parsemacro(struct mdoc *m, int ln, char *buf) |
|
break; |
break; |
} |
} |
|
|
/* FIXME: be able to skip unknown macro lines! */ |
|
|
|
mac[i - 1] = 0; |
mac[i - 1] = 0; |
|
|
if (i == 5 || i <= 2) { |
if (i == 5 || i <= 2) { |
(void)mdoc_perr(m, ln, 1, "unknown macro: %s%s", |
if ( ! macrowarn(m, ln, mac)) |
mac, i == 5 ? "..." : ""); |
goto err; |
goto err; |
return(1); |
} |
} |
|
|
if (MDOC_MAX == (c = mdoc_tokhash_find(m->htab, mac))) { |
if (MDOC_MAX == (c = mdoc_tokhash_find(m->htab, mac))) { |
(void)mdoc_perr(m, ln, 1, "unknown macro: %s", mac); |
if ( ! macrowarn(m, ln, mac)) |
goto err; |
goto err; |
|
return(1); |
} |
} |
|
|
/* The macro is sane. Jump to the next word. */ |
/* The macro is sane. Jump to the next word. */ |