Back to index

nordugrid-arc-nox  1.1.0~rc6
gridmap.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <string>
00006 #include <fstream>
00007 #include "environment.h"
00008 #include "conf.h"
00009 #include "gridmap.h"
00010 
00011 #if defined __GNUC__ && __GNUC__ >= 3
00012 
00013 #include <limits>
00014 #define istream_readline(__f,__s,__n) {      \
00015    __f.get(__s,__n,__f.widen('\n'));         \
00016    if(__f.fail()) __f.clear();               \
00017    __f.ignore(std::numeric_limits<std::streamsize>::max(), __f.widen('\n')); \
00018 }
00019 
00020 #else
00021 
00022 #define istream_readline(__f,__s,__n) {      \
00023    __f.get(__s,__n,'\n');         \
00024    if(__f.fail()) __f.clear();               \
00025    __f.ignore(INT_MAX,'\n'); \
00026 }
00027 
00028 #endif
00029 
00030 bool gridmap_user_list(std::string &ulist) {
00031   std::string path = globus_gridmap();
00032   std::ifstream f(path.c_str()); 
00033   if(! f.is_open() ) return false;
00034   for(;!f.eof();) {
00035     char buf[512];
00036     istream_readline(f,buf,sizeof(buf));
00037     std::string rest = buf;
00038     std::string name = "";
00039     for(;rest.length() != 0;) {
00040       name=config_next_arg(rest);
00041     };
00042     if(name.length() == 0) continue;
00043     std::string::size_type pos;
00044     if((pos=ulist.find(name)) != std::string::npos) {
00045       if(pos!=0) 
00046         if(ulist[pos-1] != ' ') { ulist+=" "+name; continue; };
00047       pos+=name.length();
00048       if(pos < ulist.length())
00049         if(ulist[pos] != ' ') { ulist+=" "+name; continue; };
00050     }
00051     else { ulist+=" "+name; };
00052   };
00053   f.close();
00054   return true;
00055 }
00056 
00057 bool gridmap_user_list(std::list<std::string> &ulist) {
00058   std::string path = globus_gridmap();
00059   std::ifstream f(path.c_str()); 
00060   if(! f.is_open() ) return false;
00061   for(;!f.eof();) {
00062     char buf[512];
00063     istream_readline(f,buf,sizeof(buf));
00064     std::string rest = buf;
00065     std::string name = "";
00066     for(;rest.length() != 0;) {
00067       name=config_next_arg(rest);
00068     };
00069     if(name.length() == 0) continue;
00070     std::string::size_type pos;
00071     for(std::list<std::string>::iterator u = ulist.begin();
00072                           u != ulist.end(); ++u) {
00073       if(name == *u) { name.resize(0); break; };
00074     };
00075     if(name.length() == 0) continue;
00076     ulist.push_back(name);
00077   };
00078   f.close();
00079   return true;
00080 }