Changeset 1099 for toilet/trunk/src
- Timestamp:
- Sep 23, 2006, 9:27:19 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
toilet/trunk/src/main.c
r1087 r1099 33 33 /* Canvas special effects */ 34 34 static void filter_autocrop(cucul_canvas_t *); 35 static void filter_metal(cucul_canvas_t *); 35 36 static void filter_gay(cucul_canvas_t *); 36 37 … … 47 48 char const *export = "utf8"; 48 49 unsigned flag_gay = 0; 50 unsigned flag_metal = 0; 49 51 50 52 #if defined(HAVE_GETOPT_H) … … 57 59 { 58 60 /* Long option, needs arg, flag, short option */ 61 { "metal", 0, NULL, 'm' }, 59 62 { "gay", 0, NULL, 'g' }, 60 63 { "irc", 0, NULL, 'i' }, … … 64 67 }; 65 68 66 int c = getopt_long(argc, argv, "g ihv", long_options, &option_index);69 int c = getopt_long(argc, argv, "gmihv", long_options, &option_index); 67 70 # else 68 71 # define MOREINFO "Try `%s -h' for more information.\n" 69 int c = getopt(argc, argv, "g ihv");72 int c = getopt(argc, argv, "gmihv"); 70 73 # endif 71 74 if(c == -1) … … 75 78 { 76 79 case 'h': /* --help */ 77 printf("Usage: %s [ -g ihv ] [ message ]\n", argv[0]);80 printf("Usage: %s [ -gmihv ] [ message ]\n", argv[0]); 78 81 # ifdef HAVE_GETOPT_LONG 79 82 printf(" -g, --gay add a rainbow effect to the text\n"); 83 printf(" -m, --metal add a metal effect to the text\n"); 80 84 printf(" -i, --irc output IRC colour codes\n"); 81 85 printf(" -h, --help display this help and exit\n"); … … 83 87 # else 84 88 printf(" -g add a rainbow effect to the text\n"); 89 printf(" -m add a metal effect to the text\n"); 85 90 printf(" -i output IRC colour codes\n"); 86 91 printf(" -h display this help and exit\n"); … … 88 93 # endif 89 94 return 0; 95 case 'm': /* --metal */ 96 flag_metal = 1; 97 break; 90 98 case 'g': /* --gay */ 91 99 flag_gay = 1; … … 148 156 cv = cuculize_big(string, length); 149 157 filter_autocrop(cv); 158 if(flag_metal) 159 filter_metal(cv); 150 160 if(flag_gay) 151 161 filter_gay(cv); … … 260 270 } 261 271 272 static void filter_metal(cucul_canvas_t *cv) 273 { 274 static struct 275 { 276 char ch[6]; 277 unsigned char fg, bg; 278 } 279 const palette[] = 280 { 281 { " ", CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_LIGHTBLUE }, 282 { "░", CUCUL_COLOR_BLUE, CUCUL_COLOR_LIGHTBLUE }, 283 { "▒", CUCUL_COLOR_BLUE, CUCUL_COLOR_LIGHTBLUE }, 284 { "░", CUCUL_COLOR_LIGHTBLUE, CUCUL_COLOR_BLUE }, 285 { " ", CUCUL_COLOR_BLUE, CUCUL_COLOR_BLUE }, 286 { " ", CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_LIGHTGRAY }, 287 { "░", CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY }, 288 { "▒", CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_LIGHTGRAY }, 289 { "░", CUCUL_COLOR_LIGHTGRAY, CUCUL_COLOR_DARKGRAY }, 290 { " ", CUCUL_COLOR_DARKGRAY, CUCUL_COLOR_DARKGRAY }, 291 }; 292 293 unsigned int x, y, w, h; 294 295 w = cucul_get_canvas_width(cv); 296 h = cucul_get_canvas_height(cv); 297 298 for(y = 0; y < h; y++) 299 for(x = 0; x < w; x++) 300 { 301 int i; 302 303 if(cucul_getchar(cv, x, y) == (unsigned char)' ') 304 continue; 305 306 i = y * 10 / h; 307 cucul_set_color(cv, palette[i].fg, palette[i].bg); 308 cucul_putstr(cv, x, y, palette[i].ch); 309 } 310 } 311 262 312 static void filter_gay(cucul_canvas_t *cv) 263 313 {
Note: See TracChangeset
for help on using the changeset viewer.