aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-12-11 00:09:24 +1300
committerTom Ryder <tom@sanctum.geek.nz>2016-12-11 00:09:24 +1300
commit960208a496240318b38a6a6cfdf1f5e266099c85 (patch)
treede7ff197a3514d3e0bcfa6acbfa748b2738c5692 /bin
parentRemove superfluous calls to next in sec(1df) (diff)
downloaddotfiles-960208a496240318b38a6a6cfdf1f5e266099c85.tar.gz
dotfiles-960208a496240318b38a6a6cfdf1f5e266099c85.zip
Stylistic tweaks to awk scripts
Diffstat (limited to 'bin')
-rw-r--r--bin/gwp.awk4
-rw-r--r--bin/med.awk5
-rw-r--r--bin/mftl.awk4
-rw-r--r--bin/rfct.awk4
-rw-r--r--bin/rndi.awk8
-rw-r--r--bin/sec.awk16
-rw-r--r--bin/unf.awk8
7 files changed, 14 insertions, 35 deletions
diff --git a/bin/gwp.awk b/bin/gwp.awk
index 79f59b61..32fe97f2 100644
--- a/bin/gwp.awk
+++ b/bin/gwp.awk
@@ -51,6 +51,4 @@ function fnpr() {
}
# Exit zero if we found at least one match, non-zero otherwise
-END {
- exit(!found)
-}
+END { exit(!found) }
diff --git a/bin/med.awk b/bin/med.awk
index 83f0eb74..8167f8dd 100644
--- a/bin/med.awk
+++ b/bin/med.awk
@@ -7,11 +7,10 @@ END {
# Error out if we read no values at all
if (!NR)
exit(1)
- if (NR % 2) {
+ if (NR % 2)
med = vals[(NR+1)/2]
- } else {
+ else
med = (vals[NR/2] + vals[NR/2+1]) / 2
- }
print med
if (warn)
exit(1)
diff --git a/bin/mftl.awk b/bin/mftl.awk
index 893766ef..21976337 100644
--- a/bin/mftl.awk
+++ b/bin/mftl.awk
@@ -2,9 +2,7 @@
# could be reasonably expected to call directly
# Separators are space, tab, or colon
-BEGIN {
- FS = "[ \t:]"
-}
+BEGIN { FS = "[ \t:]" }
# Skip comments
/^#/ { next }
diff --git a/bin/rfct.awk b/bin/rfct.awk
index 3cd32e40..2f0cc42d 100644
--- a/bin/rfct.awk
+++ b/bin/rfct.awk
@@ -1,9 +1,7 @@
# Format an RFC in text format for terminal reading
# A record is a paragraph
-BEGIN {
- RS=""
-}
+BEGIN { RS = "" }
# Print the block followed by two newlines, as long as it has at least one
# alphanumeric character and no pagebreak characters
diff --git a/bin/rndi.awk b/bin/rndi.awk
index 337498cb..49df4398 100644
--- a/bin/rndi.awk
+++ b/bin/rndi.awk
@@ -5,17 +5,15 @@
BEGIN {
# Seed with the third argument if given
- if (ARGV[3]) {
+ if (ARGV[3])
srand(ARGV[3])
- }
# If not, just seed with what is probably a date/time-derived value
- else {
+ else
srand()
- }
# Print a random integer bounded by the first and second arguments
- print int(ARGV[1]+rand()*(ARGV[2]-ARGV[1]+1))
+ print int(ARGV[1] + rand() * (ARGV[2] - ARGV[1] + 1))
# Bail before processing any lines
exit
diff --git a/bin/sec.awk b/bin/sec.awk
index cac40cb9..3ebf02b6 100644
--- a/bin/sec.awk
+++ b/bin/sec.awk
@@ -12,21 +12,13 @@ BEGIN { FS = ":0*" }
}
# Match hh:mm:ss
-NF == 3 {
- printf "%u\n", $1 * 3600 + $2 * 60 + $3
-}
+NF == 3 { printf "%u\n", $1 * 3600 + $2 * 60 + $3 }
# Match mm:ss
-NF == 2 {
- printf "%u\n", $1 * 60 + $2
-}
+NF == 2 { printf "%u\n", $1 * 60 + $2 }
# Match ss (in which case all we've done is strip zeroes)
-NF == 1 {
- printf "%u\n", $1
-}
+NF == 1 { printf "%u\n", $1 }
# Done, exit 1 if we had any errors on the way
-END {
- exit(err > 0)
-}
+END { exit(err > 0) }
diff --git a/bin/unf.awk b/bin/unf.awk
index 22a10aa8..a9837a8a 100644
--- a/bin/unf.awk
+++ b/bin/unf.awk
@@ -18,9 +18,7 @@ body {
}
# Write any buffer contents once we hit a line not starting with a space
-/^[^ \t]/ {
- wrbuf()
-}
+/^[^ \t]/ { wrbuf() }
# Append the current line to the buffer
{
@@ -29,6 +27,4 @@ body {
}
# Write the buffer out again when we hit the end
-END {
- wrbuf()
-}
+END { wrbuf() }