{Comment}.*/{Eol} ; /* do nothing */
{Equals} {
yy_push_state(RVALUE, yyscanner);
- yyextra->rvalct = 0;
+ lk_array_empty(yyextra->key_line);
return(EQUALS);
}
{String} {
}
int
+lk_array_empty(struct lk_array *a)
+{
+ if (!a)
+ return -EINVAL;
+
+ memset(a->array, 0, (a->memb * a->total));
+ a->count = 0;
+
+ return 0;
+}
+
+int
lk_array_exist(struct lk_array *a, unsigned int i)
{
char *s;
return 0;
}
+
+int
+lk_array_append(struct lk_array *a, const void *e)
+{
+ int ret = array_resize(a, a->count);
+
+ if (ret < 0)
+ return ret;
+
+ memcpy(a->array + (a->memb * a->count), e, a->memb);
+ a->count++;
+
+ return 0;
+}
lk_set_log_priority(kmap, LOG_ERR);
kmap->keymap = malloc(sizeof(struct lk_array));
- if (!(kmap->keymap)) {
- ERR(kmap, "out of memory");
- return -1;
- }
+ kmap->key_constant = malloc(sizeof(struct lk_array));
+ kmap->key_line = malloc(sizeof(struct lk_array));
- if (lk_array_init(kmap->keymap, sizeof(void *), 0) < 0) {
+ if (!(kmap->keymap) || !(kmap->key_constant) || !(kmap->key_line)) {
ERR(kmap, "out of memory");
return -1;
}
+ lk_array_init(kmap->keymap, sizeof(void*), 0);
+ lk_array_init(kmap->key_constant, sizeof(char), 0);
+ lk_array_init(kmap->key_line, sizeof(int), 0);
+
return 0;
}
kmap->keymap = NULL;
}
+ if (kmap->key_constant) {
+ lk_array_free(kmap->key_constant);
+ free(kmap->key_constant);
+ kmap->key_constant = NULL;
+ }
+
+ if (kmap->key_line) {
+ lk_array_free(kmap->key_line);
+ free(kmap->key_line);
+ kmap->key_line = NULL;
+ }
+
return 0;
}
int lk_array_init(struct lk_array *a, size_t memb, size_t size);
int lk_array_free(struct lk_array *a);
+int lk_array_empty(struct lk_array *a);
+
+int lk_array_append(struct lk_array *a, const void *e);
+
int lk_array_set(struct lk_array *a, unsigned int i, const void *e);
void *lk_array_get(struct lk_array *a, unsigned int i);
void *lk_array_get_ptr(struct lk_array *a, unsigned int i);
accent_entry accent_table[MAX_DIACR];
unsigned int accent_table_size;
- char key_is_constant[NR_KEYS];
+ struct lk_array *key_constant;
- int mod; /* Line by line modifiers */
- int key_buf[MAX_NR_KEYMAPS]; /* Key definitions on one line */
+ /* Key definitions on one line */
+ struct lk_array *key_line;
+
+ /* Line by line modifiers */
+ int mod;
unsigned int charset;
- int rvalct;
lkfile_t *stack[MAX_INCLUDE_DEPTH];
int log_priority;
r0++;
}
- for (i = 0; i < NR_KEYS; i++) {
+ for (i = 0; i < kmap->key_constant->total; i++) {
+ char *constant;
u_short key;
- if (!kmap->key_is_constant[i])
+ constant = lk_array_get(kmap->key_constant, i);
+ if (!constant || !(*constant))
continue;
if (!lk_map_exist(kmap, r0)) {
;
fullline : KEYCODE NUMBER EQUALS rvalue0 EOL
{
- unsigned int j;
- int i, keycode;
+ unsigned int j, i, keycode;
+ int *val;
- if (kmap->rvalct == 1) {
+ if (kmap->key_line->count == 1) {
+ char one = 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;
+ lk_array_set(kmap->key_constant, $2, &one);
/* On the other hand, we now have include files,
* and it should be possible to override lines
if (!lk_map_exist(kmap, j))
continue;
- if (kmap->rvalct != 1 || i == 0) {
- keycode = (i < kmap->rvalct)
- ? kmap->key_buf[i]
- : K_HOLE;
+ if (kmap->key_line->count != 1 || i == 0) {
+ keycode = K_HOLE;
+
+ if (i < kmap->key_line->count) {
+ val = lk_array_get(kmap->key_line, i);
+ keycode = *val;
+ }
if (lk_add_key(kmap, j, $2, keycode) < 0)
YYERROR;
i++;
}
- if (i < kmap->rvalct) {
+ if (i < kmap->key_line->count) {
ERR(kmap, _("too many (%d) entries on one line"),
- kmap->rvalct);
+ kmap->key_line->count);
YYERROR;
}
} else {
- for (i = 0; i < kmap->rvalct; i++) {
- if (lk_add_key(kmap, i, $2, kmap->key_buf[i]) < 0)
+ for (i = 0; i < kmap->key_line->count; i++) {
+ val = lk_array_get(kmap->key_line, i);
+
+ if (lk_add_key(kmap, i, $2, *val) < 0)
YYERROR;
}
}
;
rvalue1 : rvalue
{
- if (kmap->rvalct >= MAX_NR_KEYMAPS) {
- ERR(kmap, _("too many key definitions on one line"));
- YYERROR;
- }
- kmap->key_buf[kmap->rvalct++] = $1;
+ int val = $1;
+ lk_array_append(kmap->key_line, &val);
}
;
rvalue : NUMBER { $$ = convert_code(kmap, $1, TO_AUTO); }