CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

CSTRAW.CPP (5673B)


      1 //
      2 // Copyright 2020 Electronic Arts Inc.
      3 //
      4 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free 
      5 // software: you can redistribute it and/or modify it under the terms of 
      6 // the GNU General Public License as published by the Free Software Foundation, 
      7 // either version 3 of the License, or (at your option) any later version.
      8 
      9 // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed 
     10 // in the hope that it will be useful, but with permitted additional restrictions 
     11 // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT 
     12 // distributed with this program. You should have received a copy of the 
     13 // GNU General Public License along with permitted additional restrictions 
     14 // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
     15 
     16 /* $Header: /CounterStrike/CSTRAW.CPP 1     3/03/97 10:24a Joe_bostic $ */
     17 /***********************************************************************************************
     18  ***              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               ***
     19  ***********************************************************************************************
     20  *                                                                                             *
     21  *                 Project Name : Command & Conquer                                            *
     22  *                                                                                             *
     23  *                    File Name : CSTRAW.CPP                                                   *
     24  *                                                                                             *
     25  *                   Programmer : Joe L. Bostic                                                *
     26  *                                                                                             *
     27  *                   Start Date : 11/10/96                                                     *
     28  *                                                                                             *
     29  *                  Last Update : November 10, 1996 [JLB]                                      *
     30  *                                                                                             *
     31  *---------------------------------------------------------------------------------------------*
     32  * Functions:                                                                                  *
     33  *   CacheStraw::Get -- Fetch data from the data source.                                       *
     34  * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
     35 
     36 #include	"cstraw.h"
     37 #include	<string.h>
     38 
     39 
     40 /***********************************************************************************************
     41  * CacheStraw::Get -- Fetch data from the data source.                                         *
     42  *                                                                                             *
     43  *    This will supply the data quantity requested. It performs a regulating influence on the  *
     44  *    data requests passed through it. The data is requested from the next straw in the        *
     45  *    chain such that the data stream is requested in chunks. This serves to lessen the        *
     46  *    impact of multiple small data requests.                                                  *
     47  *                                                                                             *
     48  * INPUT:   source   -- Pointer to the buffer to hold the data.                                *
     49  *                                                                                             *
     50  *          slen     -- The number of data bytes requested.                                    *
     51  *                                                                                             *
     52  * OUTPUT:  Returns with the number of data bytes stored into the buffer specified. If this    *
     53  *          number is less than that requested, it indicates that the data source has been     *
     54  *          exhausted.                                                                         *
     55  *                                                                                             *
     56  * WARNINGS:   none                                                                            *
     57  *                                                                                             *
     58  * HISTORY:                                                                                    *
     59  *   11/10/1996 JLB : Created.                                                                 *
     60  *=============================================================================================*/
     61 int CacheStraw::Get(void * source, int slen)
     62 {
     63 	int total = 0;
     64 
     65 	if (Is_Valid() && source != NULL && slen > 0) {
     66 
     67 		/*
     68 		**	Keep processing the data request until there is no more data to supply or the request
     69 		**	has been fulfilled.
     70 		*/
     71 		while (slen > 0) {
     72 
     73 			/*
     74 			**	First try to fetch the data from data previously loaded into the buffer.
     75 			*/
     76 			if (Length > 0) {
     77 				int tocopy = (Length < slen) ? Length : slen;
     78 				memmove(source, ((char *)BufferPtr.Get_Buffer()) + Index, tocopy);
     79 				slen -= tocopy;
     80 				Index += tocopy;
     81 				total += tocopy;
     82 				Length -= tocopy;
     83 				source = (char*)source + tocopy;
     84 			}
     85 			if (slen == 0) break;
     86 
     87 			/*
     88 			**	Since there is more to be fulfilled yet the holding buffer is empty,
     89 			**	refill the buffer with a fresh block of data from the source.
     90 			*/
     91 			Length = Straw::Get(BufferPtr, BufferPtr.Get_Size());
     92 			Index = 0;
     93 			if (Length == 0) break;
     94 		}
     95 	}
     96 	return(total);
     97 }