bugs about completion nw mode (windows part)
Allan CORNET [Mon, 24 Nov 2008 15:01:51 +0000 (16:01 +0100)]
34 files changed:
scilab/CHANGES_5.1
scilab/modules/completion/Makefile.am
scilab/modules/completion/includes/getPartLine.h [new file with mode: 0644]
scilab/modules/completion/src/c/completion.c
scilab/modules/completion/src/c/completion.vcproj
scilab/modules/completion/src/c/getPartLine.c [new file with mode: 0644]
scilab/modules/completion/src/c/getfilesdictionary.c
scilab/modules/completion/src/c/getfilesdictionary.h
scilab/modules/completion/src/jni/GetPartLine.i [new file with mode: 0644]
scilab/modules/completion/src/jni/GetPartLine_wrap.c [new file with mode: 0644]
scilab/modules/console/src/java/org/scilab/modules/console/SciInputParsingManager.java
scilab/modules/core/src/c/prompt.c
scilab/modules/shell/src/c/GetCommandLine.c
scilab/modules/shell/src/c/scicompletion_Import.def
scilab/modules/shell/src/c/scilines.c
scilab/modules/shell/src/c/shell.vcproj
scilab/modules/shell/src/c/windows/TermCommand.c [new file with mode: 0644]
scilab/modules/shell/src/c/windows/TermCommand.h [new file with mode: 0644]
scilab/modules/shell/src/c/windows/TermCompletion.c [new file with mode: 0644]
scilab/modules/shell/src/c/windows/TermCompletion.h [new file with mode: 0644]
scilab/modules/shell/src/c/windows/TermConsole.c [new file with mode: 0644]
scilab/modules/shell/src/c/windows/TermConsole.h [new file with mode: 0644]
scilab/modules/shell/src/c/windows/TermLine.c [new file with mode: 0644]
scilab/modules/shell/src/c/windows/TermLine.h [new file with mode: 0644]
scilab/modules/shell/src/c/windows/TermPrintf.c
scilab/modules/shell/src/c/windows/TermReadAndProcess.c
scilab/modules/shell/src/c/windows/readline_nw.c [deleted file]
scilab/modules/shell/src/c/windows/readline_nw.h [deleted file]
scilab/modules/shell/tests/nonreg_tests/bug_3286.tst [new file with mode: 0644]
scilab/modules/shell/tests/nonreg_tests/bug_3297.tst [new file with mode: 0644]
scilab/modules/shell/tests/nonreg_tests/bug_3487.tst [new file with mode: 0644]
scilab/modules/shell/tests/nonreg_tests/bug_3703.tst [new file with mode: 0644]
scilab/modules/shell/tests/nonreg_tests/bug_3757.tst [new file with mode: 0644]
scilab/modules/windows_tools/src/c/scilab_windows/console.c

index a224367..caffe96 100644 (file)
@@ -121,3 +121,5 @@ Bug fixes:
 
 * bug 3687 fixed - 'format' doesn't check inputs arguments.
 
+* bug 3757 fixed - completion works better on nw mode on Windows
+
index cd7e9e4..0022ae3 100644 (file)
@@ -9,7 +9,8 @@
 
 if GUI
 #List of the c files
-COMPLETION_JNI_SOURCES = src/jni/Completion_wrap.c
+COMPLETION_JNI_SOURCES = src/jni/Completion_wrap.c \
+src/jni/GetPartLine_wrap.c
 USEANT=1
 
 endif
@@ -21,7 +22,8 @@ src/c/getfilesdictionary.c \
 src/c/getfulldictionary.c \
 src/c/getmacrosdictionary.c \
 src/c/toolsdictionary.c \
-src/c/completion_wrap_java.c
+src/c/completion_wrap_java.c \
+src/c/getPartLine.c
 
 # List of the gateway c files
 GATEWAY_C_SOURCES = sci_gateway/c/sci_completion.c \
@@ -74,7 +76,8 @@ libscicompletion_la_include_HEADERS = includes/gw_completion.h \
 includes/completion.h
 
 #### SWIG Declaration ####
-SWIG_WRAPPERS = src/jni/Completion.i
+SWIG_WRAPPERS = src/jni/Completion.i \
+src/jni/GetPartLine.i
 
 if SWIG
 BUILT_SOURCES=swig
diff --git a/scilab/modules/completion/includes/getPartLine.h b/scilab/modules/completion/includes/getPartLine.h
new file mode 100644 (file)
index 0000000..791084a
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2008 - DIGITEO - Allan CORNET
+* 
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at    
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+
+#ifndef __GETPARTLINE_H__
+#define __GETPARTLINE_H__
+
+/**
+* pre parsing current line to search with completion
+* @param[in] current line
+* @return word to find with completion
+*/
+char *getPartLevel(char *line);
+
+/**
+* pre parsing current line to search with completion (file)
+* @param[in] current line
+* @return word to find with completion
+*/
+char *getFilePartLevel(char *line);
+
+
+#endif /* __GETPARTLINE_H__ */
\ No newline at end of file
index 9c359be..b04b171 100644 (file)
@@ -290,7 +290,7 @@ char **completionOnFiles(char *somechars, int *sizeArrayReturned)
        char **dictionary = NULL;
        int sizedictionary = 0;
 
-       dictionary = getfilesdictionary(somechars,&sizedictionary);
+       dictionary = getfilesdictionary(somechars,&sizedictionary,FALSE);
 
        if (dictionary)
        {
index 843cc49..e8dd27a 100644 (file)
                                >
                        </File>
                        <File
+                               RelativePath=".\getPartLine.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\jni\GetPartLine_wrap.c"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\sci_gateway\c\gw_completion.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath="..\..\includes\getPartLine.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\..\includes\gw_completion.h"
                                >
                        </File>
                                RelativePath="..\jni\Completion.i"
                                >
                        </File>
+                       <File
+                               RelativePath="..\jni\GetPartLine.i"
+                               >
+                       </File>
                </Filter>
                <Filter
                        Name="Resource Files"
diff --git a/scilab/modules/completion/src/c/getPartLine.c b/scilab/modules/completion/src/c/getPartLine.c
new file mode 100644 (file)
index 0000000..92700cf
--- /dev/null
@@ -0,0 +1,140 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2008 - DIGITEO - Allan CORNET
+* 
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at    
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+/*--------------------------------------------------------------------------*/
+#include <string.h>
+#ifdef _MSC_VER
+#include "strdup_windows.h"
+#endif
+#include "getPartLine.h"
+#include "core_math.h"
+/*--------------------------------------------------------------------------*/
+char *getPartLevel(char *line)
+{
+       #define MAX_SYMBS 23
+       const char symbs[MAX_SYMBS] = "+-*/\\([ ^,;={.&|\'])}:\"\'";
+       int index = -1;
+       int i = 0;
+
+       for (i = 0; i < MAX_SYMBS; i++) 
+       {
+               int len = 0;
+               char *pch = strrchr(line, symbs[i]);
+               if (pch) 
+               {
+                       len = (int) (strlen(line) - strlen(pch));
+                       index = Max(index, len);
+               }
+       }
+
+       return strdup(&line[index + 1]);
+}
+/*--------------------------------------------------------------------------*/
+char *getFilePartLevel(char *line)
+{
+       #define MAX_SYMBS_F 2
+       char symbs[MAX_SYMBS_F] = ";,";
+       char *linebis = NULL;
+       int index = -1;
+       int i = 0;
+       int len = (int) strlen(line);
+       int indexspace = -1;
+       int indexquote = -1;
+       int indexdquote = -1;
+       char *pch = NULL;
+
+       for (i = 0; i < MAX_SYMBS_F; i++) 
+       {
+               int len = 0;
+               pch = strrchr(line, symbs[i]);
+               if (pch) 
+               {
+                       len = (int) (strlen(line) - strlen(pch));
+                       index = Max(index, len);
+               }
+       }
+
+       index++;
+
+       if (index != 0) 
+       {
+               while (line[index] == ' ')
+               {
+                       index++;
+                       if (index >= len) return NULL;
+               }
+       }
+       /* Search the beginning of the path or file name */
+       /* cd toto */
+       /* cd("toto */
+       linebis = &line[index];
+       index = (int) strlen(linebis);
+
+       /* Searching for the beginning of a white space */
+       pch = strchr(linebis,' ');
+       if (pch)
+       {
+               indexspace = (int) ( strlen(linebis) - strlen(pch) );
+       }
+       else indexspace = -1;
+
+       if (indexspace != -1) 
+       {
+               len = (int) strlen(linebis);
+               /* In case of more than 1 blanks, have to skip all but the last one */
+               while(linebis[indexspace] == ' ')
+               {
+                       indexspace++;
+                       if ( indexspace >= len ) return NULL;
+               }
+
+               /* Decrease index because last value read was not a ' ' */
+               indexspace--;
+               index = Min(index, indexspace);
+       }
+       /* Searching for the beginning of a character string */
+       pch = strchr(linebis,'\'');
+       if (pch)
+       {
+               indexquote = (int) ( strlen(linebis) - strlen(pch) );
+       }
+       else indexquote = -1;
+
+       if (indexquote != -1) 
+       {
+               index = Min(index, indexquote);
+       }
+
+       /* Searching for the beginning of a character string */
+       pch = strchr(linebis,'\"');
+       if (pch)
+       {
+               indexdquote = (int) ( strlen(linebis) - strlen(pch) );
+       }
+       else indexdquote = -1;
+
+       if (indexdquote != -1) 
+       {
+               index = Min(index, indexdquote);
+       }
+
+       /* If index found in not the end of the line, add 1 to get substring beginning at the next char */
+       len = (int) strlen(linebis);
+       if (index < len)
+       {
+               index++;
+       }
+
+       if ( (index <= 0) || (linebis[index] == '\0') ) return NULL;
+
+       return strdup(&linebis[index]);
+}
+/*--------------------------------------------------------------------------*/
\ No newline at end of file
index 18cf5a6..177c6ea 100644 (file)
 #include "findfiles.h" /* findfiles */
 #include "MALLOC.h"
 #include "cluni0.h"
+#include "machine.h"
 /*--------------------------------------------------------------------------*/ 
 static void splitpath(char *composite,  char *path,  char *fname);
+static char **addPath(char **dictionary, int sizearray, char *path);
 /*--------------------------------------------------------------------------*/ 
-char **getfilesdictionary(char *somechars,int *sizearray)
+char **getfilesdictionary(char *somechars,int *sizearray,BOOL fullpath)
 {
        char **dictionary = NULL;
 
@@ -47,7 +49,11 @@ char **getfilesdictionary(char *somechars,int *sizearray)
                        char *currentpath = NULL;
 
                        scigetcwd(&currentpath,&lpath,&ierr);
-                       if (currentpath) {strcpy(path,currentpath);}
+                       if (currentpath) 
+                       {
+                               strcpy(path, currentpath);
+                               strcat(path, DIR_SEPARATOR);
+                       }
                }
                else
                {
@@ -67,7 +73,12 @@ char **getfilesdictionary(char *somechars,int *sizearray)
                }
 
                C2F(cluni0)(path,pathextended,&out_n,(long)strlen(path),PATH_MAX);
-               dictionary = findfiles(pathextended,filespec,&sizeListReturned);
+               dictionary = findfiles(pathextended, filespec, &sizeListReturned);
+               if (fullpath)
+               {
+                       dictionary = addPath(dictionary, sizeListReturned, path);
+               }
+               
                *sizearray = sizeListReturned;
 
         /* Add a NULL element at the end (to get number of items from JNI) */
@@ -118,3 +129,19 @@ static void splitpath(char *composite,  char *path,  char *fname)
        }
 }
 /*--------------------------------------------------------------------------*/
+static char **addPath(char **dictionary, int sizearray, char *path)
+{
+       int i = 0;
+       for (i = 0;i < sizearray;i++)
+       {
+               char *newPath = NULL;
+               int newlength = strlen(dictionary[i]) + strlen(path) + 1;
+               newPath = (char *)MALLOC(sizeof(char)*(newlength));
+               sprintf(newPath,"%s%s",path,dictionary[i]);
+               FREE(dictionary[i]);
+               dictionary[i] = newPath;
+               
+       }
+       return dictionary;
+}
+/*--------------------------------------------------------------------------*/
\ No newline at end of file
index 80af25c..8f9edc7 100644 (file)
 #ifndef __GETFILESDICTIONARY_H__
 #define __GETFILESDICTIONARY_H__
 
+#include "BOOL.h"
+
 /**
 * get files dictionary
 * @param[in] some chars
 * @param[out] size of returned array
+* @param[in] returns with the full path name
 * @return array of strings
 */
-char **getfilesdictionary(char *somechars,int *sizearray);
+char **getfilesdictionary(char *somechars,int *sizearray,BOOL fullpath);
 
 #endif /* __GETFILESDICTIONARY_H__ */
 /*--------------------------------------------------------------------------*/ 
diff --git a/scilab/modules/completion/src/jni/GetPartLine.i b/scilab/modules/completion/src/jni/GetPartLine.i
new file mode 100644 (file)
index 0000000..807ed92
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2008 - DIGITEO - Allan CORNET
+ * 
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at    
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
+/* Completion.i */
+/*  swig -java -package org.scilab.modules.completion -outdir ../java/org/scilab/modules/completion/ GetPartLine.i */
+%module GetPartLine
+
+%{
+#include "GetPartLine.h"
+#include "MALLOC.h"
+%}
+
+%include "../../../jvm/src/jni/scilab_typemaps.i"
+
+/* JavaDoc for GetPartLineJNI class */
+%pragma(java) jniclassclassmodifiers=%{
+ /** 
+   * @author Allan CORNET
+   * @copyright DIGITEO 2008
+   */
+public class%}
+
+/* Constructor for GetPartLineJNI class */
+%pragma(java) jniclasscode="
+  /**
+    * Constructor
+    */
+  protected GetPartLineJNI() {
+       throw new UnsupportedOperationException();
+  }";
+
+/* static load of library */
+%pragma(java) jniclasscode=%{
+  static {
+    try {
+        System.loadLibrary("scicompletion");
+    } catch (SecurityException e) {
+               System.err.println("A security manager exists and does not allow the loading of the specified dynamic library :");
+               e.printStackTrace(System.err);
+       } catch (UnsatisfiedLinkError e)        {
+               System.err.println("The native library scicompletion does not exist or cannot be found.");
+               e.printStackTrace(System.err);
+    }
+  }
+%}
+
+/* JavaDoc for GetPartLine class */
+%pragma(java) moduleclassmodifiers="
+ /** 
+   * @author Allan CORNET
+   * @copyright DIGITEO 2008
+   */
+public class";
+
+/* Constructor for GetPartLine class */
+%pragma(java) modulecode="
+ /**
+   * Constructor
+   */
+ protected GetPartLine() {
+       throw new UnsupportedOperationException();
+ }";
+
+/* JavaDoc */
+%javamethodmodifiers getPartLevel(char *line) "
+/**
+* pre parsing current line to search with completion
+* @param[in] current line
+* @return word to find with completion
+*/
+public";
+char *getPartLevel(char *line);
+
+/* JavaDoc */
+%javamethodmodifiers getFilePartLevel(char *line) "
+/**
+* pre parsing current line to search with completion (file)
+* @param[in] current line
+* @return word to find with completion
+*/
+public";
+char *getFilePartLevel(char *line);
+
diff --git a/scilab/modules/completion/src/jni/GetPartLine_wrap.c b/scilab/modules/completion/src/jni/GetPartLine_wrap.c
new file mode 100644 (file)
index 0000000..c3df391
--- /dev/null
@@ -0,0 +1,244 @@
+/* ----------------------------------------------------------------------------
+ * This file was automatically generated by SWIG (http://www.swig.org).
+ * Version 1.3.33
+ * 
+ * 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. 
+ * ----------------------------------------------------------------------------- */
+
+/* -----------------------------------------------------------------------------
+ *  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 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 (__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
+#  ifndef GCC_HASCLASSVISIBILITY
+#    define GCC_HASCLASSVISIBILITY
+#  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
+
+
+
+/* Fix for jlong on some versions of gcc on Windows */
+#if defined(__GNUC__) && !defined(__INTELC__)
+  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_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_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
+
+
+#include "GetPartLine.h"
+#include "MALLOC.h"
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+SWIGEXPORT jstring JNICALL Java_org_scilab_modules_completion_GetPartLineJNI_getPartLevel(JNIEnv *jenv, jclass jcls, jstring jarg1) {
+  jstring jresult = 0 ;
+  char *arg1 = (char *) 0 ;
+  char *result = 0 ;
+  
+  (void)jenv;
+  (void)jcls;
+  arg1 = 0;
+  if (jarg1) {
+    arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0);
+    if (!arg1) return 0;
+  }
+  result = (char *)getPartLevel(arg1);
+  {
+    if (result != NULL)
+    {
+      jresult = (*jenv)->NewStringUTF(jenv, (const char *)result);
+      FREE(result);
+      result = NULL;
+    }       
+  }
+  if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1);
+  return jresult;
+}
+
+
+SWIGEXPORT jstring JNICALL Java_org_scilab_modules_completion_GetPartLineJNI_getFilePartLevel(JNIEnv *jenv, jclass jcls, jstring jarg1) {
+  jstring jresult = 0 ;
+  char *arg1 = (char *) 0 ;
+  char *result = 0 ;
+  
+  (void)jenv;
+  (void)jcls;
+  arg1 = 0;
+  if (jarg1) {
+    arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0);
+    if (!arg1) return 0;
+  }
+  result = (char *)getFilePartLevel(arg1);
+  {
+    if (result != NULL)
+    {
+      jresult = (*jenv)->NewStringUTF(jenv, (const char *)result);
+      FREE(result);
+      result = NULL;
+    }       
+  }
+  if (arg1) (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1);
+  return jresult;
+}
+
+
+#ifdef __cplusplus
+}
+#endif
+
index eda739c..5c093aa 100644 (file)
@@ -21,6 +21,8 @@ import com.artenum.rosetta.interfaces.ui.InputCommandView;
 import com.artenum.rosetta.interfaces.ui.PromptView;
 import com.artenum.rosetta.util.StringConstants;
 
+import org.scilab.modules.completion.GetPartLine;
+
 /**
  * @author Vincent COUVERT
  *
@@ -100,16 +102,7 @@ public class SciInputParsingManager implements InputParsingManager {
 
                String lineToParse = wholeLine.substring(0, caretPos);
 
-               /* Code to emulate Scilab Parser */
-               char[] symbs = {'+', '-', '*', '/', '\\', '(', '[', ' ', '^', ',', ';', '=', '{',
-                               '.', '&', '|', '\'', ']', ')', '}', ':', '"'};
-               int index = -1;
-
-               for (int i = 0; i < symbs.length; i++) {
-                       index = Math.max(index, lineToParse.lastIndexOf(symbs[i]));
-               }
-
-               return lineToParse.substring(index + 1);
+               return GetPartLine.getPartLevel(lineToParse);
        }
 
        /**
@@ -123,63 +116,7 @@ public class SciInputParsingManager implements InputParsingManager {
                int caretPos = getCaretPosition();
 
                String lineToParse = wholeLine.substring(0, caretPos);
-
-               /* Code to emulate Scilab Parser */
-               char[] symbs = {';', ','};
-               int index = -1;
-
-               for (int i = 0; i < symbs.length; i++) {
-                       index = Math.max(index, lineToParse.lastIndexOf(symbs[i]));
-               }
-               index++;
-               if (index != 0) {
-                       /* Skip all blanks following , or ; and preceeding the function name */
-                       while (lineToParse.charAt(index) == ' ') {
-                               index++;
-                               if (index >= lineToParse.length()) {
-                                       return null;
-                               }
-                       }
-               }
-               /* Search the beginning of the path or file name */
-               /* cd toto */
-               /* cd("toto */
-               lineToParse = lineToParse.substring(index);
-               index = lineToParse.length();
-
-               /* Searching for the beginning of a white space */
-               int indexspace = lineToParse.indexOf(' ');
-               if (indexspace != -1) {
-                       /* In case of more than 1 blanks, have to skip all but the last one */
-                       while (lineToParse.charAt(indexspace) == ' ') {
-                               indexspace++;
-                               if (indexspace >= lineToParse.length()) {
-                                       return null;
-                               }
-                       }
-                       /* Descrease index because last value read was not a ' ' */
-                       indexspace--;
-                       index = Math.min(index, indexspace);
-               }
-               /* Searching for the beginning of a character string */
-               int indexquote = lineToParse.indexOf('\'');
-               if (indexquote != -1) {
-                       index = Math.min(index, indexquote);
-               }
-               /* Searching for the beginning of a character string */
-               int indexdquote = lineToParse.indexOf('\"');
-               if (indexdquote != -1) {
-                       index = Math.min(index, indexdquote);
-               }
-               /* If index found in not the end of the line, add 1 to get substring beginning at the next char */
-               if (index < lineToParse.length()) {
-                       index++;
-               }
-               if (index <= 0 | lineToParse.substring(index).equals("")) {
-                       return null;
-               } else {
-                       return lineToParse.substring(index);
-               }
+               return GetPartLine.getFilePartLevel(lineToParse);
        }
 
        /**
index 0391409..85006e7 100644 (file)
@@ -54,7 +54,8 @@ void GetCurrentPrompt(char *CurrentPrompt)
 /*------------------------------------------------------------------------*/
 void SetTemporaryPrompt(char *tempPrompt)
 {
-  temporaryPrompt = strdup(tempPrompt);
+       if (temporaryPrompt) {FREE(temporaryPrompt);temporaryPrompt = NULL;}
+       temporaryPrompt = strdup(tempPrompt);
 }
 /*------------------------------------------------------------------------*/
 char *GetTemporaryPrompt(void)
index fe9dc46..7492d3a 100644 (file)
@@ -85,10 +85,6 @@ static void getCommandLine(void)
     {
       /* Call Term Management for NW and NWNI to get a string */
       __CommandLine = localeToUTF(TermReadAndProcess());
-      #ifdef _MSC_VER
-       appendLineToScilabHistory(__CommandLine);
-     #endif
-
     }
 }
 
index 23537a2..7586939 100644 (file)
@@ -2,4 +2,11 @@ LIBRARY    scicompletion.dll
 
 
 EXPORTS
-completion
\ No newline at end of file
+completionOnHandleGraphicsProperties
+completionOnFiles
+completionOnVariablesWithoutMacros
+completionOnMacros
+completionOnCommandWords
+completionOnFunctions
+getPartLevel
+getFilePartLevel
\ No newline at end of file
index e5020ec..644851a 100644 (file)
@@ -57,8 +57,8 @@ int scilinesdefault(void)
                int X = getXConsoleScreenSize();
                int Y = getYConsoleScreenSize();
 
-               if (X < DEFAULT_NUMBERS_LINES) X = DEFAULT_NUMBERS_LINES;
-               if (Y < DEFAULT_NUMBERS_COLUMNS) X = DEFAULT_NUMBERS_COLUMNS;
+               if (X < DEFAULT_NUMBERS_COLUMNS) X = DEFAULT_NUMBERS_COLUMNS;
+               if (Y < DEFAULT_NUMBERS_LINES) Y = DEFAULT_NUMBERS_LINES;
                setColumnsSize(X);
                setLinesSize(Y);
        }
index 3ec677d..a422dc3 100644 (file)
                                >
                        </File>
                        <File
-                               RelativePath=".\preparsecompletion_nw.c"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\windows\readline_nw.c"
-                               >
-                       </File>
-                       <File
                                RelativePath="..\..\sci_gateway\c\sci_clc.c"
                                >
                        </File>
                                >
                        </File>
                        <File
+                               RelativePath=".\windows\TermCommand.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\windows\TermCompletion.c"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\windows\TermConsole.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\TerminateShell.c"
                                >
                        </File>
                        <File
+                               RelativePath=".\windows\TermLine.c"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\windows\TermPrintf.c"
                                >
                        </File>
                                >
                        </File>
                        <File
-                               RelativePath=".\preparsecompletion_nw.h"
+                               RelativePath=".\resource.h"
                                >
                        </File>
                        <File
-                               RelativePath=".\windows\readline_nw.h"
+                               RelativePath=".\windows\TermCommand.h"
                                >
                        </File>
                        <File
-                               RelativePath=".\resource.h"
+                               RelativePath=".\windows\TermCompletion.h"
+                               >
+                       </File>
+                       <File
+                               RelativePath=".\windows\TermConsole.h"
                                >
                        </File>
                        <File
                                >
                        </File>
                        <File
+                               RelativePath=".\windows\TermLine.h"
+                               >
+                       </File>
+                       <File
                                RelativePath=".\windows\TermPrintf.h"
                                >
                        </File>
diff --git a/scilab/modules/shell/src/c/windows/TermCommand.c b/scilab/modules/shell/src/c/windows/TermCommand.c
new file mode 100644 (file)
index 0000000..0a2d6f5
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2008 - DIGITEO - Allan CORNET
+* 
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at    
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+
+/*--------------------------------------------------------------------------*/
+#include "TermCommand.h"
+#include "machine.h" /* C2F */
+#include "sigbas.h" /* C2F (sigbas) */
+#include "dynamic_menus.h" /* StoreCommand */
+#include "MALLOC.h"
+/*--------------------------------------------------------------------------*/
+void ControlC_Command(void)
+{
+       int j = 2;
+       C2F (sigbas) (&j);
+}
+/*--------------------------------------------------------------------------*/
+void ControlX_Command(void)
+{
+       ControlC_Command();
+}
+/*--------------------------------------------------------------------------*/
+void F1_Command(void)
+{
+       StoreCommand("help");
+}
+/*--------------------------------------------------------------------------*/
+void ALTF4_Command(void)
+{
+       StoreCommand("quit");
+}
+/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/shell/src/c/windows/TermCommand.h b/scilab/modules/shell/src/c/windows/TermCommand.h
new file mode 100644 (file)
index 0000000..a9ca048
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2008 - DIGITEO - Allan CORNET
+* 
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at    
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+
+#ifndef __TERMCOMMAND_H__
+#define __TERMCOMMAND_H__
+
+/**
+* Do action Control C in scilab
+*/ 
+void ControlC_Command(void);
+
+/**
+* Do action Control X in scilab
+*/ 
+void ControlX_Command(void);
+
+/**
+* Do action F1 in scilab
+* launch help
+*/ 
+void F1_Command(void);
+
+/**
+* Do action ALT-F4 in scilab
+* Close Scilab (standard Windows)
+*/ 
+void ALTF4_Command(void);
+
+#endif /* __TERMCOMMAND_H__ */
\ No newline at end of file
diff --git a/scilab/modules/shell/src/c/windows/TermCompletion.c b/scilab/modules/shell/src/c/windows/TermCompletion.c
new file mode 100644 (file)
index 0000000..2b78c0b
--- /dev/null
@@ -0,0 +1,207 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2008 - DIGITEO - Allan CORNET
+* 
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at    
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+
+/*--------------------------------------------------------------------------*/
+#include <string.h>
+#include "TermCompletion.h"
+#include "MALLOC.h"
+#include "freeArrayOfString.h"
+#include "localization.h"
+#include "TermLine.h"
+#include "TermConsole.h"
+#include "getPartLine.h"
+#include "completion.h"
+#include "scilines.h"
+/*--------------------------------------------------------------------------*/
+static void displayCompletionDictionary(char **dictionary,int sizedictionary, char *namedictionary);
+/*--------------------------------------------------------------------------*/
+void TermCompletion(void)
+{
+       char *CurrentLine = getCurrentLine();
+       char *fileSearchedPattern = getFilePartLevel(CurrentLine);
+       char *SearchedPattern = getPartLevel(CurrentLine);
+       char **completionDictionaryFiles = NULL;
+       int sizecompletionDictionaryFiles = 0;
+
+       completionDictionaryFiles = completionOnFiles(fileSearchedPattern, &sizecompletionDictionaryFiles);
+
+       if (completionDictionaryFiles)
+       {
+               if (sizecompletionDictionaryFiles == 1)
+               {
+                       char *result = completionDictionaryFiles[0];
+                       char *partResult = &result[strlen(SearchedPattern)];
+                       char *newline = (char*)MALLOC(sizeof(char)*(strlen(CurrentLine)+ strlen(partResult)));
+
+                       if (newline)
+                       {
+                               strcpy(newline,CurrentLine);
+                               strcat(newline,partResult);
+                               clearCurrentLine();
+                               copyLine(newline);
+                               FREE(newline);
+                       }
+               }
+               else
+               {
+                       displayCompletionDictionary(completionDictionaryFiles,sizecompletionDictionaryFiles,gettext("File or Directory"));
+                       TerminalPrintf("\n");
+                       displayPrompt();
+                       newLine();
+                       copyLine(CurrentLine);
+               }
+               FREE(CurrentLine);
+               FREE(fileSearchedPattern);
+               FREE(SearchedPattern);
+               freeArrayOfString(completionDictionaryFiles,sizecompletionDictionaryFiles);
+               return;
+       }
+       else
+       {
+               int numberWordFound = 0;
+
+               char **completionDictionaryFunctions = NULL;
+               int sizecompletionDictionaryFunctions = 0;
+
+               char **completionDictionaryCommandWords = NULL;
+               int sizecompletionDictionaryCommandWords = 0;
+
+               char **completionDictionaryMacros = NULL;
+               int sizecompletionDictionaryMacros = 0;
+
+               char **completionDictionaryVariables = NULL;
+               int sizecompletionDictionaryVariables = 0;
+
+               char **completionDictionaryFiles = NULL;
+               int sizecompletionDictionaryFiles = 0;
+
+               char **completionDictionaryHandleGraphicsProperties = NULL;
+               int sizecompletionDictionaryHandleGraphicsProperties = 0;
+
+               if ( SearchedPattern && strcmp(SearchedPattern,"") )
+               {
+
+               completionDictionaryFunctions = completionOnFunctions(SearchedPattern, 
+                       &sizecompletionDictionaryFunctions);
+
+               completionDictionaryCommandWords = completionOnCommandWords(SearchedPattern, 
+                       &sizecompletionDictionaryCommandWords);
+
+               completionDictionaryMacros = completionOnMacros(SearchedPattern, 
+                       &sizecompletionDictionaryMacros);
+
+               completionDictionaryVariables = completionOnVariablesWithoutMacros(SearchedPattern, 
+                       &sizecompletionDictionaryVariables);
+
+               completionDictionaryFiles = completionOnFiles(SearchedPattern, 
+                       &sizecompletionDictionaryFiles);
+
+               completionDictionaryHandleGraphicsProperties = completionOnHandleGraphicsProperties(SearchedPattern, 
+                       &sizecompletionDictionaryHandleGraphicsProperties);
+               }
+
+               numberWordFound = sizecompletionDictionaryFunctions + sizecompletionDictionaryCommandWords +
+                       sizecompletionDictionaryMacros + sizecompletionDictionaryVariables +
+                       sizecompletionDictionaryHandleGraphicsProperties;
+
+               if (numberWordFound)
+               {
+                       if (numberWordFound == 1)
+                       {
+                               char **completionDictionary = NULL;
+                               char *result = NULL;
+                               char *partResult = NULL;
+                               char *newline = NULL;
+
+                               if (completionDictionaryFunctions) completionDictionary = completionDictionaryFunctions;
+                               if (completionDictionaryCommandWords) completionDictionary = completionDictionaryCommandWords;
+                               if (completionDictionaryMacros) completionDictionary = completionDictionaryMacros;
+                               if (completionDictionaryVariables) completionDictionary = completionDictionaryVariables;
+                               if (completionDictionaryHandleGraphicsProperties) completionDictionary = completionDictionaryHandleGraphicsProperties;
+
+                               result = completionDictionary[0];
+                               partResult = &result[strlen(SearchedPattern)];
+                               newline = (char*)MALLOC(sizeof(char)*(strlen(CurrentLine)+ strlen(partResult)));
+
+                               if (newline)
+                               {
+                                       strcpy(newline,CurrentLine);
+                                       strcat(newline,partResult);
+                                       clearCurrentLine();
+                                       copyLine(newline);
+                                       FREE(newline);
+                               }
+                       }
+                       else
+                       {
+                               displayCompletionDictionary(completionDictionaryFunctions,sizecompletionDictionaryFunctions,gettext("Scilab Function"));
+                               displayCompletionDictionary(completionDictionaryCommandWords, sizecompletionDictionaryCommandWords,gettext("Scilab Command"));
+                               displayCompletionDictionary(completionDictionaryMacros,sizecompletionDictionaryMacros,gettext("Scilab Macro"));
+                               displayCompletionDictionary(completionDictionaryVariables,sizecompletionDictionaryVariables,gettext("Scilab Variable"));
+                               displayCompletionDictionary(completionDictionaryHandleGraphicsProperties,sizecompletionDictionaryHandleGraphicsProperties,gettext("Graphics handle field"));
+
+                               TerminalPrintf("\n");
+                               displayPrompt();
+                               newLine();
+                               copyLine(CurrentLine);
+                       }
+                       freeArrayOfString(completionDictionaryFunctions,sizecompletionDictionaryFunctions);
+                       freeArrayOfString(completionDictionaryCommandWords,sizecompletionDictionaryCommandWords);
+                       freeArrayOfString(completionDictionaryMacros,sizecompletionDictionaryMacros);
+                       freeArrayOfString(completionDictionaryVariables,sizecompletionDictionaryVariables);
+                       freeArrayOfString(completionDictionaryFiles,sizecompletionDictionaryFiles);
+                       freeArrayOfString(completionDictionaryHandleGraphicsProperties,sizecompletionDictionaryHandleGraphicsProperties);
+                       FREE(CurrentLine);
+                       FREE(fileSearchedPattern);
+                       FREE(SearchedPattern);
+               }
+               else
+               {
+                       FREE(CurrentLine);
+                       FREE(fileSearchedPattern);
+                       FREE(SearchedPattern);
+               }
+       }
+}
+/*--------------------------------------------------------------------------*/
+static void displayCompletionDictionary(char **dictionary,int sizedictionary, char *namedictionary)
+{
+       if (dictionary)
+       {
+               int i = 0;
+               int lenCurrentLine = 0;
+
+               TerminalPrintf("\n");
+               TerminalPrintf(namedictionary);
+               TerminalPrintf(":");
+               TerminalPrintf("\n");
+
+               for(i = 0;i < sizedictionary;i++)
+               {
+                       int newlenLine = lenCurrentLine + (int)strlen(dictionary[i]) + (int)strlen(" ");
+                       if ( newlenLine >= (getColumnsSize() - 10) )
+                       {
+                               TerminalPrintf("\n");
+                               lenCurrentLine = 0;
+                       }
+                       else
+                       {
+                               lenCurrentLine = newlenLine;
+                       }
+
+                       TerminalPrintf(dictionary[i]);
+                       TerminalPrintf(" ");
+               }
+               TerminalPrintf("\n");
+       }
+}
+/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/shell/src/c/windows/TermCompletion.h b/scilab/modules/shell/src/c/windows/TermCompletion.h
new file mode 100644 (file)
index 0000000..740c921
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2008 - DIGITEO - Allan CORNET
+* 
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at    
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+
+#ifndef __TERMCOMPLETION_H__
+#define __TERMCOMPLETION_H__
+
+/**
+* Do completion in terminal
+*/ 
+void TermCompletion(void);
+
+#endif /* __TERMCOMPLETION_H__ */
diff --git a/scilab/modules/shell/src/c/windows/TermConsole.c b/scilab/modules/shell/src/c/windows/TermConsole.c
new file mode 100644 (file)
index 0000000..e0a9c21
--- /dev/null
@@ -0,0 +1,484 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2008 - DIGITEO - Allan CORNET
+* 
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at    
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+/*--------------------------------------------------------------------------*/
+#include <Windows.h>
+#include <stdio.h>
+#include <ctype.h>
+#include "TermConsole.h"
+#include "MALLOC.h"
+#include "TermCommand.h"
+#include "FocusOnConsole.h"
+#include "strdup_Windows.h"
+#include "TermCompletion.h"
+#include "TermLine.h"
+#include "scilines.h"
+#include "HistoryManager.h"
+#include "dynamic_menus.h" /* ismenu */
+#include "localization.h"
+/*--------------------------------------------------------------------------*/
+#ifdef CR_1
+#undef CR_1
+#endif 
+#define CR_1 '\n'
+
+#ifdef CR_2
+#undef CR_2
+#endif 
+#define CR_2 '\r'
+/*--------------------------------------------------------------------------*/
+static HANDLE Win32OutputStream = NULL, Win32InputStream = NULL;
+static DWORD OldWin32Mode;
+/*--------------------------------------------------------------------------*/
+static BOOL InitTerm = TRUE;
+/*--------------------------------------------------------------------------*/
+static unsigned char TerminalGetchar(void);
+static BOOL isCTRLPressed(DWORD StateKey);
+static BOOL isCTRL_VKEY(int VKEY);
+static BOOL isALTPressed(DWORD StateKey);
+static BOOL isALT_VKEY(int VKEY);
+static BOOL isExtendedPressed(DWORD StateKey);
+static void simulateCarriageReturn(void);
+static char actionControlKey(void);
+/*--------------------------------------------------------------------------*/
+static BOOL CtrlHandler( DWORD fdwCtrlType ) 
+{
+       switch( fdwCtrlType ) 
+       { 
+               case CTRL_C_EVENT: 
+                       {
+                               ControlC_Command();
+                               newLine();
+                               simulateCarriageReturn();
+                       }
+               return TRUE;
+       }
+       return FALSE;
+}
+/*--------------------------------------------------------------------------*/
+static void simulateCarriageReturn(void)
+{
+       INPUT_RECORD rec;
+       DWORD written;
+
+       memset (&rec, 0, sizeof(rec));
+       rec.EventType = KEY_EVENT;
+       rec.Event.KeyEvent.bKeyDown = TRUE;
+       rec.Event.KeyEvent.wRepeatCount = 13;
+       rec.Event.KeyEvent.uChar.AsciiChar = 13;
+
+       if (!Win32InputStream) Win32InputStream = GetStdHandle(STD_INPUT_HANDLE);
+       WriteConsoleInput(Win32InputStream, &rec, 1, &written);
+}
+/*--------------------------------------------------------------------------*/
+void InitializeTerminal(void)
+{
+       if (!Win32InputStream)
+       {
+               Win32InputStream = GetStdHandle(STD_INPUT_HANDLE);
+               GetConsoleMode(Win32InputStream, &OldWin32Mode);
+               SetConsoleMode(Win32InputStream, ENABLE_PROCESSED_INPUT);
+       }
+
+       if (!Win32OutputStream) Win32OutputStream = GetStdHandle(STD_OUTPUT_HANDLE);
+
+       setFocusOnConsole();
+
+       SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE );
+
+}
+/*--------------------------------------------------------------------------*/
+void TerminalBeep(void)
+{
+       MessageBeep(MB_OK);
+}
+/*--------------------------------------------------------------------------*/
+int TerminalPrintf(char *buffer)
+{
+       if (buffer)
+       {
+               if (buffer[0] != 0)
+               {
+                       int len = strlen (buffer);
+                       /* UTF-8 coded on 2 chars */
+                       char *OEM_string = (char*)MALLOC(sizeof(char)*(2*len)); 
+                       if (OEM_string)
+                       {
+                               /* flush all stream */
+                               /* problem with fortran output */
+                               fflush(NULL);
+
+                               /* NW windows term uses OEM characters */
+                               /* We need to convert to ANSI characters with OEMToChar */
+                               /* http://msdn.microsoft.com/en-us/library/ms647473(VS.85).aspx */
+                               CharToOem(buffer,OEM_string);
+
+                               len = fputs (OEM_string, stdout);
+
+                               FREE(OEM_string);
+                               OEM_string = NULL;
+
+                               /* flush all stream */
+                               /* problem with fortran output */
+                               fflush(NULL);
+
+                               return len;
+                       }
+                       return -1;
+               }
+               return 0;
+       }
+       return -1;
+}
+/*--------------------------------------------------------------------------*/
+int TerminalPutc(char ch)
+{
+       return putc(ch, stdout);
+}
+/*--------------------------------------------------------------------------*/
+static unsigned char TerminalGetchar(void)
+{
+       INPUT_RECORD irBuffer;
+       DWORD n = 0;
+       unsigned char ch = 0;
+       do
+       {
+               /* http://bugzilla.scilab.org/show_bug.cgi?id=1052 */
+               if ( ismenu() == 1 ) return 0;
+
+               WaitForSingleObject(Win32InputStream, INFINITE);
+               PeekConsoleInput (Win32InputStream, &irBuffer, 1, &n);
+
+               switch (irBuffer.EventType)
+               {
+               case KEY_EVENT:
+                       {
+                               if (irBuffer.Event.KeyEvent.bKeyDown)
+                               {
+                                       if (irBuffer.Event.KeyEvent.dwControlKeyState)
+                                       {
+                                               if (isCTRLPressed(irBuffer.Event.KeyEvent.dwControlKeyState))
+                                               {
+                                                       char c = actionControlKey();
+                                                       if (c) 
+                                                       {
+                                                               ReadConsoleInput (Win32InputStream, &irBuffer, 1, &n);
+                                                               return c;
+                                                       }
+                                                       else
+                                                       {
+                                                               if (irBuffer.Event.KeyEvent.uChar.AsciiChar != '\0')
+                                                               {
+                                                                       ReadConsoleInput (Win32InputStream, &irBuffer, 1, &n);
+                                                                       c = irBuffer.Event.KeyEvent.uChar.AsciiChar;
+                                                                       if ( (c>0) && !iscntrl(c) ) return c;
+                                                               }
+                                                               else
+                                                               {
+                                                                       ReadConsoleInput (Win32InputStream, &irBuffer, 1, &n);
+                                                               }
+                                                       }
+                                                       break;
+                                               }
+                                       
+                                               if (isALTPressed(irBuffer.Event.KeyEvent.dwControlKeyState))
+                                               {
+                                                       if (irBuffer.Event.KeyEvent.uChar.AsciiChar != '\0')
+                                                       {
+                                                               ReadConsole (Win32InputStream, &ch, 1, &n, NULL);
+                                                               return ch;
+                                                       }
+                                                       else
+                                                       {
+                                                               DWORD stateKey = 0;
+                                                               WORD vk = 0;
+
+                                                               ReadConsoleInput (Win32InputStream, &irBuffer, 1, &n);
+
+                                                               stateKey = irBuffer.Event.KeyEvent.dwControlKeyState;
+                                                               vk = irBuffer.Event.KeyEvent.wVirtualKeyCode;
+
+                                                               switch(vk)
+                                                               {
+                                                                       case VK_F4:
+                                                                               ALTF4_Command();
+                                                                       break;
+
+                                                                       default:
+                                                                       break;
+                                                               }
+                                                       }
+                                                       break;
+                                               }
+                                       }
+
+                                       if (irBuffer.Event.KeyEvent.uChar.AsciiChar != '\0')
+                                       {
+                                               ReadConsole (Win32InputStream, &ch, 1, &n, NULL);
+
+                                               switch (ch)
+                                               {
+                                                       case VK_TAB:
+                                                               TermCompletion();
+                                                               break;
+                                                       case VK_BACK:
+                                                               deletePreviousChar();
+                                                               break;
+                                                       default:
+                                                               {
+                                                                       if ( !iscntrl(ch) || (ch == CR_1) || (ch == CR_2) ) return ch;
+                                                               }
+                                                               break;
+                                               }
+                                       }
+                                       else
+                                       {
+                                               WORD vk = 0;
+                                               ReadConsoleInput (Win32InputStream, &irBuffer, 1, &n);
+                                               vk = irBuffer.Event.KeyEvent.wVirtualKeyCode;
+
+                                               switch (vk)
+                                               {
+                                                               case VK_F1: case VK_HELP:
+                                                                       F1_Command();
+                                                               break;
+                                                               case VK_LEFT:
+                                                                       moveBackSingleChar();
+                                                                       break;
+                                                               case VK_RIGHT:
+                                                                       moveForwardSingleChar();
+                                                                       break;
+                                                               case VK_UP:
+                                                                       moveBackHistory();
+                                                                       break;
+                                                               case VK_DOWN:
+                                                                       moveForwardHistory();
+                                                                       break;
+                                                               case VK_DELETE:
+                                                                       deleteCurrentChar();
+                                                                       break;
+                                                               case VK_HOME:
+                                                                       moveBeginningLine();
+                                                                       break;
+                                                               case VK_END:
+                                                                       moveEndLine();
+                                                                       break;
+                                                               default:
+                                                               break;
+                                               }
+                                       }
+                               }
+                               else
+                               {
+                                       ReadConsoleInput (Win32InputStream, &irBuffer, 1, &n);
+                               }
+                       }
+                       break;
+               case MOUSE_EVENT:
+                       {
+                               /* Read mouse Input but not used */
+                               ReadConsoleInput (Win32InputStream, &irBuffer, 1, &n);
+                       }
+                       break;
+               case WINDOW_BUFFER_SIZE_EVENT:
+                       {
+                               /* Read resize event Input */
+                               setColumnsSize(irBuffer.Event.WindowBufferSizeEvent.dwSize.X);
+                               setLinesSize(irBuffer.Event.WindowBufferSizeEvent.dwSize.Y);
+
+                               ReadConsoleInput (Win32InputStream, &irBuffer, 1, &n);
+                       }
+                       break;
+               case MENU_EVENT:
+                       {
+                               ReadConsoleInput (Win32InputStream, &irBuffer, 1, &n);
+                       }
+                       break;
+               case FOCUS_EVENT:
+                       {
+                               ReadConsoleInput (Win32InputStream, &irBuffer, 1, &n);
+                       }
+                       break;
+               default:
+                       {
+                               /* Read Input but not used */
+                               ReadConsoleInput (Win32InputStream, &irBuffer, 1, &n);
+                       }
+                       break;
+               }
+       }
+       while (TRUE);
+}
+/*--------------------------------------------------------------------------*/
+static char actionControlKey(void)
+{
+       if ( isCTRL_VKEY('X') || isCTRL_VKEY('C') )
+       {
+               ControlC_Command();
+               return '\n';
+       }
+       else
+       if (isCTRL_VKEY('A')) /* moves to the beginning of the line */
+       {
+               moveBeginningLine();
+       }
+       else
+       if (isCTRL_VKEY('B')) /* moves back a single character */
+       {
+               moveBackSingleChar();
+       }       
+       else
+       if (isCTRL_VKEY('D')) /* deletes the current character */
+       {
+               deleteCurrentChar();
+       }
+       else
+       if (isCTRL_VKEY('E')) /* moves to the end of the line */
+       {
+               moveEndLine();
+       }
+       else
+       if (isCTRL_VKEY('F')) /* moves forward a single character */
+       {
+               moveForwardSingleChar();
+       }
+       else
+       if (isCTRL_VKEY('H')) /* delete the previous character */
+       {
+               deletePreviousChar();
+       }
+       else
+       if (isCTRL_VKEY('K')) /* kills from current position to the end of line */
+       {
+               killCurrentPositionToEndLine();
+       }
+       else
+       if (isCTRL_VKEY('N')) /* moves forward through history */
+       {
+               moveForwardHistory();
+       }
+       else
+       if (isCTRL_VKEY('P')) /* moves back through history */
+       {
+               moveBackHistory();
+       }
+       else
+       if ( isCTRL_VKEY('R') || isCTRL_VKEY('L') )  /* redraw line in case it gets trashed */
+       {
+               redrawLine();
+       }
+       else
+       if (isCTRL_VKEY('U')) /* kills the entire line */
+       {
+               clearCurrentLine();
+       }
+       else
+       if (isCTRL_VKEY('V'))
+       {
+               pasteClipBoard();
+       }
+       else
+       if (isCTRL_VKEY('W')) /* kills last word */
+       {
+               killLastWord();
+       }
+       else
+       if (isCTRL_VKEY(VK_TAB) || isCTRL_VKEY(VK_SPACE)) /* Completion */
+       {
+               TermCompletion();
+       }
+       else
+       if (isCTRL_VKEY(VK_LEFT)) /* */
+       {
+               moveBackSingleWord();
+       }
+       else
+       if (isCTRL_VKEY(VK_RIGHT)) /* */
+       {
+               moveForwardSingleWord();
+       }
+       return 0;
+}
+/*--------------------------------------------------------------------------*/
+char *TerminalGetString(char *prompt)
+{
+       if (InitTerm)
+       {
+               InitializeTerminal();
+               InitTerm = FALSE;
+       }
+
+       newLine();
+
+       setCurrentPrompt(prompt);
+
+       /* print the prompt */
+       displayPrompt();
+
+       /* initialize history search */
+       setSearchedTokenInScilabHistory(NULL);
+
+       for (;;)
+       {
+               unsigned char cur_char = TerminalGetchar();
+
+               if (cur_char <= 0) return NULL;
+
+               /* http://bugzilla.scilab.org/show_bug.cgi?id=1052 */
+               if (ismenu () == 1)
+               {
+                       /* Abort current line */
+                       return NULL;
+               }
+
+               if ( (cur_char == CR_1) || (cur_char == CR_2) )
+               {
+                       if ( isHistorySearch() )
+                       {
+                               putLineSearchedHistory();
+                       }
+                       else
+                       {
+                               char *line = getCurrentLine();
+                               TerminalPutc('\n');
+                               appendLineToScilabHistory(localeToUTF(line));
+                               return line;
+                       }
+               }
+               else
+               {
+                       TerminalPutc(cur_char);
+                       addCharacterCurrentLine(cur_char);
+               }
+       }
+       return NULL;
+}
+/*--------------------------------------------------------------------------*/
+static BOOL isCTRLPressed(DWORD StateKey)
+{
+       return ((StateKey & (RIGHT_CTRL_PRESSED|LEFT_CTRL_PRESSED)) != 0);
+}
+/*--------------------------------------------------------------------------*/
+static BOOL isALTPressed(DWORD StateKey)
+{
+       return ((StateKey & (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED)) != 0);
+}
+/*--------------------------------------------------------------------------*/
+static BOOL isExtendedPressed(DWORD StateKey)
+{
+       return ((StateKey & (ENHANCED_KEY)) != 0);
+}
+/*--------------------------------------------------------------------------*/
+static BOOL isCTRL_VKEY(int VKEY)
+{
+       return ( GetKeyState(VKEY) & 0x80 );
+}
+/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/shell/src/c/windows/TermConsole.h b/scilab/modules/shell/src/c/windows/TermConsole.h
new file mode 100644 (file)
index 0000000..e965017
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2008 - DIGITEO - Allan CORNET
+* 
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at    
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+
+#ifndef __TERMCONSOLE_H__
+#define __TERMCONSOLE_H__
+
+/**
+* initialize Terminal
+*/ 
+void InitializeTerminal(void);
+
+/**
+* printf in terminal
+* @param[in] buffer
+* @return number of characters
+*/ 
+int TerminalPrintf(char *buffer);
+
+/**
+* put a character
+* @param[in] character
+*/ 
+int TerminalPutc(char ch);
+
+/**
+* returns line from terminal
+* @param[in] prompt 
+* @return line from terminal
+*/ 
+char *TerminalGetString(char *prompt);
+
+/**
+* do a beep
+*/ 
+void TerminalBeep(void);
+
+#endif /* __TERMCONSOLE_H__ */
diff --git a/scilab/modules/shell/src/c/windows/TermLine.c b/scilab/modules/shell/src/c/windows/TermLine.c
new file mode 100644 (file)
index 0000000..8875258
--- /dev/null
@@ -0,0 +1,372 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2008 - DIGITEO - Allan CORNET
+* 
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at    
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+
+/*--------------------------------------------------------------------------*/
+#include <windows.h>
+#include <string.h>
+#include "TermLine.h"
+#include "HistoryManager.h"
+#include "TermConsole.h"
+#include "localization.h"
+#include "MALLOC.h"
+#include "strdup_windows.h"
+/*--------------------------------------------------------------------------*/
+/* TODO : remove static array */
+static char cur_line[4096];    /* current contents of the line */      
+static char *currentPrompt = NULL;
+
+static int cur_pos = 0;                /* current position of the cursor */
+static int max_pos = 0;
+/*--------------------------------------------------------------------------*/
+/* do backspace on line */
+static void backSpace(void);
+/*--------------------------------------------------------------------------*/
+void moveBeginningLine(void)
+{
+       while (cur_pos > 0)
+       {
+               cur_pos -= 1;
+               backSpace();
+       }
+}
+/*--------------------------------------------------------------------------*/
+void moveEndLine(void)
+{
+       while (cur_pos < max_pos)
+       {
+               TerminalPutc (cur_line[cur_pos]);
+               cur_pos += 1;
+       }
+}
+/*--------------------------------------------------------------------------*/
+void moveBackSingleChar(void)
+{
+       if (cur_pos > 0)
+       {
+               cur_pos -= 1;
+               backSpace();
+       }
+}
+/*--------------------------------------------------------------------------*/
+void moveForwardSingleChar(void)
+{
+       if (cur_pos < max_pos)
+       {
+               TerminalPutc(cur_line[cur_pos]);
+               cur_pos += 1;
+       }
+}
+/*--------------------------------------------------------------------------*/
+void moveBackSingleWord(void)
+{
+       while ((cur_pos > 0) && (isspace(cur_line[cur_pos - 1]) ))
+       {
+               cur_pos -= 1;
+               backSpace ();
+       }
+       while ((cur_pos > 0) && ( !isspace(cur_line[cur_pos - 1]) ))
+       {
+               cur_pos -= 1;
+               backSpace ();
+       }
+       refreshLine();
+}
+/*--------------------------------------------------------------------------*/
+void moveForwardSingleWord(void)
+{
+       while ( !isspace(cur_line[cur_pos]) && (cur_pos < max_pos) ) 
+       {
+               TerminalPutc(cur_line[cur_pos]);
+               cur_pos++;
+       }
+       while ( isspace(cur_line[cur_pos]) && (cur_pos < max_pos) ) 
+       {
+               TerminalPutc(cur_line[cur_pos]);
+               cur_pos++;
+       }
+       refreshLine();
+}
+/*--------------------------------------------------------------------------*/
+void killCurrentPositionToEndLine(void)
+{
+       int i = 0;
+       for (i = cur_pos; i < max_pos; i++)  cur_line[i] = '\0';
+       for (i = cur_pos; i < max_pos; i++) TerminalPutc(VK_SPACE);
+       for (i = cur_pos; i < max_pos; i++) backSpace ();
+       max_pos = cur_pos;
+}
+/*--------------------------------------------------------------------------*/
+void deletePreviousChar(void)
+{
+       if (cur_pos > 0)
+       {
+               int i = 0;
+               cur_pos -= 1;
+               backSpace ();
+               for (i = cur_pos; i < max_pos; i++) cur_line[i] = cur_line[i + 1];
+               max_pos -= 1;
+               refreshLine();
+       }
+       else TerminalBeep();
+}
+/*--------------------------------------------------------------------------*/
+void deleteCurrentChar(void)
+{
+       if (max_pos == 0) 
+       {
+               TerminalBeep();
+       }
+       else
+       {
+               if (cur_pos < max_pos)
+               {
+                       int i =0;
+                       for (i = cur_pos; i < max_pos; i++) cur_line[i] = cur_line[i + 1];
+                       max_pos -= 1;
+                       refreshLine();
+               }
+       }
+}
+/*--------------------------------------------------------------------------*/
+void moveBackHistory(void)
+{
+       char *newline = NULL;
+
+       cur_line[max_pos + 1] = '\0';
+       if (cur_line[0]== '\0')
+       {
+               resetSearchedTokenInScilabHistory();
+               setSearchedTokenInScilabHistory(NULL);
+       }
+
+       newline = getPreviousLineInScilabHistory();
+
+       if (newline)
+       {
+               clearCurrentLine();
+               copyLine(UTFToLocale(newline));
+               FREE(newline);
+               newline = NULL;
+       }
+}
+/*--------------------------------------------------------------------------*/
+void moveForwardHistory(void)
+{
+       char *newline = NULL;
+
+       cur_line[max_pos + 1] = '\0';
+       if (cur_line[0]== '\0')
+       {
+               resetSearchedTokenInScilabHistory();
+               setSearchedTokenInScilabHistory(NULL);
+       }
+
+       newline = getNextLineInScilabHistory();
+
+       if (newline)
+       {
+               clearCurrentLine();
+               copyLine(UTFToLocale(newline));
+               FREE(newline);
+               newline = NULL;
+       }
+}
+/*--------------------------------------------------------------------------*/
+void redrawLine(void)
+{
+       int i =0;
+       char *line = getCurrentLine();
+
+       TerminalPutc('\n');
+       displayPrompt();
+       for (i = max_pos; i > cur_pos; i--)  backSpace ();
+       if (line)
+       {
+               copyLine(line);
+               FREE(line);
+               line = NULL;
+       }
+}
+/*--------------------------------------------------------------------------*/
+void copyLine(char *line)
+{
+       if (line)
+       {
+               TerminalPrintf(line);
+               CharToOem(line,cur_line);
+               cur_pos = max_pos = (int)strlen (cur_line);
+       }
+}
+/*--------------------------------------------------------------------------*/
+void killLastWord(void)
+{
+       while ((cur_pos > 0) && (cur_line[cur_pos - 1] == VK_SPACE))
+       {
+               cur_pos -= 1;
+               backSpace ();
+       }
+       while ((cur_pos > 0) && (cur_line[cur_pos - 1] != VK_SPACE))
+       {
+               cur_pos -= 1;
+               backSpace ();
+       }
+
+       killCurrentPositionToEndLine();
+}
+/*--------------------------------------------------------------------------*/
+void newLine(void)
+{
+       cur_line[0] = '\0';
+       cur_pos = 0;
+       max_pos = 0;
+}
+/*--------------------------------------------------------------------------*/
+void refreshLine(void)
+{
+       int i = 0;
+
+       /* write tail of string */
+       for (i = cur_pos; i < max_pos; i++) TerminalPutc(cur_line[i]);
+
+       /* write a space at the end of the line in case we deleted one */
+       TerminalPutc(VK_SPACE);
+
+       /* backup to original position */
+       for (i = max_pos + 1; i > cur_pos; i--) backSpace ();
+
+}
+/*--------------------------------------------------------------------------*/
+void clearCurrentLine(void)
+{
+       int i = 0;
+
+       for (i = 0; i < max_pos; i++) cur_line[i] = '\0';
+
+       moveBeginningLine();
+       
+       for (i = 0; i < max_pos; i++) TerminalPutc(VK_SPACE);
+
+       TerminalPutc('\r');
+       displayPrompt();
+
+       newLine();
+}
+/*--------------------------------------------------------------------------*/
+static void backSpace(void)
+{
+       TerminalPutc(VK_BACK);
+}
+/*--------------------------------------------------------------------------*/
+static char *getCurrentPrompt(void)
+{
+       return currentPrompt;
+}
+/*--------------------------------------------------------------------------*/
+void setCurrentPrompt(char *prompt)
+{
+       currentPrompt = prompt;
+}
+/*--------------------------------------------------------------------------*/
+void displayPrompt(void)
+{
+       TerminalPrintf(getCurrentPrompt());
+}
+/*--------------------------------------------------------------------------*/
+char *getCurrentLine(void)
+{
+       char *line = NULL;
+       cur_line[max_pos + 1] = '\0';
+       line = strdup_windows(cur_line);
+       if (line) OemToChar(cur_line, line);
+       return line;
+}
+/*--------------------------------------------------------------------------*/
+void addCharacterCurrentLine(unsigned char ch)
+{
+       int i = 0;
+       for (i = max_pos; i > cur_pos; i--) cur_line[i] = cur_line[i - 1];
+
+       cur_line[cur_pos] = ch;
+       cur_pos += 1;
+       max_pos += 1;
+       cur_line[max_pos] = '\0';
+
+       setSearchedTokenInScilabHistory(cur_line);
+
+       if (cur_pos < max_pos) refreshLine();
+}
+/*--------------------------------------------------------------------------*/
+BOOL isHistorySearch(void)
+{
+       return (cur_line[0] == '!');
+}
+/*--------------------------------------------------------------------------*/
+void putLineSearchedHistory(void)
+{
+       char *line = NULL;
+       char *token = getCurrentLine();
+
+       if (token)
+       {
+               if ( (int)strlen(token) > 1 )
+               {
+                       setSearchedTokenInScilabHistory(&token[1]);
+                       line = getNextLineInScilabHistory();
+               }
+               FREE(token);
+               token = NULL;
+       }
+
+       clearCurrentLine();
+
+       if (line)
+       {
+               copyLine(UTFToLocale(line));
+               FREE(line);
+               line = NULL;
+       }
+}
+/*--------------------------------------------------------------------------*/
+void pasteClipBoard(void)
+{
+       HGLOBAL hGMem = NULL;
+       LPSTR lpMem; /* Ptr on clipboard */
+
+       int typeClipboard = CF_TEXT;
+
+       OpenClipboard(NULL);
+
+       hGMem = GetClipboardData (typeClipboard);
+       if (hGMem)
+       {
+               
+               char *CurrentLine = getCurrentLine();
+
+               lpMem  = GlobalLock( hGMem );
+               if (lpMem)
+               {
+                       char *newline = (char*)MALLOC(sizeof(char)*(strlen(CurrentLine)+ strlen(lpMem)));
+                       strncpy(newline, CurrentLine, cur_pos);
+                       strcat(newline, lpMem);
+                       strcat(newline, &CurrentLine[cur_pos]);
+
+                       clearCurrentLine();
+                       copyLine(newline);
+                       FREE(newline);
+               }
+               GlobalUnlock (hGMem);
+               FREE(CurrentLine);
+       }
+
+       CloseClipboard ();
+}
+/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/shell/src/c/windows/TermLine.h b/scilab/modules/shell/src/c/windows/TermLine.h
new file mode 100644 (file)
index 0000000..808d6f9
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+* Copyright (C) 2008 - DIGITEO - Allan CORNET
+* 
+* This file must be used under the terms of the CeCILL.
+* This source file is licensed as described in the file COPYING, which
+* you should have received as part of this distribution.  The terms
+* are also available at    
+* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+*
+*/
+
+#ifndef __TERMLINE_H__
+#define __TERMLINE_H__
+
+/**
+* returns current line
+* @return current line
+*/ 
+char *getCurrentLine(void);
+
+/**
+* moves to the beginning of the line 
+*/ 
+void moveBeginningLine(void);
+
+/**
+* moves to the end of the line 
+*/ 
+void moveEndLine(void);
+
+/**
+* moves back a single character 
+*/ 
+void moveBackSingleChar(void);
+
+/**
+* moves forward a single character 
+*/ 
+void moveForwardSingleChar(void);
+
+/**
+* moves back a single word
+*/ 
+void moveBackSingleWord(void);
+
+/**
+* moves forward a single word 
+*/ 
+void moveForwardSingleWord(void);
+
+/**
+* kills from current position to the end of line 
+*/ 
+void killCurrentPositionToEndLine(void);
+
+/**
+* delete the previous character 
+*/ 
+void deletePreviousChar(void);
+
+/**
+* deletes the current character
+*/ 
+void deleteCurrentChar(void);
+
+/**
+* moves back through history 
+*/ 
+void moveBackHistory(void);
+
+/**
+* moves forward through history  
+*/ 
+void moveForwardHistory(void);
+
+/**
+* redraw line
+*/ 
+void redrawLine(void);
+
+/**
+* kills last word 
+*/ 
+void killLastWord(void);
+
+/**
+* initialize new line
+*/ 
+void newLine(void);
+
+/**
+* clear current line
+*/ 
+void clearCurrentLine(void);
+
+/**
+* set prompt used by terminal
+*/ 
+void setCurrentPrompt(char *prompt);
+
+/**
+* display prompt
+*/ 
+void displayPrompt(void);
+
+/**
+* refresh line
+*/ 
+void refreshLine(void);
+
+/**
+* copy line on terminal
+*/ 
+void copyLine(char *line);
+
+/**
+* line is a history search
+* @return TRUE or FALSE;
+*/ 
+BOOL isHistorySearch(void);
+
+/**
+* add character to current line
+* @param[in] character to add
+*/ 
+void addCharacterCurrentLine(unsigned char ch);
+
+/**
+* put line searched in history
+*/
+void putLineSearchedHistory(void);
+
+/**
+* Paste current clipboard on line
+*/
+void pasteClipBoard(void);
+
+#endif /* __TERMLINE_H__ */
\ No newline at end of file
index 771afe3..409d718 100644 (file)
 */
 
 /*--------------------------------------------------------------------------*/
-#include <stdio.h>
-#include <Windows.h>
 #include "TermPrintf.h"
-#include "MALLOC.h"
-#include "strdup_Windows.h"
+#include "TermConsole.h"
 /*--------------------------------------------------------------------------*/
 void TermPrintf_Windows(char *buffer)
 {
-       if (buffer)
-       {
-               char *OEM_string = strdup(buffer);
-
-               /* flush all stream */
-               /* problem with fortran output */
-               fflush(NULL);
-
-               /* converts standard chars to OEM string */
-               /* windows term output */
-               if (OEM_string)
-               {
-                       /* console output must be to OEM format (accents) */
-                       CharToOem(buffer,OEM_string);
-                       printf("%s",OEM_string);
-                       FREE(OEM_string);
-                       OEM_string = NULL;
-               }
-               /* we try to disp without OEM format */
-               else printf("%s",buffer); 
-               fflush(NULL);
-       }
+       TerminalPrintf(buffer);
 }
 /*--------------------------------------------------------------------------*/
index 4714ec5..084a6d8 100644 (file)
 
 /*--------------------------------------------------------------------------*/
 #include <string.h>
-#include "HistoryManager.h"
 #include "TermReadAndProcess.h"
 #include "MALLOC.h"
 #include "prompt.h"
-#include "readline_nw.h"
-#include "strdup_Windows.h"
+#include "TermConsole.h"
 /*--------------------------------------------------------------------------*/
 static char *returnedline = NULL;
 /*--------------------------------------------------------------------------*/
 char * TermReadAndProcess(void)
 {
        static char save_prompt[10];
-       char* OEMChars = NULL;
 
        /* free previous line */
        if (returnedline) {FREE(returnedline);returnedline = NULL;}
 
-    if (GetTemporaryPrompt()!=NULL) /* Input function is used */
+    if (GetTemporaryPrompt() != NULL) /* Input function is used */
     {
-               OEMChars = readline_nw(GetTemporaryPrompt());
+               returnedline = TerminalGetString(GetTemporaryPrompt());
         ClearTemporaryPrompt();
        }
        else
        {
                GetCurrentPrompt(save_prompt);
-               OEMChars = readline_nw (save_prompt);
+               returnedline = TerminalGetString(save_prompt);
        }
-
-       /* NW windows term uses OEM characters */
-       /* We need to convert to ANSI characters with OEMToChar */
-       /* http://msdn.microsoft.com/en-us/library/ms647493(VS.85).aspx */
-       returnedline = strdup(OEMChars);
-       OemToChar(OEMChars, returnedline);
-       if (OEMChars) {FREE(OEMChars); OEMChars = NULL;}
-
        strcpy(save_prompt,"");
+
        return returnedline;
 }
 /*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/shell/src/c/windows/readline_nw.c b/scilab/modules/shell/src/c/windows/readline_nw.c
deleted file mode 100644 (file)
index df74afd..0000000
+++ /dev/null
@@ -1,777 +0,0 @@
-/***********************************************************
-* a small portable version of readline 
-* ^A moves to the beginning of the line 
-* ^B moves back a single character 
-* ^E moves to the end of the line 
-* ^F moves forward a single character 
-* ^K kills from current position to the end of line 
-* ^H and DEL delete the previous character 
-* ^D deletes the current character, or EOF if line is empty 
-* ^P moves back through history 
-* ^N moves forward through history 
-* ^L/^R redraw line in case it gets trashed 
-* ^U kills the entire line 
-* ^W kills last word 
-* LF and CR return the entire line regardless of the cursor position 
-* EOF with an empty line returns (char *)NULL 
-* all other characters are ignored 
-***********************************************************/
-#include <stdio.h>
-#include <ctype.h>
-#include <signal.h>
-#include <conio.h>
-#include <string.h>
-#include <Windows.h>   
-#include "readline_nw.h"
-#include "prompt.h"
-#include "MALLOC.h"
-#include "dynamic_menus.h"
-#include "HistoryManager.h"
-#include "scilabmode.h"
-#include "sigbas.h"
-#include "freeArrayOfString.h"
-#include "scilines.h"
-#include "strdup_windows.h"
-#include "completion.h"
-#include "preparsecompletion_nw.h"
-#include "charEncoding.h"
-#include "FocusOnConsole.h"
-/*--------------------------------------------------------------------------*/
-#define MAXBUF 512
-#define BACKSPACE 0x08         /* ^H */
-#define SPACE  ' '
-#define isterm(f) ((f==stdin)|| f==stdout || f==stderr)
-
-#ifdef TAB_KEY
-#undef TAB_KEY
-#endif
-#define TAB_KEY 9
-
-#ifdef PIPE
-#undef PIPE
-#endif 
-#define PIPE 255
-
-#ifdef CTRL_A
-#undef CTRL_A
-#endif 
-#define CTRL_A 001
-
-#ifdef CTRL_B
-#undef CTRL_B
-#endif 
-#define CTRL_B 002
-
-#ifdef CTRL_C
-#undef CTRL_C
-#endif 
-#define CTRL_C 003
-
-#ifdef CTRL_D
-#undef CTRL_D
-#endif 
-#define CTRL_D 004
-
-#ifdef CTRL_E
-#undef CTRL_E
-#endif 
-#define CTRL_E 005
-
-#ifdef CTRL_F
-#undef CTRL_F
-#endif 
-#define CTRL_F 006
-
-#ifdef CTRL_H
-#undef CTRL_H
-#endif 
-#define CTRL_H 010
-
-#ifdef CTRL_K
-#undef CTRL_K
-#endif 
-#define CTRL_K 013
-
-#ifdef CTRL_L
-#undef CTRL_L
-#endif 
-#define CTRL_L 014
-
-#ifdef CTRL_N
-#undef CTRL_N
-#endif 
-#define CTRL_N 016
-
-#ifdef CTRL_P
-#undef CTRL_P
-#endif 
-#define CTRL_P 020
-
-#ifdef CTRL_R
-#undef CTRL_R
-#endif 
-#define CTRL_R 022
-
-#ifdef CTRL_U
-#undef CTRL_U
-#endif 
-#define CTRL_U 025
-
-#ifdef CTRL_W
-#undef CTRL_W
-#endif 
-#define CTRL_W 027
-
-#ifdef CTRL_X
-#undef CTRL_X
-#endif 
-#define CTRL_X 030
-
-#ifdef ESC_KEY
-#undef ESC_KEY
-#endif 
-#define ESC_KEY 033
-
-#ifdef DEL
-#undef DEL
-#endif 
-#define DEL 0177
-
-#ifdef CR_1
-#undef CR_1
-#endif 
-#define CR_1 '\n'
-
-#ifdef CR_2
-#undef CR_2
-#endif 
-#define CR_2 '\r'
-
-#ifdef LEFT_ARROW
-#undef LEFT_ARROW
-#endif 
-#define LEFT_ARROW 75
-
-#ifdef RIGHT_ARROW
-#undef RIGHT_ARROW
-#endif 
-#define RIGHT_ARROW 77
-
-#ifdef UP_ARROW
-#undef UP_ARROW
-#endif 
-#define UP_ARROW 72
-
-#ifdef DOWN_ARROW
-#undef DOWN_ARROW
-#endif 
-#define DOWN_ARROW 80
-
-#ifdef HOME_KEY
-#undef HOME_KEY
-#endif 
-#define HOME_KEY 71
-
-#ifdef END_KEY
-#undef END_KEY
-#endif 
-#define END_KEY 79
-
-#ifdef DELETE_KEY
-#undef DELETE_KEY
-#endif 
-#define DELETE_KEY 83
-
-#ifdef CTRL_LEFT_ARROW
-#undef CTRL_LEFT_ARROW
-#endif 
-#define CTRL_LEFT_ARROW 115
-
-#ifdef CTRL_RIGHT_ARROW
-#undef CTRL_RIGHT_ARROW
-#endif 
-#define CTRL_RIGHT_ARROW 116
-/*--------------------------------------------------------------------------*/
-char cur_line[MAXBUF]; /* current contents of the line */
-/*--------------------------------------------------------------------------*/
-extern int IsFromC(void);
-/*--------------------------------------------------------------------------*/
-static int cur_pos = 0;                /* current position of the cursor */
-static int max_pos = 0;                /* maximum character position */
-static int sendprompt = 1;  /* default */
-static int lenCurrentLine = 0;
-static BOOL forceFocus = TRUE;
-/*--------------------------------------------------------------------------*/
-static char msdos_getch (void);
-static void fix_line (void);
-static void redraw_line(char *prompt);
-static void clear_line (char *prompt);
-static void clear_eoline (char *prompt);
-static void copy_line (char *line);
-static void doCompletion(const char *current_line,const char *prompt);
-/*--------------------------------------------------------------------------*/
-/* user_putc and user_puts should be used in the place of
-* fputc(ch,stdout) and fputs(str,stdout) for all output
-* of user typed characters.  This allows MS-Windows to 
-* display user input in a different color. */
-/*--------------------------------------------------------------------------*/
-static int user_putc (int ch)
-{
-       return fputc(ch,stdout);
-}
-/*--------------------------------------------------------------------------*/
-static int user_puts (char *str)
-{
-       return fputs (str, stdout);
-}
-/*--------------------------------------------------------------------------*/
-static void doNewLine(BOOL displayPrompt)
-{
-       fputs ("\n", stdout);
-       if (displayPrompt) fputs (SCIPROMPT, stdout);
-       cur_line[0] = '\0';
-       cur_pos = 0;
-       max_pos = 0;
-}
-/*--------------------------------------------------------------------------*/
-static void strip_blank(char *source)
-{
-       char *p;
-       p = source;
-       /* look for end of string */
-       while(*p != '\0') p++;
-       while(p != source)
-       {
-               p--;
-               if(*p != ' ') break;
-               *p = '\0';
-       }
-}
-/*--------------------------------------------------------------------------*/
-static void backspace ()
-{
-       user_putc (BACKSPACE);
-}
-/*--------------------------------------------------------------------------*/
-/***************************************************
-* reads one line when stdin is not a tty 
-* the input characters are not echoed 
-***************************************************/
-static int NotTTyRead (char *prompt, char *buffer, int buf_size, int *eof)
-{
-       static int firstentry = 0, tty;
-       if (firstentry == 0)
-       {
-               tty = isterm (stdin);
-               firstentry++;
-       }
-       if (!tty)
-       {
-               /** We are reading a file ==> no prompts : XXXXX to test **/
-               fputs (SCIPROMPT, stdout);
-               /* read a line into the buffer, but not too* big */
-               *eof = (fgets (buffer, buf_size, stdin) == NULL);
-               /* remove newline character if there */
-               return (1);
-       }
-       return (0);
-}
-/*--------------------------------------------------------------------------*/
-/***************************************************
-* reads one line 
-* a pointer to an allocated zone (alloc) where
-* the read characters are stored is returned 
-***************************************************/
-char * readline_nw (char *prompt)
-{
-       unsigned char cur_char;
-       char *new_line = NULL;
-       int eof;
-
-       if (NotTTyRead (prompt, cur_line, MAXBUF, &eof) == 1)
-       {
-               if (eof == 1)
-               {
-                       /** coded line to return eof **/
-                       cur_line[0] = -1;
-                       cur_line[1] = '\0';
-               }
-               return strdup(cur_line);
-       }
-
-       /* print the prompt */
-       if (sendprompt) 
-    {
-               fputs ("\n", stdout);
-               fputs (prompt, stdout);
-       }
-       sendprompt=1;
-
-       cur_line[0] = '\0';
-       cur_pos = 0;
-       max_pos = 0;
-
-       /* bug 3702 */
-       if (forceFocus) 
-       {
-               setFocusOnConsole();
-               forceFocus = FALSE;
-       }
-
-       setSearchedTokenInScilabHistory(NULL);
-
-       for (;;)
-       {
-               cur_char = msdos_getch();
-
-               if (cur_char == TAB_KEY)
-               {
-                       doCompletion(cur_line,prompt);
-                       cur_char = 0;
-               }
-
-               if (ismenu () == 1)
-               {
-                       /* abort current line aquisition SS */
-                       sendprompt=0;
-                       if (new_line) {FREE(new_line);new_line=NULL;}
-                       new_line = (char*)MALLOC(sizeof(char)*2);
-                       new_line[0] = -2;
-                       new_line[1] = '\0';
-                       return (new_line);
-               }
-
-               if ((isprint (cur_char)  || ((unsigned char) cur_char > 0x7f)  ) && max_pos < MAXBUF - 1)
-               {
-                       int i;
-                       for (i = max_pos; i > cur_pos; i--) cur_line[i] = cur_line[i - 1];
-                       user_putc (cur_char);
-                       cur_line[cur_pos] = cur_char;
-                       cur_pos += 1;
-                       max_pos += 1;
-                       if (cur_pos < max_pos) fix_line ();
-
-                       cur_line[max_pos] = '\0';
-                       setSearchedTokenInScilabHistory(cur_line);
-               }
-               else
-               {
-                       /* do normal editing commands */
-                       /* some of these are also done above */
-                       int i;
-
-                       switch (cur_char)
-                       {
-                       case PIPE: 
-                               if (new_line) {FREE(new_line);new_line=NULL;}
-                               new_line = (char *)MALLOC(sizeof(char)*2);
-                               if (new_line)
-                               {
-                                       new_line[0] = -1;
-                                       new_line[1] = '\0';
-                               }
-                               return (new_line);
-
-                       case EOF:
-                               return ((char *) NULL);
-                       case CTRL_A: 
-                               while (cur_pos > 0)
-                               {
-                                       cur_pos -= 1;
-                                       backspace ();
-                               }
-                               break;
-                       case CTRL_B: 
-                               if (cur_pos > 0)
-                               {
-                                       cur_pos -= 1;
-                                       backspace ();
-                               }
-                               break;
-                       case CTRL_E: 
-                               while (cur_pos < max_pos)
-                               {
-                                       user_putc (cur_line[cur_pos]);
-                                       cur_pos += 1;
-                               }
-                               break;
-                       case CTRL_F: 
-                               if (cur_pos < max_pos)
-                               {
-                                       user_putc (cur_line[cur_pos]);
-                                       cur_pos += 1;
-                               }
-                               break;
-                       case CTRL_K: 
-                               clear_eoline (prompt);
-                               max_pos = cur_pos;
-                               break;
-                       case CTRL_P: 
-                               {
-                                       /* move in history */
-                                       cur_line[max_pos + 1] = '\0';
-                                       if (cur_line[0]== '\0')
-                                       {
-                                               resetSearchedTokenInScilabHistory();
-                                               setSearchedTokenInScilabHistory(NULL);
-                                       }
-
-                                       {
-                                               char *line = getPreviousLineInScilabHistory();
-                                               if (line)
-                                               {
-                                                       clear_line(prompt);
-                                                       copy_line( UTFToLocale(line) );// Scilab history record must saved in UTF format
-                                                       FREE(line);
-                                               }
-                                       }
-                               }
-                               break;
-                       case CTRL_N: 
-                               {
-                                       /* move in history */
-                                       cur_line[max_pos + 1] = '\0';
-                                       if (cur_line[0]== '\0')
-                                       {
-                                               resetSearchedTokenInScilabHistory();
-                                               setSearchedTokenInScilabHistory(NULL);
-                                       }
-
-                                       {
-                                               char *line = getNextLineInScilabHistory();
-                                               if (line)
-                                               {
-                                                       clear_line(prompt);
-                                                       copy_line(line);
-                                                       FREE(line);
-                                               }
-                                       }
-                               }
-                               break;
-                       case CTRL_L: case CTRL_R:
-                               putc ('\n', stdout);    /* go to a fresh line */
-                               redraw_line (prompt);
-                               break;
-                       case DEL: case CTRL_H:
-                               if (cur_pos > 0)
-                               {
-                                       cur_pos -= 1;
-                                       backspace ();
-                                       for (i = cur_pos; i < max_pos; i++) cur_line[i] = cur_line[i + 1];
-                                       max_pos -= 1;
-                                       fix_line ();
-                               }
-                               break;
-                       case CTRL_D:            /* ^D */
-                               if (max_pos == 0) return ((char *) NULL);
-                               if (cur_pos < max_pos)
-                               {
-                                       for (i = cur_pos; i < max_pos; i++)
-                                               cur_line[i] = cur_line[i + 1];
-                                       max_pos -= 1;
-                                       fix_line ();
-                               }
-                               break;
-                       case CTRL_U:            /* ^U */
-                               clear_line (prompt);
-                               break;
-                       case CTRL_W:            /* ^W */
-                               while ((cur_pos > 0) && (cur_line[cur_pos - 1] == SPACE))
-                               {
-                                       cur_pos -= 1;
-                                       backspace ();
-                               }
-                               while ((cur_pos > 0) && (cur_line[cur_pos - 1] != SPACE))
-                               {
-                                       cur_pos -= 1;
-                                       backspace ();
-                               }
-                               clear_eoline (prompt);
-                               max_pos = cur_pos;
-                               break;
-                       case CR_1: case CR_2:
-                               cur_line[max_pos + 1] = '\0';
-                               if (cur_line[0]=='!')
-                               {
-                                       char *token = NULL;
-                                       token = (char*)MALLOC(sizeof(char)*strlen(cur_line));
-                                       if (token)
-                                       {
-                                               char *line = NULL;
-                                               strcpy(token,&cur_line[1]);
-                                               setSearchedTokenInScilabHistory(token);
-                                               line = getNextLineInScilabHistory();
-                                               clear_line(prompt);
-                                               if (line)
-                                               {
-                                                       copy_line(line);
-                                                       FREE(line);
-                                                       line = NULL;
-                                               }
-
-
-                                               FREE(token);
-                                               token = NULL;
-                                       }
-                                       else clear_line(prompt);
-                               }
-                               else
-                               {
-                                       putc('\n',stdout);
-                                       if (new_line) {FREE(new_line);new_line=NULL;}
-                                       new_line = (char *) MALLOC (sizeof(char)*(strlen (cur_line) + 1));
-                                       if (new_line) strcpy (new_line, cur_line);
-                                       setSearchedTokenInScilabHistory(NULL);
-                                       return (new_line);
-                               }
-                               break;
-
-                       default:
-                               break;
-                       }
-               }
-       }
-}
-/*--------------------------------------------------------------------------*/
-/* redraw the entire line, putting the cursor where it belongs */
-static void redraw_line (char *prompt)
-{
-       int i = 0;
-
-       fputs (prompt, stdout);
-       user_puts (cur_line);
-
-       /* put the cursor where it belongs */
-       for (i = max_pos; i > cur_pos; i--)  backspace ();
-}
-/*--------------------------------------------------------------------------*/
-/* fix up the line from cur_pos to max_pos */
-/* do not need any terminal capabilities except backspace, */
-/* and space overwrites a character */
-static void fix_line(void)
-{
-       int i = 0;
-
-       /* write tail of string */
-       for (i = cur_pos; i < max_pos; i++) user_putc (cur_line[i]);
-
-       /* write a space at the end of the line in case we deleted one */
-       user_putc (SPACE);
-
-       /* backup to original position */
-       for (i = max_pos + 1; i > cur_pos; i--) backspace ();
-}
-/*--------------------------------------------------------------------------*/
-/* clear cur_line and the screen line */
-static void clear_line (char *prompt)
-{
-       int i = 0;
-
-       for (i = 0; i < max_pos; i++) cur_line[i] = '\0';
-
-       for (i = cur_pos; i > 0; i--) backspace ();
-
-       for (i = 0; i < max_pos; i++) putc (SPACE, stdout);
-       putc ('\r', stdout);
-       fputs (prompt, stdout);
-
-       cur_pos = 0;
-       max_pos = 0;
-}
-/*--------------------------------------------------------------------------*/
-/* clear to end of line and the screen end of line */
-static void clear_eoline (char *prompt)
-{
-       int i = 0;
-       for (i = cur_pos; i < max_pos; i++)  cur_line[i] = '\0';
-
-       for (i = cur_pos; i < max_pos; i++) putc (SPACE, stdout);
-       for (i = cur_pos; i < max_pos; i++) backspace ();
-}
-/*--------------------------------------------------------------------------*/
-/* copy line to cur_line, draw it and set cur_pos and max_pos */
-static void copy_line (char *line)
-{
-       if (line)
-       {
-               char *OEM_string = (char*)MALLOC(sizeof(char)*(strlen(line)+1));
-               if (OEM_string)
-               {
-                       CharToOem(line,OEM_string);
-                       strcpy (cur_line,OEM_string);
-                       user_puts (cur_line);
-                       cur_pos = max_pos = (int)strlen (cur_line);
-                       FREE(OEM_string);
-                       OEM_string = NULL;
-               }
-       }
-}
-/*--------------------------------------------------------------------------*/
-/* Convert Arrow keystrokes to Control characters: */
-static char msdos_getch (void)
-{
-       char c = 0;
-
-       if (!IsFromC())
-       {
-               while( !_kbhit() && ismenu()==0)  /* Test on ismenu added (bug 1052) - Francois VOGEL */
-               {
-                       Sleep(1);
-               }
-       }
-       if (ismenu()==1) return 0;  /* This line added to fix bug 1052 - Francois VOGEL */
-
-       c = (char)_getch ();
-
-       Sleep(1);
-
-       if ( (c == CTRL_C) || (c == CTRL_X) )
-       {
-               /** control-C : we return a \n for stopping line processing **/
-               int j = 2;
-               C2F (sigbas) (&j);
-               return ((int) '\n');
-       }
-
-       if (c == -32) /* 0 avant ? ? ? */
-       {
-               c = (char)_getch ();            /* Get the extended code. */
-
-               switch (c)
-               {
-               case LEFT_ARROW:
-                       c = CTRL_B;
-                       break;
-
-               case RIGHT_ARROW:
-                       c = CTRL_F;
-                       break;
-
-               case UP_ARROW:
-                       c = CTRL_P;
-                       break;
-
-               case DOWN_ARROW:
-                       c = CTRL_N;
-                       break;
-               case CTRL_LEFT_ARROW: case HOME_KEY:
-                       c = CTRL_A;
-                       break;
-               case CTRL_RIGHT_ARROW: case END_KEY:
-                       c = CTRL_E;
-                       break;
-               case DELETE_KEY:
-                       c = CTRL_D;
-                       break;
-               default:
-                       c = 0;
-                       break;
-               }
-       }
-       else if (c == ESC_KEY)
-       {                               
-               /* ESC */
-               c = CTRL_U;
-       }
-       return c;
-}
-/*--------------------------------------------------------------------------*/
-static void doCompletion(const char *current_line,const char *prompt)
-{
-       const char *wordToFind = NULL;
-       char *backup_line = NULL;
-       char **completionDictionary = NULL;
-       int sizeCompletionDictionary = 0;
-
-       wordToFind = preparse_line_for_completion_nw(current_line);
-
-       if (wordToFind) 
-       {
-               completionDictionary = completion((char*)wordToFind,&sizeCompletionDictionary);
-               if (sizeCompletionDictionary)
-               {
-                       if (sizeCompletionDictionary == 1)
-                       {
-                               char *wordtodisp = completionDictionary[0];
-                               if ( strcmp(wordtodisp,wordToFind) != 0)
-                               {
-                                       backup_line = strdup( cur_line);
-                                       backup_line[strlen (cur_line) - strlen(wordToFind)] = '\0';
-
-                                       doNewLine(FALSE);
-                                       fputs ("\n", stdout);
-                                       redraw_line((char*)prompt);
-                                       strcat(backup_line,wordtodisp);
-                                       strcpy(cur_line,backup_line);
-                                       fputs (cur_line, stdout);
-                                       cur_pos = (int)strlen(cur_line);
-                                       max_pos = (int)strlen(cur_line);
-                                       FREE(backup_line);
-                               }
-                       }
-                       else
-                       {
-                               int i = 0;
-                               char *pieceOfWord = NULL;
-
-                               backup_line = strdup(cur_line);
-
-                               doNewLine(FALSE);
-                               fputs ("\n", stdout);
-                               for(i= 0;i<sizeCompletionDictionary;i++)
-                               {
-                                       int newlenLine = lenCurrentLine + (int)strlen(completionDictionary[i]) + (int)strlen(" ");
-                                       if ( newlenLine >= (getColumnsSize() - 10) )
-                                       {
-                                               fputs ("\n", stdout);
-                                               lenCurrentLine = 0;
-                                       }
-                                       else
-                                       {
-                                               lenCurrentLine = newlenLine;
-                                       }
-
-                                       fputs (completionDictionary[i], stdout);
-                                       fputs (" ", stdout);
-
-                               }
-                               fputs ("\n", stdout);
-                               lenCurrentLine = 0;
-                               redraw_line((char*)prompt);
-                               strcpy(cur_line,backup_line);
-                               
-                               for (i = 0; i < sizeCompletionDictionary; i++)
-                               {
-                                        if ( strncmp(completionDictionary[0],completionDictionary[i],strlen(completionDictionary[0])) == 0)
-                                        {
-                                                if (pieceOfWord) {FREE(pieceOfWord); pieceOfWord = NULL;}
-                                                pieceOfWord = strdup(completionDictionary[0]);
-                                        }
-                                        else
-                                        {
-                                                if (pieceOfWord) {FREE(pieceOfWord); pieceOfWord = NULL;}
-                                                pieceOfWord = strdup(wordToFind);
-                                                break;
-                                        }
-                               }
-
-                               if (pieceOfWord)
-                               {
-                                       strcpy(cur_line,pieceOfWord);
-                                       FREE(pieceOfWord); pieceOfWord = NULL;
-                               }
-                               else
-                               {
-                                       strcpy(cur_line,wordToFind);
-                               }
-
-                               fputs (cur_line, stdout);
-                               cur_pos = (int)strlen(cur_line);
-                               max_pos = (int)strlen(cur_line);
-                               FREE(backup_line);
-                       }
-                       freeArrayOfString(completionDictionary,sizeCompletionDictionary);
-               }
-       }
-}
-/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/shell/src/c/windows/readline_nw.h b/scilab/modules/shell/src/c/windows/readline_nw.h
deleted file mode 100644 (file)
index 81455ef..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2007 - INRIA - Allan CORNET 
- * 
- * This file must be used under the terms of the CeCILL.
- * This source file is licensed as described in the file COPYING, which
- * you should have received as part of this distribution.  The terms
- * are also available at    
- * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
- *
- */
-/*--------------------------------------------------------------------------*/
-#ifndef __READLINE_NW_H__
-#define __READLINE_NW_H__
-
-/**
-* read line No Windows mode
-* @param[in] current prompt
-* @return a string 
-*/
-char * readline_nw (char *prompt);
-
-#endif /* __READLINE_NW_H__ */
-/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/shell/tests/nonreg_tests/bug_3286.tst b/scilab/modules/shell/tests/nonreg_tests/bug_3286.tst
new file mode 100644 (file)
index 0000000..2ef47d0
--- /dev/null
@@ -0,0 +1,21 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - DIGITEO - Allan CORNET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- Non-regression test for bug 3286 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=3286
+//
+// <-- Short Description -->
+
+
+// <-- INTERACTIVE TEST -->
+// try : 
+// ./bin/scilab -nw
+//--> fa=gcf()
+//--> fa.[TAB]
+// it must return nothing (no files)
diff --git a/scilab/modules/shell/tests/nonreg_tests/bug_3297.tst b/scilab/modules/shell/tests/nonreg_tests/bug_3297.tst
new file mode 100644 (file)
index 0000000..2583ecc
--- /dev/null
@@ -0,0 +1,19 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - DIGITEO - Allan CORNET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- Non-regression test for bug 3297 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=3297
+//
+// <-- Short Description -->
+
+
+// <-- INTERACTIVE TEST -->
+// try : 
+//get*<TAB>
+// it must return nothing
diff --git a/scilab/modules/shell/tests/nonreg_tests/bug_3487.tst b/scilab/modules/shell/tests/nonreg_tests/bug_3487.tst
new file mode 100644 (file)
index 0000000..3608a6a
--- /dev/null
@@ -0,0 +1,34 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - DIGITEO - Allan CORNET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- Non-regression test for bug 3487 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=3487
+//
+// <-- Short Description -->
+//In nw & nwni modes:
+//-->cd modules/umfpack/s[TAB]
+//sci_gateway src
+//type r+[TAB]
+//-->cd modules/umfpack/sr?
+//=> a strange char is added
+//Other example:
+//-->cd modules/ou[TAB]
+//to get "output_stream"
+//but I get:
+//"modules/oueam"
+
+
+// <-- INTERACTIVE TEST -->
+// On Windows
+// launch a shell (cmd.exe)
+// go to in SCI/bin
+// scilex.exe
+// cd SCI
+//-->cd modules/umfpack/s[TAB]
+//-->cd modules/umfpack/sr[TAB]
diff --git a/scilab/modules/shell/tests/nonreg_tests/bug_3703.tst b/scilab/modules/shell/tests/nonreg_tests/bug_3703.tst
new file mode 100644 (file)
index 0000000..07b9d6b
--- /dev/null
@@ -0,0 +1,23 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - DIGITEO - Allan CORNET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- Non-regression test for bug 3703 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=3703
+//
+// <-- Short Description -->
+// cursor blinks too slowly (on Windows scilex).
+
+
+// <-- INTERACTIVE TEST -->
+// On Windows
+// launch a shell (cmd.exe)
+// go to in SCI/bin
+// scilex.exe
+// checks that cursor blinks ...
+
diff --git a/scilab/modules/shell/tests/nonreg_tests/bug_3757.tst b/scilab/modules/shell/tests/nonreg_tests/bug_3757.tst
new file mode 100644 (file)
index 0000000..d566946
--- /dev/null
@@ -0,0 +1,23 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - DIGITEO - Allan CORNET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+// <-- Non-regression test for bug 3757 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=3757
+//
+// <-- Short Description -->
+// Under Scilex, the completion of paths is incorrect
+
+
+// <-- INTERACTIVE TEST -->
+// On Windows
+// launch a shell (cmd.exe)
+// go to in SCI/bin
+// scilex.exe
+// creates a directory  d:\Project\Test
+// cd d:\Pro<TAB>
index 1d961e6..ab68584 100644 (file)
@@ -131,9 +131,11 @@ void CreateScilabConsole(int ShowBanner)
                printf(line);
                wsprintf(line,"                         %s\n\n",SCI_VERSION_STRING);
                printf(line);
-               strcpy(line,"                  Copyright (c) 1989-2008          \n");
+               strcpy(line,"                 Consortium Scilab (DIGITEO)\n");
                printf(line);
-               strcpy(line,"              Consortium Scilab (INRIA, ENPC)      \n");
+               strcpy(line,"               Copyright (c) 1989-2008 (INRIA)\n");
+               printf(line);
+               strcpy(line,"               Copyright (c) 1989-2007 (ENPC)\n");
                printf(line);
                strcpy(line,"        ___________________________________________\n\n");
                printf(line);