2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "ifilesystem.h"
26 #include "stream/stringstream.h"
30 void ViewShader( const char *pFile, const char *pName ){
33 vfsLoadFile( pFile, reinterpret_cast<void**>( &pBuff ) );
35 globalErrorStream() << "Failed to load shader file " << pFile << "\n";
38 // look for the shader declaration
39 StringOutputStream strFind( string_length( pName ) );
40 strFind << LowerCase( pName );
41 StringOutputStream strLook( string_length( pBuff ) );
42 strLook << LowerCase( pBuff );
43 // offset used when jumping over commented out definitions
44 int length = string_length( pBuff );
45 std::size_t nOffset = 0;
48 while ( !startOK || !endOK ){
49 const char* substr = strstr( strLook.c_str() + nOffset, strFind.c_str() );
53 std::size_t nStart = substr - strLook.c_str();
54 startOK = endOK = false;
58 //validate found one...
59 for ( const char* i = substr - 1; i > strLook.c_str(); i-- ){
60 if( (strncmp( i, "\t", 1 ) == 0) || (strncmp( i, " ", 1 ) == 0) ){
64 else if ( (strncmp( i, "\n", 1 ) == 0) || (strncmp( i, "\r", 1 ) == 0) ){
73 const char* b = strLook.c_str() + strlen( strLook.c_str() );
74 for ( const char* i = substr + strlen( strFind.c_str() ); i < b; i++ ){
75 if( (strncmp( i, "\t", 1 ) == 0) || (strncmp( i, " ", 1 ) == 0) ){
79 else if ( (strncmp( i, "\n", 1 ) == 0) || (strncmp( i, "\r", 1 ) == 0) || (strncmp( i, "{", 1 ) == 0) || (strncmp( i, ":q3map", 6 ) == 0) ){
88 if( !startOK || !endOK ){
92 //globalErrorStream() << "Validated successfully" << "\n";
95 for ( const char* i = strLook.c_str(); i < substr ; i++ ){
96 if ( (strncmp( i, "\r\n", 2 ) == 0) ){
101 /*// we have found something, maybe it's a commented out shader name?
102 char *strCheck = new char[string_length( strLook.c_str() ) + 1];
103 strcpy( strCheck, strLook.c_str() );
104 strCheck[nStart] = 0;
105 char *pCheck = strrchr( strCheck, '\n' );
106 // if there's a commentary sign in-between we'll continue
107 if ( pCheck && strstr( pCheck, "//" ) ) {
109 nOffset = nStart + 1;
117 const char* b = strLook.c_str() + strlen( strLook.c_str() ) - 1;
118 for ( const char* i = strLook.c_str(); i < b; i++ ){
119 if ( (strncmp( i, "\r\n", 2 ) == 0) ){
123 // now close the file
124 vfsFreeFile( pBuff );
126 DoTextEditor( pFile, static_cast<int>( nOffset ), length );