]> git.cameronkatri.com Git - mandoc.git/blobdiff - mdoc_argv.c
More lint fixes.
[mandoc.git] / mdoc_argv.c
index 7d36784d7fe1da1bf960cf72b2091814b94a9736..71fa94088ba28d8c4ebf999d6e27ba3263b4d76d 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: mdoc_argv.c,v 1.25 2009/08/20 13:22:48 kristaps Exp $ */
+/*     $Id: mdoc_argv.c,v 1.32 2009/10/30 05:58:38 kristaps Exp $ */
 /*
  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
  *
@@ -23,6 +23,7 @@
 #include <string.h>
 
 #include "libmdoc.h"
+#include "libmandoc.h"
 
 /*
  * Routines to parse arguments of macros.  Arguments follow the syntax
@@ -59,8 +60,8 @@ static        int mdoc_argvflags[MDOC_ARG_MAX] = {
        ARGV_NONE,      /* MDOC_Ragged */
        ARGV_NONE,      /* MDOC_Unfilled */
        ARGV_NONE,      /* MDOC_Literal */
-       ARGV_NONE,      /* MDOC_File */
-       ARGV_SINGLE,    /* MDOC_Offset */
+       ARGV_SINGLE,    /* MDOC_File */
+       ARGV_OPT_SINGLE, /* MDOC_Offset */
        ARGV_NONE,      /* MDOC_Bullet */
        ARGV_NONE,      /* MDOC_Dash */
        ARGV_NONE,      /* MDOC_Hyphen */
@@ -203,6 +204,7 @@ static      int mdoc_argflags[MDOC_MAX] = {
        0, /* %Q */
        0, /* br */
        0, /* sp */
+       0, /* %U */
 };
 
 
