localization (compatibility_functions module)
[scilab.git] / scilab / modules / compatibility_functions / macros / mtlb_fprintf.sci
1 function count = mtlb_fprintf(varargin)
2 // Copyright INRIA
3 // Emulation function for fprintf() Matlab function
4 // S.S. V.C.
5
6 [lhs,rhs]=argn()
7
8 count=0
9 // No fid given: mtlb_fprintf(fmt,...)
10 // Output is the screen
11
12 if size(varargin)==1 & type(varargin(1))==10 then
13 mprintf("%s \n",varargin(1))
14 count=length(varargin(1))
15 elseif type(varargin(1))==10 then
16   fmt=varargin(1)
17   nfmt=size(strindex(fmt,"%"),"*")
18   nv=size(varargin)-1
19   if nv==1 then
20     a=varargin(2)
21     na=size(a,"*")
22     
23     // If more values than formats
24     mult=max(na/nfmt,1)
25     fmt=strcat(fmt(ones(1,mult))) // duplicate format
26     
27     l=list()
28     A=a
29     for k=1:size(a,"*")
30       l($+1)=A(k)
31     end
32     mprintf(fmt,l(:))
33     count=size(a,"*")
34   elseif nv==0 then
35     error(msprintf(gettext("errors","compatibility_functions_error_42"),fmt));
36   else
37     sz=[]
38     for k=1:nv
39       sz=[sz size(varargin(k+1),1)]
40     end
41     // Size of args is verified because Scilab mprintf function
42     // does not work if args have more than one row
43     if and(sz==1) then // All args have only one row
44       mult=max(nv/nfmt,1)
45       fmt=strcat(fmt(ones(1,mult))) // duplicate format 
46       mprintf(fmt,varargin(2:$))
47       count=size(sz,"*")
48     else
49       error(gettext("errors","compatibility_functions_error_43"))
50     end
51   end  
52 // mtlb_fprintf(fid,fmt,...)
53 else 
54   fid=varargin(1)
55   fmt=varargin(2)
56   
57   // count % in fmt
58   nfmt=size(strindex(fmt,"%"),"*")
59   nv=size(varargin)-2
60   if nv==1 then
61     a=varargin(3)
62     na=size(a,"*")
63     
64     mult=max(na/nfmt,1)
65     
66     fmt=strcat(fmt(ones(1,mult))) // duplicate format
67     
68     l=list()
69     for k=1:size(a,"*")
70       l(k)=a(k)
71     end
72     if or(fid==[1 2]) then
73       mprintf(fmt,l(:))
74       count=size(a,"*")
75     else
76       mfprintf(fid,fmt,l(:))
77       count=size(a,"*")
78     end
79   elseif nv==0 & nfmt==0 & type(varargin(2))==10
80     mfprintf(fid,"%s",varargin(2))
81     count=length(varargin(2))
82   elseif nv==0 then
83     if or(fid==[1 2]) then
84       error(gettext("errors","compatibility_functions_error_44"))
85     else
86       error(gettext("errors","compatibility_functions_error_45"))
87     end 
88   else
89     sz=[]
90     for k=1:nv
91       sz=[sz size(varargin(k+2),1)]
92     end
93     if and(sz==1) then
94       mult=max(nv/nfmt,1)
95       fmt=strcat(fmt(ones(1,mult))) // duplicate format 
96       
97       if or(fid==[1 2]) then
98         mprintf(fmt,varargin(3:$))
99         count=size(sz,"*")
100       else
101         mfprintf(fid,fmt,varargin(3:$))
102         count=size(sz,"*")
103       end
104     else
105       if or(fid==[1 2]) then
106         error(gettext("errors","compatibility_functions_error_43"))
107       else
108         mfprintfMat(fid,varargin(3:$),fmt)
109         for k=1:nv
110           count=count+size(varargin(k+2),"*")
111         end
112       end 
113     end
114   end
115 end
116 endfunction