]> git.cameronkatri.com Git - mandoc.git/blobdiff - mandoc.c
Clarified EXIT STATUS sections. Discussed among schwarze@, Thomas, and
[mandoc.git] / mandoc.c
index 72eba853271b2d85437e80158252d551613aa8dd..5598ca810f72dee8f98797c86560ef0181b2ed57 100644 (file)
--- a/mandoc.c
+++ b/mandoc.c
@@ -1,4 +1,4 @@
-/*     $Id: mandoc.c,v 1.23 2010/07/18 17:00:26 schwarze Exp $ */
+/*     $Id: mandoc.c,v 1.34 2010/08/29 11:28:09 kristaps Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
  *
@@ -48,13 +48,56 @@ mandoc_special(char *p)
        p++;
 
        switch (*p++) {
+#if 0
+       case ('Z'):
+               /* FALLTHROUGH */
+       case ('X'):
+               /* FALLTHROUGH */
+       case ('x'):
+               /* FALLTHROUGH */
+       case ('S'):
+               /* FALLTHROUGH */
+       case ('R'):
+               /* FALLTHROUGH */
+       case ('N'):
+               /* FALLTHROUGH */
+       case ('l'):
+               /* FALLTHROUGH */
+       case ('L'):
+               /* FALLTHROUGH */
+       case ('H'):
+               /* FALLTHROUGH */
+       case ('h'):
+               /* FALLTHROUGH */
+       case ('D'):
+               /* FALLTHROUGH */
+       case ('C'):
+               /* FALLTHROUGH */
+       case ('b'):
+               /* FALLTHROUGH */
+       case ('B'):
+               /* FALLTHROUGH */
+       case ('a'):
+               /* FALLTHROUGH */
+       case ('A'):
+               if (*p++ != '\'')
+                       return(0);
+               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 ('('):
@@ -66,6 +109,9 @@ mandoc_special(char *p)
                case ('\''):
                        term = '\'';
                        break;
+               case ('0'):
+                       i = 1;
+                       /* FALLTHROUGH */
                default:
                        len = 1;
                        p--;
@@ -75,14 +121,49 @@ 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'):
+               /* FALLTHROUGH */
+       case ('V'):
+               /* FALLTHROUGH */
+       case ('$'):
+               /* FALLTHROUGH */
+       case ('n'):
+               /* FALLTHROUGH */
+#endif
+       case ('k'):
+               /* FALLTHROUGH */
+       case ('M'):
+               /* FALLTHROUGH */
+       case ('m'):
+               /* FALLTHROUGH */
        case ('f'):
                /* FALLTHROUGH */
        case ('F'):
@@ -107,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--;
@@ -117,13 +215,13 @@ mandoc_special(char *p)
                for ( ; *p && term != *p; p++)
                        if (ASCII_HYPH == *p)
                                *p = '-';
-               return(*p ? p - sv : 0);
+               return(*p ? (int)(p - sv) : 0);
        }
 
        for (i = 0; *p && i < len; i++, p++)
                if (ASCII_HYPH == *p)
                        *p = '-';
-       return(i == len ? p - sv : 0);
+       return(i == len ? (int)(p - sv) : 0);
 }
 
 
@@ -135,7 +233,7 @@ mandoc_calloc(size_t num, size_t size)
        ptr = calloc(num, size);
        if (NULL == ptr) {
                perror(NULL);
-               exit(EXIT_FAILURE);
+               exit(MANDOCLEVEL_SYSERR);
        }
 
        return(ptr);
@@ -150,7 +248,7 @@ mandoc_malloc(size_t size)
        ptr = malloc(size);
        if (NULL == ptr) {
                perror(NULL);
-               exit(EXIT_FAILURE);
+               exit(MANDOCLEVEL_SYSERR);
        }
 
        return(ptr);
@@ -164,7 +262,7 @@ mandoc_realloc(void *ptr, size_t size)
        ptr = realloc(ptr, size);
        if (NULL == ptr) {
                perror(NULL);
-               exit(EXIT_FAILURE);
+               exit(MANDOCLEVEL_SYSERR);
        }
 
        return(ptr);
@@ -179,7 +277,7 @@ mandoc_strdup(const char *ptr)
        p = strdup(ptr);
        if (NULL == p) {
                perror(NULL);
-               exit(EXIT_FAILURE);
+               exit(MANDOCLEVEL_SYSERR);
        }
 
        return(p);
@@ -255,7 +353,7 @@ mandoc_eos(const char *p, size_t sz, int enclosed)
         */
 
        found = 0;
-       for (q = p + sz - 1; q >= p; q--) {
+       for (q = p + (int)sz - 1; q >= p; q--) {
                switch (*q) {
                case ('\"'):
                        /* FALLTHROUGH */
@@ -275,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)));
                }
        }