~ubuntu-branches/ubuntu/dapper/xscreensaver/dapper

« back to all changes in this revision

Viewing changes to hacks/noseguy.c

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2005-10-11 21:00:42 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20051011210042-u7q6zslgevdxspr3
Tags: 4.21-4ubuntu17
updated pt_BR again, fixed to UTF-8 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* xscreensaver, Copyright (c) 1992, 1996, 1997, 1998
 
1
/* xscreensaver, Copyright (c) 1992, 1996, 1997, 1998, 2005
2
2
 *  Jamie Zawinski <jwz@jwz.org>
3
3
 *
4
4
 * Permission to use, copy, modify, distribute, and sell this software and its
16
16
 */
17
17
 
18
18
#include "screenhack.h"
 
19
#include "xpm-pixmap.h"
19
20
#include <stdio.h>
20
21
 
21
22
extern FILE *popen (const char *, const char *);
32
33
static char *get_words (void);
33
34
static int x, y;
34
35
static XFontStruct *font;
35
 
static char *def_words = "I'm out running around.";
36
36
static void walk (int dir);
37
37
static void talk (int erase);
38
38
static void talk_1 (void);
48
48
#define FROM_PROGRAM 2
49
49
#define FROM_FILE    3
50
50
#define FROM_RESRC   4
51
 
static int getwordsfrom;
52
51
 
53
52
#define IS_MOVING  1
54
53
#define GET_PASSWD 2
56
55
 
57
56
static void (*next_fn) (void);
58
57
 
59
 
#ifdef HAVE_XPM
60
 
# include <X11/xpm.h>
61
 
 
 
58
#if defined(HAVE_GDK_PIXBUF) || defined(HAVE_XPM)
62
59
# include "images/noseguy/nose-f1.xpm"
63
60
# include "images/noseguy/nose-f2.xpm"
64
61
# include "images/noseguy/nose-f3.xpm"
86
83
    &left_front, &right_front, &front, &down
87
84
  };
88
85
  int i;
89
 
#ifdef HAVE_XPM
 
86
#if defined(HAVE_GDK_PIXBUF) || defined(HAVE_XPM)
 
87
 
90
88
  static char **bits[] = {
91
89
    nose_l1_xpm, nose_l2_xpm, nose_r1_xpm, nose_r2_xpm,
92
90
    nose_f2_xpm, nose_f3_xpm, nose_f1_xpm, nose_f4_xpm
93
91
  };
 
92
 
 
93
 
94
94
  for (i = 0; i < sizeof (images) / sizeof(*images); i++)
