GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: Add Line Numbers


A Paste by Anonymous
#include "CShader.h"
#include "CDebug.h"
#include "mmgr.h"

CShader::CShader()
{
    cut = new char[512];
    memset(cut,0,512);
}



char* CShader::LoadAll(char *folder)
{
    FILE *fp[500];
    WIN32_FIND_DATA FindFileData;
    HANDLE hFind;
    int files=1;

    char *buffer;
    int  fpsize=0;


    char list[500][128];

    sbuf = new char[1000000];
    memset(sbuf,0,1000000);

    char buf2[128];
    char buf3[128];

    GetCurrentDirectory(128,buf2);
    GetCurrentDirectory(128,buf3);
  

    sprintf(buf2,"%s/%s",buf2,folder);

    SetCurrentDirectory(buf2);

    GetCurrentDirectory(1000,buf2);

    const char search[] = "*.shader";

    hFind = FindFirstFile(search, &FindFileData);

    sprintf(list[0], FindFileData.cFileName); 

    while(FindNextFile(hFind,&FindFileData)) 
    {    
        files++;
        sprintf(list[files-1], FindFileData.cFileName);
    }
  
    FindClose(hFind);

    for(int i=0;i<files;i++) {
        fp[i] = fopen(list[i],"rb");    

          fseek (fp[i] , 0 , SEEK_END);
        fpsize = ftell (fp[i]);
        rewind (fp[i]);
    
        buffer = new char [fpsize+1];

        memset(buffer,0,fpsize+1);

        fread (buffer,1,fpsize,fp[i]);

        strcat(sbuf,buffer);
        delete [] buffer;
    }

    SetCurrentDirectory(buf3);

    

    return sbuf;
}




char* CShader::Search(char *shadername)
{

    if(strstr(sbuf,shadername) !=NULL) {
        if(strstr(strstr(sbuf,shadername),"{")) {
                strcpy(cut,strstr(strstr(sbuf,shadername),"{"));                
                if(strchr(cut,'}', '))*strchr(cut,'}', ')=0;
                return cut;
        } 
    } else {
        return "";
    }


    return "";
}


char* CShader::Parse(char *input,char *cmd)
{    

    if(strstr(input,"map") !=NULL && !strcmp(cmd, "map")) {
        sscanf(strstr(input,"map"), "map %s\n",cut);
        return cut;        
    }

    if(strstr(input,"clampmap") !=NULL && !strcmp(cmd, "clampmap")) {
        sscanf(strstr(input,"clampmap"), "clampmap %s\n",cut);
        return cut;        
    }

    if(strstr(input,"blendfunc") !=NULL && !strcmp(cmd, "blendfunc")) {
        sscanf(strstr(input,"blendfunc"), "blendfunc %s\n",cut);        
        return cut;        
    }

    if(strstr(input,"tcMod rotate") !=NULL && !strcmp(cmd, "tcMod rotate")) {
        int r=0;
        sscanf(strstr(input,"tcMod rotate"), "tcMod rotate %d\n",&r);
        sprintf(cut,"%d",r);
        return cut;        
    }



    return "";
}

void CShader::Free()
{
    delete [] sbuf;
    delete [] cut;
}