kbdcontrol.c (f01de75c0fd4679efb628e060f0c094131f7f014) kbdcontrol.c (e9deda23ae07ac86ee4f289ee3ac6979f2205627)
1/*-
2 * Copyright (c) 1994-1995 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 14 unchanged lines hidden (view full) ---

23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef lint
30static const char rcsid[] =
1/*-
2 * Copyright (c) 1994-1995 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 14 unchanged lines hidden (view full) ---

23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef lint
30static const char rcsid[] =
31 "$Id: kbdcontrol.c,v 1.21 1999/01/12 23:06:29 mjacob Exp $";
31 "$Id: kbdcontrol.c,v 1.22 1999/01/23 17:04:13 dfr Exp $";
32#endif /* not lint */
33
34#include <ctype.h>
35#include <err.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
39#include <unistd.h>

--- 43 unchanged lines hidden (view full) ---

83/* 73-76 */ "" , "" , "" , "" ,
84/* 77-80 */ "" , "" , "" , "" ,
85/* 81-84 */ "" , "" , "" , "" ,
86/* 85-88 */ "" , "" , "" , "" ,
87/* 89-92 */ "" , "" , "" , "" ,
88/* 93-96 */ "" , "" , "" , "" ,
89 };
90
32#endif /* not lint */
33
34#include <ctype.h>
35#include <err.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
39#include <unistd.h>

--- 43 unchanged lines hidden (view full) ---

83/* 73-76 */ "" , "" , "" , "" ,
84/* 77-80 */ "" , "" , "" , "" ,
85/* 81-84 */ "" , "" , "" , "" ,
86/* 85-88 */ "" , "" , "" , "" ,
87/* 89-92 */ "" , "" , "" , "" ,
88/* 93-96 */ "" , "" , "" , "" ,
89 };
90
91const int delays[] = {250, 500, 750, 1000};
92const int repeats[] = { 34, 38, 42, 46, 50, 55, 59, 63,
93 68, 76, 84, 92, 100, 110, 118, 126,
94 136, 152, 168, 184, 200, 220, 236, 252,
95 272, 304, 336, 368, 400, 440, 472, 504};
96const int ndelays = (sizeof(delays) / sizeof(int));
97const int nrepeats = (sizeof(repeats) / sizeof(int));
98int hex = 0;
99int number;
100char letter;
101int token;
102
103static void usage __P((void));
104
105char *

--- 306 unchanged lines hidden (view full) ---

412 fprintf(fp, " 0x%02x ", val);
413 else
414 fprintf(fp, " %3d ", val);
415 }
416 }
417}
418
419
91int hex = 0;
92int number;
93char letter;
94int token;
95
96static void usage __P((void));
97
98char *

--- 306 unchanged lines hidden (view full) ---

