bug-inetutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-inetutils] [PATCH 3/7] argp'fied argument parsing & tiny fixes


From: Alfred M. Szmidt
Subject: Re: [bug-inetutils] [PATCH 3/7] argp'fied argument parsing & tiny fixes
Date: Sat, 30 Aug 2008 15:31:33 -0400

Thank you for working on this.

           * telnet/main.c: Include <argp.h> and
           <libinetutils/libinetutils.h>.
           Remove include for <getopt.h>.
           (MAX_TLINE_BUF): New macro.
           (cmd_args): New data structure.
           (ARGP_PROGRAM_DATA): Call macro.
           (argp, args_doc, doc, argp_options): New variables.
           (parse_opt): New function.
           (help, try_help, usage): Functions removed.
           (long_options): Variables removed.
           (args, argp): Variables removed.
           (main): Use strncpy () instead of strcpy for copying command line
           args. Use argp to parse program options. Moved all of secondary
           argumetn parsing to parse_opt.
           ^^^^^^^^
Typo.


   -/* Print a help message describing all options to STDOUT and exit with a
   -   status of 0.  */
   -static void
   -help ()
   +struct _cmd_args
    {
   -  fprintf (stdout, USAGE, prompt);
   +  char *argv[8];
   +  char **argptr;
   +};
   +typedef struct _cmd_args cmd_args;

_FOO tends to be reserved for the compiler, and lower level parts.  I
generally use something like:

| struct cmd_args
| {
|   char **argv[8];
|   char **argptr;
| };
| typedef struct cmd_args cmd_args_t;


I don't follow the following code from parse_opt, what are you trying
to achieve?

   +    case ARGP_KEY_ARG:
   +      if (state->arg_num == 0)
   +    /* More than 2 arguments */
   +    if ((state->argc - state->next) > 1)
   +      argp_usage (state);
   +      
   +      if (user)
   +      {
   +    *(c_args->argptr)++ = "-l";
   +    *(c_args->argptr)++ = user;
   +      }
   +      if (family == 4)
   +    *(c_args->argptr)++ = "-4";
   +      else if (family == 6)
   +    *(c_args->argptr)++ = "-6";
   +
   +      *(c_args->argptr)++ = arg;    /* host */
   +      if (state->argc - state->next)
   +    *(c_args->argptr)++ = state->argv[state->next]; /* port */
   +
   +      *(c_args->argptr) = NULL;
   +
   +      /* Froce argp to stop processing remaining args,
   +       * as we've got them all. */
   +      state->next = state->argc;
   +      break;
   +
   +    default:
   +      return ARGP_ERR_UNKNOWN;
   +  }
   +  
   +  return 0;
    }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]