This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: Different behavior for -s argument in Kawa 2.0?
- From: Per Bothner <per at bothner dot com>
- To: kawa at sourceware dot org
- Cc: Jeff Gonis <jeff dot gonis at gmail dot com>
- Date: Fri, 09 Jan 2015 17:13:00 -0800
- Subject: Re: Different behavior for -s argument in Kawa 2.0?
- Authentication-results: sourceware.org; auth=none
- References: <CAFVyn8RdRnhc9DGpzT=oA6sQ0oWcbRM71hYvVUROV+7grKkTMQ at mail dot gmail dot com> <CAFVyn8SzaE6Og3UT9+CXQJoPLRBZ7BD6pRSRznUcrxpZVXEC8w at mail dot gmail dot com> <54B03F22 dot 7050801 at bothner dot com> <CAFVyn8S9Tdzdwmczg883U2yXmZUmRMxArtf2sXBKA2HhjXTCNA at mail dot gmail dot com> <687DFB7D-EADA-43CC-9242-B1A0C9C8B7A2 at theptrgroup dot com> <54B05E87 dot 1050101 at bothner dot com> <54B066AF dot 5050804 at bothner dot com> <54B06CEB dot 3090902 at bothner dot com>
On 01/09/2015 04:06 PM, Per Bothner wrote:
On 01/09/2015 03:39 PM, Per Bothner wrote:
On 01/09/2015 03:04 PM, Per Bothner wrote:
A possible solution is to add a --console flag (similar to
sh's -i flag), which would be the inverse of the --no-console flag,
in that it would force haveConsole to return true.
Please try the attached patch. You will need to specify --console.
You shouldn't don't need to specify -s.
The patch doesn't work, because setHaveConsole is executed before
InPort is initialized.
Please try the attached console2.patch instead.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
Index: gnu/Makefile.am
===================================================================
--- gnu/Makefile.am (revision 8257)
+++ gnu/Makefile.am (working copy)
@@ -221,6 +221,7 @@
kawa/io/BinaryOutPort.java \
kawa/io/CharArrayInPort.java \
kawa/io/CharArrayOutPort.java \
+ kawa/io/CheckConsole.java \
kawa/io/FilePath.java \
kawa/io/InPort.java \
kawa/io/LogWriter.java \
Index: gnu/Makefile.in
===================================================================
--- gnu/Makefile.in (revision 8257)
+++ gnu/Makefile.in (working copy)
@@ -453,6 +453,7 @@
kawa/io/BinaryOutPort.java \
kawa/io/CharArrayInPort.java \
kawa/io/CharArrayOutPort.java \
+ kawa/io/CheckConsole.java \
kawa/io/FilePath.java \
kawa/io/InPort.java \
kawa/io/LogWriter.java \
Index: gnu/kawa/io/CheckConsole.java
===================================================================
--- gnu/kawa/io/CheckConsole.java (revision 0)
+++ gnu/kawa/io/CheckConsole.java (working copy)
@@ -0,0 +1,26 @@
+package gnu.kawa.io;
+
+/** Helper class to decide if we have an interactive console.
+ * This needs to be separate from InPort, since the latter uses haveConsole
+ * in its static constructor, but we may need to call setHaveConsole first.
+ */
+
+public class CheckConsole {
+ private static int haveConsole;
+
+ public static void setHaveConsole(boolean value) {
+ haveConsole = value ? 1 : -1;
+ }
+
+ public static boolean haveConsole() {
+ if (haveConsole < 0)
+ return false;
+ if (haveConsole > 0)
+ return true;
+ /* #ifdef JAVA6 */
+ return System.console() != null;
+ /* #else */
+ // return true;
+ /* #endif */
+ }
+}
Index: gnu/kawa/io/InPort.java
===================================================================
--- gnu/kawa/io/InPort.java (revision 8255)
+++ gnu/kawa/io/InPort.java (working copy)
@@ -31,23 +31,11 @@
public class InPort extends Reader implements Printable
{
- public static boolean noConsole;
-
- public static boolean haveConsole() {
- if (noConsole)
- return false;
- /* #ifdef JAVA6 */
- return System.console() != null;
- /* #else */
- // return true;
- /* #endif */
- }
-
public static final String systemInFilename = "/dev/stdin";
private static InPort systemInPort;
static {
Path systemInPath = Path.valueOf(systemInFilename);
- if (haveConsole())
+ if (CheckConsole.haveConsole())
systemInPort = new TtyInPort(System.in, systemInPath,
OutPort.outInitial);
else
Index: kawa/GuiConsole.java
===================================================================
--- kawa/GuiConsole.java (revision 8255)
+++ kawa/GuiConsole.java (working copy)
@@ -1,5 +1,6 @@
package kawa;
+import gnu.kawa.io.CheckConsole;
import gnu.kawa.io.InPort;
import gnu.kawa.io.OutPort;
import gnu.mapping.*;
@@ -27,7 +28,7 @@
ReplDocument document;
public static void main(String[] args) {
- InPort.noConsole = false;
+ CheckConsole.setHaveConsole(true);
int iArg = repl.processArgs(args, 0, args.length);
repl.getLanguage();
repl.setArgs(args, iArg);
Index: kawa/repl.java
===================================================================
--- kawa/repl.java (revision 8257)
+++ kawa/repl.java (working copy)
@@ -12,6 +12,7 @@
import gnu.bytecode.ClassType;
import gnu.kawa.servlet.HttpRequestContext;
import gnu.kawa.io.CharArrayInPort;
+import gnu.kawa.io.CheckConsole;
import gnu.kawa.io.InPort;
import gnu.kawa.io.OutPort;
import gnu.kawa.io.Path;
@@ -651,7 +652,9 @@
Compilation.inlineOk = false;
}
else if (arg.equals("--no-console"))
- InPort.noConsole = true;
+ CheckConsole.setHaveConsole(false);
+ else if (arg.equals("--console"))
+ CheckConsole.setHaveConsole(true);
else if (arg.equals("--inline"))
{
Compilation.inlineOk = true;
@@ -893,7 +896,7 @@
getLanguage();
setArgs (args, iArg);
checkInitFile();
- if (! InPort.haveConsole())
+ if (! CheckConsole.haveConsole())
startGuiConsole();
else
{