Changeset 10654


Ignore:
Timestamp:
05/10/11 19:32:32 (14 years ago)
Author:
tbretz
Message:
Added script execution.
Location:
trunk/FACT++/src
Files:
3 edited

Legend:

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

    r10498 r10654  
    897897    fprintf(rl_outstream, "   c,commands   Dump available commands\n");
    898898    fprintf(rl_outstream, "   k,keylist    Dump key bindings\n");
     899    fprintf(rl_outstream, "   .x filename  Execute a script of commands\n");
    899900    fprintf(rl_outstream, "   .q,quit      Quit\n");
    900901    fprintf(rl_outstream, "\n");
     
    941942bool Readline::Process(const string &str)
    942943{
     944    if (str.substr(0, 3)==".x ")
     945    {
     946         Execute(str.substr(3));
     947         return true;
     948    }
     949
    943950    // ----------- Readline static -------------
    944951
     
    10811088}
    10821089
     1090// --------------------------------------------------------------------------
     1091//
     1092//! Executes commands read from an ascii file as they were typed in
     1093//! the console. Empty lines and lines beginning with # are ignored.
     1094//!
     1095//! @param fname
     1096//!    Filename of file to read
     1097//!
     1098//! @returns
     1099//!    -1 if the file couldn't be read and the number of command for which
     1100//!    Process() was callled otherwise
     1101//!
     1102int Readline::Execute(const string &fname)
     1103{
     1104    int rc = 0;
     1105
     1106    ifstream fin(Tools::Trim(fname).c_str());
     1107    if (!fin)
     1108        return -1;
     1109
     1110    string buffer;
     1111    while (getline(fin, buffer, '\n'))
     1112    {
     1113        buffer = Tools::Trim(buffer);
     1114        if (buffer.empty())
     1115            continue;
     1116
     1117        if (buffer[0]=='#')
     1118            continue;
     1119
     1120        rc++;
     1121
     1122        if (Process(buffer))
     1123            continue;
     1124
     1125        fLine++;
     1126
     1127        AddToHistory(buffer);
     1128    }
     1129
     1130    return rc;
     1131}
     1132
    10831133void Readline::Stop()
    10841134{
  • trunk/FACT++/src/Readline.h

    r10343 r10654  
    8787    virtual void Run(const char *prompt=0);
    8888    static  void Stop();
     89    int      Execute(const std::string &fname);
    8990
    9091    int GetLine() const { return fLine; }
  • trunk/FACT++/src/ReadlineColor.cc

    r10337 r10654  
    151151    out << kBold << "   k,keylist    " << kReset << "Dump key bindings" << endl;
    152152    out << kBold << "   a,attrs      " << kReset << "Dump available stream attributes" << endl;
     153    out << kBold << "   .x filename  " << kReset << "Execute a script of commands" << endl;
    153154    out << kBold << "   .q,quit      " << kReset << "Quit" << endl;
    154155    out << endl;
Note: See TracChangeset for help on using the changeset viewer.