diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2021-08-19 15:23:36 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2021-08-19 15:23:36 +0000 |
commit | c8b9d4298c238425ec68dad55b5f7411180338b6 (patch) | |
tree | 015eeec70e92ede08531349ae8ab16548a17725c /cgi.c | |
parent | 510f116a58364ccf5c3399f053bfacc9d675025c (diff) | |
download | mandoc-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.c | 32 |
1 files changed, 24 insertions, 8 deletions
@@ -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" |