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

World: r4wp

[#Red] Red language group

DocKimbel
18-Apr-2013
[7108x2]
It would be best to do the conversions on the fly, that is why I 
want to wait for I/O get done to implement such conversion routines. 


Anyway, for doing it now, you need to allocate a new string, the 
best way to do it is:

    str: as red-string! stack/push*
    str/header: TYPE_STRING
    str/head: 0
    str/node:  alloc-bytes size


The new string! value will be put on stack, so any other call to 
a Red internal native or action might destroy it. Also, keep in mind 
that the GC is not there yet, so intensive I/O might quickly eat 
up all your RAM.
Oh, you meant a c-string!, not a string!, so it's even easier, just 
use: alloc-bytes size
PeterWood
18-Apr-2013
[7110x2]
Thanks.
Is there any easy way to free the c-string?
DocKimbel
18-Apr-2013
[7112x4]
Currently no, the freeing function requires a memory frame pointer 
in addition to the buffer pointer. It is meant for internal use only 
for now.
Anyway, even freeing it won't help much as long as the GC doesn't 
do the cleanup.
Here's how your main loop would look like for retrieving every codepoint 
from a string! value:

	head: string/rs-head str
	tail: string/rs-tail str
		
	s: GET_BUFFER(str)
	unit: GET_UNIT(s)
		
	while [head < tail][
		cp: switch unit [
			Latin1 [as-integer p/value]
			UCS-2  [(as-integer p/2) << 8 + p/1]
			UCS-4  [p4: as int-ptr! p p4/value]
		]
		...emit UTF-8 char...
		head: head + unit
	]
Oops, you should replace 'head by 'p in the above code.
PeterWood
18-Apr-2013
[7116]
Many thanks.
DocKimbel
18-Apr-2013
[7117]
cp hold your codepoint as a 32-bit integer.
PeterWood
18-Apr-2013
[7118]
I should be able to turn this into a function for Kaj to include 
in his routine! where he needs UTF-8
DocKimbel
18-Apr-2013
[7119]
I guess that should be enough for his needs.
PeterWood
18-Apr-2013
[7120]
Fingers crossed :-)
Oldes
18-Apr-2013
[7121]
why not to use native OS functions? At least on WIn there is: http://msdn.microsoft.com/en-us/library/windows/desktop/dd374085(v=vs.85).aspx
DocKimbel
18-Apr-2013
[7122]
Kaj is working on Linux and Syllable only. Also that API provides 
UTF-16 to UTF-8 support, but we need also UCS-4 to UTF-8 (UCS-2 being 
a subset of UTF-16).
Oldes
18-Apr-2013
[7123]
Some UCS related code for porting is here: http://public.googlecode.com/svn/trunk/UCSUTF.cpp
DocKimbel
18-Apr-2013
[7124]
Endo: I have submitted a report for false positive to AVIRA, I hope 
Red binaries will be whitelisted soon. It seems to be the last AV 
vendor producing false alams, according to virustotal online testing 
tool.
Endo
18-Apr-2013
[7125]
Thank you, I'll check it later.
PeterWood
19-Apr-2013
[7126x5]
Kaj - You can find a rough and ready  red-string! to  c-string! function 
at:


https://github.com/PeterWAWood/Red-System-Libs/blob/master/UTF-8/string-c-string.reds


it #includes the UCS4 character to UTF8 convertor which you will 
need in the same directory as the string-c-string func.
The ucs4 -> utf8 char convertor:


https://github.com/PeterWAWood/Red-System-Libs/blob/master/UTF-8/ucs4-utf8.reds
I haven't really tested it as you can see from :


https://github.com/PeterWAWood/Red-System-Libs/blob/master/UTF-8/Tests/string-c-string-test.red
I'm not sure how it will cope with repeaated use as there is no way 
to release allocated c-strings under the Red memory manager.
Hope it helps.
Pekr
19-Apr-2013
[7131]
who needs a GC/memory manager these days, just buy more RAM :-)
DocKimbel
19-Apr-2013
[7132]
Peter, maybe you could user ALLOCATE function from Red/Sytem and 
let Kaj's code call FREE on UTF-8 buffers after usage?
PeterWood
19-Apr-2013
[7133]
I didn't think that it was possible to mix using the Red Memory Manager 
and C memory management in the same program. Is it safe to do so?
DocKimbel
19-Apr-2013
[7134]
Yes, it is.
PeterWood
19-Apr-2013
[7135]
I have committed the change for the c-string to be allocated with 
Red/System ALLOCATE function.
DocKimbel
20-Apr-2013
[7136]
FYI, Bruno is working on a Zlib binding for Red/System:
https://github.com/be-red/Red/commits/zlib
Kaj
20-Apr-2013
[7137]
Much obliged, Peter. I can work that into my I/O routines
PeterWood
21-Apr-2013
[7138x3]
Really the thanks should go to Nenad. Without his help, I still be 
trying to work out how to do it.
I've add support for code points above the BMP.
add -> added
DocKimbel
21-Apr-2013
[7141]
That is just called team work. :-)
Arnold
21-Apr-2013
[7142]
Would be nice to be able to download the Red zip file and be able 
to compile scripts in another directory?
Kaj
21-Apr-2013
[7143]
How do you mean? What you seem to ask is already possible
Arnold
21-Apr-2013
[7144]
I was in the impression that Red and Red/System scripts should be 
in a directory within the Red dir. Where the other (test)scriots 
are too.

I am now hesitant to put a new zip over the old one and lose my scripts 
(but maybe even that fear is vain).
Kaj
23-Apr-2013
[7145x2]
Nenad did a lot of work on making it location independent. A few 
issues remain, for example that Red/System always gets compiled into 
the builds/ subdirectory, but the source can be anywhere
If you just unzip, thereīs no reason your scripts would be lost, 
but you can make it a lot easier by not putting them in the Red folders
Andreas
23-Apr-2013
[7147x2]
Not sure what mode of compiling Red/System you are thinking about, 
but if you compile via rsc.r, you can tell it where to write the 
binary by passing a `-o` command-line option.
As in:
rebol2 -qsc rsc.r -o hello tests/hello.reds
Kaj
23-Apr-2013
[7149x3]
Iīm referring to the normal case of wanting to get the output in 
your working directory. Red does that now, but Red/System not without 
using that switch
You also need to give the full path to the source file
Actually, you also have to give the full path in the -o switch
Arnold
23-Apr-2013
[7152]
I did some compiling today and found the resulting executable in 
the build directory.
Andreas
23-Apr-2013
[7153]
Relative paths work for me.
MaxV
23-Apr-2013
[7154x2]
Ishttps://github.com/dockimbel/Redthe official Github site?
Is https://github.com/dockimbel/Redthe official github site?
Pekr
23-Apr-2013
[7156]
yes, it is ...
Kaj
23-Apr-2013
[7157]
./ paths donīt work for me on rsc.r