diff options
author | June McEnroe <june@causal.agency> | 2020-12-15 23:52:37 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-12-15 23:52:37 -0500 |
commit | c401b3d4af2462e96aa327f1282e2882aa94609a (patch) | |
tree | 8c803064ffbb65a37882466a61cedb57de3457aa | |
parent | Add modem -r flag to set baud rate (diff) | |
download | src-c401b3d4af2462e96aa327f1282e2882aa94609a.tar.gz src-c401b3d4af2462e96aa327f1282e2882aa94609a.zip |
Add bibsort
My first perl script! hi doesn't have syntax highlighting for perl, and I don't think I could sanely implement it, but oh well.
-rw-r--r-- | bin/.gitignore | 1 | ||||
-rw-r--r-- | bin/Makefile | 14 | ||||
-rw-r--r-- | bin/README.7 | 4 | ||||
-rw-r--r-- | bin/bibsort.pl | 66 | ||||
-rw-r--r-- | bin/html.sh | 2 | ||||
-rw-r--r-- | bin/man1/bibsort.1 | 37 |
6 files changed, 120 insertions, 4 deletions
diff --git a/bin/.gitignore b/bin/.gitignore index f7c65388..df322fd4 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1,6 +1,7 @@ *.html *.o beef +bibsort bit bri c diff --git a/bin/Makefile b/bin/Makefile index 3ba877c1..5691b0fc 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -20,6 +20,7 @@ LDLIBS.title = -lcurl -include config.mk BINS += beef +BINS += bibsort BINS += bit BINS += c BINS += dtch @@ -65,12 +66,18 @@ tls: meta ${BINS_TLS} meta: .gitignore tags +.SUFFIXES: .pl + .c: ${CC} ${CFLAGS} ${LDFLAGS} $< ${LDLIBS.$@} -o $@ .o: ${CC} ${LDFLAGS} $< ${LDLIBS.$@} -o $@ +.pl: + cp -f $< $@ + chmod a+x $@ + hi: hi.c ${CC} ${CFLAGS} ${LDFLAGS} hi.c ${LDLIBS.$@} -o $@ ./hi -c @@ -127,11 +134,14 @@ ${HTMLS}: html.sh scheme hi ttpre .h.html: sh html.sh $< man3/${<:.h=.3} > $@ +.y.html: + sh html.sh $< man1/${<:.y=.1} > $@ + .sh.html: sh html.sh $< man1/${<:.sh=.1} > $@ -.y.html: - sh html.sh $< man1/${<:.y=.1} > $@ +.pl.html: + sh html.sh $< man1/${<:.pl=.1} > $@ index.html: Makefile README.7 sh html.sh Makefile README.7 \ diff --git a/bin/README.7 b/bin/README.7 index 4ce7fc74..40dcdd0b 100644 --- a/bin/README.7 +++ b/bin/README.7 @@ -1,4 +1,4 @@ -.Dd October 29, 2020 +.Dd December 15, 2020 .Dt BIN 7 .Os "Causal Agency" . @@ -18,6 +18,8 @@ Some tools target Linux. .Bl -tag -width "fbclock(1)" -compact .It Xr beef 1 Befunge-93 interpreter +.It Xr bibsort 1 +reformat bibliography .It Xr bit 1 calculator .It Xr bri 1 diff --git a/bin/bibsort.pl b/bin/bibsort.pl new file mode 100644 index 00000000..5f0ad7ba --- /dev/null +++ b/bin/bibsort.pl @@ -0,0 +1,66 @@ +#!/usr/bin/env perl +use strict; +use warnings; + +while (<>) { + print; + last if /^[.]Sh STANDARDS$/; +} + +my ($ref, @refs); +while (<>) { + next if /^[.](Bl|It|$)/; + last if /^[.]El$/; + if (/^[.]Rs$/) { + $ref = {}; + } elsif (/^[.]%(.) (.*)/) { + $ref->{$1} = [] unless $ref->{$1}; + push @{$ref->{$1}}, $2; + } elsif (/^[.]Re$/) { + push @refs, $ref; + } else { + print; + } +} + +sub byLast { + my ($af, $al) = split /\s/, $a, 2; + my ($bf, $bl) = split /\s/, $b, 2; + $al cmp $bl || $af cmp $bf; +} + +foreach $ref (@refs) { + @{$ref->{A}} = sort byLast @{$ref->{A}}; + @{$ref->{Q}} = sort @{$ref->{Q}} if $ref->{Q}; + next unless $ref->{N}; + if ($ref->{N}[0] =~ /RFC/) { + $ref->{R} = $ref->{N}; + delete $ref->{N}; + } +} + +sub byAuthor { + local ($a, $b) = ($a->{A}[0], $b->{A}[0]); + byLast(); +} + +{ + local ($,, $\) = (' ', "\n"); + print '.Bl', '-item'; + foreach $ref (sort byAuthor @refs) { + print '.It'; + print '.Rs'; + foreach my $key (qw(A T B I J R N V U P Q C D O)) { + next unless $ref->{$key}; + foreach (@{$ref->{$key}}) { + print ".%${key}", $_; + } + } + print '.Re'; + } + print '.El'; +} + +while (<>) { + print; +} diff --git a/bin/html.sh b/bin/html.sh index 4a6b52f8..e96a7210 100644 --- a/bin/html.sh +++ b/bin/html.sh @@ -38,4 +38,4 @@ pre.hi { EOF [ -f "$man" ] && man -P cat "${PWD}/${man}" | ./ttpre -./hi -f html -o anchor "$src" +./hi -t -f html -o anchor "$src" diff --git a/bin/man1/bibsort.1 b/bin/man1/bibsort.1 new file mode 100644 index 00000000..9d036920 --- /dev/null +++ b/bin/man1/bibsort.1 @@ -0,0 +1,37 @@ +.Dd December 15, 2020 +.Dt BIBSORT 1 +.Os +. +.Sh NAME +.Nm bibsort +.Nd reformat bibliography +. +.Sh SYNOPSIS +.Nm +.Op Ar file +. +.Sh DESCRIPTION +.Nm +reformats on standard output +the +.Em STANDARDS +section of the +.Xr mdoc 7 +manual page +.Ar file +or standard input. +Bibliographic references +are sorted by author last names, +and formatted in an item list +with macro lines appearing +in the order they are formatted by +.Xr mandoc 1 . +Additionally, +.Ic \&%N +macros referencing RFC numbers +are rewritten to +.Ic \&%R +macros. +. +.Sh EXAMPLES +.Dl :%!bibsort |