]> git.cameronkatri.com Git - mandoc.git/blobdiff - mdoc.c
Strings abstracted into dynamically-created C files.
[mandoc.git] / mdoc.c
diff --git a/mdoc.c b/mdoc.c
index 23f0d7bb5410e5fb97e83f79352b8a3a1a2faac4..48785716e0f9bbe69fd4ce8a89c21b8a556688b9 100644 (file)
--- a/mdoc.c
+++ b/mdoc.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc.c,v 1.48 2009/02/23 12:45:19 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.52 2009/03/06 14:13:47 kristaps Exp $ */
 /*
  * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
  *
@@ -74,7 +74,7 @@ const char *const __mdoc_macronames[MDOC_MAX] = {
        "Tn",           "Ux",           "Xc",           "Xo",
        "Fo",           "Fc",           "Oo",           "Oc",
        "Bk",           "Ek",           "Bt",           "Hf",
-       "Fr",           "Ud",
+       "Fr",           "Ud",           "Lb",
        };
 
 const  char *const __mdoc_argnames[MDOC_ARG_MAX] = {            
@@ -85,20 +85,8 @@ const        char *const __mdoc_argnames[MDOC_ARG_MAX] = {
        "tag",                  "diag",                 "hang",          
        "ohang",                "inset",                "column",        
        "width",                "compact",              "std",   
-       "p1003.1-88",           "p1003.1-90",           "p1003.1-96",
-       "p1003.1-2001",         "p1003.1-2004",         "p1003.1",
-       "p1003.1b",             "p1003.1b-93",          "p1003.1c-95",
-       "p1003.1g-2000",        "p1003.2-92",           "p1387.2-95",
-       "p1003.2",              "p1387.2",              "isoC-90",
-       "isoC-amd1",            "isoC-tcor1",           "isoC-tcor2",
-       "isoC-99",              "ansiC",                "ansiC-89",
-       "ansiC-99",             "ieee754",              "iso8802-3",
-       "xpg3",                 "xpg4",                 "xpg4.2",
-       "xpg4.3",               "xbd5",                 "xcu5",
-       "xsh5",                 "xns5",                 "xns5.2d2.0",
-       "xcurses4.2",           "susv2",                "susv3",
-       "svid4",                "filled",               "words",
-       "emphasis",             "symbolic",
+       "filled",               "words",                "emphasis",
+       "symbolic"
        };
 
 const  char * const *mdoc_macronames = __mdoc_macronames;
@@ -135,6 +123,10 @@ mdoc_free(struct mdoc *mdoc)
                free(mdoc->meta.os);
        if (mdoc->meta.name)
                free(mdoc->meta.name);
+       if (mdoc->meta.arch)
+               free(mdoc->meta.arch);
+       if (mdoc->meta.vol)
+               free(mdoc->meta.vol);
 
        free(mdoc);
 }
@@ -180,6 +172,12 @@ mdoc_endparse(struct mdoc *mdoc)
 }
 
 
+/*
+ * Main line-parsing routine.  If the line is a macro-line (started with
+ * a '.' control character), then pass along to the parser, which parses
+ * subsequent macros until the end of line.  If normal text, simply
+ * append the entire line to the chain.
+ */
 int
 mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
 {
@@ -192,20 +190,30 @@ mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
        mdoc->linetok = 0;
 
        if ('.' != *buf) {
+               /*
+                * Free-form text.  Not allowed in the prologue.
+                */
                if (SEC_PROLOGUE == mdoc->lastnamed)
-                       return(mdoc_perr(mdoc, line, 0, "text disallowed in document prologue"));
+                       return(mdoc_perr(mdoc, line, 0, 
+                                       "no text in prologue"));
+
                if ( ! mdoc_word_alloc(mdoc, line, 0, buf))
                        return(0);
                mdoc->next = MDOC_NEXT_SIBLING;
                return(1);
        }
 
+       /*
+        * Control-character detected.  Begin the parsing sequence.
+        */
+
        if (buf[1] && '\\' == buf[1])
                if (buf[2] && '\"' == buf[2])
                        return(1);
 
        i = 1;
-       while (buf[i] && ! isspace((int)buf[i]) && i < (int)sizeof(tmp))
+       while (buf[i] && ! isspace((u_char)buf[i]) && 
+                       i < (int)sizeof(tmp))
                i++;
 
        if (i == (int)sizeof(tmp)) {
@@ -226,13 +234,14 @@ mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
                return(mdoc_perr(mdoc, line, 1, "unknown macro"));
        }
 
-       while (buf[i] && isspace((int)buf[i]))
+       while (buf[i] && isspace((u_char)buf[i]))
                i++;
 
        if ( ! mdoc_macro(mdoc, c, line, 1, &i, buf)) {
                mdoc->flags |= MDOC_HALT;
                return(0);
        }
+
        return(1);
 }
 
@@ -309,7 +318,6 @@ mdoc_macro(struct mdoc *mdoc, int tok,
 static int
 mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *p)
 {
-       const char       *nn, *nt, *on, *ot, *act;
 
        assert(mdoc->last);
        assert(mdoc->first);
@@ -336,34 +344,15 @@ mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *p)
                                        MDOC_LINEARG_SOFTMAX, mdoc->linetok))
                        return(0);
 
-       if (MDOC_TEXT == mdoc->last->type)
-               on = "<text>";
-       else if (MDOC_ROOT == mdoc->last->type)
-               on = "<root>";
-       else
-               on = mdoc_macronames[mdoc->last->tok];
-
-       if (MDOC_TEXT == p->type)
-               nn = "<text>";
-       else if (MDOC_ROOT == p->type)
-               nn = "<root>";
-       else
-               nn = mdoc_macronames[p->tok];
-
-       ot = mdoc_type2a(mdoc->last->type);
-       nt = mdoc_type2a(p->type);
-
        switch (mdoc->next) {
        case (MDOC_NEXT_SIBLING):
                mdoc->last->next = p;
                p->prev = mdoc->last;
                p->parent = mdoc->last->parent;
-               act = "sibling";
                break;
        case (MDOC_NEXT_CHILD):
                mdoc->last->child = p;
                p->parent = mdoc->last;
-               act = "child";
                break;
        default:
                abort();
@@ -391,8 +380,6 @@ mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *p)
        }
 
        mdoc->last = p;
-       mdoc_msg(mdoc, "parse: %s `%s' %s of %s `%s'", 
-                       nt, nn, act, ot, on);
        return(1);
 }
 
@@ -656,27 +643,3 @@ argdup(size_t argsz, const struct mdoc_arg *args)
        return(pp);
 }
 
-
-/* FIXME: deprecate. */
-char *
-mdoc_node2a(struct mdoc_node *node)
-{
-       static char      buf[64];
-
-       assert(node);
-
-       buf[0] = 0;
-       (void)xstrlcat(buf, mdoc_type2a(node->type), 64);
-       if (MDOC_ROOT == node->type)
-               return(buf);
-       (void)xstrlcat(buf, " `", 64);
-       if (MDOC_TEXT == node->type)
-               (void)xstrlcat(buf, node->data.text.string, 64);
-       else
-               (void)xstrlcat(buf, mdoc_macronames[node->tok], 64);
-       (void)xstrlcat(buf, "'", 64);
-
-       return(buf);
-}
-
-