Create readable text `.bas' for each tokenized BASIC `,ffb' file.
[ssr] / StraySrc / Utilities / b / msgaof.bas
1 REM
2 REM msgAOF
3 REM
4 REM Convert message files to an AOF format
5 REM
6 REM © 1995-1998 Straylight
7 REM
8
9 REM ----- Licensing note ----------------------------------------------------
10 REM
11 REM This file is part of Straylight's core utilities (coreutils)
12 REM
13 REM Coreutils is free software; you can redistribute it and/or modify
14 REM it under the terms of the GNU General Public License as published by
15 REM the Free Software Foundation; either version 2, or (at your option)
16 REM any later version
17 REM
18 REM Coreutils is distributed in the hope that it will be useful,
19 REM but WITHOUT ANY WARRANTY; without even the implied warranty of
20 REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 REM GNU General Public License for more details.
22 REM
23 REM You should have received a copy of the GNU General Public License
24 REM along with Coreutils. If not, write to the Free Software Foundation,
25 REM 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27 ON ERROR ERROR EXT 0,REPORT$+" ["+STR$(ERL)+"]"
28
29 DIM q% 256
30 SYS "OS_GetEnv" TO comm$
31 IF INSTR(comm$,"-quit")=0 THEN ERROR 1,"msgAOF must be started using *Run"
32 comm$=MID$(comm$,INSTR(comm$,"""")+1)
33 comm$=MID$(comm$,INSTR(comm$," ")+1)
34 comm$=LEFT$(comm$,INSTR(comm$,"""")-1)
35
36 table%=FALSE
37 file$=FNword(comm$)
38 out$=FNword(comm$)
39 header$=FNword(comm$)
40 IF file$="" OR out$="" THEN ERROR 0,"Syntax: msgAOF <in> <out> [<header>]"
41 IF header$<>"" THEN
42 hdr%=OPENOUT(header$)
43 BPUT #hdr%,";"
44 BPUT #hdr%,"; Message symbols [generated by msgAOF]"
45 BPUT #hdr%,";"
46 BPUT #hdr%,""
47 BPUT #hdr%,CHR$(9)+CHR$(9)+"["+CHR$(9)+":LNOT::DEF:msg__dfn"
48 BPUT #hdr%,CHR$(9)+CHR$(9)+"GBLL"+CHR$(9)+"msg__dfn"
49 BPUT #hdr%,""
50 ELSE
51 hdr%=0
52 ENDIF
53
54 LIBRARY "libs:bas"
55 PROCbas_init
56
57 in%=OPENIN(file$)
58 ON ERROR CLOSE #in%:IF hdr% THEN CLOSE #hdr%:IF0ELSE:ERROR EXT 0,REPORT$+" ["+STR$(ERL)+"]"
59
60 PROCbas_aofInit(64*1024)
61 FOR o=4 TO 6 STEP 2
62 [ opt o
63 FNpass
64
65 FNarea("Resources$$Data","CODE,READONLY")
66 ]
67
68 PTR #in%=0
69 REPEAT
70 line$=FNstrip(GET$#in%)
71
72 CASE LEFT$(line$,1) OF
73 WHEN ";","#",":",""
74 REM Ignore comment lines
75 OTHERWISE
76 col%=INSTR(line$,":")
77 IF col%=0 THEN
78 CLOSE #in%:IF hdr% THEN CLOSE #hdr%:IF0ELSE:ERROR 0,"Bad message line"
79 ENDIF
80 tag$=FNstrip(LEFT$(line$,col%-1))
81 msg$=FNstrip(MID$(line$,col%+1))
82 CASE LEFT$(msg$,1) OF
83 WHEN "{"
84 [ opt o
85 .help
86 .syntax ;Just make sure of this
87 ]
88 REPEAT
89 msg$=FNstrip(GET$#in%)
90 CASE msg$ OF
91 WHEN "|"
92 [ opt o
93 .syntax
94 ]
95 WHEN "}"
96 REM Do nothing
97 OTHERWISE
98 IF RIGHT$(msg$,1)="\" THEN
99 [ opt o
100 dcb FNgsTrans(LEFT$(msg$,LEN(msg$)-1))
101 ]
102 ELSE
103 [ opt o
104 dcb FNgsTrans(msg$)
105 dcb 13
106 ]
107 ENDIF
108 ENDCASE
109 UNTIL msg$="}"
110 [ opt o
111 dcb 0
112 FNdoExport("help","help_"+tag$)
113 FNdoExport("syntax","synt_"+tag$)
114 ]
115 WHEN "["
116 msg$=MID$(msg$,2)
117 col%=INSTR(msg$,"]")
118 err%=EVAL(LEFT$(msg$,col%-1))
119 msg$=FNstrip(MID$(msg$,col%+1))
120 msg$=FNgsTrans(msg$)
121 [ opt o
122 FNalign
123 .label
124 dcd err%
125 dcb msg$
126 dcb 0
127 FNdoExport("label","msg_"+tag$)
128 ]
129 OTHERWISE
130 msg$=FNgsTrans(msg$)
131 [ opt o
132 .label
133 dcb msg$
134 dcb 0
135 FNdoExport("label","msg_"+tag$)
136 ]
137 ENDCASE
138 ENDCASE
139
140 UNTIL EOF #in%
141 NEXT
142
143 CLOSE #in%
144 IF hdr% THEN
145 BPUT #hdr%,""
146 BPUT #hdr%,CHR$(9)+CHR$(9)+"]"
147 BPUT #hdr%,""
148 BPUT #hdr%,CHR$(9)+CHR$(9)+"END"
149 CLOSE #hdr%
150 SYS "OS_File",1,header$,&FFFFFF3A,&BD896000,,3
151 ENDIF
152 ON ERROR ERROR EXT 0,REPORT$+" ["+STR$(ERL)+"]"
153 PROCbas_aofSaveAs(out$)
154 END
155
156 DEF FNdoExport(alias$,name$)
157 IF FNexportAs(alias$,name$)
158 IF hdr%<>0 AND o=6 THEN BPUT #hdr%,CHR$(9)+CHR$(9)+"IMPORT"+CHR$(9)+name$
159 =0
160
161 DEF FNword(RETURN line$)
162 LOCAL word$
163 IF INSTR(line$," ") THEN
164 word$=LEFT$(line$,INSTR(line$," ")-1)
165 line$=MID$(line$,INSTR(line$," ")+1)
166 ELSE
167 word$=line$
168 line$=""
169 ENDIF
170 =word$
171
172 DEF FNstrip(line$)
173 LOCAL x$,f%,s%
174 WHILE line$<>""
175 IF LEFT$(line$,1)=" " THEN
176 s%+=1
177 ELSE
178 IF (f% AND 1) THEN
179 x$+=STRING$(s%," ")+LEFT$(line$,1)
180 ELSE
181 x$+=LEFT$(line$,1)
182 ENDIF
183 s%=0
184 f%=f% OR 1
185 ENDIF
186 line$=MID$(line$,2)
187 ENDWHILE
188 =x$
189
190 DEF FNupper(line$)
191 LOCAL i%
192 $q%=line$
193 FOR i%=0 TO LEN(line$)-1
194 IF q%?i%>=97 AND q%?i%<=122 THEN q%?i%-=32
195 NEXT
196 =$q%
197
198 DEF FNgsTrans(s$)
199 LOCAL p%,t$
200 SYS "OS_GSTrans",s$,q%,256 TO ,,len%
201 p%=q%
202 WHILE p%<q%+len%
203 t$+=CHR$(?p%)
204 p%+=1
205 ENDWHILE
206 =t$