Post by knoware on Mar 2, 2008 13:30:17 GMT -5
I couldn't find a program to clean up RunBasic code. So wrote a quick program. It indents RB code with TABS. You supply the program to UPLOAD. It outputs the cleaned up code in your DefaultDir$ + \public\ directory with the same name. It also prints the indent count and clean code to the screen.
Until one becomes available this may help.
Have a great day.
Until one becomes available this may help.
' *******************************************************
' Program Clean up
' supply program name in UPLOAD
' Output: program with same name placed in DefaultDir$ + \public\
' *******************************************************
dim inWord$(3)
inWord$(1) = "*IF "
inWord$(2) = "*WHILE "
inWord$(3) = "*FOR "
dim outWord$(3)
outWord$(1) = "*END IF "
outWord$(2) = "*WEND "
outWord$(3) = "*NEXT "
dim inCnt(3)
upload "Select Program to look Good"; prog$
if prog$ = "" then end
print "Program:";prog$;" will be looken good"
' -------------------------
' file out in \public dir
' -------------------------
fileOut$ = DefaultDir$ + "\public\" + prog$
print "File Out:";fileOut$
OPEN fileOut$ for OUTPUT as #fo
' -------------------------------
' open file in from upload
' -------------------------------
OPEN prog$ FOR binary as #fi
while not(eof(#fi))
line input #fi, a$
if asc(a$) = 10 then a$ = mid$(a$,2) ' if it has a leading LF, dump it
a$ = trim$(a$)
endPos = len(a$)
b$ = ""
' ----------------------------------
' turn any junk character to a space
' ----------------------------------
for i = 1 to endPos
if mid$(a$,i,1) < chr$(32) then
b$ = b$ + " "
else
b$ = b$ + mid$(a$,i,1)
end if
next i
b$ = trim$(b$)
a$ = b$
' -------------------------------
' turn SPACE= to TAB=
' -------------------------------
cmtPos = instr(a$,"'") ' find position of comment
if cmtPos = 0 then cmtPos = len(a$)
be = instr(a$," =")
if be > 0 then
if be < cmtPos then
a$ = mid$(a$,1,be) + chr$(9) + mid$(a$,be + 1)
end if
end if
' ----------------------------------------
' get rid of everything after the comment
' ----------------------------------------
cmtPos = instr(b$,"'")
if cmtPos > 0 then
b$ = left$(b$,cmtPos - 1)
end if
b$ = trim$(b$)
b$ = "*" + b$ + " "
b$ = upper$(b$)
endPos = len(b$)
if endPos > 1 then ' if the line is not blank work with it
' hunt for words that cause inDent
for i = 1 to 3
posWord = instr(b$,inWord$(i))
if posWord > 0 then
posWordQ = instr(b$,"""";inWord$(i);"""")
if posWordQ = 0 then
indent = indent + 1
thisCnt = thisCnt + 1
end if
end if
next i
' if THEN something is on the same line as the IF don not indent
posThenq = instr(b$,""" THEN """)
if posThenq = 0 then
if posThenq > 0 then print "then q:";posThenq
posThen = instr(b$," THEN ")
if posThen > 0 then
if trim$(mid$(b$,posThen + 5)) <> "" then
indent = indent -1
thisCnt = thisCnt - 1
end if
end if
end if
' hunt for stuff that causes outDent
for i = 1 to 3
posWord = instr(b$,outWord$(i))
if posWord > 0 then
posWordQ = instr(b$,"""";outWord$(i);"""")
if posWordQ = 0 then
indent = indent - 1
end if
end if
next i
end if
' if indent is negative, got too many outDents
if indent < 0 then
print "ERROR: indent it negative :";a$
end if
print indent;"|";
' ------------------------------
' Make a TAB for each indent
' ------------------------------
for i = 1 to indent - thisCnt
print chr$(9); ' out to screen
print #fo,chr$(9); ' out to output file
next i
thisCnt = 0
' Make label stand out
if mid$(a$,1,1) = "[" then
print a$
print #fo,a$
else
print " ";a$
print #fo," ";a$
end if
wend
if indent <> 0 then print "Got indent problems"
close #fi
close #fo
Have a great day.