* Bug #13514 fixed - External modules' loader_pal.sce contains absolute path.
[scilab.git] / scilab / modules / modules_manager / macros / tbx_build_pal_loader.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2013 - INRIA - Serge STEER
3 // Copyright (C) 2014 - Scilab Enterprises - ClĂ©ment DAVID
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.1-en.txt
10
11 function tbx_build_pal_loader(palettename,interfacefunctions,module_path,script_path)
12     if argn(2) < 3 then
13         error(msprintf(gettext("%s: Wrong number of input arguments: At least %d expected.\n"),"tbx_build_blocks",3));
14     end
15     // checking palettename argument
16     if type(palettename) <> 10 then
17         error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"tbx_build_blocks",1));
18     end
19     if size(palettename,"*") <> 1 then
20         error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"tbx_build_blocks",1));
21     end
22
23     // checking module_path argument
24     if type(module_path) <> 10 then
25         error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"tbx_build_blocks",3));
26     end
27     if size(module_path,"*") <> 1 then
28         error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"tbx_build_blocks",3));
29     end
30     if ~isdir(module_path) then
31         error(msprintf(gettext("%s: The directory ''%s'' doesn''t exist or is not read accessible.\n"),"tbx_build_blocks",module_path));
32     end
33
34     // checking interfacefunctions argument
35     if type(interfacefunctions) <> 10 then
36         error(msprintf(gettext("%s: Wrong type for input argument #%d: A string array expected.\n"),"tbx_build_blocks",2));
37     end
38
39     // checking optional script_path argument
40     if argn(2)==4 then
41         if type(script_path) <> 10 then
42             error(msprintf(gettext("%s: Wrong type for input argument #%d: A string expected.\n"),"tbx_build_blocks",4));
43         end
44         if size(script_path,"*") <> 1 then
45             error(msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n"),"tbx_build_blocks",4));
46         end
47     else
48         script_path=module_path + "/macros"
49     end
50     if ~isdir(script_path) then
51         error(msprintf(gettext("%s: The directory ''%s'' doesn''t exist or is not read accessible.\n"),"tbx_build_blocks",script_path));
52     end
53
54
55     t=["// This file is released under the 3-clause BSD license. See COPYING-BSD."
56     "// Generated by tbx_build_pal_loader: Please, do not edit this file"
57     ""
58     "function loaderpal()"
59     "  xpal = xcosPal("""+palettename+""");"
60     "  images_path = get_absolute_file_path(""loader_pal.sce"")+""/../images/"";"
61     "  interfacefunctions ="+sci2exp(interfacefunctions);
62     "  for i=1:size(interfacefunctions,""*"")"
63     "    h5_instances  = ls(images_path + ""h5/""  + interfacefunctions(i) + "".sod"");"
64     "    if h5_instances==[] then"
65     "      error(msprintf(_(""%s: block %s has not been built.\n""),""loader_pal.sce"",interfacefunctions(i)))"
66     "    end"
67     "    pal_icons     = ls(images_path + ""gif/"" + interfacefunctions(i) + ""."" + [""png"" ""jpg"" ""gif""]);"
68     "    if pal_icons==[] then"
69     "      error(msprintf(_(""%s: block %s has no palette icon.\n""),""loader_pal.sce"",interfacefunctions(i)))"
70     "    end"
71     "    graph_icons   = ls(images_path + ""svg/"" + interfacefunctions(i) + ""."" + [""svg"" ""png"" ""jpg"" ""gif""]);"
72     "    if graph_icons==[] then"
73     "      error(msprintf(_(""%s: block %s has no editor icon.\n""),""loader_pal.sce"",interfacefunctions(i)))"
74     "    end"
75     "    xpal = xcosPalAddBlock(xpal, interfacefunctions(i), pal_icons(1) , graph_icons(1));"
76     "  end"
77     "  xcosPalAdd(xpal);"
78     "endfunction"
79     "loaderpal(),clear loaderpal"]
80     mputl(t,script_path+"loader_pal.sce")
81 endfunction
82