* Bug 10964 fixed: now Scinotes can execute the current file in NW mode 80/21680/8
mottelet [Wed, 20 Jan 2021 16:21:53 +0000 (17:21 +0100)]
http://bugzilla.scilab.org/show_bug.cgi?id=10964

This patch also allows the evaluation of a selection.

Change-Id: I14c3b519ec58ed9cd22c713f990a8ce6c2179f01

scilab/modules/console/Makefile.am
scilab/modules/console/Makefile.in
scilab/modules/console/src/c/console.vcxproj
scilab/modules/console/src/c/console.vcxproj.filters
scilab/modules/console/src/java/org/scilab/modules/console/AdvCLIManagement.java [new file with mode: 0644]
scilab/modules/console/src/java/org/scilab/modules/console/AdvCLIManagementJNI.java [new file with mode: 0644]
scilab/modules/console/src/jni/AdvCLIManagement.i [new file with mode: 0644]
scilab/modules/console/src/jni/AdvCLIManagement_wrap.c [new file with mode: 0644]
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/EvaluateSelectionAction.java
scilab/modules/scinotes/src/java/org/scilab/modules/scinotes/actions/ExecuteFileIntoScilabAction.java

index efc6f4f..c42d52b 100644 (file)
@@ -54,7 +54,8 @@ CONSOLE_CPP_SOURCES = \
 #### console : List of the c files ####
 CONSOLE_C_JNI_SOURCES = \
     src/jni/GuiManagement_wrap.c \
-    src/jni/DropFiles_wrap.c
+    src/jni/DropFiles_wrap.c \
+    src/jni/AdvCLIManagement_wrap.c
 
 GIWS_WRAPPERS = src/jni/CallScilabBridge.giws.xml
 
@@ -189,7 +190,8 @@ INCLUDE_FLAGS = $(libsciconsole_la_CPPFLAGS)
 
 #### SWIG Declaration ####
 SWIG_WRAPPERS = src/jni/GuiManagement.i \
-       src/jni/DropFiles.i
+       src/jni/DropFiles.i \
+    src/jni/AdvCLIManagement.i
 
 # Provides macros compilation, Java compilation, cleaning
 # If you want Makefile to call ant, add USEANT=1
index 444450d..0be2453 100644 (file)
@@ -1,7 +1,7 @@
-# Makefile.in generated by automake 1.16.1 from Makefile.am.
+# Makefile.in generated by automake 1.16.3 from Makefile.am.
 # @configure_input@
 
-# Copyright (C) 1994-2018 Free Software Foundation, Inc.
+# Copyright (C) 1994-2020 Free Software Foundation, Inc.
 
 # This Makefile.in is free software; the Free Software Foundation
 # gives unlimited permission to copy and/or distribute it,
@@ -233,15 +233,17 @@ am__v_lt_0 = --silent
 am__v_lt_1 = 
 libsciconsole_la_DEPENDENCIES = libsciconsole-minimal.la
 am__libsciconsole_la_SOURCES_DIST = src/jni/GuiManagement_wrap.c \
-       src/jni/DropFiles_wrap.c src/c/GuiManagement.c \
-       src/c/dropFiles.c src/c/others/initMacOSXEnv.c \
-       src/jni/CallScilabBridge.cpp src/cpp/ClearConsole.cpp \
-       src/cpp/ClearConsolePart.cpp src/cpp/ConsolePrintf.cpp \
-       src/cpp/ConsoleRead.cpp src/cpp/ConsoleIsWaitingForInput.cpp \
+       src/jni/DropFiles_wrap.c src/jni/AdvCLIManagement_wrap.c \
+       src/c/GuiManagement.c src/c/dropFiles.c \
+       src/c/others/initMacOSXEnv.c src/jni/CallScilabBridge.cpp \
+       src/cpp/ClearConsole.cpp src/cpp/ClearConsolePart.cpp \
+       src/cpp/ConsolePrintf.cpp src/cpp/ConsoleRead.cpp \
+       src/cpp/ConsoleIsWaitingForInput.cpp \
        src/cpp/GetCharWithoutOutput.cpp src/cpp/PromptToHome.cpp \
        src/cpp/ScilabLinesUpdate.cpp src/cpp/SetConsolePrompt.cpp
 am__objects_1 = src/jni/libsciconsole_la-GuiManagement_wrap.lo \
