linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] v4l-utils: ir-keytable file parsing errors
@ 2012-01-08 23:31 Chris Pockele
  2012-01-23 18:27 ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Pockele @ 2012-01-08 23:31 UTC (permalink / raw)
  To: linux-media

[-- Attachment #1: Type: text/plain, Size: 1159 bytes --]

Hello,

While configuring a remote control I noticed that the ir-keytable
utility would throw the message "Invalid parameter on line 1" if the
first line following the "table ... type: ..." line is a comment.
Also, if a configuration line is invalid, the line number indication
of the error message is sometimes incorrect, because the comments
before it are not counted.
This happens because of the "continue" statement when processing
comments (or the table/type line), thus skipping the line counter
increase at the end of the loop.  The included patch fixes both
problems by making sure the counter is always increased.
The parse_cfgfile() function had a similar problem.

For the "table ... type: ..." configuration line at the beginning of a
keyfile, I suggest replacing the marker character by something
different from '#'.  That way, it can be commented out by the user,
and it doesn't have to be on the first line.  However, that's
something for another patch and probably up to someone else to decide
:-).  If desirable, I can generate such a patch.

Regards,
Chris

Signed-off-by: Chris Pockelé <chris.pockele.f1@gmail.com>

[-- Attachment #2: fix_keyfile_lineno.patch --]
[-- Type: text/x-diff, Size: 1094 bytes --]

diff -ru a/utils/keytable/keytable.c b/utils/keytable/keytable.c
--- a/utils/keytable/keytable.c	2012-01-08 15:22:15.000000000 +0100
+++ b/utils/keytable/keytable.c	2012-01-08 21:17:11.215826012 +0100
@@ -201,9 +201,11 @@
 
 	while (fgets(s, sizeof(s), fin)) {
 		char *p = s;
+
+		line++;
 		while (*p == ' ' || *p == '\t')
 			p++;
-		if (!line && p[0] == '#') {
+		if (line==1 && p[0] == '#') {
 			p++;
 			p = strtok(p, "\n\t =:");
 			do {
@@ -278,7 +280,6 @@
 			return ENOMEM;
 		}
 		nextkey = nextkey->next;
-		line++;
 	}
 	fclose(fin);
 
@@ -286,7 +287,7 @@
 
 err_einval:
 	fprintf(stderr, "Invalid parameter on line %d of %s\n",
-		line + 1, fname);
+		line, fname);
 	return EINVAL;
 
 }
@@ -311,6 +312,8 @@
 
 	while (fgets(s, sizeof(s), fin)) {
 		char *p = s;
+
+		line++;
 		while (*p == ' ' || *p == '\t')
 			p++;
 
@@ -348,7 +351,6 @@
 			return ENOMEM;
 		}
 		nextcfg = nextcfg->next;
-		line++;
 	}
 	fclose(fin);
 
@@ -356,7 +358,7 @@
 
 err_einval:
 	fprintf(stderr, "Invalid parameter on line %d of %s\n",
-		line + 1, fname);
+		line, fname);
 	return EINVAL;
 
 }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] v4l-utils: ir-keytable file parsing errors
  2012-01-08 23:31 [PATCH] v4l-utils: ir-keytable file parsing errors Chris Pockele
@ 2012-01-23 18:27 ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 2+ messages in thread
From: Mauro Carvalho Chehab @ 2012-01-23 18:27 UTC (permalink / raw)
  To: Chris Pockele; +Cc: linux-media

Em 08-01-2012 21:31, Chris Pockele escreveu:
> Hello,
> 
> While configuring a remote control I noticed that the ir-keytable
> utility would throw the message "Invalid parameter on line 1" if the
> first line following the "table ... type: ..." line is a comment.
> Also, if a configuration line is invalid, the line number indication
> of the error message is sometimes incorrect, because the comments
> before it are not counted.
> This happens because of the "continue" statement when processing
> comments (or the table/type line), thus skipping the line counter
> increase at the end of the loop.  The included patch fixes both
> problems by making sure the counter is always increased.
> The parse_cfgfile() function had a similar problem.

Applied, thanks.

> For the "table ... type: ..." configuration line at the beginning of a
> keyfile, I suggest replacing the marker character by something
> different from '#'.  That way, it can be commented out by the user,
> and it doesn't have to be on the first line.  However, that's
> something for another patch and probably up to someone else to decide
> :-).  If desirable, I can generate such a patch.

Such patch is welcome, provided that it will keep working with the
old format, in order to not mangle configs with the old format.

Regards,
Mauro

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-01-23 18:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-08 23:31 [PATCH] v4l-utils: ir-keytable file parsing errors Chris Pockele
2012-01-23 18:27 ` Mauro Carvalho Chehab

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).