Changeset 1077
- Timestamp:
- Sep 21, 2006, 11:30:50 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/test/toilet.c
r1076 r1077 31 31 32 32 /* String to canvas transformations */ 33 static cucul_canvas_t *cuculize_big( char const *);34 static cucul_canvas_t *cuculize_tiny( char const *);33 static cucul_canvas_t *cuculize_big(uint32_t const *, unsigned int); 34 static cucul_canvas_t *cuculize_tiny(uint32_t const *, unsigned int); 35 35 36 36 /* Canvas special effects */ … … 42 42 cucul_buffer_t *buffer; 43 43 44 char *string = NULL; 45 unsigned int n; 44 uint32_t *string = NULL; 45 unsigned int length; 46 46 47 int i; 47 48 49 char const *export = "utf8"; 48 50 unsigned flag_gay = 0; 49 51 … … 58 60 /* Long option, needs arg, flag, short option */ 59 61 { "gay", 0, NULL, 'g' }, 62 { "irc", 0, NULL, 'i' }, 60 63 { "help", 0, NULL, 'h' }, 61 64 { "version", 0, NULL, 'v' }, … … 63 66 }; 64 67 65 int c = getopt_long(argc, argv, "g hv", long_options, &option_index);68 int c = getopt_long(argc, argv, "gihv", long_options, &option_index); 66 69 # else 67 70 # define MOREINFO "Try `%s -h' for more information.\n" 68 int c = getopt(argc, argv, "g hv");71 int c = getopt(argc, argv, "gihv"); 69 72 # endif 70 73 if(c == -1) … … 74 77 { 75 78 case 'h': /* --help */ 76 printf("Usage: %s [ -g hv ] [ message ]\n", argv[0]);77 # ifdef HAVE_GETOPT_LONG79 printf("Usage: %s [ -gihv ] [ message ]\n", argv[0]); 80 # ifdef HAVE_GETOPT_LONG 78 81 printf(" -g, --gay add a rainbow effect to the text\n"); 82 printf(" -i, --irc output IRC colour codes\n"); 79 83 printf(" -h, --help display this help and exit\n"); 80 84 printf(" -v, --version output version information and exit\n"); 81 # else85 # else 82 86 printf(" -g add a rainbow effect to the text\n"); 87 printf(" -i output IRC colour codes\n"); 83 88 printf(" -h display this help and exit\n"); 84 89 printf(" -v output version information and exit\n"); 85 # endif90 # endif 86 91 return 0; 87 92 case 'g': /* --gay */ 88 93 flag_gay = 1; 94 break; 95 case 'i': /* --irc */ 96 export = "irc"; 89 97 break; 90 98 case 'v': /* --version */ … … 114 122 } 115 123 116 for(i = optind, n = 0; i < argc; i++) 117 { 118 unsigned int l = strlen(argv[i]); 124 /* Load rest of commandline into a UTF-32 string */ 125 for(i = optind, length = 0; i < argc; i++) 126 { 127 unsigned int k, guessed_len, real_len; 128 129 guessed_len = strlen(argv[i]); 130 119 131 if(i > optind) 120 string[n++] = ' '; 121 string = realloc(string, n + l + 1); 122 strcpy(string + n, argv[i]); 123 n += l; 132 string[length++] = (uint32_t)' '; 133 134 string = realloc(string, (length + guessed_len + 1) * 4); 135 136 for(k = 0, real_len = 0; k < guessed_len; real_len++) 137 { 138 unsigned int char_len; 139 140 string[length + real_len] = 141 cucul_utf8_to_utf32(argv[i] + k, &char_len); 142 143 k += char_len; 144 } 145 146 length += real_len; 124 147 } 125 148 126 149 /* Do gay stuff with our string (léopard) */ 127 cv = cuculize_big(string );150 cv = cuculize_big(string, length); 128 151 if(flag_gay) 129 152 make_gay(cv); 130 153 131 154 /* Output char */ 132 buffer = cucul_export_canvas(cv, "utf8");155 buffer = cucul_export_canvas(cv, export); 133 156 fwrite(cucul_get_buffer_data(buffer), 134 157 cucul_get_buffer_size(buffer), 1, stdout); … … 140 163 } 141 164 142 static cucul_canvas_t *cuculize_big(char const *string) 165 static cucul_canvas_t *cuculize_big(uint32_t const *string, 166 unsigned int length) 143 167 { 144 168 cucul_canvas_t *cv; … … 146 170 char const * const * fonts; 147 171 unsigned char *buf; 148 unsigned int n,w, h, x, y, miny, maxy;149 150 n = strlen(string);151 cv = cucul_create_canvas(n, 1);152 cucul_putstr(cv, 0, 0, string);172 unsigned int w, h, x, y, miny, maxy; 173 174 cv = cucul_create_canvas(length, 1); 175 for(x = 0; x < length; x++) 176 cucul_putchar(cv, x, 0, string[x]); 153 177 154 178 fonts = cucul_get_font_list(); … … 194 218 } 195 219 196 static cucul_canvas_t *cuculize_tiny(char const *string) 197 { 198 unsigned int n = strlen(string); 199 cucul_canvas_t *cv = cucul_create_canvas(n, 1); 200 201 cucul_putstr(cv, 0, 0, string); 220 static cucul_canvas_t *cuculize_tiny(uint32_t const *string, 221 unsigned int length) 222 { 223 unsigned int x; 224 cucul_canvas_t *cv = cucul_create_canvas(length, 1); 225 226 for(x = 0; x < length; x++) 227 cucul_putchar(cv, x, 0, string[x]); 202 228 203 229 return cv;
Note: See TracChangeset
for help on using the changeset viewer.