apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jerenkra...@apache.org
Subject cvs commit: apr-iconv/util iconv.c
Date Fri, 26 Sep 2003 07:11:24 GMT
jerenkrantz    2003/09/26 00:11:24

  Modified:    .        Tag: API_0_9_BRANCH CHANGES
               util     Tag: API_0_9_BRANCH iconv.c
  Log:
  Check in a CHANGES file, and add a -v option to iconv utility program.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.8.2.1   +6 -0      apr-iconv/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr-iconv/CHANGES,v
  retrieving revision 1.8
  retrieving revision 1.8.2.1
  diff -u -u -r1.8 -r1.8.2.1
  --- CHANGES	24 Apr 2003 08:08:31 -0000	1.8
  +++ CHANGES	26 Sep 2003 07:11:24 -0000	1.8.2.1
  @@ -1,5 +1,11 @@
   Changes with APR-ICONV 0.9.4
   
  +  *) Add -v option to iconv program. [Justin Erenkrantz]
  +
  +  *) Add api_version.h. [Justin Erenkrantz]
  +
  +  *) A fourth pass at a build system. [Justin Erenkrantz]
  +
     *) A third pass at a build system. [Justin Erenkrantz]
   
   Changes with APR-ICONV 0.9.3
  
  
  
  No                   revision
  No                   revision
  1.6.2.1   +46 -27    apr-iconv/util/iconv.c
  
  Index: iconv.c
  ===================================================================
  RCS file: /home/cvs/apr-iconv/util/iconv.c,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -u -r1.6 -r1.6.2.1
  --- iconv.c	28 May 2003 14:05:50 -0000	1.6
  +++ iconv.c	26 Sep 2003 07:11:24 -0000	1.6.2.1
  @@ -31,6 +31,9 @@
    */
   
   #include "apr.h"
  +#include "apr_getopt.h"
  +
  +#include "api_version.h"
   
   #include <stdarg.h>	/* va_end, va_list, va_start */
   #include <stdio.h>	/* FILE, fclose, ferror, fopen, fread, stdin,
  @@ -79,31 +82,55 @@
   }
   
   int
  -main(int argc, char * const *argv)
  +main(int argc, const char **argv)
   {
   	apr_iconv_t cd;
   	iconv_stream *is;
  -	char *from = NULL, *to = NULL, *input = NULL;
  -	int opt;
  +	const char *from = NULL, *to = NULL, *input = NULL;
  +	char opt;
   	apr_pool_t *ctx; 
   	apr_status_t status;
  +    apr_getopt_t *options;
  +    const char *opt_arg;
   
  -	while ((opt = getopt(argc, argv, "f:s:t:")) > 0) {
  -		switch (opt) {
  -		    case 'f':
  -			from = optarg;
  -			break;
  -		    case 't':
  -			to = optarg;
  -			break;
  -		    case 's':
  -			input = optarg;
  -			break;
  -		    default:
  -			fprintf(stderr, "Usage: iconv -f <name> -t <name> [-s <input>]\n");
  -			exit(3);
  -		}
  -	}
  +    /* Initialize APR */
  +    apr_initialize();
  +    atexit(closeapr);
  +    if (apr_pool_create(&ctx, NULL) != APR_SUCCESS) {
  +        fprintf(stderr, "Couldn't allocate context.\n");
  +        exit(-1);
  +    }
  +
  +    apr_getopt_init(&options, ctx, argc, argv);
  +
  +    status = apr_getopt(options, "f:s:t:v", &opt, &opt_arg);
  +
  +    while (status == APR_SUCCESS) {
  +        switch (opt) {
  +        case 'f':
  +            from = opt_arg;
  +            break;
  +        case 't':
  +            to = opt_arg;
  +            break;
  +        case 's':
  +            input = opt_arg;
  +            break;
  +        case 'v':
  +            fprintf(stderr, "APR-iconv version " API_VERSION_STRING "\n");
  +            exit(0);
  +        default:
  +            fprintf(stderr, "Usage: iconv -f <name> -t <name> [-s <input>]\n");
  +            exit(3);
  +        }
  +
  +        status = apr_getopt(options, "f:s:t:v",&opt, &opt_arg);
  +    }
  +
  +    if (status == APR_BADCH || status == APR_BADARG) {
  +        fprintf(stderr, "Usage: iconv -f <name> -t <name> [-s <input>]\n");
  +        exit(3);
  +    }
   	if (from == NULL) {
   		fprintf(stderr, "missing source charset (-f <name>)\n");
   		exit(4);
  @@ -111,14 +138,6 @@
   	if (to == NULL) {
   		fprintf(stderr, "missing destination charset (-t <name>)\n");
   		exit(5);
  -	}
  -
  -	/* Initialize APR */
  -	apr_initialize();
  -	atexit(closeapr);
  -	if (apr_pool_create(&ctx, NULL) != APR_SUCCESS) {
  -		fprintf(stderr, "Couldn't allocate context.\n");
  -		exit(-1);
   	}
   
   	/* Use it */
  
  
  

Mime
View raw message