Skip to content

Commit 0d083e7

Browse files
authored
Merge pull request #553 from flukiluke/add_prefix_converter
Add $NOPREFIX converter
2 parents 2f6d5cb + fb96053 commit 0d083e7

File tree

9 files changed

+1255
-160
lines changed

9 files changed

+1255
-160
lines changed

internal/support/addprefix/addprefix.bas

+785
Large diffs are not rendered by default.

source/ide/file_converters.bas

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
'Old QuickBasic "quick load" format
2+
FUNCTION BinaryFormatCheck% (pathToCheck$, pathSepToCheck$, fileToCheck$)
3+
4+
file$ = pathToCheck$ + pathSepToCheck$ + fileToCheck$
5+
6+
fh = FREEFILE
7+
OPEN file$ FOR BINARY AS #fh
8+
a$ = SPACE$(LOF(fh))
9+
GET #fh, 1, a$
10+
IF INSTR(a$, CHR$(0)) = 0 THEN CLOSE #fh: EXIT FUNCTION 'not a binary file
11+
a$ = ""
12+
GET #fh, 1, Format%
13+
GET #fh, , Version%
14+
CLOSE #fh
15+
16+
SELECT CASE Format%
17+
CASE 2300 'VBDOS
18+
result = idemessagebox("Invalid format", "VBDOS binary format not supported.", "")
19+
BinaryFormatCheck% = 1
20+
CASE 764 'QBX 7.1
21+
result = idemessagebox("Invalid format", "QBX 7.1 binary format not supported.", "")
22+
BinaryFormatCheck% = 1
23+
CASE 252 'QuickBASIC 4.5
24+
IF INSTR(_OS$, "WIN") THEN
25+
convertUtility$ = "internal\utilities\QB45BIN.exe"
26+
ELSE
27+
convertUtility$ = "./internal/utilities/QB45BIN"
28+
END IF
29+
IF _FILEEXISTS(convertUtility$) THEN
30+
what$ = ideyesnobox("Binary format", "QuickBASIC 4.5 binary format detected. Convert to plain text?")
31+
IF what$ = "Y" THEN
32+
ConvertIt:
33+
IF FileHasExtension(file$) THEN
34+
FOR i = LEN(file$) TO 1 STEP -1
35+
IF ASC(file$, i) = 46 THEN
36+
'keep previous extension
37+
ofile$ = LEFT$(file$, i - 1) + " (converted)" + MID$(file$, i)
38+
EXIT FOR
39+
END IF
40+
NEXT
41+
ELSE
42+
ofile$ = file$ + " (converted).bas"
43+
END IF
44+
45+
SCREEN , , 3, 0
46+
dummy = DarkenFGBG(1)
47+
clearStatusWindow 0
48+
COLOR 15, 1
49+
_PRINTSTRING (2, idewy - 3), "Converting... "
50+
PCOPY 3, 0
51+
52+
convertLine$ = convertUtility$ + " " + QuotedFilename$(file$) + " -o " + QuotedFilename$(ofile$)
53+
SHELL _HIDE convertLine$
54+
55+
clearStatusWindow 0
56+
dummy = DarkenFGBG(0)
57+
PCOPY 3, 0
58+
59+
IF _FILEEXISTS(ofile$) = 0 THEN
60+
result = idemessagebox("Binary format", "Conversion failed.", "")
61+
BinaryFormatCheck% = 2 'conversion failed
62+
ELSE
63+
pathToCheck$ = getfilepath$(ofile$)
64+
IF LEN(pathToCheck$) THEN
65+
fileToCheck$ = MID$(ofile$, LEN(pathToCheck$) + 1)
66+
pathToCheck$ = LEFT$(pathToCheck$, LEN(pathToCheck$) - 1) 'remove path separator
67+
ELSE
68+
fileToCheck$ = ofile$
69+
END IF
70+
END IF
71+
ELSE
72+
BinaryFormatCheck% = 1
73+
END IF
74+
ELSE
75+
IF _FILEEXISTS("internal/support/converter/QB45BIN.bas") = 0 THEN
76+
result = idemessagebox("Binary format", "Conversion utility not found. Cannot open QuickBASIC 4.5 binary format.", "")
77+
BinaryFormatCheck% = 1
78+
EXIT FUNCTION
79+
END IF
80+
what$ = ideyesnobox("Binary format", "QuickBASIC 4.5 binary format detected. Convert to plain text?")
81+
IF what$ = "Y" THEN
82+
'Compile the utility first, then convert the file
83+
IF _DIREXISTS("./internal/utilities") = 0 THEN MKDIR "./internal/utilities"
84+
PCOPY 3, 0
85+
SCREEN , , 3, 0
86+
dummy = DarkenFGBG(1)
87+
clearStatusWindow 0
88+
COLOR 15, 1
89+
_PRINTSTRING (2, idewy - 3), "Preparing to convert..."
90+
PCOPY 3, 0
91+
IF INSTR(_OS$, "WIN") THEN
92+
SHELL _HIDE "qb64pe -x internal/support/converter/QB45BIN.bas -o internal/utilities/QB45BIN"
93+
ELSE
94+
SHELL _HIDE "./qb64pe -x ./internal/support/converter/QB45BIN.bas -o ./internal/utilities/QB45BIN"
95+
END IF
96+
IF _FILEEXISTS(convertUtility$) THEN GOTO ConvertIt
97+
clearStatusWindow 0
98+
dummy = DarkenFGBG(0)
99+
PCOPY 3, 0
100+
result = idemessagebox("Binary format", "Error launching conversion utility.", "")
101+
END IF
102+
BinaryFormatCheck% = 1
103+
END IF
104+
END SELECT
105+
END FUNCTION
106+
107+
FUNCTION OfferNoprefixConversion(file$)
108+
what$ = ideyesnobox("$NOPREFIX", "This program uses the $NOPREFIX directive which is unsupported.\n\nQB64PE can automatically convert this file and any included files to\nremove $NOPREFIX. Backups of all files will be made.\n\nConvert this program?")
109+
IF what$ <> "Y" THEN EXIT FUNCTION
110+
111+
SCREEN , , 3, 0
112+
dummy = DarkenFGBG(1)
113+
COLOR 15, 1
114+
_PRINTSTRING (2, idewy - 3), "Converting... "
115+
PCOPY 3, 0
116+
117+
IF INSTR(_OS$, "WIN") THEN
118+
convertUtility$ = "internal\utilities\addprefix.exe"
119+
ELSE
120+
convertUtility$ = "internal/utilities/addprefix"
121+
END IF
122+
IF NOT _FILEEXISTS(convertUtility$) THEN
123+
IF _DIREXISTS("./internal/utilities") = 0 THEN MKDIR "./internal/utilities"
124+
IF INSTR(_OS$, "WIN") THEN
125+
SHELL _HIDE "qb64pe -x internal/support/addprefix/addprefix.bas -o " + convertUtility$
126+
ELSE
127+
SHELL _HIDE "./qb64pe -x ./internal/support/addprefix/addprefix.bas -o " + convertUtility$
128+
END IF
129+
END IF
130+
131+
convertLine$ = convertUtility$ + " " + QuotedFilename$(file$)
132+
IF _SHELLHIDE(convertLine$) = 0 _ANDALSO OpenFile$(file$) <> "C" THEN
133+
OfferNoprefixConversion = -1
134+
ELSE
135+
clearStatusWindow 0
136+
dummy = DarkenFGBG(0)
137+
PCOPY 3, 0
138+
SCREEN , , 3, 0
139+
result = idemessagebox("$NOPREFIX", "Error running conversion utility.", "")
140+
END IF
141+
END FUNCTION

source/ide/ide_global.bas

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ DIM SHARED idefindonlycomments AS INTEGER, idefindonlystrings AS INTEGER
165165
DIM SHARED idefindinvert AS INTEGER
166166
DIM SHARED idechangeto AS STRING
167167
DIM SHARED idechangemade AS INTEGER
168+
DIM SHARED ideFirstCompileFromDisk AS INTEGER 'Set true when a file is loaded, false once a compilation is done. Supports one-off actions on loaded programs.
168169
DIM SHARED ideinsert AS INTEGER
169170
DIM SHARED idepathsep AS STRING * 1
170171
DIM SHARED SubFuncLIST(0) AS STRING

0 commit comments

Comments
 (0)