static void format(const struct req *req, const char *file) { struct manoutput conf; struct mparse *mp; struct roff_man *man; void *vp; int fd; int usepath; if (-1 == (fd = open(file, O_RDONLY, 0))) { puts("<P>You specified an invalid manual file.</P>"); return; } mchars_alloc(); mp = mparse_alloc(MPARSE_SO, MANDOCLEVEL_BADARG, NULL, req->q.manpath); 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(&conf.man, "%s?query=%%N&sec=%%S%s%s%s%s", scriptname, req->q.arch ? "&arch=" : "", req->q.arch ? req->q.arch : "", usepath ? "&manpath=" : "", usepath ? req->q.manpath : ""); mparse_result(mp, &man, NULL); if (man == NULL) { fprintf(stderr, "fatal mandoc error: %s/%s\n", req->q.manpath, file); pg_error_internal(); mparse_free(mp); mchars_free(); return; } vp = html_alloc(&conf); if (man->macroset == MACROSET_MDOC) { mdoc_validate(man); html_mdoc(vp, man); } else { man_validate(man); html_man(vp, man); } html_free(vp); mparse_free(mp); mchars_free(); free(conf.man); }
static void format(const struct req *req, const char *file) { struct mparse *mp; int fd; struct mdoc *mdoc; struct man *man; void *vp; enum mandoclevel rc; char opts[PATH_MAX + 128]; if (-1 == (fd = open(file, O_RDONLY, 0))) { resp_baddb(); return; } mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL, NULL); rc = mparse_readfd(mp, fd, file); close(fd); if (rc >= MANDOCLEVEL_FATAL) { resp_baddb(); return; } snprintf(opts, sizeof(opts), "fragment," "man=%s/search.html?sec=%%S&expr=Nm~^%%N$," /*"includes=/cgi-bin/man.cgi/usr/include/%%I"*/, progname); mparse_result(mp, &mdoc, &man); if (NULL == man && NULL == mdoc) { resp_baddb(); mparse_free(mp); return; } resp_begin_html(200, NULL); resp_searchform(req); vp = html_alloc(opts); if (NULL != mdoc) html_mdoc(vp, mdoc); else html_man(vp, man); puts("</BODY>\n" "</HTML>"); html_free(vp); mparse_free(mp); }
static void format(const struct req *req, const char *file) { struct mparse *mp; struct mchars *mchars; struct mdoc *mdoc; struct man *man; void *vp; char *opts; enum mandoclevel rc; int fd; int usepath; if (-1 == (fd = open(file, O_RDONLY, 0))) { puts("<P>You specified an invalid manual file.</P>"); return; } mchars = mchars_alloc(); mp = mparse_alloc(MPARSE_SO, MANDOCLEVEL_FATAL, NULL, mchars, req->q.manpath); rc = mparse_readfd(mp, fd, file); close(fd); if (rc >= MANDOCLEVEL_FATAL) { fprintf(stderr, "fatal mandoc error: %s/%s\n", req->q.manpath, file); pg_error_internal(); return; } usepath = strcmp(req->q.manpath, req->p[0]); mandoc_asprintf(&opts, "fragment,man=%s?query=%%N&sec=%%S%s%s%s%s", scriptname, req->q.arch ? "&arch=" : "", req->q.arch ? req->q.arch : "", usepath ? "&manpath=" : "", usepath ? req->q.manpath : ""); mparse_result(mp, &mdoc, &man, NULL); if (NULL == man && NULL == mdoc) { fprintf(stderr, "fatal mandoc error: %s/%s\n", req->q.manpath, file); pg_error_internal(); mparse_free(mp); mchars_free(mchars); return; } vp = html_alloc(mchars, opts); if (NULL != mdoc) html_mdoc(vp, mdoc); else html_man(vp, man); html_free(vp); mparse_free(mp); mchars_free(mchars); free(opts); }