michael@0: /* michael@0: ******************************************************************************* michael@0: * michael@0: * Copyright (C) 2000-2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************* michael@0: * michael@0: * File reslist.h michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 02/21/00 weiv Creation. michael@0: ******************************************************************************* michael@0: */ michael@0: michael@0: #ifndef RESLIST_H michael@0: #define RESLIST_H michael@0: michael@0: #define KEY_SPACE_SIZE 65536 michael@0: #define RESLIST_MAX_INT_VECTOR 2048 michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/ures.h" michael@0: #include "unicode/ustring.h" michael@0: #include "uresdata.h" michael@0: #include "cmemory.h" michael@0: #include "cstring.h" michael@0: #include "unewdata.h" michael@0: #include "ustr.h" michael@0: #include "uhash.h" michael@0: michael@0: U_CDECL_BEGIN michael@0: michael@0: typedef struct KeyMapEntry { michael@0: int32_t oldpos, newpos; michael@0: } KeyMapEntry; michael@0: michael@0: /* Resource bundle root table */ michael@0: struct SRBRoot { michael@0: struct SResource *fRoot; michael@0: char *fLocale; michael@0: int32_t fIndexLength; michael@0: int32_t fMaxTableLength; michael@0: UBool noFallback; /* see URES_ATT_NO_FALLBACK */ michael@0: int8_t fStringsForm; /* default STRINGS_UTF16_V1 */ michael@0: UBool fIsPoolBundle; michael@0: michael@0: char *fKeys; michael@0: KeyMapEntry *fKeyMap; michael@0: int32_t fKeysBottom, fKeysTop; michael@0: int32_t fKeysCapacity; michael@0: int32_t fKeysCount; michael@0: int32_t fLocalKeyLimit; /* key offset < limit fits into URES_TABLE */ michael@0: michael@0: UHashtable *fStringSet; michael@0: uint16_t *f16BitUnits; michael@0: int32_t f16BitUnitsCapacity; michael@0: int32_t f16BitUnitsLength; michael@0: michael@0: const char *fPoolBundleKeys; michael@0: int32_t fPoolBundleKeysLength; michael@0: int32_t fPoolBundleKeysCount; michael@0: int32_t fPoolChecksum; michael@0: }; michael@0: michael@0: struct SRBRoot *bundle_open(const struct UString* comment, UBool isPoolBundle, UErrorCode *status); michael@0: void bundle_write(struct SRBRoot *bundle, const char *outputDir, const char *outputPkg, char *writtenFilename, int writtenFilenameLen, UErrorCode *status); michael@0: michael@0: /* write a java resource file */ michael@0: void bundle_write_java(struct SRBRoot *bundle, const char *outputDir, const char* outputEnc, char *writtenFilename, michael@0: int writtenFilenameLen, const char* packageName, const char* bundleName, UErrorCode *status); michael@0: michael@0: /* write a xml resource file */ michael@0: /* commented by Jing*/ michael@0: /* void bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc, michael@0: char *writtenFilename, int writtenFilenameLen,UErrorCode *status); */ michael@0: michael@0: /* added by Jing*/ michael@0: void bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc, const char* rbname, michael@0: char *writtenFilename, int writtenFilenameLen, const char* language, const char* package, UErrorCode *status); michael@0: michael@0: void bundle_close(struct SRBRoot *bundle, UErrorCode *status); michael@0: void bundle_setlocale(struct SRBRoot *bundle, UChar *locale, UErrorCode *status); michael@0: int32_t bundle_addtag(struct SRBRoot *bundle, const char *tag, UErrorCode *status); michael@0: michael@0: const char * michael@0: bundle_getKeyBytes(struct SRBRoot *bundle, int32_t *pLength); michael@0: michael@0: int32_t michael@0: bundle_addKeyBytes(struct SRBRoot *bundle, const char *keyBytes, int32_t length, UErrorCode *status); michael@0: michael@0: void michael@0: bundle_compactKeys(struct SRBRoot *bundle, UErrorCode *status); michael@0: michael@0: /* Various resource types */ michael@0: michael@0: /* michael@0: * Return a unique pointer to a dummy object, michael@0: * for use in non-error cases when no resource is to be added to the bundle. michael@0: * (NULL is used in error cases.) michael@0: */ michael@0: struct SResource* res_none(void); michael@0: michael@0: struct SResTable { michael@0: uint32_t fCount; michael@0: int8_t fType; /* determined by table_write16() for table_preWrite() & table_write() */ michael@0: struct SResource *fFirst; michael@0: struct SRBRoot *fRoot; michael@0: }; michael@0: michael@0: struct SResource* table_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status); michael@0: void table_add(struct SResource *table, struct SResource *res, int linenumber, UErrorCode *status); michael@0: michael@0: struct SResArray { michael@0: uint32_t fCount; michael@0: struct SResource *fFirst; michael@0: struct SResource *fLast; michael@0: }; michael@0: michael@0: struct SResource* array_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status); michael@0: void array_add(struct SResource *array, struct SResource *res, UErrorCode *status); michael@0: michael@0: struct SResString { michael@0: struct SResource *fSame; /* used for duplicates */ michael@0: UChar *fChars; michael@0: int32_t fLength; michael@0: int32_t fSuffixOffset; /* this string is a suffix of fSame at this offset */ michael@0: int8_t fNumCharsForLength; michael@0: }; michael@0: michael@0: struct SResource *string_open(struct SRBRoot *bundle, const char *tag, const UChar *value, int32_t len, const struct UString* comment, UErrorCode *status); michael@0: michael@0: /** michael@0: * Remove a string from a bundle and close (delete) it. michael@0: * The string must not have been added to a table or array yet. michael@0: * This function only undoes what string_open() did. michael@0: */ michael@0: void bundle_closeString(struct SRBRoot *bundle, struct SResource *string); michael@0: michael@0: struct SResource *alias_open(struct SRBRoot *bundle, const char *tag, UChar *value, int32_t len, const struct UString* comment, UErrorCode *status); michael@0: michael@0: struct SResIntVector { michael@0: uint32_t fCount; michael@0: uint32_t *fArray; michael@0: }; michael@0: michael@0: struct SResource* intvector_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status); michael@0: void intvector_add(struct SResource *intvector, int32_t value, UErrorCode *status); michael@0: michael@0: struct SResInt { michael@0: uint32_t fValue; michael@0: }; michael@0: michael@0: struct SResource *int_open(struct SRBRoot *bundle, const char *tag, int32_t value, const struct UString* comment, UErrorCode *status); michael@0: michael@0: struct SResBinary { michael@0: uint32_t fLength; michael@0: uint8_t *fData; michael@0: char* fFileName; /* file name for binary or import binary tags if any */ michael@0: }; michael@0: michael@0: struct SResource *bin_open(struct SRBRoot *bundle, const char *tag, uint32_t length, uint8_t *data, const char* fileName, const struct UString* comment, UErrorCode *status); michael@0: michael@0: /* Resource place holder */ michael@0: michael@0: struct SResource { michael@0: int8_t fType; /* nominal type: fRes (when != 0xffffffff) may use subtype */ michael@0: UBool fWritten; /* res_write() can exit early */ michael@0: uint32_t fRes; /* resource item word; 0xffffffff if not known yet */ michael@0: int32_t fKey; /* Index into bundle->fKeys; -1 if no key. */ michael@0: int line; /* used internally to report duplicate keys in tables */ michael@0: struct SResource *fNext; /*This is for internal chaining while building*/ michael@0: struct UString fComment; michael@0: union { michael@0: struct SResTable fTable; michael@0: struct SResArray fArray; michael@0: struct SResString fString; michael@0: struct SResIntVector fIntVector; michael@0: struct SResInt fIntValue; michael@0: struct SResBinary fBinaryValue; michael@0: } u; michael@0: }; michael@0: michael@0: const char * michael@0: res_getKeyString(const struct SRBRoot *bundle, const struct SResource *res, char temp[8]); michael@0: michael@0: void res_close(struct SResource *res); michael@0: michael@0: void setIncludeCopyright(UBool val); michael@0: UBool getIncludeCopyright(void); michael@0: michael@0: void setFormatVersion(int32_t formatVersion); michael@0: michael@0: void setUsePoolBundle(UBool use); michael@0: michael@0: /* in wrtxml.cpp */ michael@0: uint32_t computeCRC(char *ptr, uint32_t len, uint32_t lastcrc); michael@0: michael@0: U_CDECL_END michael@0: #endif /* #ifndef RESLIST_H */