# HG changeset patch # User John W. Eaton # Date 1558651264 14400 # Node ID 1e5a1e15fa5611ff89084aba55a2219c04814ea6 # Parent d179b0bb85e47311b9df3ddfdfc7b575db2317aa clean up header files, more small readline changes diff -r d179b0bb85e4 -r 1e5a1e15fa56 command-window.cpp --- 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 #include -#include -#include - #include #include #include @@ -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 ^^^^^ diff -r d179b0bb85e4 -r 1e5a1e15fa56 gui-main.cpp --- 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 -#include -#include - -#include -#include - #include #include "command-window.h" diff -r d179b0bb85e4 -r 1e5a1e15fa56 interpreter.cpp --- 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 #include +// For sleep. #include #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) { diff -r d179b0bb85e4 -r 1e5a1e15fa56 interpreter.h --- 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; diff -r d179b0bb85e4 -r 1e5a1e15fa56 parser.yy --- 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 #include #include diff -r d179b0bb85e4 -r 1e5a1e15fa56 qt-interpreter.cpp --- 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 -#include +#include #include -#include "gui-main.h" #include "interpreter.h" #include "qt-interpreter.h" -#include -#include - namespace calc { qt_interpreter::qt_interpreter (void)