#68480 - 2002-07-21 12:08 AM
KiXtart Golf Solution(s)
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Here is the function I created that solves the problem and script(s) Jens posted.
Kixgolf score = 716 (Please someone else verify). I'm using KiXtart 2001 v4.10 (99) with Windows 2000 SP2.
Here is the code:
code:
Function ImportRegFile($c) DIM $,$y,$z,$k,$n,$a,$i,$b,$t IF UBOUND($c)<0 $c=SPLIT($c) ENDIF FOR EACH $y in $c OPEN(9,$y) Do $=READLINE(9) $y=LEFT($,1) $i=INSTR($,'=') If $y='[' $k=SUBSTR($,2,LEN($)-2) ADDKEY($k) If LEFT($k,1)='-' DELKEY(SUBSTR($k,2)) Endif Endif IF $i $a=SPLIT($,'=')[1] $n=SUBSTR($,2,$i-3) While RIGHT($a,1)=\ $a=LEFT($a,LEN($a)-1)+TRIM(READLINE(9)) Loop $y=SPLIT($a,':') SELECT CASE $y[0]=dword $=VAL('&'+SUBSTR($a,7)) $t=DWORD CASE UBOUND($y) $z=SUBSTR($y[0],5,1) $='' For $i= 1 to LEN($y[1]) STEP 3 $b=SUBSTR($y[1],$i,2) $t=BINARY If $Z $t=EXPAND_SZ $b=CHR(VAL('&'+$b)) Endif $=$+$b Next IF 7=$z $t=MULTI_SZ $=$+'|' Endif CASE 1 $=SUBSTR($a,2,LEN($a)-2) $t=SZ ENDSELECT WRITEVALUE($k,$n,$,'REG_'+$t) IF $a='-' Delvalue($k,$n) Endif Endif Until @error Close(9) Next EndFunction
I'm not sure I used every trick in the book, but I used most of them. Feel free to verify the script and score.
There are some shortcomings in my script in that it doesn't work for every .reg file, only ones similar to the ones Jens created....
The next stage is to improve this script (I would suggest we add error-correction and support various exceptions that would cause the script to bomb with some .reg files in addition to) by making it even shorter.
Brian
{edit} Also, please post your versions of the script, as well! I won't be here for a bit, cuz I'm going out to a movie.. Cheers! [ 21 July 2002, 00:14: Message edited by: BrianTX ]
|
|
Top
|
|
|
|
#68481 - 2002-07-21 01:44 AM
Re: KiXtart Golf Solution(s)
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
Brian,
Nice script
Just checked your score 716 (hereby verified)
I wil post my own code even if the score is 777, here it is
code:
Function ImportRegfile($p) Dim $,$a[0],$f,$n,$r,$t,$v,$x If VarType($p)=8 $a[0]=$p Else $a=$p EndIf For Each $f In $a Open(1,$f) Do Do $=ReadLine(1) $p=Left($,1)='[' Until @Error+$p If $p $t=SubStr($,2,Len($)-2) If Left($t,1)='-' DelKey(SubStr($t,2)) Else AddKey($t) Do $='' Do $=Left($,Len($)-1)+Trim(ReadLine(1)) Until Right($,1)<>'\' If $ $x=Split($,'=') $n=Split($x[0]+'"','"')[1] $x=$x[1] If Left($x,1)='-' DelValue($t,$n) Else $r=Split(SubStr($x,InStr($x,':')+1),',') $v='' For $=0 To UBound($r)-1 $p=Val('&'+$r[$]) $v=$v+Chr($p+($p=0)*124) Next $=SubStr($x,5,1) Select Case Left($x,1)='"' $v=Split($x,'"')[1] $x='SZ' Case $='d' $v=Val('&'+$r[0]) $x='DWORD' Case $='2' $x='EXPAND_SZ' Case $='7' $x='MULTI_SZ' Case 1 $v=Join($r,'') $x='BINARY' EndSelect WriteValue($t,$n,$v,'REG_'+$x) EndIf EndIf Until $='' EndIf EndIf Until @Error Close(1) Next EndFunction
I wil reread your script tomorrow, it's getting late here. Allready in the parametercheck you gain some points, but the rest i thought looked very similar to mine, but there must be some small tricks.
-Erik
|
|
Top
|
|
|
|
#68482 - 2002-07-21 02:47 AM
Re: KiXtart Golf Solution(s)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Here is my script that uses regular expressions via WSH to isolate the keys, and data. I decided that I wanted to explore this approach and did not want to abandon it just because I could not find a way to reduce the code content. It was a learning a experience.
check for all registry keys Errors:0 check for registry value types in import1:0 check for registry value types in import2:0 check for registry value types in import3:0 check for registry values in import1:0 check for registry values in import2:0 check for registry values in import3:0 The UDF ImportRegFile passed the validation test. Please do not forget to post your KiXtart Golf score.
KixGolf score = 918 code:
function ImportRegfile($Z) Dim $, $A[4], $B, $C, $o, $D, $E, $F, $G, $i, $K, $N, $T $o = createobject("VBscript.RegExp") $o.Global = 1
if ubound($Z)<0 $Z=$Z,"" endif for each $C in $Z
;ReadFile Kix $=open(1,$C) while @error=0 $B=ReadLine(1) if $B="" $E=$E+"`" else $E=$E+$B+"`" endif loop $=close(1)
$F=join(split($E,"\` "),"") $o.Pattern = '`\[(\-?)(.*?)\](?=`)|`"?([\w\- ]+)?@@?"?=("|.{3,6}\:)?(.*?)"?(?=`)' for each $B in $o.Execute($F) for $i=0 to 4 $A[$i]=$B.SubMatches($i) next
if $A[1] $K=$A[1] if $A[0] $C=DelKey($K) else $C=AddKey($K) endif else ;Add Values $N=$A[2] $D=$A[4] $T = 'dword:','hex:','"','hex(2):','','hex(7):' for $i=0 to 5 if $A[3]=$T[$i] $=$i endif next
if $=0 $D=val("&"+$D) endif
for each $C in split($D,",") if $=3 | $C>"00" & $=5 $B=execute('$C=Chr(&'+$C+')') endif $G=""+$G+$C next $D=$G $G="" if $=5 $D=join(split($D,"0000"),"|") endif
;Write Value if $D="-" $C=DelValue($K, $N) else if not $D $D="" endif $T = "DWORD","BINARY","SZ","EXPAND_SZ","","MULTI_SZ" $C=WriteValue($K, $N, $D, "REG_"+$T[$]) endif endif next next $ImportRegfile=0 exit 0 endfunction
[ 04 August 2002, 03:35: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#68484 - 2002-07-21 03:44 AM
Re: KiXtart Golf Solution(s)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Sorry to hear about that. I hope they get caught and you are not out too much stuff.
|
|
Top
|
|
|
|
#68487 - 2002-07-21 04:57 AM
Re: KiXtart Golf Solution(s)
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
ok, back.
here is my code. maybe will cut it or yours... code:
function ImportRegfile($) if ubound($)<1 $=split($) endif for each $ in $ dim $k,$v,$m,$d,$s $=open(1,$) do if "["=left($,1) $=substr($,2,len($)-2) if "-"=left($,1) $=delkey(substr($,2)) else $k=$ $=addkey($) endif endif if $k&$ while "\"=right($,1) $=left($,len($)-1)+trim(readline(1)) loop $=split($,"=") $v=substr($[0],2,len($[0])-2) $=$[1] if '"'=left($,1) $m="SZ" $s=substr($,2,len($)-2) else $s="" $m=instr($,":") $d=substr($,$m-2,1) for each $ in split(substr($,$m+1),",") $m=val("&"+$) if $d="r" $=$m $m="DWORD" endif if $d="e" $m="BINARY" endif if $d=2|$d=7 $=chr($m) $m="EXPAND_SZ" endif $s=$s+$ next if $d=7 $m="MULTI_SZ" for each $ in split($s,00) $s=$+"|" next endif endif if '-'=$s $=delvalue($k,$v) else $=writevalue($k,$v,$s,"reg_"+$m) endif endif $=readline(1) until @error $=close(1) next endfunction
KixGolf score = 729
_________________________
!download KiXnet
|
|
Top
|
|
|
|
#68489 - 2002-07-21 05:42 AM
Re: KiXtart Golf Solution(s)
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
ok. got mine to 720 code:
function ImportRegfile($) if ubound($)<1 $=$,"" endif for each $ in $ dim $k,$v,$m,$d,$s $=open(1,$) do if "["=left($,1) $=substr($,2,len($)-2) if "-"=left($,1) $=delkey(substr($,2)) else $k=$ $=addkey($) endif endif if $k&$ while \=right($,1) $=left($,len($)-1)+trim(readline(1)) loop $v=substr($,2,instr($,"=")-3) $=split($,"=")[1] if '"'=left($,1) $m="SZ" $s=substr($,2,len($)-2) else $s="" $m=instr($,":") $d=substr($,$m-2,1) for each $ in split(substr($,$m+1),",") $m=val("&"+$) if $d="r" $=$m $m="DWORD" endif if $d="e" $m="BINARY" endif if $d=2|$d=7 $=chr($m) $m="EXPAND_SZ" endif $s=$s+$ next if $d=7 $m="MULTI_SZ" for each $ in split($s,00) $s=$+"|" next endif endif if '-'=$s $=delvalue($k,$v) else $=writevalue($k,$v,$s,"reg_"+$m) endif endif $=readline(1) until @error $=close(1) next endfunction
{edit} posted wrong code. [ 21 July 2002, 06:52: Message edited by: Lonkero ]
_________________________
!download KiXnet
|
|
Top
|
|
|
|
#68491 - 2002-07-21 06:06 AM
Re: KiXtart Golf Solution(s)
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
I didn't catch the part where returning values is not allowed. I was under the impression that it was. Regardless.. add 12 strokes and and I was still ahead (just barely). As far as producing trash in the registry... with the golf.zip file I downloaded, it does not product trash in the registry....
On another note.. whether or not my script is deemed valid, I'm not worried. I enjoyed the exercise and see some others have shaved some from their scores in other ways. So, the final script should be able to get near 700, I believe.
Also, I'm sorry about your car being broken into. I hope that everything turns out alright!
(I noticed that much of everyone's code looks identical... pretty interesting..... )
Brian [ 21 July 2002, 06:08: Message edited by: BrianTX ]
|
|
Top
|
|
|
|
#68493 - 2002-07-21 03:29 PM
Re: KiXtart Golf Solution(s)
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Yeah.. that part was because I removed an "ELSE" statement... probably should not have.. just trying to squeeze a few more strokes...
Brian
|
|
Top
|
|
|
|
#68494 - 2002-07-21 03:37 PM
Re: KiXtart Golf Solution(s)
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Howard,
I actually think I like your script the best.. I'm pretty sure that if I wanted a UDF to do this operation, I would use yours... I'm also pretty sure you should be able to shave more strokes from the script.
Brian
|
|
Top
|
|
|
|
#68495 - 2002-07-21 04:35 PM
Re: KiXtart Golf Solution(s)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Thanks, Brian. I know there are ways to trim the code a little, but I can not think of a way to cut 200 strokes.
Regular expressions are a very powerful tool. Having them available in KiXtart via WSH is a great thing. The Microsoft implementaion isn't quite as stream lined as that in Perl, but having them available for consideration can offer new alternatives.
{edit} KixGolf score = 897 saved some! (-21) (edit) KixGolf score = 891 (-6) {edit} KixGolf score = 878 (-13) {edit} KixGolf score = 843 (-35) [ 22 July 2002, 00:08: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#68497 - 2002-07-22 01:26 AM
Re: KiXtart Golf Solution(s)
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I am still trying to trim my script down...
C:\Data\Scripts\Golf>C:\Data\Kix2001\KiX2001.410\kix32 golf5b.kix
check for all registry keys Errors:0 check for registry value types in import1:0 check for registry value types in import2:0 check for registry value types in import3:0 check for registry values in import1:0 check for registry values in import2:0 check for registry values in import3:0 The UDF ImportRegFile passed the validation test. Please do not forget to post your KiXtart Golf score.
KixGolf score = 840 code:
function ImportRegfile($) Dim $A[4], $B, $C, $D, $G, $i, $K, $N, $o $o = createobject("VBscript.RegExp") $o.Global = 1
if ubound($)<0 $=$,"" endif for each $B in $ $B=open(1,$B) do $C=$C+ReadLine(1)+"`" until @error $B=close(1) next
$C=join(split($C,"\` "),"")
$o.Pattern = '`\[(\-?)(.*?)\](?=`)|`"?([\w\- ]+)?@@?"?=("|.{3,6}\:)?(.*?)"?(?=`)' for each $B in $o.Execute($C) for $i=0 to 4 $A[$i]=$B.SubMatches($i) next
if $A[1] $K=$A[1] if $A[0] $C=DelKey($K) else $C=AddKey($K) endif else ;Add Values $N=$A[2] $D=$A[4] for $i=0 to 5 if $A[3]=split('dword: hex: " hex(2): hex(7):')[$i] $=$i endif next if $=0 $D=val("&"+$D) endif for each $C in split($D,",") if $=3 | $C>"00" & $=5 $B=execute('$C=Chr(&'+$C+')') endif $G=""+$G+$C next $D=$G $G="" if $=5 $D=join(split($D,'0000'),"|") endif
;Write Value if $D="-" $C=DelValue($K, $N) else $C=WriteValue($K, $N, $D, "REG_"+split('DWORD BINARY SZ EXPAND_SZ MULTI_SZ')[$]) endif endif next $ImportRegfile=0 exit 0 endfunction
[ 22 July 2002, 01:28: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#68499 - 2002-07-22 10:08 AM
Re: KiXtart Golf Solution(s)
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
I hope jens clarifies that output issue.
if I don't use the output blocking and if I don't make my multilined string to work properly for real multilines my script ends up with: KixGolf score = 687
code:
function ImportRegfile($) if ubound($)<1 $=$,"" endif for each $ in $ dim $k,$v,$m,$d,$s open(1,$) do if "["=left($,1) $=substr($,2,len($)-2) if "-"=left($,1) $=delkey(substr($,2)) else $k=$ $=addkey($) endif endif if $k&$ while \=right($,1) $=left($,len($)-1)+trim(readline(1)) loop $v=substr($,2,instr($,"=")-3) $=split($,"=")[1] if '"'=left($,1) $m="SZ" $s=substr($,2,len($)-2) else $s="" $m=instr($,":") $d=substr($,$m-2,1) for each $ in split(substr($,$m+1),",") $m=val("&"+$) if $d="r" $=$m $m="DWORD" endif if $d="e" $m="BINARY" endif if $d=2|$d=7 $=chr($m) $m="EXPAND_SZ" endif $s=$s+$ next if $d=7 $m="MULTI_SZ" $s=$s+"|" endif endif if '-'=$s delvalue($k,$v) else writevalue($k,$v,$s,"reg_"+$m) endif endif $=readline(1) until @error close(1) next endfunction
with the output of: quote: C:\KiX2001.401\kixgolf>KIX32.EXE golf.kix 00000000000000-10000000000000000000000-10 The UDF ImportRegFile passed the validation test. Please do not forget to post your KiXtart Golf score.
and it still does not produce the trash in reg
cheers,
_________________________
!download KiXnet
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 601 anonymous users online.
|
|
|