1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
/*** textfile.h - routines to handle text files efficiently
*
* Microsoft Confidential
* Copyright (C) Microsoft Corporation 1993-1994
* All Rights Reserved.
*
* Author:
* Benjamin W. Slivka
*
* History:
* 29-Oct-1991 bens Initial version
* 12-Aug-1993 bens Updated types for portability
* 22-Aug-1993 bens Added perr to TFReadLine()
* 17-Feb-1994 bens Abstract read vs. read-write modes
* 23-Feb-1994 bens Added TFWriteLine()
*
* Functions:
* TFOpen - Open text file
* TFReadLine - Read line from text file
* TFEof - Test text file for end-of-file
* TFClose - Close text file
* TFGetFileName - Return name of file
*/
#ifndef INCLUDED_TEXTFILE
#define INCLUDED_TEXTFILE 1
#include "error.h"
#define cbTEXT_FILE_LINE_MAX 256 // Longest textfile line
typedef void *HTEXTFILE; /* htf - Handle to text file */
/** tfREAD_ONLY, tfREAD_WRITE - Open modes for TFOpen
*
*/
typedef enum {
tfREAD_ONLY,
tfREAD_WRITE,
} TF_OPEN_MODES; /* tfom */
/*** TFOpen - Open a text file for I/O
*
* Entry
* pszFile - File name.
* tfom - Read/Write/Sharing flags.
* cbBuffer - Size of read/write buffer. 0 specifies
* default size.
* perr - ERROR structure
*
* Exit-Success:
* Returns number of bytes read into buffer, *including* the
* NULL terminating character. This number may be smaller than
* the parameter cb, in which case the file has been read to its
* end.
*
* Exit-Failure:
* Returns NULL; perr filled in with error message.
*/
HTEXTFILE TFOpen(char *pszFile, TF_OPEN_MODES tfom, int cbBuffer, PERROR perr);
/*** TFReadLine - Read a line from a text file
*
* Read from current file position to end of line (as indicated by
* a carriage return and/or line feed). File position is advanced
* to start of next line.
*
* Entry:
* htf - Text file handle returned by TFOpen().
* ach - Buffer to recieve line from file. The line
* terminating characters are removed, and the
* line is terminated with a NULL character.
* cb - Size of buffer, in bytes, on input.
* perr - ERROR structure
*
* Exit-Success:
* Returns number of bytes read into buffer, *including* the
* NULL terminating character.
*
* Exit-Failure:
* Returns 0;
* If TFEof() returns TRUE, then file is at end.
* If TFEof() returns FALSE, then perr is filled in with error.
*
* NOTE:
* A sequence of zero or more carriage returns ('\r') followed by
* a single line feed ('\a') is interpreted as a line separator.
*
* Carriage returns embedded in a line are ignored.
*/
int TFReadLine(HTEXTFILE htf, char *pBuffer, int cbBuffer, PERROR perr);
/*** TFEof - Test for EOF on a text file
*
* NOTE: Does not return TRUE until TFReadLine has encountered EOF!
*
* Entry:
* htf - Text file handle returned by TFOpen().
*
* Exit-Success:
* Returns TRUE if at EOF.
* Returns FALSE if not at EOF.
*
* Exit-Failure:
* Returns FALSE. htf was invalid.
*/
BOOL TFEof(HTEXTFILE htf);
/*** TFClose - Close a text file
*
* Close file opened by TFOpen.
*
* Entry:
* htf - Text file handle returned by TFOpen().
*
* Exit-Success:
* Returns TRUE.
*
* Exit-Failure:
* Returns FALSE. htf was invalid.
*/
BOOL TFClose(HTEXTFILE htf);
/*** TFGetFileName - Return name of file
*
* Entry:
* htf - Text file handle returned by TFOpen().
*
* Exit-Success:
* Returns pointer to file name.
*
* Exit-Failure:
* Returns NULL. htf was invalid.
*/
char *TFGetFileName(HTEXTFILE htf);
// BOOL TFFlush(HTEXTFILE htf);
#endif // !INCLUDED_TEXTFILE
|