annotate libinterp/corefcn/syminfo.cc @ 31241:5ea5fe592a9a

Don't delete labels when reordering of axes children (bug #63117) * graphics.in.h (children_property::do_set): Avoid using a temporary variable for new children list. Rephrase error message to be more accurate. Always return true for clarity.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Tue, 27 Sep 2022 23:30:54 +0200
parents 796f54d4ddbf
children e88a07dec498
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29856
diff changeset
3 // Copyright (C) 2018-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #if defined (HAVE_CONFIG_H)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 # include "config.h"
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #endif
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include <iomanip>
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include <list>
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include <ostream>
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include <sstream>
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include "Cell.h"
27130
396d17dcfb9f don't include error.h in ov-base.h
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
36 #include "error.h"
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 #include "octave-preserve-stream-state.h"
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 #include "ov.h"
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include "oct-map.h"
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include "pager.h"
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 #include "syminfo.h"
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 namespace octave
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 void
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46 symbol_info::display_line (std::ostream& os,
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 const std::list<whos_parameter>& params) const
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 std::string dims_str = m_value.get_dims_str ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 auto i = params.begin ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
53 preserve_stream_state stream_state (os);
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 while (i != params.end ())
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 whos_parameter param = *i;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 if (param.command != '\0')
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 // Do the actual printing.
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 switch (param.modifier)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 case 'l':
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 os << std::setiosflags (std::ios::left)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 << std::setw (param.parameter_length);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68 break;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 case 'r':
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 os << std::setiosflags (std::ios::right)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 << std::setw (param.parameter_length);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 break;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 case 'c':
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 if (param.command == 's')
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 int front = param.first_parameter_length
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
79 - dims_str.find ('x');
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 int back = param.parameter_length
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
81 - dims_str.length ()
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
82 - front;
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 front = (front > 0) ? front : 0;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 back = (back > 0) ? back : 0;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 os << std::setiosflags (std::ios::left)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 << std::setw (front)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88 << ""
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 << std::resetiosflags (std::ios::left)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 << dims_str
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 << std::setiosflags (std::ios::left)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 << std::setw (back)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 << ""
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94 << std::resetiosflags (std::ios::left);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 else
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98 os << std::setiosflags (std::ios::left)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 << std::setw (param.parameter_length);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 break;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 default:
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 error ("whos_line_format: modifier '%c' unknown",
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 param.modifier);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 switch (param.command)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 case 'a':
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 {
29856
56b3e2af0298 Add 's'=sparse attribute for whos function (bug #60687)
Rik <rik@octave.org>
parents: 29572
diff changeset
112 char tmp[6];
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113
26659
8fbda39ca075 eliminate "automatic" type from symbol info class
John W. Eaton <jwe@octave.org>
parents: 26658
diff changeset
114 tmp[0] = (m_is_complex ? 'c' : ' ');
29856
56b3e2af0298 Add 's'=sparse attribute for whos function (bug #60687)
Rik <rik@octave.org>
parents: 29572
diff changeset
115 tmp[1] = (m_is_sparse ? 's' : ' ');
56b3e2af0298 Add 's'=sparse attribute for whos function (bug #60687)
Rik <rik@octave.org>
parents: 29572
diff changeset
116 tmp[2] = (m_is_formal ? 'f' : ' ');
56b3e2af0298 Add 's'=sparse attribute for whos function (bug #60687)
Rik <rik@octave.org>
parents: 29572
diff changeset
117 tmp[3] = (m_is_global ? 'g' : ' ');
56b3e2af0298 Add 's'=sparse attribute for whos function (bug #60687)
Rik <rik@octave.org>
parents: 29572
diff changeset
118 tmp[4] = (m_is_persistent ? 'p' : ' ');
56b3e2af0298 Add 's'=sparse attribute for whos function (bug #60687)
Rik <rik@octave.org>
parents: 29572
diff changeset
119 tmp[5] = 0;
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 os << tmp;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 break;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 case 'b':
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 os << m_value.byte_size ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 break;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 case 'c':
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 os << m_value.class_name ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 break;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 case 'e':
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 os << m_value.numel ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 break;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 case 'n':
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 os << m_name;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 break;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 case 's':
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142 if (param.modifier != 'c')
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 os << dims_str;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 break;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
145
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146 case 't':
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 os << m_value.type_name ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148 break;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150 default:
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 error ("whos_line_format: command '%c' unknown",
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 param.command);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 os << std::resetiosflags (std::ios::left)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156 << std::resetiosflags (std::ios::right);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 i++;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 else
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161 os << param.text;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
162 i++;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
163 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
164 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
165 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166
26117
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 26088
diff changeset
167 // FIXME: should we be using std::map<symbol_info> instead of a list?
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 26088
diff changeset
168
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 26088
diff changeset
169 octave_value symbol_info_list::varval (const std::string& name) const
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 26088
diff changeset
170 {
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 26088
diff changeset
171 for (const auto& syminfo : m_lst)
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 26088
diff changeset
172 {
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 26088
diff changeset
173 if (name == syminfo.name ())
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 26088
diff changeset
174 return syminfo.value ();
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 26088
diff changeset
175 }
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 26088
diff changeset
176
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 26088
diff changeset
177 return octave_value ();
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 26088
diff changeset
178 }
a6df420457ac use symbol_info_list instead of symbol_scope to pass workspace info to gui
John W. Eaton <jwe@octave.org>
parents: 26088
diff changeset
179
26657
be909a861e52 new symbol_info method to list names
John W. Eaton <jwe@octave.org>
parents: 26433
diff changeset
180 std::list<std::string> symbol_info_list::names (void) const
be909a861e52 new symbol_info method to list names
John W. Eaton <jwe@octave.org>
parents: 26433
diff changeset
181 {
be909a861e52 new symbol_info method to list names
John W. Eaton <jwe@octave.org>
parents: 26433
diff changeset
182 std::list<std::string> retval;
be909a861e52 new symbol_info method to list names
John W. Eaton <jwe@octave.org>
parents: 26433
diff changeset
183
be909a861e52 new symbol_info method to list names
John W. Eaton <jwe@octave.org>
parents: 26433
diff changeset
184 for (const auto& syminfo : m_lst)
be909a861e52 new symbol_info method to list names
John W. Eaton <jwe@octave.org>
parents: 26433
diff changeset
185 retval.push_back (syminfo.name ());
be909a861e52 new symbol_info method to list names
John W. Eaton <jwe@octave.org>
parents: 26433
diff changeset
186
be909a861e52 new symbol_info method to list names
John W. Eaton <jwe@octave.org>
parents: 26433
diff changeset
187 return retval;
be909a861e52 new symbol_info method to list names
John W. Eaton <jwe@octave.org>
parents: 26433
diff changeset
188 }
be909a861e52 new symbol_info method to list names
John W. Eaton <jwe@octave.org>
parents: 26433
diff changeset
189
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190 octave_map
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 symbol_info_list::map_value (const std::string& caller_function_name,
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192 int nesting_level) const
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193 {
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
194 std::size_t len = m_lst.size ();
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196 Cell name_info (len, 1);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197 Cell size_info (len, 1);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
198 Cell bytes_info (len, 1);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199 Cell class_info (len, 1);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200 Cell global_info (len, 1);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201 Cell sparse_info (len, 1);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202 Cell complex_info (len, 1);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203 Cell nesting_info (len, 1);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204 Cell persistent_info (len, 1);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
206 std::size_t j = 0;
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 for (const auto& syminfo : m_lst)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210 octave_scalar_map ni;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
212 ni.assign ("function", caller_function_name);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213 ni.assign ("level", nesting_level);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215 name_info(j) = syminfo.name ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216 global_info(j) = syminfo.is_global ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 persistent_info(j) = syminfo.is_persistent ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219 octave_value val = syminfo.value ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221 size_info(j) = val.size ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
222 bytes_info(j) = val.byte_size ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
223 class_info(j) = val.class_name ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224 sparse_info(j) = val.issparse ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225 complex_info(j) = val.iscomplex ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226 nesting_info(j) = ni;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
228 j++;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
229 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
230
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
231 octave_map info;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
232
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233 info.assign ("name", name_info);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
234 info.assign ("size", size_info);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235 info.assign ("bytes", bytes_info);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
236 info.assign ("class", class_info);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
237 info.assign ("global", global_info);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
238 info.assign ("sparse", sparse_info);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
239 info.assign ("complex", complex_info);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
240 info.assign ("nesting", nesting_info);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241 info.assign ("persistent", persistent_info);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
242
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
243 return info;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
245
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
246 void
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
247 symbol_info_list::print_descriptor (std::ostream& os,
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
248 const std::list<whos_parameter> params) const
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
249 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
250 std::ostringstream param_buf;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
251
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26659
diff changeset
252 preserve_stream_state stream_state (os);
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
253
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
254 for (const auto& param : params)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
255 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
256 if (param.command != '\0')
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
257 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
258 // Do the actual printing
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
259 switch (param.modifier)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
260 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
261 case 'l':
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
262 os << std::setiosflags (std::ios::left)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
263 << std::setw (param.parameter_length);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
264 param_buf << std::setiosflags (std::ios::left)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
265 << std::setw (param.parameter_length);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
266 break;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
267
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
268 case 'r':
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
269 os << std::setiosflags (std::ios::right)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
270 << std::setw (param.parameter_length);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
271 param_buf << std::setiosflags (std::ios::right)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
272 << std::setw (param.parameter_length);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
273 break;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
274
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
275 case 'c':
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
276 if (param.command != 's')
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
277 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
278 os << std::setiosflags (std::ios::left)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
279 << std::setw (param.parameter_length);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
280 param_buf << std::setiosflags (std::ios::left)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
281 << std::setw (param.parameter_length);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
282 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
283 break;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
284
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
285 default:
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
286 os << std::setiosflags (std::ios::left)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
287 << std::setw (param.parameter_length);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
288 param_buf << std::setiosflags (std::ios::left)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
289 << std::setw (param.parameter_length);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
290 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
291
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
292 if (param.command == 's' && param.modifier == 'c')
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
293 {
26433
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
294 int a = param.first_parameter_length - param.balance;
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
295 a = (a < 0 ? 0 : a);
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
296 int b = param.parameter_length - a - param.text.length ();
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
297 b = (b < 0 ? 0 : b);
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
298 os << std::setiosflags (std::ios::left) << std::setw (a)
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
299 << "" << std::resetiosflags (std::ios::left) << param.text
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
300 << std::setiosflags (std::ios::left)
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
301 << std::setw (b) << ""
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
302 << std::resetiosflags (std::ios::left);
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
303 param_buf << std::setiosflags (std::ios::left)
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
304 << std::setw (a)
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
305 << "" << std::resetiosflags (std::ios::left)
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
306 << param.line
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
307 << std::setiosflags (std::ios::left)
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
308 << std::setw (b) << ""
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
309 << std::resetiosflags (std::ios::left);
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
310 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
311 else
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
312 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
313 os << param.text;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
314 param_buf << param.line;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
315 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
316 os << std::resetiosflags (std::ios::left)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
317 << std::resetiosflags (std::ios::right);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
318 param_buf << std::resetiosflags (std::ios::left)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
319 << std::resetiosflags (std::ios::right);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
320 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
321 else
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
322 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
323 os << param.text;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
324 param_buf << param.line;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
325 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
326 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
327
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
328 os << param_buf.str ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
329 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
330
26658
fc7d72df08fa add const qualifiers to two symbol_info methods
John W. Eaton <jwe@octave.org>
parents: 26657
diff changeset
331 void symbol_info_list::display (std::ostream& os,
fc7d72df08fa add const qualifiers to two symbol_info methods
John W. Eaton <jwe@octave.org>
parents: 26657
diff changeset
332 const std::string& format) const
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
333 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
334 if (! m_lst.empty ())
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
335 {
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
336 std::size_t bytes = 0;
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
337 std::size_t elements = 0;
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
338
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
339 std::list<whos_parameter> params = parse_whos_line_format (format);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
340
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
341 print_descriptor (os, params);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
342
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
343 octave_stdout << "\n";
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
344
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
345 for (const auto& syminfo : m_lst)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
346 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
347 syminfo.display_line (os, params);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
348
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
349 octave_value val = syminfo.value ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
350
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
351 elements += val.numel ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
352 bytes += val.byte_size ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
353 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
354
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
355 os << "\nTotal is " << elements
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
356 << (elements == 1 ? " element" : " elements")
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
357 << " using " << bytes << (bytes == 1 ? " byte" : " bytes")
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
358 << "\n";
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
359 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
360 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
361
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
362 std::list<whos_parameter>
26658
fc7d72df08fa add const qualifiers to two symbol_info methods
John W. Eaton <jwe@octave.org>
parents: 26657
diff changeset
363 symbol_info_list::parse_whos_line_format (const std::string& format) const
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
364 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
365 int idx;
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
366 std::size_t format_len = format.length ();
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
367 char garbage;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
368 std::list<whos_parameter> params;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
369
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
370 std::size_t bytes1;
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
371 int elements1;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
372
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
373 std::string param_string = "abcenst";
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
374 Array<int> param_length (dim_vector (param_string.length (), 1));
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
375 Array<std::string> param_names (dim_vector (param_string.length (), 1));
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
376 std::size_t pos_a, pos_b, pos_c, pos_e, pos_n, pos_s, pos_t;
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
377
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
378 pos_a = param_string.find ('a'); // Attributes
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
379 pos_b = param_string.find ('b'); // Bytes
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
380 pos_c = param_string.find ('c'); // Class
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
381 pos_e = param_string.find ('e'); // Elements
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
382 pos_n = param_string.find ('n'); // Name
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
383 pos_s = param_string.find ('s'); // Size
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
384 pos_t = param_string.find ('t'); // Type
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
385
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
386 param_names(pos_a) = "Attr";
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
387 param_names(pos_b) = "Bytes";
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
388 param_names(pos_c) = "Class";
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
389 param_names(pos_e) = "Elements";
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
390 param_names(pos_n) = "Name";
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
391 param_names(pos_s) = "Size";
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
392 param_names(pos_t) = "Type";
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
393
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
394 for (std::size_t i = 0; i < param_string.length (); i++)
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
395 param_length(i) = param_names(i).length ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
396
29856
56b3e2af0298 Add 's'=sparse attribute for whos function (bug #60687)
Rik <rik@octave.org>
parents: 29572
diff changeset
397 // The attribute column needs size 6.
56b3e2af0298 Add 's'=sparse attribute for whos function (bug #60687)
Rik <rik@octave.org>
parents: 29572
diff changeset
398 param_length(pos_a) = 6;
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
399
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
400 // Calculating necessary spacing for name column,
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
401 // bytes column, elements column and class column
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
402
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
403 for (const auto& syminfo : m_lst)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
404 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
405 std::stringstream ss1, ss2;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
406 std::string str;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
407
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
408 str = syminfo.name ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
409 param_length(pos_n) = ((str.length ()
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
410 > static_cast<std::size_t> (param_length(pos_n)))
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
411 ? str.length () : param_length(pos_n));
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
412
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
413 octave_value val = syminfo.value ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
414
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
415 str = val.type_name ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
416 param_length(pos_t) = ((str.length ()
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
417 > static_cast<std::size_t> (param_length(pos_t)))
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
418 ? str.length () : param_length(pos_t));
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
419
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
420 elements1 = val.numel ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
421 ss1 << elements1;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
422 str = ss1.str ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
423 param_length(pos_e) = ((str.length ()
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
424 > static_cast<std::size_t> (param_length(pos_e)))
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
425 ? str.length () : param_length(pos_e));
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
426
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
427 bytes1 = val.byte_size ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
428 ss2 << bytes1;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
429 str = ss2.str ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
430 param_length(pos_b) = ((str.length ()
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
431 > static_cast<std::size_t> (param_length(pos_b)))
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
432 ? str.length () : param_length (pos_b));
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
433 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
434
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
435 idx = 0;
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
436 while (static_cast<std::size_t> (idx) < format_len)
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
437 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
438 whos_parameter param;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
439 param.command = '\0';
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
440
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
441 if (format[idx] == '%')
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
442 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
443 param.modifier = 'r';
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
444 param.parameter_length = 0;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
445
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
446 int a = 0;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
447 int b = -1;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
448 int balance = 1;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
449 unsigned int items;
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
450 std::size_t pos;
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
451 std::string cmd;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
452
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
453 // Parse one command from format
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
454 cmd = format.substr (idx, format.length ());
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
455 pos = cmd.find (';');
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
456 if (pos == std::string::npos)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
457 error ("parameter without ; in format");
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
458
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
459 cmd = cmd.substr (0, pos+1);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
460
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
461 idx += cmd.length ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
462
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
463 // FIXME: use iostream functions instead of sscanf!
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
464
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
465 if (cmd.find_first_of ("crl") != 1)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
466 items = sscanf (cmd.c_str (), "%c%c:%d:%d:%d;",
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
467 &garbage, &param.command, &a, &b, &balance);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
468 else
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
469 items = sscanf (cmd.c_str (), "%c%c%c:%d:%d:%d;",
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
470 &garbage, &param.modifier, &param.command,
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
471 &a, &b, &balance) - 1;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
472
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
473 if (items < 2)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
474 error ("whos_line_format: found parameter structure without command");
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
475
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
476 // Exception case of bare class command 'c' without modifier 'l/r'
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
477 if (param.modifier == 'c'
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
478 && param_string.find (param.command) == std::string::npos)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
479 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
480 param.modifier = 'r';
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
481 param.command = 'c';
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
482 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
483
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
484 // Insert data into parameter
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
485 param.first_parameter_length = 0;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
486 pos = param_string.find (param.command);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
487 if (pos == std::string::npos)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
488 error ("whos_line_format: '%c' is not a command", param.command);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
489
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
490 param.parameter_length = param_length(pos);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
491 param.text = param_names(pos);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
492 param.line.assign (param_names(pos).length (), '=');
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
493
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
494 param.parameter_length = (a > param.parameter_length
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
495 ? a : param.parameter_length);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
496 if (param.command == 's' && param.modifier == 'c' && b > 0)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
497 param.first_parameter_length = b;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
498
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
499 if (param.command == 's')
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
500 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
501 // Have to calculate space needed for printing
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
502 // matrix dimensions Space needed for Size column is
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
503 // hard to determine in prior, because it depends on
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
504 // dimensions to be shown. That is why it is
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
505 // recalculated for each Size-command int first,
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
506 // rest = 0, total;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
507 int rest = 0;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
508 int first = param.first_parameter_length;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
509 int total = param.parameter_length;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
510
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
511 for (const auto& syminfo : m_lst)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
512 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
513 octave_value val = syminfo.value ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
514 std::string dims_str = val.get_dims_str ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
515 int first1 = dims_str.find ('x');
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
516 int total1 = dims_str.length ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
517 int rest1 = total1 - first1;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
518 rest = (rest1 > rest ? rest1 : rest);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
519 first = (first1 > first ? first1 : first);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
520 total = (total1 > total ? total1 : total);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
521 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
522
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
523 if (param.modifier == 'c')
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
524 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
525 if (first < balance)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
526 first += balance - first;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
527 if (rest + balance < param.parameter_length)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
528 rest += param.parameter_length - rest - balance;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
529
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
530 param.parameter_length = first + rest;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
531 param.first_parameter_length = first;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
532 param.balance = balance;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
533 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
534 else
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
535 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
536 param.parameter_length = total;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
537 param.first_parameter_length = 0;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
538 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
539 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
540 else if (param.modifier == 'c')
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
541 error ("whos_line_format: modifier 'c' not available for command '%c'",
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
542 param.command);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
543
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
544 // What happens if format contains negative numbers
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
545 // at param_length positions?
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
546 param.balance = (b < 0 ? 0 : param.balance);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
547 param.first_parameter_length = (b < 0
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
548 ? 0
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
549 : param.first_parameter_length);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
550 param.parameter_length = (a < 0
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
551 ? 0
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
552 : (param.parameter_length
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
553 < param_length(pos_s)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
554 ? param_length(pos_s)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
555 : param.parameter_length));
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
556
26433
58aa6d0694c2 syminfo.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents: 26376
diff changeset
557 params.push_back (param);
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
558 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
559 else
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
560 {
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
561 // Text string, to be printed as it is ...
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
562 std::string text;
29572
aef11bb4e6d1 use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
563 std::size_t pos;
26088
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
564 text = format.substr (idx, format.length ());
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
565 pos = text.find ('%');
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
566 if (pos != std::string::npos)
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
567 text = text.substr (0, pos);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
568
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
569 // Push parameter into list ...
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
570 idx += text.length ();
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
571 param.text=text;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
572 param.line.assign (text.length (), ' ');
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
573 params.push_back (param);
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
574 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
575 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
576
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
577 return params;
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
578 }
2b92498c111e move symbol_info and symbol_info_list classes to separate file
John W. Eaton <jwe@octave.org>
parents:
diff changeset
579 }