95
95
    {
96
 
      XWindowAttributes xgwa;
97
 
      XpmAttributes xpmattrs;
98
 
      Pixmap pixmap = 0;
99
 
      int result;
100
 
      xpmattrs.valuemask = 0;
101
 
 
102
 
      XGetWindowAttributes (dpy, window, &xgwa);
103
 
 
104
 
# ifdef XpmCloseness
105
 
      xpmattrs.valuemask |= XpmCloseness;
106
 
      xpmattrs.closeness = 40000;
107
 
# endif
108
 
# ifdef XpmVisual
109
 
      xpmattrs.valuemask |= XpmVisual;
110
 
      xpmattrs.visual = xgwa.visual;
111
 
# endif
112
 
# ifdef XpmDepth
113
 
      xpmattrs.valuemask |= XpmDepth;
114
 
      xpmattrs.depth = xgwa.depth;
115
 
# endif
116
 
# ifdef XpmColormap
117
 
      xpmattrs.valuemask |= XpmColormap;
118
 
      xpmattrs.colormap = xgwa.colormap;
119
 
# endif
120
 
 
121
 
      result = XpmCreatePixmapFromData(dpy, window, bits[i],
122
 
                                       &pixmap, 0 /* mask */, &xpmattrs);
123
 
      if (!pixmap || (result != XpmSuccess && result != XpmColorError))
 
96
      Pixmap pixmap = xpm_data_to_pixmap (dpy, window, bits[i],
 
97
                                          0, 0, 0);
 
98
      if (!pixmap)
124
99
        {
125
100
          fprintf (stderr, "%s: Can't load nose images\n", progname);
126
101
          exit (1);
311
286
        walk(FRONT);
312
287
    if (random() & 1)
313
288
    {
314
 
        if (getwordsfrom == FROM_PROGRAM)
315
 
            words = get_words();
316
 
        return 1;
 
289
      words = get_words();
 
290
      return 1;
317
291
    }
318
292
    return 0;
319
293
}
320
294
 
321
 
#define MAXLINES 40
 
295
#define MAXLINES 25
 
296
 
 
297
#undef BUFSIZ
 
298
#define BUFSIZ ((MAXLINES + 1) * 100)
 
299
 
322
300
 
323
301
static void
324
302
talk(int force_erase)
366
344
    walk(FRONT);
367
345
    p = strcpy(buf, words);
368
346
 
 
347
    for (p2 = p; *p2; p2++)
 
348
      if (*p2 == '\t') *p2 = ' ';
 
349
 
369
350
    if (!(p2 = strchr(p, '\n')) || !p2[1])
370
351
      {
371
352
        total = strlen (words);
386
367
          (void) strcpy(args[height], p);
387
368
          if (height == MAXLINES - 1)
388
369
            {
389
 
              puts("Message too long!");
 
370
              /* puts("Message too long!"); */
390
371
              break;
391
372
            }
392
373
          p = p2 + 1;
471
452
static void
472
453
init_words (void)
473
454
{
474
 
  char *mode = get_string_resource ("mode", "Mode");
475
 
 
476
455
  program = get_string_resource ("program", "Program");
477
456
  filename = get_string_resource ("filename", "Filename");
478
457
  text = get_string_resource ("text", "Text");
486
465
      strcat (program, " ) 2>&1");
487
466
    }
488
467
 
489
 
  if (!mode || !strcmp (mode, "program"))
490
 
    getwordsfrom = FROM_PROGRAM;
491
 
  else if (!strcmp (mode, "file"))
492
 
    getwordsfrom = FROM_FILE;
493
 
  else if (!strcmp (mode, "string"))
494
 
    getwordsfrom = FROM_RESRC;
495
 
  else
496
 
    {
497
 
      fprintf (stderr,
498
 
               "%s: mode must be program, file, or string, not %s\n",
499
 
               progname, mode);
500
 
      exit (1);
501
 
    }
502
 
 
503
 
  if (getwordsfrom == FROM_PROGRAM && !program)
504
 
    {
505
 
      fprintf (stderr, "%s: no program specified.\n", progname);
506
 
      exit (1);
507
 
    }
508
 
  if (getwordsfrom == FROM_FILE && !filename)
509
 
    {
510
 
      fprintf (stderr, "%s: no file specified.\n", progname);
511
 
      exit (1);
512
 
    }
513
 
 
514
468
  words = get_words();  
515
469
}
516
470
 
525
479
 
526
480
    buf[0] = '\0';
527
481
 
528
 
    switch (getwordsfrom)
529
 
    {
530
 
    case FROM_PROGRAM:
531
 
#ifndef VMS
532
482
        if ((pp = popen(program, "r")))
533
483
        {
534
484
            while (fgets(p, sizeof(buf) - strlen(buf), pp))
570
520
        else
571
521
        {
572
522
            perror(program);
573
 
            p = def_words;
574
 
        }
575
 
        break;
576
 
#endif /* VMS */
577
 
    case FROM_FILE:
578
 
        if ((pp = fopen(filename, "r")))
579
 
        {
580
 
            while (fgets(p, sizeof(buf) - strlen(buf), pp))
581
 
            {
582
 
                if (strlen(buf) + 1 < sizeof(buf))
583
 
                    p = buf + strlen(buf);
584
 
                else
585
 
                    break;
586
 
            }
587
 
            (void) fclose(pp);
588
 
            if (! buf[0])
589
 
              sprintf (buf, "file \"%s\" is empty!", filename);
590
 
            p = buf;
591
 
        }
592
 
        else
593
 
        {
594
 
          sprintf (buf, "couldn't read file \"%s\"!", filename);
595
 
          p = buf;
596
 
        }
597
 
        break;
598
 
    case FROM_RESRC:
599
 
        p = text;
600
 
        break;
601
 
    default:
602
 
        p = def_words;
603
 
        break;
604
 
    }
 
523
        }
605
524
 
606
 
    if (!p || *p == '\0')
607
 
        p = def_words;
608
525
    return p;
609
526
}
610
527
 
613
530
char *progclass = "Noseguy";
614
531
 
615
532
char *defaults [] = {
616
 
  ".background:         black",
617
 
  ".foreground:         gray80",
618
 
#ifndef VMS
619
 
  "*mode:               program",
620
 
#else
621
 
  "*mode:               string",
622
 
#endif
623
 
  "*program:            " ZIPPY_PROGRAM,
624
 
  "noseguy.font:        -*-new century schoolbook-*-r-*-*-*-180-*-*-*-*-*-*",
 
533
  ".background:  black",
 
534
  ".foreground:  gray80",
 
535
  "*program:     xscreensaver-text --cols 40 | head -15",
 
536
  "noseguy.font: -*-new century schoolbook-*-r-*-*-*-180-*-*-*-*-*-*",
625
537
  0
626
538
};
627
539