X-Git-Url: http://git.droids-corp.org/?p=libcmdline.git;a=blobdiff_plain;f=src%2Fcalculator_standalone%2Fmain.c;h=aa56e40f0c2e712f2b9ae01ccf8d37e6d22d1a22;hp=de5a752ceaf9664301c7df716f073edfcb69fcb7;hb=0c0e81f94cfed584ea3b4baeb5735f4dd0366187;hpb=1c84aafee969908b17be56daeb96682a654ddebf diff --git a/src/calculator_standalone/main.c b/src/calculator_standalone/main.c index de5a752..aa56e40 100644 --- a/src/calculator_standalone/main.c +++ b/src/calculator_standalone/main.c @@ -54,27 +54,10 @@ extern cmdline_parse_ctx_t main_ctx[]; struct cmdline *cl; -/*** main */ - -void basic_char_loop(void) -{ - char c; - - c = -1; - while (1) { - read(cl->s_in, &c, 1); - if (cmdline_in(cl, &c, 1) < 0) - break; - } - cmdline_free(cl); - printf("\n"); -} - -/* #define STANDALONE */ - -int main(void) +int main(void) { struct termios oldterm, term; + int err = 0; tcgetattr(0, &oldterm); memcpy(&term, &oldterm, sizeof(term)); @@ -82,9 +65,17 @@ int main(void) tcsetattr(0, TCSANOW, &term); setbuf(stdin, NULL); cl = cmdline_stdin_new(main_ctx, "calc> "); - basic_char_loop(); + if (cl == NULL) { + err = 1; + goto fail; + } + + cmdline_interact(cl); + cmdline_free(cl); + + fail: tcsetattr(0, TCSANOW, &oldterm); - return 0; + return err; }