apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kfo...@locus.apache.org
Subject cvs commit: apr/misc/unix getopt.c
Date Sat, 25 Nov 2000 05:15:00 GMT
kfogel      00/11/24 21:15:00

  Modified:    misc/unix getopt.c
  Log:
  More changes from Greg Hudson <ghudson@mit.edu>, w/ small doc tweaks
  from Karl Fogel <kfogel@collab.net>:
  
  (apr_getopt_option_t): rename from apr_longopt_t, because more accurate.
  (apr_initopt, apr_getopt_long, reverse): take "char *const *argv", act
  on a copy instead of the original, since we may permute the array.
  
  This is a compromise.  The parameter must be compatible with the argv
  value passed to main, since that is the primary purpose of the
  function.  But as has been pointed out, people might want to use the
  function with arrays other than argv, and we shouldn't touch the
  caller's data.
  
  Revision  Changes    Path
  1.26      +15 -5     apr/misc/unix/getopt.c
  
  Index: getopt.c
  ===================================================================
  RCS file: /home/cvs/apr/misc/unix/getopt.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- getopt.c	2000/11/25 02:19:43	1.25
  +++ getopt.c	2000/11/25 05:14:59	1.26
  @@ -49,14 +49,24 @@
   }
   
   APR_DECLARE(apr_status_t) apr_initopt(apr_getopt_t **os, apr_pool_t *cont,
  -                                     int argc, char **argv)
  +                                     int argc, char *const *argv)
   {
  +    int i;
  +
       *os = apr_palloc(cont, sizeof(apr_getopt_t));
       (*os)->cont = cont;
       (*os)->err = 1;
       (*os)->place = EMSG;
       (*os)->argc = argc;
  -    (*os)->argv = argv;
  +
  +    /* The argv parameter must be compatible with main()'s argv, since
  +       that's the primary purpose of this function.  But people might
  +       want to use this function with arrays other than the main argv,
  +       and we shouldn't touch the caller's data.  So we copy. */
  +    (*os)->argv = apr_palloc(cont, argc * sizeof(const char *));
  +    for (i = 0; i < argc; i++)
  +	(*os)->argv[i] = argv[i];
  +
       (*os)->interleave = 0;
       (*os)->ind = 1;
       (*os)->skip_start = 1;
  @@ -135,9 +145,9 @@
   }
   
   /* Reverse the sequence argv[start..start+len-1]. */
  -static void reverse(char **argv, int start, int len)
  +static void reverse(const char **argv, int start, int len)
   {
  -    char *temp;
  +    const char *temp;
   
       for (; len >= 2; start++, len -= 2) {
   	temp = argv[start];
  @@ -193,7 +203,7 @@
   }
   
   APR_DECLARE(apr_status_t) apr_getopt_long(apr_getopt_t *os,
  -					  const apr_longopt_t *opts,
  +					  const apr_getopt_option_t *opts,
   					  int *optch, const char **optarg)
   {
       const char *p;
  
  
  

Mime
View raw message