r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Jerry
20-Oct-2006
[5807x2]
To Gregg,

The diff algorithm I am using ... 

2 blocks, one for reg-data-old (block1), the other for reg-data-new 
(block2).
data in these blocks are in the following format:
   [ key1 value1 key2 value2 key3 value3 ... ]
   where keyX and valueX are both strings. 
Example:

   [ "HKEY_LOCAL_MACHINE_SOFTWARE_ABC"  {"sid"=dword:00000001^/"tid"=dword:000000FF} 
   ... ]


I use "SORT/SKIP 2" to sort the 2 blocks. It's very fast, I guess 
that's because the original data are in order already. After sorting, 
I can comapre these two blocks with the "race" algorithm. 

The "race" algorithm is very simple ...

loop [
    if ... the key in block1 is equal to the key in block2 
    then ... check their values (different values mean modified) 

    if ... the key in block1 is less than the key in block2

    then ... the key in block1 is deleted-key. Move the key in block 
    1 to the next key.  

    if ... the key in block1 is greater than the key in block2

    then ... the key in block2 is added-key. Move the key in block 2 
    to the next key.  
] 


Well, my English is not very good. I hope you understand what I am 
saying here.
I would like to know ...


1. How to use the OPEN function with the /SEEK refinement to replace 
the 1,000,000th byte with the 2,000,000th byte in a file.


2. How to truncate a huge file to its helf size, and keep the head 
helf only. 

Thanks.
PeterWood
20-Oct-2006
[5809x3]
My answer to your first question (from reading http://www.rebol.net/article/0199.html
)


>> write %testdata "123456789A123456789B"    ;; A simple test file

>> fp: open/seek %testdata                                   ;; Open 
the file in seek mode

>> fp: skip fp 19                                                
      ;; Move to 20th character

>> newval: copy fp                                               
  ;; Copy the 20th character
== "B"

>> fp: head fp                                                   
       ;; Position at start of file

>> change at fp 10 newval                                      ;; 
Overwrite 10th character

>> copy head fp                                                  
     ;; Check change made
== "123456789B123456789B"
>> close fp
>> fp: open %testdata

>> copy fp                                                       
             ;; Check file was changed
== "123456789B123456789B"
Some of the statements can, of course be consolidated and there are, 
no doubt, better ways of doing this.
Second question:

>> fp: open/direct %testdata
>> write %testdata2 copy/part fp 10
>> read %testdata2
== "123456789B"
Graham
20-Oct-2006
[5812]
Peter, the second answer would not work well with large files.  I 
think Carl gives an example of how to copy large files and one should 
use that method.
PeterWood
20-Oct-2006
[5813x2]
Thanks Graham
Was it this example? http://www.rebol.net/article/0281.html
Graham
20-Oct-2006
[5815x2]
Yes.
T'was
Jerry
21-Oct-2006
[5817]
Thanks. The #0281 Article in the "Vivi la REBOLution" Blog is very 
helpful. Maybe I should read these articals all over again. BTW, 
I really hope that the web page in http://www.rebol.com/docs/changes.html
would be updated to reflect the changes after 2.5.6.
Gregg
21-Oct-2006
[5818]
OK, so it's not just the volume of raw registry data we're dealing 
with, but loading it into blocks as well. Do you have any idea how 
many keys there are that you're dealing with (i.e. how many block 
entries)?  (Your English is very good BTW :-)
Jerry
21-Oct-2006
[5819x2]
Gregg. There are 166,659 keys in my registry system.
And loading the registry into a REBOL block is not a problem so far. 
I simply READ the registry-dump file as a string, then PARSE the 
long string into block:

parse-reg: func [ file /local str blk ] [
    str: read file
    blk: copy []
    parse str [ 
        to "[HKEY_" 
        some [
            copy txt thru "]" (append blk txt)
            skip

            copy txt [ to "[HKEY_" | to end ] (append blk trim txt)
        ]
    ]
    str: none
    blk
]
Graham
22-Oct-2006
[5821x3]
anyone got a function that converts rebol colours to html colour 
codes ?
sint-to-hex: func [ smallint [integer!]][
    copy/part skip tail form to-hex smallint -2 2
]

