X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fnoseguy.c;h=594d7462e3d3b961e5a1713a6fcceafe9fef4b89;hb=0d6b320def9180cf907ceaed56b23a972a11b757;hp=9ea9f4e54204247a6b4c8ce8475b46c0283e802c;hpb=f65151994eba80ecabcdac6eef6fa0dde7e2d45b;p=xscreensaver diff --git a/hacks/noseguy.c b/hacks/noseguy.c index 9ea9f4e5..594d7462 100644 --- a/hacks/noseguy.c +++ b/hacks/noseguy.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992, 1996, 1997, 1998 +/* xscreensaver, Copyright (c) 1992, 1996, 1997, 1998, 2005 * Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its @@ -11,10 +11,12 @@ */ /* Make a little guy with a big nose and a hat wanter around the screen, - spewing out messages. Derived from xnlock by Dan Heller . + spewing out messages. Derived from xnlock by + Dan Heller . */ #include "screenhack.h" +#include "xpm-pixmap.h" #include extern FILE *popen (const char *, const char *); @@ -31,7 +33,6 @@ static char *words; static char *get_words (void); static int x, y; static XFontStruct *font; -static char *def_words = "I'm out running around."; static void walk (int dir); static void talk (int erase); static void talk_1 (void); @@ -47,7 +48,6 @@ static char *program, *orig_program, *filename, *text; #define FROM_PROGRAM 2 #define FROM_FILE 3 #define FROM_RESRC 4 -static int getwordsfrom; #define IS_MOVING 1 #define GET_PASSWD 2 @@ -55,9 +55,7 @@ static int state; /* indicates states: walking or getting passwd */ static void (*next_fn) (void); -#ifdef HAVE_XPM -# include - +#if defined(HAVE_GDK_PIXBUF) || defined(HAVE_XPM) # include "images/noseguy/nose-f1.xpm" # include "images/noseguy/nose-f2.xpm" # include "images/noseguy/nose-f3.xpm" @@ -85,41 +83,19 @@ init_images (void) &left_front, &right_front, &front, &down }; int i; -#ifdef HAVE_XPM +#if defined(HAVE_GDK_PIXBUF) || defined(HAVE_XPM) + static char **bits[] = { nose_l1_xpm, nose_l2_xpm, nose_r1_xpm, nose_r2_xpm, nose_f2_xpm, nose_f3_xpm, nose_f1_xpm, nose_f4_xpm }; + + for (i = 0; i < sizeof (images) / sizeof(*images); i++) { - XWindowAttributes xgwa; - XpmAttributes xpmattrs; - Pixmap pixmap = 0; - int result; - xpmattrs.valuemask = 0; - - XGetWindowAttributes (dpy, window, &xgwa); - -# ifdef XpmCloseness - xpmattrs.valuemask |= XpmCloseness; - xpmattrs.closeness = 40000; -# endif -# ifdef XpmVisual - xpmattrs.valuemask |= XpmVisual; - xpmattrs.visual = xgwa.visual; -# endif -# ifdef XpmDepth - xpmattrs.valuemask |= XpmDepth; - xpmattrs.depth = xgwa.depth; -# endif -# ifdef XpmColormap - xpmattrs.valuemask |= XpmColormap; - xpmattrs.colormap = xgwa.colormap; -# endif - - result = XpmCreatePixmapFromData(dpy, window, bits[i], - &pixmap, 0 /* mask */, &xpmattrs); - if (!pixmap || (result != XpmSuccess && result != XpmColorError)) + Pixmap pixmap = xpm_data_to_pixmap (dpy, window, bits[i], + 0, 0, 0); + if (!pixmap) { fprintf (stderr, "%s: Can't load nose images\n", progname); exit (1); @@ -310,14 +286,17 @@ think (void) walk(FRONT); if (random() & 1) { - if (getwordsfrom == FROM_PROGRAM) - words = get_words(); - return 1; + words = get_words(); + return 1; } return 0; } -#define MAXLINES 40 +#define MAXLINES 25 + +#undef BUFSIZ +#define BUFSIZ ((MAXLINES + 1) * 100) + static void talk(int force_erase) @@ -365,6 +344,9 @@ talk(int force_erase) walk(FRONT); p = strcpy(buf, words); + for (p2 = p; *p2; p2++) + if (*p2 == '\t') *p2 = ' '; + if (!(p2 = strchr(p, '\n')) || !p2[1]) { total = strlen (words); @@ -385,7 +367,7 @@ talk(int force_erase) (void) strcpy(args[height], p); if (height == MAXLINES - 1) { - puts("Message too long!"); + /* puts("Message too long!"); */ break; } p = p2 + 1; @@ -470,8 +452,6 @@ look (void) static void init_words (void) { - char *mode = get_string_resource ("mode", "Mode"); - program = get_string_resource ("program", "Program"); filename = get_string_resource ("filename", "Filename"); text = get_string_resource ("text", "Text"); @@ -485,31 +465,6 @@ init_words (void) strcat (program, " ) 2>&1"); } - if (!mode || !strcmp (mode, "program")) - getwordsfrom = FROM_PROGRAM; - else if (!strcmp (mode, "file")) - getwordsfrom = FROM_FILE; - else if (!strcmp (mode, "string")) - getwordsfrom = FROM_RESRC; - else - { - fprintf (stderr, - "%s: mode must be program, file, or string, not %s\n", - progname, mode); - exit (1); - } - - if (getwordsfrom == FROM_PROGRAM && !program) - { - fprintf (stderr, "%s: no program specified.\n", progname); - exit (1); - } - if (getwordsfrom == FROM_FILE && !filename) - { - fprintf (stderr, "%s: no file specified.\n", progname); - exit (1); - } - words = get_words(); } @@ -524,10 +479,6 @@ get_words (void) buf[0] = '\0'; - switch (getwordsfrom) - { - case FROM_PROGRAM: -#ifndef VMS if ((pp = popen(program, "r"))) { while (fgets(p, sizeof(buf) - strlen(buf), pp)) @@ -542,7 +493,9 @@ get_words (void) sprintf (buf, "\"%s\" produced no output!", orig_program); else if (!first_time && (strstr (buf, ": not found") || - strstr (buf, ": Not found"))) + strstr (buf, ": Not found") || + strstr (buf, ": command not found") || + strstr (buf, ": Command not found"))) switch (random () % 20) { case 1: strcat (buf, "( Get with the program, bub. )\n"); @@ -567,41 +520,8 @@ get_words (void) else { perror(program); - p = def_words; - } - break; -#endif /* VMS */ - case FROM_FILE: - if ((pp = fopen(filename, "r"))) - { - while (fgets(p, sizeof(buf) - strlen(buf), pp)) - { - if (strlen(buf) + 1 < sizeof(buf)) - p = buf + strlen(buf); - else - break; - } - (void) fclose(pp); - if (! buf[0]) - sprintf (buf, "file \"%s\" is empty!", filename); - p = buf; } - else - { - sprintf (buf, "couldn't read file \"%s\"!", filename); - p = buf; - } - break; - case FROM_RESRC: - p = text; - break; - default: - p = def_words; - break; - } - if (!p || *p == '\0') - p = def_words; return p; } @@ -610,15 +530,10 @@ get_words (void) char *progclass = "Noseguy"; char *defaults [] = { - ".background: black", - ".foreground: gray80", -#ifndef VMS - "*mode: program", -#else - "*mode: string", -#endif - "*program: " ZIPPY_PROGRAM, - "noseguy.font: -*-new century schoolbook-*-r-*-*-*-180-*-*-*-*-*-*", + ".background: black", + ".foreground: gray80", + "*program: xscreensaver-text --cols 40 | head -n15", + "noseguy.font: -*-new century schoolbook-*-r-*-*-*-180-*-*-*-*-*-*", 0 };