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 FILE *fout
= NULL
;
78 static GScannerConfig scanner_config_template
=
81 " \t\r" /* "\n" is statement delimiter */
82 ) /* cset_skip_characters */,
87 ) /* cset_identifier_first */,
92 ) /* cset_identifier_nth */,
93 ( "#\n" ) /* cpair_comment_single */,
95 FALSE
/* case_sensitive */,
97 TRUE
/* skip_comment_multi */,
98 TRUE
/* skip_comment_single */,
99 TRUE
/* scan_comment_multi */,
100 TRUE
/* scan_identifier */,
101 FALSE
/* scan_identifier_1char */,
102 FALSE
/* scan_identifier_NULL */,
103 TRUE
/* scan_symbols */,
104 FALSE
/* scan_binary */,
105 TRUE
/* scan_octal */,
106 TRUE
/* scan_float */,
108 FALSE
/* scan_hex_dollar */,
109 TRUE
/* scan_string_sq */,
110 TRUE
/* scan_string_dq */,
111 TRUE
/* numbers_2_int */,
112 FALSE
/* int_2_float */,
113 FALSE
/* identifier_2_string */,
114 TRUE
/* char_2_token */,
115 FALSE
/* symbol_2_token */,
116 FALSE
/* scope_0_fallback */,
118 static gchar
* const std_marshaller_prefix
= "g_cclosure_marshal";
119 static gchar
*marshaller_prefix
= "g_cclosure_user_marshal";
120 static GHashTable
*marshallers
= NULL
;
121 static gboolean gen_cheader
= FALSE
;
122 static gboolean gen_cbody
= FALSE
;
123 static gboolean skip_ploc
= FALSE
;
124 static gboolean std_includes
= TRUE
;
127 /* --- functions --- */
129 put_marshal_value_getters (void)
132 fputs ("#ifdef G_ENABLE_DEBUG\n", fout
);
133 fputs ("#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)\n", fout
);
134 fputs ("#define g_marshal_value_peek_char(v) g_value_get_char (v)\n", fout
);
135 fputs ("#define g_marshal_value_peek_uchar(v) g_value_get_uchar (v)\n", fout
);
136 fputs ("#define g_marshal_value_peek_int(v) g_value_get_int (v)\n", fout
);
137 fputs ("#define g_marshal_value_peek_uint(v) g_value_get_uint (v)\n", fout
);
138 fputs ("#define g_marshal_value_peek_long(v) g_value_get_long (v)\n", fout
);
139 fputs ("#define g_marshal_value_peek_ulong(v) g_value_get_ulong (v)\n", fout
);
140 fputs ("#define g_marshal_value_peek_int64(v) g_value_get_int64 (v)\n", fout
);
141 fputs ("#define g_marshal_value_peek_uint64(v) g_value_get_uint64 (v)\n", fout
);
142 fputs ("#define g_marshal_value_peek_enum(v) g_value_get_enum (v)\n", fout
);
143 fputs ("#define g_marshal_value_peek_flags(v) g_value_get_flags (v)\n", fout
);
144 fputs ("#define g_marshal_value_peek_float(v) g_value_get_float (v)\n", fout
);
145 fputs ("#define g_marshal_value_peek_double(v) g_value_get_double (v)\n", fout
);
146 fputs ("#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v)\n", fout
);
147 fputs ("#define g_marshal_value_peek_param(v) g_value_get_param (v)\n", fout
);
148 fputs ("#define g_marshal_value_peek_boxed(v) g_value_get_boxed (v)\n", fout
);
149 fputs ("#define g_marshal_value_peek_pointer(v) g_value_get_pointer (v)\n", fout
);
150 fputs ("#define g_marshal_value_peek_object(v) g_value_get_object (v)\n", fout
);
151 fputs ("#else /* !G_ENABLE_DEBUG */\n", fout
);
152 fputs ("/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.\n", fout
);
153 fputs (" * Do not access GValues directly in your code. Instead, use the\n", fout
);
154 fputs (" * g_value_get_*() functions\n", fout
);
155 fputs (" */\n", fout
);
156 fputs ("#define g_marshal_value_peek_boolean(v) (v)->data[0].v_int\n", fout
);
157 fputs ("#define g_marshal_value_peek_char(v) (v)->data[0].v_int\n", fout
);
158 fputs ("#define g_marshal_value_peek_uchar(v) (v)->data[0].v_uint\n", fout
);
159 fputs ("#define g_marshal_value_peek_int(v) (v)->data[0].v_int\n", fout
);
160 fputs ("#define g_marshal_value_peek_uint(v) (v)->data[0].v_uint\n", fout
);
161 fputs ("#define g_marshal_value_peek_long(v) (v)->data[0].v_long\n", fout
);
162 fputs ("#define g_marshal_value_peek_ulong(v) (v)->data[0].v_ulong\n", fout
);
163 fputs ("#define g_marshal_value_peek_int64(v) (v)->data[0].v_int64\n", fout
);
164 fputs ("#define g_marshal_value_peek_uint64(v) (v)->data[0].v_uint64\n", fout
);
165 fputs ("#define g_marshal_value_peek_enum(v) (v)->data[0].v_long\n", fout
);
166 fputs ("#define g_marshal_value_peek_flags(v) (v)->data[0].v_ulong\n", fout
);
167 fputs ("#define g_marshal_value_peek_float(v) (v)->data[0].v_float\n", fout
);
168 fputs ("#define g_marshal_value_peek_double(v) (v)->data[0].v_double\n", fout
);
169 fputs ("#define g_marshal_value_peek_string(v) (v)->data[0].v_pointer\n", fout
);
170 fputs ("#define g_marshal_value_peek_param(v) (v)->data[0].v_pointer\n", fout
);
171 fputs ("#define g_marshal_value_peek_boxed(v) (v)->data[0].v_pointer\n", fout
);
172 fputs ("#define g_marshal_value_peek_pointer(v) (v)->data[0].v_pointer\n", fout
);
173 fputs ("#define g_marshal_value_peek_object(v) (v)->data[0].v_pointer\n", fout
);
174 fputs ("#endif /* !G_ENABLE_DEBUG */\n", fout
);
179 complete_in_arg (InArgument
*iarg
)
181 static const InArgument args
[] = {
182 /* keyword sig_name ctype getter */
183 { "VOID", "VOID", "void", NULL
, },
184 { "BOOLEAN", "BOOLEAN", "gboolean", "g_marshal_value_peek_boolean", },
185 { "CHAR", "CHAR", "gchar", "g_marshal_value_peek_char", },
186 { "UCHAR", "UCHAR", "guchar", "g_marshal_value_peek_uchar", },
187 { "INT", "INT", "gint", "g_marshal_value_peek_int", },
188 { "UINT", "UINT", "guint", "g_marshal_value_peek_uint", },
189 { "LONG", "LONG", "glong", "g_marshal_value_peek_long", },
190 { "ULONG", "ULONG", "gulong", "g_marshal_value_peek_ulong", },
191 { "INT64", "INT64", "gint64", "g_marshal_value_peek_int64", },
192 { "UINT64", "UINT64", "guint64", "g_marshal_value_peek_uint64", },
193 { "ENUM", "ENUM", "gint", "g_marshal_value_peek_enum", },
194 { "FLAGS", "FLAGS", "guint", "g_marshal_value_peek_flags", },
195 { "FLOAT", "FLOAT", "gfloat", "g_marshal_value_peek_float", },
196 { "DOUBLE", "DOUBLE", "gdouble", "g_marshal_value_peek_double", },
197 { "STRING", "STRING", "gpointer", "g_marshal_value_peek_string", },
198 { "PARAM", "PARAM", "gpointer", "g_marshal_value_peek_param", },
199 { "BOXED", "BOXED", "gpointer", "g_marshal_value_peek_boxed", },
200 { "POINTER", "POINTER", "gpointer", "g_marshal_value_peek_pointer", },
201 { "OBJECT", "OBJECT", "gpointer", "g_marshal_value_peek_object", },
203 { "NONE", "VOID", "void", NULL
, },
204 { "BOOL", "BOOLEAN", "gboolean", "g_marshal_value_peek_boolean", },
206 const guint n_args
= sizeof (args
) / sizeof (args
[0]);
209 g_return_val_if_fail (iarg
!= NULL
, FALSE
);
211 for (i
= 0; i
< n_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", },
251 const guint n_args
= sizeof (args
) / sizeof (args
[0]);
254 g_return_val_if_fail (oarg
!= NULL
, FALSE
);
256 for (i
= 0; i
< n_args
; i
++)
257 if (strcmp (args
[i
].keyword
, oarg
->keyword
) == 0)
259 oarg
->sig_name
= args
[i
].sig_name
;
260 oarg
->ctype
= args
[i
].ctype
;
261 oarg
->setter
= args
[i
].setter
;
269 pad (const gchar
*string
)
271 #define PAD_LENGTH 12
272 static gchar
*buffer
= NULL
;
275 g_return_val_if_fail (string
!= NULL
, NULL
);
278 buffer
= g_new (gchar
, PAD_LENGTH
+ 1);
281 if (strlen (string
) >= PAD_LENGTH
)
284 buffer
= g_strdup_printf ("%s ", string
);
285 g_warning ("overfull string (%u bytes) for padspace", (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 marshaller
330 * 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
, "extern void ");
360 ind
+= g_fprintf (fout
, "%s_%s (", marshaller_prefix
, signame
);
361 g_fprintf (fout
, "GClosure *closure,\n");
362 g_fprintf (fout
, "%sGValue *return_value,\n", indent (ind
));
363 g_fprintf (fout
, "%sguint n_param_values,\n", indent (ind
));
364 g_fprintf (fout
, "%sconst GValue *param_values,\n", indent (ind
));
365 g_fprintf (fout
, "%sgpointer invocation_hint,\n", indent (ind
));
366 g_fprintf (fout
, "%sgpointer marshal_data);\n", indent (ind
));
368 if (gen_cbody
&& !have_std_marshaller
)
370 /* cfile marhsal header */
371 g_fprintf (fout
, "void\n");
372 ind
= g_fprintf (fout
, "%s_%s (", marshaller_prefix
, signame
);
373 g_fprintf (fout
, "GClosure *closure,\n");
374 g_fprintf (fout
, "%sGValue *return_value,\n", indent (ind
));
375 g_fprintf (fout
, "%sguint n_param_values,\n", indent (ind
));
376 g_fprintf (fout
, "%sconst GValue *param_values,\n", indent (ind
));
377 g_fprintf (fout
, "%sgpointer invocation_hint,\n", indent (ind
));
378 g_fprintf (fout
, "%sgpointer marshal_data)\n", indent (ind
));
379 g_fprintf (fout
, "{\n");
381 /* cfile GMarshalFunc typedef */
382 ind
= g_fprintf (fout
, " typedef %s (*GMarshalFunc_%s) (", sig
->rarg
->ctype
, signame
);
383 g_fprintf (fout
, "%s data1,\n", pad ("gpointer"));
384 for (a
= 1, node
= sig
->args
; node
; node
= node
->next
)
386 InArgument
*iarg
= node
->data
;
389 g_fprintf (fout
, "%s%s arg_%d,\n", indent (ind
), pad (iarg
->ctype
), a
++);
391 g_fprintf (fout
, "%s%s data2);\n", indent (ind
), pad ("gpointer"));
393 /* cfile marshal variables */
394 g_fprintf (fout
, " register GMarshalFunc_%s callback;\n", signame
);
395 g_fprintf (fout
, " register GCClosure *cc = (GCClosure*) closure;\n");
396 g_fprintf (fout
, " register gpointer data1, data2;\n");
397 if (sig
->rarg
->setter
)
398 g_fprintf (fout
, " %s v_return;\n", sig
->rarg
->ctype
);
400 if (sig
->args
|| sig
->rarg
->setter
)
402 g_fprintf (fout
, "\n");
404 if (sig
->rarg
->setter
)
405 g_fprintf (fout
, " g_return_if_fail (return_value != NULL);\n");
408 for (a
= 0, node
= sig
->args
; node
; node
= node
->next
)
410 InArgument
*iarg
= node
->data
;
415 g_fprintf (fout
, " g_return_if_fail (n_param_values == %u);\n", 1 + a
);
419 /* cfile marshal data1, data2 and callback setup */
420 g_fprintf (fout
, "\n");
421 g_fprintf (fout
, " if (G_CCLOSURE_SWAP_DATA (closure))\n {\n");
422 g_fprintf (fout
, " data1 = closure->data;\n");
423 g_fprintf (fout
, " data2 = g_value_peek_pointer (param_values + 0);\n");
424 g_fprintf (fout
, " }\n else\n {\n");
425 g_fprintf (fout
, " data1 = g_value_peek_pointer (param_values + 0);\n");
426 g_fprintf (fout
, " data2 = closure->data;\n");
427 g_fprintf (fout
, " }\n");
428 g_fprintf (fout
, " callback = (GMarshalFunc_%s) (marshal_data ? marshal_data : cc->callback);\n", signame
);
430 /* cfile marshal callback action */
431 g_fprintf (fout
, "\n");
432 ind
= g_fprintf (fout
, " %s callback (", sig
->rarg
->setter
? " v_return =" : "");
433 g_fprintf (fout
, "data1,\n");
434 for (a
= 1, node
= sig
->args
; node
; node
= node
->next
)
436 InArgument
*iarg
= node
->data
;
439 g_fprintf (fout
, "%s%s (param_values + %d),\n", indent (ind
), iarg
->getter
, a
++);
441 g_fprintf (fout
, "%sdata2);\n", indent (ind
));
443 /* cfile marshal return value storage */
444 if (sig
->rarg
->setter
)
446 g_fprintf (fout
, "\n");
447 g_fprintf (fout
, " %s (return_value, v_return);\n", sig
->rarg
->setter
);
450 /* cfile marshal footer */
451 g_fprintf (fout
, "}\n");
456 process_signature (Signature
*sig
)
458 gchar
*pname
, *sname
, *tmp
;
461 /* lookup and complete info on arguments */
462 if (!complete_out_arg (sig
->rarg
))
464 g_warning ("unknown type: %s", sig
->rarg
->keyword
);
467 for (node
= sig
->args
; node
; node
= node
->next
)
469 InArgument
*iarg
= node
->data
;
471 if (!complete_in_arg (iarg
))
473 g_warning ("unknown type: %s", iarg
->keyword
);
478 /* construct requested marshaller name and technical marshaller name */
479 pname
= g_strconcat (sig
->rarg
->keyword
, "_", NULL
);
480 sname
= g_strconcat (sig
->rarg
->sig_name
, "_", NULL
);
481 for (node
= sig
->args
; node
; node
= node
->next
)
483 InArgument
*iarg
= node
->data
;
487 sname
= g_strconcat (tmp
, "_", iarg
->sig_name
, NULL
);
490 pname
= g_strconcat (tmp
, "_", iarg
->keyword
, NULL
);
494 /* introductionary comment */
495 g_fprintf (fout
, "\n/* %s", sig
->rarg
->keyword
);
496 for (node
= sig
->args
; node
; node
= node
->next
)
498 InArgument
*iarg
= node
->data
;
500 g_fprintf (fout
, "%c%s", node
->prev
? ',' : ':', iarg
->keyword
);
503 g_fprintf (fout
, " (%s)", sig
->ploc
);
504 g_fprintf (fout
, " */\n");
506 /* ensure technical marshaller exists (<marshaller_prefix>_<sname>) */
507 generate_marshal (sname
, sig
);
509 /* put out marshaller alias for requested name if required (<marshaller_prefix>_<pname>) */
510 tmp
= g_strconcat (marshaller_prefix
, "_", pname
, NULL
);
511 if (gen_cheader
&& !g_hash_table_lookup (marshallers
, tmp
))
513 g_fprintf (fout
, "#define %s_%s\t%s_%s\n", marshaller_prefix
, pname
, marshaller_prefix
, sname
);
515 g_hash_table_insert (marshallers
, tmp
, tmp
);
525 new_in_arg (const gchar
*pname
)
527 InArgument
*iarg
= g_new0 (InArgument
, 1);
529 iarg
->keyword
= g_strdup (pname
);
535 new_out_arg (const gchar
*pname
)
537 OutArgument
*oarg
= g_new0 (OutArgument
, 1);
539 oarg
->keyword
= g_strdup (pname
);
545 parse_line (GScanner
*scanner
,
548 /* parse identifier for return value */
549 if (g_scanner_get_next_token (scanner
) != G_TOKEN_IDENTIFIER
)
550 return G_TOKEN_IDENTIFIER
;
551 sig
->rarg
= new_out_arg (scanner
->value
.v_identifier
);
553 /* keep a note on the location */
554 sig
->ploc
= g_strdup_printf ("%s:%u", scanner
->input_name
, scanner
->line
);
557 if (g_scanner_get_next_token (scanner
) != ':')
560 /* parse first argument */
561 if (g_scanner_get_next_token (scanner
) != G_TOKEN_IDENTIFIER
)
562 return G_TOKEN_IDENTIFIER
;
563 sig
->args
= g_list_append (sig
->args
, new_in_arg (scanner
->value
.v_identifier
));
565 /* parse rest of argument list */
566 while (g_scanner_peek_next_token (scanner
) == ',')
569 g_scanner_get_next_token (scanner
);
571 /* parse arg identifier */
572 if (g_scanner_get_next_token (scanner
) != G_TOKEN_IDENTIFIER
)
573 return G_TOKEN_IDENTIFIER
;
574 sig
->args
= g_list_append (sig
->args
, new_in_arg (scanner
->value
.v_identifier
));
577 /* expect end of line, done */
578 if (g_scanner_get_next_token (scanner
) != '\n')
586 string_key_destroy (gpointer key
,
599 const gchar
*gobject_marshallers
[] = {
600 #include "gmarshal.strings"
603 GSList
*slist
, *files
= NULL
;
607 /* parse args and do fast exits */
608 parse_args (&argc
, &argv
);
610 /* list input files */
611 for (i
= 1; i
< argc
; i
++)
612 files
= g_slist_prepend (files
, argv
[i
]);
614 files
= g_slist_reverse (files
);
616 files
= g_slist_prepend (files
, "/dev/stdin");
618 /* setup auxillary structs */
619 scanner
= g_scanner_new (&scanner_config_template
);
621 marshallers
= g_hash_table_new (g_str_hash
, g_str_equal
);
623 /* add standard marshallers of the GObject library */
625 for (i
= 0; i
< G_N_ELEMENTS (gobject_marshallers
); i
++)
627 gchar
*tmp
= g_strdup (gobject_marshallers
[i
]);
629 g_hash_table_insert (marshallers
, tmp
, tmp
);
632 /* put out initial heading */
633 g_fprintf (fout
, "\n");
635 if (gen_cheader
&& std_includes
)
637 g_fprintf (fout
, "#ifndef __%s_MARSHAL_H__\n", marshaller_prefix
);
638 g_fprintf (fout
, "#define __%s_MARSHAL_H__\n\n", marshaller_prefix
);
641 if ((gen_cheader
|| gen_cbody
) && std_includes
)
642 g_fprintf (fout
, "#include\t<glib-object.h>\n\n");
645 g_fprintf (fout
, "G_BEGIN_DECLS\n");
647 /* generate necessary preprocessor directives */
649 put_marshal_value_getters ();
651 /* process input files */
652 for (slist
= files
; slist
; slist
= slist
->next
)
654 gchar
*file
= slist
->data
;
655 gint fd
= open (file
, O_RDONLY
);
659 g_warning ("failed to open \"%s\": %s", file
, g_strerror (errno
));
664 /* set file name for error reports */
665 scanner
->input_name
= file
;
667 /* parse & process file */
668 g_scanner_input_file (scanner
, fd
);
670 /* scanning loop, we parse the input untill it's end is reached,
671 * or our sub routine came across invalid syntax
675 guint expected_token
= G_TOKEN_NONE
;
677 switch (g_scanner_peek_next_token (scanner
))
680 /* eat newline and restart */
681 g_scanner_get_next_token (scanner
);
687 /* parse and process signatures */
689 Signature signature
= { NULL
, NULL
, NULL
};
692 expected_token
= parse_line (scanner
, &signature
);
694 /* once we got a valid signature, process it */
695 if (expected_token
== G_TOKEN_NONE
)
696 process_signature (&signature
);
698 /* clean up signature contents */
699 g_free (signature
.ploc
);
701 g_free (signature
.rarg
->keyword
);
702 g_free (signature
.rarg
);
703 for (node
= signature
.args
; node
; node
= node
->next
)
705 InArgument
*iarg
= node
->data
;
707 g_free (iarg
->keyword
);
710 g_list_free (signature
.args
);
715 /* bail out on errors */
716 if (expected_token
!= G_TOKEN_NONE
)
718 g_scanner_unexp_token (scanner
, expected_token
, "type name", NULL
, NULL
, NULL
, TRUE
);
723 g_scanner_peek_next_token (scanner
);
725 while (scanner
->next_token
!= G_TOKEN_EOF
);
730 /* put out trailer */
733 g_fprintf (fout
, "\nG_END_DECLS\n");
736 g_fprintf (fout
, "\n#endif /* __%s_MARSHAL_H__ */\n", marshaller_prefix
);
738 g_fprintf (fout
, "\n");
741 g_slist_free (files
);
742 g_scanner_destroy (scanner
);
743 g_hash_table_foreach_remove (marshallers
, string_key_destroy
, NULL
);
744 g_hash_table_destroy (marshallers
);
750 parse_args (gint
*argc_p
,
753 guint argc
= *argc_p
;
754 gchar
**argv
= *argv_p
;
757 for (i
= 1; i
< argc
; i
++)
759 if (strcmp ("--header", argv
[i
]) == 0)
764 else if (strcmp ("--body", argv
[i
]) == 0)
769 else if (strcmp ("--skip-source", argv
[i
]) == 0)
774 else if (strcmp ("--nostdinc", argv
[i
]) == 0)
776 std_includes
= FALSE
;
779 else if (strcmp ("--stdinc", argv
[i
]) == 0)
784 else if ((strcmp ("--prefix", argv
[i
]) == 0) ||
785 (strncmp ("--prefix=", argv
[i
], 9) == 0))
787 gchar
*equal
= argv
[i
] + 8;
790 marshaller_prefix
= g_strdup (equal
+ 1);
791 else if (i
+ 1 < argc
)
793 marshaller_prefix
= g_strdup (argv
[i
+ 1]);
799 else if (strcmp ("-h", argv
[i
]) == 0 ||
800 strcmp ("--help", argv
[i
]) == 0)
802 print_blurb (stderr
, TRUE
);
806 else if (strcmp ("-v", argv
[i
]) == 0 ||
807 strcmp ("--version", argv
[i
]) == 0)
809 print_blurb (stderr
, FALSE
);
813 else if (strcmp (argv
[i
], "--g-fatal-warnings") == 0)
815 GLogLevelFlags fatal_mask
;
817 fatal_mask
= g_log_set_always_fatal (G_LOG_FATAL_MASK
);
818 fatal_mask
|= G_LOG_LEVEL_WARNING
| G_LOG_LEVEL_CRITICAL
;
819 g_log_set_always_fatal (fatal_mask
);
826 for (i
= 1; i
< argc
; i
++)
844 print_blurb (FILE *bout
,
849 g_fprintf (bout
, "%s version ", PRG_NAME
);
850 g_fprintf (bout
, "%u.%u.%u", GLIB_MAJOR_VERSION
, GLIB_MINOR_VERSION
, GLIB_MICRO_VERSION
);
851 g_fprintf (bout
, "\n");
852 g_fprintf (bout
, "%s comes with ABSOLUTELY NO WARRANTY.\n", PRG_NAME
);
853 g_fprintf (bout
, "You may redistribute copies of %s under the terms of\n", PRG_NAME
);
854 g_fprintf (bout
, "the GNU General Public License which can be found in the\n");
855 g_fprintf (bout
, "%s source package. Sources, examples and contact\n", PKG_NAME
);
856 g_fprintf (bout
, "information are available at %s\n", PKG_HTTP_HOME
);
860 g_fprintf (bout
, "Usage: %s [options] [files...]\n", PRG_NAME
);
861 g_fprintf (bout
, " --header generate C headers\n");
862 g_fprintf (bout
, " --body generate C code\n");
863 g_fprintf (bout
, " --prefix=string specify marshaller prefix\n");
864 g_fprintf (bout
, " --skip-source skip source location comments\n");
865 g_fprintf (bout
, " --stdinc, --nostdinc include/use standard marshallers\n");
866 g_fprintf (bout
, " -h, --help show this help message\n");
867 g_fprintf (bout
, " -v, --version print version informations\n");
868 g_fprintf (bout
, " --g-fatal-warnings make warnings fatal (abort)\n");