diff options
Diffstat (limited to 'contrib/awk/awklib/eg')
64 files changed, 0 insertions, 2811 deletions
diff --git a/contrib/awk/awklib/eg/data/BBS-list b/contrib/awk/awklib/eg/data/BBS-list deleted file mode 100644 index 1007417f2b45..000000000000 --- a/contrib/awk/awklib/eg/data/BBS-list +++ /dev/null @@ -1,11 +0,0 @@ -aardvark 555-5553 1200/300 B -alpo-net 555-3412 2400/1200/300 A -barfly 555-7685 1200/300 A -bites 555-1675 2400/1200/300 A -camelot 555-0542 300 C -core 555-2912 1200/300 C -fooey 555-1234 2400/1200/300 B -foot 555-6699 1200/300 B -macfoo 555-6480 1200/300 A -sdace 555-3430 2400/1200/300 A -sabafoo 555-2127 1200/300 C diff --git a/contrib/awk/awklib/eg/data/inventory-shipped b/contrib/awk/awklib/eg/data/inventory-shipped deleted file mode 100644 index 6788a0ef37a0..000000000000 --- a/contrib/awk/awklib/eg/data/inventory-shipped +++ /dev/null @@ -1,17 +0,0 @@ -Jan 13 25 15 115 -Feb 15 32 24 226 -Mar 15 24 34 228 -Apr 31 52 63 420 -May 16 34 29 208 -Jun 31 42 75 492 -Jul 24 34 67 436 -Aug 15 34 47 316 -Sep 13 55 37 277 -Oct 29 54 68 525 -Nov 20 87 82 577 -Dec 17 35 61 401 - -Jan 21 36 64 620 -Feb 26 58 80 652 -Mar 24 75 70 495 -Apr 21 70 74 514 diff --git a/contrib/awk/awklib/eg/lib/assert.awk b/contrib/awk/awklib/eg/lib/assert.awk deleted file mode 100644 index bbfc0669bb79..000000000000 --- a/contrib/awk/awklib/eg/lib/assert.awk +++ /dev/null @@ -1,20 +0,0 @@ -# assert --- assert that a condition is true. Otherwise exit. - -# -# Arnold Robbins, arnold@gnu.org, 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/contrib/awk/awklib/eg/lib/bits2str.awk b/contrib/awk/awklib/eg/lib/bits2str.awk deleted file mode 100644 index 9725ee8fa7d0..000000000000 --- a/contrib/awk/awklib/eg/lib/bits2str.awk +++ /dev/null @@ -1,16 +0,0 @@ -# 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/contrib/awk/awklib/eg/lib/cliff_rand.awk b/contrib/awk/awklib/eg/lib/cliff_rand.awk deleted file mode 100644 index 345447ec82a9..000000000000 --- a/contrib/awk/awklib/eg/lib/cliff_rand.awk +++ /dev/null @@ -1,14 +0,0 @@ -# cliff_rand.awk --- generate Cliff random numbers -# -# Arnold Robbins, arnold@gnu.org, 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/contrib/awk/awklib/eg/lib/ctime.awk b/contrib/awk/awklib/eg/lib/ctime.awk deleted file mode 100644 index 0a50d262428d..000000000000 --- a/contrib/awk/awklib/eg/lib/ctime.awk +++ /dev/null @@ -1,11 +0,0 @@ -# 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/contrib/awk/awklib/eg/lib/ftrans.awk b/contrib/awk/awklib/eg/lib/ftrans.awk deleted file mode 100644 index b0743e2889bf..000000000000 --- a/contrib/awk/awklib/eg/lib/ftrans.awk +++ /dev/null @@ -1,15 +0,0 @@ -# ftrans.awk --- handle data file transitions -# -# user supplies beginfile() and endfile() functions -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# November 1992 - -FNR == 1 { - if (_filename_ != "") - endfile(_filename_) - _filename_ = FILENAME - beginfile(FILENAME) -} - -END { endfile(_filename_) } diff --git a/contrib/awk/awklib/eg/lib/getopt.awk b/contrib/awk/awklib/eg/lib/getopt.awk deleted file mode 100644 index 93753052eef1..000000000000 --- a/contrib/awk/awklib/eg/lib/getopt.awk +++ /dev/null @@ -1,80 +0,0 @@ -# getopt.awk --- do C library getopt(3) function in awk -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# -# Initial version: March, 1991 -# Revised: May, 1993 - -# External variables: -# Optind -- index in ARGV of first non-option 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/contrib/awk/awklib/eg/lib/gettime.awk b/contrib/awk/awklib/eg/lib/gettime.awk deleted file mode 100644 index c425123c6268..000000000000 --- a/contrib/awk/awklib/eg/lib/gettime.awk +++ /dev/null @@ -1,62 +0,0 @@ -# gettimeofday.awk --- get the time of day in a usable format -# -# Arnold Robbins, arnold@gnu.org, 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/contrib/awk/awklib/eg/lib/grcat.c b/contrib/awk/awklib/eg/lib/grcat.c deleted file mode 100644 index d34ddd560b65..000000000000 --- a/contrib/awk/awklib/eg/lib/grcat.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * grcat.c - * - * Generate a printable version of the group database - */ -/* - * Arnold Robbins, arnold@gnu.org, May 1993 - * Public Domain - */ - -#include <stdio.h> -#include <grp.h> - -int -main(argc, argv) -int argc; -char **argv; -{ - struct group *g; - int i; - - while ((g = getgrent()) != NULL) { - printf("%s:%s:%d:", g->gr_name, g->gr_passwd, - g->gr_gid); - for (i = 0; g->gr_mem[i] != NULL; i++) { - printf("%s", g->gr_mem[i]); - if (g->gr_mem[i+1] != NULL) - putchar(','); - } - putchar('\n'); - } - endgrent(); - exit(0); -} diff --git a/contrib/awk/awklib/eg/lib/groupawk.in b/contrib/awk/awklib/eg/lib/groupawk.in deleted file mode 100644 index 9d8b402197e2..000000000000 --- a/contrib/awk/awklib/eg/lib/groupawk.in +++ /dev/null @@ -1,87 +0,0 @@ -# group.awk --- functions for dealing with the group file -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# May 1993 -# Revised October 2000 - -BEGIN \ -{ - # Change to suit your system - _gr_awklib = "/usr/local/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/contrib/awk/awklib/eg/lib/join.awk b/contrib/awk/awklib/eg/lib/join.awk deleted file mode 100644 index e17b4270ca38..000000000000 --- a/contrib/awk/awklib/eg/lib/join.awk +++ /dev/null @@ -1,16 +0,0 @@ -# join.awk --- join an array into a string -# -# Arnold Robbins, arnold@gnu.org, 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/contrib/awk/awklib/eg/lib/libintl.awk b/contrib/awk/awklib/eg/lib/libintl.awk deleted file mode 100644 index a9402c2af9fa..000000000000 --- a/contrib/awk/awklib/eg/lib/libintl.awk +++ /dev/null @@ -1,9 +0,0 @@ -function bindtextdomain(dir, domain) -{ - return dir -} - -function dcgettext(string, domain, category) -{ - return string -} diff --git a/contrib/awk/awklib/eg/lib/mktime.awk b/contrib/awk/awklib/eg/lib/mktime.awk deleted file mode 100644 index 57ff20e53aed..000000000000 --- a/contrib/awk/awklib/eg/lib/mktime.awk +++ /dev/null @@ -1,105 +0,0 @@ -# mktime.awk --- convert a canonical date representation -# into a timestamp -# Arnold Robbins, arnold@gnu.org, Public Domain -# May 1993 - -BEGIN \ -{ - # Initialize table of month lengths - _tm_months[0,1] = _tm_months[1,1] = 31 - _tm_months[0,2] = 28; _tm_months[1,2] = 29 - _tm_months[0,3] = _tm_months[1,3] = 31 - _tm_months[0,4] = _tm_months[1,4] = 30 - _tm_months[0,5] = _tm_months[1,5] = 31 - _tm_months[0,6] = _tm_months[1,6] = 30 - _tm_months[0,7] = _tm_months[1,7] = 31 - _tm_months[0,8] = _tm_months[1,8] = 31 - _tm_months[0,9] = _tm_months[1,9] = 30 - _tm_months[0,10] = _tm_months[1,10] = 31 - _tm_months[0,11] = _tm_months[1,11] = 30 - _tm_months[0,12] = _tm_months[1,12] = 31 -} -# decide if a year is a leap year -function _tm_isleap(year, ret) -{ - ret = (year % 4 == 0 && year % 100 != 0) || - (year % 400 == 0) - - return ret -} -# convert a date into seconds -function _tm_addup(a, total, yearsecs, daysecs, - hoursecs, i, j) -{ - hoursecs = 60 * 60 - daysecs = 24 * hoursecs - yearsecs = 365 * daysecs - - total = (a[1] - 1970) * yearsecs - - # extra day for leap years - for (i = 1970; i < a[1]; i++) - if (_tm_isleap(i)) - total += daysecs - - j = _tm_isleap(a[1]) - for (i = 1; i < a[2]; i++) - total += _tm_months[j, i] * daysecs - - total += (a[3] - 1) * daysecs - total += a[4] * hoursecs - total += a[5] * 60 - total += a[6] - - return total -} -# mktime --- convert a date into seconds, -# compensate for time zone - -function mktime(str, res1, res2, a, b, i, j, t, diff) -{ - i = split(str, a, " ") # don't rely on FS - - if (i != 6) - return -1 - - # force numeric - for (j in a) - a[j] += 0 - - # validate - if (a[1] < 1970 || - a[2] < 1 || a[2] > 12 || - a[3] < 1 || a[3] > 31 || - a[4] < 0 || a[4] > 23 || - a[5] < 0 || a[5] > 59 || - a[6] < 0 || a[6] > 60 ) - return -1 - - res1 = _tm_addup(a) - t = strftime("%Y %m %d %H %M %S", res1) - - if (_tm_debug) - printf("(%s) -> (%s)\n", str, t) > "/dev/stderr" - - split(t, b, " ") - res2 = _tm_addup(b) - - diff = res1 - res2 - - if (_tm_debug) - printf("diff = %d seconds\n", diff) > "/dev/stderr" - - res1 += diff - - return res1 -} -BEGIN { - if (_tm_test) { - printf "Enter date as yyyy mm dd hh mm ss: " - getline _tm_test_date - t = mktime(_tm_test_date) - r = strftime("%Y %m %d %H %M %S", t) - printf "Got back (%s)\n", r - } -} diff --git a/contrib/awk/awklib/eg/lib/nextfile.awk b/contrib/awk/awklib/eg/lib/nextfile.awk deleted file mode 100644 index caedf0e478e3..000000000000 --- a/contrib/awk/awklib/eg/lib/nextfile.awk +++ /dev/null @@ -1,16 +0,0 @@ -# nextfile --- skip remaining records in current file -# correctly handle successive occurrences of the same file -# -# Arnold Robbins, arnold@gnu.org, 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/contrib/awk/awklib/eg/lib/noassign.awk b/contrib/awk/awklib/eg/lib/noassign.awk deleted file mode 100644 index d6d176e40e9d..000000000000 --- a/contrib/awk/awklib/eg/lib/noassign.awk +++ /dev/null @@ -1,17 +0,0 @@ -# noassign.awk --- library file to avoid the need for a -# special option that disables command-line assignments -# -# Arnold Robbins, arnold@gnu.org, 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/contrib/awk/awklib/eg/lib/ord.awk b/contrib/awk/awklib/eg/lib/ord.awk deleted file mode 100644 index 3eacbcc576dc..000000000000 --- a/contrib/awk/awklib/eg/lib/ord.awk +++ /dev/null @@ -1,44 +0,0 @@ -# ord.awk --- do ord and chr - -# Global identifiers: -# _ord_: numerical values indexed by characters -# _ord_init: function to initialize _ord_ -# -# Arnold Robbins, arnold@gnu.org, 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/contrib/awk/awklib/eg/lib/passwdawk.in b/contrib/awk/awklib/eg/lib/passwdawk.in deleted file mode 100644 index 5f6f9e2657fb..000000000000 --- a/contrib/awk/awklib/eg/lib/passwdawk.in +++ /dev/null @@ -1,63 +0,0 @@ -# passwd.awk --- access password file information -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# May 1993 -# Revised October 2000 - -BEGIN { - # tailor this to suit your system - _pw_awklib = "/usr/local/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/contrib/awk/awklib/eg/lib/pwcat.c b/contrib/awk/awklib/eg/lib/pwcat.c deleted file mode 100644 index b9a71340a43e..000000000000 --- a/contrib/awk/awklib/eg/lib/pwcat.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * pwcat.c - * - * Generate a printable version of the password database - */ -/* - * Arnold Robbins, arnold@gnu.org, May 1993 - * Public Domain - */ - -#include <stdio.h> -#include <pwd.h> - -int -main(argc, argv) -int argc; -char **argv; -{ - struct passwd *p; - - while ((p = getpwent()) != NULL) - printf("%s:%s:%d:%d:%s:%s:%s\n", - p->pw_name, p->pw_passwd, p->pw_uid, - p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell); - - endpwent(); - exit(0); -} diff --git a/contrib/awk/awklib/eg/lib/readable.awk b/contrib/awk/awklib/eg/lib/readable.awk deleted file mode 100644 index 51705aea0a56..000000000000 --- a/contrib/awk/awklib/eg/lib/readable.awk +++ /dev/null @@ -1,16 +0,0 @@ -# readable.awk --- library file to skip over unreadable files -# -# Arnold Robbins, arnold@gnu.org, 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/contrib/awk/awklib/eg/lib/rewind.awk b/contrib/awk/awklib/eg/lib/rewind.awk deleted file mode 100644 index 33286611341c..000000000000 --- a/contrib/awk/awklib/eg/lib/rewind.awk +++ /dev/null @@ -1,20 +0,0 @@ -# rewind.awk --- rewind the current file and start over -# -# Arnold Robbins, arnold@gnu.org, 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/contrib/awk/awklib/eg/lib/round.awk b/contrib/awk/awklib/eg/lib/round.awk deleted file mode 100644 index bf16c2b64902..000000000000 --- a/contrib/awk/awklib/eg/lib/round.awk +++ /dev/null @@ -1,32 +0,0 @@ -# round --- do normal rounding -# -# Arnold Robbins, arnold@gnu.org, 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 - } -} - -# test harness -{ print $0, round($0) } diff --git a/contrib/awk/awklib/eg/misc/arraymax.awk b/contrib/awk/awklib/eg/misc/arraymax.awk deleted file mode 100644 index 20dd17689d56..000000000000 --- a/contrib/awk/awklib/eg/misc/arraymax.awk +++ /dev/null @@ -1,10 +0,0 @@ -{ - if ($1 > max) - max = $1 - arr[$1] = $0 -} - -END { - for (x = 1; x <= max; x++) - print arr[x] -} diff --git a/contrib/awk/awklib/eg/misc/arraymax.data b/contrib/awk/awklib/eg/misc/arraymax.data deleted file mode 100644 index dbee328c6ea5..000000000000 --- a/contrib/awk/awklib/eg/misc/arraymax.data +++ /dev/null @@ -1,5 +0,0 @@ -5 I am the Five man -2 Who are you? The new number two! -4 . . . And four on the floor -1 Who is number one? -3 I three you. diff --git a/contrib/awk/awklib/eg/misc/findpat.awk b/contrib/awk/awklib/eg/misc/findpat.awk deleted file mode 100644 index e9bef9eaf5d1..000000000000 --- a/contrib/awk/awklib/eg/misc/findpat.awk +++ /dev/null @@ -1,10 +0,0 @@ -{ - if ($1 == "FIND") - regex = $2 - else { - where = match($0, regex) - if (where != 0) - print "Match of", regex, "found at", - where, "in", $0 - } -} diff --git a/contrib/awk/awklib/eg/misc/findpat.data b/contrib/awk/awklib/eg/misc/findpat.data deleted file mode 100644 index 9f72969e0c69..000000000000 --- a/contrib/awk/awklib/eg/misc/findpat.data +++ /dev/null @@ -1,7 +0,0 @@ -FIND ru+n -My program runs -but not very quickly -FIND Melvin -JF+KM -This line is property of Reality Engineering Co. -Melvin was here. diff --git a/contrib/awk/awklib/eg/misc/findpat.sh b/contrib/awk/awklib/eg/misc/findpat.sh deleted file mode 100644 index 397103247a1e..000000000000 --- a/contrib/awk/awklib/eg/misc/findpat.sh +++ /dev/null @@ -1,10 +0,0 @@ -awk '{ - if ($1 == "FIND") - regex = $2 - else { - where = match($0, regex) - if (where != 0) - print "Match of", regex, "found at", \ - where, "in", $0 - } -}' diff --git a/contrib/awk/awklib/eg/network/PostAgent.sh b/contrib/awk/awklib/eg/network/PostAgent.sh deleted file mode 100644 index ccf9a6874b4a..000000000000 --- a/contrib/awk/awklib/eg/network/PostAgent.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -MobAg=/tmp/MobileAgent.$$ -# direct script to mobile agent file -cat > $MobAg -# execute agent concurrently -gawk -f $MobAg $MobAg > /dev/null & -# HTTP header, terminator and body -gawk 'BEGIN { print "\r\nAgent started" }' -rm $MobAg # delete script file of agent diff --git a/contrib/awk/awklib/eg/network/coreserv.awk b/contrib/awk/awklib/eg/network/coreserv.awk deleted file mode 100644 index e9e617109a25..000000000000 --- a/contrib/awk/awklib/eg/network/coreserv.awk +++ /dev/null @@ -1,113 +0,0 @@ -# CGI Library and core of a web server -# -# Juergen Kahrs, Juergen.Kahrs@vr-web.de -# with Arnold Robbins, arnold@gnu.org -# September 2000 - -# Global arrays -# GETARG --- arguments to CGI GET command -# MENU --- menu items (path names) -# PARAM --- parameters of form x=y - -# Optional variable MyHost contains host address -# Optional variable MyPort contains port number -# Needs TopHeader, TopDoc, TopFooter -# Sets MyPrefix, HttpService, Status, Reason - -BEGIN { - if (MyHost == "") { - "uname -n" | getline MyHost - close("uname -n") - } - if (MyPort == 0) MyPort = 8080 - HttpService = "/inet/tcp/" MyPort "/0/0" - MyPrefix = "http://" MyHost ":" MyPort - SetUpServer() - while ("awk" != "complex") { - # header lines are terminated this way - RS = ORS = "\r\n" - Status = 200 # this means OK - Reason = "OK" - Header = TopHeader - Document = TopDoc - Footer = TopFooter - if (GETARG["Method"] == "GET") { - HandleGET() - } else if (GETARG["Method"] == "HEAD") { - # not yet implemented - } else if (GETARG["Method"] != "") { - print "bad method", GETARG["Method"] - } - Prompt = Header Document Footer - print "HTTP/1.0", Status, Reason |& HttpService - print "Connection: Close" |& HttpService - print "Pragma: no-cache" |& HttpService - len = length(Prompt) + length(ORS) - print "Content-length:", len |& HttpService - print ORS Prompt |& HttpService - # ignore all the header lines - while ((HttpService |& getline) > 0) - continue - # stop talking to this client - close(HttpService) - # wait for new client request - HttpService |& getline - # do some logging - print systime(), strftime(), $0 - CGI_setup($1, $2, $3) - } -} - -function CGI_setup( method, uri, version, i) -{ - delete GETARG - delete MENU - delete PARAM - GETARG["Method"] = method - GETARG["URI"] = uri - GETARG["Version"] = version - - i = index(uri, "?") - if (i > 0) { # is there a "?" indicating a CGI request? - split(substr(uri, 1, i-1), MENU, "[/:]") - split(substr(uri, i+1), PARAM, "&") - for (i in PARAM) { - PARAM[i] = _CGI_decode(PARAM[i]) - j = index(PARAM[i], "=") - GETARG[substr(PARAM[i], 1, j-1)] = \ - substr(PARAM[i], j+1) - } - } else { # there is no "?", no need for splitting PARAMs - split(uri, MENU, "[/:]") - } - for (i in MENU) # decode characters in path - if (i > 4) # but not those in host name - MENU[i] = _CGI_decode(MENU[i]) -} -function _CGI_decode(str, hexdigs, i, pre, code1, code2, - val, result) -{ - hexdigs = "123456789abcdef" - - i = index(str, "%") - if (i == 0) # no work to do - return str - - do { - pre = substr(str, 1, i-1) # part before %xx - code1 = substr(str, i+1, 1) # first hex digit - code2 = substr(str, i+2, 1) # second hex digit - str = substr(str, i+3) # rest of string - - code1 = tolower(code1) - code2 = tolower(code2) - val = index(hexdigs, code1) * 16 \ - + index(hexdigs, code2) - - result = result pre sprintf("%c", val) - i = index(str, "%") - } while (i != 0) - if (length(str) > 0) - result = result str - return result -} diff --git a/contrib/awk/awklib/eg/network/eliza.awk b/contrib/awk/awklib/eg/network/eliza.awk deleted file mode 100644 index 2e022b41a919..000000000000 --- a/contrib/awk/awklib/eg/network/eliza.awk +++ /dev/null @@ -1,270 +0,0 @@ -function SetUpServer() { - SetUpEliza() - TopHeader = \ - "<HTML><title>An HTTP-based System with GAWK</title>\ - <HEAD><META HTTP-EQUIV=\"Content-Type\"\ - CONTENT=\"text/html; charset=iso-8859-1\"></HEAD>\ - <BODY BGCOLOR=\"#ffffff\" TEXT=\"#000000\"\ - LINK=\"#0000ff\" VLINK=\"#0000ff\"\ - ALINK=\"#0000ff\"> <A NAME=\"top\">" - TopDoc = "\ - <h2>Please choose one of the following actions:</h2>\ - <UL>\ - <LI>\ - <A HREF=" MyPrefix "/AboutServer>About this server</A>\ - </LI><LI>\ - <A HREF=" MyPrefix "/AboutELIZA>About Eliza</A></LI>\ - <LI>\ - <A HREF=" MyPrefix \ - "/StartELIZA>Start talking to Eliza</A></LI></UL>" - TopFooter = "</BODY></HTML>" -} -function HandleGET() { - # A real HTTP server would treat some parts of the URI as a file name. - # We take parts of the URI as menu choices and go on accordingly. - if(MENU[2] == "AboutServer") { - Document = "This is not a CGI script.\ - This is an httpd, an HTML file, and a CGI script all \ - in one GAWK script. It needs no separate www-server, \ - no installation, and no root privileges.\ - <p>To run it, do this:</p><ul>\ - <li> start this script with \"gawk -f httpserver.awk\",</li>\ - <li> and on the same host let your www browser open location\ - \"http://localhost:8080\"</li>\ - </ul>\<p>\ Details of HTTP come from:</p><ul>\ - <li>Hethmon: Illustrated Guide to HTTP</p>\ - <li>RFC 2068</li></ul><p>JK 14.9.1997</p>" - } else if (MENU[2] == "AboutELIZA") { - Document = "This is an implementation of the famous ELIZA\ - program by Joseph Weizenbaum. It is written in GAWK and\ -/bin/sh: expad: command not found - } else if (MENU[2] == "StartELIZA") { - gsub(/\+/, " ", GETARG["YouSay"]) - # Here we also have to substitute coded special characters - Document = "<form method=GET>" \ - "<h3>" ElizaSays(GETARG["YouSay"]) "</h3>\ - <p><input type=text name=YouSay value=\"\" size=60>\ - <br><input type=submit value=\"Tell her about it\"></p></form>" - } -} -function ElizaSays(YouSay) { - if (YouSay == "") { - cost = 0 - answer = "HI, IM ELIZA, TELL ME YOUR PROBLEM" - } else { - q = toupper(YouSay) - gsub("'", "", q) - if(q == qold) { - answer = "PLEASE DONT REPEAT YOURSELF !" - } else { - if (index(q, "SHUT UP") > 0) { - answer = "WELL, PLEASE PAY YOUR BILL. ITS EXACTLY ... $"\ - int(100*rand()+30+cost/100) - } else { - qold = q - w = "-" # no keyword recognized yet - for (i in k) { # search for keywords - if (index(q, i) > 0) { - w = i - break - } - } - if (w == "-") { # no keyword, take old subject - w = wold - subj = subjold - } else { # find subject - subj = substr(q, index(q, w) + length(w)+1) - wold = w - subjold = subj # remember keyword and subject - } - for (i in conj) - gsub(i, conj[i], q) # conjugation - # from all answers to this keyword, select one randomly - answer = r[indices[int(split(k[w], indices) * rand()) + 1]] - # insert subject into answer - gsub("_", subj, answer) - } - } - } - cost += length(answer) # for later payment : 1 cent per character - return answer -} -function SetUpEliza() { - srand() - wold = "-" - subjold = " " - - # table for conjugation - conj[" ARE " ] = " AM " - conj["WERE " ] = "WAS " - conj[" YOU " ] = " I " - conj["YOUR " ] = "MY " - conj[" IVE " ] =\ - conj[" I HAVE " ] = " YOU HAVE " - conj[" YOUVE " ] =\ - conj[" YOU HAVE "] = " I HAVE " - conj[" IM " ] =\ - conj[" I AM " ] = " YOU ARE " - conj[" YOURE " ] =\ - conj[" YOU ARE " ] = " I AM " - - # table of all answers - r[1] = "DONT YOU BELIEVE THAT I CAN _" - r[2] = "PERHAPS YOU WOULD LIKE TO BE ABLE TO _ ?" - r[3] = "YOU WANT ME TO BE ABLE TO _ ?" - r[4] = "PERHAPS YOU DONT WANT TO _ " - r[5] = "DO YOU WANT TO BE ABLE TO _ ?" - r[6] = "WHAT MAKES YOU THINK I AM _ ?" - r[7] = "DOES IT PLEASE YOU TO BELIEVE I AM _ ?" - r[8] = "PERHAPS YOU WOULD LIKE TO BE _ ?" - r[9] = "DO YOU SOMETIMES WISH YOU WERE _ ?" - r[10] = "DONT YOU REALLY _ ?" - r[11] = "WHY DONT YOU _ ?" - r[12] = "DO YOU WISH TO BE ABLE TO _ ?" - r[13] = "DOES THAT TROUBLE YOU ?" - r[14] = "TELL ME MORE ABOUT SUCH FEELINGS" - r[15] = "DO YOU OFTEN FEEL _ ?" - r[16] = "DO YOU ENJOY FEELING _ ?" - r[17] = "DO YOU REALLY BELIEVE I DONT _ ?" - r[18] = "PERHAPS IN GOOD TIME I WILL _ " - r[19] = "DO YOU WANT ME TO _ ?" - r[20] = "DO YOU THINK YOU SHOULD BE ABLE TO _ ?" - r[21] = "WHY CANT YOU _ ?" - r[22] = "WHY ARE YOU INTERESTED IN WHETHER OR NOT I AM _ ?" - r[23] = "WOULD YOU PREFER IF I WERE NOT _ ?" - r[24] = "PERHAPS IN YOUR FANTASIES I AM _ " - r[25] = "HOW DO YOU KNOW YOU CANT _ ?" - r[26] = "HAVE YOU TRIED ?" - r[27] = "PERHAPS YOU CAN NOW _ " - r[28] = "DID YOU COME TO ME BECAUSE YOU ARE _ ?" - r[29] = "HOW LONG HAVE YOU BEEN _ ?" - r[30] = "DO YOU BELIEVE ITS NORMAL TO BE _ ?" - r[31] = "DO YOU ENJOY BEING _ ?" - r[32] = "WE WERE DISCUSSING YOU -- NOT ME" - r[33] = "Oh, I _" - r[34] = "YOU'RE NOT REALLY TALKING ABOUT ME, ARE YOU ?" - r[35] = "WHAT WOULD IT MEAN TO YOU, IF YOU GOT _ ?" - r[36] = "WHY DO YOU WANT _ ?" - r[37] = "SUPPOSE YOU SOON GOT _" - r[38] = "WHAT IF YOU NEVER GOT _ ?" - r[39] = "I SOMETIMES ALSO WANT _" - r[40] = "WHY DO YOU ASK ?" - r[41] = "DOES THAT QUESTION INTEREST YOU ?" - r[42] = "WHAT ANSWER WOULD PLEASE YOU THE MOST ?" - r[43] = "WHAT DO YOU THINK ?" - r[44] = "ARE SUCH QUESTIONS IN YOUR MIND OFTEN ?" - r[45] = "WHAT IS IT THAT YOU REALLY WANT TO KNOW ?" - r[46] = "HAVE YOU ASKED ANYONE ELSE ?" - r[47] = "HAVE YOU ASKED SUCH QUESTIONS BEFORE ?" - r[48] = "WHAT ELSE COMES TO MIND WHEN YOU ASK THAT ?" - r[49] = "NAMES DON'T INTEREST ME" - r[50] = "I DONT CARE ABOUT NAMES -- PLEASE GO ON" - r[51] = "IS THAT THE REAL REASON ?" - r[52] = "DONT ANY OTHER REASONS COME TO MIND ?" - r[53] = "DOES THAT REASON EXPLAIN ANYTHING ELSE ?" - r[54] = "WHAT OTHER REASONS MIGHT THERE BE ?" - r[55] = "PLEASE DON'T APOLOGIZE !" - r[56] = "APOLOGIES ARE NOT NECESSARY" - r[57] = "WHAT FEELINGS DO YOU HAVE WHEN YOU APOLOGIZE ?" - r[58] = "DON'T BE SO DEFENSIVE" - r[59] = "WHAT DOES THAT DREAM SUGGEST TO YOU ?" - r[60] = "DO YOU DREAM OFTEN ?" - r[61] = "WHAT PERSONS APPEAR IN YOUR DREAMS ?" - r[62] = "ARE YOU DISTURBED BY YOUR DREAMS ?" - r[63] = "HOW DO YOU DO ... PLEASE STATE YOUR PROBLEM" - r[64] = "YOU DON'T SEEM QUITE CERTAIN" - r[65] = "WHY THE UNCERTAIN TONE ?" - r[66] = "CAN'T YOU BE MORE POSITIVE ?" - r[67] = "YOU AREN'T SURE ?" - r[68] = "DON'T YOU KNOW ?" - r[69] = "WHY NO _ ?" - r[70] = "DON'T SAY NO, IT'S ALWAYS SO NEGATIVE" - r[71] = "WHY NOT ?" - r[72] = "ARE YOU SURE ?" - r[73] = "WHY NO ?" - r[74] = "WHY ARE YOU CONCERNED ABOUT MY _ ?" - r[75] = "WHAT ABOUT YOUR OWN _ ?" - r[76] = "CAN'T YOU THINK ABOUT A SPECIFIC EXAMPLE ?" - r[77] = "WHEN ?" - r[78] = "WHAT ARE YOU THINKING OF ?" - r[79] = "REALLY, ALWAYS ?" - r[80] = "DO YOU REALLY THINK SO ?" - r[81] = "BUT YOU ARE NOT SURE YOU _ " - r[82] = "DO YOU DOUBT YOU _ ?" - r[83] = "IN WHAT WAY ?" - r[84] = "WHAT RESEMBLANCE DO YOU SEE ?" - r[85] = "WHAT DOES THE SIMILARITY SUGGEST TO YOU ?" - r[86] = "WHAT OTHER CONNECTION DO YOU SEE ?" - r[87] = "COULD THERE REALLY BE SOME CONNECTIONS ?" - r[88] = "HOW ?" - r[89] = "YOU SEEM QUITE POSITIVE" - r[90] = "ARE YOU SURE ?" - r[91] = "I SEE" - r[92] = "I UNDERSTAND" - r[93] = "WHY DO YOU BRING UP THE TOPIC OF FRIENDS ?" - r[94] = "DO YOUR FRIENDS WORRY YOU ?" - r[95] = "DO YOUR FRIENDS PICK ON YOU ?" - r[96] = "ARE YOU SURE YOU HAVE ANY FRIENDS ?" - r[97] = "DO YOU IMPOSE ON YOUR FRIENDS ?" - r[98] = "PERHAPS YOUR LOVE FOR FRIENDS WORRIES YOU" - r[99] = "DO COMPUTERS WORRY YOU ?" - r[100] = "ARE YOU TALKING ABOUT ME IN PARTICULAR ?" - r[101] = "ARE YOU FRIGHTENED BY MACHINES ?" - r[102] = "WHY DO YOU MENTION COMPUTERS ?" - r[103] = "WHAT DO YOU THINK MACHINES HAVE TO DO WITH YOUR PROBLEMS ?" - r[104] = "DON'T YOU THINK COMPUTERS CAN HELP PEOPLE ?" - r[105] = "WHAT IS IT ABOUT MACHINES THAT WORRIES YOU ?" - r[106] = "SAY, DO YOU HAVE ANY PSYCHOLOGICAL PROBLEMS ?" - r[107] = "WHAT DOES THAT SUGGEST TO YOU ?" - r[108] = "I SEE" - r[109] = "IM NOT SURE I UNDERSTAND YOU FULLY" - r[110] = "COME COME ELUCIDATE YOUR THOUGHTS" - r[111] = "CAN YOU ELABORATE ON THAT ?" - r[112] = "THAT IS QUITE INTERESTING" - r[113] = "WHY DO YOU HAVE PROBLEMS WITH MONEY ?" - r[114] = "DO YOU THINK MONEY IS EVERYTHING ?" - r[115] = "ARE YOU SURE THAT MONEY IS THE PROBLEM ?" - r[116] = "I THINK WE WANT TO TALK ABOUT YOU, NOT ABOUT ME" - r[117] = "WHAT'S ABOUT ME ?" - r[118] = "WHY DO YOU ALWAYS BRING UP MY NAME ?" - # table for looking up answers that - # fit to a certain keyword - k["CAN YOU"] = "1 2 3" - k["CAN I"] = "4 5" - k["YOU ARE"] =\ - k["YOURE"] = "6 7 8 9" - k["I DONT"] = "10 11 12 13" - k["I FEEL"] = "14 15 16" - k["WHY DONT YOU"] = "17 18 19" - k["WHY CANT I"] = "20 21" - k["ARE YOU"] = "22 23 24" - k["I CANT"] = "25 26 27" - k["I AM"] =\ - k["IM "] = "28 29 30 31" - k["YOU "] = "32 33 34" - k["I WANT"] = "35 36 37 38 39" - k["WHAT"] =\ - k["HOW"] =\ - k["WHO"] =\ - k["WHERE"] =\ - k["WHEN"] =\ - k["WHY"] = "40 41 42 43 44 45 46 47 48" - k["NAME"] = "49 50" - k["CAUSE"] = "51 52 53 54" - k["SORRY"] = "55 56 57 58" - k["DREAM"] = "59 60 61 62" - k["HELLO"] =\ - k["HI "] = "63" - k["MAYBE"] = "64 65 66 67 68" - k[" NO "] = "69 70 71 72 73" - k["YOUR"] = "74 75" - k["ALWAYS"] = "76 77 78 79" - k["THINK"] = "80 81 82" - k["LIKE"] = "83 84 85 86 87 88 89" - k["YES"] = "90 91 92" - k["FRIEND"] = "93 94 95 96 97 98" - k["COMPUTER"] = "99 100 101 102 103 104 105" - k["-"] = "106 107 108 109 110 111 112" - k["MONEY"] = "113 114 115" - k["ELIZA"] = "116 117 118" -} diff --git a/contrib/awk/awklib/eg/network/fingerclient.awk b/contrib/awk/awklib/eg/network/fingerclient.awk deleted file mode 100644 index bcc2c94cfa55..000000000000 --- a/contrib/awk/awklib/eg/network/fingerclient.awk +++ /dev/null @@ -1,7 +0,0 @@ -BEGIN { - NetService = "/inet/tcp/0/localhost/finger" - print "var{name}" |& NetService - while ((NetService |& getline) > 0) - print $0 - close(NetService) -} diff --git a/contrib/awk/awklib/eg/network/geturl.awk b/contrib/awk/awklib/eg/network/geturl.awk deleted file mode 100644 index 53853e50283b..000000000000 --- a/contrib/awk/awklib/eg/network/geturl.awk +++ /dev/null @@ -1,24 +0,0 @@ -BEGIN { - if (ARGC != 2) { - print "GETURL - retrieve Web page via HTTP 1.0" - print "IN:\n the URL as a command-line parameter" - print "PARAM(S):\n -v Proxy=MyProxy" - print "OUT:\n the page content on stdout" - print " the page header on stderr" - print "JK 16.05.1997" - print "ADR 13.08.2000" - exit - } - URL = ARGV[1]; ARGV[1] = "" - if (Proxy == "") Proxy = "127.0.0.1" - if (ProxyPort == 0) ProxyPort = 80 - if (Method == "") Method = "GET" - HttpService = "/inet/tcp/0/" Proxy "/" ProxyPort - ORS = RS = "\r\n\r\n" - print Method " " URL " HTTP/1.0" |& HttpService - HttpService |& getline Header - print Header > "/dev/stderr" - while ((HttpService |& getline) > 0) - printf "%s", $0 - close(HttpService) -} diff --git a/contrib/awk/awklib/eg/network/hello-serv.awk b/contrib/awk/awklib/eg/network/hello-serv.awk deleted file mode 100644 index 003ee088ac44..000000000000 --- a/contrib/awk/awklib/eg/network/hello-serv.awk +++ /dev/null @@ -1,14 +0,0 @@ -BEGIN { - RS = ORS = "\r\n" - HttpService = "/inet/tcp/8080/0/0" - Hello = "<HTML><HEAD>" \ - "<TITLE>A Famous Greeting</TITLE></HEAD>" \ - "<BODY><H1>Hello, world</H1></BODY></HTML>" - Len = length(Hello) + length(ORS) - print "HTTP/1.0 200 OK" |& HttpService - print "Content-Length: " Len ORS |& HttpService - print Hello |& HttpService - while ((HttpService |& getline) > 0) - continue; - close(HttpService) -} diff --git a/contrib/awk/awklib/eg/network/maze.awk b/contrib/awk/awklib/eg/network/maze.awk deleted file mode 100644 index 94888f8c61fe..000000000000 --- a/contrib/awk/awklib/eg/network/maze.awk +++ /dev/null @@ -1,73 +0,0 @@ -function SetUpServer() { - TopHeader = "<HTML><title>Walk through a maze</title>" - TopDoc = "\ - <h2>Please choose one of the following actions:</h2>\ - <UL>\ - <LI><A HREF=" MyPrefix "/AboutServer>About this server</A>\ - <LI><A HREF=" MyPrefix "/VRMLtest>Watch a simple VRML scene</A>\ - </UL>" - TopFooter = "</HTML>" - srand() -} -function HandleGET() { - if (MENU[2] == "AboutServer") { - Document = "If your browser has a VRML 2 plugin,\ - this server shows you a simple VRML scene." - } else if (MENU[2] == "VRMLtest") { - XSIZE = YSIZE = 11 # initially, everything is wall - for (y = 0; y < YSIZE; y++) - for (x = 0; x < XSIZE; x++) - Maze[x, y] = "#" - delete Maze[0, 1] # entry is not wall - delete Maze[XSIZE-1, YSIZE-2] # exit is not wall - MakeMaze(1, 1) - Document = "\ -#VRML V2.0 utf8\n\ -Group {\n\ - children [\n\ - PointLight {\n\ - ambientIntensity 0.2\n\ - color 0.7 0.7 0.7\n\ - location 0.0 8.0 10.0\n\ - }\n\ - DEF B1 Background {\n\ - skyColor [0 0 0, 1.0 1.0 1.0 ]\n\ - skyAngle 1.6\n\ - groundColor [1 1 1, 0.8 0.8 0.8, 0.2 0.2 0.2 ]\n\ - groundAngle [ 1.2 1.57 ]\n\ - }\n\ - DEF Wall Shape {\n\ - geometry Box {size 1 1 1}\n\ - appearance Appearance { material Material { diffuseColor 0 0 1 } }\n\ - }\n\ - DEF Entry Viewpoint {\n\ - position 0.5 1.0 5.0\n\ - orientation 0.0 0.0 -1.0 0.52\n\ - }\n" - for (i in Maze) { - split(i, t, SUBSEP) - Document = Document " Transform { translation " - Document = Document t[1] " 0 -" t[2] " children USE Wall }\n" - } - Document = Document " ] # end of group for world\n}" - Reason = "OK" ORS "Content-type: model/vrml" - Header = Footer = "" - } -} -function MakeMaze(x, y) { - delete Maze[x, y] # here we are, we have no wall here - p = 0 # count unvisited fields in all directions - if (x-2 SUBSEP y in Maze) d[p++] = "-x" - if (x SUBSEP y-2 in Maze) d[p++] = "-y" - if (x+2 SUBSEP y in Maze) d[p++] = "+x" - if (x SUBSEP y+2 in Maze) d[p++] = "+y" - if (p>0) { # if there are univisited fields, go there - p = int(p*rand()) # choose one unvisited field at random - if (d[p] == "-x") { delete Maze[x - 1, y]; MakeMaze(x - 2, y) - } else if (d[p] == "-y") { delete Maze[x, y - 1]; MakeMaze(x, y - 2) - } else if (d[p] == "+x") { delete Maze[x + 1, y]; MakeMaze(x + 2, y) - } else if (d[p] == "+y") { delete Maze[x, y + 1]; MakeMaze(x, y + 2) - } # we are back from recursion - MakeMaze(x, y); # try again while there are unvisited fields - } -} diff --git a/contrib/awk/awklib/eg/network/mobag.awk b/contrib/awk/awklib/eg/network/mobag.awk deleted file mode 100644 index a8c55008b78d..000000000000 --- a/contrib/awk/awklib/eg/network/mobag.awk +++ /dev/null @@ -1,72 +0,0 @@ -BEGIN { - if (ARGC != 2) { - print "MOBAG - a simple mobile agent" - print "CALL:\n gawk -f mobag.awk mobag.awk" - print "IN:\n the name of this script as a command-line parameter" - print "PARAM:\n -v MyOrigin=myhost.com" - print "OUT:\n the result on stdout" - print "JK 29.03.1998 01.04.1998" - exit - } - if (MyOrigin == "") { - "uname -n" | getline MyOrigin - close("uname -n") - } -} -#ReadMySelf -/^function / { FUNC = $2 } -/^END/ || /^#ReadMySelf/ { FUNC = $1 } -FUNC != "" { MOBFUN[FUNC] = MOBFUN[FUNC] RS $0 } -(FUNC != "") && (/^}/ || /^#EndOfMySelf/) \ - { FUNC = "" } -#EndOfMySelf -function migrate(Destination, MobCode, Label) { - MOBVAR["Label"] = Label - MOBVAR["Destination"] = Destination - RS = ORS = "\r\n" - HttpService = "/inet/tcp/0/" Destination - for (i in MOBFUN) - MobCode = (MobCode "\n" MOBFUN[i]) - MobCode = MobCode "\n\nBEGIN {" - for (i in MOBVAR) - MobCode = (MobCode "\n MOBVAR[\"" i "\"] = \"" MOBVAR[i] "\"") - MobCode = MobCode "\n}\n" - print "POST /cgi-bin/PostAgent.sh HTTP/1.0" |& HttpService - print "Content-length:", length(MobCode) ORS |& HttpService - printf "%s", MobCode |& HttpService - while ((HttpService |& getline) > 0) - print $0 - close(HttpService) -} -END { - if (ARGC != 2) exit # stop when called with wrong parameters - if (MyOrigin != "") # is this the originating host? - MyInit() # if so, initialize the application - else # we are on a host with migrated data - MyJob() # so we do our job -} -function MyInit() { - MOBVAR["MyOrigin"] = MyOrigin - MOBVAR["Machines"] = "localhost/80 max/80 moritz/80 castor/80" - split(MOBVAR["Machines"], Machines) # which host is the first? - migrate(Machines[1], "", "") # go to the first host - while (("/inet/tcp/8080/0/0" |& getline) > 0) # wait for result - print $0 # print result - close("/inet/tcp/8080/0/0") -} -function MyJob() { - # forget this host - sub(MOBVAR["Destination"], "", MOBVAR["Machines"]) - MOBVAR["Result"]=MOBVAR["Result"] SUBSEP SUBSEP MOBVAR["Destination"] ":" - while (("who" | getline) > 0) # who is logged in? - MOBVAR["Result"] = MOBVAR["Result"] SUBSEP $0 - close("who") - if (index(MOBVAR["Machines"], "/") > 0) { # any more machines to visit? - split(MOBVAR["Machines"], Machines) # which host is next? - migrate(Machines[1], "", "") # go there - } else { # no more machines - gsub(SUBSEP, "\n", MOBVAR["Result"]) # send result to origin - print MOBVAR["Result"] |& "/inet/tcp/0/" MOBVAR["MyOrigin"] "/8080" - close("/inet/tcp/0/" MOBVAR["MyOrigin"] "/8080") - } -} diff --git a/contrib/awk/awklib/eg/network/panic.awk b/contrib/awk/awklib/eg/network/panic.awk deleted file mode 100644 index 6db8c46d4b04..000000000000 --- a/contrib/awk/awklib/eg/network/panic.awk +++ /dev/null @@ -1,18 +0,0 @@ -BEGIN { - RS = ORS = "\r\n" - if (MyPort == 0) MyPort = 8080 - HttpService = "/inet/tcp/" MyPort "/0/0" - Hello = "<HTML><HEAD><TITLE>Out Of Service</TITLE>" \ - "</HEAD><BODY><H1>" \ - "This site is temporarily out of service." \ - "</H1></BODY></HTML>" - Len = length(Hello) + length(ORS) - while ("awk" != "complex") { - print "HTTP/1.0 200 OK" |& HttpService - print "Content-Length: " Len ORS |& HttpService - print Hello |& HttpService - while ((HttpService |& getline) > 0) - continue; - close(HttpService) - } -} diff --git a/contrib/awk/awklib/eg/network/protbase.awk b/contrib/awk/awklib/eg/network/protbase.awk deleted file mode 100644 index 16199e45121e..000000000000 --- a/contrib/awk/awklib/eg/network/protbase.awk +++ /dev/null @@ -1,11 +0,0 @@ -{ request = request "\n" $0 } - -END { - BLASTService = "/inet/tcp/0/www.ncbi.nlm.nih.gov/80" - printf "POST /cgi-bin/BLAST/nph-blast_report HTTP/1.0\n" |& BLASTService - printf "Content-Length: " length(request) "\n\n" |& BLASTService - printf request |& BLASTService - while ((BLASTService |& getline) > 0) - print $0 - close(BLASTService) -} diff --git a/contrib/awk/awklib/eg/network/protbase.request b/contrib/awk/awklib/eg/network/protbase.request deleted file mode 100644 index 4c5c3d2c1d2f..000000000000 --- a/contrib/awk/awklib/eg/network/protbase.request +++ /dev/null @@ -1,7 +0,0 @@ -PROGRAM blastn -DATALIB month -EXPECT 0.75 -BEGIN ->GAWK310 the gawking gene GNU AWK -tgcttggctgaggagccataggacgagagcttcctggtgaagtgtgtttcttgaaatcat -caccaccatggacagcaaa diff --git a/contrib/awk/awklib/eg/network/protbase.result b/contrib/awk/awklib/eg/network/protbase.result deleted file mode 100644 index a087af43fefa..000000000000 --- a/contrib/awk/awklib/eg/network/protbase.result +++ /dev/null @@ -1,9 +0,0 @@ -Sequences producing significant alignments: (bits) Value - -gb|AC021182.14|AC021182 Homo sapiens chromosome 7 clone RP11-733... 38 0.20 -gb|AC021056.12|AC021056 Homo sapiens chromosome 3 clone RP11-115... 38 0.20 -emb|AL160278.10|AL160278 Homo sapiens chromosome 9 clone RP11-57... 38 0.20 -emb|AL391139.11|AL391139 Homo sapiens chromosome X clone RP11-35... 38 0.20 -emb|AL365192.6|AL365192 Homo sapiens chromosome 6 clone RP3-421H... 38 0.20 -emb|AL138812.9|AL138812 Homo sapiens chromosome 11 clone RP1-276... 38 0.20 -gb|AC073881.3|AC073881 Homo sapiens chromosome 15 clone CTD-2169... 38 0.20 diff --git a/contrib/awk/awklib/eg/network/remconf.awk b/contrib/awk/awklib/eg/network/remconf.awk deleted file mode 100644 index f4f21e1a9af3..000000000000 --- a/contrib/awk/awklib/eg/network/remconf.awk +++ /dev/null @@ -1,54 +0,0 @@ -function SetUpServer() { - TopHeader = "<HTML><title>Remote Configuration</title>" - TopDoc = "<BODY>\ - <h2>Please choose one of the following actions:</h2>\ - <UL>\ - <LI><A HREF=" MyPrefix "/AboutServer>About this server</A></LI>\ - <LI><A HREF=" MyPrefix "/ReadConfig>Read Configuration</A></LI>\ - <LI><A HREF=" MyPrefix "/CheckConfig>Check Configuration</A></LI>\ - <LI><A HREF=" MyPrefix "/ChangeConfig>Change Configuration</A></LI>\ - <LI><A HREF=" MyPrefix "/SaveConfig>Save Configuration</A></LI>\ - </UL>" - TopFooter = "</BODY></HTML>" - if (ConfigFile == "") ConfigFile = "config.asc" -} -function HandleGET() { - if(MENU[2] == "AboutServer") { - Document = "This is a GUI for remote configuration of an\ - embedded system. It is is implemented as one GAWK script." - } else if (MENU[2] == "ReadConfig") { - RS = "\n" - while ((getline < ConfigFile) > 0) - config[$1] = $2; - close(ConfigFile) - RS = "\r\n" - Document = "Configuration has been read." - } else if (MENU[2] == "CheckConfig") { - Document = "<TABLE BORDER=1 CELLPADDING=5>" - for (i in config) - Document = Document "<TR><TD>" i "</TD>" \ - "<TD>" config[i] "</TD></TR>" - Document = Document "</TABLE>" - } else if (MENU[2] == "ChangeConfig") { - if ("Param" in GETARG) { # any parameter to set? - if (GETARG["Param"] in config) { # is parameter valid? - config[GETARG["Param"]] = GETARG["Value"] - Document = (GETARG["Param"] " = " GETARG["Value"] ".") - } else { - Document = "Parameter <b>" GETARG["Param"] "</b> is invalid." - } - } else { - Document = "<FORM method=GET><h4>Change one parameter</h4>\ - <TABLE BORDER CELLPADDING=5>\ - <TR><TD>Parameter</TD><TD>Value</TD></TR>\ - <TR><TD><input type=text name=Param value=\"\" size=20></TD>\ - <TD><input type=text name=Value value=\"\" size=40></TD>\ - </TR></TABLE><input type=submit value=\"Set\"></FORM>" - } - } else if (MENU[2] == "SaveConfig") { - for (i in config) - printf("%s %s\n", i, config[i]) > ConfigFile - close(ConfigFile) - Document = "Configuration has been saved." - } -} diff --git a/contrib/awk/awklib/eg/network/statist.awk b/contrib/awk/awklib/eg/network/statist.awk deleted file mode 100644 index 8a583940ef74..000000000000 --- a/contrib/awk/awklib/eg/network/statist.awk +++ /dev/null @@ -1,85 +0,0 @@ -function SetUpServer() { - TopHeader = "<HTML><title>Statistics with GAWK</title>" - TopDoc = "<BODY>\ - <h2>Please choose one of the following actions:</h2>\ - <UL>\ - <LI><A HREF=" MyPrefix "/AboutServer>About this server</A></LI>\ - <LI><A HREF=" MyPrefix "/EnterParameters>Enter Parameters</A></LI>\ - </UL>" - TopFooter = "</BODY></HTML>" - GnuPlot = "gnuplot 2>&1" - m1=m2=0; v1=v2=1; n1=n2=10 -} -function HandleGET() { - if(MENU[2] == "AboutServer") { - Document = "This is a GUI for a statistical computation.\ - It compares means and variances of two distributions.\ - It is implemented as one GAWK script and uses GNUPLOT." - } else if (MENU[2] == "EnterParameters") { - Document = "" - if ("m1" in GETARG) { # are there parameters to compare? - Document = Document "<SCRIPT LANGUAGE=\"JavaScript\">\ - setTimeout(\"window.open(\\\"" MyPrefix "/Image" systime()\ - "\\\",\\\"dist\\\", \\\"status=no\\\");\", 1000); </SCRIPT>" - m1 = GETARG["m1"]; v1 = GETARG["v1"]; n1 = GETARG["n1"] - m2 = GETARG["m2"]; v2 = GETARG["v2"]; n2 = GETARG["n2"] - t = (m1-m2)/sqrt(v1/n1+v2/n2) - df = (v1/n1+v2/n2)*(v1/n1+v2/n2)/((v1/n1)*(v1/n1)/(n1-1) \ - + (v2/n2)*(v2/n2) /(n2-1)) - if (v1>v2) { - f = v1/v2 - df1 = n1 - 1 - df2 = n2 - 1 - } else { - f = v2/v1 - df1 = n2 - 1 - df2 = n1 - 1 - } - print "pt=ibeta(" df/2 ",0.5," df/(df+t*t) ")" |& GnuPlot - print "pF=2.0*ibeta(" df2/2 "," df1/2 "," \ - df2/(df2+df1*f) ")" |& GnuPlot - print "print pt, pF" |& GnuPlot - RS="\n"; GnuPlot |& getline; RS="\r\n" # $1 is pt, $2 is pF - print "invsqrt2pi=1.0/sqrt(2.0*pi)" |& GnuPlot - print "nd(x)=invsqrt2pi/sd*exp(-0.5*((x-mu)/sd)**2)" |& GnuPlot - print "set term png small color" |& GnuPlot - #print "set term postscript color" |& GnuPlot - #print "set term gif medium size 320,240" |& GnuPlot - print "set yrange[-0.3:]" |& GnuPlot - print "set label 'p(m1=m2) =" $1 "' at 0,-0.1 left" |& GnuPlot - print "set label 'p(v1=v2) =" $2 "' at 0,-0.2 left" |& GnuPlot - print "plot mu=" m1 ",sd=" sqrt(v1) ", nd(x) title 'sample 1',\ - mu=" m2 ",sd=" sqrt(v2) ", nd(x) title 'sample 2'" |& GnuPlot - print "quit" |& GnuPlot - GnuPlot |& getline Image - while ((GnuPlot |& getline) > 0) - Image = Image RS $0 - close(GnuPlot) - } - Document = Document "\ - <h3>Do these samples have the same Gaussian distribution?</h3>\ - <FORM METHOD=GET> <TABLE BORDER CELLPADDING=5>\ - <TR>\ - <TD>1. Mean </TD> - <TD><input type=text name=m1 value=" m1 " size=8></TD>\ - <TD>1. Variance</TD> - <TD><input type=text name=v1 value=" v1 " size=8></TD>\ - <TD>1. Count </TD> - <TD><input type=text name=n1 value=" n1 " size=8></TD>\ - </TR><TR>\ - <TD>2. Mean </TD> - <TD><input type=text name=m2 value=" m2 " size=8></TD>\ - <TD>2. Variance</TD> - <TD><input type=text name=v2 value=" v2 " size=8></TD>\ - <TD>2. Count </TD> - <TD><input type=text name=n2 value=" n2 " size=8></TD>\ - </TR> <input type=submit value=\"Compute\">\ - </TABLE></FORM><BR>" - } else if (MENU[2] ~ "Image") { - Reason = "OK" ORS "Content-type: image/png" - #Reason = "OK" ORS "Content-type: application/x-postscript" - #Reason = "OK" ORS "Content-type: image/gif" - Header = Footer = "" - Document = Image - } -} diff --git a/contrib/awk/awklib/eg/network/stoxdata.txt b/contrib/awk/awklib/eg/network/stoxdata.txt deleted file mode 100644 index 1b6d015eef16..000000000000 --- a/contrib/awk/awklib/eg/network/stoxdata.txt +++ /dev/null @@ -1,4 +0,0 @@ -Date,Open,High,Low,Close,Volume -9-Oct-00,22.75,22.75,21.375,22.375,7888500 -6-Oct-00,23.8125,24.9375,21.5625,22,10701100 -5-Oct-00,24.4375,24.625,23.125,23.50,5810300 diff --git a/contrib/awk/awklib/eg/network/stoxpred.awk b/contrib/awk/awklib/eg/network/stoxpred.awk deleted file mode 100644 index 5cdc2a8d65a2..000000000000 --- a/contrib/awk/awklib/eg/network/stoxpred.awk +++ /dev/null @@ -1,116 +0,0 @@ -function ReadQuotes() { - # Retrieve historical data for each ticker symbol - FS = "," - for (stock = 1; stock <= StockCount; stock++) { - URL = "http://chart.yahoo.com/table.csv?s=" name[stock] \ - "&a=" month "&b=" day "&c=" year-1 \ - "&d=" month "&e=" day "&f=" year \ - "g=d&q=q&y=0&z=" name[stock] "&x=.csv" - printf("GET " URL " HTTP/1.0\r\n\r\n") |& YahooData - while ((YahooData |& getline) > 0) { - if (NF == 6 && $1 ~ /Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/) { - if (stock == 1) - days[++daycount] = $1; - quote[$1, stock] = $5 - } - } - close(YahooData) - } - FS = " " -} -function CleanUp() { - # clean up time series; eliminate incomplete data sets - for (d = 1; d <= daycount; d++) { - for (stock = 1; stock <= StockCount; stock++) - if (! ((days[d], stock) in quote)) - stock = StockCount + 10 - if (stock > StockCount + 1) - continue - datacount++ - for (stock = 1; stock <= StockCount; stock++) - data[datacount, stock] = int(0.5 + quote[days[d], stock]) - } - delete quote - delete days -} -function Prediction() { - # Predict each ticker symbol by prolonging yesterday's trend - for (stock = 1; stock <= StockCount; stock++) { - if (data[1, stock] > data[2, stock]) { - predict[stock] = "up" - } else if (data[1, stock] < data[2, stock]) { - predict[stock] = "down" - } else { - predict[stock] = "neutral" - } - if ((data[1, stock] > data[2, stock]) && (data[2, stock] > data[3, stock])) - hot[stock] = 1 - if ((data[1, stock] < data[2, stock]) && (data[2, stock] < data[3, stock])) - avoid[stock] = 1 - } - # Do a plausibility check: how many predictions proved correct? - for (s = 1; s <= StockCount; s++) { - for (d = 1; d <= datacount-2; d++) { - if (data[d+1, s] > data[d+2, s]) { - UpCount++ - } else if (data[d+1, s] < data[d+2, s]) { - DownCount++ - } else { - NeutralCount++ - } - if (((data[d, s] > data[d+1, s]) && (data[d+1, s] > data[d+2, s])) || - ((data[d, s] < data[d+1, s]) && (data[d+1, s] < data[d+2, s])) || - ((data[d, s] == data[d+1, s]) && (data[d+1, s] == data[d+2, s]))) - CorrectCount++ - } - } -} -function Report() { - # Generate report - report = "\nThis is your daily " - report = report "stock market report for "strftime("%A, %B %d, %Y")".\n" - report = report "Here are the predictions for today:\n\n" - for (stock = 1; stock <= StockCount; stock++) - report = report "\t" name[stock] "\t" predict[stock] "\n" - for (stock in hot) { - if (HotCount++ == 0) - report = report "\nThe most promising shares for today are these:\n\n" - report = report "\t" name[stock] "\t\thttp://biz.yahoo.com/n/" \ - tolower(substr(name[stock], 1, 1)) "/" tolower(name[stock]) ".html\n" - } - for (stock in avoid) { - if (AvoidCount++ == 0) - report = report "\nThe stock shares to avoid today are these:\n\n" - report = report "\t" name[stock] "\t\thttp://biz.yahoo.com/n/" \ - tolower(substr(name[stock], 1, 1)) "/" tolower(name[stock]) ".html\n" - } - report = report "\nThis sums up to " HotCount+0 " winners and " AvoidCount+0 - report = report " losers. When using this kind\nof prediction scheme for" - report = report " the 12 months which lie behind us,\nwe get " UpCount - report = report " 'ups' and " DownCount " 'downs' and " NeutralCount - report = report " 'neutrals'. Of all\nthese " UpCount+DownCount+NeutralCount - report = report " predictions " CorrectCount " proved correct next day.\n" - report = report "A success rate of "\ - int(100*CorrectCount/(UpCount+DownCount+NeutralCount)) "%.\n" - report = report "Random choice would have produced a 33% success rate.\n" - report = report "Disclaimer: Like every other prediction of the stock\n" - report = report "market, this report is, of course, complete nonsense.\n" - report = report "If you are stupid enough to believe these predictions\n" - report = report "you should visit a doctor who can treat your ailment." -} -function SendMail() { - # send report to customers - customer["uncle.scrooge@ducktown.gov"] = "Uncle Scrooge" - customer["more@utopia.org" ] = "Sir Thomas More" - customer["spinoza@denhaag.nl" ] = "Baruch de Spinoza" - customer["marx@highgate.uk" ] = "Karl Marx" - customer["keynes@the.long.run" ] = "John Maynard Keynes" - customer["bierce@devil.hell.org" ] = "Ambrose Bierce" - customer["laplace@paris.fr" ] = "Pierre Simon de Laplace" - for (c in customer) { - MailPipe = "mail -s 'Daily Stock Prediction Newsletter'" c - print "Good morning " customer[c] "," | MailPipe - print report "\n.\n" | MailPipe - close(MailPipe) - } -} diff --git a/contrib/awk/awklib/eg/network/testserv.awk b/contrib/awk/awklib/eg/network/testserv.awk deleted file mode 100644 index 812bfe6a617a..000000000000 --- a/contrib/awk/awklib/eg/network/testserv.awk +++ /dev/null @@ -1,12 +0,0 @@ -BEGIN { - CGI_setup("GET", - "http://www.gnu.org/cgi-bin/foo?p1=stuff&p2=stuff%26junk" \ - "&percent=a %25 sign", - "1.0") - for (i in MENU) - printf "MENU[\"%s\"] = %s\n", i, MENU[i] - for (i in PARAM) - printf "PARAM[\"%s\"] = %s\n", i, PARAM[i] - for (i in GETARG) - printf "GETARG[\"%s\"] = %s\n", i, GETARG[i] -} diff --git a/contrib/awk/awklib/eg/network/urlchk.awk b/contrib/awk/awklib/eg/network/urlchk.awk deleted file mode 100644 index 6ddedfa854df..000000000000 --- a/contrib/awk/awklib/eg/network/urlchk.awk +++ /dev/null @@ -1,28 +0,0 @@ -BEGIN { - if (ARGC != 2) { - print "URLCHK - check if URLs have changed" - print "IN:\n the file with URLs as a command-line parameter" - print " file contains URL, old length, new length" - print "PARAMS:\n -v Proxy=MyProxy -v ProxyPort=8080" - print "OUT:\n same as file with URLs" - print "JK 02.03.1998" - exit - } - URLfile = ARGV[1]; ARGV[1] = "" - if (Proxy != "") Proxy = " -v Proxy=" Proxy - if (ProxyPort != "") ProxyPort = " -v ProxyPort=" ProxyPort - while ((getline < URLfile) > 0) - Length[$1] = $3 + 0 - close(URLfile) # now, URLfile is read in and can be updated - GetHeader = "gawk " Proxy ProxyPort " -v Method=\"HEAD\" -f geturl.awk " - for (i in Length) { - GetThisHeader = GetHeader i " 2>&1" - while ((GetThisHeader | getline) > 0) - if (toupper($0) ~ /CONTENT-LENGTH/) NewLength = $2 + 0 - close(GetThisHeader) - print i, Length[i], NewLength > URLfile - if (Length[i] != NewLength) # report only changed URLs - print i, Length[i], NewLength - } - close(URLfile) -} diff --git a/contrib/awk/awklib/eg/network/webgrab.awk b/contrib/awk/awklib/eg/network/webgrab.awk deleted file mode 100644 index 41738805afb2..000000000000 --- a/contrib/awk/awklib/eg/network/webgrab.awk +++ /dev/null @@ -1,6 +0,0 @@ -BEGIN { RS = "http://[#%&\\+\\-\\./0-9\\:;\\?A-Z_a-z\\~]*" } -RT != "" { - command = ("gawk -v Proxy=MyProxy -f geturl.awk " RT \ - " > doc" NR ".html") - print command -} diff --git a/contrib/awk/awklib/eg/prog/alarm.awk b/contrib/awk/awklib/eg/prog/alarm.awk deleted file mode 100644 index 26252fa1a820..000000000000 --- a/contrib/awk/awklib/eg/prog/alarm.awk +++ /dev/null @@ -1,85 +0,0 @@ -# alarm.awk --- set an alarm -# -# Requires gettimeofday library function -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# May 1993 - -# usage: alarm time [ "message" [ count [ delay ] ] ] - -BEGIN \ -{ - # Initial argument sanity checking - usage1 = "usage: alarm time ['message' [count [delay]]]" - usage2 = sprintf("\t(%s) time ::= hh:mm", ARGV[1]) - - if (ARGC < 2) { - print usage1 > "/dev/stderr" - print usage2 > "/dev/stderr" - exit 1 - } else if (ARGC == 5) { - delay = ARGV[4] + 0 - count = ARGV[3] + 0 - message = ARGV[2] - } else if (ARGC == 4) { - count = ARGV[3] + 0 - message = ARGV[2] - } else if (ARGC == 3) { - message = ARGV[2] - } else if (ARGV[1] !~ /[0-9]?[0-9]:[0-9][0-9]/) { - print usage1 > "/dev/stderr" - print usage2 > "/dev/stderr" - exit 1 - } - - # set defaults for once we reach the desired time - if (delay == 0) - delay = 180 # 3 minutes - if (count == 0) - count = 5 - if (message == "") - message = sprintf("\aIt is now %s!\a", ARGV[1]) - else if (index(message, "\a") == 0) - message = "\a" message "\a" - # split up alarm time - split(ARGV[1], atime, ":") - hour = atime[1] + 0 # force numeric - minute = atime[2] + 0 # force numeric - - # get current broken down time - gettimeofday(now) - - # if time given is 12-hour hours and it's after that - # hour, e.g., `alarm 5:30' at 9 a.m. means 5:30 p.m., - # then add 12 to real hour - if (hour < 12 && now["hour"] > hour) - hour += 12 - - # set target time in seconds since midnight - target = (hour * 60 * 60) + (minute * 60) - - # get current time in seconds since midnight - current = (now["hour"] * 60 * 60) + \ - (now["minute"] * 60) + now["second"] - - # how long to sleep for - naptime = target - current - if (naptime <= 0) { - print "time is in the past!" > "/dev/stderr" - exit 1 - } - # zzzzzz..... go away if interrupted - if (system(sprintf("sleep %d", naptime)) != 0) - exit 1 - - # time to notify! - command = sprintf("sleep %d", delay) - for (i = 1; i <= count; i++) { - print message - # if sleep command interrupted, go away - if (system(command) != 0) - break - } - - exit 0 -} diff --git a/contrib/awk/awklib/eg/prog/awksed.awk b/contrib/awk/awklib/eg/prog/awksed.awk deleted file mode 100644 index 4b188c64d0a9..000000000000 --- a/contrib/awk/awklib/eg/prog/awksed.awk +++ /dev/null @@ -1,31 +0,0 @@ -# awksed.awk --- do s/foo/bar/g using just print -# Thanks to Michael Brennan for the idea -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# August 1995 - -function usage() -{ - print "usage: awksed pat repl [files...]" > "/dev/stderr" - exit 1 -} - -BEGIN { - # validate arguments - if (ARGC < 3) - usage() - - RS = ARGV[1] - ORS = ARGV[2] - - # don't use arguments as files - ARGV[1] = ARGV[2] = "" -} - -# look ma, no hands! -{ - if (RT == "") - printf "%s", $0 - else - print -} diff --git a/contrib/awk/awklib/eg/prog/cut.awk b/contrib/awk/awklib/eg/prog/cut.awk deleted file mode 100644 index d9c6c9b945f0..000000000000 --- a/contrib/awk/awklib/eg/prog/cut.awk +++ /dev/null @@ -1,139 +0,0 @@ -# cut.awk --- implement cut in awk -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# May 1993 - -# Options: -# -f list Cut fields -# -d c Field delimiter character -# -c list Cut characters -# -# -s Suppress lines without the delimiter -# -# Requires getopt and join library functions - -function usage( e1, e2) -{ - e1 = "usage: cut [-f list] [-d c] [-s] [files...]" - e2 = "usage: cut [-c list] [files...]" - print e1 > "/dev/stderr" - print e2 > "/dev/stderr" - exit 1 -} -BEGIN \ -{ - FS = "\t" # default - OFS = FS - while ((c = getopt(ARGC, ARGV, "sf:c:d:")) != -1) { - if (c == "f") { - by_fields = 1 - fieldlist = Optarg - } else if (c == "c") { - by_chars = 1 - fieldlist = Optarg - OFS = "" - } else if (c == "d") { - if (length(Optarg) > 1) { - printf("Using first character of %s" \ - " for delimiter\n", Optarg) > "/dev/stderr" - Optarg = substr(Optarg, 1, 1) - } - FS = Optarg - OFS = FS - if (FS == " ") # defeat awk semantics - FS = "[ ]" - } else if (c == "s") - suppress++ - else - usage() - } - - for (i = 1; i < Optind; i++) - ARGV[i] = "" - if (by_fields && by_chars) - usage() - - if (by_fields == 0 && by_chars == 0) - by_fields = 1 # default - - if (fieldlist == "") { - print "cut: needs list for -c or -f" > "/dev/stderr" - exit 1 - } - - if (by_fields) - set_fieldlist() - else - set_charlist() -} -function set_fieldlist( n, m, i, j, k, f, g) -{ - n = split(fieldlist, f, ",") - j = 1 # index in flist - for (i = 1; i <= n; i++) { - if (index(f[i], "-") != 0) { # a range - m = split(f[i], g, "-") - if (m != 2 || g[1] >= g[2]) { - printf("bad field list: %s\n", - f[i]) > "/dev/stderr" - exit 1 - } - for (k = g[1]; k <= g[2]; k++) - flist[j++] = k - } else - flist[j++] = f[i] - } - nfields = j - 1 -} -function set_charlist( field, i, j, f, g, t, - filler, last, len) -{ - field = 1 # count total fields - n = split(fieldlist, f, ",") - j = 1 # index in flist - for (i = 1; i <= n; i++) { - if (index(f[i], "-") != 0) { # range - m = split(f[i], g, "-") - if (m != 2 || g[1] >= g[2]) { - printf("bad character list: %s\n", - f[i]) > "/dev/stderr" - exit 1 - } - len = g[2] - g[1] + 1 - if (g[1] > 1) # compute length of filler - filler = g[1] - last - 1 - else - filler = 0 - if (filler) - t[field++] = filler - t[field++] = len # length of field - last = g[2] - flist[j++] = field - 1 - } else { - if (f[i] > 1) - filler = f[i] - last - 1 - else - filler = 0 - if (filler) - t[field++] = filler - t[field++] = 1 - last = f[i] - flist[j++] = field - 1 - } - } - FIELDWIDTHS = join(t, 1, field - 1) - nfields = j - 1 -} -{ - if (by_fields && suppress && index($0, FS) != 0) - next - - for (i = 1; i <= nfields; i++) { - if ($flist[i] != "") { - printf "%s", $flist[i] - if (i < nfields && $flist[i+1] != "") - printf "%s", OFS - } - } - print "" -} diff --git a/contrib/awk/awklib/eg/prog/dupword.awk b/contrib/awk/awklib/eg/prog/dupword.awk deleted file mode 100644 index a2cc7d2b2b12..000000000000 --- a/contrib/awk/awklib/eg/prog/dupword.awk +++ /dev/null @@ -1,21 +0,0 @@ -# dupword.awk --- find duplicate words in text -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# December 1991 -# Revised October 2000 - -{ - $0 = tolower($0) - gsub(/[^[:alnum:][:blank:]]/, " "); - $0 = $0 # re-split - if (NF == 0) - next - if ($1 == prev) - printf("%s:%d: duplicate %s\n", - FILENAME, FNR, $1) - for (i = 2; i <= NF; i++) - if ($i == $(i-1)) - printf("%s:%d: duplicate %s\n", - FILENAME, FNR, $i) - prev = $NF -} diff --git a/contrib/awk/awklib/eg/prog/egrep.awk b/contrib/awk/awklib/eg/prog/egrep.awk deleted file mode 100644 index 73f175ca6ce5..000000000000 --- a/contrib/awk/awklib/eg/prog/egrep.awk +++ /dev/null @@ -1,102 +0,0 @@ -# egrep.awk --- simulate egrep in awk -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# May 1993 - -# Options: -# -c count of lines -# -s silent - use exit value -# -v invert test, success if no match -# -i ignore case -# -l print filenames only -# -e argument is pattern -# -# Requires getopt and file transition library functions - -BEGIN { - while ((c = getopt(ARGC, ARGV, "ce:svil")) != -1) { - if (c == "c") - count_only++ - else if (c == "s") - no_print++ - else if (c == "v") - invert++ - else if (c == "i") - IGNORECASE = 1 - else if (c == "l") - filenames_only++ - else if (c == "e") - pattern = Optarg - else - usage() - } - if (pattern == "") - pattern = ARGV[Optind++] - - for (i = 1; i < Optind; i++) - ARGV[i] = "" - if (Optind >= ARGC) { - ARGV[1] = "-" - ARGC = 2 - } else if (ARGC - Optind > 1) - do_filenames++ - -# if (IGNORECASE) -# pattern = tolower(pattern) -} -#{ -# if (IGNORECASE) -# $0 = tolower($0) -#} -function beginfile(junk) -{ - fcount = 0 -} -function endfile(file) -{ - if (! no_print && count_only) - if (do_filenames) - print file ":" fcount - else - print fcount - - total += fcount -} -{ - matches = ($0 ~ pattern) - if (invert) - matches = ! matches - - fcount += matches # 1 or 0 - - if (! matches) - next - - if (! count_only) { - if (no_print) - nextfile - - if (filenames_only) { - print FILENAME - nextfile - } - - if (do_filenames) - print FILENAME ":" $0 - else - print - } -} -END \ -{ - if (total == 0) - exit 1 - exit 0 -} -function usage( e) -{ - e = "Usage: egrep [-csvil] [-e pat] [files ...]" - e = e "\n\tegrep [-csvil] pat [files ...]" - print e > "/dev/stderr" - exit 1 -} diff --git a/contrib/awk/awklib/eg/prog/extract.awk b/contrib/awk/awklib/eg/prog/extract.awk deleted file mode 100644 index 5cb191ae1cd9..000000000000 --- a/contrib/awk/awklib/eg/prog/extract.awk +++ /dev/null @@ -1,75 +0,0 @@ -# extract.awk --- extract files and run programs -# from texinfo files -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# May 1993 -# Revised September 2000 - -BEGIN { IGNORECASE = 1 } - -/^@c(omment)?[ \t]+system/ \ -{ - if (NF < 3) { - e = (FILENAME ":" FNR) - e = (e ": badly formed `system' line") - print e > "/dev/stderr" - next - } - $1 = "" - $2 = "" - stat = system($0) - if (stat != 0) { - e = (FILENAME ":" FNR) - e = (e ": warning: system returned " stat) - print e > "/dev/stderr" - } -} -/^@c(omment)?[ \t]+file/ \ -{ - if (NF != 3) { - e = (FILENAME ":" FNR ": badly formed `file' line") - print e > "/dev/stderr" - next - } - if ($3 != curfile) { - if (curfile != "") - close(curfile) - curfile = $3 - } - - for (;;) { - if ((getline line) <= 0) - unexpected_eof() - if (line ~ /^@c(omment)?[ \t]+endfile/) - break - else if (line ~ /^@(end[ \t]+)?group/) - continue - else if (line ~ /^@c(omment+)?[ \t]+/) - continue - if (index(line, "@") == 0) { - print line > curfile - continue - } - n = split(line, a, "@") - # if a[1] == "", means leading @, - # don't add one back in. - for (i = 2; i <= n; i++) { - if (a[i] == "") { # was an @@ - a[i] = "@" - if (a[i+1] == "") - i++ - } - } - print join(a, 1, n, SUBSEP) > curfile - } -} -function unexpected_eof() { - printf("%s:%d: unexpected EOF or error\n", - FILENAME, FNR) > "/dev/stderr" - exit 1 -} - -END { - if (curfile) - close(curfile) -} diff --git a/contrib/awk/awklib/eg/prog/guide.awk b/contrib/awk/awklib/eg/prog/guide.awk deleted file mode 100644 index a2dea1b7f64a..000000000000 --- a/contrib/awk/awklib/eg/prog/guide.awk +++ /dev/null @@ -1,7 +0,0 @@ -BEGIN { - TEXTDOMAIN = "guide" - bindtextdomain(".") # for testing - print _"Don't Panic" - print _"The Answer Is", 42 - print "Pardon me, Zaphod who?" -} diff --git a/contrib/awk/awklib/eg/prog/histsort.awk b/contrib/awk/awklib/eg/prog/histsort.awk deleted file mode 100644 index c0a9165a12e3..000000000000 --- a/contrib/awk/awklib/eg/prog/histsort.awk +++ /dev/null @@ -1,15 +0,0 @@ -# histsort.awk --- compact a shell history file -# Thanks to Byron Rakitzis for the general idea -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# May 1993 - -{ - if (data[$0]++ == 0) - lines[++count] = $0 -} - -END { - for (i = 1; i <= count; i++) - print lines[i] -} diff --git a/contrib/awk/awklib/eg/prog/id.awk b/contrib/awk/awklib/eg/prog/id.awk deleted file mode 100644 index af78f7600a96..000000000000 --- a/contrib/awk/awklib/eg/prog/id.awk +++ /dev/null @@ -1,67 +0,0 @@ -# id.awk --- implement id in awk -# -# Requires user and group library functions -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# May 1993 -# Revised February 1996 - -# output is: -# uid=12(foo) euid=34(bar) gid=3(baz) \ -# egid=5(blat) groups=9(nine),2(two),1(one) - -BEGIN \ -{ - uid = PROCINFO["uid"] - euid = PROCINFO["euid"] - gid = PROCINFO["gid"] - egid = PROCINFO["egid"] - - printf("uid=%d", uid) - pw = getpwuid(uid) - if (pw != "") { - split(pw, a, ":") - printf("(%s)", a[1]) - } - - if (euid != uid) { - printf(" euid=%d", euid) - pw = getpwuid(euid) - if (pw != "") { - split(pw, a, ":") - printf("(%s)", a[1]) - } - } - - printf(" gid=%d", gid) - pw = getgrgid(gid) - if (pw != "") { - split(pw, a, ":") - printf("(%s)", a[1]) - } - - if (egid != gid) { - printf(" egid=%d", egid) - pw = getgrgid(egid) - if (pw != "") { - split(pw, a, ":") - printf("(%s)", a[1]) - } - } - - for (i = 1; ("group" i) in PROCINFO; i++) { - if (i == 1) - printf(" groups=") - group = PROCINFO["group" i] - printf("%d", group) - pw = getgrgid(group) - if (pw != "") { - split(pw, a, ":") - printf("(%s)", a[1]) - } - if (("group" (i+1)) in PROCINFO) - printf(",") - } - - print "" -} diff --git a/contrib/awk/awklib/eg/prog/igawk.sh b/contrib/awk/awklib/eg/prog/igawk.sh deleted file mode 100644 index 7144ce50464f..000000000000 --- a/contrib/awk/awklib/eg/prog/igawk.sh +++ /dev/null @@ -1,130 +0,0 @@ -#! /bin/sh -# igawk --- like gawk but do @include processing -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# July 1993 - -if [ "$1" = debug ] -then - set -x - shift -else - # cleanup on exit, hangup, interrupt, quit, termination - trap 'rm -f /tmp/ig.[se].$$' 0 1 2 3 15 -fi - -while [ $# -ne 0 ] # loop over arguments -do - case $1 in - --) shift; break;; - - -W) shift - set -- -W"$@" - continue;; - - -[vF]) opts="$opts $1 '$2'" - shift;; - - -[vF]*) opts="$opts '$1'" ;; - - -f) echo @include "$2" >> /tmp/ig.s.$$ - shift;; - - -f*) f=`echo "$1" | sed 's/-f//'` - echo @include "$f" >> /tmp/ig.s.$$ ;; - - -?file=*) # -Wfile or --file - f=`echo "$1" | sed 's/-.file=//'` - echo @include "$f" >> /tmp/ig.s.$$ ;; - - -?file) # get arg, $2 - echo @include "$2" >> /tmp/ig.s.$$ - shift;; - - -?source=*) # -Wsource or --source - t=`echo "$1" | sed 's/-.source=//'` - echo "$t" >> /tmp/ig.s.$$ ;; - - -?source) # get arg, $2 - echo "$2" >> /tmp/ig.s.$$ - shift;; - - -?version) - echo igawk: version 1.0 1>&2 - gawk --version - exit 0 ;; - - -[W-]*) opts="$opts '$1'" ;; - - *) break;; - esac - shift -done - -if [ ! -s /tmp/ig.s.$$ ] -then - if [ -z "$1" ] - then - echo igawk: no program! 1>&2 - exit 1 - else - echo "$1" > /tmp/ig.s.$$ - shift - fi -fi - -# at this point, /tmp/ig.s.$$ has the program -gawk -- ' -# process @include directives - -function pathto(file, i, t, junk) -{ - if (index(file, "/") != 0) - return file - - for (i = 1; i <= ndirs; i++) { - t = (pathlist[i] "/" file) - if ((getline junk < t) > 0) { - # found it - close(t) - return t - } - } - return "" -} -BEGIN { - path = ENVIRON["AWKPATH"] - ndirs = split(path, pathlist, ":") - for (i = 1; i <= ndirs; i++) { - if (pathlist[i] == "") - pathlist[i] = "." - } - stackptr = 0 - input[stackptr] = ARGV[1] # ARGV[1] is first file - - for (; stackptr >= 0; stackptr--) { - while ((getline < input[stackptr]) > 0) { - if (tolower($1) != "@include") { - print - continue - } - fpath = pathto($2) - if (fpath == "") { - printf("igawk:%s:%d: cannot find %s\n", - input[stackptr], FNR, $2) > "/dev/stderr" - continue - } - if (! (fpath in processed)) { - processed[fpath] = input[stackptr] - input[++stackptr] = fpath # push onto stack - } else - print $2, "included in", input[stackptr], - "already included in", - processed[fpath] > "/dev/stderr" - } - close(input[stackptr]) - } -}' /tmp/ig.s.$$ > /tmp/ig.e.$$ -eval gawk -f /tmp/ig.e.$$ $opts -- "$@" - -exit $? diff --git a/contrib/awk/awklib/eg/prog/labels.awk b/contrib/awk/awklib/eg/prog/labels.awk deleted file mode 100644 index fa9c4dab5388..000000000000 --- a/contrib/awk/awklib/eg/prog/labels.awk +++ /dev/null @@ -1,54 +0,0 @@ -# labels.awk --- print mailing labels -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# June 1992 - -# Each label is 5 lines of data that may have blank lines. -# The label sheets have 2 blank lines at the top and 2 at -# the bottom. - -BEGIN { RS = "" ; MAXLINES = 100 } - -function printpage( i, j) -{ - if (Nlines <= 0) - return - - printf "\n\n" # header - - for (i = 1; i <= Nlines; i += 10) { - if (i == 21 || i == 61) - print "" - for (j = 0; j < 5; j++) { - if (i + j > MAXLINES) - break - printf " %-41s %s\n", line[i+j], line[i+j+5] - } - print "" - } - - printf "\n\n" # footer - - for (i in line) - line[i] = "" -} - -# main rule -{ - if (Count >= 20) { - printpage() - Count = 0 - Nlines = 0 - } - n = split($0, a, "\n") - for (i = 1; i <= n; i++) - line[++Nlines] = a[i] - for (; i <= 5; i++) - line[++Nlines] = "" - Count++ -} - -END \ -{ - printpage() -} diff --git a/contrib/awk/awklib/eg/prog/split.awk b/contrib/awk/awklib/eg/prog/split.awk deleted file mode 100644 index 2906a8531512..000000000000 --- a/contrib/awk/awklib/eg/prog/split.awk +++ /dev/null @@ -1,57 +0,0 @@ -# split.awk --- do split in awk -# -# Requires ord and chr library functions -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# May 1993 - -# usage: split [-num] [file] [outname] - -BEGIN { - outfile = "x" # default - count = 1000 - if (ARGC > 4) - usage() - - i = 1 - if (ARGV[i] ~ /^-[0-9]+$/) { - count = -ARGV[i] - ARGV[i] = "" - i++ - } - # test argv in case reading from stdin instead of file - if (i in ARGV) - i++ # skip data file name - if (i in ARGV) { - outfile = ARGV[i] - ARGV[i] = "" - } - - s1 = s2 = "a" - out = (outfile s1 s2) -} -{ - if (++tcount > count) { - close(out) - if (s2 == "z") { - if (s1 == "z") { - printf("split: %s is too large to split\n", - FILENAME) > "/dev/stderr" - exit 1 - } - s1 = chr(ord(s1) + 1) - s2 = "a" - } - else - s2 = chr(ord(s2) + 1) - out = (outfile s1 s2) - tcount = 1 - } - print > out -} -function usage( e) -{ - e = "usage: split [-num] [file] [outname]" - print e > "/dev/stderr" - exit 1 -} diff --git a/contrib/awk/awklib/eg/prog/tee.awk b/contrib/awk/awklib/eg/prog/tee.awk deleted file mode 100644 index eafc4b9ae7b7..000000000000 --- a/contrib/awk/awklib/eg/prog/tee.awk +++ /dev/null @@ -1,39 +0,0 @@ -# tee.awk --- tee in awk -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# May 1993 -# Revised December 1995 - -BEGIN \ -{ - for (i = 1; i < ARGC; i++) - copy[i] = ARGV[i] - - if (ARGV[1] == "-a") { - append = 1 - delete ARGV[1] - delete copy[1] - ARGC-- - } - if (ARGC < 2) { - print "usage: tee [-a] file ..." > "/dev/stderr" - exit 1 - } - ARGV[1] = "-" - ARGC = 2 -} -{ - # moving the if outside the loop makes it run faster - if (append) - for (i in copy) - print >> copy[i] - else - for (i in copy) - print > copy[i] - print -} -END \ -{ - for (i in copy) - close(copy[i]) -} diff --git a/contrib/awk/awklib/eg/prog/testbits.awk b/contrib/awk/awklib/eg/prog/testbits.awk deleted file mode 100644 index 143cd9167c74..000000000000 --- a/contrib/awk/awklib/eg/prog/testbits.awk +++ /dev/null @@ -1,27 +0,0 @@ -# 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 -} -BEGIN { - printf "123 = %s\n", bits2str(123) - printf "0123 = %s\n", bits2str(0123) - printf "0x99 = %s\n", bits2str(0x99) - comp = compl(0x99) - printf "compl(0x99) = %#x = %s\n", comp, bits2str(comp) - shift = lshift(0x99, 2) - printf "lshift(0x99, 2) = %#x = %s\n", shift, bits2str(shift) - shift = rshift(0x99, 2) - printf "rshift(0x99, 2) = %#x = %s\n", shift, bits2str(shift) -} diff --git a/contrib/awk/awklib/eg/prog/translate.awk b/contrib/awk/awklib/eg/prog/translate.awk deleted file mode 100644 index 803700c44d4d..000000000000 --- a/contrib/awk/awklib/eg/prog/translate.awk +++ /dev/null @@ -1,47 +0,0 @@ -# translate.awk --- do tr-like stuff -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# August 1989 - -# Bugs: does not handle things like: tr A-Z a-z, it has -# to be spelled out. However, if `to' is shorter than `from', -# the last character in `to' is used for the rest of `from'. - -function stranslate(from, to, target, lf, lt, t_ar, i, c) -{ - lf = length(from) - lt = length(to) - for (i = 1; i <= lt; i++) - t_ar[substr(from, i, 1)] = substr(to, i, 1) - if (lt < lf) - for (; i <= lf; i++) - t_ar[substr(from, i, 1)] = substr(to, lt, 1) - for (i = 1; i <= lf; i++) { - c = substr(from, i, 1) - if (index(target, c) > 0) - gsub(c, t_ar[c], target) - } - return target -} - -function translate(from, to) -{ - return $0 = stranslate(from, to, $0) -} - -# main program -BEGIN { - if (ARGC < 3) { - print "usage: translate from to" > "/dev/stderr" - exit - } - FROM = ARGV[1] - TO = ARGV[2] - ARGC = 2 - ARGV[1] = "-" -} - -{ - translate(FROM, TO) - print -} diff --git a/contrib/awk/awklib/eg/prog/uniq.awk b/contrib/awk/awklib/eg/prog/uniq.awk deleted file mode 100644 index cfb50c79789b..000000000000 --- a/contrib/awk/awklib/eg/prog/uniq.awk +++ /dev/null @@ -1,119 +0,0 @@ -# uniq.awk --- do uniq in awk -# -# Requires getopt and join library functions -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# May 1993 - -function usage( e) -{ - e = "Usage: uniq [-udc [-n]] [+n] [ in [ out ]]" - print e > "/dev/stderr" - exit 1 -} - -# -c count lines. overrides -d and -u -# -d only repeated lines -# -u only non-repeated lines -# -n skip n fields -# +n skip n characters, skip fields first - -BEGIN \ -{ - count = 1 - outputfile = "/dev/stdout" - opts = "udc0:1:2:3:4:5:6:7:8:9:" - while ((c = getopt(ARGC, ARGV, opts)) != -1) { - if (c == "u") - non_repeated_only++ - else if (c == "d") - repeated_only++ - else if (c == "c") - do_count++ - else if (index("0123456789", c) != 0) { - # getopt requires args to options - # this messes us up for things like -5 - if (Optarg ~ /^[0-9]+$/) - fcount = (c Optarg) + 0 - else { - fcount = c + 0 - Optind-- - } - } else - usage() - } - - if (ARGV[Optind] ~ /^\+[0-9]+$/) { - charcount = substr(ARGV[Optind], 2) + 0 - Optind++ - } - - for (i = 1; i < Optind; i++) - ARGV[i] = "" - - if (repeated_only == 0 && non_repeated_only == 0) - repeated_only = non_repeated_only = 1 - - if (ARGC - Optind == 2) { - outputfile = ARGV[ARGC - 1] - ARGV[ARGC - 1] = "" - } -} -function are_equal( n, m, clast, cline, alast, aline) -{ - if (fcount == 0 && charcount == 0) - return (last == $0) - - if (fcount > 0) { - n = split(last, alast) - m = split($0, aline) - clast = join(alast, fcount+1, n) - cline = join(aline, fcount+1, m) - } else { - clast = last - cline = $0 - } - if (charcount) { - clast = substr(clast, charcount + 1) - cline = substr(cline, charcount + 1) - } - - return (clast == cline) -} -NR == 1 { - last = $0 - next -} - -{ - equal = are_equal() - - if (do_count) { # overrides -d and -u - if (equal) - count++ - else { - printf("%4d %s\n", count, last) > outputfile - last = $0 - count = 1 # reset - } - next - } - - if (equal) - count++ - else { - if ((repeated_only && count > 1) || - (non_repeated_only && count == 1)) - print last > outputfile - last = $0 - count = 1 - } -} - -END { - if (do_count) - printf("%4d %s\n", count, last) > outputfile - else if ((repeated_only && count > 1) || - (non_repeated_only && count == 1)) - print last > outputfile -} diff --git a/contrib/awk/awklib/eg/prog/wc.awk b/contrib/awk/awklib/eg/prog/wc.awk deleted file mode 100644 index f46616b906a0..000000000000 --- a/contrib/awk/awklib/eg/prog/wc.awk +++ /dev/null @@ -1,69 +0,0 @@ -# wc.awk --- count lines, words, characters -# -# Arnold Robbins, arnold@gnu.org, Public Domain -# May 1993 - -# Options: -# -l only count lines -# -w only count words -# -c only count characters -# -# Default is to count lines, words, characters -# -# Requires getopt and file transition library functions - -BEGIN { - # let getopt print a message about - # invalid options. we ignore them - while ((c = getopt(ARGC, ARGV, "lwc")) != -1) { - if (c == "l") - do_lines = 1 - else if (c == "w") - do_words = 1 - else if (c == "c") - do_chars = 1 - } - for (i = 1; i < Optind; i++) - ARGV[i] = "" - - # if no options, do all - if (! do_lines && ! do_words && ! do_chars) - do_lines = do_words = do_chars = 1 - - print_total = (ARGC - i > 2) -} -function beginfile(file) -{ - chars = lines = words = 0 - fname = FILENAME -} -function endfile(file) -{ - tchars += chars - tlines += lines - twords += words - if (do_lines) - printf "\t%d", lines - if (do_words) - printf "\t%d", words - if (do_chars) - printf "\t%d", chars - printf "\t%s\n", fname -} -# do per line -{ - chars += length($0) + 1 # get newline - lines++ - words += NF -} -END { - if (print_total) { - if (do_lines) - printf "\t%d", tlines - if (do_words) - printf "\t%d", twords - if (do_chars) - printf "\t%d", tchars - print "\ttotal" - } -} diff --git a/contrib/awk/awklib/eg/prog/wordfreq.awk b/contrib/awk/awklib/eg/prog/wordfreq.awk deleted file mode 100644 index 62db5cfa1c00..000000000000 --- a/contrib/awk/awklib/eg/prog/wordfreq.awk +++ /dev/null @@ -1,20 +0,0 @@ -# wordfreq.awk --- print list of word frequencies - -{ - $0 = tolower($0) # remove case distinctions - # remove punctuation - gsub(/[^[:alnum:]_[:blank:]]/, "", $0) - for (i = 1; i <= NF; i++) - freq[$i]++ -} - -END { - for (word in freq) - printf "%s\t%d\n", word, freq[word] -} -END { - sort = "sort +1 -nr" - for (word in freq) - printf "%s\t%d\n", word, freq[word] | sort - close(sort) -} |