aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2021-08-19 15:23:36 +0000
committerIngo Schwarze <schwarze@openbsd.org>2021-08-19 15:23:36 +0000
commitcbbdb9798fbefe0870d5857631fb51afe0697da2 (patch)
tree0ee75625011abc0e356860629f443b7a6e13fc4f
parente7b68c6d2c0067916b7389ffc4ae72b567852c95 (diff)
downloadmandoc-cbbdb9798fbefe0870d5857631fb51afe0697da2.tar.gz
mandoc-cbbdb9798fbefe0870d5857631fb51afe0697da2.tar.zst
mandoc-cbbdb9798fbefe0870d5857631fb51afe0697da2.zip
fix the section number in the <title> element for preformatted pages;
minibug reported by Ian <Ropers at gmail dot com> on misc@
-rw-r--r--cgi.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/cgi.c b/cgi.c
index 31f1dcf4..91310ce4 100644
--- a/cgi.c
+++ b/cgi.c
@@ -1,6 +1,6 @@
-/* $Id: cgi.c,v 1.174 2021/05/13 13:33:11 schwarze Exp $ */
+/* $Id: cgi.c,v 1.175 2021/08/19 15:23:36 schwarze Exp $ */
/*
- * 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 *msg, const char *file)
" <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"