summaryrefslogtreecommitdiff
path: root/awklib/eg/lib
diff options
context:
space:
mode:
Diffstat (limited to 'awklib/eg/lib')
-rw-r--r--awklib/eg/lib/assert.awk2
-rw-r--r--awklib/eg/lib/bits2str.awk16
-rw-r--r--awklib/eg/lib/cliff_rand.awk14
-rw-r--r--awklib/eg/lib/ftrans.awk4
-rw-r--r--awklib/eg/lib/getopt.awk20
-rw-r--r--awklib/eg/lib/gettime.awk15
-rw-r--r--awklib/eg/lib/grcat.c6
-rw-r--r--awklib/eg/lib/groupawk.in9
-rw-r--r--awklib/eg/lib/join.awk1
-rw-r--r--awklib/eg/lib/libintl.awk9
-rw-r--r--awklib/eg/lib/mktime.awk105
-rw-r--r--awklib/eg/lib/nextfile.awk1
-rw-r--r--awklib/eg/lib/noassign.awk17
-rw-r--r--awklib/eg/lib/ord.awk18
-rw-r--r--awklib/eg/lib/passwdawk.in9
-rw-r--r--awklib/eg/lib/pwcat.c7
-rw-r--r--awklib/eg/lib/readable.awk16
-rw-r--r--awklib/eg/lib/rewind.awk20
-rw-r--r--awklib/eg/lib/round.awk4
19 files changed, 143 insertions, 150 deletions
diff --git a/awklib/eg/lib/assert.awk b/awklib/eg/lib/assert.awk
index 50f42e7d..bbfc0669 100644
--- a/awklib/eg/lib/assert.awk
+++ b/awklib/eg/lib/assert.awk
@@ -1,4 +1,6 @@
# assert --- assert that a condition is true. Otherwise exit.
+
+#
# Arnold Robbins, arnold@gnu.org, Public Domain
# May, 1993
diff --git a/awklib/eg/lib/bits2str.awk b/awklib/eg/lib/bits2str.awk
new file mode 100644
index 00000000..9725ee8f
--- /dev/null
+++ b/awklib/eg/lib/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/awklib/eg/lib/cliff_rand.awk b/awklib/eg/lib/cliff_rand.awk
new file mode 100644
index 00000000..345447ec
--- /dev/null
+++ b/awklib/eg/lib/cliff_rand.awk
@@ -0,0 +1,14 @@
+# 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/awklib/eg/lib/ftrans.awk b/awklib/eg/lib/ftrans.awk
index cec615be..b0743e28 100644
--- a/awklib/eg/lib/ftrans.awk
+++ b/awklib/eg/lib/ftrans.awk
@@ -2,8 +2,8 @@
#
# user supplies beginfile() and endfile() functions
#
-# Arnold Robbins, arnold@gnu.org, November 1992
-# Public Domain
+# Arnold Robbins, arnold@gnu.org, Public Domain
+# November 1992
FNR == 1 {
if (_filename_ != "")
diff --git a/awklib/eg/lib/getopt.awk b/awklib/eg/lib/getopt.awk
index dae20e5f..93753052 100644
--- a/awklib/eg/lib/getopt.awk
+++ b/awklib/eg/lib/getopt.awk
@@ -1,28 +1,26 @@
-# getopt --- do C library getopt(3) function in awk
+# getopt.awk --- do C library getopt(3) function in awk
#
-# arnold@gnu.org
-# Public domain
+# Arnold Robbins, arnold@gnu.org, Public Domain
#
# Initial version: March, 1991
# Revised: May, 1993
# External variables:
-# Optind -- index of ARGV for first non-option argument
+# Optind -- index in ARGV of first non-option argument
# Optarg -- string value of argument to current option
-# Opterr -- if non-zero, print our own diagnostic
+# Opterr -- if nonzero, print our own diagnostic
# Optopt -- current option letter
-# Returns
+# 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, optl, thisopt, i)
+# Private Data:
+# _opti -- index in multi-flag option, e.g., -abc
+function getopt(argc, argv, options, thisopt, i)
{
- optl = length(options)
- if (optl == 0) # no options given
+ if (length(options) == 0) # no options given
return -1
if (argv[Optind] == "--") { # all done
diff --git a/awklib/eg/lib/gettime.awk b/awklib/eg/lib/gettime.awk
index 82f09d72..c425123c 100644
--- a/awklib/eg/lib/gettime.awk
+++ b/awklib/eg/lib/gettime.awk
@@ -1,6 +1,8 @@
-# gettimeofday --- get the time of day in a usable format
+# 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)
@@ -11,17 +13,17 @@
# time["month"] -- month of year (1 - 12)
# time["monthname"] -- name of the month
# time["shortmonth"] -- short name of the month
-# time["year"] -- year within century (0 - 99)
-# time["fullyear"] -- year with century (19xx or 20xx)
+# 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["weeknum"] -- week number, Sunday first day
-# time["altweeknum"] -- week number, Monday first day
# 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)
{
@@ -32,8 +34,7 @@ function gettimeofday(time, ret, now, i)
ret = strftime("%a %b %d %H:%M:%S %Z %Y", now)
# clear out target array
- for (i in time)
- delete time[i]
+ delete time
# fill in values, force numeric values to be
# numeric by adding 0
diff --git a/awklib/eg/lib/grcat.c b/awklib/eg/lib/grcat.c
index 570b3230..d34ddd56 100644
--- a/awklib/eg/lib/grcat.c
+++ b/awklib/eg/lib/grcat.c
@@ -2,9 +2,9 @@
* grcat.c
*
* Generate a printable version of the group database
- *
- * Arnold Robbins, arnold@gnu.org
- * May 1993
+ */
+/*
+ * Arnold Robbins, arnold@gnu.org, May 1993
* Public Domain
*/
diff --git a/awklib/eg/lib/groupawk.in b/awklib/eg/lib/groupawk.in
index 11a72a5a..9d8b4021 100644
--- a/awklib/eg/lib/groupawk.in
+++ b/awklib/eg/lib/groupawk.in
@@ -1,13 +1,17 @@
# 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, n, a, i)
+
+function _gr_init( oldfs, oldrs, olddol0, grcat,
+ using_fw, n, a, i)
{
if (_gr_inited)
return
@@ -15,6 +19,7 @@ function _gr_init( oldfs, oldrs, olddol0, grcat, n, a, i)
oldfs = FS
oldrs = RS
olddol0 = $0
+ using_fw = (PROCINFO["FS"] == "FIELDWIDTHS")
FS = ":"
RS = "\n"
@@ -43,6 +48,8 @@ function _gr_init( oldfs, oldrs, olddol0, grcat, n, a, i)
_gr_count = 0
_gr_inited++
FS = oldfs
+ if (using_fw)
+ FIELDWIDTHS = FIELDWIDTHS
RS = oldrs
$0 = olddol0
}
diff --git a/awklib/eg/lib/join.awk b/awklib/eg/lib/join.awk
index f52f5e62..e17b4270 100644
--- a/awklib/eg/lib/join.awk
+++ b/awklib/eg/lib/join.awk
@@ -1,4 +1,5 @@
# join.awk --- join an array into a string
+#
# Arnold Robbins, arnold@gnu.org, Public Domain
# May 1993
diff --git a/awklib/eg/lib/libintl.awk b/awklib/eg/lib/libintl.awk
new file mode 100644
index 00000000..a9402c2a
--- /dev/null
+++ b/awklib/eg/lib/libintl.awk
@@ -0,0 +1,9 @@
+function bindtextdomain(dir, domain)
+{
+ return dir
+}
+
+function dcgettext(string, domain, category)
+{
+ return string
+}
diff --git a/awklib/eg/lib/mktime.awk b/awklib/eg/lib/mktime.awk
deleted file mode 100644
index 57ff20e5..00000000
--- a/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/awklib/eg/lib/nextfile.awk b/awklib/eg/lib/nextfile.awk
index 4bb07bc3..caedf0e4 100644
--- a/awklib/eg/lib/nextfile.awk
+++ b/awklib/eg/lib/nextfile.awk
@@ -1,5 +1,6 @@
# nextfile --- skip remaining records in current file
# correctly handle successive occurrences of the same file
+#
# Arnold Robbins, arnold@gnu.org, Public Domain
# May, 1993
diff --git a/awklib/eg/lib/noassign.awk b/awklib/eg/lib/noassign.awk
new file mode 100644
index 00000000..d6d176e4
--- /dev/null
+++ b/awklib/eg/lib/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@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/awklib/eg/lib/ord.awk b/awklib/eg/lib/ord.awk
index b19149eb..3eacbcc5 100644
--- a/awklib/eg/lib/ord.awk
+++ b/awklib/eg/lib/ord.awk
@@ -1,16 +1,15 @@
# 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
+# 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
@@ -37,18 +36,9 @@ function ord(str, c)
c = substr(str, 1, 1)
return _ord_[c]
}
+
function chr(c)
{
# force c to be numeric by adding 0
return sprintf("%c", c + 0)
}
-#### test code ####
-# BEGIN \
-# {
-# for (;;) {
-# printf("enter a character: ")
-# if (getline var <= 0)
-# break
-# printf("ord(%s) = %d\n", var, ord(var))
-# }
-# }
diff --git a/awklib/eg/lib/passwdawk.in b/awklib/eg/lib/passwdawk.in
index dd6ee7f5..5f6f9e26 100644
--- a/awklib/eg/lib/passwdawk.in
+++ b/awklib/eg/lib/passwdawk.in
@@ -1,21 +1,26 @@
# 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)
+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
@@ -26,6 +31,8 @@ function _pw_init( oldfs, oldrs, olddol0, pwcat)
_pw_count = 0
_pw_inited = 1
FS = oldfs
+ if (using_fw)
+ FIELDWIDTHS = FIELDWIDTHS
RS = oldrs
$0 = olddol0
}
diff --git a/awklib/eg/lib/pwcat.c b/awklib/eg/lib/pwcat.c
index 591b8523..b9a71340 100644
--- a/awklib/eg/lib/pwcat.c
+++ b/awklib/eg/lib/pwcat.c
@@ -2,10 +2,9 @@
* pwcat.c
*
* Generate a printable version of the password database
- *
- * Arnold Robbins
- * arnold@gnu.org
- * May 1993
+ */
+/*
+ * Arnold Robbins, arnold@gnu.org, May 1993
* Public Domain
*/
diff --git a/awklib/eg/lib/readable.awk b/awklib/eg/lib/readable.awk
new file mode 100644
index 00000000..51705aea
--- /dev/null
+++ b/awklib/eg/lib/readable.awk
@@ -0,0 +1,16 @@
+# 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/awklib/eg/lib/rewind.awk b/awklib/eg/lib/rewind.awk
new file mode 100644
index 00000000..33286611
--- /dev/null
+++ b/awklib/eg/lib/rewind.awk
@@ -0,0 +1,20 @@
+# 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/awklib/eg/lib/round.awk b/awklib/eg/lib/round.awk
index 67ce6469..bf16c2b6 100644
--- a/awklib/eg/lib/round.awk
+++ b/awklib/eg/lib/round.awk
@@ -1,7 +1,7 @@
# round --- do normal rounding
#
-# Arnold Robbins, arnold@gnu.org, August, 1996
-# Public Domain
+# Arnold Robbins, arnold@gnu.org, Public Domain
+# August, 1996
function round(x, ival, aval, fraction)
{