[Pinfo-devel] r22 - in pinfo/trunk: macros src

Bas Zoetekouw bas at costa.debian.org
Mon Jul 25 20:14:50 UTC 2005


Author: bas
Date: 2005-07-25 20:14:49 +0000 (Mon, 25 Jul 2005)
New Revision: 22

Modified:
   pinfo/trunk/macros/readline.m4
   pinfo/trunk/src/readlinewrapper.c
   pinfo/trunk/src/utils.c
Log:
Fixed the readline code 
 - search and check for libreadline version 5
 - enabled use of libreadline by default
 - fixed cooperation between ncurses and libreadline by specifying a custom
   output routine
 - fixed the history behaviour of the non-libreadline input code:
   the last history entry is shown by default, but it is deleted automatically
   on input of a non-edit key (this fixes Debian bug #222651)


Modified: pinfo/trunk/macros/readline.m4
===================================================================
--- pinfo/trunk/macros/readline.m4	2005-07-25 16:52:10 UTC (rev 21)
+++ pinfo/trunk/macros/readline.m4	2005-07-25 20:14:49 UTC (rev 22)
@@ -44,7 +44,7 @@
 	[ Defined if found readline ])
 
 AC_DEFUN([AC_CHECK_READLINE],[
-	search_readline=false
+	search_readline=true
 	has_readline=false
 
 dnl	CFLAGS=${CFLAGS--O}
@@ -72,7 +72,19 @@
 		AC_SEARCH_READLINE()
 	fi
 
+	if $has_readline
+	then
+		AC_READLINE_VERSION()
+		if test $readline_version -ge 5
+		then
+			AC_DEFINE(HAS_READLINE)
+		else
+			AC_MSG_RESULT(Readline version $readline_version is too old; needs at least version 5)
+		fi
+	fi
 
+
+
 ])
 	
 dnl
@@ -87,17 +99,36 @@
  	    READLINE_LIBS="$3"
 	    READLINE_INCLUDES="$4"
 	    search_readline=false
-            AC_DEFINE(HAS_READLINE)
             has_readline=true
 	fi
     fi
 ])
 
 AC_DEFUN([AC_SEARCH_READLINE], [
-    AC_CHECKING("location of readline.h file")
+    AC_CHECKING(location of readline.h file)
 
     AC_READLINE(/usr/include, readline.h, -lreadline,, "readline on /usr/include")
     AC_READLINE(/usr/include/readline, readline.h, -lreadline, -I/usr/include/readline, "readline on /usr/include/readline")
     AC_READLINE(/usr/local/include, readline.h, -L/usr/local/lib -lreadline, -I/usr/local/include, "readline on /usr/local")
     AC_READLINE(/usr/local/include/readline, readline.h, -L/usr/local/lib -L/usr/local/lib/readline -lreadline, -I/usr/local/include/readline, "readline on /usr/local/include/readline")
 ] ) 
