1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2009 - DIGITEO - Pierre MARECHAL <pierre.marechal@scilab.org>
3 // Copyright (C) 2021 - DIGITEO - Allan CORNET
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
11 // Get the configuration of the atoms system
13 function result = atomsGetConfig(field)
17 // Check number of input arguments
18 // =========================================================================
20 error(msprintf(gettext("%s: Wrong number of input argument: %d to %d expected.\n"), "atomsGetConfig", 0, 1));
23 // Check input parameters type
24 // =========================================================================
25 if (rhs > 0) & (type(field) <> 10) then
26 error(msprintf(gettext("%s: Wrong type for input argument #%d: Single string expected.\n"), "atomsGetConfig", 1));
29 // Check input parameters dimensions
30 // =========================================================================
31 if (rhs > 0) & (size(field, "*") <> 1) then
32 error(msprintf(gettext("%s: Wrong size for input argument #%d: Single string expected.\n"), "atomsGetConfig", 1));
37 supported_field = ["useProxy", "proxyHost", "proxyPort", ..
38 "proxyUser", "proxyPassword", "offline", ..
39 "autoload", "autoloadAddAfterInstall", ..
40 "verbose", "downloadTool", "downloadTimeout"];
42 if ~or(convstr(supported_field) == convstr(field)) then
43 error(msprintf(gettext("%s: Wrong value for input argument #%d.\n"),"atomsGetConfig", 1));
47 // Load Atoms Internals lib if it's not already loaded
48 // =========================================================================
49 if ~ exists("atomsinternalslib") then
50 load("SCI/modules/atoms/macros/atoms_internals/lib");
53 // Define the default value of the result according to the number of input
55 // =========================================================================
63 // Define the path of the file that will record the change
64 // =========================================================================
65 atoms_directory = atomsPath("system", "user");
67 // Does the SCIHOME/atoms/config exist, if yes load it
68 // =========================================================================
70 if fileinfo(atoms_directory + "config") <> [] then
71 config_lines = mgetl(atoms_directory + "config");
76 // Loop on each URL specified as input argument
77 // =========================================================================
79 for i=1:size(config_lines, "*")
80 if isempty( stripblanks(config_lines(i))) then
84 if regexp(config_lines(i),"/^[a-zA-Z0-9]*\s=\s/","o") == 1 then
86 current_field_length = regexp(config_lines(i),"/\s=\s/","o")
87 current_field = part(config_lines(i),1:current_field_length-1);
88 current_value = part(config_lines(i),current_field_length+3:length(config_lines(i)));
90 if (rhs == 1) & (current_field == field) then
91 result = current_value;
94 result(current_field) = current_value;
97 error(msprintf(gettext("%s: The config file (''%s'') is not well formated at line %d\n"),"atomsGetConfig",atoms_directory+"config",i));