2007-11-04 03:51:54 +00:00
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Copyright (C) 1999-2007 id Software, Inc. and contributors.
|
|
|
|
For a list of contributors, see the accompanying CONTRIBUTORS file.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
This file is part of GtkRadiant.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
GtkRadiant 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.
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with GtkRadiant; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
Camera plugin for GtkRadiant
|
|
|
|
Copyright (C) 2002 Splash Damage Ltd.
|
|
|
|
*/
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
#include "camera.h"
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void Sys_ERROR( char* text, ... ){
|
|
|
|
va_list argptr;
|
|
|
|
char buf[32768];
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
va_start( argptr,text );
|
|
|
|
vsprintf( buf, text,argptr );
|
|
|
|
va_end( argptr );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "Camera::ERROR->%s", buf );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
char* UnixToDosPath( char* path ){
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
return path;
|
|
|
|
#else
|
2012-03-17 20:01:54 +00:00
|
|
|
for ( char* p = path; *p; p++ )
|
2007-11-04 03:51:54 +00:00
|
|
|
{
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( *p == '/' ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
*p = '\\';
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
return path;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void CAMERA_ExtractFilePath( const char *path, char *dest ){
|
|
|
|
const char *src;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
src = path + strlen( path ) - 1;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// back up until a \ or the start
|
|
|
|
//
|
2012-03-17 20:01:54 +00:00
|
|
|
while ( src != path && *( src - 1 ) != '/' && *( src - 1 ) != '\\' )
|
|
|
|
src--;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
memcpy( dest, path, src - path );
|
|
|
|
dest[src - path] = 0;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
const char* ExtractFilename( const char* path ){
|
|
|
|
char* p = (char *)strrchr( path, '/' );
|
|
|
|
if ( !p ) {
|
|
|
|
p = (char *)strrchr( path, '\\' );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !p ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return path;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
return ++p;
|
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
int Q_stricmp( const char *s1, const char *s2 ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return stricmp( s1, s2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-03-17 20:01:54 +00:00
|
|
|
==============
|
|
|
|
FileExists
|
|
|
|
==============
|
|
|
|
*/
|
|
|
|
bool FileExists( const char *filename ){
|
|
|
|
FILE *f;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
f = fopen( filename, "r" );
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( !f ) {
|
2007-11-04 03:51:54 +00:00
|
|
|
return false;
|
2012-03-17 20:01:54 +00:00
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
fclose( f );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// command buffer
|
|
|
|
// empty wrappers, don't really use them here
|
|
|
|
//
|
|
|
|
void Cbuf_AddText( const char *text ) {};
|
2012-03-17 20:01:54 +00:00
|
|
|
void Cbuf_Execute( void ) {};
|
2007-11-04 03:51:54 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Common
|
|
|
|
//
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void CDECL Com_Error( int level, const char *error, ... ){
|
|
|
|
va_list argptr;
|
|
|
|
char buf[32768];
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
va_start( argptr,error );
|
|
|
|
vsprintf( buf, error,argptr );
|
|
|
|
va_end( argptr );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "Camera::ERROR->%s", buf );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void CDECL Com_Printf( const char* msg, ... ){
|
|
|
|
va_list argptr;
|
|
|
|
char buf[32768];
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
va_start( argptr,msg );
|
|
|
|
vsprintf( buf, msg,argptr );
|
|
|
|
va_end( argptr );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "Camera::%s", buf );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
void CDECL Com_DPrintf( const char* msg, ... ){
|
2007-11-04 03:51:54 +00:00
|
|
|
#ifdef _DEBUG
|
2012-03-17 20:01:54 +00:00
|
|
|
va_list argptr;
|
|
|
|
char buf[32768];
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
va_start( argptr,msg );
|
|
|
|
vsprintf( buf, msg,argptr );
|
|
|
|
va_end( argptr );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
Sys_Printf( "Camera::%s", buf );
|
2007-11-04 03:51:54 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Com_Allocate( int bytes ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
return( malloc( bytes ) );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Com_Dealloc( void *ptr ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
free( ptr );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Filesystem
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
#pragma warning(disable : 4311)
|
|
|
|
#pragma warning(disable : 4312)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int FS_Read( void *buffer, int len, fileHandle_t f ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
return fread( buffer, len, 1, (FILE *)f );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FS_Write( const void *buffer, int len, fileHandle_t h ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
return fwrite( buffer, len, 1, (FILE *)h );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FS_ReadFile( const char *qpath, void **buffer ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
fileHandle_t h;
|
|
|
|
byte* buf;
|
|
|
|
int len;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
buf = NULL;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
len = FS_FOpenFileRead( qpath, &h, qfalse );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( h == 0 ) {
|
|
|
|
if ( buffer ) {
|
|
|
|
*buffer = NULL;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
buf = (byte *)Com_Allocate( len + 1 );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
*buffer = buf;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
FS_Read( buf, len, h );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
buf[len] = 0;
|
|
|
|
FS_FCloseFile( h );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
return len;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FS_FreeFile( void *buffer ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
Com_Dealloc( buffer );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FS_FOpenFileRead( const char *filename, fileHandle_t *file, qboolean uniqueFILE ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
FILE *fh;
|
2007-11-04 03:51:54 +00:00
|
|
|
long len;
|
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
fh = fopen( filename, "rb" );
|
|
|
|
*file = *(fileHandle_t *)&fh;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
if ( file ) {
|
|
|
|
fseek( fh, 0, SEEK_END );
|
|
|
|
len = ftell( fh );
|
|
|
|
rewind( fh );
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return -1;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fileHandle_t FS_FOpenFileWrite( const char *filename ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
FILE *fh;
|
|
|
|
fileHandle_t f;
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
memset( &f, 0, sizeof( f ) );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
fh = fopen( filename, "wb" );
|
2007-11-04 03:51:54 +00:00
|
|
|
|
2012-03-17 20:01:54 +00:00
|
|
|
f = (fileHandle_t)fh;
|
|
|
|
return f;
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FS_FCloseFile( fileHandle_t f ) {
|
2012-03-17 20:01:54 +00:00
|
|
|
fclose( (FILE *)f );
|
2007-11-04 03:51:54 +00:00
|
|
|
}
|