* Bug 16178 fixed: sci2exp() failed with input macros w/o argout
[scilab.git] / scilab / modules / string / macros / sci2exp.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) INRIA -
3 // Copyright (C) 2012 - 2016 - Scilab Enterprises
4 // Copyright (C) 2016, 2017, 2019 - Samuel GOUGEON
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 t=sci2exp(a,nom,lmax)
14     // sci2exp - convert a variable to an expression
15     //%SYNTAX
16     // t=sci2exp(a [,nam] [,lmax])
17     //%PARAMETERS
18     //   a  : matrix of scalar or polynomials
19     //   nam: character string
20     //   t  : vector of string, contains the expression definition
21     //   lmax : maximum line lengh (0 for no line length control)
22     //%Example
23     //  a=[1 2;3 4]
24     //  sci2exp(a,'aa')
25     //!
26
27     deff("x=String(a)",["x=string(a)"
28     "x=strsubst(x,''Nan'',''%nan'')"
29     "x=strsubst(x,''Inf'',''%inf'')"
30     ])
31
32
33     [lhs,rhs]=argn(0)
34     $ // import global variable $ in sci2exp context for efficiency
35     select rhs
36     case 1 then
37         named=%f
38         lmax=0
39     case 2 then
40         if type(nom)==1 then
41             lmax=nom
42             named=%f
43         else
44             named=%t
45             lmax=0
46         end
47     case 3 then
48         named=%t
49         if type(nom)==1 then
50             [lmax,nom]=(nom,lmax)
51         end
52     end
53     // For an hypermatrix, we concatenate all components in a single row:
54     hyperMat = or(type(a)==[1 2 4 8 10]) && ndims(a) > 2;
55     if hyperMat then
56         s = size(a);
57         a = matrix(a,1,-1);
58     end
59
60     dots="..";
61
62     select type(a)
63     case 1 then
64         t=mat2exp(a,lmax)
65     case 2 then
66         t=pol2exp(a,lmax)
67     case 4 then
68         t=log2exp(a,lmax)
69     case 5 then
70         t=sp2exp(a,lmax)
71     case 6 then
72         t=sp2exp(a,lmax)
73     case 7 then
74         t=sp2exp(a,lmax)
75     case 8 then
76         t=int2exp(a,lmax)
77     case 9 then
78         t=h2exp(a, lmax)
79     case 10 then
80         t=str2exp(a,lmax)
81     case 13 then
82         tree=macr2tree(a);
83         strfun=tree2code(tree);
84         name="%fun";
85         if named then
86             name=nom;
87         end
88         strfun(1) = strsubst(strfun(1), tree.name+"(", name+"(");
89         strfun($)=[];
90         t=strfun;
91         t(1) = part(t(1),10:length(t(1)))
92         t($) = [];
93         t = sci2exp(t, lmax);
94         t(1) = "createfun(" + t(1);
95         t($) = t($) + ")";
96     case 15 then
97         t = list2exp(a, lmax);
98     case 16 then
99         t = tlist2exp(a, lmax);
100     case 17 then            // cells, struct, mlists
101         if typeof(a)=="st" & length(a)==1
102             t = scalarstruct2exp(a, lmax);
103         else
104             t = mlist2exp(a, lmax);
105         end
106     case 128 then
107         t = mlist2exp(user2mlist(a), lmax);
108     case 129 then
109         t = imp2exp(a, lmax);
110     else
111         //  execstr('t='+typeof(a)+'2exp(a,lmax)')
112         msg = _("%s: This feature has not been implemented: Variable translation of type %s.\n");
113         error(msprintf(msg, "sci2exp", string(type(a))));
114     end
115     // Post-processing:
116     if hyperMat then
117         s = strcat(msprintf("%d\n",s(:)), ",");  // Literal list of sizes
118         if lmax>0
119             if length(t(1)) > (lmax-8)
120                 t = ["matrix(.."; t];
121             else
122                 t(1) = "matrix("+t(1);
123             end
124             if length(t($)) > (lmax-length(s)-5)
125                 t($) = t($)+",..";
126                 t = [t ; "["+s+"])"];
127             else
128                 t($) = t($)+", ["+s+"])";
129             end
130         else
131             t = "matrix(" + t + ", ["+s+"])";
132         end
133     end
134     if named&and(type(a)<>13) then
135         t(1)=nom+" = "+t(1)
136     end
137 endfunction
138
139 function t=str2exp(a,lmax)
140     if rhs<2 then lmax=0,end
141     [lhs,rhs]=argn(0)
142
143     [m,n]=size(a),
144     dots="."+"."
145     t="";
146     quote="''"
147
148     a=strsubst(a,quote,quote+quote)
149     dquote=""""
150     a=strsubst(a,dquote,dquote+dquote)
151     a = strsubst(a, ascii(10), """+ascii(10)+""")
152     a=quote(ones(a))+a+quote(ones(a))
153
154     for i=1:m
155         x=emptystr();
156         for j=1:n,
157             y=a(i,j);
158             y=dquote+part(y,2:length(y))
159             y=part(y,1:length(y)-1)+dquote
160             if y=="''''" then y="emptystr()",end
161             if lmax==0|length(x($))+length(y)<lmax then
162                 if j==1 then
163                     x=y
164                 else
165                     x($)=x($)+","+y,
166                 end
167             else
168                 if j>1 then
169                     x($)=x($)+","+dots;
170                     x($+1)=y
171                 else
172                     x=y
173                 end
174             end
175         end
176         if i<m then x($)=x($)+";",end
177         if lmax>0 then
178             t=[t;x]
179         else
180             t=t+x
181         end
182     end,
183     if lmax>0&sum(length(t))<lmax then
184         t=strcat(t)
185     end
186     if m*n>1 then
187         t(1)="["+t(1)
188         t($)=t($)+"]"
189     end
190 endfunction
191
192 function t=mat2exp(a,lmax)
193     if rhs<2 then lmax=0,end
194     [lhs,rhs]=argn(0)
195     if size(a,"*")==0 then t="[]",return,end
196     [m,n]=size(a);
197     if m<0 then
198         t=mat2exp(a+0);
199         if t=="1" then
200             t="eye()";
201         else
202             t="("+t+")*eye()";
203         end
204         return
205     end
206     a=String(a);
207     dots="."+"."
208     t="";
209     if n==1 then
210         x=strcat(a,";")
211         lx=length(x)
212         if lmax==0|lx<lmax then
213             t=x;
214         else
215             ind=strindex(x,";");
216             k1=1;l=0;I=[];
217             while %t
218                 if lx-l<lmax|k1>length(ind) then,break,end
219                 k2=k1-1+max(find(ind(k1:$)<l+lmax))
220                 I=[I ind(k2)];
221                 //      t=[t;part(x,l+1:ind(k2))]
222                 k1=k2+1
223                 l=ind(k2)
224             end
225             t=[t;strsplit(x,I)];
226         end
227     elseif m==1 then
228         x=strcat(a,",")
229         lx=length(x)
230         if lmax==0|lx<lmax then
231             t=x;
232
233         else
234             ind=strindex(x,",");
235             k1=1;l=0;I=[];
236             while %t
237                 if lx-l<lmax|k1>length(ind) then break,end
238                 k2=k1-1+max(find(ind(k1:$)<l+lmax))
239                 I=[I ind(k2)];
240                 //      t=[t;part(x,l+1:ind(k2))+dots]
241                 k1=k2+1
242                 l=ind(k2)
243             end
244             x=strsplit(x,I);x(1:$-1)=x(1:$-1)+dots;
245             t=[t;x]
246         end
247     else
248         for i=1:m
249             x=strcat(a(i,:),",")
250             if i<m then x=x+";",end
251             lx=length(x)
252             if lmax==0 then
253                 t=t+x
254             elseif lx<lmax then
255                 t=[t;x]
256             else
257                 ind=strindex(x,",");
258                 k1=1;l=0;I=[];
259                 while %t
260                     if lx-l<lmax|k1>length(ind) then break,end
261                     k2=k1-1+max(find(ind(k1:$)<l+lmax))
262                     I=[I ind(k2)];
263                     //    t=[t;part(x,l+1:ind(k2))+dots]
264                     k1=k2+1
265                     l=ind(k2)
266                 end
267                 x=strsplit(x,I);x(1:$-1)=x(1:$-1)+dots;x(2:$)=" "+x(2:$);
268                 t=[t;x]
269             end
270         end
271     end
272     if m*n>1 then
273         t(1)="["+t(1)
274         t($)=t($)+"]"
275     end
276 endfunction
277
278 function t=pol2exp(a,lmax)
279     $
280     if rhs<2 then lmax = 0, end
281     [lhs,rhs] = argn(0)
282
283     [m,n] = size(a)
284     var = " ";
285     lvar = 1;
286     var = varn(a);
287     if or(var==["s" "z"]) then
288         var = "%"+var;
289     end
290     lvar=length(var);
291     while part(var,lvar)==" " then lvar=lvar-1,end
292     var=part(var,1:lvar);
293     if m<0 then
294         t=pol2exp(a+0)
295         t="("+t+")*eye()"
296         return
297     end
298     t=[];
299     for i=1:m
300         x=emptystr(1)
301         for j=1:n,
302             v=a(i,j);d=max(0,degree(v));
303             v=coeff(v);
304             k0=1;while (k0<d+1)&(v(k0))==0 then k0=k0+1,end
305             y=emptystr(1)
306             nul=%t
307             for k=k0:(d+1),
308                 s=String(v(k))
309                 if s<>"0" then
310                     nul=%f
311                     if part(s,1)==" " then s=part(s,2:length(s)),end
312                     mnm=emptystr(1)
313                     if k>0 then
314                         mnm=var
315                         if k>2 then
316                             mnm=mnm+"^"+string(k-1),
317                         end
318                     end
319                     if k>1 then
320                         if string(imag(v(k)))<>"0" then s="("+s+")",end
321                         if s=="1" then
322                             s=mnm
323                         elseif s=="-1" then
324                             s="-"+mnm
325                         else
326                             s=s+"*"+mnm
327                         end
328                         if k>k0&part(s,1)<>"-" then s="+"+s,end
329                     end
330                     if lmax==0|length(y($))+length(s) <lmax then
331                         y($)=y($)+s
332                     else
333                         y($)=y($)+dots
334                         y($+1)=s
335                     end
336                 end
337             end
338             if nul then y="0*"+var,end
339             [ny,my]=size(y)
340
341             if lmax==0|length(x($))+length(y(1))<lmax then
342                 if j==1 then
343                     x=y(1)
344                 else
345                     x($)=x($)+","+y(1),
346                 end
347                 if ny>1 then x($+1:$+ny-1)=y(2:ny),end
348             else
349                 if length(x($))==0 then
350                     x($:$+ny-1) = y;
351                 else
352                     x($)=x($)+","+dots;
353                     x($+1:$+ny)=y
354                 end
355             end
356         end
357         if i<m then x($)=x($)+";",end
358         if lmax>0 | t==[] then
359             t=[t;x]
360         else
361             t=t+x
362         end
363     end,
364     if lmax>0&sum(length(t))<lmax then
365         t=strcat(t)
366     end
367     if m*n>1 then
368         t(1)="["+t(1)
369         t($)=t($)+"]"
370     end
371 endfunction
372
373 function t = glist2exp(listType, l, lmax)
374     [lhs,rhs] = argn(0)
375     if rhs<3 then lmax = 0, end
376     dots = "."+".";
377     isCell = typeof(l)=="ce";
378     if isCell then
379         s = size(l);
380         s = strcat(msprintf("%d\n",s(:)),",");  // Literal list of sizes
381         t = "makecell(";
382         if lmax>0 & (length(t) > (lmax-length(s)-4))
383             t = [t + dots; "["+s+"],.. "];
384         else
385             t = t + "["+s+"], ";
386         end
387         // ND-transposition needed due to makecell() special indexing:
388         if ndims(l)<3
389             l = l'
390         else
391             i = 1:ndims(l);
392             i([1 2]) = [2 1];
393             l = permute(l, i);
394         end
395         //
396         l = l{:};
397         L = length(l);
398     else
399         t = listType + "("
400         if or(listType==["list", "mlist", "tlist"]) then
401             L = length(l)
402         else
403              L = size(getfield(1,l),"*");
404         end
405     end
406     for k = 1:L
407         sep = ",", if k==1 then sep = "", end
408         clear lk
409         if listType ~= "mlist"
410             lk = l(k)
411         else
412             lk = getfield(k,l)
413         end
414         if ~isdef("lk","local")
415             t1 = ""
416         else
417             t1 = sci2exp(lk, lmax)
418         end
419         if size(t1,"*")==1&(lmax==0|max(length(t1))+length(t($))<lmax) then
420             t($) = t($)+sep+t1
421         else
422             t($) = t($)+sep+dots
423             t = [t; t1]
424         end
425     end
426     t($) = t($)+")"
427 endfunction
428
429 function t = list2exp(l, lmax)
430     t = glist2exp("list", l, lmax)
431 endfunction
432 function t = tlist2exp(l, lmax)
433     t = glist2exp("tlist", l, lmax)
434 endfunction
435 function t = mlist2exp(l, lmax)
436     t = glist2exp("mlist", l, lmax)
437 endfunction
438
439 function t = scalarstruct2exp(l, lmax)
440     if argn(2)<2 then lmax = 0, end
441     dots = "."+".";
442     t = "struct(";
443     fields = fieldnames(l);
444     n = size(fields,"*");
445     for i = 1:n
446         if ~lmax | lmax>(12+length(fields(i)))
447             t($) = t($) + """"+fields(i)+""",";
448         else
449             t($) = t($) + " " + dots;
450             t = [t; """"+fields(i)+""","];
451         end
452         clear lk
453         lk = l(fields(i));
454         if ~isdef("lk","local")
455             t1 = "";
456         else
457             t1 = sci2exp(lk, lmax)
458         end
459         if i<n then
460             tmp = ", ";
461         else
462             tmp = "";
463         end
464         if size(t1,"*")==1&(lmax==0|max(length(t1))+length(t($))<lmax) then
465             t($) = t($) + t1 + tmp;
466         else
467             t($) = t($) + " ..";
468             t = [t; t1 + tmp]
469         end
470     end
471     t($) = t($)+")"
472 endfunction
473
474 function t=log2exp(a,lmax)
475     $;
476     if rhs<2 then lmax = 0, end
477     [lhs,rhs] = argn(0)
478     [m,n]=size(a),
479     a1=matrix(a,m*n,1)
480     F="%f"
481     T="%t"
482     a=F(ones(m*n,1))
483     k=find(a1);
484     if k<>[] then
485         a(k)=T(ones(size(k,"*"),1));
486     end
487     a=matrix(a,m,n);
488     dots="."+"."
489     t=[];
490     for i=1:m
491         x=emptystr()
492         for j=1:n,
493             y=a(i,j);
494             if lmax==0|length(x($))+length(y)<lmax then
495                 if j==1 then
496                     x=y
497                 else
498                     x($)=x($)+","+y,
499                 end
500             else
501                 x($)=x($)+","+dots;
502                 x($+1)=y
503             end
504         end
505         t=[t;x]
506     end,
507     if lmax==0|lmax>0&sum(length(t))<lmax then
508         t=strcat(t,";")
509     end
510     if m*n>1 then
511         t(1)="["+t(1)
512         t($)=t($)+"]"
513     end
514
515 endfunction
516
517 function t=func2exp(a,lmax)
518     if rhs<2 then lmax=0,end
519     [lhs,rhs]=argn(0)
520     [out,in,text]=string(a)
521     if out==[] then out=emptystr(),end
522     text=str2exp(text,lmax)
523     nt=size(text,"*")
524     if named then mac=nom,else mac="mac",end
525     if nt==1 then
526         t="deff(''["+strcat(out,",")+"]="+mac+"("+strcat(in,",")+")'',"+text+")"
527     else
528         text($)=text($)+")"
529         semi=";"
530         text(1:$-1)=text(1:$-1)+semi(ones(nt-1,1))'
531         t=["deff(''["+strcat(out,",")+"]="+mac+"("+strcat(in,",")+")'',"+text(1)
532         text(2:$)]
533     end
534 endfunction
535
536 function t=imp2exp(a,lmax)
537     if rhs<2 then lmax=0,end
538     [lhs,rhs]=argn(0)
539     v=[a(1),a(2),a(3)]
540     if a(2)==1 then
541         t=sci2exp(a(1))+":"+sci2exp(a(3))
542     else
543         t=sci2exp(a(1))+":"+sci2exp(a(2))+":"+sci2exp(a(3))
544     end
545 endfunction
546
547 function t=sp2exp(a,lmax)
548     if rhs<2 then lmax=0,end
549     [lhs,rhs]=argn(0)
550     dots="..";
551     [ij,v,mn]=spget(a)
552     t=sci2exp(ij,lmax)
553     v=sci2exp(v,lmax)
554     mn=sci2exp(mn,lmax)
555
556     t(1)="sparse("+t(1)
557     if lmax==0|length(t($))+length(v(1))+1<lmax then
558         t($)=t($)+","+v(1)
559         t=[t;v(2:$)]
560     else
561         t($)=t($)+","+dots
562         t=[t;v]
563     end
564     if lmax==0|length(t($))+length(mn(1))+1<lmax then
565         t($)=t($)+","+mn(1)
566         t=[t;mn(2:$)]
567     else
568         t($)=t($)+","+dots
569         t=[t;mn]
570     end
571     t($)=t($)+")"
572 endfunction
573
574
575 function t=int2exp(a,lmax)
576     it=inttype(a)
577     if it>10 then f="uint",else f="int",end
578     f=f+string(8*modulo(it,10))
579     t=mat2exp(double(a),lmax)
580     t(1)=f+"("+t(1)
581     t($)=t($)+")"
582 endfunction
583
584
585 function t=h2exp(a,lmax) //Only for figure and uicontrol
586     $;
587     if rhs<2 then lmax=0
588     end
589     [lhs,rhs]=argn(0);
590
591     f1="''parent'', ";
592     f2="''children'', ";
593     f3="''BackgroundColor'', ";
594     f4="''Enable'', ";
595     f5="''fontAngle'', ";
596     f6="''fontName'', ";
597     f7="''fontSize'', ";
598     f8="''fontUnits'', ";
599     f9="''fontWeight'', ";
600     f10="''ForegroundColor'', ";
601     f11="''HorizontalAlignment'', ";
602     f12="''ListboxTop'', ";
603     f13="''Max'', ";
604     f14="''Min'', ";
605     f15="''Position'', ";
606     f16="''Relief'', ";
607     f17="''SliderStep'', ";
608     f18="''String'', ";
609     f19="''Style'', ";
610     f20="''TooltipString'', ";
611     f21="''Units'', ";
612     f22="''Value'', ";
613     f23="''VerticalAlignment'', ";
614     f24="''Visible'', ";
615     f25="''Callback'', ";
616     f26="''Callback_Type'', ";
617     f27="''Handle_Visible'', ";
618     f28="''Userdata'', ";
619     f29="''Tag'', ";
620     f30="''figure_position'', ";
621     f31="''figure_size'', ";
622     f32="''axes_size'', ";
623     f33="''auto_resize'', ";
624     f34="''viewport'', ";
625     f35="''figure_name'', ";
626     f36="''figure_id'', ";
627     f37="''info_message'', ";
628     f38="''color_map'', ";
629     f40="''pixel_drawing_mode'', ";
630     f41="''anti_aliasing'', ";
631     f42="''immediate_drawing'', ";
632     f43="''background'', ";
633     f44="''rotation_style'', ";
634     f45="''event_handler'', ";
635     f46="''event_handler_enable'', ";
636     f47="''resizefcn'', ";
637     f48="''closerequestfcn'', ";
638     x="";
639
640
641     if a.type=="uicontrol"
642         f="uicontrol";
643         if a.BackgroundColor <> [0.8 0.8 0.8] then
644             if type(a.BackgroundColor)==1 then
645                 f3_strg=String(a.Backgroundcolor);
646                 f3_strg="["+f3_strg(1)+" "+f3_strg(2)+" "+f3_strg(3)+"]";
647                 x=x+f3+f3_strg+", ";
648             else
649                 f3_strg=a.BackgroundColor;
650                 x=x+f3+"''"+f3_strg+"''"+", ";
651             end
652         end
653         if a.Enable <> "on" then x=x+f4+"''"+a.Enable+"''"+", "; end
654         if a.fontAngle <> "normal" then x=x+f5+"''"+a.fontAngle+"''"+", "; end
655         if a.fontName <> "helvetica" then x=x+f6+"''"+a.fontName+"''"+", "; end
656         f7_strg=String(a.fontSize);
657         if a.fontSize <> 10 then x=x+f7+f7_strg+", "; end
658         if a.fontUnits <> "points" then x=x+f8+"''"+a.fontUnits+"''"+", "; end
659         if a.fontWeight <> "normal" then x=x+f9+"''"+a.fontWeight+"''"+", "; end
660         if a.foregroundColor <>[0 0 0] then
661             if type(a.ForegroundColor)==1 then
662                 f10_strg=String(a.foregroundColor);
663                 f10_strg="["+f10_strg(1)+" "+f10_strg(2)+" "+f10_strg(3)+"]";
664                 x=x+f10+f10_strg+" ,";
665             else
666                 f10_strg=a.ForegroundColor;
667                 x=x+f10+"''"+f10_strg+"''"+", ";
668             end
669         end
670         if a.HorizontalAlignment <> "center" then x=x+f11+"''"+a.horizontalAlignment+"''"+", "; end
671         f12_strg=String(a.ListBoxTop);
672         if a.ListBoxTop <>[] then x=x+f12+f12_strg+", "; end
673         f13_strg=String(a.Max);
674         if a.max<> 1 then x=x+f13+f13_strg+", "; end
675         f14_strg=String(a.Min);
676         if a.min<> 0 then x=x+f14+f14_strg+", "; end
677         if a.Position <>[20 40 40 20] then
678             if type(a.Position)==1 then
679                 f15_strg=String(a.Position);
680                 f15_strg="["+f15_strg(1)+" "+f15_strg(2)+" "+f15_strg(3)+" "+f15_strg(4)+"]";
681                 x=x+f15+f15_strg+", ";
682             else
683                 f15_strg=a.Position;
684                 x=x+f15+"''"+f15_strg+"''"+", ";
685             end
686         end
687         x=x+f16+"''"+a.Relief+"''"+", ";
688         f17_strg=String(a.sliderStep); f17_strg="["+f17_strg(1)+" "+f17_strg(2)+"]";
689         if a.sliderStep <> [0.01 0.1] then x=x+f17+f17_strg+", "; end
690         if a.String <>"" then
691             if isempty(a.String)
692                 x = x + f18 + "'''' ,";
693             else
694                 x=x+f18+"''"+a.String+"''"+" ,";
695             end
696         end
697         if a.Style <> "pushbutton" then x=x+f19+"''"+a.Style+"''"+", "; end
698         if a.TooltipString <> "" then x=x+f20+"''"+a.TooltipString+"''"+", "; end
699         if a.Units <> "pixels" then x=x+f21+"''"+a.Units+"''"+", "; end
700         if a.Value<>[] then
701             f22_strg=String(a.value);
702             f22l=length(a.value);
703             for i=1:f22l
704                 f22_strg=strcat(f22_strg, ",");
705                 f22_strg="["+f22_strg+"]";
706             end
707             x=x+f22+", "+f22_strg+", ";
708         end
709         if a.VerticalAlignment <> "middle" then x=x+f23+"''"+a.VerticalAlignment+"''"+", "; end
710         if a.Visible <> "on" then x=x+f24+"''"+a.Visible+"''"+", "; end
711         if a.Callback <>"" then x=x+f25+"''"+a.Callback+"''"+" ,"; end
712         f26_strg=String(a.Callback_Type);
713         if a.Callback_Type <> -1 then x=x+f26+f26_strg+", "; end
714         if a.Handle_Visible <> "on" then x=x+f27+"''"+a.Handle_Visible+"''"+", "; end
715         if a.Userdata <>[] then
716             if type(a.userdata) == 1 then
717                 f28_strg=mat2exp(a.userdata,0)
718             elseif type(a.userdata) == 2 then
719                 f28_strg=pol2exp(a.userdata,0)
720             elseif type(a.userdata) == 4 then
721                 f28_strg=log2exp(a.userdata,0)
722             elseif type(a.userdata) == 5 | type(a.userdata) == 6 | type(a.userdata) == 7 then
723                 f28_strg=sp2exp(a.userdata,0)
724             elseif type(a.userdata) == 8 then
725                 f28_strg=int2exp(a.userdata,0)
726             elseif type(a.userdata) == 9 then
727                 f28_strg=h2exp(a.userdata,0)
728             elseif type(a.userdata) == 10 then
729                 f28_strg=str2exp(a.userdata,0)
730             elseif type(a.userdata) == 13 then
731                 if named then
732                     f28_strg=sci2exp(a.userdata,nom)
733                 else
734                     f28_strg=sci2exp(a.userdata,"%fun")
735                 end
736             elseif type(a.userdata) == 15 then
737                 f28_strg=list2exp(a.userdata);
738             elseif type(a.userdata) == 16 then
739                 f28_strg=tlist2exp(a.userdata,0);
740             elseif type(a.userdata) == 17 then
741                 f28_strg=mlist2exp(a.userdata,0);
742             elseif type(a.userdata) == 129 then
743                 f28_strg=imp2exp(a.userdata,0);
744             end
745             x=x+f28+f28_strg+", ";
746         end
747         if a.Tag<>"" then x=x+f29+"''"+a.Tag+"''"+", "; end
748         lx=length(x);
749         x=part(x,1:lx-2);
750         t(1)=f+"("+x;
751         t(1)=t(1)+")";
752         dots="."+".";
753         lt=length(t(1))
754         if lt>lmax & lmax<>0 then
755             ind=strindex(x,",");
756             k1=1;l=0;I=[];
757             while %t
758                 if lt-l<lmax|k1>length(ind) then break,end
759                 k2=k1-1+max(find(ind(k1:$)<l+lmax))
760                 I=[I ind(k2)];
761                 k1=k2+1
762                 l=ind(k2)
763             end
764             t=strsplit(t(1),I);
765             t(1:$-1)=t(1:$-1)+dots;
766         end
767
768
769     elseif a.type == "Figure" then
770         f="figure";
771         f30_strg=String(a.figure_position);
772         f30_strg="["+f30_strg(1)+" "+f30_strg(2)+"]";
773         if a.figure_position <> [] then x=f30+f30_strg+", "; end
774         f31_strg=String(a.figure_size);
775         f31_strg="["+f31_strg(1)+" "+f31_strg(2)+"]";
776         if a.figure_size <> [] then x=x+f31+f31_strg+", "; end
777         f32_strg=String(a.axes_size);
778         f32_strg="["+f32_strg(1)+" "+f32_strg(2)+"]";
779         if a.axes_size <> [] then x=x+f32+f32_strg+", "; end
780         if a.auto_resize<>"on" then x=x+f33+"''"+a.auto_resize+"''"+", "; end
781         f34_strg=String(a.viewport);
782         f34_strg="["+f34_strg(1)+" "+f34_strg(2)+"]";
783         if a.viewport <>[0 0] then x=x+f34+f34_strg+", "; end
784         if a.figure_name<>"Figure n°%d" then x=x+f35+"''"+a.figure_name+"''"+", ";
785         end
786         f36_strg=String(a.figure_id);
787         x=x+f36+f36_strg+", ";
788         if a.info_message<>"" then x=x+f37+"''"+a.info_message+"''"+", "; end
789         if a.pixel_drawing_mode <> "copy" then x=x+f40+"''"+a.pixel_drawing_mode+"''"+", "; end
790         if a.anti_aliasing <> "off" then x=x+f41+"''"+a.anti_aliasing+"''"+", "; end
791         if a.immediate_drawing <>"on" then x=x+f42+"''"+a.immediate_drawing+"''"+", "; end
792         f43_strg=String(f43);
793         if a.background <> 33 then x=x+f43+f43_strg+", "; end
794         if a.visible <> "on" then x=x+f24+"''"+a.visible+"''"+", "; end
795         if a.rotation_style <> "unary" then x=x+f44+"''"+a.rotation_style+"''"+", "; end
796         if a.event_handler <> "" then x=x+f45+"''"+a.event_handler+"''"+", "; end
797         if a.event_handler_enable <> "off" then x=x+f46+"''"+a.event_handler_enable+"''"+", "; end
798         if a.userdata <> [] then
799             if type(a.userdata) == 1 then
800                 f47_strg=mat2exp(a.userdata,0)
801             elseif type(a.userdata) == 2 then
802                 f47_strg=pol2exp(a.userdata,0)
803             elseif type(a.userdata) == 4 then
804                 f47_strg=log2exp(a.userdata,0)
805             elseif type(a.userdata) == 5 | type(a.userdata) == 6 | type(a.userdata) == 7 then
806                 f47_strg=sp2exp(a.userdata,0)
807             elseif type(a.userdata) == 8 then
808                 f47_strg=int2exp(a.userdata,0)
809             elseif type(a.userdata) == 9 then
810                 f47_strg=h2exp(a.userdata,0)
811             elseif type(a.userdata) == 10 then
812                 f47_strg=str2exp(a.userdata,0)
813             elseif type(a.userdata) == 13 then
814                 if named then
815                     f47_strg=sci2exp(a.userdata,nom)
816                 else
817                     f47_strg=sci2exp(a.userdata,"%fun")
818                 end
819             elseif type(a.userdata) == 15 then
820                 f47_strg=list2exp(a.userdata);
821             elseif type(a.userdata) == 16 then
822                 f47_strg=tlist2exp(a.userdata,0)
823             elseif type(a.userdata) == 17 then
824                 f47_strg=mlist2exp(a.userdata,0)
825             elseif type(a.userdata) == 129 then
826                 f47_strg=imp2exp(a.userdata,0)
827             end
828             x=x+f28+f47_strg+", ";
829         end
830         if a.resizefcn <> "" then x=x+f47+"''"+a.resizefcn+"''"+", "; end
831         if a.closerequestfcn <> "" then x=x+f48+"''"+a.closerequestfcn+"''"+", "; end
832         if a.tag <> "" then x=x+f27+"''"+a.tag+"''"+", "; end
833         lx=length(x);
834         x=part(x,1:lx-2);
835         t(1)=f+"("+x;
836         t(1)=t(1)+")";
837         dots="."+".";
838         lt=length(t(1))
839         if lt>lmax & lmax<>0 then
840             ind=strindex(x,",");
841             k1=1;l=0;I=[];
842             while %t
843                 if lt-l<lmax|k1>length(ind) then break,end
844                 k2=k1-1+max(find(ind(k1:$)<l+lmax))
845                 I=[I ind(k2)];
846                 k1=k2+1
847                 l=ind(k2)
848             end
849             t=strsplit(t(1),I);
850             t(1:$-1)=t(1:$-1)+dots;
851         end
852     else
853         msg = _("%s: This feature has not been implemented: Variable translation of type %s.\n")
854         error(msprintf(msg,"sci2exp",string(a.type)));
855     end
856
857 endfunction
858
859 function ml = user2mlist(u)
860     fn = getfield(1, u);
861     ml = mlist(fn);
862
863     for k = 1:size(fn,"*")
864         ml(k) = u(fn(k));
865     end
866 endfunction