=================================================================== RCS file: /cvs/mandoc/cgi.c,v retrieving revision 1.176 retrieving revision 1.178 diff -u -p -r1.176 -r1.178 --- mandoc/cgi.c 2021/11/05 17:04:10 1.176 +++ mandoc/cgi.c 2022/07/05 14:04:25 1.178 @@ -1,7 +1,8 @@ -/* $Id: cgi.c,v 1.176 2021/11/05 17:04:10 schwarze Exp $ */ +/* $Id: cgi.c,v 1.178 2022/07/05 14:04:25 schwarze Exp $ */ /* - * Copyright (c) 2014-2019, 2021 Ingo Schwarze + * Copyright (c) 2014-2019, 2021, 2022 Ingo Schwarze * Copyright (c) 2011, 2012 Kristaps Dzonsons + * Copyright (c) 2022 Anna Vyalkova * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -86,10 +87,10 @@ static void pg_search(const struct req *); static void pg_searchres(const struct req *, struct manpage *, size_t); static void pg_show(struct req *, const char *); -static void resp_begin_html(int, const char *, const char *); +static int resp_begin_html(int, const char *, const char *); static void resp_begin_http(int, const char *); static void resp_catman(const struct req *, const char *); -static void resp_copy(const char *); +static int resp_copy(const char *, const char *); static void resp_end_html(void); static void resp_format(const struct req *, const char *); static void resp_searchform(const struct req *, enum focus); @@ -352,22 +353,26 @@ resp_begin_http(int code, const char *msg) fflush(stdout); } -static void -resp_copy(const char *filename) +static int +resp_copy(const char *element, const char *filename) { char buf[4096]; ssize_t sz; int fd; - if ((fd = open(filename, O_RDONLY)) != -1) { - fflush(stdout); - while ((sz = read(fd, buf, sizeof(buf))) > 0) - write(STDOUT_FILENO, buf, sz); - close(fd); - } + if ((fd = open(filename, O_RDONLY)) == -1) + return 0; + + if (element != NULL) + printf("<%s>\n", element); + fflush(stdout); + while ((sz = read(fd, buf, sizeof(buf))) > 0) + write(STDOUT_FILENO, buf, sz); + close(fd); + return 1; } -static void +static int resp_begin_html(int code, const char *msg, const char *file) { const char *name, *sec, *cp; @@ -413,15 +418,15 @@ resp_begin_html(int code, const char *msg, const char "\n", CUSTOMIZE_TITLE); - resp_copy(MAN_DIR "/header.html"); + return resp_copy("header", MAN_DIR "/header.html"); } static void resp_end_html(void) { + if (resp_copy("footer", MAN_DIR "/footer.html")) + puts(""); - resp_copy(MAN_DIR "/footer.html"); - puts("\n" ""); } @@ -431,7 +436,7 @@ resp_searchform(const struct req *req, enum focus focu { int i; - printf("
\n" "
\n" " Manual Page Search Parameters\n", @@ -457,7 +462,7 @@ resp_searchform(const struct req *req, enum focus focu /* Write section selector. */ - puts(" "); for (i = 0; i < sec_MAX; i++) { printf("