forked from trishume/ddbus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransformer.rb
68 lines (59 loc) · 1.65 KB
/
transformer.rb
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
# Script used to transform dbus headers into sources/ddbus/c_lib.d
# Uses dstep and then fixes a bunch of things up
# This should only need to be done once but I'm including it in case things
# need to be re-done. Put dbus headers into the "dbus" folder and install dstep.
Dir["dbus/*.h"].each do |h|
system "dstep #{h} -DDBUS_INSIDE_DBUS_H -I."
end
FILES_ORDER =
[
"dbus/dbus-arch-deps.d",
"dbus/dbus-types.d",
"dbus/dbus-protocol.d",
"dbus/dbus-errors.d",
"dbus/dbus-macros.d",
"dbus/dbus-memory.d",
"dbus/dbus-shared.d",
"dbus/dbus-address.d",
"dbus/dbus-syntax.d",
"dbus/dbus-signature.d",
"dbus/dbus-misc.d",
"dbus/dbus-threads.d",
"dbus/dbus-message.d",
"dbus/dbus-connection.d",
"dbus/dbus-pending-call.d",
"dbus/dbus-server.d",
"dbus/dbus-bus.d",
"dbus/dbus.d"
]
ANON_ALIAS = /^alias _Anonymous_(\d) (.*);$/
def fixup(cont)
cont.gsub!("extern (C):",'')
cont.gsub!(/^import .*$/,'')
anons = cont.scan(ANON_ALIAS)
cont.gsub!(ANON_ALIAS,'')
anons.each do |num,name|
cont.gsub!("_Anonymous_#{num}",name)
end
# Special case for bug in translator
cont.gsub!("alias function", "alias DBusHandlerResult function")
cont.gsub!(/^alias (\S*) (\S*);$/){ |s| ($1 == $2) ? '' : s }
cont.strip
end
f = File.open("c_lib.d","w")
f.puts <<END
module ddbus.c_lib;
import core.stdc.config;
import core.stdc.stdarg;
extern (C):
END
FILES_ORDER.each do |h|
f.puts "// START #{h}"
File.open(h,'r') do |header|
contents = header.read
f.puts fixup(contents)
end
f.puts "// END #{h}"
end
# Manual Notes:
# - Put correct return result (DBusHandlerResult) for some typedefs (DBusHandleMessageFunction, DBusObjectPathMessageFunction)