ufile.h 3.6 KB

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