diff options
-rw-r--r-- | cgi.c | 8 | ||||
-rw-r--r-- | chars.c | 2 | ||||
-rw-r--r-- | demandoc.c | 5 | ||||
-rw-r--r-- | html.c | 24 | ||||
-rw-r--r-- | html.h | 2 | ||||
-rw-r--r-- | libmandoc.h | 2 | ||||
-rw-r--r-- | main.c | 36 | ||||
-rw-r--r-- | main.h | 13 | ||||
-rw-r--r-- | man_term.c | 3 | ||||
-rw-r--r-- | mandoc.3 | 16 | ||||
-rw-r--r-- | mandoc.h | 2 | ||||
-rw-r--r-- | mandocdb.c | 6 | ||||
-rw-r--r-- | mdoc_term.c | 3 | ||||
-rw-r--r-- | read.c | 8 | ||||
-rw-r--r-- | roff.c | 11 | ||||
-rw-r--r-- | term.c | 6 | ||||
-rw-r--r-- | term.h | 2 | ||||
-rw-r--r-- | term_ascii.c | 18 | ||||
-rw-r--r-- | term_ps.c | 13 |
19 files changed, 93 insertions, 87 deletions
@@ -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); } @@ -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 @@ -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); } @@ -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); } @@ -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 027009db..d518b35a 100644 --- a/libmandoc.h +++ b/libmandoc.h @@ -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 *); @@ -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")) @@ -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 *); @@ -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); @@ -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 @@ -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 *, @@ -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 5f94ba8e..95643e27 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -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); @@ -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, @@ -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); @@ -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); } @@ -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 737382b7..079df118 100644 --- a/term_ascii.c +++ b/term_ascii.c @@ -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 @@ -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)); |