diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2011-10-24 20:29:22 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2011-10-24 20:29:22 +0000 |
commit | e3a7741b37324badd4a8798bc11f5f6f48cbed5d (patch) | |
tree | 65a9c2a58fea5d8cce32f9c54bfbed283952daae /usr.bin/mandoc | |
parent | 6c0965f8d7fb84a02196d91d79ef425eae0b7578 (diff) |
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".
This fixes most of src/regress/usr.bin/mandoc/char/N/basic.in, except
that handling of non-printable characters still differs from groff.
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@
Diffstat (limited to 'usr.bin/mandoc')
-rw-r--r-- | usr.bin/mandoc/mandoc.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/usr.bin/mandoc/mandoc.c b/usr.bin/mandoc/mandoc.c index e816496638b..716940f257c 100644 --- a/usr.bin/mandoc/mandoc.c +++ b/usr.bin/mandoc/mandoc.c @@ -1,4 +1,4 @@ -/* $Id: mandoc.c,v 1.28 2011/09/18 15:54:48 schwarze Exp $ */ +/* $Id: mandoc.c,v 1.29 2011/10/24 20:29:21 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org> @@ -157,8 +157,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) @@ -218,10 +217,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 */ @@ -237,6 +233,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. */ |