#include <MINFScript.h>
Public Member Functions | |
| MINFScript () | |
| virtual | ~MINFScript () |
| virtual EParseResult | ParseMacro () |
| virtual void | RunScript () |
| virtual void | SetScriptFileName () |
Private Member Functions | |
| void | init () |
Private Attributes | |
| Text_t | fScriptFileName [255] |
| AddParmDlg * | fParDlg |
| name of input data file | |
|
|
Definition at line 50 of file MINFScript.cxx. References init().
|
|
|
Definition at line 65 of file MINFScript.cxx. 00066 {
00067 delete fParDlg;
00068 }
|
|
|
Definition at line 57 of file MINFScript.cxx. References MINFast::Display(), fParDlg, fScriptFileName, MINFDisplay::GetMINFGUIPanel(), and gMINFast. 00058 {
00059 fScriptFileName[0] = '\0';
00060 fParDlg = new AddParmDlg(gClient->GetRoot(), (TGWindow *)
00061 (gMINFast->Display()->GetMINFGUIPanel()), 310, 210);
00062 }
|
|
|
Definition at line 71 of file MINFScript.cxx. References count, EParseResult, fParDlg, fScriptFileName, gSystem(), AddParmDlg::SetArgs(), and AddParmDlg::SetReqArgs(). Referenced by RunScript(). 00072 {
00073
00074 // consts needed for parsing.
00075 const char kLeftBracket = '(';
00076 const char kRightBracket = ')';
00077 const char kComma = ',';
00078 const char kSpace = ' ';
00079 const char kCommentTokenOne = '/';
00080 const char kCommentTokenTwo = '*';
00081 const char kQuote = '"';
00082 const char kPPSymbol = '#';
00083 const char kSingleQuote = '\'';
00084 const char kSlash = '\\';
00085 const char kEqual = '=';
00086
00087 Char_t i;
00088
00089 Char_t funcProto[256] = "\0", tmpbuffer[256] = "\0";
00090 Char_t *mainOfMacro;
00091
00092 Int_t OldCommentsEnd = 0; // if `1' we found `*/'.
00093 Int_t ReadArguments = 0; // if `1' we found macro's `main(...)'.
00094 Int_t SpaceJump = 0; // if `1' we read a sequence of spaces.
00095 Int_t count, matched = 0,
00096 argcount = 0, required = 0,
00097 p = 0;
00098
00099 // check if we have an ASCII file.
00100 Long_t flags;
00101 gSystem->GetPathInfo(fScriptFileName, (Long_t *) 0,
00102 (Long_t *) 0, &flags, (Long_t *) 0);
00103 if ((Int_t)flags != 0) {
00104 cerr << "MINFScript::ParseMacro() - Unknown Format." << endl;
00105 return kNOMACRO;
00106 }
00107
00108 // open macro for parsing.
00109 ifstream macroStream(fScriptFileName, ios::in);
00110 if (!macroStream) {
00111 cerr << "MINFScript::ParseMacro() - Can't Open File." << endl;
00112 return kNOMACRO;
00113 }
00114
00115 // cut extension and path from macro's filename. This is the name
00116 // of the function we must find in macro's source code.
00117 sprintf(tmpbuffer, fScriptFileName);
00118 mainOfMacro = strrchr(tmpbuffer, '/');
00119 mainOfMacro = strtok(mainOfMacro, ".C");
00120 mainOfMacro++;
00121
00122 count = strlen(mainOfMacro);
00123
00124 while (1) {
00125
00126 start_parsing:
00127
00128 // we parsed the whole file and no main function found.
00129 if (macroStream.eof()) {
00130 if (ReadArguments) {
00131 // eof() while we were reading arguments, this happened
00132 // due to a syntax error, so we abort running.
00133 cerr << "MINFScript::ParseMacro() - An error occurred!"
00134 << endl;
00135 return kNOMACRO;
00136 } else return kUNNAMEDMACRO;
00137 }
00138
00139 i = macroStream.get();
00140
00141 // read until we find a non-space char.
00142 SpaceJump = 0;
00143 while (i == kSpace) {
00144 i = macroStream.get();
00145 SpaceJump = 1;
00146 }
00147
00148 switch (i) {
00149 // check for string in preprocessor's statements.
00150 case kPPSymbol:
00151 // skip a line.
00152 while (i != '\n') i = macroStream.get();
00153 goto start_parsing;
00154
00155 // check for string inside quotes.
00156 case kQuote:
00157 // skip until we find another one.
00158 while (i != kQuote) {
00159 i = macroStream.get();
00160 if (i == kSlash) {
00161 // read 2 chars in case it was "...\"...".
00162 i = macroStream.get();
00163 i = macroStream.get();
00164 }
00165 // in case of a macro syntax error,
00166 // we don't want to get in an endless loop.
00167 if (macroStream.eof()) {
00168 cerr << "MINFScript::ParseMacro() - An error occurred!"
00169 << endl;
00170 return kNOMACRO;
00171 }
00172
00173 }
00174 goto start_parsing;
00175
00176 // chech for chars inside single quotes.
00177 case kSingleQuote:
00178 // skip until we find another one.
00179 while (i != kSingleQuote) {
00180 i = macroStream.get();
00181 if (i == kSlash) {
00182 // read 2 chars in case it was '\''.
00183 i = macroStream.get();
00184 i = macroStream.get();
00185 }
00186 // in case of a macro syntax error,
00187 // we don't want to get in an endless loop.
00188 if (macroStream.eof()) {
00189 cerr << "MINFScript::ParseMacro() - An error occurred!"
00190 << endl;
00191 return kNOMACRO;
00192 }
00193
00194 }
00195 goto start_parsing;
00196
00197 // check for comments.
00198 case kCommentTokenOne:
00199 i = macroStream.get();
00200 if (i == kCommentTokenOne) {
00201 // skip a line.
00202 while (i != '\n') i = macroStream.get();
00203 goto start_parsing;
00204 }
00205 else if (i == kCommentTokenTwo) {
00206 // skip until we catch '*/'.
00207 OldCommentsEnd = 0;
00208 while (!OldCommentsEnd) {
00209 i = macroStream.get();
00210 if (i == kCommentTokenTwo) {
00211 i = macroStream.get();
00212 if (i == kCommentTokenOne) OldCommentsEnd = 1;
00213 }
00214 // in case of a macro syntax error,
00215 // we don't want to get in an endless loop.
00216 if (macroStream.eof()) {
00217 cerr << "MINFScript::ParseMacro() - An error occurred!"
00218 << endl;
00219 return kNOMACRO;
00220 }
00221 }
00222 }
00223 goto start_parsing;
00224 } /* switch (i) */
00225
00226 // did we find macro's main function body?
00227 if (matched == (count-1)) {
00228 if (i == kLeftBracket) {
00229 ReadArguments = 1;
00230 cout << "MINFScript::ParseMacro() - Guessed Prototype: ";
00231 }
00232 matched = 0;
00233 goto start_parsing;
00234 }
00235
00236 // we found macro's main function body.
00237 if (ReadArguments) {
00238 // dump args.
00239 if (SpaceJump == 1) cout << ' ';
00240 if (i == kRightBracket) break;
00241 cout << i;
00242 // store prototype in an array (without spaces).
00243 funcProto[p++] = i;
00244 goto start_parsing;
00245 }
00246
00247 // check for macro's `main' function.
00248 while (i == mainOfMacro[matched] && matched < (count-1)) {
00249 i = macroStream.get();
00250 matched++;
00251 }
00252
00253 // not a real match!
00254 if (matched != (count-1)) {
00255 matched = 0;
00256 goto start_parsing;
00257 }
00258 } /* while (1) */
00259
00260 // close macro file.
00261 macroStream.close();
00262
00263 // analyze prototype. Macro has no args in case of:
00264 // (a) prototype is a zero-length string.
00265 // (b) prototype is: "void".
00266 if (strlen(funcProto) && strcmp(funcProto, "void")) argcount++;
00267 if (argcount) {
00268 while (p) {
00269 if (funcProto[p] == kComma) argcount++;
00270 if (funcProto[p] == kEqual) required++;
00271 p--;
00272 }
00273 required = argcount - required;
00274 }
00275 cout << " -- Arguments: " << argcount << endl;
00276 cout << "Required Arguments (at least): " << required << endl;
00277
00278
00279 if (argcount == 0)
00280 return kMACROWITHOUTARGS;
00281 else {
00282 fParDlg->SetArgs(argcount);
00283 fParDlg->SetReqArgs(required);
00284 return kMACROWITHARGS;
00285 }
00286 }
|
|
|
Definition at line 289 of file MINFScript.cxx. References EParseResult, fParDlg, fScriptFileName, kMACROWITHARGS, kMACROWITHOUTARGS, kNOMACRO, kUNNAMEDMACRO, ParseMacro(), AddParmDlg::PopUpParmDialog(), and AddParmDlg::SetMacroName(). Referenced by MINFast::RunScript(). 00290 {
00291 Text_t cintLine[255];
00292 EParseResult parseResult;
00293
00294 // user has clicked on Cancel.
00295 if (!fScriptFileName) return;
00296
00297 // Save previous active pad.
00298 TVirtualPad *padsave = gPad;
00299
00300 // Parse macro's source.
00301 parseResult = ParseMacro();
00302
00303 switch(parseResult) {
00304 case kNOMACRO:
00305 break;
00306 case kMACROWITHARGS:
00307 // pop up the add parameters dialog.
00308 fParDlg->SetMacroName(fScriptFileName);
00309 fParDlg->PopUpParmDialog();
00310 // fScriptFileName now contains the desired parameters,
00311 // so go to next statement and execute the concatenated
00312 // fScriptFileName.
00313 parseResult = kMACROWITHOUTARGS;
00314 case kMACROWITHOUTARGS:
00315 // ROOT tries to find a filename identical to macro's name
00316 // + parameters and fails to execute it, so gROOT->Macro()
00317 // cannot be used here. We must force CINT to process line:
00318 // ".x macroname.C(parameters)", instead.
00319 strcpy(cintLine, ".x ");
00320 strcat(cintLine, fScriptFileName);
00321 gROOT->ProcessLine(cintLine);
00322 break;
00323 case kUNNAMEDMACRO:
00324 gROOT->Macro(fScriptFileName);
00325 break;
00326 }
00327
00328 gPad = padsave;
00329 }
|
|
|
Definition at line 332 of file MINFScript.cxx. References MINFast::Display(), fScriptFileName, MINFDisplay::GetMINFGUIPanel(), and gMINFast. Referenced by MINFast::RunScript(). 00333 {
00334 const char *filetypes[] = { "ROOT macros", "*.C",
00335 "ROOT files", "*.root",
00336 "All files", "*",
00337 0, 0 };
00338
00339 // Use file browser to let user choose input filename.
00340 TGFileInfo fi;
00341 fi.fFileTypes = filetypes;
00342 new TGFileDialog(gClient->GetRoot(), (TGWindow *)
00343 (gMINFast->Display()->GetMINFGUIPanel()),kFDOpen, &fi);
00344
00345 // Attach reroot file of MINOS data.
00346 if (fi.fFilename && strlen(fi.fFilename)) {
00347 strcpy(fScriptFileName, fi.fFilename);
00348 }
00349 }
|
|
|
name of input data file
Definition at line 56 of file MINFScript.h. Referenced by init(), ParseMacro(), and RunScript(). |
|
|
Definition at line 55 of file MINFScript.h. Referenced by init(), ParseMacro(), RunScript(), and SetScriptFileName(). |
1.3.9.1