comparison src/input.cc @ 3523:b80bbb43a1a9

[project @ 2000-02-02 10:25:52 by jwe]
author jwe
date Wed, 02 Feb 2000 10:26:25 +0000
parents 957d7d6ab0e0
children 096ad38d7ab5
comparison
equal deleted inserted replaced
3522:bd422cf62f0c 3523:b80bbb43a1a9
66 #include "unwind-prot.h" 66 #include "unwind-prot.h"
67 #include "utils.h" 67 #include "utils.h"
68 #include "variables.h" 68 #include "variables.h"
69 69
70 // Primary prompt string. 70 // Primary prompt string.
71 static string Vps1; 71 static std::string Vps1;
72 72
73 // Secondary prompt string. 73 // Secondary prompt string.
74 static string Vps2; 74 static std::string Vps2;
75 75
76 // String printed before echoed input (enabled by --echo-input). 76 // String printed before echoed input (enabled by --echo-input).
77 string Vps4; 77 std::string Vps4;
78 78
79 // Echo commands as they are executed? 79 // Echo commands as they are executed?
80 // 80 //
81 // 1 ==> echo commands read from script files 81 // 1 ==> echo commands read from script files
82 // 2 ==> echo commands from functions 82 // 2 ==> echo commands from functions
90 90
91 // Character to append after successful command-line completion attempts. 91 // Character to append after successful command-line completion attempts.
92 static char Vcompletion_append_char; 92 static char Vcompletion_append_char;
93 93
94 // Global pointer for eval(). 94 // Global pointer for eval().
95 string current_eval_string; 95 std::string current_eval_string;
96 96
97 // TRUE means get input from current_eval_string. 97 // TRUE means get input from current_eval_string.
98 bool get_input_from_eval_string = false; 98 bool get_input_from_eval_string = false;
99 99
100 // TRUE means we're parsing a function file. 100 // TRUE means we're parsing a function file.
101 bool reading_fcn_file = false; 101 bool reading_fcn_file = false;
102 102
103 // Simple name of function file we are reading. 103 // Simple name of function file we are reading.
104 string curr_fcn_file_name; 104 std::string curr_fcn_file_name;
105 105
106 // Full name of file we are reading. 106 // Full name of file we are reading.
107 string curr_fcn_file_full_name; 107 std::string curr_fcn_file_full_name;
108 108
109 // TRUE means we're parsing a script file. 109 // TRUE means we're parsing a script file.
110 bool reading_script_file = false; 110 bool reading_script_file = false;
111 111
112 // If we are reading from an M-file, this is it. 112 // If we are reading from an M-file, this is it.
120 120
121 // Should we issue a prompt? 121 // Should we issue a prompt?
122 int promptflag = 1; 122 int promptflag = 1;
123 123
124 // The current line of input, from wherever. 124 // The current line of input, from wherever.
125 string current_input_line; 125 std::string current_input_line;
126 126
127 // TRUE after a call to completion_matches(). 127 // TRUE after a call to completion_matches().
128 bool octave_completion_matches_called = false; 128 bool octave_completion_matches_called = false;
129 129
130 static void 130 static void
131 do_input_echo (const string& input_string) 131 do_input_echo (const std::string& input_string)
132 { 132 {
133 int do_echo = reading_script_file ? 133 int do_echo = reading_script_file ?
134 (Vecho_executing_commands & ECHO_SCRIPTS) 134 (Vecho_executing_commands & ECHO_SCRIPTS)
135 : (Vecho_executing_commands & ECHO_CMD_LINE) && ! forced_interactive; 135 : (Vecho_executing_commands & ECHO_CMD_LINE) && ! forced_interactive;
136 136
155 } 155 }
156 } 156 }
157 } 157 }
158 158
159 string 159 string
160 gnu_readline (const string& s, bool force_readline) 160 gnu_readline (const std::string& s, bool force_readline)
161 { 161 {
162 string retval; 162 std::string retval;
163 163
164 if (line_editing || force_readline) 164 if (line_editing || force_readline)
165 { 165 {
166 bool eof; 166 bool eof;
167 167
192 } 192 }
193 193
194 static string 194 static string
195 octave_gets (void) 195 octave_gets (void)
196 { 196 {
197 string retval; 197 std::string retval;
198 198
199 Vlast_prompt_time.stamp (); 199 Vlast_prompt_time.stamp ();
200 200
201 if ((interactive || forced_interactive) 201 if ((interactive || forced_interactive)
202 && (! (reading_fcn_file || reading_script_file))) 202 && (! (reading_fcn_file || reading_script_file)))
203 { 203 {
204 string ps = (promptflag > 0) ? Vps1 : Vps2; 204 std::string ps = (promptflag > 0) ? Vps1 : Vps2;
205 205
206 string prompt = command_editor::decode_prompt_string (ps); 206 std::string prompt = command_editor::decode_prompt_string (ps);
207 207
208 pipe_handler_error_count = 0; 208 pipe_handler_error_count = 0;
209 209
210 flush_octave_stdout (); 210 flush_octave_stdout ();
211 211
242 // Read a line from the input stream. 242 // Read a line from the input stream.
243 243
244 static string 244 static string
245 get_user_input (void) 245 get_user_input (void)
246 { 246 {
247 string retval; 247 std::string retval;
248 248
249 if (get_input_from_eval_string) 249 if (get_input_from_eval_string)
250 { 250 {
251 retval = current_eval_string; 251 retval = current_eval_string;
252 252
269 int 269 int
270 octave_read (char *buf, unsigned max_size) 270 octave_read (char *buf, unsigned max_size)
271 { 271 {
272 // XXX FIXME XXX -- is this a safe way to buffer the input? 272 // XXX FIXME XXX -- is this a safe way to buffer the input?
273 273
274 static string input_buf; 274 static std::string input_buf;
275 static const char *pos = 0; 275 static const char *pos = 0;
276 static size_t chars_left = 0; 276 static size_t chars_left = 0;
277 277
278 int status = 0; 278 int status = 0;
279 279
336 336
337 // Fix things up so that input can come from file `name', printing a 337 // Fix things up so that input can come from file `name', printing a
338 // warning if the file doesn't exist. 338 // warning if the file doesn't exist.
339 339
340 FILE * 340 FILE *
341 get_input_from_file (const string& name, int warn) 341 get_input_from_file (const std::string& name, int warn)
342 { 342 {
343 FILE *instream = 0; 343 FILE *instream = 0;
344 344
345 if (name.length () > 0) 345 if (name.length () > 0)
346 instream = fopen (name.c_str (), "r"); 346 instream = fopen (name.c_str (), "r");
368 } 368 }
369 369
370 // XXX FIXME XXX -- make this generate file names when appropriate. 370 // XXX FIXME XXX -- make this generate file names when appropriate.
371 371
372 static string_vector 372 static string_vector
373 generate_possible_completions (const string& text, string& prefix, 373 generate_possible_completions (const std::string& text, std::string& prefix,
374 string& hint) 374 std::string& hint)
375 { 375 {
376 string_vector names; 376 string_vector names;
377 377
378 prefix = ""; 378 prefix = "";
379 379
388 388
389 return names; 389 return names;
390 } 390 }
391 391
392 static string 392 static string
393 generate_completion (const string& text, int state) 393 generate_completion (const std::string& text, int state)
394 { 394 {
395 string retval; 395 std::string retval;
396 396
397 static string prefix; 397 static std::string prefix;
398 static string hint; 398 static std::string hint;
399 399
400 static size_t prefix_len = 0; 400 static size_t prefix_len = 0;
401 static size_t hint_len = 0; 401 static size_t hint_len = 0;
402 402
403 static int list_index = 0; 403 static int list_index = 0;
431 431
432 if (name_list_len > 0 && matches > 0) 432 if (name_list_len > 0 && matches > 0)
433 { 433 {
434 while (list_index < name_list_len) 434 while (list_index < name_list_len)
435 { 435 {
436 string name = name_list[list_index]; 436 std::string name = name_list[list_index];
437 437
438 list_index++; 438 list_index++;
439 439
440 if (! name.compare (hint, 0, hint_len)) 440 if (! name.compare (hint, 0, hint_len))
441 { 441 {
470 470
471 command_editor::set_completion_function (generate_completion); 471 command_editor::set_completion_function (generate_completion);
472 } 472 }
473 473
474 static bool 474 static bool
475 match_sans_spaces (const string& standard, const string& test) 475 match_sans_spaces (const std::string& standard, const std::string& test)
476 { 476 {
477 size_t beg = test.find_first_not_of (" \t"); 477 size_t beg = test.find_first_not_of (" \t");
478 478
479 if (beg != NPOS) 479 if (beg != NPOS)
480 { 480 {
500 int read_as_string = 0; 500 int read_as_string = 0;
501 501
502 if (nargin == 2) 502 if (nargin == 2)
503 read_as_string++; 503 read_as_string++;
504 504
505 string prompt ("debug> "); 505 std::string prompt ("debug> ");
506 506
507 if (nargin > 0) 507 if (nargin > 0)
508 { 508 {
509 prompt = args(0).string_value (); 509 prompt = args(0).string_value ();
510 510
517 517
518 again: 518 again:
519 519
520 flush_octave_stdout (); 520 flush_octave_stdout ();
521 521
522 string input_buf = gnu_readline (prompt.c_str (), true); 522 std::string input_buf = gnu_readline (prompt.c_str (), true);
523 523
524 if (! input_buf.empty ()) 524 if (! input_buf.empty ())
525 { 525 {
526 if (! input_from_startup_file) 526 if (! input_from_startup_file)
527 command_history::add (input_buf); 527 command_history::add (input_buf);
735 } 735 }
736 break; 736 break;
737 737
738 case 2: 738 case 2:
739 { 739 {
740 string arg = argv[1]; 740 std::string arg = argv[1];
741 741
742 if (arg == "on") 742 if (arg == "on")
743 bind_builtin_variable ("echo_executing_commands", 743 bind_builtin_variable ("echo_executing_commands",
744 static_cast<double> (ECHO_SCRIPTS)); 744 static_cast<double> (ECHO_SCRIPTS));
745 else if (arg == "off") 745 else if (arg == "off")
750 } 750 }
751 break; 751 break;
752 752
753 case 3: 753 case 3:
754 { 754 {
755 string arg = argv[1]; 755 std::string arg = argv[1];
756 756
757 if (arg == "on" && argv[2] == "all") 757 if (arg == "on" && argv[2] == "all")
758 { 758 {
759 int tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS); 759 int tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS);
760 bind_builtin_variable ("echo_executing_commands", 760 bind_builtin_variable ("echo_executing_commands",
791 791
792 int nargin = args.length (); 792 int nargin = args.length ();
793 793
794 if (nargin == 1) 794 if (nargin == 1)
795 { 795 {
796 string hint = args(0).string_value (); 796 std::string hint = args(0).string_value ();
797 797
798 if (! error_state) 798 if (! error_state)
799 { 799 {
800 int n = 32; 800 int n = 32;
801 801
803 803
804 int k = 0; 804 int k = 0;
805 805
806 for (;;) 806 for (;;)
807 { 807 {
808 string cmd = generate_completion (hint, k); 808 std::string cmd = generate_completion (hint, k);
809 809
810 if (! cmd.empty ()) 810 if (! cmd.empty ())
811 { 811 {
812 if (k == n) 812 if (k == n)
813 { 813 {
866 866
867 if (nargin == 0) 867 if (nargin == 0)
868 command_editor::read_init_file (); 868 command_editor::read_init_file ();
869 else if (nargin == 1) 869 else if (nargin == 1)
870 { 870 {
871 string file = file_ops::tilde_expand (args(0).string_value ()); 871 std::string file = file_ops::tilde_expand (args(0).string_value ());
872 872
873 if (! error_state) 873 if (! error_state)
874 command_editor::read_init_file (file); 874 command_editor::read_init_file (file);
875 } 875 }
876 else 876 else
877 print_usage ("read_readline_init_file"); 877 print_usage ("read_readline_init_file");
878 878
879 return retval; 879 return retval;
880 } 880 }
881 881
882 static string hook_fcn; 882 static std::string hook_fcn;
883 static octave_value user_data; 883 static octave_value user_data;
884 884
885 static void 885 static void
886 input_event_hook (void) 886 input_event_hook (void)
887 { 887 {
915 print_usage ("input_event_hook"); 915 print_usage ("input_event_hook");
916 else 916 else
917 { 917 {
918 octave_value tmp_user_data; 918 octave_value tmp_user_data;
919 919
920 string tmp_hook_fcn; 920 std::string tmp_hook_fcn;
921 921
922 if (nargin > 1) 922 if (nargin > 1)
923 tmp_user_data = args(1); 923 tmp_user_data = args(1);
924 924
925 if (nargin > 0) 925 if (nargin > 0)
981 static int 981 static int
982 completion_append_char (void) 982 completion_append_char (void)
983 { 983 {
984 int status = 0; 984 int status = 0;
985 985
986 string s = builtin_string_variable ("completion_append_char"); 986 std::string s = builtin_string_variable ("completion_append_char");
987 987
988 switch (s.length ()) 988 switch (s.length ())
989 { 989 {
990 case 1: 990 case 1:
991 Vcompletion_append_char = s[0]; 991 Vcompletion_append_char = s[0];