-       src/jni/libsciconsole_la-DropFiles_wrap.lo
+       src/jni/libsciconsole_la-DropFiles_wrap.lo \
+       src/jni/libsciconsole_la-AdvCLIManagement_wrap.lo
 @IS_MACOSX_TRUE@am__objects_2 = src/c/others/libsciconsole_la-initMacOSXEnv.lo
 am__objects_3 = src/c/libsciconsole_la-GuiManagement.lo \
        src/c/libsciconsole_la-dropFiles.lo $(am__objects_2)
@@ -311,6 +313,7 @@ am__depfiles_remade = sci_gateway/cpp/$(DEPDIR)/libsciconsole_minimal_la-console
        src/cpp/$(DEPDIR)/libsciconsole_la-SetConsolePrompt.Plo \
        src/cpp/$(DEPDIR)/libsciconsole_minimal_la-prompt.Plo \
        src/cpp/$(DEPDIR)/libsciconsole_minimal_la-scilabRead.Plo \
+       src/jni/$(DEPDIR)/libsciconsole_la-AdvCLIManagement_wrap.Plo \
        src/jni/$(DEPDIR)/libsciconsole_la-CallScilabBridge.Plo \
        src/jni/$(DEPDIR)/libsciconsole_la-DropFiles_wrap.Plo \
        src/jni/$(DEPDIR)/libsciconsole_la-GuiManagement_wrap.Plo \
@@ -528,8 +531,8 @@ MKDIR_P = @MKDIR_P@
 MPI_ENABLE = @MPI_ENABLE@
 MSGCAT = @MSGCAT@
 MSGFMT = @MSGFMT@
-MSGFMT_015 = @MSGFMT_015@
 MSGMERGE = @MSGMERGE@
+MSGMERGE_FOR_MSGFMT_OPTION = @MSGMERGE_FOR_MSGFMT_OPTION@
 NM = @NM@
 NMEDIT = @NMEDIT@
 OBJDUMP = @OBJDUMP@
@@ -716,7 +719,8 @@ CONSOLE_CPP_SOURCES = \
 #### console : List of the c files ####
 CONSOLE_C_JNI_SOURCES = \
     src/jni/GuiManagement_wrap.c \
-    src/jni/DropFiles_wrap.c
+    src/jni/DropFiles_wrap.c \
+    src/jni/AdvCLIManagement_wrap.c
 
 GIWS_WRAPPERS = src/jni/CallScilabBridge.giws.xml
 BUILT_SOURCES = $(am__append_1) $(am__append_2)
@@ -820,7 +824,8 @@ INCLUDE_FLAGS = $(libsciconsole_la_CPPFLAGS)
 
 #### SWIG Declaration ####
 SWIG_WRAPPERS = src/jni/GuiManagement.i \
-       src/jni/DropFiles.i
+       src/jni/DropFiles.i \
+    src/jni/AdvCLIManagement.i
 
 
 # Provides macros compilation, Java compilation, cleaning
@@ -1117,6 +1122,8 @@ src/jni/libsciconsole_la-GuiManagement_wrap.lo:  \
        src/jni/$(am__dirstamp) src/jni/$(DEPDIR)/$(am__dirstamp)
 src/jni/libsciconsole_la-DropFiles_wrap.lo: src/jni/$(am__dirstamp) \
        src/jni/$(DEPDIR)/$(am__dirstamp)
+src/jni/libsciconsole_la-AdvCLIManagement_wrap.lo:  \
+       src/jni/$(am__dirstamp) src/jni/$(DEPDIR)/$(am__dirstamp)
 src/c/libsciconsole_la-GuiManagement.lo: src/c/$(am__dirstamp) \
        src/c/$(DEPDIR)/$(am__dirstamp)
 src/c/libsciconsole_la-dropFiles.lo: src/c/$(am__dirstamp) \
