summaryrefslogtreecommitdiffstats
path: root/mandoc.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2018-12-16 00:17:02 +0000
committerIngo Schwarze <schwarze@openbsd.org>2018-12-16 00:17:02 +0000
commit0cfd5175e34d41bc422a986950293edb0d8d2c38 (patch)
tree63934b15f1f9821374eb2a81ad104851dbc5cf12 /mandoc.c
parent0e3f0b740ea18224c3b2c07114be601dd8be97bb (diff)
downloadmandoc-0cfd5175e34d41bc422a986950293edb0d8d2c38.tar.gz
Yet another round of improvements to manual font selection.
Unify handling of \f and .ft. Support \f4 (bold+italic). Support ".ft BI" and ".ft CW" for terminal output. Support the .ft request in HTML output. Reject the bogus fonts \f(C1, \f(C2, \f(C3, and \f(CP. In regress.pl, only strip leading whitespace in math mode.
Diffstat (limited to 'mandoc.c')
-rw-r--r--mandoc.c95
1 files changed, 54 insertions, 41 deletions
diff --git a/mandoc.c b/mandoc.c
index aec05f73..94a58e3f 100644
--- a/mandoc.c
+++ b/mandoc.c
@@ -38,6 +38,59 @@ static char *time2a(time_t);
enum mandoc_esc
+mandoc_font(const char *cp, int sz)
+{
+ switch (sz) {
+ case 0:
+ return ESCAPE_FONTPREV;
+ case 1:
+ switch (cp[0]) {
+ case 'B':
+ case '3':
+ return ESCAPE_FONTBOLD;
+ case 'I':
+ case '2':
+ return ESCAPE_FONTITALIC;
+ case 'P':
+ return ESCAPE_FONTPREV;
+ case 'R':
+ case '1':
+ return ESCAPE_FONTROMAN;
+ case '4':
+ return ESCAPE_FONTBI;
+ default:
+ return ESCAPE_ERROR;
+ }
+ case 2:
+ switch (cp[0]) {
+ case 'B':
+ switch (cp[1]) {
+ case 'I':
+ return ESCAPE_FONTBI;
+ default:
+ return ESCAPE_ERROR;
+ }
+ case 'C':
+ switch (cp[1]) {
+ case 'B':
+ return ESCAPE_FONTBOLD;
+ case 'I':
+ return ESCAPE_FONTITALIC;
+ case 'R':
+ case 'W':
+ return ESCAPE_FONTCW;
+ default:
+ return ESCAPE_ERROR;
+ }
+ default:
+ return ESCAPE_ERROR;
+ }
+ default:
+ return ESCAPE_ERROR;
+ }
+}
+
+enum mandoc_esc
mandoc_escape(const char **end, const char **start, int *sz)
{
const char *local_start;
@@ -367,47 +420,7 @@ mandoc_escape(const char **end, const char **start, int *sz)
switch (gly) {
case ESCAPE_FONT:
- if (*sz == 2) {
- if (**start == 'C') {
- if ((*start)[1] == 'W' ||
- (*start)[1] == 'R') {
- gly = ESCAPE_FONTCW;
- break;
- }
- /*
- * Treat other constant-width font modes
- * just like regular font modes.
- */
- (*start)++;
- (*sz)--;
- } else {
- if ((*start)[0] == 'B' && (*start)[1] == 'I')
- gly = ESCAPE_FONTBI;
- break;
- }
- } else if (*sz != 1) {
- if (*sz == 0)
- gly = ESCAPE_FONTPREV;
- break;
- }
-
- switch (**start) {
- case '3':
- case 'B':
- gly = ESCAPE_FONTBOLD;
- break;
- case '2':
- case 'I':
- gly = ESCAPE_FONTITALIC;
- break;
- case 'P':
- gly = ESCAPE_FONTPREV;
- break;
- case '1':
- case 'R':
- gly = ESCAPE_FONTROMAN;
- break;
- }
+ gly = mandoc_font(*start, *sz);
break;
case ESCAPE_SPECIAL:
if (**start == 'c') {