From a396b6e93d7fff98e63428e9ea2aa24c34b4e333 Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani <3fb650a9-b47e-4604-a282-1dd91953b2ee@anonaddy.me> Date: Thu, 29 Oct 2020 21:08:15 -0400 Subject: [PATCH] fixed multi-line cmd issue --- src/main.cpp | 3 +- src/main.cpp.bak | 117 ----------------------------------------------- 2 files changed, 2 insertions(+), 118 deletions(-) delete mode 100644 src/main.cpp.bak diff --git a/src/main.cpp b/src/main.cpp index 5849c28..b334ce7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -79,6 +79,7 @@ int main(int argc, char** argv) string root_cmd; for (int i = 1; i < argc; ++i) { root_cmd +=argv[i]; + root_cmd += " "; } while (status == 0) { @@ -102,7 +103,7 @@ int main(int argc, char** argv) } else { string whole_command = root_cmd + " " + command; - std::cout << "[" << whole_command << "]\n"; + // std::cout << "[" << whole_command << "]\n"; system (whole_command.c_str ()); } } diff --git a/src/main.cpp.bak b/src/main.cpp.bak deleted file mode 100644 index e39b131..0000000 --- a/src/main.cpp.bak +++ /dev/null @@ -1,117 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////// -// -// Copyright 2006 - 2017, Paul Beckingham, Federico Hernandez, 2020 Armaan Bhojwani -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// -// http://www.opensource.org/licenses/mit-license.php -// -//////////////////////////////////////////////////////////////////////////////// - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_READLINE -#include -#include -#endif - -using namespace std; -std::string promptCompose (); - -const std::string getResponse (const std::string& prompt) -{ - std::string response {""}; - - // Display prompt, get input. -#ifdef HAVE_READLINE - char *line_read = readline (prompt.c_str ()); - if (! line_read) - { - std::cout << "\n"; - response = ""; - } - else - { - // Save history. - if (*line_read) - add_history (line_read); - - response = std::string (line_read); - free (line_read); - } -#else - std::cout << prompt; - std::getline (std::cin, response); - if (std::cin.eof () == 1) - { - std::cout << "\n"; - response = ""; - } -#endif - - return response; -} - -int commandLoop () -{ - // Compose the prompt. - auto prompt = promptCompose (); - - // Display prompt, get input. - auto command = getResponse (prompt); - - int status = 0; - if (! isatty (fileno (stdin)) && command == "") - { - status = -1; - } - else if (command != "") - { - // Dispatch command. - if (command == "") status = -1; - else if (command != "") - { - command = command; - std::cout << "[" << command << "]\n"; - system (command.c_str ()); - } - } - - return status; -} - -int main () -// int main (int argc, const char** argv) -{ - int status = 0; - - while (status == 0) - commandLoop(); - - return status == -1 ? 0 : status; -} - -//////////////////////////////////////////////////////////////////////////////// -- 2.39.2