]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/tools/genprops/genprops.c
ICU-6.2.10.tar.gz
[apple/icu.git] / icuSources / tools / genprops / genprops.c
index 95091d52412cc0e18f58a8f983b0ce4c9ef0335b..3c09e197c6686e86437410bc150afd2a3f2ccd5d 100644 (file)
@@ -26,6 +26,7 @@
 #include "unicode/uchar.h"
 #include "unicode/uset.h"
 #include "unicode/putil.h"
+#include "unicode/uclean.h"
 #include "cmemory.h"
 #include "cstring.h"
 #include "unewdata.h"
@@ -66,6 +67,20 @@ parseDB(const char *filename, UErrorCode *pErrorCode);
 
 /* -------------------------------------------------------------------------- */
 
+
+enum
+{
+    HELP_H,
+    HELP_QUESTION_MARK,
+    VERBOSE,
+    COPYRIGHT,
+    DESTDIR,
+    SOURCEDIR,
+    UNICODE_VERSION,
+    ICUDATADIR
+};
+
+/* Keep these values in sync with the above enums */
 static UOption options[]={
     UOPTION_HELP_H,
     UOPTION_HELP_QUESTION_MARK,
@@ -73,7 +88,8 @@ static UOption options[]={
     UOPTION_COPYRIGHT,
     UOPTION_DESTDIR,
     UOPTION_SOURCEDIR,
-    { "unicode", NULL, NULL, NULL, 'u', UOPT_REQUIRES_ARG, 0 }
+    { "unicode", NULL, NULL, NULL, 'u', UOPT_REQUIRES_ARG, 0 },
+    UOPTION_ICUDATADIR
 };
 
 extern int
@@ -86,9 +102,10 @@ main(int argc, char* argv[]) {
     U_MAIN_INIT_ARGS(argc, argv);
 
     /* preset then read command line options */
-    options[4].value=u_getDataDirectory();
-    options[5].value="";
-    options[6].value="";
+    options[DESTDIR].value=u_getDataDirectory();
+    options[SOURCEDIR].value="";
+    options[UNICODE_VERSION].value="";
+    options[ICUDATADIR].value=u_getDataDirectory();
     argc=u_parseArgs(argc, argv, sizeof(options)/sizeof(options[0]), options);
 
     /* error handling, printing usage message */
@@ -97,7 +114,7 @@ main(int argc, char* argv[]) {
             "error in command line argument \"%s\"\n",
             argv[-argc]);
     }
-    if(argc<0 || options[0].doesOccur || options[1].doesOccur) {
+    if(argc<0 || options[HELP_H].doesOccur || options[HELP_QUESTION_MARK].doesOccur) {
         /*
          * Broken into chucks because the C89 standard says the minimum
          * required supported string length is 509 bytes.
@@ -118,17 +135,20 @@ main(int argc, char* argv[]) {
         fprintf(stderr,
             "\t-d or --destdir     destination directory, followed by the path\n"
             "\t-s or --sourcedir   source directory, followed by the path\n"
+            "\t-i or --icudatadir  directory for locating any needed intermediate data files,\n"
+            "\t                    followed by path, defaults to %s\n"
             "\tsuffix              suffix that is to be appended with a '-'\n"
             "\t                    to the source file basenames before opening;\n"
-            "\t                    'genprops new' will read UnicodeData-new.txt etc.\n");
+            "\t                    'genprops new' will read UnicodeData-new.txt etc.\n",
+            u_getDataDirectory());
         return argc<0 ? U_ILLEGAL_ARGUMENT_ERROR : U_ZERO_ERROR;
     }
 
     /* get the options values */
-    beVerbose=options[2].doesOccur;
-    haveCopyright=options[3].doesOccur;
-    srcDir=options[5].value;
-    destDir=options[4].value;
+    beVerbose=options[VERBOSE].doesOccur;
+    haveCopyright=options[COPYRIGHT].doesOccur;
+    srcDir=options[SOURCEDIR].value;
+    destDir=options[DESTDIR].value;
 
     if(argc>=2) {
         suffix=argv[1];
@@ -136,11 +156,15 @@ main(int argc, char* argv[]) {
         suffix=NULL;
     }
 
-    if(options[6].doesOccur) {
-        setUnicodeVersion(options[6].value);
+    if(options[UNICODE_VERSION].doesOccur) {
+        setUnicodeVersion(options[UNICODE_VERSION].value);
     }
     /* else use the default dataVersion in store.c */
 
+    if (options[ICUDATADIR].doesOccur) {
+        u_setDataDirectory(options[ICUDATADIR].value);
+    }
+
     /* prepare the filename beginning with the source dir */
     uprv_strcpy(filename, srcDir);
     basename=filename+uprv_strlen(filename);
@@ -178,17 +202,18 @@ main(int argc, char* argv[]) {
         generateData(destDir);
     }
 
+    u_cleanup();
     return errorCode;
 }
 
 U_CFUNC void
 writeUCDFilename(char *basename, const char *filename, const char *suffix) {
-    int32_t length=uprv_strlen(filename);
+    int32_t length=(int32_t)uprv_strlen(filename);
     uprv_strcpy(basename, filename);
     if(suffix!=NULL) {
         basename[length++]='-';
         uprv_strcpy(basename+length, suffix);
-        length+=uprv_strlen(suffix);
+        length+=(int32_t)uprv_strlen(suffix);
     }
     uprv_strcpy(basename+length, ".txt");
 }
@@ -1031,3 +1056,4 @@ parseDB(const char *filename, UErrorCode *pErrorCode) {
  * End:
  *
  */
+