dot

packages and services management
Log | Files | Refs | README

commit 74c557b7bf7b6a1be8314e22a1a39b3e96fd4602
parent 3bec40f80561205d21b7e8489d16291b6fcce788
Author: Josuah Demangeon <mail@josuah.net>
Date:   Tue, 10 Apr 2018 10:04:12 +0200

markup-gopher seemingly ready

Diffstat:
Mbin/markup-gopher | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+), 0 deletions(-)

diff --git a/bin/markup-gopher b/bin/markup-gopher @@ -1 +1,58 @@ #!/usr/bin/awk -f + +# format plain text markdown-style document into browsable gophermap + +# It recognises and convert the following patterns: +# +# [tag]: proto://host:port/path +# [tag]: proto://host/path +# [tag]: gopher://host:port/t/path +# [tag]: gopher://host/t/path +# [tag]: //host/t/path +# [tag]: /t/path + +BEGIN { + if (ARGC < 3 || 4 < ARGC) { + print("usage: markup-gph <host> <port> [<file>]"); + exit(1); + } + HOST = ARGV[1]; + PORT = ARGV[2]; + ARGV[1] = ARGV[3]; + ARGC = 1; +} + +match($0, "^\\[[^]]*\\]: ") { + type = "h"; + url = substr($0, RLENGTH + 1); + tag = substr($0, RSTART + 1, RLENGTH - 4); + host = HOST; + port = PORT; + path = ""; + proto = ""; + type = "0"; + if (sub("^gopher://", "", url) || sub("^//", "", url)) { + proto = "gopher://"; + host = url; + path = url; + sub("/.*", "", host); + sub(".*/", "/", path); + print host; + if (match(host, "[a-z.-]+:")) { + port = substr(host, RLENGTH + 1); + host = substr(host, RSTART, RLENGTH - 1); + } + } else if (match(url, "^[a-z]+://")) { + type = "h"; + path = "URL:" url; + } + if (match(url, "^/[01789aghI]/")) + type = substr(url, 2, 1); + printf("%s[%s]: %s%s\t%s\t%s\t%s\n", type, tag, proto, url, path, host, port); + next; +} + +{ + gsub("\t", " "); + print; +}