World: r4wp
[#Red] Red language group
older newer | first last |
Kaj 2-Jul-2013 [9190x3] | Here on Intel Linux I get: |
to-process/2013-06-29-20-18-55.h264 35 to-process/2013-06-29-20-18-55.h264/img00.bin 45 | |
Without the reversal, you were overwriting file1 with random memory from file3 | |
Bo 2-Jul-2013 [9193x2] | Yes, I can see that now. |
Works fine on Windows again, but on Linux-ARM I'm still getting messed up: 36process/2013-06-29-20-19-37.h264 /img00.bin 4613-06-29-20-19-37.h264 | |
Kaj 2-Jul-2013 [9195x2] | Everything points to null endings lacking |
Is that on Arch Linux? | |
Bo 2-Jul-2013 [9197] | No, I'm using Raspbian Wheezy right now. |
Kaj 2-Jul-2013 [9198] | Odd, that's probably just the GNU C library |
Bo 2-Jul-2013 [9199] | Based on Debian, so probably. |
Kaj 2-Jul-2013 [9200] | Try adding an explicit null marker after each append |
Bo 2-Jul-2013 [9201] | OK. Currently 42C (108F) outside my house. My small window air conditioner can't keep up. My fingers are slipping on the keys. |
Kaj 2-Jul-2013 [9202] | Wow, my hard disk runs that hot |
Bo 2-Jul-2013 [9203] | It was 44C today but it is starting to cool off. |
Kaj 2-Jul-2013 [9204] | My official C book doesn't mention null ending for strcat, but it does for all the other string functions, so it would be a very malevolent C library that doesn't implement it |
Bo 2-Jul-2013 [9205] | Is this a good way to add that null marker? tmp: make-c-string 1 append-string file1 first-line tmp: file1 + length? file1 tmp/1: #"^(00)" |
Kaj 2-Jul-2013 [9206] | No, you have to ask for the length before the append, because LENGTH? depends on the marker |
Bo 2-Jul-2013 [9207x2] | OK. |
Here's my code now...still not working: tmp: make-c-string 1 file1: make-c-string 128 copy-string "to-process/" file1 ;reversed print-line [length? file1 " " length? first-line] file1len: (length? file1) + (length? first-line) append-string file1 first-line tmp: file1 + file1len tmp/1: #"^(00)" print-line [file1 " " length? file1] append-string file1 "/img00.bin" print-line [file1 " " length? file1] Here's the output 11 25 36process/2013-06-29-20-20-09.h264 /img00.bin 4613-06-29-20-20-09.h264 | |
Kaj 2-Jul-2013 [9209x2] | length? is correct |
Aha, that means there's an extra character at the end of your first-line | |
Bo 2-Jul-2013 [9211] | Yes. |
Kaj 2-Jul-2013 [9212x3] | Judging by the printing, that must be a CR |
So you probably copied a Windows text file to Linux | |
So the problem is in the only piece of the code you didn't show :-) | |
Bo 2-Jul-2013 [9215x2] | I could have pasted the whole program in here, but I thought that might have been excessive! :-) |
Sorry for the false alarm and all the trouble. | |
Kaj 2-Jul-2013 [9217] | Is first-line a literal or does it come from a text file? |
Bo 2-Jul-2013 [9218] | Here's the troubling bit of code: dirs: make-c-string 1024 dirs: read-file "to-process/dirs.txt" eol: make-c-string 1024 eol: find-char dirs #"^/" ;Finds the first end-of-line character line-len: as-integer eol - dirs + 1 ;Add one byte for the end-of-string character first-line: make-c-string line-len copy-string-part dirs first-line as-integer eol - dirs ;reversed first-line/line-len: #"^(00)" Shouldn't 'find-char dirs #"^/" return the first newline byte? |
Kaj 2-Jul-2013 [9219x4] | Yes, you're looking for the LF, so you're including the CR |
On Windows, the C library that executes the read-file converts DOS newlines to Unix LF format. I've had trouble with that before in the binding | |
The C library on Unix just assumes it's a native file, so if there are extra CRs in there, it doesn't touch them | |
It's best to standardise on LF format, even on Windows, with a capable editor | |
Bo 2-Jul-2013 [9223] | The dirs.txt file is being written to the Pi using Rebol on Windows. |
Kaj 2-Jul-2013 [9224x2] | Yes, it uses local Windows convention |
You must do the conversion somewhere in the chain | |
Bo 2-Jul-2013 [9226] | So, I'd have to form the file in Rebol, convert it to binary (in Rebol) and remove the CRs from the binary, then use write/binary to write it out. |
Kaj 2-Jul-2013 [9227x2] | Doesn't REBOL have a refinement to force it? |
The other option is to convert it in Red/System | |
Bo 2-Jul-2013 [9229] | write/with |
Kaj 2-Jul-2013 [9230] | R2 only |
Bo 2-Jul-2013 [9231x2] | I'll just use write/append/binary with #{0A} as the terminator. |
It's working now. Thanks for all your detective work! I don't know how you can find bugs so fast. | |
Kaj 2-Jul-2013 [9233] | I didn't think it was very fast. :-) I had a hunch in the direction of corrupted printing all the time, but didn't think of CR |
Bo 2-Jul-2013 [9234] | What I meant was "fast compared to me." |
Kaj 2-Jul-2013 [9235x3] | :-) |
It still sucks to loose hours to this issue fourty years after it was perpetrated | |
I suppose it would be useful if I made read-file more like REBOL, like it already behaves on Windows. I'll look into that tomorrow | |
Bo 2-Jul-2013 [9238] | You're awesome! |
Kaj 2-Jul-2013 [9239] | Thanks |
older newer | first last |