- Timestamp:
- Sep 21, 2006, 7:32:27 PM (16 years ago)
- Location:
- libcaca/trunk/test
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/test/Makefile.am
r1073 r1075 48 48 49 49 toilet_SOURCES = toilet.c 50 toilet_LDADD = ../cucul/libcucul.la 50 toilet_LDADD = ../cucul/libcucul.la @GETOPT_LIBS@ 51 51 52 52 transform_SOURCES = transform.c -
libcaca/trunk/test/toilet.c
r1073 r1075 19 19 # include <inttypes.h> 20 20 # endif 21 # if defined(HAVE_GETOPT_H) 22 # include <getopt.h> 23 # endif 21 24 # include <stdio.h> 22 25 # include <string.h> … … 40 43 41 44 char *string = NULL; 42 unsigned int i, n; 43 44 if(argc < 2) 45 { 46 fprintf(stderr, "%s: too few arguments\n", argv[0]); 47 fprintf(stderr, "usage: %s [OPTIONS] <string>\n", argv[0]); 48 return -1; 49 } 50 51 for(i = 1, n = 0; i < (unsigned int)argc; i++) 45 unsigned int n; 46 int i; 47 48 unsigned flag_gay = 0; 49 50 for(;;) 51 { 52 #ifdef HAVE_GETOPT_LONG 53 # define MOREINFO "Try `%s --help' for more information.\n" 54 int option_index = 0; 55 static struct option long_options[] = 56 { 57 /* Long option, needs arg, flag, short option */ 58 { "gay", 0, NULL, 'g' }, 59 { "help", 0, NULL, 'h' }, 60 { "version", 0, NULL, 'v' }, 61 { NULL, 0, NULL, 0 } 62 }; 63 64 int c = getopt_long(argc, argv, "ghv", long_options, &option_index); 65 #else 66 # define MOREINFO "Try `%s -h' for more information.\n" 67 int c = getopt(argc, argv, "ghv"); 68 #endif 69 if(c == -1) 70 break; 71 72 switch(c) 73 { 74 case 'h': /* --help */ 75 printf("Usage: %s [ -ghv ] [ message ]\n", argv[0]); 76 #ifdef HAVE_GETOPT_LONG 77 printf(" -g, --gay add a rainbow effect to the text\n"); 78 printf(" -h, --help display this help and exit\n"); 79 printf(" -v, --version output version information and exit\n"); 80 #else 81 printf(" -g add a rainbow effect to the text\n"); 82 printf(" -h display this help and exit\n"); 83 printf(" -v output version information and exit\n"); 84 #endif 85 return 0; 86 case 'g': /* --gay */ 87 flag_gay = 1; 88 break; 89 case 'v': /* --version */ 90 printf("TOIlet Copyright 2006 Sam Hocevar %s\n", VERSION); 91 printf("Internet: <sam@zoy.org> Version: 0, date: 21 Sep 2006\n"); 92 printf("\n"); 93 return 0; 94 case '?': 95 printf(MOREINFO, argv[0]); 96 return 1; 97 default: 98 printf("%s: invalid option -- %i\n", argv[0], c); 99 printf(MOREINFO, argv[0]); 100 return 1; 101 } 102 } 103 104 if(optind >= argc) 105 { 106 printf("%s: too few arguments\n", argv[0]); 107 printf(MOREINFO, argv[0]); 108 return 1; 109 } 110 111 for(i = optind, n = 0; i < argc; i++) 52 112 { 53 113 unsigned int l = strlen(argv[i]); 54 if(i > 1)114 if(i > optind) 55 115 string[n++] = ' '; 56 116 string = realloc(string, n + l + 1); … … 61 121 /* Do gay stuff with our string (léopard) */ 62 122 cv = cuculize_big(string); 63 make_gay(cv); 123 if(flag_gay) 124 make_gay(cv); 64 125 65 126 /* Output char */ … … 160 221 if(ch != (unsigned char)' ') 161 222 { 162 cucul_set_color(cv, rainbow[(x + y) % 6], CUCUL_COLOR_TRANSPARENT); 223 cucul_set_color(cv, rainbow[(x / 2 + y) % 6], 224 CUCUL_COLOR_TRANSPARENT); 163 225 cucul_putchar(cv, x, y, ch); 164 226 }
Note: See TracChangeset
for help on using the changeset viewer.