Welcome, Guest. Please login or register.

Author Topic: ARexx emitting 00x with WRITECH()??  (Read 1457 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline LoadWBTopic starter

  • Hero Member
  • *****
  • Join Date: Jul 2006
  • Posts: 2901
  • Country: 00
    • Show only replies by LoadWB
ARexx emitting 00x with WRITECH()??
« 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?
 

Offline Thomas

Re: ARexx emitting 00x with WRITECH()??
« Reply #1 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.

Offline LoadWBTopic starter

  • Hero Member
  • *****
  • Join Date: Jul 2006
  • Posts: 2901
  • Country: 00
    • Show only replies by LoadWB
Re: ARexx emitting 00x with WRITECH()??
« Reply #2 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.
 

Offline LoadWBTopic starter

  • Hero Member
  • *****
  • Join Date: Jul 2006
  • Posts: 2901
  • Country: 00
    • Show only replies by LoadWB
Re: ARexx emitting 00x with WRITECH()??
« Reply #3 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.
 

Offline Thomas

Re: ARexx emitting 00x with WRITECH()??
« Reply #4 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

Offline LoadWBTopic starter

  • Hero Member
  • *****
  • Join Date: Jul 2006
  • Posts: 2901
  • Country: 00
    • Show only replies by LoadWB
Re: ARexx emitting 00x with WRITECH()??
« Reply #5 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.