source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: By popular demand, bring man.cgi default mode closer to what
Date: Sun, 13 Jul 2014 08:31:23 -0400 (EDT)	[thread overview]
Message-ID: <201407131231.s6DCVN2G026221@krisdoz.my.domain> (raw)

Log Message:
-----------
By popular demand, bring man.cgi default mode closer to what man(1) does:
Even when there are multiple pages with the same name in different
sections, show one of them, using the same priorities as in the
default man.conf(5) file.

Modified Files:
--------------
    mdocml:
        cgi.c

Revision Data
-------------
Index: cgi.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/cgi.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -Lcgi.c -Lcgi.c -u -p -r1.69 -r1.70
--- cgi.c
+++ cgi.c
@@ -77,10 +77,12 @@ static	void		 resp_noresult(const struct
 static	void		 resp_search(const struct req *,
 				struct manpage *, size_t);
 static	void		 resp_searchform(const struct req *);
+static	void		 resp_show(const struct req *, const char *);
 
 static	const char	 *scriptname; /* CGI script name */
 static	const char	 *httphost; /* hostname used in the URIs */
 
+static	const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
 static	const char *const sec_numbers[] = {
     "0", "1", "2", "3", "3p", "4", "5", "6", "7", "8", "9"
 };
@@ -508,7 +510,9 @@ resp_error_internal(void)
 static void
 resp_search(const struct req *req, struct manpage *r, size_t sz)
 {
-	size_t		 i;
+	size_t		 i, iuse, isec;
+	int		 prio, priouse;
+	char		 sec;
 
 	if (1 == sz) {
 		/*
@@ -550,6 +554,30 @@ resp_search(const struct req *req, struc
 
 	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>");
+		iuse = 0;
+		priouse = 10;
+		for (i = 0; i < sz; i++) {
+			isec = strcspn(r[i].file, "123456789");
+			sec = r[i].file[isec];
+			if ('\0' == sec)
+				continue;
+			prio = sec_prios[sec - '1'];
+			if (prio >= priouse)
+				continue;
+			priouse = prio;
+			iuse = i;
+		}
+		resp_show(req, r[iuse].file);
+	}
+
 	resp_end_html();
 }
 
@@ -563,13 +591,10 @@ catman(const struct req *req, const char
 	int		 italic, bold;
 
 	if (NULL == (f = fopen(file, "r"))) {
-		resp_error_badrequest(
-		    "You specified an invalid manual file.");
+		puts("<P>You specified an invalid manual file.</P>");
 		return;
 	}
 
-	resp_begin_html(200, NULL);
-	resp_searchform(req);
 	puts("<DIV CLASS=\"catman\">\n"
 	     "<PRE>");
 
@@ -683,9 +708,7 @@ catman(const struct req *req, const char
 	}
 
 	puts("</PRE>\n"
-	     "</DIV>\n"
-	     "</BODY>\n"
-	     "</HTML>");
+	     "</DIV>");
 
 	fclose(f);
 }
@@ -702,8 +725,7 @@ format(const struct req *req, const char
 	char		 opts[PATH_MAX + 128];
 
 	if (-1 == (fd = open(file, O_RDONLY, 0))) {
-		resp_error_badrequest(
-		    "You specified an invalid manual file.");
+		puts("<P>You specified an invalid manual file.</P>");
 		return;
 	}
 
@@ -732,9 +754,6 @@ format(const struct req *req, const char
 		return;
 	}
 
-	resp_begin_html(200, NULL);
-	resp_searchform(req);
-
 	vp = html_alloc(opts);
 
 	if (NULL != mdoc)
@@ -742,14 +761,21 @@ format(const struct req *req, const char
 	else
 		html_man(vp, man);
 
-	puts("</BODY>\n"
-	     "</HTML>");
-
 	html_free(vp);
 	mparse_free(mp);
 }
 
 static void
+resp_show(const struct req *req, const char *file)
+{
+
+	if ('c' == *file)
+		catman(req, file);
+	else
+		format(req, file);
+}
+
+static void
 pg_show(const struct req *req, const char *path)
 {
 	char		*sub;
@@ -773,10 +799,10 @@ pg_show(const struct req *req, const cha
 		return;
 	}
 
-	if ('c' == *sub)
-		catman(req, sub);
-	else
-		format(req, sub);
+	resp_begin_html(200, NULL);
+	resp_searchform(req);
+	resp_show(req, sub);
+	resp_end_html();
 }
 
 static void
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-07-13 12:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201407131231.s6DCVN2G026221@krisdoz.my.domain \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).