Changeset 13771 for trunk/FACT++


Ignore:
Timestamp:
05/18/12 10:07:21 (12 years ago)
Author:
tbretz
Message:
Implemented the possibility to print errors form readline; added .gt, .lt and .eq commmands.
Location:
trunk/FACT++/src
Files:
5 edited

Legend:

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

    r12960 r13771  
    4848    fLogO.Display();
    4949    fLogI.Display();
     50}
     51
     52void Console::PrintReadlineError(const std::string &str)
     53{
     54    fLogI << kRed << str << endl;
    5055}
    5156
     
    216221}
    217222
     223void ConsoleStream::PrintReadlineError(const std::string &str)
     224{
     225    fLogO << kRed << str << endl;
     226}
     227
    218228// --------------------------------------------------------------------------
    219229//
  • trunk/FACT++/src/Console.h

    r11580 r13771  
    99private:
    1010    WindowLog fLogO;
     11
     12    void PrintReadlineError(const std::string &str);
    1113
    1214public:
     
    3436
    3537    bool fContinous;
     38
     39    void PrintReadlineError(const std::string &str);
     40
    3641public:
    3742    Console(const char *name);
  • trunk/FACT++/src/Readline.cc

    r13744 r13771  
    956956    fprintf(rl_outstream, "   .x file:N .. Execute a script of commands, start at label N\n");
    957957    fprintf(rl_outstream, "   .j N         Forward jump to label N\n");
     958    fprintf(rl_outstream, "   .lt f0 f1 N  If float f0 lower than float f1, jump to label N\n");
     959    fprintf(rl_outstream, "   .gt f0 f1 N  If float f0 greater than float f1, jump to label N\n");
     960    fprintf(rl_outstream, "   .eq i0 i1 N  If int i0 equal int i1, jump to label N\n");
    958961    fprintf(rl_outstream, "   : N          Defines a label (N=number)\n");
    959962    fprintf(rl_outstream, "   # comment    Ignored\n");
     
    10611064        map<string,string> data = Tools::Split(opt);
    10621065        if (opt.size()==0)
    1063             return false;
    1064 
    1065         /*
    1066             if (fData.size()==0)
    1067                 // File name missing ...
     1066        {
     1067            if (data.size()==0)
     1068                PrintReadlineError("Filename missing.");
    10681069            else
    1069                 // "Equal sign missing in argument '"+data.begin()->first+"'"
    1070          */
    1071 
    1072          Execute(opt, data);
    1073          return true;
     1070                PrintReadlineError("Equal sign missing in argument '"+data.begin()->first+"'");
     1071
     1072            return true;
     1073        }
     1074
     1075        Execute(opt, data);
     1076        return true;
    10741077    }
    10751078
     
    10791082         return true;
    10801083    }
     1084
     1085    if (str.substr(0, 4)==".gt ")
     1086    {
     1087        istringstream in(str.substr(4));
     1088
     1089        float v0, v1;
     1090        int label;
     1091
     1092        in >> v0 >> v1 >> label;
     1093        if (in.fail())
     1094        {
     1095            PrintReadlineError("Couldn't parse '"+str+"'");
     1096            fLabel = -2;
     1097            return true;
     1098        }
     1099
     1100        if (v0 > v1)
     1101            fLabel = label;
     1102
     1103        return true;
     1104    }
     1105
     1106    if (str.substr(0, 4)==".lt ")
     1107    {
     1108        istringstream in(str.substr(4));
     1109
     1110        float v0, v1;
     1111        int label;
     1112
     1113        in >> v0 >> v1 >> label;
     1114        if (in.fail())
     1115        {
     1116            PrintReadlineError("Couldn't parse '"+str+"'");
     1117            fLabel = -2;
     1118            return true;
     1119        }
     1120
     1121        if (v0 < v1)
     1122           fLabel = label;
     1123
     1124        return true;
     1125    }
     1126
     1127    if (str.substr(0, 4)==".eq ")
     1128    {
     1129        istringstream in(str.substr(4));
     1130
     1131        int v0, v1, label;
     1132
     1133        in >> v0 >> v1 >> label;
     1134        if (in.fail())
     1135        {
     1136            PrintReadlineError("Couldn't parse '"+str+"'");
     1137            fLabel = -2;
     1138            return true;
     1139        }
     1140
     1141        if (v0==v1)
     1142            fLabel = label;
     1143
     1144        return true;
     1145    }
     1146
    10811147
    10821148    // ----------- Readline static -------------
     
    13541420    return rl_done==1 && rl_pending_input==4;
    13551421};
     1422
     1423void Readline::PrintReadlineError(const std::string &str)
     1424{
     1425    fprintf(rl_outstream, "%s\n", str.c_str());
     1426}
  • trunk/FACT++/src/Readline.h

    r13731 r13771  
    3030    static std::string fScript;
    3131
    32     // Static member function which are used to adapt readline to ncurses
     32    /// Static member function which are used to adapt readline to ncurses
    3333    static int    rl_ncurses_getc(FILE *);
    3434    static int    rl_ncurses_startup();
     
    4141
    4242protected:
    43     // The non static implementations of the callback funtions above
     43    /// The non static implementations of the callback funtions above
    4444    virtual int  Getc(FILE *);
    4545    virtual void Startup();
     
    4949    virtual void CompletionDisplay(char **matches, int num, int max);
    5050
    51     // Functions dealing with auto completion
     51    /// Functions dealing with auto completion
    5252    virtual char *Complete(const char* text, int state);
    5353    virtual char **Completion(const char *text, int start, int end);
     
    5858    char **Complete(const std::vector<std::string> &v, const char *text);
    5959
     60    ///
    6061    virtual void SetSection(int) { }
     62    virtual void PrintReadlineError(const std::string &str);
    6163
    6264public:
  • trunk/FACT++/src/ReadlineColor.cc

    r13745 r13771  
    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";
     165    out << kBold << "   .lt f0 f1 N  " << kReset << "If float f0 lower than float f1, jump to label N\n";
     166    out << kBold << "   .gt f0 f1 N  " << kReset << "If float f0 greater than float f1, jump to label N\n";
     167    out << kBold << "   .eq i0 i1 N  " << kReset << "If int i0 equal int i1, jump to label N\n";
    165168    out << kBold << "   : N          " << kReset << "Defines a label (N=number)\n";
    166169    out << kBold << "   # comment    " << kReset << "Ignored\n";
Note: See TracChangeset for help on using the changeset viewer.