home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / tools / gencol / gencol.c next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  3.4 KB  |  134 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 gencol.c
  13. *
  14. * Modification History:
  15. *
  16. *   Date        Name        Description
  17. *   06/09/99    stephen        Creation.
  18. *******************************************************************************
  19. */
  20.  
  21. #include <stdio.h>
  22.  
  23. #include "utypes.h"
  24. #include "cmemory.h"
  25. #include "cstring.h"
  26.  
  27. #include "uloc.h"
  28. #include "ucol.h"
  29.  
  30.  
  31. /* Protos */
  32. static void usage();
  33. static void version();
  34. int main(int argc, char **argv);
  35.  
  36.  
  37. /* The version of gencol */
  38. #define GENCOL_VERSION "1.0b"
  39.  
  40.  
  41. int
  42. main(int argc,
  43.      char **argv)
  44. {
  45.   int printUsage = 0;
  46.   int printVersion = 0;
  47.   int optind;
  48.   int i;
  49.   char *arg;
  50.   const char *loc;
  51.   UCollator *coll;
  52.   UErrorCode status;
  53.  
  54.  
  55.   /* parse the options */
  56.   for(optind = 1; optind < argc; ++optind) {
  57.     arg = argv[optind];
  58.     
  59.     /* version info */
  60.     if(icu_strcmp(arg, "-v") == 0 || icu_strcmp(arg, "--version") == 0) {
  61.       printVersion = 1;
  62.     }
  63.     /* usage info */
  64.     else if(icu_strcmp(arg, "-h") == 0 || icu_strcmp(arg, "--help") == 0) {
  65.       printUsage = 1;
  66.     }
  67.     /* POSIX.1 says all arguments after -- are not options */
  68.     else if(icu_strcmp(arg, "--") == 0) {
  69.       /* skip the -- */
  70.       ++optind;
  71.       break;
  72.     }
  73.     /* unrecognized option */
  74.     else if(icu_strncmp(arg, "-", icu_strlen("-")) == 0) {
  75.       printf("gencol: invalid option -- %s\n", arg+1);
  76.       printUsage = 1;
  77.     }
  78.     /* done with options, start file processing */
  79.     else {
  80.       break;
  81.     }
  82.   }
  83.  
  84.   /* print usage info */
  85.   if(printUsage) {
  86.     usage();
  87.     return 0;
  88.   }
  89.  
  90.   /* print version info */
  91.   if(printVersion) {
  92.     version();
  93.     return 0;
  94.   }
  95.  
  96.   /* generate the binary collation files */
  97.   for(i = 0; i < uloc_countAvailable(); ++i) {
  98.     status = U_ZERO_ERROR;
  99.     loc = uloc_getAvailable(i);
  100.     printf("gencol: Creating collation data for locale \"%s\"\n", loc);
  101.     coll = ucol_open(loc, &status);
  102.     if(U_FAILURE(status)) {
  103.       printf("gencol: %s for locale \"%s\"", errorName(status), loc);
  104.     }
  105.     else {
  106.       ucol_close(coll);
  107.     }
  108.   }
  109.   
  110.   return 0;
  111. }
  112.  
  113. /* Usage information */
  114. static void
  115. usage()
  116. {  
  117.   puts("Usage: gencol [OPTIONS] [FILES]");
  118.   puts("Options:");
  119.   puts("  -h, --help        Print this message and exit.");
  120.   puts("  -v, --version     Print the version number of gencol and exit.");
  121. }
  122.  
  123. /* Version information */
  124. static void
  125. version()
  126. {
  127.   printf("gencol version %s (ICU version %s), by Stephen F. Booth.\n", 
  128.      GENCOL_VERSION, ICU_VERSION);
  129.   puts("(C) Copyright International Business Machines Corporation, 1998, 1999");
  130.   puts("Licensed Material - Program-Property of IBM - All Rights Reserved.");
  131.   puts("US Government Users Restricted Rights - Use, duplication, or disclosure");
  132.   puts("restricted by GSA ADP Schedule Contract with IBM Corp.");
  133. }
  134.