summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/ntpq/ntpq.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ntp/ntpq/ntpq.c')
-rw-r--r--contrib/ntp/ntpq/ntpq.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/contrib/ntp/ntpq/ntpq.c b/contrib/ntp/ntpq/ntpq.c
index f529d61..34404b2 100644
--- a/contrib/ntp/ntpq/ntpq.c
+++ b/contrib/ntp/ntpq/ntpq.c
@@ -21,6 +21,11 @@
#define closesocket close
#endif /* SYS_WINNT */
+#ifdef HAVE_LIBREADLINE
+# include <readline/readline.h>
+# include <readline/history.h>
+#endif /* HAVE_LIBREADLINE */
+
#ifdef SYS_VXWORKS
/* vxWorks needs mode flag -casey*/
#define open(name, flags) open(name, flags, 0777)
@@ -1259,22 +1264,33 @@ doquery(
static void
getcmds(void)
{
- char line[MAXLINE];
-
- for (;;) {
- if (interactive) {
-#ifdef VMS /* work around a problem with mixing stdout & stderr */
- fputs("",stdout);
+#ifdef HAVE_LIBREADLINE
+ char *line;
+
+ for (;;) {
+ if ((line = readline(interactive?prompt:"")) == NULL) return;
+ if (*line) add_history(line);
+ docmd(line);
+ free(line);
+ }
+#else /* not HAVE_LIBREADLINE */
+ char line[MAXLINE];
+
+ for (;;) {
+ if (interactive) {
+#ifdef VMS /* work around a problem with mixing stdout & stderr */
+ fputs("",stdout);
#endif
- (void) fputs(prompt, stderr);
- (void) fflush(stderr);
- }
+ (void) fputs(prompt, stderr);
+ (void) fflush(stderr);
+ }
- if (fgets(line, sizeof line, stdin) == NULL)
- return;
+ if (fgets(line, sizeof line, stdin) == NULL)
+ return;
- docmd(line);
- }
+ docmd(line);
+ }
+#endif /* not HAVE_LIBREADLINE */
}
OpenPOWER on IntegriCloud