@@ -1205,6 +1212,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciconsole_la-SetConsolePrompt.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciconsole_minimal_la-prompt.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libsciconsole_minimal_la-scilabRead.Plo@am__quote@ # am--include-marker
+@AMDEP_TRUE@@am__include@ @am__quote@src/jni/$(DEPDIR)/libsciconsole_la-AdvCLIManagement_wrap.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@src/jni/$(DEPDIR)/libsciconsole_la-CallScilabBridge.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@src/jni/$(DEPDIR)/libsciconsole_la-DropFiles_wrap.Plo@am__quote@ # am--include-marker
 @AMDEP_TRUE@@am__include@ @am__quote@src/jni/$(DEPDIR)/libsciconsole_la-GuiManagement_wrap.Plo@am__quote@ # am--include-marker
@@ -1380,6 +1388,13 @@ src/jni/libsciconsole_la-DropFiles_wrap.lo: src/jni/DropFiles_wrap.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciconsole_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/jni/libsciconsole_la-DropFiles_wrap.lo `test -f 'src/jni/DropFiles_wrap.c' || echo '$(srcdir)/'`src/jni/DropFiles_wrap.c
 
+src/jni/libsciconsole_la-AdvCLIManagement_wrap.lo: src/jni/AdvCLIManagement_wrap.c
+@am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciconsole_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/jni/libsciconsole_la-AdvCLIManagement_wrap.lo -MD -MP -MF src/jni/$(DEPDIR)/libsciconsole_la-AdvCLIManagement_wrap.Tpo -c -o src/jni/libsciconsole_la-AdvCLIManagement_wrap.lo `test -f 'src/jni/AdvCLIManagement_wrap.c' || echo '$(srcdir)/'`src/jni/AdvCLIManagement_wrap.c
+@am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) src/jni/$(DEPDIR)/libsciconsole_la-AdvCLIManagement_wrap.Tpo src/jni/$(DEPDIR)/libsciconsole_la-AdvCLIManagement_wrap.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      $(AM_V_CC)source='src/jni/AdvCLIManagement_wrap.c' object='src/jni/libsciconsole_la-AdvCLIManagement_wrap.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciconsole_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o src/jni/libsciconsole_la-AdvCLIManagement_wrap.lo `test -f 'src/jni/AdvCLIManagement_wrap.c' || echo '$(srcdir)/'`src/jni/AdvCLIManagement_wrap.c
+
 src/c/libsciconsole_la-GuiManagement.lo: src/c/GuiManagement.c
 @am__fastdepCC_TRUE@   $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libsciconsole_la_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT src/c/libsciconsole_la-GuiManagement.lo -MD -MP -MF src/c/$(DEPDIR)/libsciconsole_la-GuiManagement.Tpo -c -o src/c/libsciconsole_la-GuiManagement.lo `test -f 'src/c/GuiManagement.c' || echo '$(srcdir)/'`src/c/GuiManagement.c
 @am__fastdepCC_TRUE@   $(AM_V_at)$(am__mv) src/c/$(DEPDIR)/libsciconsole_la-GuiManagement.Tpo src/c/$(DEPDIR)/libsciconsole_la-GuiManagement.Plo
@@ -1723,7 +1738,8 @@ installdirs:
        done
 install: $(BUILT_SOURCES)
        $(MAKE) $(AM_MAKEFLAGS) install-am
-install-exec: install-exec-am
+install-exec: $(BUILT_SOURCES)
+       $(MAKE) $(AM_MAKEFLAGS) install-exec-am
 install-data: install-data-am
 uninstall: uninstall-am
 
@@ -1810,6 +1826,7 @@ distclean: distclean-am
        -rm -f src/cpp/$(DEPDIR)/libsciconsole_la-SetConsolePrompt.Plo
        -rm -f src/cpp/$(DEPDIR)/libsciconsole_minimal_la-prompt.Plo
        -rm -f src/cpp/$(DEPDIR)/libsciconsole_minimal_la-scilabRead.Plo
