DECLARE SUB PrintLogo ()
COLOR 15
PRINT "TXT2JUB.EXE, revision 001. Written by Svalqyatchx 'Kaze'."
COLOR 7
PRINT "Purpose: Converts a .TXT file to .JUB, .JUB format contains"
PRINT "         not symbols below 32(except CR and LF) and above 127, also"
PRINT "         contains not sequences of SPC char(spaces)."

DIM byte AS STRING * 1
DIM LastWrittenByte AS STRING * 1
DIM DUMMYbyte AS STRING * 1
DIM c13 AS STRING * 1, c10 AS STRING * 1, c32 AS STRING * 1
c13$ = CHR$(13): c10$ = CHR$(10): c32$ = CHR$(32)

IF COMMAND$ = "" THEN PrintLogo: END
NameOfTXTfile$ = COMMAND$

Varangatch$ = LEFT$(NameOfTXTfile$, INSTR(NameOfTXTfile$, "."))
OPEN Varangatch$ + "JUB" FOR OUTPUT AS #2
CLOSE #2
KILL Varangatch$ + "JUB"

LastWrittenByte = "~" ' Must be NON-SPACE because by default it is SPACE!
OPEN NameOfTXTfile$ FOR BINARY AS #1
OPEN Varangatch$ + "JUB" FOR BINARY AS #2
Kagero& = LOF(1)
FOR i = 1 TO Kagero&
GET #1, , byte$
        Dakuan% = ASC(byte$)
        IF Dakuan% <> 13 THEN
        IF Dakuan% <> 10 THEN
                        IF Dakuan% <= 31 THEN
                              IF LastWrittenByte <> c32$ THEN
                                 PUT #2, , c32$
                                 LastWrittenByte = c32$
                              END IF
                        ELSEIF Dakuan% > 127 THEN
                              IF LastWrittenByte <> c32$ THEN
                                 PUT #2, , c32$
                                 LastWrittenByte = c32$
                              END IF
                        ELSE
                              PUT #2, , byte$
                              LastWrittenByte = byte$
                        END IF
        ELSE
                IF i <> Kagero& THEN
                        PUT #2, , c13$
                        PUT #2, , c10$
                     LastWrittenByte = c10$
                ELSE
                        PUT #2, , c13$
                        PUT #2, , c10$
                     LastWrittenByte = c10$
                END IF
        END IF
        END IF
NEXT
CLOSE #1, #2
PRINT "Done."

SUB PrintLogo
PRINT "Usage: TXT2JUB lao9.txt"
END SUB

