Changeset 1193
- Timestamp:
- Oct 8, 2006, 2:14:13 PM (16 years ago)
- Location:
- toilet/trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
toilet/trunk/src/figlet.c
r1170 r1193 45 45 }; 46 46 47 static struct figfont *open_font( void);47 static struct figfont *open_font(context_t *cx); 48 48 static void free_font(struct figfont *); 49 49 50 cucul_canvas_t *render_figlet(uint32_t const *string, unsigned int length) 50 cucul_canvas_t *render_figlet(context_t *cx, uint32_t const *string, 51 unsigned int length) 51 52 { 52 53 cucul_canvas_t *cv; … … 54 55 unsigned int x, i, c; 55 56 56 font = open_font( );57 font = open_font(cx); 57 58 58 59 if(!font) … … 82 83 } 83 84 84 static struct figfont *open_font( void)85 static struct figfont *open_font(context_t *cx) 85 86 { 86 87 char *data = NULL; … … 93 94 94 95 /* Open font: try .tlf, then .flf */ 95 snprintf(path, 2047, "%s/%s.tlf", toilet_dir, toilet_font);96 snprintf(path, 2047, "%s/%s.tlf", cx->dir, cx->font); 96 97 path[2047] = '\0'; 97 98 f = fopen(path, "r"); 98 99 if(!f) 99 100 { 100 snprintf(path, 2047, "%s/%s.flf", toilet_dir, toilet_font);101 snprintf(path, 2047, "%s/%s.flf", cx->dir, cx->font); 101 102 path[2047] = '\0'; 102 103 f = fopen(path, "r"); … … 228 229 ch = cucul_getchar(font->image, i, j); 229 230 231 /* Replace hardblanks with U+00A0 NO-BREAK SPACE */ 230 232 if(ch == font->hardblank) 231 233 cucul_putchar(font->image, i, j, ch = ' '); 234 //cucul_putchar(font->image, i, j, ch = 0xa0); 232 235 233 236 if(oldch && ch != oldch) -
toilet/trunk/src/figlet.h
r1143 r1193 15 15 * This header defines functions for handling FIGlet fonts. 16 16 */ 17 extern cucul_canvas_t *render_figlet(uint32_t const *, unsigned int); 17 extern cucul_canvas_t *render_figlet(context_t *, uint32_t const *, 18 unsigned int); 18 19 -
toilet/trunk/src/main.c
r1150 r1193 37 37 #include "filters.h" 38 38 39 char const *toilet_export = "utf8";40 char const *toilet_font = "mono9";41 char const *toilet_dir = "/usr/share/figlet/";42 43 39 static void version(void); 44 40 #if defined(HAVE_GETOPT_H) … … 48 44 int main(int argc, char *argv[]) 49 45 { 50 cucul_canvas_t *cv; 46 context_t struct_cx; 47 context_t *cx = &struct_cx; 48 51 49 cucul_buffer_t *buffer; 52 50 53 uint32_t *string = NULL; 54 unsigned int length; 55 56 int i; 51 int i, j; 57 52 58 53 unsigned int flag_gay = 0; 59 54 unsigned int flag_metal = 0; 60 unsigned int term_width = 80;61 55 int infocode = -1; 56 57 cx->export = "utf8"; 58 cx->font = "mono9"; 59 cx->dir = "/usr/share/figlet/"; 60 61 cx->term_width = 80; 62 62 63 63 #if defined(HAVE_GETOPT_H) … … 104 104 return 0; 105 105 case 'f': /* --font */ 106 toilet_font = optarg;106 cx->font = optarg; 107 107 break; 108 108 case 'd': /* --directory */ 109 toilet_dir = optarg;109 cx->dir = optarg; 110 110 break; 111 111 case 'g': /* --gay */ … … 116 116 break; 117 117 case 'w': /* --width */ 118 term_width = atoi(optarg);118 cx->term_width = atoi(optarg); 119 119 break; 120 120 case 't': /* --termwidth */ … … 126 126 ioctl(2, TIOCGWINSZ, &ws) != -1 || 127 127 ioctl(0, TIOCGWINSZ, &ws) != -1) && ws.ws_col != 0) 128 term_width = ws.ws_col;128 cx->term_width = ws.ws_col; 129 129 #endif 130 130 break; 131 131 } 132 132 case 'i': /* --irc */ 133 toilet_export = "irc";133 cx->export = "irc"; 134 134 break; 135 135 case '?': … … 158 158 return 0; 159 159 case 2: 160 printf("%s\n", toilet_dir);160 printf("%s\n", cx->dir); 161 161 return 0; 162 162 case 3: 163 printf("%s\n", toilet_font);163 printf("%s\n", cx->font); 164 164 return 0; 165 165 case 4: 166 printf("%u\n", term_width);166 printf("%u\n", cx->term_width); 167 167 return 0; 168 168 default: … … 170 170 } 171 171 172 #if 0 172 173 if(optind >= argc) 173 { 174 printf("%s: too few arguments\n", argv[0]); 175 printf(MOREINFO, argv[0]); 176 return 1; 177 } 178 179 /* Load rest of commandline into a UTF-32 string */ 180 for(i = optind, length = 0; i < argc; i++) 181 { 182 unsigned int k, guessed_len, real_len; 183 184 guessed_len = strlen(argv[i]); 185 186 if(i > optind) 187 string[length++] = (uint32_t)' '; 188 189 string = realloc(string, (length + guessed_len + 1) * 4); 190 191 for(k = 0, real_len = 0; k < guessed_len; real_len++) 192 { 193 unsigned int char_len; 194 195 string[length + real_len] = 196 cucul_utf8_to_utf32(argv[i] + k, &char_len); 197 198 k += char_len; 199 } 200 201 length += real_len; 202 } 203 174 #endif 175 176 #if 0 204 177 /* Render string to canvas */ 205 if(!strcasecmp( toilet_font, "mono9"))178 if(!strcasecmp(cx->font, "mono9")) 206 179 { 207 180 cv = render_big(string, length); 208 181 filter_autocrop(cv); 209 182 } 210 else if(!strcasecmp( toilet_font, "term"))183 else if(!strcasecmp(cx->font, "term")) 211 184 cv = render_tiny(string, length); 212 185 else 213 cv = render_figlet(string, length); 214 215 free(string); 216 217 if(!cv) 218 return -1; 186 cv = render_figlet(cx, string, length); 187 #endif 188 189 init_tiny(cx); 190 191 if(optind >= argc) 192 { 193 char buf[10]; 194 unsigned int len; 195 uint32_t ch; 196 197 i = 0; 198 199 /* Read from stdin */ 200 while(!feof(stdin)) 201 { 202 buf[i++] = getchar(); 203 buf[i] = '\0'; 204 205 ch = cucul_utf8_to_utf32(buf, &len); 206 207 if(!len) 208 continue; 209 210 cx->feed(cx, ch); 211 i = 0; 212 } 213 } 214 else for(i = optind; i < argc; i++) 215 { 216 /* Read from commandline */ 217 unsigned int len; 218 219 if(i != optind) 220 cx->feed(cx, ' '); 221 222 for(j = 0; argv[i][j];) 223 { 224 cx->feed(cx, cucul_utf8_to_utf32(argv[i] + j, &len)); 225 j += len; 226 } 227 } 228 229 cx->end(cx); 219 230 220 231 /* Apply optional effects to our string */ 221 232 if(flag_metal) 222 filter_metal(c v);233 filter_metal(cx->cv); 223 234 if(flag_gay) 224 filter_gay(c v);235 filter_gay(cx->cv); 225 236 226 237 /* Output char */ 227 buffer = cucul_export_canvas(c v, toilet_export);238 buffer = cucul_export_canvas(cx->cv, cx->export); 228 239 fwrite(cucul_get_buffer_data(buffer), 229 240 cucul_get_buffer_size(buffer), 1, stdout); 230 241 cucul_free_buffer(buffer); 231 242 232 cucul_free_canvas(c v);243 cucul_free_canvas(cx->cv); 233 244 234 245 return 0; 235 246 } 236 247 248 #if defined(HAVE_GETOPT_H) 249 # define USAGE \ 250 "Usage: toilet [ -ghimtv ] [ -d fontdirectory ]\n" \ 251 " [ -f fontfile ] [ -w outputwidth ]\n" \ 252 " [ -I infocode ] [ message ]\n" 253 #else 254 # define USAGE "" 255 #endif 256 237 257 static void version(void) 238 258 { 239 printf("TOIlet Copyright 2006 Sam Hocevar %s\n", VERSION); 240 printf("Internet: <sam@zoy.org> Version: 0, date: 21 Sep 2006\n"); 241 printf("\n"); 259 printf( 260 "TOIlet Copyright 2006 Sam Hocevar\n" 261 "Internet: <sam@zoy.org> Version: %s, date: %s\n" 262 "\n" 263 "TOIlet, along with the various TOIlet fonts and documentation, may be\n" 264 "freely copied and distributed.\n" 265 "\n" 266 "If you use TOIlet, please send an e-mail message to <sam@zoy.org>.\n" 267 "\n" 268 "The latest version of TOIlet is available from the web site,\n" 269 " http://libcaca.zoy.org/toilet.html\n" 270 "\n" 271 USAGE, 272 VERSION, DATE); 242 273 } 243 274 … … 245 276 static void usage(void) 246 277 { 247 printf("Usage: toilet [ -ghimtv ] [ -d fontdirectory ]\n"); 248 printf(" [ -f fontfile ] [ -w outputwidth ]\n"); 249 printf(" [ -I infocode ] [ message ]\n"); 278 printf(USAGE); 250 279 # ifdef HAVE_GETOPT_LONG 251 280 printf(" -f, --font <fontfile> select the font\n"); -
toilet/trunk/src/render.c
r1112 r1193 24 24 #include <cucul.h> 25 25 26 #include "toilet.h" 26 27 #include "render.h" 27 28 29 static int feed_tiny(context_t *, uint32_t); 30 static int end_tiny(context_t *); 31 32 int init_tiny(context_t *cx) 33 { 34 cx->ew = 16; 35 cx->eh = 2; 36 cx->x = cx->y = 0; 37 cx->w = cx->h = 0; 38 cx->cv = cucul_create_canvas(cx->ew, cx->eh); 39 40 cx->feed = feed_tiny; 41 cx->end = end_tiny; 42 43 return 0; 44 } 45 46 static int feed_tiny(context_t *cx, uint32_t ch) 47 { 48 if(cx->x >= cx->w) 49 cx->w = cx->x + 1; 50 51 if(cx->y >= cx->h) 52 cx->h = cx->y + 1; 53 54 switch(ch) 55 { 56 case (uint32_t)'\r': 57 return 0; 58 case (uint32_t)'\n': 59 cx->x = 0; 60 cx->y++; 61 break; 62 case (uint32_t)'\t': 63 cx->x = (cx->x & ~7) + 8; 64 break; 65 default: 66 cucul_putchar(cx->cv, cx->x, cx->y, ch); 67 cx->x++; 68 break; 69 } 70 71 if(cx->x >= cx->term_width) 72 { 73 cx->x = 0; 74 cx->y++; 75 } 76 77 if(cx->x >= cx->ew) 78 cx->ew = cx->ew + cx->ew / 2; 79 80 if(cx->y >= cx->eh) 81 cx->eh = cx->eh + cx->eh / 2; 82 83 cucul_set_canvas_size(cx->cv, cx->ew, cx->eh); 84 85 return 0; 86 } 87 88 static int end_tiny(context_t *cx) 89 { 90 cucul_set_canvas_size(cx->cv, cx->w, cx->h); 91 92 return 0; 93 } 94 95 #if 0 28 96 cucul_canvas_t *render_big(uint32_t const *string, unsigned int length) 29 97 { … … 80 148 return cv; 81 149 } 150 #endif 82 151 83 cucul_canvas_t *render_tiny(uint32_t const *string, unsigned int length)84 {85 unsigned int x;86 cucul_canvas_t *cv = cucul_create_canvas(length, 1);87 88 for(x = 0; x < length; x++)89 cucul_putchar(cv, x, 0, string[x]);90 91 return cv;92 }93 -
toilet/trunk/src/render.h
r1102 r1193 16 16 */ 17 17 18 extern cucul_canvas_t *render_big(uint32_t const *, unsigned int); 19 extern cucul_canvas_t *render_tiny(uint32_t const *, unsigned int); 18 extern int init_tiny(context_t *); 20 19 -
toilet/trunk/src/toilet.h
r1143 r1193 16 16 */ 17 17 18 extern char const *toilet_export; 19 extern char const *toilet_font; 20 extern char const *toilet_dir; 18 struct toilet_context 19 { 20 char const *export; 21 char const *font; 22 char const *dir; 21 23 24 unsigned int term_width; 25 26 cucul_canvas_t *cv; 27 unsigned int w, h, ew, eh, x, y; 28 29 int (*feed)(struct toilet_context *, uint32_t); 30 int (*end)(struct toilet_context *); 31 }; 32 33 typedef struct toilet_context context_t; 34
Note: See TracChangeset
for help on using the changeset viewer.