X-Git-Url: https://git.saurik.com/android/aapt.git/blobdiff_plain/d0c4b8109ffb0ad08dcbf29203c71af10715fd87..dfc6828a06b23282f39d4c45e613d33f7e8e646e:/ResourceTable.cpp diff --git a/ResourceTable.cpp b/ResourceTable.cpp index 3641458..ef11a83 100644 --- a/ResourceTable.cpp +++ b/ResourceTable.cpp @@ -115,7 +115,7 @@ static const flag_entry gFormatFlags[] = { "a floating point value, such as \"1.2\"."}, { dimensionArray, sizeof(dimensionArray)/2, ResTable_map::TYPE_DIMENSION, "a dimension value, which is a floating point number appended with a unit such as \"14.5sp\".\n" - "Available units are: px (pixels), db (density-independent pixels), sp (scaled pixels based on preferred font size),\n" + "Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size),\n" "in (inches), mm (millimeters)." }, { fractionArray, sizeof(fractionArray)/2, ResTable_map::TYPE_FRACTION, "a fractional value, which is a floating point number appended with either % or %p, such as \"14.5%\".\n" @@ -546,6 +546,7 @@ status_t parseAndAddBag(Bundle* bundle, const String16& itemIdent, int32_t curFormat, bool pseudolocalize, + const bool overwrite, ResourceTable* outTable) { status_t err; @@ -572,7 +573,7 @@ status_t parseAndAddBag(Bundle* bundle, err = outTable->addBag(SourcePos(in->getPrintableSource(), block->getLineNumber()), myPackage, curType, ident, parentIdent, itemIdent, str, - &spans, &config, false, false, curFormat); + &spans, &config, overwrite, false, curFormat); return err; } @@ -588,6 +589,7 @@ status_t parseAndAddEntry(Bundle* bundle, bool curIsStyled, int32_t curFormat, bool pseudolocalize, + const bool overwrite, ResourceTable* outTable) { status_t err; @@ -610,7 +612,7 @@ status_t parseAndAddEntry(Bundle* bundle, err = outTable->addEntry(SourcePos(in->getPrintableSource(), block->getLineNumber()), myPackage, curType, ident, str, &spans, &config, - false, curFormat); + false, curFormat, overwrite); return err; } @@ -619,6 +621,7 @@ status_t compileResourceFile(Bundle* bundle, const sp& assets, const sp& in, const ResTable_config& defParams, + const bool overwrite, ResourceTable* outTable) { ResXMLTree block; @@ -641,6 +644,7 @@ status_t compileResourceFile(Bundle* bundle, const String16 bool16("bool"); const String16 integer16("integer"); const String16 dimen16("dimen"); + const String16 fraction16("fraction"); const String16 style16("style"); const String16 plurals16("plurals"); const String16 array16("array"); @@ -979,7 +983,7 @@ status_t compileResourceFile(Bundle* bundle, if (locale.size() > 0) { fprintf(stderr, "aapt: warning: string '%s' in %s marked untranslatable but exists" " in locale '%s'\n", String8(name).string(), - bundle->getResourceSourceDir(), + bundle->getResourceSourceDirs()[0], locale.string()); // hasErrors = localHasErrors = true; } else { @@ -1019,6 +1023,10 @@ status_t compileResourceFile(Bundle* bundle, curTag = &dimen16; curType = dimen16; curFormat = ResTable_map::TYPE_REFERENCE|ResTable_map::TYPE_DIMENSION; + } else if (strcmp16(block.getElementName(&len), fraction16.string()) == 0) { + curTag = &fraction16; + curType = fraction16; + curFormat = ResTable_map::TYPE_REFERENCE|ResTable_map::TYPE_FRACTION; } else if (strcmp16(block.getElementName(&len), bag16.string()) == 0) { curTag = &bag16; curIsBag = true; @@ -1101,7 +1109,8 @@ status_t compileResourceFile(Bundle* bundle, if (!localHasErrors) { err = outTable->startBag(SourcePos(in->getPrintableSource(), block.getLineNumber()), - myPackage, curType, ident, parentIdent, &curParams); + myPackage, curType, ident, parentIdent, &curParams, + overwrite); if (err != NO_ERROR) { hasErrors = localHasErrors = true; } @@ -1172,7 +1181,8 @@ status_t compileResourceFile(Bundle* bundle, block.getPosition(&parserPosition); err = parseAndAddBag(bundle, in, &block, curParams, myPackage, curType, - ident, parentIdent, itemIdent, curFormat, false, outTable); + ident, parentIdent, itemIdent, curFormat, + false, overwrite, outTable); if (err == NO_ERROR) { if (curIsPseudolocalizable && localeIsDefined(curParams) && bundle->getPseudolocalize()) { @@ -1181,7 +1191,7 @@ status_t compileResourceFile(Bundle* bundle, block.setPosition(parserPosition); err = parseAndAddBag(bundle, in, &block, pseudoParams, myPackage, curType, ident, parentIdent, itemIdent, curFormat, true, - outTable); + overwrite, outTable); #endif } } @@ -1204,7 +1214,7 @@ status_t compileResourceFile(Bundle* bundle, block.getPosition(&parserPosition); err = parseAndAddEntry(bundle, in, &block, curParams, myPackage, curType, ident, - *curTag, curIsStyled, curFormat, false, outTable); + *curTag, curIsStyled, curFormat, false, overwrite, outTable); if (err < NO_ERROR) { // Why err < NO_ERROR instead of err != NO_ERROR? hasErrors = localHasErrors = true; @@ -1215,7 +1225,7 @@ status_t compileResourceFile(Bundle* bundle, // pseudolocalize here block.setPosition(parserPosition); err = parseAndAddEntry(bundle, in, &block, pseudoParams, myPackage, curType, - ident, *curTag, curIsStyled, curFormat, true, outTable); + ident, *curTag, curIsStyled, curFormat, true, overwrite, outTable); if (err != NO_ERROR) { hasErrors = localHasErrors = true; } @@ -1360,7 +1370,8 @@ status_t ResourceTable::addEntry(const SourcePos& sourcePos, const Vector* style, const ResTable_config* params, const bool doSetIndex, - const int32_t format) + const int32_t format, + const bool overwrite) { // Check for adding entries in other packages... for now we do // nothing. We need to do the right thing here to support skinning. @@ -1384,7 +1395,7 @@ status_t ResourceTable::addEntry(const SourcePos& sourcePos, if (e == NULL) { return UNKNOWN_ERROR; } - status_t err = e->setItem(sourcePos, value, style, format); + status_t err = e->setItem(sourcePos, value, style, format, overwrite); if (err == NO_ERROR) { mNumLocal++; } @@ -1399,6 +1410,8 @@ status_t ResourceTable::startBag(const SourcePos& sourcePos, const ResTable_config* params, bool replace, bool isId) { + status_t result = NO_ERROR; + // Check for adding entries in other packages... for now we do // nothing. We need to do the right thing here to support skinning. uint32_t rid = mAssets->getIncludedResources() @@ -1432,8 +1445,15 @@ status_t ResourceTable::startBag(const SourcePos& sourcePos, } e->setParent(bagParent); } - - return e->makeItABag(sourcePos); + + if ((result = e->makeItABag(sourcePos)) != NO_ERROR) { + return result; + } + + if (replace) { + return e->emptyBag(sourcePos); + } + return result; } status_t ResourceTable::addBag(const SourcePos& sourcePos, @@ -2125,7 +2145,7 @@ ResourceTable::validateLocalizations(void) // Look for strings with no default localization if (configSet.count(defaultLocale) == 0) { fprintf(stdout, "aapt: warning: string '%s' has no default translation in %s; found:", - String8(nameIter->first).string(), mBundle->getResourceSourceDir()); + String8(nameIter->first).string(), mBundle->getResourceSourceDirs()[0]); for (set::iterator locales = configSet.begin(); locales != configSet.end(); locales++) { @@ -2160,15 +2180,14 @@ ResourceTable::validateLocalizations(void) // consider that string to have fulfilled the localization requirement. String8 region(config.string(), 2); if (configSet.find(region) == configSet.end()) { - // TODO: force an error if there is no default to fall back to if (configSet.count(defaultLocale) == 0) { - fprintf(stdout, "aapt: warning: " + fprintf(stdout, "aapt: error: " "*** string '%s' has no default or required localization " "for '%s' in %s\n", String8(nameIter->first).string(), config.string(), - mBundle->getResourceSourceDir()); - //err = UNKNOWN_ERROR; + mBundle->getResourceSourceDirs()[0]); + err = UNKNOWN_ERROR; } } } @@ -2728,7 +2747,8 @@ status_t ResourceTable::Entry::makeItABag(const SourcePos& sourcePos) status_t ResourceTable::Entry::setItem(const SourcePos& sourcePos, const String16& value, const Vector* style, - int32_t format) + int32_t format, + const bool overwrite) { Item item(sourcePos, false, value, style); @@ -2740,7 +2760,7 @@ status_t ResourceTable::Entry::setItem(const SourcePos& sourcePos, item.sourcePos.file.string(), item.sourcePos.line); return UNKNOWN_ERROR; } - if (mType != TYPE_UNKNOWN) { + if ( (mType != TYPE_UNKNOWN) && (overwrite == false) ) { sourcePos.error("Resource entry %s is already defined.\n" "%s:%d: Originally defined here.\n", String8(mName).string(), @@ -2788,6 +2808,17 @@ status_t ResourceTable::Entry::addToBag(const SourcePos& sourcePos, return NO_ERROR; } +status_t ResourceTable::Entry::emptyBag(const SourcePos& sourcePos) +{ + status_t err = makeItABag(sourcePos); + if (err != NO_ERROR) { + return err; + } + + mBag.clear(); + return NO_ERROR; +} + status_t ResourceTable::Entry::generateAttributes(ResourceTable* table, const String16& package) { @@ -3479,4 +3510,3 @@ bool ResourceTable::getItemValue( } return res; } -