[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-sysutils] argp patch for chsh
From: |
Barry deFreese |
Subject: |
[Bug-sysutils] argp patch for chsh |
Date: |
Mon, 31 May 2004 06:18:09 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040413 Debian/1.6-5 |
Here is another patch.
Thank you,
--
Barry deFreese
Debian 3.0r1 "Woody"
GNU/Hurd
Registered Linux "Newbie" #302256 - Hurd H4XX0r wannabe
"Programming today is a race between software engineers striving
to build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots. So far, the Universe is
winning." Rich Cook.
Index: src/chsh.c
===================================================================
RCS file: /cvsroot/sysutils/sysutils/src/chsh.c,v
retrieving revision 1.6
diff -r1.6 chsh.c
22a23
> #include <argp.h>
35,36d35
< extern int optind;
< extern char *optarg;
39,42c38,64
< /**
< * Show usage information
< */
< static void usage(void)
---
> const char *argp_program_bug_address = PACKAGE_BUGREPORT;
>
> static char doc[] =
> N_("Change the login shell for the specified user."
> "\n"
> "If no username is specified, "
> "the information for the current user is changed.");
>
> static char args_doc[] = N_("[USER]");
>
> static struct argp_option options[] = {
> {"shell", 's', N_("SHELL"), 0,
> N_("the user's login shell"), 0 },
> {"list-shells", 'l', 0, OPTION_ARG_OPTIONAL,
> N_("list valid login shells"), 0 },
> { 0, 0, 0, 0, 0, 0 }
> };
>
> /* Available arguments */
> struct arguments {
> char *user;
> char *shell;
> long list;
> };
>
> /* Parse a single option */
> static error_t parse_opt(int key, char *arg, struct argp_state *state)
44,54c66,101
< fprintf(stdout,
< _("Usage: %s [OPTION]... [USER]\n"
< "Change the login shell for the specified user.\n"
< "\n"
< "If no username is specified, "
< "the information for the current user is changed.\n"
< "\n"
< " -l, --list-shells list valid login shells\n"
< " -s, --shell=SHELL the user's login shell\n"),
< progname);
< usage_help();
---
> struct arguments *args = state->input;
>
> switch (key) {
> case 's':
> args->shell = arg;
>
> if (!(is_valid_shell(args->shell)) ||
> ((is_listed_shell(args->shell))) ) {
> argp_error(state, "invalid value supplied\n");
> }
>
> break;
>
> case 'l':
> args->list = 1;
>
>
> break;
>
> case ARGP_KEY_INIT:
> args->user = NULL;
> args->shell = NULL;
> args->list = 0;
> break;
>
> case ARGP_KEY_ARG:
> if (args->user)
> argp_usage(state);
>
> args->user = arg;
> break;
>
> default:
> return ARGP_ERR_UNKNOWN;
> }
> return 0;
72,74d118
< int optc;
< int opt_index;
<
84,89c128,130
< struct option const options[] = {
< { "list-shells", no_argument, 0, 'l' },
< { "shell", required_argument, 0, 's' },
< { "help", no_argument, 0, 'h' },
< { "version", no_argument, 0, 'V' },
< { 0, 0, 0, 0 }
---
> /* argp parser */
> struct argp argp = {
> options, parse_opt, args_doc, doc, NULL, NULL, NULL
91a133,136
> struct arguments args;
>
> argp_program_version_hook = version;
>
97a143,147
> set_author_information(_("Written by David Weinehall.\n"));
>
> /* Parse command line */
> argp_parse(&argp, argc, argv, 0, 0, &args);
>
112,150c162,165
< /* Parse the command-line options */
< while ((optc = getopt_long(argc, argv, "ls:",
< options, &opt_index)) != -1) {
< switch (optc) {
< case 'l':
< fprintf(stdout, _("Valid login shells:\n\n"));
<
< setusershell();
<
< while ((shell = getusershell()))
< fprintf(stdout, "%s\n", shell);
<
< endusershell();
<
< break;
<
< case 's':
< if (!(shell = strdup(optarg))) {
< fprintf(stderr,
< _("%s: `%s' failed; %s\n"),
< progname, "strdup()", strerror(errno));
< status = errno;
< goto EXIT;
< }
<
< if ((status = is_valid_shell(shell)) ||
< (!isadmin && (status = is_listed_shell(shell)))) {
< fprintf(stderr,
< _("%s: invalid value supplied to "
< "`%s'\n"),
< progname, "-s | --shell");
< goto EXIT;
< }
<
< break;
<
< case 'h':
< usage();
< goto EXIT;
---
> /* If --list-shell is supplied, just list the available shells and exit
> */
> if (args.list) {
> fprintf(stdout, _("\nValid login shells:\n\n"));
152,154c167
< case 'V':
< version();
< goto EXIT;
---
> setusershell();
156,161c169,170
< default:
< usage();
< status = EINVAL;
< goto EXIT;
< }
< }
---
> while ((shell = getusershell()))
> fprintf(stdout, "%s\n", shell);
163,169c172
< /* Make sure we get the correct number of arguments */
< if ((argc - optind) > 1) {
< fprintf(stderr,
< _("%s: too many arguments\n"
< "Try `%s --help' for more information.\n"),
< progname, progname);
< status = EINVAL;
---
> endusershell();
176,177c179,180
< if (optind != argc) {
< if (!(username = strdup(argv[optind]))) {
---
> if (args.user) {
> if (!(username = strdup(args.user))) {
185a189,200
> /* If a shell was entered as an arg, make a copy
> * for consistency with interactive mode
> */
> if (args.shell) {
> if (!(shell = strdup(args.shell))) {
> fprintf(stderr, _("%s: `%s' failed; %s\n"),
> progname, "strdup()", strerror(errno));
> status = errno;
> goto EXIT;
> }
> }
>
251c266
< if (optind == 1) {
---
> if (argc == 1) {
- [Bug-sysutils] argp patch for chsh,
Barry deFreese <=