Changeset 12961 for trunk


Ignore:
Timestamp:
02/29/12 10:04:55 (13 years ago)
Author:
tbretz
Message:
Implementd jumps and labels
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

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

    r12824 r12961  
    9696//
    9797Readline::Readline(const char *prgname) :
    98     fMaxLines(500), fLine(0), fCompletion(0)
     98    fMaxLines(500), fLine(0), fLabel(-1), fCompletion(0)
    9999{
    100100    if (This)
     
    952952    fprintf(rl_outstream, "   .w n         Sleep n milliseconds\n");
    953953    fprintf(rl_outstream, "   .x filename  Execute a script of commands\n");
     954    fprintf(rl_outstream, "   .x file:N    Execute a script of commands, start at label N\n");
     955    fprintf(rl_outstream, "   .j N         Forward jump to label N\n");
     956    fprintf(rl_outstream, "   : N          Defines a label\n");
    954957    fprintf(rl_outstream, "   .q,quit      Quit\n");
    955958    fprintf(rl_outstream, "\n");
     
    994997//!
    995998//
     999bool Readline::PreProcess(const string &str)
     1000{
     1001    // ----------- Labels -------------
     1002
     1003    if (str[0]==':')
     1004    {
     1005        if (fLabel!=atoi(str.substr(1).c_str()))
     1006            return true;
     1007
     1008        fLabel=-1;
     1009        return false;
     1010    }
     1011
     1012    if (fLabel>=0)
     1013    {
     1014        fCommandLog << "# SKIP[" << fLabel << "]: " << str << endl;
     1015        return true;
     1016    }
     1017
     1018    if (str.substr(0, 3)==".j ")
     1019    {
     1020        fLabel = atoi(str.substr(3).c_str());
     1021        return false;
     1022    }
     1023
     1024    return Process(str);
     1025
     1026}
     1027
     1028// --------------------------------------------------------------------------
     1029//
     1030//!
     1031//
    9961032bool Readline::Process(const string &str)
    9971033{
     1034    // ----------- Common commands -------------
     1035
    9981036    if (str.substr(0, 3)==".w ")
    9991037    {
     
    11161154void Readline::ProcessLine(const string &str)
    11171155{
    1118     const bool rc = Process(str);
     1156    const bool rc = PreProcess(str);
    11191157
    11201158    AddToHistory(str);
     
    11861224        return 0;
    11871225
    1188     int rc = 0;
    1189 
    1190     const string name = Tools::Trim(fname);
     1226    fLabel = -1;
     1227
     1228    string name = Tools::Trim(fname);
     1229
     1230    const size_t p = name.find_last_of(':');
     1231    if (p!=string::npos)
     1232    {
     1233        fLabel = atoi(name.substr(p+1).c_str());
     1234        name = name.substr(0, p);
     1235    }
    11911236
    11921237    ifstream fin(name.c_str());
     
    11941239        return -1;
    11951240
    1196     fCommandLog << "# " << Time() << " - " << name << " (START)" << endl;
     1241    fCommandLog << "# " << Time() << " - " << name << " (START";
     1242    if (fLabel>=0)
     1243        fCommandLog << ':' << fLabel;
     1244    fCommandLog << ")" << endl;
     1245
     1246    int rc = 0;
    11971247
    11981248    string buffer;
     
    12141264    }
    12151265
     1266    fLabel = -1;
     1267
    12161268    fCommandLog << "# " << Time() << " - " << name << " (FINISHED)" << endl;
    12171269
  • trunk/FACT++/src/Readline.h

    r11326 r12961  
    2626
    2727    int fLine;
     28    int fLabel;
    2829
    2930    // Static member function which are used to adapt readline to ncurses
     
    5455    void SetCompletion(const std::vector<std::string> *v) { fCompletion = v; }
    5556    char **Complete(const std::vector<std::string> &v, const char *text);
     57
     58    void SetLabel(int l) { fLabel = l; }
    5659
    5760public:
     
    8487    void UpdatePrompt() const { UpdatePrompt(GetUpdatePrompt()); }
    8588
     89    virtual bool PreProcess(const std::string &str);
    8690    virtual bool Process(const std::string &str);
    8791    virtual std::string GetUpdatePrompt() const { return ""; }
Note: See TracChangeset for help on using the changeset viewer.