]>
git.saurik.com Git - apple/icu.git/blob - icuSources/tools/toolutil/package.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
6 * Copyright (C) 2005-2014, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 *******************************************************************************
10 * file name: package.h
12 * tab size: 8 (not used)
15 * created on: 2005aug25
16 * created by: Markus W. Scherer
18 * Read, modify, and write ICU .dat data package files.
24 #include "unicode/utypes.h"
28 // .dat package file representation ---------------------------------------- ***
30 #define STRING_STORE_SIZE 100000
31 #define MAX_PKG_NAME_LENGTH 64
33 typedef void CheckDependency(void *context
, const char *itemName
, const char *targetName
);
45 class U_TOOLUTIL_API Package
{
49 * Prepare this object for a new, empty package.
57 * Uses the prefix of the first entry of the package in readPackage(),
58 * rather than the package basename.
60 void setAutoPrefix() { doAutoPrefix
=TRUE
; }
62 * Same as setAutoPrefix(), plus the prefix must end with the platform type letter.
64 void setAutoPrefixWithType() {
66 prefixEndsWithType
=TRUE
;
68 void setPrefix(const char *p
);
71 * Read an existing .dat package file.
72 * The header and item name strings are swapped into this object,
73 * but the items are left unswapped.
75 void readPackage(const char *filename
);
77 * Write a .dat package file with the items in this object.
78 * Swap all pieces to the desired output platform properties.
79 * The package becomes unusable:
80 * The item names are swapped and sorted in the outCharset rather than the local one.
81 * Also, the items themselves are swapped in-place
83 void writePackage(const char *filename
, char outType
, const char *comment
);
86 * Return the input data type letter (l, b, or e).
90 // find the item in items[], return the non-negative index if found, else the binary-not of the insertion point
91 int32_t findItem(const char *name
, int32_t length
=-1) const;
94 * Set internal state for following calls to findNextItem() which will return
95 * indexes for items whose names match the pattern.
97 void findItems(const char *pattern
);
98 int32_t findNextItem();
100 * Set the match mode for findItems() & findNextItem().
101 * @param mode 0=default
102 * MATCH_NOSLASH * does not match a '/'
104 void setMatchMode(uint32_t mode
);
110 void addItem(const char *name
);
111 void addItem(const char *name
, uint8_t *data
, int32_t length
, UBool isDataOwned
, char type
);
112 void addFile(const char *filesPath
, const char *name
);
113 void addItems(const Package
&listPkg
);
115 void removeItem(int32_t itemIndex
);
116 void removeItems(const char *pattern
);
117 void removeItems(const Package
&listPkg
);
119 /* The extractItem() functions accept outputType=0 to mean "don't swap the item". */
120 void extractItem(const char *filesPath
, int32_t itemIndex
, char outType
);
121 void extractItems(const char *filesPath
, const char *pattern
, char outType
);
122 void extractItems(const char *filesPath
, const Package
&listPkg
, char outType
);
124 /* This variant extracts an item to a specific filename. */
125 void extractItem(const char *filesPath
, const char *outName
, int32_t itemIndex
, char outType
);
127 int32_t getItemCount() const;
128 const Item
*getItem(int32_t idx
) const;
131 * Check dependencies and return TRUE if all dependencies are fulfilled.
133 UBool
checkDependencies();
136 * Enumerate all the dependencies and give the results to context and call CheckDependency callback
137 * @param context user context (will be passed to check function)
138 * @param check will be called with context and any missing items
140 void enumDependencies(void *context
, CheckDependency check
);
143 void enumDependencies(Item
*pItem
, void *context
, CheckDependency check
);
146 * Default CheckDependency function used by checkDependencies()
148 static void checkDependency(void *context
, const char *itemName
, const char *targetName
);
151 * Allocate a string in inStrings or outStrings.
152 * The length does not include the terminating NUL.
154 char *allocString(UBool in
, int32_t length
);
159 char inPkgName
[MAX_PKG_NAME_LENGTH
];
160 char pkgPrefix
[MAX_PKG_NAME_LENGTH
];
163 uint8_t header
[1024];
164 int32_t inLength
, headerLength
;
168 UBool prefixEndsWithType
;
174 int32_t inStringTop
, outStringTop
;
175 char inStrings
[STRING_STORE_SIZE
], outStrings
[STRING_STORE_SIZE
];
177 // match mode for findItems(pattern) and findNextItem()
180 // state for findItems(pattern) and findNextItem()
181 const char *findPrefix
, *findSuffix
;
182 int32_t findPrefixLength
, findSuffixLength
;
183 int32_t findNextIndex
;
185 // state for checkDependencies()
186 UBool isMissingItems
;
189 * Grow itemMax to new value
191 void setItemCapacity(int32_t max
);
194 * Grow itemMax to at least itemCount+1
196 void ensureItemCapacity();