Re: shell and glibc (Re: Inconsistent parameter expansion)

2008-05-18 Thread Herbert Xu
Oleg Verych <[EMAIL PROTECTED]> wrote:
> 
> It seems, small glibc team cannot do much in areas without interest.

Unfortunately all the cool kids want to work on the kernel instead :)

> Very surprising for me was recent discovery of big performance penalty of
> the most simple '^$' regexp; it turned to be glibc RE library problem:
> 
> http://bugs.debian.org/475474
> (bonus: 4 ways of doing one thing with `sed`, not with `perl`:)

Have you seen http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=65458 ?

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


shell and glibc (Re: Inconsistent parameter expansion)

2008-05-18 Thread Oleg Verych
> The fnmatch(3) function is now correct as far as I know but
> glob(3) still seems to be broken.

It seems, small glibc team cannot do much in areas without interest.

Very surprising for me was recent discovery of big performance penalty of
the most simple '^$' regexp; it turned to be glibc RE library problem:

http://bugs.debian.org/475474
(bonus: 4 ways of doing one thing with `sed`, not with `perl`:)

Thus, i think shell -- basic userspace tool, must be reliable with its
implementation. There are many other ways of size reduction (more on
that latter).

--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: strange `printf` arguments, parsing features (bugs?)

2008-05-18 Thread Oleg Verych
> > Or, if you want to have a slash (odd number), use slash (same). If you
> > what to place two slashes (even), use four (even << 1).
> > 
> > Nice.
> 
> Yes it is confusing, however, the `` construct is deprecated
> and the $() construct is more reasonable in this regard.

