=================================================================== RCS file: /cvs/mandoc/mandoc.c,v retrieving revision 1.71 retrieving revision 1.76 diff -u -p -r1.71 -r1.76 --- mandoc/mandoc.c 2013/12/25 00:50:05 1.71 +++ mandoc/mandoc.c 2014/03/23 11:25:26 1.76 @@ -1,4 +1,4 @@ -/* $Id: mandoc.c,v 1.71 2013/12/25 00:50:05 schwarze Exp $ */ +/* $Id: mandoc.c,v 1.76 2014/03/23 11:25:26 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011, 2012, 2013 Ingo Schwarze @@ -31,6 +31,7 @@ #include #include "mandoc.h" +#include "mandoc_aux.h" #include "libmandoc.h" #define DATESIZE 32 @@ -40,7 +41,7 @@ static char *time2a(time_t); enum mandoc_esc -mandoc_escape(const char const **end, const char const **start, int *sz) +mandoc_escape(const char **end, const char **start, int *sz) { const char *local_start; int local_sz; @@ -102,6 +103,14 @@ mandoc_escape(const char const **end, const char const break; /* + * Escapes taking no arguments at all. + */ + case ('d'): + /* FALLTHROUGH */ + case ('u'): + return(ESCAPE_IGNORE); + + /* * The \z escape is supposed to output the following * character without advancing the cursor position. * Since we are mostly dealing with terminal mode, @@ -157,12 +166,16 @@ mandoc_escape(const char const **end, const char const /* FALLTHROUGH */ case ('b'): /* FALLTHROUGH */ + case ('B'): + /* FALLTHROUGH */ case ('D'): /* FALLTHROUGH */ case ('o'): /* FALLTHROUGH */ case ('R'): /* FALLTHROUGH */ + case ('w'): + /* FALLTHROUGH */ case ('X'): /* FALLTHROUGH */ case ('Z'): @@ -177,8 +190,6 @@ mandoc_escape(const char const **end, const char const * These escapes are of the form \X'N', where 'X' is the trigger * and 'N' resolves to a numerical expression. */ - case ('B'): - /* FALLTHROUGH */ case ('h'): /* FALLTHROUGH */ case ('H'): @@ -186,19 +197,15 @@ mandoc_escape(const char const **end, const char const case ('L'): /* FALLTHROUGH */ case ('l'): - gly = ESCAPE_NUMBERED; /* FALLTHROUGH */ case ('S'): /* FALLTHROUGH */ case ('v'): /* FALLTHROUGH */ - case ('w'): - /* FALLTHROUGH */ case ('x'): if ('\'' != **start) return(ESCAPE_ERROR); - if (ESCAPE_ERROR == gly) - gly = ESCAPE_IGNORE; + gly = ESCAPE_IGNORE; *start = ++*end; term = '\''; break; @@ -347,74 +354,6 @@ mandoc_escape(const char const **end, const char const return(gly); } -void * -mandoc_calloc(size_t num, size_t size) -{ - void *ptr; - - ptr = calloc(num, size); - if (NULL == ptr) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } - - return(ptr); -} - - -void * -mandoc_malloc(size_t size) -{ - void *ptr; - - ptr = malloc(size); - if (NULL == ptr) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } - - return(ptr); -} - - -void * -mandoc_realloc(void *ptr, size_t size) -{ - - ptr = realloc(ptr, size); - if (NULL == ptr) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } - - return(ptr); -} - -char * -mandoc_strndup(const char *ptr, size_t sz) -{ - char *p; - - p = mandoc_malloc(sz + 1); - memcpy(p, ptr, sz); - p[(int)sz] = '\0'; - return(p); -} - -char * -mandoc_strdup(const char *ptr) -{ - char *p; - - p = strdup(ptr); - if (NULL == p) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } - - return(p); -} - /* * Parse a quoted or unquoted roff-style request or macro argument. * Return a pointer to the parsed argument, which is either the original @@ -588,10 +527,10 @@ mandoc_normdate(struct mparse *parse, char *in, int ln } int -mandoc_eos(const char *p, size_t sz, int enclosed) +mandoc_eos(const char *p, size_t sz) { - const char *q; - int found; + const char *q; + int enclosed, found; if (0 == sz) return(0); @@ -602,7 +541,7 @@ mandoc_eos(const char *p, size_t sz, int enclosed) * propagate outward. */ - found = 0; + enclosed = found = 0; for (q = p + (int)sz - 1; q >= p; q--) { switch (*q) { case ('\"'):