dbTalk Databases Forums  

%rdhex question

comp.databases.pick comp.databases.pick


Discuss %rdhex question in the comp.databases.pick forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
GVP
 
Posts: n/a

Default %rdhex question - 08-15-2006 , 06:47 AM






Hi

Why this program hangs at last read.

include dm,bp,unix.h fcntl.h
FD = %open("/u2/tmp/floppy",O$RDONLY)
if FD < 0 then
crt "Error ":system(0)
stop
end
loop
Buffer=SPACE(210)
Ret=%rdhex(FD,Buffer,100)
IF Ret<0 THEN EXit
crt ret, Buffer[1,Ret]
repeat
%close(FD)
end


Also can't understood documentation. In reality size is nHexChars ==
2*BytesInFile

n = %RDHEX( file.descriptor, variable, size )

Description:
reads the number of bytes designated by "size" into "variable" from the
file specified by "file.descriptor" returned by a previous call to
"%open()", "%creat()" or "dup()" converting each byte into two ASCII
hexadecimal characters.

A string of a size at least equal to 2 * "size" must have been assigned
to "variable" before the call by either an explicit assignment (e.g.
buffer=space(1000)) or by the "char" reserve statement, otherwise data
will be truncated.

The function returns the number of bytes actually read or "-1" if an
error occurred. If less than 2 * "size" bytes are returned, the content
of the string beyond is undefined, as is usual in C. This function is
the opposite of "%whex()".

!!!!! A string of a size at least equal to 2 * "size
!!!!! The function returns the number of bytes actually read

Many thanks.

Regards,
Grigory


Reply With Quote
  #2  
Old   
Peter McMurray
 
Posts: n/a

Default Re: %rdhex question - 08-15-2006 , 10:19 PM






Hi Grigory
The %rdhex function hang should be fixed in version 7.5 Release notes
Action Id 28757

The size issue I think is as follows (it is a long time since I programmed
in hex). We used to store two numbers in one hex byte using 4 bits for each
number. I believe the documentation is saying that if you read 50 bytes in
that will be converted to 100 ASCII hexadecimal characters. Therefore you
must set aside space of 100 bytes to receive every 50 bytes that you read.
Peter McMurray
"GVP" <gvp (AT) infotools (DOT) ru> wrote

Quote:
Hi

Why this program hangs at last read.

include dm,bp,unix.h fcntl.h
FD = %open("/u2/tmp/floppy",O$RDONLY)
if FD < 0 then
crt "Error ":system(0)
stop
end
loop
Buffer=SPACE(210)
Ret=%rdhex(FD,Buffer,100)
IF Ret<0 THEN EXit
crt ret, Buffer[1,Ret]
repeat
%close(FD)
end


Also can't understood documentation. In reality size is nHexChars ==
2*BytesInFile

n = %RDHEX( file.descriptor, variable, size )

Description:
reads the number of bytes designated by "size" into "variable" from the
file specified by "file.descriptor" returned by a previous call to
"%open()", "%creat()" or "dup()" converting each byte into two ASCII
hexadecimal characters.

A string of a size at least equal to 2 * "size" must have been assigned
to "variable" before the call by either an explicit assignment (e.g.
buffer=space(1000)) or by the "char" reserve statement, otherwise data
will be truncated.

The function returns the number of bytes actually read or "-1" if an
error occurred. If less than 2 * "size" bytes are returned, the content
of the string beyond is undefined, as is usual in C. This function is
the opposite of "%whex()".

!!!!! A string of a size at least equal to 2 * "size
!!!!! The function returns the number of bytes actually read

Many thanks.

Regards,
Grigory




Reply With Quote
  #3  
Old   
GVP
 
Posts: n/a

Default Re: %rdhex question - 08-15-2006 , 10:25 PM



Hello Peter,

Thanks for information.
Is it right:
1 Will fixed in version 7.5 for Linux
2 Documentation is wrong.

Regards,
Grigory


Reply With Quote
  #4  
Old   
Peter McMurray
 
Posts: n/a

Default Re: %rdhex question - 08-16-2006 , 02:44 AM



Hi Grigory
I only have information for 7.5 NT but I think that it would definitely
carry over to Linux as it should be the same routine (says he with fingers
crossed).
Also my explanation of packing could be clearer.
If we read one byte value char(254) in binary this is 1111 1110 and is an
attribute mark in Pick. This is shown in hex as FE that is binary 1111 F
and binary 1110 E. If we store this as hexadecimal FE it becomes two bytes
char(70) F and Char(69) E.
So we started with char(254) coming in and %rdhex has changed this to
char(70):char(69). Therefore the documentation is correct, whatever number
of bytes we read in say 1024 then we will need 2048 bytes to store the hex
result.
Peter McMurray
"GVP" <gvp (AT) infotools (DOT) ru> wrote

Quote:
Hello Peter,

Thanks for information.
Is it right:
1 Will fixed in version 7.5 for Linux
2 Documentation is wrong.

Regards,
Grigory




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.