diff options
author | Indrajith K L | 2022-12-03 17:00:20 +0530 |
---|---|---|
committer | Indrajith K L | 2022-12-03 17:00:20 +0530 |
commit | f5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch) | |
tree | 2764fc62da58f2ba8da7ed341643fc359873142f /coreutils-5.3.0-bin/share/awk/ord.awk | |
download | cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2 cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip |
Diffstat (limited to 'coreutils-5.3.0-bin/share/awk/ord.awk')
-rw-r--r-- | coreutils-5.3.0-bin/share/awk/ord.awk | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/coreutils-5.3.0-bin/share/awk/ord.awk b/coreutils-5.3.0-bin/share/awk/ord.awk new file mode 100644 index 0000000..be47e15 --- /dev/null +++ b/coreutils-5.3.0-bin/share/awk/ord.awk @@ -0,0 +1,44 @@ +# ord.awk --- do ord and chr + +# Global identifiers: +# _ord_: numerical values indexed by characters +# _ord_init: function to initialize _ord_ +# +# Arnold Robbins, arnold@skeeve.com, Public Domain +# 16 January, 1992 +# 20 July, 1992, revised + +BEGIN { _ord_init() } + +function _ord_init( low, high, i, t) +{ + low = sprintf("%c", 7) # BEL is ascii 7 + if (low == "\a") { # regular ascii + low = 0 + high = 127 + } else if (sprintf("%c", 128 + 7) == "\a") { + # ascii, mark parity + low = 128 + high = 255 + } else { # ebcdic(!) + low = 0 + high = 255 + } + + for (i = low; i <= high; i++) { + t = sprintf("%c", i) + _ord_[t] = i + } +} +function ord(str, c) +{ + # only first character is of interest + c = substr(str, 1, 1) + return _ord_[c] +} + +function chr(c) +{ + # force c to be numeric by adding 0 + return sprintf("%c", c + 0) +} |