Skip to contentSkip to conversation

ir-keytable: Smarter keytable location handling

PATCH New Gregor Jasny 1 participant 4 messages Jun 23, 2012 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

cover ir-keytable: Smarter keytable location handling

Hello,

this patchset will improve the keytable location handling of ir-keytable. In controst to the default install location (/etc/rc_keymaps) Debian and Ubuntu installed the shipped keymaps into /lib/udev/rc_keymaps (just like keyboard keymaps are installed into /lib/udev/keymaps). If a keymap needs to be modified it's supposed to go into /etc/rc_keymaps.

The current ir-keytable program knows only about a single default keytable directory. This patchset makes ir-keytable aware of a system and user keytable directory. The user directory is searched first, followed by a the system directory if no file was found.

Mauro, are you OK with committing?

Thanks,
Gregor

Gregor Jasny (3):
keytable: Make udev rules dir configurable
keytable: Preinstall keytables relative to sysconfdir
keytable: first search table in userdir, then in systemdir

 configure.ac               |   15 +++++++++++----
 utils/keytable/Makefile.am |    8 ++++----
 utils/keytable/keytable.c  |   30 +++++++++++++++++++++---------
 3 files changed, 36 insertions(+), 17 deletions(-)
Signature · 1 line
1.7.10
#1 lore raw

PATCH 1/3 keytable: Make udev rules dir configurable

---
 configure.ac               |    7 +++++--
 utils/keytable/Makefile.am |    1 -
 2 files changed, 5 insertions(+), 3 deletions(-)
