1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
rem Purpose: re-define externals to only 6 characters for CMS
rem Author: Howard Wulf, AF5NE
rem Date: 2015-02-10
rem Usage: implementation defined
rem Example:
rem ~/bwbasic cms.bas
rem
rem -------------------------------------------------------------------------------
rem File File Name IN/OUT Description
rem #1 "bwbasic.h" INPUT read looking for "extern" statements
rem #2 "cms.h" OUTPUT written with "#define" statements
rem -------------------------------------------------------------------------------
rem Variable Description
rem N The number of "extern" statements so far processed
rem E$ The constant value "extern "
rem E The length of E$
rem L$ The input line read from "bwbasic.h"
rem M$ The next line from "bwbasic.h" when L$ does not contain a semicolon
rem X The location of special characters in L$
rem H$ The hexadecimal value of N
rem -------------------------------------------------------------------------------
rem
let N = 0
let E$ = "extern "
let E = len( E$ )
open "bwbasic.h" for input as #1
open "cms.txt" for output as #2
while not eof( #1 )
line input #1, L$
L$ = trim$( L$ )
if left$( L$, E ) = E$ then
rem extern ....
while instr( L$, ";" ) = 0
' read more lines until we get a semicolon
line input #1, M$
M$ = trim$( M$ )
L$ = L$ + " " + M$
wend
rem extern ...;
L$ = trim$(mid$( L$, E + 1 ))
' truncate trailing semicolon
X = instr( L$, ";" )
if X > 0 then
L$ = trim$(left$( L$, X - 1 ))
end if
' truncate trailing parenthesis
X = instr( L$, "(" )
if X > 0 then
L$ = trim$(left$( L$, X - 1 ))
end if
' truncate trailing bracket
X = instr( L$, "[" )
if X > 0 then
L$ = trim$(left$( L$, X - 1 ))
end if
' find the last word
X = instr(L$, " " )
while X > 0
L$ = trim$(mid$( L$, X + 1 ))
X = instr(L$, " " )
wend
' skip leading asterick
while left$( L$, 1 ) = "*"
L$ = trim$(mid$( L$, 2 ))
wend
if L$ = "main" or L$ = "putenv" or L$="sleep" then
' ignore magic function name
else
' pad for alignment
REM L$ = L$ + space$(32)
REM L$ = left$( L$, 32 )
REM H$ = "00000" + hex$(N)
REM H$ = right$( H$, 5 )
REM print #2, "#define ";L$;" X";H$
REM N = N + 1
if len( L$ ) > 0 then
print #2, L$
end if
end if
end if
wend
close #2
close #1
REM sort before assigning value
if shell( "sort < cms.txt > cms.out" ) = 0 then
N = 0
open "cms.out" for input as #1
open "cms.h" for output as #2
while not eof(#1)
line input #1, L$
L$ = trim$(L$)
if len(L$) then
' pad for alignment
L$ = L$ + space$(32)
L$ = left$( L$, 32 )
H$ = "00000" + hex$(N)
H$ = right$( H$, 5 )
print #2, "#define ";L$;" X";H$
N = N + 1
end if
wend
close #2
close #1
rem Cleanup temporary files
kill "cms.txt"
kill "cms.out"
end if
end
|