shithub: riscv

Download patch

ref: 05b08f6665b8b0c14c0cb4caa42929db8d26c6c9
parent: 6901f0c40f4c72fe730a4daab3ae30f930a5e968
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Fri Sep 16 14:46:46 EDT 2022

pc: remove -n option and check if stdin is cons instead

--- a/sys/man/1/pc
+++ b/sys/man/1/pc
@@ -16,11 +16,6 @@
 .I Pc
 prints the value of all expressions that are not terminated by a semicolon.
 .PP
-.I Pc
-can be run non-interactively by using the
-.B -n
-switch. In this case no input prompt is printed.
-.PP
 Expressions can use the C-like operators
 .TP
 .B + - * ** \fR(exponentiation\fR)
--- a/sys/src/cmd/pc.y
+++ b/sys/src/cmd/pc.y
@@ -1025,8 +1025,9 @@
 }
 
 void
-main(int argc, char **argv)
+main(int, char **)
 {
+	char buf[32];
 	Keyword *kw;
 	
 	fmtinstall('B', mpfmt);
@@ -1056,13 +1057,10 @@
 	regfunc("rev", fnrev, 2);
 	regfunc("cat", fncat, -1);
 
-	prompt = 1;
-	ARGBEGIN{
-	case 'n': prompt = 0; break;
-	}ARGEND;
-	
+	prompt = fd2path(0, buf, sizeof buf) >= 0 && strstr(buf, "/dev/cons") != nil;
 	in = Bfdopen(0, OREAD);
-	if(in == nil) sysfatal("Bfdopen: %r");
+	if(in == nil)
+		sysfatal("Bfdopen: %r");
 	extern void yyparse(void);
 	yyparse();
 	extern int yynerrs;