Converts a binary buffer using a translation table.
BinaryXlate( data-buffer, table-buffer, mode )
(i) data-buffer: a handle to a binary buffer containing data to be converted.
(i) table-buffer: a handle to a binary buffer containing a translation table.
(i) mode: see below.
(i) eod new: EOD of the buffer.
"mode" can be one of the following:
Mode |
Source buffer |
Target buffer |
Table size |
0 |
byte |
byte |
256 |
1 |
byte |
word |
512 |
2 |
word |
byte |
65536 |
3 |
word |
word |
131072 |
This function looks up a byte or word in "data-buffer", uses that number to compute an index into "table-buffer", looks up the byte or word there, and places the result in a temporary buffer. It does this for each byte or word in "data-buffer". When it's finished processing "data-buffer", it copies the new (temporary) buffer back to "data-buffer", and sets the binary EOD appropriately.
For mode 1, "data-buffer" must be large enough to hold at least twice as much data as is currently in the buffer.
;EBCDIC to ASCII translation table ;Codes 0 1 2 3 4 5 6 7 8 9 A B C D E F row0 ="000 001 002 003 032 009 032 127 032 032 032 011 012 013 014 015" ; 0x0- row1 ="016 017 018 019 032 032 008 032 024 025 032 032 032 032 032 032" ; 0x1- row2 ="032 032 028 032 032 010 023 027 032 032 032 032 032 005 006 007" ; 0x2- row3 ="032 032 022 032 032 030 032 004 032 032 032 032 020 021 032 032" ; 0x3- row4 ="032 032 032 032 032 032 032 032 032 032 155 046 060 040 043 032" ; 0x4- row5 ="038 032 032 032 032 032 032 032 032 032 033 036 042 041 059 191" ; 0x5- row6 ="045 047 032 032 032 032 032 032 032 032 124 044 037 095 062 063" ; 0x6- row7 ="032 032 032 032 032 032 032 032 032 032 058 035 064 039 061 034" ; 0x7- row8 ="032 097 098 099 100 101 102 103 104 105 032 032 032 032 032 032" ; 0x8- row9 ="032 106 107 108 109 110 111 112 113 114 032 032 032 032 032 032" ; 0x9- row10="032 126 115 116 117 118 119 120 121 122 032 032 032 032 032 032" ; 0xA- row11="032 032 032 032 032 032 032 032 032 032 032 032 032 032 032 032" ; 0xB- row12="123 065 066 067 068 069 070 071 072 073 032 032 032 032 032 032" ; 0xC- row13="125 074 075 076 077 078 079 080 081 082 032 032 032 032 032 032" ; 0xD- row14="092 032 083 084 085 086 087 088 089 090 032 032 032 032 032 032" ; 0xE- row15="048 049 050 051 052 053 054 055 056 057 032 032 032 032 032 032" ; 0xF- ;Allocte 256 bytes for a 1:1 translation table bbxlate=BinaryAlloc(256) ;load translation table from ROW variables above. ; Could have loaded ir from a file also For rowdigit=0 To 15 For coldigit= 0 To 15 BinaryPoke(bbxlate,(rowdigit*16)+coldigit,ItemExtract(coldigit+1,row%rowdigit%," ")) Next Next ;Ask user for a file name of an EBCDIC file fn=AskFilename("EBCDIC -> ASCII", "", "EBCDIC files|*.ebc|All Files|*.*","*.*",1) ;Generate corresponding *.asc name fnout=FileMapName(fn,StrCat(FilePath(fn),"*.asc")) ;Get size of source file fs=FileSize(fn) ;Allocate a binary buffer that size bb=BinaryAlloc(fs) ;Read source file into binary buffer BinaryRead(bb,fn) ;Perform the magic Xlate function BinaryXlate(bb,bbxlate,0) ;Write result file do the output file BinaryWrite(bb,fnout) ;Free binary buffers BinaryFree(bb) BinaryFree(bbxlate) ;claim victory Message("All","Done")
Binary Operations, BinaryAlloc, BinaryCopy, BinaryFree, BinaryRead