bug 3051 + cleaning
Allan CORNET [Thu, 11 Dec 2008 11:53:12 +0000 (12:53 +0100)]
14 files changed:
scilab/modules/completion/Makefile.am
scilab/modules/completion/src/c/completion.vcproj
scilab/modules/completion/src/c/getCommonPart.c
scilab/modules/completion/src/java/completion-JAVA.vcproj
scilab/modules/completion/src/java/org/scilab/modules/completion/Completion.java
scilab/modules/completion/src/java/org/scilab/modules/completion/CompletionJNI.java
scilab/modules/completion/src/java/org/scilab/modules/completion/GetCommonPart.java [deleted file]
scilab/modules/completion/src/java/org/scilab/modules/completion/GetCommonPartJNI.java [deleted file]
scilab/modules/completion/src/java/org/scilab/modules/completion/GetPartLine.java [deleted file]
scilab/modules/completion/src/java/org/scilab/modules/completion/GetPartLineJNI.java [deleted file]
scilab/modules/completion/src/jni/Completion.i
scilab/modules/completion/src/jni/Completion_wrap.c
scilab/modules/console/src/java/org/scilab/modules/console/CompletionAction.java
scilab/modules/console/src/java/org/scilab/modules/console/SciInputParsingManager.java

index 0022ae3..28812fd 100644 (file)
@@ -9,8 +9,7 @@
 
 if GUI
 #List of the c files
-COMPLETION_JNI_SOURCES = src/jni/Completion_wrap.c \
-src/jni/GetPartLine_wrap.c
+COMPLETION_JNI_SOURCES = src/jni/Completion_wrap.c 
 USEANT=1
 
 endif
@@ -23,7 +22,8 @@ src/c/getfulldictionary.c \
 src/c/getmacrosdictionary.c \
 src/c/toolsdictionary.c \
 src/c/completion_wrap_java.c \
-src/c/getPartLine.c
+src/c/getPartLine.c \
+src/c/getCommonPart.c
 
 # List of the gateway c files
 GATEWAY_C_SOURCES = sci_gateway/c/sci_completion.c \
@@ -76,8 +76,7 @@ libscicompletion_la_include_HEADERS = includes/gw_completion.h \
 includes/completion.h
 
 #### SWIG Declaration ####
-SWIG_WRAPPERS = src/jni/Completion.i \
-src/jni/GetPartLine.i
+SWIG_WRAPPERS = src/jni/Completion.i 
 
 if SWIG
 BUILT_SOURCES=swig
index 7dd4a39..4b74047 100644 (file)
                                >
                        </File>
                        <File
-                               RelativePath="..\jni\getCommonPart_wrap.c"
-                               >
-                       </File>
-                       <File
                                RelativePath=".\getfilesdictionary.c"
                                >
                        </File>
                                >
                        </File>
                        <File
-                               RelativePath="..\jni\GetPartLine_wrap.c"
-                               >
-                       </File>
-                       <File
                                RelativePath="..\..\sci_gateway\c\gw_completion.c"
                                >
                        </File>
                                RelativePath="..\jni\Completion.i"
                                >
                        </File>
-                       <File
-                               RelativePath="..\jni\GetPartLine.i"
-                               >
-                       </File>
                </Filter>
                <Filter
                        Name="Resource Files"
index 855855c..63a6c44 100644 (file)
@@ -14,6 +14,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include "getCommonPart.h"
+#include "core_math.h"
 #include "MALLOC.h"
 #ifdef _MSC_VER
 #include "strdup_windows.h"
@@ -50,6 +51,8 @@ static int cmpPos(char *str1,char *str2)
                {
                        if ( s1[i] != s2[i] ) return i;
                }
+
+               return Min(lenstr1,lenstr2);
        }
        return -1;
 }
@@ -68,10 +71,10 @@ char *getCommonPart(char **dictionary, int sizeDictionary)
                int i = 0;
                int r = 0;
                char *currentstr = dictionary[0];
-               qsort(dictionnary, sizeof dictionary / sizeof dictionary[0], sizeof dictionary[0], cmp);
+               qsort(dictionary, sizeof dictionary / sizeof dictionary[0], sizeof dictionary[0], cmp);
 
