OSDN Git Service

Frameworks/base: Fix AAPT warnings
authorAndreas Gampe <agampe@google.com>
Wed, 1 Oct 2014 03:55:57 +0000 (20:55 -0700)
committerAndreas Gampe <agampe@google.com>
Wed, 1 Oct 2014 23:18:06 +0000 (16:18 -0700)
Turn on -Wall -Werror. Fix warnings.

Change-Id: I287fb3c1e851c654479bcf9ea8c73bd354a6b2a1

14 files changed:
tools/aapt/AaptAssets.cpp
tools/aapt/Android.mk
tools/aapt/CacheUpdater.h
tools/aapt/CrunchCache.cpp
tools/aapt/Images.cpp
tools/aapt/Package.cpp
tools/aapt/Resource.cpp
tools/aapt/ResourceIdCache.cpp
tools/aapt/ResourceTable.cpp
tools/aapt/StringPool.cpp
tools/aapt/XMLNode.cpp
tools/aapt/ZipEntry.cpp
tools/aapt/ZipEntry.h
tools/aapt/ZipFile.cpp

index 19532e8..d8e2de6 100644 (file)
@@ -13,7 +13,6 @@
 #include <dirent.h>
 #include <errno.h>
 
-static const char* kDefaultLocale = "default";
 static const char* kWildcardName = "any";
 static const char* kAssetDir = "assets";
 static const char* kResourceDir = "res";
@@ -679,7 +678,6 @@ AaptGroupEntry::initFromDirName(const char* dir, String8* resType)
     String8 uiModeType, uiModeNight, smallestwidthdp, widthdp, heightdp;
 
     AaptLocaleValue locale;
-    int numLocaleComponents = 0;
 
     const int N = parts.size();
     int index = 0;
@@ -2538,7 +2536,7 @@ bail:
 }
 
 ssize_t
-AaptAssets::slurpResourceZip(Bundle* bundle, const char* filename)
+AaptAssets::slurpResourceZip(Bundle* /* bundle */, const char* filename)
 {
     int count = 0;
     SortedVector<AaptGroupEntry> entries;
index f43060d..ede6d9d 100644 (file)
@@ -40,6 +40,7 @@ LOCAL_CFLAGS += -D_DARWIN_UNLIMITED_STREAMS
 endif
 
 LOCAL_CFLAGS += -DSTATIC_ANDROIDFW_FOR_TOOLS
+LOCAL_CFLAGS += -Wall -Werror
 
 LOCAL_C_INCLUDES += external/libpng
 LOCAL_C_INCLUDES += external/zlib
@@ -83,6 +84,7 @@ LOCAL_C_INCLUDES += external/libpng
 LOCAL_C_INCLUDES += external/zlib
 
 LOCAL_CFLAGS += -Wno-non-virtual-dtor
+LOCAL_CFLAGS += -Wall -Werror
 
 LOCAL_SHARED_LIBRARIES := \
         libandroidfw \
index 0e65589..0af5872 100644 (file)
@@ -35,6 +35,8 @@ public:
 
     // Process an image from source out to dest
     virtual void processImage(String8 source, String8 dest) = 0;
+
+    virtual ~CacheUpdater() {}
 private:
 };
 
@@ -104,4 +106,4 @@ private:
     Bundle* bundle;
 };
 
-#endif // CACHE_UPDATER_H
\ No newline at end of file
+#endif // CACHE_UPDATER_H
index c4cf6bc..6c39d1d 100644 (file)
@@ -101,4 +101,4 @@ bool CrunchCache::needsUpdating(String8 relativePath) const
     time_t sourceDate = mSourceFiles.valueFor(mSourcePath.appendPathCopy(relativePath));
     time_t destDate = mDestFiles.valueFor(mDestPath.appendPathCopy(relativePath));
     return sourceDate > destDate;
-}
\ No newline at end of file
+}
index db74831..5368418 100644 (file)
@@ -14,7 +14,8 @@
 #include <png.h>
 #include <zlib.h>
 
-#define NOISY(x) //x
+// Change this to true for noisy debug output.
+static const bool kIsDebug = false;
 
 static void
 png_write_aapt_file(png_structp png_ptr, png_bytep data, png_size_t length)
@@ -28,7 +29,7 @@ png_write_aapt_file(png_structp png_ptr, png_bytep data, png_size_t length)
 
 
 static void
-png_flush_aapt_file(png_structp png_ptr)
+png_flush_aapt_file(png_structp /* png_ptr */)
 {
 }
 
@@ -138,11 +139,13 @@ static void read_png(const char* imageName,
 
     png_read_end(read_ptr, read_info);
 
-    NOISY(printf("Image %s: w=%d, h=%d, d=%d, colors=%d, inter=%d, comp=%d\n",
-                 imageName,
-                 (int)outImageInfo->width, (int)outImageInfo->height,
-                 bit_depth, color_type,
-                 interlace_type, compression_type));
+    if (kIsDebug) {
+        printf("Image %s: w=%d, h=%d, d=%d, colors=%d, inter=%d, comp=%d\n",
+                imageName,
+                (int)outImageInfo->width, (int)outImageInfo->height,
+                bit_depth, color_type,
+                interlace_type, compression_type);
+    }
 
     png_get_IHDR(read_ptr, read_info, &outImageInfo->width,
        &outImageInfo->height, &bit_depth, &color_type,
@@ -312,7 +315,7 @@ static status_t get_vertical_ticks(
 }
 
 static status_t get_horizontal_layout_bounds_ticks(
-        png_bytep row, int width, bool transparent, bool required,
+        png_bytep row, int width, bool transparent, bool /* required */,
         int32_t* outLeft, int32_t* outRight, const char** outError)
 {
     int i;
@@ -350,7 +353,7 @@ static status_t get_horizontal_layout_bounds_ticks(
 }
 
 static status_t get_vertical_layout_bounds_ticks(
-        png_bytepp rows, int offset, int height, bool transparent, bool required,
+        png_bytepp rows, int offset, int height, bool transparent, bool /* required */,
         int32_t* outTop, int32_t* outBottom, const char** outError)
 {
     int i;
@@ -418,41 +421,6 @@ static uint32_t get_color(
     return (color[3]<<24) | (color[0]<<16) | (color[1]<<8) | color[2];
 }
 
-static void select_patch(
-    int which, int front, int back, int size, int* start, int* end)
-{
-    switch (which) {
-    case 0:
-        *start = 0;
-        *end = front-1;
-        break;
-    case 1:
-        *start = front;
-        *end = back-1;
-        break;
-    case 2:
-        *start = back;
-        *end = size-1;
-        break;
-    }
-}
-
-static uint32_t get_color(image_info* image, int hpatch, int vpatch)
-{
-    int left, right, top, bottom;
-    select_patch(
-        hpatch, image->xDivs[0], image->xDivs[1],
-        image->width, &left, &right);
-    select_patch(
-        vpatch, image->yDivs[0], image->yDivs[1],
-        image->height, &top, &bottom);
-    //printf("Selecting h=%d v=%d: (%d,%d)-(%d,%d)\n",
-    //       hpatch, vpatch, left, top, right, bottom);
-    const uint32_t c = get_color(image->rows, left, top, right, bottom);
-    NOISY(printf("Color in (%d,%d)-(%d,%d): #%08x\n", left, top, right, bottom, c));
-    return c;
-}
-
 static status_t do_9patch(const char* imageName, image_info* image)
 {
     image->is9Patch = true;
@@ -557,8 +525,10 @@ static status_t do_9patch(const char* imageName, image_info* image)
                                || image->layoutBoundsBottom != 0;
 
     if (image->haveLayoutBounds) {
-        NOISY(printf("layoutBounds=%d %d %d %d\n", image->layoutBoundsLeft, image->layoutBoundsTop,
-                image->layoutBoundsRight, image->layoutBoundsBottom));
+        if (kIsDebug) {
+            printf("layoutBounds=%d %d %d %d\n", image->layoutBoundsLeft, image->layoutBoundsTop,
+                    image->layoutBoundsRight, image->layoutBoundsBottom);
+        }
     }
 
     // If padding is not yet specified, take values from size.
@@ -577,12 +547,14 @@ static status_t do_9patch(const char* imageName, image_info* image)
         image->info9Patch.paddingBottom = H - 2 - image->info9Patch.paddingBottom;
     }
 
-    NOISY(printf("Size ticks for %s: x0=%d, x1=%d, y0=%d, y1=%d\n", imageName,
-                 image->info9Patch.xDivs[0], image->info9Patch.xDivs[1],
-                 image->info9Patch.yDivs[0], image->info9Patch.yDivs[1]));
-    NOISY(printf("padding ticks for %s: l=%d, r=%d, t=%d, b=%d\n", imageName,
-                 image->info9Patch.paddingLeft, image->info9Patch.paddingRight,
-                 image->info9Patch.paddingTop, image->info9Patch.paddingBottom));
+    if (kIsDebug) {
+        printf("Size ticks for %s: x0=%d, x1=%d, y0=%d, y1=%d\n", imageName,
+                image->info9Patch.getXDivs()[0], image->info9Patch.getXDivs()[1],
+                image->info9Patch.getYDivs()[0], image->info9Patch.getYDivs()[1]);
+        printf("padding ticks for %s: l=%d, r=%d, t=%d, b=%d\n", imageName,
+                image->info9Patch.paddingLeft, image->info9Patch.paddingRight,
+                image->info9Patch.paddingTop, image->info9Patch.paddingBottom);
+    }
 
     // Remove frame from image.
     image->rows = (png_bytepp)malloc((H-2) * sizeof(png_bytep));
@@ -664,7 +636,10 @@ static status_t do_9patch(const char* imageName, image_info* image)
             }
             c = get_color(image->rows, left, top, right - 1, bottom - 1);
             image->colors[colorIndex++] = c;
-            NOISY(if (c != Res_png_9patch::NO_COLOR) hasColor = true);
+            if (kIsDebug) {
+                if (c != Res_png_9patch::NO_COLOR)
+                    hasColor = true;
+            }
             left = right;
         }
         top = bottom;
@@ -767,7 +742,7 @@ static void dump_image(int w, int h, png_bytepp rows, int color_type)
                 break;
             }
             if (i == (w - 1)) {
-                NOISY(printf("\n"));
+                printf("\n");
             }
         }
     }
