Rationnalization of the tcl/tk init process and use function instead of a silly globa...
Sylvestre Ledru [Wed, 26 Dec 2007 21:03:23 +0000 (21:03 +0000)]
scilab/modules/tclsci/includes/InitTclTk.h [deleted file]
scilab/modules/tclsci/includes/TCL_Global.h
scilab/modules/tclsci/sci_gateway/c/gw_tclsci.c
scilab/modules/tclsci/sci_gateway/c/sci_TCL_DeleteInterp.c
scilab/modules/tclsci/src/c/InitTclTk.c
scilab/modules/tclsci/src/c/InitTclTk.h [new file with mode: 0644]
scilab/modules/tclsci/src/c/InitializeTclTk.c
scilab/modules/tclsci/src/c/TerminateTclTk.c
scilab/modules/tclsci/src/c/tksynchro.c

diff --git a/scilab/modules/tclsci/includes/InitTclTk.h b/scilab/modules/tclsci/includes/InitTclTk.h
deleted file mode 100644 (file)
index 4d2a7e7..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*--------------------------------------------------------------------------*/
-/* INRIA 2005 */
-/* Allan CORNET */
-/*--------------------------------------------------------------------------*/ 
-#ifndef __INITTCLTK__
-#define __INITTCLTK__
-
-#include "TCL_Global.h"
-
-/**
- * TODO : comment 
- */
-void initTCLTK(void);
-
-/**
- * TODO : comment 
- * @return 
- */
-int OpenTCLsci(void);
-
-/**
- * TODO : comment 
- * @return
- */
-int CloseTCLsci(void);
-
-#endif /* __INITTCLTK__ */
-/*--------------------------------------------------------------------------*/ 
index c8dd137..84de7fa 100644 (file)
@@ -24,7 +24,6 @@
 extern Tcl_Interp *TCLinterp;
 extern Tk_Window TKmainWindow;
 extern int XTKsocket;
-extern int TK_Started;
 /*--------------------------------------------------------------------------*/
 
 /**
index c85ae50..ec30b01 100644 (file)
@@ -42,7 +42,7 @@ int C2F(gw_tclsci)()
 {  
        if ( getScilabMode() != SCILAB_NWNI )
        {
-               if (TK_Started)
+               if (isTkStarted())
                {
                        Rhs = Max(0, Rhs);
                        callFunctionFromGateway(Tab);           
index adc1f8f..c442dd8 100644 (file)
@@ -55,7 +55,7 @@ int C2F(sci_TCL_DeleteInterp) _PARAMS((char *fname,unsigned long l))
                        return 0;
                }
                CloseTCLsci();
-               initTCLTK();
+               InitializeTclTk();
        }
 
        LhsVar(1)=0;
index abb9388..abc32f9 100644 (file)
 #include "scilabmode.h"
 #include "ScilabEval.h"
 /*--------------------------------------------------------------------------*/
-int TK_Started=0;
+BOOL TK_Started=FALSE;
 /*--------------------------------------------------------------------------*/
 static char *GetSciPath(void);
 /*--------------------------------------------------------------------------*/
-void initTCLTK(void)
-{
-       if ( getScilabMode() != SCILAB_NWNI )
-       {
-               if ( OpenTCLsci()==0 )
-               {
-                       TK_Started=1;
-               }
-               else
-               {
-                       TK_Started=0;
-               }
-       }
-       else
-       {
-               TK_Started=0;
-       }
-}
-/*--------------------------------------------------------------------------*/
 int OpenTCLsci(void)
 /* Checks if tcl/tk has already been initialised and if not */
 /* initialise it. It must find the tcl script */
@@ -152,21 +133,20 @@ int OpenTCLsci(void)
 
 }
 /*--------------------------------------------------------------------------*/
