Create readable text `.bas' for each tokenized BASIC `,ffb' file.
[ssr] / StraySrc / Utilities / b / msgaof.bas
CommitLineData
c1b567d8
MW
1REM
2REM msgAOF
3REM
4REM Convert message files to an AOF format
5REM
6REM © 1995-1998 Straylight
7REM
8
9REM ----- Licensing note ----------------------------------------------------
10REM
11REM This file is part of Straylight's core utilities (coreutils)
12REM
13REM Coreutils is free software; you can redistribute it and/or modify
14REM it under the terms of the GNU General Public License as published by
15REM the Free Software Foundation; either version 2, or (at your option)
16REM any later version
17REM
18REM Coreutils is distributed in the hope that it will be useful,
19REM but WITHOUT ANY WARRANTY; without even the implied warranty of
20REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21REM GNU General Public License for more details.
22REM
23REM You should have received a copy of the GNU General Public License
24REM along with Coreutils. If not, write to the Free Software Foundation,
25REM 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27ON ERROR ERROR EXT 0,REPORT$+" ["+STR$(ERL)+"]"
28
29DIM q% 256
30SYS "OS_GetEnv" TO comm$
31IF INSTR(comm$,"-quit")=0 THEN ERROR 1,"msgAOF must be started using *Run"
32comm$=MID$(comm$,INSTR(comm$,"""")+1)
33comm$=MID$(comm$,INSTR(comm$," ")+1)
34comm$=LEFT$(comm$,INSTR(comm$,"""")-1)
35
36table%=FALSE
37file$=FNword(comm$)
38out$=FNword(comm$)
39header$=FNword(comm$)
40IF file$="" OR out$="" THEN ERROR 0,"Syntax: msgAOF <in> <out> [<header>]"
41IF 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%,""
50ELSE
51 hdr%=0
52ENDIF
53
54LIBRARY "libs:bas"
55PROCbas_init
56
57in%=OPENIN(file$)
58ON ERROR CLOSE #in%:IF hdr% THEN CLOSE #hdr%:IF0ELSE:ERROR EXT 0,REPORT$+" ["+STR$(ERL)+"]"
59
60PROCbas_aofInit(64*1024)
61FOR 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%
141NEXT
142
143CLOSE #in%
144IF 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
151ENDIF
152ON ERROR ERROR EXT 0,REPORT$+" ["+STR$(ERL)+"]"
153PROCbas_aofSaveAs(out$)
154END
155
156DEF FNdoExport(alias$,name$)
157IF FNexportAs(alias$,name$)
158IF hdr%<>0 AND o=6 THEN BPUT #hdr%,CHR$(9)+CHR$(9)+"IMPORT"+CHR$(9)+name$
159=0
160
161DEF FNword(RETURN line$)
162LOCAL word$
163IF INSTR(line$," ") THEN
164 word$=LEFT$(line$,INSTR(line$," ")-1)
165 line$=MID$(line$,INSTR(line$," ")+1)
166ELSE
167 word$=line$
168 line$=""
169ENDIF
170=word$
171
172DEF FNstrip(line$)
173LOCAL x$,f%,s%
174WHILE 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)
187ENDWHILE
188=x$
189
190DEF FNupper(line$)
191LOCAL i%
192$q%=line$
193FOR i%=0 TO LEN(line$)-1
194 IF q%?i%>=97 AND q%?i%<=122 THEN q%?i%-=32
195NEXT
196=$q%
197
198DEF FNgsTrans(s$)
199LOCAL p%,t$
200SYS "OS_GSTrans",s$,q%,256 TO ,,len%
201p%=q%
202WHILE p%<q%+len%
203 t$+=CHR$(?p%)
204 p%+=1
205ENDWHILE
206=t$