]> granicus.if.org Git - icu/commitdiff
ICU-8559 Removed requirement for flags being in a fixed order
authorMichael Ow <mow@svn.icu-project.org>
Mon, 27 Jun 2011 21:58:09 +0000 (21:58 +0000)
committerMichael Ow <mow@svn.icu-project.org>
Mon, 27 Jun 2011 21:58:09 +0000 (21:58 +0000)
X-SVN-Rev: 30243

icu4c/source/tools/pkgdata/pkgdata.cpp
icu4c/source/tools/toolutil/flagparser.c
icu4c/source/tools/toolutil/flagparser.h

index 54c8d06d7a9a4e5d1546403e51774154f5ac348a..9819dd93fe689916082867ea9f406a9c83421198 100644 (file)
@@ -99,6 +99,7 @@ U_CDECL_END
 
 #define LARGE_BUFFER_MAX_SIZE 2048
 #define SMALL_BUFFER_MAX_SIZE 512
+#define SMALL_BUFFER_FLAG_NAMES 32
 #define BUFFER_PADDING_SIZE 20
 
 static void loadLists(UPKGOptions *o, UErrorCode *status);
@@ -187,6 +188,7 @@ static UOption options[]={
     /*19*/    UOPTION_DEF( "quiet", 'q', UOPT_NO_ARG)
 };
 
