-/* $Id: mdoc.c,v 1.101 2009/08/19 11:58:32 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.107 2009/09/24 15:01:06 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <sys/types.h>
+
#include <assert.h>
#include <ctype.h>
#include <stdarg.h>
"unclosed explicit scope", /* EOPEN */
"unterminated quoted phrase", /* EQUOTPHR */
"closure macro without prior context", /* ENOCTX */
- "no description found for library" /* ELIB */
+ "no description found for library", /* ELIB */
+ "bad child for parent context", /* EBADCHILD */
};
const char *const __mdoc_macronames[MDOC_MAX] = {
{
mdoc_free1(mdoc);
- if (mdoc->htab)
- mdoc_hash_free(mdoc->htab);
free(mdoc);
}
if (cb)
(void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb));
+ mdoc_hash_init();
+
p->data = data;
p->pflags = pflags;
- if (NULL == (p->htab = mdoc_hash_alloc())) {
- free(p);
- return(NULL);
- } else if (mdoc_alloc1(p))
+ if (mdoc_alloc1(p))
return(p);
free(p);
p = node_alloc(m, line, pos, tok, MDOC_TAIL);
if (NULL == p)
return(0);
- return(node_append(m, p));
+ if ( ! node_append(m, p))
+ return(0);
+ m->next = MDOC_NEXT_CHILD;
+ return(1);
}
p = node_alloc(m, line, pos, tok, MDOC_HEAD);
if (NULL == p)
return(0);
- return(node_append(m, p));
+ if ( ! node_append(m, p))
+ return(0);
+ m->next = MDOC_NEXT_CHILD;
+ return(1);
}
p = node_alloc(m, line, pos, tok, MDOC_BODY);
if (NULL == p)
return(0);
- return(node_append(m, p));
+ if ( ! node_append(m, p))
+ return(0);
+ m->next = MDOC_NEXT_CHILD;
+ return(1);
}
p->args = args;
if (p->args)
(args->refcnt)++;
- return(node_append(m, p));
+ if ( ! node_append(m, p))
+ return(0);
+ m->next = MDOC_NEXT_CHILD;
+ return(1);
}
p->args = args;
if (p->args)
(args->refcnt)++;
- return(node_append(m, p));
+ if ( ! node_append(m, p))
+ return(0);
+ m->next = MDOC_NEXT_CHILD;
+ return(1);
}
int
parsemacro(struct mdoc *m, int ln, char *buf)
{
- int i, j, c, ppos;
+ int i, j, c;
char mac[5];
/* Empty lines are ignored. */
return(1);
}
- ppos = i;
-
/* Copy the first word into a nil-terminated buffer. */
for (j = 0; j < 4; j++, i++) {
break;
else if (' ' == buf[i])
break;
+
+ /* Check for invalid characters. */
+
+ if (isgraph((u_char)buf[i]))
+ continue;
+ return(mdoc_perr(m, ln, i, EPRINT));
}
mac[j] = 0;
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))
goto err;
return(1);
* 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, ppos, &i, buf))
+ if ( ! mdoc_macro(m, c, ln, 1, &i, buf))
goto err;
return(1);