612f1580a521c47c06203912bdb20424b7017962
[scilab.git] / scilab / modules / output_stream / sci_gateway / cpp / sci_diary.cpp
1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2009 - DIGITEO - Allan CORNET
4 *
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution.  The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
12 /*--------------------------------------------------------------------------*/
13 #include "diary_manager.hxx"
14 /*--------------------------------------------------------------------------*/
15 extern "C"
16 {
17 #include "gw_output_stream.h"
18 #include "stack-c.h"
19 #include "api_scilab.h"
20 #include "localization.h"
21 #include "charEncoding.h"
22 #include "Scierror.h"
23 #include "MALLOC.h"
24 #include "freeArrayOfString.h"
25 }
26 /*--------------------------------------------------------------------------*/
27 #define DIARY_SECOND_ARG_LIST L"list"
28 #define DIARY_SECOND_ARG_CLOSE L"close"
29 #define DIARY_SECOND_ARG_PAUSE L"pause"
30 #define DIARY_SECOND_ARG_OFF L"off"
31 #define DIARY_SECOND_ARG_RESUME L"resume"
32 #define DIARY_SECOND_ARG_ON L"on"
33 #define DIARY_SECOND_ARG_NEW L"new"
34 #define DIARY_SECOND_ARG_APPEND L"append"
35 #define DIARY_SECOND_ARG_EXISTS L"exists"
36 #define DIARY_THIRD_ARG_FILTER_COMMAND L"filter=command"
37 #define DIARY_THIRD_ARG_FILTER_OUTPUT L"filter=output"
38 #define DIARY_THIRD_ARG_PREFIX_UNIX_EPOCH L"prefix=U"
39 #define DIARY_THIRD_ARG_PREFIX_DEFAULT L"prefix=YYYY-MM-DD hh:mm:ss"
40 #define DIARY_THIRD_ARG_PREFIX_ONLY_COMMANDS L"prefix-only-commands"
41 /*--------------------------------------------------------------------------*/
42 static int sci_diary_no_rhs(char *fname);
43 static int sci_diary_one_rhs(char *fname);
44 static int sci_diary_two_rhs(char *fname);
45 static int sci_diary_three_rhs(char *fname);
46 /*--------------------------------------------------------------------------*/
47 static double *getInputArgumentOneIDs(char *fname,int *sizeReturnedArray, int *ierror);
48 static wchar_t **getInputArgumentOneFilenames(char *fname,int *sizeReturnedArray, int *ierror);
49 static wchar_t *getInputArgumentTwo(char *fname, int *ierror);
50 static wchar_t **getInputArgumentThree(char *fname,int *sizeReturnedArray, int *ierror);
51 static int checkExistByIDs(char *fname, double *IDs, int size_IDs); 
52 static int checkExistByFilenames(char *fname, wchar_t **wcFilenames, int size_IDs); 
53 static int CloseByFilenames(char *fname);
54 static int CloseByIds(char *fname);
55 static int PauseByFilenames(char *fname);
56 static int PauseByIds(char *fname);
57 static int ResumeByFilenames(char *fname);
58 static int ResumeByIds(char *fname);
59 static int ExistByFilenames(char *fname);
60 static int ExistByIds(char *fname);
61 static int AppendByFilenames(char *fname, 
62                                                          diary_filter filterMode, 
63                                                          diary_prefix_time_format prefixMode, 
64                                                          diary_prefix_time_filter prefixModeFilter,
65                                                          bool suspended);
66 static int NewByFilenames(char *fname, 
67                                                   diary_filter filterMode, 
68                                                   diary_prefix_time_format prefixMode, 
69                                                   diary_prefix_time_filter prefixModeFilter,
70                                                   bool suspended);
71 /*--------------------------------------------------------------------------*/
72 int sci_diary(char *fname,unsigned long fname_len)
73 {
74         CheckRhs(0,3);
75         CheckLhs(0,2);
76
77         switch (Rhs)
78         {
79         case 0:
80                 return sci_diary_no_rhs(fname);
81         case 1:
82                 return sci_diary_one_rhs(fname);
83         case 2:
84                 return sci_diary_two_rhs(fname);
85         case 3:
86                 return sci_diary_three_rhs(fname);
87         }
88         return 0;
89 }
90 /*--------------------------------------------------------------------------*/
91 static int sci_diary_no_rhs(char *fname)
92 {
93         // [ids, filenames] = diary()
94         // [ids, filenames] = diary([],"list")
95         SciErr sciErr;
96         int nb_diary_ids = 0;
97         double *diary_ids  = getDiaryIDsAsDouble(&nb_diary_ids);
98
99         if ( (diary_ids) && (nb_diary_ids > 0) )
100         {
101                 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, nb_diary_ids, 1, diary_ids);
102                 if(sciErr.iErr)
103                 {
104                         printError(&sciErr, 0);
105                         return 0;
106                 }
107
108                 LhsVar(1) = Rhs + 1;
109
110                 delete [] diary_ids;
111                 diary_ids = NULL;
112                 nb_diary_ids = 0;
113         }
114         else
115         {
116                 if (nb_diary_ids == 0)
117                 {
118                         sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, 0, 0, NULL);
119                         if(sciErr.iErr)
120                         {
121                                 printError(&sciErr, 0);
122                                 return 0;
123                         }
124                         LhsVar(1) = Rhs + 1;
125
126                         if (diary_ids) 
127                         {
128                                 delete [] diary_ids;
129                                 diary_ids = NULL;
130                                 nb_diary_ids = 0;
131                         }
132                 }
133                 else
134                 {
135                         Scierror(999,_("%s: Memory allocation error.\n"),fname);
136                         return 0;
137                 }
138         }
139
140         if (Lhs == 2)
141         {
142                 int nb_diary_filenames = 0;
143                 wchar_t **wcdiary_filenames = getDiaryFilenames(&nb_diary_filenames);
144
145                 if ( (wcdiary_filenames) && (nb_diary_filenames > 0) )
146                 {
147                         sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 2, nb_diary_filenames, 1, wcdiary_filenames);
148                         if(sciErr.iErr)
149                         {
150                                 printError(&sciErr, 0);
151                                 return 0;
152                         }
153
154                         LhsVar(2) = Rhs + 2;
155
156                         freeArrayOfWideString(wcdiary_filenames, nb_diary_filenames);
157                         nb_diary_filenames = 0;
158                 }
159                 else
160                 {
161                         if (nb_diary_filenames == 0)
162                         {
163                                 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 2, 0, 0, NULL);
164                                 if(sciErr.iErr)
165                                 {
166                                         printError(&sciErr, 0);
167                                         return 0;
168                                 }
169
170                                 LhsVar(2) = Rhs + 2;
171                                 if (wcdiary_filenames)
172                                 {
173                                         freeArrayOfWideString(wcdiary_filenames, nb_diary_filenames);
174                                         nb_diary_filenames = 0;
175                                 }
176                         }
177                         else
178                         {
179                                 Scierror(999,_("%s: Memory allocation error.\n"),fname);
180                                 return 0;
181                         }
182                 }
183         }
184
185         PutLhsVar();
186
187         return 0;
188 }
189 /*--------------------------------------------------------------------------*/
190 static int sci_diary_one_rhs(char *fname)
191 {
192         SciErr sciErr;
193         int iType       = 0;
194         int *piAddressVarOne = NULL;
195
196         sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
197         if(sciErr.iErr)
198         {
199                         printError(&sciErr, 0);
200                         return 0;
201         }
202
203         sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
204         if(sciErr.iErr)
205         {
206                         printError(&sciErr, 0);
207                         return 0;
208         }
209
210         if (iType == sci_matrix)
211         {
212                 int IDs_size = 0;
213                 int ierr = 0;
214                 double * IDs = getInputArgumentOneIDs(fname, &IDs_size, &ierr);
215                 if (ierr) return 0;
216
217                 // diary([])
218                 // diary(0)
219                 // close all
220                 if ( (IDs_size == 0) ||
221                          ((IDs_size == 1) && ((int)IDs[0] == 0)))
222                 {
223                         diaryCloseAll();
224                         PutLhsVar();
225                 }
226                 else
227                 {
228                         Scierror(999,_("%s: Wrong value for input argument #%d: 0 expected.\n"),fname,1);
229                 }
230         }
231         else if (iType == sci_strings)
232         {
233                 int ierr = 0;
234                 int sizewcFilenames = 0;
235                 wchar_t ** wcFilenames = getInputArgumentOneFilenames(fname,&sizewcFilenames,&ierr);
236                 if (ierr) return 0;
237
238                 if (sizewcFilenames == 1)
239                 {
240                         if (diaryExists(wcFilenames[0]))
241                         {
242                                 double dID = (double)diaryNew(wcFilenames[0], false);
243                                 if (dID == -1)
244                                 {
245                                         char *utf_str = wide_string_to_UTF8(wcFilenames[0]);
246                                         if (utf_str)
247                                         {
248                                                 Scierror(999,_("%s: error can not create diary: %s.\n"), fname, utf_str);
249                                                 FREE(utf_str); utf_str = NULL;
250                                         }
251                                         else
252                                         {
253                                                 Scierror(999,_("%s: error can not create diary.\n"),fname);
254                                         }
255                                         return 0;
256                                 }
257
258                                 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, 1, 1, &dID);
259                                 if(sciErr.iErr)
260                                 {
261                                                 printError(&sciErr, 0);
262                                                 return 0;
263                                 }
264
265                                 LhsVar(1) = Rhs + 1;
266
267                                 if (Lhs == 2)
268                                 {
269                                         wchar_t **wfilenameUsed = new wchar_t*[1];
270                                         wfilenameUsed[0] = getDiaryFilename((int)dID);
271                                         sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 2, 1, 1, wfilenameUsed);
272                                         if(sciErr.iErr)
273                                         {
274                                                         printError(&sciErr, 0);
275                                                         return 0;
276                                         }
277
278                                         LhsVar(2) = Rhs + 2;
279                                         FREE(wfilenameUsed[0]);
280                                         delete [] wfilenameUsed;
281                                 }
282                         }
283                         else // diary(filename) exists (close diary)
284                         {
285                                 if (diaryClose(wcFilenames[0]))
286                                 {
287                                         if (wcFilenames)
288                                         {
289                                                 freeArrayOfWideString(wcFilenames, 1);
290                                                 Scierror(999,_("%s: error can not close diary.\n"),fname);
291                                                 return 0;
292                                         }
293                                 }
294                                 LhsVar(1) = 0; 
295                         }
296
297                         freeArrayOfWideString(wcFilenames,sizewcFilenames);
298                         PutLhsVar();
299                 }
300                 else
301                 {
302                         freeArrayOfWideString(wcFilenames,sizewcFilenames);
303                         Scierror(999,_("%s: Wrong size for input argument #%d.\n"),fname, 1);
304                 }
305         }
306         else
307         {
308                 Scierror(999,_("%s: Wrong type for input argument #%d.\n"),fname, 1);
309         }
310         return 0;
311 }
312 /*--------------------------------------------------------------------------*/
313 static int sci_diary_two_rhs(char *fname)
314 {
315         int ierr = 0;
316         wchar_t *wcArgumentTwo = getInputArgumentTwo(fname, &ierr);
317         SciErr sciErr;
318         int *piAddressVarOne = NULL;
319
320         sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
321         if(sciErr.iErr)
322         {
323                         printError(&sciErr, 0);
324                         return 0;
325         }
326
327         if (ierr) return 0;
328
329         if (wcArgumentTwo)
330         {
331                 if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_LIST) == 0)
332                 {
333                         int m1 = 0, n1 = 0;
334                         sciErr = getVarDimension(pvApiCtx, piAddressVarOne,&m1,&n1);
335                         if(sciErr.iErr)
336                         {
337                                 printError(&sciErr, 0);
338                                 return 0;
339                         }
340
341                         if ( (m1 == n1) && (n1 == 0) )
342                         {
343                                 // diary() == diary([], "list")
344                                 return sci_diary_no_rhs(fname);
345                         }
346                         else
347                         {
348                                 Scierror(999,_("%s: Wrong value for input argument #%d.\n"),fname, 2);
349                         }
350                 }
351                 else if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_CLOSE) == 0)
352                 {
353                         int iType = 0;
354                         sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
355                         if(sciErr.iErr)
356                         {
357                                 printError(&sciErr, 0);
358                                 return 0;
359                         }
360
361                         if(iType == sci_matrix)
362                         {
363                                 return CloseByIds(fname);
364                         }
365                         else if (iType == sci_strings)
366                         {
367                                 return CloseByFilenames(fname);
368                         }
369                         else
370                         {
371                                 Scierror(999,_("%s: Wrong type for input argument #%d.\n"),fname, 1);
372                                 return 0;
373                         }
374                 }
375                 else if ( (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_PAUSE) == 0) ||
376                                   (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_OFF) == 0) )
377                 {
378                         int iType = 0;
379                         sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
380                         if(sciErr.iErr)
381                         {
382                                 printError(&sciErr, 0);
383                                 return 0;
384                         }
385
386                         if (iType == sci_matrix)
387                         {
388                                 return PauseByIds(fname);
389                         }
390                         else if(iType == sci_strings)
391                         {
392                                 return PauseByFilenames(fname);
393                         }
394                         else
395                         {
396                                 Scierror(999,_("%s: Wrong type for input argument #%d.\n"),fname, 1);
397                                 return 0;
398                         }
399                 }
400                 else if ( (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_RESUME) == 0) ||
401                                   (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_ON) == 0) )
402                 {
403                         int iType = 0;
404                         sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
405                         if(sciErr.iErr)
406                         {
407                                 printError(&sciErr, 0);
408                                 return 0;
409                         }
410
411                         if (iType == sci_matrix)
412                         {
413                                 return ResumeByIds(fname);
414                         }
415                         else if (iType == sci_strings)
416                         {
417                                 return ResumeByFilenames(fname);
418                         }
419                         else
420                         {
421                                 Scierror(999,_("%s: Wrong type for input argument #%d.\n"),fname, 1);
422                                 return 0;
423                         }
424                 }
425                 else if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_NEW) == 0)
426                 {
427                         int iType = 0;
428                         sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
429                         if(sciErr.iErr)
430                         {
431                                 printError(&sciErr, 0);
432                                 return 0;
433                         }
434
435                         if (iType == sci_strings)
436                         {
437                                 return NewByFilenames(fname, DIARY_FILTER_INPUT_AND_OUTPUT, 
438                                         PREFIX_TIME_FORMAT_UNIX_EPOCH, 
439                                         PREFIX_FILTER_NONE, false);
440                         }
441                         else
442                         {
443                                 Scierror(999,_("%s: Wrong type for input argument #%d.\n"),fname, 1);
444                                 return 0;
445                         }
446                 }
447                 else if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_APPEND) == 0)
448                 {
449                         int iType = 0;
450                         sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
451                         if(sciErr.iErr)
452                         {
453                                 printError(&sciErr, 0);
454                                 return 0;
455                         }
456
457                         if (iType == sci_strings)
458                         {
459                                 return AppendByFilenames(fname, DIARY_FILTER_INPUT_AND_OUTPUT, 
460                                         PREFIX_TIME_FORMAT_UNIX_EPOCH, 
461                                         PREFIX_FILTER_NONE, false);
462                         }
463                         else
464                         {
465                                 Scierror(999,_("%s: Wrong type for input argument #%d.\n"),fname, 1);
466                                 return 0;
467                         }
468                 }
469                 else if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_EXISTS) == 0)
470                 {
471                         int iType = 0;
472                         sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
473                         if(sciErr.iErr)
474                         {
475                                 printError(&sciErr, 0);
476                                 return 0;
477                         }
478
479                         if (iType == sci_matrix)
480                         {
481                                 return ExistByIds(fname);
482                         }
483                         else if (iType == sci_strings)
484                         {
485                                 return ExistByFilenames(fname);
486                         }
487                         else
488                         {
489                                 Scierror(999,_("%s: Wrong type for input argument #%d.\n"),fname, 1);
490                                 return 0;
491                         }
492                 }
493                 else
494                 {
495                         Scierror(999,_("%s: Wrong value for input argument #%d.\n"),fname, 2);
496                         return 0;
497                 }
498         }
499         else
500         {
501                 Scierror(999,_("%s: Wrong value for input argument #%d.\n"),fname, 2);
502         }
503         
504         return 0;
505 }
506 /*--------------------------------------------------------------------------*/
507 static int sci_diary_three_rhs(char *fname)
508 {
509         int ierr = 0;
510         int size_ArgThree = 0;
511         wchar_t **wcArgumentThree = getInputArgumentThree(fname, &size_ArgThree, &ierr);
512         if (ierr) return 0;
513
514         if (wcArgumentThree)
515         {
516                 diary_filter filterMode = DIARY_FILTER_INPUT_AND_OUTPUT;
517                 diary_prefix_time_format iPrefixMode = PREFIX_TIME_FORMAT_UNIX_EPOCH;
518                 diary_prefix_time_filter iPrefixIoModeFilter = PREFIX_FILTER_NONE;
519                 bool suspendedDiary = false;
520
521                 for (int i = 0; i < size_ArgThree; i++)
522                 {
523                         if (wcscmp(wcArgumentThree[i], DIARY_THIRD_ARG_FILTER_COMMAND) == 0)
524                         {
525                                 filterMode = DIARY_FILTER_ONLY_INPUT; // input only
526                         }
527                         else if (wcscmp(wcArgumentThree[i], DIARY_THIRD_ARG_FILTER_OUTPUT) == 0)
528                         {
529                                 filterMode = DIARY_FILTER_ONLY_OUTPUT; // output only
530                         }
531                         else if (wcscmp(wcArgumentThree[i], DIARY_THIRD_ARG_PREFIX_UNIX_EPOCH) == 0)
532                         {
533                                 iPrefixMode = PREFIX_TIME_FORMAT_UNIX_EPOCH;
534                                 if (iPrefixIoModeFilter == PREFIX_FILTER_NONE) iPrefixIoModeFilter = PREFIX_FILTER_INPUT_AND_OUTPUT;
535                         }
536                         else if (wcscmp(wcArgumentThree[i], DIARY_THIRD_ARG_PREFIX_DEFAULT) == 0)
537                         {
538                                 iPrefixMode = PREFIX_TIME_FORMAT_ISO_8601;
539                                 if (iPrefixIoModeFilter == PREFIX_FILTER_NONE) iPrefixIoModeFilter = PREFIX_FILTER_INPUT_AND_OUTPUT;
540                         }
541                         else if (wcscmp(wcArgumentThree[i], DIARY_THIRD_ARG_PREFIX_ONLY_COMMANDS) == 0)
542                         {
543                                 iPrefixIoModeFilter = PREFIX_FILTER_ONLY_INPUT;
544                         }
545                         else if ( (wcscmp(wcArgumentThree[i], DIARY_SECOND_ARG_ON) == 0) || (wcscmp(wcArgumentThree[i], DIARY_SECOND_ARG_RESUME) == 0) )
546                         {
547                                 suspendedDiary = false;
548                         }
549                         else if ( (wcscmp(wcArgumentThree[i], DIARY_SECOND_ARG_OFF) == 0) || (wcscmp(wcArgumentThree[i], DIARY_SECOND_ARG_PAUSE) == 0) )
550                         {
551                                 suspendedDiary = true;
552                         }
553                         else
554                         {
555                                 freeArrayOfWideString(wcArgumentThree, size_ArgThree);
556                                 Scierror(999,_("%s: Wrong value for input argument #%d.\n"),fname, 3);
557                                 return 0;
558                         }                       
559                 }
560                 freeArrayOfWideString(wcArgumentThree, size_ArgThree);
561
562                 wchar_t *wcArgumentTwo = getInputArgumentTwo(fname, &ierr);
563                 if (ierr) return 0;
564                 if (wcArgumentTwo)
565                 {
566                         int *piAddressVarOne = NULL;
567                         SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
568                         if(sciErr.iErr)
569                         {
570                                 printError(&sciErr, 0);
571                                 return 0;
572                         }
573
574                         if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_NEW) == 0)
575                         {
576                                 int iType = 0;
577                                 sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
578                                 if(sciErr.iErr)
579                                 {
580                                         printError(&sciErr, 0);
581                                         return 0;
582                                 }
583
584                                 FREE(wcArgumentTwo); wcArgumentTwo = NULL;
585                                 if (iType == sci_strings)
586                                 {
587                                         return NewByFilenames(fname, filterMode, iPrefixMode, iPrefixIoModeFilter, suspendedDiary);
588                                 }
589                                 else
590                                 {
591                                         Scierror(999,_("%s: Wrong type for input argument #%d.\n"),fname, 1);
592                                         return 0;
593                                 }
594                         }
595                         else if (wcscmp(wcArgumentTwo, DIARY_SECOND_ARG_APPEND) == 0)
596                         {
597                                 int iType = 0;
598                                 sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
599                                 if(sciErr.iErr)
600                                 {
601                                         printError(&sciErr, 0);
602                                         return 0;
603                                 }
604
605                                 FREE(wcArgumentTwo); wcArgumentTwo = NULL;
606                                 if (iType == sci_strings)
607                                 {
608                                         return AppendByFilenames(fname, filterMode, iPrefixMode, iPrefixIoModeFilter, suspendedDiary);
609                                 }
610                                 else
611                                 {
612                                         Scierror(999,_("%s: Wrong type for input argument #%d.\n"),fname, 1);
613                                         return 0;
614                                 }
615                         }
616                         else
617                         {
618                                 FREE(wcArgumentTwo); wcArgumentTwo = NULL;
619                                 Scierror(999,_("%s: Wrong value for input argument #%d.\n"),fname, 2);
620                                 return 0;
621                         }
622                 }
623                 else
624                 {
625                         Scierror(999,_("%s: Memory allocation error.\n"),fname);
626                 }
627         }
628         else
629         {
630                 Scierror(999,_("%s: Memory allocation error.\n"),fname);
631         }
632         return 0;
633 }
634 /*--------------------------------------------------------------------------*/
635 static double *getInputArgumentOneIDs(char *fname,int *sizeReturnedArray, int *ierror)
636 {
637         double *IDs = NULL;
638         *sizeReturnedArray = 0;
639         *ierror = 0;
640
641         int m1 = 0, n1 = 0;
642         int *piAddressVarOne = NULL;
643
644         SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
645         if(sciErr.iErr)
646         {
647                 printError(&sciErr, 0);
648                 return 0;
649         }
650
651         int iType = 0;
652         sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
653         if(sciErr.iErr)
654         {
655                 printError(&sciErr, 0);
656                 return 0;
657         }
658
659         if (iType == sci_matrix)
660         {
661                 sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarOne,&m1,&n1,&IDs);
662                 if(sciErr.iErr)
663                 {
664                         printError(&sciErr, 0);
665                         return 0;
666                 }
667
668                 if ( (m1 == 1) || (n1 == 1) )
669                 {
670                         *sizeReturnedArray = m1 * n1;
671                 }
672                 else if ( (m1 == 0) || (n1 == 0) )
673                 {
674                         *sizeReturnedArray = 0;
675                         *ierror = 2;
676                         return NULL;
677                 }
678                 else
679                 {
680                         Scierror(999,_("%s: Wrong size for input argument #%d: A vector expected.\n"),fname,1);
681                         *ierror = 1;
682                 }
683         }
684         else
685         {
686                 Scierror(999,_("%s: Wrong type for input argument #%d: A scalar expected.\n"),fname,1);
687                 *ierror = 1;
688         }
689
690         return IDs;
691 }
692 /*--------------------------------------------------------------------------*/
693 static wchar_t **getInputArgumentOneFilenames(char *fname,int *sizeReturnedArray, int *ierror)
694 {
695         wchar_t** wcFilenames = NULL;
696         *sizeReturnedArray = 0;
697         *ierror = 0;
698
699         int m1 = 0, n1 = 0;
700         int *piAddressVarOne = NULL;
701
702         SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
703         if(sciErr.iErr)
704         {
705                 printError(&sciErr, 0);
706                 return 0;
707         }
708
709         int iType = 0;
710         sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
711         if(sciErr.iErr)
712         {
713                 printError(&sciErr, 0);
714                 return 0;
715         }
716
717         if (iType == sci_strings)
718         {
719                 int *lenStVarOne = NULL;
720
721                 sciErr = getVarDimension(pvApiCtx, piAddressVarOne,&m1,&n1);
722                 if(sciErr.iErr)
723                 {
724                         printError(&sciErr, 0);
725                         return 0;
726                 }
727
728                 if (m1*n1 < 1)
729                 {
730                         Scierror(999,_("%s: Wrong size for input argument #%d.\n"),fname,1);
731                         *ierror = 1;
732                 }
733                 else if ( (m1 == 1) || (n1 == 1) )
734                 {
735                         lenStVarOne = (int *)MALLOC(sizeof(int) * (m1 * n1));
736                         if (lenStVarOne == NULL)
737                         {
738                                 Scierror(999,_("%s: Memory allocation error.\n"),fname);
739                                 *ierror = 1;
740                         }
741                         else
742                         {
743                                 sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, NULL);
744                                 if(sciErr.iErr)
745                                 {
746                                         printError(&sciErr, 0);
747                                         return 0;
748                                 }
749
750                                 wcFilenames = (wchar_t **)MALLOC(sizeof(wchar_t *) * (m1 * n1));
751                                 if (wcFilenames == NULL)
752                                 {
753                                         Scierror(999,_("%s: Memory allocation error.\n"),fname);
754                                         *ierror = 1;
755                                 }
756                                 else
757                                 {
758                                         for (int i = 0; i < m1 * n1;i++)
759                                         {
760                                                 wcFilenames[i] = (wchar_t*)MALLOC(sizeof(wchar_t)* (lenStVarOne[i] + 1));
761                                                 if (wcFilenames[i] == NULL)
762                                                 {
763                                                         Scierror(999,_("%s: Memory allocation error.\n"),fname);
764                                                         *ierror = 1;
765                                                 }
766                                         }
767
768                                         sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, wcFilenames);
769                                         if(sciErr.iErr)
770                                         {
771                                                 printError(&sciErr, 0);
772                                                 return 0;
773                                         }
774
775                                         *sizeReturnedArray = m1 * n1;
776                                 }
777                         }
778                 }
779                 else
780                 {
781                         Scierror(999,_("%s: Wrong size for input argument #%d: A vector expected.\n"),fname,1);
782                         *ierror = 1;
783                 }
784         }
785         else
786         {
787                 Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,1);
788                 *ierror = 1;
789         }
790         return wcFilenames;
791 }
792 /*--------------------------------------------------------------------------*/
793 static wchar_t *getInputArgumentTwo(char *fname, int *ierror)
794 {
795         wchar_t *wcInputArgumentTwo = NULL;
796         *ierror = 0;
797
798         int m2 = 0, n2 = 0;
799         int *piAddressVarTwo = NULL;
800
801         SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo);
802         if(sciErr.iErr)
803         {
804                 printError(&sciErr, 0);
805                 return 0;
806         }
807
808         int iType = 0;
809         sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType);
810         if(sciErr.iErr)
811         {
812                 printError(&sciErr, 0);
813                 return 0;
814         }
815
816         if (iType == sci_strings)
817         {
818                 int lenStVarTwo = 0;
819
820                 sciErr = getVarDimension(pvApiCtx, piAddressVarTwo,&m2,&n2);
821                 if(sciErr.iErr)
822                 {
823                         printError(&sciErr, 0);
824                         return 0;
825                 }
826
827                 if ( (m2 != n2) && (n2 != 1) ) 
828                 {
829                         Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"),fname,2);
830                         *ierror = 1;
831                 }
832                 else
833                 {
834                         // get length lenStVarTwo
835                         sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarTwo,&m2,&n2,&lenStVarTwo, NULL);
836                         if(sciErr.iErr)
837                         {
838                                 printError(&sciErr, 0);
839                                 return 0;
840                         }
841
842                         wcInputArgumentTwo = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarTwo + 1));
843
844                         if (wcInputArgumentTwo == NULL)
845                         {
846                                 Scierror(999,_("%s: Memory allocation error.\n"),fname);
847                                 *ierror = 1;
848                         }
849
850                         sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarTwo,&m2,&n2,&lenStVarTwo,&wcInputArgumentTwo);
851                         if(sciErr.iErr)
852                         {
853                                 printError(&sciErr, 0);
854                                 return 0;
855                         }
856                 }
857         }
858         else
859         {
860                 Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,2);
861                 *ierror = 1;
862         }
863         return wcInputArgumentTwo;
864 }
865 /*--------------------------------------------------------------------------*/
866 static wchar_t** getInputArgumentThree(char *fname,int *sizeReturnedArray, int *ierror)
867 {
868         wchar_t** wcInputArgumentThree = NULL;
869         *sizeReturnedArray = 0;
870         *ierror = 0;
871
872         int m3 = 0, n3 = 0;
873         int *piAddressVarThree = NULL;
874
875         SciErr sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree);
876         if(sciErr.iErr)
877         {
878                 printError(&sciErr, 0);
879                 return 0;
880         }
881
882         int iType = 0;
883         sciErr = getVarType(pvApiCtx, piAddressVarThree, &iType);
884         if(sciErr.iErr)
885         {
886                 printError(&sciErr, 0);
887                 return 0;
888         }
889
890         if (iType == sci_strings)
891         {
892                 int *lenStVarThree = NULL;
893
894                 sciErr = getVarDimension(pvApiCtx, piAddressVarThree,&m3,&n3);
895                 if(sciErr.iErr)
896                 {
897                         printError(&sciErr, 0);
898                         return 0;
899                 }
900
901                 if (m3*n3 < 1)
902                 {
903                         Scierror(999,_("%s: Wrong size for input argument #%d.\n"),fname,3);
904                         *ierror = 1;
905                 }
906                 else if ( (m3 == 1) || (n3 == 1) )
907                 {
908                         lenStVarThree = (int *)MALLOC(sizeof(int) * (m3 * n3));
909                         if (lenStVarThree == NULL)
910                         {
911                                 Scierror(999,_("%s: Memory allocation error.\n"),fname);
912                                 *ierror = 1;
913                         }
914                         else
915                         {
916                                 sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarThree, &m3, &n3, lenStVarThree, NULL);
917                                 if(sciErr.iErr)
918                                 {
919                                         printError(&sciErr, 0);
920                                         return 0;
921                                 }
922
923                                 wcInputArgumentThree = (wchar_t **)MALLOC(sizeof(wchar_t *) * (m3 * n3));
924                                 if (wcInputArgumentThree == NULL)
925                                 {
926                                         Scierror(999,_("%s: Memory allocation error.\n"),fname);
927                                         *ierror = 1;
928                                 }
929                                 else
930                                 {
931                                         for (int i = 0; i < m3 * n3; i++)
932                                         {
933                                                 wcInputArgumentThree[i] = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarThree[i] + 1));
934                                         }
935
936                                         sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarThree, &m3, &n3, lenStVarThree, wcInputArgumentThree);
937                                         if(sciErr.iErr)
938                                         {
939                                                 printError(&sciErr, 0);
940                                                 return 0;
941                                         }
942
943                                         *sizeReturnedArray = m3 * n3;
944                                 }
945                         }
946                 }
947                 else
948                 {
949                         Scierror(999,_("%s: Wrong size for input argument #%d: A vector expected.\n"),fname,3);
950                         *ierror = 1;
951                 }
952         }
953         else
954         {
955                 Scierror(999,_("%s: Wrong type for input argument #%d: A string expected.\n"),fname,3);
956                 *ierror = 1;
957         }
958         return wcInputArgumentThree;
959 }
960 /*--------------------------------------------------------------------------*/
961 static int checkExistByIDs(char *fname, double *IDs, int size_IDs)
962 {
963         if (IDs)
964         {
965                 for (int i = 0; i < size_IDs; i++)
966                 {
967                         if (diaryExists((int)IDs[i]))
968                         {
969                                 Scierror(999,_("%s: Wrong value for input argument #%d: diary ID %d not exists.\n"),fname,1, (int)IDs[i]);
970                                 return 1;
971                         }
972                 }
973                 return 0;
974         }
975         return 1;
976 }
977 /*--------------------------------------------------------------------------*/
978 static int checkExistByFilenames(char *fname, wchar_t **wcFilenames, int size_IDs)
979 {
980         if (wcFilenames)
981         {
982                 for (int i = 0; i < size_IDs; i++)
983                 {
984                         if (diaryExists(wcFilenames[i]))
985                         {
986                                 Scierror(999,_("%s: Wrong value for input argument #%d: diary filename not exists.\n"),fname,1);
987                                 return 1;
988                         }
989                 }
990                 return 0;
991         }
992         return 1;
993 }
994 /*--------------------------------------------------------------------------*/
995 static int CloseByFilenames(char *fname)
996 {
997         wchar_t **wcFilenames = NULL;
998         int dIDs_size = 0;
999         int ierr = 0;
1000
1001         wcFilenames = getInputArgumentOneFilenames(fname, &dIDs_size, &ierr);
1002         if (ierr) return 0;
1003
1004         ierr = checkExistByFilenames(fname, wcFilenames, dIDs_size);
1005         if (ierr) 
1006         {
1007                 freeArrayOfWideString(wcFilenames, dIDs_size);
1008                 return 0;
1009         }
1010
1011         for (int i = 0; i < dIDs_size; i++)
1012         {
1013                 if (diaryClose(wcFilenames[i]))
1014                 {
1015                         freeArrayOfWideString(wcFilenames, dIDs_size);
1016                         Scierror(999,_("%s: Wrong value for input argument #%d: error can not close diary.\n"),fname);
1017                         return 0;
1018                 }
1019         }
1020
1021         freeArrayOfWideString(wcFilenames, dIDs_size);
1022         PutLhsVar();
1023         return 0;
1024 }
1025 /*--------------------------------------------------------------------------*/
1026 static int CloseByIds(char *fname)
1027 {
1028         double *dIDs = NULL;
1029         int dIDs_size = 0;
1030         int ierr = 0;
1031
1032         dIDs = getInputArgumentOneIDs(fname, &dIDs_size, &ierr);
1033
1034         if (ierr == 2)
1035         {
1036                 // diary([], 'close')
1037                 diaryCloseAll();
1038                 PutLhsVar();
1039                 return 0;
1040         }
1041         else if (ierr) return 0;
1042
1043         ierr = checkExistByIDs(fname, dIDs, dIDs_size);
1044         if (ierr) return 0;
1045
1046         for (int i = 0; i < dIDs_size; i++)
1047         {
1048                 if (diaryClose((int)dIDs[i]))
1049                 {
1050                         Scierror(999,_("%s: Wrong value for input argument #%d: error can not close diary %d.\n"),fname, (int)dIDs[i]);
1051                         return 0;
1052                 }
1053         }
1054         PutLhsVar();
1055         return 0;
1056 }
1057 /*--------------------------------------------------------------------------*/
1058 static int PauseByFilenames(char *fname)
1059 {
1060         wchar_t **wcFilenames = NULL;
1061         int dIDs_size = 0;
1062         int ierr = 0;
1063
1064         wcFilenames = getInputArgumentOneFilenames(fname, &dIDs_size, &ierr);
1065         if (ierr) return 0;
1066
1067         ierr = checkExistByFilenames(fname, wcFilenames, dIDs_size);
1068         if (ierr) 
1069         {
1070                 freeArrayOfWideString(wcFilenames, dIDs_size);
1071                 return 0;
1072         }
1073
1074         for (int i = 0; i < dIDs_size; i++)
1075         {
1076                 if (diaryPause(wcFilenames[i]))
1077                 {
1078                         freeArrayOfWideString(wcFilenames, dIDs_size);
1079                         Scierror(999,_("%s: Wrong value for input argument #%d: error can not pause diary.\n"),fname);
1080                         return 0;
1081                 }
1082         }
1083
1084         freeArrayOfWideString(wcFilenames, dIDs_size);
1085
1086         PutLhsVar();
1087         return 0;
1088 }
1089 /*--------------------------------------------------------------------------*/
1090 static int PauseByIds(char *fname)
1091 {
1092         double *dIDs = NULL;
1093         int dIDs_size = 0;
1094         int ierr = 0;
1095
1096         dIDs = getInputArgumentOneIDs(fname, &dIDs_size, &ierr);
1097         if (ierr) return 0;
1098
1099         ierr = checkExistByIDs(fname, dIDs, dIDs_size);
1100         if (ierr) return 0;
1101
1102         for (int i = 0; i < dIDs_size; i++)
1103         {
1104                 if (diaryPause((int)dIDs[i]))
1105                 {
1106                         Scierror(999,_("%s: Wrong value for input argument #%d: error can not pause diary %d.\n"),fname, (int)dIDs[i]);
1107                         return 0;
1108                 }
1109         }
1110
1111         PutLhsVar();
1112
1113         return 0;
1114 }
1115 /*--------------------------------------------------------------------------*/
1116 static int ResumeByFilenames(char *fname)
1117 {
1118         wchar_t **wcFilenames = NULL;
1119         int dIDs_size = 0;
1120         int ierr = 0;
1121         wcFilenames = getInputArgumentOneFilenames(fname, &dIDs_size, &ierr);
1122         if (ierr) return 0;
1123
1124         ierr = checkExistByFilenames(fname, wcFilenames, dIDs_size);
1125         if (ierr) 
1126         {
1127                 freeArrayOfWideString(wcFilenames, dIDs_size);
1128                 return 0;
1129         }
1130
1131         for (int i = 0; i < dIDs_size; i++)
1132         {
1133                 if (diaryResume(wcFilenames[i]))
1134                 {
1135                         freeArrayOfWideString(wcFilenames, dIDs_size);
1136                         Scierror(999,_("%s: Wrong value for input argument #%d: error can not resume diary.\n"),fname);
1137                         return 0;
1138                 }
1139         }
1140
1141         freeArrayOfWideString(wcFilenames, dIDs_size);
1142
1143         PutLhsVar();
1144
1145         return 0;
1146 }
1147 /*--------------------------------------------------------------------------*/
1148 static int ResumeByIds(char *fname)
1149 {
1150         double *dIDs = NULL;
1151         int dIDs_size = 0;
1152         int ierr = 0;
1153
1154         dIDs = getInputArgumentOneIDs(fname, &dIDs_size, &ierr);
1155         if (ierr) return 0;
1156
1157         ierr = checkExistByIDs(fname, dIDs, dIDs_size);
1158         if (ierr) return 0;
1159
1160         for (int i = 0; i < dIDs_size; i++)
1161         {
1162                 if (diaryResume((int)dIDs[i]))
1163                 {
1164                         Scierror(999,_("%s: Wrong value for input argument #%d: error can not resume diary %d.\n"),fname, (int)dIDs[i]);
1165                         return 0;
1166                 }
1167         }
1168
1169         PutLhsVar();
1170
1171         return 0;
1172 }
1173 /*--------------------------------------------------------------------------*/
1174 static int ExistByFilenames(char *fname)
1175 {
1176         wchar_t **wcFilenames = NULL;
1177         int dIDs_size = 0;
1178         int ierr = 0;
1179         wcFilenames = getInputArgumentOneFilenames(fname, &dIDs_size, &ierr);
1180         if (ierr) return 0;
1181
1182         int *resultExist = (int*)MALLOC(sizeof(int)*dIDs_size);
1183         if (resultExist == NULL)
1184         {
1185                 freeArrayOfWideString(wcFilenames,dIDs_size);
1186                 Scierror(999,_("%s: Memory allocation error.\n"),fname);
1187                 return 0;
1188         }
1189         
1190         for(int i=0; i < dIDs_size; i++)
1191         {
1192                 int bExists = diaryExists(wcFilenames[i]);
1193                 if ( bExists == 0)
1194                 {
1195                         resultExist[i]  = TRUE;
1196                 }
1197                 else
1198                 {
1199                         resultExist[i]  = FALSE;
1200                 }
1201         }
1202         freeArrayOfWideString(wcFilenames,dIDs_size);
1203
1204         SciErr sciErr = createMatrixOfBoolean(pvApiCtx, Rhs + 1, 1, dIDs_size, resultExist);
1205         if(sciErr.iErr)
1206         {
1207                 printError(&sciErr, 0);
1208                 return 0;
1209         }
1210
1211         FREE(resultExist); resultExist = NULL;
1212         LhsVar(1) = Rhs + 1;
1213         PutLhsVar();
1214         return 0;
1215 }
1216 /*--------------------------------------------------------------------------*/
1217 static int ExistByIds(char *fname)
1218 {
1219         double *dIDs = NULL;
1220         int dIDs_size = 0;
1221         int ierr = 0;
1222
1223         dIDs = getInputArgumentOneIDs(fname, &dIDs_size, &ierr);
1224         if (ierr) return 0;
1225
1226         int *resultExist = (int*)MALLOC(sizeof(int)*dIDs_size);
1227         if (resultExist == NULL)
1228         {
1229                 Scierror(999,_("%s: Memory allocation error.\n"),fname);
1230                 return 0;
1231         }
1232
1233         for(int i=0; i < dIDs_size; i++)
1234         {
1235                 int bExists = diaryExists((int)dIDs[i]);
1236                 if ( bExists == 0)
1237                 {
1238                         resultExist[i]  = TRUE;
1239                 }
1240                 else
1241                 {
1242                         resultExist[i]  = FALSE;
1243                 }
1244         }
1245
1246         SciErr sciErr = createMatrixOfBoolean(pvApiCtx, Rhs + 1, 1, dIDs_size, resultExist);
1247         if(sciErr.iErr)
1248         {
1249                 printError(&sciErr, 0);
1250                 return 0;
1251         }
1252
1253         FREE(resultExist); resultExist = NULL;
1254         LhsVar(1) = Rhs + 1;
1255         PutLhsVar();
1256         return 0;
1257 }
1258 /*--------------------------------------------------------------------------*/
1259 static int AppendByFilenames(char *fname, 
1260                                                          diary_filter filterMode, 
1261                                                          diary_prefix_time_format prefixMode, 
1262                                                          diary_prefix_time_filter prefixModeFilter,
1263                                                          bool suspended)
1264 {
1265         SciErr sciErr;
1266         wchar_t **wcFilenames = NULL;
1267         int dIDs_size = 0;
1268         int ierr = 0;
1269
1270         wcFilenames = getInputArgumentOneFilenames(fname, &dIDs_size, &ierr);
1271         if (ierr) return 0;
1272
1273         if (dIDs_size == 1)
1274         {
1275                 double dID = (double)diaryAppend(wcFilenames[0]);
1276                 if (dID == -1)
1277                 {
1278                         char *utf_str = wide_string_to_UTF8(wcFilenames[0]);
1279                         if (utf_str)
1280                         {
1281                                 Scierror(999,_("%s: error can not create diary: %s.\n"), fname, utf_str);
1282                                 FREE(utf_str); utf_str = NULL;
1283                         }
1284                         else
1285                         {
1286                                 Scierror(999,_("%s: error can not create diary.\n"),fname);
1287                         }
1288                         freeArrayOfWideString(wcFilenames, dIDs_size);
1289                         return 0;
1290                 }
1291
1292                 freeArrayOfWideString(wcFilenames, dIDs_size);
1293
1294                 diarySetFilterMode((int)dID, filterMode);
1295                 diarySetPrefixMode((int)dID, prefixMode);
1296                 diarySetPrefixIoModeFilter((int)dID, prefixModeFilter);
1297                 if (suspended) diaryPause((int)dID);
1298
1299                 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, 1, 1, &dID);
1300                 if(sciErr.iErr)
1301                 {
1302                         printError(&sciErr, 0);
1303                         return 0;
1304                 }
1305
1306                 LhsVar(1) = Rhs + 1;
1307
1308                 if (Lhs == 2)
1309                 {
1310                         wchar_t **wfilenameUsed = new wchar_t*[1];
1311                         wfilenameUsed[0] = getDiaryFilename((int)dID);
1312                         sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 2, 1, 1, wfilenameUsed);
1313                         if(sciErr.iErr)
1314                         {
1315                                 printError(&sciErr, 0);
1316                                 return 0;
1317                         }
1318
1319                         LhsVar(2) = Rhs + 2;
1320                         freeArrayOfWideString(wfilenameUsed, 1);
1321                 }
1322                 PutLhsVar();
1323         }
1324         else
1325         {
1326                 freeArrayOfWideString(wcFilenames, dIDs_size);
1327                 Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"),fname,1);
1328         }
1329
1330         return 0;
1331 }
1332 /*--------------------------------------------------------------------------*/
1333 static int NewByFilenames(char *fname,
1334                                                   diary_filter filterMode, 
1335                                                   diary_prefix_time_format prefixMode, 
1336                                                   diary_prefix_time_filter prefixModeFilter, 
1337                                                   bool suspended)
1338 {
1339         wchar_t **wcFilenames = NULL;
1340         int dIDs_size = 0;
1341         int ierr = 0;
1342
1343         wcFilenames = getInputArgumentOneFilenames(fname, &dIDs_size, &ierr);
1344         if (ierr) return 0;
1345
1346         if (dIDs_size == 1)
1347         {
1348                 double dID = (double)diaryNew(wcFilenames[0], true);
1349                 if (dID == -1)
1350                 {
1351                         char *utf_str = wide_string_to_UTF8(wcFilenames[0]);
1352                         if (utf_str)
1353                         {
1354                                 Scierror(999,_("%s: error can not create diary: %s.\n"), fname, utf_str);
1355                                 FREE(utf_str); utf_str = NULL;
1356                         }
1357                         else
1358                         {
1359                                 Scierror(999,_("%s: error can not create diary.\n"),fname);
1360                         }
1361                         freeArrayOfWideString(wcFilenames, dIDs_size);
1362                         return 0;
1363                 }
1364
1365                 freeArrayOfWideString(wcFilenames, dIDs_size);
1366
1367                 diarySetFilterMode((int)dID, filterMode);
1368                 diarySetPrefixMode((int)dID, prefixMode);
1369                 diarySetPrefixIoModeFilter((int)dID, prefixModeFilter);
1370                 if (suspended) diaryPause((int)dID);
1371
1372                 SciErr sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, 1, 1, &dID);
1373                 LhsVar(1) = Rhs + 1;
1374
1375                 if (Lhs == 2)
1376                 {
1377                         wchar_t **wfilenameUsed = new wchar_t*[1];
1378                         wfilenameUsed[0] = getDiaryFilename((int)dID);
1379                         sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 2, 1, 1, wfilenameUsed);
1380                         if(sciErr.iErr)
1381                         {
1382                                 printError(&sciErr, 0);
1383                                 return 0;
1384                         }
1385
1386                         LhsVar(2) = Rhs + 2;
1387                         FREE(wfilenameUsed[0]);
1388                         delete [] wfilenameUsed;
1389                 }
1390                 PutLhsVar();
1391         }
1392         else
1393         {
1394                 freeArrayOfWideString(wcFilenames, dIDs_size);
1395                 Scierror(999,_("%s: Wrong size for input argument #%d: A string expected.\n"),fname,1);
1396         }
1397
1398         return 0;
1399 }
1400 /*--------------------------------------------------------------------------*/