summaryrefslogtreecommitdiffstats
path: root/scilab/modules/core
diff options
context:
space:
mode:
authorAllan CORNET <allan.cornet@scilab.org>2010-04-12 16:20:37 +0200
committerAllan CORNET <allan.cornet@scilab.org>2010-04-13 15:22:05 +0200
commit7431fdaa18f681f36aaa84b40b8df70bd62ed983 (patch)
treec12105673267ee8bb492303c32992b752f5222f9 /scilab/modules/core
parent1f549a2ede0ab2740da75874ddcf1ac31184d686 (diff)
downloadscilab-7431fdaa18f681f36aaa84b40b8df70bd62ed983.zip
scilab-7431fdaa18f681f36aaa84b40b8df70bd62ed983.tar.gz
bug 6891
Change-Id: Ia241d3318291ee3eaaeee0119b3e592b26dea3a9
Diffstat (limited to 'scilab/modules/core')
-rw-r--r--scilab/modules/core/macros/whos.sci176
-rw-r--r--scilab/modules/core/tests/nonreg_tests/bug_6891.dia.ref27
-rw-r--r--scilab/modules/core/tests/nonreg_tests/bug_6891.tst19
3 files changed, 177 insertions, 45 deletions
diff --git a/scilab/modules/core/macros/whos.sci b/scilab/modules/core/macros/whos.sci
index 4628b3f..cf966fd 100644
--- a/scilab/modules/core/macros/whos.sci
+++ b/scilab/modules/core/macros/whos.sci
@@ -1,66 +1,152 @@
1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) INRIA 2// Copyright (C) INRIA
3// Copyright (C) DIGITEO - 2010 - Allan CORNET
3// 4//
4// This file must be used under the terms of the CeCILL. 5// 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// 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// you should have received as part of this distribution. The terms
7// are also available at 8// are also available at
8// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt 9// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
9 10//=============================================================================
10function whos(%_opt,%_sel) 11function whos(%_opt,%_sel)
11//display defined variable in a long form
12 12
13//get the variables 13 // get the variables local & global
14 [%_nams,%_vol]=who('get'); 14 [%_nams, %_vol] = who('local');
15 [%_lhs,%_rhs]=argn(); 15 [%_nams_global, %_vol_global] = who('global');
16 if %_rhs==1 then error(msprintf(gettext("%s: Wrong number of input arguments: %d or %d expected.\n"),"whos",0, 2)),end 16
17 if %_rhs==2 then 17//=============================================================================
18 %_nams($-1:$)=[], 18// getSizeAsString, writeWhosLine, doDisplayWhosLine defined only in whos
19 if %_opt<>'-type'&%_opt<>'-name' then 19// to remove some tmp variables defined on stack
20 error(msprintf(gettext("%s: Wrong value for input argument #%d: ''%s'' or ''%s'' expected.\n"),"whos",1,"-name","-type")) 20//=============================================================================
21function sz = getSizeAsString(_varname, _type)
22 sz = ' ';
23 if _type == 0 then
24 sz = '?';
25 elseif _type <= 10 then
26 execstr('sz = size(' + _varname + ');')
27 elseif _type == 17 | _type == 16 then
28 execstr('%_tt = getfield(1,' + _varname + ')');
29 %_tt = %_tt(1);
30 ierr = execstr('sz = %' + %_tt + 'size(' + _varname + ')', 'errcatch');
31 if ierr <> 0 then
32 sz = '?'
33 end
34 end
35endfunction
36//=============================================================================
37function writeWhosLine(_name, _namedtype, _sz, _bytes)
38 write(%io(2),part(_name, 1:25) + part(_namedtype,1:15) + ..
39 part(strcat(string(_sz),' by '), 1:15) + ..
40 part(string(_bytes), 1:13));
41endfunction
42//=============================================================================
43function bOK = doDisplayWhosLine(_rhs, _opt, _name, _namedtype, _sel)
44 bOK = %t;
45 if _rhs == 2 then
46 if _opt == '-type' then
47 if _namedtype <> _sel then
48 bOK = %f;
49 end
50 elseif _opt == '-name' then
51 if part(_name, 1:length(_sel)) <> _sel then
52 bOK = %f;
53 end
21 end 54 end
55 else
56 bOK = %t;
22 end 57 end
58endfunction
59//=============================================================================
60
61 // display defined variable in a long form
62
63 [%_lhs, %_rhs] = argn();
64
65 if %_rhs == 0 then
66 %_opt = [];
67 %_sel = [];
68 end
69
70 if %_rhs == 1 then
71 error(msprintf( ..
72 gettext("%s: Wrong number of input arguments: %d or %d expected.\n"), ..
73 "whos", 0, 2));
74 end
75
76 if %_rhs == 2 then
77 %_nams($-1:$) = [];
78 if %_opt <> '-type' & %_opt <> '-name' then
79 error(msprintf( ..
80 gettext( "%s: Wrong value for input argument #%d: ''%s'' or ''%s'' expected.\n"), ..
81 "whos", 1, "-name", "-type"));
82 end
83 end
84
23 //write the display header 85 //write the display header
24 write(%io(2),part('Name',1:25)+.. 86 write(%io(2),part('Name',1:25) + ..
25 part('Type',1:15)+.. 87 part('Type',1:15) + ..
26 part('Size',1:15)+.. 88 part('Size',1:15) + ..
27 part('Bytes',1:13)) 89 part('Bytes',1:13))
90
28 write(%io(2),' ') 91 write(%io(2),' ')
92
93 %_typn = '';
94 %_typ = 0;
95 b_ok = %f;
29 96
30 //loop on variables 97 // loop on local variables
31 for %_k=1:size(%_nams,1) 98 for %_k = 1:size(%_nams, 1)
32 %_sz=' ' 99 %_sz = ' ';
33 if execstr('%_typ=type('+%_nams(%_k)+')','errcatch')==228 then 100 %_typn = '';
34 %_typ=0 101 %_typ = 0;
35 %_typn='*deleted' 102 b_ok = %f;
36 else 103
37 execstr('%_typn=typeof('+%_nams(%_k)+')') 104 execstr('%_typn = typeof(' + %_nams(%_k) + ')');
38 execstr('%_isg=isglobal('+%_nams(%_k)+')') 105 if execstr('%_typ = type(' + %_nams(%_k) + ')','errcatch') == 228 then
39 if %_isg then %_typn='*'+%_typn,end 106 %_typ = 0;
107 %_typn = '*deleted';
108 else
109 execstr('%_typn = typeof(' + %_nams(%_k) + ')');
40 end 110 end
41 %_ok=%t 111
42 if %_rhs==2 then 112 %_sz = getSizeAsString(%_nams(%_k), %_typ);
43 if %_opt=='-type' then 113 b_ok = doDisplayWhosLine(%_rhs, %_opt, %_nams(%_k), %_typn, %_sel);
44 if %_typn<>%_sel then %_ok=%f,end 114
45 elseif %_opt=='-name' then 115 if b_ok then
46 if part(%_nams(%_k),1:length(%_sel))<>%_sel then %_ok=%f,end 116 writeWhosLine(%_nams(%_k), %_typn, %_sz, %_vol(%_k)*8);
47 end
48 end 117 end
118 end
119
120 // loop on global variables
121 for %_k = 1:size(%_nams_global, 1)
122 %_sz = ' ';
123 %_typn = '';
124 %_typ = 0;
125 b_ok = %f;
126 bDoClear = %f;
49 127
50 if %_ok then 128 if isdef(%_nams_global(%_k)) then
51 if %_typ==0 then 129 execstr('%_typ = type(' + %_nams_global(%_k) + ')');
52 %_sz='?' 130 execstr('%_typn = typeof(' + %_nams_global(%_k) + ')');
53 elseif %_typ<=10 then 131 else
54 execstr('%_sz=size('+%_nams(%_k)+');') 132 execstr('global ' + %_nams_global(%_k));
55 elseif %_typ==17|%_typ==16 then 133 execstr('%_typ = type(' + %_nams_global(%_k) + ')');
56 execstr('%_tt=getfield(1,'+%_nams(%_k)+')');%_tt=%_tt(1) 134 execstr('%_typn = typeof(' + %_nams_global(%_k) + ')');
57 ierr=execstr('%_sz=%'+%_tt+'_size('+%_nams(%_k)+')','errcatch') 135 bDoClear = %t;
58 if ierr<>0 then %_sz='?',end 136 end
59 end 137
60 138 %_typn = '*' + %_typn;
61 write(%io(2),part(%_nams(%_k),1:25)+part(%_typn,1:15)+.. 139 %_sz = getSizeAsString(%_nams_global(%_k), %_typ);
62 part(strcat(string(%_sz),' by '),1:15)+.. 140
63 part(string(%_vol(%_k)*8),1:13)) 141 if bDoClear then
142 execstr('clear ' + %_nams_global(%_k));
143 end
144
145 b_ok = doDisplayWhosLine(%_rhs, %_opt, %_nams_global(%_k), %_typn, %_sel);
146
147 if b_ok then
148 writeWhosLine(%_nams_global(%_k), %_typn, %_sz, %_vol_global(%_k)*8);
64 end 149 end
65 end 150 end
66endfunction 151endfunction
152//=============================================================================
diff --git a/scilab/modules/core/tests/nonreg_tests/bug_6891.dia.ref b/scilab/modules/core/tests/nonreg_tests/bug_6891.dia.ref
new file mode 100644
index 0000000..e8319d8
--- /dev/null
+++ b/scilab/modules/core/tests/nonreg_tests/bug_6891.dia.ref
@@ -0,0 +1,27 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2010 - DIGITEO - Allan CORNET
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7// <-- Non-regression test for bug 6891 -->
8//
9// <-- Bugzilla URL -->
10// http://bugzilla.scilab.org/show_bug.cgi?id=6891
11//
12// <-- Short Description -->
13// whos did not display global variables
14whos -name %modalWarning
15Name Type Size Bytes
16
17%modalWarning *boolean 1 by 1 24
18whos -name corel
19Name Type Size Bytes
20
21corelib library 688
22whos -type polynomial
23Name Type Size Bytes
24
25%z polynomial 1 by 1 56
26%s polynomial 1 by 1 56
27$ polynomial 1 by 1 56
diff --git a/scilab/modules/core/tests/nonreg_tests/bug_6891.tst b/scilab/modules/core/tests/nonreg_tests/bug_6891.tst
new file mode 100644
index 0000000..5afcab6
--- /dev/null
+++ b/scilab/modules/core/tests/nonreg_tests/bug_6891.tst
@@ -0,0 +1,19 @@
1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2010 - DIGITEO - Allan CORNET
4//
5// This file is distributed under the same license as the Scilab package.
6// =============================================================================
7
8// <-- Non-regression test for bug 6891 -->
9//
10// <-- Bugzilla URL -->
11// http://bugzilla.scilab.org/show_bug.cgi?id=6891
12//
13// <-- Short Description -->
14// whos did not display global variables
15
16whos -name %modalWarning
17whos -name corel
18
19whos -type polynomial