Add summary functions
authorAlexey Gladkov <gladkov.alexey@gmail.com>
Sun, 6 Jan 2013 21:14:59 +0000 (01:14 +0400)
committerAlexey Gladkov <gladkov.alexey@gmail.com>
Sun, 6 Jan 2013 21:14:59 +0000 (01:14 +0400)
Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
src/libkeymap/Makefile.am
src/libkeymap/dump.c
src/libkeymap/keymap.h
src/libkeymap/modifiers.c [new file with mode: 0644]
src/libkeymap/modifiers.h
src/libkeymap/parse.y
src/libkeymap/summary.c [new file with mode: 0644]

index 7357f77..5cf18c8 100644 (file)
@@ -14,8 +14,9 @@ libkeymap_la_SOURCES = \
        parse.y analyze.l \
        load.c \
        dump.c keymap.h \
-       modifiers.h \
+       modifiers.c modifiers.h \
        ksyms.c ksyms.h cp1250.syms.h ethiopic.syms.h koi8.syms.h sami.syms.h thai.syms.h \
+       summary.c \
        $(ALL_S)
 
 AM_LFLAGS = --header-file=$(CURDIR)/analyze.h
index 697c982..3814795 100644 (file)
@@ -270,31 +270,15 @@ dump_keymaps(struct keymap *kmap, FILE *fd)
        fprintf(fd, "\n");
 }
 
