michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 1998-2004, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ****************************************************************************** michael@0: * michael@0: * File uscanf.c michael@0: * michael@0: * Modification History: michael@0: * michael@0: * Date Name Description michael@0: * 12/02/98 stephen Creation. michael@0: * 03/13/99 stephen Modified for new C API. michael@0: ****************************************************************************** michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/putil.h" michael@0: #include "unicode/ustdio.h" michael@0: #include "unicode/ustring.h" michael@0: #include "uscanf.h" michael@0: #include "ufile.h" michael@0: #include "ufmt_cmn.h" michael@0: michael@0: #include "cmemory.h" michael@0: #include "cstring.h" michael@0: michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: u_fscanf(UFILE *f, michael@0: const char *patternSpecification, michael@0: ... ) michael@0: { michael@0: va_list ap; michael@0: int32_t converted; michael@0: michael@0: va_start(ap, patternSpecification); michael@0: converted = u_vfscanf(f, patternSpecification, ap); michael@0: va_end(ap); michael@0: michael@0: return converted; michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: u_fscanf_u(UFILE *f, michael@0: const UChar *patternSpecification, michael@0: ... ) michael@0: { michael@0: va_list ap; michael@0: int32_t converted; michael@0: michael@0: va_start(ap, patternSpecification); michael@0: converted = u_vfscanf_u(f, patternSpecification, ap); michael@0: va_end(ap); michael@0: michael@0: return converted; michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ michael@0: u_vfscanf(UFILE *f, michael@0: const char *patternSpecification, michael@0: va_list ap) michael@0: { michael@0: int32_t converted; michael@0: UChar *pattern; michael@0: UChar patBuffer[UFMT_DEFAULT_BUFFER_SIZE]; michael@0: int32_t size = (int32_t)uprv_strlen(patternSpecification) + 1; michael@0: michael@0: /* convert from the default codepage to Unicode */ michael@0: if (size >= MAX_UCHAR_BUFFER_SIZE(patBuffer)) { michael@0: pattern = (UChar *)uprv_malloc(size * sizeof(UChar)); michael@0: if(pattern == 0) { michael@0: return 0; michael@0: } michael@0: } michael@0: else { michael@0: pattern = patBuffer; michael@0: } michael@0: u_charsToUChars(patternSpecification, pattern, size); michael@0: michael@0: /* do the work */ michael@0: converted = u_vfscanf_u(f, pattern, ap); michael@0: michael@0: /* clean up */ michael@0: if (pattern != patBuffer) { michael@0: uprv_free(pattern); michael@0: } michael@0: michael@0: return converted; michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */ michael@0: u_vfscanf_u(UFILE *f, michael@0: const UChar *patternSpecification, michael@0: va_list ap) michael@0: { michael@0: return u_scanf_parse(f, patternSpecification, ap); michael@0: } michael@0: michael@0: #endif /* #if !UCONFIG_NO_FORMATTING */ michael@0: