From 710062d6e1ed8c891a2888d767039ee85af89b3a Mon Sep 17 00:00:00 2001 From: Adolfo Perez Alvarez Date: Wed, 8 Jun 2022 10:07:41 +0000 Subject: [PATCH] Initial commit --- LICENSE | 24 ++++++++++++++++++++++++ Makefile | 8 ++++++++ README.md | 3 +++ bwrap | 15 +++++++++++++++ bwrap.1 | 45 +++++++++++++++++++++++++++++++++++++++++++++ hppt | 12 ++++++++++++ hppt.1 | 31 +++++++++++++++++++++++++++++++ mkgmap | 15 +++++++++++++++ mkgmap.1 | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ rot | 11 +++++++++++ rot.1 | 25 +++++++++++++++++++++++++ scmfmt | 37 +++++++++++++++++++++++++++++++++++++ scmfmt.1 | 39 +++++++++++++++++++++++++++++++++++++++ unpage | 13 +++++++++++++ unpage.1 | 20 ++++++++++++++++++++ upcasetl | 3 +++ upcasetl.1 | 42 ++++++++++++++++++++++++++++++++++++++++++ 17 files changed, 397 insertions(+) create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100755 bwrap create mode 100644 bwrap.1 create mode 100755 hppt create mode 100644 hppt.1 create mode 100755 mkgmap create mode 100644 mkgmap.1 create mode 100755 rot create mode 100644 rot.1 create mode 100755 scmfmt create mode 100644 scmfmt.1 create mode 100755 unpage create mode 100644 unpage.1 create mode 100755 upcasetl create mode 100644 upcasetl.1 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..68a49da --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ca8525b --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +prefix=$$HOME/opt/pkg/miscutils +target_bin=${prefix}/bin +target_man=${prefix}/share/man/man1 +bin=bwrap hppt mkgmap newp rot scmfmt upcasetl unpage +install: + install -d ${target_bin} ${target_man} + install -c ${bin} ${target_bin} + install -c ${bin:%=%.1} ${target_man} diff --git a/README.md b/README.md new file mode 100644 index 0000000..1f14065 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# miscutils + +Miscellaneous UNIX utilities. diff --git a/bwrap b/bwrap new file mode 100755 index 0000000..284042c --- /dev/null +++ b/bwrap @@ -0,0 +1,15 @@ +#!/usr/bin/awk -f +BEGIN { LINELEN = 64 } +{ + s[++i] = $0; + n = length($0); + maxlen = n > maxlen ? n : maxlen; +} +END { + for (i = 1; i <= maxlen; i += LINELEN) + for (j = 1; j <= NR; j++) { + pref = i == 1 ? "" : ":"; + suff = maxlen - i <= LINELEN ? "" : ":"; + print pref substr(s[j], i, LINELEN) suff; + } +} diff --git a/bwrap.1 b/bwrap.1 new file mode 100644 index 0000000..e4a8571 --- /dev/null +++ b/bwrap.1 @@ -0,0 +1,45 @@ +.Dd April 15, 2022 +.Dt BWRAP 1 +.Os +.Sh NAME +.Nm bwrap +.Nd Wrap input text as a unit +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +Wrap text received in stdin as if it was a single line. +Indicate breaks with the \(dq:\(dq charater at both ends. +.Pp +.Nm +will take the input text as a block, +wrapping the whole thing as a unit. +For normal text this is silly, +but it is useful to make ASCII art look alright in terminals that are not wide enough. +.Sh EXIT STATUS +.Ex -std +.Sh EXAMPLES +.Bd -literal -offset indent +$ fortune | hppt | bwrap + ---------------------------------------------------------------: +|o ooo o ooo o o o o oo o ooo o oo o o oo ooo o ooo : +| o o o o oo oo o o o o oo oooo o : +| o o ooooo o oooooo o oooo o oo oo o ooo oo : +|...............................................................: +|oo o o ooo ooo o o ooo o o o oo o : +| o oo o o o o o o ooo o o: +| oo oooooooo oooooooooooooooooooooooooooooooooooooooooooooooooo: +|oo ooooooo oooooooooo oo oo ooooooo oo ooooo o ooooooooo oooo: + ---------------------------------------------------------------: +:------------------------------------ +:o o oo o o oo oo o o o | +:oo o o oo o o o o oo oo| +:oo o o ooo oooo o ooooo o | +:....................................| +:oo o oo o oo oo o o ooo| +: o o o o o o o o o | +:ooooooo ooooooooooooooooooooooooooo | +:oo oooo oo oooo ooo oooo oo oooooo | +:------------------------------------ +.Ed +.Sh AUTHORS +.An Adolfo Perez Alvarez Aq Mt adolfopa@sdf.org diff --git a/hppt b/hppt new file mode 100755 index 0000000..a423ab8 --- /dev/null +++ b/hppt @@ -0,0 +1,12 @@ +#!/bin/sh +/usr/games/ppt | +rot | +sed ' +1ba +$ba +/^_ *_ *$/d +s/_/|/g +b +:a +s/_/ /g +s/|/-/g' diff --git a/hppt.1 b/hppt.1 new file mode 100644 index 0000000..d534c9e --- /dev/null +++ b/hppt.1 @@ -0,0 +1,31 @@ +.Dd April 14, 2022 +.Dt HPPT 1 +.Os +.Sh NAME +.Nm hppt +.Nd Reformat stdin as a horizontal paper tape +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +Reformat stdin as a horizontal paper tape. +.Sh EXIT STATUS +.Ex -std +.Sh EXAMPLES +.Bd -literal -offset indent +$ echo 'Hello, world!' | hppt + -------------- +| o o oo o | +| o ooo o| +| ooooo oo oo | +|..............| +|o oooo o o o| +| o o | +| oooooooooooo | +|ooooo ooooo | + -------------- +.Ed +.Sh SEE ALSO +.Xr bcd 6 , +.Xr ppt 6 +.Sh AUTHORS +.An Adolfo Perez Alvarez Aq Mt adolfopa@sdf.org diff --git a/mkgmap b/mkgmap new file mode 100755 index 0000000..5e06fa9 --- /dev/null +++ b/mkgmap @@ -0,0 +1,15 @@ +#!/bin/sh +[ -f $HOME/.mkgmap.head ] && cat $HOME/.mkgmap.head +for i in $(ls -r *.txt) +do + date=$(echo $i | sed 's/\(....\)\(..\)\(..\).*/[\1.\2.\3]/') + name=$( + sed -n -e ' + /[^ ]/ { + s/^[ ]*// + p + q + } + b' $i) + printf "0%s %s\t%s\n" "$date" "$name" "$i" +done diff --git a/mkgmap.1 b/mkgmap.1 new file mode 100644 index 0000000..85b37e8 --- /dev/null +++ b/mkgmap.1 @@ -0,0 +1,54 @@ +.Dd May 29, 2022 +.Dt MKGMAP 1 +.Os +.Sh NAME +.Nm mkgmap +.Nd Create a simple Gophermap for the current directory +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +.Nm +generates a simple Gophermap in its standard output, +listing all text files in the current directory +in reverse alphabetical order. +.Pp +File names are assumed to follow the format +.Pa "" Ns Ar date Ns - Ns Ar word Ns -...- Ns Ar word Ns .txt, +where +.Ar date +is a sequence of six digits +\(em 4 for the year, 2 for the month and 2 for the day \(em +and +.Ar word +is a sequence of alphanumerical characters. +For example: +.Bd -literal -offset indent +20220512-this-is-an-example.txt. +.Ed +.Pp +Each Gophermap entry displays the date and the title of the file. +The date is extracted from the file name +and displayed as \(dq[yyyy.mm.dd]\(dq. +The first non empty line of the file is used as the title. +.Pp +If the file +.Pa ~/.mkgmap.head +exists, it will be included at the top of the Gophermap as a header. +.Sh FILES +.Pa ~/.mkgmap.head +.Sh EXIT STATUS +.Ex -std +.Sh EXAMPLES +.Bd -literal -offset indent +$ cat ~/.mkgmap.head # no file / empty +$ ls *.txt +20220601-sample.txt +$ mkgmap +0[2022.06.01] The first line in the file 20220601-sample.txt +$ echo 'Header!' > ~/.mkgmap.head +$ mkgmap +Header! +0[2022.06.01] The first line in the file 20220601-sample.txt +.Ed +.Sh AUTHORS +.An Adolfo Perez Alvarez Aq Mt adolfopa@sdf.org diff --git a/rot b/rot new file mode 100755 index 0000000..6c066d3 --- /dev/null +++ b/rot @@ -0,0 +1,11 @@ +#!/usr/bin/awk -f +{ + m = split($0, a, ""); + n = m > n ? m : n; + for (i = 1; i <= n; i++) + s[i] = s[i]a[i]; +} +END { + for (i = n; i > 0; i--) + print s[i]; +} diff --git a/rot.1 b/rot.1 new file mode 100644 index 0000000..ce5a8a8 --- /dev/null +++ b/rot.1 @@ -0,0 +1,25 @@ +.Dd April 14, 2022 +.Dt ROT 1 +.Os +.Sh NAME +.Nm rot +.Nd Rotate stdin 90 degrees +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +Visually rotate stdin 90 degrees counter clockwise, +swapping rows and columns. +.Sh EXIT STATUS +.Ex -std +.Sh EXAMPLES +.Bd -literal -offset indent +$ printf 'Aa\\nBb\\nCc\\n' +Aa +Bb +Cc +$ printf 'Aa\\nBb\\nCc\\n' | rot +abc +ABC +.Ed +.Sh AUTHORS +.An Adolfo Perez Alvarez Aq Mt adolfopa@sdf.org diff --git a/scmfmt b/scmfmt new file mode 100755 index 0000000..7145d41 --- /dev/null +++ b/scmfmt @@ -0,0 +1,37 @@ +#!/bin/sh +expand | +sed -n ' +/./!d +p +i\ + +:l +n +p +bl' | +sed -n ' +:l +p +n +/./bl +:b +n +/./!bb +i\ + +bl' | +sed -e '1s/^/./' -e 's/^ /./' | +fmt -p | +awk ' +BEGIN { LIMIT = 65 } +NR == 1 || /^[^\.]/ || length($0) < LIMIT { + sub(/^\./, NR == 1 ? "" : " "); + print; +} +/^\./ && length($0) >= LIMIT { + sub(/^\./, " "); + print substr($0, 1, LIMIT)"\\"; + for (i = 2*LIMIT - length($0) + 1; i; i--) + printf " "; + print substr($0, LIMIT+1); +}' diff --git a/scmfmt.1 b/scmfmt.1 new file mode 100644 index 0000000..c375b68 --- /dev/null +++ b/scmfmt.1 @@ -0,0 +1,39 @@ +.Dd April 14, 2022 +.Dt SCMFMT 1 +.Os +.Sh NAME +.Nm scmfmt +.Nd Format a commit message +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +Format stdin to use as a commit message. +.Pp +.Nm +will apply the following formatting rules to the input text: +.Bl -bullet +.It +All leading blank lines will be removed. +Afterwards, any sequence of blanklines will be reduced to a single blank line. +.It +The first non blank line will be interpreted as the title. +This line will be taken as is; no wrapping nor filling will be done. +A blank line will be inserted after the title if one doesn't exist. +.It +If a line is prefixed with tabs or spaces +it will be treated as literal code +These lines will not be filled; instead, a soft wrap will be +simulated, terminating the line with a backslash and +right justifying the rest. +.It +Lines not starting with tabs or spaces will be treated as regular text. +A sequence of these lines will be filled as a single paragraph. +Breaks will only occur at blanks. +.El +.Sh EXIT STATUS +.Ex -std +.Sh SEE ALSO +.Xr fmt 1 , +.Xr par 1 +.Sh AUTHORS +.An Adolfo Perez Alvarez Aq Mt adolfopa@sdf.org diff --git a/unpage b/unpage new file mode 100755 index 0000000..59ff197 --- /dev/null +++ b/unpage @@ -0,0 +1,13 @@ +#!/usr/bin/awk -f +BEGIN { HDLEN = 9; FTLEN = 3 } +NR < HDLEN - 1 { next } +/^$/ { nl++; next} +/^./ { + if (nl == HDLEN) + for (i = 0; i < FTLEN; i++) + getline; + else + while (nl--) print ""; + nl = 0; +} +{ print } diff --git a/unpage.1 b/unpage.1 new file mode 100644 index 0000000..4aa6b12 --- /dev/null +++ b/unpage.1 @@ -0,0 +1,20 @@ +.Dd May 31, 2022 +.Dt UNPAGE 1 +.Os +.Sh NAME +.Nm unpage +.Nd Remove page headers and footers from text documents +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +.Nm +removes all page headers and footers from stdin, +getting as result output that contains a single continuous page. +.Pp +This command expects its input to be the result of processing an ms document +with the default settings. +It will probably not work as expected if the input was created by other means. +.Sh EXIT STATUS +.Ex -std +.Sh AUTHORS +.An Adolfo Perez Alvarez Aq Mt adolfopa@sdf.org diff --git a/upcasetl b/upcasetl new file mode 100755 index 0000000..b7ee166 --- /dev/null +++ b/upcasetl @@ -0,0 +1,3 @@ +#!/usr/bin/awk -f +/^\.(TL|SH)/ { print; getline; print toupper($0); next } +{ print } diff --git a/upcasetl.1 b/upcasetl.1 new file mode 100644 index 0000000..a3e42fc --- /dev/null +++ b/upcasetl.1 @@ -0,0 +1,42 @@ +.Dd Jun 22, 2022 +.Dt UPCASETL 1 +.Os +.Sh NAME +.Nm upcasetl +.Nd Upcase titles and section headers in an ms troff document +.Sh SYNOPSIS +.Nm +.Sh DESCRIPTION +.Nm +takes an ms troff document in stdin, +and outputs to its stdout the same document +with all +.Qq .TL +and +.Qq .SH +content converted to uppercase. +.Sh EXIT STATUS +.Ex -std +.Sh EXAMPLES +.Bd -literal -offset indent +$ cat sample.ms +\&.TL +This is a sample +\&.AU +Me +\&.SH +A section header +\&.PP +Fin +$ upcasetl