dbus/glib dbus-glib-tool.c, 1.9, 1.10 dbus-binding-tool-glib.c, 1.2,
1.3
Colin Walters
walters at freedesktop.org
Sat Feb 19 15:25:43 PST 2005
Update of /cvs/dbus/dbus/glib
In directory gabe:/tmp/cvs-serv30457/glib
Modified Files:
dbus-glib-tool.c dbus-binding-tool-glib.c
Log Message:
2005-02-19 Colin Walters <walters at verbum.org>
* glib/dbus-binding-tool-glib.c
(dbus_binding_tool_output_glib_server): Fix iochannel refcounting.
* glib/dbus-glib-tool.c: Include dbus-glib-tool.h, as well
as errno.h and sys/stat.h.
(lose): New function, prints error with
newline and exits.
(lose_gerror): Similar, but takes GError for message.
(main): Add --output argument to specify output file to write to,
instead of always printing to stdout. In this mode, determine
timestamps on source files to see whether any are newer than the
target file. If not, exit. Also convert a number of error
messages to use lose (since it's shorter), and switch to using
g_io_channel_shutdown.
Index: dbus-glib-tool.c
===================================================================
RCS file: /cvs/dbus/dbus/glib/dbus-glib-tool.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- dbus-glib-tool.c 17 Feb 2005 21:11:18 -0000 1.9
+++ dbus-glib-tool.c 19 Feb 2005 23:25:41 -0000 1.10
@@ -25,6 +25,7 @@
#include "dbus-gidl.h"
#include "dbus-gparser.h"
#include "dbus-gutils.h"
+#include "dbus-glib-tool.h"
#include "dbus-binding-tool-glib.h"
#include <locale.h>
#include <libintl.h>
@@ -32,6 +33,8 @@
#define N_(x) x
#include <stdio.h>
#include <stdlib.h>
+#include <errno.h>
+#include <sys/stat.h>
#include <string.h>
#ifdef DBUS_BUILD_TESTS
@@ -215,6 +218,30 @@
return quark;
}
+static void lose (const char *fmt, ...) G_GNUC_NORETURN G_GNUC_PRINTF (1, 2);
+static void lose_gerror (const char *prefix, GError *error) G_GNUC_NORETURN;
+
+static void
+lose (const char *str, ...)
+{
+ va_list args;
+
+ va_start (args, str);
+
+ vfprintf (stderr, str, args);
+ fputc ('\n', stderr);
+
+ va_end (args);
+
+ exit (1);
+}
+
+static void
+lose_gerror (const char *prefix, GError *error)
+{
+ lose ("%s: %s", prefix, error->message);
+}
+
static void
usage (int ecode)
{
@@ -237,6 +264,8 @@
main (int argc, char **argv)
{
const char *prev_arg;
+ const char *output_file;
+ char *output_file_tmp;
int i;
GSList *files;
DBusBindingOutputMode outputmode;
@@ -244,6 +273,10 @@
GSList *tmp;
GIOChannel *channel;
GError *error;
+ time_t newest_src;
+ struct stat srcbuf;
+ struct stat targetbuf;
+ gboolean force;
setlocale (LC_ALL, "");
bindtextdomain (GETTEXT_PACKAGE, DBUS_LOCALEDIR);
@@ -256,6 +289,8 @@
end_of_args = FALSE;
files = NULL;
prev_arg = NULL;
+ output_file = NULL;
+ force = FALSE;
i = 1;
while (i < argc)
{
@@ -269,6 +304,8 @@
usage (0);
else if (strcmp (arg, "--version") == 0)
version ();
+ else if (strcmp (arg, "--force") == 0)
+ force = TRUE;
#ifdef DBUS_BUILD_TESTS
else if (strcmp (arg, "--self-test") == 0)
run_all_tests (NULL);
@@ -285,6 +322,10 @@
else
usage (1);
}
+ else if (strncmp (arg, "--output=", 9) == 0)
+ {
+ output_file = arg + 9;
+ }
else if (arg[0] == '-' &&
arg[1] == '-' &&
arg[2] == '\0')
@@ -307,18 +348,45 @@
}
error = NULL;
- channel = g_io_channel_unix_new (fileno (stdout));
- if (!g_io_channel_set_encoding (channel, NULL, &error))
+
+ files = g_slist_reverse (files);
+
+ if (output_file && !force)
{
- fprintf (stderr, _("Couldn't set channel encoding to NULL: %s\n"),
- error->message);
- exit (1);
+ newest_src = 0;
+ for (tmp = files; tmp != NULL; tmp = tmp->next)
+ {
+ const char *filename;
+
+ filename = tmp->data;
+ if (stat (filename, &srcbuf) < 0)
+ lose ("Couldn't stat %s: %s", filename, g_strerror (errno));
+
+ if (srcbuf.st_mtime > newest_src)
+ newest_src = srcbuf.st_mtime;
+ }
+
+ if (stat (output_file, &targetbuf) > 0
+ && targetbuf.st_mtime >= newest_src)
+ exit (0);
}
+
+ if (output_file)
+ {
+ output_file_tmp = g_strconcat (output_file, ".tmp", NULL);
- files = g_slist_reverse (files);
+ if (!(channel = g_io_channel_new_file (output_file_tmp, "w", &error)))
+ lose_gerror (_("Couldn't open temporary file"), error);
+ }
+ else
+ {
+ channel = g_io_channel_unix_new (fileno (stdout));
+ }
+ if (!g_io_channel_set_encoding (channel, NULL, &error))
+ lose_gerror (_("Couldn't set channel encoding to NULL"), error);
- tmp = files;
- while (tmp != NULL)
+
+ for (tmp = files; tmp != NULL; tmp = tmp->next)
{
NodeInfo *node;
GError *error;
@@ -331,11 +399,7 @@
&error);
if (node == NULL)
{
- g_assert (error != NULL);
- fprintf (stderr, _("Unable to load \"%s\": %s\n"),
- filename, error->message);
- g_error_free (error);
- exit (1);
+ lose_gerror (_("Unable to load \"%s\""), error);
}
else
{
@@ -346,17 +410,11 @@
break;
case DBUS_BINDING_OUTPUT_GLIB_SERVER:
if (!dbus_binding_tool_output_glib_server ((BaseInfo *) node, channel, &error))
- {
- g_error (_("Compilation failed: %s\n"), error->message);
- exit (1);
- }
+ lose_gerror (_("Compilation failed"), error);
break;
case DBUS_BINDING_OUTPUT_GLIB_CLIENT:
if (!dbus_binding_tool_output_glib_client ((BaseInfo *) node, channel, &error))
- {
- g_error (_("Compilation failed: %s\n"), error->message);
- exit (1);
- }
+ lose_gerror (_("Compilation failed"), error);
break;
case DBUS_BINDING_OUTPUT_NONE:
break;
@@ -365,16 +423,20 @@
if (node)
node_info_unref (node);
-
- tmp = tmp->next;
}
- if (!g_io_channel_flush (channel, &error))
+ if (g_io_channel_shutdown (channel, TRUE, &error) != G_IO_STATUS_NORMAL)
+ lose_gerror (_("Failed to shutdown IO channel"), error);
+ g_io_channel_unref (channel);
+
+ if (output_file)
{
- g_error (_("Failed to flush IO channel: %s"), error->message);
- exit (1);
+ if (rename (output_file_tmp, output_file) < 0)
+ lose ("Failed to rename %s to %s: %s", output_file_tmp, output_file,
+ g_strerror (errno));
+ g_free (output_file_tmp);
}
-
+
return 0;
}
@@ -383,8 +445,7 @@
static void
test_die (const char *failure)
{
- fprintf (stderr, "Unit test failed: %s\n", failure);
- exit (1);
+ lose ("Unit test failed: %s", failure);
}
/**
Index: dbus-binding-tool-glib.c
===================================================================
RCS file: /cvs/dbus/dbus/glib/dbus-binding-tool-glib.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dbus-binding-tool-glib.c 17 Feb 2005 21:11:18 -0000 1.2
+++ dbus-binding-tool-glib.c 19 Feb 2005 23:25:41 -0000 1.3
@@ -527,8 +527,8 @@
WRITE_OR_LOSE ("#include <dbus/dbus-glib.h>\n");
- g_io_channel_ref (data.channel);
data.channel = channel;
+ g_io_channel_ref (data.channel);
if (!generate_glue (info, &data, error))
goto io_lose;
More information about the dbus-commit
mailing list