1 /* 2 ****************************************************************************** 3 * 4 * Copyright (C) 1998-2004, International Business Machines 5 * Corporation and others. All Rights Reserved. 6 * 7 ****************************************************************************** 8 * 9 * File uscanf.c 10 * 11 * Modification History: 12 * 13 * Date Name Description 14 * 12/02/98 stephen Creation. 15 * 03/13/99 stephen Modified for new C API. 16 ****************************************************************************** 17 */ 18 19 #include "unicode/utypes.h" 20 21 #if !UCONFIG_NO_FORMATTING 22 23 #include "unicode/putil.h" 24 #include "unicode/ustdio.h" 25 #include "unicode/ustring.h" 26 #include "uscanf.h" 27 #include "ufile.h" 28 #include "ufmt_cmn.h" 29 30 #include "cmemory.h" 31 #include "cstring.h" 32 33 34 U_CAPI int32_t U_EXPORT2 35 u_fscanf(UFILE *f, 36 const char *patternSpecification, 37 ... ) 38 { 39 va_list ap; 40 int32_t converted; 41 42 va_start(ap, patternSpecification); 43 converted = u_vfscanf(f, patternSpecification, ap); 44 va_end(ap); 45 46 return converted; 47 } 48 49 U_CAPI int32_t U_EXPORT2 50 u_fscanf_u(UFILE *f, 51 const UChar *patternSpecification, 52 ... ) 53 { 54 va_list ap; 55 int32_t converted; 56 57 va_start(ap, patternSpecification); 58 converted = u_vfscanf_u(f, patternSpecification, ap); 59 va_end(ap); 60 61 return converted; 62 } 63 64 U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ 65 u_vfscanf(UFILE *f, 66 const char *patternSpecification, 67 va_list ap) 68 { 69 int32_t converted; 70 UChar *pattern; 71 UChar patBuffer[UFMT_DEFAULT_BUFFER_SIZE]; 72 int32_t size = (int32_t)uprv_strlen(patternSpecification) + 1; 73 74 /* convert from the default codepage to Unicode */ 75 if (size >= MAX_UCHAR_BUFFER_SIZE(patBuffer)) { 76 pattern = (UChar *)uprv_malloc(size * sizeof(UChar)); 77 if(pattern == 0) { 78 return 0; 79 } 80 } 81 else { 82 pattern = patBuffer; 83 } 84 u_charsToUChars(patternSpecification, pattern, size); 85 86 /* do the work */ 87 converted = u_vfscanf_u(f, pattern, ap); 88 89 /* clean up */ 90 if (pattern != patBuffer) { 91 uprv_free(pattern); 92 } 93 94 return converted; 95 } 96 97 U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ 98 u_vfscanf_u(UFILE *f, 99 const UChar *patternSpecification, 100 va_list ap) 101 { 102 return u_scanf_parse(f, patternSpecification, ap); 103 } 104 105 #endif /* #if !UCONFIG_NO_FORMATTING */ 106 107