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

« back to all changes in this revision

Viewing changes to libaqsistypes/posix/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
 
 
28
#include        <string.h>
 
29
#include        <ctype.h>
 
30
#include        <glob.h>
 
31
 
 
32
#include        "aqsis.h"
 
33
 
 
34
#include        "file.h"
 
35
#include        "config.h"
 
36
 
 
37
START_NAMESPACE( Aqsis )
 
38
 
 
39
//---------------------------------------------------------------------
 
40
/** Given a string representing a filename with wildcards, return a list
 
41
 * of filenames that match that string.
 
42
*/
 
43
std::list<CqString*> CqFile::Glob ( const CqString& strFileGlob )
 
44
{
 
45
    glob_t globbuf;
 
46
    const char *pt = strFileGlob.c_str();
 
47
 
 
48
    globbuf.gl_offs = 0;
 
49
    glob( pt, GLOB_DOOFFS, NULL, &globbuf );
 
50
 
 
51
    std::list<CqString*> result;
 
52
    int i;
 
53
    for ( i = 0;i < globbuf.gl_pathc;i++ )
 
54
    {
 
55
        result.push_front( new CqString( globbuf.gl_pathv[ i ] ) );
 
56
    }
 
57
 
 
58
    globfree( &globbuf );
 
59
    return result;
 
60
}
 
61
 
 
62
 
 
63
 
 
64
//---------------------------------------------------------------------
 
65
/** Get the searchpath for a the specified asset type. The way in which the
 
66
 *  searchpath is specified is OS specific. Under Windows, environment variables
 
67
 *  are used.
 
68
 *
 
69
 *  \param strAsset The name of the asset whose searchpath is to be returned, i.e. "shaders".
 
70
 *  \return A string containing the ":" separated list of searchpaths.
 
71
 */
 
72
 
 
73
CqString CqFile::GetSystemSetting( const CqString& strAsset )
 
74
{
 
75
    char * env;
 
76
    char* base_path;
 
77
    CqString result( "" );
 
78
 
 
79
    if ( ( env = getenv( "AQSIS_BASE_PATH" ) ) != NULL )
 
80
    {
 
81
        base_path = env;
 
82
    }
 
83
    else
 
84
    {
 
85
        // use the default from the build system
 
86
        base_path = BASE_PATH;
 
87
    };
 
88
 
 
89
 
 
90
    if ( strAsset.compare( "base" ) == 0 )
 
91
    {
 
92
        result = base_path;
 
93
    }
 
94
    else if ( strAsset.compare( "config" ) == 0 )
 
95
    {
 
96
        if ( ( env = getenv( "AQSIS_CONFIG" ) ) != NULL )
 
97
            result = env;
 
98
        else
 
99
        {
 
100
            result = CONFIG_PATH;
 
101
            result.append( "/aqsisrc" );
 
102
        }
 
103
 
 
104
        std::ifstream cfgfile( result.c_str() );
 
105
        if ( !cfgfile.is_open() )
 
106
            if ( ( env = getenv( "HOME" ) ) != NULL )
 
107
            {
 
108
                result = env;
 
109
                result.append( "/.aqsisrc" );
 
110
                std::ifstream cfgfile( result.c_str() );
 
111
                if ( !cfgfile.is_open() )
 
112
                {
 
113
                    result = ".aqsisrc";
 
114
                }
 
115
            }
 
116
    }
 
117
    else if ( strAsset.compare( "shaders" ) == 0 )
 
118
    {
 
119
        if ( ( env = getenv( "AQSIS_SHADERS_PATH" ) ) != 0 )
 
120
            result = env;
 
121
        else
 
122
        {
 
123
            result = CqString( ".:" ) + base_path;
 
124
            result.append( "/shaders" );
 
125
        }
 
126
    }
 
127
    else if ( strAsset.compare( "archives" ) == 0 )
 
128
    {
 
129
        if ( ( env = getenv( "AQSIS_ARCHIVES_PATH" ) ) != 0 )
 
130
            result = env;
 
131
        else
 
132
        {
 
133
            result = CqString( ".:" ) + base_path;
 
134
            result.append( "/archives" );
 
135
        }
 
136
    }
 
137
    else if ( strAsset.compare( "textures" ) == 0 )
 
138
    {
 
139
        if ( ( env = getenv( "AQSIS_TEXTURES_PATH" ) ) != 0 )
 
140
            result = env;
 
141
        else
 
142
        {
 
143
            result = CqString( ".:" ) + base_path;
 
144
            result.append( "/textures" );
 
145
        }
 
146
    }
 
147
    else if ( strAsset.compare( "displays" ) == 0 )
 
148
    {
 
149
        if ( ( env = getenv( "AQSIS_DISPLAYS_PATH" ) ) != 0 )
 
150
            result = env;
 
151
        else
 
152
        {
 
153
            result = base_path;
 
154
            result.append( "/displays" );
 
155
        }
 
156
    }
 
157
    else if ( strAsset.compare( "procedurals" ) == 0 )
 
158
    {
 
159
        if ( ( env = getenv( "AQSIS_PROCEDURALS" ) ) != 0 )
 
160
            result = env;
 
161
        else
 
162
        {
 
163
            result = CqString( ".:" ) + base_path;
 
164
            result.append( "/procedurals" );
 
165
        }
 
166
    }
 
167
    else if ( strAsset.compare( "dsolibs" ) == 0 )
 
168
    {
 
169
        if ( ( env = getenv( "AQSIS_DSO_LIBS" ) ) != 0 )
 
170
            result = env;
 
171
        else
 
172
        {
 
173
            result = base_path;
 
174
            result.append( "/dso" );
 
175
        }
 
176
    }
 
177
 
 
178
    return ( result );
 
179
}
 
180
 
 
181
CqString CqFile::FixupPath(CqString& strPath)
 
182
{
 
183
    return( strPath );
 
184
}
 
185
 
 
186
 
 
187
END_NAMESPACE( Aqsis )
 
188
//---------------------------------------------------------------------