=================================================================== RCS file: /cvs/mandoc/mandoc.c,v retrieving revision 1.103 retrieving revision 1.110 diff -u -p -r1.103 -r1.110 --- mandoc/mandoc.c 2017/07/03 13:40:19 1.103 +++ mandoc/mandoc.c 2018/12/14 06:33:14 1.110 @@ -1,7 +1,7 @@ -/* $Id: mandoc.c,v 1.103 2017/07/03 13:40:19 schwarze Exp $ */ +/* $Id: mandoc.c,v 1.110 2018/12/14 06:33:14 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons - * Copyright (c) 2011-2015, 2017 Ingo Schwarze + * Copyright (c) 2011-2015, 2017, 2018 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 @@ -41,7 +41,7 @@ enum mandoc_esc mandoc_escape(const char **end, const char **start, int *sz) { const char *local_start; - int local_sz; + int local_sz, c, i; char term; enum mandoc_esc gly; @@ -139,6 +139,13 @@ mandoc_escape(const char **end, const char **start, in break; } break; + case '*': + if (strncmp(*start, "(.T", 3) != 0) + abort(); + gly = ESCAPE_DEVICE; + *start = ++*end; + *sz = 2; + break; /* * These escapes are of the form \X'Y', where 'X' is the trigger @@ -295,21 +302,29 @@ mandoc_escape(const char **end, const char **start, in switch (gly) { case ESCAPE_FONT: - if (2 == *sz) { - if ('C' == **start) { + if (*sz == 2) { + if (**start == 'C') { + if ((*start)[1] == 'W' || + (*start)[1] == 'R') { + gly = ESCAPE_FONTCW; + break; + } /* - * Treat constant-width font modes + * Treat other constant-width font modes * just like regular font modes. */ (*start)++; (*sz)--; } else { - if ('B' == (*start)[0] && 'I' == (*start)[1]) + if ((*start)[0] == 'B' && (*start)[1] == 'I') gly = ESCAPE_FONTBI; break; } - } else if (1 != *sz) + } else if (*sz != 1) { + if (*sz == 0) + gly = ESCAPE_FONTPREV; break; + } switch (**start) { case '3': @@ -330,8 +345,26 @@ mandoc_escape(const char **end, const char **start, in } break; case ESCAPE_SPECIAL: - if (1 == *sz && 'c' == **start) - gly = ESCAPE_NOSPACE; + if (**start == 'c') { + if (*sz == 1) { + gly = ESCAPE_NOSPACE; + break; + } + if (*sz < 6 || *sz > 7 || + strncmp(*start, "char", 4) != 0 || + (int)strspn(*start + 4, "0123456789") + 4 < *sz) + break; + c = 0; + for (i = 4; i < *sz; i++) + c = 10 * c + ((*start)[i] - '0'); + if (c < 0x21 || (c > 0x7e && c < 0xa0) || c > 0xff) + break; + *start += 4; + *sz -= 4; + gly = ESCAPE_NUMBERED; + break; + } + /* * Unicode escapes are defined in groff as \[u0000] * to \[u10FFFF], where the contained value must be @@ -368,7 +401,7 @@ mandoc_escape(const char **end, const char **start, in * or to the NUL byte terminating the argument line. */ char * -mandoc_getarg(struct mparse *parse, char **cpp, int ln, int *pos) +mandoc_getarg(char **cpp, int ln, int *pos) { char *start, *cp; int quoted, pairs, white; @@ -434,7 +467,7 @@ mandoc_getarg(struct mparse *parse, char **cpp, int ln /* Quoted argument without a closing quote. */ if (1 == quoted) - mandoc_msg(MANDOCERR_ARG_QUOTE, parse, ln, *pos, NULL); + mandoc_msg(MANDOCERR_ARG_QUOTE, ln, *pos, NULL); /* NUL-terminate this argument and move to the next one. */ if (pairs) @@ -448,7 +481,7 @@ mandoc_getarg(struct mparse *parse, char **cpp, int ln *cpp = cp; if ('\0' == *cp && (white || ' ' == cp[-1])) - mandoc_msg(MANDOCERR_SPACE_EOL, parse, ln, *pos, NULL); + mandoc_msg(MANDOCERR_SPACE_EOL, ln, *pos, NULL); return start; } @@ -529,7 +562,7 @@ mandoc_normdate(struct roff_man *man, char *in, int ln /* No date specified: use today's date. */ if (in == NULL || *in == '\0' || strcmp(in, "$" "Mdocdate$") == 0) { - mandoc_msg(MANDOCERR_DATE_MISSING, man->parse, ln, pos, NULL); + mandoc_msg(MANDOCERR_DATE_MISSING, ln, pos, NULL); return time2a(time(NULL)); } @@ -539,20 +572,20 @@ mandoc_normdate(struct roff_man *man, char *in, int ln a2time(&t, "%b %d, %Y", in)) { cp = time2a(t); if (t > time(NULL) + 86400) - mandoc_msg(MANDOCERR_DATE_FUTURE, man->parse, - ln, pos, cp); + mandoc_msg(MANDOCERR_DATE_FUTURE, ln, pos, "%s", cp); + else if (*in != '$' && strcmp(in, cp) != 0) + mandoc_msg(MANDOCERR_DATE_NORM, ln, pos, "%s", cp); return cp; } /* In man(7), do not warn about the legacy format. */ if (a2time(&t, "%Y-%m-%d", in) == 0) - mandoc_msg(MANDOCERR_DATE_BAD, man->parse, ln, pos, in); + mandoc_msg(MANDOCERR_DATE_BAD, ln, pos, "%s", in); else if (t > time(NULL) + 86400) - mandoc_msg(MANDOCERR_DATE_FUTURE, man->parse, ln, pos, in); + mandoc_msg(MANDOCERR_DATE_FUTURE, ln, pos, "%s", in); else if (man->macroset == MACROSET_MDOC) - mandoc_vmsg(MANDOCERR_DATE_LEGACY, man->parse, - ln, pos, "Dd %s", in); + mandoc_msg(MANDOCERR_DATE_LEGACY, ln, pos, "Dd %s", in); /* Use any non-mdoc(7) date verbatim. */