Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #45 from jvdcf/hotfix
Browse files Browse the repository at this point in the history
Errors with undo()
  • Loading branch information
guilherme-ds-matos authored Nov 2, 2023
2 parents 2191697 + 79ad167 commit 0dc143e
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions src/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void Runtime::process_args(std::vector<std::string> args) {
}

if (args[0] == "undo") {
if (args.size() != 0) {
if (args.size() != 1) {
std::cerr << "ERROR: USAGE: undo" << std::endl;
} else {
Process t(TypeOfRequest::Undo);
Expand Down Expand Up @@ -640,29 +640,34 @@ void Runtime::handle_process(Process p) {
}

// handle undo--------------------------------------------------------------------------------------------------------
if (p.get_type() == TypeOfRequest::Undo) {
Process to_revert = history.top();
history.pop();
if (to_revert.get_type() == TypeOfRequest::Remove) {
Process t = Process(TypeOfRequest::Add);
t.add_operand(to_revert.get_ops()[0]);
t.add_operand(to_revert.get_ops()[1]);
t.add_operand(to_revert.get_ops()[2]);
procs.push(t);
}
if (to_revert.get_type() == TypeOfRequest::Add) {
if (p.get_type() == TypeOfRequest::Undo) {
if (history.empty()) {
std::cerr << "ERROR: There is nothing to undo." << std::endl;
return;
}

Process to_revert = history.top();
history.pop();
if (to_revert.get_type() == TypeOfRequest::Remove) {
Process t = Process(TypeOfRequest::Add);
t.add_operand(to_revert.get_ops()[0]);
t.add_operand(to_revert.get_ops()[1]);
t.add_operand(to_revert.get_ops()[2]);
procs.push(t);
}
if (to_revert.get_type() == TypeOfRequest::Add) {
Process t = Process(TypeOfRequest::Remove);
t.add_operand(to_revert.get_ops()[0]);
t.add_operand(to_revert.get_ops()[1]);
procs.push(t);
}
if (to_revert.get_type() == TypeOfRequest::Switch) {
procs.push(to_revert);
}
Process pop = Process(TypeOfRequest::PopHistory);
procs.push(pop);
return;
}
if (to_revert.get_type() == TypeOfRequest::Switch) {
procs.push(to_revert);
}
Process pop = Process(TypeOfRequest::PopHistory);
procs.push(pop);
return;
}

// handle pop
if (p.get_type() == TypeOfRequest::PopHistory) {
Expand Down

0 comments on commit 0dc143e

Please sign in to comment.