]> git.cameronkatri.com Git - mandoc.git/blobdiff - strings.c
Documentation, more validations, cleaned up actions, added Nm action.
[mandoc.git] / strings.c
index 0125671da30f1afa86891f678461e12712c118d4..a94eb8014737c6dae2162aea77ba1fed90baebae 100644 (file)
--- a/strings.c
+++ b/strings.c
@@ -1,4 +1,4 @@
-/* $Id: strings.c,v 1.2 2008/12/17 17:18:38 kristaps Exp $ */
+/* $Id: strings.c,v 1.9 2009/01/17 16:15:27 kristaps Exp $ */
 /*
  * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
  *
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#ifdef __linux__
+#include <time.h>
+#endif
 
 #include "private.h"
 
+#ifdef __linux__
+extern char            *strptime(const char *, const char *, struct tm *);
+#endif
+
 int
-mdoc_isdelim(const char *p)
+mdoc_iscdelim(char p)
 {
 
-       if (0 == *p)
-               return(0);
-       if (0 != *(p + 1))
-               return(0);
-
-       switch (*p) {
-       case('{'):
-               /* FALLTHROUGH */
+       switch (p) {
        case('.'):
                /* FALLTHROUGH */
        case(','):
@@ -56,6 +56,8 @@ mdoc_isdelim(const char *p)
                /* FALLTHROUGH */
        case(']'):
                /* FALLTHROUGH */
+       case('{'):
+               /* FALLTHROUGH */
        case('}'):
                return(1);
        default:
@@ -66,48 +68,52 @@ mdoc_isdelim(const char *p)
 }
 
 