Still it is quite useful with nested calls, it is (at least) something
different and interesting with $[{((] all over and also a matter of
taste sometimes. But this behaviour of \\ there is just ugly.

--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Inconsistent parameter expansion

2008-05-18 Thread Herbert Xu
Oleg Verych <[EMAIL PROTECTED]> wrote:
>
>> This is a bug in dash.  The following patch should fix the problem,
>> provided that Ubuntu hasn't built dash with glob(3) enabled because
>> glob(3) has a similar bug and that needs to be fixed in glibc.
> 
> What was/is whole story? What are FNMATCH_BROKEN GLOB_BROKEN?

I added fnmatch(3) and glob(3) support to dash in order to tap
into existing libc functions rather than duplicating them.  However
at the time it turned out that both were broken which is why these
macros were added until such a time when they were fixed.

The fnmatch(3) function is now correct as far as I know but
glob(3) still seems to be broken.

In any case you may enable them with --enable-fnmatch and --enable-glob
when running configure to see their effect on dash.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: strange `printf` arguments, parsing features (bugs?)

2008-05-18 Thread Herbert Xu
Oleg Verych <[EMAIL PROTECTED]> wrote:
>
> Or, if you want to have a slash (odd number), use slash (same). If you
> what to place two slashes (even), use four (even << 1).
> 
> Nice.

Yes it is confusing, however, the `` construct is deprecated
and the $() construct is more reasonable in this regard.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: strange `printf` arguments, parsing features (bugs?)

2008-05-18 Thread Oleg Verych
> > > > # (3) '\' in `` and in $();
> > > > # what is POSIX "literal meaning" of '\' in `` and what is '\\' then?
> Within the backquoted style of command substitution, backslash
> shall retain its literal meaning, except when followed by:
> '$', '`', or '\\' (dollar sign, backquote, backslash).

> > $( '  ' ) ; ` '  ' ` ; $( ' \\\ ' ) ; ` ' \\\ ' `
> >   (4)(2)(3)   (2)
> > $( "  " ) ; ` "  " ` ; $( " \\\ " ) ; ` " \\\ " `

So, literal meaning of '\' is '\' and '\\' is '\' there.

Or, if you want to have a slash (odd number), use slash (same). If you
what to place two slashes (even), use four (even << 1).

Nice.

> > it is so, but how to explain this wrt spec.?
> 
> Section 2.6.3, "Command Substitution":
> 

--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: strange `printf` arguments, parsing features (bugs?)

2008-05-18 Thread Herbert Xu
On Sun, May 18, 2008 at 06:40:26PM +0200, Oleg Verych wrote:
> Herbert Xu @ Sun, May 18, 2008 at 11:41:08PM +0800:
> 
> > > # (1) parameters to `printf`?
> > > 
> > > [EMAIL PROTECTED]:/tmp$ sh -c 'printf "-1"'
> > > printf: 1: Illegal option -1
> > 
> > This is expected.  Use printf -- if you want to disable option parsing.
> 
> [second] Again for `echo` it's not so, `printf` is a mean for "propper"
>  (portable) `echo`, nothing about getopt() stuff is mentioned in
>POSIX spec.

All POSIX utilities accept -- by default.  The specification for
echo specifically forbids --, while that of printf does not.

> > > # (3) '\' in `` and in $();
> > > # what is POSIX "literal meaning" of '\' in `` and what is '\\' then?
> (bash removed)
> 
> $( '  ' ) ; ` '  ' ` ; $( ' \\\ ' ) ; ` ' \\\ ' `
>   (4)(2)(3)   (2)
> $( "  " ) ; ` "  " ` ; $( " \\\ " ) ; ` " \\\ " `
> 
> it is so, but how to explain this wrt spec.?

Section 2.6.3, "Command Substitution":

Within the backquoted style of command substitution, backslash
shall retain its literal meaning, except when followed by:
'$', '`', or '\\' (dollar sign, backquote, backslash).

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Inconsistent parameter expansion

2008-05-18 Thread Oleg Verych
> > I can't figure out why '*/FILE' and '*"/FILE"' are not expanded the same
> > way...

This and one from "[EXPAND] Fix slash treatment in expmeta"
work with Etch:

[EMAIL PROTECTED] dash -c 'echo "/"root*'
/root
[EMAIL PROTECTED] dash -c 'echo *"/FILE"'
A/FILE B/FILE C/FILE D/FILE
[EMAIL PROTECTED]


> This is a bug in dash.  The following patch should fix the problem,
> provided that Ubuntu hasn't built dash with glob(3) enabled because
> glob(3) has a similar bug and that needs to be fixed in glibc.

What was/is whole story? What are FNMATCH_BROKEN GLOB_BROKEN?

Thanks.

--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Inconsistent parameter expansion

2008-05-18 Thread Herbert Xu
On Thu, May 15, 2008 at 02:26:02PM +, Romain Tartière wrote:
>
> I can't figure out why '*/FILE' and '*"/FILE"' are not expanded the same
> way...

This is a bug in dash.  The following patch should fix the problem,
provided that Ubuntu hasn't built dash with glob(3) enabled because
glob(3) has a similar bug and that needs to be fixed in glibc.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
diff --git a/ChangeLog b/ChangeLog
index 2f65e03..bf9dd4a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-05-19  Herbert Xu <[EMAIL PROTECTED]>
+
+   * Fixed non-leading slash treatment in expmeta.
+
 2008-05-07  Gerrit Pape <[EMAIL PROTECTED]>
 
* Fixed lexical error in arithmetic expansion of & and |.
diff --git a/src/expand.c b/src/expand.c
index 2c52781..e4c4c8b 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -1269,10 +1269,11 @@ expmeta(char *enddir, char *name)
struct dirent *dp;
int atend;
int matchdot;
+   int esc;
 
metaflag = 0;
start = name;
-   for (p = name; *p; p++) {
+   for (p = name; esc = 0, *p; p += esc + 1) {
if (*p == '*' || *p == '?')
metaflag = 1;
else if (*p == '[') {
@@ -1291,11 +1292,11 @@ expmeta(char *enddir, char *name)
}
} else {
if (*p == '\\')
-   p++;
-   if (*p == '/') {
+   esc++;
+   if (p[esc] == '/') {
if (metaflag)
break;
-   start = p + 1;
+   start = p + esc + 1;
}
}
}
@@ -1337,7 +1338,8 @@ expmeta(char *enddir, char *name)
atend = 1;
} else {
atend = 0;
-   *endname++ = '\0';
+   *endname = '\0';
+   endname += esc + 1;
}
matchdot = 0;
p = start;
@@ -1363,7 +1365,7 @@ expmeta(char *enddir, char *name)
}
closedir(dirp);
if (! atend)
-   endname[-1] = '/';
+   endname[-esc - 1] = esc ? '\\' : '/';
 }
 #endif /* HAVE_GLOB */
 
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: strange `printf` arguments, parsing features (bugs?)

2008-05-18 Thread Oleg Verych
Herbert Xu @ Sun, May 18, 2008 at 11:41:08PM +0800:

> > # (1) parameters to `printf`?
> > 
> > [EMAIL PROTECTED]:/tmp$ sh -c 'printf "-1"'
> > printf: 1: Illegal option -1
> 
> This is expected.  Use printf -- if you want to disable option parsing.

[second] Again for `echo` it's not so, `printf` is a mean for "propper"
 (portable) `echo`, nothing about getopt() stuff is mentioned in
 POSIX spec.


> > $(echo ' \' >&2)
> > `echo  ' \' >&2`
> 
> bash and dash in fact agree on these except that echo in dash
> interprets escape codes as required by POSIX.

[first] Gee, that `echo` thing (how stupid to catch it:)
Correct test (works), question remains:

> > # (3) '\' in `` and in $();
> > # what is POSIX "literal meaning" of '\' in `` and what is '\\' then?
(bash removed)

$( '  ' ) ; ` '  ' ` ; $( ' \\\ ' ) ; ` ' \\\ ' `
  (4)(2)(3)   (2)
$( "  " ) ; ` "  " ` ; $( " \\\ " ) ; ` " \\\ " `

it is so, but how to explain this wrt spec.?

[EMAIL PROTECTED] bash -s <<"E"
$(printf %s '  ' >&2)
`printf '\n%s\n-\n'  '  ' >&2`
$(printf %s "  " >&2)
`printf '\n%s\n-\n'  "  " >&2`
E
 
 \\
-
 \\
 \
-
[EMAIL PROTECTED] sh -s <<"E"
$(printf %s '  ' >&2)
`printf '\n%s\n-\n'  '  ' >&2`
$(printf %s "  " >&2)
`printf '\n%s\n-\n'  "  " >&2`
E
 
 \\
-
 \\
 \
-
[EMAIL PROTECTED] bash -s <<"E"
$(printf %s ' \\\ ' >&2)
`printf '\n%s\n-\n'  ' \\\ ' >&2`
$(printf %s " \\\ " >&2)
`printf '\n%s\n-\n'  " \\\ " >&2`
E
 \\\
 \\
-
 \\
 \
-
[EMAIL PROTECTED] sh -s <<"E"
$(printf %s ' \\\ ' >&2)
`printf '\n%s\n-\n'  ' \\\ ' >&2`
$(printf %s " \\\ " >&2)
`printf '\n%s\n-\n'  " \\\ " >&2`
E
 \\\
 \\
-
 \\
 \
-
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: strange `printf` arguments, parsing features (bugs?)

2008-05-18 Thread Herbert Xu
Oleg Verych <[EMAIL PROTECTED]> wrote:
> # (1) parameters to `printf`?
> 
> [EMAIL PROTECTED]:/tmp$ sh -c 'printf "-1"'
> printf: 1: Illegal option -1

This is expected.  Use printf -- if you want to disable option parsing.

> # (2) parsing features?
> 
> [EMAIL PROTECTED]:/tmp$ sh -c 'echo 1; } echo 2'
> 1
> 2
> [EMAIL PROTECTED]:/tmp$ sh -c '} echo 2'
> sh: Syntax error: "}" unexpected
> [EMAIL PROTECTED]:/tmp$ sh -c 'echo 2; }'
> 2
> [EMAIL PROTECTED]:/tmp$

Yes that's a defect in the dash parser.

> # (3) '\' in `` and in $();
> # what is POSIX "literal meaning" of '\' in `` and what is '\\' then?
> # bash has its own opinion
> 
> [EMAIL PROTECTED]:/tmp$ PS2=''
> [EMAIL PROTECTED]:/tmp$ dash -s << '='
> `echo ' \' >&2`
> `echo ' \\' >&2`
> `echo ' \\\' >&2`
> `echo ' ' >&2`
> $(echo ' \' >&2)
> $(echo ' \\' >&2)
> $(echo ' \\\' >&2)
> $(echo ' ' >&2)
> echo --
> $(echo ' \' >&2)
> `echo  ' \' >&2`

bash and dash in fact agree on these except that echo in dash
interprets escape codes as required by POSIX.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[EMAIL PROTECTED]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html