1/*
2*******************************************************************************
3*
4*   Copyright (C) 2000-2014, International Business Machines
5*   Corporation and others.  All Rights Reserved.
6*
7*******************************************************************************
8*
9* File reslist.h
10*
11* Modification History:
12*
13*   Date        Name        Description
14*   02/21/00    weiv        Creation.
15*******************************************************************************
16*/
17
18#ifndef RESLIST_H
19#define RESLIST_H
20
21#define KEY_SPACE_SIZE 65536
22#define RESLIST_MAX_INT_VECTOR 2048
23
24#include "unicode/utypes.h"
25#include "unicode/ures.h"
26#include "unicode/ustring.h"
27#include "uresdata.h"
28#include "cmemory.h"
29#include "cstring.h"
30#include "unewdata.h"
31#include "ustr.h"
32
33U_CDECL_BEGIN
34
35typedef struct KeyMapEntry {
36    int32_t oldpos, newpos;
37} KeyMapEntry;
38
39/* Resource bundle root table */
40struct SRBRoot {
41  struct SResource *fRoot;
42  char *fLocale;
43  int32_t fIndexLength;
44  int32_t fMaxTableLength;
45  UBool noFallback; /* see URES_ATT_NO_FALLBACK */
46  int8_t fStringsForm; /* default STRINGS_UTF16_V1 */
47  UBool fIsPoolBundle;
48
49  char *fKeys;
50  KeyMapEntry *fKeyMap;
51  int32_t fKeysBottom, fKeysTop;
52  int32_t fKeysCapacity;
53  int32_t fKeysCount;
54  int32_t fLocalKeyLimit; /* key offset < limit fits into URES_TABLE */
55
56  uint16_t *f16BitUnits;
57  int32_t f16BitUnitsCapacity;
58  int32_t f16BitUnitsLength;
59
60  const char *fPoolBundleKeys;
61  int32_t fPoolBundleKeysLength;
62  int32_t fPoolBundleKeysCount;
63  int32_t fPoolChecksum;
64};
65
66struct SRBRoot *bundle_open(const struct UString* comment, UBool isPoolBundle, UErrorCode *status);
67void bundle_write(struct SRBRoot *bundle, const char *outputDir, const char *outputPkg, char *writtenFilename, int writtenFilenameLen, UErrorCode *status);
68
69/* write a java resource file */
70void bundle_write_java(struct SRBRoot *bundle, const char *outputDir, const char* outputEnc, char *writtenFilename,
71                       int writtenFilenameLen, const char* packageName, const char* bundleName, UErrorCode *status);
72
73/* write a xml resource file */
74/* commented by Jing*/
75/* void bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc,
76                  char *writtenFilename, int writtenFilenameLen,UErrorCode *status); */
77
78/* added by Jing*/
79void bundle_write_xml(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc, const char* rbname,
80                  char *writtenFilename, int writtenFilenameLen, const char* language, const char* package, UErrorCode *status);
81
82void bundle_close(struct SRBRoot *bundle, UErrorCode *status);
83void bundle_setlocale(struct SRBRoot *bundle, UChar *locale, UErrorCode *status);
84int32_t bundle_addtag(struct SRBRoot *bundle, const char *tag, UErrorCode *status);
85
86const char *
87bundle_getKeyBytes(struct SRBRoot *bundle, int32_t *pLength);
88
89int32_t
90bundle_addKeyBytes(struct SRBRoot *bundle, const char *keyBytes, int32_t length, UErrorCode *status);
91
92void
93bundle_compactKeys(struct SRBRoot *bundle, UErrorCode *status);
94
95/* Various resource types */
96
97/*
98 * Return a unique pointer to a dummy object,
99 * for use in non-error cases when no resource is to be added to the bundle.
100 * (NULL is used in error cases.)
101 */
102struct SResource* res_none(void);
103
104struct SResTable {
105    uint32_t fCount;
106    int8_t fType;  /* determined by table_write16() for table_preWrite() & table_write() */
107    struct SResource *fFirst;
108    struct SRBRoot *fRoot;
109};
110
111struct SResource* table_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status);
112void table_add(struct SResource *table, struct SResource *res, int linenumber, UErrorCode *status);
113
114struct SResArray {
115    uint32_t fCount;
116    struct SResource *fFirst;
117    struct SResource *fLast;
118};
119
120struct SResource* array_open(struct SRBRoot *bundle, const char *tag, const struct UString* comment, UErrorCode *status);
121void array_add(struct SResource *array, struct SResource *res, UErrorCode *status);
122
123struct SResString {
124    struct SResource *fSame;  /* used for duplicates */
125    UChar *fChars;
126    int32_t fLength;
127    int32_t fSuffixOffset;  /* this string is a suffix of fSame at this offset */
128    int8_t fNumCharsForLength;
129};
130
131struct SResource *string_open(struct SRBRoot *bundle, const char *tag, const UChar *value, int32_t len, const struct UString* comment, UErrorCode *status);
132
133struct SResource *alias_open(struct SRBRoot *bundle, const char *tag, UChar *value, int32_t len, const struct UString* comment, UErrorCode *status);
134
135struct SResIntVector {
136    uint32_t fCount;
137    uint32_t *fArray;
138};
139
140struct SResource* intvector_open(struct SRBRoot *bundle, const char *tag,  const struct UString* comment, UErrorCode *status);
141void intvector_add(struct SResource *intvector, int32_t value, UErrorCode *status);
142
143struct SResInt {
144    uint32_t fValue;
145};
146
147struct SResource *int_open(struct SRBRoot *bundle, const char *tag, int32_t value, const struct UString* comment, UErrorCode *status);
148
149struct SResBinary {
150    uint32_t fLength;
151    uint8_t *fData;
152    char* fFileName; /* file name for binary or import binary tags if any */
153};
154
155struct SResource *bin_open(struct SRBRoot *bundle, const char *tag, uint32_t length, uint8_t *data, const char* fileName, const struct UString* comment, UErrorCode *status);
156
157/* Resource place holder */
158
159struct SResource {
160    int8_t   fType;     /* nominal type: fRes (when != 0xffffffff) may use subtype */
161    UBool    fWritten;  /* res_write() can exit early */
162    uint32_t fRes;      /* resource item word; 0xffffffff if not known yet */
163    int32_t  fKey;      /* Index into bundle->fKeys; -1 if no key. */
164    int      line;      /* used internally to report duplicate keys in tables */
165    struct SResource *fNext; /*This is for internal chaining while building*/
166    struct UString fComment;
167    union {
168        struct SResTable fTable;
169        struct SResArray fArray;
170        struct SResString fString;
171        struct SResIntVector fIntVector;
172        struct SResInt fIntValue;
173        struct SResBinary fBinaryValue;
174    } u;
175};
176
177const char *
178res_getKeyString(const struct SRBRoot *bundle, const struct SResource *res, char temp[8]);
179
180void res_close(struct SResource *res);
181
182void setIncludeCopyright(UBool val);
183UBool getIncludeCopyright(void);
184
185void setFormatVersion(int32_t formatVersion);
186
187void setUsePoolBundle(UBool use);
188
189/* in wrtxml.cpp */
190uint32_t computeCRC(char *ptr, uint32_t len, uint32_t lastcrc);
191
192U_CDECL_END
193#endif /* #ifndef RESLIST_H */
194