Changeset 13668 for trunk/FACT++


Ignore:
Timestamp:
05/12/12 12:35:03 (13 years ago)
Author:
tbretz
Message:
Added a hint for the command line arguments to the explanation of .x; added argument-replacement to Execute; set section label to -2 if script done and to 0 if script is executing; added argument parsing to .x
Location:
trunk/FACT++/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Readline.cc

    r13649 r13668  
    7171
    7272Readline *Readline::This   =  0;
    73 int       Readline::fLabel = -1;
     73int       Readline::fLabel = -2;
    7474
    7575// --------------------------------------------------------------------------
     
    952952    fprintf(rl_outstream, "   .! command   Execute a shell command\n");
    953953    fprintf(rl_outstream, "   .w n         Sleep n milliseconds\n");
    954     fprintf(rl_outstream, "   .x filename  Execute a script of commands\n");
    955     fprintf(rl_outstream, "   .x file:N   Execute a script of commands, start at label N\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");
    956956    fprintf(rl_outstream, "   .j N         Forward jump to label N\n");
    957957    fprintf(rl_outstream, "   : N          Defines a label\n");
     
    10461046    if (str.substr(0, 3)==".x ")
    10471047    {
    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);
    10491062         return true;
    10501063    }
     
    12191232//!    Filename of file to read
    12201233//!
     1234//! @param args
     1235//!    Arguments to be passed to the script. A search and replace
     1236//!    will be done for ${arg}
     1237//!
    12211238//! @returns
    12221239//!    -1 if the file couldn't be read and the number of commands for which
    12231240//!    Process() was callled otherwise
    12241241//!
    1225 int Readline::Execute(const string &fname)
    1226 {
     1242int 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
    12271247    if (IsStopped())
    12281248        return 0;
     
    12421262    ifstream fin(name.c_str());
    12431263    if (!fin)
     1264    {
     1265        SetSection(-2);
    12441266        return -1;
     1267    }
    12451268
    12461269    fCommandLog << "# " << Time() << " - " << name << " (START";
     
    12481271        fCommandLog << ':' << fLabel;
    12491272    fCommandLog << ")" << endl;
     1273
     1274    SetSection(0);
    12501275
    12511276    int rc = 0;
     
    12661291        }
    12671292
     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
    12681302        ProcessLine(buffer);
    12691303    }
    12701304
    12711305    fLabel = -1;
    1272     SetSection(-1);
     1306    SetSection(-2);
    12731307
    12741308    fCommandLog << "# " << Time() << " - " << name << " (FINISHED)" << endl;
  • trunk/FACT++/src/Readline.h

    r13649 r13668  
    22#define FACT_Readline
    33
     4#include <map>
    45#include <string>
    56#include <vector>
     
    9596    static  void Stop();
    9697    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>());
    9899    bool         IsStopped() const;
    99100    void         ProcessLine(const std::string &str);
     
    125126    int GetRows() const;
    126127
     128    static Readline *Instance() { return This; }
    127129};
    128130
  • trunk/FACT++/src/ReadlineColor.cc

    r12962 r13668  
    160160    out << kBold << "   .! command   " << kReset << "Execute a shell command\n";
    161161    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";
    163163    out << kBold << "   .x file:N    " << kReset << "Execute a script of commands, start at label N\n";
    164164    out << kBold << "   .j N         " << kReset << "Forward jump to label N\n";
Note: See TracChangeset for help on using the changeset viewer.