From 2505d967b5ac796c935678545504313dca6f519d Mon Sep 17 00:00:00 2001 From: nick Date: Fri, 15 Feb 2008 00:24:15 +0000 Subject: [PATCH] Release xcowsay 0.3.1 git-svn-id: http://svn.nickg.me.uk/work/xcowsay@276 a97b1542-0b21-0410-a459-e47997c36f34 --- COPYING | 1 - INSTALL | 1 - Makefile.am | 2 +- config.h.in | 3 --- configure.ac | 2 +- display_cow.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ display_cow.h | 3 +++ settings.c | 6 +++--- xcowat | 8 +++++++- xcowsay.c | 10 ++++----- xcowsayd.c | 2 +- xcowsend | 1 - 12 files changed, 78 insertions(+), 18 deletions(-) delete mode 120000 COPYING delete mode 120000 INSTALL delete mode 100755 xcowsend diff --git a/COPYING b/COPYING deleted file mode 120000 index 7153769..0000000 --- a/COPYING +++ /dev/null @@ -1 +0,0 @@ -/usr/share/automake-1.9/COPYING \ No newline at end of file diff --git a/INSTALL b/INSTALL deleted file mode 120000 index 81fa6ff..0000000 --- a/INSTALL +++ /dev/null @@ -1 +0,0 @@ -/usr/share/automake-1.9/INSTALL \ No newline at end of file diff --git a/Makefile.am b/Makefile.am index c8efb53..83b1b7c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ bin_PROGRAMS = xcowsay -bin_SCRIPTS = xcowat xcowsend +bin_SCRIPTS = xcowat xcowfortune AM_CFLAGS = $(XCOWSAY_CFLAGS) -DDATADIR=\"$(pkgdatadir)\" LDADD = $(XCOWSAY_LIBS) diff --git a/config.h.in b/config.h.in index 6ac0f7f..3de8d60 100644 --- a/config.h.in +++ b/config.h.in @@ -3,9 +3,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H -/* Define to 1 if you have the `getopt' library (-lgetopt). */ -#undef HAVE_LIBGETOPT - /* Define to 1 if your system has a GNU libc compatible `malloc' function, and to 0 otherwise. */ #undef HAVE_MALLOC diff --git a/configure.ac b/configure.ac index 5c2fe2f..af91519 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([xcowsay], [0.2.1], +AC_INIT([xcowsay], [0.3.1], [Nick Gasson ], [xcowsay]) AM_INIT_AUTOMAKE([-Wall]) diff --git a/display_cow.c b/display_cow.c index 19ecabb..71f0f09 100644 --- a/display_cow.c +++ b/display_cow.c @@ -6,6 +6,12 @@ #include #include +#ifndef WITHOUT_DBUS +#include +#define XCOWSAY_PATH "/uk/me/doof/Cowsay" +#define XCOWSAY_NAMESPACE "uk.me.doof.Cowsay" +#endif + #include "floating_shape.h" #include "display_cow.h" #include "settings.h" @@ -308,3 +314,54 @@ void display_cow(const char *text) g_object_unref(xcowsay.bubble_pixbuf); xcowsay.bubble_pixbuf = NULL; } + +#ifdef WITHOUT_DBUS + +bool try_dbus(bool debug, const char *text) +{ + if (debug) + printf("Skipping DBus (disabled by configure)\n"); + return false; +} + +#else + +bool try_dbus(bool debug, const char *text) +{ + DBusGConnection *connection; + GError *error; + DBusGProxy *proxy; + + g_type_init(); + error = NULL; + connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (NULL == connection) { + if (debug) + g_printerr("Failed to open connection to bus: %s\n", error->message); + g_error_free(error); + return false; + } + + proxy = dbus_g_proxy_new_for_name(connection, XCOWSAY_NAMESPACE, + XCOWSAY_PATH, XCOWSAY_NAMESPACE); + g_assert(proxy); + + error = NULL; + if (!dbus_g_proxy_call(proxy, "ShowCow", &error, G_TYPE_STRING, text, + G_TYPE_INVALID, G_TYPE_INVALID)) { + if (debug) + g_printerr("ShowCow failed: %s\n", error->message); + g_error_free(error); + return false; + } + + return true; +} + +#endif /* #ifdef WITHOUT_DBUS */ + +void display_cow_or_invoke_daemon(bool debug, const char *text) +{ + if (!try_dbus(debug, text)) + display_cow(text); +} diff --git a/display_cow.h b/display_cow.h index 14cc85e..db9b23c 100644 --- a/display_cow.h +++ b/display_cow.h @@ -1,11 +1,14 @@ #ifndef INC_DISPLAY_COW_H #define INC_DISPLAY_COW_H +#include + #include #include // Show a cow with the given string and clean up afterwards void display_cow(const char *text); +void display_cow_or_invoke_daemon(bool debug, const char *text); void cowsay_init(int *argc, char ***argv); #endif diff --git a/settings.c b/settings.c index 057f711..62449aa 100644 --- a/settings.c +++ b/settings.c @@ -10,7 +10,7 @@ typedef enum { typedef union { int ival; bool bval; - const char *sval; + char *sval; } option_value_t; typedef struct { @@ -114,7 +114,7 @@ void add_bool_option(const char *name, bool bval) add_option(name, optBool, u); } -static const char *copy_string(const char *s) +static char *copy_string(const char *s) { char *copy = malloc(strlen(s)+1); strcpy(copy, s); @@ -147,5 +147,5 @@ void set_string_option(const char *name, const char *sval) option_t *opt = get_option(name); assert_string(opt); free(opt->u.sval); - opt->u.sval = sval; + opt->u.sval = copy_string(sval); } diff --git a/xcowat b/xcowat index 1e845bb..33209e1 100755 --- a/xcowat +++ b/xcowat @@ -1 +1,7 @@ -echo "dbus-send --dest=uk.me.doof.Cowsay /uk/me/doof/Cowsay uk.me.doof.Cowsay.ShowCow string:\"$2\"" | at $1 +#!/bin/sh + +# +# Run xcowsay at the specified time using atd +# + +echo "xcowsay \"$2\"" | at $1 diff --git a/xcowsay.c b/xcowsay.c index df7082a..dc7c62d 100644 --- a/xcowsay.c +++ b/xcowsay.c @@ -16,14 +16,14 @@ #define MAX_STDIN 4096 // Maximum chars to read from stdin static int daemon_flag = 0; -static int daemon_debug = 0; +static int debug = 0; static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"time", required_argument, 0, 't'}, {"font", required_argument, 0, 'f'}, {"daemon", no_argument, &daemon_flag, 1}, - {"debug", no_argument, &daemon_debug, 1}, + {"debug", no_argument, &debug, 1}, {0, 0, 0, 0} }; @@ -37,7 +37,7 @@ static void read_from_stdin(void) } data[n] = '\0'; - display_cow(data); + display_cow_or_invoke_daemon(debug, data); free(data); } @@ -107,7 +107,7 @@ int main(int argc, char **argv) srand((unsigned)time(NULL)); if (daemon_flag) { - run_cowsay_daemon(daemon_debug, argc, argv); + run_cowsay_daemon(debug, argc, argv); } else { cowsay_init(&argc, &argv); @@ -116,7 +116,7 @@ int main(int argc, char **argv) read_from_stdin(); } else if (optind == argc - 1) { - display_cow(argv[optind]); + display_cow_or_invoke_daemon(debug, argv[optind]); } else { fprintf(stderr, "Error: Too many arguments\n"); diff --git a/xcowsayd.c b/xcowsayd.c index bffc954..8eb3313 100644 --- a/xcowsayd.c +++ b/xcowsayd.c @@ -225,7 +225,7 @@ void run_cowsay_daemon(bool debug, int argc, char **argv) #else /* #ifndef WITHOUT_DBUS */ -void run_cowsay_daemon(bool debug) +void run_cowsay_daemon(bool debug, int argc, char **argv) { fprintf(stderr, "Error: Daemon mode unavailable as xcowsay was compiled " "without DBus support.\n"); diff --git a/xcowsend b/xcowsend deleted file mode 100755 index b09af18..0000000 --- a/xcowsend +++ /dev/null @@ -1 +0,0 @@ -exec dbus-send --dest=uk.me.doof.Cowsay /uk/me/doof/Cowsay uk.me.doof.Cowsay.ShowCow string:"$*" -- 2.39.2