This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Different behavior for -s argument in Kawa 2.0?


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
               {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]