#include "CallScilab.h"#include "MALLOC.h"#include "scirun.h"Include dependency graph for SendScilabJobs.c:

Go to the source code of this file.
Defines | |
| #define | BufferSecuritySize 64 |
Functions | |
| static BOOL | RemoveCharsFromEOL (char *line, char CharToRemove) |
| static BOOL | RemoveComments (char *line) |
| static BOOL | CleanBuffers (char *bufCommands, char **LOCALJOBS, int numberjobs) |
| static BOOL | SetLastJob (char *JOB) |
| int | SendScilabJob (char *job) |
| BOOL | GetLastJob (char *JOB, int nbcharsJOB) |
| int | SendScilabJobs (char **jobs, int numberjobs) |
Variables | |
| static char * | lastjob = NULL |
| #define BufferSecuritySize 64 |
Referenced by SendScilabJobs().
| static BOOL CleanBuffers | ( | char * | bufCommands, | |
| char ** | LOCALJOBS, | |||
| int | numberjobs | |||
| ) | [static] |
Definition at line 287 of file SendScilabJobs.c.
References FALSE, FREE, i, NULL, and TRUE.
Referenced by SendScilabJobs().
00288 { 00289 BOOL bOK=FALSE; 00290 00291 if (bufCommands) {FREE(bufCommands);bufCommands=NULL;} 00292 00293 if (LOCALJOBS) 00294 { 00295 int i=0; 00296 for (i=0; i < numberjobs;i++) 00297 { 00298 if (LOCALJOBS[i]) {FREE(LOCALJOBS[i]);LOCALJOBS[i]=NULL;} 00299 } 00300 LOCALJOBS=NULL; 00301 } 00302 00303 bOK=TRUE; 00304 00305 return bOK; 00306 00307 }
Here is the caller graph for this function:

