From 1b6e4fc9ac0b77c1092165465275218ade6454d8 Mon Sep 17 00:00:00 2001 From: Alexey Gladkov Date: Wed, 22 Aug 2012 01:17:03 +0400 Subject: [PATCH] loadkeys: Rewrite the parser to reentrant mode Signed-off-by: Alexey Gladkov --- src/Makefile.am | 1 - src/loadkeys.analyze.c | 1316 ++++++++++++++++++++++++++++-------------------- src/loadkeys.analyze.h | 108 ++-- src/loadkeys.analyze.l | 272 +++++----- src/loadkeys.c | 893 ++++++++++++++++---------------- src/loadkeys.h | 28 +- src/loadkeys.keymap.h | 18 +- src/loadkeys.y | 503 +++++++++--------- 8 files changed, 1739 insertions(+), 1400 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 05bf006..629f2f7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -86,7 +86,6 @@ kbdinfo_SOURCES = $(ALL_S) kbdinfo.c mapscrn_CFLAGS = -DMAIN loadunimap_CFLAGS = -DMAIN -AM_YFLAGS = -d AM_LFLAGS = --header-file=$(CURDIR)/loadkeys.analyze.h BUILT_SOURCES = loadkeys.c loadkeys.analyze.c loadkeys.h loadkeys.analyze.h loadkeys_SOURCES = loadkeys.y loadkeys.analyze.l $(KSYMS_S) diff --git a/src/loadkeys.analyze.c b/src/loadkeys.analyze.c index 5d2ad83..a3c6cf6 100644 --- a/src/loadkeys.analyze.c +++ b/src/loadkeys.analyze.c @@ -118,24 +118,41 @@ typedef unsigned int flex_uint32_t; */ #define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) +/* An opaque pointer. */ +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif + +/* For convenience, these vars (plus the bison vars far below) + are macros in the reentrant scanner. */ +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yy_flex_debug yyg->yy_flex_debug_r + /* Enter a start condition. This macro really ought to take a parameter, * but we do it the disgusting crufty way forced on us by the ()-less * definition of BEGIN. */ -#define BEGIN (yy_start) = 1 + 2 * +#define BEGIN yyg->yy_start = 1 + 2 * /* Translate the current start state into a value that can be later handed * to BEGIN to return to the state. The YYSTATE alias is for lex * compatibility. */ -#define YY_START (((yy_start) - 1) / 2) +#define YY_START ((yyg->yy_start - 1) / 2) #define YYSTATE YY_START /* Action number for EOF rule of a given start state. */ #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) /* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) +#define YY_NEW_FILE yyrestart(yyin ,yyscanner ) #define YY_END_OF_BUFFER_CHAR 0 @@ -153,15 +170,24 @@ typedef unsigned int flex_uint32_t; typedef struct yy_buffer_state *YY_BUFFER_STATE; #endif -extern int yyleng; - -extern FILE *yyin, *yyout; - #define EOB_ACT_CONTINUE_SCAN 0 #define EOB_ACT_END_OF_FILE 1 #define EOB_ACT_LAST_MATCH 2 - #define YY_LESS_LINENO(n) + /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires + * access to the local variable yy_act. Since yyless() is a macro, it would break + * existing scanners that call yyless() from OUTSIDE yylex. + * One obvious solution it to make yy_act a global. I tried that, and saw + * a 5% performance hit in a non-yylineno scanner, because yy_act is + * normally declared as a register variable-- so it is not worth it. + */ + #define YY_LESS_LINENO(n) \ + do { \ + int yyl;\ + for ( yyl = n; yyl < yyleng; ++yyl )\ + if ( yytext[yyl] == '\n' )\ + --yylineno;\ + }while(0) /* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ @@ -170,14 +196,14 @@ extern FILE *yyin, *yyout; /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ + *yy_cp = yyg->yy_hold_char; \ YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ YY_DO_BEFORE_ACTION; /* set up yytext again */ \ } \ while ( 0 ) -#define unput(c) yyunput( c, (yytext_ptr) ) +#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) #ifndef YY_TYPEDEF_YY_SIZE_T #define YY_TYPEDEF_YY_SIZE_T @@ -249,71 +275,51 @@ struct yy_buffer_state }; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ - /* We provide macros for accessing buffer states in case in the * future we want to put the buffer states in a more general * "scanner state". * * Returns the top of the stack, or NULL. */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ +#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ + ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ : NULL) /* Same as previous macro, but useful when we know that the buffer stack is not * NULL or when we need an lvalue. For internal use only. */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 0; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; +#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); +void yyrestart (FILE *input_file ,yyscan_t yyscanner ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner ); +void yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); +void yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); +void yypop_buffer_state (yyscan_t yyscanner ); -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); +static void yyensure_buffer_stack (yyscan_t yyscanner ); +static void yy_load_buffer_state (yyscan_t yyscanner ); +static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ,yyscan_t yyscanner ); -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ,yyscanner) -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner ); -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); +void *yyalloc (yy_size_t ,yyscan_t yyscanner ); +void *yyrealloc (void *,yy_size_t ,yyscan_t yyscanner ); +void yyfree (void * ,yyscan_t yyscanner ); #define yy_new_buffer yy_create_buffer #define yy_set_interactive(is_interactive) \ { \ if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ + yyensure_buffer_stack (yyscanner); \ YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ + yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ } @@ -321,9 +327,9 @@ void yyfree (void * ); #define yy_set_bol(at_bol) \ { \ if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ + yyensure_buffer_stack (yyscanner); \ YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ + yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); \ } \ YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ } @@ -337,35 +343,28 @@ void yyfree (void * ); typedef unsigned char YY_CHAR; -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; - typedef int yy_state_type; -extern int yylineno; - -int yylineno = 1; - -extern char *yytext; -#define yytext_ptr yytext +#define yytext_ptr yytext_r -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); +static yy_state_type yy_get_previous_state (yyscan_t yyscanner ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ,yyscan_t yyscanner); +static int yy_get_next_buffer (yyscan_t yyscanner ); #ifdef __GNUC__ -static void yy_fatal_error (yyconst char msg[] ) __attribute__((noreturn)); +static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner ) __attribute__((noreturn)); #else -static void yy_fatal_error (yyconst char msg[] ); +static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner ); #endif /* Done after the current pattern has been matched and before the * corresponding action - sets up yytext. */ #define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ + yyg->yytext_ptr = yy_bp; \ yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ + yyg->yy_hold_char = *yy_cp; \ *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; + yyg->yy_c_buf_p = yy_cp; #define YY_NUM_RULES 48 #define YY_END_OF_BUFFER 49 @@ -780,11 +779,12 @@ static yyconst flex_int16_t yy_chk[785] = 503, 503, 503, 503 } ; -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; +/* Table of booleans, true if rule could match eol. */ +static yyconst flex_int32_t yy_rule_can_match_eol[49] = + { 0, +0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, }; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. @@ -793,92 +793,72 @@ int yy_flex_debug = 0; #define yymore() yymore_used_but_not_detected #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET -char *yytext; #line 1 "loadkeys.analyze.l" -#define YY_NO_INPUT 1 -#line 7 "loadkeys.analyze.l" -#define YY_NO_INPUT 1 - +#line 2 "loadkeys.analyze.l" #include #include /* readlink */ -#include -#include -#include #include "ksyms.h" #include "nls.h" #include "kbd.h" #include "paths.h" #include "findfile.h" -#include "loadkeys.h" +#include "loadkeys.h" #include "loadkeys.keymap.h" +#define YY_NO_INPUT 1 +#line 28 "loadkeys.analyze.l" +extern int lkverbose(struct keymap *kmap, int level, const char *fmt, ...); -extern struct keymap kmap; -extern int lkverbose(int level, const char *fmt, ...); - -int stack_push(lkfile_t *fp); - -/* Include file handling - unfortunately flex-specific. */ -#define MAX_INCLUDE_DEPTH 20 -static struct infile { - lkfile_t fp; - int linenr; - YY_BUFFER_STATE buffer; -} infile_stack[MAX_INCLUDE_DEPTH]; - -static char *filename = NULL; -static int line_nr = 1; - -static char *p, *pmax; - -static int infile_stack_ptr = -1; -static int state_ptr = 0; +int stack_push(struct keymap *kmap, lkfile_t *fp, yyscan_t scanner); +int stack_pop(struct keymap *kmap, yyscan_t scanner); int -stack_push(lkfile_t *fp) +stack_push(struct keymap *kmap, lkfile_t *fp, yyscan_t scanner) { - if (infile_stack_ptr >= MAX_INCLUDE_DEPTH) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + int i = 0; + + while (kmap->stack[i]) i++; + + if (i == MAX_INCLUDE_DEPTH) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("includes are nested too deeply")); return -1; } - infile_stack_ptr++; - - infile_stack[infile_stack_ptr].buffer = yy_create_buffer(fp->fd,YY_BUF_SIZE); - infile_stack[infile_stack_ptr].linenr = line_nr; - - memcpy(&infile_stack[infile_stack_ptr].fp, fp, sizeof(fp)); - yy_switch_to_buffer(infile_stack[infile_stack_ptr].buffer); + kmap->stack[i] = malloc(sizeof(lkfile_t)); + if (kmap->stack[i] == NULL) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), + _("out of memory")); + return -1; + } - // Set global variables - filename = infile_stack[infile_stack_ptr].fp.pathname; - line_nr = 1; + kmap->stack[i]->fd = fp->fd; + kmap->stack[i]->pipe = fp->pipe; + strncpy(kmap->stack[i]->pathname, fp->pathname, sizeof(kmap->stack[i]->pathname) - 1); + kmap->stack[i]->pathname[sizeof(kmap->stack[i]->pathname)] = '\0'; + yypush_buffer_state(yy_create_buffer(fp->fd,YY_BUF_SIZE,scanner),scanner); return 0; } -static int -stack_pop(void) { - fpclose(&infile_stack[infile_stack_ptr].fp); +int +stack_pop(struct keymap *kmap, yyscan_t scanner) +{ + int i = 0; - // Destroy previous buffer - yy_delete_buffer(infile_stack[infile_stack_ptr].buffer); + while (kmap->stack[i]) i++; + if (i == 0) + return 0; + i--; - infile_stack_ptr--; + fpclose(kmap->stack[i]); - if (infile_stack_ptr >= 0) { - // Set new state - filename = infile_stack[infile_stack_ptr].fp.pathname; - line_nr = infile_stack[infile_stack_ptr].linenr; + free(kmap->stack[i]); + kmap->stack[i] = NULL; - // Switch to new buffer - yy_switch_to_buffer(infile_stack[infile_stack_ptr].buffer); - return 0; - } - - return 1; + yypop_buffer_state(scanner); + return 0; } /* @@ -919,7 +899,7 @@ static char *include_dirpath3[] = { static char *include_suffixes[] = { "", ".inc", 0 }; static int -find_incl_file_near_fn(char *s, char *fn, lkfile_t *fp) +find_incl_file_near_fn(struct keymap *kmap, char *s, char *fn, lkfile_t *fp) { char *t, *te, *t1, *t2; int len, rc = 1; @@ -954,17 +934,25 @@ find_incl_file_near_fn(char *s, char *fn, lkfile_t *fp) return rc; /* FIXME: free */ -nomem: snprintf(kmap.errmsg, sizeof(kmap.errmsg), _("out of memory")); +nomem: snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("out of memory")); return -1; } static int -find_standard_incl_file(char *s, lkfile_t *fp) +find_standard_incl_file(struct keymap *kmap, char *s, lkfile_t *fp) { + char *pathname; int rc = 1; + int i = 0; + + while (kmap->stack[i]) i++; + if (i == 0) + return -1; + i--; + pathname = kmap->stack[i]->pathname; if (findfile(s, include_dirpath1, include_suffixes, fp)) { - if ((rc = find_incl_file_near_fn(s, filename, fp)) == -1) + if ((rc = find_incl_file_near_fn(kmap, s, pathname, fp)) == -1) return rc; } @@ -973,20 +961,20 @@ find_standard_incl_file(char *s, lkfile_t *fp) char buf[MAXPATHLEN], path[MAXPATHLEN], *ptr; unsigned int n; - n = readlink(filename, buf, sizeof(buf)); + n = readlink(pathname, buf, sizeof(buf)); if (n > 0 && n < sizeof(buf)) { buf[n] = 0; if (buf[0] == '/') { - rc = find_incl_file_near_fn(s, buf, fp); + rc = find_incl_file_near_fn(kmap, s, buf, fp); - } else if (strlen(filename) + n < sizeof(path)) { - strcpy(path, filename); + } else if (strlen(pathname) + n < sizeof(path)) { + strcpy(path, pathname); path[sizeof(path) - 1] = 0; ptr = strrchr(path, '/'); if (ptr) ptr[1] = 0; strcat(path, buf); - rc = find_incl_file_near_fn(s, path, fp); + rc = find_incl_file_near_fn(kmap, s, path, fp); } } } @@ -997,7 +985,7 @@ find_standard_incl_file(char *s, lkfile_t *fp) } static int -find_incl_file(char *s, lkfile_t *fp) +find_incl_file(struct keymap *kmap, char *s, lkfile_t *fp) { char *ev; @@ -1022,7 +1010,7 @@ find_incl_file(char *s, lkfile_t *fp) if (*ev) rc = findfile(s, user_dir, include_suffixes, fp); else /* empty string denotes system path */ - rc = find_standard_incl_file(s, fp); + rc = find_standard_incl_file(kmap, s, fp); if (rc <= 0) return rc; @@ -1032,20 +1020,20 @@ find_incl_file(char *s, lkfile_t *fp) } return 1; } - return find_standard_incl_file(s, fp); + return find_standard_incl_file(kmap, s, fp); } static int -open_include(char *s) +open_include(struct keymap *kmap, char *s, yyscan_t scanner) { int rc; lkfile_t fp; - lkverbose(2, _("switching to %s"), s); + lkverbose(kmap, 2, _("switching to %s"), s); - rc = find_incl_file(s, &fp); + rc = find_incl_file(kmap, s, &fp); if (rc > 0) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("cannot open include file %s"), s); free(s); return -1; @@ -1056,13 +1044,13 @@ open_include(char *s) free(s); - return stack_push(&fp); + return stack_push(kmap, &fp, scanner); } -#line 1066 "loadkeys.analyze.c" +#line 1054 "loadkeys.analyze.c" #define INITIAL 0 #define RVALUE 1 @@ -1077,40 +1065,86 @@ open_include(char *s) #include #endif -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif +#define YY_EXTRA_TYPE struct keymap * + +/* Holds the entire state of the reentrant scanner. */ +struct yyguts_t + { + + /* User-defined. Not touched by flex. */ + YY_EXTRA_TYPE yyextra_r; + + /* The rest are the same as the globals declared in the non-reentrant scanner. */ + FILE *yyin_r, *yyout_r; + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ + char yy_hold_char; + int yy_n_chars; + int yyleng_r; + char *yy_c_buf_p; + int yy_init; + int yy_start; + int yy_did_buffer_switch_on_eof; + int yy_start_stack_ptr; + int yy_start_stack_depth; + int *yy_start_stack; + yy_state_type yy_last_accepting_state; + char* yy_last_accepting_cpos; + + int yylineno_r; + int yy_flex_debug_r; + + char *yytext_r; + int yy_more_flag; + int yy_more_len; + + YYSTYPE * yylval_r; + + }; /* end struct yyguts_t */ + +static int yy_init_globals (yyscan_t yyscanner ); + + /* This must go here because YYSTYPE and YYLTYPE are included + * from bison output in section 1.*/ + # define yylval yyg->yylval_r + +int yylex_init (yyscan_t* scanner); -static int yy_init_globals (void ); +int yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int yylex_destroy (void ); +int yylex_destroy (yyscan_t yyscanner ); + +int yyget_debug (yyscan_t yyscanner ); -int yyget_debug (void ); +void yyset_debug (int debug_flag ,yyscan_t yyscanner ); -void yyset_debug (int debug_flag ); +YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner ); -YY_EXTRA_TYPE yyget_extra (void ); +void yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); -void yyset_extra (YY_EXTRA_TYPE user_defined ); +FILE *yyget_in (yyscan_t yyscanner ); -FILE *yyget_in (void ); +void yyset_in (FILE * in_str ,yyscan_t yyscanner ); -void yyset_in (FILE * in_str ); +FILE *yyget_out (yyscan_t yyscanner ); -FILE *yyget_out (void ); +void yyset_out (FILE * out_str ,yyscan_t yyscanner ); -void yyset_out (FILE * out_str ); +int yyget_leng (yyscan_t yyscanner ); -int yyget_leng (void ); +char *yyget_text (yyscan_t yyscanner ); -char *yyget_text (void ); +int yyget_lineno (yyscan_t yyscanner ); -int yyget_lineno (void ); +void yyset_lineno (int line_number ,yyscan_t yyscanner ); -void yyset_lineno (int line_number ); +YYSTYPE * yyget_lval (yyscan_t yyscanner ); + +void yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner ); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -1118,37 +1152,33 @@ void yyset_lineno (int line_number ); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int yywrap (void ); +extern "C" int yywrap (yyscan_t yyscanner ); #else -extern int yywrap (void ); +extern int yywrap (yyscan_t yyscanner ); #endif #endif #ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); +static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); +static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner); #endif #ifndef YY_NO_INPUT #ifdef __cplusplus -static int yyinput (void ); +static int yyinput (yyscan_t yyscanner ); #else -static int input (void ); +static int input (yyscan_t yyscanner ); #endif #endif - static int yy_start_stack_ptr = 0; - static int yy_start_stack_depth = 0; - static int *yy_start_stack = NULL; - - static void yy_push_state (int new_state ); + static void yy_push_state (int new_state ,yyscan_t yyscanner); - static void yy_pop_state (void ); + static void yy_pop_state (yyscan_t yyscanner ); /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE @@ -1214,7 +1244,7 @@ static int input (void ); /* Report a fatal error. */ #ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) #endif /* end tables serialization structures and prototypes */ @@ -1225,9 +1255,11 @@ static int input (void ); #ifndef YY_DECL #define YY_DECL_IS_OURS 1 -extern int yylex (void); +extern int yylex \ + (YYSTYPE * yylval_param ,yyscan_t yyscanner); -#define YY_DECL int yylex (void) +#define YY_DECL int yylex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner) #endif /* !YY_DECL */ /* Code executed at the beginning of each rule, after yytext and yyleng @@ -1252,35 +1284,25 @@ YY_DECL register yy_state_type yy_current_state; register char *yy_cp, *yy_bp; register int yy_act; - -#line 307 "loadkeys.analyze.l" + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; +#line 306 "loadkeys.analyze.l" -/* To protect from wrong code in the higher level parser (loadkeys.y), - * make sure we do not return a sensible value if we - * do not intend to. (So wrong code would crash, or issue an error message. - * I mean the code like the one for PLAIN handling in past loadkeys.y. - * What to choose as the "bad" value: 0, -1?.. - * Well, make it equal to CODE_FOR_UNKNOWN_KSYM as the most efficient thing. - */ -#define YYLVAL_UNDEF CODE_FOR_UNKNOWN_KSYM -/* Every time yylex is called, initialize the associated - * yylval to YYLVAL_UNDEF. Then it might be overwritten by specific rules. */ - yylval = YYLVAL_UNDEF; +#line 1293 "loadkeys.analyze.c" -#line 1273 "loadkeys.analyze.c" + yylval = yylval_param; - if ( !(yy_init) ) + if ( !yyg->yy_init ) { - (yy_init) = 1; + yyg->yy_init = 1; #ifdef YY_USER_INIT YY_USER_INIT; #endif - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ + if ( ! yyg->yy_start ) + yyg->yy_start = 1; /* first start state */ if ( ! yyin ) yyin = stdin; @@ -1289,35 +1311,35 @@ YY_DECL yyout = stdout; if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); + yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); } - yy_load_buffer_state( ); + yy_load_buffer_state(yyscanner ); } while ( 1 ) /* loops until end-of-file is reached */ { - yy_cp = (yy_c_buf_p); + yy_cp = yyg->yy_c_buf_p; /* Support of yytext. */ - *yy_cp = (yy_hold_char); + *yy_cp = yyg->yy_hold_char; /* yy_bp points to the position in yy_ch_buf of the start of * the current run. */ yy_bp = yy_cp; - yy_current_state = (yy_start); + yy_current_state = yyg->yy_start; yy_match: do { register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -1328,62 +1350,70 @@ yy_match: yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; } - while ( yy_base[yy_current_state] != 727 ); + while ( yy_current_state != 503 ); + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; yy_find_action: yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - yy_act = yy_accept[yy_current_state]; - } YY_DO_BEFORE_ACTION; + if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) + { + int yyl; + for ( yyl = 0; yyl < yyleng; ++yyl ) + if ( yytext[yyl] == '\n' ) + + do{ yylineno++; + yycolumn=0; + }while(0) +; + } + do_action: /* This label is used only to access EOF actions. */ switch ( yy_act ) { /* beginning of action switch */ case 0: /* must back up */ /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); + *yy_cp = yyg->yy_hold_char; + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; goto yy_find_action; case 1: YY_RULE_SETUP -#line 322 "loadkeys.analyze.l" +#line 308 "loadkeys.analyze.l" { - yy_push_state(INCLSTR); - state_ptr++; + yy_push_state(INCLSTR, yyscanner); + yyextra->state_ptr++; } YY_BREAK case 2: YY_RULE_SETUP -#line 326 "loadkeys.analyze.l" +#line 312 "loadkeys.analyze.l" { char *s = strndup(yytext+1, strlen(yytext)-2); if (s == NULL) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("out of memory")); return(ERROR); } - /* use static pathname to store *s ? */ - if (open_include(s) == -1) + if (open_include(yyextra, s, yyscanner) == -1) return(ERROR); - yy_pop_state(); - state_ptr--; + + yy_pop_state(yyscanner); + yyextra->state_ptr--; } YY_BREAK case 3: /* rule 3 can match eol */ YY_RULE_SETUP -#line 340 "loadkeys.analyze.l" +#line 326 "loadkeys.analyze.l" { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("expected filename between quotes")); return(ERROR); } @@ -1392,9 +1422,9 @@ case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(RVALUE): case YY_STATE_EOF(STR): case YY_STATE_EOF(INCLSTR): -#line 345 "loadkeys.analyze.l" +#line 331 "loadkeys.analyze.l" { - stack_pop(); + stack_pop(yyextra, yyscanner); if (!YY_CURRENT_BUFFER) yyterminate(); } @@ -1402,73 +1432,74 @@ case YY_STATE_EOF(INCLSTR): case 4: /* rule 4 can match eol */ YY_RULE_SETUP -#line 350 "loadkeys.analyze.l" +#line 336 "loadkeys.analyze.l" { - line_nr++; + yyset_lineno(yyget_lineno(yyscanner) + 1,yyscanner); } YY_BREAK case 5: /* rule 5 can match eol */ YY_RULE_SETUP -#line 353 "loadkeys.analyze.l" +#line 339 "loadkeys.analyze.l" { - line_nr++; - if (state_ptr > 0) { - yy_pop_state(); - state_ptr--; + yyset_lineno(yyget_lineno(yyscanner) + 1,yyscanner); + + if (yyextra->state_ptr > 0) { + yy_pop_state(yyscanner); + yyextra->state_ptr--; } return(EOL); } YY_BREAK case 6: YY_RULE_SETUP -#line 361 "loadkeys.analyze.l" +#line 348 "loadkeys.analyze.l" ; /* do nothing */ YY_BREAK case 7: /* rule 7 can match eol */ -*yy_cp = (yy_hold_char); /* undo effects of setting up yytext */ -(yy_c_buf_p) = yy_cp -= 1; +*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */ +yyg->yy_c_buf_p = yy_cp -= 1; YY_DO_BEFORE_ACTION; /* set up yytext again */ YY_RULE_SETUP -#line 362 "loadkeys.analyze.l" +#line 349 "loadkeys.analyze.l" ; /* do nothing */ YY_BREAK case 8: YY_RULE_SETUP -#line 363 "loadkeys.analyze.l" +#line 350 "loadkeys.analyze.l" { - yy_push_state(RVALUE); - state_ptr++; - kmap.rvalct = 0; + yy_push_state(RVALUE, yyscanner); + yyextra->state_ptr++; + yyextra->rvalct = 0; return(EQUALS); } YY_BREAK case 9: YY_RULE_SETUP -#line 369 "loadkeys.analyze.l" +#line 356 "loadkeys.analyze.l" { - yy_push_state(RVALUE); - state_ptr++; + yy_push_state(RVALUE, yyscanner); + yyextra->state_ptr++; return(STRING); } YY_BREAK case 10: YY_RULE_SETUP -#line 374 "loadkeys.analyze.l" +#line 361 "loadkeys.analyze.l" { - yy_push_state(RVALUE); - state_ptr++; + yy_push_state(RVALUE, yyscanner); + yyextra->state_ptr++; return(TO); } YY_BREAK case 11: YY_RULE_SETUP -#line 379 "loadkeys.analyze.l" +#line 366 "loadkeys.analyze.l" { - yylval = strtol(yytext + 1, NULL, 16); - if (yylval >= 0xf000) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + yylval->num = strtol(yytext + 1, NULL, 16); + if (yylval->num >= 0xf000) { + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("unicode keysym out of range: %s"), yytext); return(ERROR); @@ -1478,262 +1509,265 @@ YY_RULE_SETUP YY_BREAK case 12: YY_RULE_SETUP -#line 389 "loadkeys.analyze.l" +#line 376 "loadkeys.analyze.l" { - yylval = strtol(yytext, NULL, 0); + yylval->num = strtol(yytext, NULL, 0); return(NUMBER); } YY_BREAK case 13: YY_RULE_SETUP -#line 393 "loadkeys.analyze.l" -{ return((yylval = ksymtocode(kmap.prefer_unicode, yytext, TO_AUTO)) == -1 ? ERROR : LITERAL); } +#line 380 "loadkeys.analyze.l" +{ return((yylval->num = ksymtocode(yyextra->prefer_unicode, yytext, TO_AUTO)) == -1 ? ERROR : LITERAL); } YY_BREAK case 14: YY_RULE_SETUP -#line 394 "loadkeys.analyze.l" +#line 381 "loadkeys.analyze.l" { return(DASH); } YY_BREAK case 15: YY_RULE_SETUP -#line 395 "loadkeys.analyze.l" +#line 382 "loadkeys.analyze.l" { return(COMMA); } YY_BREAK case 16: YY_RULE_SETUP -#line 396 "loadkeys.analyze.l" +#line 383 "loadkeys.analyze.l" { return(PLUS); } YY_BREAK case 17: YY_RULE_SETUP -#line 397 "loadkeys.analyze.l" +#line 384 "loadkeys.analyze.l" { return(CHARSET); } YY_BREAK case 18: YY_RULE_SETUP -#line 398 "loadkeys.analyze.l" +#line 385 "loadkeys.analyze.l" { return(KEYMAPS); } YY_BREAK case 19: YY_RULE_SETUP -#line 399 "loadkeys.analyze.l" +#line 386 "loadkeys.analyze.l" { return(KEYCODE); } YY_BREAK case 20: YY_RULE_SETUP -#line 400 "loadkeys.analyze.l" +#line 387 "loadkeys.analyze.l" { return(PLAIN); } YY_BREAK case 21: YY_RULE_SETUP -#line 401 "loadkeys.analyze.l" +#line 388 "loadkeys.analyze.l" { return(SHIFT); } YY_BREAK case 22: YY_RULE_SETUP -#line 402 "loadkeys.analyze.l" +#line 389 "loadkeys.analyze.l" { return(CONTROL); } YY_BREAK case 23: YY_RULE_SETUP -#line 403 "loadkeys.analyze.l" +#line 390 "loadkeys.analyze.l" { return(ALT); } YY_BREAK case 24: YY_RULE_SETUP -#line 404 "loadkeys.analyze.l" +#line 391 "loadkeys.analyze.l" { return(ALTGR); } YY_BREAK case 25: YY_RULE_SETUP -#line 405 "loadkeys.analyze.l" +#line 392 "loadkeys.analyze.l" { return(SHIFTL); } YY_BREAK case 26: YY_RULE_SETUP -#line 406 "loadkeys.analyze.l" +#line 393 "loadkeys.analyze.l" { return(SHIFTR); } YY_BREAK case 27: YY_RULE_SETUP -#line 407 "loadkeys.analyze.l" +#line 394 "loadkeys.analyze.l" { return(CTRLL); } YY_BREAK case 28: YY_RULE_SETUP -#line 408 "loadkeys.analyze.l" +#line 395 "loadkeys.analyze.l" { return(CTRLR); } YY_BREAK case 29: YY_RULE_SETUP -#line 409 "loadkeys.analyze.l" +#line 396 "loadkeys.analyze.l" { return(CAPSSHIFT); } YY_BREAK case 30: YY_RULE_SETUP -#line 410 "loadkeys.analyze.l" +#line 397 "loadkeys.analyze.l" { return(ALT_IS_META); } YY_BREAK case 31: YY_RULE_SETUP -#line 411 "loadkeys.analyze.l" +#line 398 "loadkeys.analyze.l" { return(STRINGS); } YY_BREAK case 32: YY_RULE_SETUP -#line 412 "loadkeys.analyze.l" +#line 399 "loadkeys.analyze.l" { return(COMPOSE); } YY_BREAK case 33: YY_RULE_SETUP -#line 413 "loadkeys.analyze.l" +#line 400 "loadkeys.analyze.l" { return(AS); } YY_BREAK case 34: YY_RULE_SETUP -#line 414 "loadkeys.analyze.l" +#line 401 "loadkeys.analyze.l" { return(USUAL); } YY_BREAK case 35: YY_RULE_SETUP -#line 415 "loadkeys.analyze.l" +#line 402 "loadkeys.analyze.l" { return(ON); } YY_BREAK case 36: YY_RULE_SETUP -#line 416 "loadkeys.analyze.l" +#line 403 "loadkeys.analyze.l" { return(FOR); } YY_BREAK case 37: YY_RULE_SETUP -#line 417 "loadkeys.analyze.l" +#line 404 "loadkeys.analyze.l" { - yylval = strtol(yytext + 2, NULL, 8); + yylval->num = strtol(yytext + 2, NULL, 8); return(CCHAR); } YY_BREAK case 38: YY_RULE_SETUP -#line 421 "loadkeys.analyze.l" +#line 408 "loadkeys.analyze.l" { - yylval = (unsigned char) yytext[2]; + yylval->num = (unsigned char) yytext[2]; return(CCHAR); } YY_BREAK case 39: YY_RULE_SETUP -#line 425 "loadkeys.analyze.l" +#line 412 "loadkeys.analyze.l" { - yylval = (unsigned char) yytext[1]; + yylval->num = (unsigned char) yytext[1]; return(CCHAR); } YY_BREAK case 40: YY_RULE_SETUP -#line 429 "loadkeys.analyze.l" +#line 416 "loadkeys.analyze.l" { - p = (char *) kmap.string; - pmax = p + sizeof(kmap.string) - 1; - yy_push_state(STR); - state_ptr++; + yylval->str.data[0] = '\0'; + yylval->str.len = 0; + + yy_push_state(STR, yyscanner); + yyextra->state_ptr++; } YY_BREAK case 41: YY_RULE_SETUP -#line 435 "loadkeys.analyze.l" +#line 423 "loadkeys.analyze.l" { - if (p >= pmax) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (yylval->str.len == MAX_PARSER_STRING) { + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("string too long")); return(ERROR); } - *p++ = strtol(yytext + 1, NULL, 8); + yylval->str.data[yylval->str.len++] = strtol(yytext + 1, NULL, 8); } YY_BREAK case 42: YY_RULE_SETUP -#line 443 "loadkeys.analyze.l" +#line 431 "loadkeys.analyze.l" { - if (p >= pmax) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (yylval->str.len == MAX_PARSER_STRING) { + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("string too long")); return(ERROR); } - *p++ = '"'; + yylval->str.data[yylval->str.len++] = '"'; } YY_BREAK case 43: YY_RULE_SETUP -#line 451 "loadkeys.analyze.l" +#line 439 "loadkeys.analyze.l" { - if (p >= pmax) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (yylval->str.len == MAX_PARSER_STRING) { + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("string too long")); return(ERROR); } - *p++ = '\\'; + yylval->str.data[yylval->str.len++] = '\\'; } YY_BREAK case 44: YY_RULE_SETUP -#line 459 "loadkeys.analyze.l" +#line 447 "loadkeys.analyze.l" { - if (p >= pmax) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (yylval->str.len == MAX_PARSER_STRING) { + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("string too long")); return(ERROR); } - *p++ = '\n'; + yylval->str.data[yylval->str.len++] = '\n'; } YY_BREAK case 45: /* rule 45 can match eol */ YY_RULE_SETUP -#line 467 "loadkeys.analyze.l" +#line 455 "loadkeys.analyze.l" { - char *ptmp = p; - p += strlen(yytext); - if (p > pmax) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + int len = strlen(yytext); + + if (yylval->str.len + len >= MAX_PARSER_STRING) { + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("string too long")); return(ERROR); } - strcpy(ptmp, yytext); + + strcpy((char *) yylval->str.data + yylval->str.len, yytext); + yylval->str.len += len; } YY_BREAK case 46: YY_RULE_SETUP -#line 477 "loadkeys.analyze.l" +#line 467 "loadkeys.analyze.l" { - *p = '\0'; - yy_pop_state(); - state_ptr--; + yylval->str.data[yylval->str.len] = '\0'; + yy_pop_state(yyscanner); + yyextra->state_ptr--; return(STRLITERAL); } YY_BREAK case 47: YY_RULE_SETUP -#line 483 "loadkeys.analyze.l" +#line 473 "loadkeys.analyze.l" { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("unknown characters")); return(ERROR); /* report any unknown characters */ } YY_BREAK case 48: YY_RULE_SETUP -#line 488 "loadkeys.analyze.l" +#line 478 "loadkeys.analyze.l" ECHO; YY_BREAK -#line 1729 "loadkeys.analyze.c" +#line 1763 "loadkeys.analyze.c" case YY_END_OF_BUFFER: { /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); + *yy_cp = yyg->yy_hold_char; YY_RESTORE_YY_MORE_OFFSET if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) @@ -1747,7 +1781,7 @@ ECHO; * this is the first action (other than possibly a * back-up) that will match for the new input source. */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; } @@ -1759,13 +1793,13 @@ ECHO; * end-of-buffer state). Contrast this with the test * in input(). */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) { /* This was really a NUL. */ yy_state_type yy_next_state; - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); /* Okay, we're now positioned to make the NUL * transition. We couldn't have @@ -1776,32 +1810,33 @@ ECHO; * will run more slowly). */ - yy_next_state = yy_try_NUL_trans( yy_current_state ); + yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; if ( yy_next_state ) { /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); + yy_cp = ++yyg->yy_c_buf_p; yy_current_state = yy_next_state; goto yy_match; } else { - yy_cp = (yy_c_buf_p); + yy_cp = yyg->yy_last_accepting_cpos; + yy_current_state = yyg->yy_last_accepting_state; goto yy_find_action; } } - else switch ( yy_get_next_buffer( ) ) + else switch ( yy_get_next_buffer( yyscanner ) ) { case EOB_ACT_END_OF_FILE: { - (yy_did_buffer_switch_on_eof) = 0; + yyg->yy_did_buffer_switch_on_eof = 0; - if ( yywrap( ) ) + if ( yywrap(yyscanner ) ) { /* Note: because we've taken care in * yy_get_next_buffer() to have set up @@ -1812,7 +1847,7 @@ ECHO; * YY_NULL, it'll still work - another * YY_NULL will get returned. */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; yy_act = YY_STATE_EOF(YY_START); goto do_action; @@ -1820,30 +1855,30 @@ ECHO; else { - if ( ! (yy_did_buffer_switch_on_eof) ) + if ( ! yyg->yy_did_buffer_switch_on_eof ) YY_NEW_FILE; } break; } case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; + yyg->yy_c_buf_p = + yyg->yytext_ptr + yy_amount_of_matched_text; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; goto yy_match; case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + yyg->yy_c_buf_p = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; - yy_current_state = yy_get_previous_state( ); + yy_current_state = yy_get_previous_state( yyscanner ); - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; + yy_cp = yyg->yy_c_buf_p; + yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; goto yy_find_action; } break; @@ -1863,20 +1898,21 @@ ECHO; * EOB_ACT_CONTINUE_SCAN - continue scanning from current position * EOB_ACT_END_OF_FILE - end of file */ -static int yy_get_next_buffer (void) +static int yy_get_next_buffer (yyscan_t yyscanner) { - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = (yytext_ptr); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = yyg->yytext_ptr; register int number_to_move, i; int ret_val; - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) YY_FATAL_ERROR( "fatal flex scanner internal error--end of buffer missed" ); if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) { /* We matched a single character, the EOB, so * treat this as a final EOF. @@ -1896,7 +1932,7 @@ static int yy_get_next_buffer (void) /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr) - 1; for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); @@ -1905,7 +1941,7 @@ static int yy_get_next_buffer (void) /* don't do the read, it's not guaranteed to return an EOF, * just force an EOF */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; else { @@ -1919,7 +1955,7 @@ static int yy_get_next_buffer (void) YY_BUFFER_STATE b = YY_CURRENT_BUFFER; int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); + (int) (yyg->yy_c_buf_p - b->yy_ch_buf); if ( b->yy_is_our_buffer ) { @@ -1932,7 +1968,7 @@ static int yy_get_next_buffer (void) b->yy_ch_buf = (char *) /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ,yyscanner ); } else /* Can't grow it, we don't own it. */ @@ -1942,7 +1978,7 @@ static int yy_get_next_buffer (void) YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" ); - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; @@ -1954,17 +1990,17 @@ static int yy_get_next_buffer (void) /* Read in more data. */ YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), (size_t) num_to_read ); + yyg->yy_n_chars, (size_t) num_to_read ); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } - if ( (yy_n_chars) == 0 ) + if ( yyg->yy_n_chars == 0 ) { if ( number_to_move == YY_MORE_ADJ ) { ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); + yyrestart(yyin ,yyscanner); } else @@ -1978,39 +2014,40 @@ static int yy_get_next_buffer (void) else ret_val = EOB_ACT_CONTINUE_SCAN; - if ((yy_size_t) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + if ((yy_size_t) (yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ - yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + yy_size_t new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ,yyscanner ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); } - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + yyg->yy_n_chars += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; return ret_val; } /* yy_get_previous_state - get the state just before the EOB char was reached */ - static yy_state_type yy_get_previous_state (void) + static yy_state_type yy_get_previous_state (yyscan_t yyscanner) { register yy_state_type yy_current_state; register char *yy_cp; - - yy_current_state = (yy_start); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + yy_current_state = yyg->yy_start; - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) { register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -2029,16 +2066,17 @@ static int yy_get_next_buffer (void) * synopsis * next_state = yy_try_NUL_trans( current_state ); */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) { register int yy_is_jam; - register char *yy_cp = (yy_c_buf_p); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ + register char *yy_cp = yyg->yy_c_buf_p; register YY_CHAR yy_c = 1; if ( yy_accept[yy_current_state] ) { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; + yyg->yy_last_accepting_state = yy_current_state; + yyg->yy_last_accepting_cpos = yy_cp; } while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { @@ -2054,32 +2092,33 @@ static int yy_get_next_buffer (void) #ifndef YY_NO_INPUT #ifdef __cplusplus - static int yyinput (void) + static int yyinput (yyscan_t yyscanner) #else - static int input (void) + static int input (yyscan_t yyscanner) #endif { int c; - - *(yy_c_buf_p) = (yy_hold_char); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + *yyg->yy_c_buf_p = yyg->yy_hold_char; - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) { /* yy_c_buf_p now points to the character we want to return. * If this occurs *before* the EOB characters, then it's a * valid NUL; if not, then we've hit the end of the buffer. */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; + *yyg->yy_c_buf_p = '\0'; else { /* need more input */ - int offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); + int offset = yyg->yy_c_buf_p - yyg->yytext_ptr; + ++yyg->yy_c_buf_p; - switch ( yy_get_next_buffer( ) ) + switch ( yy_get_next_buffer( yyscanner ) ) { case EOB_ACT_LAST_MATCH: /* This happens because yy_g_n_b() @@ -2093,34 +2132,41 @@ static int yy_get_next_buffer (void) */ /* Reset buffer status. */ - yyrestart(yyin ); + yyrestart(yyin ,yyscanner); /*FALLTHROUGH*/ case EOB_ACT_END_OF_FILE: { - if ( yywrap( ) ) + if ( yywrap(yyscanner ) ) return EOF; - if ( ! (yy_did_buffer_switch_on_eof) ) + if ( ! yyg->yy_did_buffer_switch_on_eof ) YY_NEW_FILE; #ifdef __cplusplus - return yyinput(); + return yyinput(yyscanner); #else - return input(); + return input(yyscanner); #endif } case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; + yyg->yy_c_buf_p = yyg->yytext_ptr + offset; break; } } } - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); + c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ + *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ + yyg->yy_hold_char = *++yyg->yy_c_buf_p; + + if ( c == '\n' ) + + do{ yylineno++; + yycolumn=0; + }while(0) +; return c; } @@ -2128,76 +2174,79 @@ static int yy_get_next_buffer (void) /** Immediately switch to a different input stream. * @param input_file A readable stream. - * + * @param yyscanner The scanner object. * @note This function does not reset the start condition to @c INITIAL . */ - void yyrestart (FILE * input_file ) + void yyrestart (FILE * input_file , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); + yy_create_buffer(yyin,YY_BUF_SIZE ,yyscanner); } - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); + yy_init_buffer(YY_CURRENT_BUFFER,input_file ,yyscanner); + yy_load_buffer_state(yyscanner ); } /** Switch to a different input buffer. * @param new_buffer The new input buffer. - * + * @param yyscanner The scanner object. */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* TODO. We should be able to replace this entire function body * with * yypop_buffer_state(); * yypush_buffer_state(new_buffer); */ - yyensure_buffer_stack (); + yyensure_buffer_stack (yyscanner); if ( YY_CURRENT_BUFFER == new_buffer ) return; if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); + yy_load_buffer_state(yyscanner ); /* We don't actually know whether we did this switch during * EOF (yywrap()) processing, but the only time this flag * is looked at is after yywrap() is called, so it's safe * to go ahead and always set it. */ - (yy_did_buffer_switch_on_eof) = 1; + yyg->yy_did_buffer_switch_on_eof = 1; } -static void yy_load_buffer_state (void) +static void yy_load_buffer_state (yyscan_t yyscanner) { - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); + yyg->yy_hold_char = *yyg->yy_c_buf_p; } /** Allocate and initialize an input buffer state. * @param file A readable stream. * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * + * @param yyscanner The scanner object. * @return the allocated buffer state. */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size , yyscan_t yyscanner) { YY_BUFFER_STATE b; - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); @@ -2206,24 +2255,25 @@ static void yy_load_buffer_state (void) /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ,yyscanner ); if ( ! b->yy_ch_buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); b->yy_is_our_buffer = 1; - yy_init_buffer(b,file ); + yy_init_buffer(b,file ,yyscanner); return b; } /** Destroy the buffer. * @param b a buffer created with yy_create_buffer() - * + * @param yyscanner The scanner object. */ - void yy_delete_buffer (YY_BUFFER_STATE b ) + void yy_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! b ) return; @@ -2231,25 +2281,22 @@ static void yy_load_buffer_state (void) YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); + yyfree((void *) b->yy_ch_buf ,yyscanner ); - yyfree((void *) b ); + yyfree((void *) b ,yyscanner ); } -#if defined(YY_NO_UNISTD_H) && !defined(__cplusplus) -extern int isatty (int ); -#endif /* YY_NO_UNISTD_H && !__cplusplus */ - /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) { int oerrno = errno; - - yy_flush_buffer(b ); + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + yy_flush_buffer(b ,yyscanner); b->yy_input_file = file; b->yy_fill_buffer = 1; @@ -2263,18 +2310,19 @@ extern int isatty (int ); b->yy_bs_column = 0; } - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + b->yy_is_interactive = 0; errno = oerrno; } /** Discard all buffered characters. On the next scan, YY_INPUT will be called. * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * + * @param yyscanner The scanner object. */ - void yy_flush_buffer (YY_BUFFER_STATE b ) + void yy_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) { - if ( ! b ) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( ! b ) return; b->yy_n_chars = 0; @@ -2292,114 +2340,117 @@ extern int isatty (int ); b->yy_buffer_status = YY_BUFFER_NEW; if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); + yy_load_buffer_state(yyscanner ); } /** Pushes the new state onto the stack. The new state becomes * the current state. This function will allocate the stack * if necessary. * @param new_buffer The new state. - * + * @param yyscanner The scanner object. */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) { - if (new_buffer == NULL) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (new_buffer == NULL) return; - yyensure_buffer_stack(); + yyensure_buffer_stack(yyscanner); /* This block is copied from yy_switch_to_buffer. */ if ( YY_CURRENT_BUFFER ) { /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + *yyg->yy_c_buf_p = yyg->yy_hold_char; + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; } /* Only push if top exists. Otherwise, replace top. */ if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; + yyg->yy_buffer_stack_top++; YY_CURRENT_BUFFER_LVALUE = new_buffer; /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; + yy_load_buffer_state(yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; } /** Removes and deletes the top of the stack, if present. * The next element becomes the new top. - * + * @param yyscanner The scanner object. */ -void yypop_buffer_state (void) +void yypop_buffer_state (yyscan_t yyscanner) { - if (!YY_CURRENT_BUFFER) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if (!YY_CURRENT_BUFFER) return; - yy_delete_buffer(YY_CURRENT_BUFFER ); + yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner); YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); + if (yyg->yy_buffer_stack_top > 0) + --yyg->yy_buffer_stack_top; if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; + yy_load_buffer_state(yyscanner ); + yyg->yy_did_buffer_switch_on_eof = 1; } } /* Allocates the stack if it does not exist. * Guarantees space for at least one push. */ -static void yyensure_buffer_stack (void) +static void yyensure_buffer_stack (yyscan_t yyscanner) { int num_to_alloc; - - if (!(yy_buffer_stack)) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (!yyg->yy_buffer_stack) { /* First allocation is just for 2 elements, since we don't know if this * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ num_to_alloc = 1; - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; + yyg->yy_buffer_stack_max = num_to_alloc; + yyg->yy_buffer_stack_top = 0; return; } - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ /* Increase the buffer to prepare for a possible push. */ int grow_size = 8 /* arbitrary grow size */; - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), + num_to_alloc = yyg->yy_buffer_stack_max + grow_size; + yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc + (yyg->yy_buffer_stack, num_to_alloc * sizeof(struct yy_buffer_state*) - ); - if ( ! (yy_buffer_stack) ) + , yyscanner); + if ( ! yyg->yy_buffer_stack ) YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; + memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); + yyg->yy_buffer_stack_max = num_to_alloc; } } /** Setup the input buffer state to scan directly from a user-specified character buffer. * @param base the character buffer * @param size the size in bytes of the character buffer - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) { YY_BUFFER_STATE b; @@ -2409,7 +2460,7 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) /* They forgot to leave room for the EOB's. */ return 0; - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ,yyscanner ); if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); @@ -2423,7 +2474,7 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) b->yy_fill_buffer = 0; b->yy_buffer_status = YY_BUFFER_NEW; - yy_switch_to_buffer(b ); + yy_switch_to_buffer(b ,yyscanner ); return b; } @@ -2431,25 +2482,25 @@ YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) /** Setup the input buffer state to scan a string. The next call to yylex() will * scan from a @e copy of @a str. * @param yystr a NUL-terminated string to scan - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. * @note If you want to scan bytes that may contain NUL values, then use * yy_scan_bytes() instead. */ -YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) +YY_BUFFER_STATE yy_scan_string (yyconst char * yystr , yyscan_t yyscanner) { - return yy_scan_bytes(yystr,strlen(yystr) ); + return yy_scan_bytes(yystr,strlen(yystr) ,yyscanner); } /** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. * @param yybytes the byte buffer to scan * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * + * @param yyscanner The scanner object. * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) +YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner) { YY_BUFFER_STATE b; char *buf; @@ -2458,7 +2509,7 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; - buf = (char *) yyalloc(n ); + buf = (char *) yyalloc(n ,yyscanner ); if ( ! buf ) YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); @@ -2467,7 +2518,7 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - b = yy_scan_buffer(buf,n ); + b = yy_scan_buffer(buf,n ,yyscanner); if ( ! b ) YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); @@ -2479,43 +2530,45 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) return b; } - static void yy_push_state (int new_state ) + static void yy_push_state (int new_state , yyscan_t yyscanner) { - if ( (yy_start_stack_ptr) >= (yy_start_stack_depth) ) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( yyg->yy_start_stack_ptr >= yyg->yy_start_stack_depth ) { yy_size_t new_size; - (yy_start_stack_depth) += YY_START_STACK_INCR; - new_size = (yy_start_stack_depth) * sizeof( int ); + yyg->yy_start_stack_depth += YY_START_STACK_INCR; + new_size = yyg->yy_start_stack_depth * sizeof( int ); - if ( ! (yy_start_stack) ) - (yy_start_stack) = (int *) yyalloc(new_size ); + if ( ! yyg->yy_start_stack ) + yyg->yy_start_stack = (int *) yyalloc(new_size ,yyscanner ); else - (yy_start_stack) = (int *) yyrealloc((void *) (yy_start_stack),new_size ); + yyg->yy_start_stack = (int *) yyrealloc((void *) yyg->yy_start_stack,new_size ,yyscanner ); - if ( ! (yy_start_stack) ) + if ( ! yyg->yy_start_stack ) YY_FATAL_ERROR( "out of memory expanding start-condition stack" ); } - (yy_start_stack)[(yy_start_stack_ptr)++] = YY_START; + yyg->yy_start_stack[yyg->yy_start_stack_ptr++] = YY_START; BEGIN(new_state); } - static void yy_pop_state (void) + static void yy_pop_state (yyscan_t yyscanner) { - if ( --(yy_start_stack_ptr) < 0 ) + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + if ( --yyg->yy_start_stack_ptr < 0 ) YY_FATAL_ERROR( "start-condition stack underflow" ); - BEGIN((yy_start_stack)[(yy_start_stack_ptr)]); + BEGIN(yyg->yy_start_stack[yyg->yy_start_stack_ptr]); } #ifndef YY_EXIT_FAILURE #define YY_EXIT_FAILURE 2 #endif -static void yy_fatal_error (yyconst char* msg ) +static void yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) { (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); @@ -2530,110 +2583,253 @@ static void yy_fatal_error (yyconst char* msg ) /* Undo effects of setting up yytext. */ \ int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ + yytext[yyleng] = yyg->yy_hold_char; \ + yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ + yyg->yy_hold_char = *yyg->yy_c_buf_p; \ + *yyg->yy_c_buf_p = '\0'; \ yyleng = yyless_macro_arg; \ } \ while ( 0 ) /* Accessor methods (get/set functions) to struct members. */ +/** Get the user-defined data for this scanner. + * @param yyscanner The scanner object. + */ +YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyextra; +} + /** Get the current line number. - * + * @param yyscanner The scanner object. */ -int yyget_lineno (void) +int yyget_lineno (yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; + return yylineno; } +/** Get the current column number. + * @param yyscanner The scanner object. + */ +int yyget_column (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + if (! YY_CURRENT_BUFFER) + return 0; + + return yycolumn; +} + /** Get the input stream. - * + * @param yyscanner The scanner object. */ -FILE *yyget_in (void) +FILE *yyget_in (yyscan_t yyscanner) { - return yyin; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyin; } /** Get the output stream. - * + * @param yyscanner The scanner object. */ -FILE *yyget_out (void) +FILE *yyget_out (yyscan_t yyscanner) { - return yyout; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyout; } /** Get the length of the current token. - * + * @param yyscanner The scanner object. */ -int yyget_leng (void) +int yyget_leng (yyscan_t yyscanner) { - return yyleng; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yyleng; } /** Get the current token. - * + * @param yyscanner The scanner object. */ -char *yyget_text (void) +char *yyget_text (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yytext; +} + +/** Set the user-defined data. This data is never touched by the scanner. + * @param user_defined The data to be associated with this scanner. + * @param yyscanner The scanner object. + */ +void yyset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) { - return yytext; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyextra = user_defined ; } /** Set the current line number. * @param line_number - * + * @param yyscanner The scanner object. */ -void yyset_lineno (int line_number ) +void yyset_lineno (int line_number , yyscan_t yyscanner) { + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* lineno is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + yy_fatal_error( "yyset_lineno called with no buffer" , yyscanner); yylineno = line_number; } +/** Set the current column. + * @param line_number + * @param yyscanner The scanner object. + */ +void yyset_column (int column_no , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + + /* column is only valid if an input buffer exists. */ + if (! YY_CURRENT_BUFFER ) + yy_fatal_error( "yyset_column called with no buffer" , yyscanner); + + yycolumn = column_no; +} + /** Set the input stream. This does not discard the current * input buffer. * @param in_str A readable stream. - * + * @param yyscanner The scanner object. * @see yy_switch_to_buffer */ -void yyset_in (FILE * in_str ) +void yyset_in (FILE * in_str , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyin = in_str ; +} + +void yyset_out (FILE * out_str , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yyout = out_str ; +} + +int yyget_debug (yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yy_flex_debug; +} + +void yyset_debug (int bdebug , yyscan_t yyscanner) +{ + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yy_flex_debug = bdebug ; +} + +/* Accessor methods for yylval and yylloc */ + +YYSTYPE * yyget_lval (yyscan_t yyscanner) { - yyin = in_str ; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + return yylval; } -void yyset_out (FILE * out_str ) +void yyset_lval (YYSTYPE * yylval_param , yyscan_t yyscanner) { - yyout = out_str ; + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + yylval = yylval_param; } -int yyget_debug (void) +/* User-visible API */ + +/* yylex_init is special because it creates the scanner itself, so it is + * the ONLY reentrant function that doesn't take the scanner as the last argument. + * That's why we explicitly handle the declaration, instead of using our macros. + */ + +int yylex_init(yyscan_t* ptr_yy_globals) + { - return yy_flex_debug; + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + return yy_init_globals ( *ptr_yy_globals ); } -void yyset_debug (int bdebug ) +/* yylex_init_extra has the same functionality as yylex_init, but follows the + * convention of taking the scanner as the last argument. Note however, that + * this is a *pointer* to a scanner, as it will be allocated by this call (and + * is the reason, too, why this function also must handle its own declaration). + * The user defined value in the first argument will be available to yyalloc in + * the yyextra field. + */ + +int yylex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) + { - yy_flex_debug = bdebug ; + struct yyguts_t dummy_yyguts; + + yyset_extra (yy_user_defined, &dummy_yyguts); + + if (ptr_yy_globals == NULL){ + errno = EINVAL; + return 1; + } + + *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); + + if (*ptr_yy_globals == NULL){ + errno = ENOMEM; + return 1; + } + + /* By setting to 0xAA, we expose bugs in + yy_init_globals. Leave at 0x00 for releases. */ + memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); + + yyset_extra (yy_user_defined, *ptr_yy_globals); + + return yy_init_globals ( *ptr_yy_globals ); } -static int yy_init_globals (void) +static int yy_init_globals (yyscan_t yyscanner) { - /* Initialization is the same as for the non-reentrant scanner. + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* Initialization is the same as for the non-reentrant scanner. * This function is called from yylex_destroy(), so don't allocate here. */ - (yy_buffer_stack) = 0; - (yy_buffer_stack_top) = 0; - (yy_buffer_stack_max) = 0; - (yy_c_buf_p) = (char *) 0; - (yy_init) = 0; - (yy_start) = 0; + yyg->yy_buffer_stack = 0; + yyg->yy_buffer_stack_top = 0; + yyg->yy_buffer_stack_max = 0; + yyg->yy_c_buf_p = (char *) 0; + yyg->yy_init = 0; + yyg->yy_start = 0; - (yy_start_stack_ptr) = 0; - (yy_start_stack_depth) = 0; - (yy_start_stack) = NULL; + yyg->yy_start_stack_ptr = 0; + yyg->yy_start_stack_depth = 0; + yyg->yy_start_stack = NULL; /* Defined in main.c */ #ifdef YY_STDINIT @@ -2651,28 +2847,32 @@ static int yy_init_globals (void) } /* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) +int yylex_destroy (yyscan_t yyscanner) { - + struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; + /* Pop the buffer stack, destroying each element. */ while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); + yy_delete_buffer(YY_CURRENT_BUFFER ,yyscanner ); YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); + yypop_buffer_state(yyscanner); } /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; + yyfree(yyg->yy_buffer_stack ,yyscanner); + yyg->yy_buffer_stack = NULL; /* Destroy the start condition stack. */ - yyfree((yy_start_stack) ); - (yy_start_stack) = NULL; + yyfree(yyg->yy_start_stack ,yyscanner ); + yyg->yy_start_stack = NULL; /* Reset the globals. This is important in a non-reentrant scanner so the next time * yylex() is called, initialization will occur. */ - yy_init_globals( ); + yy_init_globals( yyscanner); + /* Destroy the main struct (reentrant only). */ + yyfree ( yyscanner , yyscanner ); + yyscanner = NULL; return 0; } @@ -2681,7 +2881,7 @@ int yylex_destroy (void) */ #ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner) { register int i; for ( i = 0; i < n; ++i ) @@ -2690,7 +2890,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) +static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) { register int n; for ( n = 0; s[n]; ++n ) @@ -2700,12 +2900,12 @@ static int yy_flex_strlen (yyconst char * s ) } #endif -void *yyalloc (yy_size_t size ) +void *yyalloc (yy_size_t size , yyscan_t yyscanner) { return (void *) malloc( size ); } -void *yyrealloc (void * ptr, yy_size_t size ) +void *yyrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner) { /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those @@ -2717,14 +2917,14 @@ void *yyrealloc (void * ptr, yy_size_t size ) return (void *) realloc( (char *) ptr, size ); } -void yyfree (void * ptr ) +void yyfree (void * ptr , yyscan_t yyscanner) { free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ } #define YYTABLES_NAME "yytables" -#line 488 "loadkeys.analyze.l" +#line 478 "loadkeys.analyze.l" diff --git a/src/loadkeys.analyze.h b/src/loadkeys.analyze.h index d914a27..579cc4f 100644 --- a/src/loadkeys.analyze.h +++ b/src/loadkeys.analyze.h @@ -111,6 +111,23 @@ typedef unsigned int flex_uint32_t; #define yyconst #endif +/* An opaque pointer. */ +#ifndef YY_TYPEDEF_YY_SCANNER_T +#define YY_TYPEDEF_YY_SCANNER_T +typedef void* yyscan_t; +#endif + +/* For convenience, these vars (plus the bison vars far below) + are macros in the reentrant scanner. */ +#define yyin yyg->yyin_r +#define yyout yyg->yyout_r +#define yyextra yyg->yyextra_r +#define yyleng yyg->yyleng_r +#define yytext yyg->yytext_r +#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) +#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) +#define yy_flex_debug yyg->yy_flex_debug_r + /* Size of default input buffer. */ #ifndef YY_BUF_SIZE #define YY_BUF_SIZE 16384 @@ -121,10 +138,6 @@ typedef unsigned int flex_uint32_t; typedef struct yy_buffer_state *YY_BUFFER_STATE; #endif -extern int yyleng; - -extern FILE *yyin, *yyout; - #ifndef YY_TYPEDEF_YY_SIZE_T #define YY_TYPEDEF_YY_SIZE_T typedef size_t yy_size_t; @@ -181,31 +194,28 @@ struct yy_buffer_state }; #endif /* !YY_STRUCT_YY_BUFFER_STATE */ -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); +void yyrestart (FILE *input_file ,yyscan_t yyscanner ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ,yyscan_t yyscanner ); +void yy_delete_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); +void yy_flush_buffer (YY_BUFFER_STATE b ,yyscan_t yyscanner ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ,yyscan_t yyscanner ); +void yypop_buffer_state (yyscan_t yyscanner ); -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ,yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ,yyscan_t yyscanner ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ,yyscan_t yyscanner ); -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); +void *yyalloc (yy_size_t ,yyscan_t yyscanner ); +void *yyrealloc (void *,yy_size_t ,yyscan_t yyscanner ); +void yyfree (void * ,yyscan_t yyscanner ); /* Begin user sect3 */ #define yywrap(n) 1 #define YY_SKIP_YYWRAP -extern int yylineno; - -extern char *yytext; -#define yytext_ptr yytext +#define yytext_ptr yytext_r #ifdef YY_HEADER_EXPORT_START_CONDITIONS #define INITIAL 0 @@ -223,38 +233,44 @@ extern char *yytext; #include #endif -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif +#define YY_EXTRA_TYPE struct keymap * + +int yylex_init (yyscan_t* scanner); + +int yylex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); /* Accessor methods to globals. These are made visible to non-reentrant scanners for convenience. */ -int yylex_destroy (void ); +int yylex_destroy (yyscan_t yyscanner ); + +int yyget_debug (yyscan_t yyscanner ); + +void yyset_debug (int debug_flag ,yyscan_t yyscanner ); -int yyget_debug (void ); +YY_EXTRA_TYPE yyget_extra (yyscan_t yyscanner ); -void yyset_debug (int debug_flag ); +void yyset_extra (YY_EXTRA_TYPE user_defined ,yyscan_t yyscanner ); -YY_EXTRA_TYPE yyget_extra (void ); +FILE *yyget_in (yyscan_t yyscanner ); -void yyset_extra (YY_EXTRA_TYPE user_defined ); +void yyset_in (FILE * in_str ,yyscan_t yyscanner ); -FILE *yyget_in (void ); +FILE *yyget_out (yyscan_t yyscanner ); -void yyset_in (FILE * in_str ); +void yyset_out (FILE * out_str ,yyscan_t yyscanner ); -FILE *yyget_out (void ); +int yyget_leng (yyscan_t yyscanner ); -void yyset_out (FILE * out_str ); +char *yyget_text (yyscan_t yyscanner ); -int yyget_leng (void ); +int yyget_lineno (yyscan_t yyscanner ); -char *yyget_text (void ); +void yyset_lineno (int line_number ,yyscan_t yyscanner ); -int yyget_lineno (void ); +YYSTYPE * yyget_lval (yyscan_t yyscanner ); -void yyset_lineno (int line_number ); +void yyset_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner ); /* Macros after this point can all be overridden by user definitions in * section 1. @@ -262,18 +278,18 @@ void yyset_lineno (int line_number ); #ifndef YY_SKIP_YYWRAP #ifdef __cplusplus -extern "C" int yywrap (void ); +extern "C" int yywrap (yyscan_t yyscanner ); #else -extern int yywrap (void ); +extern int yywrap (yyscan_t yyscanner ); #endif #endif #ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); +static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner); #endif #ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); +static int yy_flex_strlen (yyconst char * ,yyscan_t yyscanner); #endif #ifndef YY_NO_INPUT @@ -296,9 +312,11 @@ static int yy_flex_strlen (yyconst char * ); #ifndef YY_DECL #define YY_DECL_IS_OURS 1 -extern int yylex (void); +extern int yylex \ + (YYSTYPE * yylval_param ,yyscan_t yyscanner); -#define YY_DECL int yylex (void) +#define YY_DECL int yylex \ + (YYSTYPE * yylval_param , yyscan_t yyscanner) #endif /* !YY_DECL */ /* yy_get_previous_state - get the state just before the EOB char was reached */ @@ -315,9 +333,9 @@ extern int yylex (void); #undef YY_DECL #endif -#line 488 "/mnt/scm/legion/kbd/src/loadkeys.analyze.l" +#line 478 "/mnt/scm/legion/kbd/src/loadkeys.analyze.l" -#line 322 "/mnt/scm/legion/kbd/src/loadkeys.analyze.h" +#line 340 "/mnt/scm/legion/kbd/src/loadkeys.analyze.h" #undef yyIN_HEADER #endif /* yyHEADER_H */ diff --git a/src/loadkeys.analyze.l b/src/loadkeys.analyze.l index 7d66833..35016ea 100644 --- a/src/loadkeys.analyze.l +++ b/src/loadkeys.analyze.l @@ -1,91 +1,81 @@ -%option stack -%option noyy_top_state -%option noyywrap -%option nounput -%option noinput %{ -#define YY_NO_INPUT 1 - #include #include /* readlink */ -#include -#include -#include #include "ksyms.h" #include "nls.h" #include "kbd.h" #include "paths.h" #include "findfile.h" -#include "loadkeys.h" +#include "loadkeys.h" #include "loadkeys.keymap.h" +%} -extern struct keymap kmap; -extern int lkverbose(int level, const char *fmt, ...); - -int stack_push(lkfile_t *fp); - -/* Include file handling - unfortunately flex-specific. */ -#define MAX_INCLUDE_DEPTH 20 -static struct infile { - lkfile_t fp; - int linenr; - YY_BUFFER_STATE buffer; -} infile_stack[MAX_INCLUDE_DEPTH]; +%option reentrant +%option bison-bridge +%option stack +%option yylineno +%option never-interactive +%option noyywrap +%option nounput +%option noinput +%option noyy_top_state -static char *filename = NULL; -static int line_nr = 1; +%option extra-type="struct keymap *" -static char *p, *pmax; +%{ +extern int lkverbose(struct keymap *kmap, int level, const char *fmt, ...); -static int infile_stack_ptr = -1; -static int state_ptr = 0; +int stack_push(struct keymap *kmap, lkfile_t *fp, yyscan_t scanner); +int stack_pop(struct keymap *kmap, yyscan_t scanner); int -stack_push(lkfile_t *fp) +stack_push(struct keymap *kmap, lkfile_t *fp, yyscan_t scanner) { - if (infile_stack_ptr >= MAX_INCLUDE_DEPTH) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + int i = 0; + + while (kmap->stack[i]) i++; + + if (i == MAX_INCLUDE_DEPTH) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("includes are nested too deeply")); return -1; } - infile_stack_ptr++; - - infile_stack[infile_stack_ptr].buffer = yy_create_buffer(fp->fd, YY_BUF_SIZE); - infile_stack[infile_stack_ptr].linenr = line_nr; - - memcpy(&infile_stack[infile_stack_ptr].fp, fp, sizeof(fp)); - yy_switch_to_buffer(infile_stack[infile_stack_ptr].buffer); + kmap->stack[i] = malloc(sizeof(lkfile_t)); + if (kmap->stack[i] == NULL) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), + _("out of memory")); + return -1; + } - // Set global variables - filename = infile_stack[infile_stack_ptr].fp.pathname; - line_nr = 1; + kmap->stack[i]->fd = fp->fd; + kmap->stack[i]->pipe = fp->pipe; + strncpy(kmap->stack[i]->pathname, fp->pathname, sizeof(kmap->stack[i]->pathname) - 1); + kmap->stack[i]->pathname[sizeof(kmap->stack[i]->pathname)] = '\0'; + yypush_buffer_state(yy_create_buffer(fp->fd, YY_BUF_SIZE, scanner), scanner); return 0; } -static int -stack_pop(void) { - fpclose(&infile_stack[infile_stack_ptr].fp); - - // Destroy previous buffer - yy_delete_buffer(infile_stack[infile_stack_ptr].buffer); +int +stack_pop(struct keymap *kmap, yyscan_t scanner) +{ + int i = 0; - infile_stack_ptr--; + while (kmap->stack[i]) i++; + if (i == 0) + return 0; + i--; - if (infile_stack_ptr >= 0) { - // Set new state - filename = infile_stack[infile_stack_ptr].fp.pathname; - line_nr = infile_stack[infile_stack_ptr].linenr; + fpclose(kmap->stack[i]); - // Switch to new buffer - yy_switch_to_buffer(infile_stack[infile_stack_ptr].buffer); - return 0; - } + free(kmap->stack[i]); + kmap->stack[i] = NULL; - return 1; + yypop_buffer_state(scanner); + return 0; } /* @@ -126,7 +116,7 @@ static char *include_dirpath3[] = { static char *include_suffixes[] = { "", ".inc", 0 }; static int -find_incl_file_near_fn(char *s, char *fn, lkfile_t *fp) +find_incl_file_near_fn(struct keymap *kmap, char *s, char *fn, lkfile_t *fp) { char *t, *te, *t1, *t2; int len, rc = 1; @@ -161,17 +151,25 @@ find_incl_file_near_fn(char *s, char *fn, lkfile_t *fp) return rc; /* FIXME: free */ -nomem: snprintf(kmap.errmsg, sizeof(kmap.errmsg), _("out of memory")); +nomem: snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("out of memory")); return -1; } static int -find_standard_incl_file(char *s, lkfile_t *fp) +find_standard_incl_file(struct keymap *kmap, char *s, lkfile_t *fp) { + char *pathname; int rc = 1; + int i = 0; + + while (kmap->stack[i]) i++; + if (i == 0) + return -1; + i--; + pathname = kmap->stack[i]->pathname; if (findfile(s, include_dirpath1, include_suffixes, fp)) { - if ((rc = find_incl_file_near_fn(s, filename, fp)) == -1) + if ((rc = find_incl_file_near_fn(kmap, s, pathname, fp)) == -1) return rc; } @@ -180,20 +178,20 @@ find_standard_incl_file(char *s, lkfile_t *fp) char buf[MAXPATHLEN], path[MAXPATHLEN], *ptr; unsigned int n; - n = readlink(filename, buf, sizeof(buf)); + n = readlink(pathname, buf, sizeof(buf)); if (n > 0 && n < sizeof(buf)) { buf[n] = 0; if (buf[0] == '/') { - rc = find_incl_file_near_fn(s, buf, fp); + rc = find_incl_file_near_fn(kmap, s, buf, fp); - } else if (strlen(filename) + n < sizeof(path)) { - strcpy(path, filename); + } else if (strlen(pathname) + n < sizeof(path)) { + strcpy(path, pathname); path[sizeof(path) - 1] = 0; ptr = strrchr(path, '/'); if (ptr) ptr[1] = 0; strcat(path, buf); - rc = find_incl_file_near_fn(s, path, fp); + rc = find_incl_file_near_fn(kmap, s, path, fp); } } } @@ -204,7 +202,7 @@ find_standard_incl_file(char *s, lkfile_t *fp) } static int -find_incl_file(char *s, lkfile_t *fp) +find_incl_file(struct keymap *kmap, char *s, lkfile_t *fp) { char *ev; @@ -229,7 +227,7 @@ find_incl_file(char *s, lkfile_t *fp) if (*ev) rc = findfile(s, user_dir, include_suffixes, fp); else /* empty string denotes system path */ - rc = find_standard_incl_file(s, fp); + rc = find_standard_incl_file(kmap, s, fp); if (rc <= 0) return rc; @@ -239,20 +237,20 @@ find_incl_file(char *s, lkfile_t *fp) } return 1; } - return find_standard_incl_file(s, fp); + return find_standard_incl_file(kmap, s, fp); } static int -open_include(char *s) +open_include(struct keymap *kmap, char *s, yyscan_t scanner) { int rc; lkfile_t fp; - lkverbose(2, _("switching to %s"), s); + lkverbose(kmap, 2, _("switching to %s"), s); - rc = find_incl_file(s, &fp); + rc = find_incl_file(kmap, s, &fp); if (rc > 0) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("cannot open include file %s"), s); free(s); return -1; @@ -263,7 +261,7 @@ open_include(char *s) free(s); - return stack_push(&fp); + return stack_push(kmap, &fp, scanner); } %} @@ -304,82 +302,71 @@ Usual usual|Usual|USUAL For for|For|FOR On on|On|ON To to|To|TO + %% -%{ -/* To protect from wrong code in the higher level parser (loadkeys.y), - * make sure we do not return a sensible value if we - * do not intend to. (So wrong code would crash, or issue an error message. - * I mean the code like the one for PLAIN handling in past loadkeys.y. - * What to choose as the "bad" value: 0, -1?.. - * Well, make it equal to CODE_FOR_UNKNOWN_KSYM as the most efficient thing. - */ -#define YYLVAL_UNDEF CODE_FOR_UNKNOWN_KSYM -/* Every time yylex is called, initialize the associated - * yylval to YYLVAL_UNDEF. Then it might be overwritten by specific rules. */ - yylval = YYLVAL_UNDEF; -%} {Include} { - yy_push_state(INCLSTR); - state_ptr++; + yy_push_state(INCLSTR, yyscanner); + yyextra->state_ptr++; } \"[^\"\n]+\" { char *s = strndup(yytext+1, strlen(yytext)-2); if (s == NULL) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("out of memory")); return(ERROR); } - /* use static pathname to store *s ? */ - if (open_include(s) == -1) + if (open_include(yyextra, s, yyscanner) == -1) return(ERROR); - yy_pop_state(); - state_ptr--; + + yy_pop_state(yyscanner); + yyextra->state_ptr--; } [^"]|\"\"|\"[^"\n]*{Eol} { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("expected filename between quotes")); return(ERROR); } <> { - stack_pop(); + stack_pop(yyextra, yyscanner); if (!YY_CURRENT_BUFFER) yyterminate(); } {Continuation} { - line_nr++; + yyset_lineno(yyget_lineno(yyscanner) + 1, yyscanner); } {Eol} { - line_nr++; - if (state_ptr > 0) { - yy_pop_state(); - state_ptr--; + yyset_lineno(yyget_lineno(yyscanner) + 1, yyscanner); + + if (yyextra->state_ptr > 0) { + yy_pop_state(yyscanner); + yyextra->state_ptr--; } return(EOL); } {Blank}+ ; /* do nothing */ {Comment}.*/{Eol} ; /* do nothing */ {Equals} { - yy_push_state(RVALUE); - state_ptr++; - kmap.rvalct = 0; + yy_push_state(RVALUE, yyscanner); + yyextra->state_ptr++; + yyextra->rvalct = 0; return(EQUALS); } {String} { - yy_push_state(RVALUE); - state_ptr++; + yy_push_state(RVALUE, yyscanner); + yyextra->state_ptr++; return(STRING); } {To} { - yy_push_state(RVALUE); - state_ptr++; + yy_push_state(RVALUE, yyscanner); + yyextra->state_ptr++; return(TO); } {Unicode} { - yylval = strtol(yytext + 1, NULL, 16); - if (yylval >= 0xf000) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + yylval->num = strtol(yytext + 1, NULL, 16); + if (yylval->num >= 0xf000) { + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("unicode keysym out of range: %s"), yytext); return(ERROR); @@ -387,10 +374,10 @@ To to|To|TO return(UNUMBER); } {Decimal}|{Octal}|{Hex} { - yylval = strtol(yytext, NULL, 0); + yylval->num = strtol(yytext, NULL, 0); return(NUMBER); } -{Literal} { return((yylval = ksymtocode(kmap.prefer_unicode, yytext, TO_AUTO)) == -1 ? ERROR : LITERAL); } +{Literal} { return((yylval->num = ksymtocode(yyextra->prefer_unicode, yytext, TO_AUTO)) == -1 ? ERROR : LITERAL); } \- { return(DASH); } \, { return(COMMA); } \+ { return(PLUS); } @@ -415,73 +402,76 @@ To to|To|TO {On} { return(ON); } {For} { return(FOR); } '\\{Octa}' { - yylval = strtol(yytext + 2, NULL, 8); + yylval->num = strtol(yytext + 2, NULL, 8); return(CCHAR); } '\\.' { - yylval = (unsigned char) yytext[2]; + yylval->num = (unsigned char) yytext[2]; return(CCHAR); } '.' { - yylval = (unsigned char) yytext[1]; + yylval->num = (unsigned char) yytext[1]; return(CCHAR); } \" { - p = (char *) kmap.string; - pmax = p + sizeof(kmap.string) - 1; - yy_push_state(STR); - state_ptr++; + yylval->str.data[0] = '\0'; + yylval->str.len = 0; + + yy_push_state(STR, yyscanner); + yyextra->state_ptr++; } \\{Octa} { - if (p >= pmax) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (yylval->str.len == MAX_PARSER_STRING) { + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("string too long")); return(ERROR); } - *p++ = strtol(yytext + 1, NULL, 8); + yylval->str.data[yylval->str.len++] = strtol(yytext + 1, NULL, 8); } \\\" { - if (p >= pmax) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (yylval->str.len == MAX_PARSER_STRING) { + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("string too long")); return(ERROR); } - *p++ = '"'; + yylval->str.data[yylval->str.len++] = '"'; } \\\\ { - if (p >= pmax) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (yylval->str.len == MAX_PARSER_STRING) { + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("string too long")); return(ERROR); } - *p++ = '\\'; + yylval->str.data[yylval->str.len++] = '\\'; } \\n { - if (p >= pmax) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (yylval->str.len == MAX_PARSER_STRING) { + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("string too long")); return(ERROR); } - *p++ = '\n'; + yylval->str.data[yylval->str.len++] = '\n'; } [^\"\\]* { - char *ptmp = p; - p += strlen(yytext); - if (p > pmax) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + int len = strlen(yytext); + + if (yylval->str.len + len >= MAX_PARSER_STRING) { + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("string too long")); return(ERROR); } - strcpy(ptmp, yytext); + + strcpy((char *) yylval->str.data + yylval->str.len, yytext); + yylval->str.len += len; } \" { - *p = '\0'; - yy_pop_state(); - state_ptr--; + yylval->str.data[yylval->str.len] = '\0'; + yy_pop_state(yyscanner); + yyextra->state_ptr--; return(STRLITERAL); } . { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(yyextra->errmsg, sizeof(yyextra->errmsg), _("unknown characters")); return(ERROR); /* report any unknown characters */ } diff --git a/src/loadkeys.c b/src/loadkeys.c index 65d0a76..428a82f 100644 --- a/src/loadkeys.c +++ b/src/loadkeys.c @@ -51,7 +51,7 @@ #define YYSKELETON_NAME "yacc.c" /* Pure parsers. */ -#define YYPURE 0 +#define YYPURE 1 /* Push parsers. */ #define YYPUSH 0 @@ -67,7 +67,7 @@ /* Copy the first part of user declarations. */ /* Line 189 of yacc.c */ -#line 12 "loadkeys.y" +#line 6 "loadkeys.y" #define YY_HEADER_EXPORT_START_CONDITIONS 1 @@ -93,25 +93,163 @@ #include "nls.h" #include "version.h" -#include "loadkeys.analyze.h" - #ifdef COMPAT_HEADERS #include "compat/linux-keyboard.h" #endif +#include "loadkeys.h" +#include "loadkeys.analyze.h" + + +/* Line 189 of yacc.c */ +#line 106 "loadkeys.c" + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 1 +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE 0 +#endif + +/* "%code requires" blocks. */ + +/* Line 209 of yacc.c */ +#line 39 "loadkeys.y" + #include "loadkeys.keymap.h" -#define U(x) ((x) ^ 0xf000) -struct keymap kmap; -int yyerror(const char *s); -int lkverbose(int level, const char *fmt, ...); +/* Line 209 of yacc.c */ +#line 136 "loadkeys.c" + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + EOL = 258, + NUMBER = 259, + LITERAL = 260, + CHARSET = 261, + KEYMAPS = 262, + KEYCODE = 263, + EQUALS = 264, + PLAIN = 265, + SHIFT = 266, + CONTROL = 267, + ALT = 268, + ALTGR = 269, + SHIFTL = 270, + SHIFTR = 271, + CTRLL = 272, + CTRLR = 273, + CAPSSHIFT = 274, + COMMA = 275, + DASH = 276, + STRING = 277, + STRLITERAL = 278, + COMPOSE = 279, + TO = 280, + CCHAR = 281, + ERROR = 282, + PLUS = 283, + UNUMBER = 284, + ALT_IS_META = 285, + STRINGS = 286, + AS = 287, + USUAL = 288, + ON = 289, + FOR = 290 + }; +#endif +/* Tokens. */ +#define EOL 258 +#define NUMBER 259 +#define LITERAL 260 +#define CHARSET 261 +#define KEYMAPS 262 +#define KEYCODE 263 +#define EQUALS 264 +#define PLAIN 265 +#define SHIFT 266 +#define CONTROL 267 +#define ALT 268 +#define ALTGR 269 +#define SHIFTL 270 +#define SHIFTR 271 +#define CTRLL 272 +#define CTRLR 273 +#define CAPSSHIFT 274 +#define COMMA 275 +#define DASH 276 +#define STRING 277 +#define STRLITERAL 278 +#define COMPOSE 279 +#define TO 280 +#define CCHAR 281 +#define ERROR 282 +#define PLUS 283 +#define UNUMBER 284 +#define ALT_IS_META 285 +#define STRINGS 286 +#define AS 287 +#define USUAL 288 +#define ON 289 +#define FOR 290 + + + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ + +/* Line 214 of yacc.c */ +#line 62 "loadkeys.y" + + long long int num; + struct strdata str; + + + +/* Line 214 of yacc.c */ +#line 230 "loadkeys.c" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + + +/* Copy the second part of user declarations. */ + +/* Line 264 of yacc.c */ +#line 76 "loadkeys.y" + + +#define U(x) ((x) ^ 0xf000) + +int yyerror(yyscan_t scanner, struct keymap *kmap, const char *s); +int lkverbose(struct keymap *kmap, int level, const char *fmt, ...); int lkerror(const char *fmt, ...); int keymap_init(struct keymap *km); -extern int stack_push(lkfile_t *fp); +extern int stack_push(struct keymap *kmap, lkfile_t *fp, yyscan_t scanner); +extern int stack_pop(struct keymap *kmap, yyscan_t scanner); #include "ksyms.h" @@ -144,9 +282,9 @@ char *dirpath1[] = { "", DATADIR "/" KEYMAPDIR "/**", KERNDIR "/", 0 }; char *dirpath2[] = { 0, 0 }; char *suffixes[] = { "", ".kmap", ".map", 0 }; -int __attribute__ ((format (printf, 2, 3))) -lkverbose(int level, const char *fmt, ...) { - if (kmap.verbose < level) +int __attribute__ ((format (printf, 3, 4))) +lkverbose(struct keymap *kmap, int level, const char *fmt, ...) { + if (kmap->verbose < level) return 1; va_list ap; va_start(ap, fmt); @@ -182,9 +320,9 @@ keymap_init(struct keymap *km) return 0; } -int yyerror(const char *s) +int yyerror(yyscan_t scanner attr_unused, struct keymap *kmap, const char *s) { - if (strlen(kmap.errmsg) > 0) + if (strlen(kmap->errmsg) > 0) return 0; lkerror("%s\n", s); @@ -193,128 +331,128 @@ int yyerror(const char *s) static int -addmap(int i, int explicit) +addmap(struct keymap *kmap, int i, int explicit) { if (i < 0 || i >= MAX_NR_KEYMAPS) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("addmap called with bad index %d"), i); return -1; } - if (!kmap.defining[i]) { - if (kmap.keymaps_line_seen && !explicit) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (!kmap->defining[i]) { + if (kmap->keymaps_line_seen && !explicit) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("adding map %d violates explicit keymaps line"), i); return -1; } - kmap.defining[i] = 1; - if (kmap.max_keymap <= i) - kmap.max_keymap = i + 1; + kmap->defining[i] = 1; + if (kmap->max_keymap <= i) + kmap->max_keymap = i + 1; } return 0; } /* unset a key */ static int -killkey(int k_index, int k_table) +killkey(struct keymap *kmap, int k_index, int k_table) { /* roughly: addkey(k_index, k_table, K_HOLE); */ if (k_index < 0 || k_index >= NR_KEYS) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("killkey called with bad index %d"), k_index); return -1; } if (k_table < 0 || k_table >= MAX_NR_KEYMAPS) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("killkey called with bad table %d"), k_table); return -1; } - if (kmap.key_map[k_table]) - (kmap.key_map[k_table])[k_index] = K_HOLE; + if (kmap->key_map[k_table]) + (kmap->key_map[k_table])[k_index] = K_HOLE; - if (kmap.keymap_was_set[k_table]) - (kmap.keymap_was_set[k_table])[k_index] = 0; + if (kmap->keymap_was_set[k_table]) + (kmap->keymap_was_set[k_table])[k_index] = 0; return 0; } static int -addkey(int k_index, int k_table, int keycode) +addkey(struct keymap *kmap, int k_index, int k_table, int keycode) { int i; if (keycode == CODE_FOR_UNKNOWN_KSYM) { /* is safer not to be silent in this case, * it can be caused by coding errors as well. */ - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("addkey called with bad keycode %d"), keycode); return -1; } if (k_index < 0 || k_index >= NR_KEYS) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("addkey called with bad index %d"), k_index); return -1; } if (k_table < 0 || k_table >= MAX_NR_KEYMAPS) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("addkey called with bad table %d"), k_table); return -1; } - if (!kmap.defining[k_table]) { - if (addmap(k_table, 0) == -1) + if (!kmap->defining[k_table]) { + if (addmap(kmap, k_table, 0) == -1) return -1; } - if (!kmap.key_map[k_table]) { - kmap.key_map[k_table] = (u_short *)malloc(NR_KEYS * sizeof(u_short)); + if (!kmap->key_map[k_table]) { + kmap->key_map[k_table] = (u_short *)malloc(NR_KEYS * sizeof(u_short)); - if (kmap.key_map[k_table] == NULL) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (kmap->key_map[k_table] == NULL) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("out of memory")); return -1; } for (i = 0; i < NR_KEYS; i++) - (kmap.key_map[k_table])[i] = K_HOLE; + (kmap->key_map[k_table])[i] = K_HOLE; } - if (!kmap.keymap_was_set[k_table]) { - kmap.keymap_was_set[k_table] = (char *)malloc(NR_KEYS); + if (!kmap->keymap_was_set[k_table]) { + kmap->keymap_was_set[k_table] = (char *)malloc(NR_KEYS); - if (kmap.key_map[k_table] == NULL) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (kmap->key_map[k_table] == NULL) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("out of memory")); return -1; } for (i = 0; i < NR_KEYS; i++) - (kmap.keymap_was_set[k_table])[i] = 0; + (kmap->keymap_was_set[k_table])[i] = 0; } - if (kmap.alt_is_meta && keycode == K_HOLE - && (kmap.keymap_was_set[k_table])[k_index]) + if (kmap->alt_is_meta && keycode == K_HOLE + && (kmap->keymap_was_set[k_table])[k_index]) return 0; - (kmap.key_map[k_table])[k_index] = keycode; - (kmap.keymap_was_set[k_table])[k_index] = 1; + (kmap->key_map[k_table])[k_index] = keycode; + (kmap->keymap_was_set[k_table])[k_index] = 1; - if (kmap.alt_is_meta) { + if (kmap->alt_is_meta) { int alttable = k_table | M_ALT; int type = KTYP(keycode); int val = KVAL(keycode); - if (alttable != k_table && kmap.defining[alttable] && - (!kmap.keymap_was_set[alttable] || - !(kmap.keymap_was_set[alttable])[k_index]) && + if (alttable != k_table && kmap->defining[alttable] && + (!kmap->keymap_was_set[alttable] || + !(kmap->keymap_was_set[alttable])[k_index]) && (type == KT_LATIN || type == KT_LETTER) && val < 128) { - if (addkey(k_index, alttable, K(KT_META, val)) == -1) + if (addkey(kmap, k_index, alttable, K(KT_META, val)) == -1) return -1; } } @@ -322,27 +460,27 @@ addkey(int k_index, int k_table, int keycode) } static int -addfunc(struct kbsentry kbs) +addfunc(struct keymap *kmap, struct kbsentry kbs) { int x; x = kbs.kb_func; if (x >= MAX_NR_FUNC) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("addfunc called with bad func %d"), kbs.kb_func); return -1; } - if(kmap.func_table[x]) { - free(kmap.func_table[x]); - kmap.func_table[x] = NULL; + if(kmap->func_table[x]) { + free(kmap->func_table[x]); + kmap->func_table[x] = NULL; } - kmap.func_table[x] = strdup((char *)kbs.kb_string); + kmap->func_table[x] = strdup((char *)kbs.kb_string); - if (!kmap.func_table[x]) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (!kmap->func_table[x]) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("addfunc: out of memory")); return -1; } @@ -351,39 +489,39 @@ addfunc(struct kbsentry kbs) } static int -compose(int diacr, int base, int res) +compose(struct keymap *kmap, int diacr, int base, int res) { accent_entry *ptr; int direction; #ifdef KDSKBDIACRUC - if (kmap.prefer_unicode) + if (kmap->prefer_unicode) direction = TO_UNICODE; else #endif direction = TO_8BIT; - if (kmap.accent_table_size == MAX_DIACR) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (kmap->accent_table_size == MAX_DIACR) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("compose table overflow")); return -1; } - ptr = &(kmap.accent_table[kmap.accent_table_size++]); - ptr->diacr = convert_code(kmap.prefer_unicode, diacr, direction); - ptr->base = convert_code(kmap.prefer_unicode, base, direction); - ptr->result = convert_code(kmap.prefer_unicode, res, direction); + ptr = &(kmap->accent_table[kmap->accent_table_size++]); + ptr->diacr = convert_code(kmap->prefer_unicode, diacr, direction); + ptr->base = convert_code(kmap->prefer_unicode, base, direction); + ptr->result = convert_code(kmap->prefer_unicode, res, direction); return 0; } -static int defkeys(int fd, int kbd_mode) +static int defkeys(struct keymap *kmap, int fd, int kbd_mode) { struct kbentry ke; int ct = 0; int i, j, fail; - if (kmap.flags & LKFLAG_UNICODE_MODE) { + if (kmap->flags & LKFLAG_UNICODE_MODE) { /* temporarily switch to K_UNICODE while defining keys */ if (ioctl(fd, KDSKBMODE, K_UNICODE)) { lkerror(_("KDSKBMODE: %s: could not switch to Unicode mode"), @@ -393,14 +531,14 @@ static int defkeys(int fd, int kbd_mode) } for (i = 0; i < MAX_NR_KEYMAPS; i++) { - if (kmap.key_map[i]) { + if (kmap->key_map[i]) { for (j = 0; j < NR_KEYS; j++) { - if (!((kmap.keymap_was_set[i])[j])) + if (!((kmap->keymap_was_set[i])[j])) continue; ke.kb_index = j; ke.kb_table = i; - ke.kb_value = (kmap.key_map[i])[j]; + ke.kb_value = (kmap->key_map[i])[j]; fail = ioctl(fd, KDSKBENT, (unsigned long)&ke); @@ -415,21 +553,21 @@ static int defkeys(int fd, int kbd_mode) } else ct++; - lkverbose(2, _("keycode %d, table %d = %d%s"), - j, i, (kmap.key_map[i])[j], fail ? _(" FAILED") : ""); + lkverbose(kmap, 2, _("keycode %d, table %d = %d%s"), + j, i, (kmap->key_map[i])[j], fail ? _(" FAILED") : ""); - if (fail && kmap.verbose > 1) + if (fail && kmap->verbose > 1) lkerror(_("failed to bind key %d to value %d"), - j, (kmap.key_map[i])[j]); + j, (kmap->key_map[i])[j]); } - } else if (kmap.keymaps_line_seen && !kmap.defining[i]) { + } else if (kmap->keymaps_line_seen && !kmap->defining[i]) { /* deallocate keymap */ ke.kb_index = 0; ke.kb_table = i; ke.kb_value = K_NOSUCHMAP; - lkverbose(3, _("deallocate keymap %d"), i); + lkverbose(kmap, 3, _("deallocate keymap %d"), i); if (ioctl(fd, KDSKBENT, (unsigned long)&ke)) { if (errno != EINVAL) { @@ -457,7 +595,7 @@ static int defkeys(int fd, int kbd_mode) } } - if ((kmap.flags & LKFLAG_UNICODE_MODE) && ioctl(fd, KDSKBMODE, kbd_mode)) { + if ((kmap->flags & LKFLAG_UNICODE_MODE) && ioctl(fd, KDSKBMODE, kbd_mode)) { lkerror(_("KDSKBMODE: %s: could not return to original keyboard mode"), strerror(errno)); goto fail; @@ -468,14 +606,14 @@ static int defkeys(int fd, int kbd_mode) fail: return -1; } -static void freekeys(void) +static void freekeys(struct keymap *kmap) { int i; for (i = 0; i < MAX_NR_KEYMAPS; i++) { - if (kmap.keymap_was_set[i] != NULL) - free(kmap.keymap_was_set[i]); - if (kmap.key_map[i] != NULL) - free(kmap.key_map[i]); + if (kmap->keymap_was_set[i] != NULL) + free(kmap->keymap_was_set[i]); + if (kmap->key_map[i] != NULL) + free(kmap->key_map[i]); } } @@ -513,7 +651,7 @@ ostr(char *s) } static int -deffuncs(int fd) +deffuncs(struct keymap *kmap, int fd) { int i, ct = 0; char *ptr, *s; @@ -522,7 +660,7 @@ deffuncs(int fd) for (i = 0; i < MAX_NR_FUNC; i++) { kbs.kb_func = i; - if ((ptr = kmap.func_table[i])) { + if ((ptr = kmap->func_table[i])) { strcpy((char *)kbs.kb_string, ptr); if (ioctl(fd, KDSKBSENT, (unsigned long)&kbs)) { s = ostr((char *)kbs.kb_string); @@ -534,7 +672,7 @@ deffuncs(int fd) } else { ct++; } - } else if (kmap.flags & LKFLAG_CLEAR_STRINGS) { + } else if (kmap->flags & LKFLAG_CLEAR_STRINGS) { kbs.kb_string[0] = 0; if (ioctl(fd, KDSKBSENT, (unsigned long)&kbs)) { @@ -549,7 +687,7 @@ deffuncs(int fd) } static int -defdiacs(int fd) +defdiacs(struct keymap *kmap, int fd) { unsigned int i, count; struct kbdiacrs kd; @@ -557,19 +695,19 @@ defdiacs(int fd) struct kbdiacrsuc kdu; #endif - count = kmap.accent_table_size; + count = kmap->accent_table_size; if (count > MAX_DIACR) { count = MAX_DIACR; lkerror(_("too many compose definitions")); } #ifdef KDSKBDIACRUC - if (kmap.prefer_unicode) { + if (kmap->prefer_unicode) { kdu.kb_cnt = count; for (i = 0; i < kdu.kb_cnt; i++) { - kdu.kbdiacruc[i].diacr = kmap.accent_table[i].diacr; - kdu.kbdiacruc[i].base = kmap.accent_table[i].base; - kdu.kbdiacruc[i].result = kmap.accent_table[i].result; + kdu.kbdiacruc[i].diacr = kmap->accent_table[i].diacr; + kdu.kbdiacruc[i].base = kmap->accent_table[i].base; + kdu.kbdiacruc[i].result = kmap->accent_table[i].result; } if (ioctl(fd, KDSKBDIACRUC, (unsigned long)&kdu)) @@ -579,9 +717,9 @@ defdiacs(int fd) { kd.kb_cnt = count; for (i = 0; i < kd.kb_cnt; i++) { - kd.kbdiacr[i].diacr = kmap.accent_table[i].diacr; - kd.kbdiacr[i].base = kmap.accent_table[i].base; - kd.kbdiacr[i].result = kmap.accent_table[i].result; + kd.kbdiacr[i].diacr = kmap->accent_table[i].diacr; + kd.kbdiacr[i].base = kmap->accent_table[i].base; + kd.kbdiacr[i].result = kmap->accent_table[i].result; } if (ioctl(fd, KDSKBDIACR, (unsigned long)&kd)) @@ -600,7 +738,7 @@ defdiacs(int fd) } static int -do_constant_key(int i, u_short key) +do_constant_key(struct keymap *kmap, int i, u_short key) { int typ, val, j; @@ -621,25 +759,25 @@ do_constant_key(int i, u_short key) for (j = 8; j < 16; j++) defs[j] = K(KT_META, KVAL(defs[j - 8])); - for (j = 0; j < kmap.max_keymap; j++) { - if (!kmap.defining[j]) + for (j = 0; j < kmap->max_keymap; j++) { + if (!kmap->defining[j]) continue; if (j > 0 && - kmap.keymap_was_set[j] && (kmap.keymap_was_set[j])[i]) + kmap->keymap_was_set[j] && (kmap->keymap_was_set[j])[i]) continue; - if (addkey(i, j, defs[j % 16]) == -1) + if (addkey(kmap, i, j, defs[j % 16]) == -1) return -1; } } else { /* do this also for keys like Escape, as promised in the man page */ - for (j = 1; j < kmap.max_keymap; j++) { - if (kmap.defining[j] && - (!(kmap.keymap_was_set[j]) || !(kmap.keymap_was_set[j])[i])) { - if (addkey(i, j, key) == -1) + for (j = 1; j < kmap->max_keymap; j++) { + if (kmap->defining[j] && + (!(kmap->keymap_was_set[j]) || !(kmap->keymap_was_set[j])[i])) { + if (addkey(kmap, i, j, key) == -1) return -1; } } @@ -648,66 +786,66 @@ do_constant_key(int i, u_short key) } static int -do_constant(void) +do_constant(struct keymap *kmap) { int i, r0 = 0; - if (kmap.keymaps_line_seen) { - while (r0 < kmap.max_keymap && !kmap.defining[r0]) + if (kmap->keymaps_line_seen) { + while (r0 < kmap->max_keymap && !kmap->defining[r0]) r0++; } for (i = 0; i < NR_KEYS; i++) { - if (kmap.key_is_constant[i]) { + if (kmap->key_is_constant[i]) { u_short key; - if (!kmap.key_map[r0]) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (!kmap->key_map[r0]) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("impossible error in do_constant")); goto fail; } - key = (kmap.key_map[r0])[i]; - if (do_constant_key(i, key) == -1) + key = (kmap->key_map[r0])[i]; + if (do_constant_key(kmap, i, key) == -1) goto fail; } } return 0; - fail: lkerror("%s", kmap.errmsg); + fail: lkerror("%s", kmap->errmsg); return -1; } static int -loadkeys(int fd, int kbd_mode) +loadkeys(struct keymap *kmap, int fd, int kbd_mode) { int keyct, funcct, diacct; - if ((keyct = defkeys(fd, kbd_mode)) < 0 || (funcct = deffuncs(fd)) < 0) + if ((keyct = defkeys(kmap, fd, kbd_mode)) < 0 || (funcct = deffuncs(kmap, fd)) < 0) return -1; - lkverbose(2, _("\nChanged %d %s and %d %s"), + lkverbose(kmap, 2, _("\nChanged %d %s and %d %s"), keyct, (keyct == 1) ? _("key") : _("keys"), funcct, (funcct == 1) ? _("string") : _("strings")); - if (kmap.accent_table_size > 0 || kmap.flags & LKFLAG_CLEAR_COMPOSE) { - diacct = defdiacs(fd); + if (kmap->accent_table_size > 0 || kmap->flags & LKFLAG_CLEAR_COMPOSE) { + diacct = defdiacs(kmap, fd); if (diacct < 0) return -1; - lkverbose(2, _("Loaded %d compose %s"), + lkverbose(kmap, 2, _("Loaded %d compose %s"), diacct, (diacct == 1) ? _("definition") : _("definitions")); } else { - lkverbose(2, _("(No change in compose definitions)")); + lkverbose(kmap, 2, _("(No change in compose definitions)")); } return 0; } static int -strings_as_usual(void) +strings_as_usual(struct keymap *kmap) { /* * 26 strings, mostly inspired by the VT100 family @@ -734,7 +872,7 @@ strings_as_usual(void) sizeof(ke.kb_string)); ke.kb_string[sizeof(ke.kb_string) - 1] = 0; - if (addfunc(ke) == -1) + if (addfunc(kmap, ke) == -1) return -1; } } @@ -742,10 +880,10 @@ strings_as_usual(void) } static int -compose_as_usual(char *charset) +compose_as_usual(struct keymap *kmap, char *charset) { if (charset && strcmp(charset, "iso-8859-1")) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("loadkeys: don't know how to compose for %s"), charset); return -1; @@ -792,7 +930,7 @@ compose_as_usual(char *charset) int i; for (i = 0; i < 68; i++) { struct ccc ptr = def_latin1_composes[i]; - if (compose(ptr.c1, ptr.c2, ptr.c3) == -1) + if (compose(kmap, ptr.c1, ptr.c2, ptr.c3) == -1) return -1; } } @@ -834,7 +972,7 @@ outchar(FILE *fd, unsigned char c, int comma) } static int -mktable(FILE *fd) +mktable(struct keymap *kmap, FILE *fd) { int j; unsigned int i, imax; @@ -854,7 +992,7 @@ mktable(FILE *fd) fprintf(fd, "#include \n\n"); for (i = 0; i < MAX_NR_KEYMAPS; i++) - if (kmap.key_map[i]) { + if (kmap->key_map[i]) { keymap_count++; if (i) fprintf(fd, "static "); @@ -862,18 +1000,18 @@ mktable(FILE *fd) for (j = 0; j < NR_KEYS; j++) { if (!(j % 8)) fprintf(fd, "\n"); - fprintf(fd, "\t0x%04x,", U((kmap.key_map[i])[j])); + fprintf(fd, "\t0x%04x,", U((kmap->key_map[i])[j])); } fprintf(fd, "\n};\n\n"); } for (imax = MAX_NR_KEYMAPS - 1; imax > 0; imax--) - if (kmap.key_map[imax]) + if (kmap->key_map[imax]) break; fprintf(fd, "ushort *key_maps[MAX_NR_KEYMAPS] = {"); for (i = 0; i <= imax; i++) { fprintf(fd, (i % 4) ? " " : "\n\t"); - if (kmap.key_map[i]) + if (kmap->key_map[i]) fprintf(fd, "%s_map,", mk_mapname(i)); else fprintf(fd, "0,"); @@ -890,19 +1028,19 @@ mktable(FILE *fd) " * the default and allocate dynamically in chunks of 512 bytes.\n" " */\n" "\n"); for (maxfunc = MAX_NR_FUNC; maxfunc; maxfunc--) - if (kmap.func_table[maxfunc - 1]) + if (kmap->func_table[maxfunc - 1]) break; fprintf(fd, "char func_buf[] = {\n"); for (i = 0; i < maxfunc; i++) { - ptr = kmap.func_table[i]; + ptr = kmap->func_table[i]; if (ptr) { func_table_offs[i] = func_buf_offset; fprintf(fd, "\t"); for (; *ptr; ptr++) outchar(fd, *ptr, 1); fprintf(fd, "0, \n"); - func_buf_offset += (ptr - kmap.func_table[i] + 1); + func_buf_offset += (ptr - kmap->func_table[i] + 1); } } if (!maxfunc) @@ -916,7 +1054,7 @@ mktable(FILE *fd) fprintf(fd, "char *func_table[MAX_NR_FUNC] = {\n"); for (i = 0; i < maxfunc; i++) { - if (kmap.func_table[i]) + if (kmap->func_table[i]) fprintf(fd, "\tfunc_buf + %u,\n", func_table_offs[i]); else fprintf(fd, "\t0,\n"); @@ -926,13 +1064,13 @@ mktable(FILE *fd) fprintf(fd, "};\n"); #ifdef KDSKBDIACRUC - if (kmap.prefer_unicode) { + if (kmap->prefer_unicode) { fprintf(fd, "\nstruct kbdiacruc accent_table[MAX_DIACR] = {\n"); - for (i = 0; i < kmap.accent_table_size; i++) { + for (i = 0; i < kmap->accent_table_size; i++) { fprintf(fd, "\t{"); - outchar(fd, kmap.accent_table[i].diacr, 1); - outchar(fd, kmap.accent_table[i].base, 1); - fprintf(fd, "0x%04x},", kmap.accent_table[i].result); + outchar(fd, kmap->accent_table[i].diacr, 1); + outchar(fd, kmap->accent_table[i].base, 1); + fprintf(fd, "0x%04x},", kmap->accent_table[i].result); if (i % 2) fprintf(fd, "\n"); } @@ -943,11 +1081,11 @@ mktable(FILE *fd) #endif { fprintf(fd, "\nstruct kbdiacr accent_table[MAX_DIACR] = {\n"); - for (i = 0; i < kmap.accent_table_size; i++) { + for (i = 0; i < kmap->accent_table_size; i++) { fprintf(fd, "\t{"); - outchar(fd, kmap.accent_table[i].diacr, 1); - outchar(fd, kmap.accent_table[i].base, 1); - outchar(fd, kmap.accent_table[i].result, 0); + outchar(fd, kmap->accent_table[i].diacr, 1); + outchar(fd, kmap->accent_table[i].base, 1); + outchar(fd, kmap->accent_table[i].result, 0); fprintf(fd, "},"); if (i % 2) fprintf(fd, "\n"); @@ -956,12 +1094,12 @@ mktable(FILE *fd) fprintf(fd, "\n"); fprintf(fd, "};\n\n"); } - fprintf(fd, "unsigned int accent_table_size = %d;\n", kmap.accent_table_size); + fprintf(fd, "unsigned int accent_table_size = %d;\n", kmap->accent_table_size); return 0; } static int -bkeymap(void) +bkeymap(struct keymap *kmap) { int i, j; @@ -972,14 +1110,14 @@ bkeymap(void) if (write(1, magic, 7) == -1) goto fail; for (i = 0; i < MAX_NR_KEYMAPS; i++) { - flag = kmap.key_map[i] ? 1 : 0; + flag = kmap->key_map[i] ? 1 : 0; if (write(1, &flag, 1) == -1) goto fail; } for (i = 0; i < MAX_NR_KEYMAPS; i++) { - if (kmap.key_map[i]) { + if (kmap->key_map[i]) { for (j = 0; j < NR_KEYS / 2; j++) { - v = kmap.key_map[i][j]; + v = kmap->key_map[i][j]; if (write(1, &v, 2) == -1) goto fail; } @@ -993,120 +1131,8 @@ bkeymap(void) -/* Line 189 of yacc.c */ -#line 998 "loadkeys.c" - -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif - -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 -#endif - -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE 0 -#endif - - -/* Tokens. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - EOL = 258, - NUMBER = 259, - LITERAL = 260, - CHARSET = 261, - KEYMAPS = 262, - KEYCODE = 263, - EQUALS = 264, - PLAIN = 265, - SHIFT = 266, - CONTROL = 267, - ALT = 268, - ALTGR = 269, - SHIFTL = 270, - SHIFTR = 271, - CTRLL = 272, - CTRLR = 273, - CAPSSHIFT = 274, - COMMA = 275, - DASH = 276, - STRING = 277, - STRLITERAL = 278, - COMPOSE = 279, - TO = 280, - CCHAR = 281, - ERROR = 282, - PLUS = 283, - UNUMBER = 284, - ALT_IS_META = 285, - STRINGS = 286, - AS = 287, - USUAL = 288, - ON = 289, - FOR = 290 - }; -#endif -/* Tokens. */ -#define EOL 258 -#define NUMBER 259 -#define LITERAL 260 -#define CHARSET 261 -#define KEYMAPS 262 -#define KEYCODE 263 -#define EQUALS 264 -#define PLAIN 265 -#define SHIFT 266 -#define CONTROL 267 -#define ALT 268 -#define ALTGR 269 -#define SHIFTL 270 -#define SHIFTR 271 -#define CTRLL 272 -#define CTRLR 273 -#define CAPSSHIFT 274 -#define COMMA 275 -#define DASH 276 -#define STRING 277 -#define STRLITERAL 278 -#define COMPOSE 279 -#define TO 280 -#define CCHAR 281 -#define ERROR 282 -#define PLUS 283 -#define UNUMBER 284 -#define ALT_IS_META 285 -#define STRINGS 286 -#define AS 287 -#define USUAL 288 -#define ON 289 -#define FOR 290 - - - - -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef int YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ -# define YYSTYPE_IS_DECLARED 1 -#endif - - -/* Copy the second part of user declarations. */ - - /* Line 264 of yacc.c */ -#line 1110 "loadkeys.c" +#line 1136 "loadkeys.c" #ifdef short # undef short @@ -1411,12 +1437,12 @@ static const yytype_int8 yyrhs[] = /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint16 yyrline[] = { - 0, 938, 938, 939, 941, 942, 943, 944, 945, 946, - 947, 948, 949, 950, 952, 964, 969, 975, 980, 986, - 991, 992, 994, 1002, 1008, 1028, 1033, 1039, 1040, 1042, - 1042, 1050, 1056, 1057, 1059, 1060, 1061, 1062, 1063, 1064, - 1065, 1066, 1067, 1069, 1124, 1125, 1127, 1137, 1138, 1139, - 1140, 1141, 1142 + 0, 970, 970, 971, 973, 974, 975, 976, 977, 978, + 979, 980, 981, 982, 984, 996, 1001, 1007, 1012, 1018, + 1023, 1024, 1026, 1034, 1040, 1061, 1066, 1072, 1073, 1075, + 1075, 1083, 1089, 1090, 1092, 1093, 1094, 1095, 1096, 1097, + 1098, 1099, 1100, 1102, 1157, 1158, 1160, 1170, 1171, 1172, + 1173, 1174, 1175 }; #endif @@ -1607,7 +1633,7 @@ do \ } \ else \ { \ - yyerror (YY_("syntax error: cannot back up")); \ + yyerror (scanner, kmap, YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (YYID (0)) @@ -1662,9 +1688,9 @@ while (YYID (0)) /* YYLEX -- calling `yylex' with the right arguments. */ #ifdef YYLEX_PARAM -# define YYLEX yylex (YYLEX_PARAM) +# define YYLEX yylex (&yylval, YYLEX_PARAM) #else -# define YYLEX yylex () +# define YYLEX yylex (&yylval, scanner) #endif /* Enable debugging if requested. */ @@ -1687,7 +1713,7 @@ do { \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value); \ + Type, Value, scanner, kmap); \ YYFPRINTF (stderr, "\n"); \ } \ } while (YYID (0)) @@ -1701,17 +1727,21 @@ do { \ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, yyscan_t scanner, struct keymap *kmap) #else static void -yy_symbol_value_print (yyoutput, yytype, yyvaluep) +yy_symbol_value_print (yyoutput, yytype, yyvaluep, scanner, kmap) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; + yyscan_t scanner; + struct keymap *kmap; #endif { if (!yyvaluep) return; + YYUSE (scanner); + YYUSE (kmap); # ifdef YYPRINT if (yytype < YYNTOKENS) YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); @@ -1733,13 +1763,15 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, yyscan_t scanner, struct keymap *kmap) #else static void -yy_symbol_print (yyoutput, yytype, yyvaluep) +yy_symbol_print (yyoutput, yytype, yyvaluep, scanner, kmap) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; + yyscan_t scanner; + struct keymap *kmap; #endif { if (yytype < YYNTOKENS) @@ -1747,7 +1779,7 @@ yy_symbol_print (yyoutput, yytype, yyvaluep) else YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); - yy_symbol_value_print (yyoutput, yytype, yyvaluep); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, scanner, kmap); YYFPRINTF (yyoutput, ")"); } @@ -1790,12 +1822,14 @@ do { \ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yy_reduce_print (YYSTYPE *yyvsp, int yyrule) +yy_reduce_print (YYSTYPE *yyvsp, int yyrule, yyscan_t scanner, struct keymap *kmap) #else static void -yy_reduce_print (yyvsp, yyrule) +yy_reduce_print (yyvsp, yyrule, scanner, kmap) YYSTYPE *yyvsp; int yyrule; + yyscan_t scanner; + struct keymap *kmap; #endif { int yynrhs = yyr2[yyrule]; @@ -1809,7 +1843,7 @@ yy_reduce_print (yyvsp, yyrule) YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], &(yyvsp[(yyi + 1) - (yynrhs)]) - ); + , scanner, kmap); YYFPRINTF (stderr, "\n"); } } @@ -1817,7 +1851,7 @@ yy_reduce_print (yyvsp, yyrule) # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ - yy_reduce_print (yyvsp, Rule); \ + yy_reduce_print (yyvsp, Rule, scanner, kmap); \ } while (YYID (0)) /* Nonzero means print parse trace. It is left uninitialized so that @@ -2068,16 +2102,20 @@ yysyntax_error (char *yyresult, int yystate, int yychar) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, yyscan_t scanner, struct keymap *kmap) #else static void -yydestruct (yymsg, yytype, yyvaluep) +yydestruct (yymsg, yytype, yyvaluep, scanner, kmap) const char *yymsg; int yytype; YYSTYPE *yyvaluep; + yyscan_t scanner; + struct keymap *kmap; #endif { YYUSE (yyvaluep); + YYUSE (scanner); + YYUSE (kmap); if (!yymsg) yymsg = "Deleting"; @@ -2100,21 +2138,13 @@ int yyparse (); #endif #else /* ! YYPARSE_PARAM */ #if defined __STDC__ || defined __cplusplus -int yyparse (void); +int yyparse (yyscan_t scanner, struct keymap *kmap); #else int yyparse (); #endif #endif /* ! YYPARSE_PARAM */ -/* The lookahead symbol. */ -int yychar; - -/* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; - -/* Number of syntax errors so far. */ -int yynerrs; @@ -2136,15 +2166,23 @@ yyparse (YYPARSE_PARAM) #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) int -yyparse (void) +yyparse (yyscan_t scanner, struct keymap *kmap) #else int -yyparse () - +yyparse (scanner, kmap) + yyscan_t scanner; + struct keymap *kmap; #endif #endif { +/* The lookahead symbol. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; + /* Number of syntax errors so far. */ + int yynerrs; int yystate; /* Number of tokens to shift before error messages enabled. */ @@ -2388,34 +2426,34 @@ yyreduce: case 14: /* Line 1464 of yacc.c */ -#line 953 "loadkeys.y" +#line 985 "loadkeys.y" { - if (set_charset((char *) kmap.string)) + if (set_charset((char *) (yyvsp[(2) - (3)].str).data)) YYERROR; /* Unicode: The first 256 code points were made identical to the content of ISO 8859-1 */ - if (kmap.prefer_unicode && - !strcasecmp((char *) kmap.string, "iso-8859-1")) - kmap.prefer_unicode = 0; + if (kmap->prefer_unicode && + !strcasecmp((char *) (yyvsp[(2) - (3)].str).data, "iso-8859-1")) + kmap->prefer_unicode = 0; } break; case 15: /* Line 1464 of yacc.c */ -#line 965 "loadkeys.y" +#line 997 "loadkeys.y" { - kmap.alt_is_meta = 1; + kmap->alt_is_meta = 1; } break; case 16: /* Line 1464 of yacc.c */ -#line 970 "loadkeys.y" +#line 1002 "loadkeys.y" { - if (strings_as_usual() == -1) + if (strings_as_usual(kmap) == -1) YYERROR; } break; @@ -2423,9 +2461,9 @@ yyreduce: case 17: /* Line 1464 of yacc.c */ -#line 976 "loadkeys.y" +#line 1008 "loadkeys.y" { - if (compose_as_usual((char *) kmap.string) == -1) + if (compose_as_usual(kmap, (char *) (yyvsp[(5) - (6)].str).data) == -1) YYERROR; } break; @@ -2433,9 +2471,9 @@ yyreduce: case 18: /* Line 1464 of yacc.c */ -#line 981 "loadkeys.y" +#line 1013 "loadkeys.y" { - if (compose_as_usual(0) == -1) + if (compose_as_usual(kmap, 0) == -1) YYERROR; } break; @@ -2443,20 +2481,20 @@ yyreduce: case 19: /* Line 1464 of yacc.c */ -#line 987 "loadkeys.y" +#line 1019 "loadkeys.y" { - kmap.keymaps_line_seen = 1; + kmap->keymaps_line_seen = 1; } break; case 22: /* Line 1464 of yacc.c */ -#line 995 "loadkeys.y" +#line 1027 "loadkeys.y" { int i; - for (i = (yyvsp[(1) - (3)]); i <= (yyvsp[(3) - (3)]); i++) { - if (addmap(i,1) == -1) + for (i = (yyvsp[(1) - (3)].num); i <= (yyvsp[(3) - (3)].num); i++) { + if (addmap(kmap, i, 1) == -1) YYERROR; } } @@ -2465,9 +2503,9 @@ yyreduce: case 23: /* Line 1464 of yacc.c */ -#line 1003 "loadkeys.y" +#line 1035 "loadkeys.y" { - if (addmap((yyvsp[(1) - (1)]),1) == -1) + if (addmap(kmap, (yyvsp[(1) - (1)].num), 1) == -1) YYERROR; } break; @@ -2475,23 +2513,24 @@ yyreduce: case 24: /* Line 1464 of yacc.c */ -#line 1009 "loadkeys.y" +#line 1041 "loadkeys.y" { struct kbsentry ke; - if (KTYP((yyvsp[(2) - (5)])) != KT_FN) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (KTYP((yyvsp[(2) - (5)].num)) != KT_FN) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("'%s' is not a function key symbol"), - syms[KTYP((yyvsp[(2) - (5)]))].table[KVAL((yyvsp[(2) - (5)]))]); + syms[KTYP((yyvsp[(2) - (5)].num))].table[KVAL((yyvsp[(2) - (5)].num))]); YYERROR; } - ke.kb_func = KVAL((yyvsp[(2) - (5)])); + + ke.kb_func = KVAL((yyvsp[(2) - (5)].num)); strncpy((char *) ke.kb_string, - (char *) kmap.string, + (char *) (yyvsp[(4) - (5)].str).data, sizeof(ke.kb_string)); ke.kb_string[sizeof(ke.kb_string) - 1] = 0; - if (addfunc(ke) == -1) + if (addfunc(kmap, ke) == -1) YYERROR; } break; @@ -2499,9 +2538,9 @@ yyreduce: case 25: /* Line 1464 of yacc.c */ -#line 1029 "loadkeys.y" +#line 1062 "loadkeys.y" { - if (compose((yyvsp[(2) - (6)]), (yyvsp[(3) - (6)]), (yyvsp[(5) - (6)])) == -1) + if (compose(kmap, (yyvsp[(2) - (6)].num), (yyvsp[(3) - (6)].num), (yyvsp[(5) - (6)].num)) == -1) YYERROR; } break; @@ -2509,9 +2548,9 @@ yyreduce: case 26: /* Line 1464 of yacc.c */ -#line 1034 "loadkeys.y" +#line 1067 "loadkeys.y" { - if (compose((yyvsp[(2) - (6)]), (yyvsp[(3) - (6)]), (yyvsp[(5) - (6)])) == -1) + if (compose(kmap, (yyvsp[(2) - (6)].num), (yyvsp[(3) - (6)].num), (yyvsp[(5) - (6)].num)) == -1) YYERROR; } break; @@ -2519,32 +2558,32 @@ yyreduce: case 27: /* Line 1464 of yacc.c */ -#line 1039 "loadkeys.y" - { (yyval) = (yyvsp[(1) - (1)]); } +#line 1072 "loadkeys.y" + { (yyval.num) = (yyvsp[(1) - (1)].num); } break; case 28: /* Line 1464 of yacc.c */ -#line 1040 "loadkeys.y" - { (yyval) = (yyvsp[(1) - (1)]) ^ 0xf000; } +#line 1073 "loadkeys.y" + { (yyval.num) = (yyvsp[(1) - (1)].num) ^ 0xf000; } break; case 29: /* Line 1464 of yacc.c */ -#line 1042 "loadkeys.y" +#line 1075 "loadkeys.y" { - kmap.mod = 0; + kmap->mod = 0; } break; case 30: /* Line 1464 of yacc.c */ -#line 1046 "loadkeys.y" +#line 1079 "loadkeys.y" { - if (addkey((yyvsp[(4) - (7)]), kmap.mod, (yyvsp[(6) - (7)])) == -1) + if (addkey(kmap, (yyvsp[(4) - (7)].num), kmap->mod, (yyvsp[(6) - (7)].num)) == -1) YYERROR; } break; @@ -2552,9 +2591,9 @@ yyreduce: case 31: /* Line 1464 of yacc.c */ -#line 1051 "loadkeys.y" +#line 1084 "loadkeys.y" { - if (addkey((yyvsp[(3) - (6)]), 0, (yyvsp[(5) - (6)])) == -1) + if (addkey(kmap, (yyvsp[(3) - (6)].num), 0, (yyvsp[(5) - (6)].num)) == -1) YYERROR; } break; @@ -2562,118 +2601,118 @@ yyreduce: case 34: /* Line 1464 of yacc.c */ -#line 1059 "loadkeys.y" - { kmap.mod |= M_SHIFT; } +#line 1092 "loadkeys.y" + { kmap->mod |= M_SHIFT; } break; case 35: /* Line 1464 of yacc.c */ -#line 1060 "loadkeys.y" - { kmap.mod |= M_CTRL; } +#line 1093 "loadkeys.y" + { kmap->mod |= M_CTRL; } break; case 36: /* Line 1464 of yacc.c */ -#line 1061 "loadkeys.y" - { kmap.mod |= M_ALT; } +#line 1094 "loadkeys.y" + { kmap->mod |= M_ALT; } break; case 37: /* Line 1464 of yacc.c */ -#line 1062 "loadkeys.y" - { kmap.mod |= M_ALTGR; } +#line 1095 "loadkeys.y" + { kmap->mod |= M_ALTGR; } break; case 38: /* Line 1464 of yacc.c */ -#line 1063 "loadkeys.y" - { kmap.mod |= M_SHIFTL; } +#line 1096 "loadkeys.y" + { kmap->mod |= M_SHIFTL; } break; case 39: /* Line 1464 of yacc.c */ -#line 1064 "loadkeys.y" - { kmap.mod |= M_SHIFTR; } +#line 1097 "loadkeys.y" + { kmap->mod |= M_SHIFTR; } break; case 40: /* Line 1464 of yacc.c */ -#line 1065 "loadkeys.y" - { kmap.mod |= M_CTRLL; } +#line 1098 "loadkeys.y" + { kmap->mod |= M_CTRLL; } break; case 41: /* Line 1464 of yacc.c */ -#line 1066 "loadkeys.y" - { kmap.mod |= M_CTRLR; } +#line 1099 "loadkeys.y" + { kmap->mod |= M_CTRLR; } break; case 42: /* Line 1464 of yacc.c */ -#line 1067 "loadkeys.y" - { kmap.mod |= M_CAPSSHIFT; } +#line 1100 "loadkeys.y" + { kmap->mod |= M_CAPSSHIFT; } break; case 43: /* Line 1464 of yacc.c */ -#line 1070 "loadkeys.y" +#line 1103 "loadkeys.y" { int i, j, keycode; - if (kmap.rvalct == 1) { + if (kmap->rvalct == 1) { /* Some files do not have a keymaps line, and * we have to wait until all input has been read * before we know which maps to fill. */ - kmap.key_is_constant[(yyvsp[(2) - (5)])] = 1; + kmap->key_is_constant[(yyvsp[(2) - (5)].num)] = 1; /* On the other hand, we now have include files, * and it should be possible to override lines * from an include file. So, kill old defs. */ - for (j = 0; j < kmap.max_keymap; j++) { - if (!(kmap.defining[j])) + for (j = 0; j < kmap->max_keymap; j++) { + if (!(kmap->defining[j])) continue; - if (killkey((yyvsp[(2) - (5)]), j) == -1) + if (killkey(kmap, (yyvsp[(2) - (5)].num), j) == -1) YYERROR; } } - if (kmap.keymaps_line_seen) { + if (kmap->keymaps_line_seen) { i = 0; - for (j = 0; j < kmap.max_keymap; j++) { - if (!(kmap.defining[j])) + for (j = 0; j < kmap->max_keymap; j++) { + if (!(kmap->defining[j])) continue; - if (kmap.rvalct != 1 || i == 0) { - keycode = (i < kmap.rvalct) - ? kmap.key_buf[i] + if (kmap->rvalct != 1 || i == 0) { + keycode = (i < kmap->rvalct) + ? kmap->key_buf[i] : K_HOLE; - if (addkey((yyvsp[(2) - (5)]), j, keycode) == -1) + if (addkey(kmap, (yyvsp[(2) - (5)].num), j, keycode) == -1) YYERROR; } i++; } - if (i < kmap.rvalct) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (i < kmap->rvalct) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("too many (%d) entries on one line"), - kmap.rvalct); + kmap->rvalct); YYERROR; } } else { - for (i = 0; i < kmap.rvalct; i++) { - if (addkey((yyvsp[(2) - (5)]), i, kmap.key_buf[i]) == -1) + for (i = 0; i < kmap->rvalct; i++) { + if (addkey(kmap, (yyvsp[(2) - (5)].num), i, kmap->key_buf[i]) == -1) YYERROR; } } @@ -2683,63 +2722,63 @@ yyreduce: case 46: /* Line 1464 of yacc.c */ -#line 1128 "loadkeys.y" +#line 1161 "loadkeys.y" { - if (kmap.rvalct >= MAX_NR_KEYMAPS) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (kmap->rvalct >= MAX_NR_KEYMAPS) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("too many key definitions on one line")); YYERROR; } - kmap.key_buf[kmap.rvalct++] = (yyvsp[(1) - (1)]); + kmap->key_buf[kmap->rvalct++] = (yyvsp[(1) - (1)].num); } break; case 47: /* Line 1464 of yacc.c */ -#line 1137 "loadkeys.y" - { (yyval) = convert_code(kmap.prefer_unicode, (yyvsp[(1) - (1)]), TO_AUTO); } +#line 1170 "loadkeys.y" + { (yyval.num) = convert_code(kmap->prefer_unicode, (yyvsp[(1) - (1)].num), TO_AUTO); } break; case 48: /* Line 1464 of yacc.c */ -#line 1138 "loadkeys.y" - { (yyval) = add_capslock(kmap.prefer_unicode, (yyvsp[(2) - (2)])); } +#line 1171 "loadkeys.y" + { (yyval.num) = add_capslock(kmap->prefer_unicode, (yyvsp[(2) - (2)].num)); } break; case 49: /* Line 1464 of yacc.c */ -#line 1139 "loadkeys.y" - { (yyval) = convert_code(kmap.prefer_unicode, (yyvsp[(1) - (1)])^0xf000, TO_AUTO); } +#line 1172 "loadkeys.y" + { (yyval.num) = convert_code(kmap->prefer_unicode, (yyvsp[(1) - (1)].num)^0xf000, TO_AUTO); } break; case 50: /* Line 1464 of yacc.c */ -#line 1140 "loadkeys.y" - { (yyval) = add_capslock(kmap.prefer_unicode, (yyvsp[(2) - (2)])^0xf000); } +#line 1173 "loadkeys.y" + { (yyval.num) = add_capslock(kmap->prefer_unicode, (yyvsp[(2) - (2)].num)^0xf000); } break; case 51: /* Line 1464 of yacc.c */ -#line 1141 "loadkeys.y" - { (yyval) = (yyvsp[(1) - (1)]); } +#line 1174 "loadkeys.y" + { (yyval.num) = (yyvsp[(1) - (1)].num); } break; case 52: /* Line 1464 of yacc.c */ -#line 1142 "loadkeys.y" - { (yyval) = add_capslock(kmap.prefer_unicode, (yyvsp[(2) - (2)])); } +#line 1175 "loadkeys.y" + { (yyval.num) = add_capslock(kmap->prefer_unicode, (yyvsp[(2) - (2)].num)); } break; /* Line 1464 of yacc.c */ -#line 2743 "loadkeys.c" +#line 2782 "loadkeys.c" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -2774,7 +2813,7 @@ yyerrlab: { ++yynerrs; #if ! YYERROR_VERBOSE - yyerror (YY_("syntax error")); + yyerror (scanner, kmap, YY_("syntax error")); #else { YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); @@ -2798,11 +2837,11 @@ yyerrlab: if (0 < yysize && yysize <= yymsg_alloc) { (void) yysyntax_error (yymsg, yystate, yychar); - yyerror (yymsg); + yyerror (scanner, kmap, yymsg); } else { - yyerror (YY_("syntax error")); + yyerror (scanner, kmap, YY_("syntax error")); if (yysize != 0) goto yyexhaustedlab; } @@ -2826,7 +2865,7 @@ yyerrlab: else { yydestruct ("Error: discarding", - yytoken, &yylval); + yytoken, &yylval, scanner, kmap); yychar = YYEMPTY; } } @@ -2882,7 +2921,7 @@ yyerrlab1: yydestruct ("Error: popping", - yystos[yystate], yyvsp); + yystos[yystate], yyvsp, scanner, kmap); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -2917,7 +2956,7 @@ yyabortlab: | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: - yyerror (YY_("memory exhausted")); + yyerror (scanner, kmap, YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif @@ -2925,7 +2964,7 @@ yyexhaustedlab: yyreturn: if (yychar != YYEMPTY) yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval); + yytoken, &yylval, scanner, kmap); /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); @@ -2933,7 +2972,7 @@ yyreturn: while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp); + yystos[*yyssp], yyvsp, scanner, kmap); YYPOPSTACK (1); } #ifndef yyoverflow @@ -2951,30 +2990,40 @@ yyreturn: /* Line 1684 of yacc.c */ -#line 1144 "loadkeys.y" +#line 1177 "loadkeys.y" static int -parse_keymap(lkfile_t *f) +parse_keymap(struct keymap *kmap, lkfile_t *f) { - lkverbose(1, _("Loading %s"), f->pathname); + yyscan_t scanner; + int rc = -1; - kmap.errmsg[0] = '\0'; + yylex_init(&scanner); + yylex_init_extra(kmap, &scanner); - if (stack_push(f) == -1) { - lkerror("%s", kmap.errmsg); - return -1; + lkverbose(kmap, 1, _("Loading %s"), f->pathname); + + kmap->errmsg[0] = '\0'; + + if (stack_push(kmap, f, scanner) == -1) { + lkerror("%s", kmap->errmsg); + goto fail; } - if (yyparse()) { - if (strlen(kmap.errmsg) > 0) - lkerror("%s", kmap.errmsg); + if (yyparse(scanner, kmap)) { + if (strlen(kmap->errmsg) > 0) + lkerror("%s", kmap->errmsg); else lkerror(_("syntax error in map file")); - - return -1; + goto fail; } - return 0; + rc = 0; + + stack_pop(kmap, scanner); + + fail: yylex_destroy(scanner); + return rc; } int main(int argc, char *argv[]) @@ -3005,6 +3054,8 @@ int main(int argc, char *argv[]) }; int options = 0; + struct keymap kmap; + int c, i, rc = -1; int fd; int kbd_mode; @@ -3117,7 +3168,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - if ((rc = parse_keymap(&f)) == -1) + if ((rc = parse_keymap(&kmap, &f)) == -1) goto fail; @@ -3125,7 +3176,7 @@ int main(int argc, char *argv[]) f.fd = stdin; strcpy(f.pathname, ""); - if ((rc = parse_keymap(&f)) == -1) + if ((rc = parse_keymap(&kmap, &f)) == -1) goto fail; } @@ -3139,22 +3190,22 @@ int main(int argc, char *argv[]) goto fail; } - if ((rc = parse_keymap(&f)) == -1) + if ((rc = parse_keymap(&kmap, &f)) == -1) goto fail; } - if ((rc = do_constant()) == -1) + if ((rc = do_constant(&kmap)) == -1) goto fail; if (options & OPT_B) { - rc = bkeymap(); + rc = bkeymap(&kmap); } else if (options & OPT_M) { - rc = mktable(stdout); + rc = mktable(&kmap, stdout); } else { - rc = loadkeys(fd, kbd_mode); + rc = loadkeys(&kmap, fd, kbd_mode); } - fail: freekeys(); + fail: freekeys(&kmap); close(fd); if (rc < 0) diff --git a/src/loadkeys.h b/src/loadkeys.h index 9f6a73d..ac9afea 100644 --- a/src/loadkeys.h +++ b/src/loadkeys.h @@ -31,6 +31,17 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ +/* "%code requires" blocks. */ + +/* Line 1685 of yacc.c */ +#line 39 "loadkeys.y" + +#include "loadkeys.keymap.h" + + + +/* Line 1685 of yacc.c */ +#line 45 "loadkeys.h" /* Tokens. */ #ifndef YYTOKENTYPE @@ -112,12 +123,25 @@ #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef int YYSTYPE; +typedef union YYSTYPE +{ + +/* Line 1685 of yacc.c */ +#line 62 "loadkeys.y" + + long long int num; + struct strdata str; + + + +/* Line 1685 of yacc.c */ +#line 139 "loadkeys.h" +} YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 #endif -extern YYSTYPE yylval; + diff --git a/src/loadkeys.keymap.h b/src/loadkeys.keymap.h index a448672..a38abea 100644 --- a/src/loadkeys.keymap.h +++ b/src/loadkeys.keymap.h @@ -2,6 +2,8 @@ #define LK_KEYMAP_H #include +#include +#include "findfile.h" #ifdef KDSKBDIACRUC typedef struct kbdiacruc accent_entry; @@ -15,6 +17,8 @@ typedef enum { LKFLAG_CLEAR_STRINGS = (1 << 3), } lkflags; +#define MAX_INCLUDE_DEPTH 20 + struct keymap { /* Verbosity level */ int verbose; @@ -41,11 +45,19 @@ struct keymap { int mod; /* Line by line modifiers */ int key_buf[MAX_NR_KEYMAPS]; /* Key definitions on one line */ - int rvalct; - unsigned char string[512]; - char errmsg[1024]; int prefer_unicode; + + int rvalct; + int state_ptr; + lkfile_t *stack[MAX_INCLUDE_DEPTH]; +}; + +#define MAX_PARSER_STRING 512 + +struct strdata { + unsigned int len; + unsigned char data[MAX_PARSER_STRING]; }; #endif /* LK_KEYMAP_H */ diff --git a/src/loadkeys.y b/src/loadkeys.y index e04aaaf..39084a4 100644 --- a/src/loadkeys.y +++ b/src/loadkeys.y @@ -3,12 +3,6 @@ * * For history, see older versions. */ - -%token EOL NUMBER LITERAL CHARSET KEYMAPS KEYCODE EQUALS -%token PLAIN SHIFT CONTROL ALT ALTGR SHIFTL SHIFTR CTRLL CTRLR CAPSSHIFT -%token COMMA DASH STRING STRLITERAL COMPOSE TO CCHAR ERROR PLUS -%token UNUMBER ALT_IS_META STRINGS AS USUAL ON FOR - %{ #define YY_HEADER_EXPORT_START_CONDITIONS 1 @@ -34,25 +28,63 @@ #include "nls.h" #include "version.h" -#include "loadkeys.analyze.h" - #ifdef COMPAT_HEADERS #include "compat/linux-keyboard.h" #endif +#include "loadkeys.h" +#include "loadkeys.analyze.h" +%} + +%code requires { #include "loadkeys.keymap.h" +} -#define U(x) ((x) ^ 0xf000) +%language "C" +%yacc +%defines +%debug +%error-verbose + +/* Pure yylex. */ +%define api.pure +%lex-param { yyscan_t scanner } + +/* Pure yyparse. */ +%parse-param { yyscan_t scanner } +%parse-param { struct keymap *kmap } -struct keymap kmap; +%token EOL NUMBER LITERAL CHARSET KEYMAPS KEYCODE EQUALS +%token PLAIN SHIFT CONTROL ALT ALTGR SHIFTL SHIFTR CTRLL CTRLR CAPSSHIFT +%token COMMA DASH STRING STRLITERAL COMPOSE TO CCHAR ERROR PLUS +%token UNUMBER ALT_IS_META STRINGS AS USUAL ON FOR -int yyerror(const char *s); -int lkverbose(int level, const char *fmt, ...); +%union { + long long int num; + struct strdata str; +} + +%type STRLITERAL +%type CCHAR +%type LITERAL +%type NUMBER +%type UNUMBER + +%type compsym +%type rvalue + +%{ + +#define U(x) ((x) ^ 0xf000) + +int yyerror(yyscan_t scanner, struct keymap *kmap, const char *s); +int lkverbose(struct keymap *kmap, int level, const char *fmt, ...); int lkerror(const char *fmt, ...); int keymap_init(struct keymap *km); -extern int stack_push(lkfile_t *fp); +extern int stack_push(struct keymap *kmap, lkfile_t *fp, yyscan_t scanner); +extern int stack_pop(struct keymap *kmap, yyscan_t scanner); #include "ksyms.h" @@ -85,9 +117,9 @@ char *dirpath1[] = { "", DATADIR "/" KEYMAPDIR "/**", KERNDIR "/", 0 }; char *dirpath2[] = { 0, 0 }; char *suffixes[] = { "", ".kmap", ".map", 0 }; -int __attribute__ ((format (printf, 2, 3))) -lkverbose(int level, const char *fmt, ...) { - if (kmap.verbose < level) +int __attribute__ ((format (printf, 3, 4))) +lkverbose(struct keymap *kmap, int level, const char *fmt, ...) { + if (kmap->verbose < level) return 1; va_list ap; va_start(ap, fmt); @@ -123,9 +155,9 @@ keymap_init(struct keymap *km) return 0; } -int yyerror(const char *s) +int yyerror(yyscan_t scanner attr_unused, struct keymap *kmap, const char *s) { - if (strlen(kmap.errmsg) > 0) + if (strlen(kmap->errmsg) > 0) return 0; lkerror("%s\n", s); @@ -134,128 +166,128 @@ int yyerror(const char *s) static int -addmap(int i, int explicit) +addmap(struct keymap *kmap, int i, int explicit) { if (i < 0 || i >= MAX_NR_KEYMAPS) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("addmap called with bad index %d"), i); return -1; } - if (!kmap.defining[i]) { - if (kmap.keymaps_line_seen && !explicit) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (!kmap->defining[i]) { + if (kmap->keymaps_line_seen && !explicit) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("adding map %d violates explicit keymaps line"), i); return -1; } - kmap.defining[i] = 1; - if (kmap.max_keymap <= i) - kmap.max_keymap = i + 1; + kmap->defining[i] = 1; + if (kmap->max_keymap <= i) + kmap->max_keymap = i + 1; } return 0; } /* unset a key */ static int -killkey(int k_index, int k_table) +killkey(struct keymap *kmap, int k_index, int k_table) { /* roughly: addkey(k_index, k_table, K_HOLE); */ if (k_index < 0 || k_index >= NR_KEYS) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("killkey called with bad index %d"), k_index); return -1; } if (k_table < 0 || k_table >= MAX_NR_KEYMAPS) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("killkey called with bad table %d"), k_table); return -1; } - if (kmap.key_map[k_table]) - (kmap.key_map[k_table])[k_index] = K_HOLE; + if (kmap->key_map[k_table]) + (kmap->key_map[k_table])[k_index] = K_HOLE; - if (kmap.keymap_was_set[k_table]) - (kmap.keymap_was_set[k_table])[k_index] = 0; + if (kmap->keymap_was_set[k_table]) + (kmap->keymap_was_set[k_table])[k_index] = 0; return 0; } static int -addkey(int k_index, int k_table, int keycode) +addkey(struct keymap *kmap, int k_index, int k_table, int keycode) { int i; if (keycode == CODE_FOR_UNKNOWN_KSYM) { /* is safer not to be silent in this case, * it can be caused by coding errors as well. */ - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("addkey called with bad keycode %d"), keycode); return -1; } if (k_index < 0 || k_index >= NR_KEYS) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("addkey called with bad index %d"), k_index); return -1; } if (k_table < 0 || k_table >= MAX_NR_KEYMAPS) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("addkey called with bad table %d"), k_table); return -1; } - if (!kmap.defining[k_table]) { - if (addmap(k_table, 0) == -1) + if (!kmap->defining[k_table]) { + if (addmap(kmap, k_table, 0) == -1) return -1; } - if (!kmap.key_map[k_table]) { - kmap.key_map[k_table] = (u_short *)malloc(NR_KEYS * sizeof(u_short)); + if (!kmap->key_map[k_table]) { + kmap->key_map[k_table] = (u_short *)malloc(NR_KEYS * sizeof(u_short)); - if (kmap.key_map[k_table] == NULL) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (kmap->key_map[k_table] == NULL) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("out of memory")); return -1; } for (i = 0; i < NR_KEYS; i++) - (kmap.key_map[k_table])[i] = K_HOLE; + (kmap->key_map[k_table])[i] = K_HOLE; } - if (!kmap.keymap_was_set[k_table]) { - kmap.keymap_was_set[k_table] = (char *)malloc(NR_KEYS); + if (!kmap->keymap_was_set[k_table]) { + kmap->keymap_was_set[k_table] = (char *)malloc(NR_KEYS); - if (kmap.key_map[k_table] == NULL) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (kmap->key_map[k_table] == NULL) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("out of memory")); return -1; } for (i = 0; i < NR_KEYS; i++) - (kmap.keymap_was_set[k_table])[i] = 0; + (kmap->keymap_was_set[k_table])[i] = 0; } - if (kmap.alt_is_meta && keycode == K_HOLE - && (kmap.keymap_was_set[k_table])[k_index]) + if (kmap->alt_is_meta && keycode == K_HOLE + && (kmap->keymap_was_set[k_table])[k_index]) return 0; - (kmap.key_map[k_table])[k_index] = keycode; - (kmap.keymap_was_set[k_table])[k_index] = 1; + (kmap->key_map[k_table])[k_index] = keycode; + (kmap->keymap_was_set[k_table])[k_index] = 1; - if (kmap.alt_is_meta) { + if (kmap->alt_is_meta) { int alttable = k_table | M_ALT; int type = KTYP(keycode); int val = KVAL(keycode); - if (alttable != k_table && kmap.defining[alttable] && - (!kmap.keymap_was_set[alttable] || - !(kmap.keymap_was_set[alttable])[k_index]) && + if (alttable != k_table && kmap->defining[alttable] && + (!kmap->keymap_was_set[alttable] || + !(kmap->keymap_was_set[alttable])[k_index]) && (type == KT_LATIN || type == KT_LETTER) && val < 128) { - if (addkey(k_index, alttable, K(KT_META, val)) == -1) + if (addkey(kmap, k_index, alttable, K(KT_META, val)) == -1) return -1; } } @@ -263,27 +295,27 @@ addkey(int k_index, int k_table, int keycode) } static int -addfunc(struct kbsentry kbs) +addfunc(struct keymap *kmap, struct kbsentry kbs) { int x; x = kbs.kb_func; if (x >= MAX_NR_FUNC) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("addfunc called with bad func %d"), kbs.kb_func); return -1; } - if(kmap.func_table[x]) { - free(kmap.func_table[x]); - kmap.func_table[x] = NULL; + if(kmap->func_table[x]) { + free(kmap->func_table[x]); + kmap->func_table[x] = NULL; } - kmap.func_table[x] = strdup((char *)kbs.kb_string); + kmap->func_table[x] = strdup((char *)kbs.kb_string); - if (!kmap.func_table[x]) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (!kmap->func_table[x]) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("addfunc: out of memory")); return -1; } @@ -292,39 +324,39 @@ addfunc(struct kbsentry kbs) } static int -compose(int diacr, int base, int res) +compose(struct keymap *kmap, int diacr, int base, int res) { accent_entry *ptr; int direction; #ifdef KDSKBDIACRUC - if (kmap.prefer_unicode) + if (kmap->prefer_unicode) direction = TO_UNICODE; else #endif direction = TO_8BIT; - if (kmap.accent_table_size == MAX_DIACR) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (kmap->accent_table_size == MAX_DIACR) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("compose table overflow")); return -1; } - ptr = &(kmap.accent_table[kmap.accent_table_size++]); - ptr->diacr = convert_code(kmap.prefer_unicode, diacr, direction); - ptr->base = convert_code(kmap.prefer_unicode, base, direction); - ptr->result = convert_code(kmap.prefer_unicode, res, direction); + ptr = &(kmap->accent_table[kmap->accent_table_size++]); + ptr->diacr = convert_code(kmap->prefer_unicode, diacr, direction); + ptr->base = convert_code(kmap->prefer_unicode, base, direction); + ptr->result = convert_code(kmap->prefer_unicode, res, direction); return 0; } -static int defkeys(int fd, int kbd_mode) +static int defkeys(struct keymap *kmap, int fd, int kbd_mode) { struct kbentry ke; int ct = 0; int i, j, fail; - if (kmap.flags & LKFLAG_UNICODE_MODE) { + if (kmap->flags & LKFLAG_UNICODE_MODE) { /* temporarily switch to K_UNICODE while defining keys */ if (ioctl(fd, KDSKBMODE, K_UNICODE)) { lkerror(_("KDSKBMODE: %s: could not switch to Unicode mode"), @@ -334,14 +366,14 @@ static int defkeys(int fd, int kbd_mode) } for (i = 0; i < MAX_NR_KEYMAPS; i++) { - if (kmap.key_map[i]) { + if (kmap->key_map[i]) { for (j = 0; j < NR_KEYS; j++) { - if (!((kmap.keymap_was_set[i])[j])) + if (!((kmap->keymap_was_set[i])[j])) continue; ke.kb_index = j; ke.kb_table = i; - ke.kb_value = (kmap.key_map[i])[j]; + ke.kb_value = (kmap->key_map[i])[j]; fail = ioctl(fd, KDSKBENT, (unsigned long)&ke); @@ -356,21 +388,21 @@ static int defkeys(int fd, int kbd_mode) } else ct++; - lkverbose(2, _("keycode %d, table %d = %d%s"), - j, i, (kmap.key_map[i])[j], fail ? _(" FAILED") : ""); + lkverbose(kmap, 2, _("keycode %d, table %d = %d%s"), + j, i, (kmap->key_map[i])[j], fail ? _(" FAILED") : ""); - if (fail && kmap.verbose > 1) + if (fail && kmap->verbose > 1) lkerror(_("failed to bind key %d to value %d"), - j, (kmap.key_map[i])[j]); + j, (kmap->key_map[i])[j]); } - } else if (kmap.keymaps_line_seen && !kmap.defining[i]) { + } else if (kmap->keymaps_line_seen && !kmap->defining[i]) { /* deallocate keymap */ ke.kb_index = 0; ke.kb_table = i; ke.kb_value = K_NOSUCHMAP; - lkverbose(3, _("deallocate keymap %d"), i); + lkverbose(kmap, 3, _("deallocate keymap %d"), i); if (ioctl(fd, KDSKBENT, (unsigned long)&ke)) { if (errno != EINVAL) { @@ -398,7 +430,7 @@ static int defkeys(int fd, int kbd_mode) } } - if ((kmap.flags & LKFLAG_UNICODE_MODE) && ioctl(fd, KDSKBMODE, kbd_mode)) { + if ((kmap->flags & LKFLAG_UNICODE_MODE) && ioctl(fd, KDSKBMODE, kbd_mode)) { lkerror(_("KDSKBMODE: %s: could not return to original keyboard mode"), strerror(errno)); goto fail; @@ -409,14 +441,14 @@ static int defkeys(int fd, int kbd_mode) fail: return -1; } -static void freekeys(void) +static void freekeys(struct keymap *kmap) { int i; for (i = 0; i < MAX_NR_KEYMAPS; i++) { - if (kmap.keymap_was_set[i] != NULL) - free(kmap.keymap_was_set[i]); - if (kmap.key_map[i] != NULL) - free(kmap.key_map[i]); + if (kmap->keymap_was_set[i] != NULL) + free(kmap->keymap_was_set[i]); + if (kmap->key_map[i] != NULL) + free(kmap->key_map[i]); } } @@ -454,7 +486,7 @@ ostr(char *s) } static int -deffuncs(int fd) +deffuncs(struct keymap *kmap, int fd) { int i, ct = 0; char *ptr, *s; @@ -463,7 +495,7 @@ deffuncs(int fd) for (i = 0; i < MAX_NR_FUNC; i++) { kbs.kb_func = i; - if ((ptr = kmap.func_table[i])) { + if ((ptr = kmap->func_table[i])) { strcpy((char *)kbs.kb_string, ptr); if (ioctl(fd, KDSKBSENT, (unsigned long)&kbs)) { s = ostr((char *)kbs.kb_string); @@ -475,7 +507,7 @@ deffuncs(int fd) } else { ct++; } - } else if (kmap.flags & LKFLAG_CLEAR_STRINGS) { + } else if (kmap->flags & LKFLAG_CLEAR_STRINGS) { kbs.kb_string[0] = 0; if (ioctl(fd, KDSKBSENT, (unsigned long)&kbs)) { @@ -490,7 +522,7 @@ deffuncs(int fd) } static int -defdiacs(int fd) +defdiacs(struct keymap *kmap, int fd) { unsigned int i, count; struct kbdiacrs kd; @@ -498,19 +530,19 @@ defdiacs(int fd) struct kbdiacrsuc kdu; #endif - count = kmap.accent_table_size; + count = kmap->accent_table_size; if (count > MAX_DIACR) { count = MAX_DIACR; lkerror(_("too many compose definitions")); } #ifdef KDSKBDIACRUC - if (kmap.prefer_unicode) { + if (kmap->prefer_unicode) { kdu.kb_cnt = count; for (i = 0; i < kdu.kb_cnt; i++) { - kdu.kbdiacruc[i].diacr = kmap.accent_table[i].diacr; - kdu.kbdiacruc[i].base = kmap.accent_table[i].base; - kdu.kbdiacruc[i].result = kmap.accent_table[i].result; + kdu.kbdiacruc[i].diacr = kmap->accent_table[i].diacr; + kdu.kbdiacruc[i].base = kmap->accent_table[i].base; + kdu.kbdiacruc[i].result = kmap->accent_table[i].result; } if (ioctl(fd, KDSKBDIACRUC, (unsigned long)&kdu)) @@ -520,9 +552,9 @@ defdiacs(int fd) { kd.kb_cnt = count; for (i = 0; i < kd.kb_cnt; i++) { - kd.kbdiacr[i].diacr = kmap.accent_table[i].diacr; - kd.kbdiacr[i].base = kmap.accent_table[i].base; - kd.kbdiacr[i].result = kmap.accent_table[i].result; + kd.kbdiacr[i].diacr = kmap->accent_table[i].diacr; + kd.kbdiacr[i].base = kmap->accent_table[i].base; + kd.kbdiacr[i].result = kmap->accent_table[i].result; } if (ioctl(fd, KDSKBDIACR, (unsigned long)&kd)) @@ -541,7 +573,7 @@ defdiacs(int fd) } static int -do_constant_key(int i, u_short key) +do_constant_key(struct keymap *kmap, int i, u_short key) { int typ, val, j; @@ -562,25 +594,25 @@ do_constant_key(int i, u_short key) for (j = 8; j < 16; j++) defs[j] = K(KT_META, KVAL(defs[j - 8])); - for (j = 0; j < kmap.max_keymap; j++) { - if (!kmap.defining[j]) + for (j = 0; j < kmap->max_keymap; j++) { + if (!kmap->defining[j]) continue; if (j > 0 && - kmap.keymap_was_set[j] && (kmap.keymap_was_set[j])[i]) + kmap->keymap_was_set[j] && (kmap->keymap_was_set[j])[i]) continue; - if (addkey(i, j, defs[j % 16]) == -1) + if (addkey(kmap, i, j, defs[j % 16]) == -1) return -1; } } else { /* do this also for keys like Escape, as promised in the man page */ - for (j = 1; j < kmap.max_keymap; j++) { - if (kmap.defining[j] && - (!(kmap.keymap_was_set[j]) || !(kmap.keymap_was_set[j])[i])) { - if (addkey(i, j, key) == -1) + for (j = 1; j < kmap->max_keymap; j++) { + if (kmap->defining[j] && + (!(kmap->keymap_was_set[j]) || !(kmap->keymap_was_set[j])[i])) { + if (addkey(kmap, i, j, key) == -1) return -1; } } @@ -589,66 +621,66 @@ do_constant_key(int i, u_short key) } static int -do_constant(void) +do_constant(struct keymap *kmap) { int i, r0 = 0; - if (kmap.keymaps_line_seen) { - while (r0 < kmap.max_keymap && !kmap.defining[r0]) + if (kmap->keymaps_line_seen) { + while (r0 < kmap->max_keymap && !kmap->defining[r0]) r0++; } for (i = 0; i < NR_KEYS; i++) { - if (kmap.key_is_constant[i]) { + if (kmap->key_is_constant[i]) { u_short key; - if (!kmap.key_map[r0]) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (!kmap->key_map[r0]) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("impossible error in do_constant")); goto fail; } - key = (kmap.key_map[r0])[i]; - if (do_constant_key(i, key) == -1) + key = (kmap->key_map[r0])[i]; + if (do_constant_key(kmap, i, key) == -1) goto fail; } } return 0; - fail: lkerror("%s", kmap.errmsg); + fail: lkerror("%s", kmap->errmsg); return -1; } static int -loadkeys(int fd, int kbd_mode) +loadkeys(struct keymap *kmap, int fd, int kbd_mode) { int keyct, funcct, diacct; - if ((keyct = defkeys(fd, kbd_mode)) < 0 || (funcct = deffuncs(fd)) < 0) + if ((keyct = defkeys(kmap, fd, kbd_mode)) < 0 || (funcct = deffuncs(kmap, fd)) < 0) return -1; - lkverbose(2, _("\nChanged %d %s and %d %s"), + lkverbose(kmap, 2, _("\nChanged %d %s and %d %s"), keyct, (keyct == 1) ? _("key") : _("keys"), funcct, (funcct == 1) ? _("string") : _("strings")); - if (kmap.accent_table_size > 0 || kmap.flags & LKFLAG_CLEAR_COMPOSE) { - diacct = defdiacs(fd); + if (kmap->accent_table_size > 0 || kmap->flags & LKFLAG_CLEAR_COMPOSE) { + diacct = defdiacs(kmap, fd); if (diacct < 0) return -1; - lkverbose(2, _("Loaded %d compose %s"), + lkverbose(kmap, 2, _("Loaded %d compose %s"), diacct, (diacct == 1) ? _("definition") : _("definitions")); } else { - lkverbose(2, _("(No change in compose definitions)")); + lkverbose(kmap, 2, _("(No change in compose definitions)")); } return 0; } static int -strings_as_usual(void) +strings_as_usual(struct keymap *kmap) { /* * 26 strings, mostly inspired by the VT100 family @@ -675,7 +707,7 @@ strings_as_usual(void) sizeof(ke.kb_string)); ke.kb_string[sizeof(ke.kb_string) - 1] = 0; - if (addfunc(ke) == -1) + if (addfunc(kmap, ke) == -1) return -1; } } @@ -683,10 +715,10 @@ strings_as_usual(void) } static int -compose_as_usual(char *charset) +compose_as_usual(struct keymap *kmap, char *charset) { if (charset && strcmp(charset, "iso-8859-1")) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("loadkeys: don't know how to compose for %s"), charset); return -1; @@ -733,7 +765,7 @@ compose_as_usual(char *charset) int i; for (i = 0; i < 68; i++) { struct ccc ptr = def_latin1_composes[i]; - if (compose(ptr.c1, ptr.c2, ptr.c3) == -1) + if (compose(kmap, ptr.c1, ptr.c2, ptr.c3) == -1) return -1; } } @@ -775,7 +807,7 @@ outchar(FILE *fd, unsigned char c, int comma) } static int -mktable(FILE *fd) +mktable(struct keymap *kmap, FILE *fd) { int j; unsigned int i, imax; @@ -795,7 +827,7 @@ mktable(FILE *fd) fprintf(fd, "#include \n\n"); for (i = 0; i < MAX_NR_KEYMAPS; i++) - if (kmap.key_map[i]) { + if (kmap->key_map[i]) { keymap_count++; if (i) fprintf(fd, "static "); @@ -803,18 +835,18 @@ mktable(FILE *fd) for (j = 0; j < NR_KEYS; j++) { if (!(j % 8)) fprintf(fd, "\n"); - fprintf(fd, "\t0x%04x,", U((kmap.key_map[i])[j])); + fprintf(fd, "\t0x%04x,", U((kmap->key_map[i])[j])); } fprintf(fd, "\n};\n\n"); } for (imax = MAX_NR_KEYMAPS - 1; imax > 0; imax--) - if (kmap.key_map[imax]) + if (kmap->key_map[imax]) break; fprintf(fd, "ushort *key_maps[MAX_NR_KEYMAPS] = {"); for (i = 0; i <= imax; i++) { fprintf(fd, (i % 4) ? " " : "\n\t"); - if (kmap.key_map[i]) + if (kmap->key_map[i]) fprintf(fd, "%s_map,", mk_mapname(i)); else fprintf(fd, "0,"); @@ -831,19 +863,19 @@ mktable(FILE *fd) " * the default and allocate dynamically in chunks of 512 bytes.\n" " */\n" "\n"); for (maxfunc = MAX_NR_FUNC; maxfunc; maxfunc--) - if (kmap.func_table[maxfunc - 1]) + if (kmap->func_table[maxfunc - 1]) break; fprintf(fd, "char func_buf[] = {\n"); for (i = 0; i < maxfunc; i++) { - ptr = kmap.func_table[i]; + ptr = kmap->func_table[i]; if (ptr) { func_table_offs[i] = func_buf_offset; fprintf(fd, "\t"); for (; *ptr; ptr++) outchar(fd, *ptr, 1); fprintf(fd, "0, \n"); - func_buf_offset += (ptr - kmap.func_table[i] + 1); + func_buf_offset += (ptr - kmap->func_table[i] + 1); } } if (!maxfunc) @@ -857,7 +889,7 @@ mktable(FILE *fd) fprintf(fd, "char *func_table[MAX_NR_FUNC] = {\n"); for (i = 0; i < maxfunc; i++) { - if (kmap.func_table[i]) + if (kmap->func_table[i]) fprintf(fd, "\tfunc_buf + %u,\n", func_table_offs[i]); else fprintf(fd, "\t0,\n"); @@ -867,13 +899,13 @@ mktable(FILE *fd) fprintf(fd, "};\n"); #ifdef KDSKBDIACRUC - if (kmap.prefer_unicode) { + if (kmap->prefer_unicode) { fprintf(fd, "\nstruct kbdiacruc accent_table[MAX_DIACR] = {\n"); - for (i = 0; i < kmap.accent_table_size; i++) { + for (i = 0; i < kmap->accent_table_size; i++) { fprintf(fd, "\t{"); - outchar(fd, kmap.accent_table[i].diacr, 1); - outchar(fd, kmap.accent_table[i].base, 1); - fprintf(fd, "0x%04x},", kmap.accent_table[i].result); + outchar(fd, kmap->accent_table[i].diacr, 1); + outchar(fd, kmap->accent_table[i].base, 1); + fprintf(fd, "0x%04x},", kmap->accent_table[i].result); if (i % 2) fprintf(fd, "\n"); } @@ -884,11 +916,11 @@ mktable(FILE *fd) #endif { fprintf(fd, "\nstruct kbdiacr accent_table[MAX_DIACR] = {\n"); - for (i = 0; i < kmap.accent_table_size; i++) { + for (i = 0; i < kmap->accent_table_size; i++) { fprintf(fd, "\t{"); - outchar(fd, kmap.accent_table[i].diacr, 1); - outchar(fd, kmap.accent_table[i].base, 1); - outchar(fd, kmap.accent_table[i].result, 0); + outchar(fd, kmap->accent_table[i].diacr, 1); + outchar(fd, kmap->accent_table[i].base, 1); + outchar(fd, kmap->accent_table[i].result, 0); fprintf(fd, "},"); if (i % 2) fprintf(fd, "\n"); @@ -897,12 +929,12 @@ mktable(FILE *fd) fprintf(fd, "\n"); fprintf(fd, "};\n\n"); } - fprintf(fd, "unsigned int accent_table_size = %d;\n", kmap.accent_table_size); + fprintf(fd, "unsigned int accent_table_size = %d;\n", kmap->accent_table_size); return 0; } static int -bkeymap(void) +bkeymap(struct keymap *kmap) { int i, j; @@ -913,14 +945,14 @@ bkeymap(void) if (write(1, magic, 7) == -1) goto fail; for (i = 0; i < MAX_NR_KEYMAPS; i++) { - flag = kmap.key_map[i] ? 1 : 0; + flag = kmap->key_map[i] ? 1 : 0; if (write(1, &flag, 1) == -1) goto fail; } for (i = 0; i < MAX_NR_KEYMAPS; i++) { - if (kmap.key_map[i]) { + if (kmap->key_map[i]) { for (j = 0; j < NR_KEYS / 2; j++) { - v = kmap.key_map[i][j]; + v = kmap->key_map[i][j]; if (write(1, &v, 2) == -1) goto fail; } @@ -951,41 +983,41 @@ line : EOL ; charsetline : CHARSET STRLITERAL EOL { - if (set_charset((char *) kmap.string)) + if (set_charset((char *) $2.data)) YYERROR; /* Unicode: The first 256 code points were made identical to the content of ISO 8859-1 */ - if (kmap.prefer_unicode && - !strcasecmp((char *) kmap.string, "iso-8859-1")) - kmap.prefer_unicode = 0; + if (kmap->prefer_unicode && + !strcasecmp((char *) $2.data, "iso-8859-1")) + kmap->prefer_unicode = 0; } ; altismetaline : ALT_IS_META EOL { - kmap.alt_is_meta = 1; + kmap->alt_is_meta = 1; } ; usualstringsline: STRINGS AS USUAL EOL { - if (strings_as_usual() == -1) + if (strings_as_usual(kmap) == -1) YYERROR; } ; usualcomposeline: COMPOSE AS USUAL FOR STRLITERAL EOL { - if (compose_as_usual((char *) kmap.string) == -1) + if (compose_as_usual(kmap, (char *) $5.data) == -1) YYERROR; } | COMPOSE AS USUAL EOL { - if (compose_as_usual(0) == -1) + if (compose_as_usual(kmap, 0) == -1) YYERROR; } ; keymapline : KEYMAPS range EOL { - kmap.keymaps_line_seen = 1; + kmap->keymaps_line_seen = 1; } ; range : range COMMA range0 @@ -995,13 +1027,13 @@ range0 : NUMBER DASH NUMBER { int i; for (i = $1; i <= $3; i++) { - if (addmap(i,1) == -1) + if (addmap(kmap, i, 1) == -1) YYERROR; } } | NUMBER { - if (addmap($1,1) == -1) + if (addmap(kmap, $1, 1) == -1) YYERROR; } ; @@ -1010,29 +1042,30 @@ strline : STRING LITERAL EQUALS STRLITERAL EOL struct kbsentry ke; if (KTYP($2) != KT_FN) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("'%s' is not a function key symbol"), syms[KTYP($2)].table[KVAL($2)]); YYERROR; } + ke.kb_func = KVAL($2); strncpy((char *) ke.kb_string, - (char *) kmap.string, + (char *) $4.data, sizeof(ke.kb_string)); ke.kb_string[sizeof(ke.kb_string) - 1] = 0; - if (addfunc(ke) == -1) + if (addfunc(kmap, ke) == -1) YYERROR; } ; compline : COMPOSE compsym compsym TO compsym EOL { - if (compose($2, $3, $5) == -1) + if (compose(kmap, $2, $3, $5) == -1) YYERROR; } | COMPOSE compsym compsym TO rvalue EOL { - if (compose($2, $3, $5) == -1) + if (compose(kmap, $2, $3, $5) == -1) YYERROR; } ; @@ -1040,81 +1073,81 @@ compsym : CCHAR { $$ = $1; } | UNUMBER { $$ = $1 ^ 0xf000; } ; singleline : { - kmap.mod = 0; + kmap->mod = 0; } modifiers KEYCODE NUMBER EQUALS rvalue EOL { - if (addkey($4, kmap.mod, $6) == -1) + if (addkey(kmap, $4, kmap->mod, $6) == -1) YYERROR; } | PLAIN KEYCODE NUMBER EQUALS rvalue EOL { - if (addkey($3, 0, $5) == -1) + if (addkey(kmap, $3, 0, $5) == -1) YYERROR; } ; modifiers : modifiers modifier | modifier ; -modifier : SHIFT { kmap.mod |= M_SHIFT; } - | CONTROL { kmap.mod |= M_CTRL; } - | ALT { kmap.mod |= M_ALT; } - | ALTGR { kmap.mod |= M_ALTGR; } - | SHIFTL { kmap.mod |= M_SHIFTL; } - | SHIFTR { kmap.mod |= M_SHIFTR; } - | CTRLL { kmap.mod |= M_CTRLL; } - | CTRLR { kmap.mod |= M_CTRLR; } - | CAPSSHIFT { kmap.mod |= M_CAPSSHIFT; } +modifier : SHIFT { kmap->mod |= M_SHIFT; } + | CONTROL { kmap->mod |= M_CTRL; } + | ALT { kmap->mod |= M_ALT; } + | ALTGR { kmap->mod |= M_ALTGR; } + | SHIFTL { kmap->mod |= M_SHIFTL; } + | SHIFTR { kmap->mod |= M_SHIFTR; } + | CTRLL { kmap->mod |= M_CTRLL; } + | CTRLR { kmap->mod |= M_CTRLR; } + | CAPSSHIFT { kmap->mod |= M_CAPSSHIFT; } ; fullline : KEYCODE NUMBER EQUALS rvalue0 EOL { int i, j, keycode; - if (kmap.rvalct == 1) { + if (kmap->rvalct == 1) { /* Some files do not have a keymaps line, and * we have to wait until all input has been read * before we know which maps to fill. */ - kmap.key_is_constant[$2] = 1; + kmap->key_is_constant[$2] = 1; /* On the other hand, we now have include files, * and it should be possible to override lines * from an include file. So, kill old defs. */ - for (j = 0; j < kmap.max_keymap; j++) { - if (!(kmap.defining[j])) + for (j = 0; j < kmap->max_keymap; j++) { + if (!(kmap->defining[j])) continue; - if (killkey($2, j) == -1) + if (killkey(kmap, $2, j) == -1) YYERROR; } } - if (kmap.keymaps_line_seen) { + if (kmap->keymaps_line_seen) { i = 0; - for (j = 0; j < kmap.max_keymap; j++) { - if (!(kmap.defining[j])) + for (j = 0; j < kmap->max_keymap; j++) { + if (!(kmap->defining[j])) continue; - if (kmap.rvalct != 1 || i == 0) { - keycode = (i < kmap.rvalct) - ? kmap.key_buf[i] + if (kmap->rvalct != 1 || i == 0) { + keycode = (i < kmap->rvalct) + ? kmap->key_buf[i] : K_HOLE; - if (addkey($2, j, keycode) == -1) + if (addkey(kmap, $2, j, keycode) == -1) YYERROR; } i++; } - if (i < kmap.rvalct) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (i < kmap->rvalct) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("too many (%d) entries on one line"), - kmap.rvalct); + kmap->rvalct); YYERROR; } } else { - for (i = 0; i < kmap.rvalct; i++) { - if (addkey($2, i, kmap.key_buf[i]) == -1) + for (i = 0; i < kmap->rvalct; i++) { + if (addkey(kmap, $2, i, kmap->key_buf[i]) == -1) YYERROR; } } @@ -1126,44 +1159,54 @@ rvalue0 : ; rvalue1 : rvalue { - if (kmap.rvalct >= MAX_NR_KEYMAPS) { - snprintf(kmap.errmsg, sizeof(kmap.errmsg), + if (kmap->rvalct >= MAX_NR_KEYMAPS) { + snprintf(kmap->errmsg, sizeof(kmap->errmsg), _("too many key definitions on one line")); YYERROR; } - kmap.key_buf[kmap.rvalct++] = $1; + kmap->key_buf[kmap->rvalct++] = $1; } ; -rvalue : NUMBER { $$ = convert_code(kmap.prefer_unicode, $1, TO_AUTO); } - | PLUS NUMBER { $$ = add_capslock(kmap.prefer_unicode, $2); } - | UNUMBER { $$ = convert_code(kmap.prefer_unicode, $1^0xf000, TO_AUTO); } - | PLUS UNUMBER { $$ = add_capslock(kmap.prefer_unicode, $2^0xf000); } +rvalue : NUMBER { $$ = convert_code(kmap->prefer_unicode, $1, TO_AUTO); } + | PLUS NUMBER { $$ = add_capslock(kmap->prefer_unicode, $2); } + | UNUMBER { $$ = convert_code(kmap->prefer_unicode, $1^0xf000, TO_AUTO); } + | PLUS UNUMBER { $$ = add_capslock(kmap->prefer_unicode, $2^0xf000); } | LITERAL { $$ = $1; } - | PLUS LITERAL { $$ = add_capslock(kmap.prefer_unicode, $2); } + | PLUS LITERAL { $$ = add_capslock(kmap->prefer_unicode, $2); } ; %% static int -parse_keymap(lkfile_t *f) +parse_keymap(struct keymap *kmap, lkfile_t *f) { - lkverbose(1, _("Loading %s"), f->pathname); + yyscan_t scanner; + int rc = -1; - kmap.errmsg[0] = '\0'; + yylex_init(&scanner); + yylex_init_extra(kmap, &scanner); - if (stack_push(f) == -1) { - lkerror("%s", kmap.errmsg); - return -1; + lkverbose(kmap, 1, _("Loading %s"), f->pathname); + + kmap->errmsg[0] = '\0'; + + if (stack_push(kmap, f, scanner) == -1) { + lkerror("%s", kmap->errmsg); + goto fail; } - if (yyparse()) { - if (strlen(kmap.errmsg) > 0) - lkerror("%s", kmap.errmsg); + if (yyparse(scanner, kmap)) { + if (strlen(kmap->errmsg) > 0) + lkerror("%s", kmap->errmsg); else lkerror(_("syntax error in map file")); - - return -1; + goto fail; } - return 0; + rc = 0; + + stack_pop(kmap, scanner); + + fail: yylex_destroy(scanner); + return rc; } int main(int argc, char *argv[]) @@ -1194,6 +1237,8 @@ int main(int argc, char *argv[]) }; int options = 0; + struct keymap kmap; + int c, i, rc = -1; int fd; int kbd_mode; @@ -1306,7 +1351,7 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - if ((rc = parse_keymap(&f)) == -1) + if ((rc = parse_keymap(&kmap, &f)) == -1) goto fail; @@ -1314,7 +1359,7 @@ int main(int argc, char *argv[]) f.fd = stdin; strcpy(f.pathname, ""); - if ((rc = parse_keymap(&f)) == -1) + if ((rc = parse_keymap(&kmap, &f)) == -1) goto fail; } @@ -1328,22 +1373,22 @@ int main(int argc, char *argv[]) goto fail; } - if ((rc = parse_keymap(&f)) == -1) + if ((rc = parse_keymap(&kmap, &f)) == -1) goto fail; } - if ((rc = do_constant()) == -1) + if ((rc = do_constant(&kmap)) == -1) goto fail; if (options & OPT_B) { - rc = bkeymap(); + rc = bkeymap(&kmap); } else if (options & OPT_M) { - rc = mktable(stdout); + rc = mktable(&kmap, stdout); } else { - rc = loadkeys(fd, kbd_mode); + rc = loadkeys(&kmap, fd, kbd_mode); } - fail: freekeys(); + fail: freekeys(&kmap); close(fd); if (rc < 0) -- 2.7.4