]> git.cameronkatri.com Git - mandoc.git/blobdiff - mandoc.c
Fix enum/int mixing.
[mandoc.git] / mandoc.c
index 68caf719637520c3631b7ca3d52c68a75884e5a8..56a187de7a798ff73b28c5a97bceac68daa3ee03 100644 (file)
--- a/mandoc.c
+++ b/mandoc.c
@@ -1,4 +1,4 @@
-/*     $Id: mandoc.c,v 1.26 2010/07/22 14:03:50 kristaps Exp $ */
+/*     $Id: mandoc.c,v 1.35 2010/09/04 20:18:53 kristaps Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
  *
@@ -55,16 +55,10 @@ mandoc_special(char *p)
                /* FALLTHROUGH */
        case ('x'):
                /* FALLTHROUGH */
-       case ('w'):
-               /* FALLTHROUGH */
-       case ('v'):
-               /* FALLTHROUGH */
        case ('S'):
                /* FALLTHROUGH */
        case ('R'):
                /* FALLTHROUGH */
-       case ('o'):
-               /* FALLTHROUGH */
        case ('N'):
                /* FALLTHROUGH */
        case ('l'):
@@ -91,13 +85,19 @@ mandoc_special(char *p)
                term = '\'';
                break;
 #endif
+       case ('h'):
+               /* FALLTHROUGH */
+       case ('v'):
+               /* FALLTHROUGH */
        case ('s'):
                if (ASCII_HYPH == *p)
                        *p = '-';
-               if ('+' == *p || '-' == *p)
-                       p++;
 
-               i = ('s' != *(p - 1));
+               i = 0;
+               if ('+' == *p || '-' == *p) {
+                       p++;
+                       i = 1;
+               }
 
                switch (*p++) {
                case ('('):
@@ -110,7 +110,7 @@ mandoc_special(char *p)
                        term = '\'';
                        break;
                case ('0'):
-                       i++;
+                       i = 1;
                        /* FALLTHROUGH */
                default:
                        len = 1;
@@ -121,13 +121,32 @@ mandoc_special(char *p)
                if (ASCII_HYPH == *p)
                        *p = '-';
                if ('+' == *p || '-' == *p) {
-                       if (i++)
+                       if (i)
                                return(0);
                        p++;
                } 
                
-               if (0 == i)
+               /* Handle embedded numerical subexp or escape. */
+
+               if ('(' == *p) {
+                       while (*p && ')' != *p)
+                               if ('\\' == *p++) {
+                                       i = mandoc_special(--p);
+                                       if (0 == i)
+                                               return(0);
+                                       p += i;
+                               }
+
+                       if (')' == *p++)
+                               break;
+
                        return(0);
+               } else if ('\\' == *p) {
+                       if (0 == (i = mandoc_special(p)))
+                               return(0);
+                       p += i;
+               }
+
                break;
 #if 0
        case ('Y'):
@@ -138,9 +157,9 @@ mandoc_special(char *p)
                /* FALLTHROUGH */
        case ('n'):
                /* FALLTHROUGH */
+#endif
        case ('k'):
                /* FALLTHROUGH */
-#endif
        case ('M'):
                /* FALLTHROUGH */
        case ('m'):
@@ -169,6 +188,23 @@ mandoc_special(char *p)
        case ('['):
                term = ']';
                break;
+       case ('z'):
+               len = 1;
+               if ('\\' == *p) {
+                       if (0 == (i = mandoc_special(p)))
+                               return(0);
+                       p += i;
+                       return(*p ? (int)(p - sv) : 0);
+               }
+               break;
+       case ('o'):
+               /* FALLTHROUGH */
+       case ('w'):
+               if ('\'' == *p++) {
+                       term = '\'';
+                       break;
+               }
+               /* FALLTHROUGH */
        default:
                len = 1;
                p--;
@@ -197,7 +233,7 @@ mandoc_calloc(size_t num, size_t size)
        ptr = calloc(num, size);
        if (NULL == ptr) {
                perror(NULL);
-               exit(EXIT_FAILURE);
+               exit((int)MANDOCLEVEL_SYSERR);
        }
 
        return(ptr);
@@ -212,7 +248,7 @@ mandoc_malloc(size_t size)
        ptr = malloc(size);
        if (NULL == ptr) {
                perror(NULL);
-               exit(EXIT_FAILURE);
+               exit((int)MANDOCLEVEL_SYSERR);
        }
 
        return(ptr);
@@ -226,7 +262,7 @@ mandoc_realloc(void *ptr, size_t size)
        ptr = realloc(ptr, size);
        if (NULL == ptr) {
                perror(NULL);
-               exit(EXIT_FAILURE);
+               exit((int)MANDOCLEVEL_SYSERR);
        }
 
        return(ptr);
@@ -241,7 +277,7 @@ mandoc_strdup(const char *ptr)
        p = strdup(ptr);
        if (NULL == p) {
                perror(NULL);
-               exit(EXIT_FAILURE);
+               exit((int)MANDOCLEVEL_SYSERR);
        }
 
        return(p);
@@ -337,7 +373,7 @@ mandoc_eos(const char *p, size_t sz, int enclosed)
                        found = 1;
                        break;
                default:
-                       return(found && (!enclosed || isalnum(*q)));
+                       return(found && (!enclosed || isalnum((unsigned char)*q)));
                }
        }