Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
readline.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : Command & Conquer *
24 * *
25 * $Archive:: /Commando/Code/wwlib/readline.cpp $*
26 * *
27 * $Author:: Jani_p $*
28 * *
29 * $Modtime:: 6/14/01 7:25p $*
30 * *
31 * $Revision:: 4 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * strtrim -- Trim leading and trailing white space off of string. *
36 * Read_Line -- Read a text line from the file. *
37 * Read_Line -- Reads a text line from the straw object specified. *
38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39
40#include "always.h"
41#include "readline.h"
42#include "trim.h"
43#include "wwfile.h"
44#include "xstraw.h"
45//#include <ctype.h>
46#include <string.h>
47
48
49#if !defined(__BORLANDC__) && !defined(_MSC_VER)
50// Disable the "temporary object used to initialize a non-constant reference" warning.
51#pragma warning 665 9
52#endif
53
54
55/***********************************************************************************************
56 * Read_Line -- Read a text line from the file. *
57 * *
58 * This will read a line of text from the file specified. *
59 * *
60 * INPUT: file -- Reference to the file to read the line from. *
61 * *
62 * buffer -- Pointer to the location to store the line of text. *
63 * *
64 * len -- The length of the buffer to store the line. *
65 * *
66 * eof -- Reference to the EOF flag that will be set to true if the source *
67 * file has been exhausted. *
68 * *
69 * OUTPUT: Returns with the number of characters stored into the buffer. *
70 * *
71 * WARNINGS: none *
72 * *
73 * HISTORY: *
74 * 02/06/1997 JLB : Created. *
75 *=============================================================================================*/
76int Read_Line(FileClass & file, char * buffer, int len, bool & eof)
77{
78 FileStraw fs(file);
79 return(Read_Line(fs, buffer, len, eof));
80}
81
82
83/***********************************************************************************************
84 * Read_Line -- Reads a text line from the straw object specified. *
85 * *
86 * This reads a line of text from the straw object. *
87 * *
88 * INPUT: file -- Reference to the straw object to fetch the line of text from. *
89 * *
90 * buffer -- Pointer to the buffer that will hold the line of text. *
91 * *
92 * len -- The size of the buffer. *
93 * *
94 * eof -- Reference to the EOF flag that will be set to true if the source *
95 * straw data has been exhausted. *
96 * *
97 * OUTPUT: Returns with the number of characters stored into the buffer. *
98 * *
99 * WARNINGS: none *
100 * *
101 * HISTORY: *
102 * 02/06/1997 JLB : Created. *
103 *=============================================================================================*/
104int Read_Line(Straw & file, char * buffer, int len, bool & eof)
105{
106 if (len == 0 || buffer == NULL) return(0);
107
108 int count = 0;
109 for (;;) {
110 char c;
111 if (file.Get(&c, sizeof(c)) != sizeof(c)) {
112 eof = true;
113 buffer[count] = '\0';
114 break;
115 }
116
117 if (c == '\x0A') break;
118 if (c != '\x0D' && count+1 < len) {
119 buffer[count++] = c;
120 }
121 }
122 buffer[count] = '\0';
123
124 strtrim(buffer);
125 return(strlen(buffer));
126}
127
128int Read_Line(Straw & file, wchar_t * buffer, int len, bool & eof)
129{
130 if (len == 0 || buffer == NULL) return(0);
131
132 int count = 0;
133 for (;;) {
134 wchar_t c;
135 if (file.Get(&c, sizeof(c)) != sizeof(c)) {
136 eof = true;
137 buffer[count] = L'\0';
138 break;
139 }
140
141 if (c == L'\x0A') break;
142 if (c != L'\x0D' && count+1 < len) {
143 buffer[count++] = c;
144 }
145 }
146 buffer[count] = '\0';
147
148 wcstrim(buffer);
149 return(wcslen(buffer));
150}
#define NULL
Definition BaseType.h:92
Definition STRAW.H:51
virtual int Get(void *buffer, int slen)
Definition straw.cpp:132
int Read_Line(FileClass &file, char *buffer, int len, bool &eof)
Definition readline.cpp:76
wchar_t * wcstrim(wchar_t *buffer)
Definition trim.cpp:88
char * strtrim(char *buffer)
Definition trim.cpp:60