From c079e75b0cd4178c6a18f1e0aa6c6843f8c85438 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Mon, 24 Oct 2011 20:30:57 +0000 Subject: Handle \N numbered character escapes the same way as groff: If \N is followed by a digit, ignore \N and the digit. If \N is followed by a non-digit, the next non-digit ends the character number; the two delimiters need not match. Kristaps calls that "gross, but not our fault". For now, i'm fixing \N only. Other escapes taking numeric arguments may or may not need similar handling, but \N is by far the most important for practical purposes. ok kristaps@ --- mandoc.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/mandoc.c b/mandoc.c index 42bc8abc..9fdf9f98 100644 --- a/mandoc.c +++ b/mandoc.c @@ -1,4 +1,4 @@ -/* $Id: mandoc.c,v 1.59 2011/09/18 14:14:15 schwarze Exp $ */ +/* $Id: mandoc.c,v 1.60 2011/10/24 20:30:57 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -161,8 +161,7 @@ mandoc_escape(const char **end, const char **start, int *sz) case ('V'): /* FALLTHROUGH */ case ('Y'): - if (ESCAPE_ERROR == gly) - gly = ESCAPE_IGNORE; + gly = ESCAPE_IGNORE; /* FALLTHROUGH */ case ('f'): if (ESCAPE_ERROR == gly) @@ -222,10 +221,7 @@ mandoc_escape(const char **end, const char **start, int *sz) case ('L'): /* FALLTHROUGH */ case ('l'): - /* FALLTHROUGH */ - case ('N'): - if (ESCAPE_ERROR == gly) - gly = ESCAPE_NUMBERED; + gly = ESCAPE_NUMBERED; /* FALLTHROUGH */ case ('S'): /* FALLTHROUGH */ @@ -241,6 +237,26 @@ mandoc_escape(const char **end, const char **start, int *sz) term = numeric = '\''; break; + /* + * Special handling for the numbered character escape. + * XXX Do any other escapes need similar handling? + */ + case ('N'): + if ('\0' == cp[i]) + return(ESCAPE_ERROR); + *end = &cp[++i]; + if (isdigit((unsigned char)cp[i-1])) + return(ESCAPE_IGNORE); + while (isdigit((unsigned char)**end)) + (*end)++; + if (start) + *start = &cp[i]; + if (sz) + *sz = *end - &cp[i]; + if ('\0' != **end) + (*end)++; + return(ESCAPE_NUMBERED); + /* * Sizes get a special category of their own. */ -- cgit v1.2.3-56-ge451