1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
20 |
|
21 */ |
|
22 |
2939
|
23 // Get command input interactively or from files. |
1
|
24 |
240
|
25 #ifdef HAVE_CONFIG_H |
1192
|
26 #include <config.h> |
1
|
27 #endif |
|
28 |
1343
|
29 #include <ctime> |
|
30 #include <cstdio> |
|
31 #include <cstdlib> |
|
32 #include <cstring> |
|
33 #include <cassert> |
|
34 #include <csignal> |
|
35 |
1728
|
36 #include <string> |
|
37 |
1349
|
38 #include <iostream.h> |
|
39 |
1350
|
40 #ifdef HAVE_UNISTD_H |
2442
|
41 #ifdef HAVE_SYS_TYPES_H |
529
|
42 #include <sys/types.h> |
2442
|
43 #endif |
529
|
44 #include <unistd.h> |
|
45 #endif |
1343
|
46 |
2927
|
47 #include "cmd-edit.h" |
1755
|
48 #include "str-vec.h" |
|
49 |
1352
|
50 #include "defun.h" |
|
51 #include "dirfns.h" |
1
|
52 #include "error.h" |
2181
|
53 #include "gripes.h" |
3016
|
54 #include "help.h" |
1
|
55 #include "input.h" |
1352
|
56 #include "oct-map.h" |
1742
|
57 #include "oct-hist.h" |
1670
|
58 #include "toplev.h" |
1755
|
59 #include "oct-obj.h" |
1
|
60 #include "pager.h" |
529
|
61 #include "parse.h" |
1352
|
62 #include "pathlen.h" |
1755
|
63 #include "pt-const.h" |
1352
|
64 #include "sighandlers.h" |
|
65 #include "symtab.h" |
1114
|
66 #include "sysdep.h" |
1352
|
67 #include "utils.h" |
|
68 #include "variables.h" |
529
|
69 |
2181
|
70 // Primary prompt string. |
|
71 static string Vps1; |
|
72 |
|
73 // Secondary prompt string. |
|
74 static string Vps2; |
|
75 |
|
76 // String printed before echoed input (enabled by --echo-input). |
|
77 string Vps4; |
|
78 |
3019
|
79 // Echo commands as they are executed? |
|
80 // |
|
81 // 1 ==> echo commands read from script files |
|
82 // 2 ==> echo commands from functions |
|
83 // 4 ==> echo commands read from command line |
|
84 // |
|
85 // more than one state can be active at once. |
|
86 int Vecho_executing_commands; |
|
87 |
2181
|
88 // Character to append after successful command-line completion attempts. |
|
89 static char Vcompletion_append_char; |
|
90 |
1
|
91 // Global pointer for eval(). |
1755
|
92 string current_eval_string; |
1
|
93 |
3019
|
94 // TRUE means get input from current_eval_string. |
|
95 bool get_input_from_eval_string = false; |
1
|
96 |
3019
|
97 // TRUE means we're parsing a function file. |
|
98 bool reading_fcn_file = false; |
1
|
99 |
338
|
100 // Simple name of function file we are reading. |
1755
|
101 string curr_fcn_file_name; |
1606
|
102 |
|
103 // Full name of file we are reading. |
1755
|
104 string curr_fcn_file_full_name; |
1
|
105 |
3019
|
106 // TRUE means we're parsing a script file. |
|
107 bool reading_script_file = false; |
1
|
108 |
|
109 // If we are reading from an M-file, this is it. |
529
|
110 FILE *ff_instream = 0; |
1
|
111 |
3019
|
112 // TRUE means this is an interactive shell. |
|
113 bool interactive = false; |
1
|
114 |
3019
|
115 // TRUE means the user forced this shell to be interactive (-i). |
|
116 bool forced_interactive = false; |
1
|
117 |
|
118 // Should we issue a prompt? |
|
119 int promptflag = 1; |
|
120 |
|
121 // The current line of input, from wherever. |
1755
|
122 string current_input_line; |
1
|
123 |
2299
|
124 // TRUE after a call to completion_matches(). |
|
125 bool octave_completion_matches_called = false; |
|
126 |
1044
|
127 static void |
1755
|
128 do_input_echo (const string& input_string) |
1044
|
129 { |
1588
|
130 int do_echo = reading_script_file ? |
2205
|
131 (Vecho_executing_commands & ECHO_SCRIPTS) |
2618
|
132 : (Vecho_executing_commands & ECHO_CMD_LINE) && ! forced_interactive; |
1588
|
133 |
|
134 if (do_echo) |
1044
|
135 { |
1403
|
136 if (forced_interactive) |
|
137 { |
1755
|
138 if (promptflag > 0) |
2927
|
139 octave_stdout << command_editor::decode_prompt_string (Vps1); |
1755
|
140 else |
2927
|
141 octave_stdout << command_editor::decode_prompt_string (Vps2); |
1403
|
142 } |
|
143 else |
2927
|
144 octave_stdout << command_editor::decode_prompt_string (Vps4); |
1044
|
145 |
1755
|
146 if (! input_string.empty ()) |
1044
|
147 { |
2095
|
148 octave_stdout << input_string; |
1755
|
149 |
|
150 if (input_string[input_string.length () - 1] != '\n') |
2095
|
151 octave_stdout << "\n"; |
1044
|
152 } |
|
153 } |
|
154 } |
|
155 |
2927
|
156 string |
|
157 gnu_readline (const string& s, bool force_readline) |
1822
|
158 { |
2927
|
159 string retval; |
1822
|
160 |
2927
|
161 if (line_editing || force_readline) |
1822
|
162 { |
2927
|
163 retval = command_editor::readline (s); |
1898
|
164 |
2927
|
165 if (retval.empty ()) |
|
166 retval = "\n"; |
1822
|
167 } |
|
168 else |
|
169 { |
2927
|
170 if (! s.empty () && (interactive || forced_interactive)) |
2618
|
171 { |
2927
|
172 FILE *stream = command_editor::get_output_stream (); |
|
173 |
|
174 fprintf (stream, s.c_str ()); |
|
175 fflush (stream); |
2618
|
176 } |
1822
|
177 |
2927
|
178 FILE *curr_stream = command_editor::get_input_stream (); |
|
179 |
1822
|
180 if (reading_fcn_file || reading_script_file) |
|
181 curr_stream = ff_instream; |
|
182 |
2927
|
183 retval = octave_fgets (curr_stream); |
1822
|
184 } |
|
185 |
|
186 return retval; |
|
187 } |
581
|
188 |
2927
|
189 static string |
1
|
190 octave_gets (void) |
|
191 { |
2927
|
192 string retval; |
1
|
193 |
1822
|
194 if ((interactive || forced_interactive) |
|
195 && (! (reading_fcn_file || reading_script_file))) |
1
|
196 { |
2927
|
197 string ps = (promptflag > 0) ? Vps1 : Vps2; |
1755
|
198 |
2927
|
199 string prompt = command_editor::decode_prompt_string (ps); |
1
|
200 |
2618
|
201 pipe_handler_error_count = 0; |
|
202 |
|
203 flush_octave_stdout (); |
1
|
204 |
2095
|
205 octave_diary << prompt; |
581
|
206 |
2927
|
207 retval = gnu_readline (prompt); |
1
|
208 } |
|
209 else |
1822
|
210 retval = gnu_readline (""); |
1
|
211 |
2927
|
212 current_input_line = retval; |
1
|
213 |
1822
|
214 if (! current_input_line.empty ()) |
1
|
215 { |
1799
|
216 if (! input_from_startup_file) |
2927
|
217 command_history::add (current_input_line); |
1
|
218 |
2095
|
219 octave_diary << current_input_line; |
581
|
220 |
1822
|
221 do_input_echo (current_input_line); |
1
|
222 } |
581
|
223 |
2095
|
224 octave_diary << "\n"; |
581
|
225 |
1822
|
226 return retval; |
1
|
227 } |
|
228 |
581
|
229 // Read a line from the input stream. |
|
230 |
2927
|
231 static string |
1822
|
232 get_user_input (void) |
1
|
233 { |
2927
|
234 string retval; |
1
|
235 |
|
236 if (get_input_from_eval_string) |
|
237 { |
2927
|
238 retval = current_eval_string; |
1822
|
239 |
2927
|
240 size_t len = retval.length (); |
1822
|
241 |
2927
|
242 if (retval[len-1] != '\n') |
|
243 retval.append ("\n"); |
1822
|
244 } |
|
245 else |
|
246 retval = octave_gets (); |
|
247 |
2927
|
248 current_input_line = retval; |
1822
|
249 |
2114
|
250 if (! get_input_from_eval_string) |
|
251 input_line_number++; |
1822
|
252 |
|
253 return retval; |
|
254 } |
|
255 |
|
256 int |
|
257 octave_read (char *buf, unsigned max_size) |
|
258 { |
2927
|
259 // XXX FIXME XXX -- is this a safe way to buffer the input? |
|
260 |
|
261 static string input_buf; |
|
262 static const char *pos = 0; |
|
263 static size_t chars_left = 0; |
1822
|
264 |
|
265 int status = 0; |
|
266 |
2927
|
267 if (input_buf.empty ()) |
1822
|
268 { |
2927
|
269 pos = 0; |
|
270 |
|
271 input_buf = get_user_input (); |
1822
|
272 |
2927
|
273 chars_left = input_buf.length (); |
|
274 |
|
275 pos = input_buf.c_str (); |
1822
|
276 } |
|
277 |
|
278 if (chars_left > 0) |
|
279 { |
|
280 buf[0] = '\0'; |
|
281 |
2927
|
282 size_t len = max_size > 2 ? max_size - 2 : 0; |
1822
|
283 |
2927
|
284 assert (len > 0); |
|
285 |
|
286 strncpy (buf, pos, len); |
1822
|
287 |
|
288 if (chars_left > len) |
1
|
289 { |
1822
|
290 chars_left -= len; |
|
291 |
2927
|
292 pos += len; |
1822
|
293 |
|
294 buf[len] = '\0'; |
|
295 |
1
|
296 status = len; |
|
297 } |
|
298 else |
|
299 { |
2927
|
300 input_buf = ""; |
1755
|
301 |
1822
|
302 len = chars_left; |
|
303 |
|
304 if (buf[len-1] != '\n') |
|
305 buf[len++] = '\n'; |
1
|
306 |
1822
|
307 buf[len] = '\0'; |
1755
|
308 |
1822
|
309 status = len; |
1
|
310 } |
1044
|
311 } |
1822
|
312 else if (chars_left == 0) |
2862
|
313 { |
2927
|
314 input_buf = ""; |
2862
|
315 |
|
316 status = 0; |
|
317 } |
1822
|
318 else |
|
319 status = -1; |
1044
|
320 |
1
|
321 return status; |
|
322 } |
|
323 |
581
|
324 // Fix things up so that input can come from file `name', printing a |
|
325 // warning if the file doesn't exist. |
|
326 |
1
|
327 FILE * |
1750
|
328 get_input_from_file (const string& name, int warn) |
1
|
329 { |
529
|
330 FILE *instream = 0; |
1
|
331 |
1750
|
332 if (name.length () > 0) |
|
333 instream = fopen (name.c_str (), "r"); |
1
|
334 |
529
|
335 if (! instream && warn) |
1750
|
336 warning ("%s: no such file or directory", name.c_str ()); |
1
|
337 |
338
|
338 if (reading_fcn_file || reading_script_file) |
339
|
339 ff_instream = instream; |
1
|
340 else |
2927
|
341 command_editor::set_input_stream (instream); |
1
|
342 |
|
343 return instream; |
|
344 } |
|
345 |
581
|
346 // Fix things up so that input can come from the standard input. This |
|
347 // may need to become much more complicated, which is why it's in a |
|
348 // separate function. |
|
349 |
1
|
350 FILE * |
|
351 get_input_from_stdin (void) |
|
352 { |
2927
|
353 command_editor::set_input_stream (stdin); |
|
354 return command_editor::get_input_stream (); |
1
|
355 } |
|
356 |
2921
|
357 // XXX FIXME XXX -- make this generate file names when appropriate. |
|
358 |
2247
|
359 static string_vector |
2921
|
360 generate_possible_completions (const string& text, string& prefix, |
|
361 string& hint) |
1280
|
362 { |
2247
|
363 string_vector names; |
1280
|
364 |
2921
|
365 prefix = ""; |
1280
|
366 |
2921
|
367 if (! text.empty () && text != "." && text.rfind ('.') != NPOS) |
1430
|
368 names = generate_struct_completions (text, prefix, hint); |
|
369 else |
2247
|
370 names = make_name_list (); |
1280
|
371 |
2944
|
372 // Sort and remove duplicates. |
2348
|
373 |
2944
|
374 names.qsort (true); |
2348
|
375 |
1280
|
376 return names; |
|
377 } |
|
378 |
2944
|
379 static string |
|
380 generate_completion (const string& text, int state) |
1280
|
381 { |
2944
|
382 string retval; |
|
383 |
2921
|
384 static string prefix; |
|
385 static string hint; |
1280
|
386 |
2921
|
387 static size_t prefix_len = 0; |
|
388 static size_t hint_len = 0; |
1280
|
389 |
1
|
390 static int list_index = 0; |
2921
|
391 static int name_list_len = 0; |
2247
|
392 static string_vector name_list; |
1
|
393 |
1280
|
394 static int matches = 0; |
1
|
395 |
|
396 if (state == 0) |
|
397 { |
|
398 list_index = 0; |
|
399 |
2921
|
400 prefix = ""; |
1280
|
401 |
2921
|
402 hint = text; |
1280
|
403 |
|
404 name_list = generate_possible_completions (text, prefix, hint); |
|
405 |
2921
|
406 name_list_len = name_list.length (); |
|
407 |
|
408 prefix_len = prefix.length (); |
1280
|
409 |
2921
|
410 hint_len = hint.length (); |
1280
|
411 |
|
412 matches = 0; |
2247
|
413 |
2921
|
414 for (int i = 0; i < name_list_len; i++) |
|
415 if (! name_list[i].compare (hint, 0, hint_len)) |
2247
|
416 matches++; |
1
|
417 } |
|
418 |
2921
|
419 if (name_list_len > 0 && matches > 0) |
1
|
420 { |
2921
|
421 while (list_index < name_list_len) |
244
|
422 { |
2921
|
423 string name = name_list[list_index]; |
2247
|
424 |
1280
|
425 list_index++; |
2247
|
426 |
2921
|
427 if (! name.compare (hint, 0, hint_len)) |
1280
|
428 { |
2944
|
429 if (! prefix.empty ()) |
|
430 retval = prefix + "." + name; |
|
431 else |
|
432 retval = name; |
1280
|
433 |
2944
|
434 if (matches == 1 && looks_like_struct (retval)) |
2927
|
435 command_editor::set_completion_append_character ('.'); |
1280
|
436 else |
2927
|
437 command_editor::set_completion_append_character |
|
438 (Vcompletion_append_char); |
1280
|
439 |
2944
|
440 break; |
1280
|
441 } |
244
|
442 } |
1
|
443 } |
|
444 |
2944
|
445 return retval; |
1
|
446 } |
|
447 |
2927
|
448 void |
|
449 initialize_command_input (void) |
|
450 { |
|
451 // If we are using readline, this allows conditional parsing of the |
|
452 // .inputrc file. |
269
|
453 |
2927
|
454 command_editor::set_name ("Octave"); |
1358
|
455 |
3004
|
456 command_editor::set_basic_quote_characters ("\""); |
2944
|
457 |
|
458 command_editor::set_completion_function (generate_completion); |
269
|
459 } |
|
460 |
2927
|
461 static bool |
|
462 match_sans_spaces (const string& standard, const string& test) |
269
|
463 { |
2927
|
464 string tmp = test; |
269
|
465 |
2927
|
466 size_t beg = test.find_first_not_of (" \t"); |
|
467 size_t end = test.find_last_not_of (" \t"); |
|
468 size_t len = beg - end + 1; |
1
|
469 |
2927
|
470 return test.compare (standard, beg, len) == 0; |
529
|
471 } |
|
472 |
581
|
473 // If the user simply hits return, this will produce an empty matrix. |
|
474 |
2086
|
475 static octave_value_list |
3006
|
476 get_user_input (const octave_value_list& args, bool debug = false) |
529
|
477 { |
2086
|
478 octave_value retval; |
529
|
479 |
|
480 int nargin = args.length (); |
|
481 |
|
482 int read_as_string = 0; |
|
483 |
712
|
484 if (nargin == 2) |
529
|
485 read_as_string++; |
|
486 |
1761
|
487 string prompt ("debug> "); |
|
488 |
712
|
489 if (nargin > 0) |
529
|
490 { |
1761
|
491 prompt = args(0).string_value (); |
636
|
492 |
|
493 if (error_state) |
|
494 { |
|
495 error ("input: unrecognized argument"); |
|
496 return retval; |
|
497 } |
529
|
498 } |
|
499 |
|
500 again: |
|
501 |
2095
|
502 flush_octave_stdout (); |
529
|
503 |
2927
|
504 string input_buf = gnu_readline (prompt.c_str (), true); |
529
|
505 |
2927
|
506 if (! input_buf.empty ()) |
529
|
507 { |
1799
|
508 if (! input_from_startup_file) |
2927
|
509 command_history::add (input_buf); |
529
|
510 |
2927
|
511 size_t len = input_buf.length (); |
529
|
512 |
|
513 if (len < 1) |
|
514 { |
|
515 if (debug) |
|
516 goto again; |
|
517 else |
963
|
518 { |
|
519 if (read_as_string) |
|
520 return ""; |
|
521 else |
|
522 return Matrix (); |
|
523 } |
529
|
524 } |
|
525 |
|
526 if (match_sans_spaces ("exit", input_buf) |
|
527 || match_sans_spaces ("quit", input_buf) |
|
528 || match_sans_spaces ("return", input_buf)) |
963
|
529 { |
|
530 return retval; |
|
531 } |
529
|
532 else if (read_as_string) |
963
|
533 { |
3081
|
534 // XXX FIXME XXX -- fix gnu_readline and octave_gets instead! |
|
535 if (input_buf.length () == 1 && input_buf[0] == '\n') |
|
536 retval = ""; |
|
537 else |
|
538 retval = input_buf; |
963
|
539 } |
529
|
540 else |
|
541 { |
|
542 int parse_status = 0; |
2900
|
543 |
2896
|
544 retval = eval_string (input_buf, true, parse_status); |
2900
|
545 |
581
|
546 if (retval.is_defined ()) |
|
547 { |
|
548 if (debug) |
2900
|
549 retval.print (octave_stdout); |
581
|
550 } |
|
551 else |
963
|
552 retval = Matrix (); |
529
|
553 } |
|
554 } |
|
555 else |
|
556 error ("input: reading user-input failed!"); |
|
557 |
|
558 if (debug) |
|
559 goto again; |
|
560 |
|
561 return retval; |
|
562 } |
|
563 |
1957
|
564 DEFUN (input, args, , |
529
|
565 "input (PROMPT [, S])\n\ |
|
566 \n\ |
2802
|
567 Prompt user for input. If the second argument is present, return\n\ |
529
|
568 value as a string.") |
|
569 { |
2086
|
570 octave_value_list retval; |
529
|
571 |
|
572 int nargin = args.length (); |
|
573 |
712
|
574 if (nargin == 1 || nargin == 2) |
1488
|
575 retval = get_user_input (args); |
529
|
576 else |
|
577 print_usage ("input"); |
|
578 |
|
579 return retval; |
|
580 } |
|
581 |
1957
|
582 DEFUN (keyboard, args, , |
529
|
583 "keyboard (PROMPT)\n\ |
|
584 \n\ |
|
585 maybe help in debugging function files") |
|
586 { |
2086
|
587 octave_value_list retval; |
529
|
588 |
|
589 int nargin = args.length (); |
|
590 |
712
|
591 if (nargin == 0 || nargin == 1) |
3006
|
592 retval = get_user_input (args, true); |
529
|
593 else |
|
594 print_usage ("keyboard"); |
|
595 |
|
596 return retval; |
|
597 } |
|
598 |
1957
|
599 DEFUN_TEXT(echo, args, , |
1588
|
600 "echo [options]\n\ |
|
601 \n\ |
|
602 echo [on|off] -- enable or disable echoing of commands as\n\ |
|
603 they are executed in script files\n\ |
|
604 \n\ |
|
605 echo [on all|off all] -- enable or disable echoing of commands as they\n\ |
|
606 are executed in script files and functions\n\ |
|
607 \n\ |
|
608 Without any arguments, toggle the current echo state.") |
|
609 { |
2086
|
610 octave_value_list retval; |
1588
|
611 |
1755
|
612 int argc = args.length () + 1; |
|
613 |
1968
|
614 string_vector argv = args.make_argv ("echo"); |
1755
|
615 |
|
616 if (error_state) |
|
617 return retval; |
1588
|
618 |
|
619 switch (argc) |
|
620 { |
|
621 case 1: |
|
622 { |
2205
|
623 if ((Vecho_executing_commands & ECHO_SCRIPTS) |
|
624 || (Vecho_executing_commands & ECHO_FUNCTIONS)) |
2431
|
625 bind_builtin_variable ("echo_executing_commands", |
2800
|
626 static_cast<double> (ECHO_OFF)); |
1588
|
627 else |
2431
|
628 bind_builtin_variable ("echo_executing_commands", |
2800
|
629 static_cast<double> (ECHO_SCRIPTS)); |
1588
|
630 } |
|
631 break; |
|
632 |
|
633 case 2: |
|
634 { |
1755
|
635 string arg = argv[1]; |
|
636 |
|
637 if (arg == "on") |
2431
|
638 bind_builtin_variable ("echo_executing_commands", |
2800
|
639 static_cast<double> (ECHO_SCRIPTS)); |
1755
|
640 else if (arg == "off") |
2431
|
641 bind_builtin_variable ("echo_executing_commands", |
2800
|
642 static_cast<double> (ECHO_OFF)); |
1588
|
643 else |
|
644 print_usage ("echo"); |
|
645 } |
|
646 break; |
|
647 |
|
648 case 3: |
|
649 { |
1755
|
650 string arg = argv[1]; |
|
651 |
|
652 if (arg == "on" && argv[2] == "all") |
2800
|
653 { |
|
654 int tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS); |
|
655 bind_builtin_variable ("echo_executing_commands", |
|
656 static_cast<double> (tmp)); |
|
657 } |
1755
|
658 else if (arg == "off" && argv[2] == "all") |
2431
|
659 bind_builtin_variable ("echo_executing_commands", |
2800
|
660 static_cast<double> (ECHO_OFF)); |
1588
|
661 else |
|
662 print_usage ("echo"); |
|
663 } |
|
664 break; |
|
665 |
|
666 default: |
|
667 print_usage ("echo"); |
|
668 break; |
|
669 } |
|
670 |
|
671 return retval; |
|
672 } |
|
673 |
2234
|
674 DEFUN (completion_matches, args, nargout, |
2299
|
675 "completion_matches (HINT): generate possible completions given HINT\n\ |
|
676 \n\ |
|
677 This function is provided for the benefit of programs like Emacs which\n\ |
|
678 might be controlling Octave and handling user input. The current command\n\ |
|
679 number is not incremented when this function is called. This is a feature,\n\ |
|
680 not a bug.") |
2234
|
681 { |
2281
|
682 octave_value retval; |
2234
|
683 |
|
684 int nargin = args.length (); |
|
685 |
|
686 if (nargin == 1) |
|
687 { |
2944
|
688 string hint = args(0).string_value (); |
2234
|
689 |
|
690 if (! error_state) |
|
691 { |
|
692 int n = 32; |
|
693 |
|
694 string_vector list (n); |
|
695 |
|
696 int k = 0; |
|
697 |
|
698 for (;;) |
|
699 { |
2944
|
700 string cmd = generate_completion (hint, k); |
2234
|
701 |
2944
|
702 if (! cmd.empty ()) |
2234
|
703 { |
2944
|
704 if (k == n) |
2234
|
705 { |
2944
|
706 n *= 2; |
|
707 list.resize (n); |
|
708 } |
2235
|
709 |
2944
|
710 list[k++] = cmd; |
2234
|
711 } |
|
712 else |
|
713 { |
|
714 list.resize (k); |
|
715 break; |
|
716 } |
|
717 } |
|
718 |
|
719 if (nargout > 0) |
2281
|
720 { |
|
721 if (! list.empty ()) |
|
722 retval = list; |
2282
|
723 else |
|
724 retval = ""; |
2281
|
725 } |
2234
|
726 else |
|
727 { |
2235
|
728 // We don't use string_vector::list_in_columns here |
|
729 // because it will be easier for Emacs if the names |
|
730 // appear in a single column. |
|
731 |
2234
|
732 int len = list.length (); |
|
733 |
|
734 for (int i = 0; i < len; i++) |
|
735 octave_stdout << list[i] << "\n"; |
|
736 } |
2299
|
737 |
|
738 octave_completion_matches_called = true; |
2234
|
739 } |
|
740 } |
|
741 else |
|
742 print_usage ("completion_matches"); |
|
743 |
|
744 return retval; |
|
745 } |
|
746 |
2181
|
747 static int |
|
748 ps1 (void) |
|
749 { |
|
750 int status = 0; |
|
751 |
|
752 Vps1 = builtin_string_variable ("PS1"); |
|
753 |
|
754 return status; |
|
755 } |
|
756 |
|
757 static int |
|
758 ps2 (void) |
|
759 { |
|
760 int status = 0; |
|
761 |
|
762 Vps2 = builtin_string_variable ("PS2"); |
|
763 |
|
764 return status; |
|
765 } |
|
766 |
|
767 static int |
|
768 ps4 (void) |
|
769 { |
|
770 int status = 0; |
|
771 |
|
772 Vps4 = builtin_string_variable ("PS4"); |
|
773 |
|
774 return status; |
|
775 } |
|
776 |
|
777 static int |
|
778 completion_append_char (void) |
|
779 { |
|
780 int status = 0; |
|
781 |
|
782 string s = builtin_string_variable ("completion_append_char"); |
|
783 |
|
784 switch (s.length ()) |
|
785 { |
|
786 case 1: |
|
787 Vcompletion_append_char = s[0]; |
|
788 break; |
|
789 |
|
790 case 0: |
|
791 Vcompletion_append_char = '\0'; |
|
792 break; |
|
793 |
|
794 default: |
|
795 warning ("completion_append_char must be a single character"); |
|
796 status = -1; |
|
797 break; |
|
798 } |
|
799 |
|
800 return status; |
|
801 } |
|
802 |
3019
|
803 static int |
|
804 echo_executing_commands (void) |
|
805 { |
|
806 Vecho_executing_commands = check_preference ("echo_executing_commands"); |
|
807 |
|
808 return 0; |
|
809 } |
|
810 |
2181
|
811 void |
|
812 symbols_of_input (void) |
|
813 { |
|
814 DEFVAR (PS1, "\\s:\\#> ", 0, ps1, |
|
815 "primary prompt string"); |
|
816 |
|
817 DEFVAR (PS2, "> ", 0, ps2, |
|
818 "secondary prompt string"); |
|
819 |
|
820 DEFVAR (PS4, "+ ", 0, ps4, |
|
821 "string printed before echoed input (enabled by --echo-input)"); |
|
822 |
|
823 DEFVAR (completion_append_char, " ", 0, completion_append_char, |
|
824 "the string to append after successful command-line completion attempts"); |
3019
|
825 |
|
826 DEFVAR (echo_executing_commands, static_cast<double> (ECHO_OFF), 0, |
|
827 echo_executing_commands, |
|
828 "echo commands as they are executed"); |
2181
|
829 } |
|
830 |
1
|
831 /* |
|
832 ;;; Local Variables: *** |
|
833 ;;; mode: C++ *** |
|
834 ;;; End: *** |
|
835 */ |