Finished all commands except batch
This commit is contained in:
26
CMakeLists.txt
Normal file
26
CMakeLists.txt
Normal file
@ -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})
|
||||||
@ -1,8 +1,11 @@
|
|||||||
#include "cmd/args/arg.hpp"
|
#include "cmd/args/arg.hpp"
|
||||||
|
#include "cmd/args/arg_generic.hpp"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace fsh {
|
namespace fsh {
|
||||||
|
|
||||||
void ArgInput::svalue(const std::string& val, const Lexer::TokenType& type) {
|
void ArgInput::svalue(const std::string& val, const Lexer::TokenType& type) {
|
||||||
|
Argument<std::string>::svalue(val, type);
|
||||||
const std::string& txt = val;
|
const std::string& txt = val;
|
||||||
if (type == Lexer::TokenType::STRING_LITERAL) {
|
if (type == Lexer::TokenType::STRING_LITERAL) {
|
||||||
str = std::stringstream(txt);
|
str = std::stringstream(txt);
|
||||||
@ -12,7 +15,7 @@ namespace fsh {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::istream& ArgInput::gvalue() {
|
std::istream& ArgInput::gstream() {
|
||||||
if (str) return *str;
|
if (str) return *str;
|
||||||
return *file;
|
return *file;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,14 @@
|
|||||||
#include "cmd/cmd_base.hpp"
|
#include "cmd/cmd_base.hpp"
|
||||||
|
#include "cmd/args/arg.hpp"
|
||||||
#include "util/input.hpp"
|
#include "util/input.hpp"
|
||||||
|
|
||||||
namespace fsh {
|
namespace fsh {
|
||||||
|
|
||||||
void Command::execute(FlagNode flag, ArgNodes& vec, std::istream& in, std::ostream& out) {
|
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;
|
ArgManager args;
|
||||||
arg_factory.parse(args, vec, flag);
|
arg_factory.parse(args, vec, flag);
|
||||||
if (arg_factory.ghas_input()) {
|
if (arg_factory.ghas_input()) {
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#include <string>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
@ -25,6 +26,7 @@ namespace fsh::util {
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* Ovaj deo koda je namenjen da omoguci koriscenje neke ansi-escape sekvence na windows platformi */
|
/* Ovaj deo koda je namenjen da omoguci koriscenje neke ansi-escape sekvence na windows platformi */
|
||||||
|
// TODO: dodati windows pozive za virtual terminal...
|
||||||
#else
|
#else
|
||||||
|
|
||||||
/* Ova porcija koda je preuzata sa https://www.gnu.org/software/libc/manual/html_node/Noncanon-Example.html
|
/* 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() {
|
int CursorIStreamBuffer::underflow() {
|
||||||
if (gptr() < egptr()) return traits_type::to_int_type(*gptr());
|
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);
|
int n = input.copy(buffer, sizeof(buffer) - 1, read_chars);
|
||||||
read_chars += n;
|
read_chars += n;
|
||||||
@ -84,9 +88,12 @@ namespace fsh::util {
|
|||||||
read_chars = 0;
|
read_chars = 0;
|
||||||
cursor_pos = 0;
|
cursor_pos = 0;
|
||||||
input = "";
|
input = "";
|
||||||
char c;
|
if(std::cin.peek() == 0x4) {
|
||||||
while (std::cin.get(c)) {
|
std::cin.get();
|
||||||
//std::cout << (int)c;
|
return 1;
|
||||||
|
}
|
||||||
|
while (std::cin.peek() != 0x4) {
|
||||||
|
char c = std::cin.get();
|
||||||
EscapeSequence e = testForEscapeCodes(c);
|
EscapeSequence e = testForEscapeCodes(c);
|
||||||
if (c == '\r') continue; // Skip CR to keep sanity
|
if (c == '\r') continue; // Skip CR to keep sanity
|
||||||
else if (c == 127 || c == 8) {
|
else if (c == 127 || c == 8) {
|
||||||
@ -116,7 +123,8 @@ namespace fsh::util {
|
|||||||
std::cout << "\033[@" << c;
|
std::cout << "\033[@" << c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
input.push_back(0);
|
// input.push_back(0);
|
||||||
|
// std::cout << "AAA" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user