Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
cwb_csh2sh.C
Go to the documentation of this file.
1 vector<TString> getFileListFromDir(TString dir_name, TString endString="", TString beginString="");
3 
4 void cwb_csh2sh(TString script = "") {
5 
6  vector<TString> cshList = getFileListFromDir(".", ".csh");
7 
8  for(int i=0;i<cshList.size();i++) {
9 
10  TString ifile=cshList[i];
11  cout << "ifile : " << ifile.Data() << endl;
12  if(script!="") if(!ifile.Contains(script)) continue;
13 
14  ifstream in;
15  in.open(ifile.Data(),ios::in);
16  if (!in.good()) {cout << "Error Opening File : " << ifile.Data() << endl;exit(1);}
17 
19  ofile.ReplaceAll(".csh",".sh");
20  cout << "ofile : " << ofile.Data() << endl;
21 
22  ofstream out;
23  out.open(ofile.Data(),ios::out);
24  if (!out.good()) {cout << "Error Opening File : " << ofile.Data() << endl;exit(1);}
25 
26  char istring[1024];
27  while (1) {
28  in.getline(istring,1024);
29  if (!in.good()) break;
30  TString ostring(istring);
31  if(ostring.Contains("_SKIP_CSH2SH_")) {
32  out << ostring.Data() << endl;
33  continue;
34  }
35  if(!ostring.Contains("_SKIP_csh2sh_")) ostring.ReplaceAll(".csh",".sh");
36  ostring.ReplaceAll("endif","fi");
37  ostring.ReplaceAll("unsetenv","unset");
38  ostring.ReplaceAll("#!/bin/tcsh","#!/bin/bash");
39 
40  bool tag=true;
41  if(ostring.Contains("if")&&ostring.Contains("(")&&ostring.Contains(")")) {
42  tag=true;
43  for(int j=0;j<ostring.Sizeof();j++) if(ostring[j]=='(') {if(tag) tag=false; else ostring[j]=' ';}
44  tag=true;
45  for(int j=ostring.Sizeof()-1;j>=0;j--) if(ostring[j]==')') {if(tag) tag=false; else ostring[j]=' ';}
46 
47  // remove multiple blank characters within "! $?"
48  ostring = RemoveMultipleBlank(ostring,"!","$?");
49 
50  ostring.ReplaceAll("! $?","-z $");
51 
52  ostring.ReplaceAll("$1 == \'\'","-z $1");
53  ostring.ReplaceAll("$2 == \'\'","-z $2");
54  ostring.ReplaceAll("$2 != \'\'","-n $2");
55  ostring.ReplaceAll("$3 == \'\'","-z $3");
56  ostring.ReplaceAll("$3 != \'\'","-n $3");
57  ostring.ReplaceAll("(","[ ");
58  ostring.ReplaceAll("==","=");
59  ostring.ReplaceAll("\'","\"");
60  ostring.ReplaceAll(")"," ]");
61  ostring.ReplaceAll(" then","; then");
62  if(ostring.ReplaceAll("\"$PATH\" !~","! $PATH =~"))
63  {ostring.ReplaceAll(" [ "," [[ ");ostring.ReplaceAll(" ];"," ]];");}
64  if(ostring.ReplaceAll("\"$LD_LIBRARY_PATH\" !~","! $LD_LIBRARY_PATH =~"))
65  {ostring.ReplaceAll(" [ "," [[ ");ostring.ReplaceAll(" ];"," ]];");}
66  if(ostring.ReplaceAll("\"$PYTHONPATH\" !~","! $PYTHONPATH =~"))
67  {ostring.ReplaceAll(" [ "," [[ ");ostring.ReplaceAll(" ];"," ]];");}
68  if(ostring.ReplaceAll("\"$INFOPATH\" !~","! $INFOPATH =~"))
69  {ostring.ReplaceAll(" [ "," [[ ");ostring.ReplaceAll(" ];"," ]];");}
70  ostring.ReplaceAll("*","");
71  ostring.ReplaceAll(" !~ "," != ");
72  }
73 
74  TRegexp re4("set.*=.*\".*setenv.*$");
75  if(ostring.Contains(re4)) {
76  ostring.ReplaceAll("setenv ","export ");
77  ostring.ReplaceAll("set ","");
78  ostring.ReplaceAll("$","= $");
79  ostring.ReplaceAll(" ","");
80  ostring.ReplaceAll("\"export","\"export ");
81  out << ostring.Data() << endl;
82  continue;
83  }
84 
85  ostring.ReplaceAll("exit","return 0");
86  ostring.ReplaceAll("setenv","export");
87  ostring.ReplaceAll("\t"," ");
88  ostring.ReplaceAll("else if","elif");
89 
90  int iblanks=0;
91  for(int j=0;j<ostring.Sizeof();j++) if(ostring[j]==' ') iblanks++; else break;
92  if(!ostring.Contains("$#")) if(ostring.First("#")>0) ostring.Remove(ostring.First("#"));
93  if((ostring.Contains("export")&&!ostring.Contains("unexport"))||ostring.Contains("alias")){
94  TObjArray* token = TString(ostring).Tokenize(TString(' '));
95  TObjString* tok[20];
96  for(int j=0;j<token->GetEntries();j++){ tok[j]=(TObjString*)token->At(j);}
97  ostring = tok[0]->GetString()+" "+tok[1]->GetString()+"="+tok[2]->GetString();
98 
99  if(token->GetEntries()>3){for(int j=3;j<token->GetEntries();j++)
100  {ostring.Append(" ");ostring.Append(tok[j]->GetString());}}
101  } else iblanks=0;
102 
103  TRegexp re1("set.*=.*basename");
104  if(ostring.Contains(re1)) {
105  ostring.ReplaceAll("set","");
106  ostring.ReplaceAll(" ","");
107  ostring.ReplaceAll("basename","basename ");
108  }
109 
110  TRegexp re2("set.*=.*$");
111  if(ostring.Contains(re2)&&!ostring.Contains("alias")) {
112  ostring.ReplaceAll("set","");
113  //ostring.ReplaceAll(" ","");
114  }
115 
116  TRegexp re3("@.*[-=+*:].*[0-9]");
117  if(ostring.Contains(re3)) {
118  ostring.ReplaceAll("@","(( ");
119  ostring = ostring+" ))";
120  }
121 
122  for(int j=0;j<iblanks;j++) out << " "; // restore initials blanks
123  out << ostring.Data() << endl;
124  }
125  out.close();
126  in.close();
127  }
128  exit(0);
129 }
130 
132 
133  TString reg0=left+" .*"+right;
134  TString pat0=left+" "+right;
135 
136  // remove multiple blank characters within "left right"
137  TRegexp t(reg0);
138  int index = string.Index(t);
139  if(index>=0) {
140  TString pat=left;
141  for(int j=index+1; j<string.Sizeof();j++) {if(string[j]=='$') break; pat+=" ";}
142  pat+=right;
143  string.ReplaceAll(pat,pat0);
144  }
145  return string;
146 }
147 
148 vector<TString> getFileListFromDir(TString dir_name, TString endString, TString beginString) {
149 
150  TString wdir = gSystem->WorkingDirectory();
151  TSystemDirectory gdir("", dir_name);
152  TList *dfiles = gdir.GetListOfFiles();
153  TIter dnext(dfiles);
154  TSystemFile *dfile;
155  TString fname;
156  vector<TString> fileList;
157  char path[1024];
158 
159  while ((dfile = (TSystemFile*)dnext())) {
160  fname = dfile->GetName();
161  sprintf(path,"%s/%s",dir_name.Data(),fname.Data());
162  bool fsave=true;
163  if ((endString!="")&&!fname.EndsWith(endString)) fsave=false;
164  if ((beginString!="")&&!fname.BeginsWith(beginString)) fsave=false;
165  if(fsave) fileList.push_back(path);
166  }
167 
168  gSystem->ChangeDirectory(wdir); // restore original dir
169 
170  return fileList;
171 }
172 
wavearray< double > t(hp.size())
TString("c")
cout<< "baudline_FFL : "<< baudline_FFL<< endl;ofstream out;out.open(baudline_FFL, ios::out);if(!out.good()){cout<< "Error Opening File : "<< baudline_FFL<< endl;exit(1);}ifstream in;in.open(frFiles[ifoID], ios::in);if(!in.good()){cout<< "Error Opening File : "<< frFiles[ifoID]<< endl;exit(1);}TString pfile_path="";char istring[1024];while(1){in > istring
Definition: cwb_frdisplay.C:94
char ofile[512]
int j
Definition: cwb_net.C:10
i drho i
ofstream out
Definition: cwb_merge.C:196
void cwb_csh2sh(TString script="")
Definition: cwb_csh2sh.C:4
char fname[1024]
vector< TString > getFileListFromDir(TString dir_name, TString endString="", TString beginString="")
Definition: cwb_csh2sh.C:148
TObjArray * token
TFile * ifile
char tag[256]
Definition: cwb_merge.C:74
TString GetString(TTree *tree, int run, int lag, TString psfix)
Definition: Toolfun.hh:261
TString RemoveMultipleBlank(TString string, TString left, TString right)
Definition: cwb_csh2sh.C:131
ifstream in
cout<< "Starting reading output directory ..."<< endl;vector< TString > fileList
wavearray< int > index
TString dir_name[NDIR]
Definition: cwb_mkdir.C:52
sprintf(tfres,"(1/%g)x(%g) (sec)x(Hz)", 2 *df, df)
exit(0)