File: | libinterp/corefcn/octave-link.cc |
Location: | line 228, column 23 |
Description: | Value stored to 'nel' during its initialization is never read |
1 | /* |
2 | |
3 | Copyright (C) 2013 John W. Eaton |
4 | Copyright (C) 2011-2013 Jacob Dawid |
5 | Copyright (C) 2011-2013 John P. Swensen |
6 | |
7 | This file is part of Octave. |
8 | |
9 | Octave is free software; you can redistribute it and/or modify it |
10 | under the terms of the GNU General Public License as published by the |
11 | Free Software Foundation; either version 3 of the License, or (at your |
12 | option) any later version. |
13 | |
14 | Octave is distributed in the hope that it will be useful, but WITHOUT |
15 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
16 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
17 | for more details. |
18 | |
19 | You should have received a copy of the GNU General Public License |
20 | along with Octave; see the file COPYING. If not, see |
21 | <http://www.gnu.org/licenses/>. |
22 | |
23 | */ |
24 | |
25 | #ifdef HAVE_CONFIG_H1 |
26 | #include <config.h> |
27 | #endif |
28 | |
29 | #include "cmd-edit.h" |
30 | #include "defun.h" |
31 | #include "oct-env.h" |
32 | #include "oct-mutex.h" |
33 | #include "singleton-cleanup.h" |
34 | #include "toplev.h" |
35 | |
36 | #include "octave-link.h" |
37 | |
38 | static int |
39 | octave_readline_hook (void) |
40 | { |
41 | octave_link::entered_readline_hook (); |
42 | octave_link::generate_events (); |
43 | octave_link::process_events (); |
44 | octave_link::finished_readline_hook (); |
45 | |
46 | return 0; |
47 | } |
48 | |
49 | octave_link *octave_link::instance = 0; |
50 | |
51 | octave_link::octave_link (void) |
52 | : event_queue_mutex (new octave_mutex ()), gui_event_queue (), |
53 | debugging (false), link_enabled (true) |
54 | { |
55 | command_editor::add_event_hook (octave_readline_hook); |
56 | } |
57 | |
58 | void |
59 | octave_link::set_workspace (void) |
60 | { |
61 | if (enabled ()) |
62 | instance->do_set_workspace ((symbol_table::current_scope () |
63 | == symbol_table::top_scope ()), |
64 | symbol_table::workspace_info ()); |
65 | } |
66 | |
67 | // OBJ should be an object of a class that is derived from the base |
68 | // class octave_link, or 0 to disconnect the link. It is the |
69 | // responsibility of the caller to delete obj. |
70 | |
71 | void |
72 | octave_link::connect_link (octave_link* obj) |
73 | { |
74 | if (obj && instance) |
75 | ::error ("octave_link is already linked!"); |
76 | else |
77 | instance = obj; |
78 | } |
79 | |
80 | void |
81 | octave_link::do_generate_events (void) |
82 | { |
83 | } |
84 | |
85 | void |
86 | octave_link::do_process_events (void) |
87 | { |
88 | event_queue_mutex->lock (); |
89 | |
90 | gui_event_queue.run (); |
91 | |
92 | event_queue_mutex->unlock (); |
93 | } |
94 | |
95 | void |
96 | octave_link::do_discard_events (void) |
97 | { |
98 | event_queue_mutex->lock (); |
99 | |
100 | gui_event_queue.discard (); |
101 | |
102 | event_queue_mutex->unlock (); |
103 | } |
104 | |
105 | DEFUN (__octave_link_enabled__, , ,octave_value_list F__octave_link_enabled__ (const octave_value_list & , int ) |
106 | "-*- texinfo -*-\n\octave_value_list F__octave_link_enabled__ (const octave_value_list & , int ) |
107 | @deftypefn {Built-in Function} {} __octave_link_enabled__ ()\n\octave_value_list F__octave_link_enabled__ (const octave_value_list & , int ) |
108 | Undocumented internal function.\n\octave_value_list F__octave_link_enabled__ (const octave_value_list & , int ) |
109 | @end deftypefn")octave_value_list F__octave_link_enabled__ (const octave_value_list & , int ) |
110 | { |
111 | return octave_value (octave_link::enabled ()); |
112 | } |
113 | |
114 | DEFUN (__octave_link_edit_file__, args, ,octave_value_list F__octave_link_edit_file__ (const octave_value_list & args, int ) |
115 | "-*- texinfo -*-\n\octave_value_list F__octave_link_edit_file__ (const octave_value_list & args, int ) |
116 | @deftypefn {Built-in Function} {} __octave_link_edit_file__ (@var{file})\n\octave_value_list F__octave_link_edit_file__ (const octave_value_list & args, int ) |
117 | Undocumented internal function.\n\octave_value_list F__octave_link_edit_file__ (const octave_value_list & args, int ) |
118 | @end deftypefn")octave_value_list F__octave_link_edit_file__ (const octave_value_list & args, int ) |
119 | { |
120 | octave_value retval; |
121 | |
122 | if (args.length () == 1) |
123 | { |
124 | std::string file = args(0).string_value (); |
125 | |
126 | if (! error_state) |
127 | { |
128 | flush_octave_stdout (); |
129 | |
130 | retval = octave_link::edit_file (file); |
131 | } |
132 | else |
133 | error ("expecting file name as argument"); |
134 | } |
135 | else if (args.length () == 2) |
136 | { |
137 | std::string file = args(0).string_value (); |
138 | |
139 | if (! error_state) |
140 | { |
141 | flush_octave_stdout (); |
142 | |
143 | retval = octave_link::prompt_new_edit_file (file); |
144 | } |
145 | else |
146 | error ("expecting file name as first argument"); |
147 | } |
148 | |
149 | return retval; |
150 | } |
151 | |
152 | DEFUN (__octave_link_message_dialog__, args, ,octave_value_list F__octave_link_message_dialog__ (const octave_value_list & args, int ) |
153 | "-*- texinfo -*-\n\octave_value_list F__octave_link_message_dialog__ (const octave_value_list & args, int ) |
154 | @deftypefn {Built-in Function} {} __octave_link_message_dialog__ (@var{dlg}, @var{msg}, @var{title})\n\octave_value_list F__octave_link_message_dialog__ (const octave_value_list & args, int ) |
155 | Undocumented internal function.\n\octave_value_list F__octave_link_message_dialog__ (const octave_value_list & args, int ) |
156 | @end deftypefn")octave_value_list F__octave_link_message_dialog__ (const octave_value_list & args, int ) |
157 | { |
158 | octave_value retval; |
159 | |
160 | if (args.length () == 3) |
161 | { |
162 | std::string dlg = args(0).string_value (); |
163 | std::string msg = args(1).string_value (); |
164 | std::string title = args(2).string_value (); |
165 | |
166 | if (! error_state) |
167 | { |
168 | flush_octave_stdout (); |
169 | |
170 | retval = octave_link::message_dialog (dlg, msg, title); |
171 | } |
172 | else |
173 | error ("invalid arguments"); |
174 | } |
175 | |
176 | return retval; |
177 | } |
178 | |
179 | DEFUN (__octave_link_question_dialog__, args, ,octave_value_list F__octave_link_question_dialog__ (const octave_value_list & args, int ) |
180 | "-*- texinfo -*-\n\octave_value_list F__octave_link_question_dialog__ (const octave_value_list & args, int ) |
181 | @deftypefn {Built-in Function} {} __octave_link_question_dialog__ (@var{msg}, @var{title}, @var{btn1}, @var{btn2}, @var{btn3}, @var{default})\n\octave_value_list F__octave_link_question_dialog__ (const octave_value_list & args, int ) |
182 | Undocumented internal function.\n\octave_value_list F__octave_link_question_dialog__ (const octave_value_list & args, int ) |
183 | @end deftypefn")octave_value_list F__octave_link_question_dialog__ (const octave_value_list & args, int ) |
184 | { |
185 | octave_value retval; |
186 | |
187 | if (args.length () == 6) |
188 | { |
189 | std::string msg = args(0).string_value (); |
190 | std::string title = args(1).string_value (); |
191 | std::string btn1 = args(2).string_value (); |
192 | std::string btn2 = args(3).string_value (); |
193 | std::string btn3 = args(4).string_value (); |
194 | std::string btndef = args(5).string_value (); |
195 | |
196 | if (! error_state) |
197 | { |
198 | flush_octave_stdout (); |
199 | |
200 | retval = octave_link::question_dialog (msg, title, btn1, btn2, btn3, |
201 | btndef); |
202 | } |
203 | else |
204 | error ("invalid arguments"); |
205 | } |
206 | |
207 | return retval; |
208 | } |
209 | |
210 | DEFUN (__octave_link_file_dialog__, args, ,octave_value_list F__octave_link_file_dialog__ (const octave_value_list & args, int ) |
211 | "-*- texinfo -*-\n\octave_value_list F__octave_link_file_dialog__ (const octave_value_list & args, int ) |
212 | @deftypefn {Built-in Function} {} __octave_link_file_dialog__ (@var{filterlist}, @var{title}, @var{filename}, @var{size} @var{multiselect}, @var{pathname})\n\octave_value_list F__octave_link_file_dialog__ (const octave_value_list & args, int ) |
213 | Undocumented internal function.\n\octave_value_list F__octave_link_file_dialog__ (const octave_value_list & args, int ) |
214 | @end deftypefn")octave_value_list F__octave_link_file_dialog__ (const octave_value_list & args, int ) |
215 | { |
216 | octave_value_list retval; |
217 | |
218 | if (args.length () == 6) |
219 | { |
220 | |
221 | const Array<std::string> flist = args(0).cellstr_value (); |
222 | std::string title = args(1).string_value (); |
223 | std::string filename = args(2).string_value (); |
224 | Matrix pos = args(3).matrix_value (); |
225 | std::string multi_on = args(4).string_value (); // on, off, create |
226 | std::string pathname = args(5).string_value (); |
227 | |
228 | octave_idx_type nel = flist.numel (); |
Value stored to 'nel' during its initialization is never read | |
229 | octave_link::filter_list filter_lst; |
230 | |
231 | for (octave_idx_type i = 0; i < flist.rows (); i++) |
232 | filter_lst.push_back (std::make_pair (flist(i,0), |
233 | (flist.columns () > 1 |
234 | ? flist(i,1) : ""))); |
235 | |
236 | if (! error_state) |
237 | { |
238 | flush_octave_stdout (); |
239 | |
240 | std::list<std::string> items_lst |
241 | = octave_link::file_dialog (filter_lst, title, filename, pathname, |
242 | multi_on); |
243 | |
244 | nel = items_lst.size (); |
245 | |
246 | retval.resize (3); |
247 | |
248 | // If 3, then retval is filename, directory, and selected index. |
249 | if (nel <= 3) |
250 | { |
251 | int idx = 0; |
252 | for (std::list<std::string>::iterator it = items_lst.begin (); |
253 | it != items_lst.end (); it++) |
254 | { |
255 | retval(idx++) = *it; |
256 | |
257 | if (idx == 1 && retval(0).string_value ().length () == 0) |
258 | retval(0) = 0; |
259 | |
260 | if (idx == 3) |
261 | retval(2) = atoi (retval(2).string_value ().c_str ()); |
262 | } |
263 | } |
264 | else |
265 | { |
266 | // Multiple files. |
267 | nel = items_lst.size () - 2; |
268 | Cell items (dim_vector (1, nel)); |
269 | |
270 | std::list<std::string>::iterator it = items_lst.begin (); |
271 | |
272 | for (int idx = 0; idx < nel; idx++) |
273 | { |
274 | items.xelem (idx) = *it; |
275 | it++; |
276 | } |
277 | |
278 | retval(0) = items; |
279 | retval(1) = *it++; |
280 | retval(2) = atoi (it->c_str ()); |
281 | } |
282 | } |
283 | else |
284 | error ("invalid arguments"); |
285 | } |
286 | |
287 | return retval; |
288 | } |
289 | |
290 | DEFUN (__octave_link_list_dialog__, args, ,octave_value_list F__octave_link_list_dialog__ (const octave_value_list & args, int ) |
291 | "-*- texinfo -*-\n\octave_value_list F__octave_link_list_dialog__ (const octave_value_list & args, int ) |
292 | @deftypefn {Built-in Function} {} __octave_link_list_dialog__ (@var{list}, @var{mode}, @var{size}, @var{intial}, @var{name}, @var{prompt}, @var{ok_string}, @var{cancel_string})\n\octave_value_list F__octave_link_list_dialog__ (const octave_value_list & args, int ) |
293 | Undocumented internal function.\n\octave_value_list F__octave_link_list_dialog__ (const octave_value_list & args, int ) |
294 | @end deftypefn")octave_value_list F__octave_link_list_dialog__ (const octave_value_list & args, int ) |
295 | { |
296 | octave_value_list retval; |
297 | |
298 | if (args.length () == 8) |
299 | { |
300 | Cell list = args(0).cell_value (); |
301 | const Array<std::string> tlist = list.cellstr_value (); |
302 | octave_idx_type nel = tlist.numel (); |
303 | std::list<std::string> list_lst; |
304 | for (octave_idx_type i = 0; i < nel; i++) |
305 | list_lst.push_back (tlist(i)); |
306 | |
307 | std::string mode = args(1).string_value (); |
308 | |
309 | Matrix size_matrix = args(2).matrix_value (); |
310 | int width = size_matrix(0); |
311 | int height = size_matrix(1); |
312 | |
313 | Matrix initial_matrix = args(3).matrix_value (); |
314 | nel = initial_matrix.numel (); |
315 | std::list<int> initial_lst; |
316 | for (octave_idx_type i = 0; i < nel; i++) |
317 | initial_lst.push_back (initial_matrix(i)); |
318 | |
319 | std::string name = args(4).string_value (); |
320 | list = args(5).cell_value (); |
321 | const Array<std::string> plist = list.cellstr_value (); |
322 | nel = plist.numel (); |
323 | std::list<std::string> prompt_lst; |
324 | for (octave_idx_type i = 0; i < nel; i++) |
325 | prompt_lst.push_back (plist(i)); |
326 | std::string ok_string = args(6).string_value (); |
327 | std::string cancel_string = args(7).string_value (); |
328 | |
329 | if (! error_state) |
330 | { |
331 | flush_octave_stdout (); |
332 | |
333 | std::pair<std::list<int>, int> result |
334 | = octave_link::list_dialog (list_lst, mode, width, height, |
335 | initial_lst, name, prompt_lst, |
336 | ok_string, cancel_string); |
337 | |
338 | std::list<int> items_lst = result.first; |
339 | nel = items_lst.size (); |
340 | Matrix items (dim_vector (1, nel)); |
341 | octave_idx_type i = 0; |
342 | for (std::list<int>::iterator it = items_lst.begin (); |
343 | it != items_lst.end (); it++) |
344 | { |
345 | items.xelem(i++) = *it; |
346 | } |
347 | |
348 | retval(1) = result.second; |
349 | retval(0) = items; |
350 | } |
351 | else |
352 | error ("invalid arguments"); |
353 | } |
354 | |
355 | return retval; |
356 | } |
357 | |
358 | DEFUN (__octave_link_input_dialog__, args, ,octave_value_list F__octave_link_input_dialog__ (const octave_value_list & args, int ) |
359 | "-*- texinfo -*-\n\octave_value_list F__octave_link_input_dialog__ (const octave_value_list & args, int ) |
360 | @deftypefn {Built-in Function} {} __octave_link_input_dialog__ (@var{prompt}, @var{title}, @var{rowscols}, @var{defaults})\n\octave_value_list F__octave_link_input_dialog__ (const octave_value_list & args, int ) |
361 | Undocumented internal function.\n\octave_value_list F__octave_link_input_dialog__ (const octave_value_list & args, int ) |
362 | @end deftypefn")octave_value_list F__octave_link_input_dialog__ (const octave_value_list & args, int ) |
363 | { |
364 | octave_value retval; |
365 | |
366 | if (args.length () == 4) |
367 | { |
368 | Cell prompt = args(0).cell_value (); |
369 | Array<std::string> tmp = prompt.cellstr_value (); |
370 | octave_idx_type nel = tmp.numel (); |
371 | std::list<std::string> prompt_lst; |
372 | for (octave_idx_type i = 0; i < nel; i++) |
373 | prompt_lst.push_back (tmp(i)); |
374 | |
375 | std::string title = args(1).string_value (); |
376 | |
377 | Matrix rc = args(2).matrix_value (); |
378 | nel = rc.rows (); |
379 | std::list<float> nr; |
380 | std::list<float> nc; |
381 | for (octave_idx_type i = 0; i < nel; i++) |
382 | { |
383 | nr.push_back (rc(i,0)); |
384 | nc.push_back (rc(i,1)); |
385 | } |
386 | |
387 | Cell defaults = args(3).cell_value (); |
388 | tmp = defaults.cellstr_value (); |
389 | nel = tmp.numel (); |
390 | std::list<std::string> defaults_lst; |
391 | for (octave_idx_type i = 0; i < nel; i++) |
392 | defaults_lst.push_back (tmp(i)); |
393 | |
394 | if (! error_state) |
395 | { |
396 | flush_octave_stdout (); |
397 | |
398 | std::list<std::string> items_lst |
399 | = octave_link::input_dialog (prompt_lst, title, nr, nc, |
400 | defaults_lst); |
401 | |
402 | nel = items_lst.size (); |
403 | Cell items (dim_vector (1, nel)); |
404 | octave_idx_type i = 0; |
405 | for (std::list<std::string>::iterator it = items_lst.begin (); |
406 | it != items_lst.end (); it++) |
407 | { |
408 | items.xelem(i++) = *it; |
409 | } |
410 | |
411 | retval = items; |
412 | } |
413 | else |
414 | error ("invalid arguments"); |
415 | } |
416 | |
417 | return retval; |
418 | } |
419 | |
420 | DEFUN (__octave_link_show_preferences__, , ,octave_value_list F__octave_link_show_preferences__ (const octave_value_list & , int ) |
421 | "-*- texinfo -*-\n\octave_value_list F__octave_link_show_preferences__ (const octave_value_list & , int ) |
422 | @deftypefn {Built-in Function} {} __octave_link_show_preferences__ ()\n\octave_value_list F__octave_link_show_preferences__ (const octave_value_list & , int ) |
423 | Undocumented internal function.\n\octave_value_list F__octave_link_show_preferences__ (const octave_value_list & , int ) |
424 | @end deftypefn")octave_value_list F__octave_link_show_preferences__ (const octave_value_list & , int ) |
425 | { |
426 | octave_value retval; |
427 | |
428 | retval = octave_link::show_preferences (); |
429 | |
430 | return retval; |
431 | } |
432 | |
433 | DEFUN (__octave_link_show_doc__, args, ,octave_value_list F__octave_link_show_doc__ (const octave_value_list & args, int ) |
434 | "-*- texinfo -*-\n\octave_value_list F__octave_link_show_doc__ (const octave_value_list & args, int ) |
435 | @deftypefn {Built-in Function} {} __octave_link_show_doc__ ( @var{filename} )\n\octave_value_list F__octave_link_show_doc__ (const octave_value_list & args, int ) |
436 | Undocumented internal function.\n\octave_value_list F__octave_link_show_doc__ (const octave_value_list & args, int ) |
437 | @end deftypefn")octave_value_list F__octave_link_show_doc__ (const octave_value_list & args, int ) |
438 | { |
439 | octave_value retval; |
440 | std::string file; |
441 | |
442 | if (args.length () >= 1) |
443 | file = args(0).string_value(); |
444 | |
445 | retval = octave_link::show_doc (file); |
446 | |
447 | return retval; |
448 | } |
449 | |
450 | |
451 |