=================================================================== RCS file: /cvs/mandoc/mandoc.c,v retrieving revision 1.66 retrieving revision 1.75 diff -u -p -r1.66 -r1.75 --- mandoc/mandoc.c 2012/06/12 20:21:04 1.66 +++ mandoc/mandoc.c 2013/12/31 23:23:10 1.75 @@ -1,7 +1,7 @@ -/* $Id: mandoc.c,v 1.66 2012/06/12 20:21:04 kristaps Exp $ */ +/* $Id: mandoc.c,v 1.75 2013/12/31 23:23:10 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2011, 2012 Ingo Schwarze + * Copyright (c) 2011, 2012, 2013 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -93,12 +93,23 @@ mandoc_escape(const char **end, const char **start, in case ('C'): if ('\'' != **start) return(ESCAPE_ERROR); - gly = ESCAPE_SPECIAL; *start = ++*end; + if ('u' == (*start)[0] && '\'' != (*start)[1]) + gly = ESCAPE_UNICODE; + else + gly = ESCAPE_SPECIAL; term = '\''; 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, @@ -154,12 +165,16 @@ mandoc_escape(const char **end, const char **start, in /* FALLTHROUGH */ case ('b'): /* FALLTHROUGH */ + case ('B'): + /* FALLTHROUGH */ case ('D'): /* FALLTHROUGH */ case ('o'): /* FALLTHROUGH */ case ('R'): /* FALLTHROUGH */ + case ('w'): + /* FALLTHROUGH */ case ('X'): /* FALLTHROUGH */ case ('Z'): @@ -174,8 +189,6 @@ mandoc_escape(const char **end, const char **start, in * 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'): @@ -183,19 +196,15 @@ mandoc_escape(const char **end, const char **start, in 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; @@ -296,13 +305,19 @@ mandoc_escape(const char **end, const char **start, in switch (gly) { case (ESCAPE_FONT): - /* - * Pretend that the constant-width font modes are the - * same as the regular font modes. - */ - if (2 == *sz && 'C' == **start) { - (*start)++; - (*sz)--; + if (2 == *sz) { + if ('C' == **start) { + /* + * Treat constant-width font modes + * just like regular font modes. + */ + (*start)++; + (*sz)--; + } else { + if ('B' == (*start)[0] && 'I' == (*start)[1]) + gly = ESCAPE_FONTBI; + break; + } } else if (1 != *sz) break; @@ -410,10 +425,10 @@ mandoc_strdup(const char *ptr) * Parse a quoted or unquoted roff-style request or macro argument. * Return a pointer to the parsed argument, which is either the original * pointer or advanced by one byte in case the argument is quoted. - * Null-terminate the argument in place. + * NUL-terminate the argument in place. * Collapse pairs of quotes inside quoted arguments. * Advance the argument pointer to the next argument, - * or to the null byte terminating the argument line. + * or to the NUL byte terminating the argument line. */ char * mandoc_getarg(struct mparse *parse, char **cpp, int ln, int *pos) @@ -432,17 +447,35 @@ mandoc_getarg(struct mparse *parse, char **cpp, int ln pairs = 0; white = 0; for (cp = start; '\0' != *cp; cp++) { - /* Move left after quoted quotes and escaped backslashes. */ + + /* + * Move the following text left + * after quoted quotes and after "\\" and "\t". + */ if (pairs) cp[-pairs] = cp[0]; + if ('\\' == cp[0]) { - if ('\\' == cp[1]) { - /* Poor man's copy mode. */ + /* + * In copy mode, translate double to single + * backslashes and backslash-t to literal tabs. + */ + switch (cp[1]) { + case ('t'): + cp[0] = '\t'; + /* FALLTHROUGH */ + case ('\\'): pairs++; cp++; - } else if (0 == quoted && ' ' == cp[1]) + break; + case (' '): /* Skip escaped blanks. */ - cp++; + if (0 == quoted) + cp++; + break; + default: + break; + } } else if (0 == quoted) { if (' ' == cp[0]) { /* Unescaped blanks end unquoted args. */ @@ -466,7 +499,7 @@ mandoc_getarg(struct mparse *parse, char **cpp, int ln if (1 == quoted) mandoc_msg(MANDOCERR_BADQUOTE, parse, ln, *pos, NULL); - /* Null-terminate this argument and move to the next one. */ + /* NUL-terminate this argument and move to the next one. */ if (pairs) cp[-pairs] = '\0'; if ('\0' != *cp) { @@ -561,10 +594,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); @@ -575,7 +608,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 ('\"'):