+       -rm -f src/jni/$(DEPDIR)/libsciconsole_la-AdvCLIManagement_wrap.Plo
        -rm -f src/jni/$(DEPDIR)/libsciconsole_la-CallScilabBridge.Plo
        -rm -f src/jni/$(DEPDIR)/libsciconsole_la-DropFiles_wrap.Plo
        -rm -f src/jni/$(DEPDIR)/libsciconsole_la-GuiManagement_wrap.Plo
@@ -1898,6 +1915,7 @@ maintainer-clean: maintainer-clean-am
        -rm -f src/cpp/$(DEPDIR)/libsciconsole_la-SetConsolePrompt.Plo
        -rm -f src/cpp/$(DEPDIR)/libsciconsole_minimal_la-prompt.Plo
        -rm -f src/cpp/$(DEPDIR)/libsciconsole_minimal_la-scilabRead.Plo
+       -rm -f src/jni/$(DEPDIR)/libsciconsole_la-AdvCLIManagement_wrap.Plo
        -rm -f src/jni/$(DEPDIR)/libsciconsole_la-CallScilabBridge.Plo
        -rm -f src/jni/$(DEPDIR)/libsciconsole_la-DropFiles_wrap.Plo
        -rm -f src/jni/$(DEPDIR)/libsciconsole_la-GuiManagement_wrap.Plo
@@ -1923,7 +1941,8 @@ uninstall-am: uninstall-libsciconsole_la_etcDATA \
        uninstall-libsciconsole_la_rootDATA \
        uninstall-pkglibLTLIBRARIES
 
-.MAKE: all check check-am install install-am install-strip
+.MAKE: all check check-am install install-am install-exec \
+       install-strip
 
 .PHONY: CTAGS GTAGS TAGS all all-am all-local am--depfiles check \
        check-am check-local clean clean-generic clean-libtool \
index 5ce936f..6ebe60b 100644 (file)
     </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="..\jni\AdvCLIManagement_wrap.c" />
     <ClCompile Include="..\cpp\prompt.cpp" />
     <ClCompile Include="..\cpp\scilabRead.cpp" />
     <ClCompile Include="..\jni\CallScilabBridge.cpp" />
index 9c29ee7..b1d0c58 100644 (file)
@@ -23,6 +23,9 @@
     </Filter>
   </ItemGroup>
   <ItemGroup>
+    <ClCompile Include="..\jni\AdvCLIManagement_wrap.cpp">
+      <Filter>Source Files</Filter>
+    </ClCompile>
     <ClCompile Include="..\jni\CallScilabBridge.cpp">
       <Filter>Source Files</Filter>
     </ClCompile>
diff --git a/scilab/modules/console/src/java/org/scilab/modules/console/AdvCLIManagement.java b/scilab/modules/console/src/java/org/scilab/modules/console/AdvCLIManagement.java
new file mode 100644 (file)
index 0000000..f002bbd
--- /dev/null
@@ -0,0 +1,16 @@
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 4.0.1
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+package org.scilab.modules.console;
+
+public class AdvCLIManagement {
+  public static String GetCurrentPrompt() {
+    return AdvCLIManagementJNI.GetCurrentPrompt();
+  }
+
+}
diff --git a/scilab/modules/console/src/java/org/scilab/modules/console/AdvCLIManagementJNI.java b/scilab/modules/console/src/java/org/scilab/modules/console/AdvCLIManagementJNI.java
new file mode 100644 (file)
index 0000000..d9870ed
--- /dev/null
@@ -0,0 +1,33 @@
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 4.0.1
+ *
+ * Do not make changes to this file unless you know what you are doing--modify
+ * the SWIG interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+package org.scilab.modules.console;
+
+public class AdvCLIManagementJNI {
+
+  static {
+    try {
+        System.loadLibrary("sciconsole");
+    } catch (SecurityException e) {
+        System.err.println("A security manager exists and does not allow the loading of the specified dynamic library.");
+        System.err.println(e.getLocalizedMessage());
+        System.exit(-1);
+    } catch (UnsatisfiedLinkError e)    {
+           System.err.println("The native library sciconsole does not exist or cannot be found.");
+        if (System.getenv("CONTINUE_ON_JNI_ERROR") == null) {
+           System.err.println(e.getLocalizedMessage());
+           System.err.println("Current java.library.path is : "+System.getProperty("java.library.path"));
+           System.exit(-1);
+        }else{
+           System.err.println("Continuing anyway because of CONTINUE_ON_JNI_ERROR");
+        }
+    }
+  }
+
+  public final static native String GetCurrentPrompt();
+}
diff --git a/scilab/modules/console/src/jni/AdvCLIManagement.i b/scilab/modules/console/src/jni/AdvCLIManagement.i
new file mode 100644 (file)
index 0000000..4bed747
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2021 - Stépahen Mottelet
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v3.0,
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
+ *
+ */
+
+
+/* AdvCLIManagement.i */
+/** 
+ * Windows: swig -java -package org.scilab.modules.console -outdir ../java/org/scilab/modules/console/ AdvCLIManagement.i 
+ * Other: Use the option --enable-build-swig to the configure
+*/
+%module AdvCLIManagement
+%{
+extern char * GetCurrentPrompt();
+%}
+
+/* static load of library */
+%pragma(java) jniclasscode=%{
+  static {
+    try {
+        System.loadLibrary("sciconsole");
+    } catch (SecurityException e) {
+        System.err.println("A security manager exists and does not allow the loading of the specified dynamic library.");
+        System.err.println(e.getLocalizedMessage());
+        System.exit(-1);
+    } catch (UnsatisfiedLinkError e)    {
+           System.err.println("The native library sciconsole does not exist or cannot be found.");
+        if (System.getenv("CONTINUE_ON_JNI_ERROR") == null) {
+           System.err.println(e.getLocalizedMessage());
+           System.err.println("Current java.library.path is : "+System.getProperty("java.library.path"));
+           System.exit(-1);
+        }else{
+           System.err.println("Continuing anyway because of CONTINUE_ON_JNI_ERROR");
+        }
+    }
+  }
+%}
+
+extern char * GetCurrentPrompt();
+
+
+
diff --git a/scilab/modules/console/src/jni/AdvCLIManagement_wrap.c b/scilab/modules/console/src/jni/AdvCLIManagement_wrap.c
new file mode 100644 (file)
index 0000000..8fdb76b
--- /dev/null
@@ -0,0 +1,233 @@
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 4.0.1
+ *
+ * This file is not intended to be easily readable and contains a number of
+ * coding conventions designed to improve portability and efficiency. Do not make
+ * changes to this file unless you know what you are doing--modify the SWIG
+ * interface file instead.
+ * ----------------------------------------------------------------------------- */
+
+
+#ifndef SWIGJAVA
+#define SWIGJAVA
+#endif
+
+
+/* -----------------------------------------------------------------------------
+ *  This section contains generic SWIG labels for method/variable
+ *  declarations/attributes, and other compiler dependent labels.
+ * ----------------------------------------------------------------------------- */
+
+/* template workaround for compilers that cannot correctly implement the C++ standard */
+#ifndef SWIGTEMPLATEDISAMBIGUATOR
+# if defined(__SUNPRO_CC) && (__SUNPRO_CC <= 0x560)
+#  define SWIGTEMPLATEDISAMBIGUATOR template
+# elif defined(__HP_aCC)
+/* Needed even with `aCC -AA' when `aCC -V' reports HP ANSI C++ B3910B A.03.55 */
+/* If we find a maximum version that requires this, the test would be __HP_aCC <= 35500 for A.03.55 */
+#  define SWIGTEMPLATEDISAMBIGUATOR template
+# else
+#  define SWIGTEMPLATEDISAMBIGUATOR
+# endif
+#endif
+
+/* inline attribute */
+#ifndef SWIGINLINE
+# if defined(__cplusplus) || (defined(__GNUC__) && !defined(__STRICT_ANSI__))
+#   define SWIGINLINE inline
+# else
+#   define SWIGINLINE
+# endif
+#endif
+
+/* attribute recognised by some compilers to avoid 'unused' warnings */
+#ifndef SWIGUNUSED
+# if defined(__GNUC__)
+#   if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4))
+#     define SWIGUNUSED __attribute__ ((__unused__))
+#   else
+#     define SWIGUNUSED
+#   endif
+# elif defined(__ICC)
+#   define SWIGUNUSED __attribute__ ((__unused__))
+# else
+#   define SWIGUNUSED
+# endif
+#endif
+
+#ifndef SWIG_MSC_UNSUPPRESS_4505
+# if defined(_MSC_VER)
+#   pragma warning(disable : 4505) /* unreferenced local function has been removed */
+# endif
+#endif
+
+#ifndef SWIGUNUSEDPARM
+# ifdef __cplusplus
+#   define SWIGUNUSEDPARM(p)
+# else
+#   define SWIGUNUSEDPARM(p) p SWIGUNUSED
+# endif
+#endif
+
+/* internal SWIG method */
+#ifndef SWIGINTERN
+# define SWIGINTERN static SWIGUNUSED
+#endif
+
+/* internal inline SWIG method */
+#ifndef SWIGINTERNINLINE
+# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
+#endif
+
+/* exporting methods */
+#if defined(__GNUC__)
+#  if (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+#    ifndef GCC_HASCLASSVISIBILITY
+#      define GCC_HASCLASSVISIBILITY
+#    endif
+#  endif
+#endif
+
+#ifndef SWIGEXPORT
+# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+#   if defined(STATIC_LINKED)
+#     define SWIGEXPORT
+#   else
+#     define SWIGEXPORT __declspec(dllexport)
+#   endif
+# else
+#   if defined(__GNUC__) && defined(GCC_HASCLASSVISIBILITY)
+#     define SWIGEXPORT __attribute__ ((visibility("default")))
+#   else
+#     define SWIGEXPORT
+#   endif
+# endif
+#endif
+
+/* calling conventions for Windows */
+#ifndef SWIGSTDCALL
+# if defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)
+#   define SWIGSTDCALL __stdcall
+# else
+#   define SWIGSTDCALL
+# endif
+#endif
+
+/* Deal with Microsoft's attempt at deprecating C standard runtime functions */
+#if !defined(SWIG_NO_CRT_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
+# define _CRT_SECURE_NO_DEPRECATE
+#endif
+
+/* Deal with Microsoft's attempt at deprecating methods in the standard C++ library */
+#if !defined(SWIG_NO_SCL_SECURE_NO_DEPRECATE) && defined(_MSC_VER) && !defined(_SCL_SECURE_NO_DEPRECATE)
+# define _SCL_SECURE_NO_DEPRECATE
+#endif
+
+/* Deal with Apple's deprecated 'AssertMacros.h' from Carbon-framework */
+#if defined(__APPLE__) && !defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES)
+# define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0
+#endif
+
+/* Intel's compiler complains if a variable which was never initialised is
+ * cast to void, which is a common idiom which we use to indicate that we
+ * are aware a variable isn't used.  So we just silence that warning.
+ * See: https://github.com/swig/swig/issues/192 for more discussion.
+ */
+#ifdef __INTEL_COMPILER
+# pragma warning disable 592
+#endif
+
+
+/* Fix for jlong on some versions of gcc on Windows */
+#if defined(__GNUC__) && !defined(__INTEL_COMPILER)
+  typedef long long __int64;
+#endif
+
+/* Fix for jlong on 64-bit x86 Solaris */
+#if defined(__x86_64)
+# ifdef _LP64
+#   undef _LP64
+# endif
+#endif
+
+#include <jni.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+/* Support for throwing Java exceptions */
+typedef enum {
+  SWIG_JavaOutOfMemoryError = 1,
+  SWIG_JavaIOException,
+  SWIG_JavaRuntimeException,
+  SWIG_JavaIndexOutOfBoundsException,
+  SWIG_JavaArithmeticException,
+  SWIG_JavaIllegalArgumentException,
+  SWIG_JavaNullPointerException,
+  SWIG_JavaDirectorPureVirtual,
+  SWIG_JavaUnknownError,
+  SWIG_JavaIllegalStateException,
+} SWIG_JavaExceptionCodes;
+
+typedef struct {
+  SWIG_JavaExceptionCodes code;
+  const char *java_exception;
+} SWIG_JavaExceptions_t;
+
+
+static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) {
+  jclass excep;
+  static const SWIG_JavaExceptions_t java_exceptions[] = {
+    { SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" },
+    { SWIG_JavaIOException, "java/io/IOException" },
+    { SWIG_JavaRuntimeException, "java/lang/RuntimeException" },
+    { SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" },
+    { SWIG_JavaArithmeticException, "java/lang/ArithmeticException" },
+    { SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" },
+    { SWIG_JavaNullPointerException, "java/lang/NullPointerException" },
+    { SWIG_JavaDirectorPureVirtual, "java/lang/RuntimeException" },
+    { SWIG_JavaUnknownError,  "java/lang/UnknownError" },
+    { SWIG_JavaIllegalStateException, "java/lang/IllegalStateException" },
+    { (SWIG_JavaExceptionCodes)0,  "java/lang/UnknownError" }
+  };
+  const SWIG_JavaExceptions_t *except_ptr = java_exceptions;
+
+  while (except_ptr->code != code && except_ptr->code)
+    except_ptr++;
+
+  (*jenv)->ExceptionClear(jenv);
+  excep = (*jenv)->FindClass(jenv, except_ptr->java_exception);
+  if (excep)
+    (*jenv)->ThrowNew(jenv, excep, msg);
+}
+
+
+/* Contract support */
+
+#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else
+
+
+extern char * GetCurrentPrompt();
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+SWIGEXPORT jstring JNICALL Java_org_scilab_modules_console_AdvCLIManagementJNI_GetCurrentPrompt(JNIEnv *jenv, jclass jcls) {
+  jstring jresult = 0 ;
+  char *result = 0 ;
+  
+  (void)jenv;
+  (void)jcls;
+  result = (char *)GetCurrentPrompt();
+  if (result) jresult = (*jenv)->NewStringUTF(jenv, (const char *)result);
+  return jresult;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
index 868a5e0..4c67216 100644 (file)
@@ -2,8 +2,8 @@
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2009 - DIGITEO - Bruno JOFRET
  * Copyright (C) 2010 - Calixte DENIZET
- *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2021 - Stéphane MOTTELET
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
  * pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -28,6 +28,9 @@ import org.scilab.modules.scinotes.SciNotes;
 import org.scilab.modules.scinotes.ScilabEditorPane;
 
 import org.scilab.modules.history_manager.HistoryManagement;
+import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement;
+import org.scilab.modules.console.SciPromptView;
+import org.scilab.modules.console.AdvCLIManagement;
 
 /**
  * EvaluateSelectionAction class
@@ -64,8 +67,25 @@ public final class EvaluateSelectionAction extends DefaultAction {
             while (tokens.hasMoreTokens()) {
                 lines[i++] = tokens.nextToken();
             }
-            HistoryManagement.appendLinesToScilabHistory(lines, lines.length);
-            ScilabConsole.getConsole().getAsSimpleConsole().sendCommandsToScilab(selection, true, false);
+            if (ScilabConsole.isExistingConsole())
+            {
+                HistoryManagement.appendLinesToScilabHistory(lines, lines.length);
+                ScilabConsole.getConsole().getAsSimpleConsole().sendCommandsToScilab(selection, true, false);
+            } else {
+                /* This happens when SciNotes is launched as standalone (ie without
+                 * Scilab) or Scilab launched in -nw mode */
+                new Thread(() -> {
+                    try {
+                        System.out.println(selection);
+                        ScilabInterpreterManagement.synchronousScilabExec(selection);
+                        System.out.println();
+                        System.out.print(AdvCLIManagement.GetCurrentPrompt());
+                    }
+                    catch (ScilabInterpreterManagement.InterpreterException e) {
+                        System.out.println(e.getMessage());
+                    }
+                }).start();
+            }
         }
     }
 
index ae62245..3e7aa1b 100644 (file)
@@ -3,8 +3,8 @@
  * Copyright (C) 2009 - DIGITEO - Bruno JOFRET
  * Copyright (C) 2009 - DIGITEO - Allan CORNET
  * Copyright (C) 2010 - Calixte DENIZET
- *
  * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ * Copyright (C) 2021 - Stéphane MOTTELET
  *
  * This file is hereby licensed under the terms of the GNU GPL v2.0,
  * pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -19,6 +19,8 @@ package org.scilab.modules.scinotes.actions;
 
 import javax.swing.JButton;
 import javax.swing.KeyStroke;
+import javax.swing.SwingUtilities;
+
 
 import org.scilab.modules.gui.console.ScilabConsole;
 import org.scilab.modules.gui.menuitem.MenuItem;
@@ -29,6 +31,10 @@ import org.scilab.modules.gui.messagebox.ScilabModalDialog.IconType;
 import org.scilab.modules.scinotes.SciNotes;
 import org.scilab.modules.scinotes.ScilabDocument;
 import org.scilab.modules.scinotes.utils.SciNotesMessages;
+import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement;
+import org.scilab.modules.action_binding.InterpreterManagement;
+import org.scilab.modules.console.SciPromptView;
+import org.scilab.modules.console.AdvCLIManagement;
 
 /**
  * ExecuteFileIntoScilabAction Class
@@ -68,12 +74,23 @@ public class ExecuteFileIntoScilabAction extends DefaultAction {
         filePath = filePath.replaceAll("'", "''");
         if (filePath.compareTo("") != 0) {
             String cmdToExec = "exec('" + filePath + "', -1)";
-            try {
+            if (ScilabConsole.isExistingConsole())
+            {
                 ScilabConsole.getConsole().getAsSimpleConsole().sendCommandsToScilab(cmdToExec, true, false);
-            } catch (NoClassDefFoundError e) {
-                /* This happens when SciNotes is launch as standalone (ie without
-                 * Scilab) */
-                ScilabModalDialog.show(editor, SciNotesMessages.COULD_NOT_FIND_CONSOLE);
+            } else {
+                /* This happens when SciNotes is launched as standalone (ie without
+                    * Scilab) or Scilab launched in -nw mode */
+                new Thread(() -> {
+                    try {
+                        System.out.println(cmdToExec);
+                        ScilabInterpreterManagement.synchronousScilabExec(cmdToExec);
+                        System.out.println();
+                        System.out.print(AdvCLIManagement.GetCurrentPrompt());
+                    }
+                    catch (ScilabInterpreterManagement.InterpreterException e) {
+                        System.out.println(e.getMessage());
+                    }
+                }).start();
             }
         }
     }
@@ -86,7 +103,7 @@ public class ExecuteFileIntoScilabAction extends DefaultAction {
         if (((ScilabDocument) getEditor().getTextPane().getDocument()).isContentModified()) {
             if (saveBefore || ScilabModalDialog.show(getEditor(), SciNotesMessages.EXECUTE_WARNING, SciNotesMessages.EXECUTE_FILE_INTO_SCILAB,
                     IconType.WARNING_ICON, ButtonType.CANCEL_OR_SAVE_AND_EXECUTE) == AnswerOption.SAVE_EXECUTE_OPTION) {
-                if (editor.save(getEditor().getTabPane().getSelectedIndex(), true)) {
+                 if (editor.save(getEditor().getTabPane().getSelectedIndex(), true)) {
                     this.executeFile(editor, editor.getTextPane().getName());
                 }
             }