]> git.cameronkatri.com Git - mandoc.git/blobdiff - argv.c
-diag fixed (allows quoted parameters)
[mandoc.git] / argv.c
diff --git a/argv.c b/argv.c
index aed85c42c3d6a8c328bc3c4ea5cfd1df91c64fa3..413f5deeb14e9df0304296849ac59e26be7c6daf 100644 (file)
--- a/argv.c
+++ b/argv.c
@@ -1,4 +1,4 @@
-/* $Id: argv.c,v 1.28 2009/02/23 15:19:47 kristaps Exp $ */
+/* $Id: argv.c,v 1.35 2009/03/03 22:28:21 kristaps Exp $ */
 /*
  * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
  *
@@ -35,7 +35,7 @@
 #define        ARGS_DELIM      (1 << 1)
 #define        ARGS_TABSEP     (1 << 2)
 
-static int              lookup(int, const char *);
+static int              argv_a2arg(int, const char *);
 static int              args(struct mdoc *, int, int *, 
                                char *, int, char **);
 static int              argv(struct mdoc *, int,
@@ -74,7 +74,7 @@ static        int mdoc_argflags[MDOC_MAX] = {
        0, /* Ed */
        0, /* Bl */
        0, /* El */
-       ARGS_DELIM, /* It */
+       0, /* It */
        ARGS_DELIM, /* Ad */ 
        ARGS_DELIM, /* An */
        ARGS_DELIM, /* Ar */
@@ -251,11 +251,19 @@ mdoc_args(struct mdoc *mdoc, int line,
 
                /* LINTED */
                for (i = 0; i < c; i++) {
-                       if (MDOC_Column != n->data.block.argv[i].arg)
-                               continue;
-                       fl |= ARGS_TABSEP;
-                       fl &= ~ARGS_DELIM;
-                       break;
+                       switch (n->data.block.argv[i].arg) {
+                       case (MDOC_Column):
+                               fl |= ARGS_TABSEP;
+                               fl &= ~ARGS_DELIM;
+                               i = c;
+                               break;
+                       case (MDOC_Diag):
+                               fl |= ARGS_QUOTED;
+                               i = c;
+                               break;
+                       default:
+                               break;
+                       }
                }
        }
 
@@ -267,7 +275,7 @@ static int
 args(struct mdoc *mdoc, int line, 
                int *pos, char *buf, int fl, char **v)
 {
-       int               i, c;
+       int               i;
        char             *p, *pp;
 
        assert(*pos > 0);
@@ -290,14 +298,15 @@ args(struct mdoc *mdoc, int line,
         */
 
        if ((fl & ARGS_DELIM) && mdoc_iscdelim(buf[*pos])) {
-               for (i = *pos; (c = buf[i]); ) {
-                       if ( ! mdoc_iscdelim(c))
+               for (i = *pos; buf[i]; ) {
+                       if ( ! mdoc_iscdelim(buf[i]))
                                break;
                        i++;
-                       if (0 == buf[i] || ! isspace(c))
+                       /* There must be at least one space... */
+                       if (0 == buf[i] || ! isspace((int)buf[i]))
                                break;
                        i++;
-                       while (buf[i] && isspace(c))
+                       while (buf[i] && isspace((int)buf[i]))
                                i++;
                }
                if (0 == buf[i]) {
@@ -375,7 +384,7 @@ args(struct mdoc *mdoc, int line,
                                        p++;
                                if (0 != *p)
                                        *(p - 1) = 0;
-                               *pos += p - *v;
+                               *pos += (int)(p - *v);
                        } 
 
                        if (p && 0 == *p)
@@ -396,7 +405,7 @@ args(struct mdoc *mdoc, int line,
                        if (p > *v && ' ' == *(p - 1))
                                if ( ! pwarn(mdoc, line, *pos, WTAILWS))
                                        return(0);
-                       *pos += p - *v;
+                       *pos += (int)(p - *v);
 
                        return(ARGS_WORD);
                } 
@@ -404,8 +413,8 @@ args(struct mdoc *mdoc, int line,
                /* Do non-tabsep look-ahead here. */
                
                if ( ! (ARGS_TABSEP & fl))
-                       while ((c = buf[*pos])) {
-                               if (isspace(c))
+                       while (buf[*pos]) {
+                               if (isspace((int)buf[*pos]))
                                        if ('\\' != buf[*pos - 1])
                                                break;
                                (*pos)++;
@@ -466,7 +475,7 @@ args(struct mdoc *mdoc, int line,
 
 
 static int
-lookup(int tok, const char *argv)
+argv_a2arg(int tok, const char *argv)
 {
 
        switch (tok) {
@@ -650,7 +659,7 @@ argv_multi(struct mdoc *mdoc, int line,
                        return(0);
                } else if (ARGS_EOLN == c)
                        break;
-               v->value[v->sz] = p;
+               v->value[(int)v->sz] = p;
        }
 
        if (0 < v->sz && v->sz < MDOC_LINEARG_MAX)
@@ -715,7 +724,7 @@ int
 mdoc_argv(struct mdoc *mdoc, int line, int tok,
                struct mdoc_arg *v, int *pos, char *buf)
 {
-       int              i, ppos;
+       int              i;
        char            *p;
 
        (void)memset(v, 0, sizeof(struct mdoc_arg));
@@ -747,7 +756,7 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
        if (buf[*pos])
                buf[(*pos)++] = 0;
 
-       if (MDOC_ARG_MAX == (v->arg = lookup(tok, p))) {
+       if (MDOC_ARG_MAX == (v->arg = argv_a2arg(tok, p))) {
                if ( ! pwarn(mdoc, line, i, WARGVPARM))
                        return(ARGV_ERROR);
                return(ARGV_WORD);
@@ -758,7 +767,6 @@ mdoc_argv(struct mdoc *mdoc, int line, int tok,
 
        /* FIXME: whitespace if no value. */
 
-       ppos = *pos;
        if ( ! argv(mdoc, line, v, pos, buf))
                return(ARGV_ERROR);