From eb723b50bdafc4e108bbfe95a355567ad7881333 Mon Sep 17 00:00:00 2001 From: nick Date: Wed, 6 Feb 2008 14:03:18 +0000 Subject: [PATCH] Automake stuffs git-svn-id: http://svn.nickg.me.uk/work/xcowsay@271 a97b1542-0b21-0410-a459-e47997c36f34 --- AUTHORS | 0 COPYING | 1 + ChangeLog | 0 INSTALL | 1 + Makefile.am | 10 +++++++ Makefile => Makefile.old | 0 NEWS | 0 README | 0 config.h.in | 22 ++++++++++++++++ configure.ac | 12 +++++++++ display_cow.c | 6 +++-- display_cow.h | 2 +- xcowsay.c | 57 +++++++++++++++++++++++++++++++++------- 13 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 AUTHORS create mode 120000 COPYING create mode 100644 ChangeLog create mode 120000 INSTALL create mode 100644 Makefile.am rename Makefile => Makefile.old (100%) create mode 100644 NEWS create mode 100644 README create mode 100644 config.h.in create mode 100644 configure.ac diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..e69de29 diff --git a/COPYING b/COPYING new file mode 120000 index 0000000..0b6cbf8 --- /dev/null +++ b/COPYING @@ -0,0 +1 @@ +/usr/share/automake-1.10/COPYING \ No newline at end of file diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 diff --git a/INSTALL b/INSTALL new file mode 120000 index 0000000..5bb6e7b --- /dev/null +++ b/INSTALL @@ -0,0 +1 @@ +/usr/share/automake-1.10/INSTALL \ No newline at end of file diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..d7f55ef --- /dev/null +++ b/Makefile.am @@ -0,0 +1,10 @@ +bin_PROGRAMS = xcowsay + +xcowsay_CFLAGS = $(XCOWSAY_CFLAGS) +xcowsay_LDADD = $(XCOWSAY_LIBS) + +xcowsay_SOURCES = xcowsay.c display_cow.c display_cow.h floating_shape.h \ + floating_shape.c settings.h settings.c + +dist_pkgdata_DATA = cow_small.png cow_med.png cow_large.png +EXTRA_DIST = cow.svg \ No newline at end of file diff --git a/Makefile b/Makefile.old similarity index 100% rename from Makefile rename to Makefile.old diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..e69de29 diff --git a/README b/README new file mode 100644 index 0000000..e69de29 diff --git a/config.h.in b/config.h.in new file mode 100644 index 0000000..c364eda --- /dev/null +++ b/config.h.in @@ -0,0 +1,22 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Version number of package */ +#undef VERSION diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..6937fea --- /dev/null +++ b/configure.ac @@ -0,0 +1,12 @@ +AC_INIT([xcowsay], [0.2], + [Nick Gasson ], + [xcowsay]) +AM_INIT_AUTOMAKE([-Wall]) +AC_PROG_CC +AC_PROG_INSTALL + +# Check for pkg-config packages +PKG_CHECK_MODULES(XCOWSAY, gtk+-2.0) + +AC_CONFIG_HEADERS([config.h]) +AC_OUTPUT(Makefile) diff --git a/display_cow.c b/display_cow.c index 1b0e0dc..87b904e 100644 --- a/display_cow.c +++ b/display_cow.c @@ -75,7 +75,7 @@ static GdkPixbuf *create_bubble(char *text) PangoContext *pango_context = gdk_pango_context_get(); PangoLayout *layout = pango_layout_new(pango_context); PangoFontDescription *font = - pango_font_description_from_string("Bitstream Vera Sans 14"); + pango_font_description_from_string(get_string_option("font")); PangoAttrList *pango_attrs = NULL; char *stripped; @@ -246,8 +246,10 @@ static gboolean tick(gpointer data) return TRUE; } -void cowsay_init(void) +void cowsay_init(int *argc, char ***argv) { + gtk_init(argc, argv); + xcowsay.cow = NULL; xcowsay.bubble = NULL; xcowsay.bubble_pixbuf = NULL; diff --git a/display_cow.h b/display_cow.h index cc88122..14cc85e 100644 --- a/display_cow.h +++ b/display_cow.h @@ -6,6 +6,6 @@ // Show a cow with the given string and clean up afterwards void display_cow(const char *text); -void cowsay_init(void); +void cowsay_init(int *argc, char ***argv); #endif diff --git a/xcowsay.c b/xcowsay.c index 422404a..9185b76 100644 --- a/xcowsay.c +++ b/xcowsay.c @@ -1,18 +1,26 @@ #include #include #include +#include #include "display_cow.h" #include "settings.h" // Default settings -#define DEF_LEAD_IN_TIME 250 -#define DEF_DISPLAY_TIME 4000 -#define DEF_LEAD_OUT_TIME LEAD_IN_TIME +#define DEF_LEAD_IN_TIME 250 +#define DEF_DISPLAY_TIME 4000 +#define DEF_LEAD_OUT_TIME LEAD_IN_TIME +#define DEF_FONT "Bitstream Vera Sans 14" #define MAX_STDIN 4096 // Maximum chars to read from stdin +static struct option long_options[] = { + {"help", no_argument, 0, 'h'}, + {"time", required_argument, 0, 't'}, + {0, 0, 0, 0} +}; + static void read_from_stdin(void) { char *data = malloc(MAX_STDIN); @@ -27,23 +35,52 @@ static void read_from_stdin(void) free(data); } -int main(int argc, char **argv) +static void usage() { + static const char *usage_message = + "Usage: xcowsay [OPTION] [MESSAGE]\n" + "Display a cow on your desktop with [MESSAGE] or standard input.\n\n" + "Options:\n" + " -h, --help\t\tDisplay this message and exit.\n" + " -t, --time SECONDS\tDisplay message for SECONDS seconds.\n"; + puts(usage_message); +} + +int main(int argc, char **argv) +{ add_int_option("lead_in_time", DEF_LEAD_IN_TIME); add_int_option("display_time", DEF_DISPLAY_TIME); add_int_option("lead_out_time", get_int_option("lead_in_time")); + add_string_option("font", DEF_FONT); - srand((unsigned)time(NULL)); + cowsay_init(&argc, &argv); - gtk_init(&argc, &argv); + int c, option_index = 0, failure = 0; + while ((c = getopt_long(argc, argv, "h", long_options, &option_index)) != -1) { + switch (c) { + case 'h': + usage(); + exit(EXIT_SUCCESS); + case 't': + break; + case '?': + // getopt_long already printed an error message + failure = 1; + break; + default: + abort(); + } + } + if (failure) + exit(EXIT_FAILURE); - cowsay_init(); + srand((unsigned)time(NULL)); - if (argc == 1) { + if (optind == argc) { read_from_stdin(); } - else if (argc == 2) { - display_cow(argv[1]); + else if (optind == argc - 1) { + display_cow(argv[optind]); } else { fprintf(stderr, "Error: Too many arguments\n"); -- 2.39.2