|
ICU 73.2
73.2
|
00001 // © 2016 and later: Unicode, Inc. and others. 00002 // License & terms of use: http://www.unicode.org/copyright.html 00003 /* 00004 ****************************************************************************** 00005 * 00006 * Copyright (C) 1998-2015, International Business Machines 00007 * Corporation and others. All Rights Reserved. 00008 * 00009 ****************************************************************************** 00010 * 00011 * File ustdio.h 00012 * 00013 * Modification History: 00014 * 00015 * Date Name Description 00016 * 10/16/98 stephen Creation. 00017 * 11/06/98 stephen Modified per code review. 00018 * 03/12/99 stephen Modified for new C API. 00019 * 07/19/99 stephen Minor doc update. 00020 * 02/01/01 george Added sprintf & sscanf with all of its variants 00021 ****************************************************************************** 00022 */ 00023 00024 #ifndef USTDIO_H 00025 #define USTDIO_H 00026 00027 #include <stdio.h> 00028 #include <stdarg.h> 00029 00030 #include "unicode/utypes.h" 00031 #include "unicode/ucnv.h" 00032 #include "unicode/utrans.h" 00033 #include "unicode/unum.h" 00034 00035 #if U_SHOW_CPLUSPLUS_API 00036 #include "unicode/localpointer.h" 00037 #endif // U_SHOW_CPLUSPLUS_API 00038 00039 #if !UCONFIG_NO_CONVERSION 00040 00041 /* 00042 TODO 00043 The following is a small list as to what is currently wrong/suggestions for 00044 ustdio. 00045 00046 * Make sure that * in the scanf format specification works for all formats. 00047 * Each UFILE takes up at least 2KB. 00048 Look into adding setvbuf() for configurable buffers. 00049 * This library does buffering. The OS should do this for us already. Check on 00050 this, and remove it from this library, if this is the case. Double buffering 00051 wastes a lot of time and space. 00052 * Test stdin and stdout with the u_f* functions 00053 * Testing should be done for reading and writing multi-byte encodings, 00054 and make sure that a character that is contained across buffer boundaries 00055 works even for incomplete characters. 00056 * Make sure that the last character is flushed when the file/string is closed. 00057 * snprintf should follow the C99 standard for the return value, which is 00058 return the number of characters (excluding the trailing '\0') 00059 which would have been written to the destination string regardless 00060 of available space. This is like pre-flighting. 00061 * Everything that uses %s should do what operator>> does for UnicodeString. 00062 It should convert one byte at a time, and once a character is 00063 converted then check to see if it's whitespace or in the scanset. 00064 If it's whitespace or in the scanset, put all the bytes back (do nothing 00065 for sprintf/sscanf). 00066 * If bad string data is encountered, make sure that the function fails 00067 without memory leaks and the unconvertable characters are valid 00068 substitution or are escaped characters. 00069 * u_fungetc() can't unget a character when it's at the beginning of the 00070 internal conversion buffer. For example, read the buffer size # of 00071 characters, and then ungetc to get the previous character that was 00072 at the end of the last buffer. 00073 * u_fflush() and u_fclose should return an int32_t like C99 functions. 00074 0 is returned if the operation was successful and EOF otherwise. 00075 * u_fsettransliterator does not support U_READ side of transliteration. 00076 * The format specifier should limit the size of a format or honor it in 00077 order to prevent buffer overruns. (e.g. %256.256d). 00078 * u_fread and u_fwrite don't exist. They're needed for reading and writing 00079 data structures without any conversion. 00080 * u_file_read and u_file_write are used for writing strings. u_fgets and 00081 u_fputs or u_fread and u_fwrite should be used to do this. 00082 * The width parameter for all scanf formats, including scanset, needs 00083 better testing. This prevents buffer overflows. 00084 * Figure out what is suppose to happen when a codepage is changed midstream. 00085 Maybe a flush or a rewind are good enough. 00086 * Make sure that a UFile opened with "rw" can be used after using 00087 u_fflush with a u_frewind. 00088 * scanf(%i) should detect what type of number to use. 00089 * Add more testing of the alternate format, %# 00090 * Look at newline handling of fputs/puts 00091 * Think more about codeunit/codepoint error handling/support in %S,%s,%C,%c,%[] 00092 * Complete the file documentation with proper doxygen formatting. 00093 See http://oss.software.ibm.com/pipermail/icu/2003-July/005647.html 00094 */ 00095 00212 #define U_EOF 0xFFFF 00213 00215 typedef struct UFILE UFILE; 00216 00222 typedef enum { 00223 U_READ = 1, 00224 U_WRITE = 2, 00225 U_READWRITE =3 /* == (U_READ | U_WRITE) */ 00226 } UFileDirection; 00227 00245 U_CAPI UFILE* U_EXPORT2 00246 u_fopen(const char *filename, 00247 const char *perm, 00248 const char *locale, 00249 const char *codepage); 00250 00268 U_CAPI UFILE* U_EXPORT2 00269 u_fopen_u(const UChar *filename, 00270 const char *perm, 00271 const char *locale, 00272 const char *codepage); 00273 00290 U_CAPI UFILE* U_EXPORT2 00291 u_finit(FILE *f, 00292 const char *locale, 00293 const char *codepage); 00294 00311 U_CAPI UFILE* U_EXPORT2 00312 u_fadopt(FILE *f, 00313 const char *locale, 00314 const char *codepage); 00315 00330 U_CAPI UFILE* U_EXPORT2 00331 u_fstropen(UChar *stringBuf, 00332 int32_t capacity, 00333 const char *locale); 00334 00341 U_CAPI void U_EXPORT2 00342 u_fclose(UFILE *file); 00343 00344 #if U_SHOW_CPLUSPLUS_API 00345 00346 U_NAMESPACE_BEGIN 00347 00357 U_DEFINE_LOCAL_OPEN_POINTER(LocalUFILEPointer, UFILE, u_fclose); 00358 00359 U_NAMESPACE_END 00360 00361 #endif 00362 00371 U_CAPI UBool U_EXPORT2 00372 u_feof(UFILE *f); 00373 00384 U_CAPI void U_EXPORT2 00385 u_fflush(UFILE *file); 00386 00392 U_CAPI void 00393 u_frewind(UFILE *file); 00394 00401 U_CAPI FILE* U_EXPORT2 00402 u_fgetfile(UFILE *f); 00403 00404 #if !UCONFIG_NO_FORMATTING 00405 00414 U_CAPI const char* U_EXPORT2 00415 u_fgetlocale(UFILE *file); 00416 00425 U_CAPI int32_t U_EXPORT2 00426 u_fsetlocale(UFILE *file, 00427 const char *locale); 00428 00429 #endif 00430 00440 U_CAPI const char* U_EXPORT2 00441 u_fgetcodepage(UFILE *file); 00442 00458 U_CAPI int32_t U_EXPORT2 00459 u_fsetcodepage(const char *codepage, 00460 UFILE *file); 00461 00462 00469 U_CAPI UConverter* U_EXPORT2 u_fgetConverter(UFILE *f); 00470 00471 #if !UCONFIG_NO_FORMATTING 00472 00478 U_CAPI const UNumberFormat* U_EXPORT2 u_fgetNumberFormat(UFILE *f); 00479 00480 /* Output functions */ 00481 00489 U_CAPI int32_t U_EXPORT2 00490 u_printf(const char *patternSpecification, 00491 ... ); 00492 00501 U_CAPI int32_t U_EXPORT2 00502 u_fprintf(UFILE *f, 00503 const char *patternSpecification, 00504 ... ); 00505 00518 U_CAPI int32_t U_EXPORT2 00519 u_vfprintf(UFILE *f, 00520 const char *patternSpecification, 00521 va_list ap); 00522 00530 U_CAPI int32_t U_EXPORT2 00531 u_printf_u(const UChar *patternSpecification, 00532 ... ); 00533 00539 U_CAPI UFILE * U_EXPORT2 00540 u_get_stdout(void); 00541 00550 U_CAPI int32_t U_EXPORT2 00551 u_fprintf_u(UFILE *f, 00552 const UChar *patternSpecification, 00553 ... ); 00554 00567 U_CAPI int32_t U_EXPORT2 00568 u_vfprintf_u(UFILE *f, 00569 const UChar *patternSpecification, 00570 va_list ap); 00571 #endif 00572 00582 U_CAPI int32_t U_EXPORT2 00583 u_fputs(const UChar *s, 00584 UFILE *f); 00585 00593 U_CAPI UChar32 U_EXPORT2 00594 u_fputc(UChar32 uc, 00595 UFILE *f); 00596 00608 U_CAPI int32_t U_EXPORT2 00609 u_file_write(const UChar *ustring, 00610 int32_t count, 00611 UFILE *f); 00612 00613 00614 /* Input functions */ 00615 #if !UCONFIG_NO_FORMATTING 00616 00626 U_CAPI int32_t U_EXPORT2 00627 u_fscanf(UFILE *f, 00628 const char *patternSpecification, 00629 ... ); 00630 00644 U_CAPI int32_t U_EXPORT2 00645 u_vfscanf(UFILE *f, 00646 const char *patternSpecification, 00647 va_list ap); 00648 00658 U_CAPI int32_t U_EXPORT2 00659 u_fscanf_u(UFILE *f, 00660 const UChar *patternSpecification, 00661 ... ); 00662 00676 U_CAPI int32_t U_EXPORT2 00677 u_vfscanf_u(UFILE *f, 00678 const UChar *patternSpecification, 00679 va_list ap); 00680 #endif 00681 00694 U_CAPI UChar* U_EXPORT2 00695 u_fgets(UChar *s, 00696 int32_t n, 00697 UFILE *f); 00698 00708 U_CAPI UChar U_EXPORT2 00709 u_fgetc(UFILE *f); 00710 00721 U_CAPI UChar32 U_EXPORT2 00722 u_fgetcx(UFILE *f); 00723 00735 U_CAPI UChar32 U_EXPORT2 00736 u_fungetc(UChar32 c, 00737 UFILE *f); 00738 00749 U_CAPI int32_t U_EXPORT2 00750 u_file_read(UChar *chars, 00751 int32_t count, 00752 UFILE *f); 00753 00754 #if !UCONFIG_NO_TRANSLITERATION 00755 00773 U_CAPI UTransliterator* U_EXPORT2 00774 u_fsettransliterator(UFILE *file, UFileDirection direction, 00775 UTransliterator *adopt, UErrorCode *status); 00776 00777 #endif 00778 00779 00780 /* Output string functions */ 00781 #if !UCONFIG_NO_FORMATTING 00782 00783 00794 U_CAPI int32_t U_EXPORT2 00795 u_sprintf(UChar *buffer, 00796 const char *patternSpecification, 00797 ... ); 00798 00816 U_CAPI int32_t U_EXPORT2 00817 u_snprintf(UChar *buffer, 00818 int32_t count, 00819 const char *patternSpecification, 00820 ... ); 00821 00835 U_CAPI int32_t U_EXPORT2 00836 u_vsprintf(UChar *buffer, 00837 const char *patternSpecification, 00838 va_list ap); 00839 00860 U_CAPI int32_t U_EXPORT2 00861 u_vsnprintf(UChar *buffer, 00862 int32_t count, 00863 const char *patternSpecification, 00864 va_list ap); 00865 00875 U_CAPI int32_t U_EXPORT2 00876 u_sprintf_u(UChar *buffer, 00877 const UChar *patternSpecification, 00878 ... ); 00879 00896 U_CAPI int32_t U_EXPORT2 00897 u_snprintf_u(UChar *buffer, 00898 int32_t count, 00899 const UChar *patternSpecification, 00900 ... ); 00901 00915 U_CAPI int32_t U_EXPORT2 00916 u_vsprintf_u(UChar *buffer, 00917 const UChar *patternSpecification, 00918 va_list ap); 00919 00940 U_CAPI int32_t U_EXPORT2 00941 u_vsnprintf_u(UChar *buffer, 00942 int32_t count, 00943 const UChar *patternSpecification, 00944 va_list ap); 00945 00946 /* Input string functions */ 00947 00958 U_CAPI int32_t U_EXPORT2 00959 u_sscanf(const UChar *buffer, 00960 const char *patternSpecification, 00961 ... ); 00962 00977 U_CAPI int32_t U_EXPORT2 00978 u_vsscanf(const UChar *buffer, 00979 const char *patternSpecification, 00980 va_list ap); 00981 00992 U_CAPI int32_t U_EXPORT2 00993 u_sscanf_u(const UChar *buffer, 00994 const UChar *patternSpecification, 00995 ... ); 00996 01011 U_CAPI int32_t U_EXPORT2 01012 u_vsscanf_u(const UChar *buffer, 01013 const UChar *patternSpecification, 01014 va_list ap); 01015 01016 01017 #endif 01018 #endif 01019 #endif 01020 01021
1.7.6.1