This message is in MIME format
--_=XFMail.1.3.p0.Linux:990329192352:425=_
Content-Type: text/plain; charset=us-ascii
Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk>
writes:>Great... Now do you have a fix for the fix? ;^)
Here are two patches.
1. Patch to scan.c which fixes this bug, and similar ones,
by ensuring that functions which set the console prompt
reset it after use.
2. Implements Peter Holzer's suggestion, adding a
"prompt" argument to readline. Since readline is an
"internal" function I did this in the C code. The
alternative of adding some interpreted code would be
simpler. Caveat emptor with this one, obviously.
--_=XFMail.1.3.p0.Linux:990329192352:425=_
Content-Disposition: attachment; filename="scan.diff"
Content-Transfer-Encoding: 7bit
Content-Description: scan.diff
Content-Type: text/plain; charset=us-ascii; name=scan.diff; SizeOnDisk=609
--- scan.c Sun Mar 28 10:03:05 1999
+++ scan.c.fixed Sun Mar 28 10:32:44 1999
@@ -276,6 +276,7 @@
}
}
if (!quiet) REprintf("Read %d items\n", n);
+ if (ttyflag) ConsolePrompt[0] = '\0';
if (n == 0) {
UNPROTECT(1);
@@ -407,6 +408,7 @@
n++;
}
if (!quiet) REprintf("Read %d lines\n", n);
+ if (ttyflag) ConsolePrompt[0] = '\0';
for (i = 0; i < nc; i++) {
old = VECTOR(ans)[i];
@@ -775,6 +777,8 @@
*bufp++ = c;
}
*bufp++ = '\0';
+ ConsolePrompt[0] = '\0';
+
bufp = buffer;
while (isspace(*bufp)) bufp++;
first = LENGTH(CAR(args)) + 1;
--_=XFMail.1.3.p0.Linux:990329192352:425=_
Content-Disposition: attachment; filename="readline.diff"
Content-Transfer-Encoding: 7bit
Content-Description: readline.diff
Content-Type: text/plain; charset=us-ascii; name=readline.diff; SizeOnDisk=3136
diff -uNr R-0.63.3/src/library/base/R/New-Internal.R R-0.63.3-patched/src/librar
y/base/R/New-Internal.R
--- R-0.63.3/src/library/base/R/New-Internal.R Wed Dec 9 07:52:28 1998
+++ R-0.63.3-patched/src/library/base/R/New-Internal.R Sun Mar 28 13:47:39 1999
@@ -89,7 +89,7 @@
stop("rank(.., na.last != TRUE) does not yet work in R.")
.Internal(rank(x))
}
-readline <- function().Internal(readline())
+readline <- function(prompt="").Internal(readline(prompt))
search <- function().Internal(search())
sink <- function(file=NULL, append = FALSE)
diff -uNr R-0.63.3/src/library/base/man/readline.Rd R-0.63.3-patched/src/library
/base/man/readline.Rd
--- R-0.63.3/src/library/base/man/readline.Rd Wed Nov 19 18:38:56 1997
+++ R-0.63.3-patched/src/library/base/man/readline.Rd Sun Mar 28 13:41:52 1999
@@ -1,9 +1,12 @@
\name{readline}
\title{Read a Line from the Terminal}
\usage{
-readline()
+readline(prompt="")
}
\alias{readline}
+\arguments{
+\item{prompt}{the string printed when prompting the user for input.}
+}
\description{
\code{readline} reads a line from the terminal, returning it as a
character string.
diff -uNr R-0.63.3/src/main/names.c R-0.63.3-patched/src/main/names.c
--- R-0.63.3/src/main/names.c Sun Jan 31 12:24:09 1999
+++ R-0.63.3-patched/src/main/names.c Sun Mar 28 12:55:46 1999
@@ -482,7 +482,7 @@
{"substitute", do_substitute, 0, 0, -1, PP_FUNCALL},
{"quit", do_quit, 0, 111, 1, PP_FUNCALL},
{"interactive", do_interactive, 0, 0, 0, PP_FUNCALL},
-{"readline", do_readln, 0, 11, 0, PP_FUNCALL},
+{"readline", do_readln, 0, 11, 1, PP_FUNCALL},
{"menu", do_menu, 0, 11, 1, PP_FUNCALL},
{"print.default",do_printdefault,0, 111, 6, PP_FUNCALL},
{"print.matrix",do_printmatrix, 0, 111, 5, PP_FUNCALL},
diff -uNr R-0.63.3/src/main/scan.c R-0.63.3-patched/src/main/scan.c
--- R-0.63.3/src/main/scan.c Wed Feb 17 18:51:21 1999
+++ R-0.63.3-patched/src/main/scan.c Sun Mar 28 15:07:24 1999
@@ -24,11 +24,12 @@
#define SCAN_BLOCKSIZE 1000
/* The size of the console buffer */
#define CONSOLE_BUFFER_SIZE 1024
+#define CONSOLE_PROMPT_SIZE 32
static char ConsoleBuf[CONSOLE_BUFFER_SIZE];
static char *ConsoleBufp;
static int ConsoleBufCnt;
-static char ConsolePrompt[32];
+static char ConsolePrompt[CONSOLE_PROMPT_SIZE];
#ifdef NOT_used
static void InitConsoleGetchar()
@@ -731,10 +732,20 @@
{
int c;
char buffer[MAXELTSIZE], *bufp = buffer;
- SEXP ans;
+ SEXP ans, prompt;
checkArity(op,args);
+ prompt = CAR(args);
+ if (prompt == R_NilValue)
+ PROTECT(prompt);
+ else {
+ PROTECT(prompt = coerceVector(prompt, STRSXP));
+ if(length(prompt) > 0)
+ strncpy(ConsolePrompt, CHAR(*STRING(prompt)),
+ CONSOLE_PROMPT_SIZE - 1);
+ }
+
/* skip white space */
while ((c= ConsoleGetchar()) == ' ' || c=='\t');
if (c != '\n' && c != R_EOF) {
@@ -749,9 +760,11 @@
while (isspace(*--bufp))
;
*++bufp = '\0';
+ ConsolePrompt[0] = '\0';
+
PROTECT(ans = allocVector(STRSXP,1));
STRING(ans)[0] = mkChar(buffer);
- UNPROTECT(1);
+ UNPROTECT(2);
return ans;
}
--_=XFMail.1.3.p0.Linux:990329192352:425=_--
End of MIME message
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To:
r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._