* Bug #12548 fixed - Duplicated code in xmltoformat. 73/11273/3
Charlotte HECQUET [Mon, 15 Apr 2013 09:11:54 +0000 (11:11 +0200)]
Change-Id: I837d111214c27fa3b20d8a38fc3d3fac168b8db3

scilab/CHANGES_5.5.X
scilab/modules/helptools/macros/xmltoformat.sci
scilab/modules/helptools/tests/nonreg_tests/bug_12548.tst [new file with mode: 0644]
scilab/modules/helptools/tests/nonreg_tests/bug_12548.unix.dia.ref [new file with mode: 0644]

index 9910165..1642863 100644 (file)
@@ -106,3 +106,5 @@ Bug fixes
 * Bug #12475 fixed - csvRead() does not support double quoted fields.
 
 * Bug #12506 fixed - In SciNotes, miscolorization when returned values list was broken.
+
+* Bug #12548 fixed - Duplicated code in xmltoformat.
index e61b07d..9abe411 100644 (file)
@@ -518,33 +518,7 @@ function generated_files = xmltoformat(output_format,dirs,titles,directory_langu
             end
         end
 
-        // Check if the help file has been generated
-        if fileinfo(buildDoc_file)==[] then
-            chdir(cur_dir);
-            error(msprintf(gettext("%s: %s has not been generated."),"xmltoformat",buildDoc_file));
-        end
-
-        // move the generated file(s)
-        if is_chm then
-
-        elseif is_html then
-            my_html_files = listfiles(buildDoc_dir);
-            for k=1:size(my_html_files,"*")
-                if ~copyfile(my_html_files(k),pathconvert(final_output_dir+"/"+my_html_files(k),%f,%f)) then
-                    chdir(cur_dir);
-                    error(msprintf(gettext("%s: %s file hasn''t been moved in the %s directory."),"xmltoformat",my_html_files(k),final_output_dir));
-                end
-                mdelete(my_html_files(k));
-            end
-        else
-            copyfile(buildDoc_file,final_help_file);
-            mdelete(buildDoc_file);
-        end
-
-        // Move into the initial directory
-        if ~chdir(cur_dir) then
-            error(msprintf(gettext("%s: Directory %s does not exist or read access denied."),"xmltoformat",cur_dir));
-        end
+        check_move(buildDoc_file);
 
         // Now we can add the help file to the list of all generated files
         generated_files = [ generated_files ; final_help_file ];
@@ -619,33 +593,7 @@ function generated_files = xmltoformat(output_format,dirs,titles,directory_langu
                 buildDocv2("jar-only",this_tree("master_document"),directory_language_c(k),dirs_c(k));
             end
 
-            // Check if the help file has been generated
-            if fileinfo(buildDoc_file)==[] then
-                chdir(cur_dir);
-                error(msprintf(gettext("%s: %s has not been generated."),"xmltoformat",buildDoc_file));
-            end
-
-            // move the generated file(s)
-            if is_chm then
-
-            elseif is_html then
-                my_html_files = listfiles(buildDoc_dir);
-                for k=1:size(my_html_files,"*")
-                    if ~copyfile(my_html_files(k),pathconvert(final_output_dir+"/"+my_html_files(k),%f,%f)) then
-                        chdir(cur_dir);
-                        error(msprintf(gettext("%s: %s file hasn''t been moved in the %s directory."),"xmltoformat",my_html_files(k),final_output_dir));
-                    end
-                    mdelete(my_html_files(k));
-                end
-            else
-                copyfile(buildDoc_file,final_help_file);
-                mdelete(buildDoc_file);
-            end
-
-            // Move into the initial directory
-            if ~chdir(cur_dir) then
-                error(msprintf(gettext("%s: Directory %s does not exist or read access denied."),"xmltoformat",oldDir));
-            end
+            check_move(buildDoc_file);
 
             // Now we can add the help file to the list of all generated files
             generated_files = [ generated_files ; final_help_file ];
@@ -744,33 +692,7 @@ function generated_files = xmltoformat(output_format,dirs,titles,directory_langu
                 buildDocv2("jar-only",this_tree("master_document"),directory_language(k),dirs(k));
             end
 
-            // Check if the help file has been generated
-            if fileinfo(buildDoc_file)==[] then
-                chdir(cur_dir);
-                error(msprintf(gettext("%s: %s has not been generated."),"xmltoformat",buildDoc_file));
-            end
-
-            // move the generated file(s)
-            if is_chm then
-                // nothing to do
-            elseif is_html then
-                my_html_files = listfiles(buildDoc_dir);
-                for k=1:size(my_html_files,"*")
-                    if ~copyfile(my_html_files(k),pathconvert(final_output_dir+"/"+my_html_files(k),%f,%f)) then
-                        chdir(cur_dir);
-                        error(msprintf(gettext("%s: %s file hasn''t been moved in the %s directory."),"xmltoformat",my_html_files(k),final_output_dir));
-                    end
-                    mdelete(my_html_files(k));
-                end
-            else
-                copyfile(buildDoc_file,final_help_file);
-                mdelete(buildDoc_file);
-            end
-
-            // Move into the initial directory
-            if ~chdir(cur_dir) then
-                error(msprintf(gettext("%s: Directory %s does not exist or read access denied."),"xmltoformat",oldDir));
-            end
+            check_move(buildDoc_file);
 
             // Now we can add the help file to the list of all generated files
             generated_files = [ generated_files ; final_help_file ];
@@ -788,6 +710,40 @@ function generated_files = xmltoformat(output_format,dirs,titles,directory_langu
 
 endfunction
 
+// =============================================================================
+// check and move the generated files
+// =============================================================================
+function check_move(buildDoc_file)
+
+    // Check if the help file has been generated
+    if fileinfo(buildDoc_file)==[] then
+        chdir(cur_dir);
+        error(msprintf(gettext("%s: %s has not been generated."),"xmltoformat",buildDoc_file));
+    end
+
+    // move the generated file(s)
+    if is_chm then
+
+    elseif is_html then
+        my_html_files = listfiles(buildDoc_dir);
+        for k=1:size(my_html_files,"*")
+            if ~copyfile(my_html_files(k),pathconvert(final_output_dir+"/"+my_html_files(k),%f,%f)) then
+                chdir(cur_dir);
+                error(msprintf(gettext("%s: %s file hasn''t been moved in the %s directory."),"xmltoformat",my_html_files(k),final_output_dir));
+            end
+            mdelete(my_html_files(k));
+        end
+    else
+        copyfile(buildDoc_file,final_help_file);
+        mdelete(buildDoc_file);
+    end
+
+    // Move into the initial directory
+    if ~chdir(cur_dir) then
+        error(msprintf(gettext("%s: Directory %s does not exist or read access denied."),"xmltoformat",cur_dir));
+    end
+
+endfunction
 
 // =============================================================================
 // dirs_out = x2f_get_xml_path(dirs_in,my_wanted_language)
diff --git a/scilab/modules/helptools/tests/nonreg_tests/bug_12548.tst b/scilab/modules/helptools/tests/nonreg_tests/bug_12548.tst
new file mode 100644 (file)
index 0000000..2db60a1
--- /dev/null
@@ -0,0 +1,32 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- JVM MANDATORY -->
+//
+// <-- ENGLISH IMPOSED -->
+//
+// <-- NO CHECK ERROR OUTPUT --> 
+//
+// <-- Non-regression test for bug 12548 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=12548
+//
+// <-- Short Description -->
+// Duplicated code in xmltoformat
+
+function a = bug_12548(b, c, d)
+  a = 0;
+endfunction
+
+test_bug_12548 = "bug_12548";
+pathDest = TMPDIR + filesep() + test_bug_12548 + filesep();
+mkdir(TMPDIR, test_bug_12548);
+
+mputl(help_skeleton("bug_12548"), pathDest + "bug_12548.xml");
+
+assert_checktrue(execstr("xmltoformat(""javaHelp"",pathDest, ""bug help"")","errcatch")==0);
diff --git a/scilab/modules/helptools/tests/nonreg_tests/bug_12548.unix.dia.ref b/scilab/modules/helptools/tests/nonreg_tests/bug_12548.unix.dia.ref
new file mode 100644 (file)
index 0000000..8d82793
--- /dev/null
@@ -0,0 +1,36 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Charlotte HECQUET
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- JVM MANDATORY -->
+//
+// <-- ENGLISH IMPOSED -->
+//
+// <-- NO CHECK ERROR OUTPUT --> 
+//
+// <-- Non-regression test for bug 12548 -->
+//
+// <-- Bugzilla URL -->
+// http://bugzilla.scilab.org/show_bug.cgi?id=12548
+//
+// <-- Short Description -->
+// Duplicated code in xmltoformat
+function a = bug_12548(b, c, d)
+  a = 0;
+endfunction
+test_bug_12548 = "bug_12548";
+pathDest = TMPDIR + filesep() + test_bug_12548 + filesep();
+mkdir(TMPDIR, test_bug_12548);
+mputl(help_skeleton("bug_12548"), pathDest + "bug_12548.xml");
+assert_checktrue(execstr("xmltoformat(""javaHelp"",pathDest, ""bug help"")","errcatch")==0);
+
+Building the master document:
+       TMPDIR/bug_12548/
+
+Building the manual file [javaHelp] in TMPDIR/bug_12548/.
+ Generate image ./bug_12548_1.png from Scilab code from file bug_12548. 
+      xml