Changeset 13668 for trunk/FACT++
- Timestamp:
- 05/12/12 12:35:03 (13 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Readline.cc
r13649 r13668 71 71 72 72 Readline *Readline::This = 0; 73 int Readline::fLabel = - 1;73 int Readline::fLabel = -2; 74 74 75 75 // -------------------------------------------------------------------------- … … 952 952 fprintf(rl_outstream, " .! command Execute a shell command\n"); 953 953 fprintf(rl_outstream, " .w n Sleep n milliseconds\n"); 954 fprintf(rl_outstream, " .x file name Execute a script of commands\n");955 fprintf(rl_outstream, " .x file:N 954 fprintf(rl_outstream, " .x file .. Execute a script of commands (+optional argumnets)\n"); 955 fprintf(rl_outstream, " .x file:N .. Execute a script of commands, start at label N\n"); 956 956 fprintf(rl_outstream, " .j N Forward jump to label N\n"); 957 957 fprintf(rl_outstream, " : N Defines a label\n"); … … 1046 1046 if (str.substr(0, 3)==".x ") 1047 1047 { 1048 Execute(str.substr(3)); 1048 string opt(str.substr(3)); 1049 1050 map<string,string> data = Tools::Split(opt); 1051 if (data.size()==0) 1052 return false; 1053 1054 /* 1055 if (fData.size()==0) 1056 // File name missing ... 1057 else 1058 // "Equal sign missing in argument '"+data.begin()->first+"'" 1059 */ 1060 1061 Execute(opt, data); 1049 1062 return true; 1050 1063 } … … 1219 1232 //! Filename of file to read 1220 1233 //! 1234 //! @param args 1235 //! Arguments to be passed to the script. A search and replace 1236 //! will be done for ${arg} 1237 //! 1221 1238 //! @returns 1222 1239 //! -1 if the file couldn't be read and the number of commands for which 1223 1240 //! Process() was callled otherwise 1224 1241 //! 1225 int Readline::Execute(const string &fname) 1226 { 1242 int Readline::Execute(const string &fname, const map<string,string> &args) 1243 { 1244 // this could do the same: 1245 // rl_instream = fopen(str.c_str(), "r"); 1246 1227 1247 if (IsStopped()) 1228 1248 return 0; … … 1242 1262 ifstream fin(name.c_str()); 1243 1263 if (!fin) 1264 { 1265 SetSection(-2); 1244 1266 return -1; 1267 } 1245 1268 1246 1269 fCommandLog << "# " << Time() << " - " << name << " (START"; … … 1248 1271 fCommandLog << ':' << fLabel; 1249 1272 fCommandLog << ")" << endl; 1273 1274 SetSection(0); 1250 1275 1251 1276 int rc = 0; … … 1266 1291 } 1267 1292 1293 // find and replace arguments 1294 for (auto it=args.begin(); it!=args.end(); it++) 1295 { 1296 const string find = "${"+it->first+"}"; 1297 for (size_t pos=0; (pos=buffer.find(find, pos))!=string::npos; pos+=find.length()) 1298 buffer.replace(pos, find.size(), it->second); 1299 } 1300 1301 // process line 1268 1302 ProcessLine(buffer); 1269 1303 } 1270 1304 1271 1305 fLabel = -1; 1272 SetSection(- 1);1306 SetSection(-2); 1273 1307 1274 1308 fCommandLog << "# " << Time() << " - " << name << " (FINISHED)" << endl; -
trunk/FACT++/src/Readline.h
r13649 r13668 2 2 #define FACT_Readline 3 3 4 #include <map> 4 5 #include <string> 5 6 #include <vector> … … 95 96 static void Stop(); 96 97 virtual bool ExecuteShellCommand(const std::string &cmd); 97 int Execute(const std::string &fname );98 int Execute(const std::string &fname, const std::map<std::string,std::string> &args=std::map<std::string,std::string>()); 98 99 bool IsStopped() const; 99 100 void ProcessLine(const std::string &str); … … 125 126 int GetRows() const; 126 127 128 static Readline *Instance() { return This; } 127 129 }; 128 130 -
trunk/FACT++/src/ReadlineColor.cc
r12962 r13668 160 160 out << kBold << " .! command " << kReset << "Execute a shell command\n"; 161 161 out << kBold << " .w n " << kReset << "Sleep n milliseconds\n"; 162 out << kBold << " .x filename " << kReset << "Execute a script of commands \n";162 out << kBold << " .x filename " << kReset << "Execute a script of commands (+optional arguments)\n"; 163 163 out << kBold << " .x file:N " << kReset << "Execute a script of commands, start at label N\n"; 164 164 out << kBold << " .j N " << kReset << "Forward jump to label N\n";
Note:
See TracChangeset
for help on using the changeset viewer.