]> git.cameronkatri.com Git - mandoc.git/blobdiff - man.c
Added default print of `~' with empty `Pa' (not documented with OpenBSD, but still...
[mandoc.git] / man.c
diff --git a/man.c b/man.c
index c0b36b26106f2678792903e2ce79c54696d82b79..c27ddaf8002c4e527f5984907d2f21be24a31858 100644 (file)
--- a/man.c
+++ b/man.c
@@ -1,20 +1,18 @@
-/* $Id: man.c,v 1.16 2009/04/05 16:34:22 kristaps Exp $ */
+/*     $Id: man.c,v 1.27 2009/07/07 09:35:40 kristaps Exp $ */
 /*
- * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>
+ * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
  *
  * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the
- * above copyright notice and this permission notice appear in all
- * copies.
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
  *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
- * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
- * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- * PERFORMANCE OF THIS SOFTWARE.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 #include <assert.h>
 #include <ctype.h>
 
 #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;
@@ -184,6 +195,8 @@ man_node_append(struct man *man, struct man_node *p)
                abort();
                /* NOTREACHED */
        }
+       
+       p->parent->nchild++;
 
        man->last = p;
 
@@ -252,6 +265,8 @@ man_node_free(struct man_node *p)
 
        if (p->string)
                free(p->string);
+       if (p->parent)
+               p->parent->nchild--;
        free(p);
 }
 
@@ -265,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);
 }
 
@@ -326,10 +342,6 @@ man_pmacro(struct man *m, int ln, char *buf)
 
        ppos = i;
 
-       if (buf[i] && '\\' == buf[i])
-               if (buf[i + 1] && '\"' == buf[i + 1])
-                       goto out;
-
        /* Copy the first word into a nil-terminated buffer. */
 
        for (j = 0; j < 4; j++, i++) {
@@ -379,7 +391,7 @@ out:
        if (fl) {
                /*
                 * A NLINE macro has been immediately followed with
-                * another.  Close out the preceeding macro's scope, and
+                * another.  Close out the preceding macro's scope, and
                 * continue.
                 */
                assert(MAN_ROOT != m->last->type);
@@ -438,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));
+}