aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-12-03 02:02:16 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-12-03 02:02:16 +1300
commita03e011345413a9b3749deb9da895bb4e8ec9974 (patch)
tree98a96bbddff100bd896af48c9fa2215d5e0ee742
parentRemove setterm(1) call (diff)
downloaddotfiles-a03e011345413a9b3749deb9da895bb4e8ec9974.tar.gz
dotfiles-a03e011345413a9b3749deb9da895bb4e8ec9974.zip
Rewrite unf(1df) in awk
Also update manual page references to it, and improve it by making it ignore body content
-rw-r--r--ISSUES.markdown2
-rw-r--r--bin/unf.awk34
-rw-r--r--bin/unf.sed17
-rw-r--r--man/man1/unf.1df8
-rw-r--r--man/man1/urlh.1df2
-rw-r--r--man/man1/urlmt.1df2
6 files changed, 41 insertions, 24 deletions
diff --git a/ISSUES.markdown b/ISSUES.markdown
index 19177f71..6808fab3 100644
--- a/ISSUES.markdown
+++ b/ISSUES.markdown
@@ -24,5 +24,3 @@ Known issues
13:33:32 <tejr> yep it does
* dr(1df) is probably more practical in awk
-* unf(1df) doesn't work on NetBSD sed(1); might be time to give up and
- rewrite it in awk
diff --git a/bin/unf.awk b/bin/unf.awk
new file mode 100644
index 00000000..22a10aa8
--- /dev/null
+++ b/bin/unf.awk
@@ -0,0 +1,34 @@
+# Unfold header lines in an internet message, don't touch the body
+
+# Function to write and empty the buffer
+function wrbuf() {
+ if (length(buf))
+ print buf
+ buf = ""
+}
+
+# Flag to stop processing once we hit the first blank line
+!length {
+ wrbuf()
+ body = 1
+}
+body {
+ print
+ next
+}
+
+# Write any buffer contents once we hit a line not starting with a space
+/^[^ \t]/ {
+ wrbuf()
+}
+
+# Append the current line to the buffer
+{
+ sub(/^[ \t]+/, " ")
+ buf = buf $0
+}
+
+# Write the buffer out again when we hit the end
+END {
+ wrbuf()
+}
diff --git a/bin/unf.sed b/bin/unf.sed
deleted file mode 100644
index 23270fc6..00000000
--- a/bin/unf.sed
+++ /dev/null
@@ -1,17 +0,0 @@
-# Unfold lines with leading spaces (e.g. RFC 822 headers)
-/^[ \t]/!{
- 1!{
- x
- p
- x
- }
- h
-}
-/^[ \t]/{
- H
- x
- s/[\r\n]//g
- x
-}
-$!d
-x
diff --git a/man/man1/unf.1df b/man/man1/unf.1df
index b74ef9ce..288ddf5f 100644
--- a/man/man1/unf.1df
+++ b/man/man1/unf.1df
@@ -1,7 +1,7 @@
.TH UNF 1df "August 2016" "Manual page for unf"
.SH NAME
.B unf
-\- join lines with leading spaces to the previous line
+\- join header lines in an internet message
.SH USAGE
.B unf
FILE
@@ -16,7 +16,9 @@ curl -I http://www.example.net/ |
.B
unf
.SH DESCRIPTION
-Joins lines with leading spaces in the output to the previous line,
-such as folded header fields in RFC 822 format messages.
+Joins long lines denoted with leading spaces in the folded headers of an RFC
+822 style internet message, such as an email message or an HTTP response.
+.SH SEE ALSO
+urlmt(1df)
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>
diff --git a/man/man1/urlh.1df b/man/man1/urlh.1df
index d17f0a74..8eeb359a 100644
--- a/man/man1/urlh.1df
+++ b/man/man1/urlh.1df
@@ -12,6 +12,6 @@ makes a cURL HEAD request for the given URL, and searches the headers for a key
matching the given name, case-insensitively. It prints any matching values to
stdout.
.SH SEE ALSO
-curl(1), urlmt(1df)
+curl(1), unf(1df), urlmt(1df)
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>
diff --git a/man/man1/urlmt.1df b/man/man1/urlmt.1df
index 892b10d4..cbc31bed 100644
--- a/man/man1/urlmt.1df
+++ b/man/man1/urlmt.1df
@@ -10,6 +10,6 @@ https://www.sanctum.geek.nz/
uses urlh(1df) to search for a Content-Type header for the given URL, and prints
it with any trailing data (e.g. charset) trimmed off.
.SH SEE ALSO
-curl(1), urlh(1df)
+curl(1), unf(1df), urlh(1df)
.SH AUTHOR
Tom Ryder <tom@sanctum.geek.nz>