michael@0: /* michael@0: ******************************************************************************* michael@0: * michael@0: * Copyright (C) 1998-2010, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************* michael@0: * michael@0: * File ufile.h michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 12/01/98 stephen Creation. michael@0: * 03/12/99 stephen Modified for new C API. michael@0: ******************************************************************************* michael@0: */ michael@0: michael@0: #ifndef UFILE_H michael@0: #define UFILE_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/ucnv.h" michael@0: #include "unicode/utrans.h" michael@0: #include "locbund.h" michael@0: michael@0: /* The buffer size for fromUnicode calls */ michael@0: #define UFILE_CHARBUFFER_SIZE 1024 michael@0: michael@0: /* The buffer size for toUnicode calls */ michael@0: #define UFILE_UCHARBUFFER_SIZE 1024 michael@0: michael@0: /* A UFILE */ michael@0: michael@0: #if !UCONFIG_NO_TRANSLITERATION michael@0: michael@0: typedef struct { michael@0: UChar *buffer; /* Beginning of buffer */ michael@0: int32_t capacity; /* Capacity of buffer */ michael@0: int32_t pos; /* Beginning of untranslitted data */ michael@0: int32_t length; /* Length *from beginning of buffer* of untranslitted data */ michael@0: UTransliterator *translit; michael@0: } UFILETranslitBuffer; michael@0: michael@0: #endif michael@0: michael@0: typedef struct u_localized_string { michael@0: UChar *fPos; /* current pos in fUCBuffer */ michael@0: const UChar *fLimit; /* data limit in fUCBuffer */ michael@0: UChar *fBuffer; /* Place to write the string */ michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: ULocaleBundle fBundle; /* formatters */ michael@0: #endif michael@0: } u_localized_string; michael@0: michael@0: struct UFILE { michael@0: #if !UCONFIG_NO_TRANSLITERATION michael@0: UFILETranslitBuffer *fTranslit; michael@0: #endif michael@0: michael@0: FILE *fFile; /* the actual filesystem interface */ michael@0: michael@0: UConverter *fConverter; /* for codeset conversion */ michael@0: michael@0: u_localized_string str; /* struct to handle strings for number formatting */ michael@0: michael@0: UChar fUCBuffer[UFILE_UCHARBUFFER_SIZE];/* buffer used for toUnicode */ michael@0: michael@0: UBool fOwnFile; /* TRUE if fFile should be closed */ michael@0: michael@0: int32_t fFileno; /* File number. Useful to determine if it's stdin. */ michael@0: }; michael@0: michael@0: /** michael@0: * Like u_file_write but takes a flush parameter michael@0: */ michael@0: U_CFUNC int32_t U_EXPORT2 michael@0: u_file_write_flush( const UChar *chars, michael@0: int32_t count, michael@0: UFILE *f, michael@0: UBool flushIO, michael@0: UBool flushTranslit); michael@0: michael@0: /** michael@0: * Fill a UFILE's buffer with converted codepage data. michael@0: * @param f The UFILE containing the buffer to fill. michael@0: */ michael@0: void michael@0: ufile_fill_uchar_buffer(UFILE *f); michael@0: michael@0: /** michael@0: * Get one code unit and detect whether the end of file has been reached. michael@0: * @param f The UFILE containing the characters. michael@0: * @param ch The read in character michael@0: * @return TRUE if the character is valid, or FALSE when EOF has been detected michael@0: */ michael@0: U_CFUNC UBool U_EXPORT2 michael@0: ufile_getch(UFILE *f, UChar *ch); michael@0: michael@0: /** michael@0: * Get one character and detect whether the end of file has been reached. michael@0: * @param f The UFILE containing the characters. michael@0: * @param ch The read in character michael@0: * @return TRUE if the character is valid, or FALSE when EOF has been detected michael@0: */ michael@0: U_CFUNC UBool U_EXPORT2 michael@0: ufile_getch32(UFILE *f, UChar32 *ch); michael@0: michael@0: /** michael@0: * Close out the transliterator and flush any data therein. michael@0: * @param f flu michael@0: */ michael@0: void michael@0: ufile_close_translit(UFILE *f); michael@0: michael@0: /** michael@0: * Flush the buffer in the transliterator michael@0: * @param f UFile to flush michael@0: */ michael@0: void michael@0: ufile_flush_translit(UFILE *f); michael@0: michael@0: /** michael@0: * Flush the IO buffer michael@0: * @param f UFile to flush michael@0: */ michael@0: void michael@0: ufile_flush_io(UFILE *f); michael@0: michael@0: michael@0: #endif