B
Bill Guindon
for starters, I have my cheesy little debugger, forgive the globals, I
was too lazy to make it a class (yes, really, that lazy! yes, I know,
I just typed more than it would've taken).
It works wonderfully tho', output below...
# just a debugging toy atm.
$hex_idx = 0
def show_hex(val)
val.each_byte do |byte|
print "%02x ".upcase % byte
$hex_idx += 1
print " " if $hex_idx == 8
if $hex_idx == 16
print "\n"
$hex_idx = 0
end
end
end
Here's what it shows (which is exactly what I need):
44 45 53 43 00 00 00 00 00 00 00 4D 00 00 00 00
0D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^^
But this is what ends up in the file:
44 45 53 43 00 00 00 00 00 00 00 4D 00 00 00 00
0D 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^^
after beating my brains out on this, I think I see the problem, but
not the solution.
The value that I'm packing is a FixNum
I'm using pack("c") which converts it to the '0D' that I need.
Printing with an @file_name.print statement to a file that's opened
with .binmode
I'm doing this on Win32
'0D' is 13 (aka CR)
Either Windows (most likely) or Ruby (less likely, but possible) is
generously converting my perfect little '0D' to an incredibly annoying
'0D 0A' (aka CR LF)
any suggestions? Should I convert this somehow, and use a different
pack spec to avoid this problem?
was too lazy to make it a class (yes, really, that lazy! yes, I know,
I just typed more than it would've taken).
It works wonderfully tho', output below...
# just a debugging toy atm.
$hex_idx = 0
def show_hex(val)
val.each_byte do |byte|
print "%02x ".upcase % byte
$hex_idx += 1
print " " if $hex_idx == 8
if $hex_idx == 16
print "\n"
$hex_idx = 0
end
end
end
Here's what it shows (which is exactly what I need):
44 45 53 43 00 00 00 00 00 00 00 4D 00 00 00 00
0D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^^
But this is what ends up in the file:
44 45 53 43 00 00 00 00 00 00 00 4D 00 00 00 00
0D 0A 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^^
after beating my brains out on this, I think I see the problem, but
not the solution.
The value that I'm packing is a FixNum
I'm using pack("c") which converts it to the '0D' that I need.
Printing with an @file_name.print statement to a file that's opened
with .binmode
I'm doing this on Win32
'0D' is 13 (aka CR)
Either Windows (most likely) or Ruby (less likely, but possible) is
generously converting my perfect little '0D' to an incredibly annoying
'0D 0A' (aka CR LF)
any suggestions? Should I convert this somehow, and use a different
pack spec to avoid this problem?