4 * Revision 1.1 2001/04/04 05:43:36 wang
5 * First commit: compiles on Linux, Amiga, Windows, Windows CE, generic gcc
7 * Revision 1.1 1999/09/13 15:06:41 bnv
11 * This file provides some substitus for the common fxxxx I/O commands
12 * that unfortunatelly do not exist on the Windows CE of Visual C++.
20 static char buffer
[128];
21 static int bufferpos
=0;
22 static BOOL newline
=FALSE
;
24 /* ----- Bfopen ----- */
26 Bfopen( const char *filename
, const char *mode
)
37 /* scan mode string to find options */
38 for (ch
=(const char *)mode
; *ch
; ch
++) {
48 bitmode
|= BIO_BINARY
;
51 bitmode
|= BIO_APPEND
;
54 bitmode
|= BIO_UNICODE
;
61 #if defined(__BORLANDC__)
62 if ((bitmode
& (BIO_READ
|BIO_WRITE
)) == (BIO_READ
|BIO_WRITE
))
63 hnd
= _lopen(filename
,READ_WRITE
);
65 if (bitmode
& BIO_READ
)
66 hnd
= _lopen(filename
,READ
);
68 if (bitmode
& BIO_WRITE
)
69 hnd
= _lopen(filename
,WRITE
);
72 if ((HFILE
)hnd
== HFILE_ERROR
)
75 mbstowcs(path
,filename
,STRLEN(filename
)+1);
77 if ((bitmode
& (BIO_READ
|BIO_WRITE
)) == (BIO_READ
|BIO_WRITE
)) {
78 hnd
= CreateFile( path
,
79 GENERIC_READ
| GENERIC_WRITE
, FILE_SHARE_READ
, NULL
,
80 OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
82 if (bitmode
& BIO_READ
) {
83 hnd
= CreateFile(path
,
84 GENERIC_READ
, FILE_SHARE_READ
, NULL
,
85 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
87 if (bitmode
& BIO_WRITE
) {
88 hnd
= CreateFile( path
,
89 GENERIC_WRITE
, FILE_SHARE_READ
, NULL
,
90 OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
94 if (hnd
==INVALID_HANDLE_VALUE
)
97 f
= (BFILE
*)malloc(sizeof(BFILE
));
103 /* ----- Bfclose ----- */
105 Bfclose( BFILE
*stream
)
107 if (!stream
) return EOF
;
108 #if defined(__BORLANDC__)
109 _lclose(stream
->handle
);
111 CloseHandle(stream
->handle
);
117 /* ----- Bfflush ----- */
119 Bfflush(BFILE
*stream
)
121 if (!stream
) return EOF
;
122 return SetEndOfFile(stream
->handle
);
125 /* ----- Bfeof ----- */
129 return (stream
->mode
& BIO_EOF
);
132 /* ----- Bfgetc ----- */
134 Bfgetc( BFILE
*stream
)
137 #if !defined(__BORLANDC__)
144 #if defined(__BORLANDC__)
145 if (_lread(stream
->handle
, &c
, 1)==0) {
147 stream
->mode
|= BIO_EOF
;
151 ReadFile(stream
->handle
, &c
, 1, &len
, NULL
);
153 if ((c
==0x0D) && (stream
->mode
& BIO_TEXT
)) {
154 #if defined(__BORLANDC__)
155 if (_lread(stream
->handle
, &c
, 1)==0) {
157 stream
->mode
|= BIO_EOF
;
161 ReadFile(stream
->handle
, &c
, 1, &len
, NULL
);
164 #if !defined(__BORLANDC__)
167 stream
->mode
|= BIO_EOF
;
174 /* ----- Bputc ----- */
176 Bfputc( char ch
, BFILE
*stream
)
178 #if !defined(__BORLANDC__)
188 if (ch
==0x0A && (stream
->mode
& BIO_TEXT
)) {
189 cr
= TEXT('\015'); // 0x0D
190 #if defined(__BORLANDC__)
191 _lwrite(stream
->handle
, &cr
, 1);
193 _lwrite(stream
->handle
, &ch
, 1);
195 WriteFile(stream
->handle
, &cr
, 1, &written
, NULL
);
197 WriteFile(stream
->handle
, &ch
, 1, &written
, NULL
);
202 /* ------ Bfputs -------- */
204 Bfputs( const char *s
, BFILE
*stream
)
210 /* ------ Read a Character -------- */
216 /* return a new character only a new line is found in the buffer */
237 // Erase contents of buffer
238 WGotoXY(WWhereX()-bufferpos
,WWhereY());
243 if (bufferpos
<sizeof(buffer
)) {
245 buffer
[bufferpos
++] = c
;
250 if (c
=='\n') newline
= FALSE
;
252 memmove(buffer
, buffer
+1, bufferpos
);
256 /* ------ Write an ASCII char ----- */
261 tch
= (TCHAR
)ch
& 0xFF;
265 /* ------ Write an ASCII string ----- */
266 // Wanring: DIFFERENT behavior from puts(). It doesn't append a new line
268 Bputs( const char *str
)
274 /* ------ Write a number ----- */
276 Bputint( long num
, int length
, int radix
)
279 Bputs(Bl2a(str
,num
,length
,radix
));