summaryrefslogtreecommitdiff
path: root/rcm-server-keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'rcm-server-keymap.c')
-rw-r--r--rcm-server-keymap.c56
1 files changed, 31 insertions, 25 deletions
diff --git a/rcm-server-keymap.c b/rcm-server-keymap.c
index 3231ed2..d2a01c8 100644
--- a/rcm-server-keymap.c
+++ b/rcm-server-keymap.c
@@ -163,8 +163,8 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap,
if (!keymap->name)
return -ENOMEM;
} else if (!strcasecmp(p, "Description")) {
- keymap->desc = strdup(tmp);
- if (!keymap->desc)
+ keymap->description = strdup(tmp);
+ if (!keymap->description)
return -ENOMEM;
}
break;
@@ -315,7 +315,7 @@ keymap_parse(FILE *fp, char **line, size_t *buf_size, struct keymap *keymap,
}
static struct keymap *
-keymap_read(int dfd, const char *name)
+keymap_read(int dfd, const char *filename)
{
_cleanup_close_ int fd = -1;
_cleanup_fclose_ FILE *fp = NULL;
@@ -326,46 +326,51 @@ keymap_read(int dfd, const char *name)
size_t buf_size = 0;
int r;
- if (dfd < 0 || !name)
- return NULL;
+ if (dfd < 0 || !filename)
+ goto out;
- fd = openat(dfd, name, O_RDONLY);
+ fd = openat(dfd, filename, O_RDONLY);
if (fd < 0)
- return NULL;
+ goto out;
fp = fdopen(fd, "r");
if (!fp)
- return NULL;
+ goto out;
fd = -1;
- printf("Parsing keymap %s...\n", name);
+ printf("Parsing keymap %s...\n", filename);
r = keymap_parse(fp, &line, &buf_size, NULL, &rows, &cols, &keycode_count);
if (r < 0)
- return NULL;
+ goto out;
keymap = zmalloc(sizeof(*keymap) + sizeof(struct keycode) * keycode_count);
if (!keymap)
- return NULL;
+ goto out;
+
+ keymap->id = strdup(filename);
+ if (!keymap->id)
+ goto out;
keymap->layout = zmalloc(sizeof(struct keycode *) * cols * rows);
- if (!keymap->layout) {
- free(keymap);
- return NULL;
- }
+ if (!keymap->layout)
+ goto out;
r = keymap_parse(fp, &line, &buf_size, keymap, NULL, NULL, NULL);
- if (r < 0) {
- free(keymap->layout);
- free(keymap);
- return NULL;
- }
+ if (r < 0)
+ goto out;
printf("\tKeymap added\n");
- printf("\tDescription: %s\n", keymap->desc);
+ printf("\tID: %s\n", keymap->id);
printf("\tName: %s\n", keymap->name);
+ printf("\tDescription: %s\n", keymap->description);
printf("\tMappings: %u entries\n", keycode_count);
printf("\tLayout: %u rows x %u cols = %u entries\n", rows, cols, rows * cols);
return keymap;
+
+out:
+ if (keymap)
+ keymap_free(keymap);
+ return NULL;
}
static int
@@ -389,7 +394,7 @@ keymaps_load_dir(struct device *device, const char *path)
case DT_REG:
case DT_LNK:
case DT_UNKNOWN:
- keymap = find_keymap_by_name(device, dent->d_name);
+ keymap = find_keymap_by_id(device, dent->d_name);
if (keymap)
continue;
keymap = keymap_read(dfd, dent->d_name);
@@ -424,17 +429,18 @@ keymap_free(struct keymap *keymap)
{
free(keymap->layout);
free(keymap->name);
- free(keymap->desc);
+ free(keymap->description);
+ free(keymap->id);
free(keymap);
}
struct keymap *
-find_keymap_by_name(struct device *dev, const char *name)
+find_keymap_by_id(struct device *dev, const char *id)
{
struct keymap *keymap;
list_for_each_entry(keymap, &dev->keymaps, list)
- if (!strcmp(keymap->name, name))
+ if (!strcmp(keymap->id, id))
return keymap;
return NULL;