#!/bin/awk -f # SPDX-License-Identifier: CC0-1.0 # License: CC0-1.0 # Andreas K. Foerster # Filter to make a gopher menu more readable for humans # # usage: # $ curl gopher://gopher.example.net/1/ | gophermenu | less # use it only for type 1 and 7 BEGIN { FS = "\t"; RS = "\r?\n"; action = " -> " } # dot alone on a line /^\.$/ { exit } # ignore entries with less than 4 fields NF < 4 { next } # for every entry { printf "%.1s| ", $1 name = substr ($1, 2) selector = $2 host = $3 port = int ($4) } # URL (for any type, suggested: h) selector ~ /^URL:/ { print name printf " | %s%s\n", action, substr (selector, 5) next } # Information /^i/ { print name; next } # Gopher type /^[0145679+gIhsdrpPXM:;<]/ { print name if (selector ~ /^\//) selector = substr (selector, 2) printf " | %sgopher://%s", action, host if (port != 70) printf ":%d", port printf "/%.1s/%s", $1, selector # search string appended by %09 if (/^7/) printf "%%09..." print "" next } # Telnet / Telnet 3270 /^[8T]/ { cmd = /^T/ ? "x3270" : "telnet" print name printf " | %s$ %s %s", action, cmd, host # not default port? if (port != 23) printf " %d", port # login given? if (selector != "" && selector !~ /^\/?none/) printf "\t\t[login: %s]", selector print "" next } # CCSO/ph /^2/ { print name printf " | %s$ ph -s %s", action, host # not default port? if (port != 105) printf " -p %d", port print "" next } # Error message /^3/ { print "!!!", name, "!!!"; next }