1 /* GLIB-GenMarshal - Marshaller generator for GObject library
2 * Copyright (C) 2000-2001 Red Hat, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #define G_LOG_DOMAIN "GLib-Genmarshal"
25 #include <glib/gprintf.h>
33 #include <sys/types.h>
41 #define PRG_NAME "glib-genmarshal"
42 #define PKG_NAME "GLib"
43 #define PKG_HTTP_HOME "http://www.gtk.org"
46 /* --- typedefs & structures --- */
49 gchar *keyword; /* marhaller list keyword [MY_STRING] */
50 const gchar *sig_name; /* signature name [STRING] */
51 const gchar *ctype; /* C type name [gchar*] */
52 const gchar *getter; /* value getter function [g_value_get_string] */
56 gchar *keyword; /* marhaller list keyword [MY_STRING] */
57 const gchar *sig_name; /* signature name [STRING] */
58 const gchar *ctype; /* C type name [gchar*] */
59 const gchar *setter; /* value setter function [g_value_set_string] */
65 GList *args; /* of type InArgument* */
69 /* --- prototypes --- */
70 static void parse_args (gint *argc_p,
72 static void print_blurb (FILE *bout,
76 /* --- variables --- */
77 static const GScannerConfig scanner_config_template =
80 " \t\r" /* "\n" is statement delimiter */
81 ) /* cset_skip_characters */,
86 ) /* cset_identifier_first */,
91 ) /* cset_identifier_nth */,
92 ( "#\n" ) /* cpair_comment_single */,
94 FALSE /* case_sensitive */,
96 TRUE /* skip_comment_multi */,
97 TRUE /* skip_comment_single */,
98 TRUE /* scan_comment_multi */,
99 TRUE /* scan_identifier */,
100 FALSE /* scan_identifier_1char */,
101 FALSE /* scan_identifier_NULL */,
102 TRUE /* scan_symbols */,
103 FALSE /* scan_binary */,
104 TRUE /* scan_octal */,
105 TRUE /* scan_float */,
107 FALSE /* scan_hex_dollar */,
108 TRUE /* scan_string_sq */,
109 TRUE /* scan_string_dq */,
110 TRUE /* numbers_2_int */,
111 FALSE /* int_2_float */,
112 FALSE /* identifier_2_string */,
113 TRUE /* char_2_token */,
114 FALSE /* symbol_2_token */,
115 FALSE /* scope_0_fallback */,
117 static gchar * const std_marshaller_prefix = "g_cclosure_marshal";
118 static gchar *marshaller_prefix = "g_cclosure_user_marshal";
119 static GHashTable *marshallers = NULL;
120 static FILE *fout = NULL;
121 static gboolean gen_cheader = FALSE;
122 static gboolean gen_cbody = FALSE;
123 static gboolean gen_internal = FALSE;
124 static gboolean skip_ploc = FALSE;
125 static gboolean std_includes = TRUE;
128 /* --- functions --- */
130 put_marshal_value_getters (void)
133 fputs ("#ifdef G_ENABLE_DEBUG\n", fout);
134 fputs ("#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)\n", fout);
135 fputs ("#define g_marshal_value_peek_char(v) g_value_get_char (v)\n", fout);
136 fputs ("#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v)\n", fout);
137 fputs ("#define g_marshal_value_peek_int(v) g_value_get_int (v)\n", fout);
138 fputs ("#define g_marshal_value_peek_uint(v) g_value_get_uint (v)\n", fout);
139 fputs ("#define g_marshal_value_peek_long(v) g_value_get_long (v)\n", fout);
140 fputs ("#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v)\n", fout);
141 fputs ("#define g_marshal_value_peek_int64(v) g_value_get_int64 (v)\n", fout);
142 fputs ("#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v)\n", fout);
143 fputs ("#define g_marshal_value_peek_enum(v) g_value_get_enum (v)\n", fout);
144 fputs ("#define g_marshal_value_peek_flags(v) g_value_get_flags (v)\n", fout);
145 fputs ("#define g_marshal_value_peek_float(v) g_value_get_float (v)\n", fout);
146 fputs ("#define g_marshal_value_peek_double(v) g_value_get_double (v)\n", fout);
147 fputs ("#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v)\n", fout);
148 fputs ("#define g_marshal_value_peek_param(v) g_value_get_param (v)\n", fout);
149 fputs ("#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v)\n", fout);
150 fputs ("#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v)\n", fout);
151 fputs ("#define g_marshal_value_peek_object(v) g_value_get_object (v)\n", fout);
152 fputs ("#else /* !G_ENABLE_DEBUG */\n", fout);
153 fputs ("/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.\n", fout);
154 fputs (" * Do not access GValues directly in your code. Instead, use the\n", fout);
155 fputs (" * g_value_get_*() functions\n", fout);
156 fputs (" */\n", fout);
157 fputs ("#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int\n", fout);
158 fputs ("#define g_marshal_value_peek_char(v) (v)->data[0].v_int\n", fout);
159 fputs ("#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint\n", fout);
160 fputs ("#define g_marshal_value_peek_int(v) (v)->data[0].v_int\n", fout);
161 fputs ("#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint\n", fout);
162 fputs ("#define g_marshal_value_peek_long(v) (v)->data[0].v_long\n", fout);
163 fputs ("#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong\n", fout);
164 fputs ("#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64\n", fout);
165 fputs ("#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64\n", fout);
166 fputs ("#define g_marshal_value_peek_enum(v) (v)->data[0].v_long\n", fout);
167 fputs ("#define g_marshal_value_peek_flags(v) (v)->data[0].v_ulong\n", fout);
168 fputs ("#define g_marshal_value_peek_float(v) (v)->data[0].v_float\n", fout);
169 fputs ("#define g_marshal_value_peek_double(v) (v)->data[0].v_double\n", fout);
170 fputs ("#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer\n", fout);
171 fputs ("#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer\n", fout);
172 fputs ("#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer\n", fout);
173 fputs ("#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer\n", fout);
174 fputs ("#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer\n", fout);
175 fputs ("#endif /* !G_ENABLE_DEBUG */\n", fout);
180 complete_in_arg (InArgument *iarg)
182 static const InArgument args[] = {
183 /* keyword sig_name ctype getter */
184 { "VOID", "VOID", "void", NULL, },
185 { "BOOLEAN", "BOOLEAN", "gboolean", "g_marshal_value_peek_boolean", },
186 { "CHAR", "CHAR", "gchar", "g_marshal_value_peek_char", },
187 { "UCHAR", "UCHAR", "guchar", "g_marshal_value_peek_uchar", },
188 { "INT", "INT", "gint", "g_marshal_value_peek_int", },
189 { "UINT", "UINT", "guint", "g_marshal_value_peek_uint", },
190 { "LONG", "LONG", "glong", "g_marshal_value_peek_long", },
191 { "ULONG", "ULONG", "gulong", "g_marshal_value_peek_ulong", },
192 { "INT64", "INT64", "gint64", "g_marshal_value_peek_int64", },
193 { "UINT64", "UINT64", "guint64", "g_marshal_value_peek_uint64", },
194 { "ENUM", "ENUM", "gint", "g_marshal_value_peek_enum", },
195 { "FLAGS", "FLAGS", "guint", "g_marshal_value_peek_flags", },
196 { "FLOAT", "FLOAT", "gfloat", "g_marshal_value_peek_float", },
197 { "DOUBLE", "DOUBLE", "gdouble", "g_marshal_value_peek_double", },
198 { "STRING", "STRING", "gpointer", "g_marshal_value_peek_string", },
199 { "PARAM", "PARAM", "gpointer", "g_marshal_value_peek_param", },
200 { "BOXED", "BOXED", "gpointer", "g_marshal_value_peek_boxed", },
201 { "POINTER", "POINTER", "gpointer", "g_marshal_value_peek_pointer", },
202 { "OBJECT", "OBJECT", "gpointer", "g_marshal_value_peek_object", },
204 { "NONE", "VOID", "void", NULL, },
205 { "BOOL", "BOOLEAN", "gboolean", "g_marshal_value_peek_boolean", },
209 g_return_val_if_fail (iarg != NULL, FALSE);
211 for (i = 0; i < G_N_ELEMENTS (args); i++)
212 if (strcmp (args[i].keyword, iarg->keyword) == 0)
214 iarg->sig_name = args[i].sig_name;
215 iarg->ctype = args[i].ctype;
216 iarg->getter = args[i].getter;
224 complete_out_arg (OutArgument *oarg)
226 static const OutArgument args[] = {
227 /* keyword sig_name ctype setter */
228 { "VOID", "VOID", "void", NULL, },
229 { "BOOLEAN", "BOOLEAN", "gboolean", "g_value_set_boolean", },
230 { "CHAR", "CHAR", "gchar", "g_value_set_char", },
231 { "UCHAR", "UCHAR", "guchar", "g_value_set_uchar", },
232 { "INT", "INT", "gint", "g_value_set_int", },
233 { "UINT", "UINT", "guint", "g_value_set_uint", },
234 { "LONG", "LONG", "glong", "g_value_set_long", },
235 { "ULONG", "ULONG", "gulong", "g_value_set_ulong", },
236 { "INT64", "INT64", "gint64", "g_value_set_int64", },
237 { "UINT64", "UINT64", "guint64", "g_value_set_uint64", },
238 { "ENUM", "ENUM", "gint", "g_value_set_enum", },
239 { "FLAGS", "FLAGS", "guint", "g_value_set_flags", },
240 { "FLOAT", "FLOAT", "gfloat", "g_value_set_float", },
241 { "DOUBLE", "DOUBLE", "gdouble", "g_value_set_double", },
242 { "STRING", "STRING", "gchar*", "g_value_take_string", },
243 { "PARAM", "PARAM", "GParamSpec*", "g_value_take_param", },
244 { "BOXED", "BOXED", "gpointer", "g_value_take_boxed", },
245 { "POINTER", "POINTER", "gpointer", "g_value_set_pointer", },
246 { "OBJECT", "OBJECT", "GObject*", "g_value_take_object", },
248 { "NONE", "VOID", "void", NULL, },
249 { "BOOL", "BOOLEAN", "gboolean", "g_value_set_boolean", },
253 g_return_val_if_fail (oarg != NULL, FALSE);
255 for (i = 0; i < G_N_ELEMENTS (args); i++)
256 if (strcmp (args[i].keyword, oarg->keyword) == 0)
258 oarg->sig_name = args[i].sig_name;
259 oarg->ctype = args[i].ctype;
260 oarg->setter = args[i].setter;
268 pad (const gchar *string)
270 #define PAD_LENGTH 12
271 static gchar *buffer = NULL;
274 g_return_val_if_fail (string != NULL, NULL);
277 buffer = g_new (gchar, PAD_LENGTH + 1);
280 if (strlen (string) >= PAD_LENGTH)
283 buffer = g_strdup_printf ("%s ", string);
284 g_warning ("overfull string (%u bytes) for padspace",
285 (guint) strlen (string));
290 for (i = 0; i < PAD_LENGTH; i++)
292 gboolean done = *string == 0;
294 buffer[i] = done ? ' ' : *string++;
302 indent (guint n_spaces)
304 static gchar *buffer = NULL;
305 static guint blength = 0;
307 if (blength <= n_spaces)
309 blength = n_spaces + 1;
311 buffer = g_new (gchar, blength);
313 memset (buffer, ' ', n_spaces);
314 buffer[n_spaces] = 0;
320 generate_marshal (const gchar *signame,
325 gchar *tmp = g_strconcat (marshaller_prefix, "_", signame, NULL);
326 gboolean have_std_marshaller = FALSE;
328 /* here we have to make sure a marshaller named <marshaller_prefix>_<signame>
329 * exists. we might have put it out already, can revert to a standard
330 * marshaller provided by glib, or need to generate one.
333 if (g_hash_table_lookup (marshallers, tmp))
335 /* done, marshaller already generated */
341 /* need to alias/generate marshaller, register name */
342 g_hash_table_insert (marshallers, tmp, tmp);
345 /* can we revert to a standard marshaller? */
348 tmp = g_strconcat (std_marshaller_prefix, "_", signame, NULL);
349 have_std_marshaller = g_hash_table_lookup (marshallers, tmp) != NULL;
353 if (gen_cheader && have_std_marshaller)
355 g_fprintf (fout, "#define %s_%s\t%s_%s\n", marshaller_prefix, signame, std_marshaller_prefix, signame);
357 if (gen_cheader && !have_std_marshaller)
359 ind = g_fprintf (fout, gen_internal ? "G_GNUC_INTERNAL " : "extern ");
360 ind += g_fprintf (fout, "void ");
361 ind += g_fprintf (fout, "%s_%s (", marshaller_prefix, signame);
362 g_fprintf (fout, "GClosure *closure,\n");
363 g_fprintf (fout, "%sGValue *return_value,\n", indent (ind));
364 g_fprintf (fout, "%sguint n_param_values,\n", indent (ind));
365 g_fprintf (fout, "%sconst GValue *param_values,\n", indent (ind));
366 g_fprintf (fout, "%sgpointer invocation_hint,\n", indent (ind));
367 g_fprintf (fout, "%sgpointer marshal_data);\n",
370 if (gen_cbody && !have_std_marshaller)
372 /* cfile marshal header */
373 g_fprintf (fout, "void\n");
374 ind = g_fprintf (fout, "%s_%s (", marshaller_prefix, signame);
375 g_fprintf (fout, "GClosure *closure,\n");
376 g_fprintf (fout, "%sGValue *return_value,\n", indent (ind));
377 g_fprintf (fout, "%sguint n_param_values,\n", indent (ind));
378 g_fprintf (fout, "%sconst GValue *param_values,\n", indent (ind));
379 g_fprintf (fout, "%sgpointer invocation_hint,\n", indent (ind));
380 g_fprintf (fout, "%sgpointer marshal_data)\n", indent (ind));
381 g_fprintf (fout, "{\n");
383 /* cfile GMarshalFunc typedef */
384 ind = g_fprintf (fout, " typedef %s (*GMarshalFunc_%s) (", sig->rarg->ctype, signame);
385 g_fprintf (fout, "%s data1,\n", pad ("gpointer"));
386 for (a = 1, node = sig->args; node; node = node->next)
388 InArgument *iarg = node->data;
391 g_fprintf (fout, "%s%s arg_%d,\n", indent (ind), pad (iarg->ctype), a++);
393 g_fprintf (fout, "%s%s data2);\n", indent (ind), pad ("gpointer"));
395 /* cfile marshal variables */
396 g_fprintf (fout, " register GMarshalFunc_%s callback;\n", signame);
397 g_fprintf (fout, " register GCClosure *cc = (GCClosure*) closure;\n");
398 g_fprintf (fout, " register gpointer data1, data2;\n");
399 if (sig->rarg->setter)
400 g_fprintf (fout, " %s v_return;\n", sig->rarg->ctype);
402 if (sig->args || sig->rarg->setter)
404 g_fprintf (fout, "\n");
406 if (sig->rarg->setter)
407 g_fprintf (fout, " g_return_if_fail (return_value != NULL);\n");
410 for (a = 0, node = sig->args; node; node = node->next)
412 InArgument *iarg = node->data;
417 g_fprintf (fout, " g_return_if_fail (n_param_values == %u);\n", 1 + a);
421 /* cfile marshal data1, data2 and callback setup */
422 g_fprintf (fout, "\n");
423 g_fprintf (fout, " if (G_CCLOSURE_SWAP_DATA (closure))\n {\n");
424 g_fprintf (fout, " data1 = closure->data;\n");
425 g_fprintf (fout, " data2 = g_value_peek_pointer (param_values + 0);\n");
426 g_fprintf (fout, " }\n else\n {\n");
427 g_fprintf (fout, " data1 = g_value_peek_pointer (param_values + 0);\n");
428 g_fprintf (fout, " data2 = closure->data;\n");
429 g_fprintf (fout, " }\n");
430 g_fprintf (fout, " callback = (GMarshalFunc_%s) (marshal_data ? marshal_data : cc->callback);\n", signame);
432 /* cfile marshal callback action */
433 g_fprintf (fout, "\n");
434 ind = g_fprintf (fout, " %s callback (", sig->rarg->setter ? " v_return =" : "");
435 g_fprintf (fout, "data1,\n");
436 for (a = 1, node = sig->args; node; node = node->next)
438 InArgument *iarg = node->data;
441 g_fprintf (fout, "%s%s (param_values + %d),\n", indent (ind), iarg->getter, a++);
443 g_fprintf (fout, "%sdata2);\n", indent (ind));
445 /* cfile marshal return value storage */
446 if (sig->rarg->setter)
448 g_fprintf (fout, "\n");
449 g_fprintf (fout, " %s (return_value, v_return);\n", sig->rarg->setter);
452 /* cfile marshal footer */
453 g_fprintf (fout, "}\n");
458 process_signature (Signature *sig)
460 gchar *pname, *sname, *tmp;
463 /* lookup and complete info on arguments */
464 if (!complete_out_arg (sig->rarg))
466 g_warning ("unknown type: %s", sig->rarg->keyword);
469 for (node = sig->args; node; node = node->next)
471 InArgument *iarg = node->data;
473 if (!complete_in_arg (iarg))
475 g_warning ("unknown type: %s", iarg->keyword);
480 /* construct requested marshaller name and technical marshaller name */
481 pname = g_strconcat (sig->rarg->keyword, "_", NULL);
482 sname = g_strconcat (sig->rarg->sig_name, "_", NULL);
483 for (node = sig->args; node; node = node->next)
485 InArgument *iarg = node->data;
489 sname = g_strconcat (tmp, "_", iarg->sig_name, NULL);
492 pname = g_strconcat (tmp, "_", iarg->keyword, NULL);
496 /* introductionary comment */
497 g_fprintf (fout, "\n/* %s", sig->rarg->keyword);
498 for (node = sig->args; node; node = node->next)
500 InArgument *iarg = node->data;
502 g_fprintf (fout, "%c%s", node->prev ? ',' : ':', iarg->keyword);
505 g_fprintf (fout, " (%s)", sig->ploc);
506 g_fprintf (fout, " */\n");
508 /* ensure technical marshaller exists (<marshaller_prefix>_<sname>) */
509 generate_marshal (sname, sig);
511 /* put out marshaller alias for requested name if required (<marshaller_prefix>_<pname>) */
512 tmp = g_strconcat (marshaller_prefix, "_", pname, NULL);
513 if (gen_cheader && !g_hash_table_lookup (marshallers, tmp))
515 g_fprintf (fout, "#define %s_%s\t%s_%s\n", marshaller_prefix, pname, marshaller_prefix, sname);
517 g_hash_table_insert (marshallers, tmp, tmp);
527 new_in_arg (const gchar *pname)
529 InArgument *iarg = g_new0 (InArgument, 1);
531 iarg->keyword = g_strdup (pname);
537 new_out_arg (const gchar *pname)
539 OutArgument *oarg = g_new0 (OutArgument, 1);
541 oarg->keyword = g_strdup (pname);
547 parse_line (GScanner *scanner,
550 /* parse identifier for return value */
551 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER)
552 return G_TOKEN_IDENTIFIER;
553 sig->rarg = new_out_arg (scanner->value.v_identifier);
555 /* keep a note on the location */
556 sig->ploc = g_strdup_printf ("%s:%u", scanner->input_name, scanner->line);
559 if (g_scanner_get_next_token (scanner) != ':')
562 /* parse first argument */
563 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER)
564 return G_TOKEN_IDENTIFIER;
565 sig->args = g_list_append (sig->args, new_in_arg (scanner->value.v_identifier));
567 /* parse rest of argument list */
568 while (g_scanner_peek_next_token (scanner) == ',')
571 g_scanner_get_next_token (scanner);
573 /* parse arg identifier */
574 if (g_scanner_get_next_token (scanner) != G_TOKEN_IDENTIFIER)
575 return G_TOKEN_IDENTIFIER;
576 sig->args = g_list_append (sig->args, new_in_arg (scanner->value.v_identifier));
579 /* expect end of line, done */
580 if (g_scanner_get_next_token (scanner) != '\n')
588 string_key_destroy (gpointer key,
601 const gchar *gobject_marshallers[] = {
602 #include "gmarshal.strings"
605 GSList *slist, *files = NULL;
609 /* parse args and do fast exits */
610 parse_args (&argc, &argv);
612 /* list input files */
613 for (i = 1; i < argc; i++)
614 files = g_slist_prepend (files, argv[i]);
616 files = g_slist_reverse (files);
618 files = g_slist_prepend (files, "/dev/stdin");
620 /* setup auxillary structs */
621 scanner = g_scanner_new (&scanner_config_template);
623 marshallers = g_hash_table_new (g_str_hash, g_str_equal);
625 /* add standard marshallers of the GObject library */
627 for (i = 0; i < G_N_ELEMENTS (gobject_marshallers); i++)
629 gchar *tmp = g_strdup (gobject_marshallers[i]);
631 g_hash_table_insert (marshallers, tmp, tmp);
634 /* put out initial heading */
635 g_fprintf (fout, "\n");
637 if (gen_cheader && std_includes)
639 g_fprintf (fout, "#ifndef __%s_MARSHAL_H__\n", marshaller_prefix);
640 g_fprintf (fout, "#define __%s_MARSHAL_H__\n\n", marshaller_prefix);
643 if ((gen_cheader || gen_cbody) && std_includes)
644 g_fprintf (fout, "#include\t<glib-object.h>\n\n");
647 g_fprintf (fout, "G_BEGIN_DECLS\n");
649 /* generate necessary preprocessor directives */
651 put_marshal_value_getters ();
653 /* process input files */
654 for (slist = files; slist; slist = slist->next)
656 gchar *file = slist->data;
659 if (strcmp (file, "/dev/stdin") == 0)
660 /* Mostly for Win32. This is equivalent to opening /dev/stdin */
663 fd = open (file, O_RDONLY);
667 g_warning ("failed to open \"%s\": %s", file, g_strerror (errno));
672 /* set file name for error reports */
673 scanner->input_name = file;
675 /* parse & process file */
676 g_scanner_input_file (scanner, fd);
678 /* scanning loop, we parse the input untill it's end is reached,
679 * or our sub routine came across invalid syntax
683 guint expected_token = G_TOKEN_NONE;
685 switch (g_scanner_peek_next_token (scanner))
688 /* eat newline and restart */
689 g_scanner_get_next_token (scanner);
695 /* parse and process signatures */
697 Signature signature = { NULL, NULL, NULL };
700 expected_token = parse_line (scanner, &signature);
702 /* once we got a valid signature, process it */
703 if (expected_token == G_TOKEN_NONE)
704 process_signature (&signature);
706 /* clean up signature contents */
707 g_free (signature.ploc);
709 g_free (signature.rarg->keyword);
710 g_free (signature.rarg);
711 for (node = signature.args; node; node = node->next)
713 InArgument *iarg = node->data;
715 g_free (iarg->keyword);
718 g_list_free (signature.args);
723 /* bail out on errors */
724 if (expected_token != G_TOKEN_NONE)
726 g_scanner_unexp_token (scanner, expected_token, "type name", NULL, NULL, NULL, TRUE);
731 g_scanner_peek_next_token (scanner);
733 while (scanner->next_token != G_TOKEN_EOF);
738 /* put out trailer */
741 g_fprintf (fout, "\nG_END_DECLS\n");
744 g_fprintf (fout, "\n#endif /* __%s_MARSHAL_H__ */\n", marshaller_prefix);
746 g_fprintf (fout, "\n");
749 g_slist_free (files);
750 g_scanner_destroy (scanner);
751 g_hash_table_foreach_remove (marshallers, string_key_destroy, NULL);
752 g_hash_table_destroy (marshallers);
758 parse_args (gint *argc_p,
761 guint argc = *argc_p;
762 gchar **argv = *argv_p;
765 for (i = 1; i < argc; i++)
767 if (strcmp ("--header", argv[i]) == 0)
772 else if (strcmp ("--body", argv[i]) == 0)
777 else if (strcmp ("--skip-source", argv[i]) == 0)
782 else if (strcmp ("--nostdinc", argv[i]) == 0)
784 std_includes = FALSE;
787 else if (strcmp ("--stdinc", argv[i]) == 0)
792 else if (strcmp ("--internal", argv[i]) == 0)
797 else if ((strcmp ("--prefix", argv[i]) == 0) ||
798 (strncmp ("--prefix=", argv[i], 9) == 0))
800 gchar *equal = argv[i] + 8;
803 marshaller_prefix = g_strdup (equal + 1);
804 else if (i + 1 < argc)
806 marshaller_prefix = g_strdup (argv[i + 1]);
812 else if (strcmp ("-h", argv[i]) == 0 ||
813 strcmp ("--help", argv[i]) == 0)
815 print_blurb (stderr, TRUE);
819 else if (strcmp ("-v", argv[i]) == 0 ||
820 strcmp ("--version", argv[i]) == 0)
822 print_blurb (stderr, FALSE);
826 else if (strcmp (argv[i], "--g-fatal-warnings") == 0)
828 GLogLevelFlags fatal_mask;
830 fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
831 fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
832 g_log_set_always_fatal (fatal_mask);
839 for (i = 1; i < argc; i++)
857 print_blurb (FILE *bout,
862 g_fprintf (bout, "%s version ", PRG_NAME);
863 g_fprintf (bout, "%u.%u.%u", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
864 g_fprintf (bout, "\n");
865 g_fprintf (bout, "%s comes with ABSOLUTELY NO WARRANTY.\n", PRG_NAME);
866 g_fprintf (bout, "You may redistribute copies of %s under the terms of\n", PRG_NAME);
867 g_fprintf (bout, "the GNU General Public License which can be found in the\n");
868 g_fprintf (bout, "%s source package. Sources, examples and contact\n", PKG_NAME);
869 g_fprintf (bout, "information are available at %s\n", PKG_HTTP_HOME);
873 g_fprintf (bout, "Usage: %s [options] [files...]\n", PRG_NAME);
874 g_fprintf (bout, " --header generate C headers\n");
875 g_fprintf (bout, " --body generate C code\n");
876 g_fprintf (bout, " --prefix=string specify marshaller prefix\n");
877 g_fprintf (bout, " --skip-source skip source location comments\n");
878 g_fprintf (bout, " --stdinc, --nostdinc include/use standard marshallers\n");
879 g_fprintf (bout, " --internal mark generated functions as internal\n");
880 g_fprintf (bout, " -h, --help show this help message\n");
881 g_fprintf (bout, " -v, --version print version informations\n");
882 g_fprintf (bout, " --g-fatal-warnings make warnings fatal (abort)\n");