rgb-to-hex: func [ c [tuple!]
    /local
][

    rejoin [ "#" sint-to-hex c/1 sint-to-hex c/2 sint-to-hex c/3 ]
]
something like that I guess
Ashley
22-Oct-2006
[5824]
Quick question. Assuming I have a script with the following in it:

	...
	either system/script/args [
	...

and the following in another script:

	do/args %my-script.r 42


what do I need to get it working remote. Tried the following without 
success:

	do/args http://www.my-site.com/my-script.r42
	do-thru/args http://www.my-site.com/my-script.r42

Any ideas?
Gabriele
22-Oct-2006
[5825x2]
Graham:
>> enbase/base to binary! 255.0.0 16
== "FF0000"
Anton
22-Oct-2006
[5827x4]
Ashley, works for me. What do you get when you probe system/scirpt/args 
?
By the way I usually do this in the script to ensure the args are 
always a block:
	args: compose [(system/script/args)]
Ah, I see do-thru. Probably the first version you cached didn't handle 
the args properly. Ensure you have the latest version from the website 
by using /update
do-thru/update/args url args
Ashley
22-Oct-2006
[5831]
Got it working. Deleted everything and started from scratch with 
the do/args version and it now works as expected. Thanks for the 
lead.
Graham
22-Oct-2006
[5832]
Gabriele .. that is interesting!!
Henrik
22-Oct-2006
[5833]
yet another "that's it?! no more code than that?" experience :-)
Anton
22-Oct-2006
[5834]
Cool. To the next problem !
Maxim
23-Oct-2006
[5835x2]
what is the easiest/most direct way to convert an integer value into 
a 4 byte binary (equivalent to to a 4 byte unsigned LONG) ?


for some reason, this kind of thing is not 'simple in REBOL I expected 
this to work. but didn't even get a one byte binary.

>> to-binary 100
== #{313030}


100 is a numerical value, not a string, I would have expected (in 
base 16 which is default) :
#{64}
some might be tempted to suggest converting to char!  first, but 
for any value larger than 255 This obviously does not work.
Sunanda
23-Oct-2006
[5837]
to-hex 100
== #00000064
Maxim
23-Oct-2006
[5838x2]
but that's an issue!    ;-)
>> to-binary to-hex 100
== #{3030303030303634}
Gregg
23-Oct-2006
[5840]
>> ss: make struct! [val [integer!]] [100]
>> third ss
== #{64000000}
Maxim
23-Oct-2006
[5841]
thanks Gregg we are getting close now! but that's byteswapped no? 
(I am no expert in this kind of byte manipulation...btw)
what about getting this result directly?
#{00000064}
Gregg
23-Oct-2006
[5842x2]
>> reverse third ss
== #{00000064}
You need to do that to use to-integer on the binary, as you may have 
guessed.
Maxim
23-Oct-2006
[5844x3]
<sigh!>  binary data handing really is an oversight in rebol!
does REBOL always return the data as print it out here (using the 
struct!) or will that change based on OS/HW ?
what I mean is that there seems to be everything there... its just 
not REBOLish.  (not simple)
Janeks
23-Oct-2006
[5847]
Why this function runs well on some web servers (f.ex. KFWS) but 
hangs (getting cgi script time out) for MS IIS and how to solve them? 
I found that problem is in line where read-io is.

read-post-data: func [
    {Reads the HTTP entity body}
    /safe "Disables evaluation of content-length header."
    /local len data tmp
] [

    len: load any [ all [safe "65536"] system/options/cgi/content-length 
    "0" ]

    data: make string! len
    tmp: make string! len
    while [ 0 < read-io system/ports/input tmp len ] [
        insert tail data tmp
        clear tmp
    ]

    data
]
Gregg
23-Oct-2006
[5848]
REBOL, being targeted at higher level use, hasn't made bit twiddling 
terribly easy in the past, to be sure, but if you're doing a lot 
of it, write a dialect. :-)
Anton
23-Oct-2006
[5849x2]
Maxim, yes the byte order is dependent on the platform.
Janeks, try 
	set-modes system/ports/input [binary: true]
before the WHILE. Maybe it works ?
Janeks
24-Oct-2006
[5851x2]
Anton, it did not help!
How the MS IIS is putting  those cgi data into system/ports/input?
Jerry
26-Oct-2006
[5853]
I got two REBOL functions, say, f1 and f2, which are both time-consuming.

How can I make them run simultaneous in the same process? Thank you.
Jerry
27-Oct-2006
[5854]
Got the answer as "NO", form the REBOL mail archive in REBOL.org.
Anton
27-Oct-2006
[5855x2]
Janeks, I don't know, I'm sorry. I've never used MS IIS.
Jerry, yes, you will have to divide the work up into manageable chunks.