InitTclTk.c File Reference

#include "InitTclTk.h"
#include "TclEvents.h"
#include <dirent.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#include <X11/Xos.h>
#include <ctype.h>
#include "setgetSCIpath.h"
#include "sciprint.h"

Include dependency graph for InitTclTk.c:

Go to the source code of this file.

Functions

int TCL_EvalScilabCmd (ClientData clientData, Tcl_Interp *theinterp, int objc, CONST char **argv)
int GetWITH_GUI (void)
char * GetSciPath (void)
void initTCLTK (void)
int OpenTCLsci (void)
int CloseTCLsci (void)

Variables

int TK_Started = 0
int XTKsocket = 0


Function Documentation

int CloseTCLsci ( void   ) 

TODO : comment

Returns:

Definition at line 170 of file InitTclTk.c.

References GetWITH_GUI(), NULL, TCLinterp, TK_Started, and TKmainWindow.

00171 {
00172         int bOK=0;
00173         if ( GetWITH_GUI() )
00174         {
00175                 if (TK_Started)
00176                 {
00177                         Tcl_DeleteInterp(TCLinterp);
00178                         TCLinterp=NULL;
00179                         TKmainWindow=NULL;
00180                         bOK=1;
00181                         TK_Started=0;
00182                 }
00183         }
00184         return bOK;
00185 }

Here is the call graph for this function:

char * GetSciPath ( void   ) 

Definition at line 187 of file InitTclTk.c.

References FREE, getSCIpath(), i, int, MALLOC, and NULL.

Referenced by OpenTCLsci().

00189 {
00190         char *PathUnix=NULL;
00191         char *SciPathTmp=NULL;
00192         int i=0;
00193 
00194         SciPathTmp=getSCIpath();
00195 
00196         if (SciPathTmp)
00197         {
00198                 PathUnix=(char*)MALLOC( ((int)strlen(SciPathTmp)+1)*sizeof(char) );
00199 
00200                 strcpy(PathUnix,SciPathTmp);
00201                 for (i=0;i<(int)strlen(PathUnix);i++)
00202                 {
00203                         if (PathUnix[i]=='\\') PathUnix[i]='/';
00204                 }
00205         }
00206         if (SciPathTmp) {FREE(SciPathTmp);SciPathTmp=NULL;}
00207         return PathUnix;
00208 }

Here is the call graph for this function:

Here is the caller graph for this function:

int GetWITH_GUI ( void   ) 

TODO : comment

Returns:

Definition at line 297 of file inisci-c.c.

00298 {
00299         return WITH_GUI;
00300 }

void initTCLTK ( void   ) 

TODO : comment

Definition at line 32 of file InitTclTk.c.

References GetWITH_GUI(), OpenTCLsci(), and TK_Started.

00033 {
00034         if ( GetWITH_GUI() )
00035         {
00036                 if ( OpenTCLsci()==0 ) 
00037                 {
00038                         TK_Started=1;
00039                 }
00040                 else
00041                 {
00042                         TK_Started=0;
00043                 }
00044         }
00045         else
00046         {
00047                 TK_Started=0;
00048         }
00049 }

Here is the call graph for this function:

int OpenTCLsci ( void   ) 

TODO : comment

Returns:

Definition at line 51 of file InitTclTk.c.

References DIR, flushTKEvents(), FREE, GetSciPath(), NULL, sciprint(), TCL_ERROR1, TCL_ERROR2, TCL_ERROR3, TCL_ERROR4, TCL_EvalScilabCmd(), TCL_WARNING1, TCL_WARNING2, TCLinterp, TKmainWindow, tmpdir, and XTKsocket.

Referenced by initTCLTK().

