version 1.14, 2009/01/02 14:06:16 |
version 1.18, 2009/01/05 17:57:08 |
Line 85 const char *const __mdoc_argnames[MDOC_ARG_MAX] = { |
|
Line 85 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, MDOC_PROLOGUE }, /* Dd */ |
{ macro_prologue, MDOC_PROLOGUE }, /* Dd */ |
{ NULL, MDOC_PROLOGUE }, /* Dt */ |
{ macro_prologue, MDOC_PROLOGUE }, /* Dt */ |
{ NULL, MDOC_PROLOGUE }, /* Os */ |
{ macro_prologue, MDOC_PROLOGUE }, /* Os */ |
{ macro_scoped, 0 }, /* Sh */ |
{ macro_scoped, 0 }, /* Sh */ |
{ macro_scoped, 0 }, /* Ss */ |
{ macro_scoped, 0 }, /* Ss */ |
{ macro_text, 0 }, /* Pp */ |
{ macro_text, 0 }, /* Pp */ |
Line 97 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
Line 97 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
{ macro_close_explicit, 0 }, /* Ed */ |
{ macro_close_explicit, 0 }, /* Ed */ |
{ macro_scoped, MDOC_EXPLICIT }, /* Bl */ |
{ macro_scoped, MDOC_EXPLICIT }, /* Bl */ |
{ macro_close_explicit, 0 }, /* El */ |
{ macro_close_explicit, 0 }, /* El */ |
{ NULL, 0 }, /* It */ |
{ macro_scoped, MDOC_NESTED }, /* It */ |
{ macro_text, MDOC_CALLABLE }, /* Ad */ |
{ macro_text, MDOC_CALLABLE }, /* Ad */ |
{ macro_constant, 0 }, /* An */ |
{ macro_constant, 0 }, /* An */ |
{ macro_text, MDOC_CALLABLE }, /* Ar */ |
{ macro_text, MDOC_CALLABLE }, /* Ar */ |
Line 107 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
Line 107 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
{ macro_text, MDOC_CALLABLE }, /* Er */ |
{ macro_text, MDOC_CALLABLE }, /* Er */ |
{ macro_text, MDOC_CALLABLE }, /* Ev */ |
{ macro_text, MDOC_CALLABLE }, /* Ev */ |
{ macro_constant, 0 }, /* Ex */ |
{ macro_constant, 0 }, /* Ex */ |
{ macro_text, MDOC_CALLABLE }, /* Fa */ |
{ macro_text, MDOC_CALLABLE | MDOC_QUOTABLE }, /* Fa */ |
{ macro_constant, 0 }, /* Fd */ |
{ macro_constant, 0 }, /* Fd */ |
{ macro_text, MDOC_CALLABLE }, /* Fl */ |
{ macro_text, MDOC_CALLABLE }, /* Fl */ |
{ macro_text, MDOC_CALLABLE | MDOC_QUOTABLE }, /* Fn */ |
{ macro_text, MDOC_CALLABLE | MDOC_QUOTABLE }, /* Fn */ |
Line 116 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
Line 116 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
{ macro_constant, 0 }, /* In */ |
{ macro_constant, 0 }, /* In */ |
{ macro_text, MDOC_CALLABLE }, /* Li */ |
{ macro_text, MDOC_CALLABLE }, /* Li */ |
{ macro_constant, 0 }, /* Nd */ |
{ macro_constant, 0 }, /* Nd */ |
{ NULL, 0 }, /* Nm */ |
{ macro_text, MDOC_CALLABLE }, /* Nm */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Op */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Op */ |
{ macro_obsolete, 0 }, /* Ot */ |
{ macro_obsolete, 0 }, /* Ot */ |
{ macro_text, MDOC_CALLABLE }, /* Pa */ |
{ macro_text, MDOC_CALLABLE }, /* Pa */ |
Line 136 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
Line 136 const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { |
|
{ macro_constant, MDOC_QUOTABLE }, /* %R */ |
{ macro_constant, MDOC_QUOTABLE }, /* %R */ |
{ macro_constant, MDOC_QUOTABLE }, /* %T */ |
{ macro_constant, MDOC_QUOTABLE }, /* %T */ |
{ macro_constant, MDOC_QUOTABLE }, /* %V */ |
{ macro_constant, MDOC_QUOTABLE }, /* %V */ |
{ NULL, 0 }, /* Ac */ |
{ macro_close_explicit, MDOC_CALLABLE }, /* Ac */ |
{ NULL, 0 }, /* Ao */ |
{ macro_constant_scoped, MDOC_CALLABLE }, /* Ao */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Aq */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Aq */ |
{ macro_constant, 0 }, /* At */ |
{ macro_constant, 0 }, /* At */ |
{ NULL, 0 }, /* Bc */ |
{ macro_close_explicit, MDOC_CALLABLE }, /* Bc */ |
{ macro_scoped, 0 }, /* Bf */ |
{ macro_scoped, MDOC_EXPLICIT }, /* Bf */ |
{ NULL, 0 }, /* Bo */ |
{ macro_constant_scoped, MDOC_CALLABLE }, /* Bo */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Bq */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Bq */ |
{ macro_constant_delimited, 0 }, /* Bsx */ |
{ macro_constant_delimited, 0 }, /* Bsx */ |
{ macro_constant_delimited, 0 }, /* Bx */ |
{ macro_constant_delimited, 0 }, /* Bx */ |
{ macro_constant, 0 }, /* Db */ |
{ macro_constant, 0 }, /* Db */ |
{ NULL, 0 }, /* Dc */ |
{ macro_close_explicit, MDOC_CALLABLE }, /* Dc */ |
{ NULL, 0 }, /* Do */ |
{ macro_constant_scoped, MDOC_CALLABLE }, /* Do */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Dq */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Dq */ |
{ NULL, 0 }, /* Ec */ |
{ macro_close_explicit, MDOC_CALLABLE }, /* Ec */ |
{ macro_close_explicit, 0 }, /* Ef */ |
{ macro_close_explicit, 0 }, /* Ef */ |
{ macro_text, MDOC_CALLABLE }, /* Em */ |
{ macro_text, MDOC_CALLABLE }, /* Em */ |
{ NULL, 0 }, /* Eo */ |
{ macro_constant_scoped, MDOC_CALLABLE }, /* Eo */ |
{ macro_constant_delimited, 0 }, /* Fx */ |
{ macro_constant_delimited, 0 }, /* Fx */ |
{ macro_text, 0 }, /* Ms */ |
{ macro_text, 0 }, /* Ms */ |
{ macro_constant_delimited, MDOC_CALLABLE }, /* No */ |
{ macro_constant_delimited, MDOC_CALLABLE }, /* No */ |
{ macro_constant_delimited, MDOC_CALLABLE }, /* Ns */ |
{ macro_constant_delimited, MDOC_CALLABLE }, /* Ns */ |
{ macro_constant_delimited, 0 }, /* Nx */ |
{ macro_constant_delimited, 0 }, /* Nx */ |
{ macro_constant_delimited, 0 }, /* Ox */ |
{ macro_constant_delimited, 0 }, /* Ox */ |
{ NULL, 0 }, /* Pc */ |
{ macro_close_explicit, MDOC_CALLABLE }, /* Pc */ |
{ macro_constant, 0 }, /* Pf */ |
{ macro_constant, 0 }, /* Pf */ |
{ NULL, 0 }, /* Po */ |
{ macro_constant_scoped, MDOC_CALLABLE }, /* Po */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Pq */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Pq */ |
{ NULL, 0 }, /* Qc */ |
{ macro_close_explicit, MDOC_CALLABLE }, /* Qc */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Ql */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Ql */ |
{ NULL, 0 }, /* Qo */ |
{ macro_constant_scoped, MDOC_CALLABLE }, /* Qo */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Qq */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Qq */ |
{ macro_scoped, MDOC_EXPLICIT }, /* Re */ |
{ macro_close_explicit, 0 }, /* Re */ |
{ macro_scoped, MDOC_EXPLICIT }, /* Rs */ |
{ macro_scoped, MDOC_EXPLICIT }, /* Rs */ |
{ NULL, 0 }, /* Sc */ |
{ macro_close_explicit, MDOC_CALLABLE }, /* Sc */ |
{ NULL, 0 }, /* So */ |
{ macro_constant_scoped, MDOC_CALLABLE }, /* So */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Sq */ |
{ macro_scoped_line, MDOC_CALLABLE }, /* Sq */ |
{ macro_constant, 0 }, /* Sm */ |
{ macro_constant, 0 }, /* Sm */ |
{ macro_text, MDOC_CALLABLE }, /* Sx */ |
{ macro_text, MDOC_CALLABLE }, /* Sx */ |
{ macro_text, MDOC_CALLABLE }, /* Sy */ |
{ macro_text, MDOC_CALLABLE }, /* Sy */ |
{ macro_text, MDOC_CALLABLE }, /* Tn */ |
{ macro_text, MDOC_CALLABLE }, /* Tn */ |
{ macro_constant_delimited, 0 }, /* Ux */ |
{ macro_constant_delimited, 0 }, /* Ux */ |
{ NULL, 0 }, /* Xc */ |
{ macro_close_explicit, MDOC_CALLABLE }, /* Xc */ |
{ NULL, 0 }, /* Xo */ |
{ macro_constant_scoped, MDOC_CALLABLE }, /* Xo */ |
{ NULL, 0 }, /* Fo */ |
{ macro_scoped, MDOC_EXPLICIT }, /* Fo */ /* XXX - supposed to be (but isn't) callable. */ |
{ NULL, 0 }, /* Fc */ |
{ macro_close_explicit, 0 }, /* Fc */ /* XXX - supposed to be (but isn't) callable. */ |
{ NULL, 0 }, /* Oo */ |
{ macro_constant_scoped, MDOC_CALLABLE }, /* Oo */ |
{ NULL, 0 }, /* Oc */ |
{ macro_close_explicit, MDOC_CALLABLE }, /* Oc */ |
{ NULL, 0 }, /* Bk */ |
{ macro_scoped, MDOC_EXPLICIT }, /* Bk */ |
{ NULL, 0 }, /* Ek */ |
{ macro_close_explicit, 0 }, /* Ek */ |
{ macro_constant, 0 }, /* Bt */ |
{ macro_constant, 0 }, /* Bt */ |
{ macro_constant, 0 }, /* Hf */ |
{ macro_constant, 0 }, /* Hf */ |
{ macro_obsolete, 0 }, /* Fr */ |
{ macro_obsolete, 0 }, /* Fr */ |
Line 201 static struct mdoc_arg *argdup(size_t, const struct m |
|
Line 201 static struct mdoc_arg *argdup(size_t, const struct m |
|
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 *, |
const struct mdoc_arg *); |
const struct mdoc_arg *); |
static char **paramdup(size_t, const char **); |
|
static void paramfree(size_t, char **); |
|
|
|
static void mdoc_node_freelist(struct mdoc_node *); |
static void mdoc_node_freelist(struct mdoc_node *); |
static void mdoc_node_append(struct mdoc *, int, |
static void mdoc_node_append(struct mdoc *, int, |
Line 254 mdoc_parseln(struct mdoc *mdoc, char *buf) |
|
Line 252 mdoc_parseln(struct mdoc *mdoc, char *buf) |
|
char tmp[5]; |
char tmp[5]; |
|
|
if ('.' != *buf) { |
if ('.' != *buf) { |
|
if (SEC_PROLOGUE == mdoc->sec_lastn) |
|
return(mdoc_err(mdoc, -1, 0, ERR_SYNTAX_NOTEXT)); |
mdoc_word_alloc(mdoc, 0, buf); |
mdoc_word_alloc(mdoc, 0, buf); |
mdoc->next = MDOC_NEXT_SIBLING; |
mdoc->next = MDOC_NEXT_SIBLING; |
return(1); |
return(1); |
|
|
mdoc_macro(struct mdoc *mdoc, int tok, int ppos, int *pos, char *buf) |
mdoc_macro(struct mdoc *mdoc, int tok, int ppos, int *pos, char *buf) |
{ |
{ |
|
|
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(macro_prologue(mdoc, tok, ppos, pos, buf)); |
|
|
|
if (SEC_PROLOGUE == mdoc->sec_lastn) |
|
return(mdoc_err(mdoc, tok, ppos, ERR_SEC_PROLOGUE)); |
return(mdoc_err(mdoc, tok, ppos, ERR_SEC_PROLOGUE)); |
|
|
if (NULL == (mdoc_macros[tok].fp)) { |
if (NULL == (mdoc_macros[tok].fp)) { |
Line 371 mdoc_node_append(struct mdoc *mdoc, int pos, struct md |
|
Line 368 mdoc_node_append(struct mdoc *mdoc, int pos, struct md |
|
nn = mdoc_macronames[p->data.head.tok]; |
nn = mdoc_macronames[p->data.head.tok]; |
nt = "head"; |
nt = "head"; |
break; |
break; |
|
case (MDOC_TAIL): |
|
nn = mdoc_macronames[p->data.tail.tok]; |
|
nt = "tail"; |
|
break; |
case (MDOC_BLOCK): |
case (MDOC_BLOCK): |
nn = mdoc_macronames[p->data.block.tok]; |
nn = mdoc_macronames[p->data.block.tok]; |
nt = "block"; |
nt = "block"; |
Line 405 mdoc_node_append(struct mdoc *mdoc, int pos, struct md |
|
Line 406 mdoc_node_append(struct mdoc *mdoc, int pos, struct md |
|
on = mdoc_macronames[mdoc->last->data.head.tok]; |
on = mdoc_macronames[mdoc->last->data.head.tok]; |
ot = "head"; |
ot = "head"; |
break; |
break; |
|
case (MDOC_TAIL): |
|
on = mdoc_macronames[mdoc->last->data.tail.tok]; |
|
ot = "tail"; |
|
break; |
case (MDOC_BLOCK): |
case (MDOC_BLOCK): |
on = mdoc_macronames[mdoc->last->data.block.tok]; |
on = mdoc_macronames[mdoc->last->data.block.tok]; |
ot = "block"; |
ot = "block"; |
Line 439 mdoc_node_append(struct mdoc *mdoc, int pos, struct md |
|
Line 444 mdoc_node_append(struct mdoc *mdoc, int pos, struct md |
|
|
|
|
|
void |
void |
|
mdoc_tail_alloc(struct mdoc *mdoc, int pos, int tok) |
|
{ |
|
struct mdoc_node *p; |
|
|
|
assert(mdoc->first); |
|
assert(mdoc->last); |
|
|
|
p = xcalloc(1, sizeof(struct mdoc_node)); |
|
|
|
p->type = MDOC_TAIL; |
|
p->data.tail.tok = tok; |
|
|
|
mdoc_node_append(mdoc, pos, p); |
|
} |
|
|
|
|
|
void |
mdoc_head_alloc(struct mdoc *mdoc, int pos, int tok) |
mdoc_head_alloc(struct mdoc *mdoc, int pos, int tok) |
{ |
{ |
struct mdoc_node *p; |
struct mdoc_node *p; |
Line 491 mdoc_block_alloc(struct mdoc *mdoc, int pos, int tok, |
|
Line 513 mdoc_block_alloc(struct mdoc *mdoc, int pos, int tok, |
|
|
|
void |
void |
mdoc_elem_alloc(struct mdoc *mdoc, int pos, int tok, |
mdoc_elem_alloc(struct mdoc *mdoc, int pos, int tok, |
size_t argsz, const struct mdoc_arg *args, |
size_t argsz, const struct mdoc_arg *args) |
size_t paramsz, const char **params) |
|
{ |
{ |
struct mdoc_node *p; |
struct mdoc_node *p; |
|
|
p = xcalloc(1, sizeof(struct mdoc_node)); |
p = xcalloc(1, sizeof(struct mdoc_node)); |
p->type = MDOC_ELEM; |
p->type = MDOC_ELEM; |
p->data.elem.tok = tok; |
p->data.elem.tok = tok; |
p->data.elem.sz = paramsz; |
|
p->data.elem.args = paramdup(paramsz, params); |
|
p->data.elem.argc = argsz; |
p->data.elem.argc = argsz; |
p->data.elem.argv = argdup(argsz, args); |
p->data.elem.argv = argdup(argsz, args); |
|
|
|
|
mdoc_elem_free(struct mdoc_elem *p) |
mdoc_elem_free(struct mdoc_elem *p) |
{ |
{ |
|
|
paramfree(p->sz, p->args); |
|
argfree(p->argc, p->argv); |
argfree(p->argc, p->argv); |
} |
} |
|
|
Line 641 argdup(size_t argsz, const struct mdoc_arg *args) |
|
Line 659 argdup(size_t argsz, const struct mdoc_arg *args) |
|
return(pp); |
return(pp); |
} |
} |
|
|
|
|
static void |
|
paramfree(size_t sz, char **p) |
|
{ |
|
int i; |
|
|
|
if (0 == sz) |
|
return; |
|
|
|
assert(p); |
|
/* LINTED */ |
|
for (i = 0; i < (int)sz; i++) |
|
free(p[i]); |
|
free(p); |
|
} |
|
|
|
|
|
static char ** |
|
paramdup(size_t sz, const char **p) |
|
{ |
|
char **pp; |
|
int i; |
|
|
|
if (0 == sz) |
|
return(NULL); |
|
|
|
pp = xcalloc(sz, sizeof(char *)); |
|
for (i = 0; i < (int)sz; i++) |
|
pp[i] = xstrdup(p[i]); |
|
|
|
return(pp); |
|
} |
|