#!/usr/bin/awk -f function urlize(type, selector, host, port) { return "gopher://" host ":" port "/" type selector } function encode(html) { gsub(/&/, "\\&", html) gsub(/, "\\<", html) gsub(/>/, "\\>", html) return html } BEGIN { FS = "\t" # XXX: Strictly speaking RS should be `\r\n'. However, in the wild it # XXX: can happens that the `\r' is missing. Address that and then strip # XXX: trailing `\r' when parsing responses. RS = "\n" TYPE["file"] = "0" TYPE["directory"] = "1" TYPE["error"] = "3" TYPE["search"] = "7" TYPE["html"] = "h" TYPE["info"] = "i" TYPE["picture"] = "p" TYPE["sound"] = "s" # Print the header print "" print "
" print ""
}
{
sub(/^\r/, "")
sub(/\r$/, "")
type = substr($1, 1, 1)
user_name = substr($1, 2)
selector = $2
host = $3
port = $4
}
$0 == "." {
# (nothing)
next
}
# Text entry (euristically!)
NF != 4 {
printf("%s\n", encode($0))
next
}
type == TYPE["file"] || type == TYPE["directory"] {
printf("%s\n", urlize(type, selector, host, port), encode(user_name))
}
type == TYPE["error"] {
# TODO
}
type == TYPE["search"] {
printf("\n")
}
type == TYPE["info"] {
printf("%s\n", encode(user_name))
}
type == TYPE["html"] {
url = substr(selector, 5) # strip `URL:' prefix
printf("%s\n", url, encode(user_name))
}
type == TYPE["picture"] {
printf("