1
function [svar] = FormatStringsForDebugWatch(varargin)
2
// Converts input variable into a single string (not a matrix of strings),
3
// taking into account its type.
4
// This is used for the watch window of the debugger in Scipad.
5
// The output string is identical to what the user would have typed in the
6
// Scilab shell, apart from some extra characters needed to pass the string
8
// Author: Fran�ois Vogel, 2004
10
if argn(2) == 0 then error(39); else var = varargin(1); end
14
if tvar<>1 & tvar<>2 & tvar<>4 & tvar<>5 & tvar<>6 & tvar<>8 & tvar<>10 & tvar<>15 & tvar<>16 & tvar<>17 then
16
error("FormatStringsForDebugWatch: type not handled");
22
if tvar == 6 then tvar = 5; end; // this is to use the same code for sparse matrices and boolean sparse matrices
24
listpref = emptystr(); // this is to use the same code for lists, tlists and mlists
25
if tvar == 16 then tvar = 15; listpref = "t"; end;
26
if tvar == 17 then tvar = 15; listpref = "m"; end;
30
case 1 then // real or complex matrix
32
if prod(size(var)) > 1 then
33
for i = 1:size(varstr,'r')
34
oneline = strcat(varstr(i,:)," ");
35
svar = svar + oneline + ";";
37
svar = part(svar,1:length(svar)-1);
38
svar = "\[" + svar + "\]";
45
case 2 then // polynomial matrix
46
if prod(size(var)) > 1 then
47
svar = MatFormatStringsForDebugWatch(var);
49
co = strcat(string(coeff(var))," ");
50
if degree(var) > 0 then
52
poltok = tokens(varstr(2));
53
unknown = part(poltok($),length(poltok($)));
57
svar = "poly(\[" + co + "\],\""" + unknown + "\"",\""coeff\"")";
60
case 4 then // boolean matrix
62
if prod(size(var)) > 1 then
63
for i = 1:size(varstr,'r')
64
oneline = strcat(varstr(i,:)," %");
65
svar = svar + "%" + oneline + ";";
67
svar = part(svar,1:length(svar)-1);
68
svar = "\[" + svar + "\]";
73
case 5 then // sparse matrix, or boolean sparse matrix (type 6 changed into 5 above)
75
ind = FormatStringsForDebugWatch(ij);
76
vec = FormatStringsForDebugWatch(v);
77
dim = FormatStringsForDebugWatch(mn);
78
svar = "sparse(" + ind + "," + vec + "," + dim + ")";
80
case 8 then // 1, 2 or 4-bytes integer matrix (this works for 1 to 10-bytes int or uint)
81
if prod(size(var)) > 1 then
82
svar = MatFormatStringsForDebugWatch(var);
84
if it > 10 then it = it - 10; pre = "u"; else pre = emptystr(); end
86
svar = pre + "int" + string(nbits) + "(" + svar + ")";
91
case 10 then // character string matrix
92
if prod(size(var)) > 1 then
93
svar = MatFormatStringsForDebugWatch(var);
95
svar = "\""" + strsubst(string(var),"''","''''") + "\""";
98
case 15 then // list or tlist or mlist (types 16 and 17 changed into 15 above)
99
if length(var) == 0 then svar = listpref + "list()";
101
for i = 1:length(var)
102
ie = execstr("getfield(i,var)","errcatch"); // catch the undefined items
104
svar = svar + FormatStringsForDebugWatch(getfield(i,var)) + ",";
106
svar = svar + "\""Undefined\"","; // Well, this actually defines this element as a string
109
svar = part(svar,1:length(svar)-1);
110
svar = listpref + "list(" + svar + ")";
120
function [svar] = MatFormatStringsForDebugWatch(var)
121
// Ancillary for FormatStringsForDebugWatch
122
// Calls FormatStringsForDebugWatch for each element of matrix var,
123
// and properly formats the resulting string as if the user would have
124
// typed it into the Scilab shell (apart from added \ chars)
126
for i = 1:size(var,'r')
127
oneline = emptystr();
128
for j = 1:size(var,'c')
129
oneline = oneline + FormatStringsForDebugWatch(var(i,j)) + " ";
131
svar = svar + part(oneline,1:length(oneline)-1) + ";";
133
svar = part(svar,1:length(svar)-1);
134
svar = "\[" + svar + "\]";