~ubuntu-branches/ubuntu/warty/aqsis/warty

« back to all changes in this revision

Viewing changes to libaqsistypes/win32/intel/file_system.cpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:25:04 UTC
  • Revision ID: james.westby@ubuntu.com-20040824072504-zf993vnevvisdsvb
Tags: upstream-0.9.1
Import upstream version 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Aqsis
 
2
// Copyright � 1997 - 2001, Paul C. Gregory
 
3
//
 
4
// Contact: pgregory@aqsis.com
 
5
//
 
6
// This library is free software; you can redistribute it and/or
 
7
// modify it under the terms of the GNU General Public
 
8
// License as published by the Free Software Foundation; either
 
9
// version 2 of the License, or (at your option) any later version.
 
10
//
 
11
// This library is distributed in the hope that it will be useful,
 
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
// General Public License for more details.
 
15
//
 
16
// You should have received a copy of the GNU General Public
 
17
// License along with this library; if not, write to the Free Software
 
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 
 
20
 
 
21
/** \file
 
22
                \brief Implements the system specific parts of the CqFile class for handling files.
 
23
                \author Paul C. Gregory (pgregory@aqsis.com)
 
24
*/
 
25
 
 
26
#include        <fstream>
 
27
#include        <list>
 
28
 
 
29
#include        <string.h>
 
30
#include        <ctype.h>
 
31
#include        <io.h>
 
32
#include        <direct.h>
 
33
 
 
34
#include        "aqsis.h"
 
35
 
 
36
#include        "file.h"
 
37
 
 
38
START_NAMESPACE( Aqsis )
 
39
 
 
40
//---------------------------------------------------------------------
 
41
/** Given a string representing a filename with wildcards, return a list
 
42
 * of filenames that match that string.
 
43
*/
 
44
std::list<CqString*> CqFile::Glob ( const CqString& strFileGlob )
 
45
{
 
46
    _finddata_t c_file;
 
47
    long hFile;
 
48
    const char *pt = strFileGlob.c_str();
 
49
 
 
50
    std::list<CqString*> result;
 
51
    if ( ( hFile = _findfirst( pt, &c_file ) ) != -1L )
 
52
    {
 
53
        /* we found something here; then we list
 
54
        * all of them with the directory first
 
55
        */
 
56
        CqString strFile( c_file.name );
 
57
        result.push_front( &strFile );
 
58
        while ( _findnext( hFile, &c_file ) == 0 )
 
59
        {
 
60
            result.push_front( new CqString( c_file.name ) );
 
61
        }
 
62
        _findclose( hFile );
 
63
    }
 
64
 
 
65
    return result ;
 
66
}
 
67
 
 
68
 
 
69
 
 
70
//---------------------------------------------------------------------
 
71
/** Get the searchpath for a the specified asset type. The way in which the
 
72
 *  searchpath is specified is OS specific. Under Windows, environment variables
 
73
 *  are used.
 
74
 *
 
75
 *  \param strAsset The name of the asset whose searchpath is to be returned, i.e. "shaders".
 
76
 *  \return A string containing the ":" separated list of searchpaths.
 
77
 */
 
78
 
 
79
CqString CqFile::GetSystemSetting( const CqString& strAsset )
 
80
{
 
81
    char * env;
 
82
    char* base_path = ".";
 
83
    CqString result( "" );
 
84
 
 
85
    if ( ( env = getenv( "AQSIS_BASE_PATH" ) ) != NULL )
 
86
        base_path = env;
 
87
 
 
88
 
 
89
    if ( strAsset.compare( "base" ) == 0 )
 
90
    {
 
91
        result = base_path;
 
92
    }
 
93
    else if ( strAsset.compare( "config" ) == 0 )
 
94
    {
 
95
        if ( ( env = getenv( "AQSIS_CONFIG" ) ) != NULL )
 
96
            result = env;
 
97
        else
 
98
        {
 
99
            result = base_path;
 
100
            result.append( "/.aqsisrc" );
 
101
        }
 
102
 
 
103
        std::ifstream cfgfile( result.c_str() );
 
104
        if ( !cfgfile.is_open() )
 
105
            if ( ( env = getenv( "HOME" ) ) != NULL )
 
106
            {
 
107
                result = env;
 
108
                result.append( "/.aqsisrc" );
 
109
                std::ifstream cfgfile( result.c_str() );
 
110
                if ( !cfgfile.is_open() )
 
111
                {
 
112
                    result = ".aqsisrc";
 
113
                }
 
114
            }
 
115
    }
 
116
    else if ( strAsset.compare( "shaders" ) == 0 )
 
117
    {
 
118
        if ( ( env = getenv( "AQSIS_SHADERS_PATH" ) ) != 0 )
 
119
            result = env;
 
120
        else
 
121
        {
 
122
            result = base_path;
 
123
            result.append( "/shaders" );
 
124
        }
 
125
    }
 
126
    else if ( strAsset.compare( "archives" ) == 0 )
 
127
    {
 
128
        if ( ( env = getenv( "AQSIS_ARCHIVES_PATH" ) ) != 0 )
 
129
            result = env;
 
130
        else
 
131
        {
 
132
            result = base_path;
 
133
            result.append( "/archives" );
 
134
        }
 
135
    }
 
136
    else if ( strAsset.compare( "textures" ) == 0 )
 
137
    {
 
138
        if ( ( env = getenv( "AQSIS_TEXTURES_PATH" ) ) != 0 )
 
139
            result = env;
 
140
        else
 
141
        {
 
142
            result = base_path;
 
143
            result.append( "/textures" );
 
144
        }
 
145
    }
 
146
    else if ( strAsset.compare( "displays" ) == 0 )
 
147
    {
 
148
        if ( ( env = getenv( "AQSIS_DISPLAYS_PATH" ) ) != 0 )
 
149
            result = env;
 
150
        else
 
151
        {
 
152
            result = base_path;
 
153
            result.append( "/displays" );
 
154
        }
 
155
    }
 
156
    else if ( strAsset.compare( "dsolibs" ) == 0 )
 
157
    {
 
158
        if ( ( env = getenv( "AQSIS_DSO_LIBS" ) ) != 0 )
 
159
            result = env;
 
160
        else
 
161
        {
 
162
            result = base_path;
 
163
            result.append( "/dso" );
 
164
        }
 
165
    }
 
166
 
 
167
    return ( result );
 
168
}
 
169
 
 
170
 
 
171
CqString CqFile::FixupPath(CqString& strPath)
 
172
{
 
173
    if( strPath.find("//",0,2) == 0 )
 
174
    {
 
175
        if(strPath[3] == '/')
 
176
        {
 
177
            CqString strNewPath(strPath.substr(2,1));
 
178
            strNewPath.append(":/");
 
179
            strNewPath.append(strPath.substr(4));
 
180
            //std::cout << strNewPath.c_str() << std::endl;
 
181
            return(strNewPath);
 
182
        }
 
183
    }
 
184
 
 
185
    return( strPath );
 
186
}
 
187
 
 
188
 
 
189
END_NAMESPACE( Aqsis )
 
190
//---------------------------------------------------------------------