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