Commit 6e088d81 authored by Enrico Granata's avatar Enrico Granata
Browse files
If the user pressed ^D, that would bypass the exit confirmation mechanism
This checkin remedies that by making sure that users get prompted on exit when appropriate even if they use CTRL+D instead of typing quit at the prompt

llvm-svn: 181257
parent 9af6baaa
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
@@ -329,9 +329,10 @@ IOChannel::LibeditOutputBytesReceived (void *baton, const void *src, size_t src_
    }
}

bool
IOChannel::LibeditGetInputResult
IOChannel::LibeditGetInput (std::string &new_line)
{
    IOChannel::LibeditGetInputResult retval = IOChannel::eLibeditGetInputResultUnknown;
    if (m_edit_line != NULL)
    {
        int line_len = 0;
@@ -349,6 +350,7 @@ IOChannel::LibeditGetInput (std::string &new_line)

        if (line)
        {
            retval = IOChannel::eLibeditGetInputValid;
            // strip any newlines off the end of the string...
            while (line_len > 0 && (line[line_len - 1] == '\n' || line[line_len - 1] == '\r'))
                --line_len;
@@ -359,17 +361,22 @@ IOChannel::LibeditGetInput (std::string &new_line)
            }
            else
            {
                retval = IOChannel::eLibeditGetInputEmpty;
                // Someone just hit ENTER, return the empty string
                new_line.clear();
            }
            // Return true to indicate success even if a string is empty
            return true;
            return retval;
        }
        else
        {
            retval = (line_len == 0 ? IOChannel::eLibeditGetInputEOF : IOChannel::eLibeditGetInputResultError);
        }
    }
    // Return false to indicate failure. This can happen when the file handle
    // is closed (EOF).
    new_line.clear();
    return false;
    return retval;
}

void *
@@ -422,9 +429,17 @@ IOChannel::Run ()

                    if (CommandQueueIsEmpty())
                    {
                        if (LibeditGetInput(line) == false)
                        IOChannel::LibeditGetInputResult getline_result = LibeditGetInput(line);
                        if (getline_result == IOChannel::eLibeditGetInputEOF)
                        {
                            // EOF occurred
                            // pretend that a quit was typed so the user gets a potential
                            // chance to confirm
                            line.assign("quit");
                        }
                        else if (getline_result == IOChannel::eLibeditGetInputResultError || getline_result == IOChannel::eLibeditGetInputResultUnknown)
                        {
                            // EOF or some other file error occurred
                            // some random error occurred, exit and don't ask because the state might be corrupt
                            done = true;
                            continue;
                        }
+10 −1
Original line number Diff line number Diff line
@@ -39,6 +39,15 @@ public:
        eAllEventBits                 = 0xffffffff
    };
    
    enum LibeditGetInputResult
    {
        eLibeditGetInputEOF = 0,
        eLibeditGetInputValid = 1,
        eLibeditGetInputEmpty = 2,
        eLibeditGetInputResultError = 4,
        eLibeditGetInputResultUnknown = 0xffffffff
    };

    IOChannel (FILE *editline_in,
               FILE *editline_out,
               FILE *out,
@@ -66,7 +75,7 @@ public:
    void
    ErrWrite (const char *buffer, size_t len, bool asynchronous);

    bool
    LibeditGetInputResult
    LibeditGetInput (std::string &);
    
    static void