svn commit: r303221 - vendor/mdocml/dist

Baptiste Daroussin bapt at FreeBSD.org
Sat Jul 23 11:45:43 UTC 2016


Author: bapt
Date: Sat Jul 23 11:45:42 2016
New Revision: 303221
URL: https://svnweb.freebsd.org/changeset/base/303221

Log:
  Update to mdocml 1.13.4

Added:
  vendor/mdocml/dist/man.cgi.3   (contents, props changed)
Modified:
  vendor/mdocml/dist/INSTALL
  vendor/mdocml/dist/LICENSE
  vendor/mdocml/dist/Makefile
  vendor/mdocml/dist/NEWS
  vendor/mdocml/dist/TODO
  vendor/mdocml/dist/cgi.c
  vendor/mdocml/dist/cgi.h.example
  vendor/mdocml/dist/configure
  vendor/mdocml/dist/configure.local.example
  vendor/mdocml/dist/demandoc.c
  vendor/mdocml/dist/libmandoc.h
  vendor/mdocml/dist/main.c
  vendor/mdocml/dist/main.h
  vendor/mdocml/dist/man.1
  vendor/mdocml/dist/man.cgi.8
  vendor/mdocml/dist/mandoc.3
  vendor/mdocml/dist/mandoc.css
  vendor/mdocml/dist/mandoc.db.5
  vendor/mdocml/dist/mandoc_headers.3
  vendor/mdocml/dist/mandoc_malloc.3
  vendor/mdocml/dist/mandocdb.c
  vendor/mdocml/dist/manpage.c
  vendor/mdocml/dist/manpath.c
  vendor/mdocml/dist/mansearch.c
  vendor/mdocml/dist/mchars_alloc.3
  vendor/mdocml/dist/read.c
  vendor/mdocml/dist/tag.c
  vendor/mdocml/dist/term.c
  vendor/mdocml/dist/term_ascii.c
  vendor/mdocml/dist/test-rewb-bsd.c
  vendor/mdocml/dist/test-rewb-sysv.c

Modified: vendor/mdocml/dist/INSTALL
==============================================================================
--- vendor/mdocml/dist/INSTALL	Sat Jul 23 11:26:24 2016	(r303220)
+++ vendor/mdocml/dist/INSTALL	Sat Jul 23 11:45:42 2016	(r303221)
@@ -1,4 +1,4 @@
-$Id: INSTALL,v 1.13 2015/11/07 14:01:16 schwarze Exp $
+$Id: INSTALL,v 1.15 2016/07/14 11:09:06 schwarze Exp $
 
 About mdocml, the portable mandoc distribution
 ----------------------------------------------
@@ -16,7 +16,7 @@ tech@ mailing list, too.
 
 Enjoy using the mandoc toolset!
 
-Ingo Schwarze, Karlsruhe, March 2015
+Ingo Schwarze, Karlsruhe, July 2016
 
 
 Installation
@@ -52,7 +52,7 @@ and go back to step 2.
 
 4. Run "make -n install" and check whether everything will be
 installed to the intended places.  Otherwise, put some *DIR or *NM*
-variables into "configure.local" and go back to step 2.
+variables into "configure.local" and go back to step 2.
 
 5. Run "sudo make install".  If you intend to build a binary
 package using some kind of fake root mechanism, you may need a
@@ -63,7 +63,7 @@ in the "Makefile" to understand how DEST
 manpath(1), make sure it is configured correctly, in particular,
 it returns all directory trees where manual pages are installed.
 Otherwise, if your system uses man.conf(5), make sure it contains
-a "_whatdb" line for each directory tree, and the order of these
+a "manpath" line for each directory tree, and the order of these
 lines meets your wishes.
 
 7. If you compiled with database support, run the command "sudo

Modified: vendor/mdocml/dist/LICENSE
==============================================================================
--- vendor/mdocml/dist/LICENSE	Sat Jul 23 11:26:24 2016	(r303220)
+++ vendor/mdocml/dist/LICENSE	Sat Jul 23 11:45:42 2016	(r303221)
@@ -1,11 +1,11 @@
-$Id: LICENSE,v 1.11 2015/11/07 17:58:55 schwarze Exp $
+$Id: LICENSE,v 1.12 2016/07/07 23:46:36 schwarze Exp $
 
 With the exceptions noted below, all code and documentation
 contained in the mdocml toolkit is protected by the Copyright
 of the following developers:
 
 Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps at bsd.lv>
-Copyright (c) 2010-2015 Ingo Schwarze <schwarze at openbsd.org>
+Copyright (c) 2010-2016 Ingo Schwarze <schwarze at openbsd.org>
 Copyright (c) 2009, 2010, 2011, 2012 Joerg Sonnenberger <joerg at netbsd.org>
 Copyright (c) 2013 Franco Fichtner <franco at lastsummer.de>
 Copyright (c) 2014 Baptiste Daroussin <bapt at FreeBSD.org>

Modified: vendor/mdocml/dist/Makefile
==============================================================================
--- vendor/mdocml/dist/Makefile	Sat Jul 23 11:26:24 2016	(r303220)
+++ vendor/mdocml/dist/Makefile	Sat Jul 23 11:45:42 2016	(r303221)
@@ -1,7 +1,7 @@
-# $Id: Makefile,v 1.480 2015/11/07 21:53:14 schwarze Exp $
+# $Id: Makefile,v 1.488 2016/07/12 05:18:38 kristaps Exp $
 #
 # Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps at bsd.lv>
-# Copyright (c) 2011, 2013, 2014, 2015 Ingo Schwarze <schwarze at openbsd.org>
+# Copyright (c) 2011, 2013-2016 Ingo Schwarze <schwarze at openbsd.org>
 #
 # Permission to use, copy, modify, and distribute this software for any
 # purpose with or without fee is hereby granted, provided that the above
