Permalink
Browse files

Automake stuffs

git-svn-id: http://svn.nickg.me.uk/work/xcowsay@271 a97b1542-0b21-0410-a459-e47997c36f34
  • Loading branch information...
1 parent e674fe5 commit eb723b50bdafc4e108bbfe95a355567ad7881333 nick committed Feb 6, 2008
Showing with 98 additions and 13 deletions.
  1. 0 AUTHORS
  2. +1 −0 COPYING
  3. 0 ChangeLog
  4. +1 −0 INSTALL
  5. +10 −0 Makefile.am
  6. 0 Makefile → Makefile.old
  7. 0 NEWS
  8. 0 README
  9. +22 −0 config.h.in
  10. +12 −0 configure.ac
  11. +4 −2 display_cow.c
  12. +1 −1 display_cow.h
  13. +47 −10 xcowsay.c
View
No changes.
View
View
No changes.
View
View
@@ -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
File renamed without changes.
View
0 NEWS
No changes.
View
0 README
No changes.
View
@@ -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
View
@@ -0,0 +1,12 @@
+AC_INIT([xcowsay], [0.2],
+ [Nick Gasson <nick.gasson@yahoo.co.uk>],
+ [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)
View
@@ -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;
View
@@ -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
View
@@ -1,18 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
+#include <getopt.h>
#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");

0 comments on commit eb723b5

Please sign in to comment.