]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/tools/genbrk/genbrk.cpp
ICU-461.18.tar.gz
[apple/icu.git] / icuSources / tools / genbrk / genbrk.cpp
index 2ca7a4df49c4187bb6d1b216a93e13e0e785323c..72c6cffe7b5296de8678efae04b47597408f6a07 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-*   Copyright (C) 2002-2004, International Business Machines
+*   Copyright (C) 2002-2009, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
 *
 #include "uoptions.h"
 #include "unewdata.h"
 #include "ucmndata.h"
+#include "rbbidata.h"
+#include "cmemory.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
-#define DATA_TYPE "brk"
+U_NAMESPACE_USE
 
 static char *progName;
 static UOption options[]={
@@ -72,7 +74,7 @@ void usageAndDie(int retCode) {
 }
 
 
-#if UCONFIG_NO_BREAK_ITERATION
+#if UCONFIG_NO_BREAK_ITERATION || UCONFIG_NO_FILE_IO
 
 /* dummy UDataInfo cf. udata.h */
 static UDataInfo dummyDataInfo = {
@@ -108,8 +110,10 @@ DataHeader dh ={
         0,                          //     reserved
 
     { 0x42, 0x72, 0x6b, 0x20 },     //     dataFormat="Brk "
-    { 3, 0, 0, 0 },                 //     formatVersion
-        { 4, 0, 0, 0 }                //   dataVersion (Unicode version)
+    { 0xff, 0, 0, 0 },              //     formatVersion.  Filled in later with values
+                                    //      from the RBBI rule builder.  The  values declared
+                                    //      here should never appear in any real RBBI data.
+        { 4, 1, 0, 0 }              //   dataVersion (Unicode version)
     }};
 
 #endif
@@ -155,13 +159,6 @@ int  main(int argc, char **argv) {
         u_setDataDirectory(options[5].value);
     }
 
-    /* Initialize ICU */
-    u_init(&status);
-    if (U_FAILURE(status)) {
-        fprintf(stderr, "%s: can not initialize ICU.  status = %s\n",
-            argv[0], u_errorName(status));
-        exit(1);
-    }
     status = U_ZERO_ERROR;
 
     /* Combine the directory with the file name */
@@ -172,43 +169,30 @@ int  main(int argc, char **argv) {
         copyright = U_COPYRIGHT_STRING;
     }
 
-#if UCONFIG_NO_BREAK_ITERATION
+#if UCONFIG_NO_BREAK_ITERATION || UCONFIG_NO_FILE_IO
 
     UNewDataMemory *pData;
-    char msg[2048], folder[2048], name[32];
-    char *basename;
-    int length;
-
-    /* split the outFileName into folder + name + type */
-    strcpy(folder, outFileName);
-    basename = strrchr(folder, U_FILE_SEP_CHAR);
-    if(basename == NULL) {
-        basename = folder;
-    } else {
-        ++basename;
-    }
-
-    /* copy the data name and remove it from the folder */
-    strcpy(name, basename);
-    *basename = 0;
+    char msg[1024];
 
     /* write message with just the name */
-    sprintf(msg, "genbrk writes dummy %s because of UCONFIG_NO_BREAK_ITERATION, see uconfig.h", name);
+    sprintf(msg, "genbrk writes dummy %s because of UCONFIG_NO_BREAK_ITERATION and/or UCONFIG_NO_FILE_IO, see uconfig.h", outFileName);
     fprintf(stderr, "%s\n", msg);
 
-    /* remove the type suffix (hardcode to DATA_TYPE) */
-    length = strlen(name);
-    if(length > 4 && name[length - 4] == '.') {
-        name[length - 4] = 0;
-    }
-
     /* write the dummy data file */
-    pData = udata_create(folder, DATA_TYPE, name, &dummyDataInfo, NULL, &status);
+    pData = udata_create(outDir, NULL, outFileName, &dummyDataInfo, NULL, &status);
     udata_writeBlock(pData, msg, strlen(msg));
     udata_finish(pData, &status);
     return (int)status;
 
 #else
+    /* Initialize ICU */
+    u_init(&status);
+    if (U_FAILURE(status)) {
+        fprintf(stderr, "%s: can not initialize ICU.  status = %s\n",
+            argv[0], u_errorName(status));
+        exit(1);
+    }
+    status = U_ZERO_ERROR;
 
     //
     //  Read in the rule source file
@@ -318,6 +302,8 @@ int  main(int argc, char **argv) {
     const uint8_t  *outData;
     outData = bi->getBinaryRules(outDataSize);
 
+    // Copy the data format version numbers from the RBBI data header into the UDataMemory header.
+    uprv_memcpy(dh.info.formatVersion, ((RBBIDataHeader *)outData)->fFormatVersion, sizeof(dh.info.formatVersion));
 
     //
     //  Create the output file
@@ -330,6 +316,8 @@ int  main(int argc, char **argv) {
                          outFileName, u_errorName(status));
         exit(status);
     }
+
+
     //  Write the data itself.
     udata_writeBlock(pData, outData, outDataSize);
     // finish up