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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/tools/toolutil/toolutil.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,185 @@
     1.4 +/*
     1.5 +*******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 1999-2013, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +*******************************************************************************
    1.11 +*   file name:  toolutil.h
    1.12 +*   encoding:   US-ASCII
    1.13 +*   tab size:   8 (not used)
    1.14 +*   indentation:4
    1.15 +*
    1.16 +*   created on: 1999nov19
    1.17 +*   created by: Markus W. Scherer
    1.18 +*
    1.19 +*   This file defines utility functions for ICU tools like genccode.
    1.20 +*/
    1.21 +
    1.22 +#ifndef __TOOLUTIL_H__
    1.23 +#define __TOOLUTIL_H__
    1.24 +
    1.25 +#include "unicode/utypes.h"
    1.26 +
    1.27 +
    1.28 +#ifdef __cplusplus
    1.29 +
    1.30 +#include "unicode/errorcode.h"
    1.31 +
    1.32 +U_NAMESPACE_BEGIN
    1.33 +
    1.34 +/**
    1.35 + * ErrorCode subclass for use in ICU command-line tools.
    1.36 + * The destructor calls handleFailure() which calls exit(errorCode) when isFailure().
    1.37 + */
    1.38 +class U_TOOLUTIL_API IcuToolErrorCode : public ErrorCode {
    1.39 +public:
    1.40 +    /**
    1.41 +     * @param loc A short string describing where the IcuToolErrorCode is used.
    1.42 +     */
    1.43 +    IcuToolErrorCode(const char *loc) : location(loc) {}
    1.44 +    virtual ~IcuToolErrorCode();
    1.45 +protected:
    1.46 +    virtual void handleFailure() const;
    1.47 +private:
    1.48 +    const char *location;
    1.49 +};
    1.50 +
    1.51 +U_NAMESPACE_END
    1.52 +
    1.53 +#endif
    1.54 +
    1.55 +/*
    1.56 + * For Windows, a path/filename may be the short (8.3) version
    1.57 + * of the "real", long one. In this case, the short one
    1.58 + * is abbreviated and contains a tilde etc.
    1.59 + * This function returns a pointer to the original pathname
    1.60 + * if it is the "real" one itself, and a pointer to a static
    1.61 + * buffer (not thread-safe) containing the long version
    1.62 + * if the pathname is indeed abbreviated.
    1.63 + *
    1.64 + * On platforms other than Windows, this function always returns
    1.65 + * the input pathname pointer.
    1.66 + *
    1.67 + * This function is especially useful in tools that are called
    1.68 + * by a batch file for loop, which yields short pathnames on Win9x.
    1.69 + */
    1.70 +U_CAPI const char * U_EXPORT2
    1.71 +getLongPathname(const char *pathname);
    1.72 +
    1.73 +/**
    1.74 + * Find the basename at the end of a pathname, i.e., the part
    1.75 + * after the last file separator, and return a pointer
    1.76 + * to this part of the pathname.
    1.77 + * If the pathname only contains a basename and no file separator,
    1.78 + * then the pathname pointer itself is returned.
    1.79 + **/
    1.80 +U_CAPI const char * U_EXPORT2
    1.81 +findBasename(const char *filename);
    1.82 +
    1.83 +/**
    1.84 + * Find the directory name of a pathname, that is, everything
    1.85 + * up to but not including the last file separator. 
    1.86 + *
    1.87 + * If successful, copies the directory name into the output buffer along with
    1.88 + * a terminating NULL. 
    1.89 + *
    1.90 + * If there isn't a directory name in the path, it returns an empty string.
    1.91 + * @param path the full pathname to inspect. 
    1.92 + * @param buffer the output buffer
    1.93 + * @param bufLen the output buffer length
    1.94 + * @param status error code- may return U_BUFFER_OVERFLOW_ERROR if bufLen is too small.
    1.95 + * @return If successful, a pointer to the output buffer. If failure or bufLen is too small, NULL.
    1.96 + **/
    1.97 +U_CAPI const char * U_EXPORT2
    1.98 +findDirname(const char *path, char *buffer, int32_t bufLen, UErrorCode* status);
    1.99 +
   1.100 +/*
   1.101 + * Return the current year in the Gregorian calendar. Used for copyright generation.
   1.102 + */
   1.103 +U_CAPI int32_t U_EXPORT2
   1.104 +getCurrentYear(void);
   1.105 +
   1.106 +/*
   1.107 + * Creates a directory with pathname.
   1.108 + *
   1.109 + * @param status Set to an error code when mkdir failed.
   1.110 + */
   1.111 +U_CAPI void U_EXPORT2
   1.112 +uprv_mkdir(const char *pathname, UErrorCode *status);
   1.113 +
   1.114 +#if !UCONFIG_NO_FILE_IO
   1.115 +/**
   1.116 + * Return TRUE if the named item exists
   1.117 + * @param file filename
   1.118 + * @return TRUE if named item (file, dir, etc) exists, FALSE otherwise
   1.119 + */
   1.120 +U_CAPI UBool U_EXPORT2
   1.121 +uprv_fileExists(const char *file);
   1.122 +#endif
   1.123 +
   1.124 +/**
   1.125 + * Return the modification date for the specified file or directory.
   1.126 + * Return value is undefined if there was an error.
   1.127 + */
   1.128 +/*U_CAPI UDate U_EXPORT2
   1.129 +uprv_getModificationDate(const char *pathname, UErrorCode *status);
   1.130 +*/
   1.131 +/*
   1.132 + * Returns the modification
   1.133 + *
   1.134 + * @param status Set to an error code when mkdir failed.
   1.135 + */
   1.136 +
   1.137 +/*
   1.138 + * UToolMemory is used for generic, custom memory management.
   1.139 + * It is allocated with enough space for count*size bytes starting
   1.140 + * at array.
   1.141 + * The array is declared with a union of large data types so
   1.142 + * that its base address is aligned for any types.
   1.143 + * If size is a multiple of a data type size, then such items
   1.144 + * can be safely allocated inside the array, at offsets that
   1.145 + * are themselves multiples of size.
   1.146 + */
   1.147 +struct UToolMemory;
   1.148 +typedef struct UToolMemory UToolMemory;
   1.149 +
   1.150 +/**
   1.151 + * Open a UToolMemory object for allocation of initialCapacity to maxCapacity
   1.152 + * items with size bytes each.
   1.153 + */
   1.154 +U_CAPI UToolMemory * U_EXPORT2
   1.155 +utm_open(const char *name, int32_t initialCapacity, int32_t maxCapacity, int32_t size);
   1.156 +
   1.157 +/**
   1.158 + * Close a UToolMemory object.
   1.159 + */
   1.160 +U_CAPI void U_EXPORT2
   1.161 +utm_close(UToolMemory *mem);
   1.162 +
   1.163 +/**
   1.164 + * Get the pointer to the beginning of the array of items.
   1.165 + * The pointer becomes invalid after allocation of new items.
   1.166 + */
   1.167 +U_CAPI void * U_EXPORT2
   1.168 +utm_getStart(UToolMemory *mem);
   1.169 +
   1.170 +/**
   1.171 + * Get the current number of items.
   1.172 + */
   1.173 +U_CAPI int32_t U_EXPORT2
   1.174 +utm_countItems(UToolMemory *mem);
   1.175 +
   1.176 +/**
   1.177 + * Allocate one more item and return the pointer to its start in the array.
   1.178 + */
   1.179 +U_CAPI void * U_EXPORT2
   1.180 +utm_alloc(UToolMemory *mem);
   1.181 +
   1.182 +/**
   1.183 + * Allocate n items and return the pointer to the start of the first one in the array.
   1.184 + */
   1.185 +U_CAPI void * U_EXPORT2
   1.186 +utm_allocN(UToolMemory *mem, int32_t n);
   1.187 +
   1.188 +#endif

mercurial