Howard,
Your KixGolf scoring script is reporting to few point !!!
Each CRLF must be counted as one point (nessesary whitespace)
Also it dosn't count the nessary whitespaces inside the code,
your script will count this code:
code:
If $a>5 $x=1 EndIf
As 15 points
Assuming this would be working KiX-code:
code:
If$a>5$x=1EndIf
The result should be 18, because all the whitespaces are required.
The following UDF, also counts required whitespaces, it might
stil need some minor ajusts.
I have added the possibility to count parts of a script.
If the optional parameter $CountMarkers is used and <> '' or 0 the UDF wil
look for the line:
;GolfStart
before beginning to count
And wil stop counting when the line:
;GolfEnd
is found.
code:
Function KixGolf($A,Optional $CountMarkers)
$SpaceChars=Chr(9)+' ,;=<>()+-*/"'+"'"
If Open(1,$A) = 0
$X=0
If $CountMarkers
Do
$C=ReadLine(1)
Until $C = ';GolfStart'
EndIf
$C=ReadLine(1)
While @Error=0 And $C <> ';GolfEnd'
$InStr = 0
$StrCh = ''
$j=len($C)
For $h=1 To $j
$Ch = substr($C,$h,1)
If $Ch = '"' Or $Ch = "'"
If $InStr
If $Ch = $StrCh
$InStr = 0
EndIf
Else
$InStr = 1
$StrCh = $Ch
EndIf
$X=$X+1 ; Count stringdelimiter
Else
If $InStr
$X=$X+1 ; Count all chars inside strings
Else
$D=Asc($Ch)
If $D=59 ; Ignore comments in rest of line
$h=$j
Else
If $D=9 Or $D=32 ; Space or Tab: Count only if whitespace is demanded
$Count = 1
If InStr($SpaceChars,SubStr($C,$h-1,1))
$Count=0
Else
If InStr($SpaceChars,SubStr($C,$h+1,1))
$Count=0
EndIf
EndIf
$X=$X+$Count
Else
$X=$X+1 ; Count the character
EndIf
EndIf
EndIf
EndIf
Next
$C=Trim(ReadLine(1))
If $C <> '' And Left(Trim($C),1) <> ';'
$X=$X+1 ; Each CRLF counts as one whitespace, If not a full comment-line
EndIf
Loop
$RC=Close(1)
$KixGolf=$X
Else
$KixGolf = "KixGolf, bad filename: " + $A
EndIf
EndFunction
-Erik
ps.
I belive that only expirienced 'KiXters' will use this function, so it is not commented
on how to use.
I won't release it in the UDF section because i am sure it can be improved, and maybe
some of you wil have something to add.
Also, this UDF is of no general use, so maybe this or something similar should be linked
directly to the active Golf tournament.
[ 17 July 2002, 22:19: Message edited by: kholm ]