/* Macro. Ebcd2asc. Author. carlo.hogeveen@xs4all.nl. Date-written. 30 March 2001. This macro converts an ebcdic file to ascii. 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 converted. Execute the macro with acro xecute "ebcd2asc" or with acro xecute "ebcd2asc reverse". */ #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 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_ascii_to_ebcdic() 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() endif endif until error <> FALSE or not NextChar() end proc convert_ebcdic_to_ascii() integer not_ready = TRUE integer no_trailing_whitespaces = TRUE integer LinesPerMessage = NumLines() / 100 + 1 integer ebcdic = 0 BegFile() while not_ready ebcdic = CurrChar() if CurrChar() == _AT_EOL_ if CurrCol() > 1 and Query(RemoveTrailingWhite) PrevChar() if CurrChar() == 32 Set(RemoveTrailingWhite, OFF) if no_trailing_whitespaces no_trailing_whitespaces = FALSE UpdateDisplay() Alarm() Message( "TSE settings were changed to keep the found trailing whitespaces") Delay(54) endif endif NextChar() endif if CurrLine() == NumLines() or CurrLine() mod LinesPerMessage == 0 Message(CurrLine() * 100 / NumLines(), "%") endif else if not (ebcdic in -1, 0, 10, 13) if ascii_tab [ebcdic] == Chr(0) UpdateDisplay() Warn("Ebcdic code ", ebcdic:2:"0":BASE, " (hex) has no known ascii code") AbandonFile() not_ready = FALSE else InsertText(ascii_tab[ebcdic], _OVERWRITE_) PrevChar() endif endif endif if not NextChar() not_ready = FALSE endif endwhile end proc Main() init_tables() fill_tables() if Lower(Query(MacroCmdLine)) == "reverse" convert_ascii_to_ebcdic() else convert_ebcdic_to_ascii() endif BegFile() PurgeMacro("ebcd2asc") // Also initializes global variables when rerun. end