• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[#Red] Red language group

Bo
2-Jul-2013
[9168]
That's too much like Rebol.
Kaj
2-Jul-2013
[9169x2]
We could distort it :-)
The append is done by the C library, so if it doesn't append a null 
byte, that would explain it
Bo
2-Jul-2013
[9171x3]
OK.  That's just weird.  With the following code snippet:

	print-line [file1 " " length? file1]
	append-string file1 "/img00.bin"
	print-line [file1 " " length? file1]

We get these results on Linux-ARM:

	 36process/2013-06-29-20-18-55.h264
	/img00.bin 4613-06-29-20-18-55.h264
It looks like the problem is happening before the 'append-string.
Here is a more complete snippet ending with what I posted above:

	file1: make-c-string 128
	copy-string file1 "to-process/"
	append-string file1 first-line

	file3: make-c-string 128
	copy-string file3 file1

	print-line [file1 " " length? file1]
	append-string file1 "/img00.bin"
	print-line [file1 " " length? file1]

The above works perfectly on Windows.
Kaj
2-Jul-2013
[9174]
Did you update the binding yet? I've reversed the argument order 
of COPY
Bo
2-Jul-2013
[9175x2]
No
With the updated ANSI.reds, I get the following error when compiling 
now:


*** Compilation Error: argument type mismatch on calling: copy-string
*** expected: [integer!], found: [c-string!]
*** in file: %motion-detect.reds
*** at line: 47
*** near: [
    append-string file1 first-line
    file3: as c-string! allocate 128
]
Kaj
2-Jul-2013
[9177x2]
Sorry, messed that up
Fixed it
Bo
2-Jul-2013
[9179x3]
Now I get this beautiful output:

¢÷¶¢÷¶ÿÿÿÿð£÷¶ð£÷¶ 20
¢÷¶¢÷¶ÿÿÿÿð£÷¶ð£÷¶/img00.bin 30

¢÷¶¢÷¶/img00out.bin

*** Runtime Error 1: access violation
*** at: B6EC5C0Ch
I must be doing something wrong...
At least the lengths are showing up in the right place...
Kaj
2-Jul-2013
[9182]
It seems that the 36 is one too high. Does it also print that on 
Windows?
Bo
2-Jul-2013
[9183x2]
Here's Windows:

¢÷¶¢÷¶ÿÿÿÿð£÷¶ð£÷¶ 20
¢÷¶¢÷¶ÿÿÿÿð£÷¶ð£÷¶/img00.bin 30

¢÷¶¢÷¶/img00out.bin

*** Runtime Error 1: access violation
*** at: B6EC5C0Ch
Sorry, here's Windows:

+?3+?3 6
+?3+?3/img00.bin 16
x?3
8?3/img00out.bin

*** Runtime Error 1: access violation
*** at: 77C47AB4h
Kaj
2-Jul-2013
[9185]
Did you reverse copy-string file3 file1 ?
Bo
2-Jul-2013
[9186x3]
No.  That would probably be important.
But with it reversed, it looks strange.  It's the opposite of the 
order of 'append-string, 'find-string and all those other operations 
now.
Do I also reverse 'copy-string-part?
Kaj
2-Jul-2013
[9189x4]
Yes, I think it's a more natural order. You copy or move from to
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?