diff options
Diffstat (limited to 'repl.c')
-rw-r--r-- | repl.c | 46 |
1 files changed, 44 insertions, 2 deletions
@@ -1,9 +1,12 @@ #include <u.h> #include <libc.h> +#include <bio.h> #include "dat.h" #include "fns.h" +Rune parsefindmore(int); + void repl(Term *database) { @@ -12,7 +15,10 @@ repl(Term *database) print("?- "); Term *query = parse(fd, 1); Binding *bindings = nil; - int success = evalquery(database, query, &bindings); + Choicepoint *choicestack = nil; + int success; +FindMore: + success = evalquery(database, query, &bindings, &choicestack); if(success == 0) print("false.\n"); else{ @@ -20,10 +26,46 @@ repl(Term *database) print("true.\n"); else{ while(bindings){ - print("%S = %S\n", bindings->name, prettyprint(bindings->value)); + print(" %S = %S%s", + bindings->name, + prettyprint(bindings->value), + bindings->next ? " ,\n" : ""); bindings = bindings->next; } } + if(choicestack != nil){ + print(" "); + if(parsefindmore(fd) == L';'){ + print(";\n"); + goto FindMore; + }else + print(".\n"); + }else{ + print(".\n"); + } } } +} + +Rune +parsefindmore(int fd) +{ + int consctl = open("/dev/consctl", OWRITE); + if(consctl > 0) + write(consctl, "rawon", 5); + else{ + print("Could not open /dev/consctl\n"); + exits("open"); + } + + fd = dup(fd, -1); + Biobuf *input = Bfdopen(fd, OREAD); + Rune peek = Bgetrune(input); + Bterm(input); + + if(consctl > 0){ + write(consctl, "rawoff", 6); + close(consctl); + } + return peek; }
\ No newline at end of file |