Re: Allow equal after a short option

2008-03-08 Thread Jeff Johnson


On Mar 8, 2008, at 12:02 PM, Wayne Davison wrote:


I think it would be nice to allow an equal to separate a short option
letter from its abutting argument.  e.g. these commands using the  
test1

executable would all work the same:

 ./test1 -2 foo
 ./test1 -2=foo
 ./test1 -2foo
 ./test1 --arg2 foo
 ./test1 --arg2=foo

Since this has been a syntax error in released versions of popt, this
should not cause a compatibility problem.  This fix requires my prior
patch to make sure that short-option parsing doesn't have longArg set.



I think the patch is a reasonable extension, but there's more to do:

[EMAIL PROTECTED] popt]$ make check
...
make  check-TESTS
make[2]: Entering directory `/X/src/popt'
Running tests in /X/src/popt
Running test test1 - 1.
Running test test1 - 2.
Running test test1 - 3.
Running test test1 - 4.
Running test test1 - 5.
Running test test1 - 6.
Running test test1 - 7.
Running test test1 - 8.
Running test test1 - 9.
Test test1 -2 foo failed with: arg1: 0 arg2:  rest: foo != arg1:  
0 arg2: foo


Would you mind looking at the problem? Thanks ...

73 de Jeff
__
POPT Library   http://rpm5.org
Developer Communication List   popt-devel@rpm5.org


Re: Allow equal after a short option

2008-03-08 Thread Wayne Davison
On Sat, Mar 08, 2008 at 12:10:52PM -0500, Jeff Johnson wrote:
 Test test1 -2 foo failed with: arg1: 0 arg2:  rest: foo != arg1:  
 0 arg2: foo

I'm not seeing that error with the CVS version.  I do note that my prior
patch to fix the longArg pointer (e.g. ./test1 -2foo=bar) isn't there,
but even commenting out that fix doesn't get test 9 to fail for me.  I
did see failures for tests 19-23 due to the --echo-args macro now
outputting an extra -- at the start.  The attached patch fixes this,
and also adds two new tests to check that the changed equal-handling
works right.

..wayne..


popt-tests.sh
Description: Bourne shell script


Any interest in eliminating sprintf(), strcpy(), and strcat()?

2008-03-08 Thread Wayne Davison
In rsync I eliminated all use of sprintf(), strcpy(), and strcat(),
replacing them with snprintf(), strlcpy(), and strlcat().  Would you be
interested in such changes if appropriate compatibility functions were
defined?

For instance, I could imagine a configure test to see if snprintf()
returns a -1 on overflow, and a test to see if its limit is off by 1
(some don't count the '\0').  Then, a simple wrapper function would
handle both those conditions in a simple way (i.e. -1 could be mapped
to the limit-value+1 without need to compute the real overflow length
because popt doesn't ever call snprintf() expecting to find out how
much bigger its buffer needs to be -- the limit would just be used to
be extra sure that overflow was impossible.

I have compatibility functions for strlcpy() and strlcat() that I could
snag from rsync.  These functions are better than strncpy() and strncat()
as their limit value is the size of the buffer (unlike strncat()), and
the destination string will always be '\0'-terminated (unlike strncpy()).

I have most of the changes written for an earlier version (rsync includes
a version of 1.10.2 at present) that I could adapt for 1.14.

..wayne..
__
POPT Library   http://rpm5.org
Developer Communication List   popt-devel@rpm5.org


Re: Allow equal after a short option

2008-03-08 Thread Wayne Davison
On Sat, Mar 08, 2008 at 06:11:09PM -0500, Jeff Johnson wrote:
 Hmmm, we appear to have different behavior wrto echo. Your
 patch changes testit.sh to include an explicit --, which (when
 I last fixed testit.sh like 3 weeks ago) does not appear in the
 output I am (and was)  seeing.

I tried it on Ubuntu 7.10 and CentOS 5 with the same result, so it's
obviously a difference between whatever version of echo you have and
the one in the gnu coreutils package.  I'll attach a patch that makes
the code use a simple perl -e construct to accomplish the same thing in
a compatible manner (for any system with perl).  Using that avoids the
need to add the -- chars to the output like I did in my earlier patch.

 I have added the tests and the 1 liner to have -c=foo functionality,
 just commented out and disabled for now.

Please note that that one-line fix won't work without my prior patch
that fixes the problem with a short option that has an embedded (or
leading) equal in an abutting arg (e.g. test1 -2foo=bar).  I'll attach
it here in case you missed it.

..wayne..
--- test-poptrc 16 Feb 2008 22:16:10 -  1.4
+++ test-poptrc 9 Mar 2008 04:13:55 -
@@ -7,6 +7,6 @@ test1 alias -O --arg1
 test1 alias --grab --arg2 'foo !#:+'
 test1 alias --grabbar --grab bar
 
-test1 exec --echo-args echo --
+test1 exec --echo-args perl -e 'print @ARGV' --
 test1 alias -e --echo-args
-test1 exec -a /bin/echo --
+test1 exec -a perl -e 'print @ARGV' --
--- popt.c  8 Mar 2008 17:26:30 -   1.116
+++ popt.c  8 Mar 2008 20:48:43 -
@@ -901,6 +901,7 @@ int poptGetNextOpt(poptContext con)
 
if (!opt) {
con-os-nextCharArg = origOptString + 1;
+   longArg = NULL;
} else {
if (con-os == con-optionStack  F_ISSET(opt, STRIP))
{