From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]); by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id eef9c3f2; for ; Fri, 27 Mar 2015 16:33:51 -0500 (EST) Date: Fri, 27 Mar 2015 16:33:51 -0500 (EST) Message-Id: <6019153042719109375.enqueue@fantadrom.bsd.lv> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Actually use the new man.conf(5) "output" directive. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Actually use the new man.conf(5) "output" directive. Additional functionality, yet minus 45 lines of code. Modified Files: -------------- mdocml: cgi.c html.c main.c main.h man.conf.5 term_ascii.c term_ps.c Revision Data ------------- Index: cgi.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/cgi.c,v retrieving revision 1.105 retrieving revision 1.106 diff -Lcgi.c -Lcgi.c -u -p -r1.105 -r1.106 --- cgi.c +++ cgi.c @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons - * Copyright (c) 2014 Ingo Schwarze + * Copyright (c) 2014, 2015 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -816,12 +816,12 @@ catman(const struct req *req, const char static void format(const struct req *req, const char *file) { + struct manoutput conf; struct mparse *mp; struct mchars *mchars; struct mdoc *mdoc; struct man *man; void *vp; - char *opts; int fd; int usepath; @@ -836,9 +836,10 @@ format(const struct req *req, const char mparse_readfd(mp, fd, file); close(fd); + memset(&conf, 0, sizeof(conf)); + conf.fragment = 1; usepath = strcmp(req->q.manpath, req->p[0]); - mandoc_asprintf(&opts, - "fragment,man=%s?query=%%N&sec=%%S%s%s%s%s", + mandoc_asprintf(&conf.man, "%s?query=%%N&sec=%%S%s%s%s%s", scriptname, req->q.arch ? "&arch=" : "", req->q.arch ? req->q.arch : "", @@ -855,7 +856,7 @@ format(const struct req *req, const char return; } - vp = html_alloc(mchars, opts); + vp = html_alloc(mchars, &conf); if (NULL != mdoc) html_mdoc(vp, mdoc); @@ -865,7 +866,7 @@ format(const struct req *req, const char html_free(vp); mparse_free(mp); mchars_free(mchars); - free(opts); + free(conf.man); } static void Index: term_ascii.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/term_ascii.c,v retrieving revision 1.43 retrieving revision 1.44 diff -Lterm_ascii.c -Lterm_ascii.c -u -p -r1.43 -r1.44 --- term_ascii.c +++ term_ascii.c @@ -1,15 +1,15 @@ /* $Id$ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2014 Ingo Schwarze + * Copyright (c) 2014, 2015 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF @@ -35,10 +35,11 @@ #include "mandoc_aux.h" #include "out.h" #include "term.h" +#include "manconf.h" #include "main.h" -static struct termp *ascii_init(enum termenc, - const struct mchars *, char *); +static struct termp *ascii_init(enum termenc, const struct mchars *, + const struct manoutput *); static double ascii_hspan(const struct termp *, const struct roffsu *); static size_t ascii_width(const struct termp *, int); @@ -58,13 +59,11 @@ static size_t locale_width(const stru static struct termp * -ascii_init(enum termenc enc, const struct mchars *mchars, char *outopts) +ascii_init(enum termenc enc, const struct mchars *mchars, + const struct manoutput *outopts) { - const char *toks[5]; char *v; struct termp *p; - const char *errstr; - int num; p = mandoc_calloc(1, sizeof(struct termp)); @@ -102,62 +101,36 @@ ascii_init(enum termenc enc, const struc } #endif - toks[0] = "indent"; - toks[1] = "width"; - toks[2] = "mdoc"; - toks[3] = "synopsis"; - toks[4] = NULL; - - while (outopts && *outopts) - switch (getsubopt(&outopts, UNCONST(toks), &v)) { - case 0: - num = strtonum(v, 0, 1000, &errstr); - if (!errstr) - p->defindent = num; - break; - case 1: - num = strtonum(v, 0, 1000, &errstr); - if (!errstr) - p->defrmargin = num; - break; - case 2: - /* - * Temporary, undocumented mode - * to imitate mdoc(7) output style. - */ - p->mdocstyle = 1; - p->defindent = 5; - break; - case 3: - p->synopsisonly = 1; - break; - default: - break; - } - - /* Enforce a lower boundary. */ - if (p->defrmargin < 58) - p->defrmargin = 58; + if (outopts->mdoc) { + p->mdocstyle = 1; + p->defindent = 5; + } + if (outopts->indent) + p->defindent = outopts->indent; + if (outopts->width) + p->defrmargin = outopts->width; + if (outopts->synopsisonly) + p->synopsisonly = 1; return(p); } void * -ascii_alloc(const struct mchars *mchars, char *outopts) +ascii_alloc(const struct mchars *mchars, const struct manoutput *outopts) { return(ascii_init(TERMENC_ASCII, mchars, outopts)); } void * -utf8_alloc(const struct mchars *mchars, char *outopts) +utf8_alloc(const struct mchars *mchars, const struct manoutput *outopts) { return(ascii_init(TERMENC_UTF8, mchars, outopts)); } void * -locale_alloc(const struct mchars *mchars, char *outopts) +locale_alloc(const struct mchars *mchars, const struct manoutput *outopts) { return(ascii_init(TERMENC_LOCALE, mchars, outopts)); Index: main.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/main.c,v retrieving revision 1.229 retrieving revision 1.230 diff -Lmain.c -Lmain.c -u -p -r1.229 -r1.230 --- main.c +++ main.c @@ -83,7 +83,7 @@ struct curparse { out_man outman; /* man output ptr */ out_free outfree; /* free output ptr */ void *outdata; /* data for output */ - char outopts[BUFSIZ]; /* buf of output opts */ + struct manoutput *outopts; /* output options */ }; static int fs_lookup(const struct manpaths *, @@ -127,7 +127,7 @@ main(int argc, char *argv[]) struct manpage *res, *resp; char *conf_file, *defpaths; size_t isec, i, sz; - int prio, best_prio, synopsis_only; + int prio, best_prio; char sec; enum mandoclevel rctmp; enum outmode outmode; @@ -174,12 +174,12 @@ main(int argc, char *argv[]) memset(&curp, 0, sizeof(struct curparse)); curp.outtype = OUTT_LOCALE; curp.wlevel = MANDOCLEVEL_BADARG; + curp.outopts = &conf.output; options = MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1; defos = NULL; pager_pid = 1; show_usage = 0; - synopsis_only = 0; outmode = OUTMODE_DEF; while (-1 != (c = getopt(argc, argv, @@ -198,8 +198,7 @@ main(int argc, char *argv[]) search.argmode = ARG_WORD; break; case 'h': - (void)strlcat(curp.outopts, "synopsis,", BUFSIZ); - synopsis_only = 1; + conf.output.synopsisonly = 1; pager_pid = 0; outmode = OUTMODE_ALL; break; @@ -240,8 +239,9 @@ main(int argc, char *argv[]) break; case 'O': search.outkey = optarg; - (void)strlcat(curp.outopts, optarg, BUFSIZ); - (void)strlcat(curp.outopts, ",", BUFSIZ); + while (optarg != NULL) + manconf_output(&conf.output, + strsep(&optarg, ",")); break; case 'S': search.arch = optarg; @@ -444,7 +444,8 @@ main(int argc, char *argv[]) chdir(conf.manpath.paths[resp->ipath]); parse(&curp, fd, resp->file); } else - passthrough(resp->file, fd, synopsis_only); + passthrough(resp->file, fd, + conf.output.synopsisonly); rctmp = mparse_wait(curp.mp); if (rc < rctmp) Index: html.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/html.c,v retrieving revision 1.185 retrieving revision 1.186 diff -Lhtml.c -Lhtml.c -u -p -r1.185 -r1.186 --- html.c +++ html.c @@ -7,9 +7,9 @@ * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF @@ -32,6 +32,7 @@ #include "mandoc_aux.h" #include "out.h" #include "html.h" +#include "manconf.h" #include "main.h" struct htmldata { @@ -129,40 +130,20 @@ static void print_attr(struct html *, c void * -html_alloc(const struct mchars *mchars, char *outopts) +html_alloc(const struct mchars *mchars, const struct manoutput *outopts) { struct html *h; - const char *toks[5]; - char *v; - - toks[0] = "style"; - toks[1] = "man"; - toks[2] = "includes"; - toks[3] = "fragment"; - toks[4] = NULL; h = mandoc_calloc(1, sizeof(struct html)); h->tags.head = NULL; h->symtab = mchars; - while (outopts && *outopts) - switch (getsubopt(&outopts, UNCONST(toks), &v)) { - case 0: - h->style = v; - break; - case 1: - h->base_man = v; - break; - case 2: - h->base_includes = v; - break; - case 3: - h->oflags |= HTML_FRAGMENT; - break; - default: - break; - } + h->style = outopts->style; + h->base_man = outopts->man; + h->base_includes = outopts->includes; + if (outopts->fragment) + h->oflags |= HTML_FRAGMENT; return(h); } Index: main.h =================================================================== RCS file: /home/cvs/mdocml/mdocml/main.h,v retrieving revision 1.20 retrieving revision 1.21 diff -Lmain.h -Lmain.h -u -p -r1.20 -r1.21 --- main.h +++ main.h @@ -1,15 +1,15 @@ /* $Id$ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2014 Ingo Schwarze + * Copyright (c) 2014, 2015 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF @@ -23,6 +23,7 @@ __BEGIN_DECLS struct mchars; struct mdoc; struct man; +struct manoutput; /* * Definitions for main.c-visible output device functions, e.g., -Thtml @@ -31,7 +32,8 @@ struct man; * terminal output routines with different character settings. */ -void *html_alloc(const struct mchars *, char *); +void *html_alloc(const struct mchars *, + const struct manoutput *); void html_mdoc(void *, const struct mdoc *); void html_man(void *, const struct man *); void html_free(void *); @@ -42,14 +44,19 @@ void tree_man(void *, const struct ma void man_mdoc(void *, const struct mdoc *); void man_man(void *, const struct man *); -void *locale_alloc(const struct mchars *, char *); -void *utf8_alloc(const struct mchars *, char *); -void *ascii_alloc(const struct mchars *, char *); +void *locale_alloc(const struct mchars *, + const struct manoutput *); +void *utf8_alloc(const struct mchars *, + const struct manoutput *); +void *ascii_alloc(const struct mchars *, + const struct manoutput *); void ascii_free(void *); void ascii_sepline(void *); -void *pdf_alloc(const struct mchars *, char *); -void *ps_alloc(const struct mchars *, char *); +void *pdf_alloc(const struct mchars *, + const struct manoutput *); +void *ps_alloc(const struct mchars *, + const struct manoutput *); void pspdf_free(void *); void terminal_mdoc(void *, const struct mdoc *); Index: man.conf.5 =================================================================== RCS file: /home/cvs/mdocml/mdocml/man.conf.5,v retrieving revision 1.2 retrieving revision 1.3 diff -Lman.conf.5 -Lman.conf.5 -u -p -r1.2 -r1.3 --- man.conf.5 +++ man.conf.5 @@ -76,6 +76,26 @@ is recommended and necessary for .Xr apropos 1 to work, but not strictly required for .Xr man 1 . +.It Ic output Ar option Op Ar value +Configure the default value of an output option. +These directives are overridden by the +.Fl O +command line options of the same names. +For details, see the +.Xr mandoc 1 +manual. +.Pp +.Bl -column fragment integer "ascii, utf8" -compact +.It Ar option Ta Ar value Ta used by Fl T Ta purpose +.It Ta Ta Ta +.It Ic fragment Ta none Ta Cm html Ta print only body +.It Ic includes Ta string Ta Cm html Ta path to header files +.It Ic indent Ta integer Ta Cm ascii , utf8 Ta left margin +.It Ic man Ta string Ta Cm html Ta path for Xr links +.It Ic paper Ta string Ta Cm ps , pdf Ta paper size +.It Ic style Ta string Ta Cm html Ta CSS file +.It Ic width Ta integer Ta Cm ascii , utf8 Ta right margin +.El .It Ic _whatdb Ar path Ns Cm /whatis.db This directive provides the same functionality as .Ic manpath , Index: term_ps.c =================================================================== RCS file: /home/cvs/mdocml/mdocml/term_ps.c,v retrieving revision 1.72 retrieving revision 1.73 diff -Lterm_ps.c -Lterm_ps.c -u -p -r1.72 -r1.73 --- term_ps.c +++ term_ps.c @@ -7,9 +7,9 @@ * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF @@ -30,6 +30,7 @@ #include "mandoc_aux.h" #include "out.h" #include "term.h" +#include "manconf.h" #include "main.h" /* These work the buffer used by the header and footer. */ @@ -106,7 +107,8 @@ static void ps_printf(struct termp *, 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(const struct mchars *, char *); +static struct termp *pspdf_alloc(const struct mchars *, + const struct manoutput *); static void pdf_obj(struct termp *, size_t); /* @@ -507,7 +509,7 @@ static const struct font fonts[TERMFONT_ }; void * -pdf_alloc(const struct mchars *mchars, char *outopts) +pdf_alloc(const struct mchars *mchars, const struct manoutput *outopts) { struct termp *p; @@ -518,7 +520,7 @@ pdf_alloc(const struct mchars *mchars, c } void * -ps_alloc(const struct mchars *mchars, char *outopts) +ps_alloc(const struct mchars *mchars, const struct manoutput *outopts) { struct termp *p; @@ -529,14 +531,12 @@ ps_alloc(const struct mchars *mchars, ch } static struct termp * -pspdf_alloc(const struct mchars *mchars, char *outopts) +pspdf_alloc(const struct mchars *mchars, const struct manoutput *outopts) { struct termp *p; unsigned int pagex, pagey; size_t marginx, marginy, lineheight; - const char *toks[2]; const char *pp; - char *v; p = mandoc_calloc(1, sizeof(struct termp)); p->symtab = mchars; @@ -555,20 +555,6 @@ pspdf_alloc(const struct mchars *mchars, p->setwidth = ps_setwidth; p->width = ps_width; - toks[0] = "paper"; - toks[1] = NULL; - - pp = NULL; - - while (outopts && *outopts) - switch (getsubopt(&outopts, UNCONST(toks), &v)) { - case 0: - pp = v; - break; - default: - break; - } - /* Default to US letter (millimetres). */ pagex = 216; @@ -581,6 +567,7 @@ pspdf_alloc(const struct mchars *mchars, * only happens once, I'm not terribly concerned. */ + pp = outopts->paper; if (pp && strcasecmp(pp, "letter")) { if (0 == strcasecmp(pp, "a3")) { pagex = 297; -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv