version 1.2, 2008/12/15 02:23:12 |
version 1.5, 2008/12/28 00:34:20 |
|
|
|
|
#include "private.h" |
#include "private.h" |
|
|
extern int macro_text(struct mdoc *, int, int, int *, char *); |
|
extern int macro_scoped_implicit(struct mdoc *, |
|
int, int, int *, char *); |
|
|
|
const char *const __mdoc_macronames[MDOC_MAX] = { |
const char *const __mdoc_macronames[MDOC_MAX] = { |
"\\\"", "Dd", "Dt", "Os", |
"\\\"", "Dd", "Dt", "Os", |
"Sh", "Ss", "Pp", "D1", |
"Sh", "Ss", "Pp", "D1", |
Line 88 const char *const __mdoc_argnames[MDOC_ARG_MAX] = { |
|
Line 84 const char *const __mdoc_argnames[MDOC_ARG_MAX] = { |
|
|
|
const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
{ NULL, 0 }, /* \" */ |
{ NULL, 0 }, /* \" */ |
{ NULL, 0 }, /* Dd */ |
{ macro_prologue_ddate, 0 }, /* Dd */ |
{ NULL, 0 }, /* Dt */ |
{ macro_prologue_dtitle, 0 }, /* Dt */ |
{ NULL, 0 }, /* Os */ |
{ macro_prologue_os, 0 }, /* Os */ |
{ macro_scoped_implicit, 0 }, /* Sh */ |
{ macro_scoped_implicit, 0 }, /* Sh */ |
{ macro_scoped_implicit, 0 }, /* Ss */ |
{ macro_scoped_implicit, 0 }, /* Ss */ |
{ NULL, 0 }, /* Pp */ |
{ macro_text, 0 }, /* Pp */ |
{ NULL, 0 }, /* D1 */ |
{ NULL, 0 }, /* D1 */ |
{ NULL, 0 }, /* Dl */ |
{ NULL, 0 }, /* Dl */ |
{ NULL, 0 }, /* Bd */ |
{ macro_scoped_explicit, MDOC_EXPLICIT }, /* Bd */ |
{ NULL, 0 }, /* Ed */ |
{ macro_scoped_explicit, 0 }, /* Ed */ |
{ NULL, 0 }, /* Bl */ |
{ macro_scoped_explicit, MDOC_EXPLICIT }, /* Bl */ |
{ NULL, 0 }, /* El */ |
{ macro_scoped_explicit, 0 }, /* El */ |
{ NULL, 0 }, /* It */ |
{ NULL, 0 }, /* It */ |
{ macro_text, MDOC_CALLABLE }, /* Ad */ |
{ macro_text, MDOC_CALLABLE }, /* Ad */ |
{ NULL, 0 }, /* An */ |
{ NULL, 0 }, /* An */ |
Line 200 const char * const *mdoc_argnames = __mdoc_argnames; |
|
Line 196 const char * const *mdoc_argnames = __mdoc_argnames; |
|
const struct mdoc_macro * const mdoc_macros = __mdoc_macros; |
const struct mdoc_macro * const mdoc_macros = __mdoc_macros; |
|
|
|
|
static void *xcalloc(size_t, size_t); |
|
static char *xstrdup(const char *); |
|
|
|
static struct mdoc_arg *argdup(size_t, const struct mdoc_arg *); |
static struct mdoc_arg *argdup(size_t, const struct mdoc_arg *); |
static void argfree(size_t, struct mdoc_arg *); |
static void argfree(size_t, struct mdoc_arg *); |
static void argcpy(struct mdoc_arg *, |
static void argcpy(struct mdoc_arg *, |
Line 232 mdoc_free(struct mdoc *mdoc) |
|
Line 225 mdoc_free(struct mdoc *mdoc) |
|
if (mdoc->first) |
if (mdoc->first) |
mdoc_node_freelist(mdoc->first); |
mdoc_node_freelist(mdoc->first); |
if (mdoc->htab) |
if (mdoc->htab) |
mdoc_hash_free(mdoc->htab); |
mdoc_tokhash_free(mdoc->htab); |
|
|
free(mdoc); |
free(mdoc); |
} |
} |
Line 248 mdoc_alloc(void *data, const struct mdoc_cb *cb) |
|
Line 241 mdoc_alloc(void *data, const struct mdoc_cb *cb) |
|
p->data = data; |
p->data = data; |
(void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb)); |
(void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb)); |
|
|
p->htab = mdoc_hash_alloc(); |
p->htab = mdoc_tokhash_alloc(); |
return(p); |
return(p); |
} |
} |
|
|
|
|
static void * |
|
xcalloc(size_t num, size_t sz) |
|
{ |
|
void *p; |
|
|
|
if (NULL == (p = calloc(num, sz))) |
|
err(EXIT_FAILURE, "calloc"); |
|
return(p); |
|
} |
|
|
|
|
|
static char * |
|
xstrdup(const char *p) |
|
{ |
|
char *pp; |
|
|
|
if (NULL == (pp = strdup(p))) |
|
err(EXIT_FAILURE, "strdup"); |
|
return(pp); |
|
} |
|
|
|
|
|
int |
int |
mdoc_parseln(struct mdoc *mdoc, char *buf) |
mdoc_parseln(struct mdoc *mdoc, char *buf) |
{ |
{ |
int c, i; |
int c, i; |
char tmp[5]; |
char tmp[5]; |
|
|
if ('.' != *buf) { |
if ('.' != *buf) { |
/* TODO. */ |
mdoc_word_alloc(mdoc, 0, buf); |
return(1); |
return(1); |
} |
} |
|
|
if (buf[1] && '\\' == buf[1]) |
if (buf[1] && '\\' == buf[1]) |
Line 310 mdoc_parseln(struct mdoc *mdoc, char *buf) |
|
Line 281 mdoc_parseln(struct mdoc *mdoc, char *buf) |
|
while (buf[i] && isspace(buf[i])) |
while (buf[i] && isspace(buf[i])) |
i++; |
i++; |
|
|
if (NULL == (mdoc_macros[c].fp)) { |
return(mdoc_macro(mdoc, c, 1, &i, buf)); |
(void)mdoc_err(mdoc, c, 1, ERR_MACRO_NOTSUP); |
|
return(0); |
|
} |
|
|
|
return((*mdoc_macros[c].fp)(mdoc, c, 1, &i, buf)); |
|
} |
} |
|
|
|
|
Line 363 mdoc_macro(struct mdoc *mdoc, int tok, int ppos, int * |
|
Line 329 mdoc_macro(struct mdoc *mdoc, int tok, int ppos, int * |
|
if (NULL == (mdoc_macros[tok].fp)) { |
if (NULL == (mdoc_macros[tok].fp)) { |
(void)mdoc_err(mdoc, tok, ppos, ERR_MACRO_NOTSUP); |
(void)mdoc_err(mdoc, tok, ppos, ERR_MACRO_NOTSUP); |
return(0); |
return(0); |
} else if ( ! (MDOC_CALLABLE & mdoc_macros[tok].flags)) { |
} |
|
|
|
if (1 != ppos && ! (MDOC_CALLABLE & mdoc_macros[tok].flags)) { |
(void)mdoc_err(mdoc, tok, ppos, ERR_MACRO_NOTCALL); |
(void)mdoc_err(mdoc, tok, ppos, ERR_MACRO_NOTCALL); |
return(0); |
return(0); |
} |
} |
Line 379 mdoc_node_append(struct mdoc *mdoc, int pos, struct md |
|
Line 347 mdoc_node_append(struct mdoc *mdoc, int pos, struct md |
|
|
|
switch (p->type) { |
switch (p->type) { |
case (MDOC_TEXT): |
case (MDOC_TEXT): |
nn = "<text>"; |
nn = p->data.text.string; |
nt = "text"; |
nt = "text"; |
break; |
break; |
case (MDOC_BODY): |
case (MDOC_BODY): |
Line 448 mdoc_node_append(struct mdoc *mdoc, int pos, struct md |
|
Line 416 mdoc_node_append(struct mdoc *mdoc, int pos, struct md |
|
case (MDOC_HEAD): |
case (MDOC_HEAD): |
p->parent = mdoc->last->parent; |
p->parent = mdoc->last->parent; |
mdoc->last->next = p; |
mdoc->last->next = p; |
|
p->prev = mdoc->last; |
act = "sibling"; |
act = "sibling"; |
break; |
break; |
default: |
default: |
Line 472 mdoc_node_append(struct mdoc *mdoc, int pos, struct md |
|
Line 441 mdoc_node_append(struct mdoc *mdoc, int pos, struct md |
|
break; |
break; |
default: |
default: |
p->parent = mdoc->last->parent; |
p->parent = mdoc->last->parent; |
|
p->prev = mdoc->last; |
mdoc->last->next = p; |
mdoc->last->next = p; |
act = "sibling"; |
act = "sibling"; |
break; |
break; |
|
|
mdoc_find(const struct mdoc *mdoc, const char *key) |
mdoc_find(const struct mdoc *mdoc, const char *key) |
{ |
{ |
|
|
return(mdoc_hash_find(mdoc->htab, key)); |
return(mdoc_tokhash_find(mdoc->htab, key)); |
} |
} |
|
|
|
|