Changeset 1228 for toilet/trunk
- Timestamp:
- Oct 25, 2006, 6:06:19 PM (16 years ago)
- Location:
- toilet/trunk/src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
toilet/trunk/src/filter.c
r1227 r1228 21 21 # include <inttypes.h> 22 22 #endif 23 #include <string.h> 24 #include <stdio.h> 25 #include <stdlib.h> 23 26 #include <cucul.h> 24 27 28 #include "toilet.h" 25 29 #include "filter.h" 26 30 27 void filter_autocrop(cucul_canvas_t *cv) 31 static void filter_crop(cucul_canvas_t *); 32 static void filter_gay(cucul_canvas_t *); 33 static void filter_metal(cucul_canvas_t *); 34 static void filter_flip(cucul_canvas_t *); 35 static void filter_flop(cucul_canvas_t *); 36 static void filter_rotate(cucul_canvas_t *); 37 38 struct 39 { 40 char const *name; 41 void (*function)(cucul_canvas_t *); 42 } 43 const lookup[] = 44 { 45 { "crop", filter_crop }, 46 { "gay", filter_gay }, 47 { "metal", filter_metal }, 48 { "flip", filter_flip }, 49 { "flop", filter_flop }, 50 { "rotate", filter_rotate }, 51 }; 52 53 int filter_add(context_t *cx, char const *filter) 54 { 55 unsigned int n; 56 int i; 57 58 for(;;) 59 { 60 while(*filter == ':') 61 filter++; 62 63 if(*filter == '\0') 64 break; 65 66 for(i = sizeof(lookup) / sizeof(lookup[0]); i--; ) 67 if(!strncmp(filter, lookup[i].name, strlen(lookup[i].name))) 68 break; 69 70 n = strlen(lookup[i].name); 71 72 if(i == -1 || (filter[n] != ':' && filter[n] != '\0')) 73 { 74 fprintf(stderr, "unknown filter near `%s'\n", filter); 75 return -1; 76 } 77 78 if((cx->nfilters % 16) == 0) 79 cx->filters = realloc(cx->filters, (cx->nfilters + 16) 80 * sizeof(lookup[0].function)); 81 cx->filters[cx->nfilters] = lookup[i].function; 82 cx->nfilters++; 83 84 filter += n; 85 } 86 87 return 0; 88 } 89 90 int filter_do(context_t *cx) 91 { 92 unsigned int i; 93 94 for(i = 0; i < cx->nfilters; i++) 95 cx->filters[i](cx->cv); 96 97 return 0; 98 } 99 100 static void filter_crop(cucul_canvas_t *cv) 28 101 { 29 102 unsigned int x, y, w, h; … … 59 132 } 60 133 61 void filter_metal(cucul_canvas_t *cv)134 static void filter_metal(cucul_canvas_t *cv) 62 135 { 63 136 static unsigned char const palette[] = … … 89 162 } 90 163 91 void filter_gay(cucul_canvas_t *cv)164 static void filter_gay(cucul_canvas_t *cv) 92 165 { 93 166 static unsigned char const rainbow[] = … … 118 191 } 119 192 193 static void filter_flip(cucul_canvas_t *cv) 194 { 195 cucul_flip(cv); 196 } 197 198 static void filter_flop(cucul_canvas_t *cv) 199 { 200 cucul_flop(cv); 201 } 202 203 static void filter_rotate(cucul_canvas_t *cv) 204 { 205 cucul_rotate(cv); 206 } 207 -
toilet/trunk/src/filter.h
r1227 r1228 16 16 */ 17 17 18 extern void filter_autocrop(cucul_canvas_t *); 19 extern void filter_metal(cucul_canvas_t *); 20 extern void filter_gay(cucul_canvas_t *); 18 extern int filter_add(context_t *, char const *); 19 extern int filter_do(context_t *); 21 20 -
toilet/trunk/src/io.c
r1206 r1228 46 46 }; 47 47 48 TOIFILE *toiopen(c onst char*path, const char *mode)48 TOIFILE *toiopen(char const *path, const char *mode) 49 49 { 50 50 TOIFILE *toif = malloc(sizeof(*toif)); -
toilet/trunk/src/main.c
r1227 r1228 51 51 int i, j, ret; 52 52 53 unsigned int flag_gay = 0;54 unsigned int flag_metal = 0;55 53 int infocode = -1; 56 54 … … 60 58 61 59 cx->term_width = 80; 60 61 cx->filters = NULL; 62 cx->nfilters = 0; 62 63 63 64 #if defined(HAVE_GETOPT_H) … … 74 75 { "width", 1, NULL, 'w' }, 75 76 { "termwidth", 0, NULL, 't' }, 77 { "filter", 1, NULL, 'F' }, 76 78 { "gay", 0, NULL, 'g' }, 77 79 { "metal", 0, NULL, 'm' }, … … 83 85 }; 84 86 85 int c = getopt_long(argc, argv, " d:f:I:w:ghimtv",87 int c = getopt_long(argc, argv, "f:d:w:tF:gmihI:v", 86 88 long_options, &option_index); 87 89 # else 88 90 # define MOREINFO "Try `%s -h' for more information.\n" 89 int c = getopt(argc, argv, " d:f:I:w:ghimtv");91 int c = getopt(argc, argv, "f:d:w:tF:gmihI:v"); 90 92 # endif 91 93 if(c == -1) … … 109 111 cx->dir = optarg; 110 112 break; 113 case 'F': /* --filter */ 114 if(filter_add(cx, optarg)) 115 return -1; 116 break; 111 117 case 'g': /* --gay */ 112 f lag_gay = 1;118 filter_add(cx, "gay"); 113 119 break; 114 120 case 'm': /* --metal */ 115 f lag_metal = 1;121 filter_add(cx, "metal"); 116 122 break; 117 123 case 'w': /* --width */ … … 221 227 222 228 /* Apply optional effects to our string */ 223 if(!strcasecmp(cx->font, "mono9")) 224 filter_autocrop(cx->cv); 225 if(flag_metal) 226 filter_metal(cx->cv); 227 if(flag_gay) 228 filter_gay(cx->cv); 229 filter_do(cx); 229 230 230 231 /* Output char */ … … 241 242 #if defined(HAVE_GETOPT_H) 242 243 # define USAGE \ 243 "Usage: toilet [ -ghimtv ] [ -d fontdirectory ]\n" \244 "Usage: toilet [ -ghimtvF ] [ -d fontdirectory ]\n" \ 244 245 " [ -f fontfile ] [ -w outputwidth ]\n" \ 245 246 " [ -I infocode ] [ message ]\n" … … 275 276 printf(" -w, --width <width> set output width\n"); 276 277 printf(" -t, --termwidth adapt to terminal's width\n"); 278 printf(" -F, --filter apply one or several filters to the text\n"); 277 279 printf(" -g, --gay add a rainbow effect to the text\n"); 278 280 printf(" -m, --metal add a metal effect to the text\n"); … … 286 288 printf(" -w <width> set output width\n"); 287 289 printf(" -t adapt to terminal's width\n"); 290 printf(" -F apply one or several filters to the text\n"); 288 291 printf(" -g add a rainbow effect to the text\n"); 289 292 printf(" -m add a metal effect to the text\n"); -
toilet/trunk/src/toilet.h
r1196 r1228 27 27 unsigned int w, h, ew, eh, x, y; 28 28 29 /* Methods */29 /* Render methods */ 30 30 int (*feed)(struct toilet_context *, uint32_t); 31 31 int (*end)(struct toilet_context *); … … 44 44 cucul_canvas_t *image; 45 45 unsigned int *lookup; 46 47 /* Render filters */ 48 void (**filters)(cucul_canvas_t *); 49 unsigned int nfilters; 46 50 }; 47 51
Note: See TracChangeset
for help on using the changeset viewer.