/* Macro. Ebcdsort. Author. Carlo Hogeveen (hyphen@xs4all.nl). Date-written. 26 November 1998. This macro sorts an ascii file in ebcdic order. Installation: Put macro in TSE's "mac" directory, load it in the editor and compile it with acro ompile. Execution: Load the file to be sorted. Mark a block. Execute the macro with acro xecute "ebcdsort". Note 1: If the macro encounters an ascii character that has no known ebcdic code, then the macro will restore the already converted part, so it should never leave you with a partly converted file. Note 2: TSE/32 users make sure you have a version of the sort macro that is dated 17 August 1998 or later, since an importent bug was solved then. A new version is currently available at Sammy's page at Semware's FTP site. */ #define BASE 16 datadef ebcdic_to_ascii /* The first column should be at position 1, the other two columns should not, otherwise the positions of the columns are irrelevant. The first column is an optional comment for human reference, that may not contain more than one word, and if so should start with it. The second column is mandatory, containing all ebcdic codes once in BASE format. The third column is optional, containing known ascii counterpart codes in BASE format. If several ebcdic codes reference the same ascii code, then the highest ebcdic code is used for sorting. */ "nul 00 00" "soh 01 01" "stx 02 02" "etx 03 03" "pf 04 " "ht 05 09" "lc 06 " "del 07 7f" " 08 " " 09 " "smm 0a " "vt 0b 0b" "ff 0c 0c" "cr 0d 0d" "so 0e 0e" "si 0f 0f" "dle 10 10" "dc1 11 11" "dc2 12 12" "tm 13 " "res 14 " "nl 15 " "bs 16 08" "il 17 " "can 18 18" "em 19 19" "cc 1a " " 1b " "ifs 1c " "igs 1d " "irs 1e " "ius 1f " "ds 20 " "sos 21 " "fs 22 1c" " 23 " "byp 24 " "lf 25 0a" "etb 26 17" "esc 27 1b" " 28 " " 29 " "sm 2a " " 2b " " 2c " "enq 2d 05" "ack 2e 06" "bel 2f 07" " 30 " " 31 " "syn 32 " " 33 " "pn 34 " "rs 35 1e" "uc 36 " "eot 37 04" " 38 " " 39 " " 3a " " 3b " "dc4 3c 14" "nak 3d 15" " 3e " "sub 3f 1a" "sp 40 20" " 41 " " 42 " " 43 " " 44 " " 45 " " 46 " " 47 " " 48 " " 49 " "[ 4a 5d" ". 4b 2e" "< 4c 3c" "( 4d 28" "+ 4e 2b" "| 4f 7c" "& 50 26" " 51 " " 52 " " 53 " " 54 " " 55 " " 56 " " 57 " " 58 " " 59 " "] 5a 5d" "$ 5b 24" " 5c " ") 5d 29" "; 5e 3b" "ª 5f aa" "- 60 2d" "/ 61 2f" " 62 " " 63 " " 64 " " 65 " " 66 " " 67 " " 68 " " 69 " "^ 6a 5e" ", 6b 2c" "/ 6c 2f" "- 6d 2d" "> 6e 3e" "? 6f 3f" " 70 " " 71 " " 72 " " 73 " " 74 " " 75 " " 76 " " 77 " " 78 " " 79 " ": 7a 3a" "# 7b 23" "@ 7c 40" "' 7d 27" "= 7e 3d" "'' 7f 22" " 80 " "a 81 61" "b 82 62" "c 83 63" "d 84 64" "e 85 65" "f 86 66" "g 87 67" "h 88 68" "i 89 69" " 8a " " 8b " " 8c " " 8d " " 8e " " 8f " " 90 " "j 91 6a" "k 92 6b" "l 93 6c" "m 94 6d" "n 95 6e" "o 96 6f" "p 97 70" "q 98 71" "r 99 72" " 9a " " 9b " " 9c " " 9d " " 9e " " 9f " " a0 " " a1 " "s a2 73" "t a3 74" "u a4 75" "v a5 76" "w a6 77" "x a7 78" "y a8 79" "z a9 7a" " aa " " ab " " ac " " ad " " ae " " af " " b0 " " b1 " " b2 " " b3 " " b4 " " b5 " " b6 " " b7 " " b8 " " b9 " " ba " " bb " " bc " " bd " " be " " bf " " c0 " "a c1 41" "b c2 42" "c c3 43" "d c4 44" "e c5 45" "f c6 46" "g c7 47" "h c8 48" "i c9 49" " ca " " cb " " cc " " cd " " ce " " cf " " d0 " "j d1 4a" "k d2 4b" "l d3 4c" "m d4 4d" "n d5 4e" "o d6 4f" "p d7 50" "q d8 51" "r d9 52" " da " " db " " dc " " dd " " de " " df " " e0 " " e1 " "s e2 53" "t e3 54" "u e4 55" "v e5 56" "w e6 57" "x e7 58" "y e8 59" "z e9 5a" " ea " " eb " " ec " " ed " " ee " " ef " "0 f0 30" "1 f1 31" "2 f2 32" "3 f3 33" "4 f4 34" "5 f5 35" "6 f6 36" "7 f7 37" "8 f8 38" "9 f9 39" " fa " " fb " " fc " " fd " " fe " " ff " end // Global variables. string ascii_tab [255] = "" string ebcdic_tab [255] = "" integer error = false integer converted = 0 proc init_tables() integer index = 0 for index = 1 to 255 ascii_tab [index] = chr(0) ebcdic_tab [index] = chr(0) endfor end proc fill_tables() integer org_id = getbufferid() integer ascii = 0 integer ebcdic = 0 pushblock() createtempbuffer() insertdata(ebcdic_to_ascii) while replace(" ", " ", "gin") // For the endline() later on. endwhile begfile() while down() // Skip character 00, it's the same anyway. endline() if currcol() > 2 begline() wordright() ebcdic = val(getword(), BASE) if ebcdic <> 0 wordright() ascii = val(getword(), BASE) if ascii <> 0 ascii_tab[ebcdic] = chr(ascii) ebcdic_tab[ascii] = chr(ebcdic) endif endif endif endwhile abandonfile() gotobufferid(org_id) popblock() end proc convert_ebcdic_to_ascii() integer ascii = 0 begfile() repeat ascii = currchar() if ascii in -1, 0, 10, 13 // Do nothing. else if ebcdic_tab [ascii] == chr(0) error = ascii else inserttext(ebcdic_tab[ascii], _overwrite_) prevchar() converted = converted + 1 endif endif until error <> false or not nextchar() end proc convert_ascii_to_ebcdic() integer reconverted = 0 integer ebcdic = 0 begfile() while reconverted <> converted ebcdic = currchar() if ebcdic in -1, 0, 10, 13 // Do nothing. else if ascii_tab [ebcdic] == chr(0) warn("Program error in ebcdsort") abandoneditor() else inserttext(ascii_tab[ebcdic], _overwrite_) prevchar() reconverted = reconverted + 1 endif endif if not nextchar() reconverted = converted endif endwhile end proc main() init_tables() fill_tables() convert_ebcdic_to_ascii() if error == false execmacro("sort") endif convert_ascii_to_ebcdic() if error <> false warn("Ascii character ", str(error, 16), " (hex) has no ebcdic code: ", chr(error), " ") endif purgemacro("ebcdsort") // Also initializes global variables when rerun. end