-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinput.cc
1542 lines (1229 loc) · 38.5 KB
/
input.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 1993-2011 John W. Eaton
This file is part of Octave.
Octave is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.
Octave is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with Octave; see the file COPYING. If not, see
<http://www.gnu.org/licenses/>.
*/
// Get command input interactively or from files.
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <sys/types.h>
#include <unistd.h>
/*
#include "cmd-edit.h"
#include "file-ops.h"
#include "quit.h"
#include "str-vec.h"
#include "debug.h"
#include "defun.h"
#include "dirfns.h"
#include "error.h"
#include "gripes.h"
#include "help.h"
#include "input.h"
#include "lex.h"
#include "load-path.h"
#include "oct-map.h"
#include "oct-hist.h"
#include "toplev.h"
#include "oct-obj.h"
#include "pager.h"
#include "parse.h"
#include "pathlen.h"
#include "pt.h"
#include "pt-const.h"
#include "pt-eval.h"
#include "pt-stmt.h"
#include "sighandlers.h"
#include "sysdep.h"
#include "toplev.h"
#include "unwind-prot.h"
#include "utils.h"
#include "variables.h"*/
// Primary prompt string.
static std::string VPS1 = "\\s:\\#> ";
// Secondary prompt string.
static std::string VPS2 = "> ";
// String printed before echoed input (enabled by --echo-input).
std::string VPS4 = "+ ";
// Echo commands as they are executed?
//
// 1 ==> echo commands read from script files
// 2 ==> echo commands from functions
// 4 ==> echo commands read from command line
//
// more than one state can be active at once.
//int Vecho_executing_commands = ECHO_OFF;
// The time we last printed a prompt.
//octave_time Vlast_prompt_time = 0.0;
// Character to append after successful command-line completion attempts.
//static char Vcompletion_append_char = ' ';
// Global pointer for eval().
std::string current_eval_string;
// TRUE means get input from current_eval_string.
bool get_input_from_eval_string = false;
// TRUE means we haven't been asked for the input from
// current_eval_string yet.
bool input_from_eval_string_pending = false;
// TRUE means that input is coming from a file that was named on
// the command line.
bool input_from_command_line_file = false;
// TRUE means that stdin is a terminal, not a pipe or redirected file.
bool stdin_is_tty = false;
// TRUE means we're parsing a function file.
bool reading_fcn_file = false;
// TRUE means we're parsing a classdef file.
bool reading_classdef_file = false;
// Simple name of function file we are reading.
std::string curr_fcn_file_name;
// Full name of file we are reading.
std::string curr_fcn_file_full_name;
// TRUE means we're parsing a script file.
bool reading_script_file = false;
// If we are reading from an M-file, this is it.
FILE *ff_instream = 0;
// TRUE means this is an interactive shell.
bool interactive = false;
// TRUE means the user forced this shell to be interactive (-i).
bool forced_interactive = false;
// Should we issue a prompt?
int promptflag = 1;
// The current line of input, from wherever.
std::string current_input_line;
// TRUE after a call to completion_matches.
bool octave_completion_matches_called = false;
/*// TRUE if the plotting system has requested a call to drawnow at
// the next user prompt.
bool Vdrawnow_requested = false;
// TRUE if we are in debugging mode.
bool Vdebugging = false;*/
// If we are in debugging mode, this is the last command entered, so
// that we can repeat the previous command if the user just types RET.
static std::string last_debugging_command;
// TRUE if we are running in the Emacs GUD mode.
//static bool Vgud_mode = false;
// The filemarker used to separate filenames from subfunction names
char Vfilemarker = '>';
/*
static void
do_input_echo (const std::string& input_string)
{
int do_echo = reading_script_file ?
(Vecho_executing_commands & ECHO_SCRIPTS)
: (Vecho_executing_commands & ECHO_CMD_LINE) && ! forced_interactive;
if (do_echo)
{
if (forced_interactive)
{
if (promptflag > 0)
octave_stdout << command_editor::decode_prompt_string (VPS1);
else
octave_stdout << command_editor::decode_prompt_string (VPS2);
}
else
octave_stdout << command_editor::decode_prompt_string (VPS4);
if (! input_string.empty ())
{
octave_stdout << input_string;
if (input_string[input_string.length () - 1] != '\n')
octave_stdout << "\n";
}
}
}
std::string
gnu_readline (const std::string& s, bool force_readline)
{
octave_quit ();
std::string retval;
if (line_editing || force_readline)
{
bool eof;
retval = command_editor::readline (s, eof);
if (! eof && retval.empty ())
retval = "\n";
}
else
{
if (! s.empty () && (interactive || forced_interactive))
{
FILE *stream = command_editor::get_output_stream ();
gnulib::fputs (s.c_str (), stream);
fflush (stream);
}
FILE *curr_stream = command_editor::get_input_stream ();
if (reading_fcn_file || reading_script_file || reading_classdef_file)
curr_stream = ff_instream;
retval = octave_fgets (curr_stream);
}
return retval;
}
static inline std::string
interactive_input (const std::string& s, bool force_readline = false)
{
Vlast_prompt_time.stamp ();
if (Vdrawnow_requested && (interactive || forced_interactive))
{
feval ("drawnow");
flush_octave_stdout ();
// We set Vdrawnow_requested to false even if there is an error
// in drawnow so that the error doesn't reappear at every prompt.
Vdrawnow_requested = false;
if (error_state)
return "\n";
}
return gnu_readline (s, force_readline);
}
static std::string
octave_gets (void)
{
//octave_quit ();
std::string retval;
bool history_skip_auto_repeated_debugging_command = false;
if ((interactive || forced_interactive)
&& (! (reading_fcn_file
|| reading_classdef_file
|| reading_script_file
|| get_input_from_eval_string
|| input_from_startup_file
|| input_from_command_line_file)))
{
std::string ps = (promptflag > 0) ? VPS1 : VPS2;
std::string prompt = command_editor::decode_prompt_string (ps);
pipe_handler_error_count = 0;
flush_octave_stdout ();
octave_diary << prompt;
retval = interactive_input (prompt);
// There is no need to update the load_path cache if there is no
// user input.
if (! retval.empty ()
&& retval.find_first_not_of (" \t\n\r") != std::string::npos)
{
load_path::update ();
if (Vdebugging)
last_debugging_command = retval;
else
last_debugging_command = std::string ();
}
else if (Vdebugging)
{
retval = last_debugging_command;
history_skip_auto_repeated_debugging_command = true;
}
}
else
retval = gnu_readline ("");
current_input_line = retval;
if (! current_input_line.empty ())
{
if (! (input_from_startup_file || input_from_command_line_file
|| history_skip_auto_repeated_debugging_command))
command_history::add (current_input_line);
if (! (reading_fcn_file || reading_script_file || reading_classdef_file))
{
octave_diary << current_input_line;
if (current_input_line[current_input_line.length () - 1] != '\n')
octave_diary << "\n";
}
do_input_echo (current_input_line);
}
else if (! (reading_fcn_file || reading_script_file || reading_classdef_file))
octave_diary << "\n";
return retval;
}
// Read a line from the input stream.
static std::string
get_user_input (void)
{
//octave_quit ();
std::string retval;
if (get_input_from_eval_string)
{
if (input_from_eval_string_pending)
{
input_from_eval_string_pending = false;
retval = current_eval_string;
size_t len = retval.length ();
if (len > 0 && retval[len-1] != '\n')
retval.append ("\n");
}
}
else
retval = octave_gets ();
current_input_line = retval;
return retval;
}
*/
/*
int
octave_read (char *buf, unsigned max_size)
{
// FIXME -- is this a safe way to buffer the input?
static const char * const eol = "\n";
static std::string input_buf;
static const char *pos = 0;
static size_t chars_left = 0;
int status = 0;
if (chars_left == 0)
{
pos = 0;
input_buf = get_user_input ();
chars_left = input_buf.length ();
pos = input_buf.c_str ();
}
if (chars_left > 0)
{
size_t len = max_size > chars_left ? chars_left : max_size;
assert (len > 0);
memcpy (buf, pos, len);
chars_left -= len;
pos += len;
// Make sure input ends with a new line character.
if (chars_left == 0 && buf[len-1] != '\n')
{
if (len < max_size)
{
// There is enough room to plug the newline character in
// the buffer.
buf[len++] = '\n';
}
else
{
// There isn't enough room to plug the newline character
// in the buffer so make sure it is returned on the next
// octave_read call.
pos = eol;
chars_left = 1;
}
}
status = len;
}
else if (chars_left == 0)
{
status = 0;
}
else
status = -1;
return status;
}
*/
// Fix things up so that input can come from file `name', printing a
// warning if the file doesn't exist.
/*
FILE *
get_input_from_file (const std::string& name, int warn)
{
FILE *instream = 0;
if (name.length () > 0)
instream = fopen (name.c_str (), "rb");
if (! instream && warn)
warning ("%s: no such file or directory", name.c_str ());
if (reading_fcn_file || reading_script_file || reading_classdef_file)
ff_instream = instream;
else
command_editor::set_input_stream (instream);
return instream;
}
// Fix things up so that input can come from the standard input. This
// may need to become much more complicated, which is why it's in a
// separate function.
FILE *
get_input_from_stdin (void)
{
command_editor::set_input_stream (stdin);
return command_editor::get_input_stream ();
}
// FIXME -- make this generate file names when appropriate.
static string_vector
generate_possible_completions (const std::string& text, std::string& prefix,
std::string& hint)
{
string_vector names;
prefix = "";
if (looks_like_struct (text))
names = generate_struct_completions (text, prefix, hint);
else
names = make_name_list ();
// Sort and remove duplicates.
names.sort (true);
return names;
}
static bool
is_completing_dirfns (void)
{
static std::string dirfns_commands[] = {"cd", "ls"};
static const size_t dirfns_commands_length = 2;
bool retval = false;
std::string line = command_editor::get_line_buffer ();
for (size_t i = 0; i < dirfns_commands_length; i++)
{
int index = line.find (dirfns_commands[i] + " ");
if (index == 0)
{
retval = true;
break;
}
}
return retval;
}
static std::string
generate_completion (const std::string& text, int state)
{
std::string retval;
static std::string prefix;
static std::string hint;
static size_t hint_len = 0;
static int list_index = 0;
static int name_list_len = 0;
static int name_list_total_len = 0;
static string_vector name_list;
static string_vector file_name_list;
static int matches = 0;
if (state == 0)
{
list_index = 0;
prefix = "";
hint = text;
// No reason to display symbols while completing a
// file/directory operation.
if (is_completing_dirfns ())
name_list = string_vector ();
else
name_list = generate_possible_completions (text, prefix, hint);
name_list_len = name_list.length ();
file_name_list = command_editor::generate_filename_completions (text);
name_list.append (file_name_list);
name_list_total_len = name_list.length ();
hint_len = hint.length ();
matches = 0;
for (int i = 0; i < name_list_len; i++)
if (hint == name_list[i].substr (0, hint_len))
matches++;
}
if (name_list_total_len > 0 && matches > 0)
{
while (list_index < name_list_total_len)
{
std::string name = name_list[list_index];
list_index++;
if (hint == name.substr (0, hint_len))
{
if (list_index <= name_list_len && ! prefix.empty ())
retval = prefix + "." + name;
else
retval = name;
// FIXME -- looks_like_struct is broken for now,
// so it always returns false.
if (matches == 1 && looks_like_struct (retval))
{
// Don't append anything, since we don't know
// whether it should be '(' or '.'.
command_editor::set_completion_append_character ('\0');
}
else
command_editor::set_completion_append_character
(Vcompletion_append_char);
break;
}
}
}
return retval;
}
static std::string
quoting_filename (const std::string &text, int, char quote)
{
if (quote)
return text;
else
return (std::string ("'") + text);
}
void
initialize_command_input (void)
{
// If we are using readline, this allows conditional parsing of the
// .inputrc file.
command_editor::set_name ("Octave");
// FIXME -- this needs to include a comma too, but that
// causes trouble for the new struct element completion code.
static const char *s = "\t\n !\"\'*+-/:;<=>(){}[\\]^`~";
command_editor::set_basic_word_break_characters (s);
command_editor::set_completer_word_break_characters (s);
command_editor::set_basic_quote_characters ("\"");
command_editor::set_filename_quote_characters (" \t\n\\\"'@<>=;|&()#$`?*[!:{");
command_editor::set_completer_quote_characters ("'\"");
command_editor::set_completion_function (generate_completion);
command_editor::set_quoting_function (quoting_filename);
}
static void
get_debug_input (const std::string& prompt)
{
octave_user_code *caller = octave_call_stack::caller_user_code ();
std::string nm;
int curr_debug_line = octave_call_stack::current_line ();
bool have_file = false;
if (caller)
{
nm = caller->fcn_file_name ();
if (nm.empty ())
nm = caller->name ();
else
have_file = true;
}
else
curr_debug_line = -1;
std::ostringstream buf;
if (! nm.empty ())
{
if (Vgud_mode)
{
static char ctrl_z = 'Z' & 0x1f;
buf << ctrl_z << ctrl_z << nm << ":" << curr_debug_line;
}
else
{
// FIXME -- we should come up with a clean way to detect
// that we are stopped on the no-op command that marks the
// end of a function or script.
buf << "stopped in " << nm;
if (curr_debug_line > 0)
buf << " at line " << curr_debug_line;
if (have_file)
{
std::string line_buf
= get_file_line (nm, curr_debug_line);
if (! line_buf.empty ())
buf << "\n" << curr_debug_line << ": " << line_buf;
}
}
}
std::string msg = buf.str ();
if (! msg.empty ())
std::cerr << msg << std::endl;
unwind_protect frame;
frame.protect_var (VPS1);
VPS1 = prompt;
if (stdin_is_tty)
{
if (! (interactive || forced_interactive)
|| (reading_fcn_file
|| reading_classdef_file
|| reading_script_file
|| get_input_from_eval_string
|| input_from_startup_file
|| input_from_command_line_file))
{
frame.protect_var (forced_interactive);
forced_interactive = true;
frame.protect_var (reading_fcn_file);
reading_fcn_file = false;
frame.protect_var (reading_classdef_file);
reading_classdef_file = false;
frame.protect_var (reading_script_file);
reading_script_file = false;
frame.protect_var (input_from_startup_file);
input_from_startup_file = false;
frame.protect_var (input_from_command_line_file);
input_from_command_line_file = false;
frame.protect_var (get_input_from_eval_string);
get_input_from_eval_string = false;
YY_BUFFER_STATE old_buf = current_buffer ();
YY_BUFFER_STATE new_buf = create_buffer (get_input_from_stdin ());
// FIXME: are these safe?
frame.add_fcn (switch_to_buffer, old_buf);
frame.add_fcn (delete_buffer, new_buf);
switch_to_buffer (new_buf);
}
while (Vdebugging)
{
reset_error_handler ();
reset_parser ();
// Save current value of global_command.
frame.protect_var (global_command);
global_command = 0;
// Do this with an unwind-protect cleanup function so that the
// forced variables will be unmarked in the event of an interrupt.
symbol_table::scope_id scope = symbol_table::top_scope ();
frame.add_fcn (symbol_table::unmark_forced_variables, scope);
// This is the same as yyparse in parse.y.
int retval = octave_parse ();
if (retval == 0 && global_command)
{
global_command->accept (*current_evaluator);
// FIXME -- To avoid a memory leak, global_command should be
// deleted, I think. But doing that here causes trouble if
// an error occurs while executing a debugging command
// (dbstep, for example). It's not clear to me why that
// happens.
//
// delete global_command;
//
// global_command = 0;
if (octave_completion_matches_called)
octave_completion_matches_called = false;
}
// Unmark forced variables.
// Restore previous value of global_command.
frame.run_top (2);
octave_quit ();
}
}
else
warning ("invalid attempt to debug script read from stdin");
}
*/
// If the user simply hits return, this will produce an empty matrix.
/*static octave_value_list
get_user_input (const octave_value_list& args, int nargout)
{
octave_value_list retval;
int nargin = args.length ();
int read_as_string = 0;
if (nargin == 2)
read_as_string++;
std::string prompt = args(0).string_value ();
if (error_state)
{
error ("input: unrecognized argument");
return retval;
}
flush_octave_stdout ();
octave_diary << prompt;
std::string input_buf = interactive_input (prompt.c_str (), true);
if (! (error_state || input_buf.empty ()))
{
if (! input_from_startup_file)
command_history::add (input_buf);
size_t len = input_buf.length ();
octave_diary << input_buf;
if (input_buf[len - 1] != '\n')
octave_diary << "\n";
if (len < 1)
return read_as_string ? octave_value ("") : octave_value (Matrix ());
if (read_as_string)
{
// FIXME -- fix gnu_readline and octave_gets instead!
if (input_buf.length () == 1 && input_buf[0] == '\n')
retval(0) = "";
else
retval(0) = input_buf;
}
else
{
int parse_status = 0;
retval = eval_string (input_buf, true, parse_status, nargout);
if (! Vdebugging && retval.length () == 0)
retval(0) = Matrix ();
}
}
else
error ("input: reading user-input failed!");
return retval;
}*/
/*
DEFUN (input, args, nargout,
"-*- texinfo -*-\n\
@deftypefn {Built-in Function} {} input (@var{prompt})\n\
@deftypefnx {Built-in Function} {} input (@var{prompt}, \"s\")\n\
Print a prompt and wait for user input. For example,\n\
\n\
@example\n\
input (\"Pick a number, any number! \")\n\
@end example\n\
\n\
@noindent\n\
prints the prompt\n\
\n\
@example\n\
Pick a number, any number!\n\
@end example\n\
\n\
@noindent\n\
and waits for the user to enter a value. The string entered by the user\n\
is evaluated as an expression, so it may be a literal constant, a\n\
variable name, or any other valid expression.\n\
\n\
Currently, @code{input} only returns one value, regardless of the number\n\
of values produced by the evaluation of the expression.\n\
\n\
If you are only interested in getting a literal string value, you can\n\
call @code{input} with the character string @code{\"s\"} as the second\n\
argument. This tells Octave to return the string entered by the user\n\
directly, without evaluating it first.\n\
\n\
Because there may be output waiting to be displayed by the pager, it is\n\
a good idea to always call @code{fflush (stdout)} before calling\n\
@code{input}. This will ensure that all pending output is written to\n\
the screen before your prompt. @xref{Input and Output}.\n\
@end deftypefn")
{
octave_value_list retval;
int nargin = args.length ();
if (nargin == 1 || nargin == 2)
retval = get_user_input (args, nargout);
else
print_usage ();
return retval;
}
bool
octave_yes_or_no (const std::string& prompt)
{
std::string prompt_string = prompt + "(yes or no) ";
while (1)
{
std::string input_buf = interactive_input (prompt_string, true);
if (input_buf == "yes")
return true;
else if (input_buf == "no")
return false;
else
message (0, "Please answer yes or no.");
}
}
DEFUN (yes_or_no, args, ,
"-*- texinfo -*-\n\
@deftypefn {Built-in Function} {} yes_or_no (@var{prompt})\n\
Ask the user a yes-or-no question. Return 1 if the answer is yes.\n\
Takes one argument, which is the string to display to ask the\n\
question. It should end in a space; @samp{yes-or-no-p} adds\n\
@samp{(yes or no) } to it. The user must confirm the answer with\n\
RET and can edit it until it has been confirmed.\n\
@end deftypefn")
{
octave_value retval;
int nargin = args.length ();
if (nargin == 0 || nargin == 1)
{
std::string prompt;
if (nargin == 1)
{
prompt = args(0).string_value ();
if (error_state)
{
error ("yes_or_no: PROMPT must be a character string");
return retval;
}
}
retval = octave_yes_or_no (prompt);
}
else
print_usage ();
return retval;
}
octave_value
do_keyboard (const octave_value_list& args)
{
octave_value retval;
int nargin = args.length ();
assert (nargin == 0 || nargin == 1);
unwind_protect frame;
// FIXME -- we shouldn't need both the
// command_history object and the
// Vsaving_history variable...
command_history::ignore_entries (false);
frame.add_fcn (command_history::ignore_entries, ! Vsaving_history);
frame.protect_var (Vsaving_history);
frame.protect_var (Vdebugging);
frame.add_fcn (octave_call_stack::restore_frame,
octave_call_stack::current_frame ());
// FIXME -- probably we just want to print one line, not the
// entire statement, which might span many lines...
//
// tree_print_code tpc (octave_stdout);
// stmt.accept (tpc);
Vsaving_history = true;
Vdebugging = true;
std::string prompt = "debug> ";
if (nargin > 0)
prompt = args(0).string_value ();
if (! error_state)
get_debug_input (prompt);
return retval;
}
DEFUN (keyboard, args, ,
"-*- texinfo -*-\n\
@deftypefn {Built-in Function} {} keyboard ()\n\
@deftypefnx {Built-in Function} {} keyboard (@var{prompt})\n\
This function is normally used for simple debugging. When the\n\
@code{keyboard} function is executed, Octave prints a prompt and waits\n\
for user input. The input strings are then evaluated and the results\n\
are printed. This makes it possible to examine the values of variables\n\
within a function, and to assign new values if necessary. To leave the\n\
prompt and return to normal execution type @samp{return} or @samp{dbcont}.\n\
The @code{keyboard} function does not return an exit status.\n\
\n\
If @code{keyboard} is invoked without arguments, a default prompt of\n\