version 1.69, 2009/03/21 09:42:07 |
version 1.70, 2009/03/23 14:22:11 |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <string.h> |
#include <string.h> |
|
|
#include "private.h" |
#include "libmdoc.h" |
|
|
/* |
/* |
* Main caller in the libmdoc library. This begins the parsing routine, |
* Main caller in the libmdoc library. This begins the parsing routine, |
|
|
* in macro.c, validate.c and action.c. |
* in macro.c, validate.c and action.c. |
*/ |
*/ |
|
|
|
/* FIXME: have this accept line/pos/tok. */ |
static struct mdoc_node *mdoc_node_alloc(const struct mdoc *); |
static struct mdoc_node *mdoc_node_alloc(const struct mdoc *); |
static int mdoc_node_append(struct mdoc *, |
static int mdoc_node_append(struct mdoc *, |
struct mdoc_node *); |
struct mdoc_node *); |
Line 121 mdoc_meta(const struct mdoc *mdoc) |
|
Line 122 mdoc_meta(const struct mdoc *mdoc) |
|
|
|
|
|
/* |
/* |
* Free up all resources contributed by a parse: the node tree, meta-data and |
* Free up all resources contributed by a parse: the node tree, |
* so on. Then reallocate the root node for another parse. |
* meta-data and so on. Then reallocate the root node for another |
|
* parse. |
*/ |
*/ |
void |
void |
mdoc_reset(struct mdoc *mdoc) |
mdoc_reset(struct mdoc *mdoc) |
Line 144 mdoc_reset(struct mdoc *mdoc) |
|
Line 146 mdoc_reset(struct mdoc *mdoc) |
|
bzero(&mdoc->meta, sizeof(struct mdoc_meta)); |
bzero(&mdoc->meta, sizeof(struct mdoc_meta)); |
mdoc->flags = 0; |
mdoc->flags = 0; |
mdoc->lastnamed = mdoc->lastsec = 0; |
mdoc->lastnamed = mdoc->lastsec = 0; |
|
mdoc->last = calloc(1, sizeof(struct mdoc_node)); |
mdoc->first = mdoc->last = |
if (NULL == mdoc->last) |
xcalloc(1, sizeof(struct mdoc_node)); |
err(1, "calloc"); |
|
mdoc->first = mdoc->last; |
mdoc->last->type = MDOC_ROOT; |
mdoc->last->type = MDOC_ROOT; |
mdoc->next = MDOC_NEXT_CHILD; |
mdoc->next = MDOC_NEXT_CHILD; |
} |
} |
Line 184 mdoc_alloc(void *data, int pflags, const struct mdoc_c |
|
Line 187 mdoc_alloc(void *data, int pflags, const struct mdoc_c |
|
{ |
{ |
struct mdoc *p; |
struct mdoc *p; |
|
|
p = xcalloc(1, sizeof(struct mdoc)); |
if (NULL == (p = calloc(1, sizeof(struct mdoc)))) |
|
err(1, "calloc"); |
|
|
p->data = data; |
p->data = data; |
if (cb) |
if (cb) |
(void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb)); |
(void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb)); |
|
|
p->last = p->first = |
if (NULL == (p->first = calloc(1, sizeof(struct mdoc_node)))) |
xcalloc(1, sizeof(struct mdoc_node)); |
err(1, "calloc"); |
|
p->last = p->first; |
p->last->type = MDOC_ROOT; |
p->last->type = MDOC_ROOT; |
p->pflags = pflags; |
p->pflags = pflags; |
p->next = MDOC_NEXT_CHILD; |
p->next = MDOC_NEXT_CHILD; |
Line 370 mdoc_node_alloc(const struct mdoc *mdoc) |
|
Line 375 mdoc_node_alloc(const struct mdoc *mdoc) |
|
{ |
{ |
struct mdoc_node *p; |
struct mdoc_node *p; |
|
|
p = xcalloc(1, sizeof(struct mdoc_node)); |
if (NULL == (p = calloc(1, sizeof(struct mdoc_node)))) |
|
err(1, "calloc"); |
p->sec = mdoc->lastsec; |
p->sec = mdoc->lastsec; |
|
|
return(p); |
return(p); |
Line 435 mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, |
|
Line 441 mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, |
|
|
|
|
|
int |
int |
mdoc_root_alloc(struct mdoc *mdoc) |
|
{ |
|
struct mdoc_node *p; |
|
|
|
p = mdoc_node_alloc(mdoc); |
|
|
|
p->type = MDOC_ROOT; |
|
|
|
return(mdoc_node_append(mdoc, p)); |
|
} |
|
|
|
|
|
int |
|
mdoc_block_alloc(struct mdoc *mdoc, int line, int pos, |
mdoc_block_alloc(struct mdoc *mdoc, int line, int pos, |
int tok, struct mdoc_arg *args) |
int tok, struct mdoc_arg *args) |
{ |
{ |
Line 500 mdoc_word_alloc(struct mdoc *mdoc, |
|
Line 493 mdoc_word_alloc(struct mdoc *mdoc, |
|
p->line = line; |
p->line = line; |
p->pos = pos; |
p->pos = pos; |
p->type = MDOC_TEXT; |
p->type = MDOC_TEXT; |
p->string = xstrdup(word); |
if (NULL == (p->string = strdup(word))) |
|
err(1, "strdup"); |
|
|
return(mdoc_node_append(mdoc, p)); |
return(mdoc_node_append(mdoc, p)); |
} |
} |
Line 628 parsemacro(struct mdoc *m, int ln, char *buf) |
|
Line 622 parsemacro(struct mdoc *m, int ln, char *buf) |
|
|
|
if ( ! mdoc_macro(m, c, ln, 1, &i, buf)) |
if ( ! mdoc_macro(m, c, ln, 1, &i, buf)) |
goto err; |
goto err; |
|
|
/* |
|
* If we're in literal mode, then add a newline to the end of |
|
* macro lines. Our frontends will interpret this correctly |
|
* (it's documented in mdoc.3). |
|
*/ |
|
|
|
return(1); |
return(1); |
|
|