@@ -797,8 +772,10 @@ static void analyze_image(const char *imageName, image_info &imageInfo, int gray
     // 2. Every pixel has A == 255 (opaque)
     // 3. There are no more than 256 distinct RGBA colors
 
-    // NOISY(printf("Initial image data:\n"));
-    // dump_image(w, h, imageInfo.rows, PNG_COLOR_TYPE_RGB_ALPHA);
+    if (kIsDebug) {
+        printf("Initial image data:\n");
+        dump_image(w, h, imageInfo.rows, PNG_COLOR_TYPE_RGB_ALPHA);
+    }
 
     for (j = 0; j < h; j++) {
         png_bytep row = imageInfo.rows[j];
@@ -814,15 +791,19 @@ static void analyze_image(const char *imageName, image_info &imageInfo, int gray
             maxGrayDeviation = MAX(ABS(gg - bb), maxGrayDeviation);
             maxGrayDeviation = MAX(ABS(bb - rr), maxGrayDeviation);
             if (maxGrayDeviation > odev) {
-                NOISY(printf("New max dev. = %d at pixel (%d, %d) = (%d %d %d %d)\n",
-                             maxGrayDeviation, i, j, rr, gg, bb, aa));
+                if (kIsDebug) {
+                    printf("New max dev. = %d at pixel (%d, %d) = (%d %d %d %d)\n",
+                            maxGrayDeviation, i, j, rr, gg, bb, aa);
+                }
             }
 
             // Check if image is really grayscale
             if (isGrayscale) {
                 if (rr != gg || rr != bb) {
-                     NOISY(printf("Found a non-gray pixel at %d, %d = (%d %d %d %d)\n",
-                                  i, j, rr, gg, bb, aa));
+                    if (kIsDebug) {
+                        printf("Found a non-gray pixel at %d, %d = (%d %d %d %d)\n",
+                                i, j, rr, gg, bb, aa);
+                    }
                     isGrayscale = false;
                 }
             }
@@ -830,8 +811,10 @@ static void analyze_image(const char *imageName, image_info &imageInfo, int gray
             // Check if image is really opaque
             if (isOpaque) {
                 if (aa != 0xff) {
-                    NOISY(printf("Found a non-opaque pixel at %d, %d = (%d %d %d %d)\n",
-                                 i, j, rr, gg, bb, aa));
+                    if (kIsDebug) {
+                        printf("Found a non-opaque pixel at %d, %d = (%d %d %d %d)\n",
+                                i, j, rr, gg, bb, aa);
+                    }
                     isOpaque = false;
                 }
             }
@@ -853,7 +836,9 @@ static void analyze_image(const char *imageName, image_info &imageInfo, int gray
                 *out++ = idx;
                 if (!match) {
                     if (num_colors == 256) {
-                        NOISY(printf("Found 257th color at %d, %d\n", i, j));
+                        if (kIsDebug) {
+                            printf("Found 257th color at %d, %d\n", i, j);
+                        }
                         isPalette = false;
                     } else {
                         colors[num_colors++] = col;
@@ -868,12 +853,14 @@ static void analyze_image(const char *imageName, image_info &imageInfo, int gray
     int bpp = isOpaque ? 3 : 4;
     int paletteSize = w * h + bpp * num_colors;
 
-    NOISY(printf("isGrayscale = %s\n", isGrayscale ? "true" : "false"));
-    NOISY(printf("isOpaque = %s\n", isOpaque ? "true" : "false"));
-    NOISY(printf("isPalette = %s\n", isPalette ? "true" : "false"));
-    NOISY(printf("Size w/ palette = %d, gray+alpha = %d, rgb(a) = %d\n",
-                 paletteSize, 2 * w * h, bpp * w * h));
-    NOISY(printf("Max gray deviation = %d, tolerance = %d\n", maxGrayDeviation, grayscaleTolerance));
+    if (kIsDebug) {
+        printf("isGrayscale = %s\n", isGrayscale ? "true" : "false");
+        printf("isOpaque = %s\n", isOpaque ? "true" : "false");
+        printf("isPalette = %s\n", isPalette ? "true" : "false");
+        printf("Size w/ palette = %d, gray+alpha = %d, rgb(a) = %d\n",
+                paletteSize, 2 * w * h, bpp * w * h);
+        printf("Max gray deviation = %d, tolerance = %d\n", maxGrayDeviation, grayscaleTolerance);
+    }
 
     // Choose the best color type for the image.
     // 1. Opaque gray - use COLOR_TYPE_GRAY at 1 byte/pixel
@@ -950,7 +937,6 @@ static void write_png(const char* imageName,
                       png_structp write_ptr, png_infop write_info,
                       image_info& imageInfo, int grayscaleTolerance)
 {
-    bool optimize = true;
     png_uint_32 width, height;
     int color_type;
     int bit_depth, interlace_type, compression_type;
@@ -975,8 +961,10 @@ static void write_png(const char* imageName,
 
     png_set_compression_level(write_ptr, Z_BEST_COMPRESSION);
 
-    NOISY(printf("Writing image %s: w = %d, h = %d\n", imageName,
-          (int) imageInfo.width, (int) imageInfo.height));
+    if (kIsDebug) {
+        printf("Writing image %s: w = %d, h = %d\n", imageName,
+                (int) imageInfo.width, (int) imageInfo.height);
+    }
 
     png_color rgbPalette[256];
     png_byte alphaPalette[256];
@@ -993,24 +981,26 @@ static void write_png(const char* imageName,
         color_type = PNG_COLOR_TYPE_RGB_ALPHA;
     }
 
-    switch (color_type) {
-    case PNG_COLOR_TYPE_PALETTE:
-        NOISY(printf("Image %s has %d colors%s, using PNG_COLOR_TYPE_PALETTE\n",
-                     imageName, paletteEntries,
-                     hasTransparency ? " (with alpha)" : ""));
-        break;
-    case PNG_COLOR_TYPE_GRAY:
-        NOISY(printf("Image %s is opaque gray, using PNG_COLOR_TYPE_GRAY\n", imageName));
-        break;
-    case PNG_COLOR_TYPE_GRAY_ALPHA:
-        NOISY(printf("Image %s is gray + alpha, using PNG_COLOR_TYPE_GRAY_ALPHA\n", imageName));
-        break;
-    case PNG_COLOR_TYPE_RGB:
-        NOISY(printf("Image %s is opaque RGB, using PNG_COLOR_TYPE_RGB\n", imageName));
-        break;
-    case PNG_COLOR_TYPE_RGB_ALPHA:
-        NOISY(printf("Image %s is RGB + alpha, using PNG_COLOR_TYPE_RGB_ALPHA\n", imageName));
-        break;
+    if (kIsDebug) {
+        switch (color_type) {
+        case PNG_COLOR_TYPE_PALETTE:
+            printf("Image %s has %d colors%s, using PNG_COLOR_TYPE_PALETTE\n",
+                    imageName, paletteEntries,
+                    hasTransparency ? " (with alpha)" : "");
+            break;
+        case PNG_COLOR_TYPE_GRAY:
+            printf("Image %s is opaque gray, using PNG_COLOR_TYPE_GRAY\n", imageName);
+            break;
+        case PNG_COLOR_TYPE_GRAY_ALPHA:
+            printf("Image %s is gray + alpha, using PNG_COLOR_TYPE_GRAY_ALPHA\n", imageName);
+            break;
+        case PNG_COLOR_TYPE_RGB:
+            printf("Image %s is opaque RGB, using PNG_COLOR_TYPE_RGB\n", imageName);
+            break;
+        case PNG_COLOR_TYPE_RGB_ALPHA:
+            printf("Image %s is RGB + alpha, using PNG_COLOR_TYPE_RGB_ALPHA\n", imageName);
+            break;
+        }
     }
 
     png_set_IHDR(write_ptr, write_info, imageInfo.width, imageInfo.height,
@@ -1034,7 +1024,9 @@ static void write_png(const char* imageName,
         png_byte *chunk_names = imageInfo.haveLayoutBounds
                 ? (png_byte*)"npLb\0npTc\0"
                 : (png_byte*)"npTc";
-        NOISY(printf("Adding 9-patch info...\n"));
+        if (kIsDebug) {
+            printf("Adding 9-patch info...\n");
+        }
         strcpy((char*)unknowns[p_index].name, "npTc");
         unknowns[p_index].data = (png_byte*)imageInfo.serialize9patch();
         unknowns[p_index].size = imageInfo.info9Patch.serializedSize();
@@ -1078,8 +1070,10 @@ static void write_png(const char* imageName,
     }
     png_write_image(write_ptr, rows);
 
-//     NOISY(printf("Final image data:\n"));
-//     dump_image(imageInfo.width, imageInfo.height, rows, color_type);
+    if (kIsDebug) {
+        printf("Final image data:\n");
+        dump_image(imageInfo.width, imageInfo.height, rows, color_type);
+    }
 
     png_write_end(write_ptr, write_info);
 
@@ -1094,13 +1088,15 @@ static void write_png(const char* imageName,
        &bit_depth, &color_type, &interlace_type,
        &compression_type, NULL);
 
-    NOISY(printf("Image written: w=%d, h=%d, d=%d, colors=%d, inter=%d, comp=%d\n",
-                 (int)width, (int)height, bit_depth, color_type, interlace_type,
-                 compression_type));
+    if (kIsDebug) {
+        printf("Image written: w=%d, h=%d, d=%d, colors=%d, inter=%d, comp=%d\n",
+                (int)width, (int)height, bit_depth, color_type, interlace_type,
+                compression_type);
+    }
 }
 
-status_t preProcessImage(const Bundle* bundle, const sp<AaptAssets>& assets,
-                         const sp<AaptFile>& file, String8* outNewLeafName)
+status_t preProcessImage(const Bundle* bundle, const sp<AaptAssets>& /* assets */,
+                         const sp<AaptFile>& file, String8* /* outNewLeafName */)
 {
     String8 ext(file->getPath().getPathExtension());
 
index 872d95c..26cc3c1 100644 (file)
@@ -455,7 +455,6 @@ bool endsWith(const char* haystack, const char* needle)
 
 ssize_t processJarFile(ZipFile* jar, ZipFile* out)
 {
-    status_t err;
     size_t N = jar->getNumEntries();
     size_t count = 0;
     for (size_t i=0; i<N; i++) {
index f842bee..6ebf41f 100644 (file)
 
 #include "WorkQueue.h"
 
+// STATUST: mingw does seem to redefine UNKNOWN_ERROR from our enum value, so a cast is necessary.
 #if HAVE_PRINTF_ZD
 #  define ZD "%zd"
 #  define ZD_TYPE ssize_t
+#  define STATUST(x) x
 #else
 #  define ZD "%ld"
 #  define ZD_TYPE long
+#  define STATUST(x) (status_t)x
 #endif
 
-#define NOISY(x) // x
+// Set to true for noisy debug output.
+static const bool kIsDebug = false;
 
 // Number of threads to use for preprocessing images.
 static const size_t MAX_THREADS = 4;
@@ -125,15 +129,17 @@ public:
             String8 leaf(group->getLeaf());
             mLeafName = String8(leaf);
             mParams = file->getGroupEntry().toParams();
-            NOISY(printf("Dir %s: mcc=%d mnc=%d lang=%c%c cnt=%c%c orient=%d ui=%d density=%d touch=%d key=%d inp=%d nav=%d\n",
-                   group->getPath().string(), mParams.mcc, mParams.mnc,
-                   mParams.language[0] ? mParams.language[0] : '-',
-                   mParams.language[1] ? mParams.language[1] : '-',
-                   mParams.country[0] ? mParams.country[0] : '-',
-                   mParams.country[1] ? mParams.country[1] : '-',
-                   mParams.orientation, mParams.uiMode,
-                   mParams.density, mParams.touchscreen, mParams.keyboard,
-                   mParams.inputFlags, mParams.navigation));
+            if (kIsDebug) {
+                printf("Dir %s: mcc=%d mnc=%d lang=%c%c cnt=%c%c orient=%d ui=%d density=%d touch=%d key=%d inp=%d nav=%d\n",
+                        group->getPath().string(), mParams.mcc, mParams.mnc,
+                        mParams.language[0] ? mParams.language[0] : '-',
+                        mParams.language[1] ? mParams.language[1] : '-',
+                        mParams.country[0] ? mParams.country[0] : '-',
+                        mParams.country[1] ? mParams.country[1] : '-',
+                        mParams.orientation, mParams.uiMode,
+                        mParams.density, mParams.touchscreen, mParams.keyboard,
+                        mParams.inputFlags, mParams.navigation);
+            }
             mPath = "res";
             mPath.appendPath(file->getGroupEntry().toDirName(mResType));
             mPath.appendPath(leaf);
@@ -144,7 +150,9 @@ public:
                 return UNKNOWN_ERROR;
             }
 
-            NOISY(printf("file name=%s\n", mBaseName.string()));
+            if (kIsDebug) {
+                printf("file name=%s\n", mBaseName.string());
+            }
 
             return NO_ERROR;
         }
@@ -306,7 +314,7 @@ static status_t makeFileResources(Bundle* bundle, const sp<AaptAssets>& assets,
         assets->addResource(it.getLeafName(), resPath, it.getFile(), type8);
     }
 
-    return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
+    return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
 }
 
 class PreProcessImageWorkUnit : public WorkQueue::WorkUnit {
@@ -356,7 +364,7 @@ static status_t preProcessImages(const Bundle* bundle, const sp<AaptAssets>& ass
             hasErrors = true;
         }
     }
-    return (hasErrors || (res < NO_ERROR)) ? UNKNOWN_ERROR : NO_ERROR;
+    return (hasErrors || (res < NO_ERROR)) ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
 }
 
 status_t postProcessImages(const sp<AaptAssets>& assets,
@@ -373,7 +381,7 @@ status_t postProcessImages(const sp<AaptAssets>& assets,
         }
     }
 
-    return (hasErrors || (res < NO_ERROR)) ? UNKNOWN_ERROR : NO_ERROR;
+    return (hasErrors || (res < NO_ERROR)) ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
 }
 
 static void collect_files(const sp<AaptDir>& dir,
@@ -398,27 +406,35 @@ static void collect_files(const sp<AaptDir>& dir,
 
         if (index < 0) {
             sp<ResourceTypeSet> set = new ResourceTypeSet();
-            NOISY(printf("Creating new resource type set for leaf %s with group %s (%p)\n",
-                    leafName.string(), group->getPath().string(), group.get()));
+            if (kIsDebug) {
+                printf("Creating new resource type set for leaf %s with group %s (%p)\n",
+                        leafName.string(), group->getPath().string(), group.get());
+            }
             set->add(leafName, group);
             resources->add(resType, set);
         } else {
             sp<ResourceTypeSet> set = resources->valueAt(index);
             index = set->indexOfKey(leafName);
             if (index < 0) {
-                NOISY(printf("Adding to resource type set for leaf %s group %s (%p)\n",
-                        leafName.string(), group->getPath().string(), group.get()));
+                if (kIsDebug) {
+                    printf("Adding to resource type set for leaf %s group %s (%p)\n",
+                            leafName.string(), group->getPath().string(), group.get());
+                }
                 set->add(leafName, group);
             } else {
                 sp<AaptGroup> existingGroup = set->valueAt(index);
-                NOISY(printf("Extending to resource type set for leaf %s group %s (%p)\n",
-                        leafName.string(), group->getPath().string(), group.get()));
+                if (kIsDebug) {
+                    printf("Extending to resource type set for leaf %s group %s (%p)\n",
+                            leafName.string(), group->getPath().string(), group.get());
+                }
                 for (size_t j=0; j<files.size(); j++) {
-                    NOISY(printf("Adding file %s in group %s resType %s\n",
-                        files.valueAt(j)->getSourceFile().string(),
-                        files.keyAt(j).toDirName(String8()).string(),
-                        resType.string()));
-                    status_t err = existingGroup->addFile(files.valueAt(j));
+                    if (kIsDebug) {
+                        printf("Adding file %s in group %s resType %s\n",
+                                files.valueAt(j)->getSourceFile().string(),
+                                files.keyAt(j).toDirName(String8()).string(),
+                                resType.string());
+                    }
+                    existingGroup->addFile(files.valueAt(j));
                 }
             }
         }
@@ -433,12 +449,16 @@ static void collect_files(const sp<AaptAssets>& ass,
 
     for (int i=0; i<N; i++) {
         sp<AaptDir> d = dirs.itemAt(i);
-        NOISY(printf("Collecting dir #%d %p: %s, leaf %s\n", i, d.get(), d->getPath().string(),
-                d->getLeaf().string()));
+        if (kIsDebug) {
+            printf("Collecting dir #%d %p: %s, leaf %s\n", i, d.get(), d->getPath().string(),
+                    d->getLeaf().string());
+        }
         collect_files(d, resources);
 
         // don't try to include the res dir
-        NOISY(printf("Removing dir leaf %s\n", d->getLeaf().string()));
+        if (kIsDebug) {
+            printf("Removing dir leaf %s\n", d->getLeaf().string());
+        }
         ass->removeDir(d->getLeaf());
     }
 }
@@ -595,11 +615,11 @@ static bool applyFileOverlay(Bundle *bundle,
                 if (bundle->getVerbose()) {
                     printf("trying overlaySet Key=%s\n",overlaySet->keyAt(overlayIndex).string());
                 }
-                size_t baseIndex = UNKNOWN_ERROR;
+                ssize_t baseIndex = UNKNOWN_ERROR;
                 if (baseSet->get() != NULL) {
                     baseIndex = (*baseSet)->indexOfKey(overlaySet->keyAt(overlayIndex));
                 }
-                if (baseIndex < UNKNOWN_ERROR) {
+                if (baseIndex >= 0) {
                     // look for same flavor.  For a given file (strings.xml, for example)
                     // there may be a locale specific or other flavors - we want to match
                     // the same flavor.
@@ -625,10 +645,10 @@ static bool applyFileOverlay(Bundle *bundle,
                     for (size_t overlayGroupIndex = 0;
                             overlayGroupIndex<overlayGroupSize;
                             overlayGroupIndex++) {
-                        size_t baseFileIndex =
+                        ssize_t baseFileIndex =
                                 baseGroup->getFiles().indexOfKey(overlayFiles.
                                 keyAt(overlayGroupIndex));
-                        if (baseFileIndex < UNKNOWN_ERROR) {
+                        if (baseFileIndex >= 0) {
                             if (bundle->getVerbose()) {
                                 printf("found a match (" ZD ") for overlay file %s, for flavor %s\n",
                                         (ZD_TYPE) baseFileIndex,
@@ -734,7 +754,9 @@ static void fullyQualifyClassName(const String8& package, sp<XMLNode> node,
         } else {
             className += name;
         }
-        NOISY(printf("Qualifying class '%s' to '%s'", name.string(), className.string()));
+        if (kIsDebug) {
+            printf("Qualifying class '%s' to '%s'", name.string(), className.string());
+        }
         attr->string.setTo(String16(className));
     }
 }
@@ -802,7 +824,10 @@ status_t massageManifest(Bundle* bundle, sp<XMLNode> root)
         }
         String8 origPackage(attr->string);
         attr->string.setTo(String16(manifestPackageNameOverride));
-        NOISY(printf("Overriding package '%s' to be '%s'\n", origPackage.string(), manifestPackageNameOverride));
+        if (kIsDebug) {
+            printf("Overriding package '%s' to be '%s'\n", origPackage.string(),
+                    manifestPackageNameOverride);
+        }
 
         // Make class names fully qualified
         sp<XMLNode> application = root->getChildElement(String16(), String16("application"));
@@ -898,8 +923,9 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets)
         return err;
     }
 
-    NOISY(printf("Creating resources for package %s\n",
-                 assets->getPackage().string()));
+    if (kIsDebug) {
+        printf("Creating resources for package %s\n", assets->getPackage().string());
+    }
 
     ResourceTable table(bundle, String16(assets->getPackage()));
     err = table.addIncludedResources(bundle, assets);
@@ -907,7 +933,9 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets)
         return err;
     }
 
-    NOISY(printf("Found %d included resource packages\n", (int)table.size()));
+    if (kIsDebug) {
+        printf("Found %d included resource packages\n", (int)table.size());
+    }
 
     // Standard flags for compiled XML and optional UTF-8 encoding
     int xmlFlags = XML_COMPILE_STANDARD_RESOURCE;
@@ -1322,12 +1350,6 @@ status_t buildResources(Bundle* bundle, const sp<AaptAssets>& assets)
 
         // Read resources back in,
         finalResTable.add(resFile->getData(), resFile->getSize());
-#if 0
-        NOISY(
-              printf("Generated resources:\n");
-              finalResTable.print();
-        )
-#endif
     }
 
     // Perform a basic validation of the manifest file.  This time we
@@ -1889,7 +1911,7 @@ static status_t writeLayoutClasses(
 
     indent--;
     fprintf(fp, "%s};\n", getIndentSpace(indent));
-    return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
+    return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
 }
 
 static status_t writeTextLayoutClasses(
@@ -1975,7 +1997,7 @@ static status_t writeTextLayoutClasses(
                     package16.string(), package16.size(), &typeSpecFlags);
                 //printf("%s:%s/%s: 0x%08x\n", String8(package16).string(),
                 //    String8(attr16).string(), String8(name16).string(), typeSpecFlags);
-                const bool pub = (typeSpecFlags&ResTable_typeSpec::SPEC_PUBLIC) != 0;
+                //const bool pub = (typeSpecFlags&ResTable_typeSpec::SPEC_PUBLIC) != 0;
 
                 fprintf(fp,
                         "int styleable %s_%s %d\n",
@@ -1985,7 +2007,7 @@ static status_t writeTextLayoutClasses(
         }
     }
 
-    return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
+    return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
 }
 
 static status_t writeSymbolClass(
@@ -2318,7 +2340,7 @@ addProguardKeepRule(ProguardKeepSet* keep, const String8& inClassName,
 
 void
 addProguardKeepMethodRule(ProguardKeepSet* keep, const String8& memberName,
-        const char* pkg, const String8& srcName, int line)
+        const char* /* pkg */, const String8& srcName, int line)
 {
     String8 rule("-keepclassmembers class * { *** ");
     rule += memberName;
@@ -2640,7 +2662,7 @@ status_t writePathsToFile(const sp<FilePathStore>& files, FILE* fp)
 }
 
 status_t
-writeDependencyPreReqs(Bundle* bundle, const sp<AaptAssets>& assets, FILE* fp, bool includeRaw)
+writeDependencyPreReqs(Bundle* /* bundle */, const sp<AaptAssets>& assets, FILE* fp, bool includeRaw)
 {
     status_t deps = -1;
     deps += writePathsToFile(assets->getFullResPaths(), fp);
index 359443d..6e30938 100644 (file)
@@ -97,10 +97,10 @@ uint32_t ResourceIdCache::store(const android::String16& package,
 
 void ResourceIdCache::dump() {
     printf("ResourceIdCache dump:\n");
-    printf("Size: %ld\n", mIdMap.size());
-    printf("Hits:   %ld\n", mHits);
-    printf("Misses: %ld\n", mMisses);
-    printf("(Collisions: %ld)\n", mCollisions);
+    printf("Size: %zu\n", mIdMap.size());
+    printf("Hits:   %zu\n", mHits);
+    printf("Misses: %zu\n", mMisses);
+    printf("(Collisions: %zu)\n", mCollisions);
 }
 
 }
index 6632809..6e7f3fb 100644 (file)
 #include <utils/ByteOrder.h>
 #include <stdarg.h>
 
-#define NOISY(x) //x
+// SSIZE: mingw does not have signed size_t == ssize_t.
+// STATUST: mingw does seem to redefine UNKNOWN_ERROR from our enum value, so a cast is necessary.
+#if HAVE_PRINTF_ZD
+#  define SSIZE(x) x
+#  define STATUST(x) x
+#else
+#  define SSIZE(x) (signed size_t)x
+#  define STATUST(x) (status_t)x
+#endif
+
+// Set to true for noisy debug output.
+static const bool kIsDebug = false;
+
+#if PRINT_STRING_METRICS
+static const bool kPrintStringMetrics = true;
+#else
+static const bool kPrintStringMetrics = false;
+#endif
 
 status_t compileXmlFile(const sp<AaptAssets>& assets,
                         const sp<AaptFile>& target,
@@ -76,9 +93,11 @@ status_t compileXmlFile(const sp<AaptAssets>& assets,
     if (hasErrors) {
         return UNKNOWN_ERROR;
     }
-    
-    NOISY(printf("Input XML Resource:\n"));
-    NOISY(root->print());
+
+    if (kIsDebug) {
+        printf("Input XML Resource:\n");
+        root->print();
+    }
     err = root->flatten(target,
             (options&XML_COMPILE_STRIP_COMMENTS) != 0,
             (options&XML_COMPILE_STRIP_RAW_VALUES) != 0);
@@ -86,19 +105,18 @@ status_t compileXmlFile(const sp<AaptAssets>& assets,
         return err;
     }
 
-    NOISY(printf("Output XML Resource:\n"));
-    NOISY(ResXMLTree tree;
+    if (kIsDebug) {
+        printf("Output XML Resource:\n");
+        ResXMLTree tree;
         tree.setTo(target->getData(), target->getSize());
-        printXMLBlock(&tree));
+        printXMLBlock(&tree);
+    }
 
     target->setCompressionMethod(ZipEntry::kCompressDeflated);
     
     return err;
 }
 
-#undef NOISY
-#define NOISY(x) //x
-
 struct flag_entry
 {
     const char16_t* name;
@@ -576,7 +594,7 @@ status_t parseAndAddBag(Bundle* bundle,
                         const String16& itemIdent,
                         int32_t curFormat,
                         bool isFormatted,
-                        const String16& product,
+                        const String16& /* product */,
                         PseudolocalizationMethod pseudolocalize,
                         const bool overwrite,
                         ResourceTable* outTable)
@@ -592,16 +610,18 @@ status_t parseAndAddBag(Bundle* bundle,
     if (err != NO_ERROR) {
         return err;
     }
-    
-    NOISY(printf("Adding resource bag entry l=%c%c c=%c%c orien=%d d=%d "
-                 " pid=%s, bag=%s, id=%s: %s\n",
-                 config.language[0], config.language[1],
-                 config.country[0], config.country[1],
-                 config.orientation, config.density,
-                 String8(parentIdent).string(),
-                 String8(ident).string(),
-                 String8(itemIdent).string(),
-                 String8(str).string()));
+
+    if (kIsDebug) {
+        printf("Adding resource bag entry l=%c%c c=%c%c orien=%d d=%d "
+                " pid=%s, bag=%s, id=%s: %s\n",
+                config.language[0], config.language[1],
+                config.country[0], config.country[1],
+                config.orientation, config.density,
+                String8(parentIdent).string(),
+                String8(ident).string(),
+                String8(itemIdent).string(),
+                String8(str).string());
+    }
 
     err = outTable->addBag(SourcePos(in->getPrintableSource(), block->getLineNumber()),
                            myPackage, curType, ident, parentIdent, itemIdent, str,
@@ -737,11 +757,13 @@ status_t parseAndAddEntry(Bundle* bundle,
         }
     }
 
-    NOISY(printf("Adding resource entry l=%c%c c=%c%c orien=%d d=%d id=%s: %s\n",
-                 config.language[0], config.language[1],
-                 config.country[0], config.country[1],
-                 config.orientation, config.density,
-                 String8(ident).string(), String8(str).string()));
+    if (kIsDebug) {
+        printf("Adding resource entry l=%c%c c=%c%c orien=%d d=%d id=%s: %s\n",
+                config.language[0], config.language[1],
+                config.country[0], config.country[1],
+                config.orientation, config.density,
+                String8(ident).string(), String8(str).string());
+    }
 
     err = outTable->addEntry(SourcePos(in->getPrintableSource(), block->getLineNumber()),
                              myPackage, curType, ident, str, &spans, &config,
@@ -1710,7 +1732,7 @@ status_t compileResourceFile(Bundle* bundle,
         }
     }
 
-    return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
+    return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
 }
 
 ResourceTable::ResourceTable(Bundle* bundle, const String16& assetsPackage)
@@ -1764,8 +1786,9 @@ status_t ResourceTable::addIncludedResources(Bundle* bundle, const sp<AaptAssets
                 }
             }
             if (id != 0) {
-                NOISY(printf("Including package %s with ID=%d\n",
-                             String8(name).string(), id));
+                if (kIsDebug) {
+                    printf("Including package %s with ID=%d\n", String8(name).string(), id);
+                }
                 sp<Package> p = new Package(name, id);
                 mPackages.add(name, p);
                 mOrderedPackages.add(p);
@@ -1856,7 +1879,7 @@ status_t ResourceTable::startBag(const SourcePos& sourcePos,
                                  const String16& bagParent,
                                  const ResTable_config* params,
                                  bool overlay,
-                                 bool replace, bool isId)
+                                 bool replace, bool /* isId */)
 {
     status_t result = NO_ERROR;
 
@@ -2163,22 +2186,25 @@ uint32_t ResourceTable::getResId(const String16& ref,
         ref.string(), ref.size(), &package, &type, &name,
         defType, defPackage ? defPackage:&mAssetsPackage,
         outErrorMsg, &refOnlyPublic)) {
-        NOISY(printf("Expanding resource: ref=%s\n",
-                     String8(ref).string()));
-        NOISY(printf("Expanding resource: defType=%s\n",
-                     defType ? String8(*defType).string() : "NULL"));
-        NOISY(printf("Expanding resource: defPackage=%s\n",
-                     defPackage ? String8(*defPackage).string() : "NULL"));
-        NOISY(printf("Expanding resource: ref=%s\n", String8(ref).string()));
-        NOISY(printf("Expanded resource: p=%s, t=%s, n=%s, res=0\n",
-                     String8(package).string(), String8(type).string(),
-                     String8(name).string()));
+        if (kIsDebug) {
+            printf("Expanding resource: ref=%s\n", String8(ref).string());
+            printf("Expanding resource: defType=%s\n",
+                    defType ? String8(*defType).string() : "NULL");
+            printf("Expanding resource: defPackage=%s\n",
+                    defPackage ? String8(*defPackage).string() : "NULL");
+            printf("Expanding resource: ref=%s\n", String8(ref).string());
+            printf("Expanded resource: p=%s, t=%s, n=%s, res=0\n",
+                    String8(package).string(), String8(type).string(),
+                    String8(name).string());
+        }
         return 0;
     }
     uint32_t res = getResId(package, type, name, onlyPublic && refOnlyPublic);
-    NOISY(printf("Expanded resource: p=%s, t=%s, n=%s, res=%d\n",
-                 String8(package).string(), String8(type).string(),
-                 String8(name).string(), res));
+    if (kIsDebug) {
+        printf("Expanded resource: p=%s, t=%s, n=%s, res=%d\n",
+                String8(package).string(), String8(type).string(),
+                String8(name).string(), res);
+    }
     if (res == 0) {
         if (outErrorMsg)
             *outErrorMsg = "No resource found that matches the given name";
@@ -2245,9 +2271,11 @@ bool ResourceTable::stringToValue(Res_value* outValue, StringPool* pool,
             } else {
                 configStr = "(null)";
             }
-            NOISY(printf("Adding to pool string style #%d config %s: %s\n",
-                    style != NULL ? style->size() : 0,
-                    configStr.string(), String8(finalStr).string()));
+            if (kIsDebug) {
+                printf("Adding to pool string style #%zu config %s: %s\n",
+                        style != NULL ? style->size() : 0U,
+                        configStr.string(), String8(finalStr).string());
+            }
             if (style != NULL && style->size() > 0) {
                 outValue->data = pool->add(finalStr, *style, configTypeName, config);
             } else {
@@ -2851,9 +2879,9 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
         const size_t typeStringsStart = data->getSize();
         sp<AaptFile> strFile = p->getTypeStringsData();
         ssize_t amt = data->writeData(strFile->getData(), strFile->getSize());
-        #if PRINT_STRING_METRICS
-        fprintf(stderr, "**** type strings: %d\n", amt);
-        #endif
+        if (kPrintStringMetrics) {
+            fprintf(stderr, "**** type strings: %zd\n", SSIZE(amt));
+        }
         strAmt += amt;
         if (amt < 0) {
             return amt;
@@ -2861,9 +2889,9 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
         const size_t keyStringsStart = data->getSize();
         strFile = p->getKeyStringsData();
         amt = data->writeData(strFile->getData(), strFile->getSize());
-        #if PRINT_STRING_METRICS
-        fprintf(stderr, "**** key strings: %d\n", amt);
-        #endif
+        if (kPrintStringMetrics) {
+            fprintf(stderr, "**** key strings: %zd\n", SSIZE(amt));
+        }
         strAmt += amt;
         if (amt < 0) {
             return amt;
@@ -2942,29 +2970,31 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
             for (size_t ci=0; ci<NC; ci++) {
                 ConfigDescription config = t->getUniqueConfigs().itemAt(ci);
 
-                NOISY(printf("Writing config %d config: imsi:%d/%d lang:%c%c cnt:%c%c "
-                     "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d "
-                     "sw%ddp w%ddp h%ddp dir:%d\n",
-                      ti+1,
-                      config.mcc, config.mnc,
-                      config.language[0] ? config.language[0] : '-',
-                      config.language[1] ? config.language[1] : '-',
-                      config.country[0] ? config.country[0] : '-',
-                      config.country[1] ? config.country[1] : '-',
-                      config.orientation,
-                      config.uiMode,
-                      config.touchscreen,
-                      config.density,
-                      config.keyboard,
-                      config.inputFlags,
-                      config.navigation,
-                      config.screenWidth,
-                      config.screenHeight,
-                      config.smallestScreenWidthDp,
-                      config.screenWidthDp,
-                      config.screenHeightDp,
-                      config.layoutDirection));
-                      
+                if (kIsDebug) {
+                    printf("Writing config %zu config: imsi:%d/%d lang:%c%c cnt:%c%c "
+                        "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d "
+                        "sw%ddp w%ddp h%ddp layout:%d\n",
+                        ti + 1,
+                        config.mcc, config.mnc,
+                        config.language[0] ? config.language[0] : '-',
+                        config.language[1] ? config.language[1] : '-',
+                        config.country[0] ? config.country[0] : '-',
+                        config.country[1] ? config.country[1] : '-',
+                        config.orientation,
+                        config.uiMode,
+                        config.touchscreen,
+                        config.density,
+                        config.keyboard,
+                        config.inputFlags,
+                        config.navigation,
+                        config.screenWidth,
+                        config.screenHeight,
+                        config.smallestScreenWidthDp,
+                        config.screenWidthDp,
+                        config.screenHeightDp,
+                        config.screenLayout);
+                }
+
                 if (filterable && !filter.match(config)) {
                     continue;
                 }
@@ -2985,28 +3015,30 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
                 tHeader->entryCount = htodl(N);
                 tHeader->entriesStart = htodl(typeSize);
                 tHeader->config = config;
-                NOISY(printf("Writing type %d config: imsi:%d/%d lang:%c%c cnt:%c%c "
-                     "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d "
-                     "sw%ddp w%ddp h%ddp dir:%d\n",
-                      ti+1,
-                      tHeader->config.mcc, tHeader->config.mnc,
-                      tHeader->config.language[0] ? tHeader->config.language[0] : '-',
-                      tHeader->config.language[1] ? tHeader->config.language[1] : '-',
-                      tHeader->config.country[0] ? tHeader->config.country[0] : '-',
-                      tHeader->config.country[1] ? tHeader->config.country[1] : '-',
-                      tHeader->config.orientation,
-                      tHeader->config.uiMode,
-                      tHeader->config.touchscreen,
-                      tHeader->config.density,
-                      tHeader->config.keyboard,
-                      tHeader->config.inputFlags,
-                      tHeader->config.navigation,
-                      tHeader->config.screenWidth,
-                      tHeader->config.screenHeight,
-                      tHeader->config.smallestScreenWidthDp,
-                      tHeader->config.screenWidthDp,
-                      tHeader->config.screenHeightDp,
-                      tHeader->config.layoutDirection));
+                if (kIsDebug) {
+                    printf("Writing type %zu config: imsi:%d/%d lang:%c%c cnt:%c%c "
+                        "orien:%d ui:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d "
+                        "sw%ddp w%ddp h%ddp layout:%d\n",
+                        ti + 1,
+                        tHeader->config.mcc, tHeader->config.mnc,
+                        tHeader->config.language[0] ? tHeader->config.language[0] : '-',
+                        tHeader->config.language[1] ? tHeader->config.language[1] : '-',
+                        tHeader->config.country[0] ? tHeader->config.country[0] : '-',
+                        tHeader->config.country[1] ? tHeader->config.country[1] : '-',
+                        tHeader->config.orientation,
+                        tHeader->config.uiMode,
+                        tHeader->config.touchscreen,
+                        tHeader->config.density,
+                        tHeader->config.keyboard,
+                        tHeader->config.inputFlags,
+                        tHeader->config.navigation,
+                        tHeader->config.screenWidth,
+                        tHeader->config.screenHeight,
+                        tHeader->config.smallestScreenWidthDp,
+                        tHeader->config.screenWidthDp,
+                        tHeader->config.screenHeightDp,
+                        tHeader->config.screenLayout);
+                }
                 tHeader->config.swapHtoD();
 
                 // Build the entries inside of this type.
@@ -3083,10 +3115,10 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
 
     ssize_t amt = (dest->getSize()-strStart);
     strAmt += amt;
-    #if PRINT_STRING_METRICS
-    fprintf(stderr, "**** value strings: %d\n", amt);
-    fprintf(stderr, "**** total strings: %d\n", strAmt);
-    #endif
+    if (kPrintStringMetrics) {
+        fprintf(stderr, "**** value strings: %zd\n", SSIZE(amt));
+        fprintf(stderr, "**** total strings: %zd\n", SSIZE(strAmt));
+    }
     
     for (pi=0; pi<flatPackages.size(); pi++) {
         err = dest->writeData(flatPackages[pi]->getData(),
@@ -3101,13 +3133,10 @@ status_t ResourceTable::flatten(Bundle* bundle, const sp<AaptFile>& dest)
         (((uint8_t*)dest->getData()) + dataStart);
     header->header.size = htodl(dest->getSize() - dataStart);
 
-    NOISY(aout << "Resource table:"
-          << HexDump(dest->getData(), dest->getSize()) << endl);
-
-    #if PRINT_STRING_METRICS
-    fprintf(stderr, "**** total resource table size: %d / %d%% strings\n",
-        dest->getSize(), (strAmt*100)/dest->getSize());
-    #endif
+    if (kPrintStringMetrics) {
+        fprintf(stderr, "**** total resource table size: %zu / %zu%% strings\n",
+                dest->getSize(), (size_t)(strAmt*100)/dest->getSize());
+    }
     
     return NO_ERROR;
 }
@@ -3339,7 +3368,7 @@ status_t ResourceTable::Entry::generateAttributes(ResourceTable* table,
 }
 
 status_t ResourceTable::Entry::assignResourceIds(ResourceTable* table,
-                                                 const String16& package)
+                                                 const String16& /* package */)
 {
     bool hasErrors = false;
     
@@ -3372,7 +3401,7 @@ status_t ResourceTable::Entry::assignResourceIds(ResourceTable* table,
             }
         }
     }
-    return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
+    return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
 }
 
 status_t ResourceTable::Entry::prepareFlatten(StringPool* strings, ResourceTable* table,
@@ -3431,22 +3460,20 @@ status_t ResourceTable::Entry::remapStringValue(StringPool* strings)
     return NO_ERROR;
 }
 
-ssize_t ResourceTable::Entry::flatten(Bundle* bundle, const sp<AaptFile>& data, bool isPublic)
+ssize_t ResourceTable::Entry::flatten(Bundle* /* bundle */, const sp<AaptFile>& data, bool isPublic)
 {
     size_t amt = 0;
     ResTable_entry header;
     memset(&header, 0, sizeof(header));
     header.size = htods(sizeof(header));
-    const type ty = this != NULL ? mType : TYPE_ITEM;
-    if (this != NULL) {
-        if (ty == TYPE_BAG) {
-            header.flags |= htods(header.FLAG_COMPLEX);
-        }
-        if (isPublic) {
-            header.flags |= htods(header.FLAG_PUBLIC);
-        }
-        header.key.index = htodl(mNameIndex);
+    const type ty = mType;
+    if (ty == TYPE_BAG) {
+        header.flags |= htods(header.FLAG_COMPLEX);
     }
+    if (isPublic) {
+        header.flags |= htods(header.FLAG_PUBLIC);
+    }
+    header.key.index = htodl(mNameIndex);
     if (ty != TYPE_BAG) {
         status_t err = data->writeData(&header, sizeof(header));
         if (err != NO_ERROR) {
@@ -3621,10 +3648,11 @@ sp<ResourceTable::Entry> ResourceTable::Type::getEntry(const String16& entry,
     
     sp<Entry> e = c->getEntries().valueFor(cdesc);
     if (e == NULL) {
-        if (config != NULL) {
-            NOISY(printf("New entry at %s:%d: imsi:%d/%d lang:%c%c cnt:%c%c "
+        if (kIsDebug) {
+            if (config != NULL) {
+                printf("New entry at %s:%d: imsi:%d/%d lang:%c%c cnt:%c%c "
                     "orien:%d touch:%d density:%d key:%d inp:%d nav:%d sz:%dx%d "
-                    "sw%ddp w%ddp h%ddp dir:%d\n",
+                    "sw%ddp w%ddp h%ddp layout:%d\n",
                       sourcePos.file.string(), sourcePos.line,
                       config->mcc, config->mnc,
                       config->language[0] ? config->language[0] : '-',
@@ -3642,10 +3670,11 @@ sp<ResourceTable::Entry> ResourceTable::Type::getEntry(const String16& entry,
                       config->smallestScreenWidthDp,
                       config->screenWidthDp,
                       config->screenHeightDp,
-                      config->layoutDirection));
-        } else {
-            NOISY(printf("New entry at %s:%d: NULL config\n",
-                      sourcePos.file.string(), sourcePos.line));
+                      config->screenLayout);
+            } else {
+                printf("New entry at %s:%d: NULL config\n",
+                        sourcePos.file.string(), sourcePos.line);
+            }
         }
         e = new Entry(entry, sourcePos);
         c->addEntry(cdesc, e);
@@ -3751,7 +3780,7 @@ status_t ResourceTable::Type::applyPublicEntryOrder()
         j++;
     }
 
-    return hasError ? UNKNOWN_ERROR : NO_ERROR;
+    return hasError ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
 }
 
 ResourceTable::Package::Package(const String16& name, ssize_t includedId)
@@ -3807,9 +3836,6 @@ status_t ResourceTable::Package::setStrings(const sp<AaptFile>& data,
         return UNKNOWN_ERROR;
     }
 
-    NOISY(aout << "Setting restable string pool: "
-          << HexDump(data->getData(), data->getSize()) << endl);
-
     status_t err = strings->setTo(data->getData(), data->getSize());
     if (err == NO_ERROR) {
         const size_t N = strings->size();
@@ -4017,7 +4043,7 @@ bool ResourceTable::getItemValue(
         }
         item->evaluating = true;
         res = stringToValue(outValue, NULL, item->value, false, false, item->bagKeyId);
-        NOISY(
+        if (kIsDebug) {
             if (res) {
                 printf("getItemValue of #%08x[#%08x] (%s): type=#%08x, data=#%08x\n",
                        resID, attrID, String8(getEntry(resID)->getName()).string(),
@@ -4026,7 +4052,7 @@ bool ResourceTable::getItemValue(
                 printf("getItemValue of #%08x[#%08x]: failed\n",
                        resID, attrID);
             }
-        );
+        }
         item->evaluating = false;
     }
     return res;
index 5edc144..eec23aa 100644 (file)
@@ -3,7 +3,6 @@
 //
 // Build resource files from raw assets.
 //
-
 #include "StringPool.h"
 
 #include <utils/ByteOrder.h>
 
 #include "ResourceTable.h"
 
+// SSIZE: mingw does not have signed size_t == ssize_t.
 #if HAVE_PRINTF_ZD
 #  define ZD "%zd"
 #  define ZD_TYPE ssize_t
+#  define SSIZE(x) x
 #else
 #  define ZD "%ld"
 #  define ZD_TYPE long
+#  define SSIZE(x) (signed size_t)x
 #endif
 
-#define NOISY(x) //x
+// Set to true for noisy debug output.
+static const bool kIsDebug = false;
 
 void strcpy16_htod(char16_t* dst, const char16_t* src)
 {
@@ -134,8 +137,10 @@ ssize_t StringPool::add(const String16& value,
 
     if (configTypeName != NULL) {
         entry& ent = mEntries.editItemAt(eidx);
-        NOISY(printf("*** adding config type name %s, was %s\n",
-                configTypeName->string(), ent.configTypeName.string()));
+        if (kIsDebug) {
+            printf("*** adding config type name %s, was %s\n",
+                    configTypeName->string(), ent.configTypeName.string());
+        }
         if (ent.configTypeName.size() <= 0) {
             ent.configTypeName = *configTypeName;
         } else if (ent.configTypeName != *configTypeName) {
@@ -151,14 +156,18 @@ ssize_t StringPool::add(const String16& value,
             int cmp = ent.configs.itemAt(addPos).compareLogical(*config);
             if (cmp >= 0) {
                 if (cmp > 0) {
-                    NOISY(printf("*** inserting config: %s\n", config->toString().string()));
+                    if (kIsDebug) {
+                        printf("*** inserting config: %s\n", config->toString().string());
+                    }
                     ent.configs.insertAt(*config, addPos);
                 }
                 break;
             }
         }
         if (addPos >= ent.configs.size()) {
-            NOISY(printf("*** adding config: %s\n", config->toString().string()));
+            if (kIsDebug) {
+                printf("*** adding config: %s\n", config->toString().string());
+            }
             ent.configs.add(*config);
         }
     }
@@ -175,9 +184,11 @@ ssize_t StringPool::add(const String16& value,
         ent.indices.add(pos);
     }
 
-    NOISY(printf("Adding string %s to pool: pos=%d eidx=%d vidx=%d\n",
-            String8(value).string(), pos, eidx, vidx));
-    
+    if (kIsDebug) {
+        printf("Adding string %s to pool: pos=%zd eidx=%zd vidx=%zd\n",
+                String8(value).string(), SSIZE(pos), SSIZE(eidx), SSIZE(vidx));
+    }
+
     return pos;
 }
 
@@ -244,10 +255,14 @@ void StringPool::sortByConfig()
     }
 
     // Sort the array.
-    NOISY(printf("SORTING STRINGS BY CONFIGURATION...\n"));
+    if (kIsDebug) {
+        printf("SORTING STRINGS BY CONFIGURATION...\n");
+    }
     ConfigSorter sorter(*this);
     std::sort(newPosToOriginalPos.begin(), newPosToOriginalPos.end(), sorter);
-    NOISY(printf("DONE SORTING STRINGS BY CONFIGURATION.\n"));
+    if (kIsDebug) {
+        printf("DONE SORTING STRINGS BY CONFIGURATION.\n");
+    }
 
     // Create the reverse mapping from the original position in the array
     // to the new position where it appears in the sorted array.  This is
@@ -544,9 +559,13 @@ status_t StringPool::writeStringBlock(const sp<AaptFile>& pool)
     for (i=0; i<ENTRIES; i++) {
         entry& ent = mEntries.editItemAt(mEntryArray[i]);
         *index++ = htodl(ent.offset);
-        NOISY(printf("Writing entry #%d: \"%s\" ent=%d off=%d\n", i,
-                String8(ent.value).string(),
-                mEntryArray[i], ent.offset));
+        if (kIsDebug) {
+            printf("Writing entry #%zu: \"%s\" ent=%zu off=%zu\n",
+                    i,
+                    String8(ent.value).string(),
+                    mEntryArray[i],
+                    ent.offset);
+        }
     }
 
     // Write style index array.
@@ -562,8 +581,10 @@ ssize_t StringPool::offsetForString(const String16& val) const
 {
     const Vector<size_t>* indices = offsetsForString(val);
     ssize_t res = indices != NULL && indices->size() > 0 ? indices->itemAt(0) : -1;
-    NOISY(printf("Offset for string %s: %d (%s)\n", String8(val).string(), res,
-            res >= 0 ? String8(mEntries[mEntryArray[res]].value).string() : String8()));
+    if (kIsDebug) {
+        printf("Offset for string %s: %zd (%s)\n", String8(val).string(), SSIZE(res),
+                res >= 0 ? String8(mEntries[mEntryArray[res]].value).string() : String8());
+    }
     return res;
 }
 
index 03c66c1..fd3f573 100644 (file)
 #define O_BINARY 0
 #endif
 
-#define NOISY(x) //x
-#define NOISY_PARSE(x) //x
+// SSIZE: mingw does not have signed size_t == ssize_t.
+// STATUST: mingw does seem to redefine UNKNOWN_ERROR from our enum value, so a cast is necessary.
+#if HAVE_PRINTF_ZD
+#  define SSIZE(x) x
+#  define STATUST(x) x
+#else
+#  define SSIZE(x) (signed size_t)x
+#  define STATUST(x) (status_t)x
+#endif
+
+// Set to true for noisy debug output.
+static const bool kIsDebug = false;
+// Set to true for noisy debug output of parsing.
+static const bool kIsDebugParse = false;
+
+#if PRINT_STRING_METRICS
+static const bool kPrintStringMetrics = true;
+#else
+static const bool kPrintStringMetrics = false;
+#endif
 
 const char* const RESOURCES_ROOT_NAMESPACE = "http://schemas.android.com/apk/res/";
 const char* const RESOURCES_ANDROID_NAMESPACE = "http://schemas.android.com/apk/res/android";
@@ -56,7 +74,10 @@ String16 getNamespaceResourcePackage(String16 appPackage, String16 namespaceUri,
     size_t prefixSize;
     bool isPublic = true;
     if(namespaceUri.startsWith(RESOURCES_PREFIX_AUTO_PACKAGE)) {
-        NOISY(printf("Using default application package: %s -> %s\n", String8(namespaceUri).string(), String8(appPackage).string()));
+        if (kIsDebug) {
+            printf("Using default application package: %s -> %s\n", String8(namespaceUri).string(),
+                   String8(appPackage).string());
+        }
         isPublic = true;
         return appPackage;
     } else if (namespaceUri.startsWith(RESOURCES_PREFIX)) {
@@ -180,7 +201,7 @@ status_t hasSubstitutionErrors(const char* fileName,
     return NO_ERROR;
 }
 
-status_t parseStyledString(Bundle* bundle,
+status_t parseStyledString(Bundle* /* bundle */,
                            const char* fileName,
                            ResXMLTree* inXml,
                            const String16& endTag,
@@ -557,8 +578,10 @@ status_t parseXMLResource(const sp<AaptFile>& file, ResXMLTree* outTree,
     }
     root->removeWhitespace(stripAll, cDataTags);
 
-    NOISY(printf("Input XML from %s:\n", (const char*)file->getPrintableSource()));
-    NOISY(root->print());
+    if (kIsDebug) {
+        printf("Input XML from %s:\n", (const char*)file->getPrintableSource());
+        root->print();
+    }
     sp<AaptFile> rsc = new AaptFile(String8(), AaptGroupEntry(), String8());
     status_t err = root->flatten(rsc, !keepComments, false);
     if (err != NO_ERROR) {
@@ -569,8 +592,10 @@ status_t parseXMLResource(const sp<AaptFile>& file, ResXMLTree* outTree,
         return err;
     }
 
-    NOISY(printf("Output XML:\n"));
-    NOISY(printXMLBlock(outTree));
+    if (kIsDebug) {
+        printf("Output XML:\n");
+        printXMLBlock(outTree);
+    }
 
     return NO_ERROR;
 }
@@ -818,11 +843,13 @@ void XMLNode::setAttributeResID(size_t attrIdx, uint32_t resId)
     } else {
         mAttributeOrder.removeItem(e.index);
     }
-    NOISY(printf("Elem %s %s=\"%s\": set res id = 0x%08x\n",
-            String8(getElementName()).string(),
-            String8(mAttributes.itemAt(attrIdx).name).string(),
-            String8(mAttributes.itemAt(attrIdx).string).string(),
-            resId));
+    if (kIsDebug) {
+        printf("Elem %s %s=\"%s\": set res id = 0x%08x\n",
+                String8(getElementName()).string(),
+                String8(mAttributes.itemAt(attrIdx).name).string(),
+                String8(mAttributes.itemAt(attrIdx).string).string(),
+                resId);
+    }
     mAttributes.editItemAt(attrIdx).nameResId = resId;
     mAttributeOrder.add(resId, attrIdx);
 }
@@ -933,9 +960,11 @@ status_t XMLNode::parseValues(const sp<AaptAssets>& assets,
                                   e.nameResId, NULL, &defPackage, table, &ac)) {
                 hasErrors = true;
             }
-            NOISY(printf("Attr %s: type=0x%x, str=%s\n",
-                   String8(e.name).string(), e.value.dataType,
-                   String8(e.string).string()));
+            if (kIsDebug) {
+                printf("Attr %s: type=0x%x, str=%s\n",
+                        String8(e.name).string(), e.value.dataType,
+                        String8(e.string).string());
+            }
         }
     }
     const size_t N = mChildren.size();
@@ -945,7 +974,7 @@ status_t XMLNode::parseValues(const sp<AaptAssets>& assets,
             hasErrors = true;
         }
     }
-    return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
+    return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
 }
 
 status_t XMLNode::assignResourceIds(const sp<AaptAssets>& assets,
@@ -962,13 +991,15 @@ status_t XMLNode::assignResourceIds(const sp<AaptAssets>& assets,
             if (e.ns.size() <= 0) continue;
             bool nsIsPublic;
             String16 pkg(getNamespaceResourcePackage(String16(assets->getPackage()), e.ns, &nsIsPublic));
-            NOISY(printf("Elem %s %s=\"%s\": namespace(%s) %s ===> %s\n",
-                    String8(getElementName()).string(),
-                    String8(e.name).string(),
-                    String8(e.string).string(),
-                    String8(e.ns).string(),
-                    (nsIsPublic) ? "public" : "private",
-                    String8(pkg).string()));
+            if (kIsDebug) {
+                printf("Elem %s %s=\"%s\": namespace(%s) %s ===> %s\n",
+                        String8(getElementName()).string(),
+                        String8(e.name).string(),
+                        String8(e.string).string(),
+                        String8(e.ns).string(),
+                        (nsIsPublic) ? "public" : "private",
+                        String8(pkg).string());
+            }
             if (pkg.size() <= 0) continue;
             uint32_t res = table != NULL
                 ? table->getResId(e.name, &attr, &pkg, &errorMsg, nsIsPublic)
@@ -977,8 +1008,10 @@ status_t XMLNode::assignResourceIds(const sp<AaptAssets>& assets,
                                       attr.string(), attr.size(),
                                       pkg.string(), pkg.size());
             if (res != 0) {
-                NOISY(printf("XML attribute name %s: resid=0x%08x\n",
-                             String8(e.name).string(), res));
+                if (kIsDebug) {
+                    printf("XML attribute name %s: resid=0x%08x\n",
+                            String8(e.name).string(), res);
+                }
                 setAttributeResID(i, res);
             } else {
                 SourcePos(mFilename, getStartLineNumber()).error(
@@ -996,7 +1029,7 @@ status_t XMLNode::assignResourceIds(const sp<AaptAssets>& assets,
         }
     }
 
-    return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
+    return hasErrors ? STATUST(UNKNOWN_ERROR) : NO_ERROR;
 }
 
 status_t XMLNode::flatten(const sp<AaptFile>& dest,
@@ -1014,18 +1047,7 @@ status_t XMLNode::flatten(const sp<AaptFile>& dest,
     // Next collect all remainibng strings.
     collect_strings(&strings, &resids, stripComments, stripRawValues);
 
-#if 0  // No longer compiles
-    NOISY(printf("Found strings:\n");
-        const size_t N = strings.size();
-        for (size_t i=0; i<N; i++) {
-            printf("%s\n", String8(strings.entryAt(i).string).string());
-        }
-    );
-#endif    
-
     sp<AaptFile> stringPool = strings.createStringBlock();
-    NOISY(aout << "String pool:"
-          << HexDump(stringPool->getData(), stringPool->getSize()) << endl);
 
     ResXMLTree_header header;
     memset(&header, 0, sizeof(header));
@@ -1056,17 +1078,13 @@ status_t XMLNode::flatten(const sp<AaptFile>& dest,
 
     void* data = dest->editData();
     ResXMLTree_header* hd = (ResXMLTree_header*)(((uint8_t*)data)+basePos);
-    size_t size = dest->getSize()-basePos;
     hd->header.size = htodl(dest->getSize()-basePos);
 
-    NOISY(aout << "XML resource:"
-          << HexDump(dest->getData(), dest->getSize()) << endl);
-
-    #if PRINT_STRING_METRICS
-    fprintf(stderr, "**** total xml size: %d / %d%% strings (in %s)\n",
-        dest->getSize(), (stringPool->getSize()*100)/dest->getSize(),
-        dest->getPath().string());
-    #endif
+    if (kPrintStringMetrics) {
+        fprintf(stderr, "**** total xml size: %zu / %zu%% strings (in %s)\n",
+                dest->getSize(), (stringPool->getSize()*100)/dest->getSize(),
+                dest->getPath().string());
+    }
         
     return NO_ERROR;
 }
@@ -1139,7 +1157,9 @@ static void splitName(const char* name, String16* outNs, String16* outName)
 void XMLCALL
 XMLNode::startNamespace(void *userData, const char *prefix, const char *uri)
 {
-    NOISY_PARSE(printf("Start Namespace: %s %s\n", prefix, uri));
+    if (kIsDebugParse) {
+        printf("Start Namespace: %s %s\n", prefix, uri);
+    }
     ParseState* st = (ParseState*)userData;
     sp<XMLNode> node = XMLNode::newNamespace(st->filename, 
             String16(prefix != NULL ? prefix : ""), String16(uri));
@@ -1155,7 +1175,9 @@ XMLNode::startNamespace(void *userData, const char *prefix, const char *uri)
 void XMLCALL
 XMLNode::startElement(void *userData, const char *name, const char **atts)
 {
-    NOISY_PARSE(printf("Start Element: %s\n", name));
+    if (kIsDebugParse) {
+        printf("Start Element: %s\n", name);
+    }
     ParseState* st = (ParseState*)userData;
     String16 ns16, name16;
     splitName(name, &ns16, &name16);
@@ -1181,7 +1203,9 @@ XMLNode::startElement(void *userData, const char *name, const char **atts)
 void XMLCALL
 XMLNode::characterData(void *userData, const XML_Char *s, int len)
 {
-    NOISY_PARSE(printf("CDATA: \"%s\"\n", String8(s, len).string()));
+    if (kIsDebugParse) {
+        printf("CDATA: \"%s\"\n", String8(s, len).string());
+    }
     ParseState* st = (ParseState*)userData;
     sp<XMLNode> node = NULL;
     if (st->stack.size() == 0) {
@@ -1208,7 +1232,9 @@ XMLNode::characterData(void *userData, const XML_Char *s, int len)
 void XMLCALL
 XMLNode::endElement(void *userData, const char *name)
 {
-    NOISY_PARSE(printf("End Element: %s\n", name));
+    if (kIsDebugParse) {
+        printf("End Element: %s\n", name);
+    }
     ParseState* st = (ParseState*)userData;
     sp<XMLNode> node = st->stack.itemAt(st->stack.size()-1);
     node->setEndLineNumber(XML_GetCurrentLineNumber(st->parser));
@@ -1228,7 +1254,9 @@ void XMLCALL
 XMLNode::endNamespace(void *userData, const char *prefix)
 {
     const char* nonNullPrefix = prefix != NULL ? prefix : "";
-    NOISY_PARSE(printf("End Namespace: %s\n", prefix));
+    if (kIsDebugParse) {
+        printf("End Namespace: %s\n", prefix);
+    }
     ParseState* st = (ParseState*)userData;
     sp<XMLNode> node = st->stack.itemAt(st->stack.size()-1);
     node->setEndLineNumber(XML_GetCurrentLineNumber(st->parser));
@@ -1240,7 +1268,9 @@ XMLNode::endNamespace(void *userData, const char *prefix)
 void XMLCALL
 XMLNode::commentData(void *userData, const char *comment)
 {
-    NOISY_PARSE(printf("Comment: %s\n", comment));
+    if (kIsDebugParse) {
+        printf("Comment: %s\n", comment);
+    }
     ParseState* st = (ParseState*)userData;
     if (st->pendingComment.size() > 0) {
         st->pendingComment.append(String16("\n"));
@@ -1337,8 +1367,10 @@ status_t XMLNode::collect_attr_strings(StringPool* outPool,
             }
             if (idx < 0) {
                 idx = outPool->add(attr.name);
-                NOISY(printf("Adding attr %s (resid 0x%08x) to pool: idx=%d\n",
-                        String8(attr.name).string(), id, idx));
+                if (kIsDebug) {
+                    printf("Adding attr %s (resid 0x%08x) to pool: idx=%zd\n",
+                            String8(attr.name).string(), id, SSIZE(idx));
+                }
                 if (id != 0) {
                     while ((ssize_t)outResIds->size() <= idx) {
                         outResIds->add(0);
@@ -1347,8 +1379,9 @@ status_t XMLNode::collect_attr_strings(StringPool* outPool,
                 }
             }
             attr.namePoolIdx = idx;
-            NOISY(printf("String %s offset=0x%08x\n",
-                         String8(attr.name).string(), idx));
+            if (kIsDebug) {
+                printf("String %s offset=0x%08zd\n", String8(attr.name).string(), SSIZE(idx));
+            }
         }
     }
 
index b575988..f97f604 100644 (file)
@@ -141,33 +141,15 @@ void ZipEntry::initNew(const char* fileName, const char* comment)
  *
  * Initializes the CDE and the LFH.
  */
-status_t ZipEntry::initFromExternal(const ZipFile* pZipFile,
+status_t ZipEntry::initFromExternal(const ZipFile* /* pZipFile */,
     const ZipEntry* pEntry)
 {
-    /*
-     * Copy everything in the CDE over, then fix up the hairy bits.
-     */
-    memcpy(&mCDE, &pEntry->mCDE, sizeof(mCDE));
-
-    if (mCDE.mFileNameLength > 0) {
-        mCDE.mFileName = new unsigned char[mCDE.mFileNameLength+1];
-        if (mCDE.mFileName == NULL)
-            return NO_MEMORY;
-        strcpy((char*) mCDE.mFileName, (char*)pEntry->mCDE.mFileName);
-    }
-    if (mCDE.mFileCommentLength > 0) {
-        mCDE.mFileComment = new unsigned char[mCDE.mFileCommentLength+1];
-        if (mCDE.mFileComment == NULL)
-            return NO_MEMORY;
-        strcpy((char*) mCDE.mFileComment, (char*)pEntry->mCDE.mFileComment);
-    }
-    if (mCDE.mExtraFieldLength > 0) {
-        /* we null-terminate this, though it may not be a string */
-        mCDE.mExtraField = new unsigned char[mCDE.mExtraFieldLength+1];
-        if (mCDE.mExtraField == NULL)
-            return NO_MEMORY;
-        memcpy(mCDE.mExtraField, pEntry->mCDE.mExtraField,
-            mCDE.mExtraFieldLength+1);
+    mCDE = pEntry->mCDE;
+    // Check whether we got all the memory needed.
+    if ((mCDE.mFileNameLength > 0 && mCDE.mFileName == NULL) ||
+            (mCDE.mFileCommentLength > 0 && mCDE.mFileComment == NULL) ||
+            (mCDE.mExtraFieldLength > 0 && mCDE.mExtraField == NULL)) {
+        return NO_MEMORY;
     }
 
     /* construct the LFH from the CDE */
@@ -694,3 +676,60 @@ void ZipEntry::CentralDirEntry::dump(void) const
         ALOGD("  comment: '%s'\n", mFileComment);
 }
 
+/*
+ * Copy-assignment operator for CentralDirEntry.
+ */
+ZipEntry::CentralDirEntry& ZipEntry::CentralDirEntry::operator=(const ZipEntry::CentralDirEntry& src) {
+    if (this == &src) {
+        return *this;
+    }
+
+    // Free up old data.
+    delete[] mFileName;
+    delete[] mExtraField;
+    delete[] mFileComment;
+
+    // Copy scalars.
+    mVersionMadeBy = src.mVersionMadeBy;
+    mVersionToExtract = src.mVersionToExtract;
+    mGPBitFlag = src.mGPBitFlag;
+    mCompressionMethod = src.mCompressionMethod;
+    mLastModFileTime = src.mLastModFileTime;
+    mLastModFileDate = src.mLastModFileDate;
+    mCRC32 = src.mCRC32;
+    mCompressedSize = src.mCompressedSize;
+    mUncompressedSize = src.mUncompressedSize;
+    mFileNameLength = src.mFileNameLength;
+    mExtraFieldLength = src.mExtraFieldLength;
+    mFileCommentLength = src.mFileCommentLength;
+    mDiskNumberStart = src.mDiskNumberStart;
+    mInternalAttrs = src.mInternalAttrs;
+    mExternalAttrs = src.mExternalAttrs;
+    mLocalHeaderRelOffset = src.mLocalHeaderRelOffset;
+
+    // Copy strings, if necessary.
+    if (mFileNameLength > 0) {
+        mFileName = new unsigned char[mFileNameLength + 1];
+        if (mFileName != NULL)
+            strcpy((char*)mFileName, (char*)src.mFileName);
+    } else {
+        mFileName = NULL;
+    }
+    if (mFileCommentLength > 0) {
+        mFileComment = new unsigned char[mFileCommentLength + 1];
+        if (mFileComment != NULL)
+            strcpy((char*)mFileComment, (char*)src.mFileComment);
+    } else {
+        mFileComment = NULL;
+    }
+    if (mExtraFieldLength > 0) {
+        /* we null-terminate this, though it may not be a string */
+        mExtraField = new unsigned char[mExtraFieldLength + 1];
+        if (mExtraField != NULL)
+            memcpy(mExtraField, src.mExtraField, mExtraFieldLength + 1);
+    } else {
+        mExtraField = NULL;
+    }
+
+    return *this;
+}
index c2f3227..287a540 100644 (file)
@@ -298,6 +298,8 @@ private:
         status_t read(FILE* fp);
         status_t write(FILE* fp);
 
+        CentralDirEntry& operator=(const CentralDirEntry& src);
+
         // unsigned long mSignature;
         unsigned short  mVersionMadeBy;
         unsigned short  mVersionToExtract;
index 8057068..36f4e73 100644 (file)
@@ -676,8 +676,6 @@ status_t ZipFile::copyFpToFp(FILE* dstFp, FILE* srcFp, unsigned long* pCRC32)
 status_t ZipFile::copyDataToFp(FILE* dstFp,
     const void* data, size_t size, unsigned long* pCRC32)
 {
-    size_t count;
-
     *pCRC32 = crc32(0L, Z_NULL, 0);
     if (size > 0) {
         *pCRC32 = crc32(*pCRC32, (const unsigned char*)data, size);