2 *******************************************************************************
4 * Copyright (C) 1999-2010, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
8 * file name: toolutil.h
10 * tab size: 8 (not used)
13 * created on: 1999nov19
14 * created by: Markus W. Scherer
16 * This file defines utility functions for ICU tools like genccode.
19 #ifndef __TOOLUTIL_H__
20 #define __TOOLUTIL_H__
22 #include "unicode/utypes.h"
26 #include "unicode/errorcode.h"
31 * ErrorCode subclass for use in ICU command-line tools.
32 * The destructor calls handleFailure() which calls exit(errorCode) when isFailure().
34 class U_TOOLUTIL_API IcuToolErrorCode : public ErrorCode {
37 * @param loc A short string describing where the IcuToolErrorCode is used.
39 IcuToolErrorCode(const char *loc) : location(loc) {}
40 virtual ~IcuToolErrorCode();
42 virtual void handleFailure() const;
52 * For Windows, a path/filename may be the short (8.3) version
53 * of the "real", long one. In this case, the short one
54 * is abbreviated and contains a tilde etc.
55 * This function returns a pointer to the original pathname
56 * if it is the "real" one itself, and a pointer to a static
57 * buffer (not thread-safe) containing the long version
58 * if the pathname is indeed abbreviated.
60 * On platforms other than Windows, this function always returns
61 * the input pathname pointer.
63 * This function is especially useful in tools that are called
64 * by a batch file for loop, which yields short pathnames on Win9x.
66 U_CAPI const char * U_EXPORT2
67 getLongPathname(const char *pathname);
70 * Find the basename at the end of a pathname, i.e., the part
71 * after the last file separator, and return a pointer
72 * to this part of the pathname.
73 * If the pathname only contains a basename and no file separator,
74 * then the pathname pointer itself is returned.
76 U_CAPI const char * U_EXPORT2
77 findBasename(const char *filename);
80 * Find the directory name of a pathname, that is, everything
81 * up to but not including the last file separator.
83 * If successful, copies the directory name into the output buffer along with
86 * If there isn't a directory name in the path, it returns the current directory string ('.').
87 * @param path the full pathname to inspect.
88 * @param buffer the output buffer
89 * @param bufLen the output buffer length
90 * @param status error code- may return U_BUFFER_OVERFLOW_ERROR if bufLen is too small.
91 * @return If successful, a pointer to the output buffer. If failure or bufLen is too small, NULL.
93 U_CAPI const char * U_EXPORT2
94 findDirname(const char *path, char *buffer, int32_t bufLen, UErrorCode* status);
97 * Return the current year in the Gregorian calendar. Used for copyright generation.
99 U_CAPI int32_t U_EXPORT2
100 getCurrentYear(void);
103 * Creates a directory with pathname.
105 * @param status Set to an error code when mkdir failed.
107 U_CAPI void U_EXPORT2
108 uprv_mkdir(const char *pathname, UErrorCode *status);
111 * Return the modification date for the specified file or directory.
112 * Return value is undefined if there was an error.
114 /*U_CAPI UDate U_EXPORT2
115 uprv_getModificationDate(const char *pathname, UErrorCode *status);
118 * Returns the modification
120 * @param status Set to an error code when mkdir failed.
124 * UToolMemory is used for generic, custom memory management.
125 * It is allocated with enough space for count*size bytes starting
127 * The array is declared with a union of large data types so
128 * that its base address is aligned for any types.
129 * If size is a multiple of a data type size, then such items
130 * can be safely allocated inside the array, at offsets that
131 * are themselves multiples of size.
134 typedef struct UToolMemory UToolMemory;
137 * Open a UToolMemory object for allocation of initialCapacity to maxCapacity
138 * items with size bytes each.
140 U_CAPI UToolMemory * U_EXPORT2
141 utm_open(const char *name, int32_t initialCapacity, int32_t maxCapacity, int32_t size);
144 * Close a UToolMemory object.
146 U_CAPI void U_EXPORT2
147 utm_close(UToolMemory *mem);
150 * Get the pointer to the beginning of the array of items.
151 * The pointer becomes invalid after allocation of new items.
153 U_CAPI void * U_EXPORT2
154 utm_getStart(UToolMemory *mem);
157 * Get the current number of items.
159 U_CAPI int32_t U_EXPORT2
160 utm_countItems(UToolMemory *mem);
163 * Allocate one more item and return the pointer to its start in the array.
165 U_CAPI void * U_EXPORT2
166 utm_alloc(UToolMemory *mem);
169 * Allocate n items and return the pointer to the start of the first one in the array.
171 U_CAPI void * U_EXPORT2
172 utm_allocN(UToolMemory *mem, int32_t n);