@@ -265,23 +267,12 @@ mdoc_argv(struct mdoc *m, int line, int tok,
        if ( ! argv(m, line, &tmp, pos, buf))
                return(ARGV_ERROR);
 
-       if (NULL == (arg = *v)) {
-               *v = calloc(1, sizeof(struct mdoc_arg));
-               if (NULL == *v) {
-                       (void)mdoc_nerr(m, m->last, EMALLOC);
-                       return(ARGV_ERROR);
-               }
-               arg = *v;
-       } 
+       if (NULL == (arg = *v))
+               arg = *v = mandoc_calloc(1, sizeof(struct mdoc_arg));
 
        arg->argc++;
-       arg->argv = realloc(arg->argv, arg->argc * 
-                       sizeof(struct mdoc_argv));
-
-       if (NULL == arg->argv) {
-               (void)mdoc_nerr(m, m->last, EMALLOC);
-               return(ARGV_ERROR);
-       }
+       arg->argv = mandoc_realloc
+               (arg->argv, arg->argc * sizeof(struct mdoc_argv));
 
        (void)memcpy(&arg->argv[(int)arg->argc - 1], 
                        &tmp, sizeof(struct mdoc_argv));
@@ -309,9 +300,13 @@ mdoc_argv_free(struct mdoc_arg *p)
        for (i = 0; i < (int)p->argc; i++) {
                if (0 == p->argv[i].sz)
                        continue;
+               if (NULL == p->argv[i].value)
+                       continue;
+
                /* LINTED */
                for (j = 0; j < (int)p->argv[i].sz; j++) 
-                       free(p->argv[i].value[j]);
+                       if (p->argv[i].value[j])
+                               free(p->argv[i].value[j]);
 
                free(p->argv[i].value);
        }
@@ -553,7 +548,7 @@ args(struct mdoc *m, int line, int *pos,
 
 
 static int
-argv_a2arg(int tok, const char *argv)
+argv_a2arg(int tok, const char *p)
 {
 
        /*
@@ -566,80 +561,82 @@ argv_a2arg(int tok, const char *argv)
 
        switch (tok) {
        case (MDOC_An):
-               if (0 == strcmp(argv, "split"))
+               if (0 == strcmp(p, "split"))
                        return(MDOC_Split);
-               else if (0 == strcmp(argv, "nosplit"))
+               else if (0 == strcmp(p, "nosplit"))
                        return(MDOC_Nosplit);
                break;
 
        case (MDOC_Bd):
-               if (0 == strcmp(argv, "ragged"))
+               if (0 == strcmp(p, "ragged"))
                        return(MDOC_Ragged);
-               else if (0 == strcmp(argv, "unfilled"))
+               else if (0 == strcmp(p, "unfilled"))
                        return(MDOC_Unfilled);
-               else if (0 == strcmp(argv, "filled"))
+               else if (0 == strcmp(p, "filled"))
                        return(MDOC_Filled);
-               else if (0 == strcmp(argv, "literal"))
+               else if (0 == strcmp(p, "literal"))
                        return(MDOC_Literal);
-               else if (0 == strcmp(argv, "file"))
+               else if (0 == strcmp(p, "file"))
                        return(MDOC_File);
-               else if (0 == strcmp(argv, "offset"))
+               else if (0 == strcmp(p, "offset"))
                        return(MDOC_Offset);
-               else if (0 == strcmp(argv, "compact"))
+               else if (0 == strcmp(p, "compact"))
                        return(MDOC_Compact);
+               else if (0 == strcmp(p, "centered"))
+                       return(MDOC_Centred);
                break;
 
        case (MDOC_Bf):
-               if (0 == strcmp(argv, "emphasis"))
+               if (0 == strcmp(p, "emphasis"))
                        return(MDOC_Emphasis);
-               else if (0 == strcmp(argv, "literal"))
+               else if (0 == strcmp(p, "literal"))
                        return(MDOC_Literal);
-               else if (0 == strcmp(argv, "symbolic"))
+               else if (0 == strcmp(p, "symbolic"))
                        return(MDOC_Symbolic);
                break;
 
        case (MDOC_Bk):
-               if (0 == strcmp(argv, "words"))
+               if (0 == strcmp(p, "words"))
                        return(MDOC_Words);
                break;
 
        case (MDOC_Bl):
-               if (0 == strcmp(argv, "bullet"))
+               if (0 == strcmp(p, "bullet"))
                        return(MDOC_Bullet);
-               else if (0 == strcmp(argv, "dash"))
+               else if (0 == strcmp(p, "dash"))
                        return(MDOC_Dash);
-               else if (0 == strcmp(argv, "hyphen"))
+               else if (0 == strcmp(p, "hyphen"))
                        return(MDOC_Hyphen);
-               else if (0 == strcmp(argv, "item"))
+               else if (0 == strcmp(p, "item"))
                        return(MDOC_Item);
-               else if (0 == strcmp(argv, "enum"))
+               else if (0 == strcmp(p, "enum"))
                        return(MDOC_Enum);
-               else if (0 == strcmp(argv, "tag"))
+               else if (0 == strcmp(p, "tag"))
                        return(MDOC_Tag);
-               else if (0 == strcmp(argv, "diag"))
+               else if (0 == strcmp(p, "diag"))
                        return(MDOC_Diag);
-               else if (0 == strcmp(argv, "hang"))
+               else if (0 == strcmp(p, "hang"))
                        return(MDOC_Hang);
-               else if (0 == strcmp(argv, "ohang"))
+               else if (0 == strcmp(p, "ohang"))
                        return(MDOC_Ohang);
-               else if (0 == strcmp(argv, "inset"))
+               else if (0 == strcmp(p, "inset"))
                        return(MDOC_Inset);
-               else if (0 == strcmp(argv, "column"))
+               else if (0 == strcmp(p, "column"))
                        return(MDOC_Column);
-               else if (0 == strcmp(argv, "width"))
+               else if (0 == strcmp(p, "width"))
                        return(MDOC_Width);
-               else if (0 == strcmp(argv, "offset"))
+               else if (0 == strcmp(p, "offset"))
                        return(MDOC_Offset);
-               else if (0 == strcmp(argv, "compact"))
+               else if (0 == strcmp(p, "compact"))
                        return(MDOC_Compact);
-               else if (0 == strcmp(argv, "nested"))
+               else if (0 == strcmp(p, "nested"))
                        return(MDOC_Nested);
                break;
        
        case (MDOC_Rv):
                /* FALLTHROUGH */
        case (MDOC_Ex):
-               if (0 == strcmp(argv, "std"))
+               if (0 == strcmp(p, "std"))
                        return(MDOC_Std);
                break;
        default:
@@ -666,16 +663,11 @@ argv_multi(struct mdoc *m, int line,
                else if (ARGS_EOLN == c)
                        break;
 
-               if (0 == v->sz % MULTI_STEP) {
-                       v->value = realloc(v->value, 
+               if (0 == v->sz % MULTI_STEP)
+                       v->value = mandoc_realloc(v->value, 
                                (v->sz + MULTI_STEP) * sizeof(char *));
-                       if (NULL == v->value) {
-                               (void)mdoc_nerr(m, m->last, EMALLOC);
-                               return(ARGV_ERROR);
-                       }
-               }
-               if (NULL == (v->value[(int)v->sz] = strdup(p)))
-                       return(mdoc_nerr(m, m->last, EMALLOC));
+
+               v->value[(int)v->sz] = mandoc_strdup(p);
        }
 
        return(1);
@@ -699,10 +691,8 @@ argv_opt_single(struct mdoc *m, int line,
                return(1);
 
        v->sz = 1;
-       if (NULL == (v->value = calloc(1, sizeof(char *))))
-               return(mdoc_nerr(m, m->last, EMALLOC));
-       if (NULL == (v->value[0] = strdup(p)))
-               return(mdoc_nerr(m, m->last, EMALLOC));
+       v->value = mandoc_malloc(sizeof(char *));
+       v->value[0] = mandoc_strdup(p);
 
        return(1);
 }
@@ -727,10 +717,8 @@ argv_single(struct mdoc *m, int line,
                return(mdoc_perr(m, line, ppos, EARGVAL));
 
        v->sz = 1;
-       if (NULL == (v->value = calloc(1, sizeof(char *))))
-               return(mdoc_nerr(m, m->last, EMALLOC));
-       if (NULL == (v->value[0] = strdup(p)))
-               return(mdoc_nerr(m, m->last, EMALLOC));
+       v->value = mandoc_malloc(sizeof(char *));
+       v->value[0] = mandoc_strdup(p);
 
        return(1);
 }