Broke backward compatibility: lk_dump_symbols.
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
if (long_info) {
printf(_("Symbols recognized by %s:\n(numeric value, symbol)\n\n"),
progname);
- lk_dump_symbols(stdout);
+ lk_dump_symbols(ctx, stdout);
}
exit(EXIT_SUCCESS);
}
if (!ptr)
continue;
- fprintf(fd, "string %s = \"", syms[KT_FN].table[i]);
+ fprintf(fd, "string %s = \"", get_sym(ctx, KT_FN, i));
for (; *ptr; ptr++) {
if (*ptr == '"' || *ptr == '\\') {
static void
print_keysym(struct lk_ctx *ctx, FILE *fd, int code, char numeric)
{
- unsigned int t;
- int v;
+ unsigned int t, v;
const char *p;
int plus;
fprintf(fd, "+");
plus++;
}
- if (!numeric && t < syms_size && v < syms[t].size &&
- (p = syms[t].table[v])[0])
+ if (!numeric && t < syms_size && v < get_sym_size(ctx, t) &&
+ (p = get_sym(ctx, t, v))[0])
fprintf(fd, "%-*s", 16 - plus, p);
- else if (!numeric && t == KT_META && v < 128 && v < syms[0].size &&
- (p = syms[0].table[v])[0])
+ else if (!numeric && t == KT_META && v < 128 && v < get_sym_size(ctx, KT_LATIN) &&
+ (p = get_sym(ctx, KT_LATIN, v))[0])
fprintf(fd, "Meta_%-11s", p);
else
fprintf(fd, "0x%04x %s", code, plus ? "" : " ");
*/
char *lk_code_to_ksym(struct lk_ctx *ctx, int code);
+char *lk_get_sym(struct lk_ctx *ctx, unsigned int ktype, unsigned int index);
+
/**
* Converts a string to a numeric representation of the character.
* @param ctx is a keymap library context.
int lk_get_kmapinfo(struct lk_ctx *ctx, struct kmapinfo *res);
void lk_dump_summary(struct lk_ctx *ctx, FILE *fd, int console);
-void lk_dump_symbols(FILE *fd);
+void lk_dump_symbols(struct lk_ctx *ctx, FILE *fd);
#endif /* LK_DUMP_H */
return 1;
}
+unsigned int
+get_sym_size(struct lk_ctx *ctx, unsigned int ktype)
+{
+ if (ktype >= syms_size) {
+ ERR(ctx, _("unable to get symbol by wrong type: %d"), ktype);
+ return 0;
+ }
+
+ return syms[ktype].size;
+}
+
+const char *
+get_sym(struct lk_ctx *ctx, unsigned int ktype, unsigned int index)
+{
+ if (!get_sym_size(ctx, ktype))
+ return NULL;
+
+ if (index >= syms[ktype].size) {
+ ERR(ctx, _("unable to get symbol of %d type by wrong index: %d"), ktype, index);
+ return NULL;
+ }
+
+ return syms[ktype].table[index];
+}
+
+char *
+lk_get_sym(struct lk_ctx *ctx, unsigned int ktype, unsigned int index)
+{
+ const char *ksym = get_sym(ctx, ktype, index);
+ return (ksym ? strdup(ksym) : NULL);
+}
+
const char *
codetoksym(struct lk_ctx *ctx, int code) {
unsigned int i;
if (code < 0x1000) { /* "traditional" keysym */
if (code < 0x80)
- return iso646_syms[code];
+ return get_sym(ctx, KT_LATIN, code);
if (KTYP(code) == KT_META)
return NULL;
code = K(KT_LATIN, KVAL(code));
if (KTYP(code) > KT_LATIN)
- return syms[KTYP(code)].table[KVAL(code)];
+ return get_sym(ctx, KTYP(code), KVAL(code));
i = ctx->charset;
while (1) {
code ^= 0xf000;
if (code < 0x80)
- return iso646_syms[code];
+ return get_sym(ctx, KT_LATIN, code);
i = ctx->charset;
while (1) {
char *
lk_code_to_ksym(struct lk_ctx *ctx, int code)
{
- const char *sym;
+ const char *s;
- sym = codetoksym(ctx, code);
- if (!sym)
+ s = codetoksym(ctx, code);
+ if (!s)
return NULL;
- return strdup(sym);
+ return strdup(s);
}
/* Functions for loadkeys. */
static int
kt_latin(struct lk_ctx *ctx, const char *s, int direction) {
- int i, max;
+ unsigned int i, max;
if (ctx->charset) {
sym *p = (sym *) charsets[ctx->charset].charnames;
max = (direction == TO_UNICODE ? 128 : syms[KT_LATIN].size);
for (i = 0; i < max; i++) {
- if (!strcmp(s, syms[KT_LATIN].table[i]))
+ if (!strcmp(s, get_sym(ctx, KT_LATIN, i)))
return K(KT_LATIN, i);
}
int
ksymtocode(struct lk_ctx *ctx, const char *s, int direction) {
- unsigned int i;
- int n, j;
+ unsigned int i, j;
+ int n;
int keycode;
sym *p;
for (i = 1; i < syms_size; i++) {
for (j = 0; j < syms[i].size; j++) {
- if (!strcmp(s,syms[i].table[j]))
+ if (!strcmp(s, get_sym(ctx, i, j)))
return K(i, j);
}
}
typedef struct {
const char * const *table;
- const int size;
+ const unsigned int size;
} syms_entry;
-extern syms_entry const syms[];
-
struct syn {
const char *synonym;
const char *official_name;
#define TO_8BIT 0
#define TO_UNICODE 1
+const char *get_sym(struct lk_ctx *ctx, unsigned int ktype, unsigned int index);
+unsigned int get_sym_size(struct lk_ctx *ctx, unsigned int ktype);
+
const char *codetoksym(struct lk_ctx *ctx, int code);
int ksymtocode(struct lk_ctx *ctx, const char *s, int direction);
int convert_code(struct lk_ctx *ctx, int code, int direction);
if (s == NULL)
return -1;
ERR(ctx, _("failed to bind string '%s' to function %s"),
- s, syms[KT_FN].table[kbs.kb_func]);
+ s, get_sym(ctx, KT_FN, kbs.kb_func));
free(s);
} else {
ct++;
if (ioctl(fd, KDSKBSENT, (unsigned long)&kbs)) {
ERR(ctx, _("failed to clear string %s"),
- syms[KT_FN].table[kbs.kb_func]);
+ get_sym(ctx, KT_FN, kbs.kb_func));
} else {
ct++;
}
if (KTYP($2) != KT_FN) {
ERR(ctx, _("'%s' is not a function key symbol"),
- syms[KTYP($2)].table[KVAL($2)]);
+ get_sym(ctx, KTYP($2), KVAL($2)));
YYERROR;
}
}
void
-lk_dump_symbols(FILE *fd)
+lk_dump_symbols(struct lk_ctx *ctx, FILE *fd)
{
- unsigned int t;
+ unsigned int t, v;
modifier_t *mod;
- int v;
const char *p;
for (t = 0; t < syms_size; t++) {
- if (syms[t].size) {
- for (v = 0; v < syms[t].size; v++) {
- if ((p = syms[t].table[v])[0])
+ if (get_sym_size(ctx, t)) {
+ for (v = 0; v < get_sym_size(ctx, t); v++) {
+ if ((p = get_sym(ctx, t, v))[0])
fprintf(fd, "0x%04x\t%s\n", K(t, v), p);
}
} else if (t == KT_META) {
- for (v = 0; v < syms[0].size && v < 128; v++) {
- if ((p = syms[0].table[v])[0])
+ for (v = 0; v < get_sym_size(ctx, KT_LATIN) && v < 128; v++) {
+ if ((p = get_sym(ctx, KT_LATIN, v))[0])
fprintf(fd, "0x%04x\tMeta_%s\n", K(t, v), p);
}
}