Files
illusion-arena/code/game/g_fileops.c
2025-07-15 15:01:00 -03:00

120 lines
2.9 KiB
C

/*
===========================================================================
Copyright (C) 2009 Karl Kuglin
Copyright (C) 2004-2006 Tony J. White
This file is part of the Open Arena source code.
Portions copied/modified from Tremulous under GPL version 2 including any
later versions.
Open Arena source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.
Open Arena source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Open Arena source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
===========================================================================
*/
#include "g_local.h"
/*
================
readFile_int
This parses an integer for the "tag" specified (cnf)
================
*/
void readFile_int( char **cnf, int *v )
{
char *t;
//COM_MatchToken(cnf, "=");
t = COM_ParseExt( cnf, qfalse );
if( !strcmp( t, "=" ) )
{
t = COM_ParseExt( cnf, qfalse );
}
else
{
COM_ParseWarning( "expected '=' before \"%s\"", t );
}
*v = atoi( t );
}
/*
================
readFile_string
This parses a literal string for the "tag" specified
Color characters and escape sequences are parsed as well.
================
*/
void readFile_string( char **cnf, char *s, int size )
{
char *t;
//COM_MatchToken(cnf, "=");
s[ 0 ] = '\0';
t = COM_ParseExt( cnf, qfalse );
if( strcmp( t, "=" ) )
{
COM_ParseWarning( "expected '=' before \"%s\"", t );
Q_strncpyz( s, t, size );
}
while( 1 )
{
t = COM_ParseExt( cnf, qfalse );
if( !*t )
break;
if( strlen( t ) + strlen( s ) >= size )
break;
if( *s )
Q_strcat( s, size, " " );
Q_strcat( s, size, t );
}
}
/*
================
writeFile_int
This writes an integer to the file.
Since there is no logic as to where it writes, it must be called "just-in-time."
================
*/
void writeFile_int( int v, fileHandle_t f )
{
char buf[ 32 ];
Com_sprintf( buf, sizeof( buf ), "%d", v );
trap_FS_Write( buf, strlen( buf ), f );
trap_FS_Write( "\n", 1, f );
}
/*
================
writeFile_string
This writes a string to the file.
Since there is no logic as to where it writes, it must be called "just-in-time."
================
*/
void writeFile_string( char *s, fileHandle_t f )
{
char buf[ MAX_STRING_CHARS ];
buf[ 0 ] = '\0';
if( s[ 0 ] )
{
//Q_strcat(buf, sizeof(buf), s);
Q_strncpyz( buf, s, sizeof( buf ) );
trap_FS_Write( buf, strlen( buf ), f );
}
trap_FS_Write( "\n", 1, f );
}