-static const struct {
-       const char *name;
-       const int bit;
-} modifiers[] = {
-       { "shift",      KG_SHIFT     },
-       { "altgr",      KG_ALTGR     },
-       { "control",    KG_CTRL      },
-       { "alt",        KG_ALT       },
-       { "shiftl",     KG_SHIFTL    },
-       { "shiftr",     KG_SHIFTR    },
-       { "ctrll",      KG_CTRLL     },
-       { "ctrlr",      KG_CTRLR     },
-       { "capsshift",  KG_CAPSSHIFT }
-};
-
-
 static void
 print_mod(FILE *fd, int x)
 {
        if (x) {
-               unsigned int t;
-
-               for (t = 0; t < sizeof(modifiers)/sizeof(modifiers[0]); t++) {
-                       if (x & (1 << modifiers[t].bit))
-                               fprintf(fd, "%s\t", modifiers[t].name);
+               modifier_t *mod = (modifier_t *) modifiers;
+               while (mod->name) {
+                       if (x & (1 << mod->bit))
+                               fprintf(fd, "%s\t", mod->name);
+                       mod++;
                }
        } else {
                fprintf(fd, "plain\t");
index 38d9cb6..826c4e8 100644 (file)
@@ -115,4 +115,7 @@ void dump_diacs(struct keymap *kmap, FILE *fd);
 
 void dump_keys(struct keymap *kmap, FILE *fd, char table_shape, char numeric);
 
+void dump_summary(struct keymap *kmap, FILE *fd, int console);
+void dump_symbols(FILE *fd);
+
 #endif /* LK_KEYMAP_H */
diff --git a/src/libkeymap/modifiers.c b/src/libkeymap/modifiers.c
new file mode 100644 (file)
index 0000000..0f66554
--- /dev/null
@@ -0,0 +1,14 @@
+#include "modifiers.h"
+
+const modifier_t modifiers[] = {
+       { "shift",      KG_SHIFT     },
+       { "altgr",      KG_ALTGR     },
+       { "control",    KG_CTRL      },
+       { "alt",        KG_ALT       },
+       { "shiftl",     KG_SHIFTL    },
+       { "shiftr",     KG_SHIFTR    },
+       { "ctrll",      KG_CTRLL     },
+       { "ctrlr",      KG_CTRLR     },
+       { "capsshift",  KG_CAPSSHIFT },
+       { 0,            0            }
+};
index afcadf5..a385039 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef _MODIFIERS_H
 #define _MODIFIERS_H
 
+#include  <linux/keyboard.h>
+
 #define M_PLAIN  0
 #define M_SHIFT  (1 << KG_SHIFT)
 #define M_CTRL   (1 << KG_CTRL)
 #define M_CTRLR  (1 << KG_CTRLR)
 #define M_CAPSSHIFT (1 << KG_CAPSSHIFT)
 
+typedef struct {
+       const char *name;
+       const int bit;
+} modifier_t;
+
+extern const modifier_t modifiers[];
+
 #endif /* _MODIFIERS_H */
index 50b2f5a..f27766b 100644 (file)
@@ -692,7 +692,7 @@ compose_as_usual(struct keymap *kmap, char *charset)
 char *
 mk_mapname(char modifier)
 {
-       static char *modifiers[8] = {
+       static char *mods[8] = {
                "shift", "altgr", "ctrl", "alt", "shl", "shr", "ctl", "ctr"
        };
        static char buf[60];
@@ -705,7 +705,7 @@ mk_mapname(char modifier)
                if (modifier & (1 << i)) {
                        if (buf[0])
                                strcat(buf, "_");
-                       strcat(buf, modifiers[i]);
+                       strcat(buf, mods[i]);
                }
        return buf;
 }
diff --git a/src/libkeymap/summary.c b/src/libkeymap/summary.c
new file mode 100644 (file)
index 0000000..e88cecc
--- /dev/null
@@ -0,0 +1,129 @@
+/* summary.c
+ *
+ * This file is part of kbd project.
+ * Copyright (C) 2012-2013  Alexey Gladkov <gladkov.alexey@gmail.com>
+ *
+ * This file is covered by the GNU General Public License,
+ * which should be included with kbd as the file COPYING.
+ */
+#include <string.h>
+#include <errno.h>
+
+#include <sys/ioctl.h>
+
+#include "ksyms.h"
+#include "modifiers.h"
+
+#include "../nls.h"
+#include "keymap.h"
+#include "keymapP.h"
+
+static char
+valid_type(int fd, int t)
+{
+       struct kbentry ke;
+
+       ke.kb_index = 0;
+       ke.kb_table = 0;
+       ke.kb_value = K(t, 0);
+
+       return (ioctl(fd, KDSKBENT, (unsigned long) &ke) == 0);
+}
+
+static u_char
+maximum_val(int fd, int t)
+{
+       struct kbentry ke, ke0;
+       int i;
+
+       ke.kb_index = 0;
+       ke.kb_table = 0;
+       ke.kb_value = K_HOLE;
+       ke0 = ke;
+
+       ioctl(fd, KDGKBENT, (unsigned long) &ke0);
+
+       for (i = 0; i < 256; i++) {
+               ke.kb_value = K(t, i);
+               if (ioctl(fd, KDSKBENT, (unsigned long) &ke))
+                       break;
+       }
+       ke.kb_value = K_HOLE;
+       ioctl(fd, KDSKBENT, (unsigned long) &ke0);
+
+       return i - 1;
+}
+
+#define NR_TYPES 15
+
+void
+dump_summary(struct keymap *kmap, FILE *fd, int console)
+{
+       int i, allocct = 0;
+
+       for (i = 0; i < MAX_NR_KEYMAPS; i++) {
+               if (kmap->key_map[i][0] == K_ALLOCATED)
+                       allocct++;
+       }
+
+       fprintf(fd, _("keycode range supported by kernel:           1 - %d\n"),
+               NR_KEYS - 1);
+       fprintf(fd, _("max number of actions bindable to a key:         %d\n"),
+               MAX_NR_KEYMAPS);
+       fprintf(fd, _("number of keymaps in actual use:                 %d\n"),
+               kmap->max_keymap);
+
+       if (allocct)
+               fprintf(fd, _("of which %d dynamically allocated\n"), allocct);
+
+       fprintf(fd, _("ranges of action codes supported by kernel:\n"));
+
+       for (i = 0; i < NR_TYPES && valid_type(console, i); i++)
+               fprintf(fd, "   0x%04x - 0x%04x\n",
+                       K(i, 0), K(i, maximum_val(console, i)));
+
+       fprintf(fd, _("number of function keys supported by kernel: %d\n"),
+               MAX_NR_FUNC);
+       fprintf(fd, _("max nr of compose definitions: %d\n"),
+               MAX_DIACR);
+       fprintf(fd, _("nr of compose definitions in actual use: %d\n"),
+               kmap->accent_table_size);
+}
+
+void
+dump_symbols(FILE *fd)
+{
+       unsigned int t;
+       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])
+                               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])
+                               fprintf(fd, "0x%04x\tMeta_%s\n", K(t, v), p);
+               }
+           }
+       }
+
+       fprintf(fd, _("\nThe following synonyms are recognized:\n\n"));
+
+       for (t = 0; t < syn_size; t++) {
+               fprintf(fd, _("%-15s for %s\n"),
+                       synonyms[t].synonym, synonyms[t].official_name);
+       }
+
+       fprintf(fd, _("\nRecognized modifier names and their column numbers:\n"));
+
+       mod = (modifier_t *) modifiers;
+       while (mod->name) {
+               fprintf(fd, "%s\t\t%3d\n", mod->name, 1 << mod->bit);
+               mod++;
+       }
+}