-enum mdoc_sec 
-mdoc_atosec(size_t sz, const char **p)
+int
+mdoc_isdelim(const char *p)
 {
 
-       assert(sz > 0);
-       if (sz > 2)
-               return(SEC_CUSTOM);
-       if (sz == 2) {
-               if (0 == strcmp(*p, "RETURN") &&
-                               0 == strcmp(*(p + 1), "VALUES"))
-                       return(SEC_RETURN_VALUES);
-               if (0 == strcmp(*p, "SEE") &&
-                               0 == strcmp(*(p + 1), "ALSO"))
-                       return(SEC_SEE_ALSO);
-               return(SEC_CUSTOM);
-       }
+       if (0 == *p)
+               return(0);
+       if (0 != *(p + 1))
+               return(0);
+       return(mdoc_iscdelim(*p));
+}
+
+
+enum mdoc_sec 
+mdoc_atosec(const char *p)
+{
 
-       if (0 == strcmp(*p, "NAME"))
+       assert(p);
+       if (0 == strcmp(p, "NAME"))
                return(SEC_NAME);
-       else if (0 == strcmp(*p, "SYNOPSIS"))
+       else if (0 == strcmp(p, "RETURN VALUES"))
+               return(SEC_RETURN_VALUES);
+       else if (0 == strcmp(p, "SEE ALSO"))
+               return(SEC_SEE_ALSO);
+       else if (0 == strcmp(p, "SYNOPSIS"))
                return(SEC_SYNOPSIS);
-       else if (0 == strcmp(*p, "DESCRIPTION"))
+       else if (0 == strcmp(p, "DESCRIPTION"))
                return(SEC_DESCRIPTION);
-       else if (0 == strcmp(*p, "ENVIRONMENT"))
+       else if (0 == strcmp(p, "ENVIRONMENT"))
                return(SEC_ENVIRONMENT);
-       else if (0 == strcmp(*p, "FILES"))
+       else if (0 == strcmp(p, "FILES"))
                return(SEC_FILES);
-       else if (0 == strcmp(*p, "EXAMPLES"))
+       else if (0 == strcmp(p, "EXAMPLES"))
                return(SEC_EXAMPLES);
-       else if (0 == strcmp(*p, "DIAGNOSTICS"))
+       else if (0 == strcmp(p, "DIAGNOSTICS"))
                return(SEC_DIAGNOSTICS);
-       else if (0 == strcmp(*p, "ERRORS"))
+       else if (0 == strcmp(p, "ERRORS"))
                return(SEC_ERRORS);
-       else if (0 == strcmp(*p, "STANDARDS"))
+       else if (0 == strcmp(p, "STANDARDS"))
                return(SEC_STANDARDS);
-       else if (0 == strcmp(*p, "HISTORY"))
+       else if (0 == strcmp(p, "HISTORY"))
                return(SEC_HISTORY);
-       else if (0 == strcmp(*p, "AUTHORS"))
+       else if (0 == strcmp(p, "AUTHORS"))
                return(SEC_AUTHORS);
-       else if (0 == strcmp(*p, "CAVEATS"))
+       else if (0 == strcmp(p, "CAVEATS"))
                return(SEC_CAVEATS);
-       else if (0 == strcmp(*p, "BUGS"))
+       else if (0 == strcmp(p, "BUGS"))
                return(SEC_BUGS);
 
        return(SEC_CUSTOM);
@@ -119,9 +125,11 @@ mdoc_atotime(const char *p)
 {
        struct tm        tm;
 
-       if (strptime(p, "%b %d %Y", &tm))
+       (void)memset(&tm, 0, sizeof(struct tm));
+
+       if (0 == strptime(p, "%b %d %Y", &tm))
                return(mktime(&tm));
-       if (strptime(p, "%b %d, %Y", &tm))
+       if (0 == strptime(p, "%b %d, %Y", &tm))
                return(mktime(&tm));
 
        return(0);
@@ -212,6 +220,8 @@ mdoc_atoarch(const char *p)
                return(ARCH_amiga);
        else if (0 == strcmp(p, "arc"))
                return(ARCH_arc);
+       else if (0 == strcmp(p, "arm"))
+               return(ARCH_arm);
        else if (0 == strcmp(p, "armish"))
                return(ARCH_armish);
        else if (0 == strcmp(p, "aviion"))
@@ -257,3 +267,64 @@ mdoc_atoarch(const char *p)
 
        return(ARCH_DEFAULT);
 }
+
+
+enum mdoc_att
+mdoc_atoatt(const char *p)
+{
+
+       assert(p);
+       if (0 == strcmp(p, "v1"))
+               return(ATT_v1);
+       else if (0 == strcmp(p, "v2"))
+               return(ATT_v2);
+       else if (0 == strcmp(p, "v3"))
+               return(ATT_v3);
+       else if (0 == strcmp(p, "v4"))
+               return(ATT_v4);
+       else if (0 == strcmp(p, "v5"))
+               return(ATT_v5);
+       else if (0 == strcmp(p, "v6"))
+               return(ATT_v6);
+       else if (0 == strcmp(p, "v7"))
+               return(ATT_v7);
+       else if (0 == strcmp(p, "32v"))
+               return(ATT_32v);
+       else if (0 == strcmp(p, "V.1"))
+               return(ATT_V1);
+       else if (0 == strcmp(p, "V.2"))
+               return(ATT_V2);
+       else if (0 == strcmp(p, "V.3"))
+               return(ATT_V3);
+       else if (0 == strcmp(p, "V.4"))
+               return(ATT_V4);
+       
+       return(ATT_DEFAULT);
+}
+
+
+char *
+mdoc_type2a(enum mdoc_type type)
+{
+       switch (type) {
+       case (MDOC_ROOT):
+               return("root");
+       case (MDOC_BLOCK):
+               return("block");
+       case (MDOC_HEAD):
+               return("block-head");
+       case (MDOC_BODY):
+               return("block-body");
+       case (MDOC_TAIL):
+               return("block-tail");
+       case (MDOC_ELEM):
+               return("elem");
+       case (MDOC_TEXT):
+               return("text");
+       default:
+               break;
+       }
+
+       abort();
+       /* NOTREACHED */
+}