diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..95dd909 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.12) + +# Project name and C++ standard +project(fsh LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Source files +set(FSH_SOURCE_FILES + src/main.cpp + src/fsh.cpp + src/lexer.cpp + src/ast/ast.cpp + src/ast/ast_exec.cpp + src/ast/ast_print.cpp + src/util/input.cpp + src/util/text.cpp + src/cmd/arg.cpp + src/cmd/cmd_base.cpp +) + +# Include directories +include_directories(include) + +# Add executable +add_executable(fsh ${FSH_SOURCE_FILES}) \ No newline at end of file diff --git a/src/cmd/arg.cpp b/src/cmd/arg.cpp index be61d9d..0032fe9 100644 --- a/src/cmd/arg.cpp +++ b/src/cmd/arg.cpp @@ -1,8 +1,11 @@ #include "cmd/args/arg.hpp" +#include "cmd/args/arg_generic.hpp" +#include namespace fsh { void ArgInput::svalue(const std::string& val, const Lexer::TokenType& type) { + Argument::svalue(val, type); const std::string& txt = val; if (type == Lexer::TokenType::STRING_LITERAL) { str = std::stringstream(txt); @@ -12,7 +15,7 @@ namespace fsh { } } - std::istream& ArgInput::gvalue() { + std::istream& ArgInput::gstream() { if (str) return *str; return *file; } diff --git a/src/cmd/cmd_base.cpp b/src/cmd/cmd_base.cpp index b5e9050..cff130f 100644 --- a/src/cmd/cmd_base.cpp +++ b/src/cmd/cmd_base.cpp @@ -1,9 +1,14 @@ #include "cmd/cmd_base.hpp" +#include "cmd/args/arg.hpp" #include "util/input.hpp" namespace fsh { void Command::execute(FlagNode flag, ArgNodes& vec, std::istream& in, std::ostream& out) { + execute(flag,vec,in,out,arg_factory); + } + + void Command::execute(FlagNode flag, ArgNodes& vec, std::istream& in, std::ostream& out, ArgFactory &arg_factory) { ArgManager args; arg_factory.parse(args, vec, flag); if (arg_factory.ghas_input()) { diff --git a/src/util/input.cpp b/src/util/input.cpp index 8227b9e..146937c 100644 --- a/src/util/input.cpp +++ b/src/util/input.cpp @@ -1,3 +1,4 @@ +#include #ifdef _WIN32 #include @@ -25,6 +26,7 @@ namespace fsh::util { #ifdef _WIN32 /* Ovaj deo koda je namenjen da omoguci koriscenje neke ansi-escape sekvence na windows platformi */ + // TODO: dodati windows pozive za virtual terminal... #else /* Ova porcija koda je preuzata sa https://www.gnu.org/software/libc/manual/html_node/Noncanon-Example.html @@ -51,7 +53,9 @@ namespace fsh::util { int CursorIStreamBuffer::underflow() { if (gptr() < egptr()) return traits_type::to_int_type(*gptr()); - if (read_chars >= input.size()) { readInputToNewLine(); } + if (read_chars >= input.size()) { + if(readInputToNewLine()) return traits_type::eof(); + } int n = input.copy(buffer, sizeof(buffer) - 1, read_chars); read_chars += n; @@ -84,9 +88,12 @@ namespace fsh::util { read_chars = 0; cursor_pos = 0; input = ""; - char c; - while (std::cin.get(c)) { - //std::cout << (int)c; + if(std::cin.peek() == 0x4) { + std::cin.get(); + return 1; + } + while (std::cin.peek() != 0x4) { + char c = std::cin.get(); EscapeSequence e = testForEscapeCodes(c); if (c == '\r') continue; // Skip CR to keep sanity else if (c == 127 || c == 8) { @@ -116,7 +123,8 @@ namespace fsh::util { std::cout << "\033[@" << c; } } - input.push_back(0); + // input.push_back(0); + // std::cout << "AAA" << std::endl; return 0; }