[BusyBox] tar and getopt (again)

Erik Andersen andersen at lineo.com
Mon Jan 22 06:52:27 UTC 2001


On Sun Jan 21, 2001 at 10:19:27PM -0800, Matt Kraai wrote:
> Howdy,
> 
> The attached patch makes tar use getopt.  It does so by using a
> cheap trick I learned from reading GNU tar.  That is, if the first
> parameter is missing a leading -, add it.  Hehe.  The patch is
> large since most of the option parsing was reindented.  It saves
> 16 bytes.  OK to commit?
> 
> Matt


Ahh.  Pretty sneaky -- there are a few other apps that could use similar
treatment (such as dd).  Cool.  A quick look over your patch doesn't show any
major malfunctions.  I would prefer avoiding getopt_long, since it is only used
in getopt (and it needs to be removed from that too).  To use just plain old
getopt with a long option do something like the following completely untested
bit of code:

    while ((opt = getopt(argc, argv, "x-")) > 0) {
	switch (opt) {
	    case 'x':
		something++;
		break;
	    case '-':
		if(strcmp(argv[optind], "--exclude")==0) {
		    exclude++;
		    break;
		}
		usage(app_usage);
	}
    }

 -Erik

--
Erik B. Andersen   email:  andersen at lineo.com
--This message was written using 73% post-consumer electrons--
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
Url : http://lists.busybox.net/pipermail/busybox/attachments/20010121/b459feff/attachment.pgp 


More information about the busybox mailing list