1999-08-16 21:50:52 +00:00
|
|
|
/*
|
2001-03-21 22:07:51 +00:00
|
|
|
******************************************************************************
|
2000-01-13 23:54:23 +00:00
|
|
|
*
|
2004-04-04 20:44:45 +00:00
|
|
|
* Copyright (C) 1998-2004, International Business Machines
|
2000-01-13 23:54:23 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
2001-03-21 22:07:51 +00:00
|
|
|
******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*
|
|
|
|
* File uscanf.c
|
|
|
|
*
|
|
|
|
* Modification History:
|
|
|
|
*
|
|
|
|
* Date Name Description
|
|
|
|
* 12/02/98 stephen Creation.
|
|
|
|
* 03/13/99 stephen Modified for new C API.
|
2001-03-21 22:07:51 +00:00
|
|
|
******************************************************************************
|
1999-08-16 21:50:52 +00:00
|
|
|
*/
|
|
|
|
|
2000-04-06 23:06:48 +00:00
|
|
|
#include "unicode/utypes.h"
|
2002-10-01 01:26:49 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_FORMATTING
|
|
|
|
|
2004-10-18 03:03:13 +00:00
|
|
|
#include "unicode/putil.h"
|
2003-07-12 07:21:51 +00:00
|
|
|
#include "unicode/ustdio.h"
|
|
|
|
#include "unicode/ustring.h"
|
2004-05-03 06:41:58 +00:00
|
|
|
#include "uscanf.h"
|
|
|
|
#include "ufile.h"
|
2004-05-03 06:03:21 +00:00
|
|
|
#include "ufmt_cmn.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-05-03 06:41:58 +00:00
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2004-04-28 22:19:41 +00:00
|
|
|
|
2004-04-16 04:27:29 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2003-07-12 07:21:51 +00:00
|
|
|
u_fscanf(UFILE *f,
|
|
|
|
const char *patternSpecification,
|
|
|
|
... )
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int32_t converted;
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2003-07-12 07:21:51 +00:00
|
|
|
va_start(ap, patternSpecification);
|
|
|
|
converted = u_vfscanf(f, patternSpecification, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return converted;
|
|
|
|
}
|
|
|
|
|
2004-04-16 04:27:29 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2
|
2003-07-12 07:21:51 +00:00
|
|
|
u_fscanf_u(UFILE *f,
|
|
|
|
const UChar *patternSpecification,
|
|
|
|
... )
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int32_t converted;
|
|
|
|
|
|
|
|
va_start(ap, patternSpecification);
|
|
|
|
converted = u_vfscanf_u(f, patternSpecification, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
return converted;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
|
|
|
u_vfscanf(UFILE *f,
|
|
|
|
const char *patternSpecification,
|
|
|
|
va_list ap)
|
|
|
|
{
|
|
|
|
int32_t converted;
|
|
|
|
UChar *pattern;
|
2003-08-05 07:39:12 +00:00
|
|
|
UChar patBuffer[UFMT_DEFAULT_BUFFER_SIZE];
|
2004-05-03 06:41:58 +00:00
|
|
|
int32_t size = (int32_t)uprv_strlen(patternSpecification) + 1;
|
2003-07-12 07:21:51 +00:00
|
|
|
|
|
|
|
/* convert from the default codepage to Unicode */
|
2003-08-05 07:39:12 +00:00
|
|
|
if (size >= MAX_UCHAR_BUFFER_SIZE(patBuffer)) {
|
2003-07-12 07:21:51 +00:00
|
|
|
pattern = (UChar *)uprv_malloc(size * sizeof(UChar));
|
|
|
|
if(pattern == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2003-08-05 07:39:12 +00:00
|
|
|
pattern = patBuffer;
|
2003-07-12 07:21:51 +00:00
|
|
|
}
|
|
|
|
u_charsToUChars(patternSpecification, pattern, size);
|
|
|
|
|
|
|
|
/* do the work */
|
|
|
|
converted = u_vfscanf_u(f, pattern, ap);
|
|
|
|
|
|
|
|
/* clean up */
|
2003-08-05 07:39:12 +00:00
|
|
|
if (pattern != patBuffer) {
|
2003-07-12 07:21:51 +00:00
|
|
|
uprv_free(pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
return converted;
|
|
|
|
}
|
|
|
|
|
2004-05-03 06:03:21 +00:00
|
|
|
U_CAPI int32_t U_EXPORT2 /* U_CAPI ... U_EXPORT2 added by Peter Kirk 17 Nov 2001 */
|
2003-08-05 07:39:12 +00:00
|
|
|
u_vfscanf_u(UFILE *f,
|
|
|
|
const UChar *patternSpecification,
|
|
|
|
va_list ap)
|
1999-08-16 21:50:52 +00:00
|
|
|
{
|
2004-05-20 18:22:41 +00:00
|
|
|
return u_scanf_parse(f, patternSpecification, ap);
|
1999-08-16 21:50:52 +00:00
|
|
|
}
|
|
|
|
|
2002-10-01 01:26:49 +00:00
|
|
|
#endif /* #if !UCONFIG_NO_FORMATTING */
|
2003-09-25 21:14:35 +00:00
|
|
|
|