File: | libcafe-panel-applet/tmp-introspect47dmx06_/CafePanelApplet-4.0.c |
Warning: | line 239, column 11 This statement is never executed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* This file is generated, do not edit */ |
2 | |
3 | #undef GLIB_VERSION_MIN_REQUIRED((((2) << 16 | (78) << 8))) |
4 | #undef GLIB_VERSION_MAX_ALLOWED((((2) << 16 | (78) << 8))) |
5 | |
6 | #include <glib.h> |
7 | #include <string.h> |
8 | #include <stdlib.h> |
9 | |
10 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- |
11 | * GObject introspection: Dump introspection data |
12 | * |
13 | * Copyright (C) 2008 Colin Walters <walters@verbum.org> |
14 | * |
15 | * SPDX-License-Identifier: LGPL-2.1-or-later |
16 | * |
17 | * This library is free software; you can redistribute it and/or |
18 | * modify it under the terms of the GNU Lesser General Public |
19 | * License as published by the Free Software Foundation; either |
20 | * version 2 of the License, or (at your option) any later version. |
21 | * |
22 | * This library is distributed in the hope that it will be useful, |
23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
25 | * Lesser General Public License for more details. |
26 | * |
27 | * You should have received a copy of the GNU Lesser General Public |
28 | * License along with this library; if not, write to the |
29 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
30 | * Boston, MA 02111-1307, USA. |
31 | */ |
32 | |
33 | /* This file is both compiled into libgirepository.so, and installed |
34 | * on the filesystem. But for the dumper, we want to avoid linking |
35 | * to libgirepository; see |
36 | * https://bugzilla.gnome.org/show_bug.cgi?id=630342 |
37 | */ |
38 | #ifdef G_IREPOSITORY_COMPILATION |
39 | #include "config.h" |
40 | #include "girepository.h" |
41 | #endif |
42 | |
43 | #include <glib.h> |
44 | #include <glib-object.h> |
45 | #include <gmodule.h> |
46 | |
47 | #include <stdlib.h> |
48 | #include <stdio.h> |
49 | #include <string.h> |
50 | |
51 | /* Analogue of g_output_stream_write_all(). */ |
52 | static gboolean |
53 | write_all (FILE *out, |
54 | const void *buffer, |
55 | gsize count, |
56 | gsize *bytes_written, |
57 | GError **error) |
58 | { |
59 | size_t ret; |
60 | |
61 | ret = fwrite (buffer, 1, count, out); |
62 | |
63 | if (bytes_written != NULL((void*)0)) |
64 | *bytes_written = ret; |
65 | |
66 | if (ret < count) |
67 | { |
68 | g_set_error (error, G_FILE_ERRORg_file_error_quark (), G_FILE_ERROR_FAILED, |
69 | "Failed to write to file"); |
70 | return FALSE(0); |
71 | } |
72 | |
73 | return TRUE(!(0)); |
74 | } |
75 | |
76 | /* Analogue of g_data_input_stream_read_line(). */ |
77 | static char * |
78 | read_line (FILE *input, |
79 | size_t *len_out) |
80 | { |
81 | GByteArray *buffer = g_byte_array_new (); |
82 | const guint8 nul = '\0'; |
83 | |
84 | while (TRUE(!(0))) |
85 | { |
86 | size_t ret; |
87 | guint8 byte; |
88 | |
89 | ret = fread (&byte, 1, 1, input); |
90 | if (ret == 0) |
91 | break; |
92 | |
93 | if (byte == '\n') |
94 | break; |
95 | |
96 | g_byte_array_append (buffer, &byte, 1); |
97 | } |
98 | |
99 | g_byte_array_append (buffer, &nul, 1); |
100 | |
101 | if (len_out != NULL((void*)0)) |
102 | *len_out = buffer->len - 1; /* don’t include terminating nul */ |
103 | |
104 | return (char *) g_byte_array_free (buffer, FALSE(0)); |
105 | } |
106 | |
107 | static void |
108 | escaped_printf (FILE *out, const char *fmt, ...) G_GNUC_PRINTF (2, 3)__attribute__((__format__ (__printf__, 2, 3))); |
109 | |
110 | static void |
111 | escaped_printf (FILE *out, const char *fmt, ...) |
112 | { |
113 | char *str; |
114 | va_list args; |
115 | gsize written; |
116 | GError *error = NULL((void*)0); |
117 | |
118 | va_start (args, fmt)__builtin_va_start(args, fmt); |
119 | |
120 | str = g_markup_vprintf_escaped (fmt, args); |
121 | if (!write_all (out, str, strlen (str), &written, &error)) |
122 | { |
123 | g_critical ("failed to write to iochannel: %s", error->message); |
124 | g_clear_error (&error); |
125 | } |
126 | g_free (str); |
127 | |
128 | va_end (args)__builtin_va_end(args); |
129 | } |
130 | |
131 | static void |
132 | goutput_write (FILE *out, const char *str) |
133 | { |
134 | gsize written; |
135 | GError *error = NULL((void*)0); |
136 | if (!write_all (out, str, strlen (str), &written, &error)) |
137 | { |
138 | g_critical ("failed to write to iochannel: %s", error->message); |
139 | g_clear_error (&error); |
140 | } |
141 | } |
142 | |
143 | typedef GType (*GetTypeFunc)(void); |
144 | typedef GQuark (*ErrorQuarkFunc)(void); |
145 | |
146 | static GType |
147 | invoke_get_type (GModule *self, const char *symbol, GError **error) |
148 | { |
149 | GetTypeFunc sym; |
150 | GType ret; |
151 | |
152 | if (!g_module_symbol (self, symbol, (void**)&sym)) |
153 | { |
154 | g_set_error (error, |
155 | G_FILE_ERRORg_file_error_quark (), |
156 | G_FILE_ERROR_FAILED, |
157 | "Failed to find symbol '%s'", symbol); |
158 | return G_TYPE_INVALID((GType) ((0) << (2))); |
159 | } |
160 | |
161 | ret = sym (); |
162 | if (ret == G_TYPE_INVALID((GType) ((0) << (2)))) |
163 | { |
164 | g_set_error (error, |
165 | G_FILE_ERRORg_file_error_quark (), |
166 | G_FILE_ERROR_FAILED, |
167 | "Function '%s' returned G_TYPE_INVALID", symbol); |
168 | } |
169 | return ret; |
170 | } |
171 | |
172 | static GQuark |
173 | invoke_error_quark (GModule *self, const char *symbol, GError **error) |
174 | { |
175 | ErrorQuarkFunc sym; |
176 | |
177 | if (!g_module_symbol (self, symbol, (void**)&sym)) |
178 | { |
179 | g_set_error (error, |
180 | G_FILE_ERRORg_file_error_quark (), |
181 | G_FILE_ERROR_FAILED, |
182 | "Failed to find symbol '%s'", symbol); |
183 | return G_TYPE_INVALID((GType) ((0) << (2))); |
184 | } |
185 | |
186 | return sym (); |
187 | } |
188 | |
189 | static char * |
190 | value_transform_to_string (const GValue *value) |
191 | { |
192 | GValue tmp = G_VALUE_INIT{ 0, { { 0 } } }; |
193 | char *s = NULL((void*)0); |
194 | |
195 | g_value_init (&tmp, G_TYPE_STRING((GType) ((16) << (2)))); |
196 | |
197 | if (g_value_transform (value, &tmp)) |
198 | { |
199 | const char *str = g_value_get_string (&tmp); |
200 | |
201 | if (str != NULL((void*)0)) |
202 | s = g_strescape (str, NULL((void*)0)); |
203 | } |
204 | |
205 | g_value_unset (&tmp); |
206 | |
207 | return s; |
208 | } |
209 | |
210 | /* A simpler version of g_strdup_value_contents(), but with stable |
211 | * output and less complex semantics |
212 | */ |
213 | static char * |
214 | value_to_string (const GValue *value) |
215 | { |
216 | if (value == NULL((void*)0)) |
217 | return NULL((void*)0); |
218 | |
219 | if (G_VALUE_HOLDS_STRING (value)(((__extension__ ({ const GValue *__val = (const GValue*) ((value )); GType __t = (((GType) ((16) << (2)))); gboolean __r ; if (!__val) __r = (0); else if (__val->g_type == __t) __r = (!(0)); else __r = g_type_check_value_holds (__val, __t); __r ; }))))) |
220 | { |
221 | const char *s = g_value_get_string (value); |
222 | |
223 | if (s == NULL((void*)0)) |
224 | return g_strdup ("NULL")g_strdup_inline ("NULL"); |
225 | |
226 | return g_strescape (s, NULL((void*)0)); |
227 | } |
228 | else |
229 | { |
230 | GType value_type = G_VALUE_TYPE (value)(((GValue*) (value))->g_type); |
231 | |
232 | switch (G_TYPE_FUNDAMENTAL (value_type)(g_type_fundamental (value_type))) |
233 | { |
234 | case G_TYPE_BOXED((GType) ((18) << (2))): |
235 | if (g_value_get_boxed (value) == NULL((void*)0)) |
236 | return NULL((void*)0); |
237 | else |
238 | return value_transform_to_string (value); |
239 | break; |
This statement is never executed | |
240 | |
241 | case G_TYPE_OBJECT((GType) ((20) << (2))): |
242 | if (g_value_get_object (value) == NULL((void*)0)) |
243 | return NULL((void*)0); |
244 | else |
245 | return value_transform_to_string (value); |
246 | break; |
247 | |
248 | case G_TYPE_POINTER((GType) ((17) << (2))): |
249 | return NULL((void*)0); |
250 | |
251 | default: |
252 | return value_transform_to_string (value); |
253 | } |
254 | } |
255 | |
256 | return NULL((void*)0); |
257 | } |
258 | |
259 | static void |
260 | dump_properties (GType type, FILE *out) |
261 | { |
262 | guint i; |
263 | guint n_properties = 0; |
264 | GParamSpec **props; |
265 | |
266 | if (G_TYPE_FUNDAMENTAL (type)(g_type_fundamental (type)) == G_TYPE_OBJECT((GType) ((20) << (2)))) |
267 | { |
268 | GObjectClass *klass; |
269 | klass = g_type_class_ref (type); |
270 | props = g_object_class_list_properties (klass, &n_properties); |
271 | } |
272 | else |
273 | { |
274 | void *klass; |
275 | klass = g_type_default_interface_ref (type); |
276 | props = g_object_interface_list_properties (klass, &n_properties); |
277 | } |
278 | |
279 | for (i = 0; i < n_properties; i++) |
280 | { |
281 | GParamSpec *prop; |
282 | |
283 | prop = props[i]; |
284 | if (prop->owner_type != type) |
285 | continue; |
286 | |
287 | const GValue *v = g_param_spec_get_default_value (prop); |
288 | char *default_value = value_to_string (v); |
289 | |
290 | if (v != NULL((void*)0) && default_value != NULL((void*)0)) |
291 | { |
292 | escaped_printf (out, " <property name=\"%s\" type=\"%s\" flags=\"%d\" default-value=\"%s\"/>\n", |
293 | prop->name, |
294 | g_type_name (prop->value_type), |
295 | prop->flags, |
296 | default_value); |
297 | } |
298 | else |
299 | { |
300 | escaped_printf (out, " <property name=\"%s\" type=\"%s\" flags=\"%d\"/>\n", |
301 | prop->name, |
302 | g_type_name (prop->value_type), |
303 | prop->flags); |
304 | } |
305 | |
306 | g_free (default_value); |
307 | } |
308 | |
309 | g_free (props); |
310 | } |
311 | |
312 | static void |
313 | dump_signals (GType type, FILE *out) |
314 | { |
315 | guint i; |
316 | guint n_sigs; |
317 | guint *sig_ids; |
318 | |
319 | sig_ids = g_signal_list_ids (type, &n_sigs); |
320 | for (i = 0; i < n_sigs; i++) |
321 | { |
322 | guint sigid; |
323 | GSignalQuery query; |
324 | guint j; |
325 | |
326 | sigid = sig_ids[i]; |
327 | g_signal_query (sigid, &query); |
328 | |
329 | escaped_printf (out, " <signal name=\"%s\" return=\"%s\"", |
330 | query.signal_name, g_type_name (query.return_type)); |
331 | |
332 | if (query.signal_flags & G_SIGNAL_RUN_FIRST) |
333 | escaped_printf (out, " when=\"first\""); |
334 | else if (query.signal_flags & G_SIGNAL_RUN_LAST) |
335 | escaped_printf (out, " when=\"last\""); |
336 | else if (query.signal_flags & G_SIGNAL_RUN_CLEANUP) |
337 | escaped_printf (out, " when=\"cleanup\""); |
338 | else if (query.signal_flags & G_SIGNAL_MUST_COLLECT) |
339 | escaped_printf (out, " when=\"must-collect\""); |
340 | if (query.signal_flags & G_SIGNAL_NO_RECURSE) |
341 | escaped_printf (out, " no-recurse=\"1\""); |
342 | |
343 | if (query.signal_flags & G_SIGNAL_DETAILED) |
344 | escaped_printf (out, " detailed=\"1\""); |
345 | |
346 | if (query.signal_flags & G_SIGNAL_ACTION) |
347 | escaped_printf (out, " action=\"1\""); |
348 | |
349 | if (query.signal_flags & G_SIGNAL_NO_HOOKS) |
350 | escaped_printf (out, " no-hooks=\"1\""); |
351 | |
352 | goutput_write (out, ">\n"); |
353 | |
354 | for (j = 0; j < query.n_params; j++) |
355 | { |
356 | escaped_printf (out, " <param type=\"%s\"/>\n", |
357 | g_type_name (query.param_types[j])); |
358 | } |
359 | goutput_write (out, " </signal>\n"); |
360 | } |
361 | g_free (sig_ids); |
362 | } |
363 | |
364 | static void |
365 | dump_object_type (GType type, const char *symbol, FILE *out) |
366 | { |
367 | guint n_interfaces; |
368 | guint i; |
369 | GType *interfaces; |
370 | |
371 | escaped_printf (out, " <class name=\"%s\" get-type=\"%s\"", |
372 | g_type_name (type), symbol); |
373 | if (type != G_TYPE_OBJECT((GType) ((20) << (2)))) |
374 | { |
375 | GString *parent_str; |
376 | GType parent; |
377 | gboolean first = TRUE(!(0)); |
378 | |
379 | parent = g_type_parent (type); |
380 | parent_str = g_string_new (""); |
381 | while (parent != G_TYPE_INVALID((GType) ((0) << (2)))) |
382 | { |
383 | if (first) |
384 | first = FALSE(0); |
385 | else |
386 | g_string_append_c (parent_str, ',')g_string_append_c_inline (parent_str, ','); |
387 | g_string_append (parent_str, g_type_name (parent))(__builtin_constant_p (g_type_name (parent)) ? __extension__ ( { const char * const __val = (g_type_name (parent)); g_string_append_len_inline (parent_str, __val, (__val != ((void*)0)) ? (gssize) strlen ( ((__val) + !(__val))) : (gssize) -1); }) : g_string_append_len_inline (parent_str, g_type_name (parent), (gssize) -1)); |
388 | parent = g_type_parent (parent); |
389 | } |
390 | |
391 | escaped_printf (out, " parents=\"%s\"", parent_str->str); |
392 | |
393 | g_string_free (parent_str, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) ( (parent_str), ((!(0)))) : g_string_free_and_steal (parent_str )) : (g_string_free) ((parent_str), ((!(0))))); |
394 | } |
395 | |
396 | if (G_TYPE_IS_ABSTRACT (type)(g_type_test_flags ((type), G_TYPE_FLAG_ABSTRACT))) |
397 | escaped_printf (out, " abstract=\"1\""); |
398 | |
399 | if (G_TYPE_IS_FINAL (type)(g_type_test_flags ((type), G_TYPE_FLAG_FINAL))) |
400 | escaped_printf (out, " final=\"1\""); |
401 | |
402 | goutput_write (out, ">\n"); |
403 | |
404 | interfaces = g_type_interfaces (type, &n_interfaces); |
405 | for (i = 0; i < n_interfaces; i++) |
406 | { |
407 | GType itype = interfaces[i]; |
408 | escaped_printf (out, " <implements name=\"%s\"/>\n", |
409 | g_type_name (itype)); |
410 | } |
411 | g_free (interfaces); |
412 | |
413 | dump_properties (type, out); |
414 | dump_signals (type, out); |
415 | goutput_write (out, " </class>\n"); |
416 | } |
417 | |
418 | static void |
419 | dump_interface_type (GType type, const char *symbol, FILE *out) |
420 | { |
421 | guint n_interfaces; |
422 | guint i; |
423 | GType *interfaces; |
424 | |
425 | escaped_printf (out, " <interface name=\"%s\" get-type=\"%s\">\n", |
426 | g_type_name (type), symbol); |
427 | |
428 | interfaces = g_type_interface_prerequisites (type, &n_interfaces); |
429 | for (i = 0; i < n_interfaces; i++) |
430 | { |
431 | GType itype = interfaces[i]; |
432 | if (itype == G_TYPE_OBJECT((GType) ((20) << (2)))) |
433 | { |
434 | /* Treat this as implicit for now; in theory GInterfaces are |
435 | * supported on things like GstMiniObject, but right now |
436 | * the introspection system only supports GObject. |
437 | * http://bugzilla.gnome.org/show_bug.cgi?id=559706 |
438 | */ |
439 | continue; |
440 | } |
441 | escaped_printf (out, " <prerequisite name=\"%s\"/>\n", |
442 | g_type_name (itype)); |
443 | } |
444 | g_free (interfaces); |
445 | |
446 | dump_properties (type, out); |
447 | dump_signals (type, out); |
448 | goutput_write (out, " </interface>\n"); |
449 | } |
450 | |
451 | static void |
452 | dump_boxed_type (GType type, const char *symbol, FILE *out) |
453 | { |
454 | escaped_printf (out, " <boxed name=\"%s\" get-type=\"%s\"/>\n", |
455 | g_type_name (type), symbol); |
456 | } |
457 | |
458 | static void |
459 | dump_flags_type (GType type, const char *symbol, FILE *out) |
460 | { |
461 | guint i; |
462 | GFlagsClass *klass; |
463 | |
464 | klass = g_type_class_ref (type); |
465 | escaped_printf (out, " <flags name=\"%s\" get-type=\"%s\">\n", |
466 | g_type_name (type), symbol); |
467 | |
468 | for (i = 0; i < klass->n_values; i++) |
469 | { |
470 | GFlagsValue *value = &(klass->values[i]); |
471 | |
472 | escaped_printf (out, " <member name=\"%s\" nick=\"%s\" value=\"%u\"/>\n", |
473 | value->value_name, value->value_nick, value->value); |
474 | } |
475 | goutput_write (out, " </flags>\n"); |
476 | } |
477 | |
478 | static void |
479 | dump_enum_type (GType type, const char *symbol, FILE *out) |
480 | { |
481 | guint i; |
482 | GEnumClass *klass; |
483 | |
484 | klass = g_type_class_ref (type); |
485 | escaped_printf (out, " <enum name=\"%s\" get-type=\"%s\">\n", |
486 | g_type_name (type), symbol); |
487 | |
488 | for (i = 0; i < klass->n_values; i++) |
489 | { |
490 | GEnumValue *value = &(klass->values[i]); |
491 | |
492 | escaped_printf (out, " <member name=\"%s\" nick=\"%s\" value=\"%d\"/>\n", |
493 | value->value_name, value->value_nick, value->value); |
494 | } |
495 | goutput_write (out, " </enum>"); |
496 | } |
497 | |
498 | static void |
499 | dump_fundamental_type (GType type, const char *symbol, FILE *out) |
500 | { |
501 | guint n_interfaces; |
502 | guint i; |
503 | GType *interfaces; |
504 | GString *parent_str; |
505 | GType parent; |
506 | gboolean first = TRUE(!(0)); |
507 | |
508 | |
509 | escaped_printf (out, " <fundamental name=\"%s\" get-type=\"%s\"", |
510 | g_type_name (type), symbol); |
511 | |
512 | if (G_TYPE_IS_ABSTRACT (type)(g_type_test_flags ((type), G_TYPE_FLAG_ABSTRACT))) |
513 | escaped_printf (out, " abstract=\"1\""); |
514 | |
515 | if (G_TYPE_IS_FINAL (type)(g_type_test_flags ((type), G_TYPE_FLAG_FINAL))) |
516 | escaped_printf (out, " final=\"1\""); |
517 | |
518 | if (G_TYPE_IS_INSTANTIATABLE (type)(g_type_test_flags ((type), G_TYPE_FLAG_INSTANTIATABLE))) |
519 | escaped_printf (out, " instantiatable=\"1\""); |
520 | |
521 | parent = g_type_parent (type); |
522 | parent_str = g_string_new (""); |
523 | while (parent != G_TYPE_INVALID((GType) ((0) << (2)))) |
524 | { |
525 | if (first) |
526 | first = FALSE(0); |
527 | else |
528 | g_string_append_c (parent_str, ',')g_string_append_c_inline (parent_str, ','); |
529 | if (!g_type_name (parent)) |
530 | break; |
531 | g_string_append (parent_str, g_type_name (parent))(__builtin_constant_p (g_type_name (parent)) ? __extension__ ( { const char * const __val = (g_type_name (parent)); g_string_append_len_inline (parent_str, __val, (__val != ((void*)0)) ? (gssize) strlen ( ((__val) + !(__val))) : (gssize) -1); }) : g_string_append_len_inline (parent_str, g_type_name (parent), (gssize) -1)); |
532 | parent = g_type_parent (parent); |
533 | } |
534 | |
535 | if (parent_str->len > 0) |
536 | escaped_printf (out, " parents=\"%s\"", parent_str->str); |
537 | g_string_free (parent_str, TRUE)(__builtin_constant_p ((!(0))) ? (((!(0))) ? (g_string_free) ( (parent_str), ((!(0)))) : g_string_free_and_steal (parent_str )) : (g_string_free) ((parent_str), ((!(0))))); |
538 | |
539 | goutput_write (out, ">\n"); |
540 | |
541 | interfaces = g_type_interfaces (type, &n_interfaces); |
542 | for (i = 0; i < n_interfaces; i++) |
543 | { |
544 | GType itype = interfaces[i]; |
545 | escaped_printf (out, " <implements name=\"%s\"/>\n", |
546 | g_type_name (itype)); |
547 | } |
548 | g_free (interfaces); |
549 | goutput_write (out, " </fundamental>\n"); |
550 | } |
551 | |
552 | static void |
553 | dump_type (GType type, const char *symbol, FILE *out) |
554 | { |
555 | /* XXX: We need to ensure that global ancillary structures like |
556 | * GParamSpecPool are initialized before we use the GType and |
557 | * GObject reflection API to poke at things like properties and |
558 | * signals; we cannot rely on GObject being instantiated at this |
559 | * point. |
560 | */ |
561 | GObjectClass *gobject_class = g_type_class_ref (G_TYPE_OBJECT((GType) ((20) << (2)))); |
562 | |
563 | switch (g_type_fundamental (type)) |
564 | { |
565 | case G_TYPE_OBJECT((GType) ((20) << (2))): |
566 | dump_object_type (type, symbol, out); |
567 | break; |
568 | case G_TYPE_INTERFACE((GType) ((2) << (2))): |
569 | dump_interface_type (type, symbol, out); |
570 | break; |
571 | case G_TYPE_BOXED((GType) ((18) << (2))): |
572 | dump_boxed_type (type, symbol, out); |
573 | break; |
574 | case G_TYPE_FLAGS((GType) ((13) << (2))): |
575 | dump_flags_type (type, symbol, out); |
576 | break; |
577 | case G_TYPE_ENUM((GType) ((12) << (2))): |
578 | dump_enum_type (type, symbol, out); |
579 | break; |
580 | case G_TYPE_POINTER((GType) ((17) << (2))): |
581 | /* GValue, etc. Just skip them. */ |
582 | break; |
583 | default: |
584 | dump_fundamental_type (type, symbol, out); |
585 | break; |
586 | } |
587 | |
588 | g_type_class_unref ((GTypeClass *) gobject_class); |
589 | } |
590 | |
591 | static void |
592 | dump_error_quark (GQuark quark, const char *symbol, FILE *out) |
593 | { |
594 | escaped_printf (out, " <error-quark function=\"%s\" domain=\"%s\"/>\n", |
595 | symbol, g_quark_to_string (quark)); |
596 | } |
597 | |
598 | /** |
599 | * g_irepository_dump: |
600 | * @input_filename: (type filename): Input filename (for example `input.txt`) |
601 | * @output_filename: (type filename): Output filename (for example `output.xml`) |
602 | * @error: a %GError |
603 | * |
604 | * Dump the introspection data from the types specified in @input_filename to |
605 | * @output_filename. |
606 | * |
607 | * The input file should be a |
608 | * UTF-8 Unix-line-ending text file, with each line containing either |
609 | * `get-type:` followed by the name of a [type@GObject.Type] `_get_type` |
610 | * function, or `error-quark:` followed by the name of an error quark function. |
611 | * No extra whitespace is allowed. |
612 | * |
613 | * This function will overwrite the contents of the output file. |
614 | * |
615 | * Returns: true on success, false on error |
616 | * Since: 2.80 |
617 | */ |
618 | #ifndef G_IREPOSITORY_COMPILATION |
619 | static gboolean |
620 | dump_irepository (const char *arg, |
621 | GError **error) G_GNUC_UNUSED__attribute__ ((__unused__)); |
622 | static gboolean |
623 | dump_irepository (const char *arg, |
624 | GError **error) |
625 | #else |
626 | gboolean |
627 | g_irepository_dump (const char *arg, |
628 | GError **error) |
629 | #endif |
630 | { |
631 | GHashTable *output_types; |
632 | FILE *input; |
633 | FILE *output; |
634 | GModule *self; |
635 | gboolean caught_error = FALSE(0); |
636 | |
637 | char **args = g_strsplit (arg, ",", 2); |
638 | if (args == NULL((void*)0)) |
639 | return FALSE(0); |
640 | |
641 | const char *input_filename = args[0]; |
642 | const char *output_filename = args[1]; |
643 | |
644 | self = g_module_open (NULL((void*)0), 0); |
645 | if (!self) |
646 | { |
647 | g_set_error (error, |
648 | G_FILE_ERRORg_file_error_quark (), |
649 | G_FILE_ERROR_FAILED, |
650 | "failed to open self: %s", |
651 | g_module_error ()); |
652 | g_strfreev (args); |
653 | return FALSE(0); |
654 | } |
655 | |
656 | input = fopen (input_filename, "rb"); |
657 | if (input == NULL((void*)0)) |
658 | { |
659 | int saved_errno = errno(*__errno_location ()); |
660 | g_set_error (error, G_FILE_ERRORg_file_error_quark (), g_file_error_from_errno (saved_errno), |
661 | "Failed to open ‘%s’: %s", input_filename, g_strerror (saved_errno)); |
662 | |
663 | g_module_close (self); |
664 | g_strfreev (args); |
665 | |
666 | return FALSE(0); |
667 | } |
668 | |
669 | output = fopen (output_filename, "wb"); |
670 | if (output == NULL((void*)0)) |
671 | { |
672 | int saved_errno = errno(*__errno_location ()); |
673 | g_set_error (error, G_FILE_ERRORg_file_error_quark (), g_file_error_from_errno (saved_errno), |
674 | "Failed to open ‘%s’: %s", output_filename, g_strerror (saved_errno)); |
675 | |
676 | fclose (input); |
677 | g_module_close (self); |
678 | g_strfreev (args); |
679 | |
680 | return FALSE(0); |
681 | } |
682 | |
683 | goutput_write (output, "<?xml version=\"1.0\"?>\n"); |
684 | goutput_write (output, "<dump>\n"); |
685 | |
686 | output_types = g_hash_table_new (NULL((void*)0), NULL((void*)0)); |
687 | |
688 | while (TRUE(!(0))) |
689 | { |
690 | gsize len; |
691 | char *line = read_line (input, &len); |
692 | const char *function; |
693 | |
694 | if (line == NULL((void*)0) || *line == '\0') |
695 | { |
696 | g_free (line); |
697 | break; |
698 | } |
699 | |
700 | g_strchomp (line); |
701 | |
702 | if (strncmp (line, "get-type:", strlen ("get-type:")) == 0) |
703 | { |
704 | GType type; |
705 | |
706 | function = line + strlen ("get-type:"); |
707 | |
708 | type = invoke_get_type (self, function, error); |
709 | |
710 | if (type == G_TYPE_INVALID((GType) ((0) << (2)))) |
711 | { |
712 | g_printerr ("Invalid GType function: '%s'\n", function); |
713 | caught_error = TRUE(!(0)); |
714 | g_free (line); |
715 | break; |
716 | } |
717 | |
718 | if (g_hash_table_lookup (output_types, (gpointer) type)) |
719 | goto next; |
720 | g_hash_table_insert (output_types, (gpointer) type, (gpointer) type); |
721 | |
722 | dump_type (type, function, output); |
723 | } |
724 | else if (strncmp (line, "error-quark:", strlen ("error-quark:")) == 0) |
725 | { |
726 | GQuark quark; |
727 | function = line + strlen ("error-quark:"); |
728 | quark = invoke_error_quark (self, function, error); |
729 | |
730 | if (quark == 0) |
731 | { |
732 | g_printerr ("Invalid error quark function: '%s'\n", function); |
733 | caught_error = TRUE(!(0)); |
734 | g_free (line); |
735 | break; |
736 | } |
737 | |
738 | dump_error_quark (quark, function, output); |
739 | } |
740 | |
741 | |
742 | next: |
743 | g_free (line); |
744 | } |
745 | |
746 | g_hash_table_destroy (output_types); |
747 | |
748 | goutput_write (output, "</dump>\n"); |
749 | |
750 | { |
751 | /* Avoid overwriting an earlier set error */ |
752 | if (fclose (input) != 0 && !caught_error) |
753 | { |
754 | int saved_errno = errno(*__errno_location ()); |
755 | |
756 | g_set_error (error, G_FILE_ERRORg_file_error_quark (), g_file_error_from_errno (saved_errno), |
757 | "Error closing input file ‘%s’: %s", input_filename, |
758 | g_strerror (saved_errno)); |
759 | caught_error = TRUE(!(0)); |
760 | } |
761 | |
762 | if (fclose (output) != 0 && !caught_error) |
763 | { |
764 | int saved_errno = errno(*__errno_location ()); |
765 | |
766 | g_set_error (error, G_FILE_ERRORg_file_error_quark (), g_file_error_from_errno (saved_errno), |
767 | "Error closing output file ‘%s’: %s", output_filename, |
768 | g_strerror (saved_errno)); |
769 | caught_error = TRUE(!(0)); |
770 | } |
771 | } |
772 | |
773 | g_strfreev (args); |
774 | |
775 | return !caught_error; |
776 | } |
777 | |
778 | |
779 | int |
780 | main(int argc, char **argv) |
781 | { |
782 | GError *error = NULL((void*)0); |
783 | const char *introspect_dump_prefix = "--introspect-dump="; |
784 | |
785 | #if !GLIB_CHECK_VERSION(2,35,0)(2 > (2) || (2 == (2) && 78 > (35)) || (2 == (2 ) && 78 == (35) && 3 >= (0))) |
786 | g_type_init (); |
787 | #endif |
788 | |
789 | |
790 | |
791 | if (argc != 2 || !g_str_has_prefix (argv[1], introspect_dump_prefix)(__builtin_constant_p (introspect_dump_prefix)? __extension__ ({ const char * const __str = (argv[1]); const char * const __prefix = (introspect_dump_prefix); gboolean __result = (0); if (__str == ((void*)0) || __prefix == ((void*)0)) __result = (g_str_has_prefix ) (__str, __prefix); else { const size_t __str_len = strlen ( ((__str) + !(__str))); const size_t __prefix_len = strlen ((( __prefix) + !(__prefix))); if (__str_len >= __prefix_len) __result = memcmp (((__str) + !(__str)), ((__prefix) + !(__prefix)), __prefix_len ) == 0; } __result; }) : (g_str_has_prefix) (argv[1], introspect_dump_prefix ) )) |
792 | { |
793 | g_printerr ("Usage: %s --introspect-dump=input,output", argv[0]); |
794 | exit (1); |
795 | } |
796 | |
797 | if (!dump_irepository (argv[1] + strlen(introspect_dump_prefix), &error)) |
798 | { |
799 | g_printerr ("%s\n", error->message); |
800 | exit (1); |
801 | } |
802 | exit (0); |
803 | } |
804 | extern GType cafe_panel_applet_get_type(void); |
805 | extern GType cafe_panel_applet_orient_get_type(void); |
806 | extern GType cafe_panel_applet_background_type_get_type(void); |
807 | extern GType cafe_panel_applet_flags_get_type(void); |
808 | G_MODULE_EXPORT__attribute__((visibility("default"))) GType (*GI_GET_TYPE_FUNCS_[])(void) = { |
809 | cafe_panel_applet_get_type, |
810 | cafe_panel_applet_orient_get_type, |
811 | cafe_panel_applet_background_type_get_type, |
812 | cafe_panel_applet_flags_get_type |
813 | }; |