Mercurial > forge
changeset 5755:ca7b889db533 octave-forge
Clean up properly using unwind_protect
author | hauberg |
---|---|
date | Sun, 14 Jun 2009 18:33:10 +0000 |
parents | c52a23feb90b |
children | 054edb9c36d5 |
files | extra/generate_html/inst/html_help_text.m |
diffstat | 1 files changed, 44 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/extra/generate_html/inst/html_help_text.m Sun Jun 14 18:06:28 2009 +0000 +++ b/extra/generate_html/inst/html_help_text.m Sun Jun 14 18:33:10 2009 +0000 @@ -192,52 +192,57 @@ if (exist (diary_file, "file")) delete (diary_file); endif - def = get (0, "defaultfigurevisible"); - set (0, "defaultfigurevisible", "off"); - more_val = page_screen_output (false); + + unwind_protect + ## Setup figure and pager properties + def = get (0, "defaultfigurevisible"); + set (0, "defaultfigurevisible", "off"); + more_val = page_screen_output (false); - ## Evaluate the code - diary (diary_file); - eval (code); - diary ("off"); + ## Evaluate the code + diary (diary_file); + eval (code); + diary ("off"); - ## Read the results - fid = fopen (diary_file, "r"); - diary_data = char (fread (fid).'); - fclose (fid); - delete (diary_file); + ## Read the results + fid = fopen (diary_file, "r"); + diary_data = char (fread (fid).'); + fclose (fid); - ## Remove 'diary ("off");' from the diary - idx = strfind (diary_data, "diary (\"off\");"); - if (isempty (idx)) - text = diary_data; - else - text = diary_data (1:idx (end)-1); - endif - text = strtrim (text); + ## Remove 'diary ("off");' from the diary + idx = strfind (diary_data, "diary (\"off\");"); + if (isempty (idx)) + text = diary_data; + else + text = diary_data (1:idx (end)-1); + endif + text = strtrim (text); - ## Save figures - if (!isempty (get (0, "currentfigure")) && !exist (full_imagedir, "dir")) - mkdir (full_imagedir); - endif + ## Save figures + if (!isempty (get (0, "currentfigure")) && !exist (full_imagedir, "dir")) + mkdir (full_imagedir); + endif - images = {}; - while (!isempty (get (0, "currentfigure"))) - fig = gcf (); - r = round (1000*rand ()); - name = sprintf ("%s_%d.png", fileprefix, r); - full_filename = fullfile (full_imagedir, name); - filename = fullfile (imagedir, name); - print (fig, full_filename); - images {end+1} = filename; - close (fig); - endwhile + images = {}; + while (!isempty (get (0, "currentfigure"))) + fig = gcf (); + r = round (1000*rand ()); + name = sprintf ("%s_%d.png", fileprefix, r); + full_filename = fullfile (full_imagedir, name); + filename = fullfile (imagedir, name); + print (fig, full_filename); + images {end+1} = filename; + close (fig); + endwhile - ## Reverse image list, since we got them latest-first - images = images (end:-1:1); + ## Reverse image list, since we got them latest-first + images = images (end:-1:1); - set (0, "defaultfigurevisible", def); - page_screen_output (more_val); + unwind_protect_cleanup + delete (diary_file); + set (0, "defaultfigurevisible", def); + page_screen_output (more_val); + end_unwind_protect endfunction function text = images_in_html (images)