~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to tcl/scipadsources/FormatStringsForDebugWatch.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
// to TCL/TK.
 
8
// Author: Fran�ois Vogel, 2004
 
9
 
 
10
  if argn(2) == 0 then error(39); else var = varargin(1); end
 
11
 
 
12
  tvar = type(var);
 
13
 
 
14
  if tvar<>1 & tvar<>2 & tvar<>4 & tvar<>5 & tvar<>6 & tvar<>8 & tvar<>10 & tvar<>15 & tvar<>16 & tvar<>17 then
 
15
    // unsupported cases
 
16
    error("FormatStringsForDebugWatch: type not handled");
 
17
 
 
18
  else
 
19
    // supported cases
 
20
    svar = emptystr();
 
21
 
 
22
    if tvar == 6 then tvar = 5; end;  // this is to use the same code for sparse matrices and boolean sparse matrices
 
23
 
 
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;
 
27
 
 
28
    select tvar
 
29
 
 
30
    case 1 then  // real or complex matrix
 
31
      varstr = string(var);
 
32
      if prod(size(var)) > 1 then
 
33
        for i = 1:size(varstr,'r')
 
34
          oneline = strcat(varstr(i,:)," ");
 
35
          svar = svar + oneline + ";";
 
36
        end
 
37
        svar = part(svar,1:length(svar)-1);
 
38
        svar = "\[" + svar + "\]";
 
39
      elseif var == [] then
 
40
        svar = "\[\]";
 
41
      else
 
42
        svar = varstr;
 
43
      end
 
44
 
 
45
    case 2 then  // polynomial matrix
 
46
      if prod(size(var)) > 1 then
 
47
        svar = MatFormatStringsForDebugWatch(var);
 
48
      else
 
49
        co = strcat(string(coeff(var))," ");
 
50
        if degree(var) > 0 then
 
51
          varstr = string(var);
 
52
          poltok = tokens(varstr(2));
 
53
          unknown = part(poltok($),length(poltok($)));
 
54
        else
 
55
          unknown = "x";
 
56
        end
 
57
        svar = "poly(\[" + co + "\],\""" + unknown + "\"",\""coeff\"")";
 
58
      end
 
59
 
 
60
    case 4 then  // boolean matrix
 
61
      varstr = string(var);
 
62
      if prod(size(var)) > 1 then
 
63
        for i = 1:size(varstr,'r')
 
64
          oneline = strcat(varstr(i,:)," %");
 
65
          svar = svar + "%" + oneline + ";";
 
66
        end
 
67
        svar = part(svar,1:length(svar)-1);
 
68
        svar = "\[" + svar + "\]";
 
69
      else
 
70
        svar = "%" + varstr;
 
71
      end
 
72
 
 
73
    case 5 then  // sparse matrix, or boolean sparse matrix (type 6 changed into 5 above)
 
74
      [ij,v,mn]=spget(var);
 
75
      ind = FormatStringsForDebugWatch(ij);
 
76
      vec = FormatStringsForDebugWatch(v);
 
77
      dim = FormatStringsForDebugWatch(mn);
 
78
      svar = "sparse(" + ind + "," + vec + "," + dim + ")";
 
79
 
 
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);
 
83
        it = inttype(var);
 
84
        if it > 10 then it = it - 10; pre = "u"; else pre = emptystr(); end
 
85
        nbits = it*8;
 
86
        svar = pre + "int" + string(nbits) + "(" + svar + ")";
 
87
      else
 
88
        svar = string(var);
 
89
      end
 
90
 
 
91
    case 10 then  // character string matrix
 
92
      if prod(size(var)) > 1 then
 
93
        svar = MatFormatStringsForDebugWatch(var);
 
94
      else
 
95
        svar = "\""" + strsubst(string(var),"''","''''") + "\""";
 
96
      end
 
97
 
 
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()";
 
100
      else
 
101
        for i = 1:length(var)
 
102
          ie = execstr("getfield(i,var)","errcatch");  // catch the undefined items
 
103
          if ie <> 117 then
 
104
            svar = svar + FormatStringsForDebugWatch(getfield(i,var)) + ",";
 
105
          else
 
106
            svar = svar + "\""Undefined\"",";  // Well, this actually defines this element as a string
 
107
          end
 
108
        end
 
109
        svar = part(svar,1:length(svar)-1);
 
110
        svar = listpref + "list(" + svar + ")";
 
111
      end
 
112
 
 
113
    end
 
114
    
 
115
  end
 
116
 
 
117
endfunction
 
118
 
 
119
 
 
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)
 
125
  svar = emptystr();
 
126
  for i = 1:size(var,'r')
 
127
    oneline = emptystr();
 
128
    for j = 1:size(var,'c')
 
129
      oneline = oneline + FormatStringsForDebugWatch(var(i,j)) + " ";
 
130
    end
 
131
    svar = svar + part(oneline,1:length(oneline)-1) + ";";
 
132
  end
 
133
  svar = part(svar,1:length(svar)-1);
 
134
  svar = "\[" + svar + "\]";
 
135
endfunction