mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Get awk to build and make it hackable
This commit is contained in:
parent
2f1679e5cf
commit
99a92048b4
19 changed files with 885 additions and 596 deletions
33
third_party/awk/reflow.awk
vendored
Normal file
33
third_party/awk/reflow.awk
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
# fmt - format
|
||||
# input: text
|
||||
# output: text formatted into lines of <= 72 characters
|
||||
|
||||
BEGIN {
|
||||
maxlen = 72
|
||||
}
|
||||
|
||||
/^[ \t]/ { printline(); print; next } # verbatim
|
||||
###/^ +/ { printline(); } # whitespace == break
|
||||
|
||||
/./ { for (i = 1; i <= NF; i++) addword($i); next }
|
||||
|
||||
/^$/ { printline(); print "" }
|
||||
END { printline() }
|
||||
|
||||
function addword(w) {
|
||||
## print "adding [", w, "] ", length(w), length(line), maxlen
|
||||
if (length(line) + length(w) > maxlen)
|
||||
printline()
|
||||
if (length(w) > 2 && ( w ~ /[\.!]["?)]?$/ || w ~ /[?!]"?$/) &&
|
||||
w !~ /^(Mr|Dr|Ms|Mrs|vs|Ph.D)\.$/)
|
||||
w = w " "
|
||||
line = line " " w
|
||||
}
|
||||
|
||||
function printline() {
|
||||
if (length(line) > 0) {
|
||||
sub(/ +$/, "", line)
|
||||
print substr(line, 2) # removes leading blank
|
||||
line = ""
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue