]> git.cameronkatri.com Git - mandoc.git/blobdiff - cgi.c
Make sure that the configuration file is always read, even when
[mandoc.git] / cgi.c
diff --git a/cgi.c b/cgi.c
index 6d0e3293a95db6fa58fc79f6d3401ede0b2eee9f..b728c7384beca2f59a27294c8369602a18e75270 100644 (file)
--- a/cgi.c
+++ b/cgi.c
@@ -1,6 +1,6 @@
-/* $Id: cgi.c,v 1.172 2020/04/03 11:35:01 schwarze Exp $ */
+/* $Id: cgi.c,v 1.176 2021/11/05 17:04:10 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
@@ -122,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"
 };
@@ -368,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);
 
@@ -383,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"
@@ -861,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("<p>You specified an invalid manual file.</p>");
                return;
        }