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)
{
int s;
s = cmdline_tcpv4_listen(INADDR_ANY, 1234);
cl = cmdline_accept(main_ctx, "example> ", s);
- basic_char_loop();
+ if (cl == NULL)
+ return 1;
+ cmdline_interact(cl);
+ cmdline_free(cl);
return 0;
}
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));
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;
}
/*** 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));
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;
}
/*** main */
-void basic_char_loop(void)
-{
- char c;
-
- c = -1;
- /* XXX */
- while (1) {
- read(cl->s_in, &c, 1);
- if (cmdline_in(cl, &c, 1) < 0) {
- break;
- }
- }
- cmdline_free(cl);
- printf("\n");
-}
-
int main(void)
{
struct termios oldterm, term;
setbuf(stdin, NULL);
cl = cmdline_stdin_new(main_ctx, "root> ");
- basic_char_loop();
+ cmdline_interact(cl);
+ cmdline_free(cl);
tcsetattr(fileno(stdin), TCSANOW, &oldterm);
return 0;