00001 //----------------------------------------------------------- 00002 // Copyright Christian Arnault LAL-Orsay CNRS 00003 // arnault@lal.in2p3.fr 00004 // See the complete license in cmt_license.txt "http://www.cecill.info". 00005 //----------------------------------------------------------- 00006 00007 #include "cmt_sequence.h" 00008 #include "cmt_system.h" 00009 00010 SequenceRunner::SequenceRunner () 00011 { 00012 } 00013 00014 void SequenceRunner::begin () 00015 { 00016 started = false; 00017 running = false; 00018 if (style == CmtSystem::getenv ("CMTSTRUCTURINGSTYLE")) 00019 { 00020 vdir = CmtSystem::file_separator (); 00021 vdir += "v1"; 00022 } 00023 else 00024 { 00025 vdir = ""; 00026 } 00027 package = ""; 00028 filename = ""; 00029 buffer = ""; 00030 pwd = ""; 00031 } 00032 00033 void SequenceRunner::filter (const cmt_string& line) 00034 { 00035 //cout << "line=[" << line << "]" << endl; 00036 00037 CmtSystem::cmt_string_vector words; 00038 00039 CmtSystem::split (line, " \t", words); 00040 00041 cmt_string verb; 00042 00043 if (words.size () > 0) verb = words[0]; 00044 00045 if (verb.substr (0, 2) == "%%") 00046 { 00047 if (verb.substr (0, 3) == "%%%") return; 00048 00049 if (running) 00050 { 00051 buffer.write (filename); 00052 cout << "%%Writing file " << filename << endl; 00053 //cout << buffer << endl; 00054 buffer = ""; 00055 00056 running = false; 00057 } 00058 } 00059 00060 if (verb == "%%package") 00061 { 00062 package = words[1]; 00063 version = words[2]; 00064 00065 if (version == "") version = "v1"; 00066 00067 cmt_string command = "cmt create "; 00068 command += package; 00069 command += " "; 00070 command += version; 00071 00072 CmtSystem::execute (command); 00073 cout << "%% creating package " << package << " with command [" << command << "]" << endl; 00074 00075 if (style == CmtSystem::getenv ("CMTSTRUCTURINGSTYLE")) 00076 { 00077 vdir = CmtSystem::file_separator (); 00078 vdir += version; 00079 } 00080 else 00081 { 00082 vdir = ""; 00083 } 00084 00085 filename = package; 00086 filename += vdir; 00087 filename += CmtSystem::file_separator (); 00088 filename += "cmt"; 00089 filename += CmtSystem::file_separator (); 00090 filename += "requirements"; 00091 00092 started = true; 00093 } 00094 else if (verb == "%%file") 00095 { 00096 cmt_string file = words[1]; 00097 00098 cmt_string d = package; 00099 d += vdir; 00100 d += CmtSystem::file_separator (); 00101 d += file; 00102 CmtSystem::dirname (d, d); 00103 00104 CmtSystem::mkdir (d); 00105 cout << "%% creating directory " << d << endl; 00106 00107 buffer = ""; 00108 00109 filename = package; 00110 filename += vdir; 00111 filename += CmtSystem::file_separator (); 00112 filename += file; 00113 started = true; 00114 } 00115 else if (verb == "%%cdpackage") 00116 { 00117 package = words[1]; 00118 00119 pwd = package; 00120 pwd += vdir; 00121 pwd += CmtSystem::file_separator (); 00122 pwd += "cmt"; 00123 cout << "%% moving to package " << package << endl; 00124 } 00125 else if (verb == "%%cmt") 00126 { 00127 cmt_string command; 00128 00129 if (pwd != "") 00130 { 00131 command = "cd "; 00132 command += pwd; 00133 command += " "; 00134 command += CmtSystem::command_separator (); 00135 command += " "; 00136 } 00137 00138 command += line; 00139 command.replace ("%%", ""); 00140 00141 cout << "%% executing cmt command " << line << endl; 00142 00143 CmtSystem::execute (command); 00144 } 00145 else 00146 { 00147 buffer += line; 00148 buffer += "\n"; 00149 } 00150 00151 if (started) 00152 { 00153 started = false; 00154 running = true; 00155 } 00156 } 00157 00158 void SequenceRunner::end () 00159 { 00160 if (running) 00161 { 00162 if (buffer != "") 00163 { 00164 buffer.write (filename); 00165 cout << "%%Writing file " << filename << endl; 00166 //cout << buffer << endl; 00167 buffer = ""; 00168 } 00169 running = false; 00170 } 00171 } 00172 00173