Fix non-regression test for bug #2165. No more generate an error when saving a "no...
[scilab.git] / scilab / modules / io / macros / %_save.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2012 - DIGITEO - Antoine ELIAS
3 //
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution.  The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9
10 //2012/08/06 transform macros to string to save it
11
12 //called by save function, transform handle in tlist and save result
13 function [] = %_save(%__filename__, varargin)
14
15     function result = isList(var)
16
17         //15 : list
18         //16 : tlist
19         //17 : mlist
20         if or(type(var) == [15, 16, 17]) then
21             result  = %t;
22         else
23             result = %f;
24         end
25     endfunction
26
27     function result = isMacro(var)
28         //11 : sci_u_function
29         if or(type(var) == [11]) then
30             result  = %t;
31         else
32             result = %f;
33         end
34     endfunction
35
36     function result = isCompiledMacro(var)
37         //11 : sci_c_function
38         if or(type(var) == [13]) then
39             result  = %t;
40         else
41             result = %f;
42         end
43     endfunction
44
45     function result = inspectList(l)
46         if typeof(l)=="list" then
47             result = list();
48             for %__i__ = definedfields(l)
49                 if typeof(l(%__i__)) == "handle" then
50                     if ~is_handle_valid(l(%__i__)) then
51                         oldMode = warning("query");
52                         warning("on");
53                         warning(msprintf(gettext("%s: handle no more valid ignored.\n"), "save"));
54                         warning(oldMode);
55                         result(%__i__) = [];
56                     else
57                         result(%__i__) = extractMatrixHandle(l(%__i__));
58                     end
59                 elseif isMacro(l(%__i__)) | isCompiledMacro(l(%__i__)) then
60                     //build an arbitrary name to the macro
61                     result(%__i__) = extractMacro(l(%__i__), "function");
62                 elseif isList(l(%__i__)) then
63                     result(%__i__) = inspectList(l(%__i__));
64                 elseif type(l(%__i__)) == 14 then //library, must not be save
65                     result(%__i__) = [];
66                 else
67                     result(%__i__) = l(%__i__);
68                 end
69             end
70         else
71             fieldNb = size(getfield(1, l), "*");
72             for kField = 2:fieldNb // Do not inspect first field (field names)
73                 fieldValue = getfield(kField, l);
74                 if typeof(fieldValue) == "handle" then
75                     fieldValue = extractMatrixHandle(fieldValue);
76                 elseif isMacro(fieldValue) | isCompiledMacro(fieldValue) then
77                     //build an arbitrary name to the macro
78                     fieldValue = extractMacro(fieldValue, "function");
79                 elseif isList(fieldValue) then
80                     fieldValue = inspectList(fieldValue);
81                 end
82                 setfield(kField, fieldValue, l);
83             end
84             result = l;
85         end
86     endfunction
87
88     function matrixHandle = extractMatrixHandle(h)
89
90         if typeof(h) <> "handle" then
91             matrixHandle = [];
92             return;
93         end
94
95         matrixHandle = tlist(["ScilabMatrixHandle", "dims", "values"]);
96         matrixHandle.dims = size(h);
97         matrixHandle.values = list();
98         for %__i__ = 1:size(h, "*")
99             matrixHandle.values($+1) = extractSingleHandle(h(%__i__));
100             if or(fieldnames(matrixHandle.values($))=="user_data") then
101                 if isList(matrixHandle.values($).user_data) then
102                     matrixHandle.values($).user_data = inspectList(matrixHandle.values($).user_data)
103                 elseif typeof(matrixHandle.values($).user_data) == "handle" then
104                     matrixHandle.values($).user_data = extractMatrixHandle(matrixHandle.values($).user_data)
105                 end
106             end
107         end
108     endfunction
109
110
111     function item = extractSingleHandle(h)
112
113         select h.type
114         case "Figure"
115             item = extractFigure(h);
116         case "Axes"
117             item = extractAxes(h);
118         case "Polyline"
119             item = extractPolyline(h);
120         case "Plot3d"
121             item = extractPlot3d(h);
122         case "Fac3d"
123             item = extractFac3d(h);
124         case "Compound"
125             item = extractCompound(h);
126         case "Rectangle"
127             item = extractRectangle(h);
128         case "Arc"
129             item = extractArc(h);
130         case "Champ"
131             item = extractChamp(h);
132         case "Segs"
133             item = extractSegs(h);
134         case "Grayplot"
135             item = extractGrayplot(h);
136         case "Matplot"
137             item = extractMatplot(h);
138         case "Fec"
139             item = extractFec(h);
140         case "Legend"
141             item = extractLegend(h);
142         case "Text"
143             item = extractText(h);
144         case "Axis"
145             item = extractAxis(h);
146         case "uimenu"
147             item = extractuimenu(h);
148         case "uicontextmenu"
149             item = extractuicontextmenu(h);
150         case "uicontrol"
151             item = extractuicontrol(h);
152         else
153             error("handle of type " + h.type + " unhandled");
154             item = [];
155         end
156     endfunction
157
158     //
159     // FIGURE
160     //
161     function returnedFigure = extractFigure(h)
162         returnedFigure = tlist([
163         "ScilabSingleHandle", ...
164         "type", ...
165         "visible", ...
166         "figure_position", ...
167         "figure_size", ...
168         "axes_size", ...
169         "viewport", ...
170         "info_message", ...
171         "tag", ...
172         "auto_resize", ...
173         "figure_name", ...
174         "figure_id", ...
175         "color_map", ...
176         "pixmap", ...
177         "pixel_drawing_mode", ...
178         "anti_aliasing", ...
179         "immediate_drawing", ...
180         "background", ...
181         "rotation_style", ...
182         "event_handler", ...
183         "event_handler_enable", ...
184         "resizefcn", ...
185         "closerequestfcn", ...
186         "children", ...
187         "user_data"]);
188
189         fields = fieldnames(returnedFigure);
190
191         for %__i__ = 1:size(fields, "*")
192             if fields(%__i__) == "children" then
193                 returnedFigure(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
194             else
195                 returnedFigure(fields(%__i__)) = h(fields(%__i__));
196             end
197         end
198     endfunction
199
200     //
201     // LABEL
202     //
203     function returnedLabel = extractLabel(h)
204         returnedLabel = tlist([
205         "ScilabSingleHandle", ...
206         "type", ...
207         "visible", ...
208         "text", ...
209         "font_foreground", ...
210         "foreground", ...
211         "background", ...
212         "fill_mode", ...
213         "font_style", ...
214         "font_size", ...
215         "fractional_font", ...
216         "font_angle", ...
217         "auto_rotation", ...
218         "position", ...
219         "auto_position"]);
220
221         fields = fieldnames(returnedLabel);
222
223         for %__i__ = 1:size(fields, "*")
224             returnedLabel(fields(%__i__)) = h(fields(%__i__));
225         end
226     endfunction
227
228     //
229     // TICKS
230     //
231     function returnedTicks = extractTicks(ticks)
232         returnedTicks = tlist([
233         "Ticks", ...
234         "locations", ...
235         "labels"]);
236
237         fields = fieldnames(returnedTicks);
238
239         for %__i__ = 1:size(fields, "*")
240             returnedTicks(fields(%__i__)) = ticks(fields(%__i__));
241         end
242     endfunction
243
244     //
245     // AXES
246     //
247     function returnedAxes = extractAxes(h)
248         returnedAxes = tlist([
249         "ScilabSingleHandle", ...
250         "type", ...
251         "visible", ...
252         "axes_visible", ...
253         "axes_reverse", ...
254         "grid", ...
255         "grid_position", ...
256         "x_location", ...
257         "y_location", ...
258         "view", ...
259         "title", ...
260         "x_label", ...
261         "y_label", ...
262         "z_label", ...
263         "auto_ticks", ...
264         "x_ticks", ...
265         "y_ticks", ...
266         "z_ticks", ...
267         "box", ...
268         "filled", ...
269         "sub_tics", ...
270         "font_style", ...
271         "font_size", ...
272         "font_color", ...
273         "fractional_font", ...
274         "isoview", ...
275         "cube_scaling", ...
276         "rotation_angles", ...
277         "log_flags", ...
278         "tight_limits", ...
279         "data_bounds", ...
280         "zoom_box", ...
281         "margins", ...
282         "axes_bounds", ...
283         "auto_clear", ...
284         "auto_scale", ...
285         "hidden_axis_color", ...
286         "arc_drawing_method", ...
287         "hiddencolor", ...
288         "line_mode", ...
289         "line_style", ...
290         "thickness", ...
291         "mark_mode", ...
292         "mark_style", ...
293         "mark_size", ...
294         "mark_size_unit", ...
295         "mark_foreground", ...
296         "mark_background", ...
297         "foreground", ...
298         "background", ...
299         "clip_state", ...
300         "clip_box", ...
301         "children", ...
302         "user_data"]);
303
304         fields = fieldnames(returnedAxes);
305
306         for %__i__ = 1:size(fields, "*")
307             if or(fields(%__i__) == ["title","x_label","y_label","z_label"]) then
308                 returnedAxes(fields(%__i__)) = extractLabel(h(fields(%__i__)));
309             elseif or(fields(%__i__) == ["x_ticks", "y_ticks", "z_ticks"]) then
310                 returnedAxes(fields(%__i__)) = extractTicks(h(fields(%__i__)));
311             elseif fields(%__i__) == "children" then
312                 returnedAxes(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
313             else
314                 returnedAxes(fields(%__i__)) = h(fields(%__i__));
315             end
316         end
317     endfunction
318
319     //
320     // POLYLINE
321     //
322     function returnedPolyline = extractPolyline(h)
323         returnedPolyline = tlist([
324         "ScilabSingleHandle", ...
325         "type", ...
326         "visible", ...
327         "data", ...
328         "closed", ...
329         "line_mode", ...
330         "fill_mode", ...
331         "line_style", ...
332         "thickness", ...
333         "arrow_size_factor", ...
334         "polyline_style", ...
335         "interp_color_vector", ...
336         "interp_color_mode", ...
337         "mark_mode", ...
338         "mark_style", ...
339         "mark_size", ...
340         "mark_size_unit", ...
341         "foreground", ...
342         "background", ...
343         "mark_foreground", ...
344         "mark_background", ...
345         "x_shift", ...
346         "y_shift", ...
347         "z_shift", ...
348         "bar_width", ...
349         "clip_state", ...
350         "clip_box", ...
351         "user_data"]);
352
353         fields = fieldnames(returnedPolyline);
354
355         for %__i__ = 1:size(fields, "*")
356             returnedPolyline(fields(%__i__)) = h(fields(%__i__));
357         end
358     endfunction
359
360     //
361     // PLOT3D
362     //
363     function returnedPlot3d = extractPlot3d(h)
364         returnedPlot3d = extractSurface(h);
365     endfunction
366
367     //
368     // FAC3D
369     //
370     function returnedFac3d = extractFac3d(h)
371         returnedFac3d = extractSurface(h);
372     endfunction
373
374     //
375     // SURFACE
376     //
377     function returnedSurface = extractSurface(h)
378         returnedSurface = tlist([
379         "ScilabSingleHandle", ...
380         "type", ...
381         "visible", ...
382         "surface_mode", ...
383         "foreground", ...
384         "thickness", ...
385         "mark_mode", ...
386         "mark_style", ...
387         "mark_size", ...
388         "mark_size_unit", ...
389         "mark_foreground", ...
390         "mark_background", ...
391         "color_mode", ...
392         "color_flag", ...
393         "data", ...
394         "color_flag", ...
395         "hiddencolor", ...
396         "clip_state", ...
397         "clip_box", ...
398         "user_data", ...
399         "cdata_mapping"]);
400
401         fields = fieldnames(returnedSurface);
402
403         for %__i__ = 1:size(fields, "*")
404             if fields(%__i__)=="cdata_mapping" then
405                 if h.type=="Fac3d" then
406                     returnedSurface(fields(%__i__)) = h(fields(%__i__));
407                 end
408             else
409                 returnedSurface(fields(%__i__)) = h(fields(%__i__));
410             end
411         end
412     endfunction
413
414     //
415     // COMPOUND
416     //
417     function returnedCompound = extractCompound(h)
418         returnedCompound = tlist([
419         "ScilabSingleHandle", ...
420         "type", ...
421         "visible", ...
422         "children", ...
423         "user_data"]);
424
425         fields = fieldnames(returnedCompound);
426
427         for %__i__ = 1:size(fields, "*")
428             if fields(%__i__) == "children" then
429                 returnedCompound(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
430             else
431                 returnedCompound(fields(%__i__)) = h(fields(%__i__));
432             end
433         end
434     endfunction
435
436     //
437     // RECTANGLE
438     //
439     function returnedRectangle = extractRectangle(h)
440         returnedRectangle = tlist([
441         "ScilabSingleHandle", ...
442         "type", ...
443         "visible", ...
444         "thickness", ...
445         "mark_mode", ...
446         "mark_style", ...
447         "mark_size", ...
448         "mark_size_unit", ...
449         "mark_foreground", ...
450         "mark_background", ...
451         "line_mode", ...
452         "line_style", ...
453         "fill_mode", ...
454         "foreground", ...
455         "background", ...
456         "data", ...
457         "clip_state", ...
458         "clip_box", ...
459         "user_data"]);
460
461         fields = fieldnames(returnedRectangle);
462
463         for %__i__ = 1:size(fields, "*")
464             returnedRectangle(fields(%__i__)) = h(fields(%__i__));
465         end
466     endfunction
467
468     //
469     // ARC
470     //
471     function returnedArc = extractArc(h)
472         returnedArc = tlist([
473         "ScilabSingleHandle", ...
474         "type", ...
475         "visible", ...
476         "thickness", ...
477         "line_style", ...
478         "line_mode", ...
479         "fill_mode", ...
480         "foreground", ...
481         "background", ...
482         "data", ...
483         "arc_drawing_method", ...
484         "clip_state", ...
485         "clip_box", ...
486         "user_data"]);
487
488         fields = fieldnames(returnedArc);
489
490         for %__i__ = 1:size(fields, "*")
491             returnedArc(fields(%__i__)) = h(fields(%__i__));
492         end
493     endfunction
494
495     //
496     // CHAMP
497     //
498     function returnedChamp = extractChamp(h)
499         returnedChamp = tlist([
500         "ScilabSingleHandle", ...
501         "type", ...
502         "visible", ...
503         "data", ...
504         "line_style", ...
505         "thickness", ...
506         "colored", ...
507         "arrow_size", ...
508         "clip_state", ...
509         "clip_box", ...
510         "user_data"]);
511
512         fields = fieldnames(returnedChamp);
513
514         for %__i__ = 1:size(fields, "*")
515             returnedChamp(fields(%__i__)) = h(fields(%__i__));
516         end
517     endfunction
518
519     //
520     // SEG
521     //
522     function returnedSeg = extractSegs(h)
523         returnedSeg = tlist([
524         "ScilabSingleHandle", ...
525         "type", ...
526         "visible", ...
527         "data", ...
528         "line_mode", ...
529         "line_style", ...
530         "thickness", ...
531         "segs_color", ...
532         "mark_mode", ...
533         "mark_style", ...
534         "mark_size", ...
535         "mark_size_unit", ...
536         "mark_foreground", ...
537         "mark_background", ...
538         "clip_state", ...
539         "clip_box", ...
540         "user_data"]);
541
542         fields = fieldnames(returnedSeg);
543
544         for %__i__ = 1:size(fields, "*")
545             returnedSeg(fields(%__i__)) = h(fields(%__i__));
546         end
547     endfunction
548
549     //
550     // GRAYPLOT
551     //
552     function returnedGrayplot = extractGrayplot(h)
553         returnedGrayplot = tlist([
554         "ScilabSingleHandle", ...
555         "type", ...
556         "visible", ...
557         "data", ...
558         "data_mapping", ...
559         "clip_state", ...
560         "clip_box", ...
561         "user_data"]);
562
563         fields = fieldnames(returnedGrayplot);
564
565         for %__i__ = 1:size(fields, "*")
566             returnedGrayplot(fields(%__i__)) = h(fields(%__i__));
567         end
568     endfunction
569
570     //
571     // MATPLOT
572     //
573     function returnedMatplot = extractMatplot(h)
574         returnedMatplot = tlist([
575         "ScilabSingleHandle", ...
576         "type", ...
577         "visible", ...
578         "data", ...
579         "clip_state", ...
580         "clip_box", ...
581         "user_data"]);
582
583         fields = fieldnames(returnedMatplot);
584
585         for %__i__ = 1:size(fields, "*")
586             returnedMatplot(fields(%__i__)) = h(fields(%__i__));
587         end
588     endfunction
589
590     //
591     // FEC
592     //
593     function returnedFec = extractFec(h)
594         returnedFec = tlist([
595         "ScilabSingleHandle", ...
596         "type", ...
597         "visible", ...
598         "data", ...
599         "triangles", ...
600         "z_bounds", ...
601         "color_range", ...
602         "outside_colors", ...
603         "line_mode", ...
604         "foreground", ...
605         "clip_state", ...
606         "clip_box", ...
607         "user_data"]);
608
609         fields = fieldnames(returnedFec);
610
611         for %__i__ = 1:size(fields, "*")
612             returnedFec(fields(%__i__)) = h(fields(%__i__));
613         end
614     endfunction
615
616     //
617     // LEGEND
618     //
619     function returnedLegend = extractLegend(h)
620         returnedLegend = tlist([
621         "ScilabSingleHandle", ...
622         "type", ...
623         "visible", ...
624         "text", ...
625         "font_style", ...
626         "font_size", ...
627         "font_color", ...
628         "fractional_font", ...
629         "links", ...
630         "legend_location", ...
631         "position", ...
632         "line_mode", ...
633         "thickness", ...
634         "foreground", ...
635         "fill_mode", ...
636         "background", ...
637         "clip_state", ...
638         "clip_box", ...
639         "user_data", ..
640         "paths"]);
641
642         fields = fieldnames(returnedLegend);
643
644         for %__i__ = 1:size(fields, "*")
645             if fields(%__i__) == "links" then
646                 returnedLegend(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
647             elseif fields(%__i__) == "paths" then
648                 p = list();
649                 for kl=1:size(h.links,"*");
650                     p($+1) = get_entity_path(h.links(kl));
651                 end
652                 returnedLegend(fields(%__i__)) = p;
653             else
654                 returnedLegend(fields(%__i__)) = h(fields(%__i__));
655             end
656         end
657     endfunction
658
659     //
660     // TEXT
661     //
662     function returnedText = extractText(h)
663         returnedText = tlist([
664         "ScilabSingleHandle", ...
665         "type", ...
666         "visible", ...
667         "text", ...
668         "data", ...
669         "text_box", ...
670         "text_box_mode", ...
671         "foreground", ...
672         "font_style", ...
673         "font_size", ...
674         "font_angle", ...
675         "box", ...
676         "line_mode", ...
677         "fill_mode", ...
678         "font_foreground", ...
679         "background", ...
680         "alignment", ...
681         "fractional_font", ...
682         "clip_state", ...
683         "clip_box", ...
684         "user_data"]);
685
686         fields = fieldnames(returnedText);
687
688         for %__i__ = 1:size(fields, "*")
689             returnedText(fields(%__i__)) = h(fields(%__i__));
690         end
691     endfunction
692
693     //
694     // AXIS
695     //
696     function returnedAxis = extractAxis(h)
697         returnedAxis = tlist([
698         "ScilabSingleHandle", ...
699         "type", ...
700         "visible", ...
701         "tics_direction", ...
702         "xtics_coord", ...
703         "ytics_coord", ...
704         "tics_color", ...
705         "tics_segment", ...
706         "tics_style", ...
707         "sub_tics", ...
708         "tics_labels", ...
709         "labels_font_size", ...
710         "labels_font_color", ...
711         "fractional_font", ...
712         "clip_state", ...
713         "clip_box", ...
714         "user_data"]);
715
716         fields = fieldnames(returnedAxis);
717
718         for %__i__ = 1:size(fields, "*")
719             returnedAxis(fields(%__i__)) = h(fields(%__i__));
720         end
721     endfunction
722
723     //
724     // uimenu
725     //
726     function returneduimenu = extractuimenu(h)
727         returneduimenu = tlist([
728         "ScilabSingleHandle", ...
729         "type", ...
730         "enable", ...
731         "foregroundcolor", ...
732         "label", ...
733         "visible", ...
734         "callback", ...
735         "callback_type", ...
736         "tag", ...
737         "checked", ...
738         "children", ..
739         "user_data"]);
740
741         fields = fieldnames(returneduimenu);
742
743         for %__i__ = 1:size(fields, "*")
744             if fields(%__i__) == "children" then
745                 returneduimenu(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
746             else
747                 returneduimenu(fields(%__i__)) = h(fields(%__i__));
748             end
749         end
750     endfunction
751
752     //
753     // UICONTEXTMENU
754     //
755     function returneduicontextmenu = extractuicontextmenu(h)
756         returneduicontextmenu = tlist([
757         "ScilabSingleHandle", ...
758         "type", ...
759         "children"]);
760
761         fields = fieldnames(returneduicontextmenu);
762
763         for %__i__ = 1:size(fields, "*")
764             if fields(%__i__) == "children" then
765                 returneduicontextmenu(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
766             else
767                 returneduicontextmenu(fields(%__i__)) = h(fields(%__i__));
768             end
769         end
770     endfunction
771
772     //
773     // uicontrol
774     //
775     function returneduicontrol = extractuicontrol(h)
776         returneduicontrol = tlist([
777         "ScilabSingleHandle", ...
778         "type", ...
779         "style", ...
780         "backgroundcolor", ...
781         "enable", ...
782         "fontangle", ...
783         "fontname", ...
784         "fontsize", ...
785         "fontunits", ...
786         "fontweight", ...
787         "foregroundcolor", ...
788         "horizontalalignment", ...
789         "listboxtop", ...
790         "max", ...
791         "min", ...
792         "position", ...
793         "relief", ...
794         "sliderstep", ...
795         "string", ...
796         "tooltipstring", ...
797         "units", ...
798         "value", ...
799         "verticalalignment", ...
800         "visible", ...
801         "callback", ...
802         "callback_type", ...
803         "user_data", ...
804         "tag", ...
805         "children"]);
806
807         fields = fieldnames(returneduicontrol);
808
809         for %__i__ = 1:size(fields, "*")
810             if fields(%__i__) == "children" then
811                 returneduicontrol(fields(%__i__)) = extractMatrixHandle(h(fields(%__i__)));
812             else
813                 returneduicontrol(fields(%__i__)) = h(fields(%__i__));
814             end
815         end
816     endfunction
817
818     // Utility function for legends, copy/paste from %h_load
819     function p=get_entity_path(e)
820         // given a handle e on an entity this function returns its path relative
821         // to its parent axes.
822         // the path is a vector of child index.
823         p=[];
824         parent=e.parent;
825
826         while  %t
827             pos=find(parent.children==e,1)
828             if pos==[] then
829                 error(msprintf(_("%s : Invalid entity %s\n"),"save","Legend"))
830             end
831             p=[pos p]
832             if parent.type=="Axes" then
833                 break
834             end
835             e=parent
836             parent=e.parent;
837         end
838     endfunction
839
840     function macro = extractMacro(macroPtr, macroName)
841         macroSt = fun2string(macroPtr, macroName);
842         oldMode = warning("query");
843         warning("off");
844         macro = tlist("ScilabMacro", isCompiledMacro(macroPtr), macroSt);
845         warning(oldMode);
846     endfunction
847
848     //main
849
850     //save environment
851     if size(varargin) == 0 then
852         %__excludeList__ = [
853         "%_save"
854         "isList"
855         "isMacro"
856         "isCompiledMacro"
857         "inspectList"
858         "extractMatrixHandle"
859         "extractSingleHandle"
860         "extractFigure"
861         "extractLabel"
862         "extractTicks"
863         "extractAxes"
864         "extractPolyline"
865         "extractPlot3d"
866         "extractFac3d"
867         "extractSurface"
868         "extractCompound"
869         "extractRectangle"
870         "extractArc"
871         "extractChamp"
872         "extractSegs"
873         "extractGrayplot"
874         "extractMatplot"
875         "extractFec"
876         "extractLegend"
877         "extractText"
878         "extractAxis"
879         "extractuimenu"
880         "extractuicontextmenu"
881         "extractuicontrol"
882         "get_entity_path"
883         "extractMacro"
884         "%__excludeList__"
885         "%__filename__"
886         "varargin"
887         "%__varList__"];
888
889         //get all user variables
890         %__varList__ = who_user(%f);
891         //remove exclude variables/functions
892         %__grepResult__ = grep(%__varList__, %__excludeList__);
893         %__varList__(%__grepResult__) = [];
894         for %__i__ = 1:size(%__varList__, "*")
895             //store them as input arguments
896             varargin(%__i__) = %__varList__(%__i__);
897         end
898     end
899
900     oldMode = warning("query");
901     warning("off");
902
903     if size(varargin) == 0 then
904     end
905
906     for %__i__ = size(varargin):-1:1
907
908         if varargin(%__i__) == "-append" then
909             continue;
910         end
911
912         temp = evstr(varargin(%__i__));
913
914         if isList(temp) then
915             //list container
916             value = inspectList(temp);
917             //update
918             execstr(varargin(%__i__) + " = value");
919         elseif typeof(temp) == "handle" then
920             if ~is_handle_valid(temp) then // Invalid handle ignored
921                 warning(oldMode);
922                 warning(msprintf(gettext("%s: handle no more valid ignored.\n"), "save"));
923                 warning("off");
924                 varargin(%__i__) = null();
925             else //convert handle to tlist
926                 value = extractMatrixHandle(temp);
927                 //update
928                 execstr(varargin(%__i__) + " = value");
929             end
930         elseif isMacro(temp) | isCompiledMacro(temp) then
931             //convert macro to tlist
932             value = extractMacro(temp, varargin(%__i__));
933             //update
934             execstr(varargin(%__i__) + " = value");
935         elseif type(temp) == 14 then //library, must not be save
936             varargin(%__i__) = null();
937         end
938     end
939     warning(oldMode);
940
941     //if size(varargin) == 0, create an empty file
942     result = export_to_hdf5(%__filename__, varargin(:));
943
944 endfunction