- Timestamp:
- Sep 30, 2006, 1:06:20 PM (16 years ago)
- Location:
- toilet/trunk/src
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
toilet/trunk/src/figlet.c
r1113 r1143 26 26 #include <cucul.h> 27 27 28 #include "toilet.h" 28 29 #include "figlet.h" 29 30 … … 41 42 }; 42 43 43 static struct figfont *open_font( char const *);44 static struct figfont *open_font(void); 44 45 static void free_font(struct figfont *); 45 46 46 cucul_canvas_t *render_figlet(uint32_t const *string, unsigned int length, 47 char const *fontname) 47 cucul_canvas_t *render_figlet(uint32_t const *string, unsigned int length) 48 48 { 49 49 cucul_canvas_t *cv; … … 51 51 unsigned int x, i, c; 52 52 53 font = open_font(fontname); 53 font = open_font(); 54 55 if(!font) 56 return NULL; 54 57 55 58 cv = cucul_create_canvas(length * font->max_length, font->height); … … 76 79 } 77 80 78 static struct figfont *open_font( char const *fontname)81 static struct figfont *open_font(void) 79 82 { 80 83 char *data = NULL; … … 85 88 unsigned int i, j, size, comment_lines; 86 89 87 /* Open font */88 snprintf(path, 2047, " /usr/share/figlet/%s.flf", fontname);90 /* Open font: try .tlf, then .flf */ 91 snprintf(path, 2047, "%s/%s.tlf", toilet_dir, toilet_font); 89 92 path[2047] = '\0'; 90 93 f = fopen(path, "r"); 91 94 if(!f) 92 95 { 93 fprintf(stderr, "font `%s' not found\n", path); 94 return NULL; 96 snprintf(path, 2047, "%s/%s.flf", toilet_dir, toilet_font); 97 path[2047] = '\0'; 98 f = fopen(path, "r"); 99 if(!f) 100 { 101 fprintf(stderr, "font `%s' not found\n", path); 102 return NULL; 103 } 95 104 } 96 105 … … 101 110 font->full_layout = 0; 102 111 font->codetag_count = 0; 103 if(fscanf(f, " flf2a%c %u %u %u %i %u %u %u %u\n", &font->hardblank,112 if(fscanf(f, "%*[ft]lf2a%c %u %u %u %i %u %u %u %u\n", &font->hardblank, 104 113 &font->height, &font->baseline, &font->max_length, 105 114 &font->old_layout, &comment_lines, &font->print_direction, … … 169 178 /* Import buffer into canvas */ 170 179 b = cucul_load_memory(data, i); 171 font->image = cucul_import_canvas(b, " ansi");180 font->image = cucul_import_canvas(b, "utf8"); 172 181 cucul_free_buffer(b); 173 182 free(data); -
toilet/trunk/src/figlet.h
r1102 r1143 15 15 * This header defines functions for handling FIGlet fonts. 16 16 */ 17 extern cucul_canvas_t *render_figlet(uint32_t const *, unsigned int, 18 char const *); 17 extern cucul_canvas_t *render_figlet(uint32_t const *, unsigned int); 19 18 -
toilet/trunk/src/main.c
r1116 r1143 32 32 #include <cucul.h> 33 33 34 #include "toilet.h" 34 35 #include "render.h" 35 36 #include "figlet.h" 36 37 #include "filters.h" 38 39 char const *toilet_export = "utf8"; 40 char const *toilet_font = "mono9"; 41 char const *toilet_dir = "/usr/share/figlet/"; 37 42 38 43 static void version(void); … … 51 56 int i; 52 57 53 char const *export = "utf8";54 char const *font = "mono9";55 char const *dir = "/usr/share/figlet/";56 58 unsigned int flag_gay = 0; 57 59 unsigned int flag_metal = 0; … … 102 104 return 0; 103 105 case 'f': /* --font */ 104 font = optarg;106 toilet_font = optarg; 105 107 break; 106 108 case 'd': /* --directory */ 107 dir = optarg;109 toilet_dir = optarg; 108 110 break; 109 111 case 'g': /* --gay */ … … 129 131 } 130 132 case 'i': /* --irc */ 131 export = "irc";133 toilet_export = "irc"; 132 134 break; 133 135 case '?': … … 156 158 return 0; 157 159 case 2: 158 printf("%s\n", dir);160 printf("%s\n", toilet_dir); 159 161 return 0; 160 162 case 3: 161 printf("%s\n", font);163 printf("%s\n", toilet_font); 162 164 return 0; 163 165 case 4: … … 201 203 202 204 /* Render string to canvas */ 203 if(!strcasecmp( font, "mono9"))205 if(!strcasecmp(toilet_font, "mono9")) 204 206 { 205 207 cv = render_big(string, length); 206 208 filter_autocrop(cv); 207 209 } 208 else if(!strcasecmp( font, "term"))210 else if(!strcasecmp(toilet_font, "term")) 209 211 cv = render_tiny(string, length); 210 212 else 211 cv = render_figlet(string, length, font); 213 cv = render_figlet(string, length); 214 215 if(!cv) 216 return -1; 212 217 213 218 /* Do gay stuff with our string (léopard) */ … … 218 223 219 224 /* Output char */ 220 buffer = cucul_export_canvas(cv, export);225 buffer = cucul_export_canvas(cv, toilet_export); 221 226 fwrite(cucul_get_buffer_data(buffer), 222 227 cucul_get_buffer_size(buffer), 1, stdout);
Note: See TracChangeset
for help on using the changeset viewer.