Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
xpipe.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/Library/XPIPE.CPP $*
26 * *
27 * $Author:: Greg_h $*
28 * *
29 * $Modtime:: 9/28/98 12:06p $*
30 * *
31 * $Revision:: 2 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * BufferPipe::Put -- Submit data to the buffered pipe segment. *
36 * FilePipe::Put -- Submit a block of data to the pipe. *
37 * FilePipe::End -- End the file pipe handler. *
38 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
39
40
41#include "always.h"
42#include "xpipe.h"
43#include <stddef.h>
44#include <string.h>
45
46
47//---------------------------------------------------------------------------------------------------------
48// BufferPipe
49//---------------------------------------------------------------------------------------------------------
50
51
52/***********************************************************************************************
53 * BufferPipe::Put -- Submit data to the buffered pipe segment. *
54 * *
55 * The buffered pipe is a pipe terminator. That is, the data never flows onto subsequent *
56 * pipe chains. The data is stored into the buffer previously submitted to the pipe. *
57 * If the buffer is full, no more data is output to the buffer. *
58 * *
59 * INPUT: source -- Pointer to the data to submit. *
60 * *
61 * length -- The number of bytes to be submitted. *
62 * *
63 * OUTPUT: Returns with the number of bytes output to the destination buffer. *
64 * *
65 * WARNINGS: none *
66 * *
67 * HISTORY: *
68 * 07/03/1996 JLB : Created. *
69 *=============================================================================================*/
70int BufferPipe::Put(void const * source, int slen)
71{
72 int total = 0;
73
74 if (Is_Valid() && source != NULL && slen > 0) {
75 int len = slen;
76 if (BufferPtr.Get_Size() != 0) {
77 int theoretical_max = BufferPtr.Get_Size() - Index;
78 len = (slen < theoretical_max) ? slen : theoretical_max;
79 }
80
81 if (len > 0) {
82 memmove(((char *)BufferPtr.Get_Buffer()) + Index, source, len);
83 }
84
85 Index += len;
86// Length -= len;
87// Buffer = ((char *)Buffer) + len;
88 total += len;
89 }
90 return(total);
91}
92
93
94//---------------------------------------------------------------------------------------------------------
95// FilePipe
96//---------------------------------------------------------------------------------------------------------
97
99{
100 if (Valid_File() && HasOpened) {
101 HasOpened = false;
102 File->Close();
103 File = NULL;
104 }
105}
106
107
108/***********************************************************************************************
109 * FilePipe::End -- End the file pipe handler. *
110 * *
111 * This routine is called when there will be no more data sent through the pipe. It is *
112 * responsible for cleaning up anything it needs to. This is not handled by the *
113 * destructor, although it serves a similar purpose, because pipe are linked together and *
114 * the destructor order is not easily controlled. If the destructors for a pipe chain were *
115 * called out of order, the result might be less than pleasant. *
116 * *
117 * INPUT: none *
118 * *
119 * OUTPUT: Returns with the number of bytes flushed out the final end of the pipe as a *
120 * consequence of this routine. *
121 * *
122 * WARNINGS: Don't send any more data through the pipe after this routine is called. *
123 * *
124 * HISTORY: *
125 * 07/05/1996 JLB : Created. *
126 *=============================================================================================*/
128{
129 int total = Pipe::End();
130 if (Valid_File() && HasOpened) {
131 HasOpened = false;
132 File->Close();
133 }
134 return(total);
135}
136
137
138/***********************************************************************************************
139 * FilePipe::Put -- Submit a block of data to the pipe. *
140 * *
141 * Takes the data block submitted and writes it to the file. If the file was not already *
142 * open, this routine will open it for write. *
143 * *
144 * INPUT: source -- Pointer to the data to submit to the file. *
145 * *
146 * length -- The number of bytes to write to the file. *
147 * *
148 * OUTPUT: Returns with the number of bytes written to the file. *
149 * *
150 * WARNINGS: none *
151 * *
152 * HISTORY: *
153 * 07/03/1996 JLB : Created. *
154 *=============================================================================================*/
155int FilePipe::Put(void const * source, int slen)
156{
157 if (Valid_File() && source != NULL && slen > 0) {
158 if (!File->Is_Open()) {
159 HasOpened = true;
160 File->Open(FileClass::WRITE);
161 }
162
163 return(File->Write(source, slen));
164 }
165 return(0);
166}
#define NULL
Definition BaseType.h:92
virtual int Put(void const *source, int slen)
Definition xpipe.cpp:70
@ WRITE
Definition WWFILE.H:72
virtual ~FilePipe(void)
Definition xpipe.cpp:98
virtual int Put(void const *source, int slen)
Definition xpipe.cpp:155
virtual int End(void)
Definition xpipe.cpp:127
virtual int End(void)
Definition PIPE.H:57