All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] kconfig: add chomp like helper function
@ 2016-03-16 10:53 Paul Bolle
  2016-03-16 10:53 ` [PATCH 2/2] kconfig: add unexpected data itself to warning Paul Bolle
  2016-03-16 11:42 ` [PATCH 1/2] kconfig: add chomp like helper function Michal Marek
  0 siblings, 2 replies; 4+ messages in thread
From: Paul Bolle @ 2016-03-16 10:53 UTC (permalink / raw
  To: Michal Marek; +Cc: Josh Boyer, linux-kbuild, linux-kernel

Add a helper function that strips trailing new lines and carriage
returns from strings. Call it chomp, after the perl function that
inspired it.

Signed-off-by: Paul Bolle <pebolle@tiscali.nl>
---
 scripts/kconfig/confdata.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 0b7dc2fd7bac..51904c423411 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -248,6 +248,28 @@ e_out:
 	return -1;
 }
 
+/*
+ * Return newly allocated copy of string "in" with all trailing new lines and
+ * carriage returns removed.
+ */
+static char *chomp(char *in)
+{
+	size_t last = strlen(in);
+	char *copy;
+
+	copy = malloc(last + 1);
+	if (!copy)
+		return NULL;
+
+	strcpy(copy, in);
+	if (last)
+		last--;
+	while (last  && (copy[last] == '\r' || copy[last] == '\n'))
+		copy[last--] = '\0';
+
+	return copy;
+}
+
 int conf_read_simple(const char *name, int def)
 {
 	FILE *in = NULL;
-- 
2.4.3

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

* [PATCH 2/2] kconfig: add unexpected data itself to warning
  2016-03-16 10:53 [PATCH 1/2] kconfig: add chomp like helper function Paul Bolle
@ 2016-03-16 10:53 ` Paul Bolle
  2016-03-16 11:42 ` [PATCH 1/2] kconfig: add chomp like helper function Michal Marek
  1 sibling, 0 replies; 4+ messages in thread
From: Paul Bolle @ 2016-03-16 10:53 UTC (permalink / raw
  To: Michal Marek; +Cc: Josh Boyer, linux-kbuild, linux-kernel

If the .config parser runs into unexpected data it emits a warnings like
    .config:6911:warning: unexpected data

Add the unexpected data itself to the warning too, to make it easier to
discover what is going wrong:
     .config:6911:warning: unexpected data: CONFOG_CHARGER_TPS65217=m

Signed-off-by: Paul Bolle <pebolle@tiscali.nl>
---
 scripts/kconfig/confdata.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 51904c423411..62df2594bc24 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -398,8 +398,12 @@ load:
 			if (conf_set_sym_val(sym, def, def_flags, p))
 				continue;
 		} else {
-			if (line[0] != '\r' && line[0] != '\n')
-				conf_warning("unexpected data");
+			if (line[0] != '\r' && line[0] != '\n') {
+				char *tmp = chomp(line);
+
+				conf_warning("unexpected data: %s", tmp);
+				free(tmp);
+			}
 			continue;
 		}
 setsym:
-- 
2.4.3

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

* Re: [PATCH 1/2] kconfig: add chomp like helper function
  2016-03-16 10:53 [PATCH 1/2] kconfig: add chomp like helper function Paul Bolle
  2016-03-16 10:53 ` [PATCH 2/2] kconfig: add unexpected data itself to warning Paul Bolle
@ 2016-03-16 11:42 ` Michal Marek
  2016-03-16 12:41   ` Paul Bolle
  1 sibling, 1 reply; 4+ messages in thread
From: Michal Marek @ 2016-03-16 11:42 UTC (permalink / raw
  To: Paul Bolle; +Cc: Josh Boyer, linux-kbuild, linux-kernel

On 2016-03-16 11:53, Paul Bolle wrote:
> Add a helper function that strips trailing new lines and carriage
> returns from strings. Call it chomp, after the perl function that
> inspired it.
> 
> Signed-off-by: Paul Bolle <pebolle@tiscali.nl>
> ---
>  scripts/kconfig/confdata.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> index 0b7dc2fd7bac..51904c423411 100644
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
> @@ -248,6 +248,28 @@ e_out:
>  	return -1;
>  }
>  
> +/*
> + * Return newly allocated copy of string "in" with all trailing new lines and
> + * carriage returns removed.
> + */
> +static char *chomp(char *in)
> +{
> +	size_t last = strlen(in);
> +	char *copy;
> +
> +	copy = malloc(last + 1);
> +	if (!copy)
> +		return NULL;
> +
> +	strcpy(copy, in);
> +	if (last)
> +		last--;
> +	while (last  && (copy[last] == '\r' || copy[last] == '\n'))
> +		copy[last--] = '\0';
> +
> +	return copy;
> +}
> +

For this particular use, it's probably easier to just write

conf_warning("unexpected data: %.*s",
	     (int)strcspn(line, "\r\n"), line);

Or do you see more use cases for the chomp function?

No matter how the string is constructed, I like the verbose warning :)

Thanks,
Michal

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

* Re: [PATCH 1/2] kconfig: add chomp like helper function
  2016-03-16 11:42 ` [PATCH 1/2] kconfig: add chomp like helper function Michal Marek
@ 2016-03-16 12:41   ` Paul Bolle
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Bolle @ 2016-03-16 12:41 UTC (permalink / raw
  To: Michal Marek; +Cc: Josh Boyer, linux-kbuild, linux-kernel

On wo, 2016-03-16 at 12:42 +0100, Michal Marek wrote:
> For this particular use, it's probably easier to just write
> 
> conf_warning("unexpected data: %.*s",
> 	     (int)strcspn(line, "\r\n"), line);

OK. (Next time I'll try listen to the voice in my head whispering:
"There must be an easier way to do this.".)

> Or do you see more use cases for the chomp function?

No.

> No matter how the string is constructed, I like the verbose warning :)

I'll respin and resend (in a few hours).

Thanks,


Paul Bolle

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

end of thread, other threads:[~2016-03-16 12:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-16 10:53 [PATCH 1/2] kconfig: add chomp like helper function Paul Bolle
2016-03-16 10:53 ` [PATCH 2/2] kconfig: add unexpected data itself to warning Paul Bolle
2016-03-16 11:42 ` [PATCH 1/2] kconfig: add chomp like helper function Michal Marek
2016-03-16 12:41   ` Paul Bolle

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.