405 fprintf(fp, " 0x%02x ", val);
406 else
407 fprintf(fp, " %3d ", val);
408 }
409 }
410}
411
412
413#ifdef __i386__
420void
421print_key_definition_line(FILE *fp, int scancode, struct keyent_t *key)
414void
415print_key_definition_line(FILE *fp, int scancode, struct keyent_t *key)
416#else
417void
418print_key_definition_line(FILE *fp, int scancode, struct key_t *key)
419#endif
422{
423 int i;
424
425 /* print scancode number */
426 if (hex)
427 fprintf(fp, " 0x%02x ", scancode);
428 else
429 fprintf(fp, " %03d ", scancode);

--- 379 unchanged lines hidden (view full) ---

809 if ((bell & ~2) == 0)
810 fprintf(stderr, "[=%d;%dB", pitch, duration);
811}
812
813
814void
815set_keyrates(char *opt)
816{
420{
421 int i;
422
423 /* print scancode number */
424 if (hex)
425 fprintf(fp, " 0x%02x ", scancode);
426 else
427 fprintf(fp, " %03d ", scancode);

--- 379 unchanged lines hidden (view full) ---

807 if ((bell & ~2) == 0)
808 fprintf(stderr, "[=%d;%dB", pitch, duration);
809}
810
811
812void
813set_keyrates(char *opt)
814{
815 int arg[2];
817 int repeat;
818 int delay;
819
820 if (!strcmp(opt, "slow"))
816 int repeat;
817 int delay;
818
819 if (!strcmp(opt, "slow"))
821 delay = 3, repeat = 31;
820 delay = 1000, repeat = 500;
822 else if (!strcmp(opt, "normal"))
821 else if (!strcmp(opt, "normal"))
823 delay = 1, repeat = 15;
822 delay = 500, repeat = 125;
824 else if (!strcmp(opt, "fast"))
825 delay = repeat = 0;
826 else {
827 int n;
828 char *v1;
829
830 delay = strtol(opt, &v1, 0);
831 if ((delay < 0) || (*v1 != '.'))
832 goto badopt;
833 opt = ++v1;
834 repeat = strtol(opt, &v1, 0);
835 if ((repeat < 0) || (*opt == '\0') || (*v1 != '\0')) {
836badopt:
837 warnx("argument to -r must be delay.repeat");
838 return;
839 }
823 else if (!strcmp(opt, "fast"))
824 delay = repeat = 0;
825 else {
826 int n;
827 char *v1;
828
829 delay = strtol(opt, &v1, 0);
830 if ((delay < 0) || (*v1 != '.'))
831 goto badopt;
832 opt = ++v1;
833 repeat = strtol(opt, &v1, 0);
834 if ((repeat < 0) || (*opt == '\0') || (*v1 != '\0')) {
835badopt:
836 warnx("argument to -r must be delay.repeat");
837 return;
838 }
840 for (n = 0; n < ndelays - 1; n++)
841 if (delay <= delays[n])
842 break;
843 delay = n;
844 for (n = 0; n < nrepeats - 1; n++)
845 if (repeat <= repeats[n])
846 break;
847 repeat = n;
848 }
849
839 }
840
850 if (ioctl(0, KDSETRAD, (delay << 5) | repeat) < 0)
841 arg[0] = delay;
842 arg[1] = repeat;
843 if (ioctl(0, KDSETREPEAT, arg))
851 warn("setting keyboard rate");
852}
853
854
855void
856set_history(char *opt)
857{
858 int size;
859
860 size = atoi(opt);
861 if ((*opt == '\0') || size < 0) {
862 warnx("argument must be a positive number");
863 return;
864 }
865 if (ioctl(0, CONS_HISTORY, &size) == -1)
866 warn("setting history buffer size");
867}
868
844 warn("setting keyboard rate");
845}
846
847
848void
849set_history(char *opt)
850{
851 int size;
852
853 size = atoi(opt);
854 if ((*opt == '\0') || size < 0) {
855 warnx("argument must be a positive number");
856 return;
857 }
858 if (ioctl(0, CONS_HISTORY, &size) == -1)
859 warn("setting history buffer size");
860}
861
869#ifdef __i386__
870static char
871*get_kbd_type_name(int type)
872{
873 static struct {
874 int type;
875 char *name;
876 } name_table[] = {
877 { KB_84, "AT 84" },

--- 77 unchanged lines hidden (view full) ---

955 printf("kbd%d\n", info.kb_index);
956 printf(" %.*s%d, type:%s (%d)\n",
957 sizeof(info.kb_name), info.kb_name, info.kb_unit,
958 get_kbd_type_name(info.kb_type), info.kb_type);
959#endif
960 if (ioctl(0, CONS_RELKBD, 0) == -1)
961 warn("unable to release the keyboard");
962}
862static char
863*get_kbd_type_name(int type)
864{
865 static struct {
866 int type;
867 char *name;
868 } name_table[] = {
869 { KB_84, "AT 84" },

--- 77 unchanged lines hidden (view full) ---

947 printf("kbd%d\n", info.kb_index);
948 printf(" %.*s%d, type:%s (%d)\n",
949 sizeof(info.kb_name), info.kb_name, info.kb_unit,
950 get_kbd_type_name(info.kb_type), info.kb_type);
951#endif
952 if (ioctl(0, CONS_RELKBD, 0) == -1)
953 warn("unable to release the keyboard");
954}
963#endif /* __i386__ */
964
965
966static void
967usage()
968{
969 fprintf(stderr, "%s\n%s\n%s\n",
955
956
957static void
958usage()
959{
960 fprintf(stderr, "%s\n%s\n%s\n",
970#ifdef __i386__
971"usage: kbdcontrol [-dFKix] [-b duration.pitch | [quiet.]belltype]",
972" [-r delay.repeat | speed] [-l mapfile] [-f # string]",
973" [-h size] [-k device] [-L mapfile]");
961"usage: kbdcontrol [-dFKix] [-b duration.pitch | [quiet.]belltype]",
962" [-r delay.repeat | speed] [-l mapfile] [-f # string]",
963" [-h size] [-k device] [-L mapfile]");
974#else
975"usage: kbdcontrol [-dFx] [-b duration.pitch | [quiet.]belltype]",
976" [-r delay.repeat | speed] [-l mapfile] [-f # string]",
977" [-h size] [-L mapfile]");
978#endif
979 exit(1);
980}
981
982
983void
984main(int argc, char **argv)
985{
986 int opt;
987
964 exit(1);
965}
966
967
968void
969main(int argc, char **argv)
970{
971 int opt;
972
988#ifdef __i386__
989 while((opt = getopt(argc, argv, "b:df:h:iKk:Fl:L:r:x")) != -1)
973 while((opt = getopt(argc, argv, "b:df:h:iKk:Fl:L:r:x")) != -1)
990#else
991 while((opt = getopt(argc, argv, "b:df:h:Fl:L:r:x")) != -1)
992#endif
993 switch(opt) {
994 case 'b':
995 set_bell_values(optarg);
996 break;
997 case 'd':
998 print_keymap();
999 break;
1000 case 'l':

--- 7 unchanged lines hidden (view full) ---

1008 nextarg(argc, argv, &optind, 'f'));
1009 break;
1010 case 'F':
1011 load_default_functionkeys();
1012 break;
1013 case 'h':
1014 set_history(optarg);
1015 break;
974 switch(opt) {
975 case 'b':
976 set_bell_values(optarg);
977 break;
978 case 'd':
979 print_keymap();
980 break;
981 case 'l':

--- 7 unchanged lines hidden (view full) ---

989 nextarg(argc, argv, &optind, 'f'));
990 break;
991 case 'F':
992 load_default_functionkeys();
993 break;
994 case 'h':
995 set_history(optarg);
996 break;
1016#ifdef __i386__
1017 case 'i':
1018 show_kbd_info();
1019 break;
1020 case 'K':
1021 release_keyboard();
1022 break;
1023 case 'k':
1024 set_keyboard(optarg);
1025 break;
997 case 'i':
998 show_kbd_info();
999 break;
1000 case 'K':
1001 release_keyboard();
1002 break;
1003 case 'k':
1004 set_keyboard(optarg);
1005 break;
1026#endif /* __i386__ */
1027 case 'r':
1028 set_keyrates(optarg);
1029 break;
1030 case 'x':
1031 hex = 1;
1032 break;
1033 default:
1034 usage();
1035 }
1036 if ((optind != argc) || (argc == 1))
1037 usage();
1038 exit(0);
1039}
1040
1041
1006 case 'r':
1007 set_keyrates(optarg);
1008 break;
1009 case 'x':
1010 hex = 1;
1011 break;
1012 default:
1013 usage();
1014 }
1015 if ((optind != argc) || (argc == 1))
1016 usage();
1017 exit(0);
1018}
1019
1020