@@ -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.
 
-VERSION = 1.13.3
+VERSION = 1.13.4
 
 # === LIST OF FILES ====================================================
 
@@ -31,6 +31,9 @@ TESTSRCS	 = test-dirent-namlen.c \
 		   test-pledge.c \
 		   test-progname.c \
 		   test-reallocarray.c \
+		   test-rewb-bsd.c \
+		   test-rewb-sysv.c \
+		   test-sandbox_init.c \
 		   test-sqlite3.c \
 		   test-sqlite3_errstr.c \
 		   test-strcasestr.c \
@@ -138,6 +141,7 @@ DISTFILES	 = INSTALL \
 		   makewhatis.8 \
 		   man.1 \
 		   man.7 \
+		   man.cgi.3 \
 		   man.cgi.8 \
 		   man.conf.5 \
 		   man.h \
@@ -164,6 +168,7 @@ DISTFILES	 = INSTALL \
 		   predefs.in \
 		   roff.7 \
 		   roff.h \
+		   roff_int.h \
 		   soelim.1 \
 		   st.in \
 		   tag.h \
@@ -293,6 +298,7 @@ WWW_MANS	 = apropos.1.html \
 		   roff.7.html \
 		   tbl.7.html \
 		   makewhatis.8.html \
+		   man.cgi.3.html \
 		   man.cgi.8.html \
 		   man.h.html \
 		   manconf.h.html \
@@ -392,34 +398,30 @@ db-install: base-build
 cgi-install: cgi-build
 	mkdir -p $(DESTDIR)$(CGIBINDIR)
 	mkdir -p $(DESTDIR)$(HTDOCDIR)
-	mkdir -p $(DESTDIR)$(WWWPREFIX)/man/mandoc/man1
-	mkdir -p $(DESTDIR)$(WWWPREFIX)/man/mandoc/man8
 	$(INSTALL_PROGRAM) man.cgi $(DESTDIR)$(CGIBINDIR)
 	$(INSTALL_DATA) mandoc.css $(DESTDIR)$(HTDOCDIR)
-	$(INSTALL_MAN) apropos.1 $(DESTDIR)$(WWWPREFIX)/man/mandoc/man1/
-	$(INSTALL_MAN) man.cgi.8 $(DESTDIR)$(WWWPREFIX)/man/mandoc/man8/
 
 Makefile.local config.h: configure ${TESTSRCS}
 	@echo "$@ is out of date; please run ./configure"
 	@exit 1
 
 libmandoc.a: $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
-	$(AR) rs $@ $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
+	ar rs $@ $(COMPAT_OBJS) $(LIBMANDOC_OBJS)
 
 mandoc: $(MAIN_OBJS) libmandoc.a
-	$(CC) $(LDFLAGS) -o $@ $(MAIN_OBJS) libmandoc.a $(DBLIB)
+	$(CC) -o $@ $(LDFLAGS) $(MAIN_OBJS) libmandoc.a $(LDADD)
 
 manpage: $(MANPAGE_OBJS) libmandoc.a
-	$(CC) $(LDFLAGS) -o $@ $(MANPAGE_OBJS) libmandoc.a $(DBLIB)
+	$(CC) -o $@ $(LDFLAGS) $(MANPAGE_OBJS) libmandoc.a $(LDADD)
 
 man.cgi: $(CGI_OBJS) libmandoc.a
-	$(CC) $(LDFLAGS) $(STATIC) -o $@ $(CGI_OBJS) libmandoc.a $(DBLIB)
+	$(CC) $(STATIC) -o $@ $(LDFLAGS) $(CGI_OBJS) libmandoc.a $(LDADD)
 
 demandoc: $(DEMANDOC_OBJS) libmandoc.a
-	$(CC) $(LDFLAGS) -o $@ $(DEMANDOC_OBJS) libmandoc.a $(DBLIB)
+	$(CC) -o $@ $(LDFLAGS) $(DEMANDOC_OBJS) libmandoc.a $(LDADD)
 
 soelim: $(SOELIM_OBJS)
-	$(CC) $(LDFLAGS) -o $@ $(SOELIM_OBJS)
+	$(CC) -o $@ $(LDFLAGS) $(SOELIM_OBJS)
 
 # --- maintainer targets ---
 
@@ -439,6 +441,8 @@ depend: config.h
 		Makefile.depend > Makefile.tmp
 	mv Makefile.tmp Makefile.depend
 
+dist: mdocml.sha256
+
 mdocml.sha256: mdocml.tar.gz
 	sha256 mdocml.tar.gz > $@
 

Modified: vendor/mdocml/dist/NEWS
==============================================================================
--- vendor/mdocml/dist/NEWS	Sat Jul 23 11:26:24 2016	(r303220)
+++ vendor/mdocml/dist/NEWS	Sat Jul 23 11:45:42 2016	(r303221)
@@ -1,7 +1,140 @@
-$Id: NEWS,v 1.10 2015/11/05 16:58:20 schwarze Exp $
+$Id: NEWS,v 1.12 2016/07/14 11:09:06 schwarze Exp $
 
 This file lists the most important changes in the mdocml.bsd.lv distribution.
 
