#include #include #include #include #include "d_env.h" using namespace std; // ------------------------------------------------------------------------ d_env::d_env( void ) { int i; int cnt = 0; extern char **environ; while( environ[cnt] != NULL ) { cnt++; } envar.resize(cnt); for( i = 0; i < cnt; i++ ) { if( environ[i] != NULL ) { envar[i] = environ[i]; } } } // ------------------------------------------------------------------------ // returns line that contains string w string d_env::get( char * w ) { int i, l; for( i = 0; i < envar.size(); i++ ) { l = envar[i].find( w ); if( l == 0 ) return envar[i]; } return string(""); } // ------------------------------------------------------------------------ // returns string value of the line that contains string w string d_env::gets( char * w ) { int i, l, r1, r2; for( i = 0; i < envar.size(); i++ ) { l = envar[i].find( w ); if( l == 0 ) { r1 = envar[i].find( "=", 0 ) + 1; r2 = envar[i].size() - r1; return envar[i].substr(r1, r2); } } return string(""); } // ------------------------------------------------------------------------ // returns integer value of the line that contains string w int d_env::geti( char * w ) //string d_env::getv( char * w ) { int i, l, r1, r2; char tmp[12]; string tmp2; for( i = 0; i < envar.size(); i++ ) { l = envar[i].find( w ); if( l == 0 ) { r1 = envar[i].find( "=", 0 ) + 1; r2 = envar[i].size() - r1; //return envar[i].substr(r1, r2); tmp2 = envar[i].substr(r1, r2); //strcpy( tmp, envar[i].substr(r1,r2); strcpy( tmp, tmp2.c_str() ); return( atoi( tmp ) ); } } //return string(""); return( -1 ); } // ------------------------------------------------------------------------ ostream &operator<< (ostream &out, const d_env &L ) { int i; for( i = 0; i < L.envar.size(); i++ ) { //cout << i << " = " << envar[i] << endl; out << i << " = " << L.envar[i] << endl; } return( out ); } // ------------------------------------------------------------------------