1b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 2b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru******************************************************************************* 3b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru* 459d709d503bab6e2b61931737e662dd293b40578ccornelius* Copyright (C) 1999-2013, 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 2483a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius 2583a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius#ifdef __cplusplus 2650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 2750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#include "unicode/errorcode.h" 2850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 2950294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoU_NAMESPACE_BEGIN 3050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 3150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/** 3250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * ErrorCode subclass for use in ICU command-line tools. 3350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * The destructor calls handleFailure() which calls exit(errorCode) when isFailure(). 3450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 3550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoclass U_TOOLUTIL_API IcuToolErrorCode : public ErrorCode { 3650294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehopublic: 3750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho /** 3850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @param loc A short string describing where the IcuToolErrorCode is used. 3950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho */ 4050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho IcuToolErrorCode(const char *loc) : location(loc) {} 4150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho virtual ~IcuToolErrorCode(); 4250294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoprotected: 4350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho virtual void handleFailure() const; 4450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoprivate: 4550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho const char *location; 4650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho}; 4750294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 4850294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoU_NAMESPACE_END 4950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 5050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho#endif 5150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 52b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 53b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * For Windows, a path/filename may be the short (8.3) version 54b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * of the "real", long one. In this case, the short one 55b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * is abbreviated and contains a tilde etc. 56b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This function returns a pointer to the original pathname 57b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * if it is the "real" one itself, and a pointer to a static 58b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * buffer (not thread-safe) containing the long version 59b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * if the pathname is indeed abbreviated. 60b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 61b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * On platforms other than Windows, this function always returns 62b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * the input pathname pointer. 63b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 64b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * This function is especially useful in tools that are called 65b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * by a batch file for loop, which yields short pathnames on Win9x. 66b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 67b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI const char * U_EXPORT2 68b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QuerugetLongPathname(const char *pathname); 69b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 7050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/** 71b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Find the basename at the end of a pathname, i.e., the part 72b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * after the last file separator, and return a pointer 73b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * to this part of the pathname. 74b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * If the pathname only contains a basename and no file separator, 75b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * then the pathname pointer itself is returned. 7650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho **/ 77b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI const char * U_EXPORT2 78b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QuerufindBasename(const char *filename); 79b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 8050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho/** 8150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * Find the directory name of a pathname, that is, everything 8250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * up to but not including the last file separator. 8350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * 8450294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * If successful, copies the directory name into the output buffer along with 8550294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * a terminating NULL. 8650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * 8783a171d1a62abf406f7f44ae671823d5ec20db7dCraig Cornelius * If there isn't a directory name in the path, it returns an empty string. 8850294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @param path the full pathname to inspect. 8950294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @param buffer the output buffer 9050294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @param bufLen the output buffer length 9150294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @param status error code- may return U_BUFFER_OVERFLOW_ERROR if bufLen is too small. 9250294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho * @return If successful, a pointer to the output buffer. If failure or bufLen is too small, NULL. 9350294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho **/ 9450294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehoU_CAPI const char * U_EXPORT2 9550294ead5e5d23f5bbfed76e00e6b510bd41eee1clairehofindDirname(const char *path, char *buffer, int32_t bufLen, UErrorCode* status); 9650294ead5e5d23f5bbfed76e00e6b510bd41eee1claireho 97b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 98c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru * Return the current year in the Gregorian calendar. Used for copyright generation. 99c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru */ 100c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste QueruU_CAPI int32_t U_EXPORT2 101c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste QuerugetCurrentYear(void); 102c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru 103c69afcec261fc345fda8daf46f0ea6b4351dc777Jean-Baptiste Queru/* 104b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Creates a directory with pathname. 105b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * 106b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * @param status Set to an error code when mkdir failed. 107b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 108b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void U_EXPORT2 109b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruuprv_mkdir(const char *pathname, UErrorCode *status); 110b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 11159d709d503bab6e2b61931737e662dd293b40578ccornelius#if !UCONFIG_NO_FILE_IO 11259d709d503bab6e2b61931737e662dd293b40578ccornelius/** 11359d709d503bab6e2b61931737e662dd293b40578ccornelius * Return TRUE if the named item exists 11459d709d503bab6e2b61931737e662dd293b40578ccornelius * @param file filename 11559d709d503bab6e2b61931737e662dd293b40578ccornelius * @return TRUE if named item (file, dir, etc) exists, FALSE otherwise 11659d709d503bab6e2b61931737e662dd293b40578ccornelius */ 11759d709d503bab6e2b61931737e662dd293b40578ccorneliusU_CAPI UBool U_EXPORT2 11859d709d503bab6e2b61931737e662dd293b40578ccorneliusuprv_fileExists(const char *file); 11959d709d503bab6e2b61931737e662dd293b40578ccornelius#endif 12059d709d503bab6e2b61931737e662dd293b40578ccornelius 121b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/** 122b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Return the modification date for the specified file or directory. 123b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Return value is undefined if there was an error. 124b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 125b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/*U_CAPI UDate U_EXPORT2 126b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queruuprv_getModificationDate(const char *pathname, UErrorCode *status); 127b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru*/ 128b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru/* 129b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * Returns the modification 130b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * 131b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru * @param status Set to an error code when mkdir failed. 132b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru */ 133b0ac937921a2c196d8b9da665135bf6ba01a1ccfJean-Baptiste Queru 134b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/* 135b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * UToolMemory is used for generic, custom memory management. 136b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * It is allocated with enough space for count*size bytes starting 137b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * at array. 138b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * The array is declared with a union of large data types so 139b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * that its base address is aligned for any types. 140b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * If size is a multiple of a data type size, then such items 141b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * can be safely allocated inside the array, at offsets that 142b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * are themselves multiples of size. 143b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 144b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querustruct UToolMemory; 145b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Querutypedef struct UToolMemory UToolMemory; 146b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 147b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 148b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Open a UToolMemory object for allocation of initialCapacity to maxCapacity 149b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * items with size bytes each. 150b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 151b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI UToolMemory * U_EXPORT2 152b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruutm_open(const char *name, int32_t initialCapacity, int32_t maxCapacity, int32_t size); 153b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 154b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 155b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Close a UToolMemory object. 156b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 157b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void U_EXPORT2 158b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruutm_close(UToolMemory *mem); 159b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 160b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 161b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Get the pointer to the beginning of the array of items. 162b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * The pointer becomes invalid after allocation of new items. 163b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 164b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void * U_EXPORT2 165b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruutm_getStart(UToolMemory *mem); 166b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 167b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 168b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Get the current number of items. 169b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 170b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI int32_t U_EXPORT2 171b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruutm_countItems(UToolMemory *mem); 172b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 173b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 174b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Allocate one more item and return the pointer to its start in the array. 175b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 176b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void * U_EXPORT2 177b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruutm_alloc(UToolMemory *mem); 178b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 179b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru/** 180b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru * Allocate n items and return the pointer to the start of the first one in the array. 181b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru */ 182b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste QueruU_CAPI void * U_EXPORT2 183b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queruutm_allocN(UToolMemory *mem, int32_t n); 184b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru 185b13da9df870a61b11249bf741347908dbea0edd8Jean-Baptiste Queru#endif 186