Changeset 10308 for trunk/FACT++


Ignore:
Timestamp:
04/07/11 15:45:13 (14 years ago)
Author:
tbretz
Message:
Added the RedirectionWrapper member function; made the comparison for auto-completion case insensitive.
Location:
trunk/FACT++/src
Files:
2 edited

Legend:

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

    r10275 r10308  
    169169
    170170    // Trim Both leading and trailing spaces
    171     const size_t start = str.find_first_not_of(" "); // Find the first character position after excluding leading blank spaces
    172     const size_t end   = str.find_last_not_of(" ");  // Find the first character position from reverse af
     171    const size_t start = str.find_first_not_of(' '); // Find the first character position after excluding leading blank spaces
     172    const size_t end   = str.find_last_not_of(' ');  // Find the first character position from reverse af
    173173
    174174    // if all spaces or empty return an empty string
    175175    if (string::npos==start || string::npos==end)
    176         return "";
     176        return string();
    177177
    178178    return str.substr(start, end-start+1);
     179}
     180
     181// --------------------------------------------------------------------------
     182//
     183//! This wraps the given readline function such that the output can be
     184//! redirected from thr rl_outstream to the given C++ ostream.
     185//!
     186//! @param ostream
     187//!    The stream to which the output should be redirected.
     188//!
     189//! @param function
     190//!    Takes a function of type bool(*)() as argument
     191//!
     192//! @returns
     193//!    The return value of the function
     194//
     195bool Readline::RedirectionWrapper(ostream &out, bool (*function)())
     196{
     197    FILE *save = SetStreamOut(tmpfile());
     198    const bool rc = function();
     199    FILE *file = SetStreamOut(save);
     200
     201    const bool empty = ftell(file)==0;
     202
     203    rewind(file);
     204
     205    if (empty)
     206    {
     207        out << " <empty>" << endl;
     208        fclose(file);
     209        return rc;
     210    }
     211
     212    while (1)
     213    {
     214        const int c = getc(file);
     215        if (feof(file))
     216            break;
     217        out << (char)c;
     218    }
     219    out << endl;
     220
     221    fclose(file);
     222
     223    return rc;
    179224}
    180225
     
    333378char *Readline::Compare(const string &str, const string &txt)
    334379{
    335     return str.substr(0, txt.length())==txt ? strndup(str.c_str(), str.length()) : 0;
     380    /*return strncmp(str.c_str(), txt.c_str(), txt.length())==0 ? */
     381    return strncasecmp(str.c_str(), txt.c_str(), txt.length())==0 ?
     382        strndup(str.c_str(), str.length()) : 0;
    336383}
    337384
     
    814861{
    815862    HIST_ENTRY **next = history_list();
     863
     864    if (!next)
     865        return true;
    816866
    817867    for (; *next; next++)
  • trunk/FACT++/src/Readline.h

    r10275 r10308  
    99public:
    1010    static std::string TrimSpaces(const char *buf);
     11    static bool RedirectionWrapper(std::ostream &out, bool (*function)());
    1112
    1213protected:
Note: See TracChangeset for help on using the changeset viewer.