summaryrefslogtreecommitdiffstats
path: root/scilab/modules/io
diff options
context:
space:
mode:
authorAllan CORNET <allan.cornet@scilab.org>2010-01-27 15:03:22 +0100
committerAllan CORNET <allan.cornet@scilab.org>2010-01-27 15:03:22 +0100
commit6212d3c9baaff4a89c9fbbbf002393989a96a519 (patch)
treef2aebb83e480981b601d5f46ada57408af5e85b6 /scilab/modules/io
parentb647c4f12fc297552aad087b7b3caa585382248b (diff)
downloadscilab-6212d3c9baaff4a89c9fbbbf002393989a96a519.zip
scilab-6212d3c9baaff4a89c9fbbbf002393989a96a519.tar.gz
bug 6484
Diffstat (limited to 'scilab/modules/io')
-rw-r--r--scilab/modules/io/sci_gateway/c/sci_file.c335
-rw-r--r--scilab/modules/io/tests/unit_tests/file.dia.ref47
-rw-r--r--scilab/modules/io/tests/unit_tests/file.tst48
3 files changed, 429 insertions, 1 deletions
diff --git a/scilab/modules/io/sci_gateway/c/sci_file.c b/scilab/modules/io/sci_gateway/c/sci_file.c
index 99c8853..0c3b27a 100644
--- a/scilab/modules/io/sci_gateway/c/sci_file.c
+++ b/scilab/modules/io/sci_gateway/c/sci_file.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2006 - INRIA - Allan CORNET 3 * Copyright (C) 2006 - INRIA - Allan CORNET
4 * Copyright (C) 2009 - DIGITEO - Allan CORNET 4 * Copyright (C) 2009-2010 - DIGITEO - Allan CORNET
5 * 5 *
6 * This file must be used under the terms of the CeCILL. 6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which 7 * This source file is licensed as described in the file COPYING, which
@@ -12,6 +12,7 @@
12 */ 12 */
13 13
14/*--------------------------------------------------------------------------*/ 14/*--------------------------------------------------------------------------*/
15#include <string.h>
15#include "gw_io.h" 16#include "gw_io.h"
16#include "stack-c.h" 17#include "stack-c.h"
17#include "api_scilab.h" 18#include "api_scilab.h"
@@ -20,12 +21,30 @@
20#include "Scierror.h" 21#include "Scierror.h"
21#include "localization.h" 22#include "localization.h"
22#include "charEncoding.h" 23#include "charEncoding.h"
24#include "filesmanagement.h"
25#include "freeArrayOfString.h"
26#ifdef _MSC_VER
27#include "strdup_windows.h"
28#endif
23/*--------------------------------------------------------------------------*/ 29/*--------------------------------------------------------------------------*/
24#define FILE_OPEN_STR "open" 30#define FILE_OPEN_STR "open"
25#define FILE_OLD_STR "old" 31#define FILE_OLD_STR "old"
26/*--------------------------------------------------------------------------*/ 32/*--------------------------------------------------------------------------*/
33static int sci_file_no_rhs(char *fname);
34static int sci_file_one_rhs(char *fname);
35/*--------------------------------------------------------------------------*/
27int C2F(sci_file)(char *fname,unsigned long fname_len) 36int C2F(sci_file)(char *fname,unsigned long fname_len)
28{ 37{
38 if (Rhs == 0)
39 {
40 return sci_file_no_rhs(fname);
41 }
42
43 if (Rhs == 1)
44 {
45 return sci_file_one_rhs(fname);
46 }
47
29 if (Rhs >= 3) 48 if (Rhs >= 3)
30 { 49 {
31 SciErr sciErr; 50 SciErr sciErr;
@@ -270,3 +289,317 @@ int C2F(sci_file)(char *fname,unsigned long fname_len)
270 return 0; 289 return 0;
271} 290}
272/*--------------------------------------------------------------------------*/ 291/*--------------------------------------------------------------------------*/
292static int sci_file_no_rhs(char *fname)
293{
294 SciErr sciErr;
295 int m_out = 0, n_out = 0;
296
297 int sizeArray = 0;
298 int *IdUsed = NULL;
299
300 CheckLhs(0,5);
301
302 /* Lhs == 0 IDs*/
303 IdUsed = GetFilesIdUsed(&sizeArray);
304
305 if (IdUsed)
306 {
307 m_out = 1;
308 n_out = sizeArray;
309 sciErr = createMatrixOfInteger32(pvApiCtx, Rhs + 1, m_out, n_out, IdUsed);
310 FREE(IdUsed);
311 IdUsed = NULL;
312
313 if(sciErr.iErr)
314 {
315 printError(&sciErr, 0);
316 return 0;
317 }
318
319 LhsVar(1) = Rhs + 1;
320 }
321
322 if (Lhs > 1) /* Types */
323 {
324 char **TypeIdsAsString = GetTypesUsedAsString(&sizeArray);
325 if (TypeIdsAsString)
326 {
327 m_out = 1;
328 n_out = sizeArray;
329 sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, m_out, n_out, TypeIdsAsString);
330 freeArrayOfString(TypeIdsAsString, sizeArray);
331
332 if(sciErr.iErr)
333 {
334 printError(&sciErr, 0);
335 return 0;
336 }
337
338 LhsVar(2) = Rhs + 2;
339 }
340 }
341
342 if (Lhs > 2) /* names */
343 {
344 char **Filenames = GetFilenamesUsed(&sizeArray);
345 if (Filenames)
346 {
347 m_out = 1;
348 n_out = sizeArray;
349 sciErr = createMatrixOfString(pvApiCtx, Rhs + 3, m_out, n_out, Filenames);
350 freeArrayOfString(Filenames, sizeArray);
351
352 if(sciErr.iErr)
353 {
354 printError(&sciErr, 0);
355 return 0;
356 }
357
358 LhsVar(3) = Rhs + 3;
359 }
360 }
361
362 if (Lhs > 3) /* mod */
363 {
364 int *Modes = GetModesUsed(&sizeArray);
365 if (Modes)
366 {
367 m_out = 1;
368 n_out = sizeArray;
369 sciErr = createMatrixOfInteger32(pvApiCtx, Rhs + 4, m_out, n_out, Modes);
370 FREE(Modes);
371 Modes = NULL;
372 if(sciErr.iErr)
373 {
374 printError(&sciErr, 0);
375 return 0;
376 }
377
378 LhsVar(4) = Rhs + 4;
379 }
380 }
381
382 if (Lhs > 4) /* swap */
383 {
384 int *SwapId = GetSwapsUsed(&sizeArray);
385 if (SwapId)
386 {
387 m_out = 1;
388 n_out = sizeArray;
389 sciErr = createMatrixOfInteger32(pvApiCtx, Rhs + 5, m_out, n_out, SwapId);
390 FREE(SwapId);
391 SwapId = NULL;
392
393 if(sciErr.iErr)
394 {
395 printError(&sciErr, 0);
396 return 0;
397 }
398
399 LhsVar(5) = Rhs + 5;
400 }
401 }
402
403 C2F(putlhsvar)();
404 return 0;
405}
406/*--------------------------------------------------------------------------*/
407static int sci_file_one_rhs(char *fname)
408{
409 SciErr sciErr;
410
411 int iID = 0;
412 int m1 = 0, n1 = 0;
413 int iType = 0;
414 int *piAddressVarOne = NULL;
415 double *pdVarOne = NULL;
416
417 int m_out = 0;
418 int n_out = 0;
419
420 /* get Address of inputs */
421 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
422 if(sciErr.iErr)
423 {
424 printError(&sciErr, 0);
425 return 0;
426 }
427
428 sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType);
429 if(sciErr.iErr)
430 {
431 printError(&sciErr, 0);
432 return 0;
433 }
434
435 /* check input type */
436 if ( iType != sci_matrix )
437 {
438 Scierror(201,_("%s: Wrong type for input argument #%d: A scalar expected.\n"),fname,1);
439 return 0;
440 }
441
442 sciErr = getMatrixOfDouble(pvApiCtx, piAddressVarOne,&m1,&n1,&pdVarOne);
443 if(sciErr.iErr)
444 {
445 printError(&sciErr, 0);
446 return 0;
447 }
448
449 if( n1 != 1 || m1 != 1)
450 {
451 Scierror(999,_("%s: Wrong size for input argument #%d: A scalar expected.\n"),fname,1);
452 return 0;
453 }
454
455 iID = (int) *pdVarOne;
456
457 if (*pdVarOne != (double)iID)
458 {
459 Scierror(999,_("%s: Wrong value for input argument #%d: A integer expected.\n"),fname,1);
460 return 0;
461 }
462
463 /* Lhs = 0 ID */
464 if (GetFileTypeOpenedInScilab(iID) != 0)
465 {
466 m_out = 1;
467 n_out = 1;
468 sciErr = createMatrixOfInteger32(pvApiCtx, Rhs + 1, m_out, n_out, &iID);
469 }
470 else
471 {
472 /* returns [] */
473 m_out = 0;
474 n_out = 0;
475 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, m_out, n_out, NULL);
476 }
477
478 if(sciErr.iErr)
479 {
480 printError(&sciErr, 0);
481 return 0;
482 }
483
484 LhsVar(1) = Rhs + 1;
485
486 if (Lhs > 1) /* Type */
487 {
488 if (GetFileTypeOpenedInScilab(iID) != 0)
489 {
490 char *TypeIdAsString = GetFileTypeOpenedInScilabAsString(iID);
491 m_out = 1;
492 n_out = 1;
493 sciErr = createMatrixOfString(pvApiCtx, Rhs + 2, m_out, n_out, &TypeIdAsString);
494 FREE(TypeIdAsString);
495 TypeIdAsString = NULL;
496 }
497 else
498 {
499 /* returns [] */
500 m_out = 0;
501 n_out = 0;
502 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 2, m_out, n_out, NULL);
503 }
504
505 if(sciErr.iErr)
506 {
507 printError(&sciErr, 0);
508 return 0;
509 }
510
511 LhsVar(2) = Rhs + 2;
512 }
513
514 if (Lhs > 2) /* name */
515 {
516 if (GetFileTypeOpenedInScilab(iID) != 0)
517 {
518 char *filename = NULL;
519 m_out = 1;
520 n_out = 1;
521 if (GetFileNameOpenedInScilab(iID) == NULL)
522 {
523 filename = strdup("");
524 }
525 else
526 {
527 filename = strdup(GetFileNameOpenedInScilab(iID));
528 }
529
530 sciErr = createMatrixOfString(pvApiCtx, Rhs + 3, m_out, n_out, &filename);
531 FREE(filename);
532 filename = NULL;
533 }
534 else
535 {
536 /* returns [] */
537 m_out = 0;
538 n_out = 0;
539 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 3, m_out, n_out, NULL);
540 }
541
542 if(sciErr.iErr)
543 {
544 printError(&sciErr, 0);
545 return 0;
546 }
547
548 LhsVar(3) = Rhs + 3;
549 }
550
551 if (Lhs > 3) /* mod */
552 {
553 if (GetFileTypeOpenedInScilab(iID) != 0)
554 {
555 int ModeId = GetFileModeOpenedInScilab(iID);
556 m_out = 1;
557 n_out = 1;
558 sciErr = createMatrixOfInteger32(pvApiCtx, Rhs + 4, m_out, n_out, &ModeId);
559 }
560 else
561 {
562 /* returns [] */
563 m_out = 0;
564 n_out = 0;
565 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 4, m_out, n_out, NULL);
566 }
567
568 if(sciErr.iErr)
569 {
570 printError(&sciErr, 0);
571 return 0;
572 }
573
574 LhsVar(4) = Rhs + 4;
575 }
576
577 if (Lhs > 4) /* swap */
578 {
579 if (GetFileTypeOpenedInScilab(iID) != 0)
580 {
581 int SwapId = GetSwapStatus(iID);
582 m_out = 1;
583 n_out = 1;
584 sciErr = createMatrixOfInteger32(pvApiCtx, Rhs + 5, m_out, n_out, &SwapId);
585 }
586 else
587 {
588 /* returns [] */
589 m_out = 0;
590 n_out = 0;
591 sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 5, m_out, n_out, NULL);
592 }
593
594 if(sciErr.iErr)
595 {
596 printError(&sciErr, 0);
597 return 0;
598 }
599 LhsVar(5) = Rhs + 5;
600 }
601
602 C2F(putlhsvar)();
603 return 0;
604}
605/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/io/tests/unit_tests/file.dia.ref b/scilab/modules/io/tests/unit_tests/file.dia.ref
new file mode 100644
index 0000000..d6ba3e6
--- /dev/null
+++ b/scilab/modules/io/tests/unit_tests/file.dia.ref
@@ -0,0 +1,47 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2010 - DIGITEO - Allan CORNET
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7// =============================================================================
8// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
9// Copyright (C) 2010 - DIGITEO - Allan CORNET
10//
11// This file is distributed under the same license as the Scilab package.
12// =============================================================================
13[a,b,c,d,e] = file(500);
14if a <> [] then bugmes();quit;end;
15if b <> [] then bugmes();quit;end;
16if c <> [] then bugmes();quit;end;
17if d <> [] then bugmes();quit;end;
18if e <> [] then bugmes();quit;end;
19clear a b c d e
20// =============================================================================
21[a,b,c,d] = file(500);
22if a <> [] then bugmes();quit;end;
23if b <> [] then bugmes();quit;end;
24if c <> [] then bugmes();quit;end;
25if d <> [] then bugmes();quit;end;
26clear a b c d
27// =============================================================================
28[a,b,c] = file(500);
29if a <> [] then bugmes();quit;end;
30if b <> [] then bugmes();quit;end;
31if c <> [] then bugmes();quit;end;
32clear a b c
33// =============================================================================
34[a,b] = file(500);
35if a <> [] then bugmes();quit;end;
36if b <> [] then bugmes();quit;end;
37clear a b
38// =============================================================================
39[a] = file(500);
40if a <> [] then bugmes();quit;end;
41clear a
42// =============================================================================
43file(500);
44// =============================================================================
45ierr = execstr("file(''toto'')","errcatch");
46if (ierr <> 201) then bugmes();quit;end
47// =============================================================================
diff --git a/scilab/modules/io/tests/unit_tests/file.tst b/scilab/modules/io/tests/unit_tests/file.tst
new file mode 100644
index 0000000..2c367c0
--- /dev/null
+++ b/scilab/modules/io/tests/unit_tests/file.tst
@@ -0,0 +1,48 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2010 - DIGITEO - Allan CORNET
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7// =============================================================================
8// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
9// Copyright (C) 2010 - DIGITEO - Allan CORNET
10//
11// This file is distributed under the same license as the Scilab package.
12// =============================================================================
13[a,b,c,d,e] = file(500);
14if a <> [] then pause,end;
15if b <> [] then pause,end;
16if c <> [] then pause,end;
17if d <> [] then pause,end;
18if e <> [] then pause,end;
19clear a b c d e
20// =============================================================================
21[a,b,c,d] = file(500);
22if a <> [] then pause,end;
23if b <> [] then pause,end;
24if c <> [] then pause,end;
25if d <> [] then pause,end;
26clear a b c d
27// =============================================================================
28[a,b,c] = file(500);
29if a <> [] then pause,end;
30if b <> [] then pause,end;
31if c <> [] then pause,end;
32clear a b c
33// =============================================================================
34[a,b] = file(500);
35if a <> [] then pause,end;
36if b <> [] then pause,end;
37clear a b
38// =============================================================================
39[a] = file(500);
40if a <> [] then pause,end;
41clear a
42// =============================================================================
43file(500);
44// =============================================================================
45ierr = execstr("file(''toto'')","errcatch");
46if (ierr <> 201) then pause,end
47// =============================================================================
48