Fix bin/scilab script after https://codereview.scilab.org/#/c/15307/
[scilab.git] / scilab / modules / helptools / macros / xmltochm.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2008 - INRIA - Pierre MARECHAL <pierre.marechal@inria.fr>
3 // Copyright (C) 2009-2010 -  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.1-en.txt
10
11 function generated_files = xmltochm(dirs,titles,directory_language,default_language)
12
13     warnobsolete(scilabRemovedVersion="5.5.1");
14
15     all_scilab_help    = %F;
16
17     if getos() <> "Windows" then
18         warning(msprintf(gettext("%s: This function is only supported on Windows platforms.\n"),"xmltochm"));
19         return;
20     end
21
22     lhs = argn(1);
23     rhs = argn(2);
24
25     select rhs
26
27     case 0 then
28         generated_files = xmltoformat("chm");
29         dirs = [];
30
31     case 1 then
32         generated_files = xmltoformat("chm", dirs);
33
34     case 2 then
35         generated_files = xmltoformat("chm", dirs, titles);
36
37     case 3 then
38         generated_files = xmltoformat("chm", dirs, titles, directory_language);
39
40     case 4 then
41         generated_files = xmltoformat("chm", dirs, titles, directory_language, default_language);
42
43     else
44         error(msprintf(gettext("%s: Wrong number of input argument(s): At most %d expected.\n"), "xmltochm", 4));
45     end
46
47     if (dirs == []) then
48         all_scilab_help = %T;
49     end
50
51     if getos() == "Windows" then
52         if (generated_files <> []) then
53             if (getHHCpath() <> "") then
54                 for i = 1:size(generated_files, "*")
55                     currentpath = pwd();
56                     [path,fname,extension] = fileparts(getshortpathname(generated_files(i)));
57                     cd(path);
58                     cmdline = getHHCpath() + " " + fname + extension;
59                     [msg,err] = dos(cmdline);
60                     cd(currentpath);
61                     chm_origin = "htmlhelp.chm";
62
63                     chm_name = tokens(generated_files(i), filesep());
64                     chm_name = chm_name($-1);
65                     chm_name = chm_name + ".chm";
66
67                     chm_src = strsubst(generated_files(i), "htmlhelp.hhp", chm_origin);
68                     dir_src_idx = strindex(chm_src, filesep());
69                     dir_src_chm = part(chm_src,1:dir_src_idx($));
70
71                     if all_scilab_help then
72                         if (i == 1) then
73                             dir_dest_chm = part(chm_src,1:dir_src_idx($-2)) + "chm" + filesep();
74                         else
75                             dir_dest_chm = part(chm_src,1:dir_src_idx($-3)) + "chm" + filesep();
76                         end
77                     else
78                         dir_dest_chm = part(chm_src,1:dir_src_idx($-3)) + "chm" + filesep();
79                     end
80
81                     chm_destination = dir_dest_chm  + chm_name;
82
83                     copyfile(chm_src, chm_destination);
84                     generated_files(i) = chm_destination;
85                 end
86             else
87                 warning(msprintf(gettext("%s: hhc.exe not found.\n"), "xmltochm"));
88             end
89         else
90             warning(msprintf(gettext("%s: no file generate.\n"), "xmltochm"));
91         end
92     end
93
94 endfunction
95
96 function HHC_path = getHHCpath()
97
98     if win64() then
99         std_path = getshortpathname(getenv("ProgramFiles(x86)", "") + filesep() + "HTML Help Workshop" + filesep() + "hhc.exe");
100     else
101         std_path = getshortpathname(std_path = getenv("ProgramFiles", "") + filesep() + "HTML Help Workshop" + filesep() + "hhc.exe");
102     end
103
104     if (fileinfo(std_path) == []) then
105         HHC_path = "";
106     else
107         HHC_path = std_path;
108     end
109
110 endfunction