]>
Commit | Line | Data |
---|---|---|
f3c0d7a5 A |
1 | // © 2016 and later: Unicode, Inc. and others. |
2 | // License & terms of use: http://www.unicode.org/copyright.html | |
374ca955 | 3 | /* |
46f4442e A |
4 | ******************************************************************************* |
5 | * | |
b331163b | 6 | * Copyright (C) 1998-2014, International Business Machines |
46f4442e A |
7 | * Corporation and others. All Rights Reserved. |
8 | * | |
9 | ******************************************************************************* | |
10 | * | |
11 | * File ufile.h | |
12 | * | |
13 | * Modification History: | |
14 | * | |
15 | * Date Name Description | |
16 | * 12/01/98 stephen Creation. | |
17 | * 03/12/99 stephen Modified for new C API. | |
18 | ******************************************************************************* | |
19 | */ | |
374ca955 A |
20 | |
21 | #ifndef UFILE_H | |
22 | #define UFILE_H | |
23 | ||
24 | #include "unicode/utypes.h" | |
b331163b A |
25 | |
26 | #if !UCONFIG_NO_CONVERSION | |
27 | ||
f3c0d7a5 A |
28 | #include <stdio.h> |
29 | ||
374ca955 A |
30 | #include "unicode/ucnv.h" |
31 | #include "unicode/utrans.h" | |
32 | #include "locbund.h" | |
33 | ||
34 | /* The buffer size for fromUnicode calls */ | |
35 | #define UFILE_CHARBUFFER_SIZE 1024 | |
36 | ||
37 | /* The buffer size for toUnicode calls */ | |
38 | #define UFILE_UCHARBUFFER_SIZE 1024 | |
39 | ||
40 | /* A UFILE */ | |
41 | ||
42 | #if !UCONFIG_NO_TRANSLITERATION | |
43 | ||
44 | typedef struct { | |
45 | UChar *buffer; /* Beginning of buffer */ | |
46 | int32_t capacity; /* Capacity of buffer */ | |
47 | int32_t pos; /* Beginning of untranslitted data */ | |
48 | int32_t length; /* Length *from beginning of buffer* of untranslitted data */ | |
49 | UTransliterator *translit; | |
50 | } UFILETranslitBuffer; | |
51 | ||
52 | #endif | |
53 | ||
54 | typedef struct u_localized_string { | |
55 | UChar *fPos; /* current pos in fUCBuffer */ | |
56 | const UChar *fLimit; /* data limit in fUCBuffer */ | |
57 | UChar *fBuffer; /* Place to write the string */ | |
58 | ||
59 | #if !UCONFIG_NO_FORMATTING | |
60 | ULocaleBundle fBundle; /* formatters */ | |
61 | #endif | |
62 | } u_localized_string; | |
63 | ||
64 | struct UFILE { | |
65 | #if !UCONFIG_NO_TRANSLITERATION | |
66 | UFILETranslitBuffer *fTranslit; | |
67 | #endif | |
68 | ||
69 | FILE *fFile; /* the actual filesystem interface */ | |
70 | ||
71 | UConverter *fConverter; /* for codeset conversion */ | |
72 | ||
73 | u_localized_string str; /* struct to handle strings for number formatting */ | |
74 | ||
75 | UChar fUCBuffer[UFILE_UCHARBUFFER_SIZE];/* buffer used for toUnicode */ | |
76 | ||
77 | UBool fOwnFile; /* TRUE if fFile should be closed */ | |
78 | ||
79 | int32_t fFileno; /* File number. Useful to determine if it's stdin. */ | |
80 | }; | |
81 | ||
82 | /** | |
83 | * Like u_file_write but takes a flush parameter | |
84 | */ | |
46f4442e | 85 | U_CFUNC int32_t U_EXPORT2 |
73c04bcf A |
86 | u_file_write_flush( const UChar *chars, |
87 | int32_t count, | |
88 | UFILE *f, | |
89 | UBool flushIO, | |
90 | UBool flushTranslit); | |
374ca955 A |
91 | |
92 | /** | |
93 | * Fill a UFILE's buffer with converted codepage data. | |
94 | * @param f The UFILE containing the buffer to fill. | |
95 | */ | |
96 | void | |
97 | ufile_fill_uchar_buffer(UFILE *f); | |
98 | ||
99 | /** | |
100 | * Get one code unit and detect whether the end of file has been reached. | |
101 | * @param f The UFILE containing the characters. | |
102 | * @param ch The read in character | |
103 | * @return TRUE if the character is valid, or FALSE when EOF has been detected | |
104 | */ | |
105 | U_CFUNC UBool U_EXPORT2 | |
106 | ufile_getch(UFILE *f, UChar *ch); | |
107 | ||
108 | /** | |
109 | * Get one character and detect whether the end of file has been reached. | |
110 | * @param f The UFILE containing the characters. | |
111 | * @param ch The read in character | |
112 | * @return TRUE if the character is valid, or FALSE when EOF has been detected | |
113 | */ | |
114 | U_CFUNC UBool U_EXPORT2 | |
115 | ufile_getch32(UFILE *f, UChar32 *ch); | |
116 | ||
117 | /** | |
118 | * Close out the transliterator and flush any data therein. | |
119 | * @param f flu | |
120 | */ | |
121 | void | |
122 | ufile_close_translit(UFILE *f); | |
123 | ||
124 | /** | |
125 | * Flush the buffer in the transliterator | |
126 | * @param f UFile to flush | |
127 | */ | |
128 | void | |
129 | ufile_flush_translit(UFILE *f); | |
130 | ||
729e4ab9 A |
131 | /** |
132 | * Flush the IO buffer | |
133 | * @param f UFile to flush | |
134 | */ | |
135 | void | |
136 | ufile_flush_io(UFILE *f); | |
137 | ||
374ca955 A |
138 | |
139 | #endif | |
b331163b | 140 | #endif |