34 #include <sys/types.h>
53 int inList(
const char *var,
const char **Vec)
56 while(Vec[i] && strcmp(Vec[i],var)) i++;
66 std::cerr <<
"\n Usage: cconfig -c <cfn> [-h <host>] [-n <name>] [-x <prog>] [<args>]"
67 "\n<args>: [[pfx]*]<directive> | <directive>[*[sfx]] [<args>]" <<std::endl;
75 int main(
int argc,
char *argv[])
77 static const char *Pgm =
"cconfig: ";
88 const char *Cfn = 0, *Host = 0, *Name = 0, *Xeq =
"xrootd";
89 const char *noSub[] = {
"cms.prepmsg",
"ofs.notifymsg",
"oss.stagemsg",
90 "frm.xfr.copycmd", 0};
91 const char *ifChk[] = {
"xrd.port",
"all.role",
"all.manager", 0};
92 const char *slChk[] = {
"frm.xfr.copycmd", 0};
94 char buff[4096], *var, c;
95 int i, retc = 0, cfgFD, chkQ = 0;
100 if (argc > 1 &&
'-' == *argv[1])
101 while ((c = getopt(argc,argv,
":c:h:n:x:")) && ((
unsigned char)c != 0xff))
104 case 'c': Cfn = optarg;
106 case 'h': Host= optarg;
108 case 'n': Name= optarg;
110 case 'x': Xeq = optarg;
112 default: sprintf(buff,
"'%c'",
optopt);
113 if (c ==
':')
Say.
Say(Pgm, buff,
" value not specified.");
114 else Say.
Say(Pgm, buff,
" option is invalid.");
121 if (!Cfn) {
Say.
Say(Pgm,
"Config file not specified.");
Usage(1);}
125 if (!Host) Host = theAddr.
Name();
126 else if (!theAddr.
Set(Host,0)) Host = theAddr.
Name();
127 if (!Host) {
Say.
Say(Pgm,
"Unable to determine host name."); exit(3);}
132 chkQ = (DirQ.
First() != 0);
136 if ( (cfgFD =
open(Cfn, O_RDONLY, 0)) < 0)
144 sprintf(buff,
"%s %s@%s", Xeq, Name, Host);
150 while((var =
Config->GetMyFirstWord()))
151 {
if (chkQ && !DirQ.
Find(var)) {
Config->noEcho();
continue;}
154 while((var =
Config->GetWord()) && *var !=
'/') {}
155 oldEnv =
Config->SetEnv(0);
156 if (var)
Config->GetRest(buff,
sizeof(buff));
159 else if (
inList(var, ifChk))
160 {
while((var =
Config->GetWord()) && strcmp(var,
"if")) {}
163 {
Config->noEcho();
continue;}
165 else Config->GetRest(buff,
sizeof(buff));
171 if ((retc =
Config->LastError()))
172 {
Say.
Say(Pgm,
XrdSysE2T(retc),
" reading config file ", Cfn); retc = 8;}
int main(int argc, char *argv[])
int inList(const char *var, const char **Vec)
int open(const char *path, int oflag,...)
const char * XrdSysE2T(int errcode)
const char * Name(const char *eName=0, const char **eText=0)
const char * Set(const char *hSpec, int pNum=PortInSpec)
XrdOucNList * Find(const char *name)
void Replace(const char *name, int nval)
static const char * InstName(int TranOpt=0)
static int doIf(XrdSysError *eDest, XrdOucStream &Config, const char *what, const char *hname, const char *nname, const char *pname)
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)