X-Git-Url: https://git.cameronkatri.com/mandoc.git/blobdiff_plain/632038c8c98f1c408bb368edf910b849f186dc8a..deac31b6127bb1d48e15d19023fa8bfba1ebe3d7:/man.c

diff --git a/man.c b/man.c
index 5b83d958..c27ddaf8 100644
--- a/man.c
+++ b/man.c
@@ -1,4 +1,4 @@
-/*	$Id: man.c,v 1.20 2009/06/16 19:13:28 kristaps Exp $ */
+/*	$Id: man.c,v 1.27 2009/07/07 09:35:40 kristaps Exp $ */
 /*
  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
  *
@@ -23,13 +23,26 @@
 
 #include "libman.h"
 
+const	char *const __man_merrnames[WERRMAX] = {		 
+	"invalid character", /* WNPRINT */
+	"system: malloc error", /* WNMEM */
+	"invalid manual section", /* WMSEC */
+	"invalid date format", /* WDATE */
+	"scope of prior line violated", /* WLNSCOPE */
+	"trailing whitespace", /* WTSPACE */
+	"unterminated quoted parameter", /* WTQUOTE */
+	"document has no body", /* WNODATA */
+	"document has no title/section", /* WNOTITLE */
+	"invalid escape sequence", /* WESCAPE */
+};
+
 const	char *const __man_macronames[MAN_MAX] = {		 
-	"\\\"",		"TH",		"SH",		"SS",
+	"br",		"TH",		"SH",		"SS",
 	"TP", 		"LP",		"PP",		"P",
 	"IP",		"HP",		"SM",		"SB",
 	"BI",		"IB",		"BR",		"RB",
 	"R",		"B",		"I",		"IR",
-	"RI",		"br",		"na",		"i"
+	"RI",		"na",		"i"
 	};
 
 const	char * const *man_macronames = __man_macronames;
@@ -182,6 +195,8 @@ man_node_append(struct man *man, struct man_node *p)
 		abort();
 		/* NOTREACHED */
 	}
+	
+	p->parent->nchild++;
 
 	man->last = p;
 
@@ -250,6 +265,8 @@ man_node_free(struct man_node *p)
 
 	if (p->string)
 		free(p->string);
+	if (p->parent)
+		p->parent->nchild--;
 	free(p);
 }
 
@@ -263,6 +280,7 @@ man_node_freelist(struct man_node *p)
 	if (p->next)
 		man_node_freelist(p->next);
 
+	assert(0 == p->nchild);
 	man_node_free(p);
 }
 
@@ -432,3 +450,16 @@ man_vwarn(struct man *man, int ln, int pos, const char *fmt, ...)
 }
 
 
+int
+man_err(struct man *m, int line, int pos, int iserr, enum merr type)
+{
+	const char	 *p;
+	
+	p = __man_merrnames[(int)type];
+	assert(p);
+
+	if (iserr)
+		return(man_verr(m, line, pos, p));
+
+	return(man_vwarn(m, line, pos, p));
+}