Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0991a5ce8b
Fetching contributors…

Cannot retrieve contributors at this time

file 73 lines (63 sloc) 2.273 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
/*
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.

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.

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 "shaders.h"

#include "ifilesystem.h"

#include "stream/stringstream.h"

#include "gtkdlgs.h"

void ViewShader(const char *pFile, const char *pName)
{
  char* pBuff = 0;
  //int nSize =
  vfsLoadFile(pFile, reinterpret_cast<void**>(&pBuff));
  if (pBuff == 0)
  {
    globalErrorStream() << "Failed to load shader file " << pFile << "\n";
    return;
  }
  // look for the shader declaration
  StringOutputStream strFind(string_length(pName));
  strFind << LowerCase(pName);
  StringOutputStream strLook(string_length(pBuff));
  strFind << LowerCase(pBuff);
  // offset used when jumping over commented out definitions
  std::size_t nOffset = 0;
  while (true)
  {
    const char* substr = strstr(strFind.c_str() + nOffset, strFind.c_str());
    if (substr == 0)
      break;
    std::size_t nStart = substr - strLook.c_str();
    // we have found something, maybe it's a commented out shader name?
    char *strCheck = new char[string_length(strLook.c_str())+1];
    strcpy( strCheck, strLook.c_str() );
    strCheck[nStart] = 0;
    char *pCheck = strrchr( strCheck, '\n' );
    // if there's a commentary sign in-between we'll continue
    if (pCheck && strstr( pCheck, "//" ))
    {
      delete[] strCheck;
      nOffset = nStart + 1;
      continue;
    }
    delete[] strCheck;
    nOffset = nStart;
    break;
  }
  // now close the file
  vfsFreeFile(pBuff);

  DoTextEditor (pFile, static_cast<int>(nOffset));
}
Something went wrong with that request. Please try again.