+ return EXIT_SUCCESS;
+}
+
+/*
+ * Translate PATH_INFO to a query.
+ */
+static void
+parse_path_info(struct req *req, const char *path)
+{
+ const char *name, *sec, *end;
+
+ req->isquery = 0;
+ req->q.equal = 1;
+ req->q.manpath = NULL;
+ req->q.arch = NULL;
+
+ /* Mandatory manual page name. */
+ if ((name = strrchr(path, '/')) == NULL)
+ name = path;
+ else
+ name++;
+
+ /* Optional trailing section. */
+ sec = strrchr(name, '.');
+ if (sec != NULL && isdigit((unsigned char)*++sec)) {
+ req->q.query = mandoc_strndup(name, sec - name - 1);
+ req->q.sec = mandoc_strdup(sec);
+ } else {
+ req->q.query = mandoc_strdup(name);
+ req->q.sec = NULL;
+ }
+
+ /* Handle the case of name[.section] only. */
+ if (name == path)
+ return;
+
+ /* Optional manpath. */
+ end = strchr(path, '/');
+ req->q.manpath = mandoc_strndup(path, end - path);
+ if (validate_manpath(req, req->q.manpath)) {
+ path = end + 1;
+ if (name == path)
+ return;
+ } else {
+ free(req->q.manpath);
+ req->q.manpath = NULL;
+ }
+
+ /* Optional section. */
+ if (strncmp(path, "man", 3) == 0 || strncmp(path, "cat", 3) == 0) {
+ path += 3;
+ end = strchr(path, '/');
+ free(req->q.sec);
+ req->q.sec = mandoc_strndup(path, end - path);
+ path = end + 1;
+ if (name == path)
+ return;
+ }
+
+ /* Optional architecture. */
+ end = strchr(path, '/');
+ if (end + 1 != name) {
+ pg_error_badrequest(
+ "You specified too many directory components.");
+ exit(EXIT_FAILURE);
+ }
+ req->q.arch = mandoc_strndup(path, end - path);
+ if (validate_arch(req->q.arch) == 0) {
+ pg_error_badrequest(
+ "You specified an invalid directory component.");
+ exit(EXIT_FAILURE);
+ }