diff options
Diffstat (limited to 'coreutils-5.3.0-bin/share/awk')
19 files changed, 615 insertions, 0 deletions
diff --git a/coreutils-5.3.0-bin/share/awk/assert.awk b/coreutils-5.3.0-bin/share/awk/assert.awk new file mode 100644 index 0000000..75fd885 --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/assert.awk @@ -0,0 +1,20 @@ +# assert --- assert that a condition is true. Otherwise exit. + +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# May, 1993 + +function assert(condition, string) +{ + if (! condition) { + printf("%s:%d: assertion failed: %s\n", + FILENAME, FNR, string) > "/dev/stderr" + _assert_exit = 1 + exit 1 + } +} + +END { + if (_assert_exit) + exit 1 +} diff --git a/coreutils-5.3.0-bin/share/awk/bits2str.awk b/coreutils-5.3.0-bin/share/awk/bits2str.awk new file mode 100644 index 0000000..9725ee8 --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/bits2str.awk @@ -0,0 +1,16 @@ +# bits2str --- turn a byte into readable 1's and 0's + +function bits2str(bits, data, mask) +{ + if (bits == 0) + return "0" + + mask = 1 + for (; bits != 0; bits = rshift(bits, 1)) + data = (and(bits, mask) ? "1" : "0") data + + while ((length(data) % 8) != 0) + data = "0" data + + return data +} diff --git a/coreutils-5.3.0-bin/share/awk/cliff_rand.awk b/coreutils-5.3.0-bin/share/awk/cliff_rand.awk new file mode 100644 index 0000000..e6a793a --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/cliff_rand.awk @@ -0,0 +1,14 @@ +# cliff_rand.awk --- generate Cliff random numbers +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# December 2000 + +BEGIN { _cliff_seed = 0.1 } + +function cliff_rand() +{ + _cliff_seed = (100 * log(_cliff_seed)) % 1 + if (_cliff_seed < 0) + _cliff_seed = - _cliff_seed + return _cliff_seed +} diff --git a/coreutils-5.3.0-bin/share/awk/ctime.awk b/coreutils-5.3.0-bin/share/awk/ctime.awk new file mode 100644 index 0000000..0a50d26 --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/ctime.awk @@ -0,0 +1,11 @@ +# ctime.awk +# +# awk version of C ctime(3) function + +function ctime(ts, format) +{ + format = "%a %b %d %H:%M:%S %Z %Y" + if (ts == 0) + ts = systime() # use current time as default + return strftime(format, ts) +} diff --git a/coreutils-5.3.0-bin/share/awk/ftrans.awk b/coreutils-5.3.0-bin/share/awk/ftrans.awk new file mode 100644 index 0000000..1709ac8 --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/ftrans.awk @@ -0,0 +1,15 @@ +# ftrans.awk --- handle data file transitions +# +# user supplies beginfile() and endfile() functions +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# November 1992 + +FNR == 1 { + if (_filename_ != "") + endfile(_filename_) + _filename_ = FILENAME + beginfile(FILENAME) +} + +END { endfile(_filename_) } diff --git a/coreutils-5.3.0-bin/share/awk/getopt.awk b/coreutils-5.3.0-bin/share/awk/getopt.awk new file mode 100644 index 0000000..0e3421a --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/getopt.awk @@ -0,0 +1,80 @@ +# getopt.awk --- do C library getopt(3) function in awk +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# +# Initial version: March, 1991 +# Revised: May, 1993 + +# External variables: +# Optind -- index in ARGV of first nonoption argument +# Optarg -- string value of argument to current option +# Opterr -- if nonzero, print our own diagnostic +# Optopt -- current option letter + +# Returns: +# -1 at end of options +# ? for unrecognized option +# <c> a character representing the current option + +# Private Data: +# _opti -- index in multi-flag option, e.g., -abc +function getopt(argc, argv, options, thisopt, i) +{ + if (length(options) == 0) # no options given + return -1 + + if (argv[Optind] == "--") { # all done + Optind++ + _opti = 0 + return -1 + } else if (argv[Optind] !~ /^-[^: \t\n\f\r\v\b]/) { + _opti = 0 + return -1 + } + if (_opti == 0) + _opti = 2 + thisopt = substr(argv[Optind], _opti, 1) + Optopt = thisopt + i = index(options, thisopt) + if (i == 0) { + if (Opterr) + printf("%c -- invalid option\n", + thisopt) > "/dev/stderr" + if (_opti >= length(argv[Optind])) { + Optind++ + _opti = 0 + } else + _opti++ + return "?" + } + if (substr(options, i + 1, 1) == ":") { + # get option argument + if (length(substr(argv[Optind], _opti + 1)) > 0) + Optarg = substr(argv[Optind], _opti + 1) + else + Optarg = argv[++Optind] + _opti = 0 + } else + Optarg = "" + if (_opti == 0 || _opti >= length(argv[Optind])) { + Optind++ + _opti = 0 + } else + _opti++ + return thisopt +} +BEGIN { + Opterr = 1 # default is to diagnose + Optind = 1 # skip ARGV[0] + + # test program + if (_getopt_test) { + while ((_go_c = getopt(ARGC, ARGV, "ab:cd")) != -1) + printf("c = <%c>, optarg = <%s>\n", + _go_c, Optarg) + printf("non-option arguments:\n") + for (; Optind < ARGC; Optind++) + printf("\tARGV[%d] = <%s>\n", + Optind, ARGV[Optind]) + } +} diff --git a/coreutils-5.3.0-bin/share/awk/gettime.awk b/coreutils-5.3.0-bin/share/awk/gettime.awk new file mode 100644 index 0000000..d79b8f4 --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/gettime.awk @@ -0,0 +1,62 @@ +# gettimeofday.awk --- get the time of day in a usable format +# +# Arnold Robbins, arnold@skeeve.com, Public Domain, May 1993 +# + +# Returns a string in the format of output of date(1) +# Populates the array argument time with individual values: +# time["second"] -- seconds (0 - 59) +# time["minute"] -- minutes (0 - 59) +# time["hour"] -- hours (0 - 23) +# time["althour"] -- hours (0 - 12) +# time["monthday"] -- day of month (1 - 31) +# time["month"] -- month of year (1 - 12) +# time["monthname"] -- name of the month +# time["shortmonth"] -- short name of the month +# time["year"] -- year modulo 100 (0 - 99) +# time["fullyear"] -- full year +# time["weekday"] -- day of week (Sunday = 0) +# time["altweekday"] -- day of week (Monday = 0) +# time["dayname"] -- name of weekday +# time["shortdayname"] -- short name of weekday +# time["yearday"] -- day of year (0 - 365) +# time["timezone"] -- abbreviation of timezone name +# time["ampm"] -- AM or PM designation +# time["weeknum"] -- week number, Sunday first day +# time["altweeknum"] -- week number, Monday first day + +function gettimeofday(time, ret, now, i) +{ + # get time once, avoids unnecessary system calls + now = systime() + + # return date(1)-style output + ret = strftime("%a %b %d %H:%M:%S %Z %Y", now) + + # clear out target array + delete time + + # fill in values, force numeric values to be + # numeric by adding 0 + time["second"] = strftime("%S", now) + 0 + time["minute"] = strftime("%M", now) + 0 + time["hour"] = strftime("%H", now) + 0 + time["althour"] = strftime("%I", now) + 0 + time["monthday"] = strftime("%d", now) + 0 + time["month"] = strftime("%m", now) + 0 + time["monthname"] = strftime("%B", now) + time["shortmonth"] = strftime("%b", now) + time["year"] = strftime("%y", now) + 0 + time["fullyear"] = strftime("%Y", now) + 0 + time["weekday"] = strftime("%w", now) + 0 + time["altweekday"] = strftime("%u", now) + 0 + time["dayname"] = strftime("%A", now) + time["shortdayname"] = strftime("%a", now) + time["yearday"] = strftime("%j", now) + 0 + time["timezone"] = strftime("%Z", now) + time["ampm"] = strftime("%p", now) + time["weeknum"] = strftime("%U", now) + 0 + time["altweeknum"] = strftime("%W", now) + 0 + + return ret +} diff --git a/coreutils-5.3.0-bin/share/awk/group.awk b/coreutils-5.3.0-bin/share/awk/group.awk new file mode 100644 index 0000000..ba8ae50 --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/group.awk @@ -0,0 +1,87 @@ +# group.awk --- functions for dealing with the group file +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# May 1993 +# Revised October 2000 + +BEGIN \ +{ + # Change to suit your system + _gr_awklib = "c:/progra~1/Gawk/libexec/awk/" +} + +function _gr_init( oldfs, oldrs, olddol0, grcat, + using_fw, n, a, i) +{ + if (_gr_inited) + return + + oldfs = FS + oldrs = RS + olddol0 = $0 + using_fw = (PROCINFO["FS"] == "FIELDWIDTHS") + FS = ":" + RS = "\n" + + grcat = _gr_awklib "grcat" + while ((grcat | getline) > 0) { + if ($1 in _gr_byname) + _gr_byname[$1] = _gr_byname[$1] "," $4 + else + _gr_byname[$1] = $0 + if ($3 in _gr_bygid) + _gr_bygid[$3] = _gr_bygid[$3] "," $4 + else + _gr_bygid[$3] = $0 + + n = split($4, a, "[ \t]*,[ \t]*") + for (i = 1; i <= n; i++) + if (a[i] in _gr_groupsbyuser) + _gr_groupsbyuser[a[i]] = \ + _gr_groupsbyuser[a[i]] " " $1 + else + _gr_groupsbyuser[a[i]] = $1 + + _gr_bycount[++_gr_count] = $0 + } + close(grcat) + _gr_count = 0 + _gr_inited++ + FS = oldfs + if (using_fw) + FIELDWIDTHS = FIELDWIDTHS + RS = oldrs + $0 = olddol0 +} +function getgrnam(group) +{ + _gr_init() + if (group in _gr_byname) + return _gr_byname[group] + return "" +} +function getgrgid(gid) +{ + _gr_init() + if (gid in _gr_bygid) + return _gr_bygid[gid] + return "" +} +function getgruser(user) +{ + _gr_init() + if (user in _gr_groupsbyuser) + return _gr_groupsbyuser[user] + return "" +} +function getgrent() +{ + _gr_init() + if (++_gr_count in _gr_bycount) + return _gr_bycount[_gr_count] + return "" +} +function endgrent() +{ + _gr_count = 0 +} diff --git a/coreutils-5.3.0-bin/share/awk/join.awk b/coreutils-5.3.0-bin/share/awk/join.awk new file mode 100644 index 0000000..4a4ac92 --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/join.awk @@ -0,0 +1,16 @@ +# join.awk --- join an array into a string +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# May 1993 + +function join(array, start, end, sep, result, i) +{ + if (sep == "") + sep = " " + else if (sep == SUBSEP) # magic value + sep = "" + result = array[start] + for (i = start + 1; i <= end; i++) + result = result sep array[i] + return result +} diff --git a/coreutils-5.3.0-bin/share/awk/libintl.awk b/coreutils-5.3.0-bin/share/awk/libintl.awk new file mode 100644 index 0000000..7efd2b4 --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/libintl.awk @@ -0,0 +1,14 @@ +function bindtextdomain(dir, domain) +{ + return dir +} + +function dcgettext(string, domain, category) +{ + return string +} + +function dcngettext(string1, string2, number, domain, category) +{ + return (number == 1 ? string1 : string2) +} diff --git a/coreutils-5.3.0-bin/share/awk/nextfile.awk b/coreutils-5.3.0-bin/share/awk/nextfile.awk new file mode 100644 index 0000000..33f5af3 --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/nextfile.awk @@ -0,0 +1,16 @@ +# nextfile --- skip remaining records in current file +# correctly handle successive occurrences of the same file +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# May, 1993 + +# this should be read in before the "main" awk program + +function nextfile() { _abandon_ = FILENAME; next } + +_abandon_ == FILENAME { + if (FNR == 1) + _abandon_ = "" + else + next +} diff --git a/coreutils-5.3.0-bin/share/awk/noassign.awk b/coreutils-5.3.0-bin/share/awk/noassign.awk new file mode 100644 index 0000000..2ad1f37 --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/noassign.awk @@ -0,0 +1,17 @@ +# noassign.awk --- library file to avoid the need for a +# special option that disables command-line assignments +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# October 1999 + +function disable_assigns(argc, argv, i) +{ + for (i = 1; i < argc; i++) + if (argv[i] ~ /^[A-Za-z_][A-Za-z_0-9]*=.*/) + argv[i] = ("./" argv[i]) +} + +BEGIN { + if (No_command_assign) + disable_assigns(ARGC, ARGV) +} diff --git a/coreutils-5.3.0-bin/share/awk/ord.awk b/coreutils-5.3.0-bin/share/awk/ord.awk new file mode 100644 index 0000000..be47e15 --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/ord.awk @@ -0,0 +1,44 @@ +# ord.awk --- do ord and chr + +# Global identifiers: +# _ord_: numerical values indexed by characters +# _ord_init: function to initialize _ord_ +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# 16 January, 1992 +# 20 July, 1992, revised + +BEGIN { _ord_init() } + +function _ord_init( low, high, i, t) +{ + low = sprintf("%c", 7) # BEL is ascii 7 + if (low == "\a") { # regular ascii + low = 0 + high = 127 + } else if (sprintf("%c", 128 + 7) == "\a") { + # ascii, mark parity + low = 128 + high = 255 + } else { # ebcdic(!) + low = 0 + high = 255 + } + + for (i = low; i <= high; i++) { + t = sprintf("%c", i) + _ord_[t] = i + } +} +function ord(str, c) +{ + # only first character is of interest + c = substr(str, 1, 1) + return _ord_[c] +} + +function chr(c) +{ + # force c to be numeric by adding 0 + return sprintf("%c", c + 0) +} diff --git a/coreutils-5.3.0-bin/share/awk/passwd.awk b/coreutils-5.3.0-bin/share/awk/passwd.awk new file mode 100644 index 0000000..77d7860 --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/passwd.awk @@ -0,0 +1,63 @@ +# passwd.awk --- access password file information +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# May 1993 +# Revised October 2000 + +BEGIN { + # tailor this to suit your system + _pw_awklib = "c:/progra~1/Gawk/libexec/awk/" +} + +function _pw_init( oldfs, oldrs, olddol0, pwcat, using_fw) +{ + if (_pw_inited) + return + + oldfs = FS + oldrs = RS + olddol0 = $0 + using_fw = (PROCINFO["FS"] == "FIELDWIDTHS") + FS = ":" + RS = "\n" + + pwcat = _pw_awklib "pwcat" + while ((pwcat | getline) > 0) { + _pw_byname[$1] = $0 + _pw_byuid[$3] = $0 + _pw_bycount[++_pw_total] = $0 + } + close(pwcat) + _pw_count = 0 + _pw_inited = 1 + FS = oldfs + if (using_fw) + FIELDWIDTHS = FIELDWIDTHS + RS = oldrs + $0 = olddol0 +} +function getpwnam(name) +{ + _pw_init() + if (name in _pw_byname) + return _pw_byname[name] + return "" +} +function getpwuid(uid) +{ + _pw_init() + if (uid in _pw_byuid) + return _pw_byuid[uid] + return "" +} +function getpwent() +{ + _pw_init() + if (_pw_count < _pw_total) + return _pw_bycount[++_pw_count] + return "" +} +function endpwent() +{ + _pw_count = 0 +} diff --git a/coreutils-5.3.0-bin/share/awk/readable.awk b/coreutils-5.3.0-bin/share/awk/readable.awk new file mode 100644 index 0000000..dbbab57 --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/readable.awk @@ -0,0 +1,16 @@ +# readable.awk --- library file to skip over unreadable files +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# October 2000 + +BEGIN { + for (i = 1; i < ARGC; i++) { + if (ARGV[i] ~ /^[A-Za-z_][A-Za-z0-9_]*=.*/ \ + || ARGV[i] == "-") + continue # assignment or standard input + else if ((getline junk < ARGV[i]) < 0) # unreadable + delete ARGV[i] + else + close(ARGV[i]) + } +} diff --git a/coreutils-5.3.0-bin/share/awk/rewind.awk b/coreutils-5.3.0-bin/share/awk/rewind.awk new file mode 100644 index 0000000..a646eac --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/rewind.awk @@ -0,0 +1,20 @@ +# rewind.awk --- rewind the current file and start over +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# September 2000 + +function rewind( i) +{ + # shift remaining arguments up + for (i = ARGC; i > ARGIND; i--) + ARGV[i] = ARGV[i-1] + + # make sure gawk knows to keep going + ARGC++ + + # make current file next to get done + ARGV[ARGIND+1] = FILENAME + + # do it + nextfile +} diff --git a/coreutils-5.3.0-bin/share/awk/round.awk b/coreutils-5.3.0-bin/share/awk/round.awk new file mode 100644 index 0000000..c5e993f --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/round.awk @@ -0,0 +1,29 @@ +# round.awk --- do normal rounding +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# August, 1996 + +function round(x, ival, aval, fraction) +{ + ival = int(x) # integer part, int() truncates + + # see if fractional part + if (ival == x) # no fraction + return x + + if (x < 0) { + aval = -x # absolute value + ival = int(aval) + fraction = aval - ival + if (fraction >= .5) + return int(x) - 1 # -2.5 --> -3 + else + return int(x) # -2.3 --> -2 + } else { + fraction = x - ival + if (fraction >= .5) + return ival + 1 + else + return ival + } +} diff --git a/coreutils-5.3.0-bin/share/awk/strtonum.awk b/coreutils-5.3.0-bin/share/awk/strtonum.awk new file mode 100644 index 0000000..a71341f --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/strtonum.awk @@ -0,0 +1,56 @@ +# strtonum --- convert string to number + +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# February, 2004 + +function mystrtonum(str, ret, chars, n, i, k, c) +{ + if (str ~ /^0[0-7]*$/) { + # octal + n = length(str) + ret = 0 + for (i = 1; i <= n; i++) { + c = substr(str, i, 1) + if ((k = index("01234567", c)) > 0) + k-- # adjust for 1-basing in awk + + ret = ret * 8 + k + } + } else if (str ~ /^0[xX][0-9a-fA-f]+/) { + # hexadecimal + str = substr(str, 3) # lop off leading 0x + n = length(str) + ret = 0 + for (i = 1; i <= n; i++) { + c = substr(str, i, 1) + c = tolower(c) + if ((k = index("0123456789", c)) > 0) + k-- # adjust for 1-basing in awk + else if ((k = index("abcdef", c)) > 0) + k += 9 + + ret = ret * 16 + k + } + } else if (str ~ /^[-+]?([0-9]+([.][0-9]*([Ee][0-9]+)?)?|([.][0-9]+([Ee][-+]?[0-9]+)?))$/) { + # decimal number, possibly floating point + ret = str + 0 + } else + ret = "NOT-A-NUMBER" + + return ret +} + +# BEGIN { # gawk test harness +# a[1] = "25" +# a[2] = ".31" +# a[3] = "0123" +# a[4] = "0xdeadBEEF" +# a[5] = "123.45" +# a[6] = "1.e3" +# a[7] = "1.32" +# a[7] = "1.32E2" +# +# for (i = 1; i in a; i++) +# print a[i], strtonum(a[i]), mystrtonum(a[i]) +# } diff --git a/coreutils-5.3.0-bin/share/awk/zerofile.awk b/coreutils-5.3.0-bin/share/awk/zerofile.awk new file mode 100644 index 0000000..8ea549c --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/zerofile.awk @@ -0,0 +1,19 @@ +# zerofile.awk --- library file to process empty input files +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# June 2003 + +BEGIN { Argind = 0 } + +ARGIND > Argind + 1 { + for (Argind++; Argind < ARGIND; Argind++) + zerofile(ARGV[Argind], Argind) +} + +ARGIND != Argind { Argind = ARGIND } + +END { + if (ARGIND > Argind) + for (Argind++; Argind <= ARGIND; Argind++) + zerofile(ARGV[Argind], Argind) +} |