aboutsummaryrefslogtreecommitdiff
path: root/console-tools
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-02-08 19:58:47 +0000
committerErik Andersen <andersen@codepoet.org>2000-02-08 19:58:47 +0000
commite49d5ecbbe51718fa925b6890a735e5937cc2aa2 (patch)
treec90bda10731ad9333ce3b404f993354c9fc104b8 /console-tools
parentc0bf817bbc5c7867fbe8fb76d5c39f8ee802692f (diff)
downloadbusybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.gz
busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.tar.bz2
busybox-w32-e49d5ecbbe51718fa925b6890a735e5937cc2aa2.zip
Some formatting updates (ran the code through indent)
-Erik
Diffstat (limited to 'console-tools')
-rw-r--r--console-tools/chvt.c36
-rw-r--r--console-tools/clear.c6
-rw-r--r--console-tools/deallocvt.c62
-rw-r--r--console-tools/loadacm.c664
-rw-r--r--console-tools/loadfont.c196
-rw-r--r--console-tools/loadkmap.c103
6 files changed, 518 insertions, 549 deletions
diff --git a/console-tools/chvt.c b/console-tools/chvt.c
index bea00ea83..a32bd3e78 100644
--- a/console-tools/chvt.c
+++ b/console-tools/chvt.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * chvt.c - aeb - 940227 - Change virtual terminal 3 * chvt.c - aeb - 940227 - Change virtual terminal
3 * 4 *
@@ -13,24 +14,23 @@
13 14
14extern int getfd(void); 15extern int getfd(void);
15 16
16int 17int chvt_main(int argc, char **argv)
17chvt_main(int argc, char** argv)
18{ 18{
19 int fd, num; 19 int fd, num;
20 20
21 if ( ( argc != 2) || (**(argv+1) == '-' ) ) { 21 if ((argc != 2) || (**(argv + 1) == '-')) {
22 usage ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n"); 22 usage
23 } 23 ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
24 fd = get_console_fd("/dev/console"); 24 }
25 num = atoi(argv[1]); 25 fd = get_console_fd("/dev/console");
26 if (ioctl(fd,VT_ACTIVATE,num)) { 26 num = atoi(argv[1]);
27 perror("VT_ACTIVATE"); 27 if (ioctl(fd, VT_ACTIVATE, num)) {
28 exit(FALSE); 28 perror("VT_ACTIVATE");
29 } 29 exit(FALSE);
30 if (ioctl(fd,VT_WAITACTIVE,num)) { 30 }
31 perror("VT_WAITACTIVE"); 31 if (ioctl(fd, VT_WAITACTIVE, num)) {
32 exit(FALSE); 32 perror("VT_WAITACTIVE");
33 } 33 exit(FALSE);
34 exit( TRUE); 34 }
35 exit(TRUE);
35} 36}
36
diff --git a/console-tools/clear.c b/console-tools/clear.c
index 67a3af983..899840a8a 100644
--- a/console-tools/clear.c
+++ b/console-tools/clear.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Mini clear implementation for busybox 3 * Mini clear implementation for busybox
3 * 4 *
@@ -25,9 +26,8 @@
25#include <stdio.h> 26#include <stdio.h>
26 27
27 28
28extern int 29extern int clear_main(int argc, char **argv)
29clear_main(int argc, char** argv)
30{ 30{
31 printf("\033[H\033[J"); 31 printf("\033[H\033[J");
32 exit( TRUE); 32 exit(TRUE);
33} 33}
diff --git a/console-tools/deallocvt.c b/console-tools/deallocvt.c
index 1e13ff69c..141062edc 100644
--- a/console-tools/deallocvt.c
+++ b/console-tools/deallocvt.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s) 3 * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
3 * Renamed deallocvt. 4 * Renamed deallocvt.
@@ -13,38 +14,39 @@
13extern int getfd(void); 14extern int getfd(void);
14char *progname; 15char *progname;
15 16
16int 17int deallocvt_main(int argc, char *argv[])
17deallocvt_main(int argc, char *argv[]) { 18{
18 int fd, num, i; 19 int fd, num, i;
19 20
20 if ( ( argc != 2) || (**(argv+1) == '-' ) ) { 21 if ((argc != 2) || (**(argv + 1) == '-')) {
21 usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n"); 22 usage
22 } 23 ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
24 }
23 25
24 progname = argv[0]; 26 progname = argv[0];
25 27
26 fd = get_console_fd("/dev/console"); 28 fd = get_console_fd("/dev/console");
27 29
28 if (argc == 1) { 30 if (argc == 1) {
29 /* deallocate all unused consoles */ 31 /* deallocate all unused consoles */
30 if (ioctl(fd,VT_DISALLOCATE,0)) { 32 if (ioctl(fd, VT_DISALLOCATE, 0)) {
31 perror("VT_DISALLOCATE"); 33 perror("VT_DISALLOCATE");
32 exit(1); 34 exit(1);
33 } 35 }
34 } else 36 } else
35 for (i = 1; i < argc; i++) { 37 for (i = 1; i < argc; i++) {
36 num = atoi(argv[i]); 38 num = atoi(argv[i]);
37 if (num == 0) 39 if (num == 0)
38 fprintf(stderr, "%s: 0: illegal VT number\n", progname); 40 fprintf(stderr, "%s: 0: illegal VT number\n", progname);
39 else if (num == 1) 41 else if (num == 1)
40 fprintf(stderr, "%s: VT 1 cannot be deallocated\n", progname); 42 fprintf(stderr, "%s: VT 1 cannot be deallocated\n",
41 else 43 progname);
42 if (ioctl(fd,VT_DISALLOCATE,num)) { 44 else if (ioctl(fd, VT_DISALLOCATE, num)) {
43 perror("VT_DISALLOCATE"); 45 perror("VT_DISALLOCATE");
44 fprintf(stderr, "%s: could not deallocate console %d\n", 46 fprintf(stderr, "%s: could not deallocate console %d\n",
45 progname, num); 47 progname, num);
46 exit(1); 48 exit(1);
47 } 49 }
48 } 50 }
49 exit(0); 51 exit(0);
50} 52}
diff --git a/console-tools/loadacm.c b/console-tools/loadacm.c
index 491bc5ce8..072562f6b 100644
--- a/console-tools/loadacm.c
+++ b/console-tools/loadacm.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Derived from 3 * Derived from
3 * mapscrn.c - version 0.92 4 * mapscrn.c - version 0.92
@@ -23,120 +24,115 @@
23typedef unsigned short unicode; 24typedef unsigned short unicode;
24 25
25static long int ctoi(unsigned char *s, int *is_unicode); 26static long int ctoi(unsigned char *s, int *is_unicode);
26int old_screen_map_read_ascii(FILE *fp, unsigned char buf[]); 27int old_screen_map_read_ascii(FILE * fp, unsigned char buf[]);
27int uni_screen_map_read_ascii(FILE *fp, unicode buf[], int* is_unicode); 28int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode);
28unicode utf8_to_ucs2 (char* buf); 29unicode utf8_to_ucs2(char *buf);
29int screen_map_load(int fd, FILE *fp); 30int screen_map_load(int fd, FILE * fp);
30 31
31int loadacm_main(int argc, char **argv) 32int loadacm_main(int argc, char **argv)
32{ 33{
33 int fd; 34 int fd;
34 35
35 fd = open("/dev/tty", O_RDWR); 36 fd = open("/dev/tty", O_RDWR);
36 if (fd < 0) { 37 if (fd < 0) {
37 fprintf(stderr, "Error opening /dev/tty1: %s\n", strerror(errno)); 38 fprintf(stderr, "Error opening /dev/tty1: %s\n", strerror(errno));
38 return 1; 39 return 1;
39 } 40 }
40 41
41 if (screen_map_load(fd, stdin)) 42 if (screen_map_load(fd, stdin)) {
42 { 43 fprintf(stderr, "Error loading acm: %s\n", strerror(errno));
43 fprintf(stderr, "Error loading acm: %s\n", strerror(errno)); 44 return 1;
44 return 1; 45 }
45 } 46
46 47 write(fd, "\033(K", 3);
47 write(fd, "\033(K", 3); 48
48 49 return 0;
49 return 0;
50} 50}
51 51
52int screen_map_load(int fd, FILE *fp) 52int screen_map_load(int fd, FILE * fp)
53{ 53{
54 struct stat stbuf; 54 struct stat stbuf;
55 unicode wbuf[E_TABSZ]; 55 unicode wbuf[E_TABSZ];
56 unsigned char buf[E_TABSZ]; 56 unsigned char buf[E_TABSZ];
57 int parse_failed = 0; 57 int parse_failed = 0;
58 int is_unicode; 58 int is_unicode;
59 59
60 if (fstat(fp->_fileno, &stbuf)) 60 if (fstat(fp->_fileno, &stbuf))
61 perror("Cannot stat map file"), exit(1); 61 perror("Cannot stat map file"), exit(1);
62 62
63 /* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */ 63 /* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
64 if (!(parse_failed = (-1 == uni_screen_map_read_ascii(fp,wbuf,&is_unicode))) || 64 if (!
65 (S_ISREG(stbuf.st_mode) && 65 (parse_failed =
66 (stbuf.st_size == (sizeof(unicode) * E_TABSZ)))) /* test for binary UTF map by size */ 66 (-1 == uni_screen_map_read_ascii(fp, wbuf, &is_unicode)))
67 { 67|| (S_ISREG(stbuf.st_mode) && (stbuf.st_size == (sizeof(unicode) * E_TABSZ)))) { /* test for binary UTF map by size */
68 if (parse_failed) 68 if (parse_failed) {
69 { 69 if (-1 == fseek(fp, 0, SEEK_SET)) {
70 if (-1 == fseek (fp, 0, SEEK_SET)) 70 if (errno == ESPIPE)
71 { 71 fprintf(stderr,
72 if (errno == ESPIPE) 72 "16bit screen-map MUST be a regular file.\n"),
73 fprintf (stderr, "16bit screen-map MUST be a regular file.\n"), exit (1); 73 exit(1);
74 else 74 else
75 perror ("fseek failed reading binary 16bit screen-map"), exit (1); 75 perror("fseek failed reading binary 16bit screen-map"),
76 } 76 exit(1);
77 77 }
78 if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) 78
79 perror("Cannot read [new] map from file"), exit(1); 79 if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1)
80 perror("Cannot read [new] map from file"), exit(1);
80#if 0 81#if 0
81 else 82 else
82 fprintf(stderr, "Input screen-map is binary.\n"); 83 fprintf(stderr, "Input screen-map is binary.\n");
83#endif 84#endif
85 }
86
87 /* if it was effectively a 16-bit ASCII, OK, else try to read as 8-bit map */
88 /* same if it was binary, ie. if parse_failed */
89 if (parse_failed || is_unicode) {
90 if (ioctl(fd, PIO_UNISCRNMAP, wbuf))
91 perror("PIO_UNISCRNMAP ioctl"), exit(1);
92 else
93 return 0;
94 }
84 } 95 }
85 96
86 /* if it was effectively a 16-bit ASCII, OK, else try to read as 8-bit map */ 97 /* rewind... */
87 /* same if it was binary, ie. if parse_failed */ 98 if (-1 == fseek(fp, 0, SEEK_SET)) {
88 if (parse_failed || is_unicode) 99 if (errno == ESPIPE)
89 { 100 fprintf(stderr,
90 if (ioctl(fd,PIO_UNISCRNMAP,wbuf)) 101 "Assuming 8bit screen-map - MUST be a regular file.\n"),
91 perror("PIO_UNISCRNMAP ioctl"), exit(1); 102 exit(1);
92 else 103 else
93 return 0; 104 perror("fseek failed assuming 8bit screen-map"), exit(1);
94 } 105 }
95 } 106
96 107 /* ... and try an old 8-bit screen-map */
97 /* rewind... */ 108 if (!(parse_failed = (-1 == old_screen_map_read_ascii(fp, buf))) ||
98 if (-1 == fseek (fp, 0, SEEK_SET)) 109 (S_ISREG(stbuf.st_mode) && (stbuf.st_size == E_TABSZ))) { /* test for binary old 8-bit map by size */
99 { 110 if (parse_failed) {
100 if (errno == ESPIPE) 111 if (-1 == fseek(fp, 0, SEEK_SET)) {
101 fprintf (stderr, "Assuming 8bit screen-map - MUST be a regular file.\n"), exit (1); 112 if (errno == ESPIPE)
102 else 113 /* should not - it succedeed above */
103 perror ("fseek failed assuming 8bit screen-map"), exit (1); 114 fprintf(stderr, "fseek() returned ESPIPE !\n"),
104 } 115 exit(1);
105 116 else
106 /* ... and try an old 8-bit screen-map */ 117 perror("fseek for binary 8bit screen-map"), exit(1);
107 if (!(parse_failed = (-1 == old_screen_map_read_ascii(fp,buf))) || 118 }
108 (S_ISREG(stbuf.st_mode) && 119
109 (stbuf.st_size == E_TABSZ))) /* test for binary old 8-bit map by size */ 120 if (fread(buf, E_TABSZ, 1, fp) != 1)
110 { 121 perror("Cannot read [old] map from file"), exit(1);
111 if (parse_failed)
112 {
113 if (-1 == fseek (fp, 0, SEEK_SET))
114 {
115 if (errno == ESPIPE)
116 /* should not - it succedeed above */
117 fprintf (stderr, "fseek() returned ESPIPE !\n"), exit (1);
118 else
119 perror ("fseek for binary 8bit screen-map"), exit (1);
120 }
121
122 if (fread(buf,E_TABSZ,1,fp) != 1)
123 perror("Cannot read [old] map from file"), exit(1);
124#if 0 122#if 0
125 else 123 else
126 fprintf(stderr, "Input screen-map is binary.\n"); 124 fprintf(stderr, "Input screen-map is binary.\n");
127#endif 125#endif
126 }
127
128 if (ioctl(fd, PIO_SCRNMAP, buf))
129 perror("PIO_SCRNMAP ioctl"), exit(1);
130 else
131 return 0;
132 } else {
133 fprintf(stderr, "Error parsing symbolic map\n");
134 exit(1);
128 } 135 }
129
130 if (ioctl(fd,PIO_SCRNMAP,buf))
131 perror("PIO_SCRNMAP ioctl"), exit(1);
132 else
133 return 0;
134 }
135 else
136 {
137 fprintf(stderr, "Error parsing symbolic map\n");
138 exit(1);
139 }
140} 136}
141 137
142 138
@@ -149,116 +145,111 @@ int screen_map_load(int fd, FILE *fp)
149 * 145 *
150 * FIXME: ignores everything after second word 146 * FIXME: ignores everything after second word
151 */ 147 */
152int uni_screen_map_read_ascii(FILE *fp, unicode buf[], int *is_unicode) 148int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode)
153{ 149{
154 char buffer[256]; /* line buffer reading file */ 150 char buffer[256]; /* line buffer reading file */
155 char *p, *q; /* 1st + 2nd words in line */ 151 char *p, *q; /* 1st + 2nd words in line */
156 int in, on; /* the same, as numbers */ 152 int in, on; /* the same, as numbers */
157 int tmp_is_unicode; /* tmp for is_unicode calculation */ 153 int tmp_is_unicode; /* tmp for is_unicode calculation */
158 int i; /* loop index - result holder */ 154 int i; /* loop index - result holder */
159 int ret_code = 0; /* return code */ 155 int ret_code = 0; /* return code */
160 sigset_t sigset, old_sigset; 156 sigset_t sigset, old_sigset;
161 157
162 assert (is_unicode); 158 assert(is_unicode);
163 159
164 *is_unicode = 0; 160 *is_unicode = 0;
165 161
166 /* first 128 codes defaults to ASCII */ 162 /* first 128 codes defaults to ASCII */
167 for (i=0; i<128; i++) buf[i] = i; 163 for (i = 0; i < 128; i++)
168 /* remaining defaults to replacement char (usually E_TABSZ = 256) */ 164 buf[i] = i;
169 for ( ; i<E_TABSZ; i++) buf[i] = 0xfffd; 165 /* remaining defaults to replacement char (usually E_TABSZ = 256) */
170 166 for (; i < E_TABSZ; i++)
171 /* block SIGCHLD */ 167 buf[i] = 0xfffd;
172 sigemptyset (&sigset); 168
173 sigaddset (&sigset, SIGCHLD); 169 /* block SIGCHLD */
174 sigprocmask (SIG_BLOCK, &sigset, &old_sigset); 170 sigemptyset(&sigset);
175 171 sigaddset(&sigset, SIGCHLD);
176 do 172 sigprocmask(SIG_BLOCK, &sigset, &old_sigset);
177 { 173
178 if (NULL == fgets(buffer, sizeof(buffer),fp)) 174 do {
179 { 175 if (NULL == fgets(buffer, sizeof(buffer), fp)) {
180 if (feof (fp)) 176 if (feof(fp))
181 break; 177 break;
182 else 178 else {
183 { 179 perror("uni_screen_map_read_ascii() can't read line");
184 perror ("uni_screen_map_read_ascii() can't read line"); 180 exit(2);
185 exit (2); 181 }
186 } 182 }
187 } 183
188 184 /* get "charset-relative charcode", stripping leading spaces */
189 /* get "charset-relative charcode", stripping leading spaces */ 185 p = strtok(buffer, " \t\n");
190 p = strtok(buffer," \t\n"); 186
191 187 /* skip empty lines and comments */
192 /* skip empty lines and comments */ 188 if (!p || *p == '#')
193 if (!p || *p == '#') 189 continue;
194 continue; 190
195 191 /* get unicode mapping */
196 /* get unicode mapping */ 192 q = strtok(NULL, " \t\n");
197 q = strtok(NULL," \t\n"); 193 if (q) {
198 if (q) 194 in = ctoi(p, NULL);
199 { 195 if (in < 0 || in > 255) {
200 in = ctoi(p, NULL); 196 ret_code = -1;
201 if (in < 0 || in > 255) 197 break;
202 { 198 }
203 ret_code = -1; 199
204 break; 200 on = ctoi(q, &tmp_is_unicode);
205 } 201 if (in < 0 && on > 65535) {
206 202 ret_code = -1;
207 on = ctoi(q, &tmp_is_unicode); 203 break;
208 if (in < 0 && on > 65535) 204 }
209 { 205
210 ret_code = -1; 206 *is_unicode |= tmp_is_unicode;
211 break; 207 buf[in] = on;
212 } 208 } else {
213 209 ret_code = -1;
214 *is_unicode |= tmp_is_unicode; 210 break;
215 buf[in] = on; 211 }
216 } 212 }
217 else 213 while (1); /* terminated by break on feof() */
218 {
219 ret_code = -1;
220 break;
221 }
222 }
223 while (1); /* terminated by break on feof() */
224 214
225 /* restore sig mask */ 215 /* restore sig mask */
226 sigprocmask (SIG_SETMASK, &old_sigset, NULL); 216 sigprocmask(SIG_SETMASK, &old_sigset, NULL);
227 217
228 return ret_code; 218 return ret_code;
229} 219}
230 220
231 221
232int old_screen_map_read_ascii(FILE *fp, unsigned char buf[]) 222int old_screen_map_read_ascii(FILE * fp, unsigned char buf[])
233{ 223{
234 char buffer[256]; 224 char buffer[256];
235 int in, on; 225 int in, on;
236 char *p, *q; 226 char *p, *q;
237 227
238 for (in=0; in<256; in++) buf[in]=in; 228 for (in = 0; in < 256; in++)
239 229 buf[in] = in;
240 while (fgets(buffer,sizeof(buffer)-1,fp)) 230
241 { 231 while (fgets(buffer, sizeof(buffer) - 1, fp)) {
242 p = strtok(buffer," \t\n"); 232 p = strtok(buffer, " \t\n");
243 233
244 if (!p || *p == '#') 234 if (!p || *p == '#')
245 continue; 235 continue;
246 236
247 q = strtok(NULL," \t\n#"); 237 q = strtok(NULL, " \t\n#");
248 if (q) 238 if (q) {
249 { 239 in = ctoi(p, NULL);
250 in = ctoi(p, NULL); 240 if (in < 0 || in > 255)
251 if (in < 0 || in > 255) return -1; 241 return -1;
252 242
253 on = ctoi(q, NULL); 243 on = ctoi(q, NULL);
254 if (in < 0 && on > 255) return -1; 244 if (in < 0 && on > 255)
255 245 return -1;
256 buf[in] = on; 246
247 buf[in] = on;
248 } else
249 return -1;
257 } 250 }
258 else return -1; 251
259 } 252 return (0);
260
261 return(0);
262} 253}
263 254
264 255
@@ -270,172 +261,145 @@ int old_screen_map_read_ascii(FILE *fp, unsigned char buf[])
270 * 261 *
271 * CAVEAT: will report valid UTF mappings using only 1 byte as 8-bit ones. 262 * CAVEAT: will report valid UTF mappings using only 1 byte as 8-bit ones.
272 */ 263 */
273long int ctoi(unsigned char *s, int *is_unicode) 264long int ctoi(unsigned char *s, int *is_unicode)
274{ 265{
275 int i; 266 int i;
276 size_t ls; 267 size_t ls;
277 268
278 ls = strlen(s); 269 ls = strlen(s);
279 if (is_unicode) *is_unicode = 0; 270 if (is_unicode)
280 271 *is_unicode = 0;
281 /* hex-specified UCS2 */ 272
282 if ((strncmp(s,"U+",2) == 0) && 273 /* hex-specified UCS2 */
283 (strspn(s+2,"0123456789abcdefABCDEF") == ls-2)) 274 if ((strncmp(s, "U+", 2) == 0) &&
284 { 275 (strspn(s + 2, "0123456789abcdefABCDEF") == ls - 2)) {
285 sscanf(s+2,"%x",&i); 276 sscanf(s + 2, "%x", &i);
286 if (is_unicode) *is_unicode = 1; 277 if (is_unicode)
287 } 278 *is_unicode = 1;
288 279 }
289 /* hex-specified byte */ 280
290 else if ((ls <= 4) && (strncmp(s,"0x",2) == 0) && 281 /* hex-specified byte */
291 (strspn(s+2,"0123456789abcdefABCDEF") == ls-2)) 282 else if ((ls <= 4) && (strncmp(s, "0x", 2) == 0) &&
292 sscanf(s+2,"%x",&i); 283 (strspn(s + 2, "0123456789abcdefABCDEF") == ls - 2))
293 284 sscanf(s + 2, "%x", &i);
294 /* oct-specified number (byte) */ 285
295 else if ((*s == '0') && 286 /* oct-specified number (byte) */
296 (strspn(s,"01234567") == ls)) 287 else if ((*s == '0') && (strspn(s, "01234567") == ls))
297 sscanf(s,"%o",&i); 288 sscanf(s, "%o", &i);
298 289
299 /* dec-specified number (byte) */ 290 /* dec-specified number (byte) */
300 else if (strspn(s,"0123456789") == ls) 291 else if (strspn(s, "0123456789") == ls)
301 sscanf(s,"%d",&i); 292 sscanf(s, "%d", &i);
302 293
303 /* single-byte quoted char */ 294 /* single-byte quoted char */
304 else if ((strlen(s) == 3) && (s[0] == '\'') && (s[2] == '\'')) 295 else if ((strlen(s) == 3) && (s[0] == '\'') && (s[2] == '\''))
305 i=s[1]; 296 i = s[1];
306 297
307 /* multi-byte UTF8 quoted char */ 298 /* multi-byte UTF8 quoted char */
308 else if ((s[0] == '\'') && (s[ls-1] == '\'')) 299 else if ((s[0] == '\'') && (s[ls - 1] == '\'')) {
309 { 300 s[ls - 1] = 0; /* ensure we'll not "parse UTF too far" */
310 s[ls-1] = 0; /* ensure we'll not "parse UTF too far" */ 301 i = utf8_to_ucs2(s + 1);
311 i = utf8_to_ucs2(s+1); 302 if (is_unicode)
312 if (is_unicode) *is_unicode = 1; 303 *is_unicode = 1;
313 } 304 } else
314 else 305 return (-1);
315 return(-1); 306
316 307 return (i);
317 return(i);
318} 308}
319 309
320 310
321void saveoldmap(int fd, char *omfil) 311void saveoldmap(int fd, char *omfil)
322{ 312{
323 FILE *fp; 313 FILE *fp;
324 char buf[E_TABSZ]; 314 char buf[E_TABSZ];
315
325#ifdef GIO_UNISCRNMAP 316#ifdef GIO_UNISCRNMAP
326 unicode xbuf[E_TABSZ]; 317 unicode xbuf[E_TABSZ];
327 int is_old_map = 0; 318 int is_old_map = 0;
328 319
329 if (ioctl(fd,GIO_UNISCRNMAP,xbuf)) 320 if (ioctl(fd, GIO_UNISCRNMAP, xbuf)) {
330 { 321 perror("GIO_UNISCRNMAP ioctl error");
331 perror("GIO_UNISCRNMAP ioctl error");
332#endif 322#endif
333 if (ioctl(fd,GIO_SCRNMAP,buf)) 323 if (ioctl(fd, GIO_SCRNMAP, buf)) {
334 { 324 perror("GIO_SCRNMAP ioctl error");
335 perror("GIO_SCRNMAP ioctl error"); 325 exit(1);
336 exit(1); 326 } else
337 } 327 is_old_map = 1;
338 else
339 is_old_map = 1;
340#ifdef GIO_UNISCRNMAP 328#ifdef GIO_UNISCRNMAP
341 } 329 }
342#endif 330#endif
343
344 if ((fp = fopen(omfil, "w")) == NULL)
345 {
346 perror(omfil);
347 exit(1);
348 }
349 331
332 if ((fp = fopen(omfil, "w")) == NULL) {
333 perror(omfil);
334 exit(1);
335 }
350#ifdef GIO_UNISCRNMAP 336#ifdef GIO_UNISCRNMAP
351 if (is_old_map) 337 if (is_old_map) {
352 {
353#endif 338#endif
354 if (fwrite(buf,E_TABSZ,1,fp) != 1) 339 if (fwrite(buf, E_TABSZ, 1, fp) != 1) {
355 { 340 perror("Error writing map to file");
356 perror("Error writing map to file"); 341 exit(1);
357 exit(1); 342 }
358 }
359#ifdef GIO_UNISCRNMAP 343#ifdef GIO_UNISCRNMAP
360 } 344 } else if (fwrite(xbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) {
361 else 345 perror("Error writing map to file");
362 if (fwrite(xbuf, sizeof(unicode) * E_TABSZ,1,fp) != 1) 346 exit(1);
363 {
364 perror("Error writing map to file");
365 exit(1);
366 } 347 }
367#endif 348#endif
368 349
369 fclose(fp); 350 fclose(fp);
370} 351}
371 352
372unicode utf8_to_ucs2 (char* buf) 353unicode utf8_to_ucs2(char *buf)
373{ 354{
374 int utf_count = 0; 355 int utf_count = 0;
375 long utf_char; 356 long utf_char;
376 unicode tc; 357 unicode tc;
377 unsigned char c; 358 unsigned char c;
378 359
379 do 360 do {
380 { 361 c = *buf;
381 c = *buf; 362 buf++;
382 buf++; 363
383 364 /* if byte should be part of multi-byte sequence */
384 /* if byte should be part of multi-byte sequence */ 365 if (c & 0x80) {
385 if(c & 0x80) 366 /* if we have already started to parse a UTF8 sequence */
386 { 367 if (utf_count > 0 && (c & 0xc0) == 0x80) {
387 /* if we have already started to parse a UTF8 sequence */ 368 utf_char = (utf_char << 6) | (c & 0x3f);
388 if (utf_count > 0 && (c & 0xc0) == 0x80) 369 utf_count--;
389 { 370 if (utf_count == 0)
390 utf_char = (utf_char << 6) | (c & 0x3f); 371 tc = utf_char;
391 utf_count--; 372 else
392 if (utf_count == 0) 373 continue;
393 tc = utf_char; 374 } else { /* Possibly 1st char of a UTF8 sequence */
394 else 375
395 continue; 376 if ((c & 0xe0) == 0xc0) {
396 } 377 utf_count = 1;
397 else /* Possibly 1st char of a UTF8 sequence */ 378 utf_char = (c & 0x1f);
398 { 379 } else if ((c & 0xf0) == 0xe0) {
399 if ((c & 0xe0) == 0xc0) 380 utf_count = 2;
400 { 381 utf_char = (c & 0x0f);
401 utf_count = 1; 382 } else if ((c & 0xf8) == 0xf0) {
402 utf_char = (c & 0x1f); 383 utf_count = 3;
403 } 384 utf_char = (c & 0x07);
404 else if ((c & 0xf0) == 0xe0) 385 } else if ((c & 0xfc) == 0xf8) {
405 { 386 utf_count = 4;
406 utf_count = 2; 387 utf_char = (c & 0x03);
407 utf_char = (c & 0x0f); 388 } else if ((c & 0xfe) == 0xfc) {
408 } 389 utf_count = 5;
409 else if ((c & 0xf8) == 0xf0) 390 utf_char = (c & 0x01);
410 { 391 } else
411 utf_count = 3; 392 utf_count = 0;
412 utf_char = (c & 0x07); 393 continue;
413 } 394 }
414 else if ((c & 0xfc) == 0xf8) 395 } else { /* not part of multi-byte sequence - treat as ASCII
415 { 396 * this makes incomplete sequences to be ignored
416 utf_count = 4; 397 */
417 utf_char = (c & 0x03); 398 tc = c;
418 } 399 utf_count = 0;
419 else if ((c & 0xfe) == 0xfc) 400 }
420 { 401 }
421 utf_count = 5; 402 while (utf_count);
422 utf_char = (c & 0x01);
423 }
424 else
425 utf_count = 0;
426 continue;
427 }
428 }
429 else /* not part of multi-byte sequence - treat as ASCII
430 * this makes incomplete sequences to be ignored
431 */
432 {
433 tc = c;
434 utf_count = 0;
435 }
436 }
437 while (utf_count);
438
439 return tc;
440}
441 403
404 return tc;
405}
diff --git a/console-tools/loadfont.c b/console-tools/loadfont.c
index e44525d9c..64b725610 100644
--- a/console-tools/loadfont.c
+++ b/console-tools/loadfont.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * loadfont.c - Eugene Crosser & Andries Brouwer 3 * loadfont.c - Eugene Crosser & Andries Brouwer
3 * 4 *
@@ -30,72 +31,69 @@
30#define PSF_SEPARATOR 0xFFFF 31#define PSF_SEPARATOR 0xFFFF
31 32
32static const char loadfont_usage[] = "loadfont\n" 33static const char loadfont_usage[] = "loadfont\n"
33"\n" 34 "\n" "\tLoad a console font from standard input.\n" "\n";
34"\tLoad a console font from standard input.\n"
35"\n";
36 35
37struct psf_header 36struct psf_header {
38{ 37 unsigned char magic1, magic2; /* Magic number */
39 unsigned char magic1, magic2; /* Magic number */ 38 unsigned char mode; /* PSF font mode */
40 unsigned char mode; /* PSF font mode */ 39 unsigned char charsize; /* Character size */
41 unsigned char charsize; /* Character size */
42}; 40};
43 41
44#define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2) 42#define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2)
45 43
46static void loadnewfont(int fd); 44static void loadnewfont(int fd);
47 45
48extern int 46extern int loadfont_main(int argc, char **argv)
49loadfont_main(int argc, char **argv)
50{ 47{
51 int fd; 48 int fd;
52 49
53 fd = open("/dev/tty0", O_RDWR); 50 fd = open("/dev/tty0", O_RDWR);
54 if (fd < 0) { 51 if (fd < 0) {
55 fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno)); 52 fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
56 return 1; 53 return 1;
57 } 54 }
58 loadnewfont(fd); 55 loadnewfont(fd);
59 56
60 return 0; 57 return 0;
61} 58}
62 59
63static void 60static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
64do_loadfont(int fd, char *inbuf, int unit, int fontsize) { 61{
65 char buf[16384]; 62 char buf[16384];
66 int i; 63 int i;
67 64
68 memset(buf,0,sizeof(buf)); 65 memset(buf, 0, sizeof(buf));
69 66
70 if (unit < 1 || unit > 32) { 67 if (unit < 1 || unit > 32) {
71 fprintf(stderr, "Bad character size %d\n", unit); 68 fprintf(stderr, "Bad character size %d\n", unit);
72 exit(1); 69 exit(1);
73 } 70 }
74 71
75 for (i = 0; i < fontsize; i++) 72 for (i = 0; i < fontsize; i++)
76 memcpy(buf+(32*i), inbuf+(unit*i), unit); 73 memcpy(buf + (32 * i), inbuf + (unit * i), unit);
77 74
78#if defined( PIO_FONTX ) && !defined( __sparc__ ) 75#if defined( PIO_FONTX ) && !defined( __sparc__ )
79 { 76 {
80 struct consolefontdesc cfd; 77 struct consolefontdesc cfd;
81 78
82 cfd.charcount = fontsize; 79 cfd.charcount = fontsize;
83 cfd.charheight = unit; 80 cfd.charheight = unit;
84 cfd.chardata = buf; 81 cfd.chardata = buf;
85 82
86 if (ioctl(fd, PIO_FONTX, &cfd) == 0) 83 if (ioctl(fd, PIO_FONTX, &cfd) == 0)
87 return; /* success */ 84 return; /* success */
88 perror("PIO_FONTX ioctl error (trying PIO_FONT)"); 85 perror("PIO_FONTX ioctl error (trying PIO_FONT)");
89 } 86 }
90#endif 87#endif
91 if (ioctl(fd, PIO_FONT, buf)) { 88 if (ioctl(fd, PIO_FONT, buf)) {
92 perror("PIO_FONT ioctl error"); 89 perror("PIO_FONT ioctl error");
93 exit(1); 90 exit(1);
94 } 91 }
95} 92}
96 93
97static void 94static void
98do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) { 95do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
96{
99 struct unimapinit advice; 97 struct unimapinit advice;
100 struct unimapdesc ud; 98 struct unimapdesc ud;
101 struct unipair *up; 99 struct unipair *up;
@@ -103,23 +101,24 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) {
103 int glyph; 101 int glyph;
104 u_short unicode; 102 u_short unicode;
105 103
106 maxct = tailsz; /* more than enough */ 104 maxct = tailsz; /* more than enough */
107 up = (struct unipair *) malloc(maxct * sizeof(struct unipair)); 105 up = (struct unipair *) malloc(maxct * sizeof(struct unipair));
106
108 if (!up) { 107 if (!up) {
109 fprintf(stderr, "Out of memory?\n"); 108 fprintf(stderr, "Out of memory?\n");
110 exit(1); 109 exit(1);
111 } 110 }
112 for (glyph = 0; glyph < fontsize; glyph++) { 111 for (glyph = 0; glyph < fontsize; glyph++) {
113 while (tailsz >= 2) { 112 while (tailsz >= 2) {
114 unicode = (((u_short) inbuf[1]) << 8) + inbuf[0]; 113 unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
115 tailsz -= 2; 114 tailsz -= 2;
116 inbuf += 2; 115 inbuf += 2;
117 if (unicode == PSF_SEPARATOR) 116 if (unicode == PSF_SEPARATOR)
118 break; 117 break;
119 up[ct].unicode = unicode; 118 up[ct].unicode = unicode;
120 up[ct].fontpos = glyph; 119 up[ct].fontpos = glyph;
121 ct++; 120 ct++;
122 } 121 }
123 } 122 }
124 123
125 /* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP 124 /* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP
@@ -128,33 +127,33 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) {
128 advice.advised_hashsize = 0; 127 advice.advised_hashsize = 0;
129 advice.advised_hashstep = 0; 128 advice.advised_hashstep = 0;
130 advice.advised_hashlevel = 0; 129 advice.advised_hashlevel = 0;
131 if(ioctl(fd, PIO_UNIMAPCLR, &advice)) { 130 if (ioctl(fd, PIO_UNIMAPCLR, &advice)) {
132#ifdef ENOIOCTLCMD 131#ifdef ENOIOCTLCMD
133 if (errno == ENOIOCTLCMD) { 132 if (errno == ENOIOCTLCMD) {
134 fprintf(stderr, "It seems this kernel is older than 1.1.92\n"); 133 fprintf(stderr, "It seems this kernel is older than 1.1.92\n");
135 fprintf(stderr, "No Unicode mapping table loaded.\n"); 134 fprintf(stderr, "No Unicode mapping table loaded.\n");
136 } else 135 } else
137#endif 136#endif
138 perror("PIO_UNIMAPCLR"); 137 perror("PIO_UNIMAPCLR");
139 exit(1); 138 exit(1);
140 } 139 }
141 ud.entry_ct = ct; 140 ud.entry_ct = ct;
142 ud.entries = up; 141 ud.entries = up;
143 if(ioctl(fd, PIO_UNIMAP, &ud)) { 142 if (ioctl(fd, PIO_UNIMAP, &ud)) {
144#if 0 143#if 0
145 if (errno == ENOMEM) { 144 if (errno == ENOMEM) {
146 /* change advice parameters */ 145 /* change advice parameters */
147 } 146 }
148#endif 147#endif
149 perror("PIO_UNIMAP"); 148 perror("PIO_UNIMAP");
150 exit(1); 149 exit(1);
151 } 150 }
152} 151}
153 152
154static void 153static void loadnewfont(int fd)
155loadnewfont(int fd) { 154{
156 int unit; 155 int unit;
157 char inbuf[32768]; /* primitive */ 156 char inbuf[32768]; /* primitive */
158 int inputlth, offset; 157 int inputlth, offset;
159 158
160 /* 159 /*
@@ -178,57 +177,58 @@ loadnewfont(int fd) {
178 177
179 /* test for psf first */ 178 /* test for psf first */
180 { 179 {
181 struct psf_header psfhdr; 180 struct psf_header psfhdr;
182 int fontsize; 181 int fontsize;
183 int hastable; 182 int hastable;
184 int head0, head; 183 int head0, head;
185 184
186 if (inputlth < sizeof(struct psf_header)) 185 if (inputlth < sizeof(struct psf_header))
187 goto no_psf; 186 goto no_psf;
188 187
189 psfhdr = * (struct psf_header *) &inbuf[0]; 188 psfhdr = *(struct psf_header *) &inbuf[0];
190 189
191 if (!PSF_MAGIC_OK(psfhdr)) 190 if (!PSF_MAGIC_OK(psfhdr))
192 goto no_psf; 191 goto no_psf;
193 192
194 if (psfhdr.mode > PSF_MAXMODE) { 193 if (psfhdr.mode > PSF_MAXMODE) {
195 fprintf(stderr, "Unsupported psf file mode\n"); 194 fprintf(stderr, "Unsupported psf file mode\n");
196 exit(1); 195 exit(1);
197 } 196 }
198 fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256); 197 fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
199#if !defined( PIO_FONTX ) || defined( __sparc__ ) 198#if !defined( PIO_FONTX ) || defined( __sparc__ )
200 if (fontsize != 256) { 199 if (fontsize != 256) {
201 fprintf(stderr, "Only fontsize 256 supported\n"); 200 fprintf(stderr, "Only fontsize 256 supported\n");
202 exit(1); 201 exit(1);
203 } 202 }
204#endif 203#endif
205 hastable = (psfhdr.mode & PSF_MODEHASTAB); 204 hastable = (psfhdr.mode & PSF_MODEHASTAB);
206 unit = psfhdr.charsize; 205 unit = psfhdr.charsize;
207 head0 = sizeof(struct psf_header); 206 head0 = sizeof(struct psf_header);
208 head = head0 + fontsize*unit; 207
209 if (head > inputlth || (!hastable && head != inputlth)) { 208 head = head0 + fontsize * unit;
210 fprintf(stderr, "Input file: bad length\n"); 209 if (head > inputlth || (!hastable && head != inputlth)) {
211 exit(1); 210 fprintf(stderr, "Input file: bad length\n");
212 } 211 exit(1);
213 do_loadfont(fd, inbuf + head0, unit, fontsize); 212 }
214 if (hastable) 213 do_loadfont(fd, inbuf + head0, unit, fontsize);
215 do_loadtable(fd, inbuf + head, inputlth-head, fontsize); 214 if (hastable)
216 return; 215 do_loadtable(fd, inbuf + head, inputlth - head, fontsize);
216 return;
217 } 217 }
218 no_psf: 218 no_psf:
219 219
220 /* file with three code pages? */ 220 /* file with three code pages? */
221 if (inputlth == 9780) { 221 if (inputlth == 9780) {
222 offset = 40; 222 offset = 40;
223 unit = 16; 223 unit = 16;
224 } else { 224 } else {
225 /* bare font */ 225 /* bare font */
226 if (inputlth & 0377) { 226 if (inputlth & 0377) {
227 fprintf(stderr, "Bad input file size\n"); 227 fprintf(stderr, "Bad input file size\n");
228 exit(1); 228 exit(1);
229 } 229 }
230 offset = 0; 230 offset = 0;
231 unit = inputlth/256; 231 unit = inputlth / 256;
232 } 232 }
233 do_loadfont(fd, inbuf+offset, unit, 256); 233 do_loadfont(fd, inbuf + offset, unit, 256);
234} 234}
diff --git a/console-tools/loadkmap.c b/console-tools/loadkmap.c
index a228ca460..aa4f6bbc8 100644
--- a/console-tools/loadkmap.c
+++ b/console-tools/loadkmap.c
@@ -1,3 +1,4 @@
1/* vi: set sw=4 ts=4: */
1/* 2/*
2 * Mini loadkmap implementation for busybox 3 * Mini loadkmap implementation for busybox
3 * 4 *
@@ -29,61 +30,63 @@
29 30
30 31
31static const char loadkmap_usage[] = "loadkmap\n" 32static const char loadkmap_usage[] = "loadkmap\n"
32"\n" 33 "\n"
33"\tLoad a binary keyboard translation table from standard input.\n"
34"\n";
35 34
35 "\tLoad a binary keyboard translation table from standard input.\n"
36 "\n";
36 37
37int
38loadkmap_main(int argc, char * * argv)
39{
40 struct kbentry ke;
41 u_short *ibuff;
42 int i,j,fd,readsz,pos,ibuffsz=NR_KEYS * sizeof(u_short);
43 char flags[MAX_NR_KEYMAPS],magic[]="bkeymap",buff[7];
44 38
45 fd = open("/dev/tty0", O_RDWR); 39int loadkmap_main(int argc, char **argv)
46 if (fd < 0) { 40{
47 fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno)); 41 struct kbentry ke;
48 return 1; 42 u_short *ibuff;
49 } 43 int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short);
44 char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap", buff[7];
50 45
51 read(0,buff,7); 46 fd = open("/dev/tty0", O_RDWR);
52 if (0 != strncmp(buff,magic,7)) { 47 if (fd < 0) {
53 fprintf(stderr, "This is not a valid binary keymap.\n"); 48 fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
54 return 1; 49 return 1;
55 } 50 }
56 51
57 if ( MAX_NR_KEYMAPS != read(0,flags,MAX_NR_KEYMAPS) ) { 52 read(0, buff, 7);
58 fprintf(stderr, "Error reading keymap flags: %s\n", strerror(errno)); 53 if (0 != strncmp(buff, magic, 7)) {
59 return 1; 54 fprintf(stderr, "This is not a valid binary keymap.\n");
60 } 55 return 1;
56 }
61 57
62 ibuff=(u_short *) malloc(ibuffsz); 58 if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) {
63 if (!ibuff) { 59 fprintf(stderr, "Error reading keymap flags: %s\n",
64 fprintf(stderr, "Out of memory.\n"); 60 strerror(errno));
65 return 1; 61 return 1;
66 } 62 }
63
64 ibuff = (u_short *) malloc(ibuffsz);
65 if (!ibuff) {
66 fprintf(stderr, "Out of memory.\n");
67 return 1;
68 }
67 69
68 for(i=0; i<MAX_NR_KEYMAPS; i++) { 70 for (i = 0; i < MAX_NR_KEYMAPS; i++) {
69 if (flags[i]==1){ 71 if (flags[i] == 1) {
70 pos=0; 72 pos = 0;
71 while (pos < ibuffsz) { 73 while (pos < ibuffsz) {
72 if ( (readsz = read(0,(char *)ibuff+pos,ibuffsz-pos)) < 0 ) { 74 if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos))
73 fprintf(stderr, "Error reading keymap: %s\n", 75 < 0) {
74 strerror(errno)); 76 fprintf(stderr, "Error reading keymap: %s\n",
75 return 1; 77 strerror(errno));
76 } 78 return 1;
77 pos += readsz; 79 }
78 } 80 pos += readsz;
79 for(j=0; j<NR_KEYS; j++) { 81 }
80 ke.kb_index = j; 82 for (j = 0; j < NR_KEYS; j++) {
81 ke.kb_table = i; 83 ke.kb_index = j;
82 ke.kb_value = ibuff[j]; 84 ke.kb_table = i;
83 ioctl(fd, KDSKBENT, &ke); 85 ke.kb_value = ibuff[j];
84 } 86 ioctl(fd, KDSKBENT, &ke);
87 }
88 }
85 } 89 }
86 } 90 close(fd);
87 close (fd); 91 return 0;
88 return 0;
89} 92}