diff options
author | 2014-10-28 17:36:19 +0000 | |
---|---|---|
committer | 2014-10-28 17:36:19 +0000 | |
commit | d0ac87d04f62f2c8e644686b707cb2602c2ddba6 (patch) | |
tree | 69a250d8b0b0b75bc58e1c8af72b3c3269561aed | |
parent | 5fa1bace54f386a9b3ce23690f136232e1e5bb2e (diff) | |
download | mandoc-d0ac87d04f62f2c8e644686b707cb2602c2ddba6.tar.gz mandoc-d0ac87d04f62f2c8e644686b707cb2602c2ddba6.tar.zst mandoc-d0ac87d04f62f2c8e644686b707cb2602c2ddba6.zip |
Make the character table available to libroff so it can check the
validity of character escape names and warn about unknown ones.
This requires mchars_spec2cp() to report unknown names again.
Fortunately, that doesn't require changing the calling code because
according to groff, invalid character escapes should not produce
output anyway, and now that we warn about them, that's fine.
-rw-r--r-- | cgi.c | 10 | ||||
-rw-r--r-- | chars.c | 4 | ||||
-rw-r--r-- | demandoc.c | 7 | ||||
-rw-r--r-- | html.c | 26 | ||||
-rw-r--r-- | html.h | 4 | ||||
-rw-r--r-- | libmandoc.h | 4 | ||||
-rw-r--r-- | main.c | 38 | ||||
-rw-r--r-- | main.h | 15 | ||||
-rw-r--r-- | man_term.c | 5 | ||||
-rw-r--r-- | mandoc.3 | 20 | ||||
-rw-r--r-- | mandoc.h | 4 | ||||
-rw-r--r-- | mandocdb.c | 8 | ||||
-rw-r--r-- | mdoc_term.c | 5 | ||||
-rw-r--r-- | read.c | 10 | ||||
-rw-r--r-- | roff.c | 13 | ||||
-rw-r--r-- | term.c | 8 | ||||
-rw-r--r-- | term.h | 4 | ||||
-rw-r--r-- | term_ascii.c | 20 | ||||
-rw-r--r-- | term_ps.c | 15 |
19 files changed, 113 insertions, 107 deletions
@@ -1,4 +1,4 @@ -/* $Id: cgi.c,v 1.99 2014/10/07 18:20:06 schwarze Exp $ */ +/* $Id: cgi.c,v 1.100 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014 Ingo Schwarze <schwarze@usta.de> @@ -824,6 +824,7 @@ static void format(const struct req *req, const char *file) { struct mparse *mp; + struct mchars *mchars; struct mdoc *mdoc; struct man *man; void *vp; @@ -837,8 +838,9 @@ format(const struct req *req, const char *file) return; } + mchars = mchars_alloc(); mp = mparse_alloc(MPARSE_SO, MANDOCLEVEL_FATAL, NULL, - req->q.manpath); + mchars, req->q.manpath); rc = mparse_readfd(mp, fd, file); close(fd); @@ -864,10 +866,11 @@ format(const struct req *req, const char *file) req->q.manpath, file); pg_error_internal(); mparse_free(mp); + mchars_free(mchars); return; } - vp = html_alloc(opts); + vp = html_alloc(mchars, opts); if (NULL != mdoc) html_mdoc(vp, mdoc); @@ -876,6 +879,7 @@ format(const struct req *req, const char *file) html_free(vp); mparse_free(mp); + mchars_free(mchars); free(opts); } @@ -1,4 +1,4 @@ -/* $Id: chars.c,v 1.63 2014/10/28 13:24:44 schwarze Exp $ */ +/* $Id: chars.c,v 1.64 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -104,7 +104,7 @@ mchars_spec2cp(const struct mchars *arg, const char *p, size_t sz) const struct ln *ln; ln = find(arg, p, sz); - return(ln != NULL ? ln->unicode : sz == 1 ? *p : 0xFFFD); + return(ln != NULL ? ln->unicode : sz == 1 ? (unsigned char)*p : -1); } char @@ -1,4 +1,4 @@ -/* $Id: demandoc.c,v 1.11 2014/08/10 23:54:41 schwarze Exp $ */ +/* $Id: demandoc.c,v 1.12 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -43,6 +43,7 @@ int main(int argc, char *argv[]) { struct mparse *mp; + struct mchars *mchars; int ch, i, list; extern int optind; @@ -76,7 +77,8 @@ main(int argc, char *argv[]) argc -= optind; argv += optind; - mp = mparse_alloc(MPARSE_SO, MANDOCLEVEL_FATAL, NULL, NULL); + mchars = mchars_alloc(); + mp = mparse_alloc(MPARSE_SO, MANDOCLEVEL_FATAL, NULL, mchars, NULL); assert(mp); if (0 == argc) @@ -88,6 +90,7 @@ main(int argc, char *argv[]) } mparse_free(mp); + mchars_free(mchars); return((int)MANDOCLEVEL_OK); } @@ -1,4 +1,4 @@ -/* $Id: html.c,v 1.179 2014/10/27 16:29:06 schwarze Exp $ */ +/* $Id: html.c,v 1.180 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -127,11 +127,10 @@ static int print_escape(char); static int print_encode(struct html *, const char *, int); static void print_metaf(struct html *, enum mandoc_esc); static void print_attr(struct html *, const char *, const char *); -static void *ml_alloc(char *); -static void * -ml_alloc(char *outopts) +void * +html_alloc(const struct mchars *mchars, char *outopts) { struct html *h; const char *toks[5]; @@ -146,7 +145,7 @@ ml_alloc(char *outopts) h = mandoc_calloc(1, sizeof(struct html)); h->tags.head = NULL; - h->symtab = mchars_alloc(); + h->symtab = mchars; while (outopts && *outopts) switch (getsubopt(&outopts, UNCONST(toks), &v)) { @@ -169,20 +168,6 @@ ml_alloc(char *outopts) return(h); } -void * -html_alloc(char *outopts) -{ - - return(ml_alloc(outopts)); -} - -void * -xhtml_alloc(char *outopts) -{ - - return(ml_alloc(outopts)); -} - void html_free(void *p) { @@ -196,9 +181,6 @@ html_free(void *p) free(tag); } - if (h->symtab) - mchars_free(h->symtab); - free(h); } @@ -1,4 +1,4 @@ -/* $Id: html.h,v 1.66 2014/10/10 15:26:29 schwarze Exp $ */ +/* $Id: html.h,v 1.67 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -133,7 +133,7 @@ struct html { struct tagq tags; /* stack of open tags */ struct rofftbl tbl; /* current table */ struct tag *tblt; /* current open table scope */ - struct mchars *symtab; /* character-escapes */ + const struct mchars *symtab; /* character table */ char *base_man; /* base for manpage href */ char *base_includes; /* base for include href */ char *style; /* style-sheet URI */ diff --git a/libmandoc.h b/libmandoc.h index 83f977bd..c01840b1 100644 --- a/libmandoc.h +++ b/libmandoc.h @@ -1,4 +1,4 @@ -/* $Id: libmandoc.h,v 1.45 2014/10/25 01:03:52 schwarze Exp $ */ +/* $Id: libmandoc.h,v 1.46 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -76,7 +76,7 @@ int preconv_cue(const struct buf *); int preconv_encode(struct buf *, struct buf *, int *); void roff_free(struct roff *); -struct roff *roff_alloc(struct mparse *, int); +struct roff *roff_alloc(struct mparse *, const struct mchars *, int); void roff_reset(struct roff *); enum rofferr roff_parseln(struct roff *, int, char **, size_t *, int, int *); @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.194 2014/10/25 01:03:52 schwarze Exp $ */ +/* $Id: main.c,v 1.195 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2011, 2012, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -64,7 +64,6 @@ enum outt { OUTT_TREE, /* -Ttree */ OUTT_MAN, /* -Tman */ OUTT_HTML, /* -Thtml */ - OUTT_XHTML, /* -Txhtml */ OUTT_LINT, /* -Tlint */ OUTT_PS, /* -Tps */ OUTT_PDF /* -Tpdf */ @@ -72,6 +71,7 @@ enum outt { struct curparse { struct mparse *mp; + struct mchars *mchars; /* character table */ enum mandoclevel wlevel; /* ignore messages below this */ int wstop; /* stop after a file with a warning */ enum outt outtype; /* which output to use */ @@ -364,7 +364,9 @@ main(int argc, char *argv[]) if (use_pager && isatty(STDOUT_FILENO)) spawn_pager(); - curp.mp = mparse_alloc(options, curp.wlevel, mmsg, defos); + curp.mchars = mchars_alloc(); + curp.mp = mparse_alloc(options, curp.wlevel, mmsg, + curp.mchars, defos); /* * Conditionally start up the lookaside buffer before parsing. @@ -409,8 +411,8 @@ main(int argc, char *argv[]) if (curp.outfree) (*curp.outfree)(curp.outdata); - if (curp.mp) - mparse_free(curp.mp); + mparse_free(curp.mp); + mchars_free(curp.mchars); #if HAVE_SQLITE3 out: @@ -495,32 +497,34 @@ parse(struct curparse *curp, int fd, const char *file, if ( ! (curp->outman && curp->outmdoc)) { switch (curp->outtype) { - case OUTT_XHTML: - curp->outdata = xhtml_alloc(curp->outopts); - curp->outfree = html_free; - break; case OUTT_HTML: - curp->outdata = html_alloc(curp->outopts); + curp->outdata = html_alloc(curp->mchars, + curp->outopts); curp->outfree = html_free; break; case OUTT_UTF8: - curp->outdata = utf8_alloc(curp->outopts); + curp->outdata = utf8_alloc(curp->mchars, + curp->outopts); curp->outfree = ascii_free; break; case OUTT_LOCALE: - curp->outdata = locale_alloc(curp->outopts); + curp->outdata = locale_alloc(curp->mchars, + curp->outopts); curp->outfree = ascii_free; break; case OUTT_ASCII: - curp->outdata = ascii_alloc(curp->outopts); + curp->outdata = ascii_alloc(curp->mchars, + curp->outopts); curp->outfree = ascii_free; break; case OUTT_PDF: - curp->outdata = pdf_alloc(curp->outopts); + curp->outdata = pdf_alloc(curp->mchars, + curp->outopts); curp->outfree = pspdf_free; break; case OUTT_PS: - curp->outdata = ps_alloc(curp->outopts); + curp->outdata = ps_alloc(curp->mchars, + curp->outopts); curp->outfree = pspdf_free; break; default: @@ -529,8 +533,6 @@ parse(struct curparse *curp, int fd, const char *file, switch (curp->outtype) { case OUTT_HTML: - /* FALLTHROUGH */ - case OUTT_XHTML: curp->outman = html_man; curp->outmdoc = html_mdoc; break; @@ -665,7 +667,7 @@ toptions(struct curparse *curp, char *arg) else if (0 == strcmp(arg, "locale")) curp->outtype = OUTT_LOCALE; else if (0 == strcmp(arg, "xhtml")) - curp->outtype = OUTT_XHTML; + curp->outtype = OUTT_HTML; else if (0 == strcmp(arg, "ps")) curp->outtype = OUTT_PS; else if (0 == strcmp(arg, "pdf")) @@ -1,4 +1,4 @@ -/* $Id: main.h,v 1.16 2014/04/20 16:46:04 schwarze Exp $ */ +/* $Id: main.h,v 1.17 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -32,8 +32,7 @@ struct man; * terminal output routines with different character settings. */ -void *html_alloc(char *); -void *xhtml_alloc(char *); +void *html_alloc(const struct mchars *, char *); void html_mdoc(void *, const struct mdoc *); void html_man(void *, const struct man *); void html_free(void *); @@ -44,13 +43,13 @@ void tree_man(void *, const struct man *); void man_mdoc(void *, const struct mdoc *); void man_man(void *, const struct man *); -void *locale_alloc(char *); -void *utf8_alloc(char *); -void *ascii_alloc(char *); +void *locale_alloc(const struct mchars *, char *); +void *utf8_alloc(const struct mchars *, char *); +void *ascii_alloc(const struct mchars *, char *); void ascii_free(void *); -void *pdf_alloc(char *); -void *ps_alloc(char *); +void *pdf_alloc(const struct mchars *, char *); +void *ps_alloc(const struct mchars *, char *); void pspdf_free(void *); void terminal_mdoc(void *, const struct mdoc *); @@ -1,4 +1,4 @@ -/* $Id: man_term.c,v 1.154 2014/10/20 15:50:24 schwarze Exp $ */ +/* $Id: man_term.c,v 1.155 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -151,9 +151,6 @@ terminal_man(void *arg, const struct man *man) p->rmargin = p->maxrmargin = p->defrmargin; p->tabwidth = term_len(p, 5); - if (NULL == p->symtab) - p->symtab = mchars_alloc(); - n = man_node(man)->child; meta = man_meta(man); @@ -1,4 +1,4 @@ -.\" $Id: mandoc.3,v 1.26 2014/09/03 23:21:47 schwarze Exp $ +.\" $Id: mandoc.3,v 1.27 2014/10/28 17:36:19 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> .\" Copyright (c) 2010 Ingo Schwarze <schwarze@openbsd.org> @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: September 3 2014 $ +.Dd $Mdocdate: October 28 2014 $ .Dt MANDOC 3 .Os .Sh NAME @@ -52,6 +52,7 @@ .Fa "int options" .Fa "enum mandoclevel wlevel" .Fa "mandocmsg mmsg" +.Fa "const struct mchars *mchars" .Fa "char *defos" .Fc .Ft void @@ -173,6 +174,8 @@ The following describes a general parse sequence: .Bl -enum .It initiate a parsing sequence with +.Xr mchars_alloc 3 +and .Fn mparse_alloc ; .It parse files or file descriptors with @@ -187,7 +190,9 @@ or .Fn man_node ; .It free all allocated memory with -.Fn mparse_free , +.Fn mparse_free +and +.Xr mchars_free 3 , or invoke .Fn mparse_reset and parse new files. @@ -208,6 +213,12 @@ A fatal error, error, or warning message during parsing. A classification of an .Vt "enum mandocerr" as regards system operation. +.It Vt "struct mchars" +An opaque pointer to a a character table. +Created with +.Xr mchars_alloc 3 +and freed with +.Xr mchars_free 3 . .It Vt "struct mparse" An opaque pointer to a running parse sequence. Created with @@ -332,6 +343,9 @@ A callback function to handle errors and warnings. See .Pa main.c for an example. +.It Ar mchars +An opaque pointer to a a character table obtained from +.Xr mchars_alloc 3 . .It Ar defos A default string for the .Xr mdoc 7 @@ -1,4 +1,4 @@ -/* $Id: mandoc.h,v 1.166 2014/10/26 18:07:28 schwarze Exp $ */ +/* $Id: mandoc.h,v 1.167 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -433,7 +433,7 @@ int mchars_spec2cp(const struct mchars *, const char *mchars_spec2str(const struct mchars *, const char *, size_t, size_t *); struct mparse *mparse_alloc(int, enum mandoclevel, mandocmsg, - const char *); + const struct mchars *, const char *); void mparse_free(struct mparse *); void mparse_keep(struct mparse *); enum mandoclevel mparse_open(struct mparse *, int *, const char *, @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.167 2014/10/27 13:31:04 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.168 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -425,9 +425,9 @@ main(int argc, char *argv[]) } exitcode = (int)MANDOCLEVEL_OK; - mp = mparse_alloc(mparse_options, MANDOCLEVEL_FATAL, NULL, NULL); mc = mchars_alloc(); - + mp = mparse_alloc(mparse_options, MANDOCLEVEL_FATAL, NULL, + mc, NULL); ohash_init(&mpages, 6, &mpages_info); ohash_init(&mlinks, 6, &mlinks_info); @@ -525,8 +525,8 @@ main(int argc, char *argv[]) } out: manpath_free(&dirs); - mchars_free(mc); mparse_free(mp); + mchars_free(mc); mpages_free(); ohash_delete(&mpages); ohash_delete(&mlinks); diff --git a/mdoc_term.c b/mdoc_term.c index 58aac510..c931501c 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.286 2014/10/20 15:50:24 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.287 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -261,9 +261,6 @@ terminal_mdoc(void *arg, const struct mdoc *mdoc) p->rmargin = p->maxrmargin = p->defrmargin; p->tabwidth = term_len(p, 5); - if (NULL == p->symtab) - p->symtab = mchars_alloc(); - n = mdoc_node(mdoc)->child; meta = mdoc_meta(mdoc); @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.93 2014/10/25 01:03:52 schwarze Exp $ */ +/* $Id: read.c,v 1.94 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -51,6 +51,7 @@ struct mparse { struct man *man; /* man parser */ struct mdoc *mdoc; /* mdoc parser */ struct roff *roff; /* roff parser (!NULL) */ + const struct mchars *mchars; /* character table */ char *sodest; /* filename pointed to by .so */ const char *file; /* filename of current input file */ struct buf *primary; /* buffer currently being parsed */ @@ -914,8 +915,8 @@ mparse_wait(struct mparse *curp, pid_t child_pid) } struct mparse * -mparse_alloc(int options, enum mandoclevel wlevel, - mandocmsg mmsg, const char *defos) +mparse_alloc(int options, enum mandoclevel wlevel, mandocmsg mmsg, + const struct mchars *mchars, const char *defos) { struct mparse *curp; @@ -928,7 +929,8 @@ mparse_alloc(int options, enum mandoclevel wlevel, curp->mmsg = mmsg; curp->defos = defos; - curp->roff = roff_alloc(curp, options); + curp->mchars = mchars; + curp->roff = roff_alloc(curp, curp->mchars, options); if (curp->options & MPARSE_MDOC) curp->pmdoc = mdoc_alloc( curp->roff, curp, curp->defos, @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.236 2014/10/25 15:23:56 schwarze Exp $ */ +/* $Id: roff.c,v 1.237 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -107,6 +107,7 @@ struct roffreg { struct roff { struct mparse *parse; /* parse point */ + const struct mchars *mchars; /* character table */ struct roffnode *last; /* leaf of stack */ int *rstack; /* stack of inverted `ie' values */ struct roffreg *regtab; /* number registers */ @@ -476,12 +477,13 @@ roff_free(struct roff *r) } struct roff * -roff_alloc(struct mparse *parse, int options) +roff_alloc(struct mparse *parse, const struct mchars *mchars, int options) { struct roff *r; r = mandoc_calloc(1, sizeof(struct roff)); r->parse = parse; + r->mchars = mchars; r->options = options; r->format = options & (MPARSE_MDOC | MPARSE_MAN); r->rstackpos = -1; @@ -508,6 +510,8 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos) char *nbuf; /* new buffer to copy bufp to */ size_t maxl; /* expected length of the escape name */ size_t naml; /* actual length of the escape name */ + enum mandoc_esc esc; /* type of the escape sequence */ + int inaml; /* length returned from mandoc_escape() */ int expand_count; /* to avoid infinite loops */ int npos; /* position in numeric expression */ int arg_complete; /* argument not interrupted by eol */ @@ -551,7 +555,10 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos) res = ubuf; break; default: - if (ESCAPE_ERROR == mandoc_escape(&cp, NULL, NULL)) + esc = mandoc_escape(&cp, &stnam, &inaml); + if (esc == ESCAPE_ERROR || + (esc == ESCAPE_SPECIAL && + mchars_spec2cp(r->mchars, stnam, inaml) < 0)) mandoc_vmsg(MANDOCERR_ESC_BAD, r->parse, ln, (int)(stesc - *bufp), "%.*s", (int)(cp - stesc), stesc); @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.230 2014/10/27 13:31:04 schwarze Exp $ */ +/* $Id: term.c,v 1.231 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -42,11 +42,7 @@ void term_free(struct termp *p) { - if (p->buf) - free(p->buf); - if (p->symtab) - mchars_free(p->symtab); - + free(p->buf); free(p); } @@ -1,4 +1,4 @@ -/* $Id: term.h,v 1.104 2014/10/26 17:12:03 schwarze Exp $ */ +/* $Id: term.h,v 1.105 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -85,7 +85,7 @@ struct termp { #define TERMP_SPLIT (1 << 13) /* Break line before .An. */ int *buf; /* Output buffer. */ enum termenc enc; /* Type of encoding. */ - struct mchars *symtab; /* Encoded-symbol table. */ + const struct mchars *symtab; /* Character table. */ enum termfont fontl; /* Last font set. */ enum termfont fontq[10]; /* Symmetric fonts. */ int fonti; /* Index of font stack. */ diff --git a/term_ascii.c b/term_ascii.c index 0f1c1e01..6ec27be0 100644 --- a/term_ascii.c +++ b/term_ascii.c @@ -1,4 +1,4 @@ -/* $Id: term_ascii.c,v 1.37 2014/10/28 02:43:59 schwarze Exp $ */ +/* $Id: term_ascii.c,v 1.38 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -36,7 +36,8 @@ #include "term.h" #include "main.h" -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); @@ -56,7 +57,7 @@ static size_t locale_width(const struct termp *, int); static struct termp * -ascii_init(enum termenc enc, char *outopts) +ascii_init(enum termenc enc, const struct mchars *mchars, char *outopts) { const char *toks[5]; char *v; @@ -64,6 +65,7 @@ ascii_init(enum termenc enc, char *outopts) p = mandoc_calloc(1, sizeof(struct termp)); + p->symtab = mchars; p->tabwidth = 5; p->defrmargin = p->lastrmargin = 78; @@ -131,24 +133,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 @@ -1,4 +1,4 @@ -/* $Id: term_ps.c,v 1.67 2014/10/27 20:41:58 schwarze Exp $ */ +/* $Id: term_ps.c,v 1.68 2014/10/28 17:36:19 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org> @@ -106,7 +106,7 @@ static void ps_printf(struct termp *, const char *, ...); static void ps_putchar(struct termp *, char); static void ps_setfont(struct termp *, enum termfont); static void ps_setwidth(struct termp *, int, size_t); -static struct termp *pspdf_alloc(char *); +static struct termp *pspdf_alloc(const struct mchars *, char *); static void pdf_obj(struct termp *, size_t); /* @@ -507,29 +507,29 @@ static const struct font fonts[TERMFONT__MAX] = { }; void * -pdf_alloc(char *outopts) +pdf_alloc(const struct mchars *mchars, char *outopts) { struct termp *p; - if (NULL != (p = pspdf_alloc(outopts))) + if (NULL != (p = pspdf_alloc(mchars, outopts))) p->type = TERMTYPE_PDF; return(p); } void * -ps_alloc(char *outopts) +ps_alloc(const struct mchars *mchars, char *outopts) { struct termp *p; - if (NULL != (p = pspdf_alloc(outopts))) + if (NULL != (p = pspdf_alloc(mchars, outopts))) p->type = TERMTYPE_PS; return(p); } static struct termp * -pspdf_alloc(char *outopts) +pspdf_alloc(const struct mchars *mchars, char *outopts) { struct termp *p; unsigned int pagex, pagey; @@ -539,6 +539,7 @@ pspdf_alloc(char *outopts) char *v; p = mandoc_calloc(1, sizeof(struct termp)); + p->symtab = mchars; p->enc = TERMENC_ASCII; p->ps = mandoc_calloc(1, sizeof(struct termp_ps)); |