]> git.cameronkatri.com Git - mandoc.git/commitdiff
Make the character table available to libroff so it can check the
authorIngo Schwarze <schwarze@openbsd.org>
Tue, 28 Oct 2014 17:36:19 +0000 (17:36 +0000)
committerIngo Schwarze <schwarze@openbsd.org>
Tue, 28 Oct 2014 17:36:19 +0000 (17:36 +0000)
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.

19 files changed:
cgi.c
chars.c
demandoc.c
html.c
html.h
libmandoc.h
main.c
main.h
man_term.c
mandoc.3
mandoc.h
mandocdb.c
mdoc_term.c
read.c
roff.c
term.c
term.h
term_ascii.c
term_ps.c

diff --git a/cgi.c b/cgi.c
index 4cb4fa9224fcecdec637c5400b46e0706b2f9e2c..f09aaf673c8a81ddbf3e80ff4c43aa668e55444a 100644 (file)
--- a/cgi.c
+++ b/cgi.c
@@ -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);
 }
 
diff --git a/chars.c b/chars.c
index 6d26208d7e574a6062026680308b676ee45053ef..237fbe2557f5111f5ea8462693cf47d04581295c 100644 (file)
--- a/chars.c
+++ b/chars.c
@@ -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
index dc1781dccb8ba66ed0584692a98a56ec590db371..e9aa62afb2ba9b68ca0d7772f27e893632278ad2 100644 (file)
@@ -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);
 }
 
diff --git a/html.c b/html.c
index 20b9b4430488256ac99068d746672f3448589049..912c006daef41f3446c6365e64fbed829f8adcfd 100644 (file)
--- a/html.c
+++ b/html.c
@@ -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);
 }
 
diff --git a/html.h b/html.h
index 9bfc6486fe52d8fa3f05f864a30ac585b7c18acf..521635f96fd9b290219d08e639f958809914afe6 100644 (file)
--- a/html.h
+++ b/html.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 */
index 83f977bd479ba3de8878e7189c5c7ffb47b4ce76..c01840b10dc887d312bd934e54358175520e5630 100644 (file)
@@ -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 *);
diff --git a/main.c b/main.c
index d6e15b76f3dbf86336dd15b9c11046fe2a429b25..79a2ddd6fd1dd534c9bbfe563c6fc1288299c844 100644 (file)
--- a/main.c
+++ b/main.c
@@ -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"))
diff --git a/main.h b/main.h
index beb0481cab83287d3d03dc35b07ebcec9f9289f9..c7768e3bb1687afd902b7be57a9900afae965f1e 100644 (file)
--- a/main.h
+++ b/main.h
@@ -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 *);
index ab2888586a3a48e52958750b44cca34f2676f777..790d313598c9cc3585b0e32179ad294d5290828c 100644 (file)
@@ -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);
 
index 2ee6eae181d3ebcb39409dcdece29be7e8f27c40..f03b030709930ea3c5a217f94730b9a15c95b0b0 100644 (file)
--- a/mandoc.3
+++ b/mandoc.3
@@ -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
index 527b3d8e4693a3989c0097a93aecac400ff0a5fc..329b59c09be7a36b9cb2a126657388e1c939299c 100644 (file)
--- a/mandoc.h
+++ b/mandoc.h
@@ -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 *,
index 0f3d7524fbfed5cfbc4f4d04d45d14bcf221bb6a..10e64e540dfaca0d76c1cf7197eac0d733943e22 100644 (file)
@@ -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);
index 58aac5108f261a564f88c072bcb0bc4e52c26082..c931501c4e12b1bc713bbe3db3bfd8f9ae5d8b83 100644 (file)
@@ -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);
 
diff --git a/read.c b/read.c
index 67e6a8389768ae3b692b00b1bbaef878536fab71..6c558817d3ee26a5099c11bb30b761bf001018b5 100644 (file)
--- a/read.c
+++ b/read.c
@@ -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,
diff --git a/roff.c b/roff.c
index 71ffe27e1a084ba822e7ffe0edd6af335a7925d5..1ea37b3aba86f6e57c1c4f2e1c4a08e2236b921a 100644 (file)
--- a/roff.c
+++ b/roff.c
@@ -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);
diff --git a/term.c b/term.c
index 911669060a415f6da78660ad944a622420a427dc..b1e50255dd2443e3ca60a1cb199ebf1804833ce8 100644 (file)
--- a/term.c
+++ b/term.c
@@ -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);
 }
 
diff --git a/term.h b/term.h
index ecb21689796d8052cfd2a44e1e46a3545013d907..e17c244596c07e8ddc7f4ee5a1461eef2353ace5 100644 (file)
--- a/term.h
+++ b/term.h
@@ -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. */
index 0f1c1e01bedffff949912654b3b4cc7da4f8bace..6ec27be012c5c17309605ada2dbd599a4db4204b 100644 (file)
@@ -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
index e27c81197ce1d44bb75d60dc97140703d1cb21b8..ec6d9b594493d959726bbbdfcb12fdf5bf30e179 100644 (file)
--- a/term_ps.c
+++ b/term_ps.c
@@ -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));