00054 {
00055   char *SciPath=NULL;
00056   char TkScriptpath[2048];
00057   char MyCommand[2048];
00058 
00059 #ifndef _MSC_VER
00060   DIR *tmpdir=NULL;
00061   Display *XTKdisplay;
00062 #endif
00063 
00064   FILE *tmpfile2=NULL;
00065 
00066 #ifdef TCL_MAJOR_VERSION
00067   #ifdef TCL_MINOR_VERSION
00068     #if TCL_MAJOR_VERSION >= 8
00069       #if TCL_MINOR_VERSION > 0
00070          Tcl_FindExecutable(" ");
00071       #endif
00072     #endif
00073   #endif
00074 #endif
00075   SciPath=GetSciPath();
00076   
00077   /* test SCI validity */
00078   if (SciPath==NULL)
00079     {
00080       sciprint(TCL_WARNING1);
00081       return(1);
00082     }
00083 
00084 #ifdef _MSC_VER
00085   strcpy(TkScriptpath, SciPath);
00086   strcat(TkScriptpath, "/modules/tclsci/tcl/TK_Scilab.tcl");
00087 
00088   tmpfile2 = fopen(TkScriptpath,"r");
00089   if (tmpfile2==NULL) 
00090     {
00091       sciprint(TCL_WARNING2);
00092       return(1);
00093     }
00094   else fclose(tmpfile2);
00095 #else
00096   tmpdir=opendir(SciPath);
00097   if (tmpdir==NULL) 
00098     {
00099       sciprint(TCL_WARNING1);
00100       return(1);
00101     }
00102   else closedir(tmpdir);
00103   strcpy(TkScriptpath,SciPath);
00104   strcat(TkScriptpath, "/modules/tclsci/tcl/TK_Scilab.tcl");
00105   tmpfile2 = fopen(TkScriptpath,"r");
00106   if (tmpfile2==NULL) 
00107     {
00108       sciprint(TCL_WARNING2);
00109       return(1);
00110     }
00111   else fclose(tmpfile2);
00112 #endif /* _MSC_VER */ 
00113   
00114   if (TCLinterp == NULL) 
00115     {
00116       TCLinterp = Tcl_CreateInterp();
00117           if ( TCLinterp == NULL )
00118           {
00119             Scierror(999,TCL_ERROR1);
00120                 return (1);
00121           }
00122 
00123       if ( Tcl_Init(TCLinterp) == TCL_ERROR)
00124           {
00125                 Scierror(999,TCL_ERROR2);
00126                 return (1);
00127           }
00128 
00129       if ( Tk_Init(TCLinterp) == TCL_ERROR)
00130           {
00131                 Scierror(999,TCL_ERROR3);
00132                 return (1);
00133           }
00134 
00135       sprintf(MyCommand, "set SciPath \"%s\";",SciPath); 
00136       
00137           if ( Tcl_Eval(TCLinterp,MyCommand) == TCL_ERROR  )
00138           {
00139                 Scierror(999,TCL_ERROR4,TCLinterp->result);
00140                 return (1);
00141           }
00142       
00143           Tcl_CreateCommand(TCLinterp,"ScilabEval",TCL_EvalScilabCmd,(ClientData)1,NULL);
00144     }
00145    
00146   if (TKmainWindow == NULL)
00147     {
00148       TKmainWindow = Tk_MainWindow(TCLinterp);
00149           #ifndef _MSC_VER
00150         XTKdisplay=Tk_Display(TKmainWindow);
00151         XTKsocket = ConnectionNumber(XTKdisplay);
00152           #endif
00153       
00154       Tk_GeometryRequest(TKmainWindow,2,2);
00155 
00156           if ( Tcl_EvalFile(TCLinterp,TkScriptpath) == TCL_ERROR  )
00157           {
00158                 Scierror(999,TCL_ERROR4,TCLinterp->result);
00159                 return (1);
00160           }
00161 
00162       flushTKEvents();
00163     }
00164 
00165   if (SciPath) {FREE(SciPath);SciPath=NULL;}
00166   return(0);
00167 
00168 }

Here is the call graph for this function:

Here is the caller graph for this function:

int TCL_EvalScilabCmd ( ClientData  clientData,
Tcl_Interp *  theinterp,
int  objc,
CONST char **  argv 
)

Definition at line 22 of file ScilabEval.c.

References AddCharacters, arbitrary_max_queued_callbacks, bsiz, C2F, c_n1, command, ddt, FREE, GetCommand(), ierr, int, ismenu(), MALLOC, memset(), nc, NULL, sciprint(), sciprint_full(), SetCommandflag(), StoreCommand(), syncexec(), TCL_ERROR28, TCL_ERROR29, TCL_MSG10, TCL_MSG11, TCL_MSG12, TCL_MSG13, TCL_MSG14, TCL_MSG7, TCL_MSG8, TCL_MSG9, TCL_WARNING4, TCL_WARNING5, and tksynchro().

