-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfake-configure.bas
92 lines (78 loc) · 2.14 KB
/
fake-configure.bas
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
dim shared ids(any) as string
dim shared values(any) as string
function lookupDefine(byref id as string) as integer
for i as integer = lbound(ids) to ubound(ids)
if ids(i) = id then
return i
end if
next
return -1
end function
sub addDefine(byref id as string, byref value as string)
redim preserve ids(0 to ubound(ids) + 1)
redim preserve values(0 to ubound(values) + 1)
ids(ubound(ids)) = id
values(ubound(values)) = value
end sub
function strStartsWith(byref s as string, byref lookfor as string) as Boolean
function = left(s, len(lookfor)) = lookfor
end function
function strSplit(byref s as string, byref delimiter as string, byref l as string, byref r as string) as Boolean
var leftlen = instr(s, delimiter) - 1
if leftlen > 0 then
l = left(s, leftlen)
r = right(s, len(s) - leftlen - len(delimiter))
function = TRUE
else
function = FALSE
end if
end function
'----------------------------------------------------------------------
' Main
'----------------------------------------------------------------------
for i as integer = 1 to __FB_ARGC__ - 1
var arg = *__FB_ARGV__[i]
dim as string id, value
if strSplit(arg, "=", id, value) = FALSE then
id = arg
value = "1"
end if
addDefine(id, value)
next
if open cons(for input, as #1) <> 0 then
print "failed to open stdin"
end 1
end if
dim ln as string
while not eof(1)
line input #1, ln
'' Check for #undef|cmakedefine <id> lines
const undef = "#undef"
const cmakedefine = "#cmakedefine"
dim keyword as string
if strStartsWith(ln, undef) then
keyword = undef
elseif strStartsWith(ln, cmakedefine) then
keyword = cmakedefine
end if
if len(keyword) > 0 then
'' Space behind the #keyword?
if mid(ln, len(keyword) + 1, 1) = " " then
'' Id?
var id = mid(ln, len(keyword) + 2, len(ln) - len(keyword) - 1)
if len(id) > 0 then
'' Like autoconf, we either turn #undefs into #defines,
'' or comment them out (so they won't be preserved into
'' the .bi by fbfrog)
var def = lookupDefine(id)
if def >= 0 then
ln = "#define " + id + " " + values(def)
else
ln = "/* " + ln + " */"
end if
end if
end if
end if
print ln
wend
close #1