-               r = cmpPos(currentstr, dictionnary[1]);
-               for (i = 1; i < sizeDictionnary - 1; i++)
+               r = cmpPos(currentstr, dictionary[1]);
+               for (i = 1; i < sizeDictionary - 1; i++)
                {
                        int current_r = cmpPos(currentstr, dictionary[i+1]);
                        if (r > current_r  )
@@ -82,7 +85,7 @@ char *getCommonPart(char **dictionary, int sizeDictionary)
                }
                
                commonpart = strdup(currentstr);
-               commonpart[r] = '\0';
+               if (r>0) commonpart[r] = '\0';
        }
        return commonpart;
 }
index 56d8e8c..3ad6a61 100644 (file)
                                RelativePath=".\org\scilab\modules\completion\CompletionJNI.java"
                                >
                        </File>
-                       <File
-                               RelativePath=".\org\scilab\modules\completion\GetPartLine.java"
-                               >
-                       </File>
-                       <File
-                               RelativePath=".\org\scilab\modules\completion\GetPartLineJNI.java"
-                               >
-                       </File>
                </Filter>
                <File
                        RelativePath="..\..\..\build.xml"
index 5a1cc8c..cddd0eb 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.35
+ * Version 1.3.33
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
@@ -91,4 +91,35 @@ public static String[] searchHandleGraphicsPropertiesDictionary(String somechars
     return CompletionJNI.searchHandleGraphicsPropertiesDictionary(somechars);
   }
 
+  
+/**
+* pre parsing current line to search with completion
+* @param[in] current line
+* @return word to find with completion
+*/
+public static String getPartLevel(String line) {
+    return CompletionJNI.getPartLevel(line);
+  }
+
+  
+/**
+* pre parsing current line to search with completion (file)
+* @param[in] current line
+* @return word to find with completion
+*/
+public static String getFilePartLevel(String line) {
+    return CompletionJNI.getFilePartLevel(line);
+  }
+
+  
+/**
+* Get common part to a array
+* @param[in] string array
+* @param[in] size of string array
+* @return common part
+*/
+public static String getCommonPart(String[] dictionnary, int sizeDictionnary) {
+    return CompletionJNI.getCommonPart(dictionnary, sizeDictionnary);
+  }
+
 }
index 9374302..761d9dc 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.35
+ * Version 1.3.33
  *
  * Do not make changes to this file unless you know what you are doing--modify
  * the SWIG interface file instead.
@@ -41,4 +41,7 @@ public class CompletionJNI {
   public final static native String[] searchVariablesDictionary(String jarg1);
   public final static native String[] searchFilesDictionary(String jarg1);
   public final static native String[] searchHandleGraphicsPropertiesDictionary(String jarg1);
+  public final static native String getPartLevel(String jarg1);
+  public final static native String getFilePartLevel(String jarg1);
+  public final static native String getCommonPart(String[] jarg1, int jarg2);
 }
