=================================================================== RCS file: /cvs/mandoc/term_ascii.c,v retrieving revision 1.38 retrieving revision 1.43 diff -u -p -r1.38 -r1.43 --- mandoc/term_ascii.c 2014/10/28 17:36:19 1.38 +++ mandoc/term_ascii.c 2015/02/16 14:11:41 1.43 @@ -1,4 +1,4 @@ -/* $Id: term_ascii.c,v 1.38 2014/10/28 17:36:19 schwarze Exp $ */ +/* $Id: term_ascii.c,v 1.43 2015/02/16 14:11:41 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * Copyright (c) 2014 Ingo Schwarze @@ -19,6 +19,7 @@ #include +#include #if HAVE_WCHAR #include #endif @@ -62,12 +63,17 @@ ascii_init(enum termenc enc, const struct mchars *mcha const char *toks[5]; char *v; struct termp *p; + const char *errstr; + int num; p = mandoc_calloc(1, sizeof(struct termp)); p->symtab = mchars; p->tabwidth = 5; p->defrmargin = p->lastrmargin = 78; + p->fontq = mandoc_reallocarray(NULL, + (p->fontsz = 8), sizeof(enum termfont)); + p->fontq[0] = p->fontl = TERMFONT_NONE; p->begin = ascii_begin; p->end = ascii_end; @@ -105,10 +111,14 @@ ascii_init(enum termenc enc, const struct mchars *mcha while (outopts && *outopts) switch (getsubopt(&outopts, UNCONST(toks), &v)) { case 0: - p->defindent = (size_t)atoi(v); + num = strtonum(v, 0, 1000, &errstr); + if (!errstr) + p->defindent = num; break; case 1: - p->defrmargin = (size_t)atoi(v); + num = strtonum(v, 0, 1000, &errstr); + if (!errstr) + p->defrmargin = num; break; case 2: /* @@ -158,16 +168,32 @@ ascii_setwidth(struct termp *p, int iop, size_t width) { p->rmargin = p->defrmargin; - if (0 < iop) + if (iop > 0) p->defrmargin += width; - else if (0 > iop) + else if (iop == 0) + p->defrmargin = width ? width : p->lastrmargin; + else if (p->defrmargin > width) p->defrmargin -= width; else - p->defrmargin = width ? width : p->lastrmargin; + p->defrmargin = 0; p->lastrmargin = p->rmargin; p->rmargin = p->maxrmargin = p->defrmargin; } +void +ascii_sepline(void *arg) +{ + struct termp *p; + size_t i; + + p = (struct termp *)arg; + putchar('\n'); + for (i = 0; i < p->defrmargin; i++) + putchar('-'); + putchar('\n'); + putchar('\n'); +} + static size_t ascii_width(const struct termp *p, int c) { @@ -337,8 +363,7 @@ ascii_uc2str(int uc) "j", "DZ", "Dz", "dz", "'\bG", "'\bg", "HV", "W", "`\bN", "`\bn", "A", "a", "'\bAE","'\bae","O", "o"}; - if (uc < 0) - return(""); + assert(uc >= 0); if ((size_t)uc < sizeof(tab)/sizeof(tab[0])) return(tab[uc]); return(mchars_uc2str(uc));