codekingpro/portable-devtools
114k
1# ord.awk --- do ord and chr2#3# This file and how to use it are described in the manual.4# Therefore, we respectfully advise you to Read The Fine Manual5# for more information.6#7# Arnold Robbins, arnold@skeeve.com, Public Domain8# 16 January, 19929# 20 July, 1992, revised10 11# Global identifiers:12# _ord_: numerical values indexed by characters13# _ord_init: function to initialize _ord_14 15BEGIN { _ord_init() }16 17function _ord_init( low, high, i, t)18{19 low = sprintf("%c", 7) # BEL is ascii 720 if (low == "\a") { # regular ascii21 low = 022 high = 12723 } else if (sprintf("%c", 128 + 7) == "\a") {24 # ascii, mark parity25 low = 12826 high = 25527 } else { # ebcdic(!)28 low = 029 high = 25530 }31 32 for (i = low; i <= high; i++) {33 t = sprintf("%c", i)34 _ord_[t] = i35 }36}37function ord(str, c)38{39 # only first character is of interest40 c = substr(str, 1, 1)41 return _ord_[c]42}43 44function chr(c)45{46 # force c to be numeric by adding 047 return sprintf("%c", c + 0)48}49 