=================================================================== RCS file: /cvs/mandoc/term_ascii.c,v retrieving revision 1.30 retrieving revision 1.39 diff -u -p -r1.30 -r1.39 --- mandoc/term_ascii.c 2014/08/14 22:33:10 1.30 +++ mandoc/term_ascii.c 2014/10/28 18:49:33 1.39 @@ -1,4 +1,4 @@ -/* $Id: term_ascii.c,v 1.30 2014/08/14 22:33:10 schwarze Exp $ */ +/* $Id: term_ascii.c,v 1.39 2014/10/28 18:49:33 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * Copyright (c) 2014 Ingo Schwarze @@ -19,14 +19,15 @@ #include -#ifdef USE_WCHAR +#include +#if HAVE_WCHAR #include #endif #include #include #include #include -#ifdef USE_WCHAR +#if HAVE_WCHAR #include #endif @@ -36,18 +37,8 @@ #include "term.h" #include "main.h" -/* - * Sadly, this doesn't seem to be defined on systems even when they - * support it. For the time being, remove it and let those compiling - * the software decide for themselves what to use. - */ -#if 0 -#if ! defined(__STDC_ISO_10646__) -# undef USE_WCHAR -#endif -#endif - -static struct termp *ascii_init(enum termenc, char *); +static struct termp *ascii_init(enum termenc, + const struct mchars *, char *); static double ascii_hspan(const struct termp *, const struct roffsu *); static size_t ascii_width(const struct termp *, int); @@ -58,7 +49,7 @@ static void ascii_endline(struct termp *); static void ascii_letter(struct termp *, int); static void ascii_setwidth(struct termp *, int, size_t); -#ifdef USE_WCHAR +#if HAVE_WCHAR static void locale_advance(struct termp *, size_t); static void locale_endline(struct termp *); static void locale_letter(struct termp *, int); @@ -67,14 +58,15 @@ static size_t locale_width(const struct termp *, in static struct termp * -ascii_init(enum termenc enc, char *outopts) +ascii_init(enum termenc enc, const struct mchars *mchars, char *outopts) { - const char *toks[4]; + const char *toks[5]; char *v; struct termp *p; p = mandoc_calloc(1, sizeof(struct termp)); + p->symtab = mchars; p->tabwidth = 5; p->defrmargin = p->lastrmargin = 78; @@ -90,7 +82,7 @@ ascii_init(enum termenc enc, char *outopts) p->setwidth = ascii_setwidth; p->width = ascii_width; -#ifdef USE_WCHAR +#if HAVE_WCHAR if (TERMENC_ASCII != enc) { v = TERMENC_LOCALE == enc ? setlocale(LC_ALL, "") : @@ -108,7 +100,8 @@ ascii_init(enum termenc enc, char *outopts) toks[0] = "indent"; toks[1] = "width"; toks[2] = "mdoc"; - toks[3] = NULL; + toks[3] = "synopsis"; + toks[4] = NULL; while (outopts && *outopts) switch (getsubopt(&outopts, UNCONST(toks), &v)) { @@ -126,6 +119,9 @@ ascii_init(enum termenc enc, char *outopts) p->mdocstyle = 1; p->defindent = 5; break; + case 3: + p->synopsisonly = 1; + break; default: break; } @@ -138,24 +134,24 @@ ascii_init(enum termenc enc, char *outopts) } void * -ascii_alloc(char *outopts) +ascii_alloc(const struct mchars *mchars, char *outopts) { - return(ascii_init(TERMENC_ASCII, outopts)); + return(ascii_init(TERMENC_ASCII, mchars, outopts)); } void * -utf8_alloc(char *outopts) +utf8_alloc(const struct mchars *mchars, char *outopts) { - return(ascii_init(TERMENC_UTF8, outopts)); + return(ascii_init(TERMENC_UTF8, mchars, outopts)); } void * -locale_alloc(char *outopts) +locale_alloc(const struct mchars *mchars, char *outopts) { - return(ascii_init(TERMENC_LOCALE, outopts)); + return(ascii_init(TERMENC_LOCALE, mchars, outopts)); } static void @@ -264,7 +260,7 @@ ascii_hspan(const struct termp *p, const struct roffsu case SCALE_EM: r = su->scale; break; - case SCALE_MAX: + default: abort(); /* NOTREACHED */ } @@ -272,7 +268,83 @@ ascii_hspan(const struct termp *p, const struct roffsu return(r); } -#ifdef USE_WCHAR +const char * +ascii_uc2str(int uc) +{ + static const char nbrsp[2] = { ASCII_NBRSP, '\0' }; + static const char *tab[] = { + "","","","","","","","", + "", "\t", "", "", "", "", "", "", + "","","","","","","","", + "","", "","","", "", "", "", + " ", "!", "\"", "#", "$", "%", "&", "'", + "(", ")", "*", "+", ",", "-", ".", "/", + "0", "1", "2", "3", "4", "5", "6", "7", + "8", "9", ":", ";", "<", "=", ">", "?", + "@", "A", "B", "C", "D", "E", "F", "G", + "H", "I", "J", "K", "L", "M", "N", "O", + "P", "Q", "R", "S", "T", "U", "V", "W", + "X", "Y", "Z", "[", "\\", "]", "^", "_", + "`", "a", "b", "c", "d", "e", "f", "g", + "h", "i", "j", "k", "l", "m", "n", "o", + "p", "q", "r", "s", "t", "u", "v", "w", + "x", "y", "z", "{", "|", "}", "~", "", + "<80>", "<81>", "<82>", "<83>", "<84>", "<85>", "<86>", "<87>", + "<88>", "<89>", "<8A>", "<8B>", "<8C>", "<8D>", "<8E>", "<8F>", + "<90>", "<91>", "<92>", "<93>", "<94>", "<95>", "<96>", "<97>", + "<99>", "<99>", "<9A>", "<9B>", "<9C>", "<9D>", "<9E>", "<9F>", + nbrsp, "!", "/\bc", "GBP", "o\bx", "=\bY", "|", "", + "\"", "(C)", "_\ba", "<<", "~", "", "(R)", "-", + "","+-", "2", "3", "'", ",\bu", "",".", + ",", "1", "_\bo", ">>", "1/4", "1/2", "3/4", "?", + "`\bA", "'\bA", "^\bA", "~\bA", "\"\bA","o\bA", "AE", ",\bC", + "`\bE", "'\bE", "^\bE", "\"\bE","`\bI", "'\bI", "^\bI", "\"\bI", + "-\bD", "~\bN", "`\bO", "'\bO", "^\bO", "~\bO", "\"\bO","x", + "/\bO", "`\bU", "'\bU", "^\bU", "\"\bU","'\bY", "Th", "ss", + "`\ba", "'\ba", "^\ba", "~\ba", "\"\ba","o\ba", "ae", ",\bc", + "`\be", "'\be", "^\be", "\"\be","`\bi", "'\bi", "^\bi", "\"\bi", + "d", "~\bn", "`\bo", "'\bo", "^\bo", "~\bo", "\"\bo","-:-", + "/\bo", "`\bu", "'\bu", "^\bu", "\"\bu","'\by", "th", "\"\by", + "A", "a", "A", "a", "A", "a", "'\bC", "'\bc", + "^\bC", "^\bc", "C", "c", "C", "c", "D", "d", + "/\bD", "/\bd", "E", "e", "E", "e", "E", "e", + "E", "e", "E", "e", "^\bG", "^\bg", "G", "g", + "G", "g", ",\bG", ",\bg", "^\bH", "^\bh", "/\bH", "/\bh", + "~\bI", "~\bi", "I", "i", "I", "i", "I", "i", + "I", "i", "IJ", "ij", "^\bJ", "^\bj", ",\bK", ",\bk", + "q", "'\bL", "'\bl", ",\bL", ",\bl", "L", "l", "L", + "l", "/\bL", "/\bl", "'\bN", "'\bn", ",\bN", ",\bn", "N", + "n", "'n", "Ng", "ng", "O", "o", "O", "o", + "O", "o", "OE", "oe", "'\bR", "'\br", ",\bR", ",\br", + "R", "r", "'\bS", "'\bs", "^\bS", "^\bs", ",\bS", ",\bs", + "S", "s", ",\bT", ",\bt", "T", "t", "/\bT", "/\bt", + "~\bU", "~\bu", "U", "u", "U", "u", "U", "u", + "U", "u", "U", "u", "^\bW", "^\bw", "^\bY", "^\by", + "\"\bY","'\bZ", "'\bz", "Z", "z", "Z", "z", "s", + "b", "B", "B", "b", "6", "6", "O", "C", + "c", "D", "D", "D", "d", "d", "3", "@", + "E", "F", ",\bf", "G", "G", "hv", "I", "/\bI", + "K", "k", "/\bl", "l", "W", "N", "n", "~\bO", + "O", "o", "OI", "oi", "P", "p", "YR", "2", + "2", "SH", "sh", "t", "T", "t", "T", "U", + "u", "Y", "V", "Y", "y", "/\bZ", "/\bz", "ZH", + "ZH", "zh", "zh", "/\b2", "5", "5", "ts", "w", + "|", "||", "|=", "!", "DZ", "Dz", "dz", "LJ", + "Lj", "lj", "NJ", "Nj", "nj", "A", "a", "I", + "i", "O", "o", "U", "u", "U", "u", "U", + "u", "U", "u", "U", "u", "@", "A", "a", + "A", "a", "AE", "ae", "/\bG", "/\bg", "G", "g", + "K", "k", "O", "o", "O", "o", "ZH", "zh", + "j", "DZ", "Dz", "dz", "'\bG", "'\bg", "HV", "W", + "`\bN", "`\bn", "A", "a", "'\bAE","'\bae","O", "o"}; + + assert(uc >= 0); + if ((size_t)uc < sizeof(tab)/sizeof(tab[0])) + return(tab[uc]); + return(mchars_uc2str(uc)); +} + +#if HAVE_WCHAR static size_t locale_width(const struct termp *p, int c) {