1b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*
2b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*******************************************************************************
3b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*
450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho*   Copyright (C) 1999-2010, International Business Machines
5b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   Corporation and others.  All Rights Reserved.
6b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*
7b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*******************************************************************************
8b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   file name:  toolutil.h
9b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   encoding:   US-ASCII
10b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   tab size:   8 (not used)
11b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   indentation:4
12b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*
13b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   created on: 1999nov19
14b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   created by: Markus W. Scherer
15b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*
16b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*   This file defines utility functions for ICU tools like genccode.
17b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru*/
18b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
19b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#ifndef __TOOLUTIL_H__
20b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#define __TOOLUTIL_H__
21b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
22b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#include "unicode/utypes.h"
23b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
2450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#ifdef XP_CPLUSPLUS
2550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
2650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "unicode/errorcode.h"
2750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
2850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoU_NAMESPACE_BEGIN
2950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
3050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/**
3150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * ErrorCode subclass for use in ICU command-line tools.
3250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * The destructor calls handleFailure() which calls exit(errorCode) when isFailure().
3350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */
3450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoclass U_TOOLUTIL_API IcuToolErrorCode : public ErrorCode {
3550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehopublic:
3650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    /**
3750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     * @param loc A short string describing where the IcuToolErrorCode is used.
3850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho     */
3950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    IcuToolErrorCode(const char *loc) : location(loc) {}
4050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    virtual ~IcuToolErrorCode();
4150294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoprotected:
4250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    virtual void handleFailure() const;
4350294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoprivate:
4450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho    const char *location;
4550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho};
4650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
4750294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoU_NAMESPACE_END
4850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
4950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif
5050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
51b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*
52b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * For Windows, a path/filename may be the short (8.3) version
53b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * of the "real", long one. In this case, the short one
54b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * is abbreviated and contains a tilde etc.
55b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This function returns a pointer to the original pathname
56b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * if it is the "real" one itself, and a pointer to a static
57b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * buffer (not thread-safe) containing the long version
58b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * if the pathname is indeed abbreviated.
59b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *
60b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * On platforms other than Windows, this function always returns
61b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * the input pathname pointer.
62b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *
63b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This function is especially useful in tools that are called
64b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * by a batch file for loop, which yields short pathnames on Win9x.
65b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
66b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI const char * U_EXPORT2
67b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QuerugetLongPathname(const char *pathname);
68b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
6950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/**
70b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Find the basename at the end of a pathname, i.e., the part
71b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * after the last file separator, and return a pointer
72b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * to this part of the pathname.
73b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * If the pathname only contains a basename and no file separator,
74b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * then the pathname pointer itself is returned.
7550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho **/
76b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI const char * U_EXPORT2
77b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QuerufindBasename(const char *filename);
78b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
7950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/**
8050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * Find the directory name of a pathname, that is, everything
8150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * up to but not including the last file separator.
8250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho *
8350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * If successful, copies the directory name into the output buffer along with
8450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * a terminating NULL.
8550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho *
8650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * If there isn't a directory name in the path, it returns the current directory string ('.').
8750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @param path the full pathname to inspect.
8850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @param buffer the output buffer
8950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @param bufLen the output buffer length
9050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @param status error code- may return U_BUFFER_OVERFLOW_ERROR if bufLen is too small.
9150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @return If successful, a pointer to the output buffer. If failure or bufLen is too small, NULL.
9250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho **/
9350294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoU_CAPI const char * U_EXPORT2
9450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehofindDirname(const char *path, char *buffer, int32_t bufLen, UErrorCode* status);
9550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho
96b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*
97c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * Return the current year in the Gregorian calendar. Used for copyright generation.
98c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru */
99c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste QueruU_CAPI int32_t U_EXPORT2
100c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste QuerugetCurrentYear(void);
101c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru
102c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru/*
103b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Creates a directory with pathname.
104b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru *
105b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @param status Set to an error code when mkdir failed.
106b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
107b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void U_EXPORT2
108b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruuprv_mkdir(const char *pathname, UErrorCode *status);
109b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
110b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/**
111b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Return the modification date for the specified file or directory.
112b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Return value is undefined if there was an error.
113b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */
114b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/*U_CAPI UDate U_EXPORT2
115b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queruuprv_getModificationDate(const char *pathname, UErrorCode *status);
116b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru*/
117b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/*
118b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Returns the modification
119b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru *
120b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * @param status Set to an error code when mkdir failed.
121b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */
122b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru
123b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/*
124b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * UToolMemory is used for generic, custom memory management.
125b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * It is allocated with enough space for count*size bytes starting
126b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * at array.
127b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * The array is declared with a union of large data types so
128b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * that its base address is aligned for any types.
129b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * If size is a multiple of a data type size, then such items
130b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * can be safely allocated inside the array, at offsets that
131b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * are themselves multiples of size.
132b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
133b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustruct UToolMemory;
134b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querutypedef struct UToolMemory UToolMemory;
135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
136b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Open a UToolMemory object for allocation of initialCapacity to maxCapacity
138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * items with size bytes each.
139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI UToolMemory * U_EXPORT2
141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruutm_open(const char *name, int32_t initialCapacity, int32_t maxCapacity, int32_t size);
142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Close a UToolMemory object.
145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void U_EXPORT2
147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruutm_close(UToolMemory *mem);
148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
150b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Get the pointer to the beginning of the array of items.
151b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * The pointer becomes invalid after allocation of new items.
152b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
153b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void * U_EXPORT2
154b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruutm_getStart(UToolMemory *mem);
155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Get the current number of items.
158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI int32_t U_EXPORT2
160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruutm_countItems(UToolMemory *mem);
161b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Allocate one more item and return the pointer to its start in the array.
164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void * U_EXPORT2
166b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruutm_alloc(UToolMemory *mem);
167b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
168b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/**
169b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Allocate n items and return the pointer to the start of the first one in the array.
170b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */
171b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void * U_EXPORT2
172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruutm_allocN(UToolMemory *mem, int32_t n);
173b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru
174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif
175