diff --git a/scilab/modules/completion/src/java/org/scilab/modules/completion/GetCommonPart.java b/scilab/modules/completion/src/java/org/scilab/modules/completion/GetCommonPart.java
deleted file mode 100644 (file)
index be8fd41..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.33
- *
- * Do not make changes to this file unless you know what you are doing--modify
- * the SWIG interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package org.scilab.modules.completion;
-
-
- /** 
-   * @author Allan CORNET
-   * @copyright DIGITEO 2008
-   */
-public class GetCommonPart {
-
- /**
-   * Constructor
-   */
- protected GetCommonPart() {
-       throw new UnsupportedOperationException();
- }
-  
-/**
-* Get common part to a array
-* @param[in] string array
-* @param[in] size of string array
-* @return common part
-*/
-public static String getCommonPart(String[] dictionnary, int sizeDictionnary) {
-    return GetCommonPartJNI.getCommonPart(dictionnary, sizeDictionnary);
-  }
-
-}
diff --git a/scilab/modules/completion/src/java/org/scilab/modules/completion/GetCommonPartJNI.java b/scilab/modules/completion/src/java/org/scilab/modules/completion/GetCommonPartJNI.java
deleted file mode 100644 (file)
index 4d02f88..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.33
- *
- * Do not make changes to this file unless you know what you are doing--modify
- * the SWIG interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package org.scilab.modules.completion;
-
-
- /** 
-   * @author Allan CORNET
-   * @copyright DIGITEO 2008
-   */
-public class GetCommonPartJNI {
-
-  /**
-    * Constructor
-    */
-  protected GetCommonPartJNI() {
-       throw new UnsupportedOperationException();
-  }
-
-  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);
-    }
-  }
-
-  public final static native String getCommonPart(String[] jarg1, int jarg2);
-}
diff --git a/scilab/modules/completion/src/java/org/scilab/modules/completion/GetPartLine.java b/scilab/modules/completion/src/java/org/scilab/modules/completion/GetPartLine.java
deleted file mode 100644 (file)
index 2dbd2ad..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.33
- *
- * Do not make changes to this file unless you know what you are doing--modify
- * the SWIG interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package org.scilab.modules.completion;
-
-
- /** 
-   * @author Allan CORNET
-   * @copyright DIGITEO 2008
-   */
-public class GetPartLine {
-
- /**
-   * Constructor
-   */
- protected GetPartLine() {
-       throw new UnsupportedOperationException();
- }
-  
-/**
-* pre parsing current line to search with completion
-* @param[in] current line
-* @return word to find with completion
-*/
-public static String getPartLevel(String line) {
-    return GetPartLineJNI.getPartLevel(line);
-  }
-
-  
-/**
-* pre parsing current line to search with completion (file)
-* @param[in] current line
-* @return word to find with completion
-*/
-public static String getFilePartLevel(String line) {
-    return GetPartLineJNI.getFilePartLevel(line);
-  }
-
-}
diff --git a/scilab/modules/completion/src/java/org/scilab/modules/completion/GetPartLineJNI.java b/scilab/modules/completion/src/java/org/scilab/modules/completion/GetPartLineJNI.java
deleted file mode 100644 (file)
index facec21..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/* ----------------------------------------------------------------------------
- * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.33
- *
- * Do not make changes to this file unless you know what you are doing--modify
- * the SWIG interface file instead.
- * ----------------------------------------------------------------------------- */
-
-package org.scilab.modules.completion;
-
-
- /** 
-   * @author Allan CORNET
-   * @copyright DIGITEO 2008
-   */
-public class GetPartLineJNI {
-
-  /**
-    * Constructor
-    */
-  protected GetPartLineJNI() {
-       throw new UnsupportedOperationException();
-  }
-
-  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);
-    }
-  }
-
-  public final static native String getPartLevel(String jarg1);
-  public final static native String getFilePartLevel(String jarg1);
-}
index 76ec101..9ea76bd 100644 (file)
@@ -15,6 +15,8 @@
 
 %{
 #include "../c/completion_wrap_java.h"
+#include "getCommonPart.h"
+#include "getPartLine.h"
 #include "MALLOC.h"
 %}
 
@@ -139,3 +141,33 @@ char **searchFilesDictionary(char *somechars);
 public";
 char **searchHandleGraphicsPropertiesDictionary(char *somechars);
 
