1 | print qq(/* THIS FILE WAS AUTOGENERATED BY GLOBALNOTIFIERGEN.PL --- DO NOT EDIT BY HAND!!! */\n\n); |
---|
2 | |
---|
3 | my @vars = (); |
---|
4 | foreach $file (@ARGV) { |
---|
5 | open(FILE, $file); |
---|
6 | |
---|
7 | while (<FILE>) { |
---|
8 | if (m|^\s*OWLVAR_([A-Z_0-9]+)\s*\(\s*"([^"]+)"\s*/\*\s*%OwlVarStub:?([a-z0-9_]+)?\s*\*/|) { # " |
---|
9 | my $vartype = $1; |
---|
10 | my $varname = $2; |
---|
11 | my $altvarname = $2; |
---|
12 | $altvarname = $3 if ($3); |
---|
13 | |
---|
14 | my $propname = $altvarname; |
---|
15 | $propname =~ tr/a-z/A-Z/; |
---|
16 | $propname = "PROP_$propname"; |
---|
17 | |
---|
18 | my $detailname = $altvarname; |
---|
19 | $detailname =~ s/[^a-zA-Z0-9]/-/g; |
---|
20 | $detailname =~ s/^[^a-zA-Z]+//; |
---|
21 | |
---|
22 | push @vars, {type => $vartype, |
---|
23 | name => $varname, |
---|
24 | altname => $altvarname, |
---|
25 | propname => $propname, |
---|
26 | detailname => $detailname}; |
---|
27 | } |
---|
28 | } |
---|
29 | close(FILE); |
---|
30 | } |
---|
31 | |
---|
32 | print <<EOT; |
---|
33 | #include "globalnotifier.h" |
---|
34 | #include "owl.h" |
---|
35 | |
---|
36 | /* properties */ |
---|
37 | enum { |
---|
38 | PROP_NONE, |
---|
39 | /* normal properties */ |
---|
40 | PROP_RIGHTSHIFT, |
---|
41 | PROP_CURMSG_VERT_OFFSET, |
---|
42 | /* generated from variable listings */ |
---|
43 | EOT |
---|
44 | |
---|
45 | for my $var (@vars) { |
---|
46 | print " " . $var->{propname} . ",\n"; |
---|
47 | } |
---|
48 | |
---|
49 | print <<EOT; |
---|
50 | }; |
---|
51 | |
---|
52 | G_DEFINE_TYPE(OwlGlobalNotifier, owl_global_notifier, G_TYPE_OBJECT) |
---|
53 | |
---|
54 | static void owl_global_notifier_set_property(GObject *object, |
---|
55 | guint property_id, |
---|
56 | const GValue *value, |
---|
57 | GParamSpec *pspec) |
---|
58 | { |
---|
59 | OwlGlobalNotifier *notifier = OWL_GLOBAL_NOTIFIER(object); |
---|
60 | |
---|
61 | switch (property_id) { |
---|
62 | /* normal properties */ |
---|
63 | case PROP_RIGHTSHIFT: |
---|
64 | owl_global_set_rightshift(notifier->g, g_value_get_int(value)); |
---|
65 | break; |
---|
66 | case PROP_CURMSG_VERT_OFFSET: |
---|
67 | owl_global_set_curmsg_vert_offset(notifier->g, g_value_get_int(value)); |
---|
68 | break; |
---|
69 | /* generated from variable listings */ |
---|
70 | EOT |
---|
71 | |
---|
72 | for my $var (@vars) { |
---|
73 | my $varname = $var->{name}; |
---|
74 | my $propname = $var->{propname}; |
---|
75 | print " case $propname:\n"; |
---|
76 | |
---|
77 | if ($var->{type} =~ /^BOOL/) { |
---|
78 | print <<EOT; |
---|
79 | if (g_value_get_boolean(value)) { |
---|
80 | owl_variable_set_bool_on(¬ifier->g->vars, "$varname"); |
---|
81 | } else { |
---|
82 | owl_variable_set_bool_off(¬ifier->g->vars, "$varname"); |
---|
83 | } |
---|
84 | EOT |
---|
85 | } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) { |
---|
86 | print " owl_variable_set_string(¬ifier->g->vars, \"$varname\", g_value_get_string(value));\n"; |
---|
87 | } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) { |
---|
88 | print " owl_variable_set_int(¬ifier->g->vars, \"$varname\", g_value_get_int(value));\n"; |
---|
89 | } |
---|
90 | print " break;\n"; |
---|
91 | } |
---|
92 | |
---|
93 | print <<EOT; |
---|
94 | default: |
---|
95 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | static void owl_global_notifier_get_property(GObject *object, |
---|
100 | guint property_id, |
---|
101 | GValue *value, |
---|
102 | GParamSpec *pspec) |
---|
103 | { |
---|
104 | OwlGlobalNotifier *notifier = OWL_GLOBAL_NOTIFIER(object); |
---|
105 | |
---|
106 | switch (property_id) { |
---|
107 | /* normal properties */ |
---|
108 | case PROP_RIGHTSHIFT: |
---|
109 | g_value_set_int(value, owl_global_get_rightshift(notifier->g)); |
---|
110 | break; |
---|
111 | case PROP_CURMSG_VERT_OFFSET: |
---|
112 | g_value_set_int(value, owl_global_get_curmsg_vert_offset(notifier->g)); |
---|
113 | break; |
---|
114 | /* generated from variable listings */ |
---|
115 | EOT |
---|
116 | for my $var (@vars) { |
---|
117 | my $varname = $var->{name}; |
---|
118 | my $propname = $var->{propname}; |
---|
119 | print " case $propname:\n"; |
---|
120 | |
---|
121 | if ($var->{type} =~ /^BOOL/) { |
---|
122 | print " g_value_set_boolean(value, owl_variable_get_bool(¬ifier->g->vars, \"$varname\"));\n"; |
---|
123 | } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) { |
---|
124 | print " g_value_set_string(value, owl_variable_get_string(¬ifier->g->vars, \"$varname\"));\n"; |
---|
125 | } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) { |
---|
126 | print " g_value_set_int(value, owl_variable_get_int(¬ifier->g->vars, \"$varname\"));\n"; |
---|
127 | } |
---|
128 | print " break;\n"; |
---|
129 | } |
---|
130 | print <<EOT; |
---|
131 | default: |
---|
132 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | static void owl_global_notifier_class_init(OwlGlobalNotifierClass *klass) |
---|
137 | { |
---|
138 | GObjectClass *gobject_class = G_OBJECT_CLASS(klass); |
---|
139 | GParamSpec *pspec; |
---|
140 | |
---|
141 | gobject_class->get_property = owl_global_notifier_get_property; |
---|
142 | gobject_class->set_property = owl_global_notifier_set_property; |
---|
143 | |
---|
144 | /* Register properties */ |
---|
145 | |
---|
146 | pspec = g_param_spec_int("rightshift", |
---|
147 | "rightshift", |
---|
148 | "How much we shift to the right", |
---|
149 | 0, |
---|
150 | INT_MAX, |
---|
151 | 0, |
---|
152 | G_PARAM_READABLE|G_PARAM_WRITABLE |
---|
153 | |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); |
---|
154 | g_object_class_install_property(gobject_class, PROP_RIGHTSHIFT, pspec); |
---|
155 | |
---|
156 | EOT |
---|
157 | for my $var (@vars) { |
---|
158 | my $varname = $var->{name}; |
---|
159 | my $propname = $var->{propname}; |
---|
160 | my $detailname = $var->{detailname}; |
---|
161 | if ($var->{type} =~ /^BOOL/) { |
---|
162 | print <<EOT |
---|
163 | pspec = g_param_spec_boolean("$detailname", |
---|
164 | "$varname", |
---|
165 | "$varname", /* TODO: parse out the summary too */ |
---|
166 | FALSE, |
---|
167 | G_PARAM_READABLE|G_PARAM_WRITABLE |
---|
168 | |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); |
---|
169 | EOT |
---|
170 | } elsif ($var->{type} =~ /^PATH/ or $var->{type} =~ /^STRING/) { |
---|
171 | print <<EOT |
---|
172 | pspec = g_param_spec_string("$detailname", |
---|
173 | "$varname", |
---|
174 | "$varname", /* TODO: parse out the summary too */ |
---|
175 | "", |
---|
176 | G_PARAM_READABLE|G_PARAM_WRITABLE |
---|
177 | |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); |
---|
178 | EOT |
---|
179 | } elsif ($var->{type} =~ /^INT/ or $var->{type} =~ /^ENUM/) { |
---|
180 | print <<EOT |
---|
181 | pspec = g_param_spec_int("$detailname", |
---|
182 | "$varname", |
---|
183 | "$varname", /* TODO: parse out the summary too */ |
---|
184 | INT_MIN, |
---|
185 | INT_MAX, |
---|
186 | 0, |
---|
187 | G_PARAM_READABLE|G_PARAM_WRITABLE |
---|
188 | |G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB); |
---|
189 | EOT |
---|
190 | } |
---|
191 | print " g_object_class_install_property(gobject_class, $propname, pspec);\n\n"; |
---|
192 | } |
---|
193 | print <<EOT; |
---|
194 | } |
---|
195 | |
---|
196 | static void owl_global_notifier_init(OwlGlobalNotifier *self) |
---|
197 | { |
---|
198 | } |
---|
199 | |
---|
200 | OwlGlobalNotifier *owl_global_notifier_new(owl_global *g) |
---|
201 | { |
---|
202 | OwlGlobalNotifier *gn; |
---|
203 | |
---|
204 | gn = g_object_new(OWL_TYPE_GLOBAL_NOTIFIER, NULL); |
---|
205 | gn->g = g; |
---|
206 | return gn; |
---|
207 | } |
---|
208 | EOT |
---|