M keyboard.c => keyboard.c +3 -3
@@ 15,9 15,9 @@ void
kbd_init(struct kbd *kb) {
fprintf(stderr, "Initializing keyboard\n");
- kb->suggs[0].label = "Hello";
- kb->suggs[1].label = "World";
- kb->suggs[2].label = "World";
+ kb->suggs[0].label = strdup("Hello");
+ kb->suggs[1].label = strdup("Sugar");
+ kb->suggs[2].label = strdup("Pie");
kb->suggs[3].label = NULL;
}
M keyboard.h => keyboard.h +1 -1
@@ 24,7 24,7 @@ struct clr_scheme {
};
struct key {
- const char *label; // primary label
+ char *label;
// actual coordinates on the surface (pixels), will be computed automatically
// for all keys
uint32_t x, y, w, h;
M main.c => main.c +4 -2
@@ 391,7 391,7 @@ handle_input(FILE *fd, struct key *sugg) {
char *l = line;
for (i = 0; l[i+1]; i++) {
if (l[i] == '\t') {
- // free label?
+ free(key->label);
key->label = strndup(l,i);
l += i + 1;
i = 0;
@@ 400,8 400,10 @@ handle_input(FILE *fd, struct key *sugg) {
break;
}
}
+ free(key->label);
key->label = strndup(l,i);
- key+=sizeof(struct key*);
+ key++;
+ free(key->label);
key->label = NULL;
}