'===========================================================================
' Subject: Yabb Forum Code Preprocessor       Date: 12-22-02 (  :  )       
'  Author: Michael Webster                    Code: Qbasic, QB, PDS        
'  Origin: mfwebster@pdq.net                Packet: TEXT.ABC
'===========================================================================
'Yabb Preprocessor
'Michael Webster Email:  mfwebster@pdq.net 

DECLARE SUB Untab (line$, tabWidth%) 
DEFINT A-Z 
 
' This is a QBasic compatible "post preprocessor". It can be used to 
' pre-[b]format[/b] a post so [b]yabb[/b] will display the post with the original 
' [b]format[/b]ting. The problem with [b]yabb[/b] is that it displays each tab 
' character in a post as a single space, and each run of six or more 
' space characters as a smaller number of spaces. The relationship 
' between the length of the runs of space characters and the number 
' of spaces displayed is: 
' 
'     6=1...11=6, 12=2...17=7, 18=3...23=8,24=4...29=9,30=5... 
' 
' For each line of the input file, this program expands the tabs to 
' spaces and replaces each run of six or more space characters with 
' as many SPACE$(5) + CHR$(9) strings as will fit plus as many space 
' characters as necessary to match the length of the orginal run. 
' 
' For best alignment, the post should use a fixed-pitch font. 
' Instead of specifying the font directly, you can use the 
' Insert Code or Pre[b]format[/b]ted Text codes. 
 
' Modify these three statements as necessary. 
tabWidth = 4 
OPEN "[b]yabb[/b].bas" FOR INPUT AS 1 
OPEN "[b]yabb[/b].txt" FOR OUTPUT AS 2 
 
filler$ = SPACE$(5) + CHR$(9) 
DO WHILE NOT EOF(1) 
    LINE INPUT #1, line$ 
    Untab line$, tabWidth 
    out$ = "" 
    spaceCnt = 0 
    FOR i = 1 TO LEN(line$) 
        c$ = MID$(line$, i, 1) 
        IF c$ = " " THEN 
            spaceCnt = spaceCnt + 1 
        ELSE 
            IF spaceCnt > 5 THEN 
                FOR j = 1 TO spaceCnt \ 6 
                    out$ = out$ + filler$ 
                NEXT 
                out$ = out$ + SPACE$(spaceCnt MOD 6) 
            ELSE 
                out$ = out$ + SPACE$(spaceCnt) 
            END IF 
            out$ = out$ + c$ 
            spaceCnt = 0 
        END IF 
    NEXT 
    PRINT #2, out$ 
LOOP 
 
CLOSE 
 
SUB Untab (line$, tabWidth%) 
 
    ' Expands any tabs in <line$> to spaces using <tabWidth%> 
    ' to determine the location of the tab stops. 
 
    FOR i = 1 TO LEN(line$) 
        c$ = MID$(line$, i, 1) 
        IF c$ = CHR$(9) THEN 
            spaceCnt = tabWidth - (currPos MOD tabWidth) 
            temp$ = temp$ + SPACE$(spaceCnt) 
            currPos = currPos + spaceCnt 
        ELSE 
            temp$ = temp$ + c$ 
            currPos = currPos + 1 
        END IF 
    NEXT 
 
    line$ = temp$ 
 
END SUB 
