Skip to content

Commit

Permalink
Release xcowsay 0.3.1
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.nickg.me.uk/work/xcowsay@276 a97b1542-0b21-0410-a459-e47997c36f34
  • Loading branch information
nick committed Feb 15, 2008
1 parent 1c04c23 commit 2505d96
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 18 deletions.
1 change: 0 additions & 1 deletion COPYING

This file was deleted.

1 change: 0 additions & 1 deletion INSTALL

This file was deleted.

2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bin_PROGRAMS = xcowsay
bin_SCRIPTS = xcowat xcowsend
bin_SCRIPTS = xcowat xcowfortune

AM_CFLAGS = $(XCOWSAY_CFLAGS) -DDATADIR=\"$(pkgdatadir)\"
LDADD = $(XCOWSAY_LIBS)
Expand Down
3 changes: 0 additions & 3 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
/* Define to 1 if you have the <inttypes.h> 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
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([xcowsay], [0.2.1],
AC_INIT([xcowsay], [0.3.1],
[Nick Gasson <nick.gasson@yahoo.co.uk>],
[xcowsay])
AM_INIT_AUTOMAKE([-Wall])
Expand Down
57 changes: 57 additions & 0 deletions display_cow.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
#include <gtk/gtk.h>
#include <gtk/gtkwindow.h>

#ifndef WITHOUT_DBUS
#include <dbus/dbus-glib-bindings.h>
#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"
Expand Down Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions display_cow.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#ifndef INC_DISPLAY_COW_H
#define INC_DISPLAY_COW_H

#include <stdbool.h>

#include <gtk/gtk.h>
#include <gtk/gtkwindow.h>

// 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
6 changes: 3 additions & 3 deletions settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ typedef enum {
typedef union {
int ival;
bool bval;
const char *sval;
char *sval;
} option_value_t;

typedef struct {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
8 changes: 7 additions & 1 deletion xcowat
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions xcowsay.c
Original file line number Diff line number Diff line change
Expand Up @@ -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}
};

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion xcowsayd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 0 additions & 1 deletion xcowsend

This file was deleted.

0 comments on commit 2505d96

Please sign in to comment.