From: Sean Young <sean@mess.org>
To: Bastien Nocera <hadess@hadess.net>
Cc: linux-media@vger.kernel.org
Subject: Re: [PATCH v3] keytable: Add keymap test
Date: Thu, 4 Jul 2019 17:16:15 +0100 [thread overview]
Message-ID: <20190704161614.4dcukjcrqdgu4tzh@gofer.mess.org> (raw)
In-Reply-To: <20190704132454.10566-1-hadess@hadess.net>
On Thu, Jul 04, 2019 at 03:24:54PM +0200, Bastien Nocera wrote:
> This new test will try to parse all the ".toml" files in the directory
> path passed to it, error'ing out on the first parsing problem.
That is no longer true. It reads all files and does not error out after
the first parse problem.
>
> Run as "make check" in the keytable directory.
>
> Signed-off-by: Bastien Nocera <hadess@hadess.net>
> ---
> utils/keytable/Makefile.am | 6 +++
> utils/keytable/check_keymaps.c | 67 ++++++++++++++++++++++++++++++++++
> 2 files changed, 73 insertions(+)
> create mode 100644 utils/keytable/check_keymaps.c
>
> diff --git a/utils/keytable/Makefile.am b/utils/keytable/Makefile.am
> index 148b9446..eb296475 100644
> --- a/utils/keytable/Makefile.am
> +++ b/utils/keytable/Makefile.am
> @@ -1,9 +1,12 @@
> bin_PROGRAMS = ir-keytable
> +noinst_PROGRAMS = check-keymaps
> man_MANS = ir-keytable.1 rc_keymap.5
> sysconf_DATA = rc_maps.cfg
> keytablesystem_DATA = $(srcdir)/rc_keymaps/*
> udevrules_DATA = 70-infrared.rules
>
> +check_keymaps_SOURCES = toml.c toml.h check_keymaps.c
> +
> ir_keytable_SOURCES = keytable.c parse.h ir-encode.c ir-encode.h toml.c toml.h
>
> if WITH_BPF
> @@ -21,6 +24,9 @@ endif
> EXTRA_DIST = 70-infrared.rules rc_keymaps rc_keymaps_userspace gen_keytables.pl ir-keytable.1 rc_maps.cfg rc_keymap.5
>
> # custom target
> +check: check-keymaps
> + $(builddir)/check-keymaps $(srcdir)/rc_keymaps/
> +
> install-data-local:
> $(install_sh) -d "$(DESTDIR)$(keytableuserdir)"
>
> diff --git a/utils/keytable/check_keymaps.c b/utils/keytable/check_keymaps.c
> new file mode 100644
> index 00000000..eb8e3e8f
> --- /dev/null
> +++ b/utils/keytable/check_keymaps.c
> @@ -0,0 +1,67 @@
> +#include <string.h>
> +#include <errno.h>
> +#include <stdio.h>
> +#include <sys/types.h>
> +#include <dirent.h>
> +
> +#include "toml.h"
> +
> +static int
> +has_suffix(const char *str, const char *suffix)
> +{
> + if (strlen(str) < strlen(suffix))
> + return 0;
> + if (strncmp(str + strlen(str) - strlen(suffix), suffix, strlen(suffix)) == 0)
strcmp would work here.
> + return 1;
> + return 0;
> +}
> +
> +int main (int argc, char **argv)
> +{
> + DIR *dir;
> + struct dirent *entry;
> + int ret = 0;
> +
> + if (argc != 2) {
> + fprintf(stderr, "Usage: %s KEYMAPS-DIRECTORY\n", argv[0]);
> + return 1;
> + }
> +
> + dir = opendir(argv[1]);
> + if (!dir) {
> + perror("Could not open directory");
> + return 1;
> + }
> +
> + while ((entry = readdir(dir)) != NULL) {
> + struct toml_table_t *root;
> + FILE *fin;
> + char buf[200];
> + char path[2048];
> +
> + if (!has_suffix(entry->d_name, ".toml")) {
> + /* Skipping file */
> + continue;
> + }
> +
> + snprintf(path, sizeof(path), "%s/%s", argv[1], entry->d_name);
> + path[sizeof(path) - 1] = '\0';
snprintf() always adds a zero terminator, so the last line is not needed. I
know some implementations of snprintf() on platforms other than Linux are
broken, but we don't care about that.
> +
> + fin = fopen(path, "r");
> + if (!fin) {
> + fprintf(stderr, "Could not open file %s: %s", path, strerror(errno));
> + ret = 1;
> + continue;
> + }
> +
> + root = toml_parse_file(fin, buf, sizeof(buf));
> + fclose(fin);
> + if (!root) {
> + fprintf(stderr, "Failed to parse %s: %s\n", path, buf);
> + ret = 1;
> + }
> + toml_free(root);
> + }
> +
> + return ret;
> +}
> --
> 2.21.0
next prev parent reply other threads:[~2019-07-04 16:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-04 13:24 [PATCH v3] keytable: Add keymap test Bastien Nocera
2019-07-04 16:16 ` Sean Young [this message]
-- strict thread matches above, loose matches on Subject: below --
2019-06-28 9:45 Bastien Nocera
2019-07-01 11:28 ` Sean Young
2019-07-01 13:54 ` Bastien Nocera
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190704161614.4dcukjcrqdgu4tzh@gofer.mess.org \
--to=sean@mess.org \
--cc=hadess@hadess.net \
--cc=linux-media@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).