ascii-jtex/eKanji/tools/ekdump.c
/* [<][>][^][v][top][bottom][index][help] */
FUNCTIONS
This source file includes following functions.
- main
- usage
- dump_char
1 /* ekdump.c - dump eKanji font in ASCII art form.
2 * by Hirotsugu Kakugawa
3 *
4 * Copyright (C) 1999 Hirotsugu Kakugawa. All rights reserved.
5 * See "COPYING" for distribution of this software.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <fcntl.h>
26
27 #define PIXEL_SIZE 24
28 #define DOT_FOREGROUND '*'
29 #define DOT_BACKGROUND '.'
30
31 int pixel_size = PIXEL_SIZE;
32 char dot_fg = DOT_FOREGROUND;
33 char dot_bg = DOT_BACKGROUND;
34
35
36 void usage(void);
37 void dump_char(long ch, unsigned char *buff);
38
39
40 int
41 main(int argc, char** argv)
/* [<][>][^][v][top][bottom][index][help] */
42 {
43 unsigned char buff[24*(24/8)];
44 int fd, dsize, need_close;
45 long ch;
46
47 argc--; argv++;
48
49 while ((argc > 0) && (argv[0][0] == '-')){
50 if (strcmp(argv[0], "-24") == 0){
51 pixel_size = 24;
52 } else if (strcmp(argv[0], "-16") == 0){
53 pixel_size = 16;
54 } else if (strcmp(argv[0], "-fg") == 0){
55 argc--; argv++;
56 dot_fg = argv[0][0];
57 } else if (strcmp(argv[0], "-bg") == 0){
58 argc--; argv++;
59 dot_bg = argv[0][0];
60 } else if ((strcmp(argv[0], "-h") == 0)
61 || (strcmp(argv[0], "-help") == 0)
62 || (strcmp(argv[0], "--help") == 0) ){
63 usage();
64 }
65 argc--; argv++;
66 }
67
68 dsize = pixel_size * ((pixel_size + 7) / 8);
69
70 if (argc > 0){
71 need_close = 1;
72 if ((fd = open(argv[0], O_RDONLY)) < 0){
73 fprintf(stderr, "Can't open %s\n", argv[0]);
74 exit(0);
75 }
76 argc--; argv++;
77 } else {
78 need_close = 0;
79 fd = 0;
80 }
81
82 if (argc > 0){
83 while (argc > 0){
84 sscanf(argv[0], "%li", &ch);
85 if (ch < 1){
86 fprintf(stderr, "No such character: %s\n", argv[0]);
87 continue;
88 }
89 lseek(fd, (ch-1) * dsize, SEEK_SET);
90 if (read(fd, buff, dsize) > 0){
91 dump_char(ch, buff);
92 } else {
93 fprintf(stderr, "No such character: %s\n", argv[0]);
94 }
95 argc--; argv++;
96 }
97 } else {
98 ch = 1;
99 while (read(fd, buff, dsize) > 0){
100 dump_char(ch, buff);
101 ch++;
102 }
103 }
104
105 if (need_close == 1){
106 close(fd);
107 }
108
109 return 0;
110 }
111
112
113 void
114 usage(void)
/* [<][>][^][v][top][bottom][index][help] */
115 {
116
117 fprintf(stderr, "ekdump - dump eKanji font in ASCII art form.\n");
118 fprintf(stderr, "Usage: ekdump [option] [font_file [code...]]\n");
119 fprintf(stderr, " options:\n");
120 fprintf(stderr, " -fg C Foreground character [default: %c]\n",
121 DOT_FOREGROUND);
122 fprintf(stderr, " -bg C Background character [default: %c]\n",
123 DOT_BACKGROUND);
124 fprintf(stderr, " -24 Dot size of the font file 24-dot (default)\n");
125 fprintf(stderr, " -16 Dot size of the font file 16-dot\n");
126 fprintf(stderr, " -help Print help.\n");
127 fprintf(stderr, "If character codes are not given, all characters\n");
128 fprintf(stderr, "are dumped in a font file. If font file name is\n");
129 fprintf(stderr, "not given, ekdump reads font file data from\n");
130 fprintf(stderr, "standard input and all characters are dumped\n");
131 fprintf(stderr, "in the input stream.\n");
132 exit(0);
133 }
134
135 void
136 dump_char(long ch, unsigned char *buff)
/* [<][>][^][v][top][bottom][index][help] */
137 {
138 int wb, i, j;
139 static unsigned char bits[] = { 0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01 };
140
141 printf("Code %06d (0x%06x, Row %d Cel %d)\n",
142 ch, ch, (ch-1)/94+1, (ch-1)%94 + 1);
143
144 wb = (pixel_size + 7) / 8;
145 for (i = 0; i < pixel_size; i++){
146 for (j = 0; j < pixel_size; j++){
147 if ((buff[i*wb + (j/8)] & bits[j%8]) != 0){
148 putchar(dot_fg);
149 } else {
150 putchar(dot_bg);
151 }
152 }
153 putchar('\n');
154 }
155 putchar('\n');
156 }
157
158
159 /*EOF*/