tttml-gopher - tttml - converters for a simpler syntax than markdown HTML git clone git://bitreich.org/tttml git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/tttml DIR Log DIR Files DIR Refs DIR Tags DIR README --- tttml-gopher (1722B) --- 1 #!/usr/bin/awk -f 2 3 # format plain text markdown-style document into browsable gophermap 4 5 # It recognises and convert the following patterns: 6 # 7 # [tag]: proto://host:port/path 8 # [tag]: proto://host/path 9 # [tag]: gopher://host:port/t/path 10 # [tag]: gopher://host/t/path 11 # [tag]: t/path 12 13 BEGIN { 14 if (ARGC < 3 || 4 < ARGC) { 15 print("usage: tttml-gph <host> <port> [<file>]"); 16 exit(1); 17 } 18 HOST = ARGV[1]; 19 PORT = ARGV[2]; 20 ARGV[1] = ARGV[3]; 21 ARGC = 2; 22 } 23 24 match($0, "^\\[[^]]*\\]: ") { 25 host = HOST; uri = substr($0, RLENGTH + 1); 26 port = PORT; tag = substr($0, 2, RLENGTH - 4); 27 path = uri; type = "0"; 28 29 sub("^[ \t]*", "", uri); 30 31 if (match(uri, "^[01789aghI]/")) { 32 type = substr(uri, 1, 1); 33 path = uri; sub(".", "", path); 34 35 } else if (sub("^gopher://", "", uri)) { 36 host = uri; sub("/.*", "", host); 37 if (match(host, "[a-z.-]+:")) { 38 port = substr(host, RLENGTH + 1); 39 host = substr(host, RSTART, RLENGTH - 1); 40 } 41 42 path = uri; sub(".*/", "/", path); 43 if (match(path, "^/./")) { 44 type = substr(path, 2, 1); 45 sub("^/./", "/", path); 46 } else if (match(path, "^/?$")) { 47 type = "1"; 48 } else { 49 type = "3"; 50 } 51 52 } else if (match(uri, "^/")) { 53 path = uri; 54 type = sub("/$", "", uri) ? "1" : "0"; 55 56 } else { 57 path = "URL:" uri; 58 type = "h"; host = ""; port = ""; 59 } 60 61 for (name = ""; match($0, /[^ \t]/); name = name " " $0) 62 if (!getline) { end = 1; break; } 63 if (name == "" || name == " ") 64 name = " " uri; 65 66 printf("%s%s:%s\t%s\t%s\t%s\n", type, tag, name, path, host, port); 67 68 if (end) exit; 69 } 70 71 /^###+ / { sub("##", ""); gsub("#", "•"); } 72 /^=+$/ { gsub("=", "━"); } 73 /^-+$/ { gsub("-", "─"); } 74 /^\t/ { sub("^\t", "│ "); } 75 76 { 77 gsub("\t", " "); 78 printf("i%s\t\t\t\n", $0); 79 }