version 1.97, 2009/07/29 08:46:06 |
version 1.106, 2009/09/23 11:53:45 |
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
*/ |
*/ |
|
#include <sys/types.h> |
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
#include <stdarg.h> |
#include <stdarg.h> |
Line 74 const char *const __mdoc_merrnames[MERRMAX] = { |
|
Line 76 const char *const __mdoc_merrnames[MERRMAX] = { |
|
"unclosed explicit scope", /* EOPEN */ |
"unclosed explicit scope", /* EOPEN */ |
"unterminated quoted phrase", /* EQUOTPHR */ |
"unterminated quoted phrase", /* EQUOTPHR */ |
"closure macro without prior context", /* ENOCTX */ |
"closure macro without prior context", /* ENOCTX */ |
"invalid whitespace after control character", /* ESPACE */ |
|
"no description found for library" /* ELIB */ |
"no description found for library" /* ELIB */ |
}; |
}; |
|
|
Line 231 mdoc_free(struct mdoc *mdoc) |
|
Line 232 mdoc_free(struct mdoc *mdoc) |
|
{ |
{ |
|
|
mdoc_free1(mdoc); |
mdoc_free1(mdoc); |
if (mdoc->htab) |
|
mdoc_hash_free(mdoc->htab); |
|
free(mdoc); |
free(mdoc); |
} |
} |
|
|
Line 250 mdoc_alloc(void *data, int pflags, const struct mdoc_c |
|
Line 249 mdoc_alloc(void *data, int pflags, const struct mdoc_c |
|
if (cb) |
if (cb) |
(void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb)); |
(void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb)); |
|
|
|
mdoc_hash_init(); |
|
|
p->data = data; |
p->data = data; |
p->pflags = pflags; |
p->pflags = pflags; |
|
|
if (NULL == (p->htab = mdoc_hash_alloc())) { |
if (mdoc_alloc1(p)) |
free(p); |
|
return(NULL); |
|
} else if (mdoc_alloc1(p)) |
|
return(p); |
return(p); |
|
|
free(p); |
free(p); |
Line 460 mdoc_tail_alloc(struct mdoc *m, int line, int pos, int |
|
Line 458 mdoc_tail_alloc(struct mdoc *m, int line, int pos, int |
|
p = node_alloc(m, line, pos, tok, MDOC_TAIL); |
p = node_alloc(m, line, pos, tok, MDOC_TAIL); |
if (NULL == p) |
if (NULL == p) |
return(0); |
return(0); |
return(node_append(m, p)); |
if ( ! node_append(m, p)) |
|
return(0); |
|
m->next = MDOC_NEXT_CHILD; |
|
return(1); |
} |
} |
|
|
|
|
Line 475 mdoc_head_alloc(struct mdoc *m, int line, int pos, int |
|
Line 476 mdoc_head_alloc(struct mdoc *m, int line, int pos, int |
|
p = node_alloc(m, line, pos, tok, MDOC_HEAD); |
p = node_alloc(m, line, pos, tok, MDOC_HEAD); |
if (NULL == p) |
if (NULL == p) |
return(0); |
return(0); |
return(node_append(m, p)); |
if ( ! node_append(m, p)) |
|
return(0); |
|
m->next = MDOC_NEXT_CHILD; |
|
return(1); |
} |
} |
|
|
|
|
Line 487 mdoc_body_alloc(struct mdoc *m, int line, int pos, int |
|
Line 491 mdoc_body_alloc(struct mdoc *m, int line, int pos, int |
|
p = node_alloc(m, line, pos, tok, MDOC_BODY); |
p = node_alloc(m, line, pos, tok, MDOC_BODY); |
if (NULL == p) |
if (NULL == p) |
return(0); |
return(0); |
return(node_append(m, p)); |
if ( ! node_append(m, p)) |
|
return(0); |
|
m->next = MDOC_NEXT_CHILD; |
|
return(1); |
} |
} |
|
|
|
|
Line 503 mdoc_block_alloc(struct mdoc *m, int line, int pos, |
|
Line 510 mdoc_block_alloc(struct mdoc *m, int line, int pos, |
|
p->args = args; |
p->args = args; |
if (p->args) |
if (p->args) |
(args->refcnt)++; |
(args->refcnt)++; |
return(node_append(m, p)); |
if ( ! node_append(m, p)) |
|
return(0); |
|
m->next = MDOC_NEXT_CHILD; |
|
return(1); |
} |
} |
|
|
|
|
Line 519 mdoc_elem_alloc(struct mdoc *m, int line, int pos, |
|
Line 529 mdoc_elem_alloc(struct mdoc *m, int line, int pos, |
|
p->args = args; |
p->args = args; |
if (p->args) |
if (p->args) |
(args->refcnt)++; |
(args->refcnt)++; |
return(node_append(m, p)); |
if ( ! node_append(m, p)) |
|
return(0); |
|
m->next = MDOC_NEXT_CHILD; |
|
return(1); |
} |
} |
|
|
|
|
Line 544 pstring(struct mdoc *m, int line, int pos, const char |
|
Line 557 pstring(struct mdoc *m, int line, int pos, const char |
|
/* Prohibit truncation. */ |
/* Prohibit truncation. */ |
assert(sv < len + 1); |
assert(sv < len + 1); |
|
|
return(node_append(m, n)); |
if ( ! node_append(m, n)) |
|
return(0); |
|
m->next = MDOC_NEXT_SIBLING; |
|
return(1); |
} |
} |
|
|
|
|
Line 601 parsetext(struct mdoc *m, int line, char *buf) |
|
Line 617 parsetext(struct mdoc *m, int line, char *buf) |
|
* back-end, as it should be preserved as a single term. |
* back-end, as it should be preserved as a single term. |
*/ |
*/ |
|
|
if (MDOC_LITERAL & m->flags) { |
if (MDOC_LITERAL & m->flags) |
if ( ! mdoc_word_alloc(m, line, 0, buf)) |
return(mdoc_word_alloc(m, line, 0, buf)); |
return(0); |
|
m->next = MDOC_NEXT_SIBLING; |
|
return(1); |
|
} |
|
|
|
/* Disallow blank/white-space lines in non-literal mode. */ |
/* Disallow blank/white-space lines in non-literal mode. */ |
|
|
Line 631 parsetext(struct mdoc *m, int line, char *buf) |
|
Line 643 parsetext(struct mdoc *m, int line, char *buf) |
|
buf[i++] = 0; |
buf[i++] = 0; |
if ( ! pstring(m, line, j, &buf[j], (size_t)(i - j))) |
if ( ! pstring(m, line, j, &buf[j], (size_t)(i - j))) |
return(0); |
return(0); |
m->next = MDOC_NEXT_SIBLING; |
|
|
|
for ( ; ' ' == buf[i]; i++) |
for ( ; ' ' == buf[i]; i++) |
/* Skip trailing whitespace. */ ; |
/* Skip trailing whitespace. */ ; |
Line 670 macrowarn(struct mdoc *m, int ln, const char *buf) |
|
Line 681 macrowarn(struct mdoc *m, int ln, const char *buf) |
|
int |
int |
parsemacro(struct mdoc *m, int ln, char *buf) |
parsemacro(struct mdoc *m, int ln, char *buf) |
{ |
{ |
int i, c; |
int i, j, c; |
char mac[5]; |
char mac[5]; |
|
|
/* Empty lines are ignored. */ |
/* Empty lines are ignored. */ |
Line 678 parsemacro(struct mdoc *m, int ln, char *buf) |
|
Line 689 parsemacro(struct mdoc *m, int ln, char *buf) |
|
if (0 == buf[1]) |
if (0 == buf[1]) |
return(1); |
return(1); |
|
|
if (' ' == buf[1]) { |
i = 1; |
i = 2; |
|
|
/* Accept whitespace after the initial control char. */ |
|
|
|
if (' ' == buf[i]) { |
|
i++; |
while (buf[i] && ' ' == buf[i]) |
while (buf[i] && ' ' == buf[i]) |
i++; |
i++; |
if (0 == buf[i]) |
if (0 == buf[i]) |
return(1); |
return(1); |
return(mdoc_perr(m, ln, 1, ESPACE)); |
|
} |
} |
|
|
/* Copy the first word into a nil-terminated buffer. */ |
/* Copy the first word into a nil-terminated buffer. */ |
|
|
for (i = 1; i < 5; i++) { |
for (j = 0; j < 4; j++, i++) { |
if (0 == (mac[i - 1] = buf[i])) |
if (0 == (mac[j] = buf[i])) |
break; |
break; |
else if (' ' == buf[i]) |
else if (' ' == buf[i]) |
break; |
break; |
|
|
|
/* Check for invalid characters. */ |
|
|
|
if (isgraph((u_char)buf[i])) |
|
continue; |
|
return(mdoc_perr(m, ln, i, EPRINT)); |
} |
} |
|
|
mac[i - 1] = 0; |
mac[j] = 0; |
|
|
if (i == 5 || i <= 2) { |
if (j == 4 || j < 2) { |
if ( ! macrowarn(m, ln, mac)) |
if ( ! macrowarn(m, ln, mac)) |
goto err; |
goto err; |
return(1); |
return(1); |
} |
} |
|
|
if (MDOC_MAX == (c = mdoc_hash_find(m->htab, mac))) { |
if (MDOC_MAX == (c = mdoc_hash_find(mac))) { |
if ( ! macrowarn(m, ln, mac)) |
if ( ! macrowarn(m, ln, mac)) |
goto err; |
goto err; |
return(1); |
return(1); |
Line 715 parsemacro(struct mdoc *m, int ln, char *buf) |
|
Line 735 parsemacro(struct mdoc *m, int ln, char *buf) |
|
while (buf[i] && ' ' == buf[i]) |
while (buf[i] && ' ' == buf[i]) |
i++; |
i++; |
|
|
/* Begin recursive parse sequence. */ |
/* |
|
* Begin recursive parse sequence. Since we're at the start of |
|
* the line, we don't need to do callable/parseable checks. |
|
*/ |
if ( ! mdoc_macro(m, c, ln, 1, &i, buf)) |
if ( ! mdoc_macro(m, c, ln, 1, &i, buf)) |
goto err; |
goto err; |
|
|
Line 727 err: /* Error out. */ |
|
Line 749 err: /* Error out. */ |
|
m->flags |= MDOC_HALT; |
m->flags |= MDOC_HALT; |
return(0); |
return(0); |
} |
} |
|
|
|
|