[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-sysutils] argp and getline() patch for remove-shell
From: |
Barry deFreese |
Subject: |
[Bug-sysutils] argp and getline() patch for remove-shell |
Date: |
Fri, 28 May 2004 14:51:55 -0700 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040413 Debian/1.6-5 |
OK, here is the patch for remove-shell.
Thanks,
--
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/remove-shell.c
===================================================================
RCS file: /cvsroot/sysutils/sysutils/src/remove-shell.c,v
retrieving revision 1.2
diff -r1.2 remove-shell.c
21a22,23
> #define _GNU_SOURCE
> #include <argp.h>
23a26
> #include <stdlib.h>
26d28
< #include <stdlib.h>
34,35d35
< extern int optind;
< extern char *optarg;
38,41c38,57
< /**
< * Show usage information
< */
< static void usage(void)
---
> const char *argp_program_bug_address = PACKAGE_BUGREPORT;
>
> static char args_doc[] = "SHELL";
>
> static char doc[] =
> N_("Remove a shell from the list of valid shells.");
>
> static struct argp_option options[] = {
> {"verbose", 'v', 0, 0,
> N_("warn if the shell is not listed as a valid shell\n"), 0},
> { 0, 0, 0, 0, 0, 0}
> };
>
> struct arguments {
> char *args;
> long verbose;
> };
>
> /* Parse a single option */
> static error_t parse_opt(int key, char *arg, struct argp_state *state)
43,50c59,81
< fprintf(stdout,
< _("Usage: %s [OPTION] SHELL\n"
< "Remove a shell from the list of valid shells.\n"
< "\n"
< " --verbose warn if the shell is not "
< "listed as a valid shell\n"),
< progname);
< usage_help();
---
> struct arguments *args = state->input;
>
> switch(key) {
> case 'v':
> args->verbose = 1;
> break;
>
> case ARGP_KEY_INIT:
> args->verbose = 0;
> break;
>
> case ARGP_KEY_ARG:
> if (state->arg_num >= 2)
> argp_usage(state);
>
> args->args = arg;
>
> break;
>
> default:
> return ARGP_ERR_UNKNOWN;
> }
> return 0;
62c93
< static char buf[PATH_MAX + 1];
---
> size_t len = 0;
67c98
< int verbose = 0;
---
> int status = 0;
69,70c100,103
< int optc;
< int opt_index;
---
> /* argp parser */
> struct argp argp = {
> options, parse_opt, args_doc, doc, NULL, NULL, NULL
> };
72c105,109
< int status = 0;
---
> struct arguments args;
>
> argp_program_version_hook = version;
>
> int getline_rc = 0;
78,84d114
< struct option const options[] = {
< { "verbose", no_argument, 0, 'v' },
< { "help", no_argument, 0, 'h' },
< { "version", no_argument, 0, 'V' },
< { 0, 0, 0, 0 }
< };
<
87,88d116
< buf[PATH_MAX] = '\0';
<
93,114c121,124
< /* Parse the command-line options */
< while ((optc = getopt_long(argc, argv, "",
< options, &opt_index)) != -1) {
< switch (optc) {
< case 'v':
< verbose = 1;
< break;
<
< case 'h':
< usage();
< goto EXIT;
<
< case 'V':
< version();
< goto EXIT;
<
< default:
< usage();
< status = EINVAL;
< goto EXIT;
< }
< }
---
> set_author_information(_("Written by David Weinhall.\n"));
>
> /* Parse command line */
> argp_parse(&argp, argc, argv, 0, 0, &args);
134,154c144,145
< /* Make sure we get the correct number of arguments */
< if (argc - optind < 1) {
< fprintf(stderr,
< _("%s: too few arguments\n"
< "Try `%s --help' for more information.\n"),
< progname, progname);
< status = EINVAL;
< goto EXIT;
< }
<
< if ((argc - optind) > 1) {
< fprintf(stderr,
< _("%s: too many arguments\n"
< "Try `%s --help' for more information.\n"),
< progname, progname);
< status = EINVAL;
< goto EXIT;
< }
<
< if (is_listed_shell(argv[optind])) {
< if (verbose) {
---
> if (is_listed_shell(args.args)) {
> if (args.verbose) {
158c149
< progname, argv[optind]);
---
> progname, args.args);
197,215c188,189
< while ((shell = fgets(buf, PATH_MAX, rfp))) {
< static long lines = 1;
< char *tmp;
<
< if (buf[PATH_MAX] != '\0') {
< fprintf(stderr,
< _("%s: line `%ld' in `%s' is too long, "
< "truncating\n"),
< progname, lines, SHELLS_FILE);
< buf[PATH_MAX] = '\0';
< }
<
< lines++;
<
<
< if ((tmp = strchr(shell, '\n')))
< *tmp = '\0';
<
< if (!strcmp(shell, argv[optind]))
---
> while ((getline_rc = getline(&shell, &len, rfp)) != -1) {
> if (!strncmp(shell, args.args, strlen(args.args)))
219c193
< if ((status = fprintf(wfp, "%s\n", shell)) < 0) {
---
> if ((status = fprintf(wfp, "%s", shell)) < 0) {
225a200,202
>
> if (shell)
> free(shell);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug-sysutils] argp and getline() patch for remove-shell,
Barry deFreese <=