]> git.cameronkatri.com Git - mandoc.git/blobdiff - argv.c
Strings abstracted into dynamically-created C files.
[mandoc.git] / argv.c
diff --git a/argv.c b/argv.c
index 261c6b64773926f23c9e39d93377289b4ccdf6b3..2e75d70e43f26ec50dc455835d8bee6c213f65f2 100644 (file)
--- a/argv.c
+++ b/argv.c
@@ -1,4 +1,4 @@
-/* $Id: argv.c,v 1.36 2009/03/05 12:08:53 kristaps Exp $ */
+/* $Id: argv.c,v 1.38 2009/03/06 14:13:47 kristaps Exp $ */
 /*
  * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
  *
@@ -34,6 +34,7 @@
 #define        ARGS_QUOTED     (1 << 0)
 #define        ARGS_DELIM      (1 << 1)
 #define        ARGS_TABSEP     (1 << 2)
+#define        ARGS_ARGVLIKE   (1 << 3)
 
 #define        ARGV_NONE       (1 << 0)
 #define        ARGV_SINGLE     (1 << 1)
@@ -43,7 +44,7 @@
 static int              argv_a2arg(int, const char *);
 static int              args(struct mdoc *, int, int *, 
                                char *, int, char **);
-static int              argv(struct mdoc *, int,
+static int              argv(struct mdoc *, int, int,
                                struct mdoc_arg *, int *, char *);
 static int              argv_single(struct mdoc *, int, 
                                struct mdoc_arg *, int *, char *);
@@ -90,44 +91,7 @@ static       int mdoc_argvflags[MDOC_ARG_MAX] = {
        ARGV_MULTI,     /* MDOC_Column */
        ARGV_SINGLE,    /* MDOC_Width */
        ARGV_NONE,      /* MDOC_Compact */
-       ARGV_OPT_SINGLE, /* MDOC_Std */
-       ARGV_NONE,      /* MDOC_p1003_1_88 */
-       ARGV_NONE,      /* MDOC_p1003_1_90 */
-       ARGV_NONE,      /* MDOC_p1003_1_96 */
-       ARGV_NONE,      /* MDOC_p1003_1_2001 */
-       ARGV_NONE,      /* MDOC_p1003_1_2004 */
-       ARGV_NONE,      /* MDOC_p1003_1 */
-       ARGV_NONE,      /* MDOC_p1003_1b */
-       ARGV_NONE,      /* MDOC_p1003_1b_93 */
-       ARGV_NONE,      /* MDOC_p1003_1c_95 */
-       ARGV_NONE,      /* MDOC_p1003_1g_2000 */
-       ARGV_NONE,      /* MDOC_p1003_2_92 */
-       ARGV_NONE,      /* MDOC_p1387_2_95 */
-       ARGV_NONE,      /* MDOC_p1003_2 */
-       ARGV_NONE,      /* MDOC_p1387_2 */
-       ARGV_NONE,      /* MDOC_isoC_90 */
-       ARGV_NONE,      /* MDOC_isoC_amd1 */
-       ARGV_NONE,      /* MDOC_isoC_tcor1 */
-       ARGV_NONE,      /* MDOC_isoC_tcor2 */
-       ARGV_NONE,      /* MDOC_isoC_99 */
-       ARGV_NONE,      /* MDOC_ansiC */
-       ARGV_NONE,      /* MDOC_ansiC_89 */
-       ARGV_NONE,      /* MDOC_ansiC_99 */
-       ARGV_NONE,      /* MDOC_ieee754 */
-       ARGV_NONE,      /* MDOC_iso8802_3 */
-       ARGV_NONE,      /* MDOC_xpg3 */
-       ARGV_NONE,      /* MDOC_xpg4 */
-       ARGV_NONE,      /* MDOC_xpg4_2 */
-       ARGV_NONE,      /* MDOC_xpg4_3 */
-       ARGV_NONE,      /* MDOC_xbd5 */
-       ARGV_NONE,      /* MDOC_xcu5 */
-       ARGV_NONE,      /* MDOC_xsh5 */
-       ARGV_NONE,      /* MDOC_xns5 */
-       ARGV_NONE,      /* MDOC_xns5_2d2_0 */
-       ARGV_NONE,      /* MDOC_xcurses4_2 */
-       ARGV_NONE,      /* MDOC_susv2 */
-       ARGV_NONE,      /* MDOC_susv3 */
-       ARGV_NONE,      /* MDOC_svid4 */
+       ARGV_SINGLE,    /* MDOC_Std */
        ARGV_NONE,      /* MDOC_Filled */
        ARGV_NONE,      /* MDOC_Words */
        ARGV_NONE,      /* MDOC_Emphasis */
