00001 00002 // $Id: JobCInterpreter.cxx,v 1.6 2003/10/17 00:10:19 messier Exp $ 00003 // 00004 // messier@huhepl.harvard.edu 00006 #include "JobControl/JobCInterpreter.h" 00007 #include "MessageService/MsgService.h" 00008 #include "JobControl/JobCommand.h" 00009 00010 CVSID("$Id: JobCInterpreter.cxx,v 1.6 2003/10/17 00:10:19 messier Exp $"); 00011 00012 //...................................................................... 00013 00014 JobCInterpreter& operator<<(JobCInterpreter& jci, const char *c) 00015 { 00016 jci.Interp(c); 00017 return jci; 00018 } 00019 00020 //...................................................................... 00021 00022 JobCInterpreter::JobCInterpreter() : 00023 fEchoCommand(false),fBuffer(""), fCmdIndx(0) { } 00024 00025 //...................................................................... 00026 00027 JobCInterpreter::JobCInterpreter(bool echo) : 00028 fEchoCommand(echo),fBuffer(""), fCmdIndx(0) { } 00029 00030 //...................................................................... 00031 00032 JobCInterpreter::~JobCInterpreter() 00033 { 00034 // Delete the job commands in the history list 00035 vector<JobCommand*>::iterator itrend(fCmdList.end()); 00036 vector<JobCommand*>::iterator itr; 00037 for (itr = fCmdList.begin(); itr != itrend; ++itr) { 00038 delete *itr; 00039 } 00040 } 00041 00042 //...................................................................... 00043 00044 void JobCInterpreter::ReadFile(const string& /*filename*/ ) { } 00045 00046 //...................................................................... 00047 00048 void JobCInterpreter::EchoOn() { fEchoCommand = true; } 00049 00050 //...................................................................... 00051 00052 void JobCInterpreter::EchoOff() { fEchoCommand = false; } 00053 00054 //...................................................................... 00055 00056 JobCommand *JobCInterpreter::PopJobCommand() 00057 { 00058 //====================================================================== 00059 // Return the next command in the list 00060 //====================================================================== 00061 if (fCmdIndx<fCmdList.size()) { 00062 JobCommand *jc = fCmdList[fCmdIndx++]; 00063 if (jc) { 00064 if (fEchoCommand) MSG("JobC",Msg::kInfo) << "jobc> " << (*jc) << "\n"; 00065 return jc; 00066 } 00067 } 00068 return 0; 00069 } 00070 00071 //...................................................................... 00072 00073 void JobCInterpreter::PushJobCommand(JobCommand *c) 00074 { 00075 fCmdList.push_back(c); 00076 } 00077 00078 //...................................................................... 00079 00080 void JobCInterpreter::Interp(const char *cmd) 00081 { 00082 const char *c = cmd; 00083 00084 // Skip lines starting with '#' 00085 if (*c == '#') return; 00086 00087 // Skip leading white space 00088 if (fBuffer.length()==0) while (*c == ' ') ++c; 00089 00090 // Add to current string buffer 00091 for (; *c!='\0'; ++c) { 00092 // Don't read pass continuation flags 00093 if (*c=='\\') return; 00094 00095 // Don't read pass comments 00096 if (*c=='/' && *(c+1)=='/') { 00097 if (fBuffer.length()>0) { 00098 JobCommand *jcmd = new JobCommand(fBuffer.c_str()); 00099 this->PushJobCommand(jcmd); 00100 fBuffer = ""; 00101 } 00102 return; 00103 } 00104 00105 // Parse what we have 00106 if (*c=='\n' || *c==';') { 00107 if (fBuffer.length()>0) { 00108 JobCommand *jcmd = new JobCommand(fBuffer.c_str()); 00109 this->PushJobCommand(jcmd); 00110 fBuffer = ""; 00111 } 00112 } 00113 else { 00114 if (*c == ' ' && fBuffer.length()==0) continue; 00115 else fBuffer += (*c); 00116 } 00117 } 00118 } 00119
1.3.9.1