=================================================================== RCS file: /cvs/mandoc/cgi.c,v retrieving revision 1.171 retrieving revision 1.176 diff -u -p -r1.171 -r1.176 --- mandoc/cgi.c 2020/01/10 15:21:19 1.171 +++ mandoc/cgi.c 2021/11/05 17:04:10 1.176 @@ -1,7 +1,7 @@ -/* $Id: cgi.c,v 1.171 2020/01/10 15:21:19 schwarze Exp $ */ +/* $Id: cgi.c,v 1.176 2021/11/05 17:04:10 schwarze Exp $ */ /* + * Copyright (c) 2014-2019, 2021 Ingo Schwarze * Copyright (c) 2011, 2012 Kristaps Dzonsons - * Copyright (c) 2014-2019 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -14,6 +14,8 @@ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Implementation of the man.cgi(8) program. */ #include "config.h" @@ -70,9 +72,9 @@ enum focus { static void html_print(const char *); static void html_putchar(char); static int http_decode(char *); -static void http_encode(const char *p); +static void http_encode(const char *); static void parse_manpath_conf(struct req *); -static void parse_path_info(struct req *req, const char *path); +static void parse_path_info(struct req *, const char *); static void parse_query_string(struct req *, const char *); static void pg_error_badrequest(const char *); static void pg_error_internal(void); @@ -120,16 +122,18 @@ static const char *const sec_names[] = { static const int sec_MAX = sizeof(sec_names) / sizeof(char *); static const char *const arch_names[] = { - "amd64", "alpha", "armv7", "arm64", - "hppa", "i386", "landisk", - "loongson", "luna88k", "macppc", "mips64", - "octeon", "sgi", "socppc", "sparc64", + "amd64", "alpha", "armv7", "arm64", + "hppa", "i386", "landisk", "loongson", + "luna88k", "macppc", "mips64", "octeon", + "powerpc64", "riscv64", "sparc64", + "amiga", "arc", "armish", "arm32", "atari", "aviion", "beagle", "cats", "hppa64", "hp300", "ia64", "mac68k", "mvme68k", "mvme88k", "mvmeppc", "palm", "pc532", "pegasos", - "pmax", "powerpc", "solbourne", "sparc", + "pmax", "powerpc", "sgi", "socppc", + "solbourne", "sparc", "sun3", "vax", "wgrisc", "x68k", "zaurus" }; @@ -366,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); @@ -381,12 +386,27 @@ resp_begin_html(int code, const char *msg, const char " ", 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\n" "\n" @@ -859,7 +879,7 @@ resp_format(const struct req *req, const char *file) int fd; int usepath; - if (-1 == (fd = open(file, O_RDONLY, 0))) { + if (-1 == (fd = open(file, O_RDONLY))) { puts("

You specified an invalid manual file.

"); return; }