1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************************* 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 427f654740f2a26ad62a5c155af9199af9e69b889claireho * Copyright (C) 1998-2010, International Business Machines 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Corporation and others. All Rights Reserved. 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************************* 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * File ufile.h 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Modification History: 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Date Name Description 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 12/01/98 stephen Creation. 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * 03/12/99 stephen Modified for new C API. 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ******************************************************************************* 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef UFILE_H 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UFILE_H 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h" 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucnv.h" 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utrans.h" 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "locbund.h" 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* The buffer size for fromUnicode calls */ 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UFILE_CHARBUFFER_SIZE 1024 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* The buffer size for toUnicode calls */ 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UFILE_UCHARBUFFER_SIZE 1024 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* A UFILE */ 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_TRANSLITERATION 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef struct { 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *buffer; /* Beginning of buffer */ 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t capacity; /* Capacity of buffer */ 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t pos; /* Beginning of untranslitted data */ 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t length; /* Length *from beginning of buffer* of untranslitted data */ 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UTransliterator *translit; 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} UFILETranslitBuffer; 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef struct u_localized_string { 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *fPos; /* current pos in fUCBuffer */ 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru const UChar *fLimit; /* data limit in fUCBuffer */ 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar *fBuffer; /* Place to write the string */ 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ULocaleBundle fBundle; /* formatters */ 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} u_localized_string; 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustruct UFILE { 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_TRANSLITERATION 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UFILETranslitBuffer *fTranslit; 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru FILE *fFile; /* the actual filesystem interface */ 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UConverter *fConverter; /* for codeset conversion */ 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru u_localized_string str; /* struct to handle strings for number formatting */ 67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UChar fUCBuffer[UFILE_UCHARBUFFER_SIZE];/* buffer used for toUnicode */ 69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool fOwnFile; /* TRUE if fFile should be closed */ 71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t fFileno; /* File number. Useful to determine if it's stdin. */ 73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru}; 74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Like u_file_write but takes a flush parameter 77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CFUNC int32_t U_EXPORT2 79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruu_file_write_flush( const UChar *chars, 80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru int32_t count, 81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UFILE *f, 82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool flushIO, 83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru UBool flushTranslit); 84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Fill a UFILE's buffer with converted codepage data. 87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param f The UFILE containing the buffer to fill. 88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid 90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruufile_fill_uchar_buffer(UFILE *f); 91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Get one code unit and detect whether the end of file has been reached. 94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param f The UFILE containing the characters. 95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param ch The read in character 96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return TRUE if the character is valid, or FALSE when EOF has been detected 97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CFUNC UBool U_EXPORT2 99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruufile_getch(UFILE *f, UChar *ch); 100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Get one character and detect whether the end of file has been reached. 103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param f The UFILE containing the characters. 104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param ch The read in character 105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return TRUE if the character is valid, or FALSE when EOF has been detected 106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CFUNC UBool U_EXPORT2 108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruufile_getch32(UFILE *f, UChar32 *ch); 109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Close out the transliterator and flush any data therein. 112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param f flu 113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid 115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruufile_close_translit(UFILE *f); 116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/** 118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Flush the buffer in the transliterator 119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param f UFile to flush 120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */ 121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid 122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruufile_flush_translit(UFILE *f); 123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 12427f654740f2a26ad62a5c155af9199af9e69b889claireho/** 12527f654740f2a26ad62a5c155af9199af9e69b889claireho * Flush the IO buffer 12627f654740f2a26ad62a5c155af9199af9e69b889claireho * @param f UFile to flush 12727f654740f2a26ad62a5c155af9199af9e69b889claireho */ 12827f654740f2a26ad62a5c155af9199af9e69b889clairehovoid 12927f654740f2a26ad62a5c155af9199af9e69b889clairehoufile_flush_io(UFILE *f); 13027f654740f2a26ad62a5c155af9199af9e69b889claireho 131ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 132ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif 133