File: | cdk/tmp-introspecty8k2o5io/Cdk-3.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 | (82) << 8))) |
4 | #undef GLIB_VERSION_MAX_ALLOWED((((2) << 16 | (82) << 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_pointer_type (GType type, const char *symbol, FILE *out) |
460 | { |
461 | escaped_printf (out, " <pointer name=\"%s\" get-type=\"%s\"/>\n", |
462 | g_type_name (type), symbol); |
463 | } |
464 | |
465 | static void |
466 | dump_flags_type (GType type, const char *symbol, FILE *out) |
467 | { |
468 | guint i; |
469 | GFlagsClass *klass; |
470 | |
471 | klass = g_type_class_ref (type); |
472 | escaped_printf (out, " <flags name=\"%s\" get-type=\"%s\">\n", |
473 | g_type_name (type), symbol); |
474 | |
475 | for (i = 0; i < klass->n_values; i++) |
476 | { |
477 | GFlagsValue *value = &(klass->values[i]); |
478 | |
479 | escaped_printf (out, " <member name=\"%s\" nick=\"%s\" value=\"%u\"/>\n", |
480 | value->value_name, value->value_nick, value->value); |
481 | } |
482 | goutput_write (out, " </flags>\n"); |
483 | } |
484 | |
485 | static void |
486 | dump_enum_type (GType type, const char *symbol, FILE *out) |
487 | { |
488 | guint i; |
489 | GEnumClass *klass; |
490 | |
491 | klass = g_type_class_ref (type); |
492 | escaped_printf (out, " <enum name=\"%s\" get-type=\"%s\">\n", |
493 | g_type_name (type), symbol); |
494 | |
495 | for (i = 0; i < klass->n_values; i++) |
496 | { |
497 | GEnumValue *value = &(klass->values[i]); |
498 | |
499 | escaped_printf (out, " <member name=\"%s\" nick=\"%s\" value=\"%d\"/>\n", |
500 | value->value_name, value->value_nick, value->value); |
501 | } |
502 | goutput_write (out, " </enum>"); |
503 | } |
504 | |
505 | static void |
506 | dump_fundamental_type (GType type, const char *symbol, FILE *out) |
507 | { |
508 | guint n_interfaces; |
509 | guint i; |
510 | GType *interfaces; |
511 | GString *parent_str; |
512 | GType parent; |
513 | gboolean first = TRUE(!(0)); |
514 | |
515 | |
516 | escaped_printf (out, " <fundamental name=\"%s\" get-type=\"%s\"", |
517 | g_type_name (type), symbol); |
518 | |
519 | if (G_TYPE_IS_ABSTRACT (type)(g_type_test_flags ((type), G_TYPE_FLAG_ABSTRACT))) |
520 | escaped_printf (out, " abstract=\"1\""); |
521 | |
522 | if (G_TYPE_IS_FINAL (type)(g_type_test_flags ((type), G_TYPE_FLAG_FINAL))) |
523 | escaped_printf (out, " final=\"1\""); |
524 | |
525 | if (G_TYPE_IS_INSTANTIATABLE (type)(g_type_test_flags ((type), G_TYPE_FLAG_INSTANTIATABLE))) |
526 | escaped_printf (out, " instantiatable=\"1\""); |
527 | |
528 | parent = g_type_parent (type); |
529 | parent_str = g_string_new (""); |
530 | while (parent != G_TYPE_INVALID((GType) ((0) << (2)))) |
531 | { |
532 | if (first) |
533 | first = FALSE(0); |
534 | else |
535 | g_string_append_c (parent_str, ',')g_string_append_c_inline (parent_str, ','); |
536 | if (!g_type_name (parent)) |
537 | break; |
538 | 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)); |
539 | parent = g_type_parent (parent); |
540 | } |
541 | |
542 | if (parent_str->len > 0) |
543 | escaped_printf (out, " parents=\"%s\"", parent_str->str); |
544 | 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))))); |
545 | |
546 | goutput_write (out, ">\n"); |
547 | |
548 | interfaces = g_type_interfaces (type, &n_interfaces); |
549 | for (i = 0; i < n_interfaces; i++) |
550 | { |
551 | GType itype = interfaces[i]; |
552 | escaped_printf (out, " <implements name=\"%s\"/>\n", |
553 | g_type_name (itype)); |
554 | } |
555 | g_free (interfaces); |
556 | goutput_write (out, " </fundamental>\n"); |
557 | } |
558 | |
559 | static void |
560 | dump_type (GType type, const char *symbol, FILE *out) |
561 | { |
562 | /* XXX: We need to ensure that global ancillary structures like |
563 | * GParamSpecPool are initialized before we use the GType and |
564 | * GObject reflection API to poke at things like properties and |
565 | * signals; we cannot rely on GObject being instantiated at this |
566 | * point. |
567 | */ |
568 | GObjectClass *gobject_class = g_type_class_ref (G_TYPE_OBJECT((GType) ((20) << (2)))); |
569 | |
570 | switch (g_type_fundamental (type)) |
571 | { |
572 | case G_TYPE_OBJECT((GType) ((20) << (2))): |
573 | dump_object_type (type, symbol, out); |
574 | break; |
575 | case G_TYPE_INTERFACE((GType) ((2) << (2))): |
576 | dump_interface_type (type, symbol, out); |
577 | break; |
578 | case G_TYPE_BOXED((GType) ((18) << (2))): |
579 | dump_boxed_type (type, symbol, out); |
580 | break; |
581 | case G_TYPE_FLAGS((GType) ((13) << (2))): |
582 | dump_flags_type (type, symbol, out); |
583 | break; |
584 | case G_TYPE_ENUM((GType) ((12) << (2))): |
585 | dump_enum_type (type, symbol, out); |
586 | break; |
587 | case G_TYPE_POINTER((GType) ((17) << (2))): |
588 | dump_pointer_type (type, symbol, out); |
589 | break; |
590 | default: |
591 | dump_fundamental_type (type, symbol, out); |
592 | break; |
593 | } |
594 | |
595 | g_type_class_unref ((GTypeClass *) gobject_class); |
596 | } |
597 | |
598 | static void |
599 | dump_error_quark (GQuark quark, const char *symbol, FILE *out) |
600 | { |
601 | escaped_printf (out, " <error-quark function=\"%s\" domain=\"%s\"/>\n", |
602 | symbol, g_quark_to_string (quark)); |
603 | } |
604 | |
605 | /** |
606 | * g_irepository_dump: |
607 | * @input_filename: (type filename): Input filename (for example `input.txt`) |
608 | * @output_filename: (type filename): Output filename (for example `output.xml`) |
609 | * @error: a %GError |
610 | * |
611 | * Dump the introspection data from the types specified in @input_filename to |
612 | * @output_filename. |
613 | * |
614 | * The input file should be a |
615 | * UTF-8 Unix-line-ending text file, with each line containing either |
616 | * `get-type:` followed by the name of a [type@GObject.Type] `_get_type` |
617 | * function, or `error-quark:` followed by the name of an error quark function. |
618 | * No extra whitespace is allowed. |
619 | * |
620 | * This function will overwrite the contents of the output file. |
621 | * |
622 | * Returns: true on success, false on error |
623 | * Since: 2.80 |
624 | */ |
625 | #ifndef G_IREPOSITORY_COMPILATION |
626 | static gboolean |
627 | dump_irepository (const char *arg, |
628 | GError **error) G_GNUC_UNUSED__attribute__ ((__unused__)); |
629 | static gboolean |
630 | dump_irepository (const char *arg, |
631 | GError **error) |
632 | #else |
633 | gboolean |
634 | g_irepository_dump (const char *arg, |
635 | GError **error) |
636 | #endif |
637 | { |
638 | GHashTable *output_types; |
639 | FILE *input; |
640 | FILE *output; |
641 | GModule *self; |
642 | gboolean caught_error = FALSE(0); |
643 | |
644 | char **args = g_strsplit (arg, ",", 2); |
645 | if (args == NULL((void*)0)) |
646 | { |
647 | g_set_error (error, |
648 | G_FILE_ERRORg_file_error_quark (), |
649 | G_FILE_ERROR_FAILED, |
650 | "Usage: --introspect-dump=input,output"); |
651 | return FALSE(0); |
652 | } |
653 | |
654 | const char *input_filename = args[0]; |
655 | const char *output_filename = args[1]; |
656 | |
657 | self = g_module_open (NULL((void*)0), 0); |
658 | if (!self) |
659 | { |
660 | g_set_error (error, |
661 | G_FILE_ERRORg_file_error_quark (), |
662 | G_FILE_ERROR_FAILED, |
663 | "failed to open self: %s", |
664 | g_module_error ()); |
665 | g_strfreev (args); |
666 | return FALSE(0); |
667 | } |
668 | |
669 | input = fopen (input_filename, "rb"); |
670 | if (input == 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", input_filename, g_strerror (saved_errno)); |
675 | |
676 | g_module_close (self); |
677 | g_strfreev (args); |
678 | |
679 | return FALSE(0); |
680 | } |
681 | |
682 | output = fopen (output_filename, "wb"); |
683 | if (output == NULL((void*)0)) |
684 | { |
685 | int saved_errno = errno(*__errno_location ()); |
686 | g_set_error (error, G_FILE_ERRORg_file_error_quark (), g_file_error_from_errno (saved_errno), |
687 | "Failed to open ‘%s’: %s", output_filename, g_strerror (saved_errno)); |
688 | |
689 | fclose (input); |
690 | g_module_close (self); |
691 | g_strfreev (args); |
692 | |
693 | return FALSE(0); |
694 | } |
695 | |
696 | goutput_write (output, "<?xml version=\"1.0\"?>\n"); |
697 | goutput_write (output, "<dump>\n"); |
698 | |
699 | output_types = g_hash_table_new (NULL((void*)0), NULL((void*)0)); |
700 | |
701 | while (TRUE(!(0))) |
702 | { |
703 | gsize len; |
704 | char *line = read_line (input, &len); |
705 | const char *function; |
706 | |
707 | if (line == NULL((void*)0) || *line == '\0') |
708 | { |
709 | g_free (line); |
710 | break; |
711 | } |
712 | |
713 | g_strchomp (line); |
714 | |
715 | if (strncmp (line, "get-type:", strlen ("get-type:")) == 0) |
716 | { |
717 | GType type; |
718 | |
719 | function = line + strlen ("get-type:"); |
720 | |
721 | type = invoke_get_type (self, function, error); |
722 | |
723 | if (type == G_TYPE_INVALID((GType) ((0) << (2)))) |
724 | { |
725 | g_printerr ("Invalid GType function: '%s'\n", function); |
726 | caught_error = TRUE(!(0)); |
727 | g_free (line); |
728 | break; |
729 | } |
730 | |
731 | if (g_hash_table_lookup (output_types, (gpointer) type)) |
732 | goto next; |
733 | g_hash_table_insert (output_types, (gpointer) type, (gpointer) type); |
734 | |
735 | dump_type (type, function, output); |
736 | } |
737 | else if (strncmp (line, "error-quark:", strlen ("error-quark:")) == 0) |
738 | { |
739 | GQuark quark; |
740 | function = line + strlen ("error-quark:"); |
741 | quark = invoke_error_quark (self, function, error); |
742 | |
743 | if (quark == 0) |
744 | { |
745 | g_printerr ("Invalid error quark function: '%s'\n", function); |
746 | caught_error = TRUE(!(0)); |
747 | g_free (line); |
748 | break; |
749 | } |
750 | |
751 | dump_error_quark (quark, function, output); |
752 | } |
753 | |
754 | |
755 | next: |
756 | g_free (line); |
757 | } |
758 | |
759 | g_hash_table_destroy (output_types); |
760 | |
761 | goutput_write (output, "</dump>\n"); |
762 | |
763 | { |
764 | /* Avoid overwriting an earlier set error */ |
765 | if (fclose (input) != 0 && !caught_error) |
766 | { |
767 | int saved_errno = errno(*__errno_location ()); |
768 | |
769 | g_set_error (error, G_FILE_ERRORg_file_error_quark (), g_file_error_from_errno (saved_errno), |
770 | "Error closing input file ‘%s’: %s", input_filename, |
771 | g_strerror (saved_errno)); |
772 | caught_error = TRUE(!(0)); |
773 | } |
774 | |
775 | if (fclose (output) != 0 && !caught_error) |
776 | { |
777 | int saved_errno = errno(*__errno_location ()); |
778 | |
779 | g_set_error (error, G_FILE_ERRORg_file_error_quark (), g_file_error_from_errno (saved_errno), |
780 | "Error closing output file ‘%s’: %s", output_filename, |
781 | g_strerror (saved_errno)); |
782 | caught_error = TRUE(!(0)); |
783 | } |
784 | } |
785 | |
786 | g_strfreev (args); |
787 | |
788 | return !caught_error; |
789 | } |
790 | |
791 | |
792 | int |
793 | main(int argc, char **argv) |
794 | { |
795 | GError *error = NULL((void*)0); |
796 | const char *introspect_dump_prefix = "--introspect-dump="; |
797 | |
798 | #if !GLIB_CHECK_VERSION(2,35,0)(2 > (2) || (2 == (2) && 82 > (35)) || (2 == (2 ) && 82 == (35) && 4 >= (0))) |
799 | g_type_init (); |
800 | #endif |
801 | |
802 | |
803 | |
804 | 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 ) )) |
805 | { |
806 | g_printerr ("Usage: %s --introspect-dump=input,output", argv[0]); |
807 | exit (1); |
808 | } |
809 | |
810 | if (!dump_irepository (argv[1] + strlen(introspect_dump_prefix), &error)) |
811 | { |
812 | g_printerr ("%s\n", error->message); |
813 | exit (1); |
814 | } |
815 | exit (0); |
816 | } |
817 | extern GType cdk_device_get_type(void); |
818 | extern GType cdk_drag_context_get_type(void); |
819 | extern GType cdk_device_tool_get_type(void); |
820 | extern GType cdk_event_get_type(void); |
821 | extern GType cdk_event_sequence_get_type(void); |
822 | extern GType cdk_device_manager_get_type(void); |
823 | extern GType cdk_drawing_context_get_type(void); |
824 | extern GType cdk_frame_timings_get_type(void); |
825 | extern GType cdk_frame_clock_get_type(void); |
826 | extern GType cdk_window_get_type(void); |
827 | extern GType cdk_seat_get_type(void); |
828 | extern GType cdk_rectangle_get_type(void); |
829 | extern GType cdk_monitor_get_type(void); |
830 | extern GType cdk_display_get_type(void); |
831 | extern GType cdk_screen_get_type(void); |
832 | extern GType cdk_app_launch_context_get_type(void); |
833 | extern GType cdk_color_get_type(void); |
834 | extern GType cdk_rgba_get_type(void); |
835 | extern GType cdk_cursor_get_type(void); |
836 | extern GType cdk_device_pad_get_type(void); |
837 | extern GType cdk_display_manager_get_type(void); |
838 | extern GType cdk_cursor_type_get_type(void); |
839 | extern GType cdk_input_source_get_type(void); |
840 | extern GType cdk_input_mode_get_type(void); |
841 | extern GType cdk_device_type_get_type(void); |
842 | extern GType cdk_device_pad_feature_get_type(void); |
843 | extern GType cdk_device_tool_type_get_type(void); |
844 | extern GType cdk_drag_action_get_type(void); |
845 | extern GType cdk_drag_cancel_reason_get_type(void); |
846 | extern GType cdk_drag_protocol_get_type(void); |
847 | extern GType cdk_filter_return_get_type(void); |
848 | extern GType cdk_event_type_get_type(void); |
849 | extern GType cdk_visibility_state_get_type(void); |
850 | extern GType cdk_touchpad_gesture_phase_get_type(void); |
851 | extern GType cdk_scroll_direction_get_type(void); |
852 | extern GType cdk_notify_type_get_type(void); |
853 | extern GType cdk_crossing_mode_get_type(void); |
854 | extern GType cdk_property_state_get_type(void); |
855 | extern GType cdk_window_state_get_type(void); |
856 | extern GType cdk_setting_action_get_type(void); |
857 | extern GType cdk_owner_change_get_type(void); |
858 | extern GType cdk_frame_clock_phase_get_type(void); |
859 | extern GType cdk_subpixel_layout_get_type(void); |
860 | extern GType cdk_prop_mode_get_type(void); |
861 | extern GType cdk_seat_capabilities_get_type(void); |
862 | extern GType cdk_byte_order_get_type(void); |
863 | extern GType cdk_modifier_type_get_type(void); |
864 | extern GType cdk_modifier_intent_get_type(void); |
865 | extern GType cdk_status_get_type(void); |
866 | extern GType cdk_grab_status_get_type(void); |
867 | extern GType cdk_grab_ownership_get_type(void); |
868 | extern GType cdk_event_mask_get_type(void); |
869 | extern GType cdk_gl_error_get_type(void); |
870 | extern GType cdk_window_type_hint_get_type(void); |
871 | extern GType cdk_axis_use_get_type(void); |
872 | extern GType cdk_axis_flags_get_type(void); |
873 | extern GType cdk_visual_type_get_type(void); |
874 | extern GType cdk_window_window_class_get_type(void); |
875 | extern GType cdk_window_type_get_type(void); |
876 | extern GType cdk_window_attributes_type_get_type(void); |
877 | extern GType cdk_window_hints_get_type(void); |
878 | extern GType cdk_wm_decoration_get_type(void); |
879 | extern GType cdk_wm_function_get_type(void); |
880 | extern GType cdk_gravity_get_type(void); |
881 | extern GType cdk_anchor_hints_get_type(void); |
882 | extern GType cdk_window_edge_get_type(void); |
883 | extern GType cdk_fullscreen_mode_get_type(void); |
884 | extern GType cdk_gl_context_get_type(void); |
885 | extern GType cdk_keymap_get_type(void); |
886 | extern GType cdk_visual_get_type(void); |
887 | G_MODULE_EXPORT__attribute__((visibility("default"))) GType (*GI_GET_TYPE_FUNCS_[])(void) = { |
888 | cdk_device_get_type, |
889 | cdk_drag_context_get_type, |
890 | cdk_device_tool_get_type, |
891 | cdk_event_get_type, |
892 | cdk_event_sequence_get_type, |
893 | cdk_device_manager_get_type, |
894 | cdk_drawing_context_get_type, |
895 | cdk_frame_timings_get_type, |
896 | cdk_frame_clock_get_type, |
897 | cdk_window_get_type, |
898 | cdk_seat_get_type, |
899 | cdk_rectangle_get_type, |
900 | cdk_monitor_get_type, |
901 | cdk_display_get_type, |
902 | cdk_screen_get_type, |
903 | cdk_app_launch_context_get_type, |
904 | cdk_color_get_type, |
905 | cdk_rgba_get_type, |
906 | cdk_cursor_get_type, |
907 | cdk_device_pad_get_type, |
908 | cdk_display_manager_get_type, |
909 | cdk_cursor_type_get_type, |
910 | cdk_input_source_get_type, |
911 | cdk_input_mode_get_type, |
912 | cdk_device_type_get_type, |
913 | cdk_device_pad_feature_get_type, |
914 | cdk_device_tool_type_get_type, |
915 | cdk_drag_action_get_type, |
916 | cdk_drag_cancel_reason_get_type, |
917 | cdk_drag_protocol_get_type, |
918 | cdk_filter_return_get_type, |
919 | cdk_event_type_get_type, |
920 | cdk_visibility_state_get_type, |
921 | cdk_touchpad_gesture_phase_get_type, |
922 | cdk_scroll_direction_get_type, |
923 | cdk_notify_type_get_type, |
924 | cdk_crossing_mode_get_type, |
925 | cdk_property_state_get_type, |
926 | cdk_window_state_get_type, |
927 | cdk_setting_action_get_type, |
928 | cdk_owner_change_get_type, |
929 | cdk_frame_clock_phase_get_type, |
930 | cdk_subpixel_layout_get_type, |
931 | cdk_prop_mode_get_type, |
932 | cdk_seat_capabilities_get_type, |
933 | cdk_byte_order_get_type, |
934 | cdk_modifier_type_get_type, |
935 | cdk_modifier_intent_get_type, |
936 | cdk_status_get_type, |
937 | cdk_grab_status_get_type, |
938 | cdk_grab_ownership_get_type, |
939 | cdk_event_mask_get_type, |
940 | cdk_gl_error_get_type, |
941 | cdk_window_type_hint_get_type, |
942 | cdk_axis_use_get_type, |
943 | cdk_axis_flags_get_type, |
944 | cdk_visual_type_get_type, |
945 | cdk_window_window_class_get_type, |
946 | cdk_window_type_get_type, |
947 | cdk_window_attributes_type_get_type, |
948 | cdk_window_hints_get_type, |
949 | cdk_wm_decoration_get_type, |
950 | cdk_wm_function_get_type, |
951 | cdk_gravity_get_type, |
952 | cdk_anchor_hints_get_type, |
953 | cdk_window_edge_get_type, |
954 | cdk_fullscreen_mode_get_type, |
955 | cdk_gl_context_get_type, |
956 | cdk_keymap_get_type, |
957 | cdk_visual_get_type |
958 | }; |
959 | extern GQuark cdk_gl_error_quark(void); |
960 | G_MODULE_EXPORT__attribute__((visibility("default"))) GQuark (*GI_ERROR_QUARK_FUNCS_[])(void) = { |
961 | cdk_gl_error_quark |
962 | }; |