Just use fgets in that case. If the user hits Ctrl-D a new-line
is also printed.
#include <config.h>
#endif
#include <config.h>
#endif
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char buf[100000];
char *cp;
const char *bp = buf;
char buf[100000];
char *cp;
const char *bp = buf;
#if HAVE_READLINE_READLINE_H
#if HAVE_READLINE_READLINE_H
- char* line_in;
- line_in = readline("ZOOM>");
- if (!line_in)
+ line_in = readline("ZOOM>");
+ if (!line_in)
+ {
+ putchar('\n');
+ res = -1;
+ break;
+ }
#if HAVE_READLINE_HISTORY_H
#if HAVE_READLINE_HISTORY_H
- if (*line_in)
- add_history(line_in);
+ if (*line_in)
+ add_history(line_in);
- if (strlen(line_in) > sizeof(buf)-1)
- {
- printf("Input line too long\n");
- res = 1;
- break;
+ if (strlen(line_in) > sizeof(buf)-1)
+ {
+ printf("Input line too long\n");
+ res = 1;
+ break;
+ }
+ strcpy(buf,line_in);
+ free(line_in);
- strcpy(buf,line_in);
- free(line_in);
-#else
- printf("ZOOM>"); fflush(stdout);
- if (!fgets(buf, sizeof(buf)-1, stdin))
+#endif
+ if (!line_in) /* no line buffer via readline or not enabled at all */
+ printf("ZOOM>"); fflush(stdout);
+ if (!fgets(buf, sizeof(buf)-1, stdin))
+ {
+ res = -1;
+ break;
+ }
if ((cp = strchr(buf, '\n')))
*cp = '\0';
res = cmd_parse(c, r, options, &bp);
if ((cp = strchr(buf, '\n')))
*cp = '\0';
res = cmd_parse(c, r, options, &bp);