ScilabEval.c

Go to the documentation of this file.
00001 /*-----------------------------------------------------------------------------------*/
00002 /* INRIA 2005 */
00003 /* Allan CORNET */
00004 /*-----------------------------------------------------------------------------------*/ 
00005 #include "TCL_Global.h"
00006 #include "ScilabEval.h"
00007 #include "sciprint.h"
00008 #include "tksynchro.h"
00009 /*-----------------------------------------------------------------------------------*/
00010 /* what's the max number of commands in the queue ??*/
00011 #define arbitrary_max_queued_callbacks 20
00012 #define AddCharacters 4
00013 /*-----------------------------------------------------------------------------------*/
00014 static int c_n1 = -1;     
00015 /*-----------------------------------------------------------------------------------*/
00016 extern void SetCommandflag(int flag) ;
00017 extern void C2F(syncexec)(char * str, int *ns, int *ierr, int *seq);
00018 extern int GetCommand(char *str);
00019 extern int StoreCommand ( char *command); 
00020 extern integer C2F (ismenu)(void); 
00021 /*-----------------------------------------------------------------------------------*/
00022 int TCL_EvalScilabCmd(ClientData clientData,Tcl_Interp * theinterp,int objc,CONST char ** argv)
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 }

Generated on Sun Mar 4 15:04:01 2007 for Scilab [trunk] by  doxygen 1.5.1