-int CloseTCLsci(void)
+BOOL CloseTCLsci(void)
 {
-       int bOK=0;
        if ( getScilabMode() != SCILAB_NWNI )
        {
-               if (TK_Started)
+               if (isTkStarted())
                {
                        Tcl_DeleteInterp(TCLinterp);
                        TCLinterp=NULL;
                        TKmainWindow=NULL;
-                       bOK=1;
-                       TK_Started=0;
+                       setTkStarted(FALSE);
+                       return TRUE;
                }
        }
-       return bOK;
+       return FALSE;
 }
 /*--------------------------------------------------------------------------*/
 static char *GetSciPath(void)
@@ -192,3 +172,11 @@ static char *GetSciPath(void)
        return PathUnix;
 }
 /*--------------------------------------------------------------------------*/
+BOOL isTkStarted(void){
+       return TK_Started;
+}
+/*--------------------------------------------------------------------------*/ 
+void setTkStarted(BOOL isTkSet){
+       TK_Started=isTkSet;
+}
+/*--------------------------------------------------------------------------*/ 
diff --git a/scilab/modules/tclsci/src/c/InitTclTk.h b/scilab/modules/tclsci/src/c/InitTclTk.h
new file mode 100644 (file)
index 0000000..57bd74a
--- /dev/null
@@ -0,0 +1,44 @@
+/*--------------------------------------------------------------------------*/
+/* INRIA 2005/2007 */
+/* @author Allan CORNET */
+/* @author Sylvestre Ledru <sylvestre.ledru@inria.fr> */
+/*--------------------------------------------------------------------------*/ 
+#ifndef __INITTCLTK__
+#define __INITTCLTK__
+
+#include "TCL_Global.h"
+#include "BOOL.h"
+
+/**
+ * Initialize TCL/TK
+ * @return if started (TRUE) or not (FALSE)
+ */
+BOOL initTCLTK(void);
+
+/**
+ * @TODO add comment
+ *
+ * @return <ReturnValue>
+ */
+int OpenTCLsci(void);
+
+/**
+ * TODO : comment 
+ * @return
+ */
+BOOL CloseTCLsci(void);
+
+/**
+ * Set if tcl/tk is started or not
+ * @param isTkSet if enable or not
+ */
+void setTkStarted(BOOL isTkSet);
+
+/**
+ * Set if tcl/tk is started or not
+ * @return says if TCL/TK is started (TRUE) or not (FALSE)
+ */
+BOOL isTkStarted(void);
+
+#endif /* __INITTCLTK__ */
+/*--------------------------------------------------------------------------*/ 
index 39bd4bb..995d02a 100644 (file)
@@ -4,12 +4,27 @@
 /*--------------------------------------------------------------------------*/ 
 #include "InitializeTclTk.h"
 #include "InitTclTk.h"
+#include "scilabmode.h"
+/*--------------------------------------------------------------------------*/ 
 /*--------------------------------------------------------------------------*/ 
 BOOL InitializeTclTk(void)
 {
-       BOOL bOK=FALSE;
-       initTCLTK();
-       return bOK;
+       if ( getScilabMode() != SCILAB_NWNI )
+       {
+               if ( OpenTCLsci()==0 )
+               {
+                       setTkStarted(TRUE);
+                       return TRUE;
+               }
+               else
+               {
+                       setTkStarted(FALSE);
+               }
+       }
+       else
+       {
+               setTkStarted(FALSE);
+       }
+       return FALSE;
 }
 /*--------------------------------------------------------------------------*/ 
-
index a86cc63..b8e5d92 100644 (file)
@@ -8,7 +8,6 @@
 /*--------------------------------------------------------------------------*/ 
 BOOL TerminateTclTk(void)
 {
-       CloseTCLsci();
-       return TRUE;
+       return CloseTCLsci();
 }
 /*--------------------------------------------------------------------------*/ 
index 6c23cef..f063d7b 100644 (file)
@@ -3,6 +3,7 @@
 /*--------------------------------------------------------------------------*/
 #include <math.h>
 #include <stdio.h>
+#include "InitTclTk.h"
 #include "machine.h"
 #include "TCL_Global.h"
 #include "tksynchro.h"
@@ -13,7 +14,7 @@ void C2F(tksynchro)( int *l)
 {
   char str[128];
 
-  if (TK_Started) 
+  if (isTkStarted()) 
   {
     int RET;