phroxy

Gopher to HTTP proxy
git clone git://git.z3bra.org/phroxy.git
Log | Files | Refs | LICENSE

commit c0fb38b06388606d2e946528858a523b0cd0a280
parent 3f1b87eb0e31a6f42bef4f4673ced6e446a2b335
Author: Willy Goiffon <dev@z3bra.org>
Date:   Thu, 24 Sep 2020 10:23:18 +0200

Ditch <p> and <pre> tags. Improve menu formatting

Diffstat:
Mphroxy.c | 22++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/phroxy.c b/phroxy.c @@ -232,8 +232,8 @@ int printmenu(int fd, char *data) { char i, *p, a[LINE_MAX], *f[4]; - char *ifmt = "%s\n"; - char *afmt = "<a href='http://%s/%s:%s/%c%s'>%s (%s)</a>\n"; + char *ifmt = "<div class='item'><span></span><pre>%s</pre></div>\n"; + char *afmt = "<div class='item'><span>%s</span><a href='http://%s/%s:%s/%c%s'><pre>%s</pre></a></div>\n"; p = data; @@ -253,7 +253,7 @@ printmenu(int fd, char *data) snprintf(a, sizeof(a), ifmt, f[0]); break; default: - snprintf(a, sizeof(a), afmt, http_host, f[2], f[3], i, f[1], f[0], itemname(i)); + snprintf(a, sizeof(a), afmt, itemname(i), http_host, f[2], f[3], i, f[1], f[0]); } write(fd, a, strlen(a)); @@ -270,25 +270,19 @@ printhtml(int fd, const char *data, size_t len) const char *s, *e; n = 0; + write(fd, "<pre>", 5); while(n < len) { s = data + n; e = strstr(s, "\n\n"); - r = e ? (size_t)(e - s) : strlen(s); + r = e ? (size_t)(e - s + 2) : strlen(s); + n += r; if (!r) break; - n += r + 2; /* go past "\n\n" */ - if (strstr(s, " ") && strstr(s, " ") < e) { - write(fd, "<pre>", 5); - write(fd, s, r); - write(fd, "</pre>\n", 7); - } else { - write(fd, "<p>", 3); - write(fd, s, r); - write(fd, "</p>\n", 5); - } + write(fd, s, r); } + write(fd, "</pre>\n", 7); return 0; }