From 71eea69789f404319515ea8c09169419bb7e4375 Mon Sep 17 00:00:00 2001 From: Alexey Gladkov Date: Tue, 22 Feb 2011 20:43:28 +0300 Subject: [PATCH] loadkeys: fatal errors - change to varargs Signed-off-by: Alexey Gladkov --- src/kbd.h | 1 + src/loadkeys.analyze.c | 113 ++++++++++++++++++++------------------- src/loadkeys.analyze.l | 5 +- src/loadkeys.c | 140 ++++++++++++++++++++++--------------------------- src/loadkeys.y | 54 +++++++------------ 5 files changed, 140 insertions(+), 173 deletions(-) diff --git a/src/kbd.h b/src/kbd.h index 7b12a7f..08c6945 100644 --- a/src/kbd.h +++ b/src/kbd.h @@ -3,5 +3,6 @@ #define attr_noreturn __attribute__ ((noreturn)) #define attr_unused __attribute__ ((unused)) +#define attr_format_1_2 __attribute__ ((format (printf, 1, 2))) #endif /* _KBD_H */ diff --git a/src/loadkeys.analyze.c b/src/loadkeys.analyze.c index 9244304..43e2937 100644 --- a/src/loadkeys.analyze.c +++ b/src/loadkeys.analyze.c @@ -813,8 +813,7 @@ char *p, *pmax; extern int yyerror(const char *s); extern void stringovfl(void); -extern void lkfatal(const char *s); -extern void lkfatal1(const char *s, const char *s2); +extern void lkfatal(const char *fmt, ...); extern void open_include(char *s); /* Include file handling - unfortunately flex-specific. */ @@ -838,7 +837,7 @@ int stack_pop(void); -#line 842 "loadkeys.analyze.c" +#line 841 "loadkeys.analyze.c" #define INITIAL 0 #define RVALUE 1 @@ -1021,7 +1020,7 @@ YY_DECL register char *yy_cp, *yy_bp; register int yy_act; -#line 82 "loadkeys.analyze.l" +#line 81 "loadkeys.analyze.l" /* To protect from wrong code in the higher level parser (loadkeys.y), @@ -1037,7 +1036,7 @@ YY_DECL yylval = YYLVAL_UNDEF; -#line 1041 "loadkeys.analyze.c" +#line 1040 "loadkeys.analyze.c" if ( !(yy_init) ) { @@ -1122,12 +1121,12 @@ do_action: /* This label is used only to access EOF actions. */ case 1: YY_RULE_SETUP -#line 97 "loadkeys.analyze.l" +#line 96 "loadkeys.analyze.l" {BEGIN(INCLSTR);} YY_BREAK case 2: YY_RULE_SETUP -#line 98 "loadkeys.analyze.l" +#line 97 "loadkeys.analyze.l" {char *s = xstrndup(yytext+1, strlen(yytext)-2); /* use static pathname to store *s ? */ open_include(s); @@ -1137,7 +1136,7 @@ YY_RULE_SETUP case 3: /* rule 3 can match eol */ YY_RULE_SETUP -#line 103 "loadkeys.analyze.l" +#line 102 "loadkeys.analyze.l" { yyerror("expected filename between quotes"); BEGIN(0); } @@ -1146,7 +1145,7 @@ case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(RVALUE): case YY_STATE_EOF(STR): case YY_STATE_EOF(INCLSTR): -#line 106 "loadkeys.analyze.l" +#line 105 "loadkeys.analyze.l" {stack_pop(); if (!YY_CURRENT_BUFFER) yyterminate(); } @@ -1154,18 +1153,18 @@ case YY_STATE_EOF(INCLSTR): case 4: /* rule 4 can match eol */ YY_RULE_SETUP -#line 109 "loadkeys.analyze.l" +#line 108 "loadkeys.analyze.l" {line_nr++;} YY_BREAK case 5: /* rule 5 can match eol */ YY_RULE_SETUP -#line 110 "loadkeys.analyze.l" +#line 109 "loadkeys.analyze.l" {line_nr++;BEGIN(0);return(EOL);} YY_BREAK case 6: YY_RULE_SETUP -#line 111 "loadkeys.analyze.l" +#line 110 "loadkeys.analyze.l" ; /* do nothing */ YY_BREAK case 7: @@ -1174,219 +1173,219 @@ case 7: (yy_c_buf_p) = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 112 "loadkeys.analyze.l" +#line 111 "loadkeys.analyze.l" ; /* do nothing */ YY_BREAK case 8: YY_RULE_SETUP -#line 113 "loadkeys.analyze.l" +#line 112 "loadkeys.analyze.l" {BEGIN(RVALUE);rvalct=0;return(EQUALS);} YY_BREAK case 9: YY_RULE_SETUP -#line 114 "loadkeys.analyze.l" +#line 113 "loadkeys.analyze.l" {return(DASH);} YY_BREAK case 10: YY_RULE_SETUP -#line 115 "loadkeys.analyze.l" +#line 114 "loadkeys.analyze.l" {return(COMMA);} YY_BREAK case 11: YY_RULE_SETUP -#line 116 "loadkeys.analyze.l" +#line 115 "loadkeys.analyze.l" {return(PLUS);} YY_BREAK case 12: YY_RULE_SETUP -#line 117 "loadkeys.analyze.l" -{yylval=strtol(yytext+1,NULL,16);if(yylval>=0xf000)lkfatal1("unicode keysym out of range: %s",yytext);return(UNUMBER);} +#line 116 "loadkeys.analyze.l" +{yylval=strtol(yytext+1,NULL,16);if(yylval>=0xf000)lkfatal("unicode keysym out of range: %s",yytext);return(UNUMBER);} YY_BREAK case 13: YY_RULE_SETUP -#line 118 "loadkeys.analyze.l" +#line 117 "loadkeys.analyze.l" {yylval=strtol(yytext,NULL,0);return(NUMBER);} YY_BREAK case 14: YY_RULE_SETUP -#line 119 "loadkeys.analyze.l" +#line 118 "loadkeys.analyze.l" {return((yylval=ksymtocode(yytext, TO_AUTO))==-1?ERROR:LITERAL);} YY_BREAK case 15: YY_RULE_SETUP -#line 120 "loadkeys.analyze.l" +#line 119 "loadkeys.analyze.l" {return(CHARSET);} YY_BREAK case 16: YY_RULE_SETUP -#line 121 "loadkeys.analyze.l" +#line 120 "loadkeys.analyze.l" {return(KEYMAPS);} YY_BREAK case 17: YY_RULE_SETUP -#line 122 "loadkeys.analyze.l" +#line 121 "loadkeys.analyze.l" {return(KEYCODE);} YY_BREAK case 18: YY_RULE_SETUP -#line 123 "loadkeys.analyze.l" +#line 122 "loadkeys.analyze.l" {BEGIN(RVALUE);return(STRING);} YY_BREAK case 19: YY_RULE_SETUP -#line 124 "loadkeys.analyze.l" +#line 123 "loadkeys.analyze.l" {return(PLAIN);} YY_BREAK case 20: YY_RULE_SETUP -#line 125 "loadkeys.analyze.l" +#line 124 "loadkeys.analyze.l" {return(SHIFT);} YY_BREAK case 21: YY_RULE_SETUP -#line 126 "loadkeys.analyze.l" +#line 125 "loadkeys.analyze.l" {return(CONTROL);} YY_BREAK case 22: YY_RULE_SETUP -#line 127 "loadkeys.analyze.l" +#line 126 "loadkeys.analyze.l" {return(ALT);} YY_BREAK case 23: YY_RULE_SETUP -#line 128 "loadkeys.analyze.l" +#line 127 "loadkeys.analyze.l" {return(ALTGR);} YY_BREAK case 24: YY_RULE_SETUP -#line 129 "loadkeys.analyze.l" +#line 128 "loadkeys.analyze.l" {return(SHIFTL);} YY_BREAK case 25: YY_RULE_SETUP -#line 130 "loadkeys.analyze.l" +#line 129 "loadkeys.analyze.l" {return(SHIFTR);} YY_BREAK case 26: YY_RULE_SETUP -#line 131 "loadkeys.analyze.l" +#line 130 "loadkeys.analyze.l" {return(CTRLL);} YY_BREAK case 27: YY_RULE_SETUP -#line 132 "loadkeys.analyze.l" +#line 131 "loadkeys.analyze.l" {return(CTRLR);} YY_BREAK case 28: YY_RULE_SETUP -#line 133 "loadkeys.analyze.l" +#line 132 "loadkeys.analyze.l" {return(CAPSSHIFT);} YY_BREAK case 29: YY_RULE_SETUP -#line 134 "loadkeys.analyze.l" +#line 133 "loadkeys.analyze.l" {return(ALT_IS_META);} YY_BREAK case 30: YY_RULE_SETUP -#line 135 "loadkeys.analyze.l" +#line 134 "loadkeys.analyze.l" {return(STRINGS);} YY_BREAK case 31: YY_RULE_SETUP -#line 136 "loadkeys.analyze.l" +#line 135 "loadkeys.analyze.l" {return(COMPOSE);} YY_BREAK case 32: YY_RULE_SETUP -#line 137 "loadkeys.analyze.l" +#line 136 "loadkeys.analyze.l" {return(AS);} YY_BREAK case 33: YY_RULE_SETUP -#line 138 "loadkeys.analyze.l" +#line 137 "loadkeys.analyze.l" {return(USUAL);} YY_BREAK case 34: YY_RULE_SETUP -#line 139 "loadkeys.analyze.l" +#line 138 "loadkeys.analyze.l" {BEGIN(RVALUE); return(TO);} YY_BREAK case 35: YY_RULE_SETUP -#line 140 "loadkeys.analyze.l" +#line 139 "loadkeys.analyze.l" {return(ON);} YY_BREAK case 36: YY_RULE_SETUP -#line 141 "loadkeys.analyze.l" +#line 140 "loadkeys.analyze.l" {return(FOR);} YY_BREAK case 37: YY_RULE_SETUP -#line 142 "loadkeys.analyze.l" +#line 141 "loadkeys.analyze.l" {yylval = strtol(yytext+2,NULL,8); return(CCHAR);} YY_BREAK case 38: YY_RULE_SETUP -#line 143 "loadkeys.analyze.l" +#line 142 "loadkeys.analyze.l" {yylval = (unsigned char) yytext[2]; return(CCHAR);} YY_BREAK case 39: YY_RULE_SETUP -#line 144 "loadkeys.analyze.l" +#line 143 "loadkeys.analyze.l" {yylval = (unsigned char) yytext[1]; return(CCHAR);} YY_BREAK case 40: YY_RULE_SETUP -#line 145 "loadkeys.analyze.l" +#line 144 "loadkeys.analyze.l" {p=(char *) kbs_buf.kb_string; pmax=p+sizeof(kbs_buf.kb_string)-1; BEGIN(STR);} YY_BREAK case 41: YY_RULE_SETUP -#line 148 "loadkeys.analyze.l" +#line 147 "loadkeys.analyze.l" {if(p>=pmax)stringovfl();*p++=strtol(yytext+1,NULL,8);} YY_BREAK case 42: YY_RULE_SETUP -#line 149 "loadkeys.analyze.l" +#line 148 "loadkeys.analyze.l" {if(p>=pmax)stringovfl();*p++='"';} YY_BREAK case 43: YY_RULE_SETUP -#line 150 "loadkeys.analyze.l" +#line 149 "loadkeys.analyze.l" {if(p>=pmax)stringovfl();*p++='\\';} YY_BREAK case 44: YY_RULE_SETUP -#line 151 "loadkeys.analyze.l" +#line 150 "loadkeys.analyze.l" {if(p>=pmax)stringovfl();*p++='\n';} YY_BREAK case 45: /* rule 45 can match eol */ YY_RULE_SETUP -#line 152 "loadkeys.analyze.l" +#line 151 "loadkeys.analyze.l" {char *ptmp=p;p+=strlen(yytext); if(p>pmax)stringovfl();strcpy(ptmp,yytext);} YY_BREAK case 46: YY_RULE_SETUP -#line 154 "loadkeys.analyze.l" +#line 153 "loadkeys.analyze.l" {*p='\0';BEGIN(0);return(STRLITERAL);} YY_BREAK case 47: YY_RULE_SETUP -#line 155 "loadkeys.analyze.l" +#line 154 "loadkeys.analyze.l" {return(ERROR); /* report any unknown characters */} YY_BREAK case 48: YY_RULE_SETUP -#line 157 "loadkeys.analyze.l" +#line 156 "loadkeys.analyze.l" ECHO; YY_BREAK -#line 1390 "loadkeys.analyze.c" +#line 1389 "loadkeys.analyze.c" case YY_END_OF_BUFFER: { @@ -2345,7 +2344,7 @@ void yyfree (void * ptr ) #define YYTABLES_NAME "yytables" -#line 157 "loadkeys.analyze.l" +#line 156 "loadkeys.analyze.l" diff --git a/src/loadkeys.analyze.l b/src/loadkeys.analyze.l index e409f94..46722e5 100644 --- a/src/loadkeys.analyze.l +++ b/src/loadkeys.analyze.l @@ -18,8 +18,7 @@ char *p, *pmax; extern int yyerror(const char *s); extern void stringovfl(void); -extern void lkfatal(const char *s); -extern void lkfatal1(const char *s, const char *s2); +extern void lkfatal(const char *fmt, ...); extern void open_include(char *s); /* Include file handling - unfortunately flex-specific. */ @@ -114,7 +113,7 @@ To to|To|TO \- {return(DASH);} \, {return(COMMA);} \+ {return(PLUS);} -{Unicode} {yylval=strtol(yytext+1,NULL,16);if(yylval>=0xf000)lkfatal1("unicode keysym out of range: %s",yytext);return(UNUMBER);} +{Unicode} {yylval=strtol(yytext+1,NULL,16);if(yylval>=0xf000)lkfatal("unicode keysym out of range: %s",yytext);return(UNUMBER);} {Decimal}|{Octal}|{Hex} {yylval=strtol(yytext,NULL,0);return(NUMBER);} {Literal} {return((yylval=ksymtocode(yytext, TO_AUTO))==-1?ERROR:LITERAL);} {Charset} {return(CHARSET);} diff --git a/src/loadkeys.c b/src/loadkeys.c index 5d06e1b..e421bd6 100644 --- a/src/loadkeys.c +++ b/src/loadkeys.c @@ -73,6 +73,7 @@ #include #include #include +#include #include #include #include @@ -131,9 +132,7 @@ static void loadkeys(char *console, int kbd_mode); static void strings_as_usual(void); static void compose_as_usual(char *charset); -void lkfatal0(const char *, int); -void lkfatal(const char *s); -void lkfatal1(const char *s, const char *s2); +void lkfatal(const char *fmt, ...); extern int set_charset(const char *charset); extern int prefer_unicode; @@ -163,7 +162,7 @@ int yylex(void); /* Line 189 of yacc.c */ -#line 167 "loadkeys.c" +#line 166 "loadkeys.c" /* Enabling traces. */ #ifndef YYDEBUG @@ -275,7 +274,7 @@ typedef int YYSTYPE; /* Line 264 of yacc.c */ -#line 279 "loadkeys.c" +#line 278 "loadkeys.c" #ifdef short # undef short @@ -580,12 +579,12 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 107, 107, 108, 110, 111, 112, 113, 114, 115, - 116, 117, 118, 119, 121, 126, 131, 136, 140, 145, - 150, 151, 153, 159, 164, 173, 177, 182, 184, 187, - 187, 192, 197, 198, 200, 201, 202, 203, 204, 205, - 206, 207, 208, 210, 243, 244, 246, 253, 255, 257, - 259, 261, 263 + 0, 106, 106, 107, 109, 110, 111, 112, 113, 114, + 115, 116, 117, 118, 120, 125, 130, 135, 139, 144, + 149, 150, 152, 158, 163, 172, 176, 181, 183, 186, + 186, 191, 196, 197, 199, 200, 201, 202, 203, 204, + 205, 206, 207, 209, 242, 243, 245, 252, 254, 256, + 258, 260, 262 }; #endif @@ -1557,7 +1556,7 @@ yyreduce: case 14: /* Line 1464 of yacc.c */ -#line 122 "loadkeys.y" +#line 121 "loadkeys.y" { set_charset((char *) kbs_buf.kb_string); } @@ -1566,7 +1565,7 @@ yyreduce: case 15: /* Line 1464 of yacc.c */ -#line 127 "loadkeys.y" +#line 126 "loadkeys.y" { alt_is_meta = 1; } @@ -1575,7 +1574,7 @@ yyreduce: case 16: /* Line 1464 of yacc.c */ -#line 132 "loadkeys.y" +#line 131 "loadkeys.y" { strings_as_usual(); } @@ -1584,7 +1583,7 @@ yyreduce: case 17: /* Line 1464 of yacc.c */ -#line 137 "loadkeys.y" +#line 136 "loadkeys.y" { compose_as_usual((char *) kbs_buf.kb_string); } @@ -1593,7 +1592,7 @@ yyreduce: case 18: /* Line 1464 of yacc.c */ -#line 141 "loadkeys.y" +#line 140 "loadkeys.y" { compose_as_usual(0); } @@ -1602,7 +1601,7 @@ yyreduce: case 19: /* Line 1464 of yacc.c */ -#line 146 "loadkeys.y" +#line 145 "loadkeys.y" { keymaps_line_seen = 1; } @@ -1611,7 +1610,7 @@ yyreduce: case 22: /* Line 1464 of yacc.c */ -#line 154 "loadkeys.y" +#line 153 "loadkeys.y" { int i; for (i = (yyvsp[(1) - (3)]); i<= (yyvsp[(3) - (3)]); i++) @@ -1622,7 +1621,7 @@ yyreduce: case 23: /* Line 1464 of yacc.c */ -#line 160 "loadkeys.y" +#line 159 "loadkeys.y" { addmap((yyvsp[(1) - (1)]),1); } @@ -1631,10 +1630,10 @@ yyreduce: case 24: /* Line 1464 of yacc.c */ -#line 165 "loadkeys.y" +#line 164 "loadkeys.y" { if (KTYP((yyvsp[(2) - (5)])) != KT_FN) - lkfatal1(_("'%s' is not a function key symbol"), + lkfatal(_("'%s' is not a function key symbol"), syms[KTYP((yyvsp[(2) - (5)]))].table[KVAL((yyvsp[(2) - (5)]))]); kbs_buf.kb_func = KVAL((yyvsp[(2) - (5)])); addfunc(kbs_buf); @@ -1644,7 +1643,7 @@ yyreduce: case 25: /* Line 1464 of yacc.c */ -#line 174 "loadkeys.y" +#line 173 "loadkeys.y" { compose((yyvsp[(2) - (6)]), (yyvsp[(3) - (6)]), (yyvsp[(5) - (6)])); } @@ -1653,7 +1652,7 @@ yyreduce: case 26: /* Line 1464 of yacc.c */ -#line 178 "loadkeys.y" +#line 177 "loadkeys.y" { compose((yyvsp[(2) - (6)]), (yyvsp[(3) - (6)]), (yyvsp[(5) - (6)])); } @@ -1662,28 +1661,28 @@ yyreduce: case 27: /* Line 1464 of yacc.c */ -#line 183 "loadkeys.y" +#line 182 "loadkeys.y" { (yyval) = (yyvsp[(1) - (1)]); } break; case 28: /* Line 1464 of yacc.c */ -#line 185 "loadkeys.y" +#line 184 "loadkeys.y" { (yyval) = (yyvsp[(1) - (1)]) ^ 0xf000; } break; case 29: /* Line 1464 of yacc.c */ -#line 187 "loadkeys.y" +#line 186 "loadkeys.y" { mod = 0; } break; case 30: /* Line 1464 of yacc.c */ -#line 189 "loadkeys.y" +#line 188 "loadkeys.y" { addkey((yyvsp[(4) - (7)]), mod, (yyvsp[(6) - (7)])); } @@ -1692,7 +1691,7 @@ yyreduce: case 31: /* Line 1464 of yacc.c */ -#line 193 "loadkeys.y" +#line 192 "loadkeys.y" { addkey((yyvsp[(3) - (6)]), 0, (yyvsp[(5) - (6)])); } @@ -1701,70 +1700,70 @@ yyreduce: case 34: /* Line 1464 of yacc.c */ -#line 200 "loadkeys.y" +#line 199 "loadkeys.y" { mod |= M_SHIFT; } break; case 35: /* Line 1464 of yacc.c */ -#line 201 "loadkeys.y" +#line 200 "loadkeys.y" { mod |= M_CTRL; } break; case 36: /* Line 1464 of yacc.c */ -#line 202 "loadkeys.y" +#line 201 "loadkeys.y" { mod |= M_ALT; } break; case 37: /* Line 1464 of yacc.c */ -#line 203 "loadkeys.y" +#line 202 "loadkeys.y" { mod |= M_ALTGR; } break; case 38: /* Line 1464 of yacc.c */ -#line 204 "loadkeys.y" +#line 203 "loadkeys.y" { mod |= M_SHIFTL; } break; case 39: /* Line 1464 of yacc.c */ -#line 205 "loadkeys.y" +#line 204 "loadkeys.y" { mod |= M_SHIFTR; } break; case 40: /* Line 1464 of yacc.c */ -#line 206 "loadkeys.y" +#line 205 "loadkeys.y" { mod |= M_CTRLL; } break; case 41: /* Line 1464 of yacc.c */ -#line 207 "loadkeys.y" +#line 206 "loadkeys.y" { mod |= M_CTRLR; } break; case 42: /* Line 1464 of yacc.c */ -#line 208 "loadkeys.y" +#line 207 "loadkeys.y" { mod |= M_CAPSSHIFT; } break; case 43: /* Line 1464 of yacc.c */ -#line 211 "loadkeys.y" +#line 210 "loadkeys.y" { int i, j; @@ -1790,7 +1789,7 @@ yyreduce: i++; } if (i < rvalct) - lkfatal0(_("too many (%d) entries on one line"), rvalct); + lkfatal(_("too many (%d) entries on one line"), rvalct); } else for (i = 0; i < rvalct; i++) addkey((yyvsp[(2) - (5)]), i, key_buf[i]); @@ -1800,7 +1799,7 @@ yyreduce: case 46: /* Line 1464 of yacc.c */ -#line 247 "loadkeys.y" +#line 246 "loadkeys.y" { if (rvalct >= MAX_NR_KEYMAPS) lkfatal(_("too many key definitions on one line")); @@ -1811,49 +1810,49 @@ yyreduce: case 47: /* Line 1464 of yacc.c */ -#line 254 "loadkeys.y" +#line 253 "loadkeys.y" {(yyval)=convert_code((yyvsp[(1) - (1)]), TO_AUTO);} break; case 48: /* Line 1464 of yacc.c */ -#line 256 "loadkeys.y" +#line 255 "loadkeys.y" {(yyval)=add_capslock((yyvsp[(2) - (2)]));} break; case 49: /* Line 1464 of yacc.c */ -#line 258 "loadkeys.y" +#line 257 "loadkeys.y" {(yyval)=convert_code((yyvsp[(1) - (1)])^0xf000, TO_AUTO);} break; case 50: /* Line 1464 of yacc.c */ -#line 260 "loadkeys.y" +#line 259 "loadkeys.y" {(yyval)=add_capslock((yyvsp[(2) - (2)])^0xf000);} break; case 51: /* Line 1464 of yacc.c */ -#line 262 "loadkeys.y" +#line 261 "loadkeys.y" {(yyval)=(yyvsp[(1) - (1)]);} break; case 52: /* Line 1464 of yacc.c */ -#line 264 "loadkeys.y" +#line 263 "loadkeys.y" {(yyval)=add_capslock((yyvsp[(2) - (2)]));} break; /* Line 1464 of yacc.c */ -#line 1857 "loadkeys.c" +#line 1856 "loadkeys.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -2065,7 +2064,7 @@ yyreturn: /* Line 1684 of yacc.c */ -#line 266 "loadkeys.y" +#line 265 "loadkeys.y" static void attr_noreturn @@ -2288,30 +2287,15 @@ yyerror(const char *s) { return(0); } -/* fatal errors - change to varargs next time */ -void attr_noreturn -lkfatal(const char *s) { - fprintf(stderr, "%s: %s:%d: %s\n", progname, filename, line_nr, s); - xfree(filename); - exit(1); -} - -void attr_noreturn -lkfatal0(const char *s, int d) { +void attr_noreturn attr_format_1_2 +lkfatal(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); fprintf(stderr, "%s: %s:%d: ", progname, filename, line_nr); - fprintf(stderr, s, d); + vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); - xfree(filename); - exit(1); -} - -void attr_noreturn -lkfatal1(const char *s, const char *s2) { - fprintf(stderr, "%s: %s:%d: ", progname, filename, line_nr); - fprintf(stderr, s, s2); - fprintf(stderr, "\n"); - xfree(filename); - exit(1); + va_end(ap); + exit(EXIT_FAILURE); } /* @@ -2453,7 +2437,7 @@ open_include(char *s) { fd = find_incl_file(s); if (!fd) - lkfatal1(_("cannot open include file %s"), s); + lkfatal(_("cannot open include file %s"), s); xfree(s); @@ -2463,11 +2447,11 @@ open_include(char *s) { static void addmap(int i, int explicit) { if (i < 0 || i >= MAX_NR_KEYMAPS) - lkfatal0(_("addmap called with bad index %d"), i); + lkfatal(_("addmap called with bad index %d"), i); if (!defining[i]) { if (keymaps_line_seen && !explicit) - lkfatal0(_("adding map %d violates explicit keymaps line"), i); + lkfatal(_("adding map %d violates explicit keymaps line"), i); defining[i] = 1; if (max_keymap <= i) @@ -2481,9 +2465,9 @@ killkey(int k_index, int k_table) { /* roughly: addkey(k_index, k_table, K_HOLE); */ if (k_index < 0 || k_index >= NR_KEYS) - lkfatal0(_("killkey called with bad index %d"), k_index); + lkfatal(_("killkey called with bad index %d"), k_index); if (k_table < 0 || k_table >= MAX_NR_KEYMAPS) - lkfatal0(_("killkey called with bad table %d"), k_table); + lkfatal(_("killkey called with bad table %d"), k_table); if (key_map[k_table]) (key_map[k_table])[k_index] = K_HOLE; if (keymap_was_set[k_table]) @@ -2497,11 +2481,11 @@ addkey(int k_index, int k_table, int keycode) { if (keycode == CODE_FOR_UNKNOWN_KSYM) /* is safer not to be silent in this case, * it can be caused by coding errors as well. */ - lkfatal0(_("addkey called with bad keycode %d"), keycode); + lkfatal(_("addkey called with bad keycode %d"), keycode); if (k_index < 0 || k_index >= NR_KEYS) - lkfatal0(_("addkey called with bad index %d"), k_index); + lkfatal(_("addkey called with bad index %d"), k_index); if (k_table < 0 || k_table >= MAX_NR_KEYMAPS) - lkfatal0(_("addkey called with bad table %d"), k_table); + lkfatal(_("addkey called with bad table %d"), k_table); if (!defining[k_table]) addmap(k_table, 0); diff --git a/src/loadkeys.y b/src/loadkeys.y index 3bcb777..b8940b1 100644 --- a/src/loadkeys.y +++ b/src/loadkeys.y @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -72,9 +73,7 @@ static void loadkeys(char *console, int kbd_mode); static void strings_as_usual(void); static void compose_as_usual(char *charset); -void lkfatal0(const char *, int); -void lkfatal(const char *s); -void lkfatal1(const char *s, const char *s2); +void lkfatal(const char *fmt, ...); extern int set_charset(const char *charset); extern int prefer_unicode; @@ -164,7 +163,7 @@ range0 : NUMBER DASH NUMBER strline : STRING LITERAL EQUALS STRLITERAL EOL { if (KTYP($2) != KT_FN) - lkfatal1(_("'%s' is not a function key symbol"), + lkfatal(_("'%s' is not a function key symbol"), syms[KTYP($2)].table[KVAL($2)]); kbs_buf.kb_func = KVAL($2); addfunc(kbs_buf); @@ -233,7 +232,7 @@ fullline : KEYCODE NUMBER EQUALS rvalue0 EOL i++; } if (i < rvalct) - lkfatal0(_("too many (%d) entries on one line"), rvalct); + lkfatal(_("too many (%d) entries on one line"), rvalct); } else for (i = 0; i < rvalct; i++) addkey($2, i, key_buf[i]); @@ -485,30 +484,15 @@ yyerror(const char *s) { return(0); } -/* fatal errors - change to varargs next time */ -void attr_noreturn -lkfatal(const char *s) { - fprintf(stderr, "%s: %s:%d: %s\n", progname, filename, line_nr, s); - xfree(filename); - exit(1); -} - -void attr_noreturn -lkfatal0(const char *s, int d) { +void attr_noreturn attr_format_1_2 +lkfatal(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); fprintf(stderr, "%s: %s:%d: ", progname, filename, line_nr); - fprintf(stderr, s, d); + vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); - xfree(filename); - exit(1); -} - -void attr_noreturn -lkfatal1(const char *s, const char *s2) { - fprintf(stderr, "%s: %s:%d: ", progname, filename, line_nr); - fprintf(stderr, s, s2); - fprintf(stderr, "\n"); - xfree(filename); - exit(1); + va_end(ap); + exit(EXIT_FAILURE); } /* @@ -650,7 +634,7 @@ open_include(char *s) { fd = find_incl_file(s); if (!fd) - lkfatal1(_("cannot open include file %s"), s); + lkfatal(_("cannot open include file %s"), s); xfree(s); @@ -660,11 +644,11 @@ open_include(char *s) { static void addmap(int i, int explicit) { if (i < 0 || i >= MAX_NR_KEYMAPS) - lkfatal0(_("addmap called with bad index %d"), i); + lkfatal(_("addmap called with bad index %d"), i); if (!defining[i]) { if (keymaps_line_seen && !explicit) - lkfatal0(_("adding map %d violates explicit keymaps line"), i); + lkfatal(_("adding map %d violates explicit keymaps line"), i); defining[i] = 1; if (max_keymap <= i) @@ -678,9 +662,9 @@ killkey(int k_index, int k_table) { /* roughly: addkey(k_index, k_table, K_HOLE); */ if (k_index < 0 || k_index >= NR_KEYS) - lkfatal0(_("killkey called with bad index %d"), k_index); + lkfatal(_("killkey called with bad index %d"), k_index); if (k_table < 0 || k_table >= MAX_NR_KEYMAPS) - lkfatal0(_("killkey called with bad table %d"), k_table); + lkfatal(_("killkey called with bad table %d"), k_table); if (key_map[k_table]) (key_map[k_table])[k_index] = K_HOLE; if (keymap_was_set[k_table]) @@ -694,11 +678,11 @@ addkey(int k_index, int k_table, int keycode) { if (keycode == CODE_FOR_UNKNOWN_KSYM) /* is safer not to be silent in this case, * it can be caused by coding errors as well. */ - lkfatal0(_("addkey called with bad keycode %d"), keycode); + lkfatal(_("addkey called with bad keycode %d"), keycode); if (k_index < 0 || k_index >= NR_KEYS) - lkfatal0(_("addkey called with bad index %d"), k_index); + lkfatal(_("addkey called with bad index %d"), k_index); if (k_table < 0 || k_table >= MAX_NR_KEYMAPS) - lkfatal0(_("addkey called with bad table %d"), k_table); + lkfatal(_("addkey called with bad table %d"), k_table); if (!defining[k_table]) addmap(k_table, 0); -- 2.7.4