| # Gaudi Framework, version v21r10p1 |

Home |  | Generated: 29 Jul 2010

# Environment.cpp File Reference

`#include "GaudiKernel/Environment.h"`
`#include <cstdlib>`

Include dependency graph for Environment.cpp:

Go to the source code of this file.

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

## Function Documentation

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

Definition at line 5 of file Environment.cpp.

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