Finished Batch + Minor improvements
This commit is contained in:
@ -3,8 +3,10 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "cmd/cmd_base.hpp"
|
||||
#include "cmd/cmd_batch.hpp"
|
||||
#include "cmd/cmd_date.hpp"
|
||||
#include "cmd/cmd_echo.hpp"
|
||||
#include "cmd/cmd_head.hpp"
|
||||
#include "cmd/cmd_misc.hpp"
|
||||
#include "cmd/cmd_time.hpp"
|
||||
#include "cmd/cmd_touch.hpp"
|
||||
@ -38,9 +40,11 @@ namespace fsh {
|
||||
cmds["rm"] = Command::register_cmd<CmdRM>();
|
||||
cmds["wc"] = Command::register_cmd<CmdWc>();
|
||||
cmds["date"] = Command::register_cmd<CmdDate>();
|
||||
cmds["head"] = Command::register_cmd<CmdHead>();
|
||||
cmds["time"] = Command::register_cmd<CmdTime>();
|
||||
cmds["echo"] = Command::register_cmd<CmdEcho>();
|
||||
cmds["exit"] = Command::register_cmd<CmdExit>();
|
||||
cmds["batch"] = Command::register_cmd<CmdBatch>();
|
||||
cmds["touch"] = Command::register_cmd<CmdTouch>();
|
||||
cmds["debug"] = Command::register_cmd<CmdPrintTree>();
|
||||
cmds["prompt"] = Command::register_cmd<CmdPrompt>();
|
||||
|
||||
25
include/cmd/cmd_batch.hpp
Normal file
25
include/cmd/cmd_batch.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "cmd/cmd_base.hpp"
|
||||
#include "fsh.hpp"
|
||||
|
||||
namespace fsh {
|
||||
|
||||
class CmdBatch : public Command {
|
||||
|
||||
protected:
|
||||
virtual void register_flags() override {
|
||||
ArgFactory& factory = get_factory();
|
||||
factory.add_input_rule();
|
||||
}
|
||||
|
||||
virtual void run(std::istream& in, std::ostream& out, ArgManager& args) override {
|
||||
std::string s;
|
||||
while (std::getline(in, s)) {
|
||||
if(s == "") continue;
|
||||
fsh::instance().run_line(s, util::cin, out);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@ -14,9 +14,11 @@ namespace fsh {
|
||||
|
||||
virtual void run(std::istream& in, std::ostream& out, ArgManager& args) override {
|
||||
std::string s;
|
||||
std::string o;
|
||||
while (std::getline(in, s)) { o += s + "\n"; }
|
||||
out << o;
|
||||
char c;
|
||||
while (in.get(c)) {
|
||||
s+=c;
|
||||
}
|
||||
out << s;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
29
include/cmd/cmd_head.hpp
Normal file
29
include/cmd/cmd_head.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include "cmd/cmd_base.hpp"
|
||||
|
||||
namespace fsh {
|
||||
|
||||
class CmdHead : public Command {
|
||||
|
||||
protected:
|
||||
virtual void register_flags() override {
|
||||
ArgFactory& factory = get_factory();
|
||||
factory.add_rule<int>((std::string) "-n", true);
|
||||
factory.add_input_rule();
|
||||
}
|
||||
|
||||
virtual void run(std::istream& in, std::ostream& out, ArgManager& args) override {
|
||||
std::string s;
|
||||
std::string o;
|
||||
|
||||
int count = args.get<int>("-n").value();
|
||||
while (std::getline(in, s)) {
|
||||
if(count-- < 1) break;
|
||||
o += s + "\n";
|
||||
}
|
||||
out << o;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
@ -26,12 +26,13 @@ namespace fsh {
|
||||
|
||||
virtual void run(std::istream& in, std::ostream& out, ArgManager& args) override {
|
||||
std::string line;
|
||||
std::getline(in, line);
|
||||
while(std::getline(in, line)) {
|
||||
auto tokens = Lexer::process(line);
|
||||
auto ast = AstFactory::generate_ast(tokens);
|
||||
|
||||
auto tokens = Lexer::process(line);
|
||||
auto ast = AstFactory::generate_ast(tokens);
|
||||
ast->print(0);
|
||||
}
|
||||
|
||||
ast->print(0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -1,15 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "cmd/args/arg.hpp"
|
||||
#include "cmd/args/arg_generic.hpp"
|
||||
#include "cmd/args/arg_input.hpp"
|
||||
#include "cmd/args/arg_manager.hpp"
|
||||
#include "cmd/cmd_base.hpp"
|
||||
#include "util/input.hpp"
|
||||
#include "util/stringliteral.hpp"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user