| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- File List
- File Members

# Environment.cpp File Reference

`#include "GaudiKernel/Environment.h"`

Include dependency graph for Environment.cpp:

Go to the source code of this file.

## Functions
std::string | i_resolve (std::string &source, int recursions)
StatusCode | System::resolveEnv (const std::string &var, std::string &res, int recursions)
std::string | System::homeDirectory ()
std::string | System::tempDirectory ()

## Function Documentation

std::string @375::i_resolve | ( | std::string & | source,
|  | int | recursions |
| ) |  |  | `[static]`

Definition at line 4 of file Environment.cpp.

References c, std::basic_string< _CharT, _Traits, _Alloc >::c_str(), std::basic_string< _CharT, _Traits, _Alloc >::find(), std::basic_string< _CharT, _Traits, _Alloc >::npos, and std::basic_string< _CharT, _Traits, _Alloc >::replace().

Referenced by System::resolveEnv().

    00004                                                           {
    00005     if ( recursions > 0 )  {
    00006       int lvl = 0, mx_lvl = 0;
    00007       for(const char* c=source.c_str(), *beg=0; *c != 0; ++c)  {
    00008         switch ( *c )  {
    00009           case '$':
    00010             if ( *(c+1) == '{' )  {
    00011               lvl++;
    00012               if ( lvl > mx_lvl )  {
    00013                 mx_lvl = lvl;
    00014                 beg = c;
    00015               }
    00016               c += 2;
    00017             }
    00018             break;
    00019           case '}':
    00020             if ( lvl == mx_lvl )  {
    00021               std::string env(beg+2,c-beg-2);
    00022               const char* res = ::getenv(env.c_str());
    00023               std::string rep = (res) ? std::string(res) : i_resolve(env,--recursions);
    00024               if ( rep.length() )  {
    00025                 std::string e(beg,c-beg+1);
    00026                 size_t idx=std::string::npos;
    00027                 while((idx=source.find(e)) != std::string::npos)  {
    00028                   source.replace(idx, e.length(), rep);
    00029                 }
    00030                 return i_resolve(source, --recursions);
    00031               }
    00032               else  {
    00033                 // error: environment cannot be reolved....
    00034                 // Try to continue, but there is not too much hope.
    00035               }
    00036             }
    00037             lvl--;
    00038             break;
    00039           default:
    00040             break;
    00041         }
    00042       }
    00043     }
    00044     return source;
    00045   }