+/* 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);
+
+/* JavaDoc */
+%javamethodmodifiers getCommonPart(char **dictionnary, int sizeDictionnary) "
+/**
+* Get common part to a array
+* @param[in] string array
+* @param[in] size of string array
+* @return common part
+*/
+public";
+char *getCommonPart(char **dictionnary, int sizeDictionnary);
index a20ccad..e97093d 100644 (file)
@@ -1,6 +1,6 @@
 /* ----------------------------------------------------------------------------
  * This file was automatically generated by SWIG (http://www.swig.org).
- * Version 1.3.35
+ * 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
@@ -179,6 +179,8 @@ static void SWIGUNUSED SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionC
 
 
 #include "../c/completion_wrap_java.h"
+#include "getCommonPart.h"
+#include "getPartLine.h"
 #include "MALLOC.h"
 
 
@@ -473,6 +475,102 @@ SWIGEXPORT jobjectArray JNICALL Java_org_scilab_modules_completion_CompletionJNI
 }
 
 
+SWIGEXPORT jstring JNICALL Java_org_scilab_modules_completion_CompletionJNI_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_CompletionJNI_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;
+}
+
+
+SWIGEXPORT jstring JNICALL Java_org_scilab_modules_completion_CompletionJNI_getCommonPart(JNIEnv *jenv, jclass jcls, jobjectArray jarg1, jint jarg2) {
+  jstring jresult = 0 ;
+  char **arg1 = (char **) 0 ;
+  int arg2 ;
+  char *result = 0 ;
+  jint size1 ;
+  
+  (void)jenv;
+  (void)jcls;
+  {
+    int i = 0;
+    size1 = (*jenv)->GetArrayLength(jenv, jarg1);
+    arg1 = (char **) MALLOC((size1+1)*sizeof(char *));
+    /* make a copy of each string */
+    for (i = 0; i<size1; i++) {
+      jstring j_string = (jstring)(*jenv)->GetObjectArrayElement(jenv, jarg1, i);
+      const char * c_string = (*jenv)->GetStringUTFChars(jenv, j_string, 0);
+      arg1[i] = MALLOC((strlen(c_string)+1)*sizeof(const char *));
+      strcpy(arg1[i], c_string);
+      (*jenv)->ReleaseStringUTFChars(jenv, j_string, c_string);
+      (*jenv)->DeleteLocalRef(jenv, j_string);
+    }
+    arg1[i] = 0;
+  }
+  arg2 = (int)jarg2; 
+  result = (char *)getCommonPart(arg1,arg2);
+  {
+    if (result != NULL)
+    {
+      jresult = (*jenv)->NewStringUTF(jenv, (const char *)result);
+      FREE(result);
+      result = NULL;
+    }       
+  }
+  {
+    int i;
+    for (i=0; i<size1-1; i++)
+    FREE(arg1[i]);
+    FREE(arg1);
+  }
+  return jresult;
+}
+
+
 #ifdef __cplusplus
 }
 #endif
index 419dc94..3cb0942 100644 (file)
@@ -20,7 +20,7 @@ import java.util.Iterator;
 import com.artenum.rosetta.core.action.AbstractConsoleAction;
 import com.artenum.rosetta.interfaces.core.CompletionItem;
 
-import org.scilab.modules.completion.GetCommonPart;
+import org.scilab.modules.completion.Completion;
 
 /**
  * Class used when Scilab user asks for completion on the current edited line
@@ -53,6 +53,7 @@ public class CompletionAction extends AbstractConsoleAction {
                        ((SciCompletionWindow) configuration.getCompletionWindow()).setVisible(false);
                } else if (completionItems != null && completionItems.size() != 0) {
                        String [] completionArray = new String [completionItems.size()];
+                       
                        int i = 0;
                        Iterator < CompletionItem >  it = completionItems.iterator(); 
                        while  (it.hasNext()) {  
@@ -62,9 +63,17 @@ public class CompletionAction extends AbstractConsoleAction {
                        }
            
                        java.util.Arrays.sort(completionArray);
-                       configuration.getInputParsingManager().writeCompletionPart(
-                                       GetCommonPart.getCommonPart(completionArray, completionItems.size()));
+                       String commonPartOfWord = Completion.getCommonPart(completionArray, completionItems.size() );
+
+                       if (commonPartOfWord.length()!= 0) {
+                               if (configuration.getInputParsingManager().getPartLevel(0).length() != 0) {
+                                       configuration.getInputParsingManager().append(commonPartOfWord.substring(configuration.getInputParsingManager().getPartLevel(0).length()) );
+                               }
+                       }
                        configuration.getCompletionWindow().show(completionItems, location);
+                       
                }
+
        }
+       
 }
index 5c093aa..637d01e 100644 (file)
@@ -21,7 +21,7 @@ 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;
+import org.scilab.modules.completion.Completion;
 
 /**
  * @author Vincent COUVERT
@@ -102,7 +102,7 @@ public class SciInputParsingManager implements InputParsingManager {
 
                String lineToParse = wholeLine.substring(0, caretPos);
 
-               return GetPartLine.getPartLevel(lineToParse);
+               return Completion.getPartLevel(lineToParse);
        }
 
        /**
@@ -116,7 +116,7 @@ public class SciInputParsingManager implements InputParsingManager {
                int caretPos = getCaretPosition();
 
                String lineToParse = wholeLine.substring(0, caretPos);
-               return GetPartLine.getFilePartLevel(lineToParse);
+               return Completion.getFilePartLevel(lineToParse);
        }
 
        /**