diff options
author | nobody <nobody@localhost> | 2004-10-13 09:42:10 +0000 |
---|---|---|
committer | nobody <nobody@localhost> | 2004-10-13 09:42:10 +0000 |
commit | 8c59a0bf0e9e2d87b0ff273ea3f0bf05bbbf6373 (patch) | |
tree | 1826706cd4fd009fcd14f4f8021005ec8ec0fa59 /busybox/console-tools | |
download | busybox-w32-8c59a0bf0e9e2d87b0ff273ea3f0bf05bbbf6373.tar.gz busybox-w32-8c59a0bf0e9e2d87b0ff273ea3f0bf05bbbf6373.tar.bz2 busybox-w32-8c59a0bf0e9e2d87b0ff273ea3f0bf05bbbf6373.zip |
This commit was manufactured by cvs2svn to create tag 'busybox_1_00'.
Diffstat (limited to 'busybox/console-tools')
-rw-r--r-- | busybox/console-tools/Config.in | 68 | ||||
-rw-r--r-- | busybox/console-tools/Makefile | 32 | ||||
-rw-r--r-- | busybox/console-tools/Makefile.in | 44 | ||||
-rw-r--r-- | busybox/console-tools/chvt.c | 61 | ||||
-rw-r--r-- | busybox/console-tools/clear.c | 34 | ||||
-rw-r--r-- | busybox/console-tools/deallocvt.c | 56 | ||||
-rw-r--r-- | busybox/console-tools/dumpkmap.c | 91 | ||||
-rw-r--r-- | busybox/console-tools/loadfont.c | 207 | ||||
-rw-r--r-- | busybox/console-tools/loadkmap.c | 82 | ||||
-rw-r--r-- | busybox/console-tools/openvt.c | 84 | ||||
-rw-r--r-- | busybox/console-tools/reset.c | 45 | ||||
-rw-r--r-- | busybox/console-tools/setkeycodes.c | 72 |
12 files changed, 876 insertions, 0 deletions
diff --git a/busybox/console-tools/Config.in b/busybox/console-tools/Config.in new file mode 100644 index 000000000..e261794ab --- /dev/null +++ b/busybox/console-tools/Config.in | |||
@@ -0,0 +1,68 @@ | |||
1 | # | ||
2 | # For a description of the syntax of this configuration file, | ||
3 | # see scripts/kbuild/config-language.txt. | ||
4 | # | ||
5 | |||
6 | menu "Console Utilities" | ||
7 | |||
8 | config CONFIG_CHVT | ||
9 | bool "chvt" | ||
10 | default n | ||
11 | help | ||
12 | This program is used to change to another terminal. | ||
13 | Example: chvt 4 (change to terminal /dev/tty4) | ||
14 | |||
15 | config CONFIG_CLEAR | ||
16 | bool "clear" | ||
17 | default n | ||
18 | help | ||
19 | This program clears the terminal screen. | ||
20 | |||
21 | config CONFIG_DEALLOCVT | ||
22 | bool "deallocvt" | ||
23 | default n | ||
24 | help | ||
25 | This program deallocates unused virtual consoles. | ||
26 | |||
27 | config CONFIG_DUMPKMAP | ||
28 | bool "dumpkmap" | ||
29 | default n | ||
30 | help | ||
31 | This program dumps the kernel's keyboard translation table to | ||
32 | stdout, in binary format. You can then use loadkmap to load it. | ||
33 | |||
34 | config CONFIG_LOADFONT | ||
35 | bool "loadfont" | ||
36 | default n | ||
37 | help | ||
38 | This program loads a console font from standard input. | ||
39 | |||
40 | config CONFIG_LOADKMAP | ||
41 | bool "loadkmap" | ||
42 | default n | ||
43 | help | ||
44 | This program loads a keyboard translation table from | ||
45 | standard input. | ||
46 | |||
47 | config CONFIG_OPENVT | ||
48 | bool "openvt" | ||
49 | default n | ||
50 | help | ||
51 | This program is used to start a command on an unused | ||
52 | virtual terminal. | ||
53 | |||
54 | config CONFIG_RESET | ||
55 | bool "reset" | ||
56 | default n | ||
57 | help | ||
58 | This program is used to reset the terminal screen, if it | ||
59 | gets messed up. | ||
60 | |||
61 | config CONFIG_SETKEYCODES | ||
62 | bool "setkeycodes" | ||
63 | default n | ||
64 | help | ||
65 | This program loads entries into the kernel's scancode-to-keycode | ||
66 | map, allowing unusual keyboards to generate usable keycodes. | ||
67 | |||
68 | endmenu | ||
diff --git a/busybox/console-tools/Makefile b/busybox/console-tools/Makefile new file mode 100644 index 000000000..42cf2c8c3 --- /dev/null +++ b/busybox/console-tools/Makefile | |||
@@ -0,0 +1,32 @@ | |||
1 | # Makefile for busybox | ||
2 | # | ||
3 | # Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | ||
4 | # | ||
5 | # This program is free software; you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License as published by | ||
7 | # the Free Software Foundation; either version 2 of the License, or | ||
8 | # (at your option) any later version. | ||
9 | # | ||
10 | # This program is distributed in the hope that it will be useful, | ||
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | # General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with this program; if not, write to the Free Software | ||
17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | # | ||
19 | |||
20 | top_srcdir=.. | ||
21 | top_builddir=.. | ||
22 | srcdir=$(top_srcdir)/console/tools | ||
23 | CONSOLETOOLS_DIR:=./ | ||
24 | include $(top_builddir)/Rules.mak | ||
25 | include $(top_builddir)/.config | ||
26 | include $(srcdir)/Makefile.in | ||
27 | all: $(libraries-y) | ||
28 | -include $(top_builddir)/.depend | ||
29 | |||
30 | clean: | ||
31 | rm -f *.o *.a $(AR_TARGET) | ||
32 | |||
diff --git a/busybox/console-tools/Makefile.in b/busybox/console-tools/Makefile.in new file mode 100644 index 000000000..b19ce5cb2 --- /dev/null +++ b/busybox/console-tools/Makefile.in | |||
@@ -0,0 +1,44 @@ | |||
1 | # Makefile for busybox | ||
2 | # | ||
3 | # Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | ||
4 | # | ||
5 | # This program is free software; you can redistribute it and/or modify | ||
6 | # it under the terms of the GNU General Public License as published by | ||
7 | # the Free Software Foundation; either version 2 of the License, or | ||
8 | # (at your option) any later version. | ||
9 | # | ||
10 | # This program is distributed in the hope that it will be useful, | ||
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | # General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU General Public License | ||
16 | # along with this program; if not, write to the Free Software | ||
17 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | # | ||
19 | |||
20 | CONSOLETOOLS_AR:=console-tools.a | ||
21 | ifndef $(CONSOLETOOLS_DIR) | ||
22 | CONSOLETOOLS_DIR:=$(top_builddir)/console-tools/ | ||
23 | endif | ||
24 | srcdir=$(top_srcdir)/console-tools | ||
25 | |||
26 | CONSOLETOOLS_DIR-y:= | ||
27 | CONSOLETOOLS_DIR-$(CONFIG_CHVT) += chvt.o | ||
28 | CONSOLETOOLS_DIR-$(CONFIG_CLEAR) += clear.o | ||
29 | CONSOLETOOLS_DIR-$(CONFIG_DEALLOCVT) += deallocvt.o | ||
30 | CONSOLETOOLS_DIR-$(CONFIG_DUMPKMAP) += dumpkmap.o | ||
31 | CONSOLETOOLS_DIR-$(CONFIG_LOADFONT) += loadfont.o | ||
32 | CONSOLETOOLS_DIR-$(CONFIG_LOADKMAP) += loadkmap.o | ||
33 | CONSOLETOOLS_DIR-$(CONFIG_OPENVT) += openvt.o | ||
34 | CONSOLETOOLS_DIR-$(CONFIG_RESET) += reset.o | ||
35 | CONSOLETOOLS_DIR-$(CONFIG_SETKEYCODES) += setkeycodes.o | ||
36 | |||
37 | libraries-y+=$(CONSOLETOOLS_DIR)$(CONSOLETOOLS_AR) | ||
38 | |||
39 | $(CONSOLETOOLS_DIR)$(CONSOLETOOLS_AR): $(patsubst %,$(CONSOLETOOLS_DIR)%, $(CONSOLETOOLS_DIR-y)) | ||
40 | $(AR) -ro $@ $(patsubst %,$(CONSOLETOOLS_DIR)%, $(CONSOLETOOLS_DIR-y)) | ||
41 | |||
42 | $(CONSOLETOOLS_DIR)%.o: $(srcdir)/%.c | ||
43 | $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< | ||
44 | |||
diff --git a/busybox/console-tools/chvt.c b/busybox/console-tools/chvt.c new file mode 100644 index 000000000..3398892f5 --- /dev/null +++ b/busybox/console-tools/chvt.c | |||
@@ -0,0 +1,61 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Mini chvt implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | * GNU General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | */ | ||
21 | |||
22 | /* no options, no getopt */ | ||
23 | |||
24 | #include <stdio.h> | ||
25 | #include <stdlib.h> | ||
26 | #include <fcntl.h> | ||
27 | #include <sys/types.h> | ||
28 | #include <sys/ioctl.h> | ||
29 | #include "busybox.h" | ||
30 | |||
31 | /* From <linux/vt.h> */ | ||
32 | static const int VT_ACTIVATE = 0x5606; /* make vt active */ | ||
33 | static const int VT_WAITACTIVE = 0x5607; /* wait for vt active */ | ||
34 | |||
35 | int chvt_main(int argc, char **argv) | ||
36 | { | ||
37 | int fd, num; | ||
38 | |||
39 | if (argc != 2) { | ||
40 | bb_show_usage(); | ||
41 | } | ||
42 | |||
43 | fd = get_console_fd(); | ||
44 | num = bb_xgetlarg(argv[1], 10, 0, INT_MAX); | ||
45 | if (ioctl(fd, VT_ACTIVATE, num)) { | ||
46 | bb_perror_msg_and_die("VT_ACTIVATE"); | ||
47 | } | ||
48 | if (ioctl(fd, VT_WAITACTIVE, num)) { | ||
49 | bb_perror_msg_and_die("VT_WAITACTIVE"); | ||
50 | } | ||
51 | return EXIT_SUCCESS; | ||
52 | } | ||
53 | |||
54 | |||
55 | /* | ||
56 | Local Variables: | ||
57 | c-file-style: "linux" | ||
58 | c-basic-offset: 4 | ||
59 | tab-width: 4 | ||
60 | End: | ||
61 | */ | ||
diff --git a/busybox/console-tools/clear.c b/busybox/console-tools/clear.c new file mode 100644 index 000000000..e43ed0e02 --- /dev/null +++ b/busybox/console-tools/clear.c | |||
@@ -0,0 +1,34 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Mini clear implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | /* no options, no getopt */ | ||
24 | |||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | #include "busybox.h" | ||
28 | |||
29 | |||
30 | extern int clear_main(int argc, char **argv) | ||
31 | { | ||
32 | printf("\033[H\033[J"); | ||
33 | return EXIT_SUCCESS; | ||
34 | } | ||
diff --git a/busybox/console-tools/deallocvt.c b/busybox/console-tools/deallocvt.c new file mode 100644 index 000000000..08a9d2122 --- /dev/null +++ b/busybox/console-tools/deallocvt.c | |||
@@ -0,0 +1,56 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Disallocate virtual terminal(s) | ||
4 | * | ||
5 | * Copyright (C) 2003 by Tito Ragusa <farmatito@tiscali.it> | ||
6 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | */ | ||
22 | |||
23 | /* no options, no getopt */ | ||
24 | |||
25 | #include <stdlib.h> | ||
26 | #include <stdio.h> | ||
27 | #include <fcntl.h> | ||
28 | #include <sys/types.h> | ||
29 | #include <sys/ioctl.h> | ||
30 | #include "busybox.h" | ||
31 | |||
32 | /* From <linux/vt.h> */ | ||
33 | static const int VT_DISALLOCATE = 0x5608; /* free memory associated to vt */ | ||
34 | |||
35 | int deallocvt_main(int argc, char *argv[]) | ||
36 | { | ||
37 | /* num = 0 deallocate all unused consoles */ | ||
38 | int num = 0; | ||
39 | |||
40 | switch(argc) | ||
41 | { | ||
42 | case 2: | ||
43 | if((num = bb_xgetlarg(argv[1], 10, 0, INT_MAX)) == 0) | ||
44 | bb_error_msg_and_die("0: illegal VT number"); | ||
45 | /* Falltrough */ | ||
46 | case 1: | ||
47 | break; | ||
48 | default: | ||
49 | bb_show_usage(); | ||
50 | } | ||
51 | |||
52 | if (ioctl( get_console_fd(), VT_DISALLOCATE, num )) { | ||
53 | bb_perror_msg_and_die("VT_DISALLOCATE"); | ||
54 | } | ||
55 | return EXIT_SUCCESS; | ||
56 | } | ||
diff --git a/busybox/console-tools/dumpkmap.c b/busybox/console-tools/dumpkmap.c new file mode 100644 index 000000000..6085a446b --- /dev/null +++ b/busybox/console-tools/dumpkmap.c | |||
@@ -0,0 +1,91 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Mini dumpkmap implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) Arne Bernin <arne@matrix.loopback.org> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <errno.h> | ||
24 | #include <fcntl.h> | ||
25 | #include <stdio.h> | ||
26 | #include <unistd.h> | ||
27 | #include <string.h> | ||
28 | #include <stdlib.h> | ||
29 | #include <sys/ioctl.h> | ||
30 | #include "busybox.h" | ||
31 | |||
32 | /* From <linux/kd.h> */ | ||
33 | struct kbentry { | ||
34 | unsigned char kb_table; | ||
35 | unsigned char kb_index; | ||
36 | unsigned short kb_value; | ||
37 | }; | ||
38 | static const int KDGKBENT = 0x4B46; /* gets one entry in translation table */ | ||
39 | |||
40 | /* From <linux/keyboard.h> */ | ||
41 | static const int NR_KEYS = 128; | ||
42 | static const int MAX_NR_KEYMAPS = 256; | ||
43 | |||
44 | int dumpkmap_main(int argc, char **argv) | ||
45 | { | ||
46 | struct kbentry ke; | ||
47 | int i, j, fd; | ||
48 | char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap"; | ||
49 | |||
50 | if (argc>=2 && *argv[1]=='-') { | ||
51 | bb_show_usage(); | ||
52 | } | ||
53 | |||
54 | fd=bb_xopen(CURRENT_VC, O_RDWR); | ||
55 | |||
56 | write(1, magic, 7); | ||
57 | |||
58 | for (i=0; i < MAX_NR_KEYMAPS; i++) flags[i]=0; | ||
59 | flags[0]=1; | ||
60 | flags[1]=1; | ||
61 | flags[2]=1; | ||
62 | flags[4]=1; | ||
63 | flags[5]=1; | ||
64 | flags[6]=1; | ||
65 | flags[8]=1; | ||
66 | flags[9]=1; | ||
67 | flags[10]=1; | ||
68 | flags[12]=1; | ||
69 | |||
70 | /* dump flags */ | ||
71 | for (i=0; i < MAX_NR_KEYMAPS; i++) write(1,&flags[i],1); | ||
72 | |||
73 | for (i = 0; i < MAX_NR_KEYMAPS; i++) { | ||
74 | if (flags[i] == 1) { | ||
75 | for (j = 0; j < NR_KEYS; j++) { | ||
76 | ke.kb_index = j; | ||
77 | ke.kb_table = i; | ||
78 | if (ioctl(fd, KDGKBENT, &ke) < 0) { | ||
79 | |||
80 | bb_error_msg("ioctl returned: %m, %s, %s, %xqq", (char *)&ke.kb_index,(char *)&ke.kb_table,(int)&ke.kb_value); | ||
81 | } | ||
82 | else { | ||
83 | write(1,(void*)&ke.kb_value,2); | ||
84 | } | ||
85 | |||
86 | } | ||
87 | } | ||
88 | } | ||
89 | close(fd); | ||
90 | return EXIT_SUCCESS; | ||
91 | } | ||
diff --git a/busybox/console-tools/loadfont.c b/busybox/console-tools/loadfont.c new file mode 100644 index 000000000..4580dc4e0 --- /dev/null +++ b/busybox/console-tools/loadfont.c | |||
@@ -0,0 +1,207 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * loadfont.c - Eugene Crosser & Andries Brouwer | ||
4 | * | ||
5 | * Version 0.96bb | ||
6 | * | ||
7 | * Loads the console font, and possibly the corresponding screen map(s). | ||
8 | * (Adapted for busybox by Matej Vela.) | ||
9 | */ | ||
10 | #include <stdio.h> | ||
11 | #include <string.h> | ||
12 | #include <fcntl.h> | ||
13 | #include <memory.h> | ||
14 | #include <stdlib.h> | ||
15 | #include <unistd.h> | ||
16 | #include <sys/types.h> | ||
17 | #include <dirent.h> | ||
18 | #include <errno.h> | ||
19 | #include <sys/ioctl.h> | ||
20 | #include <sys/kd.h> | ||
21 | #include <endian.h> | ||
22 | #include "busybox.h" | ||
23 | |||
24 | static const int PSF_MAGIC1 = 0x36; | ||
25 | static const int PSF_MAGIC2 = 0x04; | ||
26 | |||
27 | static const int PSF_MODE512 = 0x01; | ||
28 | static const int PSF_MODEHASTAB = 0x02; | ||
29 | static const int PSF_MAXMODE = 0x03; | ||
30 | static const int PSF_SEPARATOR = 0xFFFF; | ||
31 | |||
32 | struct psf_header { | ||
33 | unsigned char magic1, magic2; /* Magic number */ | ||
34 | unsigned char mode; /* PSF font mode */ | ||
35 | unsigned char charsize; /* Character size */ | ||
36 | }; | ||
37 | |||
38 | #define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2) | ||
39 | |||
40 | static void loadnewfont(int fd); | ||
41 | |||
42 | extern int loadfont_main(int argc, char **argv) | ||
43 | { | ||
44 | int fd; | ||
45 | |||
46 | if (argc != 1) | ||
47 | bb_show_usage(); | ||
48 | |||
49 | fd = bb_xopen(CURRENT_VC, O_RDWR); | ||
50 | loadnewfont(fd); | ||
51 | |||
52 | return EXIT_SUCCESS; | ||
53 | } | ||
54 | |||
55 | static void do_loadfont(int fd, char *inbuf, int unit, int fontsize) | ||
56 | { | ||
57 | char buf[16384]; | ||
58 | int i; | ||
59 | |||
60 | memset(buf, 0, sizeof(buf)); | ||
61 | |||
62 | if (unit < 1 || unit > 32) | ||
63 | bb_error_msg_and_die("Bad character size %d", unit); | ||
64 | |||
65 | for (i = 0; i < fontsize; i++) | ||
66 | memcpy(buf + (32 * i), inbuf + (unit * i), unit); | ||
67 | |||
68 | #if defined( PIO_FONTX ) && !defined( __sparc__ ) | ||
69 | { | ||
70 | struct consolefontdesc cfd; | ||
71 | |||
72 | cfd.charcount = fontsize; | ||
73 | cfd.charheight = unit; | ||
74 | cfd.chardata = buf; | ||
75 | |||
76 | if (ioctl(fd, PIO_FONTX, &cfd) == 0) | ||
77 | return; /* success */ | ||
78 | bb_perror_msg("PIO_FONTX ioctl error (trying PIO_FONT)"); | ||
79 | } | ||
80 | #endif | ||
81 | if (ioctl(fd, PIO_FONT, buf)) | ||
82 | bb_perror_msg_and_die("PIO_FONT ioctl error"); | ||
83 | } | ||
84 | |||
85 | static void | ||
86 | do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) | ||
87 | { | ||
88 | struct unimapinit advice; | ||
89 | struct unimapdesc ud; | ||
90 | struct unipair *up; | ||
91 | int ct = 0, maxct; | ||
92 | int glyph; | ||
93 | u_short unicode; | ||
94 | |||
95 | maxct = tailsz; /* more than enough */ | ||
96 | up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair)); | ||
97 | |||
98 | for (glyph = 0; glyph < fontsize; glyph++) { | ||
99 | while (tailsz >= 2) { | ||
100 | unicode = (((u_short) inbuf[1]) << 8) + inbuf[0]; | ||
101 | tailsz -= 2; | ||
102 | inbuf += 2; | ||
103 | if (unicode == PSF_SEPARATOR) | ||
104 | break; | ||
105 | up[ct].unicode = unicode; | ||
106 | up[ct].fontpos = glyph; | ||
107 | ct++; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | /* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP | ||
112 | this printf did not work on many kernels */ | ||
113 | |||
114 | advice.advised_hashsize = 0; | ||
115 | advice.advised_hashstep = 0; | ||
116 | advice.advised_hashlevel = 0; | ||
117 | if (ioctl(fd, PIO_UNIMAPCLR, &advice)) { | ||
118 | #ifdef ENOIOCTLCMD | ||
119 | if (errno == ENOIOCTLCMD) { | ||
120 | bb_error_msg("It seems this kernel is older than 1.1.92"); | ||
121 | bb_error_msg_and_die("No Unicode mapping table loaded."); | ||
122 | } else | ||
123 | #endif | ||
124 | bb_perror_msg_and_die("PIO_UNIMAPCLR"); | ||
125 | } | ||
126 | ud.entry_ct = ct; | ||
127 | ud.entries = up; | ||
128 | if (ioctl(fd, PIO_UNIMAP, &ud)) { | ||
129 | #if 0 | ||
130 | if (errno == ENOMEM) { | ||
131 | /* change advice parameters */ | ||
132 | } | ||
133 | #endif | ||
134 | bb_perror_msg_and_die("PIO_UNIMAP"); | ||
135 | } | ||
136 | } | ||
137 | |||
138 | static void loadnewfont(int fd) | ||
139 | { | ||
140 | int unit; | ||
141 | char inbuf[32768]; /* primitive */ | ||
142 | unsigned int inputlth, offset; | ||
143 | |||
144 | /* | ||
145 | * We used to look at the length of the input file | ||
146 | * with stat(); now that we accept compressed files, | ||
147 | * just read the entire file. | ||
148 | */ | ||
149 | inputlth = fread(inbuf, 1, sizeof(inbuf), stdin); | ||
150 | if (ferror(stdin)) | ||
151 | bb_perror_msg_and_die("Error reading input font"); | ||
152 | /* use malloc/realloc in case of giant files; | ||
153 | maybe these do not occur: 16kB for the font, | ||
154 | and 16kB for the map leaves 32 unicode values | ||
155 | for each font position */ | ||
156 | if (!feof(stdin)) | ||
157 | bb_perror_msg_and_die("Font too large"); | ||
158 | |||
159 | /* test for psf first */ | ||
160 | { | ||
161 | struct psf_header psfhdr; | ||
162 | int fontsize; | ||
163 | int hastable; | ||
164 | unsigned int head0, head; | ||
165 | |||
166 | if (inputlth < sizeof(struct psf_header)) | ||
167 | goto no_psf; | ||
168 | |||
169 | psfhdr = *(struct psf_header *) &inbuf[0]; | ||
170 | |||
171 | if (!PSF_MAGIC_OK(psfhdr)) | ||
172 | goto no_psf; | ||
173 | |||
174 | if (psfhdr.mode > PSF_MAXMODE) | ||
175 | bb_error_msg_and_die("Unsupported psf file mode"); | ||
176 | fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256); | ||
177 | #if !defined( PIO_FONTX ) || defined( __sparc__ ) | ||
178 | if (fontsize != 256) | ||
179 | bb_error_msg_and_die("Only fontsize 256 supported"); | ||
180 | #endif | ||
181 | hastable = (psfhdr.mode & PSF_MODEHASTAB); | ||
182 | unit = psfhdr.charsize; | ||
183 | head0 = sizeof(struct psf_header); | ||
184 | |||
185 | head = head0 + fontsize * unit; | ||
186 | if (head > inputlth || (!hastable && head != inputlth)) | ||
187 | bb_error_msg_and_die("Input file: bad length"); | ||
188 | do_loadfont(fd, inbuf + head0, unit, fontsize); | ||
189 | if (hastable) | ||
190 | do_loadtable(fd, inbuf + head, inputlth - head, fontsize); | ||
191 | return; | ||
192 | } | ||
193 | no_psf: | ||
194 | |||
195 | /* file with three code pages? */ | ||
196 | if (inputlth == 9780) { | ||
197 | offset = 40; | ||
198 | unit = 16; | ||
199 | } else { | ||
200 | /* bare font */ | ||
201 | if (inputlth & 0377) | ||
202 | bb_error_msg_and_die("Bad input file size"); | ||
203 | offset = 0; | ||
204 | unit = inputlth / 256; | ||
205 | } | ||
206 | do_loadfont(fd, inbuf + offset, unit, 256); | ||
207 | } | ||
diff --git a/busybox/console-tools/loadkmap.c b/busybox/console-tools/loadkmap.c new file mode 100644 index 000000000..849d747a6 --- /dev/null +++ b/busybox/console-tools/loadkmap.c | |||
@@ -0,0 +1,82 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Mini loadkmap implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <errno.h> | ||
24 | #include <fcntl.h> | ||
25 | #include <stdio.h> | ||
26 | #include <string.h> | ||
27 | #include <stdlib.h> | ||
28 | #include <unistd.h> | ||
29 | #include <sys/ioctl.h> | ||
30 | #include "busybox.h" | ||
31 | |||
32 | #define BINARY_KEYMAP_MAGIC "bkeymap" | ||
33 | |||
34 | /* From <linux/kd.h> */ | ||
35 | struct kbentry { | ||
36 | unsigned char kb_table; | ||
37 | unsigned char kb_index; | ||
38 | unsigned short kb_value; | ||
39 | }; | ||
40 | /* sets one entry in translation table */ | ||
41 | #define KDSKBENT 0x4B47 | ||
42 | |||
43 | /* From <linux/keyboard.h> */ | ||
44 | #define NR_KEYS 128 | ||
45 | #define MAX_NR_KEYMAPS 256 | ||
46 | |||
47 | int loadkmap_main(int argc, char **argv) | ||
48 | { | ||
49 | struct kbentry ke; | ||
50 | int i, j, fd; | ||
51 | u_short ibuff[NR_KEYS]; | ||
52 | char flags[MAX_NR_KEYMAPS]; | ||
53 | char buff[7]; | ||
54 | |||
55 | if (argc != 1) | ||
56 | bb_show_usage(); | ||
57 | |||
58 | fd = bb_xopen(CURRENT_VC, O_RDWR); | ||
59 | |||
60 | if ((bb_full_read(0, buff, 7) != 7) || (strncmp(buff, BINARY_KEYMAP_MAGIC, 7) != 0)) | ||
61 | bb_error_msg_and_die("This is not a valid binary keymap."); | ||
62 | |||
63 | if (bb_full_read(0, flags, MAX_NR_KEYMAPS) != MAX_NR_KEYMAPS) | ||
64 | bb_perror_msg_and_die("Error reading keymap flags"); | ||
65 | |||
66 | for (i = 0; i < MAX_NR_KEYMAPS; i++) { | ||
67 | if (flags[i] == 1) { | ||
68 | bb_full_read(0, ibuff, NR_KEYS * sizeof(u_short)); | ||
69 | for (j = 0; j < NR_KEYS; j++) { | ||
70 | ke.kb_index = j; | ||
71 | ke.kb_table = i; | ||
72 | ke.kb_value = ibuff[j]; | ||
73 | ioctl(fd, KDSKBENT, &ke); | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | /* Don't bother to close files. Exit does that | ||
79 | * automagically, so we can save a few bytes */ | ||
80 | /* close(fd); */ | ||
81 | return EXIT_SUCCESS; | ||
82 | } | ||
diff --git a/busybox/console-tools/openvt.c b/busybox/console-tools/openvt.c new file mode 100644 index 000000000..5f244579c --- /dev/null +++ b/busybox/console-tools/openvt.c | |||
@@ -0,0 +1,84 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * openvt.c - open a vt to run a command. | ||
4 | * | ||
5 | * busyboxed by Quy Tonthat <quy@signal3.com> | ||
6 | * hacked by Tito <farmatito@tiscali.it> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
21 | */ | ||
22 | |||
23 | /* getopt not needed */ | ||
24 | |||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <unistd.h> | ||
28 | #include <fcntl.h> | ||
29 | #include <string.h> | ||
30 | #include <sys/types.h> | ||
31 | #include <ctype.h> | ||
32 | |||
33 | #include "busybox.h" | ||
34 | |||
35 | int openvt_main(int argc, char **argv) | ||
36 | { | ||
37 | int fd; | ||
38 | char vtname[sizeof VC_FORMAT + 2]; | ||
39 | |||
40 | |||
41 | if (argc < 3) | ||
42 | bb_show_usage(); | ||
43 | |||
44 | /* check for Illegal vt number: < 1 or > 12 */ | ||
45 | sprintf(vtname, VC_FORMAT,(int)bb_xgetlarg(argv[1], 10, 1, 12)); | ||
46 | |||
47 | argv+=2; | ||
48 | argc-=2; | ||
49 | |||
50 | if(fork() == 0) { | ||
51 | /* leave current vt */ | ||
52 | |||
53 | #ifdef ESIX_5_3_2_D | ||
54 | if (setpgrp() < 0) { | ||
55 | #else | ||
56 | if (setsid() < 0) { | ||
57 | #endif | ||
58 | |||
59 | bb_perror_msg_and_die("Unable to set new session"); | ||
60 | } | ||
61 | close(0); /* so that new vt becomes stdin */ | ||
62 | |||
63 | /* and grab new one */ | ||
64 | fd = bb_xopen(vtname, O_RDWR); | ||
65 | |||
66 | /* Reassign stdout and sterr */ | ||
67 | close(1); | ||
68 | close(2); | ||
69 | dup(fd); | ||
70 | dup(fd); | ||
71 | |||
72 | execvp(argv[0], argv); | ||
73 | _exit(1); | ||
74 | } | ||
75 | return EXIT_SUCCESS; | ||
76 | } | ||
77 | |||
78 | /* | ||
79 | Local Variables: | ||
80 | c-file-style: "linux" | ||
81 | c-basic-offset: 4 | ||
82 | tab-width: 4 | ||
83 | End: | ||
84 | */ | ||
diff --git a/busybox/console-tools/reset.c b/busybox/console-tools/reset.c new file mode 100644 index 000000000..9d38e7a28 --- /dev/null +++ b/busybox/console-tools/reset.c | |||
@@ -0,0 +1,45 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Mini reset implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> | ||
6 | * Written by Erik Andersen and Kent Robotti <robotti@metconnect.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | /* no options, no getopt */ | ||
25 | |||
26 | #include <stdio.h> | ||
27 | #include <stdlib.h> | ||
28 | #include <unistd.h> | ||
29 | #include "busybox.h" | ||
30 | |||
31 | extern int reset_main(int argc, char **argv) | ||
32 | { | ||
33 | if (isatty(0) || isatty(0) || isatty(0)) { | ||
34 | /* See 'man 4 console_codes' for details: | ||
35 | * "ESC c" -- Reset | ||
36 | * "ESC ( K" -- Select user mapping | ||
37 | * "ESC [ J" -- Erase display | ||
38 | * "ESC [ 0 m" -- Reset all Graphics Rendition display attributes | ||
39 | * "ESC [ ? 25 h" -- Make cursor visible. | ||
40 | */ | ||
41 | printf("\033c\033(K\033[J\033[0m\033[?25h"); | ||
42 | } | ||
43 | return EXIT_SUCCESS; | ||
44 | } | ||
45 | |||
diff --git a/busybox/console-tools/setkeycodes.c b/busybox/console-tools/setkeycodes.c new file mode 100644 index 000000000..169d0bb0a --- /dev/null +++ b/busybox/console-tools/setkeycodes.c | |||
@@ -0,0 +1,72 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * setkeycodes | ||
4 | * | ||
5 | * Copyright (C) 1994-1998 Andries E. Brouwer <aeb@cwi.nl> | ||
6 | * | ||
7 | * Adjusted for BusyBox by Erik Andersen <andersen@codepoet.org> | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or modify | ||
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | */ | ||
24 | |||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <fcntl.h> | ||
28 | #include <sys/ioctl.h> | ||
29 | #include "busybox.h" | ||
30 | |||
31 | |||
32 | /* From <linux/kd.h> */ | ||
33 | struct kbkeycode { | ||
34 | unsigned int scancode, keycode; | ||
35 | }; | ||
36 | static const int KDSETKEYCODE = 0x4B4D; /* write kernel keycode table entry */ | ||
37 | |||
38 | extern int | ||
39 | setkeycodes_main(int argc, char** argv) | ||
40 | { | ||
41 | char *ep; | ||
42 | int fd, sc; | ||
43 | struct kbkeycode a; | ||
44 | |||
45 | if (argc % 2 != 1 || argc < 2) { | ||
46 | bb_show_usage(); | ||
47 | } | ||
48 | |||
49 | fd = get_console_fd(); | ||
50 | |||
51 | while (argc > 2) { | ||
52 | a.keycode = atoi(argv[2]); | ||
53 | a.scancode = sc = strtol(argv[1], &ep, 16); | ||
54 | if (*ep) { | ||
55 | bb_error_msg_and_die("error reading SCANCODE: '%s'", argv[1]); | ||
56 | } | ||
57 | if (a.scancode > 127) { | ||
58 | a.scancode -= 0xe000; | ||
59 | a.scancode += 128; | ||
60 | } | ||
61 | if (a.scancode > 255 || a.keycode > 127) { | ||
62 | bb_error_msg_and_die("SCANCODE or KEYCODE outside bounds"); | ||
63 | } | ||
64 | if (ioctl(fd,KDSETKEYCODE,&a)) { | ||
65 | perror("KDSETKEYCODE"); | ||
66 | bb_error_msg_and_die("failed to set SCANCODE %x to KEYCODE %d", sc, a.keycode); | ||
67 | } | ||
68 | argc -= 2; | ||
69 | argv += 2; | ||
70 | } | ||
71 | return EXIT_SUCCESS; | ||
72 | } | ||