aboutsummaryrefslogtreecommitdiff
path: root/console-tools/loadfont.c
diff options
context:
space:
mode:
authorMatt Kraai <kraai@debian.org>2000-10-25 17:00:36 +0000
committerMatt Kraai <kraai@debian.org>2000-10-25 17:00:36 +0000
commitef5529b27865adc79cd4d48f932d477b1d79b94e (patch)
tree88e77273fdc4f681859d3b3ef99507535c172f7b /console-tools/loadfont.c
parent9133c98a9d5b26fd645d30f70c4cf994aea972e9 (diff)
downloadbusybox-w32-ef5529b27865adc79cd4d48f932d477b1d79b94e.tar.gz
busybox-w32-ef5529b27865adc79cd4d48f932d477b1d79b94e.tar.bz2
busybox-w32-ef5529b27865adc79cd4d48f932d477b1d79b94e.zip
Added a new perrorMsg function, cleanup up error handling, fixed TRUE/FALSE
uses, and other minor fixes.
Diffstat (limited to 'console-tools/loadfont.c')
-rw-r--r--console-tools/loadfont.c69
1 files changed, 24 insertions, 45 deletions
diff --git a/console-tools/loadfont.c b/console-tools/loadfont.c
index d6eadc353..f69f52fd8 100644
--- a/console-tools/loadfont.c
+++ b/console-tools/loadfont.c
@@ -43,18 +43,15 @@ extern int loadfont_main(int argc, char **argv)
43{ 43{
44 int fd; 44 int fd;
45 45
46 if (argc>=2 && *argv[1]=='-') { 46 if (argc != 1)
47 usage(loadfont_usage); 47 usage(loadfont_usage);
48 }
49 48
50 fd = open("/dev/tty0", O_RDWR); 49 fd = open("/dev/tty0", O_RDWR);
51 if (fd < 0) { 50 if (fd < 0)
52 errorMsg("Error opening /dev/tty0: %s\n", strerror(errno)); 51 fatalPerror("Error opening /dev/tty0");
53 return( FALSE);
54 }
55 loadnewfont(fd); 52 loadnewfont(fd);
56 53
57 return( TRUE); 54 return EXIT_SUCCESS;
58} 55}
59 56
60static void do_loadfont(int fd, char *inbuf, int unit, int fontsize) 57static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
@@ -64,10 +61,8 @@ static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
64 61
65 memset(buf, 0, sizeof(buf)); 62 memset(buf, 0, sizeof(buf));
66 63
67 if (unit < 1 || unit > 32) { 64 if (unit < 1 || unit > 32)
68 errorMsg("Bad character size %d\n", unit); 65 fatalError("Bad character size %d\n", unit);
69 exit(1);
70 }
71 66
72 for (i = 0; i < fontsize; i++) 67 for (i = 0; i < fontsize; i++)
73 memcpy(buf + (32 * i), inbuf + (unit * i), unit); 68 memcpy(buf + (32 * i), inbuf + (unit * i), unit);
@@ -82,13 +77,11 @@ static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
82 77
83 if (ioctl(fd, PIO_FONTX, &cfd) == 0) 78 if (ioctl(fd, PIO_FONTX, &cfd) == 0)
84 return; /* success */ 79 return; /* success */
85 perror("PIO_FONTX ioctl error (trying PIO_FONT)"); 80 perrorMsg("PIO_FONTX ioctl error (trying PIO_FONT)");
86 } 81 }
87#endif 82#endif
88 if (ioctl(fd, PIO_FONT, buf)) { 83 if (ioctl(fd, PIO_FONT, buf))
89 perror("PIO_FONT ioctl error"); 84 fatalPerror("PIO_FONT ioctl error");
90 exit(1);
91 }
92} 85}
93 86
94static void 87static void
@@ -127,11 +120,10 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
127#ifdef ENOIOCTLCMD 120#ifdef ENOIOCTLCMD
128 if (errno == ENOIOCTLCMD) { 121 if (errno == ENOIOCTLCMD) {
129 errorMsg("It seems this kernel is older than 1.1.92\n"); 122 errorMsg("It seems this kernel is older than 1.1.92\n");
130 errorMsg("No Unicode mapping table loaded.\n"); 123 fatalError("No Unicode mapping table loaded.\n");
131 } else 124 } else
132#endif 125#endif
133 perror("PIO_UNIMAPCLR"); 126 fatalPerror("PIO_UNIMAPCLR");
134 exit(1);
135 } 127 }
136 ud.entry_ct = ct; 128 ud.entry_ct = ct;
137 ud.entries = up; 129 ud.entries = up;
@@ -141,8 +133,7 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
141 /* change advice parameters */ 133 /* change advice parameters */
142 } 134 }
143#endif 135#endif
144 perror("PIO_UNIMAP"); 136 fatalPerror("PIO_UNIMAP");
145 exit(1);
146 } 137 }
147} 138}
148 139
@@ -158,18 +149,14 @@ static void loadnewfont(int fd)
158 * just read the entire file. 149 * just read the entire file.
159 */ 150 */
160 inputlth = fread(inbuf, 1, sizeof(inbuf), stdin); 151 inputlth = fread(inbuf, 1, sizeof(inbuf), stdin);
161 if (ferror(stdin)) { 152 if (ferror(stdin))
162 perror("Error reading input font"); 153 fatalPerror("Error reading input font");
163 exit(1);
164 }
165 /* use malloc/realloc in case of giant files; 154 /* use malloc/realloc in case of giant files;
166 maybe these do not occur: 16kB for the font, 155 maybe these do not occur: 16kB for the font,
167 and 16kB for the map leaves 32 unicode values 156 and 16kB for the map leaves 32 unicode values
168 for each font position */ 157 for each font position */
169 if (!feof(stdin)) { 158 if (!feof(stdin))
170 perror("Font too large"); 159 fatalPerror("Font too large");
171 exit(1);
172 }
173 160
174 /* test for psf first */ 161 /* test for psf first */
175 { 162 {
@@ -186,26 +173,20 @@ static void loadnewfont(int fd)
186 if (!PSF_MAGIC_OK(psfhdr)) 173 if (!PSF_MAGIC_OK(psfhdr))
187 goto no_psf; 174 goto no_psf;
188 175
189 if (psfhdr.mode > PSF_MAXMODE) { 176 if (psfhdr.mode > PSF_MAXMODE)
190 errorMsg("Unsupported psf file mode\n"); 177 fatalError("Unsupported psf file mode\n");
191 exit(1);
192 }
193 fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256); 178 fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
194#if !defined( PIO_FONTX ) || defined( __sparc__ ) 179#if !defined( PIO_FONTX ) || defined( __sparc__ )
195 if (fontsize != 256) { 180 if (fontsize != 256)
196 errorMsg("Only fontsize 256 supported\n"); 181 fatalError("Only fontsize 256 supported\n");
197 exit(1);
198 }
199#endif 182#endif
200 hastable = (psfhdr.mode & PSF_MODEHASTAB); 183 hastable = (psfhdr.mode & PSF_MODEHASTAB);
201 unit = psfhdr.charsize; 184 unit = psfhdr.charsize;
202 head0 = sizeof(struct psf_header); 185 head0 = sizeof(struct psf_header);
203 186
204 head = head0 + fontsize * unit; 187 head = head0 + fontsize * unit;
205 if (head > inputlth || (!hastable && head != inputlth)) { 188 if (head > inputlth || (!hastable && head != inputlth))
206 errorMsg("Input file: bad length\n"); 189 fatalError("Input file: bad length\n");
207 exit(1);
208 }
209 do_loadfont(fd, inbuf + head0, unit, fontsize); 190 do_loadfont(fd, inbuf + head0, unit, fontsize);
210 if (hastable) 191 if (hastable)
211 do_loadtable(fd, inbuf + head, inputlth - head, fontsize); 192 do_loadtable(fd, inbuf + head, inputlth - head, fontsize);
@@ -219,10 +200,8 @@ static void loadnewfont(int fd)
219 unit = 16; 200 unit = 16;
220 } else { 201 } else {
221 /* bare font */ 202 /* bare font */
222 if (inputlth & 0377) { 203 if (inputlth & 0377)
223 errorMsg("Bad input file size\n"); 204 fatalError("Bad input file size\n");
224 exit(1);
225 }
226 offset = 0; 205 offset = 0;
227 unit = inputlth / 256; 206 unit = inputlth / 256;
228 } 207 }