00023 {
00024   int ns,ierr,seq;
00025   char *command;
00026   
00027   char *comm[arbitrary_max_queued_callbacks];
00028   int   seqf[arbitrary_max_queued_callbacks];
00029   int nc,ncomm=-1;
00030 
00031   if (C2F(iop).ddt==-1)
00032   {
00033         /* trace for debugging */
00034     int argc=1;
00035         char *AsciiFromUTF8=NULL;
00036 
00037         AsciiFromUTF8=MALLOC(sizeof(char)*(strlen(argv[1])+AddCharacters));
00038 
00039     /* UTF to ANSI */
00040         Tcl_UtfToExternal(theinterp, NULL, argv[1], (int)strlen(argv[1]), 0, NULL, AsciiFromUTF8, (int)(strlen(argv[1])+AddCharacters), NULL, NULL,NULL);
00041 
00042     sciprint_full(TCL_MSG7,AsciiFromUTF8);
00043 
00044     while (argv[++argc]) sciprint(" %s",argv[argc]);
00045     sciprint("\n");
00046 
00047         if (AsciiFromUTF8){FREE(AsciiFromUTF8);AsciiFromUTF8=NULL;}
00048   }
00049 
00050   if (argv[1] != (char *)0)
00051   {
00052           char *AsciiFromUTF8=NULL;
00053           AsciiFromUTF8=MALLOC(sizeof(char)*(strlen(argv[1])+AddCharacters));
00054 
00055           /* UTF to ANSI */
00056           Tcl_UtfToExternal(theinterp, NULL, argv[1], (int)strlen(argv[1]), 0, NULL, AsciiFromUTF8, (int)(strlen(argv[1])+AddCharacters), NULL, NULL,NULL);
00057 
00058     if (strlen(AsciiFromUTF8)>=bsiz)
00059         {
00060       command = (char *) MALLOC (bsiz * sizeof (char));
00061       if (command == (char *) 0)
00062       {
00063         sciprint(TCL_ERROR28);
00064         return TCL_ERROR;
00065       }
00066       memset(command,'\0',bsiz);
00067       strncpy(command,AsciiFromUTF8,bsiz-1);
00068       sciprint(TCL_WARNING4,bsiz-1);
00069     }
00070         else
00071         {
00072       command = (char *) MALLOC ((strlen (AsciiFromUTF8) + 1) * sizeof (char));
00073       if (command == (char *) 0)
00074       {
00075         sciprint(TCL_ERROR28);
00076         return TCL_ERROR;
00077       }
00078       strcpy(command,AsciiFromUTF8);
00079     }
00080         if (AsciiFromUTF8){FREE(AsciiFromUTF8);AsciiFromUTF8=NULL;}
00081 
00082     if ( (argv[2] != (char *)0) && (strncmp(argv[2],"sync",4)==0) )
00083         {
00084       /* sync or sync seq */
00085       C2F(tksynchro)(&c_n1);  /* set sciprompt to -1 (scilab busy) */
00086       seq= ( (argv[3] != (char *)0) && (strncmp(argv[3],"seq",3)==0) );
00087       ns=(int)strlen(command); 
00088       if (C2F(iop).ddt==-1) sciprint_full(TCL_MSG8,command);
00089       C2F(syncexec)(command,&ns,&ierr,&seq);
00090       if (C2F(iop).ddt==-1) sciprint_full(TCL_MSG9,command);
00091       C2F(tksynchro)(&C2F(recu).paus);
00092       if (ierr != 0) return TCL_ERROR;
00093     }
00094     else if (strncmp(command,"flush",5)==0)
00095         {
00096       /* flush */
00097       if (C2F(iop).ddt==-1) sciprint(TCL_MSG10);
00098       while (C2F(ismenu)() && ncomm<arbitrary_max_queued_callbacks-1)
00099           {
00100         ncomm++;
00101         comm[ncomm] = (char *) MALLOC (bsiz+1);
00102         if (comm[ncomm] == (char *) 0)
00103         {
00104           sciprint (TCL_ERROR28);
00105           return TCL_ERROR;
00106         }
00107         seqf[ncomm]=GetCommand (comm[ncomm]);
00108       }
00109       if (C2F(ismenu)()) sciprint(TCL_WARNING5);
00110       for (nc = 0 ; nc <= ncomm ; nc++ )
00111           {
00112         C2F(tksynchro)(&c_n1);  /* set sciprompt to -1 (scilab busy) */
00113         if (C2F(iop).ddt==-1)
00114         {
00115               if (seqf[nc]==0)
00116                   {
00117                           sciprint_full(TCL_MSG11,comm[nc]);
00118                   }
00119               else
00120                   {
00121                           sciprint_full(TCL_MSG12,comm[nc]);
00122                   }
00123         }
00124         ns=(int)strlen(comm[nc]);
00125         C2F(syncexec)(comm[nc],&ns,&ierr,&(seqf[nc]));
00126         if (C2F(iop).ddt==-1)
00127         {
00128           sciprint_full(TCL_MSG13,comm[nc]);
00129         }
00130         FREE(comm[nc]);
00131         C2F(tksynchro)(&C2F(recu).paus);
00132         if (ierr != 0) return TCL_ERROR;
00133       }
00134       if (C2F(iop).ddt==-1) sciprint(TCL_MSG14);
00135     }
00136     else
00137         {
00138       /* seq or no option */
00139       StoreCommand(command); 
00140 
00141       if ( (argv[2] != (char *)0) && (strncmp(argv[2],"seq",3)==0) )
00142           {
00143         SetCommandflag(1);
00144       }
00145       else
00146           {
00147                 /* unknown option */
00148         Tcl_SetResult(theinterp,NULL,NULL);
00149           }
00150     }
00151     FREE(command);
00152 
00153   } 
00154   else
00155   {
00156         /* ScilabEval called without argument */
00157     Scierror(999,TCL_ERROR29);
00158   }
00159 
00160   return TCL_OK;
00161 }

Here is the call graph for this function:


Variable Documentation

int TK_Started = 0

Definition at line 25 of file InitTclTk.c.

int XTKsocket = 0

Definition at line 27 of file InitTclTk.c.

Referenced by basic_scilab_mask(), OpenTCLsci(), sxevents(), and Xorgetchar().


Generated on Sun Mar 4 16:13:44 2007 for Scilab [trunk] by  doxygen 1.5.1