]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - tools/quake3/q3data/p3dlib.c
p3dlib.c: include “cmdlib.h” on non Windows platform
[xonotic/netradiant.git] / tools / quake3 / q3data / p3dlib.c
index 3ccdfbe1d977498bb1e4557939025aa318a0c4f5..0b228e2fad9a439039719a03eea366d726598465 100644 (file)
@@ -1,23 +1,23 @@
 /*
-Copyright (C) 1999-2006 Id Software, Inc. and contributors.
-For a list of contributors, see the accompanying CONTRIBUTORS file.
+   Copyright (C) 1999-2006 Id Software, Inc. and contributors.
+   For a list of contributors, see the accompanying CONTRIBUTORS file.
 
-This file is part of GtkRadiant.
+   This file is part of GtkRadiant.
 
-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.
+   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.
 
-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.
+   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.
 
-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
-*/
+   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
+ */
 
 #include "p3dlib.h"
 
@@ -30,16 +30,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #define MAX_POLYSETS 64
 
-#if defined (__linux__) || defined (__APPLE__)
-#define _strcmpi Q_stricmp
-#define filelength Q_filelength
-#define strlwr strlower
+#if defined ( __linux__ ) || defined ( __APPLE__ )
+       #include "cmdlib.h"
+       #define _strcmpi Q_stricmp
+       #define filelength Q_filelength
+       #define strlwr strlower
 #endif
 typedef struct
 {
        long len;
 
-       int      numPairs;
+       int numPairs;
        char polysetNames[MAX_POLYSETS][256];
        char shaders[MAX_POLYSETS][256];
 
@@ -52,18 +53,18 @@ static int P3DProcess();
 static int P3DGetToken( int restOfLine );
 
 static char s_token[1024];
-static int     s_curpair;
+static int s_curpair;
 
 /*
 ** P3DLoad
 **
 */
-int P3DLoad( const char *filename )
-{
+int P3DLoad( const char *filename ){
        FILE *fp = fopen( filename, "rb" );
 
-       if ( !fp )
+       if ( !fp ) {
                return 0;
+       }
 
        memset( &p3d, 0, sizeof( p3d ) );
 
@@ -71,8 +72,7 @@ int P3DLoad( const char *filename )
 
        p3d.curpos = p3d.buffer = malloc( p3d.len );
 
-       if ( fread( p3d.buffer, p3d.len, 1, fp ) != 1 )
-       {
+       if ( fread( p3d.buffer, p3d.len, 1, fp ) != 1 ) {
                fclose( fp );
                return 0;
        }
@@ -86,28 +86,26 @@ int P3DLoad( const char *filename )
 ** P3DClose
 **
 */
-void P3DClose()
-{
-       if ( p3d.buffer )
-       {
+void P3DClose(){
+       if ( p3d.buffer ) {
                free( p3d.buffer );
                p3d.buffer = 0;
        }
 }
 
-int CharIsTokenDelimiter( int ch )
-{
-       if ( ch <= 32 )
+int CharIsTokenDelimiter( int ch ){
+       if ( ch <= 32 ) {
                return 1;
+       }
        return 0;
 }
 
-int P3DSkipToToken( const char *name )
-{
+int P3DSkipToToken( const char *name ){
        while ( P3DGetToken( 0 ) )
        {
-               if ( !_strcmpi( s_token, name ) )
+               if ( !_strcmpi( s_token, name ) ) {
                        return 1;
+               }
        }
 
        return 0;
@@ -117,19 +115,20 @@ int P3DSkipToToken( const char *name )
 ** P3DGetToken
 **
 */
-int P3DGetToken( int restOfLine )
-{
+int P3DGetToken( int restOfLine ){
        int i = 0;
 
-       if ( p3d.buffer == 0 )
+       if ( p3d.buffer == 0 ) {
                return 0;
+       }
 
-       if ( ( p3d.curpos - p3d.buffer ) == p3d.len )
+       if ( ( p3d.curpos - p3d.buffer ) == p3d.len ) {
                return 0;
+       }
 
        // skip over crap
        while ( ( ( p3d.curpos - p3d.buffer ) < p3d.len ) &&
-                   ( *p3d.curpos <= 32 ) )
+                       ( *p3d.curpos <= 32 ) )
        {
                p3d.curpos++;
        }
@@ -141,10 +140,9 @@ int P3DGetToken( int restOfLine )
                p3d.curpos++;
                i++;
 
-               if ( ( CharIsTokenDelimiter( s_token[i-1] ) && !restOfLine ) ||
-                        ( ( s_token[i-1] == '\n' ) ) )
-               {
-                       s_token[i-1] = 0;
+               if ( ( CharIsTokenDelimiter( s_token[i - 1] ) && !restOfLine ) ||
+                        ( ( s_token[i - 1] == '\n' ) ) ) {
+                       s_token[i - 1] = 0;
                        break;
                }
        }
@@ -154,10 +152,8 @@ int P3DGetToken( int restOfLine )
        return 1;
 }
 
-int P3DGetNextPair( char **psetName, char **associatedShader )
-{
-       if ( s_curpair < p3d.numPairs )
-       {
+int P3DGetNextPair( char **psetName, char **associatedShader ){
+       if ( s_curpair < p3d.numPairs ) {
                *psetName = p3d.polysetNames[s_curpair];
                *associatedShader = p3d.shaders[s_curpair];
                s_curpair++;
@@ -167,22 +163,23 @@ int P3DGetNextPair( char **psetName, char **associatedShader )
        return 0;
 }
 
-int P3DSkipToTokenInBlock( const char *name )
-{
+int P3DSkipToTokenInBlock( const char *name ){
        int iLevel = 0;
 
-       while ( P3DGetToken( 0 ) ) 
+       while ( P3DGetToken( 0 ) )
        {
-               if ( !_strcmpi( s_token, "}" ) )
+               if ( !_strcmpi( s_token, "}" ) ) {
                        iLevel--;
-               else if ( !_strcmpi( s_token, "{" ) )
+               }
+               else if ( !_strcmpi( s_token, "{" ) ) {
                        iLevel++;
+               }
 
-               if ( !_strcmpi( s_token, name ) )
+               if ( !_strcmpi( s_token, name ) ) {
                        return 1;
+               }
 
-               if ( iLevel == 0 )
-               {
+               if ( iLevel == 0 ) {
                        return 0;
                }
        }
@@ -195,37 +192,34 @@ int P3DSkipToTokenInBlock( const char *name )
 **
 ** Nothing fancy here.
 */
-int P3DProcess()
-{
+int P3DProcess(){
 
        s_curpair = 0;
 
        // first token should be a string
-       P3DGetToken( 1 );               // Voodoo Ascii File
+       P3DGetToken( 1 );       // Voodoo Ascii File
 
        // skip to the first Obj declaration
        while ( P3DGetToken( 0 ) )
        {
-               if ( !_strcmpi( s_token, "Obj" ) )
-               {
+               if ( !_strcmpi( s_token, "Obj" ) ) {
                        int j = 0, k = 0;
 
-                       if ( P3DSkipToToken( "Text" ) )
-                       {
-                               if ( P3DSkipToTokenInBlock( "TMap" ) )
-                               {
+                       if ( P3DSkipToToken( "Text" ) ) {
+                               if ( P3DSkipToTokenInBlock( "TMap" ) ) {
                                        char *p;
 
-                                       if ( !P3DSkipToToken( "Path" ) )
+                                       if ( !P3DSkipToToken( "Path" ) ) {
                                                return 0;
+                                       }
 
-                                       if ( !P3DGetToken( 1 ) )
+                                       if ( !P3DGetToken( 1 ) ) {
                                                return 0;
+                                       }
 
                                        while ( s_token[j] != 0 )
                                        {
-                                               if ( s_token[j] == '\\' )
-                                               {
+                                               if ( s_token[j] == '\\' ) {
                                                        j++;
                                                        p3d.shaders[p3d.numPairs][k] = '/';
                                                }
@@ -241,12 +235,10 @@ int P3DProcess()
                                        //
                                        // strip off any explicit extensions
                                        //
-                                       if ( ( p = strrchr( p3d.shaders[p3d.numPairs], '/' ) ) != 0 )
-                                       {
+                                       if ( ( p = strrchr( p3d.shaders[p3d.numPairs], '/' ) ) != 0 ) {
                                                while ( *p )
                                                {
-                                                       if ( *p == '.' ) 
-                                                       {
+                                                       if ( *p == '.' ) {
                                                                *p = 0;
                                                                break;
                                                        }
@@ -257,16 +249,18 @@ int P3DProcess()
                                        //
                                        // skip to the end of the Object and grab its name
                                        //
-                                       if ( !P3DSkipToToken( "Name" ) )
+                                       if ( !P3DSkipToToken( "Name" ) ) {
                                                return 0;
+                                       }
 
-                                       if ( P3DGetToken( 0 ) )
-                                       {
+                                       if ( P3DGetToken( 0 ) ) {
                                                // strip off leading 'Obj_' if it exists
-                                               if ( strstr( s_token, "Obj_" ) == s_token )
+                                               if ( strstr( s_token, "Obj_" ) == s_token ) {
                                                        strcpy( p3d.polysetNames[p3d.numPairs], s_token + strlen( "Obj_" ) );
-                                               else
+                                               }
+                                               else{
                                                        strcpy( p3d.polysetNames[p3d.numPairs], s_token );
+                                               }
 
                                                // strip off trailing unused color information
 //                                             if ( strrchr( p3d.polysetNames[p3d.numPairs], '_' ) != 0 )
@@ -289,8 +283,7 @@ int P3DProcess()
 }
 
 #if 0
-void SkinFromP3D( const char *file )
-{
+void SkinFromP3D( const char *file ){
        char filename[1024];
        char *psetName, *associatedShader;
 
@@ -306,8 +299,9 @@ void SkinFromP3D( const char *file )
        */
        sprintf( filename, "%s/%s", g_cddir, file );
 
-       if ( !P3DLoad( filename ) )
+       if ( !P3DLoad( filename ) ) {
                Error( "unable to load '%s'", filename );
+       }
 
        while ( P3DGetNextPair( &psetName, &associatedShader ) )
        {
@@ -317,12 +311,10 @@ void SkinFromP3D( const char *file )
                // corresponds to and append the shader to it
                for ( i = 0; i < g_data.model.numSurfaces; i++ )
                {
-                       if ( !_strcmpi( g_data.surfData[i].header.name, psetName) )
-                       {
+                       if ( !_strcmpi( g_data.surfData[i].header.name, psetName ) ) {
                                char *p;
 
-                               if ( strstr( associatedShader, gamedir + 1 ) )
-                               {
+                               if ( strstr( associatedShader, gamedir + 1 ) ) {
                                        p = strstr( associatedShader, gamedir + 1 ) + strlen( gamedir ) - 1;
                                }
                                else
@@ -341,5 +333,3 @@ void SkinFromP3D( const char *file )
        P3DClose();
 }
 #endif
-
-