dot

packages and services management
Log | Files | Refs | README

commit e525c874445c5ce935f8c529034ab74fbb3dc52c
parent 6ffaf15f7d0eff3fedc694852f37f90add81acc1
Author: Josuah Demangeon <mail@josuah.net>
Date:   Mon, 27 Nov 2017 01:03:04 +0100

view-source does not work

Diffstat:
Mbin/gph-html | 48++++++++++++++++++++++++++++++------------------
1 file changed, 30 insertions(+), 18 deletions(-)

diff --git a/bin/gph-html b/bin/gph-html @@ -1,7 +1,7 @@ #!/bin/sh # convert all *.gph in current directory to html -find "$1" -name '*.gph' -exec sh -c 'awk '"'"' +awk=' function escape(str) { @@ -12,15 +12,28 @@ function escape(str) return str; } +function url(tail) +{ + split(tail, fields, "|"); + path = fields[2]; + host = fields[3]; + port = fields[4]; + if (host == "server") + host = ""; + if (port == "port") + port = ""; + else + port = ":" port; + return sprintf("%s%s%s", host, port, path); +} + function link(type, tail) { - path = tail; + sub("\\]$", "", tail); + addr = url(tail); desc = tail; - sub("[^|]*\\|", "", path); - sub("URL:", "", path); - sub("\\|.*", "", path); sub("\\|.*", "", desc); - return sprintf("<a href=\"%s\">%-7s</a> %s", path, type, escape(desc)); + return sprintf("<a href=\"%s\">%-4s</a>+ %s", addr, type, escape(desc)); } BEGIN { @@ -28,28 +41,28 @@ BEGIN { } sub("^t", "") { - print("\t" escape($0)); + print(" | " escape($0)); next; } sub("^\\[i\\|", "") { sub("\\|.*", "", $0); - print("\t" escape($0)); + print(" | " escape($0)); next; } sub("^\\[0\\|", "") { - print(link("file", $0)); + print(link("File", $0)); next; } sub("^\\[1\\|", "") { - print(link("dir", $0)); + print(link("Dir", $0)); next; } sub("^\\[8\\|", "") { - print(link("telnet", $0)); + print(link("Tnet", $0)); next; } @@ -59,22 +72,21 @@ sub("^\\[h\\|", "") { } sub("^\\[g\\|", "") || sub("^\\[I", "") { + sub("\\]$", "", $0); desc = $0; - path = $0; - sub("[^|]*\\|", "", path); + addr = url($0); sub("\\|.*", "", desc); - sub("\\|.*", "", path); - print("<img alt=\"" escape(desc) "\" src=\"" path "\"/>"); + printf("<img alt=\"%s\" src=\"%s\"/>", escape(desc), addr); next; } { - print("\t" escape($0)); + print(" | " escape($0)); next } END { print("</pre>"); -} +}' -'"'"' "$0" > "${0%.gph}.html" ' {} ';' +find "$1" -name '*.gph' -exec sh -c "awk '$awk' "'"$0" > "${0%.gph}.html"' {} ';'