@@ -172,7 +136,7 @@ static      int mdoc_argflags[MDOC_MAX] = {
        0, /* Ot */
        ARGS_DELIM, /* Pa */
        0, /* Rv */
-       ARGS_DELIM, /* St */ 
+       ARGS_DELIM | ARGS_ARGVLIKE, /* St */ 
        ARGS_DELIM, /* Va */
        ARGS_DELIM, /* Vt */ 
        ARGS_DELIM, /* Xr */
@@ -241,6 +205,7 @@ static      int mdoc_argflags[MDOC_MAX] = {
        0, /* Hf */
        0, /* Fr */
        0, /* Ud */
+       0, /* Lb */
 };
 
 
@@ -373,7 +338,7 @@ args(struct mdoc *mdoc, int line,
                if ( ! pwarn(mdoc, line, *pos, WQUOTPARM))
                        return(ARGS_ERROR);
 
-       if ('-' == buf[*pos]) 
+       if ( ! (fl & ARGS_ARGVLIKE) && '-' == buf[*pos]) 
                if ( ! pwarn(mdoc, line, *pos, WARGVPARM))
                        return(ARGS_ERROR);
 
@@ -389,10 +354,10 @@ args(struct mdoc *mdoc, int line,
                                break;
                        i++;
                        /* There must be at least one space... */
-                       if (0 == buf[i] || ! isspace((int)buf[i]))
+                       if (0 == buf[i] || ! isspace((u_char)buf[i]))
                                break;
                        i++;
-                       while (buf[i] && isspace((int)buf[i]))
+                       while (buf[i] && isspace((u_char)buf[i]))
                                i++;
                }
                if (0 == buf[i]) {
@@ -500,7 +465,7 @@ args(struct mdoc *mdoc, int line,
                
                if ( ! (ARGS_TABSEP & fl))
                        while (buf[*pos]) {
-                               if (isspace((int)buf[*pos]))
+                               if (isspace((u_char)buf[*pos]))
                                        if ('\\' != buf[*pos - 1])
                                                break;
                                (*pos)++;
@@ -515,7 +480,7 @@ args(struct mdoc *mdoc, int line,
                        return(ARGS_WORD);
 
                if ( ! (ARGS_TABSEP & fl))
-                       while (buf[*pos] && isspace((int)buf[*pos]))
+                       while (buf[*pos] && isspace((u_char)buf[*pos]))
                                (*pos)++;
 
                if (buf[*pos])
@@ -547,7 +512,7 @@ args(struct mdoc *mdoc, int line,
        if (0 == buf[*pos])
                return(ARGS_QWORD);
 
-       while (buf[*pos] && isspace((int)buf[*pos]))
+       while (buf[*pos] && isspace((u_char)buf[*pos]))
                (*pos)++;
 
        if (buf[*pos])
@@ -646,84 +611,6 @@ argv_a2arg(int tok, const char *argv)
                if (xstrcmp(argv, "std"))
                        return(MDOC_Std);
                break;
-       
-       case (MDOC_St):
-               if (xstrcmp(argv, "p1003.1-88"))
-                       return(MDOC_p1003_1_88);
-               else if (xstrcmp(argv, "p1003.1-90"))
-                       return(MDOC_p1003_1_90);
-               else if (xstrcmp(argv, "p1003.1-96"))
-                       return(MDOC_p1003_1_96);
-               else if (xstrcmp(argv, "p1003.1-2001"))
-                       return(MDOC_p1003_1_2001);
-               else if (xstrcmp(argv, "p1003.1-2004"))
-                       return(MDOC_p1003_1_2004);
-               else if (xstrcmp(argv, "p1003.1"))
-                       return(MDOC_p1003_1);
-               else if (xstrcmp(argv, "p1003.1b"))
-                       return(MDOC_p1003_1b);
-               else if (xstrcmp(argv, "p1003.1b-93"))
-                       return(MDOC_p1003_1b_93);
-               else if (xstrcmp(argv, "p1003.1c-95"))
-                       return(MDOC_p1003_1c_95);
-               else if (xstrcmp(argv, "p1003.1g-2000"))
-                       return(MDOC_p1003_1g_2000);
-               else if (xstrcmp(argv, "p1003.2-92"))
-                       return(MDOC_p1003_2_92);
-               else if (xstrcmp(argv, "p1003.2-95"))
-                       return(MDOC_p1387_2_95);
-               else if (xstrcmp(argv, "p1003.2"))
-                       return(MDOC_p1003_2);
-               else if (xstrcmp(argv, "p1387.2-95"))
-                       return(MDOC_p1387_2);
-               else if (xstrcmp(argv, "isoC-90"))
-                       return(MDOC_isoC_90);
-               else if (xstrcmp(argv, "isoC-amd1"))
-                       return(MDOC_isoC_amd1);
-               else if (xstrcmp(argv, "isoC-tcor1"))
-                       return(MDOC_isoC_tcor1);
-               else if (xstrcmp(argv, "isoC-tcor2"))
-                       return(MDOC_isoC_tcor2);
-               else if (xstrcmp(argv, "isoC-99"))
-                       return(MDOC_isoC_99);
-               else if (xstrcmp(argv, "ansiC"))
-                       return(MDOC_ansiC);
-               else if (xstrcmp(argv, "ansiC-89"))
-                       return(MDOC_ansiC_89);
-               else if (xstrcmp(argv, "ansiC-99"))
-                       return(MDOC_ansiC_99);
-               else if (xstrcmp(argv, "ieee754"))
-                       return(MDOC_ieee754);
-               else if (xstrcmp(argv, "iso8802-3"))
-                       return(MDOC_iso8802_3);
-               else if (xstrcmp(argv, "xpg3"))
-                       return(MDOC_xpg3);
-               else if (xstrcmp(argv, "xpg4"))
-                       return(MDOC_xpg4);
-               else if (xstrcmp(argv, "xpg4.2"))
-                       return(MDOC_xpg4_2);
-               else if (xstrcmp(argv, "xpg4.3"))
-                       return(MDOC_xpg4_3);
-               else if (xstrcmp(argv, "xbd5"))
-                       return(MDOC_xbd5);
-               else if (xstrcmp(argv, "xcu5"))
-                       return(MDOC_xcu5);
-               else if (xstrcmp(argv, "xsh5"))
-                       return(MDOC_xsh5);
-               else if (xstrcmp(argv, "xns5"))
-                       return(MDOC_xns5);
-               else if (xstrcmp(argv, "xns5.2d2.0"))
-                       return(MDOC_xns5_2d2_0);
-               else if (xstrcmp(argv, "xcurses4.2"))
-                       return(MDOC_xcurses4_2);
-               else if (xstrcmp(argv, "susv2"))
-                       return(MDOC_susv2);
-               else if (xstrcmp(argv, "susv3"))
-                       return(MDOC_susv3);
-               else if (xstrcmp(argv, "svid4"))
-                       return(MDOC_svid4);
-               break;
-
        default:
                break;
        }
@@ -823,14 +710,28 @@ argv_single(struct mdoc *mdoc, int line,
  * multiple parameters.
  */
 static int
-argv(struct mdoc *mdoc, int line, 
+argv(struct mdoc *mdoc, int tok, int line, 
                struct mdoc_arg *v, int *pos, char *buf)
 {
+       int              fl;
 
        v->sz = 0;
        v->value = NULL;
+       fl = mdoc_argvflags[v->arg];
+
+       /*
+        * Override the default per-argument value.
+        */
+
+       switch (tok) {
+       case (MDOC_Ex):
+               fl = ARGV_OPT_SINGLE;
+               break;
+       default:
+               break;
+       }
 
-       switch (mdoc_argvflags[v->arg]) {
+       switch (fl) {
        case (ARGV_SINGLE):
                return(argv_single(mdoc, line, v, pos, buf));
        case (ARGV_MULTI):
@@ -863,7 +764,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
        if (0 == buf[*pos])
                return(ARGV_EOLN);
 
-       assert( ! isspace((int)buf[*pos]));
+       assert( ! isspace((u_char)buf[*pos]));
 
        if ('-' != buf[*pos])
                return(ARGV_WORD);
@@ -878,7 +779,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
 
        /* LINTED */
        while (buf[*pos]) {
-               if (isspace((int)buf[*pos])) 
+               if (isspace((u_char)buf[*pos])) 
                        if ('\\' != buf[*pos - 1])
                                break;
                (*pos)++;
@@ -899,12 +800,12 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
                return(ARGV_WORD);
        }
 
-       while (buf[*pos] && isspace((int)buf[*pos]))
+       while (buf[*pos] && isspace((u_char)buf[*pos]))
                (*pos)++;
 
        /* FIXME: whitespace if no value. */
 
-       if ( ! argv(mdoc, line, v, pos, buf))
+       if ( ! argv(mdoc, tok, line, v, pos, buf))
                return(ARGV_ERROR);
 
        return(ARGV_ARG);