Amiga.org

Amiga computer related discussion => Amiga/MorphOS/AROS Programmers Forum => Topic started by: LoadWB on August 10, 2015, 07:43:40 PM

Title: ARexx emitting 00x with WRITECH()??
Post by: LoadWB on August 10, 2015, 07:43:40 PM
I am trying to manipulate binary files with ARexx.  I am using WRITECH() to emit the contents of a variable to a file, but WRITECH() apparently skips zero bytes ('00'x).

This program is expected to output five bytes, but only outputs THREE.  My guess is WRITECH() outputs a null-terminated string, so the '0099'x string will  never be output because the '00'x terminates the string, and '99'x is after the termination.

Code: [Select]
call open 'outfile', 'test.bin'

call writech 'outfile', '0099'x
call writech 'outfile', 'ff'x
call writech 'outfile', '12'x
call writech 'outfile', '34'x

call close 'outfile'


So, how in ARexx can I output a zero byte?
Title: Re: ARexx emitting 00x with WRITECH()??
Post by: Thomas on August 10, 2015, 09:45:26 PM
Works for me.

Code: [Select]

4> type test.bin opt h
0000: 0099FF12 34                            ....4                
4>


Your open is missing the write parameter. You should call it as a function and check the result. Open can fail.
Title: Re: ARexx emitting 00x with WRITECH()??
Post by: LoadWB on August 10, 2015, 09:48:40 PM
Quote from: Thomas;793777
Works for me.

Code: [Select]

4> type test.bin opt h
0000: 0099FF12 34                            ....4                
4>


Your open is missing the write parameter. You should call it as a function and check the result. Open can fail.


Ugh, you're right, thank you.  It was missing in my test program, but it's not missing in the real program.  That said, even with 'w' in the call in my test it's not working.

Maybe it's a problem with Regina's ARexx compatiblity.  (And maybe I should have said I'm using Regina.)

Good to know it works in real ARexx, though.
Title: Re: ARexx emitting 00x with WRITECH()??
Post by: LoadWB on August 11, 2015, 02:32:21 AM
Thomas, thanks for checking that for me.  I got back to my 4000D and my program works fine there.  This must be a problem with Regina.
Title: Re: ARexx emitting 00x with WRITECH()??
Post by: Thomas on August 11, 2015, 06:48:08 AM
What does Regina say about this:

Code: [Select]

a = '0099'x
say length(a)


and if length is 2, does this make any difference:

Code: [Select]

a = '0099'x
call writech 'outfile', a
Title: Re: ARexx emitting 00x with WRITECH()??
Post by: LoadWB on September 16, 2015, 05:05:40 AM
It does report a with a length of 2, but your second tidbit results in a 0-byte file.

I have been having all kinds of weird problems with Regina and file handling.  I am opening a different thread for one of them.  It appears that the accepted way of handling files is with STREAM.  There's a Rexx file library I found at OS4depot which I will likely use as a file handling framework as it compensates for the differences between ARexx and other Rexxes.