'Harry Hardjono
'August 2012
'
CSD=0
indentlevel=0
indenttext=" "
indentarray=""
indentPlus=" sub for while if else elseif "
indentMin=" endsub endfor endwhile endif else elseif "
Filename=Program.Directory+"\indent1.sb"
FileSlurp()
For i=1 To Array.GetItemCount(FileData)
SkipLeadSpace()
CatalogSub()
DoIndent()
'TextWindow.WriteLine(OutData[i])
endfor
TextWindow.WriteLine("Sub List:")
For i=1 To Array.GetItemCount(SubData)
TextWindow.Write(SubData[i])
TextWindow.WriteLine("() ")
EndFor
Sub DoIndent
StrIn=Text.ConvertToLowerCase(OutData[i])
SpcInx=text.GetIndexOf(StrIn," ")
If SpcInx=0 then
SpcInx=Text.GetLength(StrIn)
endif
StrIn=Text.GetSubText(OutData[i],1,SpcInx)
StrIn=Text.ConvertToLowerCase(StrIn)
If (text.GetLength(StrIn) > 1 And Text.GetIndexOf(indentMin,text.Append(" ",StrIn))>0) then
indentlevel=indentlevel-1
If indentlevel < 0 then
indentlevel=0
endif
If indentlevel=0 then
indentarray[0]=""
else
indentarray[indentlevel]=text.Append(indentarray[indentlevel-1],indenttext)
endif
'TextWindow.WriteLine("DoIndentMin: "+StrIn)
endif
TextWindow.WriteLine(indentarray[indentlevel] + OutData[i])
If (Text.GetIndexOf(indentPlus,StrIn) > 0) then
indentlevel=indentlevel+1
If indentlevel=0 then
indentarray[0]=""
else
indentarray[indentlevel]=text.Append(indentarray[indentlevel-1],indenttext)
endif
'TextWindow.WriteLine("DoIndentPlus: "+StrIn)
endif
endsub
Sub CatalogSub
StrIn=Text.ConvertToLowerCase(OutData[i])
if text.StartsWith(StrIn,"sub ") then
StrIn=Text.GetSubTextToEnd(StrIn,5)
SpcInx=text.GetIndexOf(StrIn," ")
If SpcInx=0 then
SpcInx=Text.GetLength(StrIn)
endif
StrOut=Text.GetSubText(OutData[i],1,SpcInx+4)
CSD=CSD+1
SubData[CSD]=StrOut
endif
endsub
Sub SkipLeadSpace
StrIn=FileData[i]
StrOut=""
For SLS_i=1 to Text.GetLength(StrIn)
If (Text.GetCharacterCode(Text.GetSubText(StrIn,SLS_i,1))>32) then 'Non-space
if (StrOut="") then
StrOut=Text.GetSubTextToEnd(StrIn,SLS_i)
EndIf
EndIf
endfor
OutData[i]=StrOut
endsub
Sub FileSlurp
'Read a file and assign it to an array
'Input Filename (string)
'Output FileData (array)
FileLength=Text.GetLength(File.ReadContents(Filename))
FileData=""
FL=0
FS_i=1
While FL
FileData[FS_i]=File.ReadLine(Filename,FS_i)
FL=FL+Text.GetLength(FileData[FS_i])+2
If FileData[FS_i]="" Then 'Fudge for blank lines in file
FileData[FS_i]=" "
EndIf
FS_i=FS_i+1
Endwhile
EndSub
No comments:
Post a Comment