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