+
+AC_DEFUN([AC_READLINE_VERSION], [
+	AC_CHECKING(for readline version)
+	readline_version=unknown
+cat > conftest.$ac_ext <<EOF
+[#]line __oline__ "configure"
+#include "confdefs.h"
+#include <readline.h>
+#undef VERSION
+VERSION:RL_VERSION_MAJOR.RL_VERSION_MINOR
+EOF
+	if (eval "$ac_cpp $READLINE_INCLUDES conftest.$ac_ext") 2>&AC_FD_CC |
+	  egrep "VERSION:" >conftest.out 2>&1; then
+changequote(,)dnl
+		readline_version=`cat conftest.out|sed -e 's/ //g' -e 's/^VERSION://' -e 's/\..*$//'`
+changequote([,])dnl
+	fi
+	rm -rf conftest*
+	AC_MSG_RESULT($readline_version)
+] )

Modified: pinfo/trunk/src/readlinewrapper.c
===================================================================
--- pinfo/trunk/src/readlinewrapper.c	2005-07-25 16:52:10 UTC (rev 21)
+++ pinfo/trunk/src/readlinewrapper.c	2005-07-25 20:14:49 UTC (rev 22)
@@ -11,6 +11,8 @@
 char *
 readlinewrapper(char *prompt)
 {
+	/* number of keys pressed */
+	int numkeys = 0;
 	/* initial buffer for the read line */
 	char *buf = xmalloc(1024);
 	/* start coords of input line */
@@ -44,7 +46,10 @@
 	strcpy(rlhistory[rlhistorylen - 1], buf);
 	/* call history to be present */
 	if (CallReadlineHistory)
+	{
 		ungetch(KEY_UP);
+		numkeys = -1;
+	}
 
 	while (key != '\n')
 	{
@@ -101,8 +106,8 @@
 						/*  recall value from history to input buf */
 						strcpy(buf, rlhistory[rlhistorypos - 1]);
 					}
-				if (cursor > strlen(buf))
-					cursor = strlen(buf);
+				cursor = strlen(buf);
+				numkeys = -1;
 				break;
 			/* forwards-history call */
 			case KEY_DOWN:
@@ -112,8 +117,8 @@
 						rlhistorypos++;
 						strcpy(buf, rlhistory[rlhistorypos - 1]);
 					}
-				if (cursor > strlen(buf))
-					cursor = strlen(buf);
+				cursor = strlen(buf);
+				numkeys = -1;
 				break;
 				/* eliminate nonprintable chars */
 			case '\n':
@@ -133,6 +138,19 @@
 			default:
 				if (key >= 32)
 				{
+					/* if this is the first key, delete the buffer */
+					if (numkeys==0 && cursor!=0)
+					{
+						for (i=0; buf[i]!=0; i++)
+							buf[i] = 0;
+						cursor = 0;
+						/* and empty the line */
+						move(origy, origx);
+						for (i = origx; i < maxx; i++)
+							addch(' ');
+						move(origy, origx + cursor);
+					}
+					
 					/* if the cursor is not at the last pos */
 					if (strlen(buf + cursor))
 					{
@@ -160,6 +178,8 @@
 		addstr(buf);
 		move(origy, origx + cursor);
 
+		numkeys++;
+
 	}
 	strcpy(rlhistory[rlhistorylen - 1], buf);
 	if (strlen(buf))

Modified: pinfo/trunk/src/utils.c
===================================================================
--- pinfo/trunk/src/utils.c	2005-07-25 16:52:10 UTC (rev 21)
+++ pinfo/trunk/src/utils.c	2005-07-25 20:14:49 UTC (rev 22)
@@ -21,14 +21,6 @@
 int pinfo_re_offset = -1;
 #endif
 
-/*
- * Readline does not work well here. VT100 screen is ruined then.
- *
- * But if you want enable readline at compile time
- * [ ./configure --with-readline ]
- *
- */
-
 #ifdef HAS_READLINE
 #include <readline/readline.h>
 #include <readline/history.h>
@@ -216,37 +208,49 @@
 	}
 }
 
+#ifdef HAS_READLINE
+/* custom function that readline will use to display text */
+void
+my_rl_display()
+{
+	/* go to the bottom line, empty it, and print the prompt and buffer */
+	attrset(bottomline);
+	mymvhline(maxy - 1, 0, ' ', maxx);
+	move(maxy-1,0);
+	printw("%s%s", rl_prompt, rl_line_buffer);
+	refresh();
+}
+#endif
+
 char *
 getstring(char *prompt)
 {
-	/*
-	 * As above -- readline is dangerous ;)
-	 * But if you want enable readline at compile time
-	 * [ ./configure --with-readline ]
-	 *
-	 */
+	char *buf;
 
-#ifndef HAS_READLINE
+#ifdef HAS_READLINE
 
+	curs_set(1);
 	move(maxy - 1, 0);
-	return readlinewrapper(prompt);
+	refresh();
 
+	rl_readline_name = PACKAGE;
+	
+	/* set display function for readline to my_rl_display and call readline */
+	rl_redisplay_function = my_rl_display;
+	buf = readline(prompt);
+	if (buf && *buf) 
+		add_history(buf);
+	
+	curs_set(0);
+
 #else
 
-	char *buf;
-	TERMINAL *term = cur_term;
-	curs_set(1);
 	move(maxy - 1, 0);
-	refresh();
-	sigblock(sigmask(SIGINT) | sigmask(SIGPIPE));
-	buf = readline(prompt);
-	cur_term = term;
-	sigblock(sigmask(SIGPIPE));
-	add_history(buf);
-	curs_set(0);
-	return buf;
+	buf = readlinewrapper(prompt);
+
 #endif
 
+	return buf;
 }
 
 void




More information about the Pinfo-devel mailing list