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