* [PATCH] Support DOS line endings
@ 2006-07-07 17:34 Matthew Wilcox
2006-07-07 22:35 ` Sam Ravnborg
2006-07-08 3:23 ` Roman Zippel
0 siblings, 2 replies; 11+ messages in thread
From: Matthew Wilcox @ 2006-07-07 17:34 UTC (permalink / raw)
To: Sam Ravnborg; +Cc: wookey, linux-kernel
Kconfig doesn't currently handle config files with DOS line endings.
While these are, of course, an abomination, etc, etc, it can be handy
to not have to convert them first. It's also a tiny patch and even adds
support for lines ending in just \r or even \n\r.
Signed-off-by: Matthew Wilcox <matthew@wil.cx>
Index: ./scripts/kconfig/confdata.c
===================================================================
RCS file: /var/cvs/linux-2.6/scripts/kconfig/confdata.c,v
retrieving revision 1.11
diff -u -p -r1.11 confdata.c
--- ./scripts/kconfig/confdata.c 19 Apr 2006 04:56:29 -0000 1.11
+++ ./scripts/kconfig/confdata.c 7 Jul 2006 17:29:16 -0000
@@ -177,6 +177,9 @@ int conf_read_simple(const char *name)
p2 = strchr(p, '\n');
if (p2)
*p2 = 0;
+ p2 = strchr(p, '\r');
+ if (p2)
+ *p2 = 0;
sym = sym_find(line + 7);
if (!sym) {
conf_warning("trying to assign nonexistent symbol %s", line + 7);
@@ -234,6 +237,7 @@ int conf_read_simple(const char *name)
}
break;
case '\n':
+ case '\r':
break;
default:
conf_warning("unexpected data");
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Support DOS line endings
2006-07-07 17:34 [PATCH] Support DOS line endings Matthew Wilcox
@ 2006-07-07 22:35 ` Sam Ravnborg
2006-07-08 3:23 ` Roman Zippel
1 sibling, 0 replies; 11+ messages in thread
From: Sam Ravnborg @ 2006-07-07 22:35 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: wookey, linux-kernel, Roman Zippel
On Fri, Jul 07, 2006 at 11:34:58AM -0600, Matthew Wilcox wrote:
> Kconfig doesn't currently handle config files with DOS line endings.
> While these are, of course, an abomination, etc, etc, it can be handy
> to not have to convert them first. It's also a tiny patch and even adds
> support for lines ending in just \r or even \n\r.
Applied after updating path to -rc1.
Sam
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Support DOS line endings
2006-07-07 17:34 [PATCH] Support DOS line endings Matthew Wilcox
2006-07-07 22:35 ` Sam Ravnborg
@ 2006-07-08 3:23 ` Roman Zippel
2006-07-13 18:18 ` Sam Ravnborg
1 sibling, 1 reply; 11+ messages in thread
From: Roman Zippel @ 2006-07-08 3:23 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: Sam Ravnborg, wookey, linux-kernel
Hi,
On Fri, 7 Jul 2006, Matthew Wilcox wrote:
> Kconfig doesn't currently handle config files with DOS line endings.
> While these are, of course, an abomination, etc, etc, it can be handy
> to not have to convert them first. It's also a tiny patch and even adds
> support for lines ending in just \r or even \n\r.
Did you try the latter? Unless you told fgets() about it I don't see how
it should work.
> if (p2)
> *p2 = 0;
> + p2 = strchr(p, '\r');
> + if (p2)
> + *p2 = 0;
I think something like this would be simpler:
if (p2[-1] == '\r')
p2[-1] = 0;
bye, Roman
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Support DOS line endings
2006-07-08 3:23 ` Roman Zippel
@ 2006-07-13 18:18 ` Sam Ravnborg
2006-07-13 18:29 ` Matthew Wilcox
2006-07-13 18:47 ` Roman Zippel
0 siblings, 2 replies; 11+ messages in thread
From: Sam Ravnborg @ 2006-07-13 18:18 UTC (permalink / raw)
To: Roman Zippel; +Cc: Matthew Wilcox, wookey, linux-kernel
On Sat, Jul 08, 2006 at 05:23:17AM +0200, Roman Zippel wrote:
> Hi,
>
> On Fri, 7 Jul 2006, Matthew Wilcox wrote:
>
> > Kconfig doesn't currently handle config files with DOS line endings.
> > While these are, of course, an abomination, etc, etc, it can be handy
> > to not have to convert them first. It's also a tiny patch and even adds
> > support for lines ending in just \r or even \n\r.
>
> Did you try the latter? Unless you told fgets() about it I don't see how
> it should work.
>
> > if (p2)
> > *p2 = 0;
> > + p2 = strchr(p, '\r');
> > + if (p2)
> > + *p2 = 0;
>
> I think something like this would be simpler:
>
> if (p2[-1] == '\r')
> p2[-1] = 0;
Negative index'es always make me supsicious.
I've applied followign patch.
The fgets thing I have not looked at.
Sam
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index 2ee48c3..a30b1bb 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -192,9 +192,14 @@ load:
if (!p)
continue;
*p++ = 0;
- p2 = strchr(p, '\n');
- if (p2)
- *p2 = 0;
+ p2 = p;
+ while (*p2) {
+ if (*p2 == '\r' || *p2 == '\n') {
+ *p2 = 0;
+ break;
+ }
+ p2++;
+ }
if (def == S_DEF_USER) {
sym = sym_find(line + 7);
if (!sym) {
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] Support DOS line endings
2006-07-13 18:18 ` Sam Ravnborg
@ 2006-07-13 18:29 ` Matthew Wilcox
2006-07-13 18:47 ` Roman Zippel
1 sibling, 0 replies; 11+ messages in thread
From: Matthew Wilcox @ 2006-07-13 18:29 UTC (permalink / raw)
To: Sam Ravnborg; +Cc: Roman Zippel, wookey, linux-kernel
On Thu, Jul 13, 2006 at 08:18:25PM +0200, Sam Ravnborg wrote:
> Negative index'es always make me supsicious.
> I've applied followign patch.
> The fgets thing I have not looked at.
Did you apply the "case '\r'" hunk (around line 269) too? If not,
it'll spew "unexpected data" error messages for every blank line.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Support DOS line endings
2006-07-13 18:18 ` Sam Ravnborg
2006-07-13 18:29 ` Matthew Wilcox
@ 2006-07-13 18:47 ` Roman Zippel
2006-07-13 19:35 ` Sam Ravnborg
1 sibling, 1 reply; 11+ messages in thread
From: Roman Zippel @ 2006-07-13 18:47 UTC (permalink / raw)
To: Sam Ravnborg; +Cc: Matthew Wilcox, wookey, linux-kernel
Hi,
On Thu, 13 Jul 2006, Sam Ravnborg wrote:
> > if (p2[-1] == '\r')
> > p2[-1] = 0;
> Negative index'es always make me supsicious.
Opencoding of the strchr is not much better, you can change the above also
to (*--p2 == '\r').
> diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
> index 2ee48c3..a30b1bb 100644
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
> @@ -192,9 +192,14 @@ load:
> if (!p)
> continue;
> *p++ = 0;
> - p2 = strchr(p, '\n');
> - if (p2)
> - *p2 = 0;
> + p2 = p;
> + while (*p2) {
> + if (*p2 == '\r' || *p2 == '\n') {
> + *p2 = 0;
> + break;
> + }
> + p2++;
> + }
IMO that's still too complicated, a '\n' is always the last character
(unless the line was too long), with an optional '\r' in front of it.
bye, Roman
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Support DOS line endings
2006-07-13 18:47 ` Roman Zippel
@ 2006-07-13 19:35 ` Sam Ravnborg
2006-07-13 20:02 ` Matthew Wilcox
0 siblings, 1 reply; 11+ messages in thread
From: Sam Ravnborg @ 2006-07-13 19:35 UTC (permalink / raw)
To: Roman Zippel; +Cc: Matthew Wilcox, wookey, linux-kernel
On Thu, Jul 13, 2006 at 08:47:12PM +0200, Roman Zippel wrote:
> Hi,
>
> On Thu, 13 Jul 2006, Sam Ravnborg wrote:
>
> > > if (p2[-1] == '\r')
> > > p2[-1] = 0;
> > Negative index'es always make me supsicious.
>
> Opencoding of the strchr is not much better, you can change the above also
> to (*--p2 == '\r').
There is no semantic difference between decrementing a variable and a
negative index.
But I used this one anyway.
So now it look like this.
Sam
diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index a69d8ac..b7e7281 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -195,6 +195,8 @@ load:
p2 = strchr(p, '\n');
if (p2)
*p2 = 0;
+ if (*--p2 == '\r')
+ *p2 = 0;
if (def == S_DEF_USER) {
sym = sym_find(line + 7);
if (!sym) {
@@ -266,6 +268,7 @@ load:
;
}
break;
+ case '\r':
case '\n':
break;
default:
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH] Support DOS line endings
2006-07-13 19:35 ` Sam Ravnborg
@ 2006-07-13 20:02 ` Matthew Wilcox
2006-07-13 21:07 ` Sam Ravnborg
0 siblings, 1 reply; 11+ messages in thread
From: Matthew Wilcox @ 2006-07-13 20:02 UTC (permalink / raw)
To: Sam Ravnborg; +Cc: Roman Zippel, wookey, linux-kernel
On Thu, Jul 13, 2006 at 09:35:43PM +0200, Sam Ravnborg wrote:
> --- a/scripts/kconfig/confdata.c
> +++ b/scripts/kconfig/confdata.c
> @@ -195,6 +195,8 @@ load:
> p2 = strchr(p, '\n');
> if (p2)
> *p2 = 0;
> + if (*--p2 == '\r')
> + *p2 = 0;
... but if p2 is NULL ...
so:
if (p2) {
*p2 = 0;
if (*--p2 == '\r')
*p2 = 0;
}
but maybe it'd be better to do ...
if (p2) {
*p2-- = 0;
if (*p2 == '\r')
*p2 = 0;
}
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Support DOS line endings
2006-07-13 20:02 ` Matthew Wilcox
@ 2006-07-13 21:07 ` Sam Ravnborg
2006-07-13 21:41 ` Bernd Petrovitsch
0 siblings, 1 reply; 11+ messages in thread
From: Sam Ravnborg @ 2006-07-13 21:07 UTC (permalink / raw)
To: Matthew Wilcox; +Cc: Roman Zippel, wookey, linux-kernel
On Thu, Jul 13, 2006 at 02:02:23PM -0600, Matthew Wilcox wrote:
> On Thu, Jul 13, 2006 at 09:35:43PM +0200, Sam Ravnborg wrote:
> > --- a/scripts/kconfig/confdata.c
> > +++ b/scripts/kconfig/confdata.c
> > @@ -195,6 +195,8 @@ load:
> > p2 = strchr(p, '\n');
> > if (p2)
> > *p2 = 0;
> > + if (*--p2 == '\r')
> > + *p2 = 0;
>
> ... but if p2 is NULL ...
>
> so:
> if (p2) {
> *p2 = 0;
> if (*--p2 == '\r')
> *p2 = 0;
> }
>
> but maybe it'd be better to do ...
>
> if (p2) {
> *p2-- = 0;
> if (*p2 == '\r')
> *p2 = 0;
> }
Thanks. Maybe I should just stop trying to code anything today ;-)
Sam
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Support DOS line endings
2006-07-13 21:07 ` Sam Ravnborg
@ 2006-07-13 21:41 ` Bernd Petrovitsch
2006-07-19 12:02 ` Alistair John Strachan
0 siblings, 1 reply; 11+ messages in thread
From: Bernd Petrovitsch @ 2006-07-13 21:41 UTC (permalink / raw)
To: Sam Ravnborg; +Cc: linux-kernel
On Thu, 2006-07-13 at 23:07 +0200, Sam Ravnborg wrote:
[...]
> Thanks. Maybe I should just stop trying to code anything today ;-)
Or take it as a sign to not support DOS line endings.
SCNR,
Bernd
--
Firmix Software GmbH http://www.firmix.at/
mobil: +43 664 4416156 fax: +43 1 7890849-55
Embedded Linux Development and Services
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] Support DOS line endings
2006-07-13 21:41 ` Bernd Petrovitsch
@ 2006-07-19 12:02 ` Alistair John Strachan
0 siblings, 0 replies; 11+ messages in thread
From: Alistair John Strachan @ 2006-07-19 12:02 UTC (permalink / raw)
To: Bernd Petrovitsch; +Cc: Sam Ravnborg, linux-kernel
On Thursday 13 July 2006 22:41, Bernd Petrovitsch wrote:
> On Thu, 2006-07-13 at 23:07 +0200, Sam Ravnborg wrote:
> [...]
>
> > Thanks. Maybe I should just stop trying to code anything today ;-)
>
> Or take it as a sign to not support DOS line endings.
It certainly would be better to warn if a file with DOS line endings is being
used, even if supported, so that such files never enter the kernel
undetected.
--
Cheers,
Alistair.
Third year Computer Science undergraduate.
1F2 55 South Clerk Street, Edinburgh, UK.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2006-07-19 12:03 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-07 17:34 [PATCH] Support DOS line endings Matthew Wilcox
2006-07-07 22:35 ` Sam Ravnborg
2006-07-08 3:23 ` Roman Zippel
2006-07-13 18:18 ` Sam Ravnborg
2006-07-13 18:29 ` Matthew Wilcox
2006-07-13 18:47 ` Roman Zippel
2006-07-13 19:35 ` Sam Ravnborg
2006-07-13 20:02 ` Matthew Wilcox
2006-07-13 21:07 ` Sam Ravnborg
2006-07-13 21:41 ` Bernd Petrovitsch
2006-07-19 12:02 ` Alistair John Strachan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox