Файловый менеджер - Редактировать - /home/lakoyani/lakoyani.com.fj/awk.tar
Назад
cliff_rand.awk 0000644 00000000463 14711163717 0007352 0 ustar 00 # cliff_rand.awk --- generate Cliff random numbers # # Arnold Robbins, arnold@skeeve.com, Public Domain # December 2000 BEGIN { _cliff_seed = 0.1 } function cliff_rand() { _cliff_seed = (100 * log(_cliff_seed)) % 1 if (_cliff_seed < 0) _cliff_seed = - _cliff_seed return _cliff_seed } zerofile.awk 0000644 00000000650 14711163717 0007100 0 ustar 00 # zerofile.awk --- library file to process empty input files # # Arnold Robbins, arnold@skeeve.com, Public Domain # June 2003 BEGIN { Argind = 0 } ARGIND > Argind + 1 { for (Argind++; Argind < ARGIND; Argind++) zerofile(ARGV[Argind], Argind) } ARGIND != Argind { Argind = ARGIND } END { if (ARGIND > Argind) for (Argind++; Argind <= ARGIND; Argind++) zerofile(ARGV[Argind], Argind) } libintl.awk 0000644 00000000356 14711163717 0006721 0 ustar 00 function bindtextdomain(dir, domain) { return dir } function dcgettext(string, domain, category) { return string } function dcngettext(string1, string2, number, domain, category) { return (number == 1 ? string1 : string2) } bits2str.awk 0000644 00000000507 14711163717 0007036 0 ustar 00 # 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 } ctime.awk 0000644 00000000351 14711163717 0006360 0 ustar 00 # ctime.awk # # awk version of C ctime(3) function function ctime(ts, format) { format = "%a %b %e %H:%M:%S %Z %Y" if (ts == 0) ts = systime() # use current time as default return strftime(format, ts) } passwd.awk 0000644 00000002257 14711163717 0006567 0 ustar 00 # passwd.awk --- access password file information # # Arnold Robbins, arnold@skeeve.com, Public Domain # May 1993 # Revised October 2000 # Revised December 2010 BEGIN { # tailor this to suit your system _pw_awklib = "/usr/libexec/awk/" } function _pw_init( oldfs, oldrs, olddol0, pwcat, using_fw, using_fpat) { if (_pw_inited) return oldfs = FS oldrs = RS olddol0 = $0 using_fw = (PROCINFO["FS"] == "FIELDWIDTHS") using_fpat = (PROCINFO["FS"] == "FPAT") 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 else if (using_fpat) FPAT = FPAT RS = oldrs $0 = olddol0 } function getpwnam(name) { _pw_init() return _pw_byname[name] } function getpwuid(uid) { _pw_init() return _pw_byuid[uid] } function getpwent() { _pw_init() if (_pw_count < _pw_total) return _pw_bycount[++_pw_count] return "" } function endpwent() { _pw_count = 0 } noassign.awk 0000644 00000000651 14711163717 0007103 0 ustar 00 # noassign.awk --- library file to avoid the need for a # special option that disables command-line assignments # # Arnold Robbins, arnold@skeeve.com, Public Domain # October 1999 function disable_assigns(argc, argv, i) { for (i = 1; i < argc; i++) if (argv[i] ~ /^[[:alpha:]_][[:alnum:]_]*=.*/) argv[i] = ("./" argv[i]) } BEGIN { if (No_command_assign) disable_assigns(ARGC, ARGV) } assert.awk 0000644 00000000576 14711163717 0006571 0 ustar 00 # assert --- assert that a condition is true. Otherwise exit. # # Arnold Robbins, arnold@skeeve.com, Public Domain # May, 1993 function assert(condition, string) { if (! condition) { printf("%s:%d: assertion failed: %s\n", FILENAME, FNR, string) > "/dev/stderr" _assert_exit = 1 exit 1 } } END { if (_assert_exit) exit 1 } rewind.awk 0000644 00000000624 14711163717 0006552 0 ustar 00 # rewind.awk --- rewind the current file and start over # # Arnold Robbins, arnold@skeeve.com, Public Domain # September 2000 function rewind( i) { # shift remaining arguments up for (i = ARGC; i > ARGIND; i--) ARGV[i] = ARGV[i-1] # make sure gawk knows to keep going ARGC++ # make current file next to get done ARGV[ARGIND+1] = FILENAME # do it nextfile } ord.awk 0000644 00000001651 14711163717 0006047 0 ustar 00 # ord.awk --- do ord and chr # Global identifiers: # _ord_: numerical values indexed by characters # _ord_init: function to initialize _ord_ # # Arnold Robbins, arnold@skeeve.com, Public Domain # 16 January, 1992 # 20 July, 1992, revised BEGIN { _ord_init() } function _ord_init( low, high, i, t) { low = sprintf("%c", 7) # BEL is ascii 7 if (low == "\a") { # regular ascii low = 0 high = 127 } else if (sprintf("%c", 128 + 7) == "\a") { # ascii, mark parity low = 128 high = 255 } else { # ebcdic(!) low = 0 high = 255 } for (i = low; i <= high; i++) { t = sprintf("%c", i) _ord_[t] = i } } function ord(str, c) { # only first character is of interest c = substr(str, 1, 1) return _ord_[c] } function chr(c) { # force c to be numeric by adding 0 return sprintf("%c", c + 0) } strtonum.awk 0000644 00000002666 14711163717 0007165 0 ustar 00 # mystrtonum --- convert string to number # # Arnold Robbins, arnold@skeeve.com, Public Domain # February, 2004 function mystrtonum(str, ret, chars, n, i, k, c) { if (str ~ /^0[0-7]*$/) { # octal n = length(str) ret = 0 for (i = 1; i <= n; i++) { c = substr(str, i, 1) if ((k = index("01234567", c)) > 0) k-- # adjust for 1-basing in awk ret = ret * 8 + k } } else if (str ~ /^0[xX][[:xdigit:]]+/) { # hexadecimal str = substr(str, 3) # lop off leading 0x n = length(str) ret = 0 for (i = 1; i <= n; i++) { c = substr(str, i, 1) c = tolower(c) if ((k = index("0123456789", c)) > 0) k-- # adjust for 1-basing in awk else if ((k = index("abcdef", c)) > 0) k += 9 ret = ret * 16 + k } } else if (str ~ \ /^[-+]?([0-9]+([.][0-9]*([Ee][0-9]+)?)?|([.][0-9]+([Ee][-+]?[0-9]+)?))$/) { # decimal number, possibly floating point ret = str + 0 } else ret = "NOT-A-NUMBER" return ret } # BEGIN { # gawk test harness # a[1] = "25" # a[2] = ".31" # a[3] = "0123" # a[4] = "0xdeadBEEF" # a[5] = "123.45" # a[6] = "1.e3" # a[7] = "1.32" # a[7] = "1.32E2" # # for (i = 1; i in a; i++) # print a[i], strtonum(a[i]), mystrtonum(a[i]) # } walkarray.awk 0000644 00000000326 14711163717 0007256 0 ustar 00 function walk_array(arr, name, i) { for (i in arr) { if (isarray(arr[i])) walk_array(arr[i], (name "[" i "]")) else printf("%s[%s] = %s\n", name, i, arr[i]) } } join.awk 0000644 00000000572 14711163717 0006223 0 ustar 00 # join.awk --- join an array into a string # # Arnold Robbins, arnold@skeeve.com, Public Domain # May 1993 function join(array, start, end, sep, result, i) { if (sep == "") sep = " " else if (sep == SUBSEP) # magic value sep = "" result = array[start] for (i = start + 1; i <= end; i++) result = result sep array[i] return result } group.awk 0000644 00000003400 14711163717 0006411 0 ustar 00 # group.awk --- functions for dealing with the group file # # Arnold Robbins, arnold@skeeve.com, Public Domain # May 1993 # Revised October 2000 # Revised December 2010 BEGIN \ { # Change to suit your system _gr_awklib = "/usr/libexec/awk/" } function _gr_init( oldfs, oldrs, olddol0, grcat, using_fw, using_fpat, n, a, i) { if (_gr_inited) return oldfs = FS oldrs = RS olddol0 = $0 using_fw = (PROCINFO["FS"] == "FIELDWIDTHS") using_fpat = (PROCINFO["FS"] == "FPAT") 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 else if (using_fpat) FPAT = FPAT RS = oldrs $0 = olddol0 } function getgrnam(group) { _gr_init() return _gr_byname[group] } function getgrgid(gid) { _gr_init() return _gr_bygid[gid] } function getgruser(user) { _gr_init() return _gr_groupsbyuser[user] } function getgrent() { _gr_init() if (++_gr_count in _gr_bycount) return _gr_bycount[_gr_count] return "" } function endgrent() { _gr_count = 0 } quicksort.awk 0000644 00000001777 14711163717 0007320 0 ustar 00 # quicksort.awk --- Quicksort algorithm, with user-supplied # comparison function # # Arnold Robbins, arnoldskeeve.com, Public Domain # January 2009 # quicksort --- C.A.R. Hoare's quick sort algorithm. See Wikipedia # or almost any algorithms or computer science text # # Adapted from K&R-II, page 110 function quicksort(data, left, right, less_than, i, last) { if (left >= right) # do nothing if array contains fewer return # than two elements quicksort_swap(data, left, int((left + right) / 2)) last = left for (i = left + 1; i <= right; i++) if (@less_than(data[i], data[left])) quicksort_swap(data, ++last, i) quicksort_swap(data, left, last) quicksort(data, left, last - 1, less_than) quicksort(data, last + 1, right, less_than) } # quicksort_swap --- helper function for quicksort, should really be inline function quicksort_swap(data, i, j, temp) { temp = data[i] data[i] = data[j] data[j] = temp } ftrans.awk 0000644 00000000475 14711163717 0006563 0 ustar 00 # ftrans.awk --- handle data file transitions # # user supplies beginfile() and endfile() functions # # Arnold Robbins, arnold@skeeve.com, Public Domain # November 1992 FNR == 1 { if (_filename_ != "") endfile(_filename_) _filename_ = FILENAME beginfile(FILENAME) } END { endfile(_filename_) } round.awk 0000644 00000001225 14711163717 0006407 0 ustar 00 # round.awk --- do normal rounding # # Arnold Robbins, arnold@skeeve.com, Public Domain # August, 1996 function round(x, ival, aval, fraction) { ival = int(x) # integer part, int() truncates # see if fractional part if (ival == x) # no fraction return ival # ensure no decimals 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 } } getopt.awk 0000644 00000004275 14711163717 0006572 0 ustar 00 # getopt.awk --- Do C library getopt(3) function in awk # # Arnold Robbins, arnold@skeeve.com, Public Domain # # Initial version: March, 1991 # Revised: May, 1993 # External variables: # Optind -- index in ARGV of first nonoption argument # Optarg -- string value of argument to current option # Opterr -- if nonzero, print our own diagnostic # Optopt -- current option letter # Returns: # -1 at end of options # "?" for unrecognized option # <c> a character representing the current option # Private Data: # _opti -- index in multi-flag option, e.g., -abc function getopt(argc, argv, options, thisopt, i) { if (length(options) == 0) # no options given return -1 if (argv[Optind] == "--") { # all done Optind++ _opti = 0 return -1 } else if (argv[Optind] !~ /^-[^:[:space:]]/) { _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]) } } gettime.awk 0000644 00000004673 14711163717 0006730 0 ustar 00 # gettimeofday.awk --- get the time of day in a usable format # # Arnold Robbins, arnold@skeeve.com, Public Domain, May 1993 # # Returns a string in the format of output of date(1) # Populates the array argument time with individual values: # time["second"] -- seconds (0 - 59) # time["minute"] -- minutes (0 - 59) # time["hour"] -- hours (0 - 23) # time["althour"] -- hours (0 - 12) # time["monthday"] -- day of month (1 - 31) # time["month"] -- month of year (1 - 12) # time["monthname"] -- name of the month # time["shortmonth"] -- short name of the month # time["year"] -- year modulo 100 (0 - 99) # time["fullyear"] -- full year # time["weekday"] -- day of week (Sunday = 0) # time["altweekday"] -- day of week (Monday = 0) # time["dayname"] -- name of weekday # time["shortdayname"] -- short name of weekday # time["yearday"] -- day of year (0 - 365) # time["timezone"] -- abbreviation of timezone name # time["ampm"] -- AM or PM designation # time["weeknum"] -- week number, Sunday first day # time["altweeknum"] -- week number, Monday first day function gettimeofday(time, ret, now, i) { # get time once, avoids unnecessary system calls now = systime() # return date(1)-style output ret = strftime("%a %b %e %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 } readable.awk 0000644 00000000754 14711163717 0007025 0 ustar 00 # readable.awk --- library file to skip over unreadable files # # Arnold Robbins, arnold@skeeve.com, Public Domain # October 2000 # December 2010 BEGIN { for (i = 1; i < ARGC; i++) { if (ARGV[i] ~ /^[[:alpha:]_][[:alnum:]_]*=.*/ \ || ARGV[i] == "-" || ARGV[i] == "/dev/stdin") continue # assignment or standard input else if ((getline junk < ARGV[i]) < 0) # unreadable delete ARGV[i] else close(ARGV[i]) } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Генерация страницы: 0.01 |
proxy
|
phpinfo
|
Настройка