+Changes in version 1.13.4, released on July 14, 2016
+
+    --- MAJOR NEW FEATURES ---
+ * man.conf(5): Design and implement a simpler configuration file format.
+ * man(1): Leverage less(1) -T and :t in a way resembling ctags(1)
+   to jump to the definitions of various terms inside manual pages.
+ * soelim(1): New implementation by Baptiste Daroussin.
+ * privilege limitation: Use OpenBSD pledge(2) or OS X sandbox_init(3)
+   when available.
+ * man.cgi(8): Support short URIs like http://man.openbsd.org/mdoc .
+ * mandoc.css: Use one unified stylesheet rather than three different ones.
+    --- MAJOR FUNCTIONALLY RELEVANT BUGFIXES ---
+ * mdoc(7): Fix multiple aspects of SYNOPSIS .Nm formatting.
+ * man(1): Fix process group handling, avoiding unclean shutdowns.
+    --- PORTABILITY IMPROVEMENTS ---
+ * Correctly use the ohash(3) compatibility implementation
+   even when building without SQLite support.
+ * Add compat glue for building on Solaris 9 and 10.
+ * Let ./configure select a supported RE syntax for word boundaries.
+ * Support LDFLAGS, to be used for example for hardening options.
+ * Avoid mixing putchar(3) and putwchar(3) on the same file descriptor,
+   it resulted in output corruption on some platforms.
+ * Avoid reusing va_lists, use va_copy(3) for better portability.
+ * Do not hardcode the path to the more(1) program.
+    --- MINOR NEW FEATURES ---
+ * roff(7): Implement \n(.$ (number of macro arguments).
+ * roff(7): Fully implement \z (do not advance cursor).
+ * roff(7): Implement the `r'  conditional (register exists).
+ * roff(7): Implement \\$* (interpolate all arguments).
+ * roff(7): Parse and ignore \, and \/ (italic corrections).
+ * When there is no -m, no -M, no MANPATH and no /etc/man.conf,
+   fall back to /usr/share/man:/usr/X11R6/man:/usr/local/man.
+ * man(1): Give manuals in purely numerical sections priority over
+   manuals of the same name in sections with an alphabetical suffix.
+ * man.cgi(8): Support "header.html" and "footer.html".
+ * man.cgi(8): Set the "autofocus" attribute on the query text box.
+ * man.cgi(8): Simplify the search form, drop two useless buttons.
+ * man.cgi(8): Delete the pseudo-manpath "mandoc", assume that
+   apropos(1) and man.cgi(8) are installed in the default manpath.
+    --- RELIABILITY BUGFIXES ---
+ * mdoc(7): Avoid a use after free and an assertion failure when nodes
+   are deleted during validation.
+ * mdoc(7): Avoid a NULL pointer access when .Bd has no arguments.
+ * mdoc(7): Avoid a NULL pointer access triggered by mismatching end macros.
+ * mdoc(7): Avoid an assertion when .Fo has no argument.
+ * mdoc(7): Avoid an assertion when .Ta<tab> occurs in .Bl -column.
+ * mdoc(7): Avoid an assertion when a body gets broken and has a tail.
+ * roff(7): Avoid an assertion caused by blanks inside \o.
+ * roff(7): Make .so links to gziped manuals work without mandoc.db(5).
+ * tbl(7): Avoid a use after free when the last line of a layout is empty.
+ * eqn(7): Avoid an infinite loop caused by recursive "define".
+ * makewhatis(8): Avoid a segfault caused by unusual directory structures.
+ * Fix handling of leading, trailing, and double colons in MANPATH and -m.
+    --- MINOR BUGFIXES ---
+ * mdoc(7): Put arguments to end macros of broken partial explicit blocks
+   inside the breaking block.
+ * mdoc(7): Let .Dv force normal font.
+ * mdoc(7): Make trailing whitespace significant in .Bl -tag widths.
+ * mdoc(7): Fix macro interpretation around tabs in .Bl -column.
+ * man(7): Use the default width for .RS without arguments.
+ * man(7): On a new RS nesting level, the saved width starts from
+   the default width, not from the saved width of the previous level.
+ * man(7): Allow .PD in next-line scope.
+ * man(7): Improve handling of empty .HP.
+ * man(7): Improve formatting of .br and .sp inside .HP.
+ * man(7): Do not mistreat empty arguments to font alternating
+   macros as vertical spacing requests.
+ * man(7): Allow fill mode changes in tagged paragraph next-line scope.
+ * man(7): Fix minor bugs in block rewinding and simplify the related code.
+ * man(7): Add missing line breaks before subsection headers.
+ * man(7): Give section and subsection headers hanging indentation.
+ * man(7): Make trailing whitespace significant in .TP widths.
+ * roff(7): Don't allow breaking the output line after hyphens
+   that immediately follow escape sequences.
+ * roff(7): Ignore blank characters at the beginning of conditional blocks.
+ * roff(7): Escape breakable hyphens only after handling input line traps.
+ * roff(7): Reject \[uD800] to \[uDFFF] (surrogates) in the parser.
+ * tbl(7): Allow more than one data field after T} on the same input line.
+ * terminal output: Apply bold and italic to non-ASCII Unicode codepoints.
+ * terminal output: Improve rounding rules for horizontal scaling widths.
+ * HTML output: Render ASCII_NBRSP as " ", not "-".
+ * man(1): Do not match the first part of a name if it continues with a dot.
+ * man(1): Keep working even if the current directory is unusable.
+ * man(1): Better error message when $PAGER is invalid.
+ * makewhatis(8): Improve handling of .Va and .Vt macros.
+ * apropos(1): Print "nothing appropriate" to stderr when appropriate.
+ * apropos(1): Abort with a useful error message when elementary
+   database operations like preparing queries or binding variables fail.
+    --- STRUCTURAL CHANGES, no functional change ---
+ * mdoc(7) and man(7): Unified data structures struct roff_node etc.
+ * mdoc(7) and man(7): Unified node handling library in roff.c.
+ * mdoc(7) and man(7): Seperate validation phase from parsing.
+ * roff(7): Major character table cleanup.
+ * Link with libz rather than forking gunzip(1).
+    --- THANKS TO ---
+ * Baptiste Daroussin (FreeBSD) for the new soelim(1)
+   and for release testing.
+ * Anthony Bentley (OpenBSD) for unifying mandoc.css, two nice
+   patches for man.cgi(8), some documentation patches, some bug
+   reports, and various useful discussions.
+ * Todd Miller (OpenBSD) for lots of help with process group and
+   signal handling, a few patches, some bug reports and some useful
+   discussions.
+ * Jonathan Gray (OpenBSD) for yet more testing with afl(1)
+   again resulting in more than half a dozen important bug reports.
+ * Svyatoslav Mishyn (Crux Linux) for some patches, several bug
+   reports, and extensive release testing.
+ * Christian Neukirchen (void Linux) for a number of compatibility
+   patches and suggestions and several bug reports.
+ * Christos Zoulas (NetBSD) for a bug fix patch and some useful
+   suggestions for cleanup.
+ * Florian Obser (OpenBSD) for a bugfix patch and some bug reports.
+ * Sevan Janiyan for help with Solaris compatibility and release
+   testing on many platforms.
+ * Jan Holzhueter and OpenCSW in general for help with Solaris
+   compatibility, and for providing me with a Solaris 9/10/11 testing
+   environment.
+ * Michael McConville (OpenBSD) for some simple cleanup patches.
+ * Thomas Klausner (NetBSD) for some bug reports and release testing.
+ * Christian Weisgerber, Dmitrij Czarkoff, Igor Sobrado,
+   Ken Westerback, Marc Espie, Mike Belopuhov, Rafael Neves,
+   Ted Unangst, Tim van der Molen, Theo Buehler, Theo de Raadt
+   (OpenBSD), Kurt Jaeger, Dag Erling Smoergrav (FreeBSD),
+   Joerg Sonnenberger (NetBSD), Carsten Kunze (Heirloom troff),
+   Daniel Levai, Fabian Raetz, Jan Stary, Jean-Yves Migeon,
+   Lorenzo Beretta, Markus Waldeck, Maxim Belooussov, Michael Reed,
+   Peter Bray, and Serguey Parkhomovsky for bug reports and feature
+   suggestions.
+ * Alexander Hall, Andrew Fresh, Antoine Jacoutot, Doug Hogan,
+   Jason McIntyre, Jasper Lievisse Adriaanse, Kent Spillner,
+   Nicholas Marriott, Peter Hessler, Sebastien Marie, Stefan Sperling,
+   and Theo de Raadt (OpenBSD) for helpful discussions and feedback.
+
 Changes in version 1.13.3, released on March 13, 2015
 
     --- MAJOR NEW FEATURES ---

Modified: vendor/mdocml/dist/TODO
==============================================================================
--- vendor/mdocml/dist/TODO	Sat Jul 23 11:26:24 2016	(r303220)
+++ vendor/mdocml/dist/TODO	Sat Jul 23 11:45:42 2016	(r303221)
@@ -1,6 +1,6 @@
 ************************************************************************
 * Official mandoc TODO.
-* $Id: TODO,v 1.216 2016/01/08 01:37:32 schwarze Exp $
+* $Id: TODO,v 1.218 2016/06/05 21:06:04 schwarze Exp $
 ************************************************************************
 
 Many issues are annotated for difficulty as follows:
@@ -416,6 +416,11 @@ are mere guesses, and some may be wrong.
   see also matthew@  Fri, 18 Jul 2014 19:25:12 -0700
   loc *  exist *  algo **  size *  imp ***
 
+- In -man -Thtml, .nf does not preserve indentation.
+  It should either convert blanks to  
+  or use <pre> rather than <div> (like .Bd -literal does).
+  Reported by afresh1@  12 Apr 2016 14:35:45 -0700
+
 - .Bf at the beginning of a paragraph inserts a bogus 1ex horizontal
   space, see for example random(3).  Introduced in
   http://mdocml.bsd.lv/cgi-bin/cvsweb/mdoc_html.c.diff?r1=1.91&r2=1.92
@@ -583,8 +588,6 @@ are mere guesses, and some may be wrong.
   to tech at mdocml, naddy@  Wed, 28 Sep 2011 11:21:46 +0200
   wait!  kristaps@  Sun, 02 Oct 2011 17:12:52 +0200
 
-- for system errors, use errno/strerror/warn/err
-
 ************************************************************************
 * documentation issues
 ************************************************************************
@@ -628,9 +631,6 @@ Several areas can be cleaned up to make 
 * structural issues
 ************************************************************************
 
-- Use libz directly instead of forking gunzip(1).
-  Suggested by bapt at FreeBSD among others.
-
 - We use the input line number at several places to distinguish
   same-line from different-line input.  That plainly doesn't work
   with user-defined macros, leading to random breakage.

Modified: vendor/mdocml/dist/cgi.c
==============================================================================
--- vendor/mdocml/dist/cgi.c	Sat Jul 23 11:26:24 2016	(r303220)
+++ vendor/mdocml/dist/cgi.c	Sat Jul 23 11:45:42 2016	(r303221)
@@ -1,7 +1,7 @@
-/*	$Id: cgi.c,v 1.116 2016/01/04 12:36:26 schwarze Exp $ */
+/*	$Id: cgi.c,v 1.135 2016/07/11 22:48:37 schwarze Exp $ */
 /*
  * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps at bsd.lv>
- * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze at usta.de>
+ * Copyright (c) 2014, 2015, 2016 Ingo Schwarze <schwarze at usta.de>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -21,6 +21,7 @@
 #include <sys/time.h>
 
 #include <ctype.h>
+#include <err.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
@@ -55,15 +56,20 @@ struct	req {
 	struct query	  q;
 	char		**p; /* array of available manpaths */
 	size_t		  psz; /* number of available manpaths */
+	int		  isquery; /* QUERY_STRING used, not PATH_INFO */
+};
+
+enum	focus {
+	FOCUS_NONE = 0,
+	FOCUS_QUERY
 };
 
-static	void		 catman(const struct req *, const char *);
-static	void		 format(const struct req *, const char *);
 static	void		 html_print(const char *);
 static	void		 html_putchar(char);
 static	int		 http_decode(char *);
-static	void		 http_parse(struct req *, const char *);
-static	void		 pathgen(struct req *);
+static	void		 parse_manpath_conf(struct req *);
+static	void		 parse_path_info(struct req *req, const char *path);
+static	void		 parse_query_string(struct req *, const char *);
 static	void		 pg_error_badrequest(const char *);
 static	void		 pg_error_internal(void);
 static	void		 pg_index(const struct req *);
@@ -74,16 +80,18 @@ static	void		 pg_searchres(const struct 
 static	void		 pg_show(struct req *, const char *);
 static	void		 resp_begin_html(int, const char *);
 static	void		 resp_begin_http(int, const char *);
+static	void		 resp_catman(const struct req *, const char *);
 static	void		 resp_copy(const char *);
 static	void		 resp_end_html(void);
-static	void		 resp_searchform(const struct req *);
+static	void		 resp_format(const struct req *, const char *);
+static	void		 resp_searchform(const struct req *, enum focus);
 static	void		 resp_show(const struct req *, const char *);
 static	void		 set_query_attr(char **, char **);
 static	int		 validate_filename(const char *);
 static	int		 validate_manpath(const struct req *, const char *);
 static	int		 validate_urifrag(const char *);
 
-static	const char	 *scriptname; /* CGI script name */
+static	const char	 *scriptname = SCRIPT_NAME;
 
 static	const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
 static	const char *const sec_numbers[] = {
@@ -106,16 +114,16 @@ static	const int sec_MAX = sizeof(sec_na
 
 static	const char *const arch_names[] = {
     "amd64",       "alpha",       "armish",      "armv7",
-    "aviion",      "hppa",        "hppa64",      "i386",
-    "ia64",        "landisk",     "loongson",    "luna88k",
-    "macppc",      "mips64",      "octeon",      "sgi",
-    "socppc",      "solbourne",   "sparc",       "sparc64",
-    "vax",         "zaurus",
+    "hppa",        "hppa64",      "i386",        "landisk",
+    "loongson",    "luna88k",     "macppc",      "mips64",
+    "octeon",      "sgi",         "socppc",      "sparc",
+    "sparc64",     "zaurus",
     "amiga",       "arc",         "arm32",       "atari",
-    "beagle",      "cats",        "hp300",       "mac68k",
-    "mvme68k",     "mvme88k",     "mvmeppc",     "palm",
-    "pc532",       "pegasos",     "pmax",        "powerpc",
-    "sun3",        "wgrisc",      "x68k"
+    "aviion",      "beagle",      "cats",        "hp300",       
+    "ia64",        "mac68k",      "mvme68k",     "mvme88k",
+    "mvmeppc",     "palm",        "pc532",       "pegasos",
+    "pmax",        "powerpc",     "solbourne",   "sun3",
+    "vax",         "wgrisc",      "x68k"
 };
 static	const int arch_MAX = sizeof(arch_names) / sizeof(char *);
 
@@ -182,11 +190,12 @@ set_query_attr(char **attr, char **val)
  * and store the values into the query structure.
  */
 static void
-http_parse(struct req *req, const char *qs)
+parse_query_string(struct req *req, const char *qs)
 {
 	char		*key, *val;
 	size_t		 keysz, valsz;
 
+	req->isquery	= 1;
 	req->q.manpath	= NULL;
 	req->q.arch	= NULL;
 	req->q.sec	= NULL;
@@ -338,14 +347,14 @@ resp_begin_html(int code, const char *ms
 	resp_begin_http(code, msg);
 
 	printf("<!DOCTYPE html>\n"
-	       "<HTML>\n"
-	       "<HEAD>\n"
-	       "<META CHARSET=\"UTF-8\" />\n"
-	       "<LINK REL=\"stylesheet\" HREF=\"%s/mandoc.css\""
-	       " TYPE=\"text/css\" media=\"all\">\n"
-	       "<TITLE>%s</TITLE>\n"
-	       "</HEAD>\n"
-	       "<BODY>\n"
+	       "<html>\n"
+	       "<head>\n"
+	       "<meta charset=\"UTF-8\"/>\n"
+	       "<link rel=\"stylesheet\" href=\"%s/mandoc.css\""
+	       " type=\"text/css\" media=\"all\">\n"
+	       "<title>%s</title>\n"
+	       "</head>\n"
+	       "<body>\n"
 	       "<!-- Begin page content. //-->\n",
 	       CSS_DIR, CUSTOMIZE_TITLE);
 
@@ -358,103 +367,87 @@ resp_end_html(void)
 
 	resp_copy(MAN_DIR "/footer.html");
 
-	puts("</BODY>\n"
-	     "</HTML>");
+	puts("</body>\n"
+	     "</html>");
 }
 
 static void
-resp_searchform(const struct req *req)
+resp_searchform(const struct req *req, enum focus focus)
 {
 	int		 i;
 
 	puts("<!-- Begin search form. //-->");
-	printf("<DIV ID=\"mancgi\">\n"
-	       "<FORM ACTION=\"%s\" METHOD=\"get\">\n"
-	       "<FIELDSET>\n"
-	       "<LEGEND>Manual Page Search Parameters</LEGEND>\n",
+	printf("<div id=\"mancgi\">\n"
+	       "<form action=\"/%s\" method=\"get\">\n"
+	       "<fieldset>\n"
+	       "<legend>Manual Page Search Parameters</legend>\n",
 	       scriptname);
 
 	/* Write query input box. */
 
-	printf(	"<TABLE><TR><TD>\n"
-		"<INPUT TYPE=\"text\" NAME=\"query\" VALUE=\"");
-	if (NULL != req->q.query)
+	printf("<input type=\"text\" name=\"query\" value=\"");
+	if (req->q.query != NULL)
 		html_print(req->q.query);
-	puts("\" SIZE=\"40\">");
-
-	/* Write submission and reset buttons. */
-
-	printf(	"<INPUT TYPE=\"submit\" VALUE=\"Submit\">\n"
-		"<INPUT TYPE=\"reset\" VALUE=\"Reset\">\n");
-
-	/* Write show radio button */
-
-	printf(	"</TD><TD>\n"
-		"<INPUT TYPE=\"radio\" ");
-	if (req->q.equal)
-		printf("CHECKED=\"checked\" ");
-	printf(	"NAME=\"apropos\" ID=\"show\" VALUE=\"0\">\n"
-		"<LABEL FOR=\"show\">Show named manual page</LABEL>\n");
+	printf( "\" size=\"40\"");
+	if (focus == FOCUS_QUERY)
+		printf(" autofocus");
+	puts(">");
+
+	/* Write submission buttons. */
+
+	printf(	"<button type=\"submit\" name=\"apropos\" value=\"0\">"
+		"man</button>\n"
+		"<button type=\"submit\" name=\"apropos\" value=\"1\">"
+		"apropos</button>\n<br/>\n");
 
 	/* Write section selector. */
 
-	puts(	"</TD></TR><TR><TD>\n"
-		"<SELECT NAME=\"sec\">");
+	puts("<select name=\"sec\">");
 	for (i = 0; i < sec_MAX; i++) {
-		printf("<OPTION VALUE=\"%s\"", sec_numbers[i]);
+		printf("<option value=\"%s\"", sec_numbers[i]);
 		if (NULL != req->q.sec &&
 		    0 == strcmp(sec_numbers[i], req->q.sec))
-			printf(" SELECTED=\"selected\"");
-		printf(">%s</OPTION>\n", sec_names[i]);
+			printf(" selected=\"selected\"");
+		printf(">%s</option>\n", sec_names[i]);
 	}
-	puts("</SELECT>");
+	puts("</select>");
 
 	/* Write architecture selector. */
 
-	printf(	"<SELECT NAME=\"arch\">\n"
-		"<OPTION VALUE=\"default\"");
+	printf(	"<select name=\"arch\">\n"
+		"<option value=\"default\"");
 	if (NULL == req->q.arch)
-		printf(" SELECTED=\"selected\"");
-	puts(">All Architectures</OPTION>");
+		printf(" selected=\"selected\"");
+	puts(">All Architectures</option>");
 	for (i = 0; i < arch_MAX; i++) {
-		printf("<OPTION VALUE=\"%s\"", arch_names[i]);
+		printf("<option value=\"%s\"", arch_names[i]);
 		if (NULL != req->q.arch &&
 		    0 == strcmp(arch_names[i], req->q.arch))
-			printf(" SELECTED=\"selected\"");
-		printf(">%s</OPTION>\n", arch_names[i]);
+			printf(" selected=\"selected\"");
+		printf(">%s</option>\n", arch_names[i]);
 	}
-	puts("</SELECT>");
+	puts("</select>");
 
 	/* Write manpath selector. */
 
 	if (req->psz > 1) {
-		puts("<SELECT NAME=\"manpath\">");
+		puts("<select name=\"manpath\">");
 		for (i = 0; i < (int)req->psz; i++) {
-			printf("<OPTION ");
+			printf("<option ");
 			if (strcmp(req->q.manpath, req->p[i]) == 0)
-				printf("SELECTED=\"selected\" ");
-			printf("VALUE=\"");
+				printf("selected=\"selected\" ");
+			printf("value=\"");
 			html_print(req->p[i]);
 			printf("\">");
 			html_print(req->p[i]);
-			puts("</OPTION>");
+			puts("</option>");
 		}
-		puts("</SELECT>");
+		puts("</select>");
 	}
 
-	/* Write search radio button */
-
-	printf(	"</TD><TD>\n"
-		"<INPUT TYPE=\"radio\" ");
-	if (0 == req->q.equal)
-		printf("CHECKED=\"checked\" ");
-	printf(	"NAME=\"apropos\" ID=\"search\" VALUE=\"1\">\n"
-		"<LABEL FOR=\"search\">Search with apropos query</LABEL>\n");
-
-	puts("</TD></TR></TABLE>\n"
-	     "</FIELDSET>\n"
-	     "</FORM>\n"
-	     "</DIV>");
+	puts("</fieldset>\n"
+	     "</form>\n"
+	     "</div>");
 	puts("<!-- End search form. //-->");
 }
 
@@ -477,9 +470,6 @@ validate_manpath(const struct req *req, 
 {
 	size_t	 i;
 
-	if ( ! strcmp(manpath, "mandoc"))
-		return 1;
-
 	for (i = 0; i < req->psz; i++)
 		if ( ! strcmp(manpath, req->p[i]))
 			return 1;
@@ -503,15 +493,16 @@ pg_index(const struct req *req)
 {
 
 	resp_begin_html(200, NULL);
-	resp_searchform(req);
-	printf("<P>\n"
+	resp_searchform(req, FOCUS_QUERY);
+	printf("<p>\n"
 	       "This web interface is documented in the\n"
-	       "<A HREF=\"%s/mandoc/man8/man.cgi.8\">man.cgi</A>\n"
+	       "<a href=\"/%s%sman.cgi.8\">man.cgi(8)</a>\n"
 	       "manual, and the\n"
-	       "<A HREF=\"%s/mandoc/man1/apropos.1\">apropos</A>\n"
+	       "<a href=\"/%s%sapropos.1\">apropos(1)</a>\n"
 	       "manual explains the query syntax.\n"
-	       "</P>\n",
-	       scriptname, scriptname);
+	       "</p>\n",
+	       scriptname, *scriptname == '\0' ? "" : "/",
+	       scriptname, *scriptname == '\0' ? "" : "/");
 	resp_end_html();
 }
 
@@ -519,10 +510,10 @@ static void
 pg_noresult(const struct req *req, const char *msg)
 {
 	resp_begin_html(200, NULL);
-	resp_searchform(req);
-	puts("<P>");
+	resp_searchform(req, FOCUS_QUERY);
+	puts("<p>");
 	puts(msg);
-	puts("</P>");
+	puts("</p>");
 	resp_end_html();
 }
 
@@ -531,12 +522,12 @@ pg_error_badrequest(const char *msg)
 {
 
 	resp_begin_html(400, "Bad Request");
-	puts("<H1>Bad Request</H1>\n"
-	     "<P>\n");
+	puts("<h1>Bad Request</h1>\n"
+	     "<p>\n");
 	puts(msg);
 	printf("Try again from the\n"
-	       "<A HREF=\"%s\">main page</A>.\n"
-	       "</P>", scriptname);
+	       "<a href=\"/%s\">main page</a>.\n"
+	       "</p>", scriptname);
 	resp_end_html();
 }
 
@@ -544,7 +535,7 @@ static void
 pg_error_internal(void)
 {
 	resp_begin_html(500, "Internal Server Error");
-	puts("<P>Internal Server Error</P>");
+	puts("<p>Internal Server Error</p>");
 	resp_end_html();
 }
 
@@ -552,28 +543,30 @@ static void
 pg_searchres(const struct req *req, struct manpage *r, size_t sz)
 {
 	char		*arch, *archend;
-	size_t		 i, iuse, isec;
+	const char	*sec;
+	size_t		 i, iuse;
 	int		 archprio, archpriouse;
 	int		 prio, priouse;
-	char		 sec;
 
 	for (i = 0; i < sz; i++) {
 		if (validate_filename(r[i].file))
 			continue;
-		fprintf(stderr, "invalid filename %s in %s database\n",
+		warnx("invalid filename %s in %s database",
 		    r[i].file, req->q.manpath);
 		pg_error_internal();
 		return;
 	}
 
-	if (1 == sz) {
+	if (req->isquery && sz == 1) {
 		/*
 		 * If we have just one result, then jump there now
 		 * without any delay.
 		 */
 		printf("Status: 303 See Other\r\n");
-		printf("Location: http://%s%s/%s/%s",
-		    HTTP_HOST, scriptname, req->q.manpath, r[0].file);
+		printf("Location: http://%s/%s%s%s/%s",
+		    HTTP_HOST, scriptname,
+		    *scriptname == '\0' ? "" : "/",
+		    req->q.manpath, r[0].file);
 		printf("\r\n"
 		     "Content-Type: text/html; charset=utf-8\r\n"
 		     "\r\n");
@@ -581,50 +574,57 @@ pg_searchres(const struct req *req, stru
 	}
 
 	resp_begin_html(200, NULL);
-	resp_searchform(req);
-	puts("<DIV CLASS=\"results\">");
-	puts("<TABLE>");
+	resp_searchform(req,
+	    req->q.equal || sz == 1 ? FOCUS_NONE : FOCUS_QUERY);
 
-	for (i = 0; i < sz; i++) {
-		printf("<TR>\n"
-		       "<TD CLASS=\"title\">\n"
-		       "<A HREF=\"%s/%s/%s",
-		    scriptname, req->q.manpath, r[i].file);
-		printf("\">");
-		html_print(r[i].names);
-		printf("</A>\n"
-		       "</TD>\n"
-		       "<TD CLASS=\"desc\">");
-		html_print(r[i].output);
-		puts("</TD>\n"
-		     "</TR>");
-	}
+	if (sz > 1) {
+		puts("<div class=\"results\">");
+		puts("<table>");
 
-	puts("</TABLE>\n"
-	     "</DIV>");
+		for (i = 0; i < sz; i++) {
+			printf("<tr>\n"
+			       "<td class=\"title\">\n"
+			       "<a href=\"/%s%s%s/%s",
+			    scriptname, *scriptname == '\0' ? "" : "/",
+			    req->q.manpath, r[i].file);
+			printf("\">");
+			html_print(r[i].names);
+			printf("</a>\n"
+			       "</td>\n"
+			       "<td class=\"desc\">");
+			html_print(r[i].output);
+			puts("</td>\n"
+			     "</tr>");
+		}
+
+		puts("</table>\n"
+		     "</div>");
+	}
 
 	/*
 	 * In man(1) mode, show one of the pages
 	 * even if more than one is found.
 	 */
 
-	if (req->q.equal) {
-		puts("<HR>");
+	if (req->q.equal || sz == 1) {
+		puts("<hr>");
 		iuse = 0;
-		priouse = 10;
+		priouse = 20;
 		archpriouse = 3;
 		for (i = 0; i < sz; i++) {
-			isec = strcspn(r[i].file, "123456789");
-			sec = r[i].file[isec];
-			if ('\0' == sec)
+			sec = r[i].file;
+			sec += strcspn(sec, "123456789");
+			if (sec[0] == '\0')
 				continue;
-			prio = sec_prios[sec - '1'];
-			if (NULL == req->q.arch) {
+			prio = sec_prios[sec[0] - '1'];
+			if (sec[1] != '/')
+				prio += 10;
+			if (req->q.arch == NULL) {
 				archprio =
-				    (NULL == (arch = strchr(
-					r[i].file + isec, '/'))) ? 3 :
-				    (NULL == (archend = strchr(
-					arch + 1, '/'))) ? 0 :
+				    ((arch = strchr(sec + 1, '/'))
+					== NULL) ? 3 :
+				    ((archend = strchr(arch + 1, '/'))
+					== NULL) ? 0 :
 				    strncmp(arch, "amd64/",
 					archend - arch) ? 2 : 1;
 				if (archprio < archpriouse) {
@@ -648,7 +648,7 @@ pg_searchres(const struct req *req, stru
 }
 
 static void
-catman(const struct req *req, const char *file)
+resp_catman(const struct req *req, const char *file)
 {
 	FILE		*f;
 	char		*p;
@@ -658,12 +658,12 @@ catman(const struct req *req, const char
 	int		 italic, bold;
 
 	if ((f = fopen(file, "r")) == NULL) {
-		puts("<P>You specified an invalid manual file.</P>");
+		puts("<p>You specified an invalid manual file.</p>");
 		return;
 	}
 
-	puts("<DIV CLASS=\"catman\">\n"
-	     "<PRE>");
+	puts("<div class=\"catman\">\n"
+	     "<pre>");
 
 	p = NULL;
 	sz = 0;
@@ -689,9 +689,9 @@ catman(const struct req *req, const char
 
 			if ('\b' != p[i + 1]) {
 				if (italic)
-					printf("</I>");
+					printf("</i>");
 				if (bold)
-					printf("</B>");
+					printf("</b>");
 				italic = bold = 0;
 				html_putchar(p[i]);
 				continue;
@@ -702,9 +702,9 @@ catman(const struct req *req, const char
 
 			if ('_' == p[i]) {
 				if (bold)
-					printf("</B>");
+					printf("</b>");
 				if ( ! italic)
-					printf("<I>");
+					printf("<i>");
 				bold = 0;
 				italic = 1;
 				i += 2;
@@ -726,9 +726,9 @@ catman(const struct req *req, const char
 					('*' == p[i] && '|' == p[i + 2]) ||
 					('|' == p[i] && '*' == p[i + 2]))  {
 				if (italic)
-					printf("</I>");
+					printf("</i>");
 				if (bold)
-					printf("</B>");
+					printf("</b>");
 				italic = bold = 0;
 				putchar('*');
 				i += 2;
@@ -740,9 +740,9 @@ catman(const struct req *req, const char
 					('+' == p[i] && '|' == p[i + 1]) ||
 					('|' == p[i] && '+' == p[i + 1]))  {
 				if (italic)
-					printf("</I>");
+					printf("</i>");
 				if (bold)
-					printf("</B>");
+					printf("</b>");
 				italic = bold = 0;
 				putchar('+');
 				i += 2;
@@ -752,9 +752,9 @@ catman(const struct req *req, const char
 			/* Bold mode. */
 
 			if (italic)
-				printf("</I>");
+				printf("</i>");
 			if ( ! bold)
-				printf("<B>");
+				printf("<b>");
 			bold = 1;
 			italic = 0;
 			i += 2;
@@ -767,9 +767,9 @@ catman(const struct req *req, const char
 		 */
 
 		if (italic)
-			printf("</I>");
+			printf("</i>");
 		if (bold)
-			printf("</B>");
+			printf("</b>");
 
 		if (i == len - 1 && p[i] != '\n')
 			html_putchar(p[i]);
@@ -778,14 +778,14 @@ catman(const struct req *req, const char
 	}
 	free(p);
 
-	puts("</PRE>\n"
-	     "</DIV>");
+	puts("</pre>\n"
+	     "</div>");
 
 	fclose(f);
 }
 
 static void
-format(const struct req *req, const char *file)
+resp_format(const struct req *req, const char *file)
 {
 	struct manoutput conf;
 	struct mparse	*mp;
@@ -795,7 +795,7 @@ format(const struct req *req, const char
 	int		 usepath;
 
 	if (-1 == (fd = open(file, O_RDONLY, 0))) {
-		puts("<P>You specified an invalid manual file.</P>");
+		puts("<p>You specified an invalid manual file.</p>");
 		return;
 	}
 
@@ -807,17 +807,12 @@ format(const struct req *req, const char
 	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 : "");
+	mandoc_asprintf(&conf.man, "/%s%s%%N.%%S",
+	    usepath ? req->q.manpath : "", usepath ? "/" : "");
 
 	mparse_result(mp, &man, NULL);
 	if (man == NULL) {
-		fprintf(stderr, "fatal mandoc error: %s/%s\n",
-		    req->q.manpath, file);
+		warnx("fatal mandoc error: %s/%s", req->q.manpath, file);
 		pg_error_internal();
 		mparse_free(mp);
 		mchars_free();
@@ -848,9 +843,9 @@ resp_show(const struct req *req, const c
 		file += 2;
 
 	if ('c' == *file)
-		catman(req, file);
+		resp_catman(req, file);
 	else
-		format(req, file);
+		resp_format(req, file);
 }
 
 static void
@@ -881,18 +876,12 @@ pg_show(struct req *req, const char *ful
 	 */
 
 	if (chdir(manpath) == -1) {
-		fprintf(stderr, "chdir %s: %s\n",
-		    manpath, strerror(errno));
+		warn("chdir %s", manpath);
 		pg_error_internal();
 		free(manpath);
 		return;
 	}
-
-	if (strcmp(manpath, "mandoc")) {
-		free(req->q.manpath);
-		req->q.manpath = manpath;
-	} else
-		free(manpath);
+	free(manpath);
 
 	if ( ! validate_filename(file)) {
 		pg_error_badrequest(
@@ -901,7 +890,7 @@ pg_show(struct req *req, const char *ful
 	}
 
 	resp_begin_html(200, NULL);
-	resp_searchform(req);
+	resp_searchform(req, FOCUS_NONE);
 	resp_show(req, file);

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-all mailing list