dot

packages and services management
Log | Files | Refs | README

commit 331bbbaee8d283e9680664f09fddeab5c48b3a85
parent 8e4fce819a27096258b7cb986d3f910f743c71b5
Author: Josuah Demangeon <mail@josuah.net>
Date:   Tue, 13 Feb 2018 21:56:16 +0100

[ref] awk-only gopher-proxy

Diffstat:
Mbin/gopher-proxy | 66+++++++++++++++++++++++++++++-------------------------------------
Mbin/xdg-open | 6+++---
Apack/os-dragonflybsd/git | 1+
3 files changed, 33 insertions(+), 40 deletions(-)

diff --git a/bin/gopher-proxy b/bin/gopher-proxy @@ -1,14 +1,10 @@ -#!/bin/sh +#!/usr/bin/awk -f # proxy from gopher to http and html for use with inetd # # /etc/inetd.conf: -# gopher-proxy stream tcp nowait root /path/gopher-proxy gopher-proxy host +# gopher-proxy stream tcp nowait root /.../gopher-proxy gopher-proxy host -#--- parse url ----------------------------------------------------------------- - -# host[:port][/flag/path] -IFS=' ' read host port flag path << EOF -$(awk '{ +{ sub("^GET /(gopher://)?", ""); sub(" HTTP/[0-9].*$", ""); gsub(" ", "%20"); gsub("\t", "%0b"); @@ -44,14 +40,7 @@ $(awk '{ path = $0; printf("%s\t%s\t%s\t%s", host, port, flag, path); - exit; -}') -EOF - -#--- content ------------------------------------------------------------------- - -printf '/%s\n' "$path" | nc -w 2 -- "$host" "$port" | -awk -v HOST="$1" -v FLAG="$flag" ' +} function esc(str) { @@ -74,34 +63,37 @@ function link(type, f) return sprintf("<a href=\"%s\">%s</a> %s", url(f), type, esc(f[1])); } -BEGIN { +END { + gsub("'", "", host); + gsub("'", "", port); + + cmd = "nc -w 2 -- '" host "' '" port "'" + print("HTTP/1.1 200 OK\r"); print("Content-Encoding: UTF-8\r"); print("Content-Type: text/html; charset=UTF-8\r"); print("\r"); print("<!doctype html><title>gopher proxy</title><pre>"); -} - -FLAG == "0" { - print(esc($0)); - next; -} -FLAG == "1" || FLAG == "." { - sub("\r$", ""); - split($0, f, "\t"); - f[0] = substr(f[1], 1, 1); - sub(".", "", f[1]); -} + if (FLAG == "0") { + print(esc($0)); + next; + } else if (flag == "1" || flag == ".") { + sub("\r$", ""); + split($0, f, "\t"); + f[0] = substr(f[1], 1, 1); + sub(".", "", f[1]); + } -f[0] == "i" { printf(" %s\n", esc(f[1])); next; } -f[0] == "0" { print(link("txt", f)); next; } -f[0] == "1" { print(link("dir", f)); next; } -f[0] == "8" { print(link("net", f)); next; } -f[0] == "h" { print(link("url", f)); next; } -f[0] == "g" { print(link("img", f)); next; } -f[0] == "I" { print(link("img", f)); next; } + while (cmd | getline) { + if (f[0] == "i") { printf(" %s\n", esc(f[1])); next; } + else if (f[0] == "0") { print(link("txt", f)); next; } + else if (f[0] == "1") { print(link("dir", f)); next; } + else if (f[0] == "8") { print(link("net", f)); next; } + else if (f[0] == "h") { print(link("url", f)); next; } + else if (f[0] == "g") { print(link("img", f)); next; } + else if (f[0] == "I") { print(link("img", f)); next; } + } -END { print("</pre>"); -}' +} diff --git a/bin/xdg-open b/bin/xdg-open @@ -118,8 +118,8 @@ case "${scheme}" in ;; (*.pdf|*.ps) mkdir -p "${LIB}/doc/${host}" - curl -Lo "${LIB}/doc/${host}"/${path##*/}" "${1}" - exec "${0}" "${LIB}/doc/${host}"/${path##*/}" + curl -Lo "${LIB}/doc/${host}/${path##*/}" "${1}" + exec "${0}" "${LIB}/doc/${host}/${path##*/}" ;; (*.txt) mkdir -p "${LIB}/text/${host}" @@ -183,7 +183,7 @@ esac exec transmission-cli "${1}" ;; (*.img|*.iso) - exec qemu-start "${1}" + exec qemu-system-x86_64 -m 500M "${1}" ;; #--- media --------------------------------------------------------------------- (*.pdf) diff --git a/pack/os-dragonflybsd/git b/pack/os-dragonflybsd/git @@ -0,0 +1 @@ +git://git.dragonflybsd.org/dragonfly.git