| BOOL GetLastJob | ( | char * | JOB, | |
| int | nbcharsJOB | |||
| ) |
Returns last job send to scilab by SendScilabJobs or SendScilabJob
| [out] | JOB | the last job |
| [out] | nbcharsJOB | the size of JOB Example : jobs[0] : a = 1; jobs[1] : b = V_NOT_EXIST; jobs[2] : c = a + b; if (SendScilabJobs(jobs,3)) { char lastjob[4096]; // bsiz in scilab if (GetLastJob(lastjob,4096)) { printf("%s\n",lastjob); } } |
Definition at line 107 of file SendScilabJobs.c.
References FALSE, lastjob, and TRUE.
Referenced by example3(), and troisieme_exemple().
00108 { 00109 BOOL bOK=FALSE; 00110 if (JOB) 00111 { 00112 if ((int)strlen(lastjob)<nbcharsJOB) 00113 { 00114 strcpy(JOB,lastjob); 00115 } 00116 else strncpy(JOB,lastjob,nbcharsJOB); 00117 bOK=TRUE; 00118 } 00119 return bOK; 00120 }
Here is the caller graph for this function:

| static BOOL RemoveCharsFromEOL | ( | char * | line, | |
| char | CharToRemove | |||
| ) | [static] |
Definition at line 240 of file SendScilabJobs.c.
References FALSE, l, len, and TRUE.
Referenced by SendScilabJobs().
00241 { 00242 int l=0; 00243 BOOL bOK=FALSE; 00244 int len=0; 00245 00246 len=strlen(line); 00247 for (l=len-1;l>0;l--) 00248 { 00249 if (line[l] == CharToRemove) 00250 { 00251 line[l] = '\0'; 00252 bOK=TRUE; 00253 } 00254 else break; 00255 } 00256 return bOK; 00257 }
Here is the caller graph for this function:

| static BOOL RemoveComments | ( | char * | line | ) | [static] |
Definition at line 259 of file SendScilabJobs.c.
Referenced by SendScilabJobs().
00260 { 00261 int l=0; 00262 BOOL bOK=FALSE; 00263 int len=0; 00264 int idx=-1; 00265 00266 len=strlen(line); 00267 for (l=len-1;l>0;l--) 00268 { 00269 if (line[l] == '/') 00270 { 00271 if (l-1>0) 00272 { 00273 if (line[l-1] == '/') 00274 { 00275 idx=l-1; 00276 l=l-2; 00277 } 00278 } 00279 } 00280 } 00281 00282 if (idx>=0) line[idx]='\0'; 00283 00284 return bOK; 00285 }
Here is the caller graph for this function:

| int SendScilabJob | ( | char * | job | ) |
Send a job to scilab
| job | the Scilab Job |
Definition at line 17 of file SendScilabJobs.c.
References C2F, cmatptr(), code, command, cwritechain(), FREE, int, lp, m, MALLOC, n, NULL, ReadMatrix, scirun(), and SetLastJob().
00018 { 00019 int retCode = -1; 00020 int lencommand=0; 00021 static char *command=NULL; 00022 00023 char ScirunCommand[]="Err=execstr(TMP_EXEC_STRING,\"errcatch\",\"n\");quit;"; 00024 char ClearTmpVariables[]="clear TMP_EXEC_STRING;clear Err;quit;"; 00025 00026 lencommand=strlen(job); 00027 command=MALLOC(sizeof(char)*(lencommand+1)); 00028 00029 if (command) 00030 { 00031 /* clear prev. Err , TMP_EXEC_STRING scilab variables */ 00032 C2F(scirun)(ClearTmpVariables,strlen(ClearTmpVariables)); 00033 00034 strcpy(command,job); 00035 SetLastJob(command); 00036 00037 /* Creation Variable temporaire dans Scilab */ 00038 if (!C2F(cwritechain)("TMP_EXEC_STRING",&lencommand,(char*)command,(int)strlen("TMP_EXEC_STRING"),(int)strlen(command)) ) 00039 { 00040 /* Probleme */ 00041 fprintf(stderr,"Error : SendScilabJob (1) 'TMP_EXEC_STRING'.\n"); 00042 retCode = -1; 00043 00044 if (command) {FREE(command);command=NULL;} 00045 return retCode; 00046 } 00047 else 00048 { 00049 int m=0,n=0,lp=0; 00050 00051 C2F(scirun)(ScirunCommand,strlen(ScirunCommand)); 00052 00053 /* get error code from scilab */ 00054 00055 if ( ! C2F(cmatptr)("Err", &m, &n, &lp,strlen("Err"))) 00056 { 00057 fprintf(stderr,"Error : SendScilabJob (2) 'Err'.\n"); 00058 retCode = -2; 00059 } 00060 else 00061 { 00062 if (m*n == 1) 00063 { 00064 double code = -1; 00065 ReadMatrix("Err", &m, &n, &code); 00066 retCode = (int) code ; 00067 } 00068 else 00069 { 00070 fprintf(stderr,"Error : SendScilabJob (3) 'Err'.\n"); 00071 retCode = -3; 00072 } 00073 } 00074 00075 /* clear prev. Err , TMP_EXEC_STRING scilab variables */ 00076 C2F(scirun)(ClearTmpVariables,strlen(ClearTmpVariables)); 00077 } 00078 if (command) {FREE(command);command=NULL;} 00079 } 00080 else 00081 { 00082 fprintf(stderr,"Error : SendScilabJob (4) 'command' MALLOC.\n"); 00083 retCode = -4; 00084 } 00085 00086 return retCode; 00087 }
Here is the call graph for this function:

Send jobs to scilab
jobs[0] : a = 1; jobs[1] : b = 3; jobs[2] : c = a + b; SendScilabJobs(jobs,3);
Definition at line 122 of file SendScilabJobs.c.
References BufferSecuritySize, CleanBuffers(), FALSE, i, MALLOC, NULL, RemoveCharsFromEOL(), RemoveComments(), retcode, SendScilabJob(), and TRUE.
Referenced by example3(), and troisieme_exemple().
00123 { 00124 #define BufferSecuritySize 64 00125 00126 int retcode=-10; 00127 00128 if (jobs) 00129 { 00130 int i=0; 00131 int nbcharsjobs=0; 00132 char *bufCommands=NULL; 00133 char **LOCALJOBS=NULL; 00134 00135 int jobsloop=0; 00136 00137 LOCALJOBS=(char**)MALLOC(sizeof(char*)*numberjobs); 00138 00139 if (LOCALJOBS) 00140 { 00141 for (i=0;i<numberjobs;i++) 00142 { 00143 if (jobs[i]) 00144 { 00145 nbcharsjobs = nbcharsjobs+(int)strlen(jobs[i]); 00146 LOCALJOBS[i]=(char*)MALLOC( sizeof(char)*(strlen(jobs[i])+BufferSecuritySize) ); 00147 if (LOCALJOBS[i]) 00148 { 00149 strcpy(LOCALJOBS[i],jobs[i]); 00150 } 00151 else 00152 { 00153 CleanBuffers(bufCommands,LOCALJOBS,numberjobs); 00154 fprintf(stderr,"Error : SendScilabJobs (1) 'LOCALJOBS[%d] MALLOC'.\n",i); 00155 return retcode; 00156 } 00157 } 00158 else 00159 { 00160 fprintf(stderr,"Error : SendScilabJobs (2) 'jobs[%d] == NULL'.\n",i); 00161 return retcode; 00162 } 00163 } 00164 00165 bufCommands = (char*)MALLOC( sizeof(char)*(nbcharsjobs+numberjobs+BufferSecuritySize) ); 00166 00167 if (bufCommands) 00168 { 00169 strcpy(bufCommands,""); 00170 00171 for (jobsloop=0;jobsloop<numberjobs;jobsloop++) 00172 { 00173 if (jobs[jobsloop]) 00174 { 00175 char *currentline=NULL; 00176 BOOL AddSemiColon; 00177 00178 if (jobsloop == 0) AddSemiColon=FALSE; 00179 else AddSemiColon=TRUE; 00180 00181 DOTDOTLOOP: 00182 currentline=LOCALJOBS[jobsloop]; 00183 00184 RemoveCharsFromEOL(currentline,'\n'); 00185 RemoveComments(currentline); 00186 RemoveCharsFromEOL(currentline,' '); 00187 00188 if (RemoveCharsFromEOL(currentline,'.')) 00189 { 00190 RemoveCharsFromEOL(currentline,' '); 00191 strcat(bufCommands,currentline); 00192 jobsloop++; 00193 AddSemiColon=FALSE; 00194 goto DOTDOTLOOP; 00195 } 00196 else 00197 { 00198 if (!AddSemiColon) 00199 { 00200 AddSemiColon=TRUE; 00201 strcat(currentline,";"); 00202 } 00203 else 00204 { 00205 strcat(bufCommands,";"); 00206 } 00207 00208 strcat(bufCommands,currentline); 00209 } 00210 } 00211 } 00212 00213 retcode=SendScilabJob(bufCommands); 00214 00215 CleanBuffers(bufCommands,LOCALJOBS,numberjobs); 00216 } 00217 else 00218 { 00219 CleanBuffers(bufCommands,LOCALJOBS,numberjobs); 00220 fprintf(stderr,"Error : SendScilabJobs (3) 'bufCommands MALLOC'.\n"); 00221 return retcode; 00222 } 00223 } 00224 else 00225 { 00226 CleanBuffers(bufCommands,LOCALJOBS,numberjobs); 00227 fprintf(stderr,"Error : SendScilabJobs (4) 'LOCALJOBS == NULL'.\n"); 00228 return retcode; 00229 } 00230 } 00231 else 00232 { 00233 fprintf(stderr,"Error : SendScilabJobs (5) 'jobs == NULL'.\n"); 00234 retcode = -10; 00235 } 00236 00237 return retcode; 00238 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static BOOL SetLastJob | ( | char * | JOB | ) | [static] |
Definition at line 89 of file SendScilabJobs.c.
References FALSE, FREE, lastjob, MALLOC, NULL, and TRUE.
Referenced by SendScilabJob().
00090 { 00091 BOOL bOK=FALSE; 00092 00093 if (lastjob) { FREE(lastjob);lastjob=NULL;} 00094 00095 if (JOB) 00096 { 00097 lastjob = MALLOC(sizeof(char)*(strlen(JOB)+1)); 00098 if (lastjob) 00099 { 00100 strcpy(lastjob,JOB); 00101 bOK =TRUE; 00102 } 00103 } 00104 return bOK; 00105 }
Here is the caller graph for this function:

char* lastjob = NULL [static] |
Definition at line 13 of file SendScilabJobs.c.
Referenced by example3(), GetLastJob(), SetLastJob(), and troisieme_exemple().
1.5.1