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