#!/bin/sh # tp - Question the Elision toki pona UDP server hosted under verisimilitudes.net, for a GNU system. # Written in 2022 by Prince Trippy . # To the extent possible under law, the author(s) have dedicated all copyright and related and # neighboring rights to this software to the public domain worldwide. # This software is distributed without any warranty. # You should have received a copy of the CC0 Public Domain Dedication along with this software. # If not, see . # There's a great deal wrong with this tiny sh work; I'll list the wrongs of this inhuman centipede. # I tried to use echo, but there's no way to correctly do so; even passing in -n is not a guarantee. # So, I begrudgingly used printf, and yet even there I must use env to get the correct little piece. # The OpenBSD nc surprisingly has a flag ideal for this program which GNU Netcat lacks, the -W flag. # That allows decoupling the timeout from the packet receival, and this program would use -w 3 -W 1. # Unfortunately, I must instead use the timeout command for it, which gives unpleasant consequences. # In all likelihood, one second is more than enough, but this program will usually hang for so long. # To avoid pipeline disruptions and malicious messages, since control characters can cause such, the # tr command is used solely and wastefully to translate any such characters for the latter commands. # I happened upon the fold command, and ain't particularly disgusted with it; it's not unreasonable. # I noticed cut repeats across lines, so fold is used to set individual records on individual lines. # Lastly, the cut command is mostly a waste, since each record has but two fields, but oh well. The # later work for this manner of program will have more, so I may as well keep basic structures here. # While writing this awful little program, I noticed it shares a basic design with my gopher server. # This language is so terrible that I prevent allowing any data to leave the stupid little pipeline. # I avoid needing any loops because the data is transformed specifically to remove the need of them. # This resembles John Backus' FP, if the environment and primitives were designed by idiots instead. # More recently, I've given an output display option, and the ability to ask many questions with one # command. I made the sh program tail-recursive with tail-call optimization, using no arguments for # the base case. I've also added two variables, one to parameterize the cut call, and it had to use # two lines, because damned fools specifically prevent something such as `echo` from working for it. set -e f=""; d=" " if [ "$1" = "-" ]; then f="-"; d=" "; shift; fi if [ "$#" -eq 0 ]; then exit; fi env printf '%s\c' "$1" | timeout 1s netcat --udp verisimilitudes.net 2001 2>/dev/null | tr '[:cntrl:]' '[ *]' | fold --bytes --width=48 | cut --bytes=-16,17- --output-delimiter "$d" shift exec "$0" $f "$@" .