editline support

This commit is contained in:
Kelvin Sherlock 2016-02-01 21:17:46 -05:00
parent 5723656988
commit af4b0e2eeb
2 changed files with 39 additions and 19 deletions

View File

@ -113,6 +113,8 @@ add_executable(mpw-shell mpw-shell.cpp mpw-shell-read.cpp mpw-shell-token.cpp mp
mpw-shell-parser.cpp value.cpp mpw-shell-quote.cpp
phase1.cpp phase2.cpp phase2-parser.cpp command.cpp environment.cpp builtins.cpp)
target_link_libraries(mpw-shell edit)
# all this for -std=c++14
set_property (TARGET mpw-shell PROPERTY CXX_STANDARD 14)
set_property (TARGET mpw-shell PROPERTY CXX_STANDARD_REQUIRED TRUE)

View File

@ -16,7 +16,8 @@
#include "phase2.h"
#include "command.h"
//#include <histedit.h>
#include <editline/readline.h>
// should set {MPW}, {MPWVersion}, then execute {MPW}StartUp
void init(Environment &e) {
@ -56,6 +57,39 @@ int read_stdin(phase1 &p) {
return 0;
}
int interactive(phase1 &p) {
for(;;) {
char *cp = readline("# ");
if (!cp) break;
std::string s(cp);
free(cp);
if (s.empty()) continue;
add_history(s.c_str());
s.push_back('\n');
try {
p.process(s);
} catch(std::exception &ex) {
fprintf(stderr, "%s\n", ex.what());
p.reset();
}
}
try {
p.finish();
} catch(std::exception &ex) {
fprintf(stderr, "%s\n", ex.what());
p.reset();
}
fprintf(stdout, "\n");
return 0;
}
int main(int argc, char **argv) {
Environment e;
@ -76,24 +110,8 @@ int main(int argc, char **argv) {
p2.process(s);
};
*/
read_stdin(p1);
interactive(p1);
p2.finish();
/*
try {
head = read_fd(0);
} catch (std::exception &ex) {
fprintf(stderr, "%s\n", ex.what());
exit(1);
}
try {
int status = execute(head);
exit(status);
} catch(std::exception &ex) {
fprintf(stderr, "%s\n", ex.what());
exit(1);
}
*/
return 0;
}