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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 *******************************************************************************
michael@0 3 *
michael@0 4 * Copyright (C) 1999-2013, International Business Machines
michael@0 5 * Corporation and others. All Rights Reserved.
michael@0 6 *
michael@0 7 *******************************************************************************
michael@0 8 * file name: toolutil.h
michael@0 9 * encoding: US-ASCII
michael@0 10 * tab size: 8 (not used)
michael@0 11 * indentation:4
michael@0 12 *
michael@0 13 * created on: 1999nov19
michael@0 14 * created by: Markus W. Scherer
michael@0 15 *
michael@0 16 * This file defines utility functions for ICU tools like genccode.
michael@0 17 */
michael@0 18
michael@0 19 #ifndef __TOOLUTIL_H__
michael@0 20 #define __TOOLUTIL_H__
michael@0 21
michael@0 22 #include "unicode/utypes.h"
michael@0 23
michael@0 24
michael@0 25 #ifdef __cplusplus
michael@0 26
michael@0 27 #include "unicode/errorcode.h"
michael@0 28
michael@0 29 U_NAMESPACE_BEGIN
michael@0 30
michael@0 31 /**
michael@0 32 * ErrorCode subclass for use in ICU command-line tools.
michael@0 33 * The destructor calls handleFailure() which calls exit(errorCode) when isFailure().
michael@0 34 */
michael@0 35 class U_TOOLUTIL_API IcuToolErrorCode : public ErrorCode {
michael@0 36 public:
michael@0 37 /**
michael@0 38 * @param loc A short string describing where the IcuToolErrorCode is used.
michael@0 39 */
michael@0 40 IcuToolErrorCode(const char *loc) : location(loc) {}
michael@0 41 virtual ~IcuToolErrorCode();
michael@0 42 protected:
michael@0 43 virtual void handleFailure() const;
michael@0 44 private:
michael@0 45 const char *location;
michael@0 46 };
michael@0 47
michael@0 48 U_NAMESPACE_END
michael@0 49
michael@0 50 #endif
michael@0 51
michael@0 52 /*
michael@0 53 * For Windows, a path/filename may be the short (8.3) version
michael@0 54 * of the "real", long one. In this case, the short one
michael@0 55 * is abbreviated and contains a tilde etc.
michael@0 56 * This function returns a pointer to the original pathname
michael@0 57 * if it is the "real" one itself, and a pointer to a static
michael@0 58 * buffer (not thread-safe) containing the long version
michael@0 59 * if the pathname is indeed abbreviated.
michael@0 60 *
michael@0 61 * On platforms other than Windows, this function always returns
michael@0 62 * the input pathname pointer.
michael@0 63 *
michael@0 64 * This function is especially useful in tools that are called
michael@0 65 * by a batch file for loop, which yields short pathnames on Win9x.
michael@0 66 */
michael@0 67 U_CAPI const char * U_EXPORT2
michael@0 68 getLongPathname(const char *pathname);
michael@0 69
michael@0 70 /**
michael@0 71 * Find the basename at the end of a pathname, i.e., the part
michael@0 72 * after the last file separator, and return a pointer
michael@0 73 * to this part of the pathname.
michael@0 74 * If the pathname only contains a basename and no file separator,
michael@0 75 * then the pathname pointer itself is returned.
michael@0 76 **/
michael@0 77 U_CAPI const char * U_EXPORT2
michael@0 78 findBasename(const char *filename);
michael@0 79
michael@0 80 /**
michael@0 81 * Find the directory name of a pathname, that is, everything
michael@0 82 * up to but not including the last file separator.
michael@0 83 *
michael@0 84 * If successful, copies the directory name into the output buffer along with
michael@0 85 * a terminating NULL.
michael@0 86 *
michael@0 87 * If there isn't a directory name in the path, it returns an empty string.
michael@0 88 * @param path the full pathname to inspect.
michael@0 89 * @param buffer the output buffer
michael@0 90 * @param bufLen the output buffer length
michael@0 91 * @param status error code- may return U_BUFFER_OVERFLOW_ERROR if bufLen is too small.
michael@0 92 * @return If successful, a pointer to the output buffer. If failure or bufLen is too small, NULL.
michael@0 93 **/
michael@0 94 U_CAPI const char * U_EXPORT2
michael@0 95 findDirname(const char *path, char *buffer, int32_t bufLen, UErrorCode* status);
michael@0 96
michael@0 97 /*
michael@0 98 * Return the current year in the Gregorian calendar. Used for copyright generation.
michael@0 99 */
michael@0 100 U_CAPI int32_t U_EXPORT2
michael@0 101 getCurrentYear(void);
michael@0 102
michael@0 103 /*
michael@0 104 * Creates a directory with pathname.
michael@0 105 *
michael@0 106 * @param status Set to an error code when mkdir failed.
michael@0 107 */
michael@0 108 U_CAPI void U_EXPORT2
michael@0 109 uprv_mkdir(const char *pathname, UErrorCode *status);
michael@0 110
michael@0 111 #if !UCONFIG_NO_FILE_IO
michael@0 112 /**
michael@0 113 * Return TRUE if the named item exists
michael@0 114 * @param file filename
michael@0 115 * @return TRUE if named item (file, dir, etc) exists, FALSE otherwise
michael@0 116 */
michael@0 117 U_CAPI UBool U_EXPORT2
michael@0 118 uprv_fileExists(const char *file);
michael@0 119 #endif
michael@0 120
michael@0 121 /**
michael@0 122 * Return the modification date for the specified file or directory.
michael@0 123 * Return value is undefined if there was an error.
michael@0 124 */
michael@0 125 /*U_CAPI UDate U_EXPORT2
michael@0 126 uprv_getModificationDate(const char *pathname, UErrorCode *status);
michael@0 127 */
michael@0 128 /*
michael@0 129 * Returns the modification
michael@0 130 *
michael@0 131 * @param status Set to an error code when mkdir failed.
michael@0 132 */
michael@0 133
michael@0 134 /*
michael@0 135 * UToolMemory is used for generic, custom memory management.
michael@0 136 * It is allocated with enough space for count*size bytes starting
michael@0 137 * at array.
michael@0 138 * The array is declared with a union of large data types so
michael@0 139 * that its base address is aligned for any types.
michael@0 140 * If size is a multiple of a data type size, then such items
michael@0 141 * can be safely allocated inside the array, at offsets that
michael@0 142 * are themselves multiples of size.
michael@0 143 */
michael@0 144 struct UToolMemory;
michael@0 145 typedef struct UToolMemory UToolMemory;
michael@0 146
michael@0 147 /**
michael@0 148 * Open a UToolMemory object for allocation of initialCapacity to maxCapacity
michael@0 149 * items with size bytes each.
michael@0 150 */
michael@0 151 U_CAPI UToolMemory * U_EXPORT2
michael@0 152 utm_open(const char *name, int32_t initialCapacity, int32_t maxCapacity, int32_t size);
michael@0 153
michael@0 154 /**
michael@0 155 * Close a UToolMemory object.
michael@0 156 */
michael@0 157 U_CAPI void U_EXPORT2
michael@0 158 utm_close(UToolMemory *mem);
michael@0 159
michael@0 160 /**
michael@0 161 * Get the pointer to the beginning of the array of items.
michael@0 162 * The pointer becomes invalid after allocation of new items.
michael@0 163 */
michael@0 164 U_CAPI void * U_EXPORT2
michael@0 165 utm_getStart(UToolMemory *mem);
michael@0 166
michael@0 167 /**
michael@0 168 * Get the current number of items.
michael@0 169 */
michael@0 170 U_CAPI int32_t U_EXPORT2
michael@0 171 utm_countItems(UToolMemory *mem);
michael@0 172
michael@0 173 /**
michael@0 174 * Allocate one more item and return the pointer to its start in the array.
michael@0 175 */
michael@0 176 U_CAPI void * U_EXPORT2
michael@0 177 utm_alloc(UToolMemory *mem);
michael@0 178
michael@0 179 /**
michael@0 180 * Allocate n items and return the pointer to the start of the first one in the array.
michael@0 181 */
michael@0 182 U_CAPI void * U_EXPORT2
michael@0 183 utm_allocN(UToolMemory *mem, int32_t n);
michael@0 184
michael@0 185 #endif

mercurial