* Bugs 16567 16586 fixed: mfile2sci() supports block %{..%}. Appended comments improved"
[scilab.git] / scilab / modules / m2sci / macros / kernel / replace_brackets.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) ???? - INRIA - Scilab
3 //
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
5 //
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
12
13 function txt=replace_brackets(txt)
14
15     symbs=[",",";","=",")","]","("]
16     // This file will be use to deal with cells...
17     for k=1:size(txt,"r")
18
19         // select-case
20         if strindex(txt(k),"case")<>[] then
21             txt(k)=strsubst(strsubst(txt(k),"{","makecell("),"}",")")
22         else
23             tk=strsubst(txt(k)," ","")
24
25             ko=strindex(tk,"{")
26             if ko<>[] then
27                 teq=strindex(tk,"=")
28
29                 ///
30                 if ko(1)==1 then
31                     txt(k)=strsubst(txt(k),"{}","makecell()")
32                     txt(k)=strsubst(strsubst(txt(k),"{","(makecell([cell(),"),"}","]))")
33                 elseif or(part(tk,ko(1)-1)==symbs) then
34                     txt(k)=strsubst(txt(k),"{}","makecell()")
35                     txt(k)=strsubst(strsubst(txt(k),"{","(makecell([cell(),"),"}","]))")
36                 else // Cell index
37                     txt(k)=strsubst(strsubst(txt(k),"{","("),"}",").entries")
38                 end
39
40                 ////
41
42                 for kk=2:size(ko,"*")
43                     if or(part(tk,ko(kk)-1)==symbs) then // Cell creation
44                         txt(k)=strsubst(txt(k),"{}","makecell()")
45                         txt(k)=strsubst(strsubst(txt(k),"{","(makecell([cell(),"),"}","]))")
46                     else // Cell index
47                         txt(k)=strsubst(strsubst(txt(k),"{","("),"}",").entries")
48                     end
49                 end
50             elseif ~isempty(strindex(txt(k),"}")) then
51                 txt(k)=strsubst(txt(k),"}","]))")
52             end
53         end
54     end
55 endfunction