10596faeddefbf198de137d5e893708495ab1584cFredrik Roubert// © 2016 and later: Unicode, Inc. and others.
264339d36f8bd4db5025fe2988eda22b491a9219cFredrik Roubert// License & terms of use: http://www.unicode.org/copyright.html
3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/*
4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *******************************************************************************
5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
6f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius *   Copyright (C) 1998-2014, International Business Machines
7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   Corporation and others.  All Rights Reserved.
8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *******************************************************************************
10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * File ufile.h
12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Modification History:
14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *
15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   Date        Name        Description
16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   12/01/98    stephen        Creation.
17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *   03/12/99    stephen     Modified for new C API.
18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru *******************************************************************************
19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#ifndef UFILE_H
22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UFILE_H
23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utypes.h"
25f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius
26f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius#if !UCONFIG_NO_CONVERSION
27f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius
280596faeddefbf198de137d5e893708495ab1584cFredrik Roubert#include <stdio.h>
290596faeddefbf198de137d5e893708495ab1584cFredrik Roubert
30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/ucnv.h"
31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "unicode/utrans.h"
32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#include "locbund.h"
33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* The buffer size for fromUnicode calls */
35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UFILE_CHARBUFFER_SIZE 1024
36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* The buffer size for toUnicode calls */
38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#define UFILE_UCHARBUFFER_SIZE 1024
39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/* A UFILE */
41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_TRANSLITERATION
43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef struct {
45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar  *buffer;             /* Beginning of buffer */
46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t capacity;           /* Capacity of buffer */
47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t pos;                /* Beginning of untranslitted data */
48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t length;             /* Length *from beginning of buffer* of untranslitted data */
49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UTransliterator *translit;
50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} UFILETranslitBuffer;
51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querutypedef struct u_localized_string {
55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar       *fPos;          /* current pos in fUCBuffer */
56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    const UChar *fLimit;        /* data limit in fUCBuffer */
57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar       *fBuffer;       /* Place to write the string */
58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_FORMATTING
60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    ULocaleBundle  fBundle; /* formatters */
61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} u_localized_string;
63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querustruct UFILE {
65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#if !UCONFIG_NO_TRANSLITERATION
66ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UFILETranslitBuffer *fTranslit;
67ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
68ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
69ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    FILE        *fFile;         /* the actual filesystem interface */
70ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
71ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UConverter  *fConverter;    /* for codeset conversion */
72ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
73ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    u_localized_string str;     /* struct to handle strings for number formatting */
74ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
75ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UChar       fUCBuffer[UFILE_UCHARBUFFER_SIZE];/* buffer used for toUnicode */
76ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
77ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    UBool       fOwnFile;       /* TRUE if fFile should be closed */
78ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
79ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru    int32_t     fFileno;        /* File number. Useful to determine if it's stdin. */
80ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru};
81ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
82ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
83ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Like u_file_write but takes a flush parameter
84ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
85ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CFUNC int32_t U_EXPORT2
86ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruu_file_write_flush( const UChar     *chars,
87ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        int32_t     count,
88ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UFILE       *f,
89ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UBool       flushIO,
90ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru        UBool       flushTranslit);
91ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
92ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
93ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Fill a UFILE's buffer with converted codepage data.
94ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param f The UFILE containing the buffer to fill.
95ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
96ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid
97ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruufile_fill_uchar_buffer(UFILE *f);
98ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
99ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
100ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Get one code unit and detect whether the end of file has been reached.
101ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param f The UFILE containing the characters.
102ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param ch The read in character
103ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return TRUE if the character is valid, or FALSE when EOF has been detected
104ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
105ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CFUNC UBool U_EXPORT2
106ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruufile_getch(UFILE *f, UChar *ch);
107ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
108ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
109ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Get one character and detect whether the end of file has been reached.
110ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param f The UFILE containing the characters.
111ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param ch The read in character
112ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @return TRUE if the character is valid, or FALSE when EOF has been detected
113ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
114ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste QueruU_CFUNC UBool U_EXPORT2
115ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruufile_getch32(UFILE *f, UChar32 *ch);
116ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
117ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
118ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Close out the transliterator and flush any data therein.
119ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param f flu
120ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
121ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid
122ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruufile_close_translit(UFILE *f);
123ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
124ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru/**
125ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * Flush the buffer in the transliterator
126ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru * @param f UFile to flush
127ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru */
128ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruvoid
129ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruufile_flush_translit(UFILE *f);
130ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
13127f654740f2a26ad62a5c155af9199af9e69b889claireho/**
13227f654740f2a26ad62a5c155af9199af9e69b889claireho * Flush the IO buffer
13327f654740f2a26ad62a5c155af9199af9e69b889claireho * @param f UFile to flush
13427f654740f2a26ad62a5c155af9199af9e69b889claireho */
13527f654740f2a26ad62a5c155af9199af9e69b889clairehovoid
13627f654740f2a26ad62a5c155af9199af9e69b889clairehoufile_flush_io(UFILE *f);
13727f654740f2a26ad62a5c155af9199af9e69b889claireho
138ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru
139ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#endif
140f9878a236aa0d9662d8e40cafdaf2e04cd615835ccornelius#endif
141