]> git.sur5r.net Git - openldap/commitdiff
Add readline support. Change prompt to "saucer dn=CURRENT-DN> ".
authorHallvard Furuseth <hallvard@openldap.org>
Tue, 9 Mar 1999 22:50:06 +0000 (22:50 +0000)
committerHallvard Furuseth <hallvard@openldap.org>
Tue, 9 Mar 1999 22:50:06 +0000 (22:50 +0000)
contrib/saucer/Makefile.in
contrib/saucer/main.c

index 2dbac4e8993377cea0a006535048c87511beb014..39aa66577a0526e5a690ced6c8e116ecc490f591 100644 (file)
@@ -6,8 +6,10 @@ OBJS=  main.o
 LDAP_INCDIR= ../../include
 LDAP_LIBDIR= ../../libraries
 
+READLINE_LIBS = @READLINE_LIBS@
+
 XLIBS =  -lldap -llber -llutil
-XXLIBS = $(KRB_LIBS) $(LUTIL_LIBS)
+XXLIBS = $(KRB_LIBS) $(LUTIL_LIBS) $(READLINE_LIBS) $(TERMCAP_LIBS)
 
 saucer:        ${OBJS} $(LDAP_LIBDEPEND)
        $(LTLINK) -o $@ $(OBJS) $(LIBS)
index 12d967a3b6a8d2dc04bca40c7c20f30bd29bcfd2..cc52dee482e811f04cd1b7ef56b37cb6f6c128e5 100644 (file)
@@ -13,6 +13,8 @@
  * 'saucer' LDAP command-line client source code.
  *
  * Author: Eric Rosenquist, 1994.
+ *
+ * 07-Mar-1999 readline support added: O. Steffensen (oddbjorn@tricknology.org)
  */
 
 #include "portable.h"
 #include <stdio.h>
 #include <stdlib.h>
 
+#ifdef HAVE_READLINE
+#  include <readline/readline.h>
+#  ifdef HAVE_READLINE_HISTORY_H
+#    include <readline/history.h>
+#  endif
+#endif
+
 #include <ac/ctype.h>
 #include <ac/string.h>
 #include <ac/unistd.h>
@@ -528,13 +537,39 @@ void do_commands(FILE *file)
 {
        char    cmd_buf[BUFSIZ];
        int             tty = isatty(fileno(file));
+       char    *buf = cmd_buf;
+       int     status;
 
        for (;;) {
                if (tty)
-                       printf("Cmd? ");
-               if (!fgets(cmd_buf, sizeof(cmd_buf), file))
-                       break;
-               if (do_command(cmd_buf))
+               {
+                       char    prompt[40];
+                       sprintf(prompt, (strlen(default_dn) < 18
+                                        ? "saucer dn=%s> "
+                                        : "saucer dn=%.15s..> "), default_dn);
+#ifndef HAVE_READLINE
+                       fputs (prompt, stdout);
+#else
+                       buf = readline (prompt);
+                       if (!buf)
+                               break;
+                       add_history (buf);
+#endif
+               }
+#ifdef HAVE_READLINE
+               else
+#endif
+               {
+                       if (!fgets(cmd_buf, sizeof(cmd_buf), file))
+                               break;
+               }
+
+               status = do_command(buf);
+#ifdef HAVE_READLINE
+               if (tty)
+                       free(buf);
+#endif
+               if (status)
                        break;
        }
 }