This is the mail archive of the
cygwin-patches@cygwin.com
mailing list for the Cygwin project.
Re: getfacl help/version patch
- From: Joshua Daniel Franklin <joshuadfranklin at yahoo dot com>
- To: Corinna Vinschen <cygwin-patches at cygwin dot com>
- Date: Wed, 22 May 2002 10:57:00 -0700 (PDT)
- Subject: Re: getfacl help/version patch
--- Corinna Vinschen <cygwin-patches@cygwin.com> wrote:
> On Tue, May 21, 2002 at 05:23:22PM -0500, Joshua Daniel Franklin wrote:
> > > On Mon, May 20, 2002 at 05:33:01PM -0500, Joshua Daniel Franklin wrote:
> > > > Here is a patch to getfacl that adds longopts for all options,
> > > > standardizes the usage output, and adds the GNU standard --version
> option.
> > >
> What I don't get is
> the reasoning for introducing the --examples option. From my point
> of view that output should still be a part of --help.
>
> Corinna
OK, here is a patch that does as you suggested. I don't like all the
information being part of usage for several reasons:
1. It is not 'standard' behavior. I couldn't find any other GNU or
other utilities that gave so much info on 'foo --help' (maybe 'less',
but it just uses itself to display the help anyway). Some GNU stuff
has mulitple pages of output but that's because there are so many
options ('ls').
2. The information is pretty obvious from just the output, at least to
someone who's familiar with UNIX. What I need the --help for is if I
forget, for example if you get UID numbers with -n or -u. I find it
frustrating that to actually get the simple usage info I need I have to
do 'getfacl --help | head' or 'getfacl --nosuchoption' However, I also
think that having helpful explanations in the binary could be useful,
so I came up with --examples
3. The extra information is difficult to process for the autogenerated
man pages I make. There is a perl function that takes the output and
creates the "OPTIONS" section. There is no page for getfacl yet, but
I plan on making one after I finish adding --help,--version to all the
utils. See 'man strace' to see what I mean. It'd be easier if it was
standard usage output. This is of course entirely my own problem that
doesn't effect anyone else, but I thought it's worth a try to 'fix' it.
Anyway, you should now have working patches that either include the extra
information or not. I am fine and happy with either though of course I prefer
the one without.
Have a nice day!
Joshua Daniel Franklin
__________________________________________________
Do You Yahoo!?
LAUNCH - Your Yahoo! Music Experience
http://launch.yahoo.com
--- getfacl.c-orig Tue May 21 17:16:56 2002
+++ getfacl.c Wed May 22 12:36:14 2002
@@ -1,6 +1,6 @@
/* getfacl.c
- Copyright 2000, 2001 Red Hat Inc.
+ Copyright 2000, 2001, 2002 Red Hat Inc.
Written by Corinna Vinschen <vinschen@redhat.com>
@@ -20,6 +20,9 @@ details. */
#include <sys/stat.h>
#include <string.h>
+static const char version[] = "$Revision: 1.13 $";
+static char *prog_name;
+
char *
permstr (mode_t perm)
{
@@ -58,68 +61,84 @@ groupname (gid_t gid)
return gbuf;
}
-#define pn(txt) fprintf (fp, txt "\n", name)
-#define p(txt) fprintf (fp, txt "\n")
-
-int
-usage (const char *name, int help)
+static void
+usage (FILE * stream)
{
- FILE *fp = help ? stdout : stderr;
-
- pn ("usage: %s [-adn] file...");
- if (!help)
- pn ("Try `%s --help' for more information.");
- else
+ fprintf (stream, "Usage: %s [-adn] FILE [FILE2...]\n"
+ "Display file and directory access control lists (ACLs).\n"
+ "\n"
+ " -a, --all display the filename, the owner, the group, and\n"
+ " the ACL of the file\n"
+ " -d, --dir display the filename, the owner, the group, and\n"
+ " the default ACL of the directory, if it exists\n"
+ " -h, --help output usage information and exit\n"
+ " -n, --noname display user and group IDs instead of names\n"
+ " -v, --version output version information and exit\n"
+ "\n"
+ "When multiple files are specified on the command line, a blank\n"
+ "line separates the ACLs for each file.\n", prog_name);
+ if (stream == stdout)
{
- p ("");
- p ("Display file and directory access control lists (ACLs).");
- p ("");
- p ("For each argument that is a regular file, special file or");
- p ("directory, getfacl displays the owner, the group, and the ACL.");
- p ("For directories getfacl displays additionally the default ACL.");
- p ("");
- p ("With no options specified, getfacl displays the filename, the");
- p ("owner, the group, and both the ACL and the default ACL, if it");
- p ("exists.");
- p ("");
- p ("The following options are supported:");
- p ("");
- p ("-a Display the filename, the owner, the group, and the ACL");
- p (" of the file.");
- p ("");
- p ("-d Display the filename, the owner, the group, and the default");
- p (" ACL of the directory, if it exists.");
- p ("");
- p ("-n Display user and group IDs instead of names.");
- p ("");
- p ("The format for ACL output is as follows:");
- p (" # file: filename");
- p (" # owner: name or uid");
- p (" # group: name or uid");
- p (" user::perm");
- p (" user:name or uid:perm");
- p (" group::perm");
- p (" group:name or gid:perm");
- p (" mask:perm");
- p (" other:perm");
- p (" default:user::perm");
- p (" default:user:name or uid:perm");
- p (" default:group::perm");
- p (" default:group:name or gid:perm");
- p (" default:mask:perm");
- p (" default:other:perm");
- p ("");
- p ("When multiple files are specified on the command line, a blank");
- p ("line separates the ACLs for each file.");
+ fprintf (stream, ""
+ "For each argument that is a regular file, special file or\n"
+ "directory, getfacl displays the owner, the group, and the ACL.\n"
+ "For directories getfacl displays additionally the default ACL.\n"
+ "\n"
+ "With no options specified, getfacl displays the filename, the\n"
+ "owner, the group, and both the ACL and the default ACL, if it\n"
+ "exists.\n"
+ "\n"
+ "The format for ACL output is as follows:\n"
+ " # file: filename\n"
+ " # owner: name or uid\n"
+ " # group: name or uid\n"
+ " user::perm\n"
+ " user:name or uid:perm\n"
+ " group::perm\n"
+ " group:name or gid:perm\n"
+ " mask:perm\n"
+ " other:perm\n"
+ " default:user::perm\n"
+ " default:user:name or uid:perm\n"
+ " default:group::perm\n"
+ " default:group:name or gid:perm\n"
+ " default:mask:perm\n"
+ " default:other:perm\n"
+ "\n");
}
- return 1;
}
struct option longopts[] = {
+ {"all", no_argument, NULL, 'a'},
+ {"dir", no_argument, NULL, 'd'},
{"help", no_argument, NULL, 'h'},
+ {"noname", no_argument, NULL, 'n'},
+ {"version", no_argument, NULL, 'v'},
{0, no_argument, NULL, 0}
};
+static void
+print_version ()
+{
+ const char *v = strchr (version, ':');
+ int len;
+ if (!v)
+ {
+ v = "?";
+ len = 1;
+ }
+ else
+ {
+ v += 2;
+ len = strchr (v, ' ') - v;
+ }
+ printf ("\
+getfacl (cygwin) %.*s\n\
+ACL Utility\n\
+Copyright (c) 2000, 2001, 2002 Red Hat, Inc.\n\
+Compiled on %s", len, v, __DATE__);
+}
+
int
main (int argc, char **argv)
{
@@ -132,7 +151,15 @@ main (int argc, char **argv)
struct stat st;
aclent_t acls[MAX_ACL_ENTRIES];
- while ((c = getopt_long (argc, argv, "adn", longopts, NULL)) != EOF)
+ prog_name = strrchr (argv[0], '/');
+ if (prog_name == NULL)
+ prog_name = strrchr (argv[0], '\\');
+ if (prog_name == NULL)
+ prog_name = argv[0];
+ else
+ prog_name++;
+
+ while ((c = getopt_long (argc, argv, "adhnv", longopts, NULL)) != EOF)
switch (c)
{
case 'a':
@@ -141,16 +168,24 @@ main (int argc, char **argv)
case 'd':
dopt = 1;
break;
+ case 'h':
+ usage (stdout);
+ return 0;
case 'n':
nopt = 1;
break;
- case 'h':
- return usage (argv[0], 1);
+ case 'v':
+ print_version ();
+ return 0;
default:
- return usage (argv[0], 0);
+ usage (stderr);
+ return 1;
}
if (optind > argc - 1)
- return usage (argv[0], 0);
+ {
+ usage (stderr);
+ return 1;
+ }
while ((c = optind++) < argc)
{
if (stat (argv[c], &st))