Codebase list kbd / 542efb8
Reformat source code in the single style Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com> Alexey Gladkov 7 years ago
98 changed file(s) with 4117 addition(s) and 4097 deletion(s). Raw diff Collapse all Expand all
0 BasedOnStyle: LLVM
1 IndentWidth: 8
2 ColumnLimit: 0
3 UseTab: ForIndentation
4 BreakBeforeBraces: Linux
5 AllowShortIfStatementsOnASingleLine: false
6 IndentCaseLabels: true
7 AlignConsecutiveAssignments: true
8 Cpp11BracedListStyle: false
9 SortIncludes: false
2222 int handle_codepage(int);
2323 void handle_fontfile(void);
2424
25 #define PACKED __attribute__ ((packed))
25 #define PACKED __attribute__((packed))
2626 /* Use this (instead of the above) to compile under MSDOS */
2727 /*#define PACKED */
2828
3030 unsigned char id0 PACKED;
3131 unsigned char id[7] PACKED;
3232 unsigned char res[8] PACKED;
33 unsigned short pnum PACKED; /* number of pointers */
34 unsigned char ptyp PACKED; /* type of pointers */
33 unsigned short pnum PACKED; /* number of pointers */
34 unsigned char ptyp PACKED; /* type of pointers */
3535 unsigned long fih_offset PACKED; /* FontInfoHeader offset */
3636 } FontFileHeader;
3737
3838 int drfont = 0;
3939
40 #define N 4
41 struct {
42 unsigned char num_fonts PACKED; /* N = 4 fonts per code page*/
40 #define N 4
41 struct {
42 unsigned char num_fonts PACKED; /* N = 4 fonts per code page*/
4343 unsigned char font_height[N] PACKED;
4444 unsigned long dfd_offset[N] PACKED; /* DisplayFontData offset */
4545 } DRDOS_ExtendedFontFileHeader;
8585
8686 unsigned short codepage;
8787
88 int main (int argc, char *argv[]) {
88 int main(int argc, char *argv[])
89 {
8990 if (argc < 2)
9091 usage();
9192
9495 if (argc == 2)
9596 optl = 1;
9697 else
97 while(1) {
98 switch(getopt(argc, argv, "alLc")) {
99 case 'a':
100 opta = 1;
101 continue;
102 case 'c':
103 optc = 1;
104 continue;
105 case 'L':
106 optL = 1;
107 continue;
108 case 'l':
109 optl = 1;
110 continue;
111 case '?':
112 default:
98 while (1) {
99 switch (getopt(argc, argv, "alLc")) {
100 case 'a':
101 opta = 1;
102 continue;
103 case 'c':
104 optc = 1;
105 continue;
106 case 'L':
107 optL = 1;
108 continue;
109 case 'l':
110 optl = 1;
111 continue;
112 case '?':
113 default:
114 usage();
115 case -1:
116 break;
117 }
118 break;
119 }
120
121 if (optind < argc) {
122 if ((in = fopen(argv[optind], "r")) == NULL) {
123 printf("\nUnable to open file %s.\n", argv[optind]);
124 exit(0);
125 }
126 optind++;
127 } else
113128 usage();
114 case -1:
115 break;
116 }
117 break;
118 }
119
120 if (optind < argc) {
121 if ((in = fopen(argv[optind], "r")) == NULL) {
122 printf("\nUnable to open file %s.\n", argv[optind]);
123 exit(0);
124 }
125 optind++;
126 } else
127 usage();
128
129
129130 if (optind != argc) {
130 if (optind != argc-1 || opta)
131 usage();
132 codepage = atoi(argv[optind]);
133 optx = 1;
131 if (optind != argc - 1 || opta)
132 usage();
133 codepage = atoi(argv[optind]);
134 optx = 1;
134135 }
135136
136137 if (optc)
137 handle_codepage(0);
138 handle_codepage(0);
138139 else
139 handle_fontfile();
140 handle_fontfile();
140141
141142 if (optx) {
142 printf("no page %d found\n", codepage);
143 exit(1);
143 printf("no page %d found\n", codepage);
144 exit(1);
144145 }
145146
146147 fclose(in);
147148 return (0);
148149 }
149150
150 void
151 handle_fontfile(){
151 void handle_fontfile()
152 {
152153 int i, j;
153154
154155 j = fread(&FontFileHeader, 1, sizeof(FontFileHeader), in);
155156 if (j != sizeof(FontFileHeader)) {
156 printf("error reading FontFileHeader - got %d chars\n", j);
157 exit (1);
157 printf("error reading FontFileHeader - got %d chars\n", j);
158 exit(1);
158159 }
159160 if (optL)
160 printf("FontFileHeader: id=0x%x \"%7.7s\" res=%8.8s "
161 "num=%d typ=%d fih_offset=%ld\n\n",
162 FontFileHeader.id0, FontFileHeader.id, FontFileHeader.res,
163 FontFileHeader.pnum, FontFileHeader.ptyp,
164 FontFileHeader.fih_offset);
161 printf("FontFileHeader: id=0x%x \"%7.7s\" res=%8.8s "
162 "num=%d typ=%d fih_offset=%ld\n\n",
163 FontFileHeader.id0, FontFileHeader.id, FontFileHeader.res,
164 FontFileHeader.pnum, FontFileHeader.ptyp,
165 FontFileHeader.fih_offset);
165166
166167 if (!strcmp(FontFileHeader.id, "DRFONT ")) {
167 drfont = 1;
168 j = fread(&DRDOS_ExtendedFontFileHeader, 1,
169 sizeof(DRDOS_ExtendedFontFileHeader), in);
170 if (j != sizeof(DRDOS_ExtendedFontFileHeader)) {
171 printf("error reading ExtendedFontFileHeader - "
172 "got %d chars\n", j);
173 exit (1);
174 }
175 if (DRDOS_ExtendedFontFileHeader.num_fonts != N) {
176 printf("found %d instead of 4 fonts in drfont\n",
177 DRDOS_ExtendedFontFileHeader.num_fonts);
178 exit (1);
179 }
180 if (optL) {
181 printf("ExtendedFontFileHeader:\n");
182 for (j=0; j<N; j++) {
183 printf("font%d: height %d dfd_offset %d\n", j,
184 DRDOS_ExtendedFontFileHeader.font_height[j],
185 DRDOS_ExtendedFontFileHeader.dfd_offset[j]);
186 }
187 printf("\n");
188 }
168 drfont = 1;
169 j = fread(&DRDOS_ExtendedFontFileHeader, 1,
170 sizeof(DRDOS_ExtendedFontFileHeader), in);
171 if (j != sizeof(DRDOS_ExtendedFontFileHeader)) {
172 printf("error reading ExtendedFontFileHeader - "
173 "got %d chars\n",
174 j);
175 exit(1);
176 }
177 if (DRDOS_ExtendedFontFileHeader.num_fonts != N) {
178 printf("found %d instead of 4 fonts in drfont\n",
179 DRDOS_ExtendedFontFileHeader.num_fonts);
180 exit(1);
181 }
182 if (optL) {
183 printf("ExtendedFontFileHeader:\n");
184 for (j = 0; j < N; j++) {
185 printf("font%d: height %d dfd_offset %d\n", j,
186 DRDOS_ExtendedFontFileHeader.font_height[j],
187 DRDOS_ExtendedFontFileHeader.dfd_offset[j]);
188 }
189 printf("\n");
190 }
189191 }
190192
191193 j = fread(&FontInfoHeader, 1, sizeof(FontInfoHeader), in);
192194 if (j != sizeof(FontInfoHeader)) {
193 printf("error reading FontInfoHeader - got %d chars\n", j);
194 exit (1);
195 printf("error reading FontInfoHeader - got %d chars\n", j);
196 exit(1);
195197 }
196198 if (optL)
197 printf("FontInfoHeader: num_codepages=%d\n\n",
198 FontInfoHeader.num_codepages);
199 printf("FontInfoHeader: num_codepages=%d\n\n",
200 FontInfoHeader.num_codepages);
199201
200202 #if 1
201203 if (drfont) {
202 printf("this program cannot handle DRDOS font files\n");
203 exit(1);
204 printf("this program cannot handle DRDOS font files\n");
205 exit(1);
204206 }
205207 #endif
206208
207209 for (i = FontInfoHeader.num_codepages; i; i--)
208 if (handle_codepage(i-1))
209 break;
210 if (handle_codepage(i - 1))
211 break;
210212 }
211213
212 int
213 handle_codepage(int more_to_come) {
214 int j;
214 int handle_codepage(int more_to_come)
215 {
216 int j;
215217 char outfile[20];
216218 unsigned char *fonts;
217219 long inpos, nexthdr;
218220
219221 j = fread(&CPEntryHeader, 1, sizeof(CPEntryHeader), in);
220222 if (j != sizeof(CPEntryHeader)) {
221 printf("error reading CPEntryHeader - got %d chars\n", j);
222 exit(1);
223 printf("error reading CPEntryHeader - got %d chars\n", j);
224 exit(1);
223225 }
224226 if (optL) {
225 int t = CPEntryHeader.device_type;
226 printf("CPEntryHeader: size=%d dev=%d [%s] name=%8.8s "
227 "codepage=%d\n\t\tres=%6.6s nxt=%ld off_font=%ld\n\n",
228 CPEntryHeader.size,
229 t, (t==1) ? "screen" : (t==2) ? "printer" : "?",
230 CPEntryHeader.device_name,
231 CPEntryHeader.codepage,
232 CPEntryHeader.res,
233 CPEntryHeader.off_nexthdr, CPEntryHeader.off_font);
227 int t = CPEntryHeader.device_type;
228 printf("CPEntryHeader: size=%d dev=%d [%s] name=%8.8s "
229 "codepage=%d\n\t\tres=%6.6s nxt=%ld off_font=%ld\n\n",
230 CPEntryHeader.size,
231 t, (t == 1) ? "screen" : (t == 2) ? "printer" : "?",
232 CPEntryHeader.device_name,
233 CPEntryHeader.codepage,
234 CPEntryHeader.res,
235 CPEntryHeader.off_nexthdr, CPEntryHeader.off_font);
234236 } else if (optl) {
235 printf("\nCodepage = %d\n", CPEntryHeader.codepage);
236 printf("Device = %.8s\n", CPEntryHeader.device_name);
237 printf("\nCodepage = %d\n", CPEntryHeader.codepage);
238 printf("Device = %.8s\n", CPEntryHeader.device_name);
237239 }
238240 #if 0
239241 if (CPEntryHeader.size != sizeof(CPEntryHeader)) {
246248 }
247249 #endif
248250 if (!opta && (!optx || CPEntryHeader.codepage != codepage) && !optc)
249 goto next;
251 goto next;
250252
251253 inpos = ftell(in);
252254 if (inpos != CPEntryHeader.off_font && !optc) {
253 if (optL)
254 printf("pos=%ld font at %ld\n", inpos, CPEntryHeader.off_font);
255 fseek(in, CPEntryHeader.off_font, SEEK_SET);
255 if (optL)
256 printf("pos=%ld font at %ld\n", inpos, CPEntryHeader.off_font);
257 fseek(in, CPEntryHeader.off_font, SEEK_SET);
256258 }
257259
258260 j = fread(&CPInfoHeader, 1, sizeof(CPInfoHeader), in);
259261 if (j != sizeof(CPInfoHeader)) {
260 printf("error reading CPInfoHeader - got %d chars\n", j);
261 exit(1);
262 printf("error reading CPInfoHeader - got %d chars\n", j);
263 exit(1);
262264 }
263265 if (optl) {
264 printf("Number of Fonts = %d\n", CPInfoHeader.num_fonts);
265 printf("Size of Bitmap = %d\n", CPInfoHeader.size);
266 printf("Number of Fonts = %d\n", CPInfoHeader.num_fonts);
267 printf("Size of Bitmap = %d\n", CPInfoHeader.size);
266268 }
267269 if (CPInfoHeader.num_fonts == 0)
268 goto next;
270 goto next;
269271 if (optc)
270 return 0;
272 return 0;
271273
272274 sprintf(outfile, "%d.cp", CPEntryHeader.codepage);
273275 if ((out = fopen(outfile, "w")) == NULL) {
274 printf("\nUnable to open file %s.\n", outfile);
275 exit(1);
276 } else printf("\nWriting %s\n", outfile);
277
278 fonts = (unsigned char *) malloc(CPInfoHeader.size);
279
276 printf("\nUnable to open file %s.\n", outfile);
277 exit(1);
278 } else
279 printf("\nWriting %s\n", outfile);
280
281 fonts = (unsigned char *)malloc(CPInfoHeader.size);
282
280283 fread(fonts, CPInfoHeader.size, 1, in);
281284 fwrite(&CPEntryHeader, sizeof(CPEntryHeader), 1, out);
282285 fwrite(&CPInfoHeader, sizeof(CPInfoHeader), 1, out);
283286 j = fwrite(fonts, 1, CPInfoHeader.size, out);
284287 if (j != CPInfoHeader.size) {
285 printf("error writing %s - wrote %d chars\n", outfile, j);
286 exit(1);
288 printf("error writing %s - wrote %d chars\n", outfile, j);
289 exit(1);
287290 }
288291 fclose(out);
289292 free(fonts);
290 if (optx) exit(0);
291 next:
293 if (optx)
294 exit(0);
295 next:
292296 /*
293297 * It seems that if entry headers and fonts are interspersed,
294298 * then nexthdr will point past the font, regardless of
298302 */
299303 nexthdr = CPEntryHeader.off_nexthdr;
300304 if (nexthdr == 0 || nexthdr == -1) {
301 if (more_to_come) {
302 printf("more codepages expected, but nexthdr=%ld\n",
303 nexthdr);
304 exit(1);
305 } else
306 return 1;
305 if (more_to_come) {
306 printf("more codepages expected, but nexthdr=%ld\n",
307 nexthdr);
308 exit(1);
309 } else
310 return 1;
307311 }
308312
309313 inpos = ftell(in);
310314 if (inpos != CPEntryHeader.off_nexthdr) {
311 if (optL)
312 printf("pos=%ld nexthdr at %ld\n", inpos, nexthdr);
313 if (opta && !more_to_come) {
314 printf("no more code pages, but nexthdr != 0\n");
315 return 1;
316 }
317
318 fseek(in, CPEntryHeader.off_nexthdr, SEEK_SET);
315 if (optL)
316 printf("pos=%ld nexthdr at %ld\n", inpos, nexthdr);
317 if (opta && !more_to_come) {
318 printf("no more code pages, but nexthdr != 0\n");
319 return 1;
320 }
321
322 fseek(in, CPEntryHeader.off_nexthdr, SEEK_SET);
319323 }
320324
321325 return 0;
66 #include <linux/kd.h>
77 #include <linux/keyboard.h>
88
9 int
10 main(void)
9 int main(void)
1110 {
1211 struct kbentry ke;
1312
55 #include <unistd.h>
66 #include <sys/stat.h>
77
8 void
9 dosplit (int from, int to, char *fontbuf, int size, char *fontfile) {
10 int itemsize = size/256;
8 void dosplit(int from, int to, char *fontbuf, int size, char *fontfile)
9 {
10 int itemsize = size / 256;
1111 int i, fd;
1212 char *p, *q, s;
1313 char filename[4096];
1414
1515 if (from < 0 || from > 255 || to < 0 || to > 255) {
1616 fprintf(stderr, "splitfont: bad argument %s,%s\n",
17 from, to);
17 from, to);
1818 exit(1);
1919 }
20 if(strlen(fontfile) >= sizeof(filename)-4) {
20 if (strlen(fontfile) >= sizeof(filename) - 4) {
2121 fprintf(stderr, "splitfont: ridiculously long name\n");
2222 exit(1);
2323 }
2424 while (from <= to) {
2525 sprintf(filename, "%s.%02x", fontfile, from);
26 if ((fd = open(filename, O_WRONLY|O_CREAT, 0666)) < 0) {
26 if ((fd = open(filename, O_WRONLY | O_CREAT, 0666)) < 0) {
2727 perror("splitfont");
2828 fprintf(stderr, "cannot open %s for writing\n", filename);
2929 }
30 p = &fontbuf[from*itemsize];
30 p = &fontbuf[from * itemsize];
3131 if (write(fd, p, itemsize) != itemsize) {
3232 perror("splitfont");
3333 fprintf(stderr, "error writing %s\n", filename);
3737 }
3838 }
3939
40 int main(int argc, char **argv) {
40 int main(int argc, char **argv)
41 {
4142 struct stat statbuf;
4243 char fontbuf[4096];
4344 int fd;
7374 }
7475
7576 p = argv[2];
76 while(1) {
77 to = from = strtoul(p,&q,0);
78 if(*q == '-') {
79 p = q+1;
80 to = strtoul(p,&q,0);
77 while (1) {
78 to = from = strtoul(p, &q, 0);
79 if (*q == '-') {
80 p = q + 1;
81 to = strtoul(p, &q, 0);
8182 }
82 if(*q && *q != ',') {
83 if (*q && *q != ',') {
8384 fprintf(stderr, "splitfont: garbage in %s\n", p);
8485 exit(1);
8586 }
8687 dosplit(from, to, fontbuf, statbuf.st_size, argv[1]);
8788 if (!*q)
8889 break;
89 p = q+1;
90 p = q + 1;
9091 }
9192 return 0;
9293 }
77 #include <termios.h>
88 #include <sys/ioctl.h>
99
10 int
11 main(int argc, char **argv) {
12 int fd;
13 char *s;
10 int main(int argc, char **argv)
11 {
12 int fd;
13 char *s;
1414
15 if(argc != 3) {
16 fprintf(stderr, "call: sti tty text\n");
17 exit(1);
18 }
19 fd = open(argv[1], O_RDONLY);
20 if(fd < 0) {
21 perror(argv[1]);
22 fprintf(stderr, "sti: could not open tty\n");
23 exit(1);
24 }
25 s = argv[2];
26 while(*s) {
27 if(ioctl(fd, TIOCSTI, s)) {
28 perror("TIOCSTI");
29 fprintf(stderr, "sti: TIOCSTI ioctl failed\n");
30 exit(1);
31 }
32 s++;
33 }
34 return 0;
15 if (argc != 3) {
16 fprintf(stderr, "call: sti tty text\n");
17 exit(1);
18 }
19 fd = open(argv[1], O_RDONLY);
20 if (fd < 0) {
21 perror(argv[1]);
22 fprintf(stderr, "sti: could not open tty\n");
23 exit(1);
24 }
25 s = argv[2];
26 while (*s) {
27 if (ioctl(fd, TIOCSTI, s)) {
28 perror("TIOCSTI");
29 fprintf(stderr, "sti: TIOCSTI ioctl failed\n");
30 exit(1);
31 }
32 s++;
33 }
34 return 0;
3535 }
99 #include <fcntl.h>
1010 #include <time.h>
1111
12 void
13 fatal(char *s) {
14 perror(s);
15 exit(1);
12 void fatal(char *s)
13 {
14 perror(s);
15 exit(1);
1616 }
1717
18 int
19 number_of_columns() {
20 int fda;
21 unsigned char rc[2]; /* unsigned: Ranty@soon.com */
18 int number_of_columns()
19 {
20 int fda;
21 unsigned char rc[2]; /* unsigned: Ranty@soon.com */
2222
23 if((fda = open("/dev/vcsa", O_RDONLY)) < 0
24 && (fda = open("/dev/vcsa0", O_RDONLY)) < 0)
25 fatal("/dev/vcsa");
26 if(read(fda, rc, 2) != 2)
27 fatal("/dev/vcsa");
28 close(fda);
29 return rc[1];
23 if ((fda = open("/dev/vcsa", O_RDONLY)) < 0 && (fda = open("/dev/vcsa0", O_RDONLY)) < 0)
24 fatal("/dev/vcsa");
25 if (read(fda, rc, 2) != 2)
26 fatal("/dev/vcsa");
27 close(fda);
28 return rc[1];
3029 }
3130
32 int
33 main(){
34 int fd;
35 int cols = number_of_columns();
36 time_t tid;
37 struct tm *t;
38 char tijd[10];
31 int main()
32 {
33 int fd;
34 int cols = number_of_columns();
35 time_t tid;
36 struct tm *t;
37 char tijd[10];
3938
40 if((fd = open("/dev/vcs", O_WRONLY)) < 0
41 && (fd = open("/dev/vcs0", O_WRONLY)) < 0)
42 fatal("/dev/vcs");
39 if ((fd = open("/dev/vcs", O_WRONLY)) < 0 && (fd = open("/dev/vcs0", O_WRONLY)) < 0)
40 fatal("/dev/vcs");
4341
44 while(1) {
45 lseek(fd, cols-10, 0);
46 tid = time(0);
47 t = localtime(&tid);
48 sprintf(tijd, " %02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec);
49 write(fd, tijd, 9);
50 usleep(500000L); /* or sleep(1); */
51 }
42 while (1) {
43 lseek(fd, cols - 10, 0);
44 tid = time(0);
45 t = localtime(&tid);
46 sprintf(tijd, " %02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec);
47 write(fd, tijd, 9);
48 usleep(500000L); /* or sleep(1); */
49 }
5250 }
1414 #include "version.h"
1515 #include "kbd_error.h"
1616
17 int
18 main(int argc, char *argv[]) {
19 int fd, num;
17 int main(int argc, char *argv[])
18 {
19 int fd, num;
2020
21 set_progname(argv[0]);
21 set_progname(argv[0]);
2222
23 setlocale(LC_ALL, "");
24 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
25 textdomain(PACKAGE_NAME);
23 setlocale(LC_ALL, "");
24 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
25 textdomain(PACKAGE_NAME);
2626
27 if (argc == 2 && !strcmp(argv[1], "-V"))
28 print_version_and_exit();
27 if (argc == 2 && !strcmp(argv[1], "-V"))
28 print_version_and_exit();
2929
30 if (argc != 2) {
31 fprintf(stderr, _("usage: chvt N\n"));
32 return EXIT_FAILURE;
33 }
30 if (argc != 2) {
31 fprintf(stderr, _("usage: chvt N\n"));
32 return EXIT_FAILURE;
33 }
3434
35 if ((fd = getfd(NULL)) < 0)
36 kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
35 if ((fd = getfd(NULL)) < 0)
36 kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
3737
38 num = atoi(argv[1]);
38 num = atoi(argv[1]);
3939
40 if (ioctl(fd,VT_ACTIVATE,num)) {
41 kbd_error(EXIT_FAILURE, errno, "ioctl VT_ACTIVATE");
42 }
40 if (ioctl(fd, VT_ACTIVATE, num)) {
41 kbd_error(EXIT_FAILURE, errno, "ioctl VT_ACTIVATE");
42 }
4343
44 if (ioctl(fd,VT_WAITACTIVE,num)) {
45 kbd_error(EXIT_FAILURE, errno, "ioctl VT_WAITACTIVE");
46 }
44 if (ioctl(fd, VT_WAITACTIVE, num)) {
45 kbd_error(EXIT_FAILURE, errno, "ioctl VT_WAITACTIVE");
46 }
4747
48 return EXIT_SUCCESS;
48 return EXIT_SUCCESS;
4949 }
1313 #include "getfd.h"
1414 #include "nls.h"
1515
16 int
17 main(int argc, char *argv[]) {
16 int main(int argc, char *argv[])
17 {
1818 int fd;
1919 char *console = NULL;
2020
2828 if ((fd = getfd(console)) < 0)
2929 kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
3030
31 return loadunimap (fd, NULL, NULL);
31 return loadunimap(fd, NULL, NULL);
3232 }
1919 * Changes in use: 1.1.74: you have to be root for PIO_FONT.
2020 */
2121 #ifndef GIO_FONT
22 #define GIO_FONT 0x4B60
23 #define PIO_FONT 0x4B61
22 #define GIO_FONT 0x4B60
23 #define PIO_FONT 0x4B61
2424 #endif
2525
2626 /*
4545 * The old GIO_FONT will fail if the fontsize is 512.
4646 */
4747 #ifndef GIO_FONTX
48 #define GIO_FONTX 0x4B6B
49 #define PIO_FONTX 0x4B6C
48 #define GIO_FONTX 0x4B6B
49 #define PIO_FONTX 0x4B6C
5050 struct consolefontdesc {
5151 unsigned short charcount;
5252 unsigned short charheight;
7272 * In other words, this ioctl is totally useless today.
7373 */
7474 #ifndef PIO_FONTRESET
75 #define PIO_FONTRESET 0x4B6D /* reset to default font */
75 #define PIO_FONTRESET 0x4B6D /* reset to default font */
7676 #endif
7777
7878 /*
8585 #ifndef KDFONTOP
8686 #define KDFONTOP 0x4B72
8787 struct console_font_op {
88 unsigned int op; /* KD_FONT_OP_* */
89 unsigned int flags; /* KD_FONT_FLAG_* */
90 unsigned int width, height;
91 unsigned int charcount;
92 unsigned char *data; /* font data with height fixed to 32 */
88 unsigned int op; /* KD_FONT_OP_* */
89 unsigned int flags; /* KD_FONT_FLAG_* */
90 unsigned int width, height;
91 unsigned int charcount;
92 unsigned char *data; /* font data with height fixed to 32 */
9393 };
9494
95 #define KD_FONT_OP_SET 0 /* Set font */
96 #define KD_FONT_OP_GET 1 /* Get font */
97 #define KD_FONT_OP_SET_DEFAULT 2 /* Set font to default,
98 data points to name / NULL */
99 #define KD_FONT_OP_COPY 3 /* Copy from another console */
95 #define KD_FONT_OP_SET 0 /* Set font */
96 #define KD_FONT_OP_GET 1 /* Get font */
97 #define KD_FONT_OP_SET_DEFAULT 2 /* Set font to default, \
98 data points to name / NULL */
99 #define KD_FONT_OP_COPY 3 /* Copy from another console */
100100
101 #define KD_FONT_FLAG_OLD 0x80000000 /* Invoked via old interface */
102 #define KD_FONT_FLAG_DONT_RECALC 1 /* Don't call adjust_height() */
103 /* (Used internally for PIO_FONT support) */
104 #endif /* KDFONTOP */
101 #define KD_FONT_FLAG_OLD 0x80000000 /* Invoked via old interface */
102 #define KD_FONT_FLAG_DONT_RECALC 1 /* Don't call adjust_height() */
103 /* (Used internally for PIO_FONT support) */
104 #endif /* KDFONTOP */
105105
106106 #ifndef KDKBDREP
107107 /* usually defined in <linux/kd.h> */
108108 /* set keyboard delay/repeat rate;
109109 * actually used values are returned */
110 #define KDKBDREP 0x4B52
110 #define KDKBDREP 0x4B52
111111 #endif
1616 #include "version.h"
1717 #include "kbd_error.h"
1818
19 int
20 main(int argc, char *argv[]) {
19 int main(int argc, char *argv[])
20 {
2121 int fd, num, i;
2222
23 if (argc < 1) /* unlikely */
23 if (argc < 1) /* unlikely */
2424 return EXIT_FAILURE;
2525 set_progname(argv[0]);
2626
4343
4444 if (argc == 1) {
4545 /* deallocate all unused consoles */
46 if (ioctl(fd,VT_DISALLOCATE,0)) {
46 if (ioctl(fd, VT_DISALLOCATE, 0)) {
4747 kbd_error(EXIT_FAILURE, errno, "ioctl VT_DISALLOCATE");
4848 }
49 } else for (i = 1; i < argc; i++) {
50 num = atoi(argv[i]);
51 if (num == 0) {
52 kbd_error(EXIT_FAILURE, 0, _("0: illegal VT number\n"));
53 } else if (num == 1) {
54 kbd_error(EXIT_FAILURE, 0, _("VT 1 is the console and cannot be deallocated\n"));
55 } else if (ioctl(fd,VT_DISALLOCATE,num)) {
56 kbd_error(EXIT_FAILURE, errno, _("could not deallocate console %d: "
57 "ioctl VT_DISALLOCATE"), num);
49 } else
50 for (i = 1; i < argc; i++) {
51 num = atoi(argv[i]);
52 if (num == 0) {
53 kbd_error(EXIT_FAILURE, 0, _("0: illegal VT number\n"));
54 } else if (num == 1) {
55 kbd_error(EXIT_FAILURE, 0, _("VT 1 is the console and cannot be deallocated\n"));
56 } else if (ioctl(fd, VT_DISALLOCATE, num)) {
57 kbd_error(EXIT_FAILURE, errno, _("could not deallocate console %d: "
58 "ioctl VT_DISALLOCATE"),
59 num);
60 }
5861 }
59 }
6062 exit(EXIT_SUCCESS);
6163 }
2323
2424 static int fd;
2525
26 static void __attribute__ ((noreturn))
27 usage(void) {
26 static void __attribute__((noreturn))
27 usage(void)
28 {
2829 fprintf(stderr, _("dumpkeys version %s"), PACKAGE_VERSION);
2930 fprintf(stderr, _("\
3031 \n\
5556 exit(1);
5657 }
5758
58 int
59 main (int argc, char *argv[]) {
60 const char *short_opts = "hilvsnf1tkdS:c:V";
59 int main(int argc, char *argv[])
60 {
61 const char *short_opts = "hilvsnf1tkdS:c:V";
6162 const struct option long_opts[] = {
62 { "help", no_argument, NULL, 'h' },
63 { "short-info", no_argument, NULL, 'i' },
64 { "long-info", no_argument, NULL, 'l' },
65 { "numeric", no_argument, NULL, 'n' },
66 { "full-table", no_argument, NULL, 'f' },
67 { "separate-lines",no_argument, NULL, '1' },
68 { "shape", required_argument, NULL, 'S' },
69 { "funcs-only", no_argument, NULL, 't' },
70 { "keys-only", no_argument, NULL, 'k' },
71 { "compose-only",no_argument, NULL, 'd' },
72 { "charset", required_argument, NULL, 'c' },
73 { "verbose", no_argument, NULL, 'v' },
74 { "version", no_argument, NULL, 'V' },
75 { NULL, 0, NULL, 0 }
63 { "help", no_argument, NULL, 'h' },
64 { "short-info", no_argument, NULL, 'i' },
65 { "long-info", no_argument, NULL, 'l' },
66 { "numeric", no_argument, NULL, 'n' },
67 { "full-table", no_argument, NULL, 'f' },
68 { "separate-lines", no_argument, NULL, '1' },
69 { "shape", required_argument, NULL, 'S' },
70 { "funcs-only", no_argument, NULL, 't' },
71 { "keys-only", no_argument, NULL, 'k' },
72 { "compose-only", no_argument, NULL, 'd' },
73 { "charset", required_argument, NULL, 'c' },
74 { "verbose", no_argument, NULL, 'v' },
75 { "version", no_argument, NULL, 'V' },
76 { NULL, 0, NULL, 0 }
7677 };
7778 int c, rc;
7879 int kbd_mode;
7980
80 char long_info = 0;
81 char short_info = 0;
82 char numeric = 0;
81 char long_info = 0;
82 char short_info = 0;
83 char numeric = 0;
8384 lk_table_shape table = LK_SHAPE_DEFAULT;
84 char funcs_only = 0;
85 char keys_only = 0;
86 char diac_only = 0;
85 char funcs_only = 0;
86 char keys_only = 0;
87 char diac_only = 0;
8788
8889 struct lk_ctx *ctx;
8990
99100 }
100101
101102 while ((c = getopt_long(argc, argv,
102 short_opts, long_opts, NULL)) != -1) {
103 short_opts, long_opts, NULL)) != -1) {
103104 switch (c) {
104105 case 'i':
105106 short_info = 1;
135136 case 'c':
136137 if ((lk_set_charset(ctx, optarg)) != 0) {
137138 fprintf(stderr, _("unknown charset %s - ignoring charset request\n"),
138 optarg);
139 optarg);
139140 usage();
140141 }
141142 printf("charset \"%s\"\n", optarg);
157158 /* check whether the keyboard is in Unicode mode */
158159 if (ioctl(fd, KDGKBMODE, &kbd_mode)) {
159160 fprintf(stderr, _("%s: error reading keyboard mode: %m\n"),
160 progname);
161 progname);
161162 exit(EXIT_FAILURE);
162163 }
163164
173174
174175 if (long_info) {
175176 printf(_("Symbols recognized by %s:\n(numeric value, symbol)\n\n"),
176 progname);
177 progname);
177178 lk_dump_symbols(ctx, stdout);
178179 }
179180 exit(EXIT_SUCCESS);
182183 #ifdef KDGKBDIACR
183184 if (!diac_only) {
184185 #endif
185 if (!funcs_only) {
186 lk_dump_keymap(ctx, stdout, table, numeric);
187 }
186 if (!funcs_only) {
187 lk_dump_keymap(ctx, stdout, table, numeric);
188 }
188189 #ifdef KDGKBDIACR
189190 }
190191
192193 lk_dump_diacs(ctx, stdout);
193194 #endif
194195
195 fail: lk_free(ctx);
196 fail:
197 lk_free(ctx);
196198 close(fd);
197199
198200 if (rc < 0)
1414 #include "version.h"
1515 #include "kbd_error.h"
1616
17 static void __attribute__ ((noreturn))
17 static void __attribute__((noreturn))
1818 usage(void)
1919 {
2020 fprintf(stderr, _("%s version %s\n"
21 "\n"
22 "Usage: %s [options]\n"
23 "\n"
24 "Valid options are:\n"
25 "\n"
26 " -h --help display this help text\n"
27 " -V --version display program version\n"
28 " -n --next-available display number of next unallocated VT\n"),
29 progname, PACKAGE_VERSION, progname);
21 "\n"
22 "Usage: %s [options]\n"
23 "\n"
24 "Valid options are:\n"
25 "\n"
26 " -h --help display this help text\n"
27 " -V --version display program version\n"
28 " -n --next-available display number of next unallocated VT\n"),
29 progname, PACKAGE_VERSION, progname);
3030 exit(EXIT_FAILURE);
3131 }
3232
33 int
34 main(int argc, char **argv){
33 int main(int argc, char **argv)
34 {
3535 struct vt_stat vtstat;
3636 int fd, vtno = -1, c, show_vt = 0;
3737 struct serial_struct sr;
3838 const struct option long_opts[] = {
39 { "help", no_argument, NULL, 'h' },
40 { "version", no_argument, NULL, 'V' },
41 { "next-available", no_argument, NULL, 'n' },
42 { NULL, 0, NULL, 0 } };
39 { "help", no_argument, NULL, 'h' },
40 { "version", no_argument, NULL, 'V' },
41 { "next-available", no_argument, NULL, 'n' },
42 { NULL, 0, NULL, 0 }
43 };
4344
4445 setlocale(LC_ALL, "");
4546 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
4647 textdomain(PACKAGE_NAME);
4748
4849 set_progname(argv[0]);
49 while (( c = getopt_long (argc, argv, "Vhn", long_opts, NULL)) != EOF) {
50 switch (c) {
51 case 'h':
52 usage();
53 exit (0);
54 case 'n':
55 show_vt = 1;
56 break;
57 case 'V':
58 print_version_and_exit();
59 break;
60 case '?':
61 usage();
62 exit(1);
63 }
50 while ((c = getopt_long(argc, argv, "Vhn", long_opts, NULL)) != EOF) {
51 switch (c) {
52 case 'h':
53 usage();
54 exit(0);
55 case 'n':
56 show_vt = 1;
57 break;
58 case 'V':
59 print_version_and_exit();
60 break;
61 case '?':
62 usage();
63 exit(1);
64 }
6465 }
65
66
6667 if ((fd = getfd(NULL)) < 0)
6768 kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
6869
6970 if (show_vt) {
70 if ((ioctl(fd, VT_OPENQRY, &vtno) < 0) || vtno == -1) {
71 kbd_error(2, errno, _("Couldn't read VTNO: "));
72 }
73 printf ("%d\n", vtno);
74 return EXIT_SUCCESS;
71 if ((ioctl(fd, VT_OPENQRY, &vtno) < 0) || vtno == -1) {
72 kbd_error(2, errno, _("Couldn't read VTNO: "));
73 }
74 printf("%d\n", vtno);
75 return EXIT_SUCCESS;
7576 }
76
77
7778 if (ioctl(fd, TIOCGSERIAL, &sr) == 0) {
78 printf ("serial\n");
79 return EXIT_SUCCESS;
79 printf("serial\n");
80 return EXIT_SUCCESS;
8081 }
81
82
8283 if (ioctl(fd, VT_GETSTATE, &vtstat)) {
83 kbd_error(EXIT_FAILURE, errno, "fgconsole: VT_GETSTATE");
84 kbd_error(EXIT_FAILURE, errno, "fgconsole: VT_GETSTATE");
8485 }
8586 printf("%d\n", vtstat.v_active);
8687 return EXIT_SUCCESS;
2828 */
2929
3030 static int
31 is_a_console(int fd) {
31 is_a_console(int fd)
32 {
3233 char arg;
3334
3435 arg = 0;
35 return (isatty (fd)
36 && ioctl(fd, KDGKBTYPE, &arg) == 0
37 && ((arg == KB_101) || (arg == KB_84)));
36 return (isatty(fd) && ioctl(fd, KDGKBTYPE, &arg) == 0 && ((arg == KB_101) || (arg == KB_84)));
3837 }
3938
4039 static int
41 open_a_console(const char *fnam) {
40 open_a_console(const char *fnam)
41 {
4242 int fd;
4343
4444 /*
5555 return fd;
5656 }
5757
58 int
59 getfd(const char *fnam) {
58 int getfd(const char *fnam)
59 {
6060 int fd, i;
6161
6262 if (fnam) {
8282 return fd;
8383
8484 fprintf(stderr,
85 _("Couldn't get a file descriptor referring to the console\n"));
85 _("Couldn't get a file descriptor referring to the console\n"));
8686
8787 /* total failure */
8888 exit(1);
1515 #include "version.h"
1616 #include "kbd_error.h"
1717
18 static void __attribute__ ((noreturn))
19 usage(void) {
20 fprintf(stderr, _("usage: getkeycodes\n"));
21 exit(EXIT_FAILURE);
18 static void __attribute__((noreturn))
19 usage(void)
20 {
21 fprintf(stderr, _("usage: getkeycodes\n"));
22 exit(EXIT_FAILURE);
2223 }
2324
24 int
25 main(int argc, char **argv) {
25 int main(int argc, char **argv)
26 {
2627 int fd;
2728 unsigned int sc, sc0;
2829 struct kbkeycode a;
4445
4546 /* Old kernels don't support changing scancodes below SC_LIM. */
4647 a.scancode = 0;
47 a.keycode = 0;
48 a.keycode = 0;
4849 if (ioctl(fd, KDGETKEYCODE, &a)) {
4950 sc0 = 89;
5051 } else
51 for (sc0 = 1; sc0 <= 88; sc0++) {
52 a.scancode = sc0;
53 a.keycode = 0;
54 if (ioctl(fd, KDGETKEYCODE, &a) || a.keycode != sc0)
55 break;
56 }
52 for (sc0 = 1; sc0 <= 88; sc0++) {
53 a.scancode = sc0;
54 a.keycode = 0;
55 if (ioctl(fd, KDGETKEYCODE, &a) || a.keycode != sc0)
56 break;
57 }
5758
5859 printf(_("Plain scancodes xx (hex) versus keycodes (dec)\n"));
5960
6061 if (sc0 == 89) {
6162 printf(_("0 is an error; "
62 "for 1-88 (0x01-0x58) scancode equals keycode\n"));
63 "for 1-88 (0x01-0x58) scancode equals keycode\n"));
6364 } else if (sc0 > 1) {
6465 printf(_("for 1-%d (0x01-0x%02x) scancode equals keycode\n"),
6566 sc0 - 1, sc0 - 1);
7273 if (sc < 128)
7374 printf("\n 0x%02x: ", sc);
7475 else
75 printf("\ne0 %02x: ", sc-128);
76 printf("\ne0 %02x: ", sc - 128);
7677 }
7778
7879 if (sc < sc0) {
8182 }
8283
8384 a.scancode = sc;
84 a.keycode = 0;
85 a.keycode = 0;
8586 if (ioctl(fd, KDGETKEYCODE, &a) == 0) {
8687 printf(" %3d", a.keycode);
8788 continue;
9192 continue;
9293 }
9394 kbd_error(EXIT_FAILURE, errno, _("failed to get keycode for scancode 0x%x: "
94 "ioctl KDGETKEYCODE"), sc);
95 "ioctl KDGETKEYCODE"),
96 sc);
9597 exit(1);
9698 }
9799 printf("\n");
1919 #endif
2020
2121 static int
22 ud_compar(const void *u1, const void *u2){
23 unsigned short fp1 = ((struct unipair *) u1)->fontpos;
24 unsigned short fp2 = ((struct unipair *) u2)->fontpos;
25 return (int) fp1 - (int) fp2;
22 ud_compar(const void *u1, const void *u2)
23 {
24 unsigned short fp1 = ((struct unipair *)u1)->fontpos;
25 unsigned short fp2 = ((struct unipair *)u2)->fontpos;
26 return (int)fp1 - (int)fp2;
2627 }
2728
28 static void __attribute__ ((noreturn))
29 usage(void) {
29 static void __attribute__((noreturn))
30 usage(void)
31 {
3032 fprintf(stderr, _("Usage:\n\t%s [-s] [-C console]\n"), progname);
3133 exit(EXIT_FAILURE);
3234 }
3335
34 int
35 main(int argc, char **argv){
36 int main(int argc, char **argv)
37 {
3638 int sortflag = 0;
37 char mb[]={0,0,0,0,0,0,0,0};
39 char mb[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
3840 unsigned mb_length;
3941 int fd, c, i;
4042 char *console = NULL;
5254
5355 while ((c = getopt(argc, argv, "sC:")) != EOF) {
5456 switch (c) {
55 case 's':
56 sortflag = 1;
57 break;
58 case 'C':
59 console = optarg;
60 break;
61 default:
62 usage();
57 case 's':
58 sortflag = 1;
59 break;
60 case 'C':
61 console = optarg;
62 break;
63 default:
64 usage();
6365 }
6466 }
6567
7678 printf("# sorted kernel unimap - count=%d\n", ud.entry_ct);
7779 /* sort and merge entries */
7880 qsort(ud.entries, ud.entry_ct, sizeof(ud.entries[0]),
79 ud_compar);
80 for(i=0; i<ud.entry_ct; i++) {
81 ud_compar);
82 for (i = 0; i < ud.entry_ct; i++) {
8183 int fp = ud.entries[i].fontpos;
8284 printf("0x%03x\tU+%04x", fp, ud.entries[i].unicode);
83 while (i+1 < ud.entry_ct &&
84 ud.entries[i+1].fontpos == fp)
85 while (i + 1 < ud.entry_ct &&
86 ud.entries[i + 1].fontpos == fp)
8587 printf(" U+%04x", ud.entries[++i].unicode);
8688 printf("\n");
8789 }
8890 } else {
8991 printf("# kernel unimap - count=%d\n", ud.entry_ct);
90 for(i=0; i<ud.entry_ct; i++) {
91 mb_length = wctomb (mb, ud.entries[i].unicode);
92 mb[ (mb_length > 6) ? 0 : mb_length ] = 0 ;
92 for (i = 0; i < ud.entry_ct; i++) {
93 mb_length = wctomb(mb, ud.entries[i].unicode);
94 mb[(mb_length > 6) ? 0 : mb_length] = 0;
9395 if (mb_length == 1 && !isprint(mb[0])) {
9496 mb[2] = 0;
9597 mb[1] = mb[0] + 0100;
11 #define _KBD_H
22
33 #ifndef __GNUC__
4 # define __attribute__(x) /*NOTHING*/
4 #define __attribute__(x) /*NOTHING*/
55 #endif
66
77 #endif /* _KBD_H */
1111 extern const char *progname;
1212
1313 void
14 __attribute__ ((format (printf, 2, 3)))
15 kbd_warning(const int errnum, const char *fmt, ...)
14 __attribute__((format(printf, 2, 3)))
15 kbd_warning(const int errnum, const char *fmt, ...)
1616 {
1717 va_list ap;
1818
2929 }
3030
3131 void
32 __attribute__ ((noreturn))
33 __attribute__ ((format (printf, 3, 4)))
34 kbd_error(const int exitnum, const int errnum, const char *fmt, ...)
32 __attribute__((noreturn))
33 __attribute__((format(printf, 3, 4)))
34 kbd_error(const int exitnum, const int errnum, const char *fmt, ...)
3535 {
3636 va_list ap;
3737 va_start(ap, fmt);
1717 #include "version.h"
1818 #include "kbd_error.h"
1919
20 static void __attribute__ ((noreturn))
21 usage(void){
22 fprintf(stderr, _("usage: kbd_mode [-a|-u|-k|-s] [-C device]\n"));
23 exit(EXIT_FAILURE);
20 static void __attribute__((noreturn))
21 usage(void)
22 {
23 fprintf(stderr, _("usage: kbd_mode [-a|-u|-k|-s] [-C device]\n"));
24 exit(EXIT_FAILURE);
2425 }
2526
26 int
27 main(int argc, char *argv[]){
28 int fd, mode, c, n = 0;
29 char *console = NULL;
27 int main(int argc, char *argv[])
28 {
29 int fd, mode, c, n = 0;
30 char *console = NULL;
3031
3132 set_progname(argv[0]);
3233
3536 textdomain(PACKAGE_NAME);
3637
3738 if (argc == 2 && !strcmp(argv[1], "-V"))
38 print_version_and_exit();
39 print_version_and_exit();
3940
4041 while ((c = getopt(argc, argv, "auskC:")) != EOF) {
4142 switch (c) {
42 case 'a':
43 if (n > 0)
44 usage ();
45 mode = K_XLATE;
46 n++;
47 break;
48 case 'u':
49 if (n > 0)
50 usage ();
51 mode = K_UNICODE;
52 n++;
53 break;
54 case 's':
55 if (n > 0)
56 usage ();
57 mode = K_RAW;
58 n++;
59 break;
60 case 'k':
61 if (n > 0)
62 usage ();
63 mode = K_MEDIUMRAW;
64 n++;
65 break;
66 case 'C':
67 if (!optarg || !optarg[0])
68 usage ();
69 console = optarg;
70 break;
71 default:
72 usage();
43 case 'a':
44 if (n > 0)
45 usage();
46 mode = K_XLATE;
47 n++;
48 break;
49 case 'u':
50 if (n > 0)
51 usage();
52 mode = K_UNICODE;
53 n++;
54 break;
55 case 's':
56 if (n > 0)
57 usage();
58 mode = K_RAW;
59 n++;
60 break;
61 case 'k':
62 if (n > 0)
63 usage();
64 mode = K_MEDIUMRAW;
65 n++;
66 break;
67 case 'C':
68 if (!optarg || !optarg[0])
69 usage();
70 console = optarg;
71 break;
72 default:
73 usage();
7374 }
7475 }
7576
7778 kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
7879
7980 if (n == 0) {
80 /* report mode */
81 if (ioctl(fd, KDGKBMODE, &mode)) {
82 kbd_error(EXIT_FAILURE, errno, "ioctl KDGKBMODE");
83 }
84 switch(mode) {
85 case K_RAW:
86 printf(_("The keyboard is in raw (scancode) mode\n"));
87 break;
88 case K_MEDIUMRAW:
89 printf(_("The keyboard is in mediumraw (keycode) mode\n"));
90 break;
91 case K_XLATE:
92 printf(_("The keyboard is in the default (ASCII) mode\n"));
93 break;
94 case K_UNICODE:
95 printf(_("The keyboard is in Unicode (UTF-8) mode\n"));
96 break;
97 default:
98 printf(_("The keyboard is in some unknown mode\n"));
99 }
100 return EXIT_SUCCESS;
81 /* report mode */
82 if (ioctl(fd, KDGKBMODE, &mode)) {
83 kbd_error(EXIT_FAILURE, errno, "ioctl KDGKBMODE");
84 }
85 switch (mode) {
86 case K_RAW:
87 printf(_("The keyboard is in raw (scancode) mode\n"));
88 break;
89 case K_MEDIUMRAW:
90 printf(_("The keyboard is in mediumraw (keycode) mode\n"));
91 break;
92 case K_XLATE:
93 printf(_("The keyboard is in the default (ASCII) mode\n"));
94 break;
95 case K_UNICODE:
96 printf(_("The keyboard is in Unicode (UTF-8) mode\n"));
97 break;
98 default:
99 printf(_("The keyboard is in some unknown mode\n"));
100 }
101 return EXIT_SUCCESS;
101102 }
102103
103104 if (ioctl(fd, KDSKBMODE, mode)) {
1313 static const char *action = NULL;
1414 static const char *value = NULL;
1515
16 static void __attribute__ ((noreturn))
17 usage(int code) {
16 static void __attribute__((noreturn))
17 usage(int code)
18 {
1819 fprintf(stderr,
19 _("Usage: %1$s [-C DEVICE] getmode [text|graphics]\n"
20 " or: %1$s [-C DEVICE] gkbmode [raw|xlate|mediumraw|unicode]\n"
20 _("Usage: %1$s [-C DEVICE] getmode [text|graphics]\n"
21 " or: %1$s [-C DEVICE] gkbmode [raw|xlate|mediumraw|unicode]\n"
2122 " or: %1$s [-C DEVICE] gkbmeta [metabit|escprefix]\n"
2223 " or: %1$s [-C DEVICE] gkbled [scrolllock|numlock|capslock]\n"
2324 "Other options:\n"
2425 " -h print this usage message\n"
2526 " -V print version number\n"),
26 progname);
27 progname);
2728 exit(code);
2829 }
2930
3031 static int
31 answer(const char *ans) {
32 answer(const char *ans)
33 {
3234 if (value)
3335 return strcasecmp(value, ans) ? EXIT_FAILURE : EXIT_SUCCESS;
3436
3638 return EXIT_SUCCESS;
3739 }
3840
39 int
40 main(int argc, char **argv) {
41 int main(int argc, char **argv)
42 {
4143 int fd, mode, c;
4244 int rc = EXIT_FAILURE;
4345 char flags;
8284 kbd_error(EXIT_FAILURE, errno, "ioctl KDGETMODE");
8385
8486 switch (mode) {
85 case KD_TEXT: rc = answer("text"); break;
86 case KD_GRAPHICS: rc = answer("graphics"); break;
87 case KD_TEXT:
88 rc = answer("text");
89 break;
90 case KD_GRAPHICS:
91 rc = answer("graphics");
92 break;
8793 }
8894
8995 } else if (!strcasecmp("GKBMODE", action)) {
9197 kbd_error(EXIT_FAILURE, errno, "ioctl KDGKBMODE");
9298
9399 switch (mode) {
94 case K_RAW: rc = answer("raw"); break;
95 case K_XLATE: rc = answer("xlate"); break;
96 case K_MEDIUMRAW: rc = answer("mediumraw"); break;
97 case K_UNICODE: rc = answer("unicode"); break;
100 case K_RAW:
101 rc = answer("raw");
102 break;
103 case K_XLATE:
104 rc = answer("xlate");
105 break;
106 case K_MEDIUMRAW:
107 rc = answer("mediumraw");
108 break;
109 case K_UNICODE:
110 rc = answer("unicode");
111 break;
98112 }
99113
100114 } else if (!strcasecmp("GKBMETA", action)) {
102116 kbd_error(EXIT_FAILURE, errno, "ioctl KDGKBMETA");
103117
104118 switch (mode) {
105 case K_METABIT: rc = answer("metabit"); break;
106 case K_ESCPREFIX: rc = answer("escprefix"); break;
119 case K_METABIT:
120 rc = answer("metabit");
121 break;
122 case K_ESCPREFIX:
123 rc = answer("escprefix");
124 break;
107125 }
108126
109127 } else if (!strcasecmp("GKBLED", action)) {
114132
115133 if (value) {
116134 if (((mode & LED_SCR) && !strcasecmp(value, "scrolllock")) ||
117 ((mode & LED_NUM) && !strcasecmp(value, "numlock")) ||
135 ((mode & LED_NUM) && !strcasecmp(value, "numlock")) ||
118136 ((mode & LED_CAP) && !strcasecmp(value, "capslock")))
119137 rc = EXIT_SUCCESS;
120138 } else {
121139 printf("scrolllock:%s ", (mode & LED_SCR) ? "on" : "off");
122 printf("numlock:%s ", (mode & LED_NUM) ? "on" : "off");
123 printf("capslock:%s\n", (mode & LED_CAP) ? "on" : "off");
140 printf("numlock:%s ", (mode & LED_NUM) ? "on" : "off");
141 printf("capslock:%s\n", (mode & LED_CAP) ? "on" : "off");
124142 rc = EXIT_SUCCESS;
125143 }
126144
8787
8888 /* Equal to kernel version, but field names vary. */
8989 struct my_kbd_repeat {
90 int delay; /* in msec; <= 0: don't change */
91 int period; /* in msec; <= 0: don't change */
92 /* earlier this field was misnamed "rate" */
90 int delay; /* in msec; <= 0: don't change */
91 int period; /* in msec; <= 0: don't change */
92 /* earlier this field was misnamed "rate" */
9393 };
9494
9595 #include <signal.h>
9999 #include "kbd_error.h"
100100
101101 static int valid_rates[] = { 300, 267, 240, 218, 200, 185, 171, 160, 150,
102 133, 120, 109, 100, 92, 86, 80, 75, 67,
103 60, 55, 50, 46, 43, 40, 37, 33, 30, 27,
104 25, 23, 21, 20 };
105 #define RATE_COUNT (sizeof( valid_rates ) / sizeof( int ))
102 133, 120, 109, 100, 92, 86, 80, 75, 67,
103 60, 55, 50, 46, 43, 40, 37, 33, 30, 27,
104 25, 23, 21, 20 };
105 #define RATE_COUNT (sizeof(valid_rates) / sizeof(int))
106106
107107 static int valid_delays[] = { 250, 500, 750, 1000 };
108 #define DELAY_COUNT (sizeof( valid_delays ) / sizeof( int ))
108 #define DELAY_COUNT (sizeof(valid_delays) / sizeof(int))
109109
110110 static int
111 KDKBDREP_ioctl_ok(double rate, int delay, int silent) {
111 KDKBDREP_ioctl_ok(double rate, int delay, int silent)
112 {
112113 /*
113114 * This ioctl is defined in <linux/kd.h> but is not
114115 * implemented anywhere - must be in some m68k patches.
118119
119120 /* don't change, just test */
120121 kbdrep_s.period = -1;
121 kbdrep_s.delay = -1;
122 if (ioctl( 0, KDKBDREP, &kbdrep_s )) {
122 kbdrep_s.delay = -1;
123 if (ioctl(0, KDKBDREP, &kbdrep_s)) {
123124 if (errno == EINVAL || errno == ENOTTY)
124125 return 0;
125126 kbd_error(EXIT_FAILURE, errno, "ioctl KDKBDREP");
131132 #endif
132133
133134 /* do the change */
134 if (rate == 0) /* switch repeat off */
135 if (rate == 0) /* switch repeat off */
135136 kbdrep_s.period = 0;
136137 else
137 kbdrep_s.period = 1000.0 / rate; /* convert cps to msec */
138 kbdrep_s.period = 1000.0 / rate; /* convert cps to msec */
138139 if (kbdrep_s.period < 1)
139140 kbdrep_s.period = 1;
140 kbdrep_s.delay = delay;
141 kbdrep_s.delay = delay;
141142 if (kbdrep_s.delay < 1)
142143 kbdrep_s.delay = 1;
143
144
144145 if (ioctl(0, KDKBDREP, &kbdrep_s)) {
145146 kbd_error(EXIT_FAILURE, errno, "ioctl KDKBDREP");
146147 }
149150 if (kbdrep_s.period == 0)
150151 rate = 0;
151152 else
152 rate = 1000.0 / (double) kbdrep_s.period;
153 rate = 1000.0 / (double)kbdrep_s.period;
153154
154155 if (!silent)
155 printf( _("Typematic Rate set to %.1f cps (delay = %d ms)\n"),
156 rate, kbdrep_s.delay );
156 printf(_("Typematic Rate set to %.1f cps (delay = %d ms)\n"),
157 rate, kbdrep_s.delay);
157158
158159 kbdrep_s.period = -1;
159 kbdrep_s.delay = -1;
160 if (ioctl( 0, KDKBDREP, &kbdrep_s )) {
160 kbdrep_s.delay = -1;
161 if (ioctl(0, KDKBDREP, &kbdrep_s)) {
161162 if (errno == EINVAL)
162163 return 0;
163164 kbd_error(EXIT_FAILURE, errno, "ioctl KDKBDREP");
167168 if (kbdrep_s.period == 0)
168169 rate = 0;
169170 else
170 rate = 1000.0 / (double) kbdrep_s.period;
171 rate = 1000.0 / (double)kbdrep_s.period;
171172
172173 if (!silent)
173 printf( _("Typematic Rate set to %.1f cps (delay = %d ms)\n"),
174 rate, kbdrep_s.delay );
175
176 return 1; /* success! */
174 printf(_("Typematic Rate set to %.1f cps (delay = %d ms)\n"),
175 rate, kbdrep_s.delay);
176
177 return 1; /* success! */
177178 }
178179
179180 #ifndef KIOCSRATE
180 #define arg_state __attribute__ ((unused))
181 #define arg_state __attribute__((unused))
181182 #else
182183 #define arg_state
183184 #endif
184185
185186 static int
186 KIOCSRATE_ioctl_ok(arg_state double rate, arg_state int delay, arg_state int silent) {
187 KIOCSRATE_ioctl_ok(arg_state double rate, arg_state int delay, arg_state int silent)
188 {
187189 #ifdef KIOCSRATE
188190 struct kbd_rate kbdrate_s;
189191 int fd;
193195 kbd_error(EXIT_FAILURE, errno, "open /dev/kbd");
194196 }
195197
196 kbdrate_s.rate = (int) (rate + 0.5); /* round up */
197 kbdrate_s.delay = delay * HZ / 1000; /* convert ms to Hz */
198 kbdrate_s.rate = (int)(rate + 0.5); /* round up */
199 kbdrate_s.delay = delay * HZ / 1000; /* convert ms to Hz */
198200 if (kbdrate_s.rate > 50)
199201 kbdrate_s.rate = 50;
200202
201 if (ioctl( fd, KIOCSRATE, &kbdrate_s )) {
203 if (ioctl(fd, KIOCSRATE, &kbdrate_s)) {
202204 kbd_error(EXIT_FAILURE, errno, "ioctl KIOCSRATE");
203205 }
204 close( fd );
206 close(fd);
205207
206208 if (!silent)
207 printf( "Typematic Rate set to %d cps (delay = %d ms)\n",
208 kbdrate_s.rate, kbdrate_s.delay * 1000 / HZ );
209 printf("Typematic Rate set to %d cps (delay = %d ms)\n",
210 kbdrate_s.rate, kbdrate_s.delay * 1000 / HZ);
209211
210212 return 1;
211 #else /* no KIOCSRATE */
213 #else /* no KIOCSRATE */
212214 return 0;
213215 #endif /* KIOCSRATE */
214216 }
215217
216218 static void
217 sigalrmhandler(int sig __attribute__ ((unused))) {
219 sigalrmhandler(int sig __attribute__((unused)))
220 {
218221 kbd_warning(0, "Failed waiting for kbd controller!\n");
219 raise( SIGINT );
222 raise(SIGINT);
220223 }
221224
222 int
223 main( int argc, char **argv ) {
225 int main(int argc, char **argv)
226 {
224227 #ifdef __sparc__
225 double rate = 5.0; /* Default rate */
226 int delay = 200; /* Default delay */
228 double rate = 5.0; /* Default rate */
229 int delay = 200; /* Default delay */
227230 #else
228 double rate = 10.9; /* Default rate */
229 int delay = 250; /* Default delay */
230 #endif
231 int value = 0x7f; /* Maximum delay with slowest rate */
232 /* DO NOT CHANGE this value */
233 int silent = 0;
234 int fd;
235 char data;
236 int c;
231 double rate = 10.9; /* Default rate */
232 int delay = 250; /* Default delay */
233 #endif
234 int value = 0x7f; /* Maximum delay with slowest rate */
235 /* DO NOT CHANGE this value */
236 int silent = 0;
237 int fd;
238 char data;
239 int c;
237240 unsigned int i;
238241 extern char *optarg;
239242
247250 (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")))
248251 print_version_and_exit();
249252
250 while ( (c = getopt( argc, argv, "r:d:s" )) != EOF ) {
253 while ((c = getopt(argc, argv, "r:d:s")) != EOF) {
251254 switch (c) {
252 case 'r':
253 rate = atof( optarg );
254 break;
255 case 'd':
256 delay = atoi( optarg );
257 break;
258 case 's':
259 silent = 1;
260 break;
261 default:
262 fprintf(stderr,
263 _("Usage: kbdrate [-V | --version] [-s] [-r rate] [-d delay]\n"));
264 exit(EXIT_FAILURE);
265 }
266 }
267
268 if(KDKBDREP_ioctl_ok(rate, delay, silent)) /* m68k? */
255 case 'r':
256 rate = atof(optarg);
257 break;
258 case 'd':
259 delay = atoi(optarg);
260 break;
261 case 's':
262 silent = 1;
263 break;
264 default:
265 fprintf(stderr,
266 _("Usage: kbdrate [-V | --version] [-s] [-r rate] [-d delay]\n"));
267 exit(EXIT_FAILURE);
268 }
269 }
270
271 if (KDKBDREP_ioctl_ok(rate, delay, silent)) /* m68k? */
269272 return 0;
270273
271 if(KIOCSRATE_ioctl_ok(rate, delay, silent)) /* sparc? */
274 if (KIOCSRATE_ioctl_ok(rate, delay, silent)) /* sparc? */
272275 return 0;
273
274276
275277 /* The ioport way */
276278
281283 break;
282284 }
283285
284
285286 for (i = 0; i < DELAY_COUNT; i++)
286287 if (delay <= valid_delays[i]) {
287288 value &= 0x1f;
289290 break;
290291 }
291292
292 if ( (fd = open( "/dev/port", O_RDWR )) < 0) {
293 if ((fd = open("/dev/port", O_RDWR)) < 0) {
293294 kbd_error(EXIT_FAILURE, errno, _("Cannot open /dev/port"));
294295 }
295296
296 signal( SIGALRM, sigalrmhandler );
297 alarm( 3 );
297 signal(SIGALRM, sigalrmhandler);
298 alarm(3);
298299
299300 do {
300 lseek( fd, 0x64, 0 );
301 if (read( fd, &data, 1 ) == -1) {
301 lseek(fd, 0x64, 0);
302 if (read(fd, &data, 1) == -1) {
302303 kbd_error(EXIT_FAILURE, errno, "read");
303304 }
304 } while ((data & 2) == 2 ); /* wait */
305
306 lseek( fd, 0x60, 0 );
307 data = 0xf3; /* set typematic rate */
308 if (write( fd, &data, 1 ) == -1) {
305 } while ((data & 2) == 2); /* wait */
306
307 lseek(fd, 0x60, 0);
308 data = 0xf3; /* set typematic rate */
309 if (write(fd, &data, 1) == -1) {
309310 kbd_error(EXIT_FAILURE, errno, "write");
310311 }
311312
312313 do {
313 lseek( fd, 0x64, 0 );
314 if (read( fd, &data, 1 ) == -1) {
314 lseek(fd, 0x64, 0);
315 if (read(fd, &data, 1) == -1) {
315316 kbd_error(EXIT_FAILURE, errno, "read");
316317 }
317 } while ((data & 2) == 2 ); /* wait */
318
319 alarm( 0 );
320
321 lseek( fd, 0x60, 0 );
322 sleep( 1 );
323 if (write( fd, &value, 1 ) == -1) {
318 } while ((data & 2) == 2); /* wait */
319
320 alarm(0);
321
322 lseek(fd, 0x60, 0);
323 sleep(1);
324 if (write(fd, &value, 1) == -1) {
324325 kbd_error(EXIT_FAILURE, errno, "write");
325326 }
326327
327 close( fd );
328 close(fd);
328329
329330 if (!silent)
330 printf( _("Typematic Rate set to %.1f cps (delay = %d ms)\n"),
331 valid_rates[value & 0x1f] / 10.0,
332 valid_delays[ (value & 0x60) >> 5 ] );
331 printf(_("Typematic Rate set to %.1f cps (delay = %d ms)\n"),
332 valid_rates[value & 0x1f] / 10.0,
333 valid_delays[(value & 0x60) >> 5]);
333334
334335 return EXIT_SUCCESS;
335336 }
77
88 #include <stdio.h>
99 #include <errno.h>
10 #include <stdlib.h> /* free() */
10 #include <stdlib.h> /* free() */
1111 #include <sys/ioctl.h>
1212 #include <linux/kd.h>
1313 #include "kdfontop.h"
1818 #include "compat/linux-kd.h"
1919 #endif
2020
21 int
22 restorefont(int fd) {
21 int restorefont(int fd)
22 {
2323 if (ioctl(fd, PIO_FONTRESET, 0)) {
2424 perror("PIO_FONTRESET");
2525 return -1;
2727 return 0;
2828 }
2929
30 int
31 font_charheight(unsigned char *buf, int count, int width) {
30 int font_charheight(unsigned char *buf, int count, int width)
31 {
3232 int h, i, x;
33 int bytewidth = (width+7)/8;
33 int bytewidth = (width + 7) / 8;
3434
3535 for (h = 32; h > 0; h--)
3636 for (i = 0; i < count; i++)
3737 for (x = 0; x < bytewidth; x++)
38 if (buf[(32*i+h-1)*bytewidth+x])
38 if (buf[(32 * i + h - 1) * bytewidth + x])
3939 goto nonzero;
40 nonzero:
40 nonzero:
4141 return h;
4242 }
4343
4646 * May be called with width==NULL and height==NULL.
4747 * Must not exit - we may have cleanup to do.
4848 */
49 int
50 getfont(int fd, unsigned char *buf, int *count, int *width, int *height) {
49 int getfont(int fd, unsigned char *buf, int *count, int *width, int *height)
50 {
5151 struct consolefontdesc cfd;
5252 struct console_font_op cfo;
5353 int i;
5454
5555 /* First attempt: KDFONTOP */
56 cfo.op = KD_FONT_OP_GET;
56 cfo.op = KD_FONT_OP_GET;
5757 cfo.flags = 0;
5858 cfo.width = cfo.height = 32;
59 cfo.charcount = *count;
60 cfo.data = buf;
61 i = ioctl(fd, KDFONTOP, &cfo);
59 cfo.charcount = *count;
60 cfo.data = buf;
61 i = ioctl(fd, KDFONTOP, &cfo);
6262 if (i == 0) {
6363 *count = cfo.charcount;
6464 if (height)
7373 }
7474
7575 /* The other methods do not support width != 8 */
76 if (width) *width = 8;
76 if (width)
77 *width = 8;
7778 /* Second attempt: GIO_FONTX */
78 cfd.charcount = *count;
79 cfd.charcount = *count;
7980 cfd.charheight = 0;
80 cfd.chardata = (char *)buf;
81 i = ioctl(fd, GIO_FONTX, &cfd);
81 cfd.chardata = (char *)buf;
82 i = ioctl(fd, GIO_FONTX, &cfd);
8283 if (i == 0) {
8384 *count = cfd.charcount;
8485 if (height)
9697 return -1;
9798 }
9899 if (!buf) {
99 fprintf(stderr, _("bug: getfont using GIO_FONT needs buf.\n"));
100 return -1;
100 fprintf(stderr, _("bug: getfont using GIO_FONT needs buf.\n"));
101 return -1;
101102 }
102103 i = ioctl(fd, GIO_FONT, buf);
103104 if (i) {
106107 }
107108 *count = 256;
108109 if (height)
109 *height = 0; /* undefined, at most 32 */
110 *height = 0; /* undefined, at most 32 */
110111 return 0;
111112 }
112113
113 int
114 getfontsize(int fd) {
114 int getfontsize(int fd)
115 {
115116 int count;
116117 int i;
117118
118119 count = 0;
119 i = getfont(fd, NULL, &count, NULL, NULL);
120 i = getfont(fd, NULL, &count, NULL, NULL);
120121 return (i == 0) ? count : 256;
121122 }
122123
123 int
124 putfont(int fd, unsigned char *buf, int count, int width, int height) {
124 int putfont(int fd, unsigned char *buf, int count, int width, int height)
125 {
125126 struct consolefontdesc cfd;
126127 struct console_font_op cfo;
127128 int i;
132133 height = font_charheight(buf, count, width);
133134
134135 /* First attempt: KDFONTOP */
135 cfo.op = KD_FONT_OP_SET;
136 cfo.flags = 0;
137 cfo.width = width;
138 cfo.height = height;
136 cfo.op = KD_FONT_OP_SET;
137 cfo.flags = 0;
138 cfo.width = width;
139 cfo.height = height;
139140 cfo.charcount = count;
140 cfo.data = buf;
141 i = ioctl(fd, KDFONTOP, &cfo);
141 cfo.data = buf;
142 i = ioctl(fd, KDFONTOP, &cfo);
142143 if (i == 0)
143144 return 0;
144145 if (width != 8 || (errno != ENOSYS && errno != EINVAL)) {
149150 /* Variation on first attempt: in case count is not 256 or 512
150151 round up and try again. */
151152 if (errno == EINVAL && width == 8 && count != 256 && count < 512) {
152 int ct = ((count > 256) ? 512 : 256);
153 int ct = ((count > 256) ? 512 : 256);
153154 unsigned char *mybuf = malloc(32 * ct);
154155
155156 if (!mybuf) {
158159 }
159160 memset(mybuf, 0, 32 * ct);
160161 memcpy(mybuf, buf, 32 * count);
161 cfo.data = mybuf;
162 cfo.data = mybuf;
162163 cfo.charcount = ct;
163 i = ioctl(fd, KDFONTOP, &cfo);
164 i = ioctl(fd, KDFONTOP, &cfo);
164165 free(mybuf);
165166 if (i == 0)
166167 return 0;
167168 }
168169
169170 /* Second attempt: PIO_FONTX */
170 cfd.charcount = count;
171 cfd.charcount = count;
171172 cfd.charheight = height;
172 cfd.chardata = (char *)buf;
173 i = ioctl(fd, PIO_FONTX, &cfd);
173 cfd.chardata = (char *)buf;
174 i = ioctl(fd, PIO_FONTX, &cfd);
174175 if (i == 0)
175176 return 0;
176177 if (errno != ENOSYS && errno != EINVAL) {
3535 * translation tables, and this ioctl would get/set the fourth
3636 * table, while the other three tables are built-in and constant.)
3737 */
38 int
39 getscrnmap(int fd, char *map) {
40 if (ioctl(fd,GIO_SCRNMAP,map)) {
38 int getscrnmap(int fd, char *map)
39 {
40 if (ioctl(fd, GIO_SCRNMAP, map)) {
4141 perror("GIO_SCRNMAP");
4242 return -1;
4343 }
4444 return 0;
4545 }
4646
47 int
48 loadscrnmap(int fd, char *map) {
49 if (ioctl(fd,PIO_SCRNMAP,map)) {
47 int loadscrnmap(int fd, char *map)
48 {
49 if (ioctl(fd, PIO_SCRNMAP, map)) {
5050 perror("PIO_SCRNMAP");
5151 return -1;
5252 }
7676 * In the new scheme, the old PIO_SCRNMAP fills the kernel umap
7777 * table with such direct-to-font values.
7878 */
79
80 int
81 getuniscrnmap(int fd, unsigned short *map) {
82 if (ioctl(fd,GIO_UNISCRNMAP,map)) {
79
80 int getuniscrnmap(int fd, unsigned short *map)
81 {
82 if (ioctl(fd, GIO_UNISCRNMAP, map)) {
8383 perror("GIO_UNISCRNMAP");
8484 return -1;
8585 }
8686 return 0;
8787 }
8888
89 int
90 loaduniscrnmap(int fd, unsigned short *map) {
91 if (ioctl(fd,PIO_UNISCRNMAP,map)) {
89 int loaduniscrnmap(int fd, unsigned short *map)
90 {
91 if (ioctl(fd, PIO_UNISCRNMAP, map)) {
9292 perror("PIO_UNISCRNMAP");
9393 return -1;
9494 }
132132 * Linux 2.6.1 makes GIO_UNIMAP, PIO_UNIMAP, PIO_UNIMAPCLR per-vt
133133 * so that fd no longer is random.
134134 */
135 int
136 getunimap(int fd, struct unimapdesc *ud0) {
135 int getunimap(int fd, struct unimapdesc *ud0)
136 {
137137 struct unimapdesc ud;
138138 int ct;
139139
140140 ud.entry_ct = 0;
141 ud.entries = 0;
141 ud.entries = 0;
142142 if (ioctl(fd, GIO_UNIMAP, &ud)) {
143 if(errno != ENOMEM || ud.entry_ct == 0) {
143 if (errno != ENOMEM || ud.entry_ct == 0) {
144144 perror("GIO_UNIMAP(0)");
145145 return -1;
146146 }
147 ct = ud.entry_ct;
147 ct = ud.entry_ct;
148148 ud.entries = (struct unipair *)
149 malloc(ct * sizeof(struct unipair));
149 malloc(ct * sizeof(struct unipair));
150150 if (ud.entries == NULL) {
151151 fprintf(stderr, _("%s: out of memory\n"), progname);
152152 return -1;
157157 }
158158 if (ct != ud.entry_ct)
159159 fprintf(stderr,
160 _("strange... ct changed from %d to %d\n"),
161 ct, ud.entry_ct);
160 _("strange... ct changed from %d to %d\n"),
161 ct, ud.entry_ct);
162162 /* someone could change the unimap between our
163163 first and second ioctl, so the above errors
164164 are not impossible */
167167 return 0;
168168 }
169169
170 int
171 loadunimap(int fd, struct unimapinit *ui, struct unimapdesc *ud) {
170 int loadunimap(int fd, struct unimapinit *ui, struct unimapdesc *ud)
171 {
172172 struct unimapinit advice;
173173
174174 if (ui)
175175 advice = *ui;
176176 else {
177 advice.advised_hashsize = 0;
178 advice.advised_hashstep = 0;
177 advice.advised_hashsize = 0;
178 advice.advised_hashstep = 0;
179179 advice.advised_hashlevel = 0;
180180 }
181 again:
181 again:
182182 if (ioctl(fd, PIO_UNIMAPCLR, &advice)) {
183183 #ifdef ENOIOCTLCMD
184184 if (errno == ENOIOCTLCMD) {
185185 fprintf(stderr,
186 _("It seems this kernel is older than 1.1.92\n"
187 "No Unicode mapping table loaded.\n"));
186 _("It seems this kernel is older than 1.1.92\n"
187 "No Unicode mapping table loaded.\n"));
188188 } else
189189 #endif
190 perror("PIO_UNIMAPCLR");
190 perror("PIO_UNIMAPCLR");
191191 return -1;
192192 }
193193 if (ud == NULL)
77
88 #include <keymap/array.h>
99
10 int
11 lk_array_init(struct lk_array *a, size_t memb, size_t size)
10 int lk_array_init(struct lk_array *a, size_t memb, size_t size)
1211 {
1312 if (!a)
1413 return -EINVAL;
2524 return 0;
2625 }
2726
28 int
29 lk_array_free(struct lk_array *a)
27 int lk_array_free(struct lk_array *a)
3028 {
3129 if (!a)
3230 return -EINVAL;
3533 return 0;
3634 }
3735
38 int
39 lk_array_empty(struct lk_array *a)
36 int lk_array_empty(struct lk_array *a)
4037 {
4138 if (!a)
4239 return -EINVAL;
4744 return 0;
4845 }
4946
50 int
51 lk_array_exists(struct lk_array *a, unsigned int i)
47 int lk_array_exists(struct lk_array *a, unsigned int i)
5248 {
5349 char *s;
5450 size_t k;
5753 return 0;
5854 }
5955
60 s = (char *) (a->array + (a->memb * i));
56 s = (char *)(a->array + (a->memb * i));
6157
6258 for (k = 0; k < a->memb; k++) {
6359 if (s[k] != 0)
106102 return 0;
107103 }
108104
109 int
110 lk_array_set(struct lk_array *a, unsigned int i, const void *e)
105 int lk_array_set(struct lk_array *a, unsigned int i, const void *e)
111106 {
112107 int ret = array_resize(a, i);
113108
120115 return 0;
121116 }
122117
123 int
124 lk_array_unset(struct lk_array *a, unsigned int i)
118 int lk_array_unset(struct lk_array *a, unsigned int i)
125119 {
126120 if (!a || i >= a->total)
127121 return -EINVAL;
134128 return 0;
135129 }
136130
137 int
138 lk_array_append(struct lk_array *a, const void *e)
131 int lk_array_append(struct lk_array *a, const void *e)
139132 {
140133 int ret = array_resize(a, a->count);
141134
99 #include "nls.h"
1010 #include "contextP.h"
1111
12 void __attribute__ ((format (printf, 6, 7)))
12 void __attribute__((format(printf, 6, 7)))
1313 lk_log(struct lk_ctx *ctx, int priority,
1414 const char *file, int line, const char *fn,
1515 const char *fmt, ...)
2323 }
2424
2525 #ifndef DEBUG
26 # define log_unused __attribute__ ((unused))
26 #define log_unused __attribute__((unused))
2727 #else
28 # define log_unused
28 #define log_unused
2929 #endif
3030
31 static void __attribute__ ((format(printf, 6, 0)))
31 static void __attribute__((format(printf, 6, 0)))
3232 log_file(void *data,
33 int priority log_unused,
33 int priority log_unused,
3434 const char *file log_unused,
35 const int line log_unused,
36 const char *fn log_unused,
35 const int line log_unused,
36 const char *fn log_unused,
3737 const char *format, va_list args)
3838 {
3939 FILE *fp = data;
4242 const char *priname;
4343
4444 switch (priority) {
45 case LOG_EMERG: priname = "EMERGENCY"; break;
46 case LOG_ALERT: priname = "ALERT"; break;
47 case LOG_CRIT: priname = "CRITICAL"; break;
48 case LOG_ERR: priname = "ERROR"; break;
49 case LOG_WARNING: priname = "WARNING"; break;
50 case LOG_NOTICE: priname = "NOTICE"; break;
51 case LOG_INFO: priname = "INFO"; break;
52 case LOG_DEBUG: priname = "DEBUG"; break;
45 case LOG_EMERG:
46 priname = "EMERGENCY";
47 break;
48 case LOG_ALERT:
49 priname = "ALERT";
50 break;
51 case LOG_CRIT:
52 priname = "CRITICAL";
53 break;
54 case LOG_ERR:
55 priname = "ERROR";
56 break;
57 case LOG_WARNING:
58 priname = "WARNING";
59 break;
60 case LOG_NOTICE:
61 priname = "NOTICE";
62 break;
63 case LOG_INFO:
64 priname = "INFO";
65 break;
66 case LOG_DEBUG:
67 priname = "DEBUG";
68 break;
5369 default:
5470 snprintf(buf, sizeof(buf), "L:%d", priority);
5571 priname = buf;
6278
6379 #undef log_unused
6480
65 int
66 lk_set_log_fn(struct lk_ctx *ctx,
67 void (*log_fn)(void *data, int priority,
68 const char *file, int line, const char *fn,
69 const char *format, va_list args),
70 const void *data)
81 int lk_set_log_fn(struct lk_ctx *ctx,
82 void (*log_fn)(void *data, int priority,
83 const char *file, int line, const char *fn,
84 const char *format, va_list args),
85 const void *data)
7186 {
7287 if (!ctx)
7388 return -1;
7893 return 0;
7994 }
8095
81 int
82 lk_get_log_priority(struct lk_ctx *ctx)
96 int lk_get_log_priority(struct lk_ctx *ctx)
8397 {
8498 if (!ctx)
8599 return -1;
87101 return ctx->log_priority;
88102 }
89103
90 int
91 lk_set_log_priority(struct lk_ctx *ctx, int priority)
104 int lk_set_log_priority(struct lk_ctx *ctx, int priority)
92105 {
93106 if (!ctx)
94107 return -1;
106119 return ctx->flags;
107120 }
108121
109 int
110 lk_set_parser_flags(struct lk_ctx *ctx, lk_flags flags)
122 int lk_set_parser_flags(struct lk_ctx *ctx, lk_flags flags)
111123 {
112124 if (!ctx)
113125 return -1;
153165 lk_set_log_fn(ctx, log_file, stderr);
154166 lk_set_log_priority(ctx, LOG_ERR);
155167
156 if (init_array(ctx, &ctx->keymap, sizeof(void*)) < 0 ||
157 init_array(ctx, &ctx->func_table, sizeof(void*)) < 0 ||
158 init_array(ctx, &ctx->accent_table, sizeof(void*)) < 0 ||
159 init_array(ctx, &ctx->key_constant, sizeof(char)) < 0 ||
160 init_array(ctx, &ctx->key_line, sizeof(int)) < 0) {
168 if (init_array(ctx, &ctx->keymap, sizeof(void *)) < 0 ||
169 init_array(ctx, &ctx->func_table, sizeof(void *)) < 0 ||
170 init_array(ctx, &ctx->accent_table, sizeof(void *)) < 0 ||
171 init_array(ctx, &ctx->key_constant, sizeof(char)) < 0 ||
172 init_array(ctx, &ctx->key_line, sizeof(int)) < 0) {
161173 lk_free(ctx);
162174 return NULL;
163175 }
165177 return ctx;
166178 }
167179
168
169 int
170 lk_free(struct lk_ctx *ctx)
171 {
172 unsigned int i;//, j;
180 int lk_free(struct lk_ctx *ctx)
181 {
182 unsigned int i; //, j;
173183
174184 if (!ctx)
175185 return -1;
1818 #include "contextP.h"
1919 #include "ksyms.h"
2020
21 int
22 lk_diacr_exists(struct lk_ctx *ctx, unsigned int index)
21 int lk_diacr_exists(struct lk_ctx *ctx, unsigned int index)
2322 {
2423 return (lk_array_get_ptr(ctx->accent_table, index) != NULL);
2524 }
2625
27 int
28 lk_get_diacr(struct lk_ctx *ctx, unsigned int index, struct lk_kbdiacr *dcr)
26 int lk_get_diacr(struct lk_ctx *ctx, unsigned int index, struct lk_kbdiacr *dcr)
2927 {
3028 struct lk_kbdiacr *ptr;
3129
4240 return 0;
4341 }
4442
45 int
46 lk_append_diacr(struct lk_ctx *ctx, struct lk_kbdiacr *dcr)
43 int lk_append_diacr(struct lk_ctx *ctx, struct lk_kbdiacr *dcr)
4744 {
4845 struct lk_kbdiacr *ptr;
4946
6259 return 0;
6360 }
6461
65 int
66 lk_add_diacr(struct lk_ctx *ctx, unsigned int index, struct lk_kbdiacr *dcr)
62 int lk_add_diacr(struct lk_ctx *ctx, unsigned int index, struct lk_kbdiacr *dcr)
6763 {
6864 struct lk_kbdiacr *ptr;
6965
8278 return 0;
8379 }
8480
85 int
86 lk_del_diacr(struct lk_ctx *ctx, unsigned int index)
81 int lk_del_diacr(struct lk_ctx *ctx, unsigned int index)
8782 {
8883 int rc;
8984 rc = lk_array_unset(ctx->accent_table, index);
9489 return 0;
9590 }
9691
97 int
98 lk_append_compose(struct lk_ctx *ctx, struct lk_kbdiacr *dcr)
92 int lk_append_compose(struct lk_ctx *ctx, struct lk_kbdiacr *dcr)
9993 {
10094 struct lk_kbdiacr dcr0;
10195 int direction = TO_8BIT;
10599 direction = TO_UNICODE;
106100 #endif
107101
108 dcr0.diacr = convert_code(ctx, dcr->diacr, direction);
109 dcr0.base = convert_code(ctx, dcr->base, direction);
102 dcr0.diacr = convert_code(ctx, dcr->diacr, direction);
103 dcr0.base = convert_code(ctx, dcr->base, direction);
110104 dcr0.result = convert_code(ctx, dcr->result, direction);
111105
112106 return lk_append_diacr(ctx, &dcr0);
2929 {
3030 fprintf(fd, "'");
3131 fprintf(fd, (c == '\'' || c == '\\') ? "\\%c"
32 : isgraph(c) ? "%c"
33 : "\\%03o", c);
32 : isgraph(c) ? "%c"
33 : "\\%03o",
34 c);
3435 fprintf(fd, comma ? "', " : "'");
3536 }
3637
4041 {
4142 fprintf(fd, "'");
4243 fprintf(fd, (c == '\'' || c == '\\') ? "\\%c"
43 : (isgraph(c) || c == ' ' || c >= 0200) ? "%c"
44 : "\\%03o", c);
44 : (isgraph(c) || c == ' ' || c >= 0200) ? "%c"
45 : "\\%03o",
46 c);
4547 fprintf(fd, comma ? "', " : "'");
4648 }
4749
48 int
49 lk_dump_bkeymap(struct lk_ctx *ctx, FILE *fd)
50 int lk_dump_bkeymap(struct lk_ctx *ctx, FILE *fd)
5051 {
5152 unsigned int i, j;
5253 char magic[] = "bkeymap";
8081
8182 return 0;
8283
83 fail: ERR(ctx, _("Error writing map to file"));
84 fail:
85 ERR(ctx, _("Error writing map to file"));
8486 return -1;
8587 }
8688
105107 return buf;
106108 }
107109
108 int
109 lk_dump_ctable(struct lk_ctx *ctx, FILE *fd)
110 int lk_dump_ctable(struct lk_ctx *ctx, FILE *fd)
110111 {
111112 int j;
112113 unsigned int i, imax;
120121 return -1;
121122
122123 fprintf(fd,
123 /* not to be translated... */
124 "/* Do not edit this file! It was automatically generated by */\n");
124 /* not to be translated... */
125 "/* Do not edit this file! It was automatically generated by */\n");
125126 fprintf(fd, "/* loadkeys --mktable defkeymap.map > defkeymap.c */\n\n");
126127 fprintf(fd, "#include <linux/keyboard.h>\n");
127128 fprintf(fd, "#include <linux/kd.h>\n\n");
152153 }
153154 if (imax < MAX_NR_KEYMAPS - 1)
154155 fprintf(fd, "\t0");
155 fprintf(fd, "\n};\n\nunsigned int keymap_count = %u;\n\n", (unsigned int) ctx->keymap->count);
156
157 /* uglified just for xgettext - it complains about nonterminated strings */
156 fprintf(fd, "\n};\n\nunsigned int keymap_count = %u;\n\n", (unsigned int)ctx->keymap->count);
157
158 /* uglified just for xgettext - it complains about nonterminated strings */
158159 fprintf(fd,
159 "/*\n"
160 " * Philosophy: most people do not define more strings, but they who do\n"
161 " * often want quite a lot of string space. So, we statically allocate\n"
162 " * the default and allocate dynamically in chunks of 512 bytes.\n"
163 " */\n" "\n");
160 "/*\n"
161 " * Philosophy: most people do not define more strings, but they who do\n"
162 " * often want quite a lot of string space. So, we statically allocate\n"
163 " * the default and allocate dynamically in chunks of 512 bytes.\n"
164 " */\n"
165 "\n");
164166 for (maxfunc = MAX_NR_FUNC; maxfunc; maxfunc--)
165167 if (lk_array_get_ptr(ctx->func_table, maxfunc - 1))
166168 break;
185187 fprintf(fd, "};\n\n");
186188
187189 fprintf(fd,
188 "char *funcbufptr = func_buf;\n"
189 "int funcbufsize = sizeof(func_buf);\n"
190 "int funcbufleft = 0; /* space left */\n" "\n");
190 "char *funcbufptr = func_buf;\n"
191 "int funcbufsize = sizeof(func_buf);\n"
192 "int funcbufleft = 0; /* space left */\n"
193 "\n");
191194
192195 fprintf(fd, "char *func_table[MAX_NR_FUNC] = {\n");
193196 for (i = 0; i < maxfunc; i++) {
233236 fprintf(fd, "};\n\n");
234237 }
235238 fprintf(fd, "unsigned int accent_table_size = %u;\n",
236 (unsigned int) ctx->accent_table->count);
239 (unsigned int)ctx->accent_table->count);
237240 return 0;
238241 }
239242
240243 /* void dump_funcs(void) */
241 void
242 lk_dump_funcs(struct lk_ctx *ctx, FILE *fd)
244 void lk_dump_funcs(struct lk_ctx *ctx, FILE *fd)
243245 {
244246 unsigned int i;
245247
266268 }
267269
268270 /* void dump_diacs(void) */
269 void
270 lk_dump_diacs(struct lk_ctx *ctx, FILE *fd)
271 void lk_dump_diacs(struct lk_ctx *ctx, FILE *fd)
271272 {
272273 unsigned int i;
273274 struct lk_kbdiacr *ptr;
292293 }
293294 } else
294295 #endif
295 if (ptr->result > 0xff) {
296 if (ptr->result > 0xff) {
296297 // impossible case?
297298 fprintf(fd, " to 0x%x\n", ptr->result);
298299 } else {
308309 }
309310 }
310311
311 void
312 lk_dump_keymaps(struct lk_ctx *ctx, FILE *fd)
312 void lk_dump_keymaps(struct lk_ctx *ctx, FILE *fd)
313313 {
314314 unsigned int i;
315315 int n, m, s;
326326 continue;
327327 n--, m--;
328328 (n == m)
329 ? fprintf(fd, "%c%d" , (s ? ',' : ' '), n)
330 : fprintf(fd, "%c%d-%d", (s ? ',' : ' '), n, m);
329 ? fprintf(fd, "%c%d", (s ? ',' : ' '), n)
330 : fprintf(fd, "%c%d-%d", (s ? ',' : ' '), n, m);
331331 n = m = 0;
332 s = 1;
332 s = 1;
333333 } else {
334334 if (!n)
335 n = i+1;
336 m = i+1;
335 n = i + 1;
336 m = i + 1;
337337 }
338338 }
339339
340340 if (m) {
341341 n--, m--;
342342 (n == m)
343 ? fprintf(fd, "%c%d" , (s ? ',' : ' '), n)
344 : fprintf(fd, "%c%d-%d", (s ? ',' : ' '), n, m);
343 ? fprintf(fd, "%c%d", (s ? ',' : ' '), n)
344 : fprintf(fd, "%c%d-%d", (s ? ',' : ' '), n, m);
345345 }
346346
347347 fprintf(fd, "\n");
351351 print_mod(FILE *fd, int x)
352352 {
353353 if (x) {
354 modifier_t *mod = (modifier_t *) modifiers;
354 modifier_t *mod = (modifier_t *)modifiers;
355355 while (mod->name) {
356356 if (x & (1 << mod->bit))
357357 fprintf(fd, "%s\t", mod->name);
389389 (p = codetoksym(ctx, code)))
390390 fprintf(fd, "%-*s", 16 - plus, p);
391391 else if (!numeric && t < syms_size && v < get_sym_size(ctx, t) &&
392 (p = get_sym(ctx, t, v))[0])
392 (p = get_sym(ctx, t, v))[0])
393393 fprintf(fd, "%-*s", 16 - plus, p);
394394 else if (!numeric && t == KT_META && v < 128 && v < get_sym_size(ctx, KT_LATIN) &&
395 (p = get_sym(ctx, KT_LATIN, v))[0])
395 (p = get_sym(ctx, KT_LATIN, v))[0])
396396 fprintf(fd, "Meta_%-11s", p);
397397 else
398398 fprintf(fd, "0x%04x %s", code, plus ? "" : " ");
401401 static void
402402 print_bind(struct lk_ctx *ctx, FILE *fd, int bufj, int i, int j, char numeric)
403403 {
404 if(j)
404 if (j)
405405 fprintf(fd, "\t");
406406 print_mod(fd, j);
407407 fprintf(fd, "keycode %3d =", i);
409409 fprintf(fd, "\n");
410410 }
411411
412 void
413 lk_dump_keys(struct lk_ctx *ctx, FILE *fd, lk_table_shape table, char numeric)
412 void lk_dump_keys(struct lk_ctx *ctx, FILE *fd, lk_table_shape table, char numeric)
414413 {
415414 unsigned int i, j;
416415 int buf[MAX_NR_KEYMAPS];
446445
447446 if ((type == KT_LATIN || type == KT_LETTER) && KVAL(buf0) < 128) {
448447 buf1 = lk_map_exists(ctx, ja)
449 ? lk_get_key(ctx, ja, i)
450 : -1;
448 ? lk_get_key(ctx, ja, i)
449 : -1;
451450
452451 if (buf1 != K(KT_META, KVAL(buf0)))
453452 goto not_alt_is_meta;
498497 continue;
499498 }
500499
501 typ = KTYP(buf[0]);
502 val = KVAL(buf[0]);
503 islatin = (typ == KT_LATIN || typ == KT_LETTER);
500 typ = KTYP(buf[0]);
501 val = KVAL(buf[0]);
502 islatin = (typ == KT_LATIN || typ == KT_LETTER);
504503 isletter = (islatin &&
505 ((val >= 'A' && val <= 'Z') ||
506 (val >= 'a' && val <= 'z')));
504 ((val >= 'A' && val <= 'Z') ||
505 (val >= 'a' && val <= 'z')));
507506
508507 isasexpected = 0;
509508 if (isletter) {
513512 defs[2] = defs[0];
514513 defs[3] = defs[1];
515514
516 for (j = 4; j < 8; j++)
515 for (j = 4; j < 8; j++)
517516 defs[j] = K(KT_LATIN, val & ~96);
518517
519 for (j = 8; j < 16; j++)
520 defs[j] = K(KT_META, KVAL(defs[j-8]));
518 for (j = 8; j < 16; j++)
519 defs[j] = K(KT_META, KVAL(defs[j - 8]));
521520
522521 for (j = 0; j < keymapnr; j++) {
523522 if ((j >= 16 && buf[j] != K_HOLE) || (j < 16 && buf[j] != defs[j]))
526525
527526 isasexpected = 1;
528527 }
529 unexpected:
528 unexpected:
530529
531530 /* wipe out predictable meta bindings */
532 for (j = 0; j < keymapnr; j++)
531 for (j = 0; j < keymapnr; j++)
533532 zapped[j] = 0;
534533
535534 if (alt_is_meta) {
536 for(j = 0; j < keymapnr; j++) {
535 for (j = 0; j < keymapnr; j++) {
537536 unsigned int ja, ktyp;
538537 ja = (j | M_ALT);
539538
540 if (j != ja && lk_map_exists(ctx, ja)
541 && ((ktyp=KTYP(buf[j])) == KT_LATIN || ktyp == KT_LETTER)
542 && KVAL(buf[j]) < 128) {
539 if (j != ja && lk_map_exists(ctx, ja) && ((ktyp = KTYP(buf[j])) == KT_LATIN || ktyp == KT_LETTER) && KVAL(buf[j]) < 128) {
543540 if (buf[ja] != K(KT_META, KVAL(buf[j])))
544541 fprintf(stderr, _("impossible: not meta?\n"));
545 buf[ja] = K_HOLE;
542 buf[ja] = K_HOLE;
546543 zapped[ja] = 1;
547544 }
548545 }
572569 count++;
573570 }
574571
575 if (bad <= count && bad < keymapnr-1) {
572 if (bad <= count && bad < keymapnr - 1) {
576573 if (buf[0] != K_HOLE) {
577574 print_keysym(ctx, fd, buf[0], numeric);
578575 }
586583 } else {
587584 for (j = 0;
588585 j < keymapnr && buf[j] != K_HOLE &&
589 (table != LK_SHAPE_UNTIL_HOLE || lk_map_exists(ctx, j));
586 (table != LK_SHAPE_UNTIL_HOLE || lk_map_exists(ctx, j));
590587 j++) {
591588 //print_bind(ctx, fd, buf[j], i, j, numeric);
592589 print_keysym(ctx, fd, buf[j], numeric);
603600 }
604601 }
605602
606 void
607 lk_dump_keymap(struct lk_ctx *ctx, FILE *fd, lk_table_shape table, char numeric)
603 void lk_dump_keymap(struct lk_ctx *ctx, FILE *fd, lk_table_shape table, char numeric)
608604 {
609605 lk_dump_keymaps(ctx, fd);
610606 lk_dump_keys(ctx, fd, table, numeric);
1010 #include "nls.h"
1111 #include "keymap/findfile.h"
1212
13 void
14 lk_fpclose(lkfile_t *fp)
13 void lk_fpclose(lkfile_t *fp)
1514 {
1615 if (!fp || !fp->fd)
1716 return;
2221 fp->fd = NULL;
2322 }
2423
25 #define SIZE(a) (sizeof(a)/sizeof(a[0]))
24 #define SIZE(a) (sizeof(a) / sizeof(a[0]))
2625
2726 static struct decompressor {
2827 const char *ext; /* starts with `.', has no other dots */
4443
4544 sprintf(pipe_cmd, "%s %s", dc->cmd, fp->pathname);
4645
47 fp->fd = popen(pipe_cmd, "r");
46 fp->fd = popen(pipe_cmd, "r");
4847 fp->pipe = 1;
4948
5049 free(pipe_cmd);
7473 return pipe_open(dc, fp);
7574 }
7675 }
77 fp->fd = fopen(fp->pathname, "r");
76 fp->fd = fopen(fp->pathname, "r");
7877 fp->pipe = 0;
7978
8079 if (fp->fd == NULL)
105104
106105 sprintf(fp->pathname, "%s%s", fnam, suffixes[i]);
107106
108 if(stat(fp->pathname, &st) == 0
109 && S_ISREG(st.st_mode)
110 && (fp->fd = fopen(fp->pathname, "r")) != NULL)
107 if (stat(fp->pathname, &st) == 0 && S_ISREG(st.st_mode) && (fp->fd = fopen(fp->pathname, "r")) != NULL)
111108 return 0;
112109
113110 for (dc = &decompressors[0]; dc->cmd; dc++) {
116113
117114 sprintf(fp->pathname, "%s%s%s", fnam, suffixes[i], dc->ext);
118115
119 if (stat(fp->pathname, &st) == 0
120 && S_ISREG(st.st_mode)
121 && access(fp->pathname, R_OK) == 0)
116 if (stat(fp->pathname, &st) == 0 && S_ISREG(st.st_mode) && access(fp->pathname, R_OK) == 0)
122117 return pipe_open(dc, fp);
123118 }
124119 }
137132 int i, rc = -1, secondpass = 0;
138133 size_t dir_len;
139134
140 fp->fd = NULL;
135 fp->fd = NULL;
141136 fp->pipe = 0;
142137
143138 if ((d = opendir(dir)) == NULL)
153148 }
154149 }
155150
156 /* Scan the directory twice: first for files, then
151 /* Scan the directory twice: first for files, then
157152 for subdirectories, so that we do never search
158153 a subdirectory when the directory itself already
159154 contains the file we are looking for. */
160155 StartScan:
161156 while ((de = readdir(d)) != NULL) {
162 struct stat st;
163 int okdir;
164 size_t d_len;
165
166 d_len = strlen(de->d_name);
167 if (d_len < 3) {
168 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
169 continue;
170 }
171
172 if (dir_len + d_len + 2 > sizeof(fp->pathname))
173 continue;
174
175 okdir = (ff && strcmp(de->d_name, fdir) == 0);
176
177 if ((secondpass && recdepth) || okdir) {
178 char *a;
179
180 if ((a = malloc(dir_len + d_len + 2)) == NULL)
181 goto EndScan;
182
183 sprintf(a, "%s/%s", dir, de->d_name);
184
185 if (stat(a, &st) == 0 && S_ISDIR(st.st_mode)) {
186 if (okdir)
187 rc = findfile_in_dir(ff+1, a, 0, suf, fp);
188
189 if (rc && recdepth)
190 rc = findfile_in_dir(fnam, a, recdepth-1, suf, fp);
191
192 if (!rc) {
193 free(a);
157 struct stat st;
158 int okdir;
159 size_t d_len;
160
161 d_len = strlen(de->d_name);
162 if (d_len < 3) {
163 if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
164 continue;
165 }
166
167 if (dir_len + d_len + 2 > sizeof(fp->pathname))
168 continue;
169
170 okdir = (ff && strcmp(de->d_name, fdir) == 0);
171
172 if ((secondpass && recdepth) || okdir) {
173 char *a;
174
175 if ((a = malloc(dir_len + d_len + 2)) == NULL)
176 goto EndScan;
177
178 sprintf(a, "%s/%s", dir, de->d_name);
179
180 if (stat(a, &st) == 0 && S_ISDIR(st.st_mode)) {
181 if (okdir)
182 rc = findfile_in_dir(ff + 1, a, 0, suf, fp);
183
184 if (rc && recdepth)
185 rc = findfile_in_dir(fnam, a, recdepth - 1, suf, fp);
186
187 if (!rc) {
188 free(a);
189 goto EndScan;
190 }
191 }
192 free(a);
193 }
194
195 if (secondpass)
196 continue;
197
198 /* Should we be in a subdirectory? */
199 if (ff)
200 continue;
201
202 /* Does d_name start right? */
203 p = &de->d_name[0];
204 q = fnam;
205 while (*p && *p == *q)
206 p++, q++;
207 if (*q)
208 continue;
209
210 sprintf(fp->pathname, "%s/%s", dir, de->d_name);
211 if (stat(fp->pathname, &st) != 0 || !S_ISREG(st.st_mode))
212 continue;
213
214 /* Does tail consist of a known suffix and possibly
215 a compression suffix? */
216 for (i = 0; suf[i]; i++) {
217 size_t l;
218
219 if (!strcmp(p, suf[i])) {
220 rc = maybe_pipe_open(fp);
194221 goto EndScan;
195222 }
196 }
197 free(a);
198 }
199
200 if (secondpass)
201 continue;
202
203 /* Should we be in a subdirectory? */
204 if (ff)
205 continue;
206
207 /* Does d_name start right? */
208 p = &de->d_name[0];
209 q = fnam;
210 while (*p && *p == *q) p++,q++;
211 if (*q)
212 continue;
213
214 sprintf(fp->pathname, "%s/%s", dir, de->d_name);
215 if (stat(fp->pathname, &st) != 0 || !S_ISREG(st.st_mode))
216 continue;
217
218 /* Does tail consist of a known suffix and possibly
219 a compression suffix? */
220 for(i = 0; suf[i]; i++) {
221 size_t l;
222
223 if (!strcmp(p, suf[i])) {
224 rc = maybe_pipe_open(fp);
225 goto EndScan;
226 }
227
228 l = strlen(suf[i]);
229 if (!strncmp(p, suf[i], l)) {
230 for (dc = &decompressors[0]; dc->cmd; dc++)
231 if (strcmp(p+l, dc->ext) == 0) {
232 rc = pipe_open(dc, fp);
233 goto EndScan;
234 }
235 }
236 }
223
224 l = strlen(suf[i]);
225 if (!strncmp(p, suf[i], l)) {
226 for (dc = &decompressors[0]; dc->cmd; dc++)
227 if (strcmp(p + l, dc->ext) == 0) {
228 rc = pipe_open(dc, fp);
229 goto EndScan;
230 }
231 }
232 }
237233 }
238234
239235 if (recdepth > 0 && !secondpass) {
249245 return rc;
250246 }
251247
252 int
253 lk_findfile(const char *fnam, const char *const *dirpath, const char *const *suffixes, lkfile_t *fp)
248 int lk_findfile(const char *fnam, const char *const *dirpath, const char *const *suffixes, lkfile_t *fp)
254249 {
255250 char *dir;
256251 int dl, recdepth, rc, i;
257252
258 fp->fd = NULL;
253 fp->fd = NULL;
259254 fp->pipe = 0;
260255
261256 /* Try explicitly given name first */
273268 /* Search a list of directories and directory hierarchies */
274269 for (i = 0; dirpath[i]; i++) {
275270 recdepth = 0;
276 dl = strlen(dirpath[i]);
271 dl = strlen(dirpath[i]);
277272
278273 /* trailing stars denote recursion */
279 while (dl && dirpath[i][dl-1] == '*')
274 while (dl && dirpath[i][dl - 1] == '*')
280275 dl--, recdepth++;
281276
282277 /* delete trailing slashes */
283 while (dl && dirpath[i][dl-1] == '/')
278 while (dl && dirpath[i][dl - 1] == '/')
284279 dl--;
285280
286281 if (dl)
1717
1818 #include "contextP.h"
1919
20 int
21 lk_func_exists(struct lk_ctx *ctx, unsigned int index)
20 int lk_func_exists(struct lk_ctx *ctx, unsigned int index)
2221 {
2322 return (lk_array_get_ptr(ctx->func_table, index) != NULL);
2423 }
2524
26 int
27 lk_get_func(struct lk_ctx *ctx, struct kbsentry *kbs)
25 int lk_get_func(struct lk_ctx *ctx, struct kbsentry *kbs)
2826 {
2927 char *s;
3028
4038 return 0;
4139 }
4240
43 int
44 lk_add_func(struct lk_ctx *ctx, struct kbsentry *kbs)
41 int lk_add_func(struct lk_ctx *ctx, struct kbsentry *kbs)
4542 {
4643 char *s;
4744
6057 return 0;
6158 }
6259
63 int
64 lk_del_func(struct lk_ctx *ctx, unsigned int index)
60 int lk_del_func(struct lk_ctx *ctx, unsigned int index)
6561 {
6662 if (lk_array_unset(ctx->func_table, index) < 0) {
6763 ERR(ctx, _("Unable to remove item from the list of functions"));
7066
7167 return 0;
7268 }
73
1616 #include "nls.h"
1717 #include "contextP.h"
1818
19 int
20 lk_kernel_keys(struct lk_ctx *ctx, int fd)
19 int lk_kernel_keys(struct lk_ctx *ctx, int fd)
2120 {
2221 int i, t;
2322 struct kbentry ke;
2827 ke.kb_index = i;
2928 ke.kb_value = 0;
3029
31 if (ioctl(fd, KDGKBENT, (unsigned long) &ke)) {
30 if (ioctl(fd, KDGKBENT, (unsigned long)&ke)) {
3231 ERR(ctx, _("KDGKBENT: %s: error at index %d in table %d"),
33 strerror(errno), i, t);
32 strerror(errno), i, t);
3433 return -1;
3534 }
3635
4847 return 0;
4948 }
5049
51 int
52 lk_kernel_funcs(struct lk_ctx *ctx, int fd)
50 int lk_kernel_funcs(struct lk_ctx *ctx, int fd)
5351 {
5452 int i;
5553 struct kbsentry kbs;
5755 for (i = 0; i < MAX_NR_FUNC; i++) {
5856 kbs.kb_func = i;
5957
60 if (ioctl(fd, KDGKBSENT, (unsigned long) &kbs)) {
58 if (ioctl(fd, KDGKBSENT, (unsigned long)&kbs)) {
6159 ERR(ctx, _("KDGKBSENT: %s: Unable to get function key string"),
62 strerror(errno));
60 strerror(errno));
6361 return -1;
6462 }
6563
66 if (!strlen((char *) kbs.kb_string))
64 if (!strlen((char *)kbs.kb_string))
6765 continue;
6866
6967 if (lk_add_func(ctx, &kbs) < 0)
7371 return 0;
7472 }
7573
76 int
77 lk_kernel_diacrs(struct lk_ctx *ctx, int fd)
74 int lk_kernel_diacrs(struct lk_ctx *ctx, int fd)
7875 {
7976 #ifdef KDGKBDIACRUC
8077 int request = KDGKBDIACRUC;
8885 unsigned int i;
8986 struct lk_kbdiacr dcr;
9087
91 if (ioctl(fd, request, (unsigned long) &kd)) {
88 if (ioctl(fd, request, (unsigned long)&kd)) {
9289 ERR(ctx, _("KDGKBDIACR(UC): %s: Unable to get accent table"),
93 strerror(errno));
90 strerror(errno));
9491 return -1;
9592 }
9693
9794 for (i = 0; i < kd.kb_cnt; i++) {
98 dcr.diacr = (ar+i)->diacr;
99 dcr.base = (ar+i)->base;
100 dcr.result = (ar+i)->result;
95 dcr.diacr = (ar + i)->diacr;
96 dcr.base = (ar + i)->base;
97 dcr.result = (ar + i)->result;
10198
10299 if (lk_add_diacr(ctx, i, &dcr) < 0)
103100 return -1;
106103 return 0;
107104 }
108105
109 int
110 lk_kernel_keymap(struct lk_ctx *ctx, int fd)
106 int lk_kernel_keymap(struct lk_ctx *ctx, int fd)
111107 {
112 if (lk_kernel_keys(ctx, fd) < 0 ||
113 lk_kernel_funcs(ctx, fd) < 0 ||
108 if (lk_kernel_keys(ctx, fd) < 0 ||
109 lk_kernel_funcs(ctx, fd) < 0 ||
114110 lk_kernel_diacrs(ctx, fd) < 0)
115111 return -1;
116112 return 0;
1818
1919 int lk_array_append(struct lk_array *a, const void *e);
2020
21 int lk_array_set(struct lk_array *a, unsigned int i, const void *e);
21 int lk_array_set(struct lk_array *a, unsigned int i, const void *e);
2222 void *lk_array_get(struct lk_array *a, unsigned int i);
2323 void *lk_array_get_ptr(struct lk_array *a, unsigned int i);
2424
6262 * @return 0 on success, -1 on error.
6363 */
6464 int lk_set_log_fn(struct lk_ctx *ctx,
65 void (*log_fn)(void *data, int priority,
66 const char *file, int line, const char *fn,
67 const char *format, va_list args),
68 const void *data);
65 void (*log_fn)(void *data, int priority,
66 const char *file, int line, const char *fn,
67 const char *format, va_list args),
68 const void *data);
6969
7070 #endif /* LK_COMMON_H */
2222 * @brief General information about the keymap.
2323 */
2424 struct kmapinfo {
25 lk_flags flags; /**< Parser flags that are set outside the library */
26 lk_keywords keywords; /**< Keywords used in keymap files */
27 size_t keymaps; /**< Number of keymaps in actual use */
28 size_t keymaps_alloced; /**< Number of keymaps dynamically allocated */
29 size_t functions; /**< Number of function keys */
30 size_t composes; /**< Number of compose definitions in actual use */
25 lk_flags flags; /**< Parser flags that are set outside the library */
26 lk_keywords keywords; /**< Keywords used in keymap files */
27 size_t keymaps; /**< Number of keymaps in actual use */
28 size_t keymaps_alloced; /**< Number of keymaps dynamically allocated */
29 size_t functions; /**< Number of function keys */
30 size_t composes; /**< Number of compose definitions in actual use */
3131
32 size_t keymaps_total;
33 size_t functions_total;
34 size_t composes_total;
32 size_t keymaps_total;
33 size_t functions_total;
34 size_t composes_total;
3535 };
3636
3737 /**
77 #include <keymap/context.h>
88 #include <keymap/findfile.h>
99
10 int lk_add_map(struct lk_ctx *ctx, unsigned int k_table);
10 int lk_add_map(struct lk_ctx *ctx, unsigned int k_table);
1111 int lk_map_exists(struct lk_ctx *ctx, unsigned int k_table);
1212
1313 int lk_get_keys_total(struct lk_ctx *ctx, unsigned int k_table);
1515 int lk_add_key(struct lk_ctx *ctx, unsigned int k_table, unsigned int k_index, int keycode);
1616 int lk_del_key(struct lk_ctx *ctx, unsigned int k_table, unsigned int k_index);
1717 int lk_get_key(struct lk_ctx *ctx, unsigned int k_table, unsigned int k_index);
18 int lk_key_exists(struct lk_ctx *ctx, unsigned int k_table, unsigned int k_index);
18 int lk_key_exists(struct lk_ctx *ctx, unsigned int k_table, unsigned int k_index);
1919
2020 /* Functions for key string manipulations */
2121 int lk_get_func(struct lk_ctx *ctx, struct kbsentry *kbs);
1717 const char *file, int line, const char *fn,
1818 const char *fmt, ...);
1919
20 #define lk_log_cond(ctx, level, arg...) \
21 do { \
22 if (ctx->log_priority >= level) \
23 lk_log(ctx, level, __FILE__, __LINE__, __func__, ## arg);\
20 #define lk_log_cond(ctx, level, arg...) \
21 do { \
22 if (ctx->log_priority >= level) \
23 lk_log(ctx, level, __FILE__, __LINE__, __func__, ##arg); \
2424 } while (0)
2525
2626 /**
2828 * @param ctx is a keymap library context.
2929 * @param arg is output message.
3030 */
31 #define DBG(ctx, arg...) lk_log_cond(ctx, LOG_DEBUG, ## arg)
31 #define DBG(ctx, arg...) lk_log_cond(ctx, LOG_DEBUG, ##arg)
3232
3333 /**
3434 * Wrapper to output informational messages
3535 * @param ctx is a keymap library context.
3636 * @param arg is output message.
3737 */
38 #define INFO(ctx, arg...) lk_log_cond(ctx, LOG_INFO, ## arg)
38 #define INFO(ctx, arg...) lk_log_cond(ctx, LOG_INFO, ##arg)
3939
4040 /**
4141 * Wrapper to output warning conditions
4242 * @param ctx is a keymap library context.
4343 * @param arg is output message.
4444 */
45 #define WARN(ctx, arg...) lk_log_cond(ctx, LOG_WARNING, ## arg)
45 #define WARN(ctx, arg...) lk_log_cond(ctx, LOG_WARNING, ##arg)
4646
4747 /**
4848 * Wrapper to output error conditions
4949 * @param ctx is a keymap library context.
5050 * @param arg is output message.
5151 */
52 #define ERR(ctx, arg...) lk_log_cond(ctx, LOG_ERR, ## arg)
52 #define ERR(ctx, arg...) lk_log_cond(ctx, LOG_ERR, ##arg)
5353
5454 #endif /* LK_LOGGING_H */
1111 #include "ksyms.h"
1212 #include "modifiers.h"
1313
14 int
15 lk_map_exists(struct lk_ctx *ctx, unsigned int k_table)
14 int lk_map_exists(struct lk_ctx *ctx, unsigned int k_table)
1615 {
1716 return (lk_array_get_ptr(ctx->keymap, k_table) != NULL);
1817 }
1918
20 int
21 lk_get_keys_total(struct lk_ctx *ctx, unsigned int k_table)
19 int lk_get_keys_total(struct lk_ctx *ctx, unsigned int k_table)
2220 {
2321 struct lk_array *map;
2422 map = lk_array_get_ptr(ctx->keymap, k_table);
2826 return map->total;
2927 }
3028
31 int
32 lk_key_exists(struct lk_ctx *ctx, unsigned int k_table, unsigned int k_index)
29 int lk_key_exists(struct lk_ctx *ctx, unsigned int k_table, unsigned int k_index)
3330 {
3431 struct lk_array *map;
3532 unsigned int *key;
4744 return (*key > 0);
4845 }
4946
50 int
51 lk_add_map(struct lk_ctx *ctx, unsigned int k_table)
47 int lk_add_map(struct lk_ctx *ctx, unsigned int k_table)
5248 {
5349 struct lk_array *keys;
5450
7369 return 0;
7470 }
7571
76 int
77 lk_get_key(struct lk_ctx *ctx, unsigned int k_table, unsigned int k_index)
72 int lk_get_key(struct lk_ctx *ctx, unsigned int k_table, unsigned int k_index)
7873 {
7974 struct lk_array *map;
8075 unsigned int *key;
9085 return K_HOLE;
9186 }
9287
93 return (*key)-1;
94 }
95
96 int
97 lk_del_key(struct lk_ctx *ctx, unsigned int k_table, unsigned int k_index)
88 return (*key) - 1;
89 }
90
91 int lk_del_key(struct lk_ctx *ctx, unsigned int k_table, unsigned int k_index)
9892 {
9993 struct lk_array *map;
10094
109103
110104 if (lk_array_unset(map, k_index) < 0) {
111105 ERR(ctx, _("unable to unset key %d for table %d"),
112 k_index, k_table);
113 return -1;
114 }
115
116 return 0;
117 }
118
119 int
120 lk_add_key(struct lk_ctx *ctx, unsigned int k_table, unsigned int k_index, int keycode)
106 k_index, k_table);
107 return -1;
108 }
109
110 return 0;
111 }
112
113 int lk_add_key(struct lk_ctx *ctx, unsigned int k_table, unsigned int k_index, int keycode)
121114 {
122115 struct lk_array *map;
123116 unsigned int code = keycode + 1;
149142
150143 if (lk_array_set(map, k_index, &code) < 0) {
151144 ERR(ctx, _("unable to set key %d for table %d"),
152 k_index, k_table);
145 k_index, k_table);
153146 return -1;
154147 }
155148
156149 if (ctx->keywords & LK_KEYWORD_ALTISMETA) {
157150 unsigned int alttable = k_table | M_ALT;
158 int type = KTYP(keycode);
159 int val = KVAL(keycode);
151 int type = KTYP(keycode);
152 int val = KVAL(keycode);
160153
161154 if (alttable != k_table && lk_map_exists(ctx, alttable) &&
162155 !lk_key_exists(ctx, alttable, k_index) &&
187180 defs[2] = defs[0];
188181 defs[3] = defs[1];
189182
190 for (j = 4; j < 8; j++)
183 for (j = 4; j < 8; j++)
191184 defs[j] = K(KT_LATIN, val & ~96);
192185
193 for (j = 8; j < 16; j++)
186 for (j = 8; j < 16; j++)
194187 defs[j] = K(KT_META, KVAL(defs[j - 8]));
195188
196189 for (j = 0; j < ctx->keymap->total; j++) {
221214 return 0;
222215 }
223216
224 int
225 lk_add_constants(struct lk_ctx *ctx)
217 int lk_add_constants(struct lk_ctx *ctx)
226218 {
227219 unsigned int i, r0 = 0;
228220
3030
3131 #include "syms.ktyp.h"
3232
33 #define E(x) { x, sizeof(x) / sizeof(x[0]) }
34
35 const syms_entry
36 syms[] = {
37 E(iso646_syms), /* KT_LATIN */
38 E(fn_syms), /* KT_FN */
39 E(spec_syms), /* KT_SPEC */
40 E(pad_syms), /* KT_PAD */
41 E(dead_syms), /* KT_DEAD */
42 E(cons_syms), /* KT_CONS */
43 E(cur_syms), /* KT_CUR */
44 E(shift_syms), /* KT_SHIFT */
45 { 0, 0 }, /* KT_META */
46 E(ascii_syms), /* KT_ASCII */
47 E(lock_syms), /* KT_LOCK */
48 { 0, 0 }, /* KT_LETTER */
49 E(sticky_syms), /* KT_SLOCK */
50 { 0, 0 }, /* */
51 E(brl_syms) /* KT_BRL */
33 #define E(x) \
34 { \
35 x, sizeof(x) / sizeof(x[0]) \
36 }
37
38 const syms_entry syms[] = {
39 E(iso646_syms), /* KT_LATIN */
40 E(fn_syms), /* KT_FN */
41 E(spec_syms), /* KT_SPEC */
42 E(pad_syms), /* KT_PAD */
43 E(dead_syms), /* KT_DEAD */
44 E(cons_syms), /* KT_CONS */
45 E(cur_syms), /* KT_CUR */
46 E(shift_syms), /* KT_SHIFT */
47 { 0, 0 }, /* KT_META */
48 E(ascii_syms), /* KT_ASCII */
49 E(lock_syms), /* KT_LOCK */
50 { 0, 0 }, /* KT_LETTER */
51 E(sticky_syms), /* KT_SLOCK */
52 { 0, 0 }, /* */
53 E(brl_syms) /* KT_BRL */
5254 };
5355
5456 #undef E
5557
5658 const unsigned int syms_size = sizeof(syms) / sizeof(syms_entry);
57 const unsigned int syn_size = sizeof(synonyms) / sizeof(synonyms[0]);
59 const unsigned int syn_size = sizeof(synonyms) / sizeof(synonyms[0]);
5860
5961 const struct cs {
6062 const char *charset;
6163 const sym *charnames;
6264 const int start;
6365 } charsets[] = {
64 { "iso-8859-1", latin1_syms, 160 },
65 { "iso-8859-2", latin2_syms, 160 },
66 { "iso-8859-3", latin3_syms, 160 },
67 { "iso-8859-4", latin4_syms, 160 },
68 { "iso-8859-5", iso8859_5_syms, 160 },
69 { "iso-8859-7", iso8859_7_syms, 160 },
70 { "iso-8859-8", iso8859_8_syms, 160 },
71 { "iso-8859-9", iso8859_9_syms, 160 },
72 { "iso-8859-10", latin6_syms, 160 },
73 { "iso-8859-15", iso8859_15_syms, 160 },
74 { "mazovia", mazovia_syms, 128 },
75 { "cp-1250", cp1250_syms, 128 },
76 { "koi8-r", koi8_syms, 128 },
77 { "koi8-u", koi8_syms, 128 },
78 { "tis-620", tis_620_syms, 160 }, /* thai */
79 { "iso-10646-18", iso10646_18_syms, 159 }, /* ethiopic */
80 { "iso-ir-197", iso_ir_197_syms, 160 }, /* sami */
81 { "iso-ir-209", iso_ir_209_syms, 160 }, /* sami */
66 { "iso-8859-1", latin1_syms, 160 },
67 { "iso-8859-2", latin2_syms, 160 },
68 { "iso-8859-3", latin3_syms, 160 },
69 { "iso-8859-4", latin4_syms, 160 },
70 { "iso-8859-5", iso8859_5_syms, 160 },
71 { "iso-8859-7", iso8859_7_syms, 160 },
72 { "iso-8859-8", iso8859_8_syms, 160 },
73 { "iso-8859-9", iso8859_9_syms, 160 },
74 { "iso-8859-10", latin6_syms, 160 },
75 { "iso-8859-15", iso8859_15_syms, 160 },
76 { "mazovia", mazovia_syms, 128 },
77 { "cp-1250", cp1250_syms, 128 },
78 { "koi8-r", koi8_syms, 128 },
79 { "koi8-u", koi8_syms, 128 },
80 { "tis-620", tis_620_syms, 160 }, /* thai */
81 { "iso-10646-18", iso10646_18_syms, 159 }, /* ethiopic */
82 { "iso-ir-197", iso_ir_197_syms, 160 }, /* sami */
83 { "iso-ir-209", iso_ir_209_syms, 160 }, /* sami */
8284 };
8385
8486 static const unsigned int charsets_size = sizeof(charsets) / sizeof(charsets[0]);
8587
8688 /* Functions for both dumpkeys and loadkeys. */
8789
88 void
89 lk_list_charsets(FILE *f) {
90 int lth,ct;
90 void lk_list_charsets(FILE *f)
91 {
92 int lth, ct;
9193 unsigned int i, j;
9294 char *mm[] = { "iso-8859-", "koi8-" };
9395
94 for (j=0; j<sizeof(mm)/sizeof(mm[0]); j++) {
95 if(j)
96 for (j = 0; j < sizeof(mm) / sizeof(mm[0]); j++) {
97 if (j)
9698 fprintf(f, ",");
9799 fprintf(f, "%s{", mm[j]);
98 ct = 0;
100 ct = 0;
99101 lth = strlen(mm[j]);
100 for(i=1; i < charsets_size; i++) {
101 if(!strncmp(charsets[i].charset, mm[j], lth)) {
102 if(ct++)
102 for (i = 1; i < charsets_size; i++) {
103 if (!strncmp(charsets[i].charset, mm[j], lth)) {
104 if (ct++)
103105 fprintf(f, ",");
104 fprintf(f, "%s", charsets[i].charset+lth);
106 fprintf(f, "%s", charsets[i].charset + lth);
105107 }
106108 }
107109 fprintf(f, "}");
108110 }
109 for(i=0; i < charsets_size; i++) {
110 for (j=0; j<sizeof(mm)/sizeof(mm[0]); j++) {
111 for (i = 0; i < charsets_size; i++) {
112 for (j = 0; j < sizeof(mm) / sizeof(mm[0]); j++) {
111113 lth = strlen(mm[j]);
112 if(!strncmp(charsets[i].charset, mm[j], lth))
114 if (!strncmp(charsets[i].charset, mm[j], lth))
113115 goto nxti;
114116 }
115117 fprintf(f, ",%s", charsets[i].charset);
127129 return charsets[ctx->charset].charset;
128130 }
129131
130 int
131 lk_set_charset(struct lk_ctx *ctx, const char *charset) {
132 int lk_set_charset(struct lk_ctx *ctx, const char *charset)
133 {
132134 unsigned int i;
133135
134136 for (i = 0; i < charsets_size; i++) {
173175 }
174176
175177 const char *
176 codetoksym(struct lk_ctx *ctx, int code) {
178 codetoksym(struct lk_ctx *ctx, int code)
179 {
177180 unsigned int i;
178181 int j;
179182 sym *p;
181184 if (code < 0)
182185 return NULL;
183186
184 if (code < 0x1000) { /* "traditional" keysym */
187 if (code < 0x1000) { /* "traditional" keysym */
185188 if (code < 0x80)
186189 return get_sym(ctx, KT_LATIN, code);
187190
195198 return get_sym(ctx, KTYP(code), KVAL(code));
196199
197200 i = ctx->charset;
198 p = (sym *) charsets[i].charnames;
201 p = (sym *)charsets[i].charnames;
199202 if (p && (KVAL(code) >= charsets[i].start)) {
200203 p += KVAL(code) - charsets[i].start;
201204 if (p->name[0])
203206 }
204207 }
205208
206 else { /* Unicode keysym */
209 else { /* Unicode keysym */
207210 code ^= 0xf000;
208211
209212 if (code < 0x80)
210213 return get_sym(ctx, KT_LATIN, code);
211214
212215 for (i = 0; i < charsets_size; i++) {
213 p = (sym *) charsets[i].charnames;
216 p = (sym *)charsets[i].charnames;
214217 if (p) {
215218 for (j = charsets[i].start; j < 256; j++, p++) {
216219 if (p->uni == code && p->name[0])
238241 /* Functions for loadkeys. */
239242
240243 static int
241 kt_latin(struct lk_ctx *ctx, const char *s, int direction) {
244 kt_latin(struct lk_ctx *ctx, const char *s, int direction)
245 {
242246 unsigned int i, max;
243247
244 sym *p = (sym *) charsets[ctx->charset].charnames;
248 sym *p = (sym *)charsets[ctx->charset].charnames;
245249
246250 max = (direction == TO_UNICODE ? 128 : 256); // TODO(dmage): is 256 valid for ethiopic charset?
247251
260264 return -1;
261265 }
262266
263 int
264 ksymtocode(struct lk_ctx *ctx, const char *s, int direction) {
267 int ksymtocode(struct lk_ctx *ctx, const char *s, int direction)
268 {
265269 unsigned int i, j;
266270 int n;
267271 int keycode;
269273
270274 if (direction == TO_AUTO)
271275 direction = (ctx->flags & LK_FLAG_PREFER_UNICODE)
272 ? TO_UNICODE : TO_8BIT;
276 ? TO_UNICODE
277 : TO_8BIT;
273278
274279 if (!strncmp(s, "Meta_", 5)) {
275 keycode = ksymtocode(ctx, s+5, TO_8BIT);
280 keycode = ksymtocode(ctx, s + 5, TO_8BIT);
276281 if (KTYP(keycode) == KT_LATIN)
277282 return K(KT_META, KVAL(keycode));
278283
279284 /* Avoid error messages for Meta_acute with UTF-8 */
280 else if(direction == TO_UNICODE)
281 return (0);
285 else if (direction == TO_UNICODE)
286 return (0);
282287
283288 /* fall through to error printf */
284289 }
300305
301306 if (direction == TO_UNICODE) {
302307 i = ctx->charset;
303 p = (sym *) charsets[i].charnames;
308 p = (sym *)charsets[i].charnames;
304309 if (p) {
305310 for (j = charsets[i].start; j < 256; j++, p++) {
306311 if (!strcmp(s, p->name))
313318 if (i == ctx->charset) {
314319 continue;
315320 }
316 p = (sym *) charsets[i].charnames;
321 p = (sym *)charsets[i].charnames;
317322 if (p) {
318323 for (j = charsets[i].start; j < 256; j++, p++) {
319324 if (!strcmp(s, p->name))
364369 return CODE_FOR_UNKNOWN_KSYM;
365370 }
366371
367 int
368 lk_ksym_to_unicode(struct lk_ctx *ctx, const char *s)
372 int lk_ksym_to_unicode(struct lk_ctx *ctx, const char *s)
369373 {
370374 return ksymtocode(ctx, s, TO_UNICODE);
371375 }
372376
373 int
374 convert_code(struct lk_ctx *ctx, int code, int direction)
377 int convert_code(struct lk_ctx *ctx, int code, int direction)
375378 {
376379 const char *ksym;
377 int unicode_forced = (direction == TO_UNICODE);
380 int unicode_forced = (direction == TO_UNICODE);
378381 int input_is_unicode = (code >= 0x1000);
379382 int result;
380383
381384 if (direction == TO_AUTO)
382385 direction = (ctx->flags & LK_FLAG_PREFER_UNICODE)
383 ? TO_UNICODE : TO_8BIT;
386 ? TO_UNICODE
387 : TO_8BIT;
384388
385389 if (KTYP(code) == KT_META)
386390 return code;
391395 /* so is Unicode "Basic Latin" */
392396 return code ^ 0xf000;
393397 else if ((input_is_unicode && direction == TO_UNICODE) ||
394 (!input_is_unicode && direction == TO_8BIT))
398 (!input_is_unicode && direction == TO_8BIT))
395399 /* no conversion necessary */
396400 result = code;
397401 else {
416420 return result;
417421 }
418422
419 int
420 add_capslock(struct lk_ctx *ctx, int code)
423 int add_capslock(struct lk_ctx *ctx, int code)
421424 {
422425 if (KTYP(code) == KT_LATIN && (!(ctx->flags & LK_FLAG_PREFER_UNICODE) || code < 0x80))
423426 return K(KT_LETTER, KVAL(code));
88 } sym;
99
1010 typedef struct {
11 const char * const *table;
11 const char *const *table;
1212 const unsigned int size;
1313 } syms_entry;
1414
2525 #define CODE_FOR_UNKNOWN_KSYM (-1)
2626
2727 /* Directions for converting keysyms */
28 #define TO_AUTO (-1) /* use LK_FLAG_PREFER_UNICODE */
28 #define TO_AUTO (-1) /* use LK_FLAG_PREFER_UNICODE */
2929 #define TO_8BIT 0
3030 #define TO_UNICODE 1
3131
2525 /* temporarily switch to K_UNICODE while defining keys */
2626 if (ioctl(fd, KDSKBMODE, K_UNICODE)) {
2727 ERR(ctx, _("KDSKBMODE: %s: could not switch to Unicode mode"),
28 strerror(errno));
28 strerror(errno));
2929 goto fail;
3030 }
3131 }
5555 ct++;
5656
5757 INFO(ctx, _("keycode %d, table %d = %d%s"),
58 j, i, lk_get_key(ctx,i, j), fail ? _(" FAILED") : "");
58 j, i, lk_get_key(ctx, i, j), fail ? _(" FAILED") : "");
5959
6060 if (fail)
6161 WARN(ctx, _("failed to bind key %d to value %d"),
7373 if (ioctl(fd, KDSKBENT, (unsigned long)&ke)) {
7474 if (errno != EINVAL) {
7575 ERR(ctx, _("KDSKBENT: %s: could not deallocate keymap %d"),
76 strerror(errno), i);
76 strerror(errno), i);
7777 goto fail;
7878 }
7979 /* probably an old kernel */
8585
8686 if (ioctl(fd, KDSKBENT, (unsigned long)&ke)) {
8787 if (errno == EINVAL && i >= 16)
88 break; /* old kernel */
88 break; /* old kernel */
8989
9090 ERR(ctx, _("KDSKBENT: %s: cannot deallocate or clear keymap"),
91 strerror(errno));
91 strerror(errno));
9292 goto fail;
9393 }
9494 }
9898
9999 if ((ctx->flags & LK_FLAG_UNICODE_MODE) && ioctl(fd, KDSKBMODE, kbd_mode)) {
100100 ERR(ctx, _("KDSKBMODE: %s: could not return to original keyboard mode"),
101 strerror(errno));
101 strerror(errno));
102102 goto fail;
103103 }
104104
105105 return ct;
106106
107 fail: return -1;
108 }
109
107 fail:
108 return -1;
109 }
110110
111111 static char *
112112 ostr(struct lk_ctx *ctx, char *s)
113113 {
114 int lth = strlen(s);
114 int lth = strlen(s);
115115 char *ns0 = malloc(4 * lth + 1);
116 char *ns = ns0;
116 char *ns = ns0;
117117
118118 if (ns == NULL) {
119119 ERR(ctx, _("out of memory"));
122122
123123 while (*s) {
124124 switch (*s) {
125 case '\n':
126 *ns++ = '\\';
127 *ns++ = 'n';
128 break;
129 case '\033':
130 *ns++ = '\\';
131 *ns++ = '0';
132 *ns++ = '3';
133 *ns++ = '3';
134 break;
135 default:
136 *ns++ = *s;
125 case '\n':
126 *ns++ = '\\';
127 *ns++ = 'n';
128 break;
129 case '\033':
130 *ns++ = '\\';
131 *ns++ = '0';
132 *ns++ = '3';
133 *ns++ = '3';
134 break;
135 default:
136 *ns++ = *s;
137137 }
138138 s++;
139139 }
160160 if (s == NULL)
161161 return -1;
162162 ERR(ctx, _("failed to bind string '%s' to function %s"),
163 s, get_sym(ctx, KT_FN, kbs.kb_func));
163 s, get_sym(ctx, KT_FN, kbs.kb_func));
164164 free(s);
165165 } else {
166166 ct++;
170170
171171 if (ioctl(fd, KDSKBSENT, (unsigned long)&kbs)) {
172172 ERR(ctx, _("failed to clear string %s"),
173 get_sym(ctx, KT_FN, kbs.kb_func));
173 get_sym(ctx, KT_FN, kbs.kb_func));
174174 } else {
175175 ct++;
176176 }
238238 return count;
239239 }
240240
241 int
242 lk_load_keymap(struct lk_ctx *ctx, int fd, int kbd_mode)
241 int lk_load_keymap(struct lk_ctx *ctx, int fd, int kbd_mode)
243242 {
244243 int keyct, funcct, diacct;
245244
259258 return -1;
260259
261260 INFO(ctx, P_("Loaded %d compose definition",
262 "Loaded %d compose definitions", diacct), diacct);
261 "Loaded %d compose definitions", diacct),
262 diacct);
263263
264264 } else {
265265 INFO(ctx, _("(No change in compose definitions)"));
11 #include "modifiers.h"
22
33 const modifier_t modifiers[] = {
4 { "shift", KG_SHIFT },
5 { "altgr", KG_ALTGR },
6 { "control", KG_CTRL },
7 { "alt", KG_ALT },
8 { "shiftl", KG_SHIFTL },
9 { "shiftr", KG_SHIFTR },
10 { "ctrll", KG_CTRLL },
11 { "ctrlr", KG_CTRLR },
12 { "capsshift", KG_CAPSSHIFT },
13 { 0, 0 }
4 { "shift", KG_SHIFT },
5 { "altgr", KG_ALTGR },
6 { "control", KG_CTRL },
7 { "alt", KG_ALT },
8 { "shiftl", KG_SHIFTL },
9 { "shiftr", KG_SHIFTR },
10 { "ctrll", KG_CTRLL },
11 { "ctrlr", KG_CTRLR },
12 { "capsshift", KG_CAPSSHIFT },
13 { 0, 0 }
1414 };
00 #ifndef _MODIFIERS_H
11 #define _MODIFIERS_H
22
3 #include <linux/keyboard.h>
3 #include <linux/keyboard.h>
44
5 #define M_PLAIN 0
6 #define M_SHIFT (1 << KG_SHIFT)
7 #define M_CTRL (1 << KG_CTRL)
8 #define M_ALT (1 << KG_ALT)
9 #define M_ALTGR (1 << KG_ALTGR)
5 #define M_PLAIN 0
6 #define M_SHIFT (1 << KG_SHIFT)
7 #define M_CTRL (1 << KG_CTRL)
8 #define M_ALT (1 << KG_ALT)
9 #define M_ALTGR (1 << KG_ALTGR)
1010 #define M_SHIFTL (1 << KG_SHIFTL)
1111 #define M_SHIFTR (1 << KG_SHIFTR)
12 #define M_CTRLL (1 << KG_CTRLL)
13 #define M_CTRLR (1 << KG_CTRLR)
12 #define M_CTRLL (1 << KG_CTRLL)
13 #define M_CTRLR (1 << KG_CTRLR)
1414 #define M_CAPSSHIFT (1 << KG_CAPSSHIFT)
1515
1616 typedef struct {
1717 #include "ksyms.h"
1818 #include "modifiers.h"
1919
20
2120 static char
2221 valid_type(int fd, int t)
2322 {
2726 ke.kb_table = 0;
2827 ke.kb_value = K(t, 0);
2928
30 return (ioctl(fd, KDSKBENT, (unsigned long) &ke) == 0);
29 return (ioctl(fd, KDSKBENT, (unsigned long)&ke) == 0);
3130 }
3231
3332 static unsigned char
3938 ke.kb_index = 0;
4039 ke.kb_table = 0;
4140 ke.kb_value = K_HOLE;
42 ke0 = ke;
41 ke0 = ke;
4342
44 ioctl(fd, KDGKBENT, (unsigned long) &ke0);
43 ioctl(fd, KDGKBENT, (unsigned long)&ke0);
4544
4645 for (i = 0; i < 256; i++) {
4746 ke.kb_value = K(t, i);
48 if (ioctl(fd, KDSKBENT, (unsigned long) &ke))
47 if (ioctl(fd, KDSKBENT, (unsigned long)&ke))
4948 break;
5049 }
5150 ke.kb_value = K_HOLE;
52 ioctl(fd, KDSKBENT, (unsigned long) &ke0);
51 ioctl(fd, KDSKBENT, (unsigned long)&ke0);
5352
5453 return i - 1;
5554 }
5655
57 int
58 lk_get_kmapinfo(struct lk_ctx *ctx, struct kmapinfo *res)
56 int lk_get_kmapinfo(struct lk_ctx *ctx, struct kmapinfo *res)
5957 {
6058 int i;
6159
8583
8684 #define NR_TYPES 15
8785
88 void
89 lk_dump_summary(struct lk_ctx *ctx, FILE *fd, int console)
86 void lk_dump_summary(struct lk_ctx *ctx, FILE *fd, int console)
9087 {
9188 int i;
9289 struct kmapinfo info;
9592 return;
9693
9794 fprintf(fd, _("keycode range supported by kernel: 1 - %d\n"),
98 NR_KEYS - 1);
95 NR_KEYS - 1);
9996 fprintf(fd, _("max number of actions bindable to a key: %d\n"),
100 MAX_NR_KEYMAPS);
97 MAX_NR_KEYMAPS);
10198 fprintf(fd, _("number of keymaps in actual use: %u\n"),
102 (unsigned int) info.keymaps);
99 (unsigned int)info.keymaps);
103100
104101 fprintf(fd, _("of which %u dynamically allocated\n"),
105 (unsigned int) info.keymaps_alloced);
102 (unsigned int)info.keymaps_alloced);
106103
107104 fprintf(fd, _("ranges of action codes supported by kernel:\n"));
108105
109106 for (i = 0; i < NR_TYPES && valid_type(console, i); i++)
110107 fprintf(fd, " 0x%04x - 0x%04x\n",
111 K(i, 0), K(i, maximum_val(console, i)));
108 K(i, 0), K(i, maximum_val(console, i)));
112109
113110 fprintf(fd, _("number of function keys supported by kernel: %d\n"),
114 MAX_NR_FUNC);
111 MAX_NR_FUNC);
115112 fprintf(fd, _("max nr of compose definitions: %d\n"),
116 MAX_DIACR);
113 MAX_DIACR);
117114 fprintf(fd, _("nr of compose definitions in actual use: %u\n"),
118 (unsigned int) info.composes);
115 (unsigned int)info.composes);
119116 }
120117
121 void
122 lk_dump_symbols(struct lk_ctx *ctx, FILE *fd)
118 void lk_dump_symbols(struct lk_ctx *ctx, FILE *fd)
123119 {
124120 unsigned int t, v;
125121 modifier_t *mod;
126122 const char *p;
127123
128124 for (t = 0; t < syms_size; t++) {
129 if (get_sym_size(ctx, t)) {
130 for (v = 0; v < get_sym_size(ctx, t); v++) {
131 if ((p = get_sym(ctx, t, v))[0])
132 fprintf(fd, "0x%04x\t%s\n", K(t, v), p);
125 if (get_sym_size(ctx, t)) {
126 for (v = 0; v < get_sym_size(ctx, t); v++) {
127 if ((p = get_sym(ctx, t, v))[0])
128 fprintf(fd, "0x%04x\t%s\n", K(t, v), p);
129 }
130 } else if (t == KT_META) {
131 for (v = 0; v < get_sym_size(ctx, KT_LATIN) && v < 128; v++) {
132 if ((p = get_sym(ctx, KT_LATIN, v))[0])
133 fprintf(fd, "0x%04x\tMeta_%s\n", K(t, v), p);
134 }
133135 }
134 } else if (t == KT_META) {
135 for (v = 0; v < get_sym_size(ctx, KT_LATIN) && v < 128; v++) {
136 if ((p = get_sym(ctx, KT_LATIN, v))[0])
137 fprintf(fd, "0x%04x\tMeta_%s\n", K(t, v), p);
138 }
139 }
140136 }
141137
142138 fprintf(fd, _("\nThe following synonyms are recognized:\n\n"));
143139
144140 for (t = 0; t < syn_size; t++) {
145141 fprintf(fd, _("%-15s for %s\n"),
146 synonyms[t].synonym, synonyms[t].official_name);
142 synonyms[t].synonym, synonyms[t].official_name);
147143 }
148144
149145 fprintf(fd, _("\nRecognized modifier names and their column numbers:\n"));
150146
151 mod = (modifier_t *) modifiers;
147 mod = (modifier_t *)modifiers;
152148 while (mod->name) {
153149 fprintf(fd, "%s\t\t%3d\n", mod->name, 1 << mod->bit);
154150 mod++;
55 *
66 * { "iso-10646-18", iso_10646_18_syms, 159 },
77 */
8 static sym
9 const iso10646_18_syms[] = { /* 0x1200 - 0x137F */
8 static sym const iso10646_18_syms[] = {
9 /* 0x1200 - 0x137F */
1010 { 0x1200, "ethiopic_syllable_ha" },
1111 { 0x1201, "ethiopic_syllable_hu" },
1212 { 0x1202, "ethiopic_syllable_hi" },
00 /*
11 * Keysyms whose KTYP is KT_LATIN or KT_LETTER and whose KVAL is 0..127.
22 */
3 static const char *
4 const iso646_syms[] = {
5 "nul", /* 0x00, 0000 */
3 static const char *const iso646_syms[] = {
4 "nul", /* 0x00, 0000 */
65 "Control_a",
76 "Control_b",
87 "Control_c",
1817 "Control_m",
1918 "Control_n",
2019 "Control_o",
21 "Control_p", /* 0x10, 0020 */
20 "Control_p", /* 0x10, 0020 */
2221 "Control_q",
2322 "Control_r",
2423 "Control_s",
3433 "Control_bracketright",
3534 "Control_asciicircum",
3635 "Control_underscore",
37 "space", /* 0x20, 0040 */
36 "space", /* 0x20, 0040 */
3837 "exclam",
3938 "quotedbl",
4039 "numbersign",
5049 "minus",
5150 "period",
5251 "slash",
53 "zero", /* 0x30, 0060 */
52 "zero", /* 0x30, 0060 */
5453 "one",
5554 "two",
5655 "three",
6665 "equal",
6766 "greater",
6867 "question",
69 "at", /* 0x40, 0100 */
68 "at", /* 0x40, 0100 */
7069 "A",
7170 "B",
7271 "C",
8281 "M",
8382 "N",
8483 "O",
85 "P", /* 0x50, 0120 */
84 "P", /* 0x50, 0120 */
8685 "Q",
8786 "R",
8887 "S",
9897 "bracketright",
9998 "asciicircum",
10099 "underscore",
101 "grave", /* 0x60, 0140 */
100 "grave", /* 0x60, 0140 */
102101 "a",
103102 "b",
104103 "c",
114113 "m",
115114 "n",
116115 "o",
117 "p", /* 0x70, 0160 */
116 "p", /* 0x70, 0160 */
118117 "q",
119118 "r",
120119 "s",
130129 "braceright",
131130 "asciitilde",
132131 "Delete",
133 "", /* 0x80, 0200 */
134 "",
135 "",
136 "",
137 "",
138 "",
139 "",
140 "",
141 "",
142 "",
143 "",
144 "",
145 "",
146 "",
147 "",
148 "",
149 "", /* 0x90, 0220 */
150 "",
151 "",
152 "",
153 "",
154 "",
155 "",
156 "",
157 "",
158 "",
159 "",
160 "",
161 "",
162 "",
163 "",
164 "",
165 "nobreakspace", /* 0xa0, 0240 */
132 "", /* 0x80, 0200 */
133 "",
134 "",
135 "",
136 "",
137 "",
138 "",
139 "",
140 "",
141 "",
142 "",
143 "",
144 "",
145 "",
146 "",
147 "",
148 "", /* 0x90, 0220 */
149 "",
150 "",
151 "",
152 "",
153 "",
154 "",
155 "",
156 "",
157 "",
158 "",
159 "",
160 "",
161 "",
162 "",
163 "",
164 "nobreakspace", /* 0xa0, 0240 */
166165 "exclamdown",
167166 "cent",
168167 "sterling",
178177 "hyphen",
179178 "registered",
180179 "macron",
181 "degree", /* 0xb0, 0260 */
180 "degree", /* 0xb0, 0260 */
182181 "plusminus",
183182 "twosuperior",
184183 "threesuperior",
194193 "onehalf",
195194 "threequarters",
196195 "questiondown",
197 "Agrave", /* 0xc0, 0300 */
196 "Agrave", /* 0xc0, 0300 */
198197 "Aacute",
199198 "Acircumflex",
200199 "Atilde",
210209 "Iacute",
211210 "Icircumflex",
212211 "Idiaeresis",
213 "ETH", /* 0xd0, 0320 */
212 "ETH", /* 0xd0, 0320 */
214213 "Ntilde",
215214 "Ograve",
216215 "Oacute",
226225 "Yacute",
227226 "THORN",
228227 "ssharp",
229 "agrave", /* 0xe0, 0340 */
228 "agrave", /* 0xe0, 0340 */
230229 "aacute",
231230 "acircumflex",
232231 "atilde",
242241 "iacute",
243242 "icircumflex",
244243 "idiaeresis",
245 "eth", /* 0xf0, 0360 */
244 "eth", /* 0xf0, 0360 */
246245 "ntilde",
247246 "ograve",
248247 "oacute",
257256 "udiaeresis",
258257 "yacute",
259258 "thorn",
260 "ydiaeresis", /* 0xff, 0377 */
261 };
262
263
259 "ydiaeresis", /* 0xff, 0377 */
260 };
264261
265262 /*
266263 * Keysyms whose KTYP is KT_FN.
267264 */
268 static const char *
269 const fn_syms[] = {
270 "F1", "F2", "F3", "F4", "F5",
271 "F6", "F7", "F8", "F9", "F10",
272 "F11", "F12", "F13", "F14", "F15",
273 "F16", "F17", "F18", "F19", "F20",
274 "Find", /* also called: "Home" */
265 static const char *const fn_syms[] = {
266 "F1", "F2", "F3", "F4", "F5",
267 "F6", "F7", "F8", "F9", "F10",
268 "F11", "F12", "F13", "F14", "F15",
269 "F16", "F17", "F18", "F19", "F20",
270 "Find", /* also called: "Home" */
275271 "Insert",
276272 "Remove",
277 "Select", /* also called: "End" */
278 "Prior", /* also called: "PageUp" */
279 "Next", /* also called: "PageDown" */
273 "Select", /* also called: "End" */
274 "Prior", /* also called: "PageUp" */
275 "Next", /* also called: "PageDown" */
280276 "Macro",
281277 "Help",
282278 "Do",
283279 "Pause",
284 "F21", "F22", "F23", "F24", "F25",
285 "F26", "F27", "F28", "F29", "F30",
286 "F31", "F32", "F33", "F34", "F35",
287 "F36", "F37", "F38", "F39", "F40",
288 "F41", "F42", "F43", "F44", "F45",
289 "F46", "F47", "F48", "F49", "F50",
290 "F51", "F52", "F53", "F54", "F55",
291 "F56", "F57", "F58", "F59", "F60",
292 "F61", "F62", "F63", "F64", "F65",
293 "F66", "F67", "F68", "F69", "F70",
294 "F71", "F72", "F73", "F74", "F75",
295 "F76", "F77", "F78", "F79", "F80",
296 "F81", "F82", "F83", "F84", "F85",
297 "F86", "F87", "F88", "F89", "F90",
298 "F91", "F92", "F93", "F94", "F95",
299 "F96", "F97", "F98", "F99", "F100",
300 "F101", "F102", "F103", "F104", "F105",
301 "F106", "F107", "F108", "F109", "F110",
302 "F111", "F112", "F113", "F114", "F115",
303 "F116", "F117", "F118", "F119", "F120",
304 "F121", "F122", "F123", "F124", "F125",
305 "F126", "F127", "F128", "F129", "F130",
306 "F131", "F132", "F133", "F134", "F135",
307 "F136", "F137", "F138", "F139", "F140",
308 "F141", "F142", "F143", "F144", "F145",
309 "F146", "F147", "F148", "F149", "F150",
310 "F151", "F152", "F153", "F154", "F155",
311 "F156", "F157", "F158", "F159", "F160",
312 "F161", "F162", "F163", "F164", "F165",
313 "F166", "F167", "F168", "F169", "F170",
314 "F171", "F172", "F173", "F174", "F175",
315 "F176", "F177", "F178", "F179", "F180",
316 "F181", "F182", "F183", "F184", "F185",
317 "F186", "F187", "F188", "F189", "F190",
318 "F191", "F192", "F193", "F194", "F195",
319 "F196", "F197", "F198", "F199", "F200",
320 "F201", "F202", "F203", "F204", "F205",
321 "F206", "F207", "F208", "F209", "F210",
322 "F211", "F212", "F213", "F214", "F215",
323 "F216", "F217", "F218", "F219", "F220",
324 "F221", "F222", "F223", "F224", "F225",
325 "F226", "F227", "F228", "F229", "F230",
326 "F231", "F232", "F233", "F234", "F235",
327 "F236", "F237", "F238", "F239", "F240",
328 "F241", "F242", "F243", "F244", "F245",
329 "F246" /* there are 10 keys named Insert etc., total 256 */
280 "F21", "F22", "F23", "F24", "F25",
281 "F26", "F27", "F28", "F29", "F30",
282 "F31", "F32", "F33", "F34", "F35",
283 "F36", "F37", "F38", "F39", "F40",
284 "F41", "F42", "F43", "F44", "F45",
285 "F46", "F47", "F48", "F49", "F50",
286 "F51", "F52", "F53", "F54", "F55",
287 "F56", "F57", "F58", "F59", "F60",
288 "F61", "F62", "F63", "F64", "F65",
289 "F66", "F67", "F68", "F69", "F70",
290 "F71", "F72", "F73", "F74", "F75",
291 "F76", "F77", "F78", "F79", "F80",
292 "F81", "F82", "F83", "F84", "F85",
293 "F86", "F87", "F88", "F89", "F90",
294 "F91", "F92", "F93", "F94", "F95",
295 "F96", "F97", "F98", "F99", "F100",
296 "F101", "F102", "F103", "F104", "F105",
297 "F106", "F107", "F108", "F109", "F110",
298 "F111", "F112", "F113", "F114", "F115",
299 "F116", "F117", "F118", "F119", "F120",
300 "F121", "F122", "F123", "F124", "F125",
301 "F126", "F127", "F128", "F129", "F130",
302 "F131", "F132", "F133", "F134", "F135",
303 "F136", "F137", "F138", "F139", "F140",
304 "F141", "F142", "F143", "F144", "F145",
305 "F146", "F147", "F148", "F149", "F150",
306 "F151", "F152", "F153", "F154", "F155",
307 "F156", "F157", "F158", "F159", "F160",
308 "F161", "F162", "F163", "F164", "F165",
309 "F166", "F167", "F168", "F169", "F170",
310 "F171", "F172", "F173", "F174", "F175",
311 "F176", "F177", "F178", "F179", "F180",
312 "F181", "F182", "F183", "F184", "F185",
313 "F186", "F187", "F188", "F189", "F190",
314 "F191", "F192", "F193", "F194", "F195",
315 "F196", "F197", "F198", "F199", "F200",
316 "F201", "F202", "F203", "F204", "F205",
317 "F206", "F207", "F208", "F209", "F210",
318 "F211", "F212", "F213", "F214", "F215",
319 "F216", "F217", "F218", "F219", "F220",
320 "F221", "F222", "F223", "F224", "F225",
321 "F226", "F227", "F228", "F229", "F230",
322 "F231", "F232", "F233", "F234", "F235",
323 "F236", "F237", "F238", "F239", "F240",
324 "F241", "F242", "F243", "F244", "F245",
325 "F246" /* there are 10 keys named Insert etc., total 256 */
330326 };
331327
332328 /*
333329 * Keysyms whose KTYP is KT_SPEC.
334330 */
335 static const char *
336 const spec_syms[] = {
331 static const char *const spec_syms[] = {
337332 "VoidSymbol",
338333 "Return",
339334 "Show_Registers",
359354 /*
360355 * Keysyms whose KTYP is KT_PAD.
361356 */
362 static const char *
363 const pad_syms[] = {
357 static const char *const pad_syms[] = {
364358 "KP_0",
365359 "KP_1",
366360 "KP_2",
384378 /*
385379 * Keysyms whose KTYP is KT_DEAD.
386380 */
387 static const char *
388 const dead_syms[] = {
381 static const char *const dead_syms[] = {
389382 "dead_grave",
390383 "dead_acute",
391384 "dead_circumflex",
397390 /*
398391 * Keysyms whose KTYP is KT_CONS.
399392 */
400 static const char *
401 const cons_syms[] = {
393 static const char *const cons_syms[] = {
402394 "Console_1",
403395 "Console_2",
404396 "Console_3",
467459 /*
468460 * Keysyms whose KTYP is KT_CUR.
469461 */
470 static const char *
471 const cur_syms[] = {
462 static const char *const cur_syms[] = {
472463 "Down",
473464 "Left",
474465 "Right",
478469 /*
479470 * Keysyms whose KTYP is KT_SHIFT.
480471 */
481 static const char *
482 const shift_syms[] = {
472 static const char *const shift_syms[] = {
483473 "Shift",
484474 "AltGr",
485475 "Control",
494484 /*
495485 * Keysyms whose KTYP is KT_ASCII.
496486 */
497 static const char *
498 const ascii_syms[] = {
487 static const char *const ascii_syms[] = {
499488 "Ascii_0",
500489 "Ascii_1",
501490 "Ascii_2",
527516 /*
528517 * Keysyms whose KTYP is KT_LOCK.
529518 */
530 static const char *
531 const lock_syms[] = {
519 static const char *const lock_syms[] = {
532520 "Shift_Lock",
533521 "AltGr_Lock",
534522 "Control_Lock",
543531 /*
544532 * Keysyms whose KTYP is KT_SLOCK.
545533 */
546 static const char *
547 const sticky_syms[] = {
534 static const char *const sticky_syms[] = {
548535 "SShift",
549536 "SAltGr",
550537 "SControl",
559546 /*
560547 * Keysyms whose KTYP is KT_BRL.
561548 */
562 static const char *
563 const brl_syms[] = {
549 static const char *const brl_syms[] = {
564550 "Brl_blank",
565551 "Brl_dot1",
566552 "Brl_dot2",
0 static sym
1 const mazovia_syms[] = {
0 static sym const mazovia_syms[] = {
21 /* as specified by Wlodek Bzyl <matwb@univ.gda.pl> */
32 { 0x0080, "" },
43 { 0x0081, "" },
55 * { "iso-ir-197", iso_ir_197_syms, nn },
66 */
77
8 static sym
9 const iso_ir_197_syms[] = {
8 static sym const iso_ir_197_syms[] = {
109 { 0x00a0, "nobreakspace" },
1110 { 0x010c, "Ccaron" },
1211 { 0x010d, "ccaron" },
117116 * 0xBB 0x021F # LATIN SMALL LETTER H WITH CARON
118117 */
119118
120 static sym
121 const iso_ir_209_syms[] = {
119 static sym const iso_ir_209_syms[] = {
122120 { 0x00a0, "nobreakspace" },
123121 { 0x010c, "Ccaron" },
124122 { 0x010d, "ccaron" },
217215 { 0x00ff, "ydiaeresis" },
218216 };
219217
220 static sym
221 const latin6_syms[] = {
218 static sym const latin6_syms[] = {
222219 { 0x00a0, "nobreakspace" },
223220 { 0x0104, "Aogonek" },
224221 { 0x0112, "Emacron" },
0 struct syn
1 const synonyms[] = {
2 { "Control_h", "BackSpace" },
3 { "Control_i", "Tab" },
4 { "Control_j", "Linefeed" },
5 { "Home", "Find" },
6 /* Unfortunately Delete already denotes ASCII 0177 */
7 /* { "Delete", "Remove" }, */
8 { "End", "Select" },
9 { "PageUp", "Prior" },
10 { "PageDown", "Next" },
11 { "multiplication", "multiply" },
12 { "pound", "sterling" },
13 { "pilcrow", "paragraph" },
14 { "Oslash", "Ooblique" },
15 { "Shift_L", "ShiftL" },
16 { "Shift_R", "ShiftR" },
17 { "Control_L", "CtrlL" },
18 { "Control_R", "CtrlR" },
19 { "AltL", "Alt" },
20 { "AltR", "AltGr" },
21 { "Alt_L", "Alt" },
22 { "Alt_R", "AltGr" },
23 { "AltGr_L", "Alt" },
24 { "AltGr_R", "AltGr" },
25 { "AltLLock", "Alt_Lock" },
26 { "AltRLock", "AltGr_Lock" },
27 { "SCtrl", "SControl" },
28 { "Spawn_Console", "KeyboardSignal" },
29 { "Uncaps_Shift", "CapsShift" },
30 /* the names of the Greek letters are spelled differently
0 struct syn const synonyms[] = {
1 { "Control_h", "BackSpace" },
2 { "Control_i", "Tab" },
3 { "Control_j", "Linefeed" },
4 { "Home", "Find" },
5 /* Unfortunately Delete already denotes ASCII 0177 */
6 /* { "Delete", "Remove" }, */
7 { "End", "Select" },
8 { "PageUp", "Prior" },
9 { "PageDown", "Next" },
10 { "multiplication", "multiply" },
11 { "pound", "sterling" },
12 { "pilcrow", "paragraph" },
13 { "Oslash", "Ooblique" },
14 { "Shift_L", "ShiftL" },
15 { "Shift_R", "ShiftR" },
16 { "Control_L", "CtrlL" },
17 { "Control_R", "CtrlR" },
18 { "AltL", "Alt" },
19 { "AltR", "AltGr" },
20 { "Alt_L", "Alt" },
21 { "Alt_R", "AltGr" },
22 { "AltGr_L", "Alt" },
23 { "AltGr_R", "AltGr" },
24 { "AltLLock", "Alt_Lock" },
25 { "AltRLock", "AltGr_Lock" },
26 { "SCtrl", "SControl" },
27 { "Spawn_Console", "KeyboardSignal" },
28 { "Uncaps_Shift", "CapsShift" },
29 /* the names of the Greek letters are spelled differently
3130 in the iso-8859-7 and the Unicode standards */
32 { "lambda", "lamda" },
33 { "Lambda", "Lamda" },
34 { "xi", "ksi" },
35 { "Xi", "Ksi" },
36 { "chi", "khi" },
37 { "Chi", "Khi" },
38 /* diacriticals */
39 { "tilde", "asciitilde" },
40 { "circumflex", "asciicircum" },
41 /* as dead_ogonek, dead_caron, dead_breve and dead_doubleacute do not exist
42 * (yet), I put also compose lines for use with respectively dead_cedilla,
43 * dead_circumflex, dead_tilde and dead_tilde */
44 { "dead_ogonek", "dead_cedilla" },
45 { "dead_caron", "dead_circumflex" },
46 { "dead_breve", "dead_tilde" },
47 { "dead_doubleacute", "dead_tilde" },
48 /* turkish */
49 { "Idotabove", "Iabovedot" },
50 { "dotlessi", "idotless" },
51 /* cyrillic */
52 { "no-break_space", "nobreakspace" },
53 { "paragraph_sign", "section" },
54 { "soft_hyphen", "hyphen" },
31 { "lambda", "lamda" },
32 { "Lambda", "Lamda" },
33 { "xi", "ksi" },
34 { "Xi", "Ksi" },
35 { "chi", "khi" },
36 { "Chi", "Khi" },
37 /* diacriticals */
38 { "tilde", "asciitilde" },
39 { "circumflex", "asciicircum" },
40 /* as dead_ogonek, dead_caron, dead_breve and dead_doubleacute do not exist
41 * (yet), I put also compose lines for use with respectively dead_cedilla,
42 * dead_circumflex, dead_tilde and dead_tilde
43 */
44 { "dead_ogonek", "dead_cedilla" },
45 { "dead_caron", "dead_circumflex" },
46 { "dead_breve", "dead_tilde" },
47 { "dead_doubleacute", "dead_tilde" },
48 /* turkish */
49 { "Idotabove", "Iabovedot" },
50 { "dotlessi", "idotless" },
51 /* cyrillic */
52 { "no-break_space", "nobreakspace" },
53 { "paragraph_sign", "section" },
54 { "soft_hyphen", "hyphen" },
5555 { "bielorussian_cyrillic_capital_letter_i", "ukrainian_cyrillic_capital_letter_i" },
5656 { "cyrillic_capital_letter_kha", "cyrillic_capital_letter_ha" },
5757 { "cyrillic_capital_letter_ge", "cyrillic_capital_letter_ghe" },
7272 { "cyrillic_small_letter_short_ii", "cyrillic_small_letter_short_i" },
7373 { "ukrainian_cyrillic_small_letter_ghe_with_upturn", "cyrillic_small_letter_ghe_with_upturn" },
7474 { "ukrainian_cyrillic_capital_letter_ghe_with_upturn", "cyrillic_capital_letter_ghe_with_upturn" },
75 /* iso-8859-7 */
76 { "rightanglequote", "guillemotright" }
75 /* iso-8859-7 */
76 { "rightanglequote", "guillemotright" }
7777 };
11 * Theppitak Karoonboonyanan <thep@linux.thai.net>
22 */
33
4 static sym
5 const tis_620_syms[] = {
6 { 0x00a0, "nobreakspace" },
7 { 0x0e01, "thai_kokai" },
8 { 0x0e02, "thai_khokhai" },
9 { 0x0e03, "thai_khokhuat" },
10 { 0x0e04, "thai_khokhwai" },
11 { 0x0e05, "thai_khokhon" },
12 { 0x0e06, "thai_khorakhang" },
13 { 0x0e07, "thai_ngongu" },
14 { 0x0e08, "thai_chochan" },
15 { 0x0e09, "thai_choching" },
16 { 0x0e0a, "thai_chochang" },
17 { 0x0e0b, "thai_soso" },
18 { 0x0e0c, "thai_chochoe" },
19 { 0x0e0d, "thai_yoying" },
20 { 0x0e0e, "thai_dochada" },
21 { 0x0e0f, "thai_topatak" },
22 { 0x0e10, "thai_thothan" },
23 { 0x0e11, "thai_thonangmontho" },
24 { 0x0e12, "thai_thophuthao" },
25 { 0x0e13, "thai_nonen" },
26 { 0x0e14, "thai_dodek" },
27 { 0x0e15, "thai_totao" },
28 { 0x0e16, "thai_thothung" },
29 { 0x0e17, "thai_thothahan" },
30 { 0x0e18, "thai_thothong" },
31 { 0x0e19, "thai_nonu" },
32 { 0x0e1a, "thai_bobaimai" },
33 { 0x0e1b, "thai_popla" },
34 { 0x0e1c, "thai_phophung" },
35 { 0x0e1d, "thai_fofa" },
36 { 0x0e1e, "thai_phophan" },
37 { 0x0e1f, "thai_fofan" },
38 { 0x0e20, "thai_phosamphao" },
39 { 0x0e21, "thai_moma" },
40 { 0x0e22, "thai_yoyak" },
41 { 0x0e23, "thai_rorua" },
42 { 0x0e24, "thai_ru" },
43 { 0x0e25, "thai_loling" },
44 { 0x0e26, "thai_lu" },
45 { 0x0e27, "thai_wowaen" },
46 { 0x0e28, "thai_sosala" },
47 { 0x0e29, "thai_sorusi" },
48 { 0x0e2a, "thai_sosua" },
49 { 0x0e2b, "thai_hohip" },
50 { 0x0e2c, "thai_lochula" },
51 { 0x0e2d, "thai_oang" },
52 { 0x0e2e, "thai_honokhuk" },
53 { 0x0e2f, "thai_paiyannoi" },
54 { 0x0e30, "thai_saraa" },
55 { 0x0e31, "thai_maihanakat" },
56 { 0x0e32, "thai_saraaa" },
57 { 0x0e33, "thai_saraam" },
58 { 0x0e34, "thai_sarai" },
59 { 0x0e35, "thai_saraii" },
60 { 0x0e36, "thai_saraue" },
61 { 0x0e37, "thai_sarauee" },
62 { 0x0e38, "thai_sarau" },
63 { 0x0e39, "thai_sarauu" },
64 { 0x0e3a, "thai_phinthu" },
65 { 0x0e3b, "" },
66 { 0x0e3c, "" },
67 { 0x0e3d, "" },
68 { 0x0e3e, "" },
69 { 0x0e3f, "thai_baht" },
70 { 0x0e40, "thai_sarae" },
71 { 0x0e41, "thai_saraae" },
72 { 0x0e42, "thai_sarao" },
73 { 0x0e43, "thai_saraaimaimuan" },
74 { 0x0e44, "thai_saraaimaimalai" },
75 { 0x0e45, "thai_lakkhangyao" },
76 { 0x0e46, "thai_maiyamok" },
77 { 0x0e47, "thai_maitaikhu" },
78 { 0x0e48, "thai_maiek" },
79 { 0x0e49, "thai_maitho" },
80 { 0x0e4a, "thai_maitri" },
81 { 0x0e4b, "thai_maichattawa" },
82 { 0x0e4c, "thai_thanthakhat" },
83 { 0x0e4d, "thai_nikhahit" },
84 { 0x0e4e, "thai_yamakkan" },
85 { 0x0e4f, "thai_fongman" },
86 { 0x0e50, "thai_leksun" },
87 { 0x0e51, "thai_leknung" },
88 { 0x0e52, "thai_leksong" },
89 { 0x0e53, "thai_leksam" },
90 { 0x0e54, "thai_leksi" },
91 { 0x0e55, "thai_lekha" },
92 { 0x0e56, "thai_lekhok" },
93 { 0x0e57, "thai_lekchet" },
94 { 0x0e58, "thai_lekpaet" },
95 { 0x0e59, "thai_lekkao" },
96 { 0x0e5a, "thai_angkhankhu" },
97 { 0x0e5b, "thai_khomut" },
98 { 0x0e5c, "" },
99 { 0x0e5d, "" },
100 { 0x0e5e, "" },
101 { 0x0e5f, "" },
4 static sym const tis_620_syms[] = {
5 { 0x00a0, "nobreakspace" },
6 { 0x0e01, "thai_kokai" },
7 { 0x0e02, "thai_khokhai" },
8 { 0x0e03, "thai_khokhuat" },
9 { 0x0e04, "thai_khokhwai" },
10 { 0x0e05, "thai_khokhon" },
11 { 0x0e06, "thai_khorakhang" },
12 { 0x0e07, "thai_ngongu" },
13 { 0x0e08, "thai_chochan" },
14 { 0x0e09, "thai_choching" },
15 { 0x0e0a, "thai_chochang" },
16 { 0x0e0b, "thai_soso" },
17 { 0x0e0c, "thai_chochoe" },
18 { 0x0e0d, "thai_yoying" },
19 { 0x0e0e, "thai_dochada" },
20 { 0x0e0f, "thai_topatak" },
21 { 0x0e10, "thai_thothan" },
22 { 0x0e11, "thai_thonangmontho" },
23 { 0x0e12, "thai_thophuthao" },
24 { 0x0e13, "thai_nonen" },
25 { 0x0e14, "thai_dodek" },
26 { 0x0e15, "thai_totao" },
27 { 0x0e16, "thai_thothung" },
28 { 0x0e17, "thai_thothahan" },
29 { 0x0e18, "thai_thothong" },
30 { 0x0e19, "thai_nonu" },
31 { 0x0e1a, "thai_bobaimai" },
32 { 0x0e1b, "thai_popla" },
33 { 0x0e1c, "thai_phophung" },
34 { 0x0e1d, "thai_fofa" },
35 { 0x0e1e, "thai_phophan" },
36 { 0x0e1f, "thai_fofan" },
37 { 0x0e20, "thai_phosamphao" },
38 { 0x0e21, "thai_moma" },
39 { 0x0e22, "thai_yoyak" },
40 { 0x0e23, "thai_rorua" },
41 { 0x0e24, "thai_ru" },
42 { 0x0e25, "thai_loling" },
43 { 0x0e26, "thai_lu" },
44 { 0x0e27, "thai_wowaen" },
45 { 0x0e28, "thai_sosala" },
46 { 0x0e29, "thai_sorusi" },
47 { 0x0e2a, "thai_sosua" },
48 { 0x0e2b, "thai_hohip" },
49 { 0x0e2c, "thai_lochula" },
50 { 0x0e2d, "thai_oang" },
51 { 0x0e2e, "thai_honokhuk" },
52 { 0x0e2f, "thai_paiyannoi" },
53 { 0x0e30, "thai_saraa" },
54 { 0x0e31, "thai_maihanakat" },
55 { 0x0e32, "thai_saraaa" },
56 { 0x0e33, "thai_saraam" },
57 { 0x0e34, "thai_sarai" },
58 { 0x0e35, "thai_saraii" },
59 { 0x0e36, "thai_saraue" },
60 { 0x0e37, "thai_sarauee" },
61 { 0x0e38, "thai_sarau" },
62 { 0x0e39, "thai_sarauu" },
63 { 0x0e3a, "thai_phinthu" },
64 { 0x0e3b, "" },
65 { 0x0e3c, "" },
66 { 0x0e3d, "" },
67 { 0x0e3e, "" },
68 { 0x0e3f, "thai_baht" },
69 { 0x0e40, "thai_sarae" },
70 { 0x0e41, "thai_saraae" },
71 { 0x0e42, "thai_sarao" },
72 { 0x0e43, "thai_saraaimaimuan" },
73 { 0x0e44, "thai_saraaimaimalai" },
74 { 0x0e45, "thai_lakkhangyao" },
75 { 0x0e46, "thai_maiyamok" },
76 { 0x0e47, "thai_maitaikhu" },
77 { 0x0e48, "thai_maiek" },
78 { 0x0e49, "thai_maitho" },
79 { 0x0e4a, "thai_maitri" },
80 { 0x0e4b, "thai_maichattawa" },
81 { 0x0e4c, "thai_thanthakhat" },
82 { 0x0e4d, "thai_nikhahit" },
83 { 0x0e4e, "thai_yamakkan" },
84 { 0x0e4f, "thai_fongman" },
85 { 0x0e50, "thai_leksun" },
86 { 0x0e51, "thai_leknung" },
87 { 0x0e52, "thai_leksong" },
88 { 0x0e53, "thai_leksam" },
89 { 0x0e54, "thai_leksi" },
90 { 0x0e55, "thai_lekha" },
91 { 0x0e56, "thai_lekhok" },
92 { 0x0e57, "thai_lekchet" },
93 { 0x0e58, "thai_lekpaet" },
94 { 0x0e59, "thai_lekkao" },
95 { 0x0e5a, "thai_angkhankhu" },
96 { 0x0e5b, "thai_khomut" },
97 { 0x0e5c, "" },
98 { 0x0e5d, "" },
99 { 0x0e5e, "" },
100 { 0x0e5f, "" },
102101 };
2424
2525 #include "keymap.h"
2626
27 static const char *progname = NULL;
27 static const char *progname = NULL;
2828 static const char *const dirpath1[] = { "", DATADIR "/" KEYMAPDIR "/**", KERNDIR "/", 0 };
2929 static const char *const suffixes[] = { "", ".kmap", ".map", 0 };
3030
31 static void __attribute__ ((noreturn))
31 static void __attribute__((noreturn))
3232 usage(void)
3333 {
3434 fprintf(stderr, _("loadkeys version %s\n"
35 "\n"
36 "Usage: %s [option...] [mapfile...]\n"
37 "\n"
38 "Valid options are:\n"
39 "\n"
40 " -a --ascii force conversion to ASCII\n"
41 " -b --bkeymap output a binary keymap to stdout\n"
42 " -c --clearcompose clear kernel compose table\n"
43 " -C --console=file\n"
44 " the console device to be used\n"
45 " -d --default load \"%s\"\n"
46 " -h --help display this help text\n"
47 " -m --mktable output a \"defkeymap.c\" to stdout\n"
48 " -p --parse search and parse keymap without action\n"
49 " -q --quiet suppress all normal output\n"
50 " -s --clearstrings clear kernel string table\n"
51 " -u --unicode force conversion to Unicode\n"
52 " -v --verbose report the changes\n"
53 " -V --version print version number\n"),
54 PACKAGE_VERSION, progname, DEFMAP);
35 "\n"
36 "Usage: %s [option...] [mapfile...]\n"
37 "\n"
38 "Valid options are:\n"
39 "\n"
40 " -a --ascii force conversion to ASCII\n"
41 " -b --bkeymap output a binary keymap to stdout\n"
42 " -c --clearcompose clear kernel compose table\n"
43 " -C --console=file\n"
44 " the console device to be used\n"
45 " -d --default load \"%s\"\n"
46 " -h --help display this help text\n"
47 " -m --mktable output a \"defkeymap.c\" to stdout\n"
48 " -p --parse search and parse keymap without action\n"
49 " -q --quiet suppress all normal output\n"
50 " -s --clearstrings clear kernel string table\n"
51 " -u --unicode force conversion to Unicode\n"
52 " -v --verbose report the changes\n"
53 " -V --version print version number\n"),
54 PACKAGE_VERSION, progname, DEFMAP);
5555 exit(EXIT_FAILURE);
5656 }
5757
6363 return (p && p + 1 ? p + 1 : name);
6464 }
6565
66 int
67 main(int argc, char *argv[])
66 int main(int argc, char *argv[])
6867 {
69 const char *const short_opts = "abcC:dhmpsuqvV";
68 const char *const short_opts = "abcC:dhmpsuqvV";
7069 const struct option const long_opts[] = {
71 { "console", required_argument, NULL, 'C'},
72 { "ascii", no_argument, NULL, 'a' },
73 { "bkeymap", no_argument, NULL, 'b' },
74 { "clearcompose", no_argument, NULL, 'c' },
75 { "default", no_argument, NULL, 'd' },
76 { "help", no_argument, NULL, 'h' },
77 { "mktable", no_argument, NULL, 'm' },
78 { "parse", no_argument, NULL, 'p' },
79 { "clearstrings", no_argument, NULL, 's' },
80 { "unicode", no_argument, NULL, 'u' },
81 { "quiet", no_argument, NULL, 'q' },
82 { "verbose", no_argument, NULL, 'v' },
83 { "version", no_argument, NULL, 'V' },
70 { "console", required_argument, NULL, 'C' },
71 { "ascii", no_argument, NULL, 'a' },
72 { "bkeymap", no_argument, NULL, 'b' },
73 { "clearcompose", no_argument, NULL, 'c' },
74 { "default", no_argument, NULL, 'd' },
75 { "help", no_argument, NULL, 'h' },
76 { "mktable", no_argument, NULL, 'm' },
77 { "parse", no_argument, NULL, 'p' },
78 { "clearstrings", no_argument, NULL, 's' },
79 { "unicode", no_argument, NULL, 'u' },
80 { "quiet", no_argument, NULL, 'q' },
81 { "verbose", no_argument, NULL, 'v' },
82 { "version", no_argument, NULL, 'V' },
8483 { NULL, 0, NULL, 0 }
8584 };
8685
121120
122121 while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
123122 switch (c) {
124 case 'a':
125 options |= OPT_A;
126 break;
127 case 'b':
128 options |= OPT_B;
129 break;
130 case 'c':
131 flags |= LK_FLAG_CLEAR_COMPOSE;
132 break;
133 case 'C':
134 console = optarg;
135 break;
136 case 'd':
137 options |= OPT_D;
138 break;
139 case 'm':
140 options |= OPT_M;
141 break;
142 case 'p':
143 options |= OPT_P;
144 break;
145 case 's':
146 flags |= LK_FLAG_CLEAR_STRINGS;
147 break;
148 case 'u':
149 options |= OPT_U;
150 flags |= LK_FLAG_UNICODE_MODE;
151 flags |= LK_FLAG_PREFER_UNICODE;
152 break;
153 case 'q':
154 lk_set_log_priority(ctx, LOG_ERR);
155 break;
156 case 'v':
157 lk_set_log_priority(ctx, LOG_INFO);
158 break;
159 case 'V':
160 fprintf(stdout, _("%s from %s\n"), progname, PACKAGE_STRING);
161 exit(0);
162 case 'h':
163 case '?':
164 usage();
123 case 'a':
124 options |= OPT_A;
125 break;
126 case 'b':
127 options |= OPT_B;
128 break;
129 case 'c':
130 flags |= LK_FLAG_CLEAR_COMPOSE;
131 break;
132 case 'C':
133 console = optarg;
134 break;
135 case 'd':
136 options |= OPT_D;
137 break;
138 case 'm':
139 options |= OPT_M;
140 break;
141 case 'p':
142 options |= OPT_P;
143 break;
144 case 's':
145 flags |= LK_FLAG_CLEAR_STRINGS;
146 break;
147 case 'u':
148 options |= OPT_U;
149 flags |= LK_FLAG_UNICODE_MODE;
150 flags |= LK_FLAG_PREFER_UNICODE;
151 break;
152 case 'q':
153 lk_set_log_priority(ctx, LOG_ERR);
154 break;
155 case 'v':
156 lk_set_log_priority(ctx, LOG_INFO);
157 break;
158 case 'V':
159 fprintf(stdout, _("%s from %s\n"), progname, PACKAGE_STRING);
160 exit(0);
161 case 'h':
162 case '?':
163 usage();
165164 }
166165 }
167166
168167 if ((options & OPT_U) && (options & OPT_A)) {
169168 fprintf(stderr,
170 _("%s: Options --unicode and --ascii are mutually exclusive\n"),
171 progname);
169 _("%s: Options --unicode and --ascii are mutually exclusive\n"),
170 progname);
172171 exit(EXIT_FAILURE);
173172 }
174173
181180 if (ioctl(fd, KDGKBMODE, &kbd_mode) ||
182181 ioctl(fd, KDGETMODE, &kd_mode)) {
183182 fprintf(stderr, _("%s: error reading keyboard mode: %m\n"),
184 progname);
183 progname);
185184 exit(EXIT_FAILURE);
186185 }
187186
188187 if (kbd_mode == K_UNICODE) {
189188 if (options & OPT_A) {
190189 fprintf(stderr,
191 _("%s: warning: loading non-Unicode keymap on Unicode console\n"
192 " (perhaps you want to do `kbd_mode -a'?)\n"),
193 progname);
190 _("%s: warning: loading non-Unicode keymap on Unicode console\n"
191 " (perhaps you want to do `kbd_mode -a'?)\n"),
192 progname);
194193 } else {
195194 flags |= LK_FLAG_PREFER_UNICODE;
196195 }
200199
201200 } else if (options & OPT_U && kd_mode != KD_GRAPHICS) {
202201 fprintf(stderr,
203 _("%s: warning: loading Unicode keymap on non-Unicode console\n"
204 " (perhaps you want to do `kbd_mode -u'?)\n"),
205 progname);
202 _("%s: warning: loading Unicode keymap on non-Unicode console\n"
203 " (perhaps you want to do `kbd_mode -u'?)\n"),
204 progname);
206205 }
207206 }
208207
211210 dirpath = dirpath1;
212211 if ((ev = getenv("LOADKEYS_KEYMAP_PATH")) != NULL) {
213212 dirpath2[0] = ev;
214 dirpath = dirpath2;
213 dirpath = dirpath2;
215214 }
216215
217216 if (options & OPT_D) {
224223
225224 if ((rc = lk_parse_keymap(ctx, &f)) == -1)
226225 goto fail;
227
228226
229227 } else if (optind == argc) {
230228 f.fd = stdin;
258256 }
259257 }
260258
261 fail: lk_free(ctx);
259 fail:
260 lk_free(ctx);
262261 lk_fpclose(&f);
263262 close(fd);
264263
2828 extern char *progname;
2929 extern int force;
3030
31 static const char *const unidirpath[] = { "", DATADIR "/" UNIMAPDIR "/", 0 };
31 static const char *const unidirpath[] = { "", DATADIR "/" UNIMAPDIR "/", 0 };
3232 static const char *const unisuffixes[] = { "", ".uni", ".sfm", 0 };
3333
3434 #ifdef MAIN
3535 #include "version.h"
3636 int verbose = 0;
37 int force = 0;
38 int debug = 0;
39
40 static void __attribute__ ((noreturn))
41 usage(void) {
42 fprintf(stderr,
43 _("Usage:\n\t%s [-C console] [-o map.orig]\n"), progname);
44 exit(1);
45 }
46
47 int
48 main(int argc, char *argv[]) {
37 int force = 0;
38 int debug = 0;
39
40 static void __attribute__((noreturn))
41 usage(void)
42 {
43 fprintf(stderr,
44 _("Usage:\n\t%s [-C console] [-o map.orig]\n"), progname);
45 exit(1);
46 }
47
48 int main(int argc, char *argv[])
49 {
4950 int fd, c;
5051 char *console = NULL;
5152 char *outfnam = NULL;
52 char *infnam = "def.uni";
53 char *infnam = "def.uni";
5354
5455 set_progname(argv[0]);
5556
6364
6465 while ((c = getopt(argc, argv, "C:o:")) != EOF) {
6566 switch (c) {
66 case 'C':
67 console = optarg;
68 break;
69 case 'o':
70 outfnam = optarg;
71 break;
72 default:
73 usage();
74 }
75 }
76
77 if (argc > optind+1 || (argc == optind && !outfnam))
67 case 'C':
68 console = optarg;
69 break;
70 case 'o':
71 outfnam = optarg;
72 break;
73 default:
74 usage();
75 }
76 }
77
78 if (argc > optind + 1 || (argc == optind && !outfnam))
7879 usage();
7980
8081 if ((fd = getfd(console)) < 0)
8687 exit(0);
8788 }
8889
89 if (argc == optind+1)
90 if (argc == optind + 1)
9091 infnam = argv[optind];
9192 loadunicodemap(fd, infnam);
9293 exit(0);
9697 /*
9798 * Skip spaces and read U+1234 or return -1 for error.
9899 * Return first non-read position in *p0 (unchanged on error).
99 */
100 */
100101 static int
101 getunicode(char **p0) {
102 getunicode(char **p0)
103 {
102104 char *p = *p0;
103105
104106 while (*p == ' ' || *p == '\t')
124126 if (*p != 'U' || p[1] != '+' || !isxdigit(p[2]) || !isxdigit(p[3]) ||
125127 !isxdigit(p[4]) || !isxdigit(p[5]) || isxdigit(p[6]))
126128 return -1;
127 *p0 = p+6;
128 return strtol(p+2,0,16);
129 *p0 = p + 6;
130 return strtol(p + 2, 0, 16);
129131 }
130132
131133 static struct unimapdesc descr;
132134
133135 static struct unipair *list = 0;
134 static int listsz = 0;
135 static int listct = 0;
136 static int listsz = 0;
137 static int listct = 0;
136138
137139 static void
138 addpair(int fp, int un) {
139 if (listct == listsz) {
140 listsz += 4096;
141 list = xrealloc((char *)list, listsz);
142 }
143 list[listct].fontpos = fp;
144 list[listct].unicode = un;
145 listct++;
140 addpair(int fp, int un)
141 {
142 if (listct == listsz) {
143 listsz += 4096;
144 list = xrealloc((char *)list, listsz);
145 }
146 list[listct].fontpos = fp;
147 list[listct].unicode = un;
148 listct++;
146149 }
147150
148151 /*
158161 */
159162
160163 static void
161 parseline(char *buffer, char *tblname) {
164 parseline(char *buffer, char *tblname)
165 {
162166 int fontlen = 512;
163167 int i;
164168 int fp0, fp1, un0, un1;
169173 while (*p == ' ' || *p == '\t')
170174 p++;
171175 if (!*p || *p == '#')
172 return; /* skip comment or blank line */
176 return; /* skip comment or blank line */
173177
174178 fp0 = strtol(p, &p1, 0);
175179 if (p1 == p) {
191195 } else
192196 fp1 = 0;
193197
194 if ( fp0 < 0 || fp0 >= fontlen ) {
198 if (fp0 < 0 || fp0 >= fontlen) {
195199 fprintf(stderr,
196 _("%s: Glyph number (0x%x) larger than font length\n"),
197 tblname, fp0);
200 _("%s: Glyph number (0x%x) larger than font length\n"),
201 tblname, fp0);
198202 exit(EX_DATAERR);
199203 }
200 if ( fp1 && (fp1 < fp0 || fp1 >= fontlen) ) {
204 if (fp1 && (fp1 < fp0 || fp1 >= fontlen)) {
201205 fprintf(stderr,
202 _("%s: Bad end of range (0x%x)\n"),
203 tblname, fp1);
206 _("%s: Bad end of range (0x%x)\n"),
207 tblname, fp1);
204208 exit(EX_DATAERR);
205209 }
206210
211215 p++;
212216 if (!strncmp(p, "idem", 4)) {
213217 p += 4;
214 for (i=fp0; i<=fp1; i++)
215 addpair(i,i);
218 for (i = fp0; i <= fp1; i++)
219 addpair(i, i);
216220 goto lookattail;
217221 }
218222
220224 while (*p == ' ' || *p == '\t')
221225 p++;
222226 if (*p != '-') {
223 for (i=fp0; i<=fp1; i++)
224 addpair(i,un0);
227 for (i = fp0; i <= fp1; i++)
228 addpair(i, un0);
225229 goto lookattail;
226230 }
227231
229233 un1 = getunicode(&p);
230234 if (un0 < 0 || un1 < 0) {
231235 fprintf(stderr,
232 _("%s: Bad Unicode range corresponding to "
233 "font position range 0x%x-0x%x\n"),
234 tblname, fp0, fp1);
236 _("%s: Bad Unicode range corresponding to "
237 "font position range 0x%x-0x%x\n"),
238 tblname, fp0, fp1);
235239 exit(EX_DATAERR);
236240 }
237241 if (un1 - un0 != fp1 - fp0) {
238242 fprintf(stderr,
239 _("%s: Unicode range U+%x-U+%x not of the same"
240 " length as font position range 0x%x-0x%x\n"),
241 tblname, un0, un1, fp0, fp1);
243 _("%s: Unicode range U+%x-U+%x not of the same"
244 " length as font position range 0x%x-0x%x\n"),
245 tblname, un0, un1, fp0, fp1);
242246 exit(EX_DATAERR);
243247 }
244 for(i=fp0; i<=fp1; i++)
245 addpair(i,un0-fp0+i);
248 for (i = fp0; i <= fp1; i++)
249 addpair(i, un0 - fp0 + i);
246250
247251 } else {
248252 /* no range; expect a list of unicode values
249253 for a single font position */
250254
251 while ( (un0 = getunicode(&p)) >= 0 )
255 while ((un0 = getunicode(&p)) >= 0)
252256 addpair(fp0, un0);
253257 }
254 lookattail:
258 lookattail:
255259 while (*p == ' ' || *p == '\t')
256260 p++;
257261 if (*p && *p != '#')
258262 fprintf(stderr, _("%s: trailing junk (%s) ignored\n"),
259 tblname, p);
260 }
261
262 void
263 loadunicodemap(int fd, char *tblname) {
263 tblname, p);
264 }
265
266 void loadunicodemap(int fd, char *tblname)
267 {
264268 char buffer[65536];
265269 char *p;
266270 lkfile_t fp;
273277 if (verbose)
274278 printf(_("Loading unicode map from file %s\n"), fp.pathname);
275279
276 while ( fgets(buffer, sizeof(buffer), fp.fd) != NULL ) {
277 if ( (p = strchr(buffer, '\n')) != NULL )
280 while (fgets(buffer, sizeof(buffer), fp.fd) != NULL) {
281 if ((p = strchr(buffer, '\n')) != NULL)
278282 *p = '\0';
279283 else
280284 fprintf(stderr, _("%s: %s: Warning: line too long\n"),
281 progname, tblname);
285 progname, tblname);
282286
283287 parseline(buffer, tblname);
284288 }
287291
288292 if (listct == 0 && !force) {
289293 fprintf(stderr,
290 _("%s: not loading empty unimap\n"
291 "(if you insist: use option -f to override)\n"),
292 progname);
294 _("%s: not loading empty unimap\n"
295 "(if you insist: use option -f to override)\n"),
296 progname);
293297 } else {
294298 descr.entry_ct = listct;
295 descr.entries = list;
296 if (loadunimap (fd, NULL, &descr))
299 descr.entries = list;
300 if (loadunimap(fd, NULL, &descr))
297301 exit(1);
298302 listct = 0;
299303 }
300304 }
301305
302306 static struct unimapdesc
303 getunicodemap(int fd) {
304 struct unimapdesc unimap_descr;
305
306 if (getunimap(fd, &unimap_descr))
307 exit(1);
307 getunicodemap(int fd)
308 {
309 struct unimapdesc unimap_descr;
310
311 if (getunimap(fd, &unimap_descr))
312 exit(1);
308313
309314 #ifdef MAIN
310 fprintf(stderr, "# %d %s\n", unimap_descr.entry_ct,
311 (unimap_descr.entry_ct == 1) ? _("entry") : _("entries"));
315 fprintf(stderr, "# %d %s\n", unimap_descr.entry_ct,
316 (unimap_descr.entry_ct == 1) ? _("entry") : _("entries"));
312317 #endif
313318
314 return unimap_descr;
315 }
316
317 void
318 saveunicodemap(int fd, char *oufil) {
319 FILE *fpo;
320 struct unimapdesc unimap_descr;
321 struct unipair *unilist;
322 int i;
323
324 if ((fpo = fopen(oufil, "w")) == NULL) {
325 perror(oufil);
326 exit(1);
327 }
328
329 unimap_descr = getunicodemap(fd);
330 unilist = unimap_descr.entries;
331
332 for(i=0; i<unimap_descr.entry_ct; i++)
333 fprintf(fpo, "0x%02x\tU+%04x\n", unilist[i].fontpos, unilist[i].unicode);
334 fclose(fpo);
335
336 if (verbose)
337 printf(_("Saved unicode map on `%s'\n"), oufil);
338 }
339
340 void
341 appendunicodemap(int fd, FILE *fp, int fontsize, int utf8) {
319 return unimap_descr;
320 }
321
322 void saveunicodemap(int fd, char *oufil)
323 {
324 FILE *fpo;
325 struct unimapdesc unimap_descr;
326 struct unipair *unilist;
327 int i;
328
329 if ((fpo = fopen(oufil, "w")) == NULL) {
330 perror(oufil);
331 exit(1);
332 }
333
334 unimap_descr = getunicodemap(fd);
335 unilist = unimap_descr.entries;
336
337 for (i = 0; i < unimap_descr.entry_ct; i++)
338 fprintf(fpo, "0x%02x\tU+%04x\n", unilist[i].fontpos, unilist[i].unicode);
339 fclose(fpo);
340
341 if (verbose)
342 printf(_("Saved unicode map on `%s'\n"), oufil);
343 }
344
345 void appendunicodemap(int fd, FILE *fp, int fontsize, int utf8)
346 {
342347 struct unimapdesc unimap_descr;
343348 struct unipair *unilist;
344349 int i, j;
345350
346351 unimap_descr = getunicodemap(fd);
347 unilist = unimap_descr.entries;
348
349
350 for(i=0; i<fontsize; i++) {
352 unilist = unimap_descr.entries;
353
354 for (i = 0; i < fontsize; i++) {
351355 #if 0
352356 /* More than one mapping is not a sequence! */
353357 int no = 0;
356360 no++;
357361 if (no > 1)
358362 appendseparator(fp, 1, utf8);
359 #endif
360 if (debug) printf ("\nchar %03x: ", i);
361 for(j=0; j<unimap_descr.entry_ct; j++)
363 #endif
364 if (debug)
365 printf("\nchar %03x: ", i);
366 for (j = 0; j < unimap_descr.entry_ct; j++)
362367 if (unilist[j].fontpos == i) {
363368 if (debug)
364 printf ("%04x ", unilist[j].unicode);
369 printf("%04x ", unilist[j].unicode);
365370 appendunicode(fp, unilist[j].unicode, utf8);
366371 }
367372 appendseparator(fp, 0, utf8);
368373 }
369374
370
371 if (debug) printf ("\n");
375 if (debug)
376 printf("\n");
372377 if (verbose)
373378 printf(_("Appended Unicode map\n"));
374379 }
22 #ifndef _LOADUNIMAP_H
33 #define _LOADUNIMAP_H
44
5 void saveunicodemap(int fd, char *oufil); /* save humanly readable */
5 void saveunicodemap(int fd, char *oufil); /* save humanly readable */
66 void loadunicodemap(int fd, char *ufil);
77 void appendunicodemap(int fd, FILE *fp, int ct, int utf8);
88
9 #endif /* _LOADUNIMAP_H */
9 #endif /* _LOADUNIMAP_H */
2222 void saveoldmap(int fd, char *omfil);
2323 void loadnewmap(int fd, char *mfil);
2424
25 static int ctoi (char *);
25 static int ctoi(char *);
2626
2727 /* search for the map file in these directories (with trailing /) */
28 static const char *const mapdirpath[] = { "", DATADIR "/" TRANSDIR "/", 0 };
28 static const char *const mapdirpath[] = { "", DATADIR "/" TRANSDIR "/", 0 };
2929 static const char *const mapsuffixes[] = { "", ".trans", "_to_uni.trans", ".acm", 0 };
3030
3131 #ifdef MAIN
3333 #include "version.h"
3434
3535 int verbose = 0;
36 int debug = 0;
37
38 int
39 main(int argc, char *argv[]) {
36 int debug = 0;
37
38 int main(int argc, char *argv[])
39 {
4040 int fd;
4141
4242 set_progname(argv[0]);
4646 textdomain(PACKAGE_NAME);
4747
4848 if (argc == 2 && !strcmp(argv[1], "-V"))
49 print_version_and_exit();
49 print_version_and_exit();
5050
5151 if (argc > 1 && !strcmp(argv[1], "-v")) {
5252 verbose = 1;
5858 kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
5959
6060 if (argc >= 3 && !strcmp(argv[1], "-o")) {
61 saveoldmap(fd, argv[2]);
62 argc -= 2;
63 argv += 2;
64 if (argc == 1)
65 exit(EXIT_SUCCESS);
66 }
67
61 saveoldmap(fd, argv[2]);
62 argc -= 2;
63 argv += 2;
64 if (argc == 1)
65 exit(EXIT_SUCCESS);
66 }
67
6868 if (argc != 2) {
6969 fprintf(stderr, _("usage: %s [-V] [-v] [-o map.orig] map-file\n"),
70 progname);
70 progname);
7171 exit(EXIT_FAILURE);
7272 }
7373 loadnewmap(fd, argv[1]);
8989 * Set lineno to line number of first error.
9090 */
9191 static int
92 parsemap(FILE *fp, char *buf, unsigned short *ubuf, int *u, int *lineno) {
92 parsemap(FILE *fp, char *buf, unsigned short *ubuf, int *u, int *lineno)
93 {
9394 char buffer[256];
9495 int in, on, ln, ret = 0;
9596 char *p, *q;
9697
9798 ln = 0;
98 while (fgets(buffer,sizeof(buffer)-1,fp)) {
99 while (fgets(buffer, sizeof(buffer) - 1, fp)) {
99100 ln++;
100101 if (!*u && strstr(buffer, "U+"))
101102 *u = 1;
102 p = strtok(buffer," \t\n");
103 p = strtok(buffer, " \t\n");
103104 if (p && *p != '#') {
104 q = strtok(NULL," \t\n#");
105 q = strtok(NULL, " \t\n#");
105106 if (q) {
106107 in = ctoi(p);
107108 on = ctoi(q);
115116 } else {
116117 if (!ret)
117118 *lineno = ln;
118 ret = -1;
119 ret = -1;
119120 }
120121 }
121122 }
124125 }
125126
126127 static int
127 readnewmapfromfile(char *mfil, char *buf, unsigned short *ubuf) {
128 readnewmapfromfile(char *mfil, char *buf, unsigned short *ubuf)
129 {
128130 struct stat stbuf;
129 int u = 0;
131 int u = 0;
130132 int lineno = 0;
131133 lkfile_t fp;
132134
133135 if (lk_findfile(mfil, mapdirpath, mapsuffixes, &fp)) {
134 fprintf(stderr, _("mapscrn: cannot open map file _%s_\n"),
135 mfil);
136 fprintf(stderr, _("mapscrn: cannot open map file _%s_\n"),
137 mfil);
136138 exit(1);
137139 }
138140 if (stat(fp.pathname, &stbuf)) {
143145 if (stbuf.st_size == E_TABSZ) {
144146 if (verbose)
145147 printf(_("Loading binary direct-to-font screen map "
146 "from file %s\n"),
148 "from file %s\n"),
147149 fp.pathname);
148 if (fread(buf,E_TABSZ,1,fp.fd) != 1) {
150 if (fread(buf, E_TABSZ, 1, fp.fd) != 1) {
149151 fprintf(stderr,
150 _("Error reading map from file `%s'\n"),
151 fp.pathname);
152 exit(1);
153 }
154 } else if (stbuf.st_size == 2*E_TABSZ) {
152 _("Error reading map from file `%s'\n"),
153 fp.pathname);
154 exit(1);
155 }
156 } else if (stbuf.st_size == 2 * E_TABSZ) {
155157 if (verbose)
156158 printf(_("Loading binary unicode screen map "
157 "from file %s\n"),
159 "from file %s\n"),
158160 fp.pathname);
159 if (fread(ubuf,2*E_TABSZ,1,fp.fd) != 1) {
161 if (fread(ubuf, 2 * E_TABSZ, 1, fp.fd) != 1) {
160162 fprintf(stderr,
161 _("Error reading map from file `%s'\n"),
162 fp.pathname);
163 _("Error reading map from file `%s'\n"),
164 fp.pathname);
163165 exit(1);
164166 }
165167 u = 1;
166 } else {
168 } else {
167169 if (verbose)
168170 printf(_("Loading symbolic screen map from file %s\n"),
169171 fp.pathname);
170 if (parsemap(fp.fd,buf,ubuf,&u,&lineno)) {
172 if (parsemap(fp.fd, buf, ubuf, &u, &lineno)) {
171173 fprintf(stderr,
172 _("Error parsing symbolic map "
173 "from `%s', line %d\n"),
174 fp.pathname, lineno);
174 _("Error parsing symbolic map "
175 "from `%s', line %d\n"),
176 fp.pathname, lineno);
175177 exit(1);
176178 }
177179 }
179181 return u;
180182 }
181183
182 void
183 loadnewmap(int fd, char *mfil) {
184 void loadnewmap(int fd, char *mfil)
185 {
184186 unsigned short ubuf[E_TABSZ];
185187 char buf[E_TABSZ];
186188 int i, u;
187189
188190 /* default: trivial straight-to-font */
189 for (i=0; i<E_TABSZ; i++) {
190 buf[i] = i;
191 for (i = 0; i < E_TABSZ; i++) {
192 buf[i] = i;
191193 ubuf[i] = (0xf000 + i);
192194 }
193195
202204 exit(1);
203205 } else {
204206 /* no */
205 if (loadscrnmap(fd,buf))
207 if (loadscrnmap(fd, buf))
206208 exit(1);
207209 }
208210 }
211213 * Read decimal, octal, hexadecimal, Unicode (U+xxxx) or character
212214 * ('x', x a single byte or a utf8 sequence).
213215 */
214 int
215 ctoi(char *s) {
216 int ctoi(char *s)
217 {
216218 int i;
217219
218 if ((strncmp(s,"0x",2) == 0) &&
219 (strspn(s+2,"0123456789abcdefABCDEF") == strlen(s+2)))
220 (void)sscanf(s+2,"%x",&i);
220 if ((strncmp(s, "0x", 2) == 0) &&
221 (strspn(s + 2, "0123456789abcdefABCDEF") == strlen(s + 2)))
222 (void)sscanf(s + 2, "%x", &i);
221223
222224 else if ((*s == '0') &&
223 (strspn(s,"01234567") == strlen(s)))
224 (void)sscanf(s,"%o",&i);
225
226 else if (strspn(s,"0123456789") == strlen(s))
227 (void)sscanf(s,"%d",&i);
228
229 else if ((strncmp(s,"U+",2) == 0) && strlen(s) == 6 &&
230 (strspn(s+2,"0123456789abcdefABCDEF") == 4))
231 (void)sscanf(s+2,"%x",&i);
225 (strspn(s, "01234567") == strlen(s)))
226 (void)sscanf(s, "%o", &i);
227
228 else if (strspn(s, "0123456789") == strlen(s))
229 (void)sscanf(s, "%d", &i);
230
231 else if ((strncmp(s, "U+", 2) == 0) && strlen(s) == 6 &&
232 (strspn(s + 2, "0123456789abcdefABCDEF") == 4))
233 (void)sscanf(s + 2, "%x", &i);
232234
233235 else if ((strlen(s) == 3) && (s[0] == '\'') && (s[2] == '\''))
234 i=s[1];
236 i = s[1];
235237
236238 else if (s[0] == '\'') {
237239 int err;
238 char *s1 = s+1;
240 char *s1 = s + 1;
239241
240242 i = from_utf8(&s1, 0, &err);
241243 if (err || s1[0] != '\'' || s1[1] != 0)
242244 return -1;
243245 }
244246
245 else return -1;
247 else
248 return -1;
246249
247250 return i;
248251 }
249252
250 void
251 saveoldmap(int fd, char *omfil) {
253 void saveoldmap(int fd, char *omfil)
254 {
252255 FILE *fp;
253256 char buf[E_TABSZ];
254257 unsigned short ubuf[E_TABSZ];
259262 exit(1);
260263 }
261264 havemap = haveumap = 1;
262 if (getscrnmap(fd,buf))
265 if (getscrnmap(fd, buf))
263266 havemap = 0;
264 if (getuniscrnmap(fd,ubuf))
267 if (getuniscrnmap(fd, ubuf))
265268 haveumap = 0;
266269 if (havemap && haveumap) {
267270 for (i = 0; i < E_TABSZ; i++) {
272275 }
273276 }
274277 if (havemap) {
275 if (fwrite(buf,sizeof(buf),1,fp) != 1) {
278 if (fwrite(buf, sizeof(buf), 1, fp) != 1) {
276279 fprintf(stderr, _("Error writing map to file\n"));
277280 exit(1);
278281 }
279282 } else if (haveumap) {
280 if (fwrite(ubuf,sizeof(ubuf),1,fp) != 1) {
283 if (fwrite(ubuf, sizeof(ubuf), 1, fp) != 1) {
281284 fprintf(stderr, _("Error writing map to file\n"));
282285 exit(1);
283286 }
22 #endif
33
44 #ifdef HAVE_LOCALE_H
5 # include <locale.h>
5 #include <locale.h>
66 #endif
77
88 #ifdef ENABLE_NLS
9 # include <libintl.h>
10 # define _(Text) gettext (Text)
11 # ifdef gettext_noop
12 # define N_(String) gettext_noop (String)
13 # else
14 # define N_(String) (String)
15 # endif
16 # define P_(singular, plural, number) ngettext(singular, plural, number)
9 #include <libintl.h>
10 #define _(Text) gettext(Text)
11 #ifdef gettext_noop
12 #define N_(String) gettext_noop(String)
1713 #else
18 # undef bindtextdomain
19 # define bindtextdomain(Domain, Directory) /* empty */
20 # undef textdomain
21 # define textdomain(Domain) /* empty */
22 # define _(Text) (Text)
23 # define N_(Text) (Text)
24 # define P_(singular, plural, number) (number == 1 ? singular : plural)
14 #define N_(String) (String)
2515 #endif
16 #define P_(singular, plural, number) ngettext(singular, plural, number)
17 #else
18 #undef bindtextdomain
19 #define bindtextdomain(Domain, Directory) /* empty */
20 #undef textdomain
21 #define textdomain(Domain) /* empty */
22 #define _(Text) (Text)
23 #define N_(Text) (Text)
24 #define P_(singular, plural, number) (number == 1 ? singular : plural)
25 #endif
2828 #define FALSE (0)
2929
3030 #ifdef ESIX_5_3_2_D
31 #define VTBASE "/dev/vt%02d"
31 #define VTBASE "/dev/vt%02d"
3232 #endif
3333
3434 // Where your VTs are hidden
4242 #endif
4343
4444 static void
45 __attribute__ ((noreturn))
46 print_help(int ret)
45 __attribute__((noreturn))
46 print_help(int ret)
4747 {
4848 printf(_("Usage: %s [OPTIONS] -- command\n"
49 "\n"
50 "This utility help you to start a program on a new virtual terminal (VT).\n"
51 "\n"
52 "Options:\n"
53 " -c, --console=NUM use the given VT number;\n"
54 " -e, --exec execute the command, without forking;\n"
55 " -f, --force force opening a VT without checking;\n"
56 " -l, --login make the command a login shell;\n"
57 " -u, --user figure out the owner of the current VT;\n"
58 " -s, --switch switch to the new VT;\n"
59 " -w, --wait wait for command to complete;\n"
60 " -v, --verbose print a message for each action;\n"
61 " -V, --version print program version and exit;\n"
62 " -h, --help output a brief help message.\n"
63 "\n"), progname);
49 "\n"
50 "This utility help you to start a program on a new virtual terminal (VT).\n"
51 "\n"
52 "Options:\n"
53 " -c, --console=NUM use the given VT number;\n"
54 " -e, --exec execute the command, without forking;\n"
55 " -f, --force force opening a VT without checking;\n"
56 " -l, --login make the command a login shell;\n"
57 " -u, --user figure out the owner of the current VT;\n"
58 " -s, --switch switch to the new VT;\n"
59 " -w, --wait wait for command to complete;\n"
60 " -v, --verbose print a message for each action;\n"
61 " -V, --version print program version and exit;\n"
62 " -h, --help output a brief help message.\n"
63 "\n"),
64 progname);
6465 exit(ret);
6566 }
6667
138139
139140 kbd_error(EXIT_FAILURE, 0, _("Couldn't find owner of current tty!"));
140141
141 got_a_process:
142 got_a_process:
142143 closedir(dp);
143144
144145 return pwnam->pw_name;
160161 return fd;
161162 }
162163
163 int
164 main(int argc, char *argv[])
164 int main(int argc, char *argv[])
165165 {
166166 int opt, pid, i;
167167 struct vt_stat vtstat;
168 int vtno = -1;
169 int fd = -1;
170 int consfd = -1;
171 int force = 0;
172 char optc = FALSE;
173 char show = FALSE;
174 char login = FALSE;
175 char verbose = FALSE;
168 int vtno = -1;
169 int fd = -1;
170 int consfd = -1;
171 int force = 0;
172 char optc = FALSE;
173 char show = FALSE;
174 char login = FALSE;
175 char verbose = FALSE;
176176 char direct_exec = FALSE;
177 char do_wait = FALSE;
178 char as_user = FALSE;
177 char do_wait = FALSE;
178 char as_user = FALSE;
179179 char vtname[sizeof(VTNAME) + 2]; /* allow 999 possible VTs */
180180 char *cmd = NULL, *def_cmd = NULL, *username = NULL;
181181
182182 struct option long_options[] = {
183 { "help", no_argument, 0, 'h' },
184 { "version", no_argument, 0, 'V' },
185 { "verbose", no_argument, 0, 'v' },
186 { "exec", no_argument, 0, 'e' },
187 { "force", no_argument, 0, 'f' },
188 { "login", no_argument, 0, 'l' },
189 { "user", no_argument, 0, 'u' },
190 { "switch", no_argument, 0, 's' },
191 { "wait", no_argument, 0, 'w' },
192 { "console", required_argument, 0, 'c' },
183 { "help", no_argument, 0, 'h' },
184 { "version", no_argument, 0, 'V' },
185 { "verbose", no_argument, 0, 'v' },
186 { "exec", no_argument, 0, 'e' },
187 { "force", no_argument, 0, 'f' },
188 { "login", no_argument, 0, 'l' },
189 { "user", no_argument, 0, 'u' },
190 { "switch", no_argument, 0, 's' },
191 { "wait", no_argument, 0, 'w' },
192 { "console", required_argument, 0, 'c' },
193193 { 0, 0, 0, 0 }
194194 };
195195
202202 while ((opt = getopt_long(argc, argv, "c:lsfuewhvV", long_options, NULL)) != -1) {
203203 switch (opt) {
204204 case 'c':
205 optc = 1; /* vtno was specified by the user */
205 optc = 1; /* vtno was specified by the user */
206206 vtno = (int)atol(optarg);
207207
208208 if (vtno <= 0 || vtno > 63)
266266 } else if (!force) {
267267 if (vtno >= 16)
268268 kbd_error(7, 0, _("Cannot check whether vt %d is free; use `%s -f' to force."),
269 vtno, progname);
269 vtno, progname);
270270
271271 if (vtstat.v_state & (1 << vtno))
272272 kbd_error(7, 0, _("vt %d is in use; command aborted; use `%s -f' to force."),
273 vtno, progname);
273 vtno, progname);
274274 }
275275
276276 if (as_user)
302302 if (direct_exec || ((pid = fork()) == 0)) {
303303 /* leave current vt */
304304 if (!direct_exec) {
305 #ifdef ESIX_5_3_2_D
305 #ifdef ESIX_5_3_2_D
306306 #ifdef HAVE_SETPGRP
307307 if (setpgrp() < 0)
308308 #else
309309 if (1)
310 #endif /* HAVE_SETPGRP */
310 #endif /* HAVE_SETPGRP */
311311 #else
312312 if (setsid() < 0)
313 #endif /* ESIX_5_3_2_D */
313 #endif /* ESIX_5_3_2_D */
314314 kbd_error(5, errno, _("Unable to set new session"));
315315 }
316316
337337 }
338338 kbd_error(5, errsv, _("Unable to open %s"), vtname);
339339 }
340 got_vtno:
340 got_vtno:
341341 if (verbose)
342342 kbd_warning(0, _("Using VT %s"), vtname);
343343
390390 wait(NULL);
391391 waitpid(pid, &retval, 0);
392392
393 if (show) { /* Switch back... */
393 if (show) { /* Switch back... */
394394 if (ioctl(consfd, VT_ACTIVATE, vtstat.v_active))
395395 kbd_error(8, errno, "ioctl(VT_ACTIVATE)");
396396
404404
405405 /* if all our stuff went right, we want to return the exit code of the command we ran
406406 super vital for scripting loops etc */
407 return(retval);
407 return (retval);
408408 }
409409
410410 return EXIT_SUCCESS;
22 #include "config.h"
33
44 #include <stdio.h>
5 #include <stdlib.h> /* exit */
5 #include <stdlib.h> /* exit */
66 #include "kbd.h"
77 #include "psf.h"
88
9 static void __attribute__ ((noreturn))
10 usage(void) {
9 static void __attribute__((noreturn))
10 usage(void)
11 {
1112 fprintf(stderr, "call: outpsfheader psftype fontsize charsize hastable\n");
1213 exit(1);
1314 }
1415
15 int
16 main(int argc, char **argv){
16 int main(int argc, char **argv)
17 {
1718 int psftype, fontsize, charsize, hastable;
1819
1920 if (argc != 5)
2021 usage();
21 psftype = atoi(argv[1]);
22 psftype = atoi(argv[1]);
2223 fontsize = atoi(argv[2]);
2324 charsize = atoi(argv[3]);
2425 hastable = atoi(argv[4]);
3031 usage();
3132 h1.magic[0] = PSF1_MAGIC0;
3233 h1.magic[1] = PSF1_MAGIC1;
33 h1.mode = (fontsize == 256) ? 0 : PSF1_MODE512;
34 h1.mode = (fontsize == 256) ? 0 : PSF1_MODE512;
3435 if (hastable)
3536 h1.mode |= PSF1_MODEHASTAB;
3637 h1.charsize = charsize;
4142 } else if (psftype == 2) {
4243 struct psf2_header h2;
4344
44 h2.magic[0] = PSF2_MAGIC0;
45 h2.magic[1] = PSF2_MAGIC1;
46 h2.magic[2] = PSF2_MAGIC2;
47 h2.magic[3] = PSF2_MAGIC3;
48 h2.version = 0;
45 h2.magic[0] = PSF2_MAGIC0;
46 h2.magic[1] = PSF2_MAGIC1;
47 h2.magic[2] = PSF2_MAGIC2;
48 h2.magic[3] = PSF2_MAGIC3;
49 h2.version = 0;
4950 h2.headersize = sizeof(h2);
50 h2.flags = (hastable ? PSF2_HAS_UNICODE_TABLE : 0);
51 h2.length = fontsize;
52 h2.charsize = charsize;
53 h2.width = 8;
54 h2.height = charsize;
51 h2.flags = (hastable ? PSF2_HAS_UNICODE_TABLE : 0);
52 h2.length = fontsize;
53 h2.charsize = charsize;
54 h2.width = 8;
55 h2.height = charsize;
5556 if (fwrite(&h2, sizeof(h2), 1, stdout) != 1) {
5657 fprintf(stderr, "write error\n");
5758 exit(1);
1717 * Default keymap, and where the kernel copy of it lives.
1818 */
1919 #ifdef __sparc__
20 # define DEFMAP "sunkeymap.map"
21 # define KERNDIR "/usr/src/linux/drivers/sbus/char"
20 #define DEFMAP "sunkeymap.map"
21 #define KERNDIR "/usr/src/linux/drivers/sbus/char"
2222 #else
23 # define DEFMAP "defkeymap.map"
24 # define KERNDIR "/usr/src/linux/drivers/tty/vt"
23 #define DEFMAP "defkeymap.map"
24 #define KERNDIR "/usr/src/linux/drivers/tty/vt"
2525 #endif
2626
2727 extern int verbose;
3434 #ifndef _PSF_H
3535 #define _PSF_H
3636
37 #define PSF1_MAGIC0 0x36
38 #define PSF1_MAGIC1 0x04
3739
38 #define PSF1_MAGIC0 0x36
39 #define PSF1_MAGIC1 0x04
40
41 #define PSF1_MODE512 0x01
40 #define PSF1_MODE512 0x01
4241 #define PSF1_MODEHASTAB 0x02
4342 #define PSF1_MODEHASSEQ 0x04
44 #define PSF1_MAXMODE 0x05
43 #define PSF1_MAXMODE 0x05
4544
46 #define PSF1_SEPARATOR 0xFFFF
47 #define PSF1_STARTSEQ 0xFFFE
45 #define PSF1_SEPARATOR 0xFFFF
46 #define PSF1_STARTSEQ 0xFFFE
4847
4948 struct psf1_header {
50 unsigned char magic[2]; /* Magic number */
51 unsigned char mode; /* PSF font mode */
52 unsigned char charsize; /* Character size */
49 unsigned char magic[2]; /* Magic number */
50 unsigned char mode; /* PSF font mode */
51 unsigned char charsize; /* Character size */
5352 };
5453
5554 /*
6463 * The integers here are little endian 4-byte integers.
6564 */
6665
67 #define PSF2_MAGIC0 0x72
68 #define PSF2_MAGIC1 0xb5
69 #define PSF2_MAGIC2 0x4a
70 #define PSF2_MAGIC3 0x86
66 #define PSF2_MAGIC0 0x72
67 #define PSF2_MAGIC1 0xb5
68 #define PSF2_MAGIC2 0x4a
69 #define PSF2_MAGIC3 0x86
7170
7271 struct psf2_header {
7372 unsigned char magic[4];
7473 unsigned int version;
75 unsigned int headersize; /* offset of bitmaps in file */
74 unsigned int headersize; /* offset of bitmaps in file */
7675 unsigned int flags;
77 unsigned int length; /* number of glyphs */
78 unsigned int charsize; /* number of bytes for each character */
76 unsigned int length; /* number of glyphs */
77 unsigned int charsize; /* number of bytes for each character */
7978 unsigned int height, width; /* max dimensions of glyphs */
80 /* charsize = height * ((width + 7) / 8) */
79 /* charsize = height * ((width + 7) / 8) */
8180 };
8281
8382 /* bits used in flags */
8483 #define PSF2_HAS_UNICODE_TABLE 0x01
8584
8685 /* max version recognized so far */
87 #define PSF2_MAXVERSION 0
86 #define PSF2_MAXVERSION 0
8887
8988 /* UTF8 separators */
90 #define PSF2_SEPARATOR 0xFF
91 #define PSF2_STARTSEQ 0xFE
89 #define PSF2_SEPARATOR 0xFF
90 #define PSF2_STARTSEQ 0xFE
9291
92 #define PSF1_MAGIC_OK(x) ((x)[0] == PSF1_MAGIC0 && (x)[1] == PSF1_MAGIC1)
93 #define PSF2_MAGIC_OK(x) ((x)[0] == PSF2_MAGIC0 && (x)[1] == PSF2_MAGIC1 && (x)[2] == PSF2_MAGIC2 && (x)[3] == PSF2_MAGIC3)
9394
94 #define PSF1_MAGIC_OK(x) ((x)[0]==PSF1_MAGIC0 && (x)[1]==PSF1_MAGIC1)
95 #define PSF2_MAGIC_OK(x) ((x)[0]==PSF2_MAGIC0 && (x)[1]==PSF2_MAGIC1 \
96 && (x)[2]==PSF2_MAGIC2 && (x)[3]==PSF2_MAGIC3)
97
98
99 #endif /* _PSF_H */
95 #endif /* _PSF_H */
1616 extern char *progname;
1717
1818 static void
19 addpair(struct unicode_list *up, unsigned int uc) {
19 addpair(struct unicode_list *up, unsigned int uc)
20 {
2021 struct unicode_list *ul;
2122 struct unicode_seq *us;
2223
23 ul = xmalloc(sizeof(struct unicode_list));
24 us = xmalloc(sizeof(struct unicode_seq));
25 us->uc = uc;
26 us->prev = us;
27 us->next = NULL;
28 ul->seq = us;
29 ul->prev = up->prev;
24 ul = xmalloc(sizeof(struct unicode_list));
25 us = xmalloc(sizeof(struct unicode_seq));
26 us->uc = uc;
27 us->prev = us;
28 us->next = NULL;
29 ul->seq = us;
30 ul->prev = up->prev;
3031 ul->prev->next = ul;
31 ul->next = NULL;
32 up->prev = ul;
32 ul->next = NULL;
33 up->prev = ul;
3334 }
3435
3536 static void
36 addseq(struct unicode_list *up, unsigned int uc) {
37 addseq(struct unicode_list *up, unsigned int uc)
38 {
3739 struct unicode_seq *us;
3840 struct unicode_seq *usl;
3941 struct unicode_list *ul = up->prev;
4042
4143 usl = ul->seq;
42 while (usl->next) usl = usl->next;
43 us = xmalloc(sizeof(struct unicode_seq));
44 us->uc = uc;
45 us->prev = usl;
46 us->next = NULL;
47 usl->next = us;
44 while (usl->next)
45 usl = usl->next;
46 us = xmalloc(sizeof(struct unicode_seq));
47 us->uc = uc;
48 us->prev = usl;
49 us->next = NULL;
50 usl->next = us;
4851 //ul->seq->prev = us;
4952 }
5053
5154 static unsigned int
52 assemble_int(unsigned char *ip) {
53 return (ip[0] + (ip[1]<<8) + (ip[2]<<16) + (ip[3]<<24));
55 assemble_int(unsigned char *ip)
56 {
57 return (ip[0] + (ip[1] << 8) + (ip[2] << 16) + (ip[3] << 24));
5458 }
5559
5660 static void
57 store_int_le(unsigned char *ip, int num) {
61 store_int_le(unsigned char *ip, int num)
62 {
5863 ip[0] = (num & 0xff);
5964 ip[1] = ((num >> 8) & 0xff);
6065 ip[2] = ((num >> 16) & 0xff);
6267 }
6368
6469 static unsigned int
65 assemble_ucs2(char **inptr, int cnt) {
70 assemble_ucs2(char **inptr, int cnt)
71 {
6672 unsigned int u1, u2;
6773
6874 if (cnt < 2) {
7177 exit(EX_DATAERR);
7278 }
7379
74 u1 = (unsigned char) *(*inptr)++;
75 u2 = (unsigned char) *(*inptr)++;
80 u1 = (unsigned char)*(*inptr)++;
81 u2 = (unsigned char)*(*inptr)++;
7682 return (u1 | (u2 << 8));
7783 }
7884
7985 /* called with cnt > 0 and **inptr not 0xff or 0xfe */
8086 static unsigned int
81 assemble_utf8(char **inptr, int cnt) {
87 assemble_utf8(char **inptr, int cnt)
88 {
8289 int err;
8390 unsigned long uc;
8491 char *u;
8693 uc = from_utf8(inptr, cnt, &err);
8794 if (err) {
8895 switch (err) {
89 case UTF8_SHORT:
90 u = _("%s: short utf8 unicode table\n");
91 break;
92 case UTF8_BAD:
93 u = _("%s: bad utf8\n");
94 break;
95 default:
96 u = _("%s: unknown utf8 error\n");
96 case UTF8_SHORT:
97 u = _("%s: short utf8 unicode table\n");
98 break;
99 case UTF8_BAD:
100 u = _("%s: bad utf8\n");
101 break;
102 default:
103 u = _("%s: unknown utf8 error\n");
97104 }
98105 fprintf(stderr, u, progname);
99106 exit(EX_DATAERR);
102109 }
103110
104111 static void
105 clear_uni_entry(struct unicode_list *up) {
112 clear_uni_entry(struct unicode_list *up)
113 {
106114 up->next = NULL;
107 up->seq = NULL;
115 up->seq = NULL;
108116 up->prev = up;
109 }
117 }
110118
111119 /*
112120 * Read description of a single font position.
113121 */
114122 static void
115 get_uni_entry(char **inptr, char **endptr, struct unicode_list *up, int utf8) {
123 get_uni_entry(char **inptr, char **endptr, struct unicode_list *up, int utf8)
124 {
116125 unsigned char uc;
117126 unicode unichar;
118127 int inseq = 0;
119128
120129 up->next = NULL;
121 up->seq = NULL;
130 up->seq = NULL;
122131 up->prev = up;
123132
124 while(1) {
133 while (1) {
125134 if (*endptr == *inptr) {
126135 char *u = _("%s: short unicode table\n");
127136 fprintf(stderr, u, progname);
176185 */
177186 extern char *progname;
178187
179 int
180 readpsffont(FILE *fontf, char **allbufp, int *allszp,
181 char **fontbufp, int *fontszp,
182 int *fontwidthp, int *fontlenp, int fontpos0,
183 struct unicode_list **uclistheadsp) {
184 char *inputbuf = NULL;
188 int readpsffont(FILE *fontf, char **allbufp, int *allszp,
189 char **fontbufp, int *fontszp,
190 int *fontwidthp, int *fontlenp, int fontpos0,
191 struct unicode_list **uclistheadsp)
192 {
193 char *inputbuf = NULL;
185194 size_t inputbuflth = 0;
186195 size_t inputlth, fontlen, fontwidth, charsize, hastable, ftoffset, utf8;
187196 size_t i, k, n;
192201 * just read the entire file.
193202 */
194203 if (fontf) {
195 inputbuflth = MAXFONTSIZE/4; /* random */
196 inputbuf = xmalloc(inputbuflth);
197 n = 0;
198
199 while(1) {
204 inputbuflth = MAXFONTSIZE / 4; /* random */
205 inputbuf = xmalloc(inputbuflth);
206 n = 0;
207
208 while (1) {
200209 if (n >= inputbuflth) {
201210 inputbuflth *= 2;
202211 inputbuf = xrealloc(inputbuf, inputbuflth);
203212 }
204 n += fread(inputbuf+n, 1, inputbuflth-n, fontf);
213 n += fread(inputbuf + n, 1, inputbuflth - n, fontf);
205214 if (ferror(fontf)) {
206215 char *u = _("%s: Error reading input font");
207216 fprintf(stderr, u, progname);
214223 *allbufp = inputbuf;
215224 if (allszp)
216225 *allszp = n;
217 inputlth = n;
226 inputlth = n;
218227 } else {
219228 if (!allbufp || !allszp) {
220229 char *u = _("%s: Bad call of readpsffont\n");
221230 fprintf(stderr, u, progname);
222231 exit(EX_SOFTWARE);
223232 }
224 inputbuf = *allbufp;
233 inputbuf = *allbufp;
225234 inputbuflth = inputlth = n = *allszp;
226235 }
227236
229238 PSF1_MAGIC_OK((unsigned char *)inputbuf)) {
230239 struct psf1_header *psfhdr;
231240
232 psfhdr = (struct psf1_header *) &inputbuf[0];
241 psfhdr = (struct psf1_header *)&inputbuf[0];
233242
234243 if (psfhdr->mode > PSF1_MAXMODE) {
235244 char *u = _("%s: Unsupported psf file mode (%d)\n");
236245 fprintf(stderr, u, progname, psfhdr->mode);
237246 exit(EX_DATAERR);
238247 }
239 fontlen = ((psfhdr->mode & PSF1_MODE512) ? 512 : 256);
240 charsize = psfhdr->charsize;
241 hastable = (psfhdr->mode & (PSF1_MODEHASTAB|PSF1_MODEHASSEQ));
242 ftoffset = sizeof(struct psf1_header);
248 fontlen = ((psfhdr->mode & PSF1_MODE512) ? 512 : 256);
249 charsize = psfhdr->charsize;
250 hastable = (psfhdr->mode & (PSF1_MODEHASTAB | PSF1_MODEHASSEQ));
251 ftoffset = sizeof(struct psf1_header);
243252 fontwidth = 8;
244 utf8 = 0;
253 utf8 = 0;
245254 } else if (inputlth >= sizeof(struct psf2_header) &&
246 PSF2_MAGIC_OK((unsigned char *)inputbuf)) {
255 PSF2_MAGIC_OK((unsigned char *)inputbuf)) {
247256 struct psf2_header psfhdr;
248257 int flags;
249258
254263 fprintf(stderr, u, progname, psfhdr.version);
255264 exit(EX_DATAERR);
256265 }
257 fontlen = assemble_int((unsigned char *) &psfhdr.length);
258 charsize = assemble_int((unsigned char *) &psfhdr.charsize);
259 flags = assemble_int((unsigned char *) &psfhdr.flags);
260 hastable = (flags & PSF2_HAS_UNICODE_TABLE);
261 ftoffset = assemble_int((unsigned char *) &psfhdr.headersize);
262 fontwidth = assemble_int((unsigned char *) &psfhdr.width);
263 utf8 = 1;
266 fontlen = assemble_int((unsigned char *)&psfhdr.length);
267 charsize = assemble_int((unsigned char *)&psfhdr.charsize);
268 flags = assemble_int((unsigned char *)&psfhdr.flags);
269 hastable = (flags & PSF2_HAS_UNICODE_TABLE);
270 ftoffset = assemble_int((unsigned char *)&psfhdr.headersize);
271 fontwidth = assemble_int((unsigned char *)&psfhdr.width);
272 utf8 = 1;
264273 } else
265 return -1; /* not psf */
274 return -1; /* not psf */
266275
267276 /* tests required - we divide by these */
268277 if (fontlen == 0) {
292301 *fontwidthp = fontwidth;
293302
294303 if (!uclistheadsp)
295 return 0; /* got font, don't need unicode_list */
304 return 0; /* got font, don't need unicode_list */
296305
297306 *uclistheadsp = xrealloc(*uclistheadsp,
298 (fontpos0+fontlen)*sizeof(struct unicode_list));
307 (fontpos0 + fontlen) * sizeof(struct unicode_list));
299308
300309 if (hastable) {
301310 char *inptr, *endptr;
302311
303 inptr = inputbuf + ftoffset + fontlen * charsize;
312 inptr = inputbuf + ftoffset + fontlen * charsize;
304313 endptr = inputbuf + inputlth;
305314
306 for (i=0; i<fontlen; i++) {
315 for (i = 0; i < fontlen; i++) {
307316 k = fontpos0 + i;
308317 get_uni_entry(&inptr, &endptr,
309 &(*uclistheadsp)[k], utf8);
318 &(*uclistheadsp)[k], utf8);
310319 }
311320 if (inptr != endptr) {
312321 char *u = _("%s: Input file: trailing garbage\n");
314323 exit(EX_DATAERR);
315324 }
316325 } else {
317 for (i=0; i<fontlen; i++) {
326 for (i = 0; i < fontlen; i++) {
318327 k = fontpos0 + i;
319328 clear_uni_entry(&(*uclistheadsp)[k]);
320329 }
321330 }
322331
323 return 0; /* got psf font */
332 return 0; /* got psf font */
324333 }
325334
326335 static int
327 has_sequences(struct unicode_list *uclistheads, int fontlen) {
336 has_sequences(struct unicode_list *uclistheads, int fontlen)
337 {
328338 struct unicode_list *ul;
329339 struct unicode_seq *us;
330340 int i;
331341
332 for (i=0; i<fontlen; i++) {
342 for (i = 0; i < fontlen; i++) {
333343 ul = uclistheads[i].next;
334 while(ul) {
344 while (ul) {
335345 us = ul->seq;
336346 if (us && us->next)
337347 return 1;
341351 return 0;
342352 }
343353
344 void
345 appendunicode(FILE *fp, unsigned int uc, int utf8) {
354 void appendunicode(FILE *fp, unsigned int uc, int utf8)
355 {
346356 int n = 6;
347357 unsigned char out[6];
348358
364374 }
365375 out[--n] = ((uc + ~mask + ~mask) & 0xff);
366376 }
367 if (fwrite(out+n, 6-n, 1, fp) != 1) {
377 if (fwrite(out + n, 6 - n, 1, fp) != 1) {
368378 perror("appendunimap");
369379 exit(1);
370380 }
371381 if (debug) {
372 printf ("(");
382 printf("(");
373383 if (!utf8)
374 printf ("U+");
375 while (n < 6) printf ("%02x ", out[n++]);
376 printf (")");
377 }
378 }
379
380 void
381 appendseparator(FILE *fp, int seq, int utf8) {
384 printf("U+");
385 while (n < 6)
386 printf("%02x ", out[n++]);
387 printf(")");
388 }
389 }
390
391 void appendseparator(FILE *fp, int seq, int utf8)
392 {
382393 int n;
383394
384395 if (utf8) {
385396 unsigned char u = (seq ? PSF2_STARTSEQ : PSF2_SEPARATOR);
386 n = fwrite(&u, sizeof(u), 1, fp);
397 n = fwrite(&u, sizeof(u), 1, fp);
387398 } else {
388399 unsigned short u = (seq ? PSF1_STARTSEQ : PSF1_SEPARATOR);
389 n = fwrite(&u, sizeof(u), 1, fp);
400 n = fwrite(&u, sizeof(u), 1, fp);
390401 }
391402 if (n != 1) {
392403 perror("appendseparator");
394405 }
395406 }
396407
397 void
398 writepsffontheader(FILE *ofil, int width, int height, int fontlen,
399 int *psftype, int flags) {
408 void writepsffontheader(FILE *ofil, int width, int height, int fontlen,
409 int *psftype, int flags)
410 {
400411 int bytewidth, charsize, ret;
401412
402 bytewidth = (width+7)/8;
403 charsize = bytewidth * height;
413 bytewidth = (width + 7) / 8;
414 charsize = bytewidth * height;
404415
405416 if ((fontlen != 256 && fontlen != 512) || width != 8)
406417 *psftype = 2;
415426 h.magic[1] = PSF2_MAGIC1;
416427 h.magic[2] = PSF2_MAGIC2;
417428 h.magic[3] = PSF2_MAGIC3;
418 store_int_le((unsigned char *) &h.version, 0);
419 store_int_le((unsigned char *) &h.headersize, sizeof(h));
420 store_int_le((unsigned char *) &h.flags, flags2);
421 store_int_le((unsigned char *) &h.length, fontlen);
422 store_int_le((unsigned char *) &h.charsize, charsize);
423 store_int_le((unsigned char *) &h.width, width);
424 store_int_le((unsigned char *) &h.height, height);
429 store_int_le((unsigned char *)&h.version, 0);
430 store_int_le((unsigned char *)&h.headersize, sizeof(h));
431 store_int_le((unsigned char *)&h.flags, flags2);
432 store_int_le((unsigned char *)&h.length, fontlen);
433 store_int_le((unsigned char *)&h.charsize, charsize);
434 store_int_le((unsigned char *)&h.width, width);
435 store_int_le((unsigned char *)&h.height, height);
425436 ret = fwrite(&h, sizeof(h), 1, ofil);
426437 } else {
427438 struct psf1_header h;
428439
429440 h.magic[0] = PSF1_MAGIC0;
430441 h.magic[1] = PSF1_MAGIC1;
431 h.mode = 0;
442 h.mode = 0;
432443 if (fontlen == 512)
433444 h.mode |= PSF1_MODE512;
434445 if (flags & WPSFH_HASSEQ)
436447 else if (flags & WPSFH_HASTAB)
437448 h.mode |= PSF1_MODEHASTAB;
438449 h.charsize = charsize;
439 ret = fwrite(&h, sizeof(h), 1, ofil);
450 ret = fwrite(&h, sizeof(h), 1, ofil);
440451 }
441452
442453 if (ret != 1) {
445456 }
446457 }
447458
448
449 int
450 writepsffont(FILE *ofil, char *fontbuf, int width, int height, size_t fontlen,
451 int psftype, struct unicode_list *uclistheads) {
459 int writepsffont(FILE *ofil, char *fontbuf, int width, int height, size_t fontlen,
460 int psftype, struct unicode_list *uclistheads)
461 {
452462 int bytewidth, charsize, flags, utf8;
453463 size_t i;
454464
455 bytewidth = (width+7)/8;
456 charsize = bytewidth * height;
457 flags = 0;
465 bytewidth = (width + 7) / 8;
466 charsize = bytewidth * height;
467 flags = 0;
458468
459469 if (uclistheads) {
460470 flags |= WPSFH_HASTAB;
471481 }
472482
473483 /* unimaps: -1 => do nothing: caller will append map */
474 if (uclistheads != NULL && uclistheads != (struct unicode_list*)-1) {
484 if (uclistheads != NULL && uclistheads != (struct unicode_list *)-1) {
475485 struct unicode_list *ul;
476486 struct unicode_seq *us;
477487
478 for (i=0; i<fontlen; i++) {
488 for (i = 0; i < fontlen; i++) {
479489 ul = uclistheads[i].next;
480 while(ul) {
490 while (ul) {
481491 us = ul->seq;
482492 if (us && us->next)
483493 appendseparator(ofil, 1, utf8);
484 while(us) {
494 while (us) {
485495 appendunicode(ofil, us->uc, utf8);
486496 us = us->next;
487497 }
492502 }
493503 return utf8;
494504 }
495
2020 };
2121
2222 extern int readpsffont(FILE *fontf, char **allbufp, int *allszp,
23 char **fontbufp, int *fontszp,
24 int *fontwidthp, int *fontlenp, int fontpos0,
25 struct unicode_list **uclistheadsp);
23 char **fontbufp, int *fontszp,
24 int *fontwidthp, int *fontlenp, int fontpos0,
25 struct unicode_list **uclistheadsp);
2626
2727 extern int writepsffont(FILE *ofil, char *fontbuf,
28 int width, int height, size_t fontlen, int psftype,
29 struct unicode_list *uclistheads);
28 int width, int height, size_t fontlen, int psftype,
29 struct unicode_list *uclistheads);
3030
31 #define WPSFH_HASTAB 1
32 #define WPSFH_HASSEQ 2
33 extern void writepsffontheader(FILE *ofil,
34 int width, int height, int fontlen,
35 int *psftype, int flags);
31 #define WPSFH_HASTAB 1
32 #define WPSFH_HASSEQ 2
33 extern void writepsffontheader(FILE *ofil,
34 int width, int height, int fontlen,
35 int *psftype, int flags);
3636
3737 extern void appendunicode(FILE *fp, unsigned int uc, int utf8);
3838 extern void appendseparator(FILE *fp, int seq, int utf8);
3939
40 #endif /* _PSFFONTOP_H */
40 #endif /* _PSFFONTOP_H */
5353 struct unicode_list *uclistheads;
5454
5555 static void
56 addpair(int fontpos, unsigned int uc) {
56 addpair(int fontpos, unsigned int uc)
57 {
5758 struct unicode_list *ul;
5859 struct unicode_seq *us;
5960
60 ul = xmalloc(sizeof(struct unicode_list));
61 us = xmalloc(sizeof(struct unicode_seq));
62 us->uc = uc;
63 us->prev = us;
64 us->next = NULL;
65 ul->seq = us;
66 ul->prev = uclistheads[fontpos].prev;
67 ul->prev->next = ul;
68 ul->next = NULL;
61 ul = xmalloc(sizeof(struct unicode_list));
62 us = xmalloc(sizeof(struct unicode_seq));
63 us->uc = uc;
64 us->prev = us;
65 us->next = NULL;
66 ul->seq = us;
67 ul->prev = uclistheads[fontpos].prev;
68 ul->prev->next = ul;
69 ul->next = NULL;
6970 uclistheads[fontpos].prev = ul;
7071 }
7172
7273 static void
73 addseq(int fontpos, unsigned int uc) {
74 addseq(int fontpos, unsigned int uc)
75 {
7476 struct unicode_list *ul;
7577 struct unicode_seq *us;
7678
77 ul = uclistheads[fontpos].prev;
78 us = xmalloc(sizeof(struct unicode_seq));
79 us->uc = uc;
80 us->prev = ul->seq->prev;
79 ul = uclistheads[fontpos].prev;
80 us = xmalloc(sizeof(struct unicode_seq));
81 us->uc = uc;
82 us->prev = ul->seq->prev;
8183 us->prev->next = us;
82 us->next = NULL;
83 ul->seq->prev = us;
84 us->next = NULL;
85 ul->seq->prev = us;
8486 }
8587
8688 static int
87 getunicode(char **p0) {
89 getunicode(char **p0)
90 {
8891 char *p = *p0;
8992
9093 while (*p == ' ' || *p == '\t')
9396 !isxdigit(p[2]) || !isxdigit(p[3]) || !isxdigit(p[4]) ||
9497 !isxdigit(p[5]) || isxdigit(p[6]))
9598 return -1;
96 *p0 = p+6;
97 return strtol(p+2,0,16);
99 *p0 = p + 6;
100 return strtol(p + 2, 0, 16);
98101 }
99102
100103 static void
101 parse_itab_line(char *buf, int fontlen){
104 parse_itab_line(char *buf, int fontlen)
105 {
102106 char *p, *p1;
103107 int i;
104108 long fp0, fp1, un0, un1;
156160 p++;
157161 if (!strncmp(p, "idem", 4)) {
158162 for (i = fp0; i <= fp1; i++)
159 addpair(i,i);
163 addpair(i, i);
160164 p += 4;
161165 } else {
162166 un0 = getunicode(&p);
164168 p++;
165169 if (*p != '-') {
166170 char *u = _("%s: Corresponding to a range of "
167 "font positions, there should be "
168 "a Unicode range\n");
171 "font positions, there should be "
172 "a Unicode range\n");
169173 fprintf(stderr, u, progname);
170174 exit(EX_DATAERR);
171175 }
173177 un1 = getunicode(&p);
174178 if (un0 < 0 || un1 < 0) {
175179 char *u = _("%s: Bad Unicode range "
176 "corresponding to font position "
177 "range 0x%x-0x%x\n");
180 "corresponding to font position "
181 "range 0x%x-0x%x\n");
178182 fprintf(stderr, u, progname, fp0, fp1);
179183 exit(EX_DATAERR);
180184 }
181185 if (un1 - un0 != fp1 - fp0) {
182186 char *u = _("%s: Unicode range U+%x-U+%x not "
183 "of the same length as font "
184 "position range 0x%x-0x%x\n");
187 "of the same length as font "
188 "position range 0x%x-0x%x\n");
185189 fprintf(stderr, u, progname,
186 un0, un1, fp0, fp1);
190 un0, un1, fp0, fp1);
187191 exit(EX_DATAERR);
188192 }
189193 for (i = fp0; i <= fp1; i++)
190 addpair(i, un0-fp0+i);
194 addpair(i, un0 - fp0 + i);
191195 } /* not idem */
192196 } else { /* no range */
193197 while ((un0 = getunicode(&p)) >= 0) {
207211 }
208212
209213 static void
210 read_itable(FILE *itab, int fontlen, struct unicode_list **uclistheadsp) {
214 read_itable(FILE *itab, int fontlen, struct unicode_list **uclistheadsp)
215 {
211216 char buf[65536];
212217 int i;
213218
214219 if (uclistheadsp) {
215220 *uclistheadsp = xrealloc(*uclistheadsp,
216 fontlen*sizeof(struct unicode_list));
217 for (i=0; i<fontlen; i++) {
221 fontlen * sizeof(struct unicode_list));
222 for (i = 0; i < fontlen; i++) {
218223 struct unicode_list *up = &((*uclistheadsp)[i]);
219 up->next = NULL;
220 up->seq = NULL;
221 up->prev = up;
224 up->next = NULL;
225 up->seq = NULL;
226 up->prev = up;
222227 }
223228 while (fgets(buf, sizeof(buf), itab) != NULL)
224229 parse_itab_line(buf, fontlen);
227232
228233 int debug = 0;
229234
230 int
231 main(int argc, char **argv) {
235 int main(int argc, char **argv)
236 {
232237 char *ifname, *ofname, *itname, *otname;
233238 FILE *ifil, *ofil, *itab, *otab;
234239 int psftype, fontlen, charsize, hastable, notable;
248253
249254 ifil = ofil = itab = otab = NULL;
250255 ifname = ofname = itname = otname = NULL;
251 fontbuf = NULL;
252 notable = 0;
256 fontbuf = NULL;
257 notable = 0;
253258
254259 if (!strcmp(progname, "psfaddtable")) {
255260 /* Do not send binary data to stdout without explicit "-" */
276281 fprintf(stderr, u, progname);
277282 exit(EX_USAGE);
278283 }
279 ifname = argv[1];
280 ofname = argv[2];
284 ifname = argv[1];
285 ofname = argv[2];
281286 notable = 1;
282287 } else {
283 for (i = 1; i < argc; i ++) {
284 if ((!strcmp(argv[i], "-i") || !strcmp(argv[i], "-if"))
285 && i < argc-1)
288 for (i = 1; i < argc; i++) {
289 if ((!strcmp(argv[i], "-i") || !strcmp(argv[i], "-if")) && i < argc - 1)
286290 ifname = argv[++i];
287 else if((!strcmp(argv[i],"-o")||!strcmp(argv[i],"-of"))
288 && i < argc-1)
291 else if ((!strcmp(argv[i], "-o") || !strcmp(argv[i], "-of")) && i < argc - 1)
289292 ofname = argv[++i];
290 else if(!strcmp(argv[i], "-it") && i < argc-1)
293 else if (!strcmp(argv[i], "-it") && i < argc - 1)
291294 itname = argv[++i];
292 else if(!strcmp(argv[i], "-ot") && i < argc-1)
295 else if (!strcmp(argv[i], "-ot") && i < argc - 1)
293296 otname = argv[++i];
294 else if(!strcmp(argv[i], "-nt"))
297 else if (!strcmp(argv[i], "-nt"))
295298 notable = 1;
296299 else
297300 break;
298301 }
299302 if (i < argc || argc <= 1) {
300303 char *u = _("Usage:\n\t%s [-i infont] [-o outfont] "
301 "[-it intable] [-ot outtable] [-nt]\n");
304 "[-it intable] [-ot outtable] [-nt]\n");
302305 fprintf(stderr, u, progname);
303306 exit(EX_USAGE);
304307 }
355358 }
356359
357360 if (readpsffont(ifil, &inbuf, &inbuflth, &fontbuf, &fontbuflth,
358 &width, &fontlen, 0,
359 itab ? NULL : &uclistheads) == -1) {
361 &width, &fontlen, 0,
362 itab ? NULL : &uclistheads) == -1) {
360363 char *u = _("%s: Bad magic number on %s\n");
361364 fprintf(stderr, u, progname, ifname);
362365 exit(EX_DATAERR);
363366 }
364367 fclose(ifil);
365368
366 charsize = fontbuflth/fontlen;
367 bytewidth = (width + 7)/8;
369 charsize = fontbuflth / fontlen;
370 bytewidth = (width + 7) / 8;
368371 if (!bytewidth)
369372 bytewidth = 1;
370 height = charsize / bytewidth;
373 height = charsize / bytewidth;
371374
372375 hastable = (uclistheads != NULL);
373376
397400 exit(EX_DATAERR);
398401 }
399402 fprintf(otab,
400 "#\n# Character table extracted from font %s\n#\n",
401 ifname);
402 for (i=0; i<fontlen; i++) {
403 "#\n# Character table extracted from font %s\n#\n",
404 ifname);
405 for (i = 0; i < fontlen; i++) {
403406 fprintf(otab, "0x%03x\t", i);
404407 sep = "";
405 ul = uclistheads[i].next;
408 ul = uclistheads[i].next;
406409 while (ul) {
407410 us = ul->seq;
408 while(us) {
411 while (us) {
409412 fprintf(otab, "%sU+%04x", sep, us->uc);
410 us = us->next;
413 us = us->next;
411414 sep = ", ";
412415 }
413 ul = ul->next;
416 ul = ul->next;
414417 sep = " ";
415418 }
416419 fprintf(otab, "\n");
420423
421424 if (ofil) {
422425 writepsffont(ofil, fontbuf, width, height, fontlen, psftype,
423 notable ? NULL : uclistheads);
426 notable ? NULL : uclistheads);
424427 fclose(ofil);
425428 }
426429
8686 #include "version.h"
8787 #include "kbd_error.h"
8888
89 #define MODE_RESTORETEXTMODE 0
90 #define MODE_VGALINES 1
89 #define MODE_RESTORETEXTMODE 0
90 #define MODE_VGALINES 1
9191
9292 static void usage(void);
9393
100100 static void vga_set_cursor(int, int);
101101 static void vga_set_verticaldisplayend_lowbyte(int);
102102
103 const char *const dirpath[] = { "", DATADIR "/" VIDEOMODEDIR "/", 0};
103 const char *const dirpath[] = { "", DATADIR "/" VIDEOMODEDIR "/", 0 };
104104 const char *const suffixes[] = { "", 0 };
105105
106 int
107 main(int argc, char **argv) {
108 int rr, cc, fd, i, mode;
109 struct vt_sizes vtsizes;
110 struct vt_stat vtstat;
111 struct winsize winsize;
112 char *p;
113 char tty[12], cmd[80], infile[1024];
114 char *defaultfont;
115 lkfile_t fp;
116
117 set_progname(argv[0]);
118
119 setlocale(LC_ALL, "");
120 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
121 textdomain(PACKAGE_NAME);
122
123 if (argc < 2)
124 usage();
125
126 if (argc == 2 && !strcmp(argv[1], "-V"))
127 print_version_and_exit();
128
129 rr = 0; /* make gcc happy */
130 cc = atoi(argv[1]);
131 mode = MODE_RESTORETEXTMODE;
132 if (argc == 3 && strcmp(argv[1], "-lines") == 0) {
133 mode = MODE_VGALINES;
134 rr = atoi(argv[2]);
135 }
136 else
137 if (argc == 2 && (p = strchr(argv[1], 'x')) != 0)
138 rr = atoi(p+1);
139 else if(argc == 3)
140 rr = atoi(argv[2]);
141 else
142 usage();
143
144 if (mode == MODE_RESTORETEXTMODE) {
145 /* prepare for: restoretextmode -r 80x25 */
146 sprintf(infile, "%dx%d", cc, rr);
147 if (lk_findfile(infile, dirpath, suffixes, &fp)) {
148 kbd_error(EXIT_FAILURE, 0, _("resizecons: cannot find videomode file %s\n"), infile);
149 }
150 lk_fpclose(&fp);
151 }
152
153 if ((fd = getfd(NULL)) < 0)
154 kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
155
156 if(ioctl(fd, TIOCGWINSZ, &winsize)) {
157 kbd_error(EXIT_FAILURE, errno, "ioctl TIOCGWINSZ");
158 }
159
160 if (mode == MODE_VGALINES) {
161 /* Get the number of columns. */
162 cc = winsize.ws_col;
163 if (rr != 25 && rr != 28 && rr != 30 && rr != 34 && rr != 36 &&
164 rr != 40 && rr != 44 && rr != 50 && rr != 60) {
165 kbd_error(EXIT_FAILURE, 0, _("Invalid number of lines\n"));
166 }
167 }
168
169 if(ioctl(fd, VT_GETSTATE, &vtstat)) {
170 kbd_error(EXIT_FAILURE, errno, "ioctl VT_GETSTATE");
171 }
172
173 vtsizes.v_rows = rr;
174 vtsizes.v_cols = cc;
175 vtsizes.v_scrollsize = 0;
176
177 vga_init_io(); /* maybe only if (mode == MODE_VGALINES) */
178
179 if(ioctl(fd, VT_RESIZE, &vtsizes)) {
180 kbd_error(EXIT_FAILURE, errno, "ioctl VT_RESIZE");
181 }
182
183 if (mode == MODE_VGALINES) {
184 /* Program the VGA registers. */
185 int scanlines_old;
186 int scanlines_new;
187 int fontheight;
188 if (winsize.ws_row == 25 || winsize.ws_row == 28 ||
189 winsize.ws_row == 36 || winsize.ws_row == 44 ||
190 winsize.ws_row == 50)
191 scanlines_old = 400;
192 else
193 scanlines_old = 480;
194 if (rr == 25 || rr == 28 || rr == 36 || rr == 44 || rr == 50)
195 scanlines_new = 400;
196 else
197 scanlines_new = 480;
198 /* Switch to 400 or 480 scanline vertical timing if required. */
199 if (scanlines_old != 400 && scanlines_new == 400)
200 vga_400_scanlines();
201 if (scanlines_old != 480 && scanlines_new == 480)
202 vga_480_scanlines();
203 switch (rr) {
204 case 25 : fontheight = 16; break;
205 case 28 : fontheight = 14; break;
206 case 30 : fontheight = 16; break;
207 case 34 : fontheight = 14; break;
208 case 36 : fontheight = 12; break;
209 case 40 : fontheight = 12; break;
210 case 44 : fontheight = 9; break;
211 case 50 : fontheight = 8; break;
212 case 60 : fontheight = 8; break;
213 default : fontheight = 8; break;
214 }
215 /* Set the VGA character height. */
216 vga_set_fontheight(fontheight);
217 /* Set the line offsets within a character cell of the cursor. */
218 if (fontheight >= 10)
219 vga_set_cursor(fontheight - 3, fontheight - 2);
106 int main(int argc, char **argv)
107 {
108 int rr, cc, fd, i, mode;
109 struct vt_sizes vtsizes;
110 struct vt_stat vtstat;
111 struct winsize winsize;
112 char *p;
113 char tty[12], cmd[80], infile[1024];
114 char *defaultfont;
115 lkfile_t fp;
116
117 set_progname(argv[0]);
118
119 setlocale(LC_ALL, "");
120 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
121 textdomain(PACKAGE_NAME);
122
123 if (argc < 2)
124 usage();
125
126 if (argc == 2 && !strcmp(argv[1], "-V"))
127 print_version_and_exit();
128
129 rr = 0; /* make gcc happy */
130 cc = atoi(argv[1]);
131 mode = MODE_RESTORETEXTMODE;
132 if (argc == 3 && strcmp(argv[1], "-lines") == 0) {
133 mode = MODE_VGALINES;
134 rr = atoi(argv[2]);
135 } else if (argc == 2 && (p = strchr(argv[1], 'x')) != 0)
136 rr = atoi(p + 1);
137 else if (argc == 3)
138 rr = atoi(argv[2]);
220139 else
221 vga_set_cursor(fontheight - 2, fontheight - 1);
222 /*
140 usage();
141
142 if (mode == MODE_RESTORETEXTMODE) {
143 /* prepare for: restoretextmode -r 80x25 */
144 sprintf(infile, "%dx%d", cc, rr);
145 if (lk_findfile(infile, dirpath, suffixes, &fp)) {
146 kbd_error(EXIT_FAILURE, 0, _("resizecons: cannot find videomode file %s\n"), infile);
147 }
148 lk_fpclose(&fp);
149 }
150
151 if ((fd = getfd(NULL)) < 0)
152 kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
153
154 if (ioctl(fd, TIOCGWINSZ, &winsize)) {
155 kbd_error(EXIT_FAILURE, errno, "ioctl TIOCGWINSZ");
156 }
157
158 if (mode == MODE_VGALINES) {
159 /* Get the number of columns. */
160 cc = winsize.ws_col;
161 if (rr != 25 && rr != 28 && rr != 30 && rr != 34 && rr != 36 &&
162 rr != 40 && rr != 44 && rr != 50 && rr != 60) {
163 kbd_error(EXIT_FAILURE, 0, _("Invalid number of lines\n"));
164 }
165 }
166
167 if (ioctl(fd, VT_GETSTATE, &vtstat)) {
168 kbd_error(EXIT_FAILURE, errno, "ioctl VT_GETSTATE");
169 }
170
171 vtsizes.v_rows = rr;
172 vtsizes.v_cols = cc;
173 vtsizes.v_scrollsize = 0;
174
175 vga_init_io(); /* maybe only if (mode == MODE_VGALINES) */
176
177 if (ioctl(fd, VT_RESIZE, &vtsizes)) {
178 kbd_error(EXIT_FAILURE, errno, "ioctl VT_RESIZE");
179 }
180
181 if (mode == MODE_VGALINES) {
182 /* Program the VGA registers. */
183 int scanlines_old;
184 int scanlines_new;
185 int fontheight;
186 if (winsize.ws_row == 25 || winsize.ws_row == 28 ||
187 winsize.ws_row == 36 || winsize.ws_row == 44 ||
188 winsize.ws_row == 50)
189 scanlines_old = 400;
190 else
191 scanlines_old = 480;
192 if (rr == 25 || rr == 28 || rr == 36 || rr == 44 || rr == 50)
193 scanlines_new = 400;
194 else
195 scanlines_new = 480;
196 /* Switch to 400 or 480 scanline vertical timing if required. */
197 if (scanlines_old != 400 && scanlines_new == 400)
198 vga_400_scanlines();
199 if (scanlines_old != 480 && scanlines_new == 480)
200 vga_480_scanlines();
201 switch (rr) {
202 case 25:
203 fontheight = 16;
204 break;
205 case 28:
206 fontheight = 14;
207 break;
208 case 30:
209 fontheight = 16;
210 break;
211 case 34:
212 fontheight = 14;
213 break;
214 case 36:
215 fontheight = 12;
216 break;
217 case 40:
218 fontheight = 12;
219 break;
220 case 44:
221 fontheight = 9;
222 break;
223 case 50:
224 fontheight = 8;
225 break;
226 case 60:
227 fontheight = 8;
228 break;
229 default:
230 fontheight = 8;
231 break;
232 }
233 /* Set the VGA character height. */
234 vga_set_fontheight(fontheight);
235 /* Set the line offsets within a character cell of the cursor. */
236 if (fontheight >= 10)
237 vga_set_cursor(fontheight - 3, fontheight - 2);
238 else
239 vga_set_cursor(fontheight - 2, fontheight - 1);
240 /*
223241 * If there are a few unused scanlines at the bottom of the
224242 * screen, make sure they are not displayed (otherwise
225243 * there is a annoying changing partial line at the bottom).
226244 */
227 vga_set_verticaldisplayend_lowbyte((fontheight * rr - 1) & 0xff);
228 printf(_("Old mode: %dx%d New mode: %dx%d\n"), winsize.ws_col,
229 winsize.ws_row, cc, rr);
230 printf(_("Old #scanlines: %d New #scanlines: %d Character height: %d\n"),
231 scanlines_old, scanlines_new, fontheight);
232 }
233
234 if (mode == MODE_RESTORETEXTMODE) {
235 /* do: restoretextmode -r 25x80 */
236 sprintf(cmd, "restoretextmode -r %s\n", fp.pathname);
237 errno = 0;
238 if(system(cmd)) {
239 if(errno)
240 perror("restoretextmode");
241 fprintf(stderr, _("resizecons: the command `%s' failed\n"), cmd);
242 exit(EXIT_FAILURE);
243 }
244 }
245
246 /*
245 vga_set_verticaldisplayend_lowbyte((fontheight * rr - 1) & 0xff);
246 printf(_("Old mode: %dx%d New mode: %dx%d\n"), winsize.ws_col,
247 winsize.ws_row, cc, rr);
248 printf(_("Old #scanlines: %d New #scanlines: %d Character height: %d\n"),
249 scanlines_old, scanlines_new, fontheight);
250 }
251
252 if (mode == MODE_RESTORETEXTMODE) {
253 /* do: restoretextmode -r 25x80 */
254 sprintf(cmd, "restoretextmode -r %s\n", fp.pathname);
255 errno = 0;
256 if (system(cmd)) {
257 if (errno)
258 perror("restoretextmode");
259 fprintf(stderr, _("resizecons: the command `%s' failed\n"), cmd);
260 exit(EXIT_FAILURE);
261 }
262 }
263
264 /*
247265 * for i in /dev/tty[0-9] /dev/tty[0-9][0-9]
248266 * do
249267 * stty rows $rr cols $cc < $i
250268 * done
251269 * kill -SIGWINCH `cat /tmp/selection.pid`
252270 */
253 winsize.ws_row = rr;
254 winsize.ws_col = cc;
255 for (i=0; i<16; i++)
256 if (vtstat.v_state & (1<<i)) {
257 sprintf(tty, "/dev/tty%d", i);
258 fd = open(tty, O_RDONLY);
259 if (fd < 0 && errno == ENOENT) {
260 sprintf(tty, "/dev/vc/%d", i);
261 fd = open(tty, O_RDONLY);
262 }
263 if (fd >= 0) {
264 if(ioctl(fd, TIOCSWINSZ, &winsize))
265 kbd_warning(errno, "ioctl TIOCSWINSZ");
266 close(fd);
267 }
268 }
271 winsize.ws_row = rr;
272 winsize.ws_col = cc;
273 for (i = 0; i < 16; i++)
274 if (vtstat.v_state & (1 << i)) {
275 sprintf(tty, "/dev/tty%d", i);
276 fd = open(tty, O_RDONLY);
277 if (fd < 0 && errno == ENOENT) {
278 sprintf(tty, "/dev/vc/%d", i);
279 fd = open(tty, O_RDONLY);
280 }
281 if (fd >= 0) {
282 if (ioctl(fd, TIOCSWINSZ, &winsize))
283 kbd_warning(errno, "ioctl TIOCSWINSZ");
284 close(fd);
285 }
286 }
269287
270288 #if 0
271289 /* Try to tell selection about the change */
284302 }
285303 #endif
286304
287 /* do: setfont default8x16 */
288 /* (other people might wish other fonts - this should be settable) */
289
290 /* We read the VGA font height register to be sure. */
291 /* There isn't much consistency in this. */
292 switch (vga_get_fontheight()) {
293 case 8 :
294 case 9 : defaultfont = "default8x9"; break;
295 case 10 : defaultfont = "lat1-10"; break;
296 case 11 :
297 case 12 : defaultfont = "lat1-12"; break;
298 case 13 :
299 case 14 : defaultfont = "iso01.14"; break;
300 case 15 :
301 case 16 :
302 default : defaultfont = "default8x16"; break;
303 }
304
305 sprintf(cmd, "setfont %s", defaultfont);
306 errno = 0;
307 if(system(cmd)) {
308 if(errno)
309 perror("setfont");
310 fprintf(stderr, "resizecons: the command `%s' failed\n", cmd);
305 /* do: setfont default8x16 */
306 /* (other people might wish other fonts - this should be settable) */
307
308 /* We read the VGA font height register to be sure. */
309 /* There isn't much consistency in this. */
310 switch (vga_get_fontheight()) {
311 case 8:
312 case 9:
313 defaultfont = "default8x9";
314 break;
315 case 10:
316 defaultfont = "lat1-10";
317 break;
318 case 11:
319 case 12:
320 defaultfont = "lat1-12";
321 break;
322 case 13:
323 case 14:
324 defaultfont = "iso01.14";
325 break;
326 case 15:
327 case 16:
328 default:
329 defaultfont = "default8x16";
330 break;
331 }
332
333 sprintf(cmd, "setfont %s", defaultfont);
334 errno = 0;
335 if (system(cmd)) {
336 if (errno)
337 perror("setfont");
338 fprintf(stderr, "resizecons: the command `%s' failed\n", cmd);
339 exit(EXIT_FAILURE);
340 }
341
342 fprintf(stderr, _("resizecons: don't forget to change TERM "
343 "(maybe to con%dx%d or linux-%dx%d)\n"),
344 cc, rr, cc, rr);
345 if (getenv("LINES") || getenv("COLUMNS"))
346 fprintf(stderr,
347 "Also the variables LINES and COLUMNS may need adjusting.\n");
348
349 return EXIT_SUCCESS;
350 }
351
352 static void __attribute__((noreturn))
353 usage()
354 {
355 fprintf(stderr,
356 _("resizecons:\n"
357 "call is: resizecons COLSxROWS or: resizecons COLS ROWS\n"
358 "or: resizecons -lines ROWS, with ROWS one of 25, 28, 30, 34,"
359 " 36, 40, 44, 50, 60\n"));
311360 exit(EXIT_FAILURE);
312 }
313
314 fprintf(stderr, _("resizecons: don't forget to change TERM "
315 "(maybe to con%dx%d or linux-%dx%d)\n"),
316 cc, rr, cc, rr);
317 if (getenv("LINES") || getenv("COLUMNS"))
318 fprintf(stderr,
319 "Also the variables LINES and COLUMNS may need adjusting.\n");
320
321 return EXIT_SUCCESS;
322 }
323
324 static void __attribute__ ((noreturn))
325 usage() {
326 fprintf(stderr,
327 _("resizecons:\n"
328 "call is: resizecons COLSxROWS or: resizecons COLS ROWS\n"
329 "or: resizecons -lines ROWS, with ROWS one of 25, 28, 30, 34,"
330 " 36, 40, 44, 50, 60\n"));
331 exit(EXIT_FAILURE);
332361 }
333362
334363 /*
339368 /* Port I/O macros. Note that these are not compatible with the ones */
340369 /* defined in the kernel header files. */
341370
342 static inline void my_outb( int port, int value )
343 {
344 __asm__ volatile ("outb %0,%1"
345 : : "a" ((unsigned char)value), "d" ((unsigned short)port));
346 }
347
348 static inline int my_inb( int port )
371 static inline void my_outb(int port, int value)
372 {
373 __asm__ volatile("outb %0,%1"
374 :
375 : "a"((unsigned char)value), "d"((unsigned short)port));
376 }
377
378 static inline int my_inb(int port)
349379 {
350380 unsigned char value;
351 __asm__ volatile ("inb %1,%0"
352 : "=a" (value)
353 : "d" ((unsigned short)port));
381 __asm__ volatile("inb %1,%0"
382 : "=a"(value)
383 : "d"((unsigned short)port));
354384 return value;
355385 }
356386
357
358387 /* VGA textmode register tweaking functions. */
359388
360389 static int crtcport;
361390
362 static void vga_init_io() {
391 static void vga_init_io()
392 {
363393 if (iopl(3) < 0) {
364394 fprintf(stderr,
365 _("resizecons: cannot get I/O permissions.\n"));
395 _("resizecons: cannot get I/O permissions.\n"));
366396 exit(EXIT_FAILURE);
367397 }
368398 crtcport = 0x3d4;
370400 crtcport = 0x3b4;
371401 }
372402
373 static void vga_set_fontheight( int h ) {
403 static void vga_set_fontheight(int h)
404 {
374405 my_outb(crtcport, 0x09);
375406 my_outb(crtcport + 1, (my_inb(crtcport + 1) & 0xe0) | (h - 1));
376407 }
377408
378 static int vga_get_fontheight() {
409 static int vga_get_fontheight()
410 {
379411 my_outb(crtcport, 0x09);
380412 return (my_inb(crtcport + 1) & 0x1f) + 1;
381413 }
382414
383 static void vga_set_cursor( int top, int bottom ) {
415 static void vga_set_cursor(int top, int bottom)
416 {
384417 my_outb(crtcport, 0x0a);
385418 my_outb(crtcport + 1, (my_inb(crtcport + 1) & 0xc0) | top);
386419 my_outb(crtcport, 0x0b);
387420 my_outb(crtcport + 1, (my_inb(crtcport + 1) & 0xe0) | bottom);
388421 }
389422
390 static void vga_set_verticaldisplayend_lowbyte( int byte ) {
423 static void vga_set_verticaldisplayend_lowbyte(int byte)
424 {
391425 /* CRTC register 0x12 */
392426 /* vertical display end */
393427 my_outb(crtcport, 0x12);
394428 my_outb(crtcport + 1, byte);
395429 }
396430
397 static void vga_480_scanlines() {
431 static void vga_480_scanlines()
432 {
398433 /* CRTC register 0x11 */
399434 /* vertical sync end (also unlocks CR0-7) */
400435 my_outb(crtcport, 0x11);
435470 my_outb(0x3c2, (my_inb(0x3cc) & 0x0d) | 0xe2);
436471 }
437472
438 static void vga_400_scanlines() {
473 static void vga_400_scanlines()
474 {
439475 /* CRTC register 0x11 */
440476 /* vertical sync end (also unlocks CR0-7) */
441477 my_outb(crtcport, 0x11);
2828 #include "version.h"
2929 #include "kbd_error.h"
3030
31 int
32 main(int argc, char **argv) {
33 int cons = 0;
34 char infile[20];
35 unsigned char header[4];
36 unsigned int rows, cols;
37 int fd;
38 unsigned int i, j;
39 char *inbuf, *outbuf, *p, *q;
31 int main(int argc, char **argv)
32 {
33 int cons = 0;
34 char infile[20];
35 unsigned char header[4];
36 unsigned int rows, cols;
37 int fd;
38 unsigned int i, j;
39 char *inbuf, *outbuf, *p, *q;
4040
41 set_progname(argv[0]);
41 set_progname(argv[0]);
4242
43 setlocale(LC_ALL, "");
44 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
45 textdomain(PACKAGE_NAME);
43 setlocale(LC_ALL, "");
44 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
45 textdomain(PACKAGE_NAME);
4646
47 if (argc == 2 && !strcmp(argv[1], "-V"))
48 print_version_and_exit();
47 if (argc == 2 && !strcmp(argv[1], "-V"))
48 print_version_and_exit();
4949
50 if (argc > 2) {
51 fprintf(stderr, _("usage: screendump [n]\n"));
52 exit(EXIT_FAILURE);
53 }
50 if (argc > 2) {
51 fprintf(stderr, _("usage: screendump [n]\n"));
52 exit(EXIT_FAILURE);
53 }
5454
55 cons = (argc == 2) ? atoi(argv[1]) : 0;
55 cons = (argc == 2) ? atoi(argv[1]) : 0;
5656
57 sprintf(infile, "/dev/vcsa%d", cons);
58 fd = open(infile, O_RDONLY);
59 if (fd < 0 && cons == 0 && errno == ENOENT) {
60 sprintf(infile, "/dev/vcsa");
61 fd = open(infile, O_RDONLY);
62 }
63 if (fd < 0 && errno == ENOENT) {
64 sprintf(infile, "/dev/vcs/a%d", cons);
65 fd = open(infile, O_RDONLY);
66 }
67 if (fd < 0 && cons == 0 && errno == ENOENT) {
68 sprintf(infile, "/dev/vcs/a");
69 fd = open(infile, O_RDONLY);
70 }
71 if (fd < 0 || read(fd, header, 4) != 4)
72 goto try_ioctl;
73 rows = header[0];
74 cols = header[1];
75 if (rows * cols == 0)
76 goto try_ioctl;
77 inbuf = xmalloc(rows*cols*2);
78 outbuf = xmalloc(rows*(cols+1));
57 sprintf(infile, "/dev/vcsa%d", cons);
58 fd = open(infile, O_RDONLY);
59 if (fd < 0 && cons == 0 && errno == ENOENT) {
60 sprintf(infile, "/dev/vcsa");
61 fd = open(infile, O_RDONLY);
62 }
63 if (fd < 0 && errno == ENOENT) {
64 sprintf(infile, "/dev/vcs/a%d", cons);
65 fd = open(infile, O_RDONLY);
66 }
67 if (fd < 0 && cons == 0 && errno == ENOENT) {
68 sprintf(infile, "/dev/vcs/a");
69 fd = open(infile, O_RDONLY);
70 }
71 if (fd < 0 || read(fd, header, 4) != 4)
72 goto try_ioctl;
73 rows = header[0];
74 cols = header[1];
75 if (rows * cols == 0)
76 goto try_ioctl;
77 inbuf = xmalloc(rows * cols * 2);
78 outbuf = xmalloc(rows * (cols + 1));
7979
80 if (read(fd, inbuf, rows*cols*2) != (ssize_t) (rows*cols*2)) {
81 kbd_error(EXIT_FAILURE, errno, _("Error reading %s"), infile);
82 }
83 p = inbuf;
84 q = outbuf;
85 for(i=0; i<rows; i++) {
86 for(j=0; j<cols; j++) {
87 *q++ = *p;
88 p += 2;
89 }
90 while(j-- > 0 && q[-1] == ' ')
91 q--;
92 *q++ = '\n';
93 }
94 goto done;
80 if (read(fd, inbuf, rows * cols * 2) != (ssize_t)(rows * cols * 2)) {
81 kbd_error(EXIT_FAILURE, errno, _("Error reading %s"), infile);
82 }
83 p = inbuf;
84 q = outbuf;
85 for (i = 0; i < rows; i++) {
86 for (j = 0; j < cols; j++) {
87 *q++ = *p;
88 p += 2;
89 }
90 while (j-- > 0 && q[-1] == ' ')
91 q--;
92 *q++ = '\n';
93 }
94 goto done;
9595
96 try_ioctl:
97 {
96 try_ioctl : {
9897 struct winsize win;
9998 char consnam[20], devfsconsnam[20];
10099 unsigned char *screenbuf;
102101 sprintf(consnam, "/dev/tty%d", cons);
103102 fd = open(consnam, O_RDONLY);
104103 if (fd < 0 && errno == ENOENT) {
105 sprintf(devfsconsnam, "/dev/vc/%d", cons);
106 fd = open(devfsconsnam, O_RDONLY);
107 if (fd < 0)
108 errno = ENOENT;
104 sprintf(devfsconsnam, "/dev/vc/%d", cons);
105 fd = open(devfsconsnam, O_RDONLY);
106 if (fd < 0)
107 errno = ENOENT;
109108 }
110109 if (fd < 0) {
111 perror(consnam);
112 fd = 0;
110 perror(consnam);
111 fd = 0;
113112 }
114113
115114 if (ioctl(fd, TIOCGWINSZ, &win)) {
116 kbd_error(EXIT_FAILURE, errno, "ioctl TIOCGWINSZ");
115 kbd_error(EXIT_FAILURE, errno, "ioctl TIOCGWINSZ");
117116 }
118117
119 screenbuf = xmalloc(2 + win.ws_row * win.ws_col);
118 screenbuf = xmalloc(2 + win.ws_row * win.ws_col);
120119 screenbuf[0] = 0;
121 screenbuf[1] = (unsigned char) cons;
120 screenbuf[1] = (unsigned char)cons;
122121
123 if (ioctl(fd,TIOCLINUX,screenbuf) &&
124 (!fd || ioctl(0,TIOCLINUX,screenbuf))) {
122 if (ioctl(fd, TIOCLINUX, screenbuf) &&
123 (!fd || ioctl(0, TIOCLINUX, screenbuf))) {
125124 #if 0
126125 perror("TIOCLINUX");
127126 fprintf(stderr,_("couldn't read %s, and cannot ioctl dump\n"),
128127 infile);
129128 #else
130 /* we tried this just to be sure, but TIOCLINUX
129 /* we tried this just to be sure, but TIOCLINUX
131130 function 0 has been disabled since 1.1.92
132131 Do not mention `ioctl dump' in error msg */
133 kbd_warning(0, _("couldn't read %s\n"), infile);
132 kbd_warning(0, _("couldn't read %s\n"), infile);
134133 #endif
135 return EXIT_FAILURE;
134 return EXIT_FAILURE;
136135 }
137136
138 rows = screenbuf[0];
139 cols = screenbuf[1];
137 rows = screenbuf[0];
138 cols = screenbuf[1];
140139 if (rows != win.ws_row || cols != win.ws_col) {
141 kbd_error(EXIT_FAILURE, 0,
142 _("Strange ... screen is both %dx%d and %dx%d ??\n"),
143 win.ws_col, win.ws_row, cols, rows);
140 kbd_error(EXIT_FAILURE, 0,
141 _("Strange ... screen is both %dx%d and %dx%d ??\n"),
142 win.ws_col, win.ws_row, cols, rows);
144143 }
145144
146 outbuf = xmalloc(rows*(cols+1));
147 p = ((char *)screenbuf) + 2;
148 q = outbuf;
149 for (i=0; i<rows; i++) {
150 for (j=0; j<cols; j++)
151 *q++ = *p++;
152 while (j-- > 0 && (q[-1] == ' '))
153 q--;
154 *q++ = '\n';
155 }
156 }
145 outbuf = xmalloc(rows * (cols + 1));
146 p = ((char *)screenbuf) + 2;
147 q = outbuf;
148 for (i = 0; i < rows; i++) {
149 for (j = 0; j < cols; j++)
150 *q++ = *p++;
151 while (j-- > 0 && (q[-1] == ' '))
152 q--;
153 *q++ = '\n';
154 }
155 }
157156 done:
158 if (write(1, outbuf, q-outbuf) != q-outbuf) {
159 kbd_error(EXIT_FAILURE, 0, _("Error writing screendump\n"));
160 }
157 if (write(1, outbuf, q - outbuf) != q - outbuf) {
158 kbd_error(EXIT_FAILURE, 0, _("Error writing screendump\n"));
159 }
161160
162 return EXIT_SUCCESS;
161 return EXIT_SUCCESS;
163162 }
3838 static void saveoldfont(int fd, char *ofil);
3939 static void saveoldfontplusunicodemap(int fd, char *Ofil);
4040 static void loadnewfont(int fd, char *ifil,
41 int iunit, int hwunit, int no_m, int no_u);
41 int iunit, int hwunit, int no_m, int no_u);
4242 static void loadnewfonts(int fd, char **ifiles, int ifilct,
43 int iunit, int hwunit, int no_m, int no_u);
43 int iunit, int hwunit, int no_m, int no_u);
4444 extern void saveoldmap(int fd, char *omfil);
4545 extern void loadnewmap(int fd, char *mfil);
4646 extern void activatemap(int fd);
4747 extern void disactivatemap(int fd);
4848
4949 int verbose = 0;
50 int force = 0;
51 int debug = 0;
50 int force = 0;
51 int debug = 0;
5252
5353 /* search for the font in these directories (with trailing /) */
54 const char *const fontdirpath[] = { "", DATADIR "/" FONTDIR "/", 0 };
54 const char *const fontdirpath[] = { "", DATADIR "/" FONTDIR "/", 0 };
5555 const char *const fontsuffixes[] = { "", ".psfu", ".psf", ".cp", ".fnt", 0 };
5656 /* hide partial fonts a bit - loading a single one is a bad idea */
57 const char *const partfontdirpath[] = { "", DATADIR "/" FONTDIR "/" PARTIALDIR "/", 0 };
57 const char *const partfontdirpath[] = { "", DATADIR "/" FONTDIR "/" PARTIALDIR "/", 0 };
5858 const char *const partfontsuffixes[] = { "", 0 };
5959
6060 static inline int
61 findfont(char *fnam, lkfile_t *fp) {
62 return lk_findfile(fnam, fontdirpath, fontsuffixes, fp);
61 findfont(char *fnam, lkfile_t *fp)
62 {
63 return lk_findfile(fnam, fontdirpath, fontsuffixes, fp);
6364 }
6465
6566 static inline int
66 findpartialfont(char *fnam, lkfile_t *fp) {
67 return lk_findfile(fnam, partfontdirpath, partfontsuffixes, fp);
68 }
69
70 static void __attribute__ ((noreturn))
67 findpartialfont(char *fnam, lkfile_t *fp)
68 {
69 return lk_findfile(fnam, partfontdirpath, partfontsuffixes, fp);
70 }
71
72 static void __attribute__((noreturn))
7173 usage(void)
7274 {
73 fprintf(stderr, _(
74 "Usage: setfont [write-options] [-<N>] [newfont..] [-m consolemap] [-u unicodemap]\n"
75 " write-options (take place before file loading):\n"
76 " -o <filename> Write current font to <filename>\n"
77 " -O <filename> Write current font and unicode map to <filename>\n"
78 " -om <filename> Write current consolemap to <filename>\n"
79 " -ou <filename> Write current unicodemap to <filename>\n"
80 "If no newfont and no -[o|O|om|ou|m|u] option is given,\n"
81 "a default font is loaded:\n"
82 " setfont Load font \"default[.gz]\"\n"
83 " setfont -<N> Load font \"default8x<N>[.gz]\"\n"
84 "The -<N> option selects a font from a codepage that contains three fonts:\n"
85 " setfont -{8|14|16} codepage.cp[.gz] Load 8x<N> font from codepage.cp\n"
86 "Explicitly (with -m or -u) or implicitly (in the fontfile) given mappings\n"
87 "will be loaded and, in the case of consolemaps, activated.\n"
88 " -h<N> (no space) Override font height.\n"
89 " -m <fn> Load console screen map.\n"
90 " -u <fn> Load font unicode map.\n"
91 " -m none Suppress loading and activation of a screen map.\n"
92 " -u none Suppress loading of a unicode map.\n"
93 " -v Be verbose.\n"
94 " -C <cons> Indicate console device to be used.\n"
95 " -V Print version and exit.\n"
96 "Files are loaded from the current directory or %s/*/.\n"
97 ), DATADIR);
75 fprintf(stderr, _(
76 "Usage: setfont [write-options] [-<N>] [newfont..] [-m consolemap] [-u unicodemap]\n"
77 " write-options (take place before file loading):\n"
78 " -o <filename> Write current font to <filename>\n"
79 " -O <filename> Write current font and unicode map to <filename>\n"
80 " -om <filename> Write current consolemap to <filename>\n"
81 " -ou <filename> Write current unicodemap to <filename>\n"
82 "If no newfont and no -[o|O|om|ou|m|u] option is given,\n"
83 "a default font is loaded:\n"
84 " setfont Load font \"default[.gz]\"\n"
85 " setfont -<N> Load font \"default8x<N>[.gz]\"\n"
86 "The -<N> option selects a font from a codepage that contains three fonts:\n"
87 " setfont -{8|14|16} codepage.cp[.gz] Load 8x<N> font from codepage.cp\n"
88 "Explicitly (with -m or -u) or implicitly (in the fontfile) given mappings\n"
89 "will be loaded and, in the case of consolemaps, activated.\n"
90 " -h<N> (no space) Override font height.\n"
91 " -m <fn> Load console screen map.\n"
92 " -u <fn> Load font unicode map.\n"
93 " -m none Suppress loading and activation of a screen map.\n"
94 " -u none Suppress loading of a unicode map.\n"
95 " -v Be verbose.\n"
96 " -C <cons> Indicate console device to be used.\n"
97 " -V Print version and exit.\n"
98 "Files are loaded from the current directory or %s/*/.\n"),
99 DATADIR);
98100 exit(EX_USAGE);
99101 }
100102
101103 #define MAXIFILES 256
102104
103 int
104 main(int argc, char *argv[]) {
105 int main(int argc, char *argv[])
106 {
105107 char *ifiles[MAXIFILES];
106108 char *mfil, *ufil, *Ofil, *ofil, *omfil, *oufil, *console;
107 int ifilct = 0, fd, i, iunit, hwunit, no_m, no_u;
109 int ifilct = 0, fd, i, iunit, hwunit, no_m, no_u;
108110 int restore = 0;
109111
110112 set_progname(argv[0]);
116118 ifiles[0] = mfil = ufil = Ofil = ofil = omfil = oufil = NULL;
117119 iunit = hwunit = 0;
118120 no_m = no_u = 0;
119 console = NULL;
121 console = NULL;
120122
121123 /*
122124 * No getopt() here because of the -om etc options.
123125 */
124126 for (i = 1; i < argc; i++) {
125 if (!strcmp(argv[i], "-V")) {
126 print_version_and_exit();
127 } else if (!strcmp(argv[i], "-v")) {
128 verbose++;
129 } else if (!strcmp(argv[i], "-R")) {
130 restore = 1;
131 } else if (!strcmp(argv[i], "-C")) {
132 if (++i == argc || console)
133 usage();
134 console = argv[i];
135 } else if (!strcmp(argv[i], "-O")) {
136 if (++i == argc || Ofil)
137 usage();
138 Ofil = argv[i];
139 } else if (!strcmp(argv[i], "-o")) {
140 if (++i == argc || ofil)
141 usage();
142 ofil = argv[i];
143 } else if (!strcmp(argv[i], "-om")) {
144 if (++i == argc || omfil)
145 usage();
146 omfil = argv[i];
147 } else if (!strcmp(argv[i], "-ou")) {
148 if (++i == argc || oufil)
149 usage();
150 oufil = argv[i];
151 } else if (!strcmp(argv[i], "-m")) {
152 if (++i == argc || mfil)
153 usage();
154 if (!strcmp(argv[i], "none"))
155 no_m = 1;
156 else
157 mfil = argv[i];
158 } else if (!strcmp(argv[i], "-u")) {
159 if (++i == argc || ufil)
160 usage();
161 if (!strcmp(argv[i], "none"))
162 no_u = 1;
163 else
164 ufil = argv[i];
165 } else if (!strcmp(argv[i], "-f")) {
166 force = 1;
167 } else if (!strncmp(argv[i], "-h", 2)) {
168 hwunit = atoi(argv[i]+2);
169 if (hwunit <= 0 || hwunit > 32)
170 usage();
171 } else if (argv[i][0] == '-') {
172 iunit = atoi(argv[i]+1);
173 if(iunit <= 0 || iunit > 32)
174 usage();
175 } else {
176 if (ifilct == MAXIFILES) {
177 fprintf(stderr, _("setfont: too many input files\n"));
178 exit(EX_USAGE);
179 }
180 ifiles[ifilct++] = argv[i];
181 }
127 if (!strcmp(argv[i], "-V")) {
128 print_version_and_exit();
129 } else if (!strcmp(argv[i], "-v")) {
130 verbose++;
131 } else if (!strcmp(argv[i], "-R")) {
132 restore = 1;
133 } else if (!strcmp(argv[i], "-C")) {
134 if (++i == argc || console)
135 usage();
136 console = argv[i];
137 } else if (!strcmp(argv[i], "-O")) {
138 if (++i == argc || Ofil)
139 usage();
140 Ofil = argv[i];
141 } else if (!strcmp(argv[i], "-o")) {
142 if (++i == argc || ofil)
143 usage();
144 ofil = argv[i];
145 } else if (!strcmp(argv[i], "-om")) {
146 if (++i == argc || omfil)
147 usage();
148 omfil = argv[i];
149 } else if (!strcmp(argv[i], "-ou")) {
150 if (++i == argc || oufil)
151 usage();
152 oufil = argv[i];
153 } else if (!strcmp(argv[i], "-m")) {
154 if (++i == argc || mfil)
155 usage();
156 if (!strcmp(argv[i], "none"))
157 no_m = 1;
158 else
159 mfil = argv[i];
160 } else if (!strcmp(argv[i], "-u")) {
161 if (++i == argc || ufil)
162 usage();
163 if (!strcmp(argv[i], "none"))
164 no_u = 1;
165 else
166 ufil = argv[i];
167 } else if (!strcmp(argv[i], "-f")) {
168 force = 1;
169 } else if (!strncmp(argv[i], "-h", 2)) {
170 hwunit = atoi(argv[i] + 2);
171 if (hwunit <= 0 || hwunit > 32)
172 usage();
173 } else if (argv[i][0] == '-') {
174 iunit = atoi(argv[i] + 1);
175 if (iunit <= 0 || iunit > 32)
176 usage();
177 } else {
178 if (ifilct == MAXIFILES) {
179 fprintf(stderr, _("setfont: too many input files\n"));
180 exit(EX_USAGE);
181 }
182 ifiles[ifilct++] = argv[i];
183 }
182184 }
183185
184186 if (ifilct && restore) {
185 fprintf(stderr, _("setfont: cannot both restore from character ROM"
186 " and from file. Font unchanged.\n"));
187 exit(EX_USAGE);
187 fprintf(stderr, _("setfont: cannot both restore from character ROM"
188 " and from file. Font unchanged.\n"));
189 exit(EX_USAGE);
188190 }
189191
190192 if ((fd = getfd(console)) < 0)
191193 kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
192194
193195 int kd_mode = -1;
194 if (!ioctl(fd, KDGETMODE, &kd_mode) && (kd_mode == KD_GRAPHICS))
195 {
196 /*
197 * PIO_FONT will fail on a console which is in foreground and in KD_GRAPHICS mode.
198 * 2005-03-03, jw@suse.de.
199 */
200 if (verbose)
201 printf("setfont: graphics console %s skipped\n", console?console:"");
202 close(fd);
203 return 0;
204 }
196 if (!ioctl(fd, KDGETMODE, &kd_mode) && (kd_mode == KD_GRAPHICS)) {
197 /*
198 * PIO_FONT will fail on a console which is in foreground and in KD_GRAPHICS mode.
199 * 2005-03-03, jw@suse.de.
200 */
201 if (verbose)
202 printf("setfont: graphics console %s skipped\n", console ? console : "");
203 close(fd);
204 return 0;
205 }
205206
206207 if (!ifilct && !mfil && !ufil &&
207208 !Ofil && !ofil && !omfil && !oufil && !restore)
208 /* reset to some default */
209 ifiles[ifilct++] = "";
209 /* reset to some default */
210 ifiles[ifilct++] = "";
210211
211212 if (Ofil)
212 saveoldfontplusunicodemap(fd, Ofil);
213 saveoldfontplusunicodemap(fd, Ofil);
213214
214215 if (ofil)
215 saveoldfont(fd, ofil);
216 saveoldfont(fd, ofil);
216217
217218 if (omfil)
218 saveoldmap(fd, omfil);
219 saveoldmap(fd, omfil);
219220
220221 if (oufil)
221 saveunicodemap(fd, oufil);
222 saveunicodemap(fd, oufil);
222223
223224 if (mfil) {
224 loadnewmap(fd, mfil);
225 activatemap(fd);
226 no_m = 1;
225 loadnewmap(fd, mfil);
226 activatemap(fd);
227 no_m = 1;
227228 }
228229
229230 if (ufil)
230 no_u = 1;
231 no_u = 1;
231232
232233 if (restore)
233 restorefont(fd);
234 restorefont(fd);
234235
235236 if (ifilct)
236 loadnewfonts(fd, ifiles, ifilct, iunit, hwunit, no_m, no_u);
237 loadnewfonts(fd, ifiles, ifilct, iunit, hwunit, no_m, no_u);
237238
238239 if (ufil)
239 loadunicodemap(fd, ufil);
240 loadunicodemap(fd, ufil);
240241
241242 return 0;
242243 }
248249
249250 static void
250251 do_loadfont(int fd, char *inbuf, int width, int height, int hwunit,
251 int fontsize, char *filename) {
252 int fontsize, char *filename)
253 {
252254 unsigned char *buf;
253255 int i, buflen;
254 int bytewidth = (width+7)/8;
255 int charsize = height * bytewidth;
256 int kcharsize = 32 * bytewidth;
256 int bytewidth = (width + 7) / 8;
257 int charsize = height * bytewidth;
258 int kcharsize = 32 * bytewidth;
257259 int bad_video_erase_char = 0;
258260
259261 if (height < 1 || height > 32) {
269271 hwunit = height;
270272
271273 buflen = kcharsize * ((fontsize < 128) ? 128 : fontsize);
272 buf = xmalloc(buflen);
273 memset(buf,0,buflen);
274 buf = xmalloc(buflen);
275 memset(buf, 0, buflen);
274276
275277 for (i = 0; i < fontsize; i++)
276 memcpy(buf+(i*kcharsize), inbuf+(i*charsize), charsize);
278 memcpy(buf + (i * kcharsize), inbuf + (i * charsize), charsize);
277279
278280 /*
279281 * Due to a kernel bug, font position 32 is used
282284 */
283285 if (erase_mode) {
284286 for (i = 0; i < kcharsize; i++)
285 if (buf[32*kcharsize+i])
287 if (buf[32 * kcharsize + i])
286288 bad_video_erase_char = 1;
287289 if (bad_video_erase_char) {
288290 fprintf(stderr,
289 _("%s: font position 32 is nonblank\n"),
290 progname);
291 switch(erase_mode) {
292 case 3:
293 exit(EX_DATAERR);
294 case 2:
295 for (i = 0; i < kcharsize; i++)
296 buf[32*kcharsize+i] = 0;
297 fprintf(stderr, _("%s: wiped it\n"), progname);
298 break;
299 case 1:
300 fprintf(stderr,
301 _("%s: background will look funny\n"),
302 progname);
291 _("%s: font position 32 is nonblank\n"),
292 progname);
293 switch (erase_mode) {
294 case 3:
295 exit(EX_DATAERR);
296 case 2:
297 for (i = 0; i < kcharsize; i++)
298 buf[32 * kcharsize + i] = 0;
299 fprintf(stderr, _("%s: wiped it\n"), progname);
300 break;
301 case 1:
302 fprintf(stderr,
303 _("%s: background will look funny\n"),
304 progname);
303305 }
304306 fflush(stderr);
305307 sleep(2);
326328 }
327329
328330 static void
329 do_loadtable(int fd, struct unicode_list *uclistheads, int fontsize) {
331 do_loadtable(int fd, struct unicode_list *uclistheads, int fontsize)
332 {
330333 struct unimapdesc ud;
331334 struct unipair *up;
332335 int i, ct = 0, maxct;
336339 maxct = 0;
337340 for (i = 0; i < fontsize; i++) {
338341 ul = uclistheads[i].next;
339 while(ul) {
342 while (ul) {
340343 us = ul->seq;
341 if (us && ! us->next)
344 if (us && !us->next)
342345 maxct++;
343346 ul = ul->next;
344347 }
346349 up = xmalloc(maxct * sizeof(struct unipair));
347350 for (i = 0; i < fontsize; i++) {
348351 ul = uclistheads[i].next;
349 if (debug) printf ("char %03x:", i);
350 while(ul) {
352 if (debug)
353 printf("char %03x:", i);
354 while (ul) {
351355 us = ul->seq;
352 if (us && ! us->next) {
356 if (us && !us->next) {
353357 up[ct].unicode = us->uc;
354358 up[ct].fontpos = i;
355359 ct++;
356 if (debug) printf (" %04x", us->uc);
360 if (debug)
361 printf(" %04x", us->uc);
362 } else if (debug) {
363 printf(" seq: <");
364 while (us) {
365 printf(" %04x", us->uc);
366 us = us->next;
367 }
368 printf(" >");
357369 }
358 else
359 if (debug) {
360 printf (" seq: <");
361 while (us) {
362 printf (" %04x", us->uc);
363 us = us->next;
364 }
365 printf (" >");
366 }
367370 ul = ul->next;
368 if (debug) printf (",");
369 }
370 if (debug) printf ("\n");
371 if (debug)
372 printf(",");
373 }
374 if (debug)
375 printf("\n");
371376 }
372377 if (ct != maxct) {
373378 char *u = _("%s: bug in do_loadtable\n");
376381 }
377382
378383 if (verbose)
379 printf(_("Loading Unicode mapping table...\n"));
384 printf(_("Loading Unicode mapping table...\n"));
380385
381386 ud.entry_ct = ct;
382 ud.entries = up;
387 ud.entries = up;
383388 if (loadunimap(fd, NULL, &ud))
384389 exit(EX_OSERR);
385390 }
386391
387392 static void
388393 loadnewfonts(int fd, char **ifiles, int ifilct,
389 int iunit, int hwunit, int no_m, int no_u)
394 int iunit, int hwunit, int no_m, int no_u)
390395 {
391396 char *ifil, *inbuf, *fontbuf, *bigfontbuf;
392397 int inputlth, fontbuflth, fontsize, height, width, bytewidth;
402407
403408 /* several fonts that must be merged */
404409 /* We just concatenate the bitmaps - only allow psf fonts */
405 bigfontbuf = NULL;
410 bigfontbuf = NULL;
406411 bigfontbuflth = 0;
407 bigfontsize = 0;
408 uclistheads = NULL;
409 bigheight = 0;
410 bigwidth = 0;
411
412 for (i=0; i<ifilct; i++) {
412 bigfontsize = 0;
413 uclistheads = NULL;
414 bigheight = 0;
415 bigwidth = 0;
416
417 for (i = 0; i < ifilct; i++) {
413418 ifil = ifiles[i];
414419 if (findfont(ifil, &fp) && findpartialfont(ifil, &fp)) {
415420 fprintf(stderr, _("Cannot open font file %s\n"), ifil);
418423
419424 inbuf = fontbuf = NULL;
420425 inputlth = fontbuflth = 0;
421 fontsize = 0;
422
423 if(readpsffont(fp.fd, &inbuf, &inputlth, &fontbuf, &fontbuflth,
424 &width, &fontsize, bigfontsize,
425 no_u ? NULL : &uclistheads)) {
426 fontsize = 0;
427
428 if (readpsffont(fp.fd, &inbuf, &inputlth, &fontbuf, &fontbuflth,
429 &width, &fontsize, bigfontsize,
430 no_u ? NULL : &uclistheads)) {
426431 fprintf(stderr, _("When loading several fonts, all "
427 "must be psf fonts - %s isn't\n"),
428 fp.pathname);
432 "must be psf fonts - %s isn't\n"),
433 fp.pathname);
429434 lk_fpclose(&fp);
430435 exit(EX_DATAERR);
431436 }
432 lk_fpclose(&fp); // avoid zombies, jw@suse.de (#88501)
433 bytewidth = (width+7) / 8;
434 height = fontbuflth / (bytewidth * fontsize);
437 lk_fpclose(&fp); // avoid zombies, jw@suse.de (#88501)
438 bytewidth = (width + 7) / 8;
439 height = fontbuflth / (bytewidth * fontsize);
435440 if (verbose)
436441 printf(_("Read %d-char %dx%d font from file %s\n"),
437442 fontsize, width, height, fp.pathname);
440445 bigheight = height;
441446 else if (bigheight != height) {
442447 fprintf(stderr, _("When loading several fonts, all "
443 "must have the same height\n"));
448 "must have the same height\n"));
444449 exit(EX_DATAERR);
445450 }
446451 if (bigwidth == 0)
447452 bigwidth = width;
448453 else if (bigwidth != width) {
449454 fprintf(stderr, _("When loading several fonts, all "
450 "must have the same width\n"));
455 "must have the same width\n"));
451456 exit(EX_DATAERR);
452457 }
453458
454459 bigfontsize += fontsize;
455460 bigfontbuflth += fontbuflth;
456461 bigfontbuf = xrealloc(bigfontbuf, bigfontbuflth);
457 memcpy(bigfontbuf+bigfontbuflth-fontbuflth,
462 memcpy(bigfontbuf + bigfontbuflth - fontbuflth,
458463 fontbuf, fontbuflth);
459464 }
460465 do_loadfont(fd, bigfontbuf, bigwidth, bigheight, hwunit,
461 bigfontsize, NULL);
466 bigfontsize, NULL);
462467 free(bigfontbuf);
463468
464469 if (uclistheads && !no_u)
478483 if (!*ifil) {
479484 /* try to find some default file */
480485
481 def = 1; /* maybe also load default unimap */
486 def = 1; /* maybe also load default unimap */
482487
483488 if (iunit < 0 || iunit > 32)
484489 iunit = 0;
510515
511516 inbuf = fontbuf = NULL;
512517 inputlth = fontbuflth = fontsize = 0;
513 width = 8;
514 uclistheads = NULL;
515 if(readpsffont(fp.fd, &inbuf, &inputlth, &fontbuf, &fontbuflth,
516 &width, &fontsize, 0,
517 no_u ? NULL : &uclistheads) == 0) {
518 width = 8;
519 uclistheads = NULL;
520 if (readpsffont(fp.fd, &inbuf, &inputlth, &fontbuf, &fontbuflth,
521 &width, &fontsize, 0,
522 no_u ? NULL : &uclistheads) == 0) {
518523 lk_fpclose(&fp);
519524 /* we've got a psf font */
520 bytewidth = (width+7) / 8;
521 height = fontbuflth / (bytewidth * fontsize);
525 bytewidth = (width + 7) / 8;
526 height = fontbuflth / (bytewidth * fontsize);
522527
523528 do_loadfont(fd, fontbuf, width, height, hwunit,
524 fontsize, fp.pathname);
529 fontsize, fp.pathname);
525530 if (uclistheads && !no_u)
526531 do_loadtable(fd, uclistheads, fontsize);
527532 #if 1
530535 #endif
531536 return;
532537 }
533 lk_fpclose(&fp); // avoid zombies, jw@suse.de (#88501)
538 lk_fpclose(&fp); // avoid zombies, jw@suse.de (#88501)
534539
535540 /* instructions to combine fonts? */
536 { char *combineheader = "# combine partial fonts\n";
537 int chlth = strlen(combineheader);
538 char *p, *q;
539 if (inputlth >= chlth && !strncmp(inbuf, combineheader, chlth)) {
540 char *ifiles[MAXIFILES];
541 int ifilct = 0;
542 q = inbuf + chlth;
543 while(q < inbuf + inputlth) {
544 p = q;
545 while (q < inbuf+inputlth && *q != '\n')
546 q++;
547 if (q == inbuf+inputlth) {
548 fprintf(stderr,
549 _("No final newline in combine file\n"));
550 exit(EX_DATAERR);
551 }
552 *q++ = 0;
553 if (ifilct == MAXIFILES) {
554 fprintf(stderr,
555 _("Too many files to combine\n"));
556 exit(EX_DATAERR);
557 }
558 ifiles[ifilct++] = p;
559 }
560 /* recursive call */
561 loadnewfonts(fd, ifiles, ifilct, iunit, hwunit, no_m, no_u);
562 return;
563 }
541 {
542 char *combineheader = "# combine partial fonts\n";
543 int chlth = strlen(combineheader);
544 char *p, *q;
545 if (inputlth >= chlth && !strncmp(inbuf, combineheader, chlth)) {
546 char *ifiles[MAXIFILES];
547 int ifilct = 0;
548 q = inbuf + chlth;
549 while (q < inbuf + inputlth) {
550 p = q;
551 while (q < inbuf + inputlth && *q != '\n')
552 q++;
553 if (q == inbuf + inputlth) {
554 fprintf(stderr,
555 _("No final newline in combine file\n"));
556 exit(EX_DATAERR);
557 }
558 *q++ = 0;
559 if (ifilct == MAXIFILES) {
560 fprintf(stderr,
561 _("Too many files to combine\n"));
562 exit(EX_DATAERR);
563 }
564 ifiles[ifilct++] = p;
565 }
566 /* recursive call */
567 loadnewfonts(fd, ifiles, ifilct, iunit, hwunit, no_m, no_u);
568 return;
569 }
564570 }
565571
566572 /* file with three code pages? */
567573 if (inputlth == 9780) {
568 offset = position_codepage(iunit);
569 height = iunit;
574 offset = position_codepage(iunit);
575 height = iunit;
570576 fontsize = 256;
571 width = 8;
577 width = 8;
572578 } else if (inputlth == 32768) {
573579 /* restorefont -w writes a SVGA font to file
574580 restorefont -r restores it
577583 and it always is, there is no default font that is saved,
578584 so probably the second half is always garbage. */
579585 fprintf(stderr, _("Hmm - a font from restorefont? "
580 "Using the first half.\n"));
581 inputlth = 16384; /* ignore rest */
586 "Using the first half.\n"));
587 inputlth = 16384; /* ignore rest */
582588 fontsize = 512;
583 offset = 0;
584 width = 8;
585 height = 32;
589 offset = 0;
590 width = 8;
591 height = 32;
586592 if (!hwunit)
587593 hwunit = 16;
588594 } else {
597603 exit(EX_DATAERR);
598604 }
599605 fontsize = 256;
600 width = 8;
601 height = inputlth/256;
602 }
603 do_loadfont(fd, inbuf+offset, width, height, hwunit, fontsize,
604 fp.pathname);
606 width = 8;
607 height = inputlth / 256;
608 }
609 do_loadfont(fd, inbuf + offset, width, height, hwunit, fontsize,
610 fp.pathname);
605611 }
606612
607613 static int
608 position_codepage(int iunit) {
609 int offset;
614 position_codepage(int iunit)
615 {
616 int offset;
610617
611618 /* code page: first 40 bytes, then 8x16 font,
612619 then 6 bytes, then 8x14 font,
613620 then 6 bytes, then 8x8 font */
614621
615622 if (!iunit) {
616 fprintf(stderr,
617 _("This file contains 3 fonts: 8x8, 8x14 and 8x16."
618 " Please indicate\n"
619 "using an option -8 or -14 or -16 "
620 "which one you want loaded.\n"));
621 exit(EX_USAGE);
623 fprintf(stderr,
624 _("This file contains 3 fonts: 8x8, 8x14 and 8x16."
625 " Please indicate\n"
626 "using an option -8 or -14 or -16 "
627 "which one you want loaded.\n"));
628 exit(EX_USAGE);
622629 }
623630 switch (iunit) {
624 case 8:
625 offset = 7732; break;
626 case 14:
627 offset = 4142; break;
628 case 16:
629 offset = 40; break;
630 default:
631 fprintf(stderr, _("You asked for font size %d, "
632 "but only 8, 14, 16 are possible here.\n"),
633 iunit);
634 exit(EX_USAGE);
631 case 8:
632 offset = 7732;
633 break;
634 case 14:
635 offset = 4142;
636 break;
637 case 16:
638 offset = 40;
639 break;
640 default:
641 fprintf(stderr, _("You asked for font size %d, "
642 "but only 8, 14, 16 are possible here.\n"),
643 iunit);
644 exit(EX_USAGE);
635645 }
636646 return offset;
637647 }
638648
639649 static void
640650 do_saveoldfont(int fd, char *ofil, FILE *fpo, int unimap_follows,
641 int *count, int *utf8) {
651 int *count, int *utf8)
652 {
642653
643654 /* this is the max font size the kernel is willing to handle */
644 #define MAXFONTSIZE 65536
655 #define MAXFONTSIZE 65536
645656 unsigned char buf[MAXFONTSIZE];
646657
647658 int i, ct, width, height, bytewidth, charsize, kcharsize;
648659
649 ct = sizeof(buf)/(32*32/8); /* max size 32x32, 8 bits/byte */
660 ct = sizeof(buf) / (32 * 32 / 8); /* max size 32x32, 8 bits/byte */
650661 if (getfont(fd, buf, &ct, &width, &height))
651662 exit(EX_OSERR);
652663
653664 /* save as efficiently as possible */
654665 bytewidth = (width + 7) / 8;
655 height = font_charheight(buf, ct, width);
656 charsize = height * bytewidth;
666 height = font_charheight(buf, ct, width);
667 charsize = height * bytewidth;
657668 kcharsize = 32 * bytewidth;
658669
659 /* Do we need a psf header? */
660 /* Yes if ct==512 - otherwise we cannot distinguish
670 /* Do we need a psf header? */
671 /* Yes if ct==512 - otherwise we cannot distinguish
661672 a 512-char 8x8 and a 256-char 8x16 font. */
662 #define ALWAYS_PSF_HEADER 1
673 #define ALWAYS_PSF_HEADER 1
663674
664675 if (ct != 256 || width != 8 || unimap_follows || ALWAYS_PSF_HEADER) {
665676 int psftype = 1;
666 int flags = 0;
677 int flags = 0;
667678
668679 if (unimap_follows)
669680 flags |= WPSFH_HASTAB;
670 writepsffontheader (fpo, width, height, ct, &psftype, flags);
681 writepsffontheader(fpo, width, height, ct, &psftype, flags);
671682 if (utf8)
672683 *utf8 = (psftype == 2);
673684 }
676687 fprintf(stderr, _("Found nothing to save\n"));
677688 } else {
678689 for (i = 0; i < ct; i++) {
679 if (fwrite(buf+(i*kcharsize), charsize, 1, fpo) != 1) {
690 if (fwrite(buf + (i * kcharsize), charsize, 1, fpo) != 1) {
680691 fprintf(stderr, _("Cannot write font file"));
681692 exit(EX_IOERR);
682693 }
692703 }
693704
694705 static void
695 saveoldfont(int fd, char *ofil) {
696 FILE *fpo;
697
698 if((fpo = fopen(ofil, "w")) == NULL) {
699 perror(ofil);
700 exit(EX_CANTCREAT);
701 }
702 do_saveoldfont(fd, ofil, fpo, 0, NULL, NULL);
703 fclose(fpo);
706 saveoldfont(int fd, char *ofil)
707 {
708 FILE *fpo;
709
710 if ((fpo = fopen(ofil, "w")) == NULL) {
711 perror(ofil);
712 exit(EX_CANTCREAT);
713 }
714 do_saveoldfont(fd, ofil, fpo, 0, NULL, NULL);
715 fclose(fpo);
704716 }
705717
706718 static void
707 saveoldfontplusunicodemap(int fd, char *Ofil) {
708 FILE *fpo;
709 int ct;
710 int utf8 = 0;
711
712 if((fpo = fopen(Ofil, "w")) == NULL) {
713 perror(Ofil);
714 exit(EX_CANTCREAT);
715 }
716 ct = 0;
717 do_saveoldfont(fd, Ofil, fpo, 1, &ct, &utf8);
718 appendunicodemap(fd, fpo, ct, utf8);
719 fclose(fpo);
719 saveoldfontplusunicodemap(int fd, char *Ofil)
720 {
721 FILE *fpo;
722 int ct;
723 int utf8 = 0;
724
725 if ((fpo = fopen(Ofil, "w")) == NULL) {
726 perror(Ofil);
727 exit(EX_CANTCREAT);
728 }
729 ct = 0;
730 do_saveoldfont(fd, Ofil, fpo, 1, &ct, &utf8);
731 appendunicodemap(fd, fpo, ct, utf8);
732 fclose(fpo);
720733 }
721734
722735 /* Only on the current console? On all allocated consoles? */
726739 /* For the moment: only the current console, only the G0 set */
727740
728741 static void
729 send_escseq(int fd, char *seq, int n) {
730 if (write(fd, seq, n) != n) /* maybe fd is read-only */
742 send_escseq(int fd, char *seq, int n)
743 {
744 if (write(fd, seq, n) != n) /* maybe fd is read-only */
731745 printf("%s", seq);
732746 }
733747
734 void
735 activatemap(int fd) {
748 void activatemap(int fd)
749 {
736750 send_escseq(fd, "\033(K", 3);
737751 }
738752
739 void
740 disactivatemap(int fd) {
753 void disactivatemap(int fd)
754 {
741755 send_escseq(fd, "\033(B", 3);
742756 }
1717 #include "version.h"
1818 #include "kbd_error.h"
1919
20 static void __attribute__ ((noreturn))
21 usage(char *s) {
20 static void __attribute__((noreturn))
21 usage(char *s)
22 {
2223 fprintf(stderr, "setkeycode: %s\n", s);
2324 fprintf(stderr, _(
24 "usage: setkeycode scancode keycode ...\n"
25 " (where scancode is either xx or e0xx, given in hexadecimal,\n"
26 " and keycode is given in decimal)\n"));
25 "usage: setkeycode scancode keycode ...\n"
26 " (where scancode is either xx or e0xx, given in hexadecimal,\n"
27 " and keycode is given in decimal)\n"));
2728 exit(EXIT_FAILURE);
2829 }
2930
30 int
31 main(int argc, char **argv) {
31 int main(int argc, char **argv)
32 {
3233 char *ep;
3334 int fd;
3435 struct kbkeycode a;
4950 kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
5051
5152 while (argc > 2) {
52 a.keycode = atoi(argv[2]);
53 a.keycode = atoi(argv[2]);
5354 a.scancode = strtol(argv[1], &ep, 16);
5455 if (*ep)
5556 usage(_("error reading scancode"));
5657 if (a.scancode >= 0xe000) {
5758 a.scancode -= 0xe000;
58 a.scancode += 128; /* some kernels needed +256 */
59 a.scancode += 128; /* some kernels needed +256 */
5960 }
6061 #if 0
6162 /* Test is OK up to 2.5.31--later kernels have more keycodes */
6768 (a.scancode > 255 || a.keycode > 239)
6869 but we can leave testing to the kernel. */
6970 #endif
70 if (ioctl(fd,KDSETKEYCODE,&a)) {
71 if (ioctl(fd, KDSETKEYCODE, &a)) {
7172 kbd_error(EXIT_FAILURE, errno,
72 _("failed to set scancode %x to keycode %d: ioctl KDSETKEYCODE"),
73 a.scancode, a.keycode);
73 _("failed to set scancode %x to keycode %d: ioctl KDSETKEYCODE"),
74 a.scancode, a.keycode);
7475 }
7576 argc -= 2;
7677 argv += 2;
1717 #include "version.h"
1818 #include "kbd_error.h"
1919
20 static void __attribute__ ((noreturn))
20 static void __attribute__((noreturn))
2121 usage(void)
2222 {
23 fprintf(stderr, _(
24 "Usage:\n"
25 " setleds [-v] [-L] [-D] [-F] [[+|-][ num | caps | scroll %s]]\n"
26 "Thus,\n"
27 " setleds +caps -num\n"
28 "will set CapsLock, clear NumLock and leave ScrollLock unchanged.\n"
29 "The settings before and after the change (if any) are reported\n"
30 "when the -v option is given or when no change is requested.\n"
31 "Normally, setleds influences the vt flag settings\n"
32 "(and these are usually reflected in the leds).\n"
33 "With -L, setleds only sets the leds, and leaves the flags alone.\n"
34 "With -D, setleds sets both the flags and the default flags, so\n"
35 "that a subsequent reset will not change the flags.\n"
36 ),
23 fprintf(stderr, _(
24 "Usage:\n"
25 " setleds [-v] [-L] [-D] [-F] [[+|-][ num | caps | scroll %s]]\n"
26 "Thus,\n"
27 " setleds +caps -num\n"
28 "will set CapsLock, clear NumLock and leave ScrollLock unchanged.\n"
29 "The settings before and after the change (if any) are reported\n"
30 "when the -v option is given or when no change is requested.\n"
31 "Normally, setleds influences the vt flag settings\n"
32 "(and these are usually reflected in the leds).\n"
33 "With -L, setleds only sets the leds, and leaves the flags alone.\n"
34 "With -D, setleds sets both the flags and the default flags, so\n"
35 "that a subsequent reset will not change the flags.\n"),
3736 #ifdef __sparc__
38 "| compose "
39 #else
40 ""
41 #endif
42 );
43 exit(EXIT_FAILURE);
37 "| compose "
38 #else
39 ""
40 #endif
41 );
42 exit(EXIT_FAILURE);
4443 }
4544
4645 #define onoff(a) ((a) ? _("on ") : _("off"))
4746
4847 /* report the bits, in the order seen on the (my) keyboard */
49 #define LED_NLOCK 1
48 #define LED_NLOCK 1
5049 #define LED_CMPOSE 2
5150 #define LED_SCRLCK 4
52 #define LED_CLOCK 8
53
54 static void
55 sunreport(int leds) {
51 #define LED_CLOCK 8
52
53 static void
54 sunreport(int leds)
55 {
5656 printf("NumLock %s Compose %s ScrollLock %s CapsLock %s\n",
5757 onoff(leds & LED_NLOCK),
5858 onoff(leds & LED_CMPOSE),
6161 }
6262
6363 static void
64 report(int leds) {
65 printf("NumLock %s CapsLock %s ScrollLock %s\n",
64 report(int leds)
65 {
66 printf("NumLock %s CapsLock %s ScrollLock %s\n",
6667 onoff(leds & LED_NUM),
6768 onoff(leds & LED_CAP),
6869 onoff(leds & LED_SCR));
6970 }
7071
7172 struct led {
72 char *name;
73 int bit;
74 int sunbit;
73 char *name;
74 int bit;
75 int sunbit;
7576 } leds[] = {
76 { "scroll", LED_SCR, LED_SCRLCK },
77 { "num", LED_NUM, LED_NLOCK },
78 { "caps", LED_CAP, LED_CLOCK },
77 { "scroll", LED_SCR, LED_SCRLCK },
78 { "num", LED_NUM, LED_NLOCK },
79 { "caps", LED_CAP, LED_CLOCK },
7980 #ifdef __sparc__
80 { "compose", 0, LED_CMPOSE }
81 { "compose", 0, LED_CMPOSE }
8182 #endif
8283 };
8384
8485 static void
85 getleds(char *cur_leds) {
86 if (ioctl(0, KDGETLED, cur_leds)) {
87 kbd_error(EXIT_FAILURE, errno, _("Error reading current led setting. "
88 "Maybe stdin is not a VT?: "
89 "ioctl KDGETLED"));
90 }
86 getleds(char *cur_leds)
87 {
88 if (ioctl(0, KDGETLED, cur_leds)) {
89 kbd_error(EXIT_FAILURE, errno, _("Error reading current led setting. "
90 "Maybe stdin is not a VT?: "
91 "ioctl KDGETLED"));
92 }
9193 }
9294
9395 static int
94 setleds(char cur_leds) {
95 if (ioctl(0, KDSETLED, cur_leds)) {
96 kbd_warning(errno, "ioctl KDSETLED");
97 return -1;
98 }
99 return 0;
100 }
101
102 static void
103 getflags(char *flags) {
104 if (ioctl(0, KDGKBLED, flags)) {
105 kbd_error(EXIT_FAILURE, errno, _("Error reading current flags setting. "
106 "Maybe you are not on the console?: "
107 "ioctl KDGKBLED"));
108 }
96 setleds(char cur_leds)
97 {
98 if (ioctl(0, KDSETLED, cur_leds)) {
99 kbd_warning(errno, "ioctl KDSETLED");
100 return -1;
101 }
102 return 0;
103 }
104
105 static void
106 getflags(char *flags)
107 {
108 if (ioctl(0, KDGKBLED, flags)) {
109 kbd_error(EXIT_FAILURE, errno, _("Error reading current flags setting. "
110 "Maybe you are not on the console?: "
111 "ioctl KDGKBLED"));
112 }
109113 }
110114
111115 static int sunkbdfd = -1;
112116
113117 #ifndef KIOCGLED
114 #define arg_state __attribute__ ((unused))
118 #define arg_state __attribute__((unused))
115119 #else
116120 #define arg_state
117121 #endif
118122
119123 static void
120 sungetleds(arg_state char *cur_leds) {
124 sungetleds(arg_state char *cur_leds)
125 {
121126 #ifdef KIOCGLED
122 if (ioctl(sunkbdfd, KIOCGLED, cur_leds)) {
123 kbd_error(EXIT_FAILURE, errno, _("Error reading current led setting from /dev/kbd: "
124 "ioctl KIOCGLED"));
125 }
126 #else
127 kbd_error(EXIT_FAILURE, 0, _("KIOCGLED unavailable?\n"));
127 if (ioctl(sunkbdfd, KIOCGLED, cur_leds)) {
128 kbd_error(EXIT_FAILURE, errno, _("Error reading current led setting from /dev/kbd: "
129 "ioctl KIOCGLED"));
130 }
131 #else
132 kbd_error(EXIT_FAILURE, 0, _("KIOCGLED unavailable?\n"));
128133 #endif
129134 }
130135
131136 #ifndef KIOCSLED
132 #define arg_state __attribute__ ((unused))
137 #define arg_state __attribute__((unused))
133138 #else
134139 #define arg_state
135140 #endif
136141
137142 static void
138 sunsetleds(arg_state char *cur_leds) {
143 sunsetleds(arg_state char *cur_leds)
144 {
139145 #ifdef KIOCSLED
140 if (ioctl(sunkbdfd, KIOCSLED, cur_leds)) {
141 kbd_error(EXIT_FAILURE, errno, _("Error reading current led setting from /dev/kbd: "
142 "ioctl KIOCSLED"));
143 }
144 #else
145 kbd_error(EXIT_FAILURE, 0, _("KIOCSLED unavailable?\n"));
146 #endif
147 }
148
149 int
150 main(int argc, char **argv) {
151 int optL = 0, optD = 0, optF = 0, verbose = 0;
152 char oleds, nleds, oflags, nflags, odefflags, ndefflags;
153 char nval, ndef, sign;
154 char osunleds = 0, nsunleds, nsunval, nsundef;
155 char *ap;
156 struct led *lp;
157
158 set_progname(argv[0]);
159
160 setlocale(LC_ALL, "");
161 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
162 textdomain(PACKAGE_NAME);
163
164 if (argc == 2 && (!strcmp("-V", argv[1]) || !strcmp("--version", argv[1])))
165 print_version_and_exit();
146 if (ioctl(sunkbdfd, KIOCSLED, cur_leds)) {
147 kbd_error(EXIT_FAILURE, errno, _("Error reading current led setting from /dev/kbd: "
148 "ioctl KIOCSLED"));
149 }
150 #else
151 kbd_error(EXIT_FAILURE, 0, _("KIOCSLED unavailable?\n"));
152 #endif
153 }
154
155 int main(int argc, char **argv)
156 {
157 int optL = 0, optD = 0, optF = 0, verbose = 0;
158 char oleds, nleds, oflags, nflags, odefflags, ndefflags;
159 char nval, ndef, sign;
160 char osunleds = 0, nsunleds, nsunval, nsundef;
161 char *ap;
162 struct led *lp;
163
164 set_progname(argv[0]);
165
166 setlocale(LC_ALL, "");
167 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
168 textdomain(PACKAGE_NAME);
169
170 if (argc == 2 && (!strcmp("-V", argv[1]) || !strcmp("--version", argv[1])))
171 print_version_and_exit();
166172
167173 #ifdef __sparc__
168 if ((sunkbdfd = open("/dev/kbd", O_RDONLY)) < 0) {
169 kbd_error(EXIT_FAILURE, errno, "open /dev/kbd");
170 /* exit(1); */
171 }
172 #endif
173
174 getflags(&oflags);
175 getleds(&oleds);
176 if (sunkbdfd >= 0)
177 sungetleds(&osunleds);
178
179 while (argc > 1) {
180 if (!strcmp("-L", argv[1]))
181 optL = 1;
182 else if (!strcmp("-D", argv[1]))
183 optD = 1;
184 else if (!strcmp("-F", argv[1]))
185 optF = 1;
186 else if (!strcmp("-v", argv[1]))
187 verbose = 1;
188 else
189 break;
190 argc--;
191 argv++;
192 }
193
194 odefflags = ndefflags = ((oflags >> 4) & 7);
195 oflags = nflags = (oflags & 7);
196
197 if (argc <= 1) {
174 if ((sunkbdfd = open("/dev/kbd", O_RDONLY)) < 0) {
175 kbd_error(EXIT_FAILURE, errno, "open /dev/kbd");
176 /* exit(1); */
177 }
178 #endif
179
180 getflags(&oflags);
181 getleds(&oleds);
182 if (sunkbdfd >= 0)
183 sungetleds(&osunleds);
184
185 while (argc > 1) {
186 if (!strcmp("-L", argv[1]))
187 optL = 1;
188 else if (!strcmp("-D", argv[1]))
189 optD = 1;
190 else if (!strcmp("-F", argv[1]))
191 optF = 1;
192 else if (!strcmp("-v", argv[1]))
193 verbose = 1;
194 else
195 break;
196 argc--;
197 argv++;
198 }
199
200 odefflags = ndefflags = ((oflags >> 4) & 7);
201 oflags = nflags = (oflags & 7);
202
203 if (argc <= 1) {
204 if (optL) {
205 nleds = 0xff;
206 if (setleds(nleds)) {
207 kbd_error(EXIT_FAILURE, 0, _("Error resetting ledmode\n"));
208 }
209 }
210
211 /* If nothing to do, report, even if not verbose */
212 if (!optD && !optL && !optF)
213 optD = optL = optF = 1;
214 if (optD) {
215 printf(_("Current default flags: "));
216 report(odefflags);
217 }
218 if (optF) {
219 printf(_("Current flags: "));
220 report(oflags & 07);
221 }
222 if (optL) {
223 printf(_("Current leds: "));
224 if (sunkbdfd >= 0)
225 sunreport(osunleds);
226 else
227 report(oleds);
228 }
229 exit(EXIT_SUCCESS);
230 }
231
232 if (!optL)
233 optF = 1;
234 nval = 0;
235 ndef = 0;
236 nsunval = 0;
237 nsundef = 0;
238
239 while (--argc) {
240 ap = *++argv;
241 sign = 1; /* by default: set */
242 if (*ap == '+')
243 ap++;
244 else if (*ap == '-') {
245 sign = 0;
246 ap++;
247 }
248 for (lp = leds; (unsigned)(lp - leds) < sizeof(leds) / sizeof(leds[0]); lp++) {
249 if (!strcmp(ap, lp->name)) {
250 if (sign) {
251 nval |= lp->bit;
252 nsunval |= lp->sunbit;
253 }
254 ndef |= lp->bit;
255 nsundef |= lp->sunbit;
256 goto nxtarg;
257 }
258 }
259 fprintf(stderr, _("unrecognized argument: _%s_\n\n"), ap);
260 usage();
261
262 nxtarg:;
263 }
264
265 if (optD) {
266 ndefflags = (odefflags & ~ndef) | nval;
267 if (verbose) {
268 printf(_("Old default flags: "));
269 report(odefflags);
270 printf(_("New default flags: "));
271 report(ndefflags);
272 }
273 }
274 if (optF) {
275 nflags = ((oflags & ~ndef) | nval);
276 if (verbose) {
277 printf(_("Old flags: "));
278 report(oflags & 07);
279 printf(_("New flags: "));
280 report(nflags & 07);
281 }
282 }
283 if (optD || optF) {
284 if (ioctl(0, KDSKBLED, (ndefflags << 4) | nflags)) {
285 kbd_error(EXIT_FAILURE, errno, "ioctl KDSKBLED");
286 }
287 }
198288 if (optL) {
199 nleds = 0xff;
200 if (setleds(nleds)) {
201 kbd_error(EXIT_FAILURE, 0, _("Error resetting ledmode\n"));
202 }
203 }
204
205 /* If nothing to do, report, even if not verbose */
206 if (!optD && !optL && !optF)
207 optD = optL = optF = 1;
208 if (optD) {
209 printf(_("Current default flags: "));
210 report(odefflags);
211 }
212 if (optF) {
213 printf(_("Current flags: "));
214 report(oflags & 07);
215 }
216 if (optL) {
217 printf(_("Current leds: "));
218 if (sunkbdfd >= 0)
219 sunreport(osunleds);
220 else
221 report(oleds);
289 if (sunkbdfd >= 0) {
290 nsunleds = (osunleds & ~nsundef) | nsunval;
291 if (verbose) {
292 printf(_("Old leds: "));
293 sunreport(osunleds);
294 printf(_("New leds: "));
295 sunreport(nsunleds);
296 }
297 sunsetleds(&nsunleds);
298 } else {
299 nleds = (oleds & ~ndef) | nval;
300 if (verbose) {
301 printf(_("Old leds: "));
302 report(oleds);
303 printf(_("New leds: "));
304 report(nleds);
305 }
306 if (setleds(nleds))
307 exit(EXIT_FAILURE);
308 }
222309 }
223310 exit(EXIT_SUCCESS);
224 }
225
226 if (!optL)
227 optF = 1;
228 nval = 0;
229 ndef = 0;
230 nsunval = 0;
231 nsundef = 0;
232
233 while(--argc) {
234 ap = *++argv;
235 sign = 1; /* by default: set */
236 if(*ap == '+')
237 ap++;
238 else if(*ap == '-') {
239 sign = 0;
240 ap++;
241 }
242 for (lp = leds; (unsigned) (lp-leds) < sizeof(leds)/sizeof(leds[0]); lp++) {
243 if(!strcmp(ap, lp->name)) {
244 if(sign) {
245 nval |= lp->bit;
246 nsunval |= lp->sunbit;
247 }
248 ndef |= lp->bit;
249 nsundef |= lp->sunbit;
250 goto nxtarg;
251 }
252 }
253 fprintf(stderr, _("unrecognized argument: _%s_\n\n"), ap);
254 usage();
255
256 nxtarg: ;
257 }
258
259 if (optD) {
260 ndefflags = (odefflags & ~ndef) | nval;
261 if (verbose) {
262 printf(_("Old default flags: "));
263 report(odefflags);
264 printf(_("New default flags: "));
265 report(ndefflags);
266 }
267 }
268 if (optF) {
269 nflags = ((oflags & ~ndef) | nval);
270 if (verbose) {
271 printf(_("Old flags: "));
272 report(oflags & 07);
273 printf(_("New flags: "));
274 report(nflags & 07);
275 }
276 }
277 if (optD || optF) {
278 if (ioctl(0, KDSKBLED, (ndefflags << 4) | nflags)) {
279 kbd_error(EXIT_FAILURE, errno, "ioctl KDSKBLED");
280 }
281 }
282 if (optL) {
283 if (sunkbdfd >= 0) {
284 nsunleds = (osunleds & ~nsundef) | nsunval;
285 if (verbose) {
286 printf(_("Old leds: "));
287 sunreport(osunleds);
288 printf(_("New leds: "));
289 sunreport(nsunleds);
290 }
291 sunsetleds(&nsunleds);
292 } else {
293 nleds = (oleds & ~ndef) | nval;
294 if (verbose) {
295 printf(_("Old leds: "));
296 report(oleds);
297 printf(_("New leds: "));
298 report(nleds);
299 }
300 if (setleds(nleds))
301 exit(EXIT_FAILURE);
302 }
303 }
304 exit(EXIT_SUCCESS);
305 }
311 }
1616 #include "nls.h"
1717 #include "kbd_error.h"
1818
19 int
20 main(int argc, char **argv){
19 int main(int argc, char **argv)
20 {
2121 int fd, cons;
22 struct { char fn, subarg; } arg;
22 struct {
23 char fn, subarg;
24 } arg;
2325
2426 setlocale(LC_ALL, "");
2527 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
2830 if (argc == 2)
2931 cons = atoi(argv[1]);
3032 else
31 cons = 0; /* current console */
33 cons = 0; /* current console */
3234
3335 if ((fd = getfd(NULL)) < 0)
3436 kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
3537
36 arg.fn = 11; /* redirect kernel messages */
37 arg.subarg = cons; /* to specified console */
38 arg.fn = 11; /* redirect kernel messages */
39 arg.subarg = cons; /* to specified console */
3840 if (ioctl(fd, TIOCLINUX, &arg)) {
3941 kbd_error(EXIT_FAILURE, errno, "TIOCLINUX");
4042 }
1616 #include "version.h"
1717 #include "kbd_error.h"
1818
19 static void __attribute__ ((noreturn))
19 static void __attribute__((noreturn))
2020 usage(void)
2121 {
22 fprintf(stderr, _(
23 "Usage:\n"
24 " setmetamode [ metabit | meta | bit | escprefix | esc | prefix ]\n"
25 "Each vt has his own copy of this bit. Use\n"
26 " setmetamode [arg] < /dev/ttyn\n"
27 "to change the settings of another vt.\n"
28 "The setting before and after the change are reported.\n"
29 ));
30 exit(EXIT_FAILURE);
22 fprintf(stderr, _(
23 "Usage:\n"
24 " setmetamode [ metabit | meta | bit | escprefix | esc | prefix ]\n"
25 "Each vt has his own copy of this bit. Use\n"
26 " setmetamode [arg] < /dev/ttyn\n"
27 "to change the settings of another vt.\n"
28 "The setting before and after the change are reported.\n"));
29 exit(EXIT_FAILURE);
3130 }
3231
3332 static void
34 report(int meta) {
35 char *s;
33 report(int meta)
34 {
35 char *s;
3636
37 switch(meta) {
38 case K_METABIT:
39 s = _("Meta key sets high order bit\n");
40 break;
41 case K_ESCPREFIX:
42 s = _("Meta key gives Esc prefix\n");
43 break;
44 default:
45 s = _("Strange mode for Meta key?\n");
46 }
47 printf("%s", s);
37 switch (meta) {
38 case K_METABIT:
39 s = _("Meta key sets high order bit\n");
40 break;
41 case K_ESCPREFIX:
42 s = _("Meta key gives Esc prefix\n");
43 break;
44 default:
45 s = _("Strange mode for Meta key?\n");
46 }
47 printf("%s", s);
4848 }
4949
5050 struct meta {
51 char *name;
52 int val;
51 char *name;
52 int val;
5353 } metas[] = {
54 { "metabit", K_METABIT },
55 { "meta", K_METABIT },
56 { "bit", K_METABIT },
57 { "escprefix", K_ESCPREFIX },
58 { "esc", K_ESCPREFIX },
59 { "prefix", K_ESCPREFIX }
54 { "metabit", K_METABIT },
55 { "meta", K_METABIT },
56 { "bit", K_METABIT },
57 { "escprefix", K_ESCPREFIX },
58 { "esc", K_ESCPREFIX },
59 { "prefix", K_ESCPREFIX }
6060 };
6161
62 #define SIZE(a) (sizeof(a)/sizeof(a[0]))
62 #define SIZE(a) (sizeof(a) / sizeof(a[0]))
6363
64 int
65 main(int argc, char **argv) {
66 char ometa, nmeta;
67 struct meta *mp;
64 int main(int argc, char **argv)
65 {
66 char ometa, nmeta;
67 struct meta *mp;
6868
69 set_progname(argv[0]);
69 set_progname(argv[0]);
7070
71 setlocale(LC_ALL, "");
72 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
73 textdomain(PACKAGE_NAME);
71 setlocale(LC_ALL, "");
72 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
73 textdomain(PACKAGE_NAME);
7474
75 if (argc == 2 && !strcmp(argv[1], "-V"))
76 print_version_and_exit();
75 if (argc == 2 && !strcmp(argv[1], "-V"))
76 print_version_and_exit();
7777
78 if (ioctl(0, KDGKBMETA, &ometa)) {
79 kbd_error(EXIT_FAILURE, errno, _("Error reading current setting. Maybe stdin is not a VT?: "
80 "ioctl KDGKBMETA"));
81 }
78 if (ioctl(0, KDGKBMETA, &ometa)) {
79 kbd_error(EXIT_FAILURE, errno, _("Error reading current setting. Maybe stdin is not a VT?: "
80 "ioctl KDGKBMETA"));
81 }
8282
83 if (argc <= 1) {
83 if (argc <= 1) {
84 report(ometa);
85 exit(EXIT_SUCCESS);
86 }
87
88 nmeta = 0; /* make gcc happy */
89 for (mp = metas; (unsigned)(mp - metas) < SIZE(metas); mp++) {
90 if (!strcmp(argv[1], mp->name)) {
91 nmeta = mp->val;
92 goto fnd;
93 }
94 }
95 fprintf(stderr, _("unrecognized argument: _%s_\n\n"), argv[1]);
96 usage();
97
98 fnd:
99 printf(_("old state: "));
84100 report(ometa);
85 exit(EXIT_SUCCESS);
86 }
101 if (ioctl(0, KDSKBMETA, nmeta)) {
102 kbd_error(EXIT_FAILURE, errno, "ioctl KDSKBMETA");
103 }
104 printf(_("new state: "));
105 report(nmeta);
87106
88 nmeta = 0; /* make gcc happy */
89 for (mp = metas; (unsigned) (mp-metas) < SIZE(metas); mp++) {
90 if(!strcmp(argv[1], mp->name)) {
91 nmeta = mp->val;
92 goto fnd;
93 }
94 }
95 fprintf(stderr, _("unrecognized argument: _%s_\n\n"), argv[1]);
96 usage();
97
98 fnd:
99 printf(_("old state: "));
100 report(ometa);
101 if (ioctl(0, KDSKBMETA, nmeta)) {
102 kbd_error(EXIT_FAILURE, errno, "ioctl KDSKBMETA");
103 }
104 printf(_("new state: "));
105 report(nmeta);
106
107 return EXIT_SUCCESS;
107 return EXIT_SUCCESS;
108108 }
88 #include "version.h"
99 #include "kbd_error.h"
1010
11 int
12 main(int argc, char **argv){
11 int main(int argc, char **argv)
12 {
1313 int fd, indx, red, green, blue;
1414 unsigned char cmap[48];
1515
3737 if (ioctl(fd, GIO_CMAP, cmap))
3838 kbd_error(EXIT_FAILURE, errno, "ioctl GIO_CMAP");
3939
40 cmap[3*indx] = red;
41 cmap[3*indx+1] = green;
42 cmap[3*indx+2] = blue;
40 cmap[3 * indx] = red;
41 cmap[3 * indx + 1] = green;
42 cmap[3 * indx + 2] = blue;
4343
4444 if (ioctl(fd, PIO_CMAP, cmap))
4545 kbd_error(EXIT_FAILURE, errno, "ioctl PIO_CMAP");
1313 #include "nls.h"
1414 #include "kbd_error.h"
1515
16 int
17 main(int argc, char *argv[]) {
16 int main(int argc, char *argv[])
17 {
1818 int fd;
19 struct { char ten, onoff; } arg;
19 struct {
20 char ten, onoff;
21 } arg;
2022
2123 setlocale(LC_ALL, "");
2224 bindtextdomain(PACKAGE_NAME, LOCALEDIR);
2830 }
2931 if ((fd = getfd(NULL)) < 0)
3032 kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
31 arg.ten = 10;
33 arg.ten = 10;
3234 arg.onoff = 0;
3335 if (!strcmp(argv[1], "on"))
3436 arg.onoff = 1;
3636 0xff, 0xff, 0xff,
3737 };
3838
39 static void __attribute__ ((noreturn))
39 static void __attribute__((noreturn))
4040 usage(int code)
4141 {
4242 fprintf(stderr,
43 _("Usage: %s [-h] [-V]\n"
44 " %s vga|FILE|-\n"
45 "\n"
46 "If you use the FILE parameter, FILE should be exactly 3 lines of\n"
47 "comma-separated decimal values for RED, GREEN, and BLUE.\n"
48 "\n"
49 "To seed a valid FILE:\n"
50 " cat /sys/module/vt/parameters/default_{red,grn,blu} > FILE\n"
51 "\n"
52 "and then edit the values in FILE.\n"
53 "\n"
54 "Other options:\n"
55 " -h print this usage message\n"
56 " -V print version number\n"
57 "\n"),
58 progname, progname);
43 _("Usage: %s [-h] [-V]\n"
44 " %s vga|FILE|-\n"
45 "\n"
46 "If you use the FILE parameter, FILE should be exactly 3 lines of\n"
47 "comma-separated decimal values for RED, GREEN, and BLUE.\n"
48 "\n"
49 "To seed a valid FILE:\n"
50 " cat /sys/module/vt/parameters/default_{red,grn,blu} > FILE\n"
51 "\n"
52 "and then edit the values in FILE.\n"
53 "\n"
54 "Other options:\n"
55 " -h print this usage message\n"
56 " -V print version number\n"
57 "\n"),
58 progname, progname);
5959 exit(code);
6060 }
6161
7272 kbd_error(EXIT_FAILURE, errno, "fscanf");
7373
7474 kbd_error(EXIT_FAILURE, 0, _("Error: %s: Invalid value in field %u in line %u."),
75 filename, rows + 1, cols + 1);
75 filename, rows + 1, cols + 1);
7676 }
7777
78 cmap[rows + cols * 3] = (unsigned char) val;
78 cmap[rows + cols * 3] = (unsigned char)val;
7979
8080 if (cols < 15 && fgetc(fd) != ',')
8181 kbd_error(EXIT_FAILURE, 0, _("Error: %s: Insufficient number of fields in line %u."),
82 filename, rows + 1);
82 filename, rows + 1);
8383 }
8484
8585 if ((c = fgetc(fd)) == EOF)
8686 kbd_error(EXIT_FAILURE, 0, _("Error: %s: Line %u has ended unexpectedly.\n"),
87 filename, rows + 1);
87 filename, rows + 1);
8888
8989 if (c != '\n')
9090 kbd_error(EXIT_FAILURE, 0, _("Error: %s: Line %u is too long.\n"),
91 filename, rows + 1);
91 filename, rows + 1);
9292 }
9393 }
9494
95 int
96 main(int argc, char **argv) {
95 int main(int argc, char **argv)
96 {
9797 int c, fd;
9898 const char *file;
9999 unsigned char *colormap = cmap;
2626
2727 unsigned short obuf[E_TABSZ], nbuf[E_TABSZ];
2828 struct unimapdesc ounimap, nunimap;
29 int fd = 0;
30 int have_obuf = 0;
29 int fd = 0;
30 int have_obuf = 0;
3131 int have_ounimap = 0;
3232
33 static void __attribute__ ((noreturn))
34 leave(int n) {
35 if (have_obuf && loaduniscrnmap(fd,obuf)) {
33 static void __attribute__((noreturn))
34 leave(int n)
35 {
36 if (have_obuf && loaduniscrnmap(fd, obuf)) {
3637 kbd_warning(0, _("failed to restore original translation table\n"));
3738 n = EXIT_FAILURE;
3839 }
39 if (have_ounimap && loadunimap(fd,NULL,&ounimap)) {
40 if (have_ounimap && loadunimap(fd, NULL, &ounimap)) {
4041 kbd_warning(0, _("failed to restore original unimap\n"));
4142 n = EXIT_FAILURE;
4243 }
4445 }
4546
4647 static void
47 settrivialscreenmap(void) {
48 settrivialscreenmap(void)
49 {
4850 int i;
4951
50 if (getuniscrnmap(fd,obuf))
52 if (getuniscrnmap(fd, obuf))
5153 exit(1);
5254 have_obuf = 1;
5355
54 for(i=0; i<E_TABSZ; i++)
56 for (i = 0; i < E_TABSZ; i++)
5557 nbuf[i] = i;
5658
57 if (loaduniscrnmap(fd,nbuf)) {
59 if (loaduniscrnmap(fd, nbuf)) {
5860 kbd_error(EXIT_FAILURE, 0, _("cannot change translation table\n"));
5961 }
6062 }
6163
6264 static void
63 getoldunicodemap(void) {
65 getoldunicodemap(void)
66 {
6467 struct unimapdesc descr;
6568
6669 if (getunimap(fd, &descr))
6770 leave(EXIT_FAILURE);
68 ounimap = descr;
71 ounimap = descr;
6972 have_ounimap = 1;
7073 }
7174
72 #define BASE 041 /* ' '+1 */
75 #define BASE 041 /* ' '+1 */
7376
7477 static void
75 setnewunicodemap(int *list, int cnt) {
78 setnewunicodemap(int *list, int cnt)
79 {
7680 int i;
7781
7882 if (!nunimap.entry_ct) {
7983 nunimap.entry_ct = 512;
80 nunimap.entries = (struct unipair *) xmalloc(nunimap.entry_ct * sizeof(struct unipair));
81 }
82 for (i=0; i<512; i++) {
84 nunimap.entries = (struct unipair *)xmalloc(nunimap.entry_ct * sizeof(struct unipair));
85 }
86 for (i = 0; i < 512; i++) {
8387 nunimap.entries[i].fontpos = i;
8488 nunimap.entries[i].unicode = 0;
8589 }
86 for (i=0; i<cnt; i++)
87 nunimap.entries[list[i]].unicode = BASE+i;
90 for (i = 0; i < cnt; i++)
91 nunimap.entries[list[i]].unicode = BASE + i;
8892
8993 if (loadunimap(fd, NULL, &nunimap))
9094 leave(EXIT_FAILURE);
9195 }
9296
93 static void __attribute__ ((noreturn))
94 usage(void) {
97 static void __attribute__((noreturn))
98 usage(void)
99 {
95100 fprintf(stderr,
96 _("usage: showconsolefont -V|--version\n"
97 " showconsolefont [-C tty] [-v] [-i]\n"
98 "(probably after loading a font with `setfont font')\n"
99 "\n"
100 "Valid options are:\n"
101 " -V --version Print version number and exit.\n"
102 " -C tty Device to read the font from. Default: current tty.\n"
103 " -v Be more verbose.\n"
104 " -i Don't print out the font table, just show\n"
105 " ROWSxCOLSxCOUNT and exit.\n"));
101 _("usage: showconsolefont -V|--version\n"
102 " showconsolefont [-C tty] [-v] [-i]\n"
103 "(probably after loading a font with `setfont font')\n"
104 "\n"
105 "Valid options are:\n"
106 " -V --version Print version number and exit.\n"
107 " -C tty Device to read the font from. Default: current tty.\n"
108 " -v Be more verbose.\n"
109 " -i Don't print out the font table, just show\n"
110 " ROWSxCOLSxCOUNT and exit.\n"));
106111 exit(EXIT_FAILURE);
107112 }
108113
109 int
110 main (int argc, char **argv) {
114 int main(int argc, char **argv)
115 {
111116 int c, n, cols, rows, nr, i, j, k;
112117 int mode;
113118 char *space, *sep, *console = NULL;
125130
126131 while ((c = getopt(argc, argv, "ivC:")) != EOF) {
127132 switch (c) {
128 case 'i':
129 info = 1;
130 break;
131 case 'v':
132 verbose = 1;
133 break;
134 case 'C':
135 console = optarg;
136 break;
137 default:
138 usage();
133 case 'i':
134 info = 1;
135 break;
136 case 'v':
137 verbose = 1;
138 break;
139 case 'C':
140 console = optarg;
141 break;
142 default:
143 usage();
139144 }
140145 }
141146
150155 leave(EXIT_FAILURE);
151156 }
152157 if (mode == K_UNICODE)
153 space = "\xef\x80\xa0"; /* U+F020 (direct-to-font space) */
158 space = "\xef\x80\xa0"; /* U+F020 (direct-to-font space) */
154159 else
155160 space = " ";
156161
157 if (info) {
158 nr = rows = cols = 0;
159 n = getfont(fd, NULL, &nr, &rows, &cols);
160 if (n != 0)
161 leave(EXIT_FAILURE);
162
163 if (verbose) {
164 printf(_("Character count: %d\n"), nr);
165 printf(_("Font width : %d\n"), rows);
166 printf(_("Font height : %d\n"), cols);
167 }
168 else
169 printf("%dx%dx%d\n", rows, cols, nr);
170 leave(EXIT_SUCCESS);
171 }
162 if (info) {
163 nr = rows = cols = 0;
164 n = getfont(fd, NULL, &nr, &rows, &cols);
165 if (n != 0)
166 leave(EXIT_FAILURE);
167
168 if (verbose) {
169 printf(_("Character count: %d\n"), nr);
170 printf(_("Font width : %d\n"), rows);
171 printf(_("Font height : %d\n"), cols);
172 } else
173 printf("%dx%dx%d\n", rows, cols, nr);
174 leave(EXIT_SUCCESS);
175 }
172176
173177 settrivialscreenmap();
174178 getoldunicodemap();
177181 if (verbose)
178182 printf(_("Showing %d-char font\n\n"), n);
179183 cols = ((n > 256) ? 32 : 16);
180 nr = 64/cols;
181 rows = (n+cols-1)/cols;
182 sep = ((cols == 16) ? "%1$s%1$s" : "%1$s");
183
184 for (i=0; i<rows; i++) {
184 nr = 64 / cols;
185 rows = (n + cols - 1) / cols;
186 sep = ((cols == 16) ? "%1$s%1$s" : "%1$s");
187
188 for (i = 0; i < rows; i++) {
185189 if (i % nr == 0) {
186190 lth = 0;
187 for (k=i; k<i+nr; k++)
188 for (j=0; j < cols; j++)
189 list[lth++] = k+j*rows;
191 for (k = i; k < i + nr; k++)
192 for (j = 0; j < cols; j++)
193 list[lth++] = k + j * rows;
190194 setnewunicodemap(list, lth);
191195 }
192196 printf("%1$s%1$s%1$s%1$s", space);
193 for(j=0; j < cols && i+j*rows < n; j++) {
194 putchar(BASE + (i%nr)*cols+j);
197 for (j = 0; j < cols && i + j * rows < n; j++) {
198 putchar(BASE + (i % nr) * cols + j);
195199 printf(sep, space);
196 if (j%8 == 7)
200 if (j % 8 == 7)
197201 printf(sep, space);
198202 }
199203 putchar('\n');
200 if (i%8 == 7)
204 if (i % 8 == 7)
201205 putchar('\n');
202206 fflush(stdout);
203207 }
1515 #include "nls.h"
1616 #include "version.h"
1717
18 int tmp; /* for debugging */
18 int tmp; /* for debugging */
1919
2020 int fd;
2121 int oldkbmode;
2626 * thus making the console unusable when it was called under X.
2727 */
2828 static void
29 get_mode(void) {
30 char *m;
29 get_mode(void)
30 {
31 char *m;
3132
3233 if (ioctl(fd, KDGKBMODE, &oldkbmode)) {
3334 kbd_error(EXIT_FAILURE, errno, "ioctl KDGKBMODE");
3435 }
35 switch(oldkbmode) {
36 case K_RAW:
37 m = "RAW"; break;
38 case K_XLATE:
39 m = "XLATE"; break;
40 case K_MEDIUMRAW:
41 m = "MEDIUMRAW"; break;
42 case K_UNICODE:
43 m = "UNICODE"; break;
44 default:
45 m = _("?UNKNOWN?"); break;
36 switch (oldkbmode) {
37 case K_RAW:
38 m = "RAW";
39 break;
40 case K_XLATE:
41 m = "XLATE";
42 break;
43 case K_MEDIUMRAW:
44 m = "MEDIUMRAW";
45 break;
46 case K_UNICODE:
47 m = "UNICODE";
48 break;
49 default:
50 m = _("?UNKNOWN?");
51 break;
4652 }
4753 printf(_("kb mode was %s\n"), m);
4854 if (oldkbmode != K_XLATE) {
49 printf(_("[ if you are trying this under X, it might not work\n"
50 "since the X server is also reading /dev/console ]\n"));
55 printf(_("[ if you are trying this under X, it might not work\n"
56 "since the X server is also reading /dev/console ]\n"));
5157 }
5258 printf("\n");
5359 }
5460
5561 static void
56 clean_up(void) {
62 clean_up(void)
63 {
5764 if (ioctl(fd, KDSKBMODE, oldkbmode)) {
5865 kbd_error(EXIT_FAILURE, errno, "ioctl KDSKBMODE");
5966 }
6269 close(fd);
6370 }
6471
65 static void __attribute__ ((noreturn))
66 die(int x) {
72 static void __attribute__((noreturn))
73 die(int x)
74 {
6775 printf(_("caught signal %d, cleaning up...\n"), x);
6876 clean_up();
6977 exit(EXIT_FAILURE);
7078 }
7179
72 static void __attribute__ ((noreturn))
73 watch_dog(int x __attribute__ ((unused))) {
80 static void __attribute__((noreturn))
81 watch_dog(int x __attribute__((unused)))
82 {
7483 clean_up();
7584 exit(EXIT_SUCCESS);
7685 }
7786
78 static void __attribute__ ((noreturn))
79 usage(void) {
87 static void __attribute__((noreturn))
88 usage(void)
89 {
8090 fprintf(stderr, _(
81 "showkey version %s\n\n"
82 "usage: showkey [options...]\n"
83 "\n"
84 "valid options are:\n"
85 "\n"
86 " -h --help display this help text\n"
87 " -a --ascii display the decimal/octal/hex values of the keys\n"
88 " -s --scancodes display only the raw scan-codes\n"
89 " -k --keycodes display only the interpreted keycodes (default)\n"
90 " -V --version print version number\n"
91 ), PACKAGE_VERSION);
91 "showkey version %s\n\n"
92 "usage: showkey [options...]\n"
93 "\n"
94 "valid options are:\n"
95 "\n"
96 " -h --help display this help text\n"
97 " -a --ascii display the decimal/octal/hex values of the keys\n"
98 " -s --scancodes display only the raw scan-codes\n"
99 " -k --keycodes display only the interpreted keycodes (default)\n"
100 " -V --version print version number\n"),
101 PACKAGE_VERSION);
92102 exit(EXIT_FAILURE);
93103 }
94104
95 int
96 main (int argc, char *argv[]) {
97 const char *short_opts = "haskV";
105 int main(int argc, char *argv[])
106 {
107 const char *short_opts = "haskV";
98108 const struct option long_opts[] = {
99 { "help", no_argument, NULL, 'h' },
100 { "ascii", no_argument, NULL, 'a' },
101 { "scancodes", no_argument, NULL, 's' },
102 { "keycodes", no_argument, NULL, 'k' },
103 { "version", no_argument, NULL, 'V' },
109 { "help", no_argument, NULL, 'h' },
110 { "ascii", no_argument, NULL, 'a' },
111 { "scancodes", no_argument, NULL, 's' },
112 { "keycodes", no_argument, NULL, 'k' },
113 { "version", no_argument, NULL, 'V' },
104114 { NULL, 0, NULL, 0 }
105115 };
106116 int c;
107117 int show_keycodes = 1;
108 int print_ascii = 0;
118 int print_ascii = 0;
109119
110120 struct termios new;
111 unsigned char buf[18]; /* divisible by 3 */
121 unsigned char buf[18]; /* divisible by 3 */
112122 int i, n;
113123
114124 set_progname(argv[0]);
118128 textdomain(PACKAGE_NAME);
119129
120130 while ((c = getopt_long(argc, argv,
121 short_opts, long_opts, NULL)) != -1) {
131 short_opts, long_opts, NULL)) != -1) {
122132 switch (c) {
123 case 's':
124 show_keycodes = 0;
125 break;
126 case 'k':
127 show_keycodes = 1;
128 break;
129 case 'a':
130 print_ascii = 1;
131 break;
132 case 'V':
133 print_version_and_exit();
134 case 'h':
135 case '?':
136 usage();
133 case 's':
134 show_keycodes = 0;
135 break;
136 case 'k':
137 show_keycodes = 1;
138 break;
139 case 'a':
140 print_ascii = 1;
141 break;
142 case 'V':
143 print_version_and_exit();
144 case 'h':
145 case '?':
146 usage();
137147 }
138148 }
139149
142152
143153 if (print_ascii) {
144154 /* no mode and signal and timer stuff - just read stdin */
145 fd = 0;
155 fd = 0;
146156
147157 if (tcgetattr(fd, &old) == -1)
148158 kbd_warning(errno, "tcgetattr");
149159 if (tcgetattr(fd, &new) == -1)
150160 kbd_warning(errno, "tcgetattr");
151161
152 new.c_lflag &= ~ (ICANON | ISIG);
162 new.c_lflag &= ~(ICANON | ISIG);
153163 new.c_lflag |= (ECHO | ECHOCTL);
154 new.c_iflag = 0;
155 new.c_cc[VMIN] = 1;
164 new.c_iflag = 0;
165 new.c_cc[VMIN] = 1;
156166 new.c_cc[VTIME] = 0;
157167
158168 if (tcsetattr(fd, TCSAFLUSH, &new) == -1)
214224 if (tcgetattr(fd, &new) == -1)
215225 kbd_warning(errno, "tcgetattr");
216226
217 new.c_lflag &= ~ (ICANON | ECHO | ISIG);
218 new.c_iflag = 0;
219 new.c_cc[VMIN] = sizeof(buf);
220 new.c_cc[VTIME] = 1; /* 0.1 sec intercharacter timeout */
227 new.c_lflag &= ~(ICANON | ECHO | ISIG);
228 new.c_iflag = 0;
229 new.c_cc[VMIN] = sizeof(buf);
230 new.c_cc[VTIME] = 1; /* 0.1 sec intercharacter timeout */
221231
222232 if (tcsetattr(fd, TCSAFLUSH, &new) == -1)
223233 kbd_warning(errno, "tcsetattr");
251261
252262 s = (buf[i] & 0x80) ? _("release") : _("press");
253263
254 if (i+2 < n && (buf[i] & 0x7f) == 0
255 && (buf[i+1] & 0x80) != 0
256 && (buf[i+2] & 0x80) != 0) {
257 kc = ((buf[i+1] & 0x7f) << 7) |
258 (buf[i+2] & 0x7f);
264 if (i + 2 < n && (buf[i] & 0x7f) == 0 && (buf[i + 1] & 0x80) != 0 && (buf[i + 2] & 0x80) != 0) {
265 kc = ((buf[i + 1] & 0x7f) << 7) |
266 (buf[i + 2] & 0x7f);
259267 i += 3;
260268 } else {
261269 kc = (buf[i] & 0x7f);
1515 #include <errno.h>
1616 #include <linux/kd.h>
1717 #include <stdio.h>
18 #include <stdlib.h> /* system */
19 #include <fcntl.h> /* open */
20 #include <sys/ioctl.h> /* ioctl */
21 #include <unistd.h> /* sleep */
18 #include <stdlib.h> /* system */
19 #include <fcntl.h> /* open */
20 #include <sys/ioctl.h> /* ioctl */
21 #include <unistd.h> /* sleep */
2222
2323 #include "version.h"
2424 #include "kbd.h"
2525 #include "kbd_error.h"
2626
2727 static void
28 sighup(int n __attribute__ ((unused))) {
29 if (system("openvt -s -l bash") == -1) {
30 kbd_error(EXIT_FAILURE, errno, "system");
31 }
32 signal(SIGHUP, sighup);
28 sighup(int n __attribute__((unused)))
29 {
30 if (system("openvt -s -l bash") == -1) {
31 kbd_error(EXIT_FAILURE, errno, "system");
32 }
33 signal(SIGHUP, sighup);
3334 }
3435
35 int
36 main(int argc __attribute__ ((unused)), char *argv[]) {
37 int fd;
36 int main(int argc __attribute__((unused)), char *argv[])
37 {
38 int fd;
3839
39 set_progname(argv[0]);
40 set_progname(argv[0]);
4041
41 fd = open("/dev/tty0", 0);
42 if (fd < 0 && errno == ENOENT)
43 fd = open("/dev/vc/0", 0);
44 if (fd < 0)
45 fd = 0;
46 signal(SIGHUP, sighup);
47 if (ioctl(fd, KDSIGACCEPT, (long) SIGHUP)) {
48 kbd_error(EXIT_FAILURE, errno, "ioctl KDSIGACCEPT");
49 }
50 while(1)
51 sleep(3600);
52 return EXIT_SUCCESS;
42 fd = open("/dev/tty0", 0);
43 if (fd < 0 && errno == ENOENT)
44 fd = open("/dev/vc/0", 0);
45 if (fd < 0)
46 fd = 0;
47 signal(SIGHUP, sighup);
48 if (ioctl(fd, KDSIGACCEPT, (long)SIGHUP)) {
49 kbd_error(EXIT_FAILURE, errno, "ioctl KDSIGACCEPT");
50 }
51 while (1)
52 sleep(3600);
53 return EXIT_SUCCESS;
5354 }
1919 #include "kbd_error.h"
2020
2121 static void
22 sighup(int n __attribute__ ((unused))) {
23 if (system("openvt -s -l -- login -h spawn") == -1) {
24 kbd_error(EXIT_FAILURE, errno, "system");
25 }
26 signal(SIGHUP, sighup);
22 sighup(int n __attribute__((unused)))
23 {
24 if (system("openvt -s -l -- login -h spawn") == -1) {
25 kbd_error(EXIT_FAILURE, errno, "system");
26 }
27 signal(SIGHUP, sighup);
2728 }
2829
29 int
30 main(int argc __attribute__ ((unused)), char *argv[]) {
31 int fd;
30 int main(int argc __attribute__((unused)), char *argv[])
31 {
32 int fd;
3233
33 set_progname(argv[0]);
34 set_progname(argv[0]);
3435
35 fd = open("/dev/tty0", 0);
36 if (fd < 0 && errno == ENOENT)
37 fd = open("/dev/vc/0", 0);
38 if (fd < 0)
39 fd = 0;
40 signal(SIGHUP, sighup);
41 if (ioctl(fd, KDSIGACCEPT, (long) SIGHUP))
42 kbd_error(EXIT_FAILURE, errno, "ioctl KDSIGACCEPT");
43 while(1)
44 sleep(3600);
45 return EXIT_SUCCESS;
36 fd = open("/dev/tty0", 0);
37 if (fd < 0 && errno == ENOENT)
38 fd = open("/dev/vc/0", 0);
39 if (fd < 0)
40 fd = 0;
41 signal(SIGHUP, sighup);
42 if (ioctl(fd, KDSIGACCEPT, (long)SIGHUP))
43 kbd_error(EXIT_FAILURE, errno, "ioctl KDSIGACCEPT");
44 while (1)
45 sleep(3600);
46 return EXIT_SUCCESS;
4647 }
1515 #include "version.h"
1616 #include "kbd_error.h"
1717
18 int
19 main(int argc, char *argv[]) {
18 int main(int argc, char *argv[])
19 {
2020 int fd, num;
2121
2222 set_progname(argv[0]);
3636 kbd_error(EXIT_FAILURE, 0, _("Couldn't get a file descriptor referring to the console"));
3737
3838 num = atoi(argv[1]);
39 if (ioctl(fd,KDSETMODE,KD_TEXT)) {
39 if (ioctl(fd, KDSETMODE, KD_TEXT)) {
4040 kbd_error(EXIT_FAILURE, errno, "totextmode: KDSETMODE");
4141 }
4242 return EXIT_SUCCESS;
1212 * cnt is either 0 or gives the number of available bytes
1313 */
1414 unsigned long
15 from_utf8(char **inptr, int cnt, int *err) {
15 from_utf8(char **inptr, int cnt, int *err)
16 {
1617 unsigned char *in;
1718 unsigned int uc, uc2;
1819 int need, bit, bad = 0;
1920
20 in = (unsigned char *)(* inptr);
21 uc = *in++;
21 in = (unsigned char *)(*inptr);
22 uc = *in++;
2223 need = 0;
23 bit = 0x80;
24 while(uc & bit) {
24 bit = 0x80;
25 while (uc & bit) {
2526 need++;
2627 bit >>= 1;
2728 }
28 uc &= (bit-1);
29 uc &= (bit - 1);
2930 if (cnt && cnt < need) {
3031 *err = UTF8_SHORT;
3132 return 0;
3233 }
3334 if (need == 1)
3435 bad = 1;
35 else if (need) while(--need) {
36 uc2 = *in++;
37 if ((uc2 & 0xc0) != 0x80) {
38 bad = 1;
39 break;
36 else if (need)
37 while (--need) {
38 uc2 = *in++;
39 if ((uc2 & 0xc0) != 0x80) {
40 bad = 1;
41 break;
42 }
43 uc = ((uc << 6) | (uc2 & 0x3f));
4044 }
41 uc = ((uc << 6) | (uc2 & 0x3f));
42 }
4345 if (bad) {
4446 *err = UTF8_BAD;
4547 return 0;
4648 }
4749 *inptr = (char *)in;
48 *err = 0;
50 *err = 0;
4951 return uc;
5052 }
22
33 extern unsigned long from_utf8(char **inptr, int cnt, int *err);
44
5 #define UTF8_BAD (-1)
6 #define UTF8_SHORT (-2)
5 #define UTF8_BAD (-1)
6 #define UTF8_SHORT (-2)
77
88 #endif /* _UTF8_H */
77 char *progname;
88
99 static inline void
10 set_progname(char *name) {
10 set_progname(char *name)
11 {
1112 char *p;
1213
13 p = strrchr(name, '/');
14 progname = (p ? p+1 : name);
14 p = strrchr(name, '/');
15 progname = (p ? p + 1 : name);
1516 }
1617
17 static inline void __attribute__ ((noreturn))
18 print_version_and_exit(void) {
18 static inline void __attribute__((noreturn))
19 print_version_and_exit(void)
20 {
1921 printf(_("%s from %s\n"), progname, PACKAGE_STRING);
2022 exit(0);
2123 }
3333 #include "nls.h"
3434
3535 /* Delay after fatal PAM errors, in seconds. */
36 #define LONG_DELAY 10
36 #define LONG_DELAY 10
3737 /* Delay after other PAM errors, in seconds. */
38 #define SHORT_DELAY 1
38 #define SHORT_DELAY 1
3939
4040 static int
41 do_account_password_management (pam_handle_t *pamh)
41 do_account_password_management(pam_handle_t *pamh)
4242 {
4343 int rc;
4444
4545 /* Whether the authenticated user is allowed to log in? */
46 rc = pam_acct_mgmt (pamh, 0);
46 rc = pam_acct_mgmt(pamh, 0);
4747
4848 /* Do we need to prompt the user for a new password? */
4949 if (rc == PAM_NEW_AUTHTOK_REQD)
50 rc = pam_chauthtok (pamh, PAM_CHANGE_EXPIRED_AUTHTOK);
50 rc = pam_chauthtok(pamh, PAM_CHANGE_EXPIRED_AUTHTOK);
5151
5252 /* Extend the lifetime of the existing credentials. */
5353 if (rc == PAM_SUCCESS)
54 rc = pam_setcred (pamh, PAM_REFRESH_CRED);
54 rc = pam_setcred(pamh, PAM_REFRESH_CRED);
5555
5656 return rc;
5757 }
5858
59 int
60 get_password (pam_handle_t * pamh, const char *username, const char *tty)
59 int get_password(pam_handle_t *pamh, const char *username, const char *tty)
6160 {
62 uid_t uid = getuid ();
61 uid_t uid = getuid();
6362
64 for (;;)
65 {
66 int rc;
63 for (;;) {
64 int rc;
6765 const char *msg;
6866
69 if (!pamh)
70 {
71 pamh = init_pam (username, tty, 1);
72 if (!pamh)
73 {
67 if (!pamh) {
68 pamh = init_pam(username, tty, 1);
69 if (!pamh) {
7470 /* Log the fact of failure. */
75 syslog (LOG_WARNING,
76 "Authentication problems on %s for %s by (uid=%u)",
77 tty, username, uid);
78 puts (_("Please try again later.\n\n\n"));
79 fflush (stdout);
80 sleep (LONG_DELAY);
71 syslog(LOG_WARNING,
72 "Authentication problems on %s for %s by (uid=%u)",
73 tty, username, uid);
74 puts(_("Please try again later.\n\n\n"));
75 fflush(stdout);
76 sleep(LONG_DELAY);
8177 continue;
8278 }
8379 }
8480
85 if (o_lock_all)
86 {
87 printf (_("The entire console display is now completely locked by %s.\n"),
88 username);
89 } else
90 {
91 printf (_("The %s is now locked by %s.\n"), tty,
92 username);
81 if (o_lock_all) {
82 printf(_("The entire console display is now completely locked by %s.\n"),
83 username);
84 } else {
85 printf(_("The %s is now locked by %s.\n"), tty,
86 username);
9387 if (is_vt)
94 puts (_("Use Alt-function keys to switch to other virtual consoles."));
88 puts(_("Use Alt-function keys to switch to other virtual consoles."));
9589 }
96 fflush (stdout);
90 fflush(stdout);
9791
9892 /*
9993 * No need to request a delay on failure via pam_fail_delay(3):
10094 * authentication module should do it for us.
10195 */
102 rc = pam_authenticate (pamh, 0);
96 rc = pam_authenticate(pamh, 0);
10397
104 switch (rc)
105 {
98 switch (rc) {
10699 case PAM_SUCCESS:
107 rc = do_account_password_management (pamh);
100 rc = do_account_password_management(pamh);
108101
109 if (rc != PAM_SUCCESS)
110 {
102 if (rc != PAM_SUCCESS) {
111103 /*
112104 * The user was authenticated but
113105 * either account or password management
114106 * returned an error.
115107 */
116 printf ("%s.\n\n\n",
117 pam_strerror (pamh, rc));
118 fflush (stdout);
119 pam_end (pamh, rc);
108 printf("%s.\n\n\n",
109 pam_strerror(pamh, rc));
110 fflush(stdout);
111 pam_end(pamh, rc);
120112 pamh = 0;
121 sleep (SHORT_DELAY);
113 sleep(SHORT_DELAY);
122114 break;
123115 }
124116
125 pam_end (pamh, rc);
117 pam_end(pamh, rc);
126118 /* Log the fact of console unlocking. */
127 syslog (LOG_NOTICE,
128 "Unlocked %s on %s for %s by (uid=%u)",
129 locked_name (), tty, username, uid);
119 syslog(LOG_NOTICE,
120 "Unlocked %s on %s for %s by (uid=%u)",
121 locked_name(), tty, username, uid);
130122 return EXIT_SUCCESS;
131123
132124 case PAM_MAXTRIES:
133125 case PAM_ABORT:
134 msg = pam_strerror (pamh, rc);
126 msg = pam_strerror(pamh, rc);
135127 /* Log the fact of failure. */
136 syslog (LOG_WARNING, "%s", msg);
137 printf ("%s.\n\n\n", msg);
138 fflush (stdout);
128 syslog(LOG_WARNING, "%s", msg);
129 printf("%s.\n\n\n", msg);
130 fflush(stdout);
139131 msg = 0;
140 pam_end (pamh, rc);
132 pam_end(pamh, rc);
141133 pamh = 0;
142 sleep (LONG_DELAY);
134 sleep(LONG_DELAY);
143135 break;
144136
145137 default:
146 printf ("%s.\n\n\n", pam_strerror (pamh, rc));
147 fflush (stdout);
138 printf("%s.\n\n\n", pam_strerror(pamh, rc));
139 fflush(stdout);
148140 /*
149141 * EOF encountered on read?
150142 * If not on VT, check stdin.
151143 */
152 if (is_vt || isatty (STDIN_FILENO))
153 {
144 if (is_vt || isatty(STDIN_FILENO)) {
154145 /* Ignore error. */
155 sleep (SHORT_DELAY);
146 sleep(SHORT_DELAY);
156147 break;
157148 }
158149
159150 /* Cancel locking. */
160 pam_end (pamh, rc);
161 syslog (LOG_NOTICE,
162 "Cancelled lock of %s on %s for %s by (uid=%u)",
163 locked_name (), tty, username, uid);
151 pam_end(pamh, rc);
152 syslog(LOG_NOTICE,
153 "Cancelled lock of %s on %s for %s by (uid=%u)",
154 locked_name(), tty, username, uid);
164155 return EXIT_FAILURE;
165156 }
166157 }
3737 };
3838
3939 pam_handle_t *
40 init_pam (const char *username, const char *tty, int log)
40 init_pam(const char *username, const char *tty, int log)
4141 {
4242 pam_handle_t *pamh = 0;
43 int rc = pam_start ("vlock", username, &conv, &pamh);
43 int rc = pam_start("vlock", username, &conv, &pamh);
4444
45 if (rc != PAM_SUCCESS)
46 {
45 if (rc != PAM_SUCCESS) {
4746 /* pam_strerror is not available atm. */
4847 if (log)
49 syslog (LOG_WARNING, "pam_start failed: %m");
48 syslog(LOG_WARNING, "pam_start failed: %m");
5049 else
5150 kbd_warning(errno, "pam_start");
5251 return 0;
5352 }
5453
55 rc = pam_set_item (pamh, PAM_TTY, tty);
56 if (rc != PAM_SUCCESS)
57 {
54 rc = pam_set_item(pamh, PAM_TTY, tty);
55 if (rc != PAM_SUCCESS) {
5856 if (log)
59 syslog (LOG_WARNING, "pam_set_item: %s",
60 pam_strerror (pamh, rc));
57 syslog(LOG_WARNING, "pam_set_item: %s",
58 pam_strerror(pamh, rc));
6159 else
6260 kbd_warning(0, "pam_set_item: %s",
63 pam_strerror (pamh, rc));
64 pam_end (pamh, rc);
61 pam_strerror(pamh, rc));
62 pam_end(pamh, rc);
6563 return 0;
6664 }
6765
2121
2222 #include <security/pam_appl.h>
2323
24 pam_handle_t *init_pam (const char *username, const char *tty, int log);
25 int get_password (pam_handle_t * pamh, const char *username,
26 const char *tty);
24 pam_handle_t *init_pam(const char *username, const char *tty, int log);
25 int get_password(pam_handle_t *pamh, const char *username,
26 const char *tty);
3535 * current VT or all of them.
3636 * 0 means current, 1 means all.
3737 */
38 int o_lock_all;
38 int o_lock_all;
3939
4040 const char *
41 locked_name (void)
41 locked_name(void)
4242 {
4343 return o_lock_all ? "console" : (is_vt ? "VC" : "tty");
4444 }
4545
46 static void __attribute__ ((__noreturn__))
46 static void __attribute__((__noreturn__))
4747 show_usage(void)
4848 {
4949 fprintf(stderr,
50 _("Try `%s --help' for more information.\n"),
51 program_invocation_short_name);
50 _("Try `%s --help' for more information.\n"),
51 program_invocation_short_name);
5252 exit(1);
5353 }
5454
55 static void __attribute__ ((__noreturn__))
55 static void __attribute__((__noreturn__))
5656 show_help(void)
5757 {
5858 printf(_("%s: locks virtual consoles, saving your current session.\n"
59 "Usage: %s [options]\n"
60 " Where [options] are any of:\n"
61 "-c or --current: lock only this virtual console, allowing user to\n"
62 " switch to other virtual consoles.\n"
63 "-a or --all: lock all virtual consoles by preventing other users\n"
64 " from switching virtual consoles.\n"
65 "-v or --version: Print the version number of vlock and exit.\n"
66 "-h or --help: Print this help message and exit.\n"),
59 "Usage: %s [options]\n"
60 " Where [options] are any of:\n"
61 "-c or --current: lock only this virtual console, allowing user to\n"
62 " switch to other virtual consoles.\n"
63 "-a or --all: lock all virtual consoles by preventing other users\n"
64 " from switching virtual consoles.\n"
65 "-v or --version: Print the version number of vlock and exit.\n"
66 "-h or --help: Print this help message and exit.\n"),
6767 progname, progname);
6868 exit(0);
6969 }
7070
71 void
72 parse (int ac, char *const av[])
71 void parse(int ac, char *const av[])
7372 {
7473 static struct option long_options[] = {
75 {"current", 0, 0, 'c'},
76 {"all", 0, 0, 'a'},
77 {"version", 0, 0, 'v'},
78 {"help", 0, 0, 'h'},
79 {0, 0, 0, 0},
74 { "current", 0, 0, 'c' },
75 { "all", 0, 0, 'a' },
76 { "version", 0, 0, 'v' },
77 { "help", 0, 0, 'h' },
78 { 0, 0, 0, 0 },
8079 };
81 int c;
80 int c;
8281
83 while ((c = getopt_long(ac, av, "acvh", long_options, 0)) != -1)
84 {
85 switch (c)
86 {
82 while ((c = getopt_long(ac, av, "acvh", long_options, 0)) != -1) {
83 switch (c) {
8784 case 'c':
8885 o_lock_all = 0;
8986 break;
3131
3232 static unsigned char lines, columns;
3333 static void *screen_buf = 0;
34 static int vcs = -1;
34 static int vcs = -1;
3535
36 void
37 init_screen(void)
36 void init_screen(void)
3837 {
39 int failed = 1;
38 int failed = 1;
4039 const char clear_str[] = "\33[3J\33[H\33[J";
4140
4241 vcs = -1;
43 do
44 {
42 do {
4543 struct stat st;
4644 unsigned i, size;
47 char path[16];
45 char path[16];
4846
4947 if (fstat(STDIN_FILENO, &st) == -1)
5048 break;
6765 if (read(vcs, &lines, 1) != 1)
6866 break;
6967
70 size = 2 * lines * columns + 2;
68 size = 2 * lines * columns + 2;
7169 screen_buf = malloc(size);
7270 if (!screen_buf)
7371 break;
7472
75 if (read(vcs, screen_buf, size) != (int) size)
76 {
73 if (read(vcs, screen_buf, size) != (int)size) {
7774 free(screen_buf);
7875 screen_buf = NULL;
7976 break;
8279 failed = 0;
8380 } while (0);
8481
85 if (failed && vcs >= 0)
86 {
82 if (failed && vcs >= 0) {
8783 close(vcs);
8884 vcs = -1;
8985 }
9490 return;
9591 }
9692
97 void
98 restore_screen(void)
93 void restore_screen(void)
9994 {
100 if (screen_buf)
101 {
102 do
103 {
95 if (screen_buf) {
96 do {
10497 if (lseek(vcs, 0, SEEK_SET))
10598 break;
10699 if (write(vcs, &columns, 1) != 1)
3535 * Try to find out proper login name.
3636 */
3737 const char *
38 get_username (void)
38 get_username(void)
3939 {
4040 const char *name;
4141 struct passwd *pw = 0;
42 uid_t uid = getuid ();
42 uid_t uid = getuid();
4343
44 char *logname = getenv ("LOGNAME");
44 char *logname = getenv("LOGNAME");
4545
46 if (logname)
47 {
48 pw = getpwnam (logname);
46 if (logname) {
47 pw = getpwnam(logname);
4948 /* Ensure uid is same as current. */
5049 if (pw && pw->pw_uid != uid)
5150 pw = 0;
5251 }
5352 if (!pw)
54 pw = getpwuid (uid);
53 pw = getpwuid(uid);
5554
5655 if (!pw)
57 kbd_error (EXIT_FAILURE, 0, _("unrecognized user"));
56 kbd_error(EXIT_FAILURE, 0, _("unrecognized user"));
5857
59 name = strdup (pw->pw_name);
58 name = strdup(pw->pw_name);
6059 if (!name)
61 kbd_error (EXIT_FAILURE, errno, "strdup");
60 kbd_error(EXIT_FAILURE, errno, "strdup");
6261
63 endpwent ();
62 endpwent();
6463 return name;
6564 }
3535 #include "version.h"
3636 #include "kbd_error.h"
3737
38 int
39 main (int ac, char *const av[])
38 int main(int ac, char *const av[])
4039 {
41 int rc;
40 int rc;
4241 const char dev_prefix[] = "/dev/";
4342 const char *username, *tty;
4443 pam_handle_t *pamh;
5049 textdomain(PACKAGE_NAME);
5150
5251 /* 1st, parse command line arguments. */
53 parse (ac, av);
52 parse(ac, av);
5453
5554 /* 2nd, find out tty name... */
56 tty = ttyname (STDIN_FILENO);
55 tty = ttyname(STDIN_FILENO);
5756 if (!tty)
5857 /* stdin is not a tty, so no need to try. */
59 kbd_error (EXIT_FAILURE, 0, _("stdin is not a tty"));
58 kbd_error(EXIT_FAILURE, 0, _("stdin is not a tty"));
6059
6160 /* ... and strip its /dev/ prefix. */
62 if (!strncmp (tty, dev_prefix, sizeof (dev_prefix) - 1))
63 tty += sizeof (dev_prefix) - 1;
61 if (!strncmp(tty, dev_prefix, sizeof(dev_prefix) - 1))
62 tty += sizeof(dev_prefix) - 1;
6463
6564 /* 3rd, get username for PAM. */
66 username = get_username ();
65 username = get_username();
6766
6867 /* 4th, initialize system logger. */
69 openlog ("vlock", LOG_PID, LOG_AUTH);
68 openlog("vlock", LOG_PID, LOG_AUTH);
7069
7170 /* 5th, initialize PAM. */
72 if (!(pamh = init_pam (username, tty, 0)))
73 exit (EXIT_FAILURE);
71 if (!(pamh = init_pam(username, tty, 0)))
72 exit(EXIT_FAILURE);
7473
7574 /* 6th, initialize VT, tty and screen. */
76 if (!init_vt (tty))
77 {
78 pam_end (pamh, PAM_SUCCESS);
79 exit (EXIT_FAILURE);
75 if (!init_vt(tty)) {
76 pam_end(pamh, PAM_SUCCESS);
77 exit(EXIT_FAILURE);
8078 }
8179
8280 /* 7th, Log the fact of console locking. */
83 syslog (LOG_NOTICE, "Locked %s on %s for %s by (uid=%u)",
84 locked_name (), tty, username, getuid ());
81 syslog(LOG_NOTICE, "Locked %s on %s for %s by (uid=%u)",
82 locked_name(), tty, username, getuid());
8583
86 rc = get_password (pamh, username, tty);
87 restore_vt ();
84 rc = get_password(pamh, username, tty);
85 restore_vt();
8886
8987 return rc;
9088 }
2020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2121 */
2222
23 int init_vt (const char *tty);
24 void restore_vt (void);
23 int init_vt(const char *tty);
24 void restore_vt(void);
2525
26 void init_screen (void);
27 void restore_screen (void);
26 void init_screen(void);
27 void restore_screen(void);
2828
29 const char *get_username (void);
29 const char *get_username(void);
3030
31 void parse (int ac, char *const av[]);
31 void parse(int ac, char *const av[]);
3232
33 const char *locked_name (void);
33 const char *locked_name(void);
3434
3535 /*
3636 * This determines whether the default behavior is to lock only the
4343 static int vfd = -1;
4444
4545 /* Copy of the VT mode when the program was started. */
46 int is_vt;
46 int is_vt;
4747
4848 /*
4949 * This is called by a signal whenever a user tries to change
5050 * the VC (with a ALT-Fn key or via VT_ACTIVATE).
5151 */
5252 static void
53 release_vt (__attribute__ ((unused)) int signo)
53 release_vt(__attribute__((unused)) int signo)
5454 {
5555 /*
5656 * Kernel is not allowed to switch.
5757 * Return code is silently ignored.
5858 */
59 ioctl (vfd, VT_RELDISP, 0);
59 ioctl(vfd, VT_RELDISP, 0);
6060 }
6161
6262 /* This is called whenever a user switches to that VC. */
6363 static void
64 acquire_vt (__attribute__ ((unused)) int signo)
64 acquire_vt(__attribute__((unused)) int signo)
6565 {
6666 /*
6767 * This call is not currently required under Linux,
6868 * but it won't hurt, either.
6969 * Return code is silently ignored.
7070 */
71 ioctl (vfd, VT_RELDISP, VT_ACKACQ);
71 ioctl(vfd, VT_RELDISP, VT_ACKACQ);
7272 }
7373
7474 /* Set the signal masks and handlers. */
7575 static void
76 mask_signals (void)
76 mask_signals(void)
7777 {
7878
7979 static sigset_t sig;
8080 static struct sigaction sa;
8181
82 memset (&sa, 0, sizeof sa);
83 sigemptyset (&(sa.sa_mask));
82 memset(&sa, 0, sizeof sa);
83 sigemptyset(&(sa.sa_mask));
8484 sa.sa_flags = SA_RESTART;
8585
86 if (o_lock_all)
87 {
86 if (o_lock_all) {
8887 /* handle SIGUSR{1,2}... */
8988 sa.sa_handler = release_vt;
90 sigaction (SIGUSR1, &sa, 0);
89 sigaction(SIGUSR1, &sa, 0);
9190 sa.sa_handler = acquire_vt;
92 sigaction (SIGUSR2, &sa, 0);
91 sigaction(SIGUSR2, &sa, 0);
9392
9493 /* ... and ensure they are unblocked. */
95 sigemptyset (&sig);
96 sigaddset (&sig, SIGUSR1);
97 sigaddset (&sig, SIGUSR2);
98 sigprocmask (SIG_UNBLOCK, &sig, 0);
94 sigemptyset(&sig);
95 sigaddset(&sig, SIGUSR1);
96 sigaddset(&sig, SIGUSR2);
97 sigprocmask(SIG_UNBLOCK, &sig, 0);
9998 }
10099
101100 /* Ignore all the rest. */
102101 sa.sa_handler = SIG_IGN;
103 if (!o_lock_all)
104 {
105 sigaction (SIGUSR1, &sa, 0);
106 sigaction (SIGUSR2, &sa, 0);
107 }
108 sigaction (SIGHUP, &sa, 0);
109 sigaction (SIGINT, &sa, 0);
110 sigaction (SIGQUIT, &sa, 0);
111 sigaction (SIGPIPE, &sa, 0);
112 sigaction (SIGALRM, &sa, 0);
113 sigaction (SIGTERM, &sa, 0);
114 sigaction (SIGTSTP, &sa, 0);
115 sigaction (SIGTTIN, &sa, 0);
116 sigaction (SIGTTOU, &sa, 0);
117 sigaction (SIGURG, &sa, 0);
118 sigaction (SIGVTALRM, &sa, 0);
119 sigaction (SIGIO, &sa, 0);
120 sigaction (SIGPWR, &sa, 0);
102 if (!o_lock_all) {
103 sigaction(SIGUSR1, &sa, 0);
104 sigaction(SIGUSR2, &sa, 0);
105 }
106 sigaction(SIGHUP, &sa, 0);
107 sigaction(SIGINT, &sa, 0);
108 sigaction(SIGQUIT, &sa, 0);
109 sigaction(SIGPIPE, &sa, 0);
110 sigaction(SIGALRM, &sa, 0);
111 sigaction(SIGTERM, &sa, 0);
112 sigaction(SIGTSTP, &sa, 0);
113 sigaction(SIGTTIN, &sa, 0);
114 sigaction(SIGTTOU, &sa, 0);
115 sigaction(SIGURG, &sa, 0);
116 sigaction(SIGVTALRM, &sa, 0);
117 sigaction(SIGIO, &sa, 0);
118 sigaction(SIGPWR, &sa, 0);
121119
122120 /*
123121 * Also block SIGCHLD.
124122 * Not really needed; just make sleep(3) more easy.
125123 */
126 sigemptyset (&sig);
127 sigaddset (&sig, SIGCHLD);
128 sigprocmask (SIG_BLOCK, &sig, 0);
129 }
130
131 int
132 init_vt (const char *tty)
124 sigemptyset(&sig);
125 sigaddset(&sig, SIGCHLD);
126 sigprocmask(SIG_BLOCK, &sig, 0);
127 }
128
129 int init_vt(const char *tty)
133130 {
134131 const char dev_tty[] = "/dev/tty";
135132
136 vfd = open (dev_tty, O_RDWR);
137 if (vfd < 0)
138 {
133 vfd = open(dev_tty, O_RDWR);
134 if (vfd < 0) {
139135 kbd_warning(errno, "could not open %s", dev_tty);
140136 return 0;
141137 }
146142 * and will print a warning message.
147143 * - If it doesn't fail, it gets the current VT status.
148144 */
149 if (ioctl (vfd, VT_GETMODE, &ovtm) < 0)
150 {
145 if (ioctl(vfd, VT_GETMODE, &ovtm) < 0) {
151146 is_vt = 0;
152 fprintf (stderr, _("This tty (%s) is not a virtual console.\n"),
153 tty);
154 if (o_lock_all)
155 {
147 fprintf(stderr, _("This tty (%s) is not a virtual console.\n"),
148 tty);
149 if (o_lock_all) {
156150 o_lock_all = 0;
157 close (vfd);
151 close(vfd);
158152 vfd = -1;
159 fprintf (stderr,
160 _("The entire console display cannot be locked.\n"));
153 fprintf(stderr,
154 _("The entire console display cannot be locked.\n"));
161155 return 0;
162156 }
163 fprintf (stderr, "\n\n");
164 fflush (stderr);
165 } else
166 {
157 fprintf(stderr, "\n\n");
158 fflush(stderr);
159 } else {
167160 is_vt = 1;
168161 }
169162
170163 /* If we aren't going to lock console, we don't need VT descriptor. */
171 if (!o_lock_all)
172 {
173 close (vfd);
164 if (!o_lock_all) {
165 close(vfd);
174166 vfd = -1;
175167 }
176168
177 mask_signals ();
178
179 if (o_lock_all)
180 {
169 mask_signals();
170
171 if (o_lock_all) {
181172 struct vt_mode vtm = ovtm;
182173
183 vtm.mode = VT_PROCESS; /* Process controls switching. */
184 vtm.relsig = SIGUSR1; /* Signal to raise on release request, handled by release_vt(). */
185 vtm.acqsig = SIGUSR2; /* Signal to raise on acquisition, handled by acquire_vt(). */
174 vtm.mode = VT_PROCESS; /* Process controls switching. */
175 vtm.relsig = SIGUSR1; /* Signal to raise on release request, handled by release_vt(). */
176 vtm.acqsig = SIGUSR2; /* Signal to raise on acquisition, handled by acquire_vt(). */
186177
187178 /* Set mode of active vt. */
188 if (ioctl (vfd, VT_SETMODE, &vtm) < 0)
189 {
179 if (ioctl(vfd, VT_SETMODE, &vtm) < 0) {
190180 kbd_warning(errno, "ioctl VT_SETMODE");
191181 return 0;
192182 }
193183 }
194184
195185 if (is_vt)
196 init_screen ();
186 init_screen();
197187
198188 return 1;
199189 }
200190
201 void
202 restore_vt (void)
203 {
204 if (is_vt)
205 {
206 restore_screen ();
207
208 if (o_lock_all)
209 {
191 void restore_vt(void)
192 {
193 if (is_vt) {
194 restore_screen();
195
196 if (o_lock_all) {
210197 /*
211198 * Reset mode of active vt.
212199 * Don't check return code - it won't help anyway.
213200 */
214 ioctl (vfd, VT_SETMODE, &ovtm);
201 ioctl(vfd, VT_SETMODE, &ovtm);
215202 }
216203 }
217204 }
1212 but stopped that after i found a system which made wchar_t an
1313 unsigned char.
1414 */
15 enum
16 {
17 T1 = 0x00,
18 Tx = 0x80,
19 T2 = 0xC0,
20 T3 = 0xE0,
21 T4 = 0xF0,
22 T5 = 0xF8,
23 T6 = 0xFC,
15 enum {
16 T1 = 0x00,
17 Tx = 0x80,
18 T2 = 0xC0,
19 T3 = 0xE0,
20 T4 = 0xF0,
21 T5 = 0xF8,
22 T6 = 0xFC,
2423
25 Bit1 = 7,
26 Bitx = 6,
27 Bit2 = 5,
28 Bit3 = 4,
29 Bit4 = 3,
30 Bit5 = 2,
31 Bit6 = 2,
24 Bit1 = 7,
25 Bitx = 6,
26 Bit2 = 5,
27 Bit3 = 4,
28 Bit4 = 3,
29 Bit5 = 2,
30 Bit6 = 2,
3231
33 Mask1 = (1<<Bit1)-1,
34 Maskx = (1<<Bitx)-1,
35 Mask2 = (1<<Bit2)-1,
36 Mask3 = (1<<Bit3)-1,
37 Mask4 = (1<<Bit4)-1,
38 Mask5 = (1<<Bit5)-1,
39 Mask6 = (1<<Bit6)-1,
32 Mask1 = (1 << Bit1) - 1,
33 Maskx = (1 << Bitx) - 1,
34 Mask2 = (1 << Bit2) - 1,
35 Mask3 = (1 << Bit3) - 1,
36 Mask4 = (1 << Bit4) - 1,
37 Mask5 = (1 << Bit5) - 1,
38 Mask6 = (1 << Bit6) - 1,
4039
41 Wchar1 = (1UL<<Bit1)-1,
42 Wchar2 = (1UL<<(Bit2+Bitx))-1,
43 Wchar3 = (1UL<<(Bit3+2*Bitx))-1,
44 Wchar4 = (1UL<<(Bit4+3*Bitx))-1,
45 Wchar5 = (1UL<<(Bit5+4*Bitx))-1
40 Wchar1 = (1UL << Bit1) - 1,
41 Wchar2 = (1UL << (Bit2 + Bitx)) - 1,
42 Wchar3 = (1UL << (Bit3 + 2 * Bitx)) - 1,
43 Wchar4 = (1UL << (Bit4 + 3 * Bitx)) - 1,
44 Wchar5 = (1UL << (Bit5 + 4 * Bitx)) - 1
4645
47 #ifndef EILSEQ
46 #ifndef EILSEQ
4847 , /* we hate ansi c's comma rules */
49 EILSEQ = 123
48 EILSEQ = 123
5049 #endif /* PLAN9 */
5150 };
5251
5352 static int
5453 our_wctomb(char *s, unsigned long wc)
5554 {
56 if(s == 0)
57 return 0; /* no shift states */
58 if(wc & ~Wchar2) {
59 if(wc & ~Wchar4) {
60 if(wc & ~Wchar5) {
55 if (s == 0)
56 return 0; /* no shift states */
57 if (wc & ~Wchar2) {
58 if (wc & ~Wchar4) {
59 if (wc & ~Wchar5) {
6160 /* 6 bytes */
62 s[0] = T6 | ((wc >> 5*Bitx) & Mask6);
63 s[1] = Tx | ((wc >> 4*Bitx) & Maskx);
64 s[2] = Tx | ((wc >> 3*Bitx) & Maskx);
65 s[3] = Tx | ((wc >> 2*Bitx) & Maskx);
66 s[4] = Tx | ((wc >> 1*Bitx) & Maskx);
67 s[5] = Tx | (wc & Maskx);
61 s[0] = T6 | ((wc >> 5 * Bitx) & Mask6);
62 s[1] = Tx | ((wc >> 4 * Bitx) & Maskx);
63 s[2] = Tx | ((wc >> 3 * Bitx) & Maskx);
64 s[3] = Tx | ((wc >> 2 * Bitx) & Maskx);
65 s[4] = Tx | ((wc >> 1 * Bitx) & Maskx);
66 s[5] = Tx | (wc & Maskx);
6867 return 6;
6968 }
7069 /* 5 bytes */
71 s[0] = T5 | (wc >> 4*Bitx);
72 s[1] = Tx | ((wc >> 3*Bitx) & Maskx);
73 s[2] = Tx | ((wc >> 2*Bitx) & Maskx);
74 s[3] = Tx | ((wc >> 1*Bitx) & Maskx);
75 s[4] = Tx | (wc & Maskx);
70 s[0] = T5 | (wc >> 4 * Bitx);
71 s[1] = Tx | ((wc >> 3 * Bitx) & Maskx);
72 s[2] = Tx | ((wc >> 2 * Bitx) & Maskx);
73 s[3] = Tx | ((wc >> 1 * Bitx) & Maskx);
74 s[4] = Tx | (wc & Maskx);
7675 return 5;
7776 }
78 if(wc & ~Wchar3) {
77 if (wc & ~Wchar3) {
7978 /* 4 bytes */
80 s[0] = T4 | (wc >> 3*Bitx);
81 s[1] = Tx | ((wc >> 2*Bitx) & Maskx);
82 s[2] = Tx | ((wc >> 1*Bitx) & Maskx);
83 s[3] = Tx | (wc & Maskx);
79 s[0] = T4 | (wc >> 3 * Bitx);
80 s[1] = Tx | ((wc >> 2 * Bitx) & Maskx);
81 s[2] = Tx | ((wc >> 1 * Bitx) & Maskx);
82 s[3] = Tx | (wc & Maskx);
8483 return 4;
8584 }
8685 /* 3 bytes */
87 s[0] = T3 | (wc >> 2*Bitx);
88 s[1] = Tx | ((wc >> 1*Bitx) & Maskx);
89 s[2] = Tx | (wc & Maskx);
86 s[0] = T3 | (wc >> 2 * Bitx);
87 s[1] = Tx | ((wc >> 1 * Bitx) & Maskx);
88 s[2] = Tx | (wc & Maskx);
9089 return 3;
9190 }
92 if(wc & ~Wchar1) {
91 if (wc & ~Wchar1) {
9392 /* 2 bytes */
94 s[0] = T2 | (wc >> 1*Bitx);
93 s[0] = T2 | (wc >> 1 * Bitx);
9594 s[1] = Tx | (wc & Maskx);
9695 return 2;
9796 }
1111
1212 extern char *progname;
1313
14 static void __attribute__ ((noreturn))
15 nomem(void) {
14 static void __attribute__((noreturn))
15 nomem(void)
16 {
1617 fprintf(stderr, _("%s: out of memory\n"), progname);
1718 exit(EX_OSERR);
1819 }
1920
2021 void *
21 xmalloc(size_t sz) {
22 xmalloc(size_t sz)
23 {
2224 void *p = malloc(sz);
2325 if (p == NULL)
2426 nomem();
2628 }
2729
2830 void *
29 xrealloc(void *pp, size_t sz) {
31 xrealloc(void *pp, size_t sz)
32 {
3033 void *p = realloc(pp, sz);
3134 if (p == NULL)
3235 nomem();
3437 }
3538
3639 char *
37 xstrdup(char *p) {
40 xstrdup(char *p)
41 {
3842 char *q = strdup(p);
3943 if (q == NULL)
4044 nomem();
4246 }
4347
4448 char *
45 xstrndup(char *p, size_t n) {
49 xstrndup(char *p, size_t n)
50 {
4651 char *q = strndup(p, n);
4752 if (q == NULL)
4853 nomem();
5055 }
5156
5257 void *
53 xfree(void *p) {
58 xfree(void *p)
59 {
5460 if (p != NULL)
5561 free(p);
5662 return NULL;
44 #include <linux/kd.h>
55
66 unsigned short plain_map[NR_KEYS] = {
7 0xf200, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
8 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
9 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
10 0xfb6f, 0xfb70, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb61, 0xfb73,
11 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03b,
12 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
13 0xfb62, 0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf30c,
14 0xf703, 0xf020, 0xf207, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
15 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
16 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
17 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03c, 0xf10a,
18 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
19 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
20 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
21 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
22 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf210, 0xf211, 0xf20e,
23 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
24 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
25 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
26 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
27 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
28 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
29 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
30 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
31 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
32 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
33 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
34 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
35 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
36 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
37 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
38 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
7 0xf200, 0xf01b, 0xf031, 0xf032, 0xf033, 0xf034, 0xf035, 0xf036,
8 0xf037, 0xf038, 0xf039, 0xf030, 0xf02d, 0xf03d, 0xf07f, 0xf009,
9 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
10 0xfb6f, 0xfb70, 0xf05b, 0xf05d, 0xf201, 0xf702, 0xfb61, 0xfb73,
11 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf03b,
12 0xf027, 0xf060, 0xf700, 0xf05c, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
13 0xfb62, 0xfb6e, 0xfb6d, 0xf02c, 0xf02e, 0xf02f, 0xf700, 0xf30c,
14 0xf703, 0xf020, 0xf207, 0xf100, 0xf101, 0xf102, 0xf103, 0xf104,
15 0xf105, 0xf106, 0xf107, 0xf108, 0xf109, 0xf208, 0xf209, 0xf307,
16 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
17 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03c, 0xf10a,
18 0xf10b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
19 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
20 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
21 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
22 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf210, 0xf211, 0xf20e,
23 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
24 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
25 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
26 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
27 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
28 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
29 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
30 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
31 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
32 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
33 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
34 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
35 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
36 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
37 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
38 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
3939 };
4040
4141 static unsigned short shift_map[NR_KEYS] = {
42 0xf200, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
43 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf809,
44 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
45 0xfb4f, 0xfb50, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb41, 0xfb53,
46 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03a,
47 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
48 0xfb42, 0xfb4e, 0xfb4d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
49 0xf703, 0xf020, 0xf207, 0xf10c, 0xf10d, 0xf10e, 0xf10f, 0xf110,
50 0xf111, 0xf112, 0xf113, 0xf11e, 0xf11f, 0xf208, 0xf203, 0xf307,
51 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
52 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03e, 0xf120,
53 0xf121, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
54 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
55 0xf20b, 0xf601, 0xf602, 0xf117, 0xf600, 0xf20a, 0xf115, 0xf116,
56 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
57 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf206, 0xf206, 0xf210,
58 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
59 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
60 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
61 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
62 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
63 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
64 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
65 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
66 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
67 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
68 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
69 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
70 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
71 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
72 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
73 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
42 0xf200, 0xf01b, 0xf021, 0xf040, 0xf023, 0xf024, 0xf025, 0xf05e,
43 0xf026, 0xf02a, 0xf028, 0xf029, 0xf05f, 0xf02b, 0xf07f, 0xf809,
44 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
45 0xfb4f, 0xfb50, 0xf07b, 0xf07d, 0xf201, 0xf702, 0xfb41, 0xfb53,
46 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf03a,
47 0xf022, 0xf07e, 0xf700, 0xf07c, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
48 0xfb42, 0xfb4e, 0xfb4d, 0xf03c, 0xf03e, 0xf03f, 0xf700, 0xf30c,
49 0xf703, 0xf020, 0xf207, 0xf10c, 0xf10d, 0xf10e, 0xf10f, 0xf110,
50 0xf111, 0xf112, 0xf113, 0xf11e, 0xf11f, 0xf208, 0xf203, 0xf307,
51 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
52 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf03e, 0xf120,
53 0xf121, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
54 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
55 0xf20b, 0xf601, 0xf602, 0xf117, 0xf600, 0xf20a, 0xf115, 0xf116,
56 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
57 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf206, 0xf206, 0xf210,
58 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
59 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
60 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
61 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
62 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
63 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
64 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
65 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
66 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
67 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
68 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
69 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
70 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
71 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
72 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
73 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
7474 };
7575
7676 static unsigned short altgr_map[NR_KEYS] = {
77 0xf200, 0xf200, 0xf200, 0xf040, 0xf200, 0xf024, 0xf200, 0xf200,
78 0xf07b, 0xf05b, 0xf05d, 0xf07d, 0xf05c, 0xf200, 0xf200, 0xf200,
79 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
80 0xfb6f, 0xfb70, 0xf200, 0xf07e, 0xf201, 0xf702, 0xfb61, 0xfb73,
81 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf200,
82 0xf200, 0xf200, 0xf700, 0xf200, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
83 0xfb62, 0xfb6e, 0xfb6d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
84 0xf703, 0xf200, 0xf207, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
85 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf202, 0xf307,
86 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
87 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf07c, 0xf516,
88 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
89 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
90 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
91 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
92 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf211, 0xf210, 0xf211,
93 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
94 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
95 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
96 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
97 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
98 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
99 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
100 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
101 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
102 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
103 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
104 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
105 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
106 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
107 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
108 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
77 0xf200, 0xf200, 0xf200, 0xf040, 0xf200, 0xf024, 0xf200, 0xf200,
78 0xf07b, 0xf05b, 0xf05d, 0xf07d, 0xf05c, 0xf200, 0xf200, 0xf200,
79 0xfb71, 0xfb77, 0xfb65, 0xfb72, 0xfb74, 0xfb79, 0xfb75, 0xfb69,
80 0xfb6f, 0xfb70, 0xf200, 0xf07e, 0xf201, 0xf702, 0xfb61, 0xfb73,
81 0xfb64, 0xfb66, 0xfb67, 0xfb68, 0xfb6a, 0xfb6b, 0xfb6c, 0xf200,
82 0xf200, 0xf200, 0xf700, 0xf200, 0xfb7a, 0xfb78, 0xfb63, 0xfb76,
83 0xfb62, 0xfb6e, 0xfb6d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
84 0xf703, 0xf200, 0xf207, 0xf50c, 0xf50d, 0xf50e, 0xf50f, 0xf510,
85 0xf511, 0xf512, 0xf513, 0xf514, 0xf515, 0xf208, 0xf202, 0xf307,
86 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
87 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf07c, 0xf516,
88 0xf517, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
89 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
90 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
91 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
92 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf211, 0xf210, 0xf211,
93 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
94 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
95 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
96 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
97 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
98 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
99 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
100 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
101 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
102 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
103 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
104 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
105 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
106 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
107 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
108 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
109109 };
110110
111111 static unsigned short shift_altgr_map[NR_KEYS] = {
112 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
113 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
114 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
115 0xfb4f, 0xfb50, 0xf200, 0xf200, 0xf201, 0xf702, 0xfb41, 0xfb53,
116 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf200,
117 0xf200, 0xf200, 0xf700, 0xf200, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
118 0xfb42, 0xfb4e, 0xfb4d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
119 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
120 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
121 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
122 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
123 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
124 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
125 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
126 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
127 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf20e, 0xf20e, 0xf206,
128 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
129 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
130 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
131 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
132 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
133 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
134 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
135 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
136 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
137 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
138 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
139 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
140 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
141 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
142 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
143 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
112 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
113 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
114 0xfb51, 0xfb57, 0xfb45, 0xfb52, 0xfb54, 0xfb59, 0xfb55, 0xfb49,
115 0xfb4f, 0xfb50, 0xf200, 0xf200, 0xf201, 0xf702, 0xfb41, 0xfb53,
116 0xfb44, 0xfb46, 0xfb47, 0xfb48, 0xfb4a, 0xfb4b, 0xfb4c, 0xf200,
117 0xf200, 0xf200, 0xf700, 0xf200, 0xfb5a, 0xfb58, 0xfb43, 0xfb56,
118 0xfb42, 0xfb4e, 0xfb4d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
119 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
120 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
121 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
122 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
123 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
124 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
125 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
126 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
127 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf20e, 0xf20e, 0xf206,
128 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
129 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
130 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
131 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
132 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
133 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
134 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
135 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
136 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
137 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
138 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
139 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
140 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
141 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
142 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
143 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
144144 };
145145
146146 static unsigned short ctrl_map[NR_KEYS] = {
147 0xf200, 0xf200, 0xf200, 0xf000, 0xf01b, 0xf01c, 0xf01d, 0xf01e,
148 0xf01f, 0xf07f, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf200,
149 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
150 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf201, 0xf702, 0xf001, 0xf013,
151 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
152 0xf007, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
153 0xf002, 0xf00e, 0xf00d, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
154 0xf703, 0xf000, 0xf207, 0xf122, 0xf123, 0xf124, 0xf125, 0xf126,
155 0xf127, 0xf128, 0xf129, 0xf12a, 0xf12b, 0xf208, 0xf204, 0xf307,
156 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
157 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf12c,
158 0xf12d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
159 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf701, 0xf205, 0xf114, 0xf603,
160 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
161 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
162 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
163 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
164 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
165 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
166 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
167 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
168 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
169 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
170 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
171 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
172 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
173 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
174 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
175 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
176 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
177 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
178 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
147 0xf200, 0xf200, 0xf200, 0xf000, 0xf01b, 0xf01c, 0xf01d, 0xf01e,
148 0xf01f, 0xf07f, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf008, 0xf200,
149 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
150 0xf00f, 0xf010, 0xf01b, 0xf01d, 0xf201, 0xf702, 0xf001, 0xf013,
151 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
152 0xf007, 0xf000, 0xf700, 0xf01c, 0xf01a, 0xf018, 0xf003, 0xf016,
153 0xf002, 0xf00e, 0xf00d, 0xf200, 0xf20e, 0xf07f, 0xf700, 0xf30c,
154 0xf703, 0xf000, 0xf207, 0xf122, 0xf123, 0xf124, 0xf125, 0xf126,
155 0xf127, 0xf128, 0xf129, 0xf12a, 0xf12b, 0xf208, 0xf204, 0xf307,
156 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
157 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf12c,
158 0xf12d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
159 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf701, 0xf205, 0xf114, 0xf603,
160 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
161 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
162 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
163 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
164 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
165 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
166 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
167 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
168 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
169 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
170 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
171 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
172 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
173 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
174 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
175 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
176 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
177 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
178 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
179179 };
180180
181181 static unsigned short shift_ctrl_map[NR_KEYS] = {
182 0xf200, 0xf200, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf200,
183 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf200, 0xf200,
184 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
185 0xf00f, 0xf010, 0xf200, 0xf200, 0xf201, 0xf702, 0xf001, 0xf013,
186 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
187 0xf200, 0xf200, 0xf700, 0xf200, 0xf01a, 0xf018, 0xf003, 0xf016,
188 0xf002, 0xf00e, 0xf00d, 0xf200, 0xf200, 0xf07f, 0xf700, 0xf30c,
189 0xf703, 0xf200, 0xf207, 0xf12e, 0xf12f, 0xf130, 0xf131, 0xf132,
190 0xf133, 0xf134, 0xf135, 0xf136, 0xf137, 0xf208, 0xf200, 0xf307,
191 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
192 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf138,
193 0xf139, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
194 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
195 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
196 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
197 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
198 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
199 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
200 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
201 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
202 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
203 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
204 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
205 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
206 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
207 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
208 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
209 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
210 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
211 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
212 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
213 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
182 0xf200, 0xf200, 0xf200, 0xf000, 0xf200, 0xf200, 0xf200, 0xf200,
183 0xf200, 0xf200, 0xf200, 0xf200, 0xf01f, 0xf200, 0xf200, 0xf200,
184 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
185 0xf00f, 0xf010, 0xf200, 0xf200, 0xf201, 0xf702, 0xf001, 0xf013,
186 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
187 0xf200, 0xf200, 0xf700, 0xf200, 0xf01a, 0xf018, 0xf003, 0xf016,
188 0xf002, 0xf00e, 0xf00d, 0xf200, 0xf200, 0xf07f, 0xf700, 0xf30c,
189 0xf703, 0xf200, 0xf207, 0xf12e, 0xf12f, 0xf130, 0xf131, 0xf132,
190 0xf133, 0xf134, 0xf135, 0xf136, 0xf137, 0xf208, 0xf200, 0xf307,
191 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
192 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf138,
193 0xf139, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
194 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
195 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
196 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
197 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
198 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
199 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
200 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
201 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
202 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
203 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
204 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
205 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
206 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
207 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
208 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
209 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
210 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
211 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
212 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
213 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
214214 };
215215
216216 static unsigned short altgr_ctrl_map[NR_KEYS] = {
217 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
218 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
219 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
220 0xf00f, 0xf010, 0xf200, 0xf200, 0xf201, 0xf702, 0xf001, 0xf013,
221 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
222 0xf200, 0xf200, 0xf700, 0xf200, 0xf01a, 0xf018, 0xf003, 0xf016,
223 0xf002, 0xf00e, 0xf00d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
224 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
225 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
226 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
227 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf200, 0xf200,
228 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
229 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
230 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
231 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
232 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
233 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
234 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
235 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
236 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
237 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
238 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
239 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
240 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
241 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
242 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
243 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
244 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
245 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
246 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
247 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
248 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
217 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
218 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
219 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
220 0xf00f, 0xf010, 0xf200, 0xf200, 0xf201, 0xf702, 0xf001, 0xf013,
221 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
222 0xf200, 0xf200, 0xf700, 0xf200, 0xf01a, 0xf018, 0xf003, 0xf016,
223 0xf002, 0xf00e, 0xf00d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
224 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
225 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
226 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
227 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf200, 0xf200,
228 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
229 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
230 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
231 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
232 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
233 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
234 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
235 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
236 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
237 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
238 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
239 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
240 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
241 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
242 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
243 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
244 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
245 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
246 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
247 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
248 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
249249 };
250250
251251 static unsigned short shift_altgr_ctrl_map[NR_KEYS] = {
252 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
253 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
254 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
255 0xf00f, 0xf010, 0xf200, 0xf200, 0xf201, 0xf702, 0xf001, 0xf013,
256 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
257 0xf200, 0xf200, 0xf700, 0xf200, 0xf01a, 0xf018, 0xf003, 0xf016,
258 0xf002, 0xf00e, 0xf00d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
259 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
260 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
261 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
262 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
263 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
264 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
265 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
266 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
267 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
268 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
269 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
270 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
271 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
272 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
273 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
274 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
275 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
276 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
277 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
278 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
279 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
280 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
281 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
282 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
283 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
252 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
253 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
254 0xf011, 0xf017, 0xf005, 0xf012, 0xf014, 0xf019, 0xf015, 0xf009,
255 0xf00f, 0xf010, 0xf200, 0xf200, 0xf201, 0xf702, 0xf001, 0xf013,
256 0xf004, 0xf006, 0xf007, 0xf008, 0xf00a, 0xf00b, 0xf00c, 0xf200,
257 0xf200, 0xf200, 0xf700, 0xf200, 0xf01a, 0xf018, 0xf003, 0xf016,
258 0xf002, 0xf00e, 0xf00d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
259 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
260 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
261 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
262 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
263 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
264 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
265 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
266 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
267 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
268 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
269 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
270 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
271 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
272 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
273 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
274 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
275 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
276 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
277 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
278 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
279 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
280 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
281 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
282 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
283 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
284284 };
285285
286286 static unsigned short alt_map[NR_KEYS] = {
287 0xf200, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
288 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
289 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
290 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
291 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
292 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
293 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
294 0xf703, 0xf820, 0xf207, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
295 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf209, 0xf907,
296 0xf908, 0xf909, 0xf30b, 0xf904, 0xf905, 0xf906, 0xf30a, 0xf901,
297 0xf902, 0xf903, 0xf900, 0xf310, 0xf206, 0xf200, 0xf83c, 0xf50a,
298 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
299 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf701, 0xf205, 0xf114, 0xf603,
300 0xf118, 0xf210, 0xf211, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
301 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
302 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
303 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
304 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
305 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
306 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
307 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
308 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
309 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
310 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
311 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
312 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
313 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
314 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
315 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
316 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
317 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
318 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
287 0xf200, 0xf81b, 0xf831, 0xf832, 0xf833, 0xf834, 0xf835, 0xf836,
288 0xf837, 0xf838, 0xf839, 0xf830, 0xf82d, 0xf83d, 0xf87f, 0xf809,
289 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
290 0xf86f, 0xf870, 0xf85b, 0xf85d, 0xf80d, 0xf702, 0xf861, 0xf873,
291 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf83b,
292 0xf827, 0xf860, 0xf700, 0xf85c, 0xf87a, 0xf878, 0xf863, 0xf876,
293 0xf862, 0xf86e, 0xf86d, 0xf82c, 0xf82e, 0xf82f, 0xf700, 0xf30c,
294 0xf703, 0xf820, 0xf207, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
295 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf209, 0xf907,
296 0xf908, 0xf909, 0xf30b, 0xf904, 0xf905, 0xf906, 0xf30a, 0xf901,
297 0xf902, 0xf903, 0xf900, 0xf310, 0xf206, 0xf200, 0xf83c, 0xf50a,
298 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
299 0xf30e, 0xf702, 0xf30d, 0xf01c, 0xf701, 0xf205, 0xf114, 0xf603,
300 0xf118, 0xf210, 0xf211, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
301 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
302 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
303 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
304 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
305 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
306 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
307 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
308 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
309 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
310 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
311 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
312 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
313 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
314 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
315 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
316 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
317 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
318 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
319319 };
320320
321321 static unsigned short shift_alt_map[NR_KEYS] = {
322 0xf200, 0xf200, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
323 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
324 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
325 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf201, 0xf702, 0xf841, 0xf853,
326 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf200,
327 0xf200, 0xf200, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
328 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf200, 0xf700, 0xf30c,
329 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
330 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
331 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
332 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
333 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
334 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
335 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
336 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
337 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
338 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
339 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
340 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
341 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
342 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
343 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
344 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
345 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
346 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
347 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
348 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
349 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
350 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
351 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
352 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
353 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
322 0xf200, 0xf200, 0xf821, 0xf840, 0xf823, 0xf824, 0xf825, 0xf85e,
323 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
324 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
325 0xf84f, 0xf850, 0xf87b, 0xf87d, 0xf201, 0xf702, 0xf841, 0xf853,
326 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf200,
327 0xf200, 0xf200, 0xf700, 0xf87c, 0xf85a, 0xf858, 0xf843, 0xf856,
328 0xf842, 0xf84e, 0xf84d, 0xf83c, 0xf83e, 0xf200, 0xf700, 0xf30c,
329 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
330 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
331 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
332 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
333 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
334 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
335 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
336 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
337 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
338 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
339 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
340 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
341 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
342 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
343 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
344 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
345 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
346 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
347 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
348 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
349 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
350 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
351 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
352 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
353 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
354354 };
355355
356356 static unsigned short altgr_alt_map[NR_KEYS] = {
357 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
358 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
359 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
360 0xf86f, 0xf870, 0xf200, 0xf200, 0xf201, 0xf702, 0xf861, 0xf873,
361 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf200,
362 0xf200, 0xf200, 0xf700, 0xf200, 0xf87a, 0xf878, 0xf863, 0xf876,
363 0xf862, 0xf86e, 0xf86d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
364 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
365 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
366 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
367 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
368 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
369 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
370 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
371 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
372 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
373 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
374 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
375 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
376 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
377 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
378 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
379 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
380 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
381 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
382 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
383 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
384 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
385 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
386 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
387 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
388 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
357 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
358 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
359 0xf871, 0xf877, 0xf865, 0xf872, 0xf874, 0xf879, 0xf875, 0xf869,
360 0xf86f, 0xf870, 0xf200, 0xf200, 0xf201, 0xf702, 0xf861, 0xf873,
361 0xf864, 0xf866, 0xf867, 0xf868, 0xf86a, 0xf86b, 0xf86c, 0xf200,
362 0xf200, 0xf200, 0xf700, 0xf200, 0xf87a, 0xf878, 0xf863, 0xf876,
363 0xf862, 0xf86e, 0xf86d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
364 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
365 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
366 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
367 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
368 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
369 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
370 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
371 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
372 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
373 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
374 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
375 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
376 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
377 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
378 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
379 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
380 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
381 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
382 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
383 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
384 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
385 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
386 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
387 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
388 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
389389 };
390390
391391 static unsigned short shift_altgr_alt_map[NR_KEYS] = {
392 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
393 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
394 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
395 0xf84f, 0xf850, 0xf200, 0xf200, 0xf201, 0xf702, 0xf841, 0xf853,
396 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf200,
397 0xf200, 0xf200, 0xf700, 0xf200, 0xf85a, 0xf858, 0xf843, 0xf856,
398 0xf842, 0xf84e, 0xf84d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
399 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
400 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
401 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
402 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
403 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
404 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
405 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
406 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
407 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
408 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
409 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
410 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
411 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
412 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
413 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
414 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
415 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
416 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
417 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
418 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
419 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
420 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
421 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
422 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
423 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
392 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
393 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
394 0xf851, 0xf857, 0xf845, 0xf852, 0xf854, 0xf859, 0xf855, 0xf849,
395 0xf84f, 0xf850, 0xf200, 0xf200, 0xf201, 0xf702, 0xf841, 0xf853,
396 0xf844, 0xf846, 0xf847, 0xf848, 0xf84a, 0xf84b, 0xf84c, 0xf200,
397 0xf200, 0xf200, 0xf700, 0xf200, 0xf85a, 0xf858, 0xf843, 0xf856,
398 0xf842, 0xf84e, 0xf84d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
399 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
400 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
401 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
402 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
403 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
404 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
405 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
406 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
407 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
408 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
409 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
410 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
411 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
412 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
413 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
414 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
415 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
416 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
417 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
418 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
419 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
420 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
421 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
422 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
423 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
424424 };
425425
426426 static unsigned short ctrl_alt_map[NR_KEYS] = {
427 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
428 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
429 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
430 0xf80f, 0xf810, 0xf200, 0xf200, 0xf201, 0xf702, 0xf801, 0xf813,
431 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
432 0xf200, 0xf200, 0xf700, 0xf200, 0xf81a, 0xf818, 0xf803, 0xf816,
433 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
434 0xf703, 0xf200, 0xf207, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
435 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf200, 0xf307,
436 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
437 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf200, 0xf50a,
438 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
439 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
440 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
441 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
442 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
443 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
444 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
445 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
446 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
447 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
448 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
449 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
450 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
451 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
452 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
453 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
454 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
455 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
456 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
457 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
458 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
427 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
428 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
429 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
430 0xf80f, 0xf810, 0xf200, 0xf200, 0xf201, 0xf702, 0xf801, 0xf813,
431 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
432 0xf200, 0xf200, 0xf700, 0xf200, 0xf81a, 0xf818, 0xf803, 0xf816,
433 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
434 0xf703, 0xf200, 0xf207, 0xf500, 0xf501, 0xf502, 0xf503, 0xf504,
435 0xf505, 0xf506, 0xf507, 0xf508, 0xf509, 0xf208, 0xf200, 0xf307,
436 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
437 0xf302, 0xf303, 0xf300, 0xf20c, 0xf206, 0xf200, 0xf200, 0xf50a,
438 0xf50b, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
439 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
440 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c,
441 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
442 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
443 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
444 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
445 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
446 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
447 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
448 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
449 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
450 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
451 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
452 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
453 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
454 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
455 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
456 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
457 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
458 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
459459 };
460460
461461 static unsigned short shift_ctrl_alt_map[NR_KEYS] = {
462 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
463 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
464 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
465 0xf80f, 0xf810, 0xf200, 0xf200, 0xf201, 0xf702, 0xf801, 0xf813,
466 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
467 0xf200, 0xf200, 0xf700, 0xf200, 0xf81a, 0xf818, 0xf803, 0xf816,
468 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
469 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
470 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
471 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
472 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
473 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
474 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
475 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
476 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
477 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
478 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
479 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
480 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
481 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
482 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
483 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
484 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
485 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
486 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
487 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
488 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
489 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
490 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
491 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
492 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
493 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
462 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
463 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
464 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
465 0xf80f, 0xf810, 0xf200, 0xf200, 0xf201, 0xf702, 0xf801, 0xf813,
466 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
467 0xf200, 0xf200, 0xf700, 0xf200, 0xf81a, 0xf818, 0xf803, 0xf816,
468 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
469 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
470 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
471 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
472 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
473 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
474 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
475 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
476 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
477 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
478 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
479 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
480 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
481 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
482 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
483 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
484 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
485 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
486 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
487 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
488 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
489 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
490 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
491 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
492 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
493 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
494494 };
495495
496496 static unsigned short altgr_ctrl_alt_map[NR_KEYS] = {
497 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
498 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
499 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
500 0xf80f, 0xf810, 0xf200, 0xf200, 0xf201, 0xf702, 0xf801, 0xf813,
501 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
502 0xf200, 0xf200, 0xf700, 0xf200, 0xf81a, 0xf818, 0xf803, 0xf816,
503 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
504 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
505 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
506 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
507 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
508 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
509 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
510 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
511 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
512 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
513 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
514 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
515 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
516 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
517 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
518 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
519 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
520 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
521 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
522 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
523 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
524 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
525 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
526 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
527 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
528 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
497 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
498 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
499 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
500 0xf80f, 0xf810, 0xf200, 0xf200, 0xf201, 0xf702, 0xf801, 0xf813,
501 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
502 0xf200, 0xf200, 0xf700, 0xf200, 0xf81a, 0xf818, 0xf803, 0xf816,
503 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
504 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
505 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
506 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
507 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
508 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
509 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
510 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
511 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
512 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
513 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
514 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
515 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
516 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
517 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
518 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
519 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
520 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
521 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
522 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
523 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
524 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
525 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
526 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
527 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
528 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
529529 };
530530
531531 static unsigned short shift_altgr_ctrl_alt_map[NR_KEYS] = {
532 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
533 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
534 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
535 0xf80f, 0xf810, 0xf200, 0xf200, 0xf201, 0xf702, 0xf801, 0xf813,
536 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
537 0xf200, 0xf200, 0xf700, 0xf200, 0xf81a, 0xf818, 0xf803, 0xf816,
538 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
539 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
540 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
541 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
542 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
543 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
544 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
545 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
546 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
547 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
548 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
549 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
550 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
551 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
552 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
553 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
554 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
555 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
556 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
557 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
558 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
559 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
560 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
561 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
562 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
563 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
532 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
533 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
534 0xf811, 0xf817, 0xf805, 0xf812, 0xf814, 0xf819, 0xf815, 0xf809,
535 0xf80f, 0xf810, 0xf200, 0xf200, 0xf201, 0xf702, 0xf801, 0xf813,
536 0xf804, 0xf806, 0xf807, 0xf808, 0xf80a, 0xf80b, 0xf80c, 0xf200,
537 0xf200, 0xf200, 0xf700, 0xf200, 0xf81a, 0xf818, 0xf803, 0xf816,
538 0xf802, 0xf80e, 0xf80d, 0xf200, 0xf200, 0xf200, 0xf700, 0xf30c,
539 0xf703, 0xf200, 0xf207, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
540 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf208, 0xf200, 0xf307,
541 0xf308, 0xf309, 0xf30b, 0xf304, 0xf305, 0xf306, 0xf30a, 0xf301,
542 0xf302, 0xf303, 0xf300, 0xf310, 0xf206, 0xf200, 0xf200, 0xf200,
543 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
544 0xf30e, 0xf702, 0xf30d, 0xf200, 0xf701, 0xf205, 0xf114, 0xf603,
545 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116,
546 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d,
547 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
548 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
549 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
550 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
551 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
552 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
553 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
554 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
555 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
556 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
557 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
558 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
559 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
560 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
561 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
562 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
563 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200,
564564 };
565565
566566 ushort *key_maps[MAX_NR_KEYMAPS] = {
567567 plain_map, shift_map, altgr_map, shift_altgr_map,
568568 ctrl_map, shift_ctrl_map, altgr_ctrl_map, shift_altgr_ctrl_map,
569569 alt_map, shift_alt_map, altgr_alt_map, shift_altgr_alt_map,
570 ctrl_alt_map, shift_ctrl_alt_map, altgr_ctrl_alt_map, shift_altgr_ctrl_alt_map, 0
570 ctrl_alt_map, shift_ctrl_alt_map, altgr_ctrl_alt_map, shift_altgr_ctrl_alt_map, 0
571571 };
572572
573573 unsigned int keymap_count = 16;
579579 */
580580
581581 char func_buf[] = {
582 '\033', '[', '[', 'A', 0,
583 '\033', '[', '[', 'B', 0,
584 '\033', '[', '[', 'C', 0,
585 '\033', '[', '[', 'D', 0,
586 '\033', '[', '[', 'E', 0,
587 '\033', '[', '1', '7', '~', 0,
588 '\033', '[', '1', '8', '~', 0,
589 '\033', '[', '1', '9', '~', 0,
590 '\033', '[', '2', '0', '~', 0,
591 '\033', '[', '2', '1', '~', 0,
592 '\033', '[', '2', '3', '~', 0,
593 '\033', '[', '2', '4', '~', 0,
594 '\033', '[', '2', '5', '~', 0,
595 '\033', '[', '2', '6', '~', 0,
596 '\033', '[', '2', '8', '~', 0,
597 '\033', '[', '2', '9', '~', 0,
598 '\033', '[', '3', '1', '~', 0,
599 '\033', '[', '3', '2', '~', 0,
600 '\033', '[', '3', '3', '~', 0,
601 '\033', '[', '3', '4', '~', 0,
602 '\033', '[', '1', '~', 0,
603 '\033', '[', '2', '~', 0,
604 '\033', '[', '3', '~', 0,
605 '\033', '[', '4', '~', 0,
606 '\033', '[', '5', '~', 0,
607 '\033', '[', '6', '~', 0,
608 '\033', '[', 'M', 0,
609 '\033', '[', 'P', 0,
582 '\033', '[', '[', 'A', 0,
583 '\033', '[', '[', 'B', 0,
584 '\033', '[', '[', 'C', 0,
585 '\033', '[', '[', 'D', 0,
586 '\033', '[', '[', 'E', 0,
587 '\033', '[', '1', '7', '~', 0,
588 '\033', '[', '1', '8', '~', 0,
589 '\033', '[', '1', '9', '~', 0,
590 '\033', '[', '2', '0', '~', 0,
591 '\033', '[', '2', '1', '~', 0,
592 '\033', '[', '2', '3', '~', 0,
593 '\033', '[', '2', '4', '~', 0,
594 '\033', '[', '2', '5', '~', 0,
595 '\033', '[', '2', '6', '~', 0,
596 '\033', '[', '2', '8', '~', 0,
597 '\033', '[', '2', '9', '~', 0,
598 '\033', '[', '3', '1', '~', 0,
599 '\033', '[', '3', '2', '~', 0,
600 '\033', '[', '3', '3', '~', 0,
601 '\033', '[', '3', '4', '~', 0,
602 '\033', '[', '1', '~', 0,
603 '\033', '[', '2', '~', 0,
604 '\033', '[', '3', '~', 0,
605 '\033', '[', '4', '~', 0,
606 '\033', '[', '5', '~', 0,
607 '\033', '[', '6', '~', 0,
608 '\033', '[', 'M', 0,
609 '\033', '[', 'P', 0,
610610 };
611611
612612 char *funcbufptr = func_buf;
613 int funcbufsize = sizeof(func_buf);
614 int funcbufleft = 0; /* space left */
613 int funcbufsize = sizeof(func_buf);
614 int funcbufleft = 0; /* space left */
615615
616616 char *func_table[MAX_NR_FUNC] = {
617617 func_buf + 0,
648648 };
649649
650650 struct kbdiacr accent_table[MAX_DIACR] = {
651 {'`', 'A', '\300'}, {'`', 'a', '\340'},
652 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
653 {'^', 'A', '\302'}, {'^', 'a', '\342'},
654 {'~', 'A', '\303'}, {'~', 'a', '\343'},
655 {'"', 'A', '\304'}, {'"', 'a', '\344'},
656 {'O', 'A', '\305'}, {'o', 'a', '\345'},
657 {'0', 'A', '\305'}, {'0', 'a', '\345'},
658 {'A', 'A', '\305'}, {'a', 'a', '\345'},
659 {'A', 'E', '\306'}, {'a', 'e', '\346'},
660 {',', 'C', '\307'}, {',', 'c', '\347'},
661 {'`', 'E', '\310'}, {'`', 'e', '\350'},
662 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
663 {'^', 'E', '\312'}, {'^', 'e', '\352'},
664 {'"', 'E', '\313'}, {'"', 'e', '\353'},
665 {'`', 'I', '\314'}, {'`', 'i', '\354'},
666 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
667 {'^', 'I', '\316'}, {'^', 'i', '\356'},
668 {'"', 'I', '\317'}, {'"', 'i', '\357'},
669 {'-', 'D', '\320'}, {'-', 'd', '\360'},
670 {'~', 'N', '\321'}, {'~', 'n', '\361'},
671 {'`', 'O', '\322'}, {'`', 'o', '\362'},
672 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
673 {'^', 'O', '\324'}, {'^', 'o', '\364'},
674 {'~', 'O', '\325'}, {'~', 'o', '\365'},
675 {'"', 'O', '\326'}, {'"', 'o', '\366'},
676 {'/', 'O', '\330'}, {'/', 'o', '\370'},
677 {'`', 'U', '\331'}, {'`', 'u', '\371'},
678 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
679 {'^', 'U', '\333'}, {'^', 'u', '\373'},
680 {'"', 'U', '\334'}, {'"', 'u', '\374'},
681 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
682 {'T', 'H', '\336'}, {'t', 'h', '\376'},
683 {'s', 's', '\337'}, {'"', 'y', '\377'},
684 {'s', 'z', '\337'}, {'i', 'j', '\377'},
651 { '`', 'A', '\300' }, { '`', 'a', '\340' }, { '\'', 'A', '\301' }, { '\'', 'a', '\341' }, { '^', 'A', '\302' }, { '^', 'a', '\342' }, { '~', 'A', '\303' }, { '~', 'a', '\343' }, { '"', 'A', '\304' }, { '"', 'a', '\344' }, { 'O', 'A', '\305' }, { 'o', 'a', '\345' }, { '0', 'A', '\305' }, { '0', 'a', '\345' }, { 'A', 'A', '\305' }, { 'a', 'a', '\345' }, { 'A', 'E', '\306' }, { 'a', 'e', '\346' }, { ',', 'C', '\307' }, { ',', 'c', '\347' }, { '`', 'E', '\310' }, { '`', 'e', '\350' }, { '\'', 'E', '\311' }, { '\'', 'e', '\351' }, { '^', 'E', '\312' }, { '^', 'e', '\352' }, { '"', 'E', '\313' }, { '"', 'e', '\353' }, { '`', 'I', '\314' }, { '`', 'i', '\354' }, { '\'', 'I', '\315' }, { '\'', 'i', '\355' }, { '^', 'I', '\316' }, { '^', 'i', '\356' }, { '"', 'I', '\317' }, { '"', 'i', '\357' }, { '-', 'D', '\320' }, { '-', 'd', '\360' }, { '~', 'N', '\321' }, { '~', 'n', '\361' }, { '`', 'O', '\322' }, { '`', 'o', '\362' }, { '\'', 'O', '\323' }, { '\'', 'o', '\363' }, { '^', 'O', '\324' }, { '^', 'o', '\364' }, { '~', 'O', '\325' }, { '~', 'o', '\365' }, { '"', 'O', '\326' }, { '"', 'o', '\366' }, { '/', 'O', '\330' }, { '/', 'o', '\370' }, { '`', 'U', '\331' }, { '`', 'u', '\371' }, { '\'', 'U', '\332' }, { '\'', 'u', '\372' }, { '^', 'U', '\333' }, { '^', 'u', '\373' }, { '"', 'U', '\334' }, { '"', 'u', '\374' }, { '\'', 'Y', '\335' }, { '\'', 'y', '\375' }, { 'T', 'H', '\336' }, { 't', 'h', '\376' }, { 's', 's', '\337' }, { '"', 'y', '\377' }, { 's', 'z', '\337' }, { 'i', 'j', '\377' },
685652 };
686653
687654 unsigned int accent_table_size = 68;
1111
1212 f.pipe = 0;
1313 strcpy(f.pathname, argv[1]);
14 f.fd = fopen( argv[1], "r");
14 f.fd = fopen(argv[1], "r");
1515
1616 lk_parse_keymap(ctx, &f);
1717 lk_dump_bkeymap(ctx, stdout);
11 #include <stdlib.h>
22 #include <check.h>
33 #include <keymap.h>
4
54
65 START_TEST(test0)
76 {
5352 static Suite *
5453 libkeymap_suite(void)
5554 {
56 Suite *s = suite_create("libkeymap");
55 Suite *s = suite_create("libkeymap");
5756 TCase *tc_core = tcase_create(NULL);
5857
5958 tcase_add_test(tc_core, test0);
6766 {
6867 int number_failed;
6968
70 Suite *s = libkeymap_suite();
71 SRunner *sr = srunner_create (s);
69 Suite *s = libkeymap_suite();
70 SRunner *sr = srunner_create(s);
7271
7372 srunner_run_all(sr, CK_NORMAL);
7473
7574 number_failed = srunner_ntests_failed(sr);
76 srunner_free (sr);
75 srunner_free(sr);
7776
7877 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
7978 }
1414 return 1;
1515 }
1616
17 if (!strcasecmp(argv[2], "FULL_TABLE")) table = LK_SHAPE_FULL_TABLE;
18 else if (!strcasecmp(argv[2], "SEPARATE_LINES")) table = LK_SHAPE_SEPARATE_LINES;
19 else if (!strcasecmp(argv[2], "UNTIL_HOLE")) table = LK_SHAPE_UNTIL_HOLE;
20 else table = LK_SHAPE_DEFAULT;
17 if (!strcasecmp(argv[2], "FULL_TABLE"))
18 table = LK_SHAPE_FULL_TABLE;
19 else if (!strcasecmp(argv[2], "SEPARATE_LINES"))
20 table = LK_SHAPE_SEPARATE_LINES;
21 else if (!strcasecmp(argv[2], "UNTIL_HOLE"))
22 table = LK_SHAPE_UNTIL_HOLE;
23 else
24 table = LK_SHAPE_DEFAULT;
2125
2226 numeric = (!strcasecmp(argv[3], "TRUE")) ? 1 : 0;
2327
2630
2731 f.pipe = 0;
2832 strcpy(f.pathname, argv[1]);
29 f.fd = fopen( argv[1], "r");
33 f.fd = fopen(argv[1], "r");
3034
3135 lk_parse_keymap(ctx, &f);
3236 lk_dump_keymap(ctx, stdout, table, numeric);
11 #include <stdlib.h>
22 #include <check.h>
33 #include <keymap.h>
4
54
65 START_TEST(test_create_0)
76 {
109 ctx = lk_init();
1110
1211 fail_if(ctx == NULL,
13 "Unable to initialize structure by valid pointer");
12 "Unable to initialize structure by valid pointer");
1413 lk_free(ctx);
1514 }
1615 END_TEST
2221 ctx = lk_init();
2322
2423 fail_if(ctx == NULL,
25 "Unable to initialize structure by valid pointer");
24 "Unable to initialize structure by valid pointer");
2625
2726 fail_unless(lk_free(ctx) == 0,
28 "Unable to free by valid pointer");
27 "Unable to free by valid pointer");
2928 }
3029 END_TEST
3130
3231 START_TEST(test_free_1)
3332 {
3433 fail_if(lk_free(NULL) == 0,
35 "Possible to free NULL pointer");
34 "Possible to free NULL pointer");
3635 }
3736 END_TEST
38
3937
4038 static Suite *
4139 libkeymap_suite(void)
4240 {
43 Suite *s = suite_create("libkeymap");
41 Suite *s = suite_create("libkeymap");
4442 TCase *tc_core = tcase_create(NULL);
4543
4644 tcase_add_test(tc_core, test_create_0);
5553 {
5654 int number_failed;
5755
58 Suite *s = libkeymap_suite();
59 SRunner *sr = srunner_create (s);
56 Suite *s = libkeymap_suite();
57 SRunner *sr = srunner_create(s);
6058
6159 srunner_run_all(sr, CK_NORMAL);
6260
6361 number_failed = srunner_ntests_failed(sr);
64 srunner_free (sr);
62 srunner_free(sr);
6563
6664 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
6765 }
11 #include <stdlib.h>
22 #include <check.h>
33 #include <keymap.h>
4
54
65 START_TEST(test_add_key_0)
76 {
1110 lk_set_log_fn(ctx, NULL, NULL);
1211
1312 fail_if(lk_add_key(ctx, 0, NR_KEYS + 1, 0) != 0,
14 "Unable to use index > NR_KEYS");
13 "Unable to use index > NR_KEYS");
1514
1615 fail_if(lk_add_key(ctx, MAX_NR_KEYMAPS + 1, 0, 0) != 0,
17 "Unable to use table > MAX_NR_KEYMAPS");
16 "Unable to use table > MAX_NR_KEYMAPS");
1817
1918 lk_free(ctx);
2019 }
2827 lk_set_log_fn(ctx, NULL, NULL);
2928
3029 fail_unless(lk_add_key(ctx, 0, 0, 0) == 0,
31 "Unable to add keycode = 0");
30 "Unable to add keycode = 0");
3231
3332 fail_unless(lk_add_key(ctx, 0, 0, 16) == 0,
34 "Unable to add keycode = 16");
33 "Unable to add keycode = 16");
3534
3635 fail_unless(lk_add_key(ctx, 1, 1, K_HOLE) == 0,
37 "Unable to add keycode = K_HOLE");
36 "Unable to add keycode = K_HOLE");
3837
3938 lk_free(ctx);
4039 }
4948 lk_set_parser_flags(ctx, LK_KEYWORD_ALTISMETA);
5049
5150 fail_unless(lk_add_key(ctx, 0, 0, 16) == 0,
52 "Unable to add keycode");
51 "Unable to add keycode");
5352
5453 fail_unless(lk_get_key(ctx, 0, 0) == 16,
55 "Unable to get keycode");
54 "Unable to get keycode");
5655
5756 lk_free(ctx);
5857 }
6261 {
6362 char *stringvalues[30] = {
6463 /* F1 .. F20 */
65 "\033[[A", "\033[[B", "\033[[C", "\033[[D", "\033[[E",
64 "\033[[A", "\033[[B", "\033[[C", "\033[[D", "\033[[E",
6665 "\033[17~", "\033[18~", "\033[19~", "\033[20~", "\033[21~",
6766 "\033[23~", "\033[24~", "\033[25~", "\033[26~",
6867 "\033[28~", "\033[29~",
6968 "\033[31~", "\033[32~", "\033[33~", "\033[34~",
7069 /* Find, Insert, Remove, Select, Prior */
71 "\033[1~", "\033[2~", "\033[3~", "\033[4~", "\033[5~",
70 "\033[1~", "\033[2~", "\033[3~", "\033[4~", "\033[5~",
7271 /* Next, Macro, Help, Do, Pause */
73 "\033[6~", 0, 0, 0, 0
72 "\033[6~", 0, 0, 0, 0
7473 };
7574 int i;
7675 struct lk_ctx *ctx;
8584 continue;
8685
8786 strncpy((char *)ke.kb_string, stringvalues[i],
88 sizeof(ke.kb_string));
87 sizeof(ke.kb_string));
8988 ke.kb_string[sizeof(ke.kb_string) - 1] = 0;
90 ke.kb_func = i;
89 ke.kb_func = i;
9190
9291 fail_if(lk_add_func(ctx, &ke) == -1,
93 "Unable to add function");
92 "Unable to add function");
9493 }
9594
9695 lk_free(ctx);
112111
113112 while (i > 0) {
114113 fail_if(lk_append_diacr(ctx, &ptr) != 0,
115 "Unable to add diacr");
114 "Unable to add diacr");
116115 i--;
117116 }
118117
123122 static Suite *
124123 libkeymap_suite(void)
125124 {
126 Suite *s = suite_create("libkeymap");
125 Suite *s = suite_create("libkeymap");
127126 TCase *tc_core = tcase_create(NULL);
128127
129128 tcase_add_test(tc_core, test_add_key_0);
140139 {
141140 int number_failed;
142141
143 Suite *s = libkeymap_suite();
144 SRunner *sr = srunner_create (s);
142 Suite *s = libkeymap_suite();
143 SRunner *sr = srunner_create(s);
145144
146145 srunner_run_all(sr, CK_NORMAL);
147146
148147 number_failed = srunner_ntests_failed(sr);
149 srunner_free (sr);
148 srunner_free(sr);
150149
151150 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
152151 }
11 #include <stdlib.h>
22 #include <check.h>
33 #include <keymap.h>
4
54
65 START_TEST(test_add_map_border)
76 {
1110 lk_set_log_fn(ctx, NULL, NULL);
1211
1312 fail_unless(lk_add_map(ctx, MAX_NR_KEYMAPS) == 0,
14 "Unable to define map == MAX_NR_KEYMAPS");
13 "Unable to define map == MAX_NR_KEYMAPS");
1514
16 fail_unless(lk_add_map(ctx, MAX_NR_KEYMAPS*2) == 0,
17 "Unable to define map == MAX_NR_KEYMAPS*2");
15 fail_unless(lk_add_map(ctx, MAX_NR_KEYMAPS * 2) == 0,
16 "Unable to define map == MAX_NR_KEYMAPS*2");
1817
1918 fail_unless(lk_add_map(ctx, 0) == 0,
20 "Unable to define map");
19 "Unable to define map");
2120
2221 fail_unless(lk_add_map(ctx, 0) == 0,
23 "Unable to define map");
22 "Unable to define map");
2423
2524 lk_free(ctx);
2625 }
4140 fail_if(lk_add_map(ctx, 0) != 0, "Unable to define map");
4241 lk_get_kmapinfo(ctx, &info);
4342 fail_if(info.keymaps != 1, "Wrong keymap number");
44
43
4544 fail_if(lk_add_map(ctx, 1) != 0, "Unable to define map");
4645 lk_get_kmapinfo(ctx, &info);
4746 fail_if(info.keymaps != 2, "Wrong keymap number");
5756 static Suite *
5857 libkeymap_suite(void)
5958 {
60 Suite *s = suite_create("libkeymap");
59 Suite *s = suite_create("libkeymap");
6160 TCase *tc_core = tcase_create(NULL);
6261
6362 tcase_add_test(tc_core, test_add_map_border);
7170 {
7271 int number_failed;
7372
74 Suite *s = libkeymap_suite();
75 SRunner *sr = srunner_create (s);
73 Suite *s = libkeymap_suite();
74 SRunner *sr = srunner_create(s);
7675
7776 srunner_run_all(sr, CK_NORMAL);
7877
7978 number_failed = srunner_ntests_failed(sr);
80 srunner_free (sr);
79 srunner_free(sr);
8180
8281 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
8382 }
1111
1212 f.pipe = 0;
1313 strcpy(f.pathname, argv[1]);
14 f.fd = fopen( argv[1], "r");
14 f.fd = fopen(argv[1], "r");
1515
1616 lk_parse_keymap(ctx, &f);
1717 lk_dump_ctable(ctx, stdout);
1010 const char ch;
1111 };
1212
13
1413 START_TEST(test_parse_0)
1514 {
1615 int c;
167166
168167 fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
169168
170 for(i = 0; i < MAX_NR_FUNC; i++) {
171 kbs.kb_func = i;
169 for (i = 0; i < MAX_NR_FUNC; i++) {
170 kbs.kb_func = i;
172171 kbs.kb_string[0] = 0;
173172 fail_if(lk_get_func(ctx, &kbs) != 0,
174 "Unable to get func %d", i);
173 "Unable to get func %d", i);
175174 }
176175
177176 lk_free(ctx);
193192
194193 fail_if(lk_parse_keymap(ctx, &f) != 0, "Unable to parse keymap");
195194
196 kbs.kb_func = 0;
195 kbs.kb_func = 0;
197196 kbs.kb_string[0] = 0;
198197 fail_if(lk_get_func(ctx, &kbs) != 0, "Unable to get func 0");
199198
200 kbs.kb_func = 1;
199 kbs.kb_func = 1;
201200 kbs.kb_string[0] = 0;
202201 fail_if(lk_get_func(ctx, &kbs) != 0, "Unable to get func 1");
203202
204 kbs.kb_func = 2;
203 kbs.kb_func = 2;
205204 kbs.kb_string[0] = 0;
206205 fail_if(lk_get_func(ctx, &kbs) != -1, "Possible to get not alloced func");
207206
212211 static Suite *
213212 libkeymap_suite(void)
214213 {
215 Suite *s = suite_create("libkeymap");
214 Suite *s = suite_create("libkeymap");
216215 TCase *tc_core = tcase_create(NULL);
217216
218217 setenv("LOADKEYS_INCLUDE_PATH", DATADIR, 1);
233232 {
234233 int number_failed;
235234
236 Suite *s = libkeymap_suite();
237 SRunner *sr = srunner_create (s);
235 Suite *s = libkeymap_suite();
236 SRunner *sr = srunner_create(s);
238237
239238 srunner_run_all(sr, CK_NORMAL);
240239
241240 number_failed = srunner_ntests_failed(sr);
242 srunner_free (sr);
241 srunner_free(sr);
243242
244243 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
245244 }
1414
1515 f.pipe = 0;
1616 strcpy(f.pathname, argv[1]);
17 f.fd = fopen( argv[1], "r");
17 f.fd = fopen(argv[1], "r");
1818
1919 lk_parse_keymap(ctx, &f);
2020