fcbe82ea37e37735f081e35f1d77dab5f6f77e26
[scilab.git] / scilab / modules / fileio / sci_gateway / c / sci_maxfiles.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2007 - INRIA - Allan CORNET
4  * ...
5  * 
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
8  * you should have received as part of this distribution.  The terms
9  * are also available at    
10  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
11  *
12  */
13 /*--------------------------------------------------------------------------*/
14 #include "gw_fileio.h"
15 #include "stack-c.h"
16 #include "MALLOC.h"
17 #include "Scierror.h"
18 #include "filesmanagement.h"
19 #include "localization.h"
20 #include "sciprint.h"
21 /*--------------------------------------------------------------------------*/
22 #define MAX_FILES 100
23 /*--------------------------------------------------------------------------*/
24 static int DoOneLhs(void);
25 /*--------------------------------------------------------------------------*/
26 /**
27 * maxfiles sets the soft limit for the number of scilab files allowed to open simultaneously.
28 * Minimum 20
29 * Maximum 100
30 * Default 20
31 */
32 int C2F(sci_maxfiles)(char *fname,unsigned long fname_len)
33 {
34         static int l1,n1,m1;
35
36         Rhs=Max(0,Rhs);
37         CheckRhs(0,1);
38         CheckLhs(0,1);
39
40         if (Rhs == 0)
41         {
42                 DoOneLhs();
43         }
44         else
45         {
46                 if ( GetType(1) == sci_matrix )
47                 {
48                         GetRhsVar(1,MATRIX_OF_DOUBLE_DATATYPE,&m1,&n1,&l1);
49                         if ( (m1 == 1) && (n1 == 1) )
50                         {
51                                 int NewMaxFiles=0;
52                                 NewMaxFiles = (unsigned long) *stk(l1);
53                                 if (NewMaxFiles > GetMaximumFileOpenedInScilab() )
54                                 {
55                                         if (NewMaxFiles > MAX_FILES)
56                                         {
57                                                 sciprint(_("%s: Warning: Specified maximum number of files (%d) > Absolute maximum number of files allowed (%d).\n"),fname,NewMaxFiles,MAX_FILES);
58                                                 DoOneLhs();
59                                         }
60                                         else
61                                         {
62                                                 if ( ExtendScilabFilesList(NewMaxFiles) )
63                                                 {
64                                                         DoOneLhs();
65                                                 }
66                                                 else
67                                                 {
68                                                         Scierror(999,_("%s: Could not extend the number of files simultaneously open in Scilab.\n"),fname,NewMaxFiles);
69                                                         return 0;
70                                                 }
71                                         }
72                                 }
73                                 else
74                                 {
75                                         sciprint(_("%s: Warning : only extend the limit for the number of scilab's files opened simultaneously.\n"),fname);
76                                         DoOneLhs();
77                                 }
78                         }
79                         else
80                         {
81                                 Scierror(999,_("%s: Wrong size for first input argument: Scalar expected.\n"),fname);
82                                 return 0;
83                         }
84                 }
85                 else
86                 {
87                         Scierror(999,_("%s: Wrong type for first input argument: Matrix expected.\n"),fname);
88                         return 0;
89                 }
90         }
91         return 0;
92 }
93 /*--------------------------------------------------------------------------*/
94 int DoOneLhs(void)
95 {
96         static int n1,m1;
97         int *paramoutINT=NULL;
98         paramoutINT=(int*)MALLOC(sizeof(int));
99
100         *paramoutINT= GetMaximumFileOpenedInScilab();
101
102         n1=1;m1=1;
103         CreateVarFromPtr(Rhs+1,MATRIX_OF_INTEGER_DATATYPE, &n1, &m1, &paramoutINT);
104
105         LhsVar(1) = Rhs+1;
106         C2F(putlhsvar)();
107
108         if (paramoutINT) {FREE(paramoutINT);paramoutINT=NULL;}
109         return 0;
110 }
111 /*--------------------------------------------------------------------------*/