Ignore IntelliJ project files
[fifth.git] / tools / 5th2src.bas
1 ' Utility to convert given file from special FSCII encoding to ASCII encoding.
2
3 DECLARE SUB getline (line$)
4 DECLARE SUB initializeProgram ()
5 DIM SHARED byte AS STRING * 1
6 DIM SHARED endOfFile
7
8 initializeProgram
9
10 OPEN COMMAND$ + ".5th" FOR BINARY AS #1
11 OPEN COMMAND$ + ".src" FOR OUTPUT AS #2
12
13 ' Start reading lines from the file
14 1
15 getline line$
16 IF endOfFile = 1 THEN GOTO 2
17 PRINT #2, line$
18 GOTO 1
19
20 ' End of file reached
21 2
22
23 CLOSE #2
24 CLOSE #1
25
26 SYSTEM
27
28 SUB getline (line$)
29
30 line$ = ""
31
32 ' Start reading bytes from the file
33 3
34 IF EOF(1) <> 0 THEN endOfFile = 1: GOTO 4
35 GET #1, , byte
36
37 ' Convert non-printable characters to printable ones
38 IF ASC(byte) <= 9 THEN
39   byte = CHR$(48 + ASC(byte))
40 END IF
41 IF ASC(byte) <= 15 THEN
42   byte = CHR$(65 + ASC(byte) - 10)
43 END IF
44 IF ASC(byte) = 255 THEN
45   byte = " "
46 END IF
47 IF ASC(byte) = 253 THEN
48   byte = CHR$(9)
49 END IF
50
51 ' Check for end of line character
52 IF byte = CHR$(254) THEN GOTO 4
53
54 line$ = line$ + byte
55 GOTO 3
56
57 ' End of line reached
58 4
59
60 END SUB
61
62 SUB initializeProgram
63 endOfFile = 0
64
65 ' Check if the command-line argument is empty
66 IF COMMAND$ = "" THEN END
67
68 END SUB