+/* This enum and the following char array should be kept in sync. */
 enum {
     GENCCODE_ASSEMBLY_TYPE,
     SO_EXT,
@@ -207,6 +209,25 @@ enum {
     INSTALL_CMD,
     PKGDATA_FLAGS_SIZE
 };
+static const char* FLAG_NAMES[PKGDATA_FLAGS_SIZE] = {
+        "GENCCODE_ASSEMBLY_TYPE",
+        "SO",
+        "SOBJ",
+        "A",
+        "LIBPREFIX",
+        "LIB_EXT_ORDER",
+        "COMPILE",
+        "LIBFLAGS",
+        "GENLIB",
+        "LDICUDTFLAGS",
+        "LD_SONAME",
+        "RPATH_FLAGS",
+        "BIR_LDFLAGS",
+        "AR",
+        "ARFLAGS",
+        "RANLIB",
+        "INSTALL_CMD"
+};
 static char **pkgDataFlags = NULL;
 
 enum {
@@ -789,7 +810,7 @@ static int32_t initializePkgDataFlags(UPKGOptions *o) {
           fprintf(stdout, "# Reading options file %s\n", o->options);
         }
         status = U_ZERO_ERROR;
-        tmpResult = parseFlagsFile(o->options, pkgDataFlags, currentBufferSize, (int32_t)PKGDATA_FLAGS_SIZE, &status);
+        tmpResult = parseFlagsFile(o->options, pkgDataFlags, currentBufferSize, FLAG_NAMES, (int32_t)PKGDATA_FLAGS_SIZE, &status);
         if (status == U_BUFFER_OVERFLOW_ERROR) {
             for (int32_t i = 0; i < PKGDATA_FLAGS_SIZE; i++) {
                 uprv_free(pkgDataFlags[i]);
@@ -801,9 +822,9 @@ static int32_t initializePkgDataFlags(UPKGOptions *o) {
         }
 #endif
         if(o->verbose) {
-            fprintf(stdout, "# pkgDataFlags=");
-            for(int32_t i=0;i<PKGDATA_FLAGS_SIZE && pkgDataFlags[i][0];i++) {
-                fprintf(stdout, "%c \"%s\"", (i>0)?',':' ',pkgDataFlags[i]);
+            fprintf(stdout, "# pkgDataFlags=\n");
+            for(int32_t i=0;i<PKGDATA_FLAGS_SIZE;i++) {
+                fprintf(stdout, "  [%d] %s:  %s\n", i, FLAG_NAMES[i], pkgDataFlags[i]);
             }
             fprintf(stdout, "\n");
         }
index 41ec9c9ce6105638f16883bb8cefb79e1d896320..66bd95c7c11094363ed965a5e387efaf35cb616a 100644 (file)
@@ -1,5 +1,5 @@
 /******************************************************************************
- *   Copyright (C) 2009-2010, International Business Machines
+ *   Copyright (C) 2009-2011, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  *******************************************************************************
  */
 
 static int32_t currentBufferSize = DEFAULT_BUFFER_SIZE;
 
-static void extractFlag(char* buffer, int32_t bufferSize, char* flag, int32_t flagSize, UErrorCode *status);
+static int32_t extractFlag(char* buffer, int32_t bufferSize, char* flag, int32_t flagSize, const char ** flagNames, int32_t numOfFlags, UErrorCode *status);
 static int32_t getFlagOffset(const char *buffer, int32_t bufferSize);
 
 /*
  * Opens the given fileName and reads in the information storing the data in flagBuffer.
  */
 U_CAPI int32_t U_EXPORT2
-parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize, int32_t numOfFlags, UErrorCode *status) {
+parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize, const char ** flagNames, int32_t numOfFlags, UErrorCode *status) {
     char* buffer = uprv_malloc(sizeof(char) * currentBufferSize);
+    char* tmpFlagBuffer = uprv_malloc(sizeof(char) * flagBufferSize);
     UBool allocateMoreSpace = FALSE;
-    int32_t i;
+    int32_t index, i;
     int32_t result = 0;
 
     FileStream *f = T_FileStream_open(fileName, "r");
@@ -44,15 +45,19 @@ parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize,
             uprv_free(buffer);
             buffer = uprv_malloc(sizeof(char) * currentBufferSize);
             if (buffer == NULL) {
+                uprv_free(tmpFlagBuffer);
                 *status = U_MEMORY_ALLOCATION_ERROR;
                 return -1;
             }
         }
-        for (i = 0; i < numOfFlags; i++) {
+        for (i = 0; i < numOfFlags;) {
             if (T_FileStream_readLine(f, buffer, currentBufferSize) == NULL) {
-                *status = U_FILE_ACCESS_ERROR;
+                /* End of file reached. */
                 break;
             }
+            if (buffer[0] == '#') {
+                continue;
+            }
 
             if (uprv_strlen(buffer) == (currentBufferSize - 1) && buffer[currentBufferSize-2] != '\n') {
                 /* Allocate more space for buffer if it didnot read the entrire line */
@@ -60,7 +65,7 @@ parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize,
                 T_FileStream_rewind(f);
                 break;
             } else {
-                extractFlag(buffer, currentBufferSize, flagBuffer[i], flagBufferSize, status);
+                index = extractFlag(buffer, currentBufferSize, tmpFlagBuffer, flagBufferSize, flagNames, numOfFlags, status);
                 if (U_FAILURE(*status)) {
                     if (*status == U_BUFFER_OVERFLOW_ERROR) {
                         result = currentBufferSize;
@@ -68,11 +73,23 @@ parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize,
                         result = -1;
                     }
                     break;
+                } else {
+                    if (flagNames != NULL) {
+                        if (index >= 0) {
+                            uprv_strcpy(flagBuffer[index], tmpFlagBuffer);
+                        } else {
+                            /* No match found.  Skip it. */
+                            continue;
+                        }
+                    } else {
+                        uprv_strcpy(flagBuffer[i++], tmpFlagBuffer);
+                    }
                 }
             }
         }
     } while (allocateMoreSpace && U_SUCCESS(*status));
 
+    uprv_free(tmpFlagBuffer);
     uprv_free(buffer);
 
     T_FileStream_close(f);
@@ -88,8 +105,8 @@ parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize,
 /*
  * Extract the setting after the '=' and store it in flag excluding the newline character.
  */
-static void extractFlag(char* buffer, int32_t bufferSize, char* flag, int32_t flagSize, UErrorCode *status) {
-    int32_t i;
+static int32_t extractFlag(char* buffer, int32_t bufferSize, char* flag, int32_t flagSize, const char **flagNames, int32_t numOfFlags, UErrorCode *status) {
+    int32_t i, index = -1;
     char *pBuffer;
     int32_t offset;
     UBool bufferWritten = FALSE;
@@ -101,7 +118,7 @@ static void extractFlag(char* buffer, int32_t bufferSize, char* flag, int32_t fl
         for(i = 0;;i++) {
             if (i >= flagSize) {
                 *status = U_BUFFER_OVERFLOW_ERROR;
-                return;
+                return -1;
             }
             if (pBuffer[i+1] == 0) {
                 /* Indicates a new line character. End here. */
@@ -119,6 +136,18 @@ static void extractFlag(char* buffer, int32_t bufferSize, char* flag, int32_t fl
     if (!bufferWritten) {
         flag[0] = 0;
     }
+
+    if (flagNames != NULL) {
+        offset--;  /* Move offset back 1 because of '='*/
+        for (i = 0; i < numOfFlags; i++) {
+            if (uprv_strncmp(buffer, flagNames[i], offset) == 0) {
+                index = i;
+                break;
+            }
+        }
+    }
+
+    return index;
 }
 
 /*
index 64056ed7a7997853440a67588b77f04757af1e84..32a51e3d2acbd82c0c41c8638195ab0964fd868e 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
 *
-*   Copyright (C) 2009-2010, International Business Machines
+*   Copyright (C) 2009-2011, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
@@ -25,6 +25,6 @@
 #include "unicode/utypes.h"
 
 U_CAPI int32_t U_EXPORT2
-parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize, int32_t numOfFlags, UErrorCode *status);
+parseFlagsFile(const char *fileName, char **flagBuffer, int32_t flagBufferSize, const char ** flagNames, int32_t numOfFlags, UErrorCode *status);
 
 #endif