home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / tools / rbdump / read.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  3.7 KB  |  152 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright International Business Machines Corporation, 1998, 1999     *
  6. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  7. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  8. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  9. *                                                                             *
  10. *******************************************************************************
  11. *
  12. * File main.c
  13. *
  14. * Modification History:
  15. *
  16. *   Date        Name        Description
  17. *   06/10/99    stephen        Creation.
  18. *******************************************************************************
  19. */
  20.  
  21. #include <stdio.h>
  22.  
  23. #include "utypes.h"
  24. #include "cmemory.h"
  25. #include "cstring.h"
  26. #include "filestrm.h"
  27. #include "parse.h"
  28.  
  29.  
  30. /* Protos */
  31. static void usage();
  32. static void version();
  33. static void processFile(const char *filename, UErrorCode *status);
  34. int main(int argc, char **argv);
  35.  
  36. /* The version of rbdump */
  37. #define RBDUMP_VERSION "1.0"
  38.  
  39.  
  40. int
  41. main(int argc,
  42.      char **argv)
  43. {
  44.   int printUsage = 0;
  45.   int printVersion = 0;
  46.   int optind = 1;
  47.   int i;
  48.   char *arg;
  49.   UErrorCode status;
  50.  
  51.  
  52.   /* parse the options */
  53.   for(optind = 1; optind < argc; ++optind) {
  54.     arg = argv[optind];
  55.     
  56.     /* version info */
  57.     if(icu_strcmp(arg, "-v") == 0 || icu_strcmp(arg, "--version") == 0) {
  58.       printVersion = 1;
  59.     }
  60.     /* usage info */
  61.     else if(icu_strcmp(arg, "-h") == 0 || icu_strcmp(arg, "--help") == 0) {
  62.       printUsage = 1;
  63.     }
  64.     /* POSIX.1 says all arguments after -- are not options */
  65.     else if(icu_strcmp(arg, "--") == 0) {
  66.       /* skip the -- */
  67.       ++optind;
  68.       break;
  69.     }
  70.     /* unrecognized option */
  71.     else if(icu_strncmp(arg, "-", icu_strlen("-")) == 0) {
  72.       printf("rbdump: invalid option -- %s\n", arg+1);
  73.       printUsage = 1;
  74.     }
  75.     /* done with options, start file processing */
  76.     else {
  77.       break;
  78.     }
  79.   }
  80.  
  81.   /* print usage info */
  82.   if(printUsage) {
  83.     usage();
  84.     return 0;
  85.   }
  86.  
  87.   /* print version info */
  88.   if(printVersion) {
  89.     version();
  90.     return 0;
  91.   }
  92.  
  93.   /* print out the files */
  94.   for(i = optind; i < argc; ++i) {
  95.     status = U_ZERO_ERROR;
  96.     processFile(argv[i], &status);
  97.     if(U_FAILURE(status)) {
  98.       printf("rbdump: %s processing file \"%s\"\n", errorName(status), argv[i]);
  99.     }
  100.   }
  101.  
  102.   return 0;
  103. }
  104.  
  105. /* Usage information */
  106. static void
  107. usage()
  108. {  
  109.   puts("Usage: rbdump [OPTIONS] [FILES]");
  110.   puts("Options:");
  111.   puts("  -h, --help        Print this message and exit.");
  112.   puts("  -v, --version     Print the version number of rbdump and exit.");
  113. }
  114.  
  115. /* Version information */
  116. static void
  117. version()
  118. {
  119.   printf("rbdump version %s (ICU version %s), by Stephen F. Booth.\n", 
  120.      RBDUMP_VERSION, ICU_VERSION);
  121.   puts("(C) Copyright International Business Machines Corporation, 1998, 1999");
  122.   puts("Licensed Material - Program-Property of IBM - All Rights Reserved.");
  123.   puts("US Government Users Restricted Rights - Use, duplication, or disclosure");
  124.   puts("restricted by GSA ADP Schedule Contract with IBM Corp.");
  125. }
  126.  
  127. /* Process a file */
  128. static void
  129. processFile(const char *filename,
  130.         UErrorCode *status)
  131. {
  132.   FileStream *in;
  133.  
  134.   if(U_FAILURE(*status)) return;
  135.  
  136.   /* Setup */
  137.   in =  0;
  138.  
  139.   /* Open the input file for reading */
  140.   in = T_FileStream_open(filename, "rb");
  141.   if(in == 0) {
  142.     *status = U_FILE_ACCESS_ERROR;
  143.     return;
  144.   }
  145.  
  146.   /* Parse the data and print it out */
  147.   parse(in, status);
  148.  
  149.   /* Clean up */
  150.   T_FileStream_close(in);
  151. }
  152.