From af4b0e2eeb7bc3d795259bf9f3a6742686b7d543 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Mon, 1 Feb 2016 21:17:46 -0500 Subject: [PATCH] editline support --- CMakeLists.txt | 2 ++ mpw-shell.cpp | 56 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a0c755..09bb9f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -113,6 +113,8 @@ add_executable(mpw-shell mpw-shell.cpp mpw-shell-read.cpp mpw-shell-token.cpp mp mpw-shell-parser.cpp value.cpp mpw-shell-quote.cpp phase1.cpp phase2.cpp phase2-parser.cpp command.cpp environment.cpp builtins.cpp) +target_link_libraries(mpw-shell edit) + # all this for -std=c++14 set_property (TARGET mpw-shell PROPERTY CXX_STANDARD 14) set_property (TARGET mpw-shell PROPERTY CXX_STANDARD_REQUIRED TRUE) diff --git a/mpw-shell.cpp b/mpw-shell.cpp index b77b983..f53068e 100644 --- a/mpw-shell.cpp +++ b/mpw-shell.cpp @@ -16,7 +16,8 @@ #include "phase2.h" #include "command.h" - +//#include +#include // should set {MPW}, {MPWVersion}, then execute {MPW}StartUp void init(Environment &e) { @@ -56,6 +57,39 @@ int read_stdin(phase1 &p) { return 0; } +int interactive(phase1 &p) { + + for(;;) { + char *cp = readline("# "); + if (!cp) break; + + std::string s(cp); + free(cp); + + if (s.empty()) continue; + add_history(s.c_str()); + s.push_back('\n'); + try { + p.process(s); + + } catch(std::exception &ex) { + fprintf(stderr, "%s\n", ex.what()); + p.reset(); + } + + } + + try { + p.finish(); + } catch(std::exception &ex) { + fprintf(stderr, "%s\n", ex.what()); + p.reset(); + } + + fprintf(stdout, "\n"); + return 0; +} + int main(int argc, char **argv) { Environment e; @@ -76,24 +110,8 @@ int main(int argc, char **argv) { p2.process(s); }; */ - read_stdin(p1); + interactive(p1); p2.finish(); -/* - try { - head = read_fd(0); - } catch (std::exception &ex) { - fprintf(stderr, "%s\n", ex.what()); - exit(1); - } - - - try { - int status = execute(head); - exit(status); - } catch(std::exception &ex) { - fprintf(stderr, "%s\n", ex.what()); - exit(1); - } -*/ + return 0; }