Mercurial > jwe > qt-gui-with-push-parser
changeset 14:1e5a1e15fa56
clean up header files, more small readline changes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 23 May 2019 18:41:04 -0400 |
parents | d179b0bb85e4 |
children | 79783f3e2017 |
files | command-window.cpp gui-main.cpp interpreter.cpp interpreter.h parser.yy qt-interpreter.cpp |
diffstat | 6 files changed, 18 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/command-window.cpp Thu May 23 18:26:35 2019 -0400 +++ b/command-window.cpp Thu May 23 18:41:04 2019 -0400 @@ -2,9 +2,6 @@ #include <sstream> #include <string> -#include <cstdlib> -#include <cstring> - #include <QApplication> #include <QKeyEvent> #include <QTextDocument> @@ -20,6 +17,8 @@ namespace calc { + // vvvvv readline vvvvv + // We could eliminate this global variable and the global // command_window::the_command_window variable if readline callbacks // could be defined as C++ lambda functions. Then the lambdas could @@ -28,8 +27,6 @@ static int available_char = 0; - // vvvvv readline vvvvv - static int getc (FILE *) { int tmp = available_char; @@ -85,6 +82,11 @@ static void readline_init (void) { + // What we really want here is a readline object that we could + // create in the command_window constructor. + + // We might also want the option of shared history? + rl_initialize (); rl_getc_function = getc; @@ -99,6 +101,14 @@ static void readline_fini (void) { rl_callback_handler_remove (); + + rl_getc_function = nullptr; + rl_redisplay_function = nullptr; + rl_prep_term_function = nullptr; + rl_deprep_term_function = nullptr; + rl_completion_display_matches_hook = nullptr; + + // Is there a function that undoes readline initialization? } // ^^^^^ readline ^^^^^
--- a/gui-main.cpp Thu May 23 18:26:35 2019 -0400 +++ b/gui-main.cpp Thu May 23 18:41:04 2019 -0400 @@ -1,10 +1,3 @@ -#include <iostream> -#include <sstream> -#include <string> - -#include <cstdlib> -#include <cstring> - #include <QApplication> #include "command-window.h"
--- a/interpreter.cpp Thu May 23 18:26:35 2019 -0400 +++ b/interpreter.cpp Thu May 23 18:41:04 2019 -0400 @@ -1,33 +1,21 @@ #include <iostream> #include <string> +// For sleep. #include <unistd.h> #include "interpreter.h" #include "parser.h" -#include "gui-main.h" -#include "tty-main.h" - namespace calc { - interpreter *interpreter::the_interpreter = nullptr; - interpreter::interpreter (void) : m_parser (*this), m_error_handler ([] (const char *msg) { std::cerr << "error: " << msg << std::endl; }), m_result_handler ([] (double value) { std::cout << "ans = " << value << std::endl; }) - { - if (the_interpreter) - { - std::cerr << "multiple interpreters are not possible!" << std::endl; - exit (1); - } - - the_interpreter = this; - } + { } int interpreter::parse_and_execute (const std::string& line) {
--- a/interpreter.h Thu May 23 18:26:35 2019 -0400 +++ b/interpreter.h Thu May 23 18:41:04 2019 -0400 @@ -11,8 +11,6 @@ { public: - static interpreter *the_interpreter; - interpreter (void); interpreter (const interpreter&) = delete;
--- a/parser.yy Thu May 23 18:26:35 2019 -0400 +++ b/parser.yy Thu May 23 18:41:04 2019 -0400 @@ -4,7 +4,6 @@ #define YYSTYPE double -#include <iostream> #include <string> #include <cctype>
--- a/qt-interpreter.cpp Thu May 23 18:26:35 2019 -0400 +++ b/qt-interpreter.cpp Thu May 23 18:41:04 2019 -0400 @@ -1,15 +1,10 @@ -#include <iostream> -#include <sstream> +#include <string> #include <QString> -#include "gui-main.h" #include "interpreter.h" #include "qt-interpreter.h" -#include <readline/readline.h> -#include <readline/history.h> - namespace calc { qt_interpreter::qt_interpreter (void)