Big rename functions and source files
[platform/upstream/kbd.git] / src / libkeymap / common.c
1 #include <string.h>
2 #include <stdlib.h>
3 #include <stdarg.h>
4
5 #include "kbd.h"
6 #include "keymap.h"
7
8 static void attr_fmt45
9 lkmessage(const char *file attr_unused, int line attr_unused, const char *fn attr_unused,
10           const char *fmt, ...)
11 {
12         va_list ap;
13         va_start(ap, fmt);
14 #ifdef DEBUG
15         fprintf(stdout, "%s(%d): %s: ", file, line, fn);
16 #endif
17         vfprintf(stdout, fmt, ap);
18         fprintf(stdout, "\n");
19         va_end(ap);
20 }
21
22 static void attr_fmt45
23 lkerror(const char *file attr_unused, int line attr_unused, const char *fn attr_unused,
24         const char *fmt, ...)
25 {
26         va_list ap;
27         va_start(ap, fmt);
28         vfprintf(stderr, fmt, ap);
29         fprintf(stderr, "\n");
30         va_end(ap);
31 }
32
33 int
34 lk_init(struct keymap *km)
35 {
36         memset(km, 0, sizeof(struct keymap));
37
38         km->verbose     = LOG_NORMAL;
39         km->log_message = lkmessage;
40         km->log_error   = lkerror;
41
42         return 0;
43 }
44
45
46 void
47 lk_free(struct keymap *kmap)
48 {
49         int i;
50         for (i = 0; i < MAX_NR_KEYMAPS; i++) {
51                 if (kmap->keymap_was_set[i] != NULL)
52                         free(kmap->keymap_was_set[i]);
53                 if (kmap->key_map[i] != NULL)
54                         free(kmap->key_map[i]);
55         }
56 }