cmdline-examples: remove basic_char_loop() and use cmdline_interact()
[libcmdline.git] / src / extension_example / main.c
index ed8c871..7d1a031 100644 (file)
@@ -59,24 +59,10 @@ 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");
-}
-
-int main(void) 
+int main(void)
 {
        struct termios oldterm, term;
+       int err = 0;
 
        tcgetattr(0, &oldterm);
        memcpy(&term, &oldterm, sizeof(term));
@@ -85,10 +71,16 @@ int main(void)
        setbuf(stdin, NULL);
 
        cl = cmdline_stdin_new(main_ctx, "example> ");
-       basic_char_loop();
+       if (cl == NULL) {
+               err = 1;
+               goto fail;
+       }
+       cmdline_interact(cl);
+       cmdline_free(cl);
 
+ fail:
        tcsetattr(fileno(stdin), TCSANOW, &oldterm);
-       return 0;
+       return err;
 }