Code alignment

Blitz3D Forums/Blitz3D Programming/Code alignment

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

nice one! il go test it!

[update]

It doesnt seem to be detecting my Ifs. Yup, im using "Then" too :)
nice start though!

[update 2]

This seems to work better:
Function Entry$(number,List$,delimeter$=",")
n=1
count = 1
found = False
start = 1

If number > 1
Repeat
If Mid(List,n,1)=delimeter
count = count + 1
If count = number
found=True
start = n + 1
Exit
EndIf
EndIf
n=n+1
Until n >= Len(List)
If found = False Then RuntimeError("List Element out of Range")
EndIf
Endof = Instr(List,delimeter,start)
If endof = 0 Then endof = Len(List)+1
Return Mid(List,start,endof-start)
End Function

Function countentries(List$,delimeter$=",")
t$ = Replace(List$,delimeter,"")
Return (Len(List)-Len(t))+1
End Function


Function removeindents$(l$)
ret$=""
For n=1 To Len(l$)
If Asc(Mid(l,n,1))>31 Then ret=ret+Mid(l,n,1)
Next
Return ret
End Function


; add addindent or decindent commands if I've missed any
addindent$="repeat,while,function,type,for"
addindentfuncs = countentries(addindent)
DebugLog addindentfuncs
decindent$="until,wend,end function,end type,next,endif"
decindentfuncs = countentries(decindent)

indent = 0

inputfilename$="Autoindent.bb"
outputfilename$="Autoindent.txt"


filein = ReadFile(inputfilename)
fileout = WriteFile(outputfilename)

addone=False

Repeat

l$ = removeindents(ReadLine(filein))

For n=1 To addindentfuncs
funky$ = Lower(entry(n,addindent))
If Left(Lower(l),Len(funky))=funky Then addone = True

; special if statement, checks if there's a 'then' in the line
If Left(Lower(l),2)="if" And Instr(Lower(l),"then")=0 Then addone = True
If Left(Lower(l),2)="if" And Right$(Lower(l),4)="then" Then addone = True

Next

For n=1 To decindentfuncs
funky$ = Lower(entry(n,decindent))
If Left(Lower(l),Len(funky))=funky Then indent = indent - 1
Next

tab$ = Chr(9)

indenter$ = ""
If indent > 0
For n=1 To indent
indenter = indenter + tab
Next
EndIf

If addone = True
indent = indent + 1
addone = False
EndIf

l = indenter + l

WriteLine fileout,l

Until Eof(filein)

CloseFile filein
CloseFile fileout
ExecFile outputfilename$