if (ioctl(fd, KDSKBMODE, K_UNICODE)) {
lkerror(_("KDSKBMODE: %s: could not switch to Unicode mode"),
strerror(errno));
- exit(EXIT_FAILURE);
+ goto fail;
}
}
if (errno != EINVAL) {
lkerror(_("KDSKBENT: %s: could not deallocate keymap %d"),
strerror(errno), i);
- exit(EXIT_FAILURE);
+ goto fail;
}
/* probably an old kernel */
/* clear keymap by hand */
lkerror(_("KDSKBENT: %s: cannot deallocate or clear keymap"),
strerror(errno));
- exit(EXIT_FAILURE);
+ goto fail;
}
}
}
if (optu && ioctl(fd, KDSKBMODE, kbd_mode)) {
lkerror(_("KDSKBMODE: %s: could not return to original keyboard mode"),
strerror(errno));
- exit(EXIT_FAILURE);
+ goto fail;
}
return ct;
+
+ fail: return -1;
}
static void freekeys(void)
}
}
-static char *ostr(char *s)
+static char *
+ostr(char *s)
{
int lth = strlen(s);
char *ns0 = malloc(4 * lth + 1);
if (ns == NULL) {
lkerror(_("out of memory"));
- exit(EXIT_FAILURE);
+ return NULL;
}
while (*s) {
return ns0;
}
-static int deffuncs(int fd)
+static int
+deffuncs(int fd)
{
int i, ct = 0;
char *ptr, *s;
strcpy((char *)kbs_buf.kb_string, ptr);
if (ioctl(fd, KDSKBSENT, (unsigned long)&kbs_buf)) {
s = ostr((char *)kbs_buf.kb_string);
+ if (s == NULL)
+ return -1;
lkerror(_("failed to bind string '%s' to function %s"),
s, syms[KT_FN].table[kbs_buf.kb_func]);
free(s);
return ct;
}
-static int defdiacs(int fd)
+static int
+defdiacs(int fd)
{
unsigned int i, count;
struct kbdiacrs kd;
kdu.kbdiacruc[i].result = accent_table[i].result;
}
- if (ioctl(fd, KDSKBDIACRUC, (unsigned long)&kdu)) {
- lkerror("KDSKBDIACRUC: %s", strerror(errno));
- exit(EXIT_FAILURE);
- }
+ if (ioctl(fd, KDSKBDIACRUC, (unsigned long)&kdu))
+ goto fail2;
} else
#endif
{
kd.kbdiacr[i].result = accent_table[i].result;
}
- if (ioctl(fd, KDSKBDIACR, (unsigned long)&kd)) {
- perror("KDSKBDIACR");
- lkerror("KDSKBDIACR: %s", strerror(errno));
- exit(EXIT_FAILURE);
- }
+ if (ioctl(fd, KDSKBDIACR, (unsigned long)&kd))
+ goto fail1;
}
return kd.kb_cnt;
+
+ fail1: lkerror("KDSKBDIACR: %s", strerror(errno));
+ return -1;
+
+#ifdef KDSKBDIACRUC
+ fail2: lkerror("KDSKBDIACRUC: %s", strerror(errno));
+ return -1;
+#endif
}
static int
return -1;
}
-static void loadkeys(int fd, int kbd_mode)
+static int
+loadkeys(int fd, int kbd_mode)
{
- int keyct, funcct, diacct = 0;
+ int keyct, funcct, diacct;
- keyct = defkeys(fd, kbd_mode);
- funcct = deffuncs(fd);
+ if ((keyct = defkeys(fd, kbd_mode)) < 0 || (funcct = deffuncs(fd)) < 0)
+ return -1;
lkverbose(1, _("\nChanged %d %s and %d %s"),
keyct, (keyct == 1) ? _("key") : _("keys"),
if (accent_table_size > 0 || nocompose) {
diacct = defdiacs(fd);
+ if (diacct < 0)
+ return -1;
+
lkverbose(1, _("Loaded %d compose %s"),
diacct, (diacct == 1) ? _("definition") : _("definitions"));
lkverbose(1, _("(No change in compose definitions)"));
}
- freekeys();
+ return 0;
}
static int
fprintf(fd, comma ? "', " : "'");
}
-static void
+static int
mktable(FILE *fd)
{
int j;
fprintf(fd, "};\n\n");
}
fprintf(fd, "unsigned int accent_table_size = %d;\n", accent_table_size);
+ return 0;
}
-static void attr_noreturn bkeymap(void)
+static int
+bkeymap(void)
{
int i, j;
}
}
}
- freekeys();
- exit(0);
+ return 0;
fail: lkerror(_("Error writing map to file"));
- freekeys();
- exit(1);
+ return -1;
}
/* Line 189 of yacc.c */
-#line 1037 "loadkeys.c"
+#line 1051 "loadkeys.c"
/* Enabling traces. */
#ifndef YYDEBUG
/* Line 264 of yacc.c */
-#line 1149 "loadkeys.c"
+#line 1163 "loadkeys.c"
#ifdef short
# undef short
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint16 yyrline[] =
{
- 0, 977, 977, 978, 980, 981, 982, 983, 984, 985,
- 986, 987, 988, 989, 991, 997, 1002, 1008, 1013, 1019,
- 1024, 1025, 1027, 1035, 1041, 1055, 1060, 1066, 1067, 1069,
- 1069, 1077, 1083, 1084, 1086, 1087, 1088, 1089, 1090, 1091,
- 1092, 1093, 1094, 1096, 1151, 1152, 1154, 1164, 1165, 1166,
- 1167, 1168, 1169
+ 0, 991, 991, 992, 994, 995, 996, 997, 998, 999,
+ 1000, 1001, 1002, 1003, 1005, 1011, 1016, 1022, 1027, 1033,
+ 1038, 1039, 1041, 1049, 1055, 1069, 1074, 1080, 1081, 1083,
+ 1083, 1091, 1097, 1098, 1100, 1101, 1102, 1103, 1104, 1105,
+ 1106, 1107, 1108, 1110, 1165, 1166, 1168, 1178, 1179, 1180,
+ 1181, 1182, 1183
};
#endif
case 14:
/* Line 1464 of yacc.c */
-#line 992 "loadkeys.y"
+#line 1006 "loadkeys.y"
{
if (set_charset((char *) kbs_buf.kb_string))
YYERROR;
case 15:
/* Line 1464 of yacc.c */
-#line 998 "loadkeys.y"
+#line 1012 "loadkeys.y"
{
alt_is_meta = 1;
}
case 16:
/* Line 1464 of yacc.c */
-#line 1003 "loadkeys.y"
+#line 1017 "loadkeys.y"
{
if (strings_as_usual() == -1)
YYERROR;
case 17:
/* Line 1464 of yacc.c */
-#line 1009 "loadkeys.y"
+#line 1023 "loadkeys.y"
{
if (compose_as_usual((char *) kbs_buf.kb_string) == -1)
YYERROR;
case 18:
/* Line 1464 of yacc.c */
-#line 1014 "loadkeys.y"
+#line 1028 "loadkeys.y"
{
if (compose_as_usual(0) == -1)
YYERROR;
case 19:
/* Line 1464 of yacc.c */
-#line 1020 "loadkeys.y"
+#line 1034 "loadkeys.y"
{
keymaps_line_seen = 1;
}
case 22:
/* Line 1464 of yacc.c */
-#line 1028 "loadkeys.y"
+#line 1042 "loadkeys.y"
{
int i;
for (i = (yyvsp[(1) - (3)]); i <= (yyvsp[(3) - (3)]); i++) {
case 23:
/* Line 1464 of yacc.c */
-#line 1036 "loadkeys.y"
+#line 1050 "loadkeys.y"
{
if (addmap((yyvsp[(1) - (1)]),1) == -1)
YYERROR;
case 24:
/* Line 1464 of yacc.c */
-#line 1042 "loadkeys.y"
+#line 1056 "loadkeys.y"
{
if (KTYP((yyvsp[(2) - (5)])) != KT_FN) {
snprintf(errmsg, sizeof(errmsg),
case 25:
/* Line 1464 of yacc.c */
-#line 1056 "loadkeys.y"
+#line 1070 "loadkeys.y"
{
if (compose((yyvsp[(2) - (6)]), (yyvsp[(3) - (6)]), (yyvsp[(5) - (6)])) == -1)
YYERROR;
case 26:
/* Line 1464 of yacc.c */
-#line 1061 "loadkeys.y"
+#line 1075 "loadkeys.y"
{
if (compose((yyvsp[(2) - (6)]), (yyvsp[(3) - (6)]), (yyvsp[(5) - (6)])) == -1)
YYERROR;
case 27:
/* Line 1464 of yacc.c */
-#line 1066 "loadkeys.y"
+#line 1080 "loadkeys.y"
{ (yyval) = (yyvsp[(1) - (1)]); }
break;
case 28:
/* Line 1464 of yacc.c */
-#line 1067 "loadkeys.y"
+#line 1081 "loadkeys.y"
{ (yyval) = (yyvsp[(1) - (1)]) ^ 0xf000; }
break;
case 29:
/* Line 1464 of yacc.c */
-#line 1069 "loadkeys.y"
+#line 1083 "loadkeys.y"
{
mod = 0;
}
case 30:
/* Line 1464 of yacc.c */
-#line 1073 "loadkeys.y"
+#line 1087 "loadkeys.y"
{
if (addkey((yyvsp[(4) - (7)]), mod, (yyvsp[(6) - (7)])) == -1)
YYERROR;
case 31:
/* Line 1464 of yacc.c */
-#line 1078 "loadkeys.y"
+#line 1092 "loadkeys.y"
{
if (addkey((yyvsp[(3) - (6)]), 0, (yyvsp[(5) - (6)])) == -1)
YYERROR;
case 34:
/* Line 1464 of yacc.c */
-#line 1086 "loadkeys.y"
+#line 1100 "loadkeys.y"
{ mod |= M_SHIFT; }
break;
case 35:
/* Line 1464 of yacc.c */
-#line 1087 "loadkeys.y"
+#line 1101 "loadkeys.y"
{ mod |= M_CTRL; }
break;
case 36:
/* Line 1464 of yacc.c */
-#line 1088 "loadkeys.y"
+#line 1102 "loadkeys.y"
{ mod |= M_ALT; }
break;
case 37:
/* Line 1464 of yacc.c */
-#line 1089 "loadkeys.y"
+#line 1103 "loadkeys.y"
{ mod |= M_ALTGR; }
break;
case 38:
/* Line 1464 of yacc.c */
-#line 1090 "loadkeys.y"
+#line 1104 "loadkeys.y"
{ mod |= M_SHIFTL; }
break;
case 39:
/* Line 1464 of yacc.c */
-#line 1091 "loadkeys.y"
+#line 1105 "loadkeys.y"
{ mod |= M_SHIFTR; }
break;
case 40:
/* Line 1464 of yacc.c */
-#line 1092 "loadkeys.y"
+#line 1106 "loadkeys.y"
{ mod |= M_CTRLL; }
break;
case 41:
/* Line 1464 of yacc.c */
-#line 1093 "loadkeys.y"
+#line 1107 "loadkeys.y"
{ mod |= M_CTRLR; }
break;
case 42:
/* Line 1464 of yacc.c */
-#line 1094 "loadkeys.y"
+#line 1108 "loadkeys.y"
{ mod |= M_CAPSSHIFT; }
break;
case 43:
/* Line 1464 of yacc.c */
-#line 1097 "loadkeys.y"
+#line 1111 "loadkeys.y"
{
int i, j, keycode;
case 46:
/* Line 1464 of yacc.c */
-#line 1155 "loadkeys.y"
+#line 1169 "loadkeys.y"
{
if (rvalct >= MAX_NR_KEYMAPS) {
snprintf(errmsg, sizeof(errmsg),
case 47:
/* Line 1464 of yacc.c */
-#line 1164 "loadkeys.y"
+#line 1178 "loadkeys.y"
{ (yyval) = convert_code((yyvsp[(1) - (1)]), TO_AUTO); }
break;
case 48:
/* Line 1464 of yacc.c */
-#line 1165 "loadkeys.y"
+#line 1179 "loadkeys.y"
{ (yyval) = add_capslock((yyvsp[(2) - (2)])); }
break;
case 49:
/* Line 1464 of yacc.c */
-#line 1166 "loadkeys.y"
+#line 1180 "loadkeys.y"
{ (yyval) = convert_code((yyvsp[(1) - (1)])^0xf000, TO_AUTO); }
break;
case 50:
/* Line 1464 of yacc.c */
-#line 1167 "loadkeys.y"
+#line 1181 "loadkeys.y"
{ (yyval) = add_capslock((yyvsp[(2) - (2)])^0xf000); }
break;
case 51:
/* Line 1464 of yacc.c */
-#line 1168 "loadkeys.y"
+#line 1182 "loadkeys.y"
{ (yyval) = (yyvsp[(1) - (1)]); }
break;
case 52:
/* Line 1464 of yacc.c */
-#line 1169 "loadkeys.y"
+#line 1183 "loadkeys.y"
{ (yyval) = add_capslock((yyvsp[(2) - (2)])); }
break;
/* Line 1464 of yacc.c */
-#line 2770 "loadkeys.c"
+#line 2784 "loadkeys.c"
default: break;
}
YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
/* Line 1684 of yacc.c */
-#line 1171 "loadkeys.y"
+#line 1185 "loadkeys.y"
-static void parse_keymap(lkfile_t *f) {
+static int
+parse_keymap(lkfile_t *f)
+{
if (!quiet && !optm)
lkverbose(1, _("Loading %s"), f->pathname);
if (stack_push(f) == -1) {
lkerror("%s", errmsg);
- exit(EXIT_FAILURE);
+ return -1;
}
if (yyparse()) {
if (!optm)
lkerror(_("key bindings not changed"));
- exit(EXIT_FAILURE);
+
+ return -1;
}
+ return 0;
}
int main(int argc, char *argv[])
{ "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 }
};
- int c, i;
+ int c, i, rc = -1;
int fd;
int kbd_mode;
int kd_mode;
fprintf(stderr, _("Cannot find %s\n"), DEFMAP);
exit(EXIT_FAILURE);
}
- parse_keymap(&f);
+
+ if ((rc = parse_keymap(&f)) == -1)
+ goto fail;
+
} else if (optind == argc) {
f.fd = stdin;
strcpy(f.pathname, "<stdin>");
- parse_keymap(&f);
+
+ if ((rc = parse_keymap(&f)) == -1)
+ goto fail;
}
for (i = optind; argv[i]; i++) {
} else if (findfile(argv[i], dirpath, suffixes, &f)) {
fprintf(stderr, _("cannot open file %s\n"), argv[i]);
- exit(EXIT_FAILURE);
+ goto fail;
}
- parse_keymap(&f);
+ if ((rc = parse_keymap(&f)) == -1)
+ goto fail;
}
- if (do_constant() == -1)
- exit(EXIT_FAILURE);
-
- if (optb)
- bkeymap();
+ if ((rc = do_constant()) == -1)
+ goto fail;
- if (optm) {
- mktable(stdout);
- freekeys();
- exit(EXIT_SUCCESS);
+ if (optb) {
+ rc = bkeymap();
+ } else if (optm) {
+ rc = mktable(stdout);
+ } else {
+ rc = loadkeys(fd, kbd_mode);
}
- loadkeys(fd, kbd_mode);
-
+ fail: freekeys();
close(fd);
+ if (rc < 0)
+ exit(EXIT_FAILURE);
+
exit(EXIT_SUCCESS);
}
if (ioctl(fd, KDSKBMODE, K_UNICODE)) {
lkerror(_("KDSKBMODE: %s: could not switch to Unicode mode"),
strerror(errno));
- exit(EXIT_FAILURE);
+ goto fail;
}
}
if (errno != EINVAL) {
lkerror(_("KDSKBENT: %s: could not deallocate keymap %d"),
strerror(errno), i);
- exit(EXIT_FAILURE);
+ goto fail;
}
/* probably an old kernel */
/* clear keymap by hand */
lkerror(_("KDSKBENT: %s: cannot deallocate or clear keymap"),
strerror(errno));
- exit(EXIT_FAILURE);
+ goto fail;
}
}
}
if (optu && ioctl(fd, KDSKBMODE, kbd_mode)) {
lkerror(_("KDSKBMODE: %s: could not return to original keyboard mode"),
strerror(errno));
- exit(EXIT_FAILURE);
+ goto fail;
}
return ct;
+
+ fail: return -1;
}
static void freekeys(void)
}
}
-static char *ostr(char *s)
+static char *
+ostr(char *s)
{
int lth = strlen(s);
char *ns0 = malloc(4 * lth + 1);
if (ns == NULL) {
lkerror(_("out of memory"));
- exit(EXIT_FAILURE);
+ return NULL;
}
while (*s) {
return ns0;
}
-static int deffuncs(int fd)
+static int
+deffuncs(int fd)
{
int i, ct = 0;
char *ptr, *s;
strcpy((char *)kbs_buf.kb_string, ptr);
if (ioctl(fd, KDSKBSENT, (unsigned long)&kbs_buf)) {
s = ostr((char *)kbs_buf.kb_string);
+ if (s == NULL)
+ return -1;
lkerror(_("failed to bind string '%s' to function %s"),
s, syms[KT_FN].table[kbs_buf.kb_func]);
free(s);
return ct;
}
-static int defdiacs(int fd)
+static int
+defdiacs(int fd)
{
unsigned int i, count;
struct kbdiacrs kd;
kdu.kbdiacruc[i].result = accent_table[i].result;
}
- if (ioctl(fd, KDSKBDIACRUC, (unsigned long)&kdu)) {
- lkerror("KDSKBDIACRUC: %s", strerror(errno));
- exit(EXIT_FAILURE);
- }
+ if (ioctl(fd, KDSKBDIACRUC, (unsigned long)&kdu))
+ goto fail2;
} else
#endif
{
kd.kbdiacr[i].result = accent_table[i].result;
}
- if (ioctl(fd, KDSKBDIACR, (unsigned long)&kd)) {
- perror("KDSKBDIACR");
- lkerror("KDSKBDIACR: %s", strerror(errno));
- exit(EXIT_FAILURE);
- }
+ if (ioctl(fd, KDSKBDIACR, (unsigned long)&kd))
+ goto fail1;
}
return kd.kb_cnt;
+
+ fail1: lkerror("KDSKBDIACR: %s", strerror(errno));
+ return -1;
+
+#ifdef KDSKBDIACRUC
+ fail2: lkerror("KDSKBDIACRUC: %s", strerror(errno));
+ return -1;
+#endif
}
static int
return -1;
}
-static void loadkeys(int fd, int kbd_mode)
+static int
+loadkeys(int fd, int kbd_mode)
{
- int keyct, funcct, diacct = 0;
+ int keyct, funcct, diacct;
- keyct = defkeys(fd, kbd_mode);
- funcct = deffuncs(fd);
+ if ((keyct = defkeys(fd, kbd_mode)) < 0 || (funcct = deffuncs(fd)) < 0)
+ return -1;
lkverbose(1, _("\nChanged %d %s and %d %s"),
keyct, (keyct == 1) ? _("key") : _("keys"),
if (accent_table_size > 0 || nocompose) {
diacct = defdiacs(fd);
+ if (diacct < 0)
+ return -1;
+
lkverbose(1, _("Loaded %d compose %s"),
diacct, (diacct == 1) ? _("definition") : _("definitions"));
lkverbose(1, _("(No change in compose definitions)"));
}
- freekeys();
+ return 0;
}
static int
fprintf(fd, comma ? "', " : "'");
}
-static void
+static int
mktable(FILE *fd)
{
int j;
fprintf(fd, "};\n\n");
}
fprintf(fd, "unsigned int accent_table_size = %d;\n", accent_table_size);
+ return 0;
}
-static void attr_noreturn bkeymap(void)
+static int
+bkeymap(void)
{
int i, j;
}
}
}
- freekeys();
- exit(0);
+ return 0;
fail: lkerror(_("Error writing map to file"));
- freekeys();
- exit(1);
+ return -1;
}
%}
;
%%
-static void parse_keymap(lkfile_t *f) {
+static int
+parse_keymap(lkfile_t *f)
+{
if (!quiet && !optm)
lkverbose(1, _("Loading %s"), f->pathname);
if (stack_push(f) == -1) {
lkerror("%s", errmsg);
- exit(EXIT_FAILURE);
+ return -1;
}
if (yyparse()) {
if (!optm)
lkerror(_("key bindings not changed"));
- exit(EXIT_FAILURE);
+
+ return -1;
}
+ return 0;
}
int main(int argc, char *argv[])
{ "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 }
};
- int c, i;
+ int c, i, rc = -1;
int fd;
int kbd_mode;
int kd_mode;
fprintf(stderr, _("Cannot find %s\n"), DEFMAP);
exit(EXIT_FAILURE);
}
- parse_keymap(&f);
+
+ if ((rc = parse_keymap(&f)) == -1)
+ goto fail;
+
} else if (optind == argc) {
f.fd = stdin;
strcpy(f.pathname, "<stdin>");
- parse_keymap(&f);
+
+ if ((rc = parse_keymap(&f)) == -1)
+ goto fail;
}
for (i = optind; argv[i]; i++) {
} else if (findfile(argv[i], dirpath, suffixes, &f)) {
fprintf(stderr, _("cannot open file %s\n"), argv[i]);
- exit(EXIT_FAILURE);
+ goto fail;
}
- parse_keymap(&f);
+ if ((rc = parse_keymap(&f)) == -1)
+ goto fail;
}
- if (do_constant() == -1)
- exit(EXIT_FAILURE);
-
- if (optb)
- bkeymap();
+ if ((rc = do_constant()) == -1)
+ goto fail;
- if (optm) {
- mktable(stdout);
- freekeys();
- exit(EXIT_SUCCESS);
+ if (optb) {
+ rc = bkeymap();
+ } else if (optm) {
+ rc = mktable(stdout);
+ } else {
+ rc = loadkeys(fd, kbd_mode);
}
- loadkeys(fd, kbd_mode);
-
+ fail: freekeys();
close(fd);
+ if (rc < 0)
+ exit(EXIT_FAILURE);
+
exit(EXIT_SUCCESS);
}