intl/icu/source/tools/toolutil/package.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/tools/toolutil/package.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,201 @@
     1.4 +/*
     1.5 +*******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 2005-2013, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +*******************************************************************************
    1.11 +*   file name:  package.h
    1.12 +*   encoding:   US-ASCII
    1.13 +*   tab size:   8 (not used)
    1.14 +*   indentation:4
    1.15 +*
    1.16 +*   created on: 2005aug25
    1.17 +*   created by: Markus W. Scherer
    1.18 +*
    1.19 +*   Read, modify, and write ICU .dat data package files.
    1.20 +*/
    1.21 +
    1.22 +#ifndef __PACKAGE_H__
    1.23 +#define __PACKAGE_H__
    1.24 +
    1.25 +#include "unicode/utypes.h"
    1.26 +
    1.27 +#include <stdio.h>
    1.28 +
    1.29 +// .dat package file representation ---------------------------------------- ***
    1.30 +
    1.31 +#define STRING_STORE_SIZE 100000
    1.32 +#define MAX_PKG_NAME_LENGTH 32
    1.33 +
    1.34 +typedef void CheckDependency(void *context, const char *itemName, const char *targetName);
    1.35 +
    1.36 +U_NAMESPACE_BEGIN
    1.37 +
    1.38 +struct Item {
    1.39 +    char *name;
    1.40 +    uint8_t *data;
    1.41 +    int32_t length;
    1.42 +    UBool isDataOwned;
    1.43 +    char type;
    1.44 +};
    1.45 +
    1.46 +class U_TOOLUTIL_API Package {
    1.47 +public:
    1.48 +    /*
    1.49 +     * Constructor.
    1.50 +     * Prepare this object for a new, empty package.
    1.51 +     */
    1.52 +    Package();
    1.53 +
    1.54 +    /* Destructor. */
    1.55 +    ~Package();
    1.56 +
    1.57 +    /**
    1.58 +     * Uses the prefix of the first entry of the package in readPackage(),
    1.59 +     * rather than the package basename.
    1.60 +     */
    1.61 +    void setAutoPrefix() { doAutoPrefix=TRUE; }
    1.62 +    /**
    1.63 +     * Same as setAutoPrefix(), plus the prefix must end with the platform type letter.
    1.64 +     */
    1.65 +    void setAutoPrefixWithType() {
    1.66 +        doAutoPrefix=TRUE;
    1.67 +        prefixEndsWithType=TRUE;
    1.68 +    }
    1.69 +    void setPrefix(const char *p);
    1.70 +
    1.71 +    /*
    1.72 +     * Read an existing .dat package file.
    1.73 +     * The header and item name strings are swapped into this object,
    1.74 +     * but the items are left unswapped.
    1.75 +     */
    1.76 +    void readPackage(const char *filename);
    1.77 +    /*
    1.78 +     * Write a .dat package file with the items in this object.
    1.79 +     * Swap all pieces to the desired output platform properties.
    1.80 +     * The package becomes unusable:
    1.81 +     * The item names are swapped and sorted in the outCharset rather than the local one.
    1.82 +     * Also, the items themselves are swapped in-place
    1.83 +     */
    1.84 +    void writePackage(const char *filename, char outType, const char *comment);
    1.85 +
    1.86 +    /*
    1.87 +     * Return the input data type letter (l, b, or e).
    1.88 +     */
    1.89 +    char getInType();
    1.90 +
    1.91 +    // find the item in items[], return the non-negative index if found, else the binary-not of the insertion point
    1.92 +    int32_t findItem(const char *name, int32_t length=-1) const;
    1.93 +
    1.94 +    /*
    1.95 +     * Set internal state for following calls to findNextItem() which will return
    1.96 +     * indexes for items whose names match the pattern.
    1.97 +     */
    1.98 +    void findItems(const char *pattern);
    1.99 +    int32_t findNextItem();
   1.100 +    /*
   1.101 +     * Set the match mode for findItems() & findNextItem().
   1.102 +     * @param mode 0=default
   1.103 +     *             MATCH_NOSLASH * does not match a '/'
   1.104 +     */
   1.105 +    void setMatchMode(uint32_t mode);
   1.106 +
   1.107 +    enum {
   1.108 +        MATCH_NOSLASH=1
   1.109 +    };
   1.110 +
   1.111 +    void addItem(const char *name);
   1.112 +    void addItem(const char *name, uint8_t *data, int32_t length, UBool isDataOwned, char type);
   1.113 +    void addFile(const char *filesPath, const char *name);
   1.114 +    void addItems(const Package &listPkg);
   1.115 +
   1.116 +    void removeItem(int32_t itemIndex);
   1.117 +    void removeItems(const char *pattern);
   1.118 +    void removeItems(const Package &listPkg);
   1.119 +
   1.120 +    /* The extractItem() functions accept outputType=0 to mean "don't swap the item". */
   1.121 +    void extractItem(const char *filesPath, int32_t itemIndex, char outType);
   1.122 +    void extractItems(const char *filesPath, const char *pattern, char outType);
   1.123 +    void extractItems(const char *filesPath, const Package &listPkg, char outType);
   1.124 +
   1.125 +    /* This variant extracts an item to a specific filename. */
   1.126 +    void extractItem(const char *filesPath, const char *outName, int32_t itemIndex, char outType);
   1.127 +
   1.128 +    int32_t getItemCount() const;
   1.129 +    const Item *getItem(int32_t idx) const;
   1.130 +
   1.131 +    /*
   1.132 +     * Check dependencies and return TRUE if all dependencies are fulfilled.
   1.133 +     */
   1.134 +    UBool checkDependencies();
   1.135 +
   1.136 +    /*
   1.137 +     * Enumerate all the dependencies and give the results to context and call CheckDependency callback
   1.138 +     * @param context user context (will be passed to check function)
   1.139 +     * @param check will be called with context and any missing items
   1.140 +     */
   1.141 +    void enumDependencies(void *context, CheckDependency check);
   1.142 +
   1.143 +private:
   1.144 +    void enumDependencies(Item *pItem, void *context, CheckDependency check);
   1.145 +
   1.146 +    /**
   1.147 +     * Default CheckDependency function used by checkDependencies()
   1.148 +     */
   1.149 +    static void checkDependency(void *context, const char *itemName, const char *targetName);
   1.150 +
   1.151 +    /*
   1.152 +     * Allocate a string in inStrings or outStrings.
   1.153 +     * The length does not include the terminating NUL.
   1.154 +     */
   1.155 +    char *allocString(UBool in, int32_t length);
   1.156 +
   1.157 +    void sortItems();
   1.158 +
   1.159 +    // data fields
   1.160 +    char inPkgName[MAX_PKG_NAME_LENGTH];
   1.161 +    char pkgPrefix[MAX_PKG_NAME_LENGTH];
   1.162 +
   1.163 +    uint8_t *inData;
   1.164 +    uint8_t header[1024];
   1.165 +    int32_t inLength, headerLength;
   1.166 +    uint8_t inCharset;
   1.167 +    UBool inIsBigEndian;
   1.168 +    UBool doAutoPrefix;
   1.169 +    UBool prefixEndsWithType;
   1.170 +
   1.171 +    int32_t itemCount;
   1.172 +    int32_t itemMax;
   1.173 +    Item   *items;
   1.174 +
   1.175 +    int32_t inStringTop, outStringTop;
   1.176 +    char inStrings[STRING_STORE_SIZE], outStrings[STRING_STORE_SIZE];
   1.177 +
   1.178 +    // match mode for findItems(pattern) and findNextItem()
   1.179 +    uint32_t matchMode;
   1.180 +
   1.181 +    // state for findItems(pattern) and findNextItem()
   1.182 +    const char *findPrefix, *findSuffix;
   1.183 +    int32_t findPrefixLength, findSuffixLength;
   1.184 +    int32_t findNextIndex;
   1.185 +
   1.186 +    // state for checkDependencies()
   1.187 +    UBool isMissingItems;
   1.188 +
   1.189 +    /**
   1.190 +     * Grow itemMax to new value
   1.191 +     */
   1.192 +    void setItemCapacity(int32_t max);
   1.193 +
   1.194 +    /**
   1.195 +     * Grow itemMax to at least itemCount+1
   1.196 +     */
   1.197 +    void ensureItemCapacity();
   1.198 +};
   1.199 +
   1.200 +U_NAMESPACE_END
   1.201 +
   1.202 +#endif
   1.203 +
   1.204 +

mercurial