Ignore:
Timestamp:
Apr 10, 2011, 10:15:14 AM (9 years ago)
Author:
tbretz
Message:
Replaces local Trim function by function from tools; set rl_pending_input in Stop to Ctrl-d; fixed removing of old entries frm the history in AddToHistory - made sure that only full matches are removed.
File:
1 edited

Legend:

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

    r10331 r10343  
    155155// --------------------------------------------------------------------------
    156156//
    157 //! This is a static helper to remove leading and trailing whitespaces.
    158 //!
    159 //! @param buf
    160 //!    a pointer to the char array from which the whitespaces should be
    161 //!    removed
    162 //!
    163 //! @returns
    164 //!    a std::string with the whitespaces removed from buf
    165 //
    166 string Readline::TrimSpaces(const char *buf)
    167 {
    168     const string str(buf);
    169 
    170     // 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
    173 
    174     // if all spaces or empty return an empty string
    175     if (string::npos==start || string::npos==end)
    176         return string();
    177 
    178     return str.substr(start, end-start+1);
    179 }
    180 
    181 // --------------------------------------------------------------------------
    182 //
    183157//! This wraps the given readline function such that the output can be
    184158//! redirected from thr rl_outstream to the given C++ ostream.
    185159//!
    186 //! @param ostream
     160//! @param out
    187161//!    The stream to which the output should be redirected.
    188162//!
     
    537511        return;
    538512
     513    int p = -1;
    539514    while (skip==2)
    540515    {
    541         int p = history_search_pos(str.c_str(), 0, 0);
     516        p = history_search_pos(str.c_str(), 0, p+1);
    542517        if (p<0)
    543518            break;
    544519
    545         delete remove_history(p);
     520        // It seems like history_search_pos works more like
     521        // history_search_prefix, therefore the identity is checked again
     522        const HIST_ENTRY *e = history_get(p+1);
     523        if (e && str==e->line)
     524            delete remove_history(p);
    546525    }
    547526
     
    943922    fprintf(rl_outstream, "   Ctrl-left       One word backward\n");
    944923    fprintf(rl_outstream, "   Ctrl-right      One word forward\n");
     924    fprintf(rl_outstream, "   Ctrl-d          Quit\n");
    945925    fprintf(rl_outstream, "   Ctrl-y          Delete line\n");
    946926    fprintf(rl_outstream, "   Alt-end/Ctrl-k  Delete until the end of the line\n");
     
    1016996        return false;
    1017997
    1018     str = TrimSpaces(buf);
     998    str = Trim(buf);
    1019999
    10201000    free(buf);
     
    10441024    Shutdown(buf ? buf : "");
    10451025
    1046     const string str = !buf || (rl_done && rl_pending_input) ? ".q" : TrimSpaces(buf);
     1026    const string str = !buf || (rl_done && rl_pending_input==4) ? ".q" : Trim(buf);
    10471027
    10481028    free(buf);
     
    11001080{
    11011081    rl_done          = 1;
    1102     rl_pending_input = 1;
    1103 }
     1082    rl_pending_input = 4; // EOT (end of transmission, ctrl-d)
     1083}
Note: See TracChangeset for help on using the changeset viewer.