source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: fix the section number in the <title> element for preformatted
@ 2021-08-19 15:24 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2021-08-19 15:24 UTC (permalink / raw)
  To: source

Log Message:
-----------
fix the section number in the <title> element for preformatted pages;
minibug reported by Ian <Ropers at gmail dot com> on misc@

Modified Files:
--------------
    mandoc:
        cgi.c

Revision Data
-------------
Index: cgi.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/cgi.c,v
retrieving revision 1.174
retrieving revision 1.175
diff -Lcgi.c -Lcgi.c -u -p -r1.174 -r1.175
--- cgi.c
+++ cgi.c
@@ -1,6 +1,6 @@
 /* $Id$ */
 /*
- * Copyright (c) 2014-2019 Ingo Schwarze <schwarze@usta.de>
+ * Copyright (c) 2014-2019, 2021 Ingo Schwarze <schwarze@usta.de>
  * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -370,7 +370,8 @@ resp_copy(const char *filename)
 static void
 resp_begin_html(int code, const char *msg, const char *file)
 {
-	char	*cp;
+	const char	*name, *sec, *cp;
+	int		 namesz, secsz;
 
 	resp_begin_http(code, msg);
 
@@ -385,12 +386,27 @@ resp_begin_html(int code, const char *ms
 	       "  <title>",
 	       CSS_DIR);
 	if (file != NULL) {
-		if ((cp = strrchr(file, '/')) != NULL)
-			file = cp + 1;
-		if ((cp = strrchr(file, '.')) != NULL) {
-			printf("%.*s(%s) - ", (int)(cp - file), file, cp + 1);
-		} else
-			printf("%s - ", file);
+		cp = strrchr(file, '/');
+		name = cp == NULL ? file : cp + 1;
+		cp = strrchr(name, '.');
+		namesz = cp == NULL ? strlen(name) : cp - name;
+		sec = NULL;
+		if (cp != NULL && cp[1] != '0') {
+			sec = cp + 1;
+			secsz = strlen(sec);
+		} else if (name - file > 1) {
+			for (cp = name - 2; cp >= file; cp--) {
+				if (*cp < '1' || *cp > '9')
+					continue;
+				sec = cp;
+				secsz = name - cp - 1;
+				break;
+			}
+		}
+		printf("%.*s", namesz, name);
+		if (sec != NULL)
+			printf("(%.*s)", secsz, sec);
+		fputs(" - ", stdout);
 	}
 	printf("%s</title>\n"
 	       "</head>\n"
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-19 15:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-19 15:24 mandoc: fix the section number in the <title> element for preformatted schwarze

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).