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