summaryrefslogtreecommitdiffstats
path: root/cgi.c
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
commitc8b9d4298c238425ec68dad55b5f7411180338b6 (patch)
tree015eeec70e92ede08531349ae8ab16548a17725c /cgi.c
parent510f116a58364ccf5c3399f053bfacc9d675025c (diff)
downloadmandoc-c8b9d4298c238425ec68dad55b5f7411180338b6.tar.gz
fix the section number in the <title> element for preformatted pages;
minibug reported by Ian <Ropers at gmail dot com> on misc@
Diffstat (limited to 'cgi.c')
-rw-r--r--cgi.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/cgi.c b/cgi.c
index 363b1a82..4e59b274 100644
--- a/cgi.c
+++ b/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 *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"