import std/os import std/strutils import utils/twtstr func gopherName(c: char): string = return case c of '0': "text file" of '1': "directory" of '3': "error" of '5': "DOS binary" of '7': "search" of 'm': "message" of 's', '<': "sound" of 'g': "gif" of 'h': "HTML" of 'I', ':': "image" of '9': "binary" of 'p': "png" of ';': "video" else: "unsupported" proc main() = if paramCount() != 2 or paramStr(1) != "-u": stdout.writeLine("Usage: gopher2html [-u URL]") quit(1) let url = htmlEscape(paramStr(2)) stdout.write("""
" ispre = true outs &= htmlEscape(name) & '\n' else: if ispre: outs &= "" ispre = false let names = '[' & gopherName(t) & ']' & htmlEscape(name) let ourls = if not file.startsWith("URL:"): if file.len == 0 or file[0] != '/': file = '/' & file let pefile = file.percentEncode(PathPercentEncodeSet) "gopher://" & host & ":" & port & "/" & t & pefile else: file.substr("URL:".len) outs &= "" & names & "