=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.151 retrieving revision 1.153 diff -u -p -r1.151 -r1.153 --- mandoc/roff.c 2011/07/25 15:37:00 1.151 +++ mandoc/roff.c 2011/07/26 14:24:06 1.153 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.151 2011/07/25 15:37:00 kristaps Exp $ */ +/* $Id: roff.c,v 1.153 2011/07/26 14:24:06 kristaps Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -395,15 +395,16 @@ roff_alloc(struct mparse *parse) return(r); } - /* * Pre-filter each and every line for reserved words (one beginning with * `\*', e.g., `\*(ab'). These must be handled before the actual line * is processed. - */ + * This also checks the syntax of regular escapes. +*/ static int roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos) { + enum mandoc_esc esc; const char *stesc; /* start of an escape sequence ('\\') */ const char *stnam; /* start of the name, after "[(*" */ const char *cp; /* end of the name, e.g. before ']' */ @@ -426,9 +427,21 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int if ('\0' == *cp) return(1); - if ('*' != *cp++) + + if ('*' != *cp) { + res = cp; + esc = mandoc_escape(&cp, NULL, NULL); + if (ESCAPE_ERROR != esc) + continue; + cp = res; + mandoc_msg + (MANDOCERR_BADESCAPE, r->parse, + ln, (int)(stesc - *bufp), NULL); continue; + } + cp++; + /* * The third character decides the length * of the name of the string. @@ -455,8 +468,13 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int /* Advance to the end of the name. */ for (i = 0; 0 == maxl || i < maxl; i++, cp++) { - if ('\0' == *cp) - return(1); /* Error. */ + if ('\0' == *cp) { + mandoc_msg + (MANDOCERR_BADESCAPE, + r->parse, ln, + (int)(stesc - *bufp), NULL); + return(1); + } if (0 == maxl && ']' == *cp) break; } @@ -469,8 +487,9 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int res = roff_getstrn(r, stnam, (size_t)i); if (NULL == res) { - /* TODO: keep track of the correct position. */ - mandoc_msg(MANDOCERR_BADESCAPE, r->parse, ln, pos, NULL); + mandoc_msg + (MANDOCERR_BADESCAPE, r->parse, + ln, (int)(stesc - *bufp), NULL); res = ""; } @@ -493,7 +512,6 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int return(1); } - enum rofferr roff_parseln(struct roff *r, int ln, char **bufp, size_t *szp, int pos, int *offs) @@ -507,7 +525,7 @@ roff_parseln(struct roff *r, int ln, char **bufp, * words to fill in. */ - if (r->first_string && ! roff_res(r, bufp, szp, ln, pos)) + if ( ! roff_res(r, bufp, szp, ln, pos)) return(ROFF_REPARSE); ppos = pos;