stagit-gopher

[fork] gopher git frontend
Log | Files | Refs | README | LICENSE

commit d97002d21462133dbd3b0f37732a62b2f5f4a529
parent 05fb5a9a9cc33ea54b3df72f0caa762519a0ccaa
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Thu, 15 Jun 2017 21:44:47 +0200

improvements

- utf-8 ellipsis to indicate truncation
- minor style and documentation fixes
- escape [ properly also
- add atom feed link (only below log lines).

Diffstat:
MREADME | 1+
Mstagit-gopher-index.c | 5++++-
Mstagit-gopher.c | 14++++++++++----
3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/README b/README @@ -31,6 +31,7 @@ $ make Dependencies ------------ +- geomyidae (for .gph file serving). - libgit2 (v0.22+). - libc (tested with OpenBSD, FreeBSD, glibc and musl). - C compiler (C99). diff --git a/stagit-gopher-index.c b/stagit-gopher-index.c @@ -43,6 +43,10 @@ printutf8pad(FILE *fp, const char *s, size_t len, int pad) if ((r = wcwidth(w)) == -1) r = 1; n += (size_t)r; + if (n >= len) { + fputs("\xe2\x80\xa6", fp); + break; + } } putc(*s, fp); } @@ -182,7 +186,6 @@ usage(const char *argv0) exit(1); } - int main(int argc, char *argv[]) { diff --git a/stagit-gopher.c b/stagit-gopher.c @@ -81,14 +81,19 @@ printutf8pad(FILE *fp, const char *s, size_t len, int pad) for (i = 0; *s && n < len; i++, s++) { if (ISUTF8(*s)) { - if ((r = mbtowc(&w, s, 4)) == -1) + if (mbtowc(&w, s, 4) == -1) break; if ((r = wcwidth(w)) == -1) r = 1; n += (size_t)r; + if (n >= len) { + fputs("\xe2\x80\xa6", fp); + break; + } } putc(*s, fp); } + for (; n < len; n++) putc(pad, fp); } @@ -313,7 +318,7 @@ gphtext(FILE *fp, const char *s, size_t len) n = 0; /* escape 't' at the start of a line */ - if (!n && s[i] == 't') { + if (!n && (s[i] == 't' || s[i] == '[')) { fputc('t', fp); n = 1; } @@ -340,7 +345,7 @@ gphlink(FILE *fp, const char *s, size_t len) fputc(' ', fp); break; case '\r': /* ignore CR */ - case '|': /* ignore separators for now */ + case '|': /* ignore separators here */ break; case '\t': fputs(" ", fp); @@ -1056,7 +1061,6 @@ usage(char *argv0) exit(1); } -/* TODO: add base argument, gopher does not support relative urls, document it too */ int main(int argc, char *argv[]) { @@ -1167,6 +1171,7 @@ main(int argc, char *argv[]) fp = efopen("log.gph", "w"); mkdir("commit", 0755); writeheader(fp, "Log"); + fprintf(fp, "%-16.16s ", "Date"); fprintf(fp, "%-50.50s ", "Commit message"); fprintf(fp, "%-25.25s\n", "Author"); @@ -1208,6 +1213,7 @@ main(int argc, char *argv[]) if (head) writelog(fp, head); } + fprintf(fp, "\n[1|Atom feed|%satom.xml|server|port]\n", relpath); writefooter(fp); fclose(fp);