comparison src/oct-hist.cc @ 3523:b80bbb43a1a9

[project @ 2000-02-02 10:25:52 by jwe]
author jwe
date Wed, 02 Feb 2000 10:26:25 +0000
parents d14c483b3c12
children 096ad38d7ab5
comparison
equal deleted inserted replaced
3522:bd422cf62f0c 3523:b80bbb43a1a9
74 74
75 // TRUE means input is coming from temporary history file. 75 // TRUE means input is coming from temporary history file.
76 bool input_from_tmp_history_file = false; 76 bool input_from_tmp_history_file = false;
77 77
78 // Where history is saved. 78 // Where history is saved.
79 static string Vhistory_file; 79 static std::string Vhistory_file;
80 80
81 // The number of lines to keep in the history file. 81 // The number of lines to keep in the history file.
82 static int Vhistory_size; 82 static int Vhistory_size;
83 83
84 // TRUE if we are saving history. 84 // TRUE if we are saving history.
90 int 90 int
91 default_history_size (void) 91 default_history_size (void)
92 { 92 {
93 int size = 1024; 93 int size = 1024;
94 94
95 string env_size = octave_env::getenv ("OCTAVE_HISTSIZE"); 95 std::string env_size = octave_env::getenv ("OCTAVE_HISTSIZE");
96 96
97 if (! env_size.empty ()) 97 if (! env_size.empty ())
98 { 98 {
99 int val; 99 int val;
100 100
106 } 106 }
107 107
108 string 108 string
109 default_history_file (void) 109 default_history_file (void)
110 { 110 {
111 string file; 111 std::string file;
112 112
113 string env_file = octave_env::getenv ("OCTAVE_HISTFILE"); 113 std::string env_file = octave_env::getenv ("OCTAVE_HISTFILE");
114 114
115 if (! env_file.empty ()) 115 if (! env_file.empty ())
116 { 116 {
117 fstream f (env_file.c_str (), (ios::in | ios::out)); 117 fstream f (env_file.c_str (), (ios::in | ios::out));
118 118
123 } 123 }
124 } 124 }
125 125
126 if (file.empty ()) 126 if (file.empty ())
127 { 127 {
128 string home_dir = octave_env::get_home_directory (); 128 std::string home_dir = octave_env::get_home_directory ();
129 129
130 if (! home_dir.empty ()) 130 if (! home_dir.empty ())
131 { 131 {
132 file = home_dir; 132 file = home_dir;
133 file.append ("/.octave_hist"); 133 file.append ("/.octave_hist");
151 int numbered_output = 1; 151 int numbered_output = 1;
152 152
153 int i; 153 int i;
154 for (i = 1; i < argc; i++) 154 for (i = 1; i < argc; i++)
155 { 155 {
156 string option = argv[i]; 156 std::string option = argv[i];
157 157
158 if (option == "-r" || option == "-w" || option == "-a" 158 if (option == "-r" || option == "-w" || option == "-a"
159 || option == "-n") 159 || option == "-n")
160 { 160 {
161 if (i < argc - 1) 161 if (i < argc - 1)
162 { 162 {
163 string file = file_ops::tilde_expand (argv[i+1]); 163 std::string file = file_ops::tilde_expand (argv[i+1]);
164 command_history::set_file (file); 164 command_history::set_file (file);
165 } 165 }
166 166
167 if (option == "-a") 167 if (option == "-a")
168 // Append `new' lines to file. 168 // Append `new' lines to file.
281 // new command becomes the history entry, and that `fc' should never 281 // new command becomes the history entry, and that `fc' should never
282 // appear in the history list. This way you can do `run_history' to 282 // appear in the history list. This way you can do `run_history' to
283 // your heart's content. 283 // your heart's content.
284 284
285 static void 285 static void
286 edit_history_repl_hist (const string& command) 286 edit_history_repl_hist (const std::string& command)
287 { 287 {
288 if (! command.empty ()) 288 if (! command.empty ())
289 { 289 {
290 string_vector hlist = command_history::list (); 290 string_vector hlist = command_history::list ();
291 291
293 293
294 if (len > 0) 294 if (len > 0)
295 { 295 {
296 int i = len - 1; 296 int i = len - 1;
297 297
298 string histent = command_history::get_entry (i); 298 std::string histent = command_history::get_entry (i);
299 299
300 if (! histent.empty ()) 300 if (! histent.empty ())
301 { 301 {
302 string cmd = command; 302 std::string cmd = command;
303 303
304 int cmd_len = cmd.length (); 304 int cmd_len = cmd.length ();
305 305
306 if (cmd[cmd_len - 1] == '\n') 306 if (cmd[cmd_len - 1] == '\n')
307 cmd.resize (cmd_len - 1); 307 cmd.resize (cmd_len - 1);
312 } 312 }
313 } 313 }
314 } 314 }
315 315
316 static void 316 static void
317 edit_history_add_hist (const string& line) 317 edit_history_add_hist (const std::string& line)
318 { 318 {
319 if (! line.empty ()) 319 if (! line.empty ())
320 { 320 {
321 string tmp = line; 321 std::string tmp = line;
322 322
323 int len = tmp.length (); 323 int len = tmp.length ();
324 324
325 if (len > 0 && tmp[len-1] == '\n') 325 if (len > 0 && tmp[len-1] == '\n')
326 tmp.resize (len - 1); 326 tmp.resize (len - 1);
332 332
333 static string 333 static string
334 mk_tmp_hist_file (int argc, const string_vector& argv, 334 mk_tmp_hist_file (int argc, const string_vector& argv,
335 int insert_curr, const char *warn_for) 335 int insert_curr, const char *warn_for)
336 { 336 {
337 string retval; 337 std::string retval;
338 338
339 string_vector hlist = command_history::list (); 339 string_vector hlist = command_history::list ();
340 340
341 int hist_count = hlist.length (); 341 int hist_count = hlist.length ();
342 342
401 hist_end = hist_beg; 401 hist_end = hist_beg;
402 hist_beg = t; 402 hist_beg = t;
403 reverse = 1; 403 reverse = 1;
404 } 404 }
405 405
406 string name = file_ops::tempnam ("", "oct-"); 406 std::string name = file_ops::tempnam ("", "oct-");
407 407
408 fstream file (name.c_str (), ios::out); 408 fstream file (name.c_str (), ios::out);
409 409
410 if (! file) 410 if (! file)
411 { 411 {
431 } 431 }
432 432
433 static void 433 static void
434 do_edit_history (int argc, const string_vector& argv) 434 do_edit_history (int argc, const string_vector& argv)
435 { 435 {
436 string name = mk_tmp_hist_file (argc, argv, 0, "edit_history"); 436 std::string name = mk_tmp_hist_file (argc, argv, 0, "edit_history");
437 437
438 if (name.empty ()) 438 if (name.empty ())
439 return; 439 return;
440 440
441 // Call up our favorite editor on the file of commands. 441 // Call up our favorite editor on the file of commands.
442 442
443 string cmd = Veditor; 443 std::string cmd = Veditor;
444 cmd.append (" "); 444 cmd.append (" ");
445 cmd.append (name); 445 cmd.append (name);
446 446
447 // Ignore interrupts while we are off editing commands. Should we 447 // Ignore interrupts while we are off editing commands. Should we
448 // maybe avoid using system()? 448 // maybe avoid using system()?
504 } 504 }
505 505
506 static void 506 static void
507 do_run_history (int argc, const string_vector& argv) 507 do_run_history (int argc, const string_vector& argv)
508 { 508 {
509 string name = mk_tmp_hist_file (argc, argv, 1, "run_history"); 509 std::string name = mk_tmp_hist_file (argc, argv, 1, "run_history");
510 510
511 if (name.empty ()) 511 if (name.empty ())
512 return; 512 return;
513 513
514 // Turn on command echo so the output from this will make better 514 // Turn on command echo so the output from this will make better
669 static int 669 static int
670 history_file (void) 670 history_file (void)
671 { 671 {
672 int status = 0; 672 int status = 0;
673 673
674 string s = builtin_string_variable ("history_file"); 674 std::string s = builtin_string_variable ("history_file");
675 675
676 if (s.empty ()) 676 if (s.empty ())
677 { 677 {
678 gripe_invalid_value_specified ("history_file"); 678 gripe_invalid_value_specified ("history_file");
679 status = -1; 679 status = -1;