cvs commit: src/usr.sbin/pkg_install/add main.c
pkg_add.1 src/usr.sbin/pkg_install/create main.c
pkg_create.1 src/usr.sbin/pkg_install/delete main.c
pkg_delete.1 src/usr.sbin/pkg_install/info main.c pkg_info.1 ...
Steve Kargl
sgk at troutmask.apl.washington.edu
Wed Jun 4 22:30:18 UTC 2008
On Wed, Jun 04, 2008 at 05:24:23PM -0400, Coleman Kane wrote:
> It's probably premature to begin shooting that down. I merely picked
> "cp" as the first tool that came to mind which lives in /bin. Maybe I
> should have picked on /bin/pax or /usr/bin/lex instead, or something
> else with 20+ getopt args :P.
>
> My point was that it was pretty absurd to start treating this like it
> will turn into a giant mad party of getopt_long conversions. I don't
> really have the inclination to go out and add long options to any tool
> myself, because I have better things to do with my time. As I said
> earlier, I think it's a better policy to discuss this when the
> patch/commit comes along, and see what people's feelings are on the
> matter then. I don't think it is anybody's place at the moment (except
> maybe core@) to try and deter a committer from making what some feel is
> a beneficial change to software.
>
Please commit. The patch gives conformance to Posix
(ie., IEEE Std 1003.1, 2004 Edition).
As a bonus, I've included long options for compatibility
with GNU wc.
Index: wc.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/wc/wc.1,v
retrieving revision 1.25
diff -u -p -r1.25 wc.1
--- wc.1 21 Dec 2006 22:59:07 -0000 1.25
+++ wc.1 4 Jun 2008 22:27:15 -0000
@@ -71,25 +71,19 @@ the last file.
.Pp
The following options are available:
.Bl -tag -width indent
-.It Fl c
+.It Fl c , -bytes
The number of bytes in each input file
is written to the standard output.
-This will cancel out any prior usage of the
-.Fl m
-option.
-.It Fl l
+.It Fl l , -lines
The number of lines in each input file
is written to the standard output.
-.It Fl m
+.It Fl m , -chars
The number of characters in each input file is written to the standard output.
If the current locale does not support multibyte characters, this
is equivalent to the
.Fl c
option.
-This will cancel out any prior usage of the
-.Fl c
-option.
-.It Fl w
+.It Fl w , -words
The number of words in each input file
is written to the standard output.
.El
Index: wc.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/wc/wc.c,v
retrieving revision 1.21
diff -u -p -r1.21 wc.c
--- wc.c 27 Dec 2004 22:27:56 -0000 1.21
+++ wc.c 4 Jun 2008 22:27:15 -0000
@@ -53,6 +53,7 @@ __FBSDID("$FreeBSD: src/usr.bin/wc/wc.c,
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <getopt.h>
#include <locale.h>
#include <stdint.h>
#include <stdio.h>
@@ -68,6 +69,15 @@ int doline, doword, dochar, domulti;
static int cnt(const char *);
static void usage(void);
+static char opts[] = "clmw";
+static struct option longopts[] = {
+ { "bytes", no_argument, NULL, 'c' },
+ { "lines", no_argument, NULL, 'l' },
+ { "chars", no_argument, NULL, 'm' },
+ { "words", no_argument, NULL, 'w' },
+ { NULL, 0, NULL, 0 },
+};
+
int
main(int argc, char *argv[])
{
@@ -75,7 +85,7 @@ main(int argc, char *argv[])
(void) setlocale(LC_CTYPE, "");
- while ((ch = getopt(argc, argv, "clmw")) != -1)
+ while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1)
switch((char)ch) {
case 'l':
doline = 1;
@@ -85,11 +95,13 @@ main(int argc, char *argv[])
break;
case 'c':
dochar = 1;
- domulti = 0;
+ if (domulti)
+ errx(1, "-c conflicts with -m");
break;
case 'm':
domulti = 1;
- dochar = 0;
+ if (dochar)
+ errx(1, "-m conflicts with -c");
break;
case '?':
default:
@@ -263,6 +275,6 @@ word: gotsp = 1;
static void
usage()
{
- (void)fprintf(stderr, "usage: wc [-clmw] [file ...]\n");
+ (void)fprintf(stderr, "usage: wc [-c|-m][-lw] [file ...]\n");
exit(1);
}
More information about the cvs-src
mailing list