configure.ac +5 -2
index 8e166b1..1a12abd 100644
@@ -145,13 +145,16 @@ AC_ARG_WITH(libv4l2subdir, AS_HELP_STRING(--with-libv4l2subdir=DIR,set libv4l2 l
 AC_ARG_WITH(libv4lconvertsubdir, AS_HELP_STRING(--with-libv4lconvertsubdir=DIR,set libv4lconvert library subdir [default=libv4l]),
    libv4lconvertsubdir=$withval, libv4lconvertsubdir="libv4l")
 
+AC_ARG_WITH(udevdir, AS_HELP_STRING(--with-udevdir=DIR,set udev directory [default=/lib/udev]),
+   udevdir=$withval, udevdir="/lib/udev")
+
 libv4l1privdir="$libdir/$libv4l1subdir"
 libv4l2privdir="$libdir/$libv4l2subdir"
 libv4l2plugindir="$libv4l2privdir/plugins"
 libv4lconvertprivdir="$libdir/$libv4lconvertsubdir"
 
 rootetcdir="/etc"
-rootlibdir="/lib"
+udevrulesdir="$udevdir/rules.d"
 pkgconfigdir="$libdir/pkgconfig"
 
 AC_SUBST(libv4l1privdir)
@@ -159,7 +162,7 @@ AC_SUBST(libv4l2privdir)
 AC_SUBST(libv4l2plugindir)
 AC_SUBST(libv4lconvertprivdir)
 AC_SUBST(rootetcdir)
-AC_SUBST(rootlibdir)
+AC_SUBST(udevrulesdir)
 AC_SUBST(pkgconfigdir)
 
 AC_DEFINE_UNQUOTED([V4L_UTILS_VERSION], ["$PACKAGE_VERSION"], [v4l-utils version string])
utils/keytable/Makefile.am +0 -1
index 0321a57..3d510e0 100644
@@ -1,4 +1,3 @@
-udevrulesdir="/lib/udev/rules.d"
 rootetcdir="/etc"
 
 bin_PROGRAMS = ir-keytable
Signature · 1 line
1.7.10
#2 lore raw

PATCH 2/3 keytable: Preinstall keytables relative to sysconfdir

In reply to Gregor Jasny
---
 configure.ac               |    5 +++--
 utils/keytable/Makefile.am |    5 ++---
 utils/keytable/keytable.c  |    7 ++-----
 3 files changed, 7 insertions(+), 10 deletions(-)
configure.ac +3 -2
index 1a12abd..661eb20 100644
@@ -153,7 +153,7 @@ libv4l2privdir="$libdir/$libv4l2subdir"
 libv4l2plugindir="$libv4l2privdir/plugins"
 libv4lconvertprivdir="$libdir/$libv4lconvertsubdir"
 
-rootetcdir="/etc"
+keytablesystemdir="$sysconfdir/rc_keymaps"
 udevrulesdir="$udevdir/rules.d"
 pkgconfigdir="$libdir/pkgconfig"
 
@@ -161,7 +161,7 @@ AC_SUBST(libv4l1privdir)
 AC_SUBST(libv4l2privdir)
 AC_SUBST(libv4l2plugindir)
 AC_SUBST(libv4lconvertprivdir)
-AC_SUBST(rootetcdir)
+AC_SUBST(keytablesystemdir)
 AC_SUBST(udevrulesdir)
 AC_SUBST(pkgconfigdir)
 
@@ -170,6 +170,7 @@ AC_DEFINE_DIR([LIBV4L1_PRIV_DIR], [libv4l1privdir], [libv4l1 private lib directo
 AC_DEFINE_DIR([LIBV4L2_PRIV_DIR], [libv4l2privdir], [libv4l2 private lib directory])
 AC_DEFINE_DIR([LIBV4L2_PLUGIN_DIR], [libv4l2plugindir], [libv4l2 plugin directory])
 AC_DEFINE_DIR([LIBV4LCONVERT_PRIV_DIR], [libv4lconvertprivdir], [libv4lconvert private lib directory])
+AC_DEFINE_DIR([IR_KEYTABLE_SYSTEM_DIR], [keytablesystemdir], [ir-keytable preinstalled tables directory])
 
 # options
 
utils/keytable/Makefile.am +2 -3
index 3d510e0..4505fc1 100644
@@ -1,8 +1,7 @@
-rootetcdir="/etc"
-
 bin_PROGRAMS = ir-keytable
 man_MANS = ir-keytable.1
-nobase_rootetc_DATA = rc_maps.cfg $(srcdir)/rc_keymaps/*
+sysconf_DATA = rc_maps.cfg
+keytablesystem_DATA = $(srcdir)/rc_keymaps/*
 udevrules_DATA = 70-infrared.rules
 
 ir_keytable_SOURCES = keytable.c parse.h
utils/keytable/keytable.c +2 -5
index fbf9c03..31376f3 100644
@@ -28,9 +28,6 @@
 
 #include "parse.h"
 
-/* Default place where the keymaps will be stored */
-#define CFGDIR "/etc/rc_keymaps"
-
 struct input_keymap_entry_v2 {
 #define KEYMAP_BY_INDEX	(1 << 0)
 	u_int8_t  flags;
@@ -1516,8 +1513,8 @@ int main(int argc, char *argv[])
 		if (cur->fname[0] == '/' || ((cur->fname[0] == '.') && strchr(cur->fname, '/'))) {
 			fname = cur->fname;
 		} else {
-			fname = malloc(strlen(cur->fname) + strlen(CFGDIR) + 2);
-			strcpy(fname, CFGDIR);
+			fname = malloc(strlen(cur->fname) + strlen(IR_KEYTABLE_SYSTEM_DIR) + 2);
+			strcpy(fname, IR_KEYTABLE_SYSTEM_DIR);
 			strcat(fname, "/");
 			strcat(fname, cur->fname);
 		}
Signature · 1 line
1.7.10
#3 lore raw

PATCH 3/3 keytable: first search table in userdir, then in systemdir

In reply to Gregor Jasny
---
 configure.ac               |    5 ++++-
 utils/keytable/Makefile.am |    2 ++
 utils/keytable/keytable.c  |   27 +++++++++++++++++++++------
 3 files changed, 27 insertions(+), 7 deletions(-)
configure.ac +4 -1
index 661eb20..a1230b2 100644
@@ -153,7 +153,8 @@ libv4l2privdir="$libdir/$libv4l2subdir"
 libv4l2plugindir="$libv4l2privdir/plugins"
 libv4lconvertprivdir="$libdir/$libv4lconvertsubdir"
 
-keytablesystemdir="$sysconfdir/rc_keymaps"
+keytablesystemdir="$udevdir/rc_keymaps"
+keytableuserdir="$sysconfdir/rc_keymaps"
 udevrulesdir="$udevdir/rules.d"
 pkgconfigdir="$libdir/pkgconfig"
 
@@ -162,6 +163,7 @@ AC_SUBST(libv4l2privdir)
 AC_SUBST(libv4l2plugindir)
 AC_SUBST(libv4lconvertprivdir)
 AC_SUBST(keytablesystemdir)
+AC_SUBST(keytableuserdir)
 AC_SUBST(udevrulesdir)
 AC_SUBST(pkgconfigdir)
 
@@ -171,6 +173,7 @@ AC_DEFINE_DIR([LIBV4L2_PRIV_DIR], [libv4l2privdir], [libv4l2 private lib directo
 AC_DEFINE_DIR([LIBV4L2_PLUGIN_DIR], [libv4l2plugindir], [libv4l2 plugin directory])
 AC_DEFINE_DIR([LIBV4LCONVERT_PRIV_DIR], [libv4lconvertprivdir], [libv4lconvert private lib directory])
 AC_DEFINE_DIR([IR_KEYTABLE_SYSTEM_DIR], [keytablesystemdir], [ir-keytable preinstalled tables directory])
+AC_DEFINE_DIR([IR_KEYTABLE_USER_DIR], [keytableuserdir], [ir-keytable user defined tables directory])
 
 # options
 
utils/keytable/Makefile.am +2 -0
index 4505fc1..886d800 100644
@@ -10,6 +10,8 @@ ir_keytable_LDFLAGS = $(ARGP_LIBS)
 EXTRA_DIST = 70-infrared.rules rc_keymaps gen_keytables.pl ir-keytable.1 rc_maps.cfg
 
 # custom target
+install-data-local:
+	$(install_sh) -d "$(DESTDIR)$(keytableuserdir)"
 
 sync-with-kernel:
 	@if [ ! -f $(KERNEL_DIR)/include/linux/input.h ]; then \
utils/keytable/keytable.c +21 -6
index 31376f3..bccd325 100644
@@ -194,7 +194,6 @@ static error_t parse_keyfile(char *fname, char **table)
 
 	fin = fopen(fname, "r");
 	if (!fin) {
-		perror("opening keycode file");
 		return errno;
 	}
 
@@ -1512,15 +1511,31 @@ int main(int argc, char *argv[])
 				cur->fname);
 		if (cur->fname[0] == '/' || ((cur->fname[0] == '.') && strchr(cur->fname, '/'))) {
 			fname = cur->fname;
+			rc = parse_keyfile(fname, &name);
+			if (rc < 0) {
+				fprintf(stderr, "Can't load %s table\n", fname);
+				return -1;
+			}
 		} else {
-			fname = malloc(strlen(cur->fname) + strlen(IR_KEYTABLE_SYSTEM_DIR) + 2);
-			strcpy(fname, IR_KEYTABLE_SYSTEM_DIR);
+			fname = malloc(strlen(cur->fname) + strlen(IR_KEYTABLE_USER_DIR) + 2);
+			strcpy(fname, IR_KEYTABLE_USER_DIR);
 			strcat(fname, "/");
 			strcat(fname, cur->fname);
+			rc = parse_keyfile(fname, &name);
+			if (rc != 0) {
+				fname = malloc(strlen(cur->fname) + strlen(IR_KEYTABLE_SYSTEM_DIR) + 2);
+				strcpy(fname, IR_KEYTABLE_SYSTEM_DIR);
+				strcat(fname, "/");
+				strcat(fname, cur->fname);
+				rc = parse_keyfile(fname, &name);
+			}
+			if (rc != 0) {
+				fprintf(stderr, "Can't load %s table from %s or %s\n", cur->fname, IR_KEYTABLE_USER_DIR, IR_KEYTABLE_SYSTEM_DIR);
+				return -1;
+			}
 		}
-		rc = parse_keyfile(fname, &name);
-		if (rc < 0 || !keys.next) {
-			fprintf(stderr, "Can't load %s table or empty table\n", fname);
+		if (!keys.next) {
+			fprintf(stderr, "Empty table %s\n", fname);
 			return -1;
 		}
 		clear = 1;
Signature · 1 line
1.7.10