]> git.saurik.com Git - apple/icu.git/blame - icuSources/tools/toolutil/package.h
ICU-8.11.1.tar.gz
[apple/icu.git] / icuSources / tools / toolutil / package.h
CommitLineData
73c04bcf
A
1/*
2*******************************************************************************
3*
4* Copyright (C) 2005-2006, International Business Machines
5* Corporation and others. All Rights Reserved.
6*
7*******************************************************************************
8* file name: package.h
9* encoding: US-ASCII
10* tab size: 8 (not used)
11* indentation:4
12*
13* created on: 2005aug25
14* created by: Markus W. Scherer
15*
16* Read, modify, and write ICU .dat data package files.
17*/
18
19#ifndef __PACKAGE_H__
20#define __PACKAGE_H__
21
22#include "unicode/utypes.h"
23
24#include <stdio.h>
25
26// .dat package file representation ---------------------------------------- ***
27
28#define STRING_STORE_SIZE 100000
29#define MAX_FILE_COUNT 2000
30#define MAX_PKG_NAME_LENGTH 32
31
32U_NAMESPACE_BEGIN
33
34struct Item {
35 char *name;
36 uint8_t *data;
37 int32_t length;
38 UBool isDataOwned;
39 char type;
40};
41
42class U_TOOLUTIL_API Package {
43public:
44 /*
45 * Constructor.
46 * Prepare this object for a new, empty package.
47 */
48 Package();
49
50 /* Destructor. */
51 ~Package();
52
53 /*
54 * Read an existing .dat package file.
55 * The header and item name strings are swapped into this object,
56 * but the items are left unswapped.
57 */
58 void readPackage(const char *filename);
59 /*
60 * Write a .dat package file with the items in this object.
61 * Swap all pieces to the desired output platform properties.
62 * The package becomes unusable:
63 * The item names are swapped and sorted in the outCharset rather than the local one.
64 * Also, the items themselves are swapped in-place
65 */
66 void writePackage(const char *filename, char outType, const char *comment);
67
68 /*
69 * Return the input data type letter (l, b, or e).
70 */
71 char getInType();
72
73 // find the item in items[], return the non-negative index if found, else the binary-not of the insertion point
74 int32_t findItem(const char *name, int32_t length=-1);
75
76 /*
77 * Set internal state for following calls to findNextItem() which will return
78 * indexes for items whose names match the pattern.
79 */
80 void findItems(const char *pattern);
81 int32_t findNextItem();
82 /*
83 * Set the match mode for findItems() & findNextItem().
84 * @param mode 0=default
85 * MATCH_NOSLASH * does not match a '/'
86 */
87 void setMatchMode(uint32_t mode);
88
89 enum {
90 MATCH_NOSLASH=1
91 };
92
93 void addItem(const char *name);
94 void addItem(const char *name, uint8_t *data, int32_t length, UBool isDataOwned, char type);
95 void addFile(const char *filesPath, const char *name);
96 void addItems(const Package &listPkg);
97
98 void removeItem(int32_t index);
99 void removeItems(const char *pattern);
100 void removeItems(const Package &listPkg);
101
102 /* The extractItem() functions accept outputType=0 to mean "don't swap the item". */
103 void extractItem(const char *filesPath, int32_t index, char outType);
104 void extractItems(const char *filesPath, const char *pattern, char outType);
105 void extractItems(const char *filesPath, const Package &listPkg, char outType);
106
107 /* This variant extracts an item to a specific filename. */
108 void extractItem(const char *filesPath, const char *outName, int32_t index, char outType);
109
110 void listItems(FILE *file);
111
112 /*
113 * Check dependencies and return TRUE if all dependencies are fulfilled.
114 */
115 UBool checkDependencies();
116
117private:
118 void enumDependencies(Item *pItem);
119
120 static void checkDependency(void *context, const char *itemName, const char *targetName);
121
122 /*
123 * Allocate a string in inStrings or outStrings.
124 * The length does not include the terminating NUL.
125 */
126 char *allocString(UBool in, int32_t length);
127
128 void sortItems();
129
130 // data fields
131 char inPkgName[MAX_PKG_NAME_LENGTH];
132
133 uint8_t *inData;
134 uint8_t header[1024];
135 int32_t inLength, headerLength;
136 uint8_t inCharset;
137 UBool inIsBigEndian;
138
139 int32_t itemCount;
140 Item items[MAX_FILE_COUNT];
141
142 int32_t inStringTop, outStringTop;
143 char inStrings[STRING_STORE_SIZE], outStrings[STRING_STORE_SIZE];
144
145 // match mode for findItems(pattern) and findNextItem()
146 uint32_t matchMode;
147
148 // state for findItems(pattern) and findNextItem()
149 const char *findPrefix, *findSuffix;
150 int32_t findPrefixLength, findSuffixLength;
151 int32_t findNextIndex;
152
153 // state for checkDependencies()
154 UBool isMissingItems;
155};
156
157U_NAMESPACE_END
158
159#endif