QB / QB64 Discussion Forum     RULES     Other Subforums, Links and Downloads    Index of Threads

 Return to Index  

QBasic Indentor

July 2 2004 at 2:11 AM
  (Login _JT_)


Response to ProgramList JT

' INTENTOR.BAS
' JT's Auto-Indentor v1.14
' 1st July 2004 - 16th October 2004
OPEN "TESTS.BAS" FOR INPUT AS #1
OPEN "TESTS2.BAS" FOR BINARY AS #2
IF LOF(2) <> 0 THEN
    CLOSE 2
    KILL "TESTS2.BAS"
    OPEN "TESTS2.BAS" FOR BINARY AS #2
    END IF
Indent = 0: IndentSize = 4 'Change to suit your liking
DO
    LINE INPUT #1, B$
    A$ = LTRIM$(B$): F = 0: G = 0: E$ = ""
    FOR C = 1 TO LEN(A$)
    IF MID$(A$, C, 1) = CHR$(34) THEN F = NOT F
    IF MID$(A$, C, 1) = "'" OR MID$(A$, C, 3) = "REM" AND F = 0 THEN
        G = 1
        ELSE
        IF G = 0 THEN E$ = E$ + MID$(A$, C, 1)
        END IF
    NEXT
    A$ = RTRIM$(E$)
    A$ = A$ + " "
    D$ = LTRIM$(B$)
    W2$ = UCASE$(MID$(A$, 1, 2)): W3$ = UCASE$(MID$(A$, 1, 3))
    W4$ = UCASE$(MID$(A$, 1, 4)): W10$ = UCASE$(MID$(A$, 1, 10))
    CurIndent = Indent
    IF UCASE$(MID$(A$, 1, 4)) = "FOR " THEN Indent = Indent + IndentSize
    IF W2$ + " " = "DO " OR W2$ + ":" = "DO:" THEN Indent = Indent + IndentSize
    IF UCASE$(MID$(A$, 1, 3)) = "IF " AND UCASE$(RIGHT$(A$, 5)) = "THEN " THEN Indent = Indent + IndentSize
    IF UCASE$(MID$(A$, 1, 7)) = "END IF " THEN Indent = Indent - IndentSize: CurIndent = CurIndent - IndentSize
    IF UCASE$(MID$(A$, 1, 7)) = "ELSEIF " THEN CurIndent = CurIndent - IndentSize
    IF W4$ + " " = "NEXT " OR W4$ + ":" = "NEXT:" THEN Indent = Indent - IndentSize: CurIndent = CurIndent - IndentSize
    IF W4$ + " " = "ELSE " OR W4$ + ":" = "ELSE:" THEN CurIndent = CurIndent - IndentSize
    IF UCASE$(MID$(A$, 1, 12)) = "SELECT CASE " THEN CurIndent = CurIndent - IndentSize
    IF UCASE$(MID$(A$, 1, 5)) = "LOOP " THEN Indent = Indent - IndentSize: CurIndent = CurIndent - IndentSize
    IF W1$ = UCASE$(MID$(A$, 1, 3)) THEN Indent = Indent - IndentSize: CurIndent = CurIndent - IndentSize
    IF UCASE$(MID$(A$, 1, 6)) = "WHILE " THEN CurIndent = CurIndent - IndentSize
    IF W10$ + " " = "END SELECT " OR W10$ + ":" = "END SELECT:" THEN Indent = Indent - IndentSize: CurIndent = CurIndent - IndentSize
    IF INSTR(2, A$, ": LOOP") THEN Indent = Indent - indentSize
    IF INSTR(2, A$, ": NEXT") THEN Indent = Indent - indentSize
    IF INSTR(2, A$, ": WEND") THEN Indent = Indent - indentSize
    IF CurIndent < 0 THEN CurIndent = 0
    C$ = SPACE$(CurIndent) + D$ + CHR$(13) + CHR$(10)
    IF Indent < 0 THEN Indent = 0
    PUT #2, , C$
    LOOP WHILE NOT EOF(1)
CLOSE
SYSTEM


    
This message has been edited by _JT_ on Oct 15, 2004 11:00 AM
This message has been edited by _JT_ on Oct 15, 2004 10:41 AM
This message has been edited by _JT_ on Jul 7, 2004 11:54 AM
This message has been edited by _JT_ on Jul 5, 2004 6:12 AM
This message has been edited by _JT_ on Jul 3, 2004 3:10 AM


 
 Respond to this message   
Response TitleAuthorDate
 A suggestion Jul 2, 2004
  The PERFECT time for my signature and I don't include it! ARGH Jul 2, 2004
  *Suggestion Noted (good idea really) Jul 3, 2004
 Great tool. Slight bug fixed by this BAT file Jul 3, 2004
 Indentor V2.0 Aug 4, 2004
  Re: Indentor V2.0 Aug 4, 2004
   Would it be better if... Aug 4, 2004
    Re: Clipboard version of Indentor Aug 5, 2004
     How would it now be easier... Aug 5, 2004
     What are you talking about? Aug 5, 2004
      Sorry if... Aug 7, 2004
       I'm confused, JT Aug 7, 2004
        Heres how Aug 7, 2004
         Point of information: Grammar correctionSolitaireAug 8, 2004
         Something like that, JT Aug 8, 2004
 Web based Indentor (URL) Aug 13, 2004