Mercurial > hg > octave-lyh
comparison src/toplev.cc @ 1755:3a9462b655f1
[project @ 1996-01-22 04:47:22 by jwe]
author | jwe |
---|---|
date | Mon, 22 Jan 1996 04:47:22 +0000 |
parents | fc59af7ea536 |
children | e8e76be43e79 |
comparison
equal
deleted
inserted
replaced
1754:5f1938919fdc | 1755:3a9462b655f1 |
---|---|
42 #include <sys/types.h> | 42 #include <sys/types.h> |
43 #include <unistd.h> | 43 #include <unistd.h> |
44 #endif | 44 #endif |
45 | 45 |
46 #include "lo-error.h" | 46 #include "lo-error.h" |
47 #include "str-vec.h" | |
47 | 48 |
48 #include "builtins.h" | 49 #include "builtins.h" |
49 #include "defaults.h" | 50 #include "defaults.h" |
50 #include "defun.h" | 51 #include "defun.h" |
51 #include "dynamic-ld.h" | 52 #include "dynamic-ld.h" |
71 #include "utils.h" | 72 #include "utils.h" |
72 #include "variables.h" | 73 #include "variables.h" |
73 #include "version.h" | 74 #include "version.h" |
74 | 75 |
75 // argv[0] for this program. | 76 // argv[0] for this program. |
76 char *raw_prog_name = 0; | 77 string raw_prog_name; |
77 | 78 |
78 // Cleaned-up name of this program, not including path information. | 79 // Cleaned-up name of this program, not including path information. |
79 char *prog_name = 0; | 80 string prog_name; |
80 | 81 |
81 // Login name for user running this program. | 82 // Login name for user running this program. |
82 char *user_name = 0; | 83 string user_name; |
83 | 84 |
84 // Name of the host we are running on. | 85 // Name of the host we are running on. |
85 char *host_name = 0; | 86 string host_name; |
86 | 87 |
87 // User's home directory. | 88 // User's home directory. |
88 char *home_directory = 0; | 89 string home_directory; |
89 | 90 |
90 // Guess what? | 91 // Guess what? |
91 char *the_current_working_directory = 0; | 92 string the_current_working_directory; |
92 | 93 |
93 // The path that will be searched for programs that we execute. | 94 // The path that will be searched for programs that we execute. |
94 // (--exec-path path) | 95 // (--exec-path path) |
95 char *exec_path = 0; | 96 string exec_path; |
96 | 97 |
97 // Load path specified on command line. | 98 // Load path specified on command line. |
98 // (--path path; -p path) | 99 // (--path path; -p path) |
99 char *load_path = 0; | 100 string load_path; |
100 | 101 |
101 // Name of the info file specified on command line. | 102 // Name of the info file specified on command line. |
102 // (--info-file file) | 103 // (--info-file file) |
103 char *info_file = 0; | 104 string info_file; |
104 | 105 |
105 // Name of the info reader we'd like to use. | 106 // Name of the info reader we'd like to use. |
106 // (--info-program program) | 107 // (--info-program program) |
107 char *info_prog = 0; | 108 string info_prog; |
108 | 109 |
109 // Name of the editor to be invoked by the edit_history command. | 110 // Name of the editor to be invoked by the edit_history command. |
110 char *editor = 0; | 111 string editor; |
111 | 112 |
112 // If nonzero, don't do fancy line editing. | 113 // If nonzero, don't do fancy line editing. |
113 int no_line_editing = 0; | 114 int no_line_editing = 0; |
114 | 115 |
115 // If nonzero, print verbose info in some cases. | 116 // If nonzero, print verbose info in some cases. |
185 const char *warn_for) | 186 const char *warn_for) |
186 { | 187 { |
187 begin_unwind_frame ("parse_and_execute_2"); | 188 begin_unwind_frame ("parse_and_execute_2"); |
188 | 189 |
189 unwind_protect_int (reading_script_file); | 190 unwind_protect_int (reading_script_file); |
190 unwind_protect_ptr (curr_fcn_file_full_name); | 191 unwind_protect_str (curr_fcn_file_full_name); |
191 | 192 |
192 reading_script_file = 1; | 193 reading_script_file = 1; |
193 curr_fcn_file_full_name = s.c_str (); | 194 curr_fcn_file_full_name = s; |
194 | 195 |
195 FILE *f = get_input_from_file (s, 0); | 196 FILE *f = get_input_from_file (s, 0); |
196 | 197 |
197 if (f) | 198 if (f) |
198 { | 199 { |
288 DEFUN_TEXT ("casesen", Fcasesen, Scasesen, 10, | 289 DEFUN_TEXT ("casesen", Fcasesen, Scasesen, 10, |
289 "casesen [on|off]") | 290 "casesen [on|off]") |
290 { | 291 { |
291 Octave_object retval; | 292 Octave_object retval; |
292 | 293 |
293 DEFINE_ARGV("casesen"); | 294 int argc = args.length () + 1; |
294 | 295 |
295 if (argc == 1 || (argc > 1 && strcmp (argv[1], "off") == 0)) | 296 string_vector argv = make_argv (args, "casesen"); |
297 | |
298 if (error_state) | |
299 return retval; | |
300 | |
301 if (argc == 1 || (argc > 1 && argv[1] == "off")) | |
296 warning ("casesen: sorry, Octave is always case sensitive"); | 302 warning ("casesen: sorry, Octave is always case sensitive"); |
297 else if (argc > 1 && strcmp (argv[1], "on") == 0) | 303 else if (argc > 1 && argv[1] == "on") |
298 ; // ok. | 304 ; // ok. |
299 else | 305 else |
300 print_usage ("casesen"); | 306 print_usage ("casesen"); |
301 | |
302 DELETE_ARGV; | |
303 | 307 |
304 return retval; | 308 return retval; |
305 } | 309 } |
306 | 310 |
307 DEFUN ("computer", Fcomputer, Scomputer, 11, | 311 DEFUN ("computer", Fcomputer, Scomputer, 11, |
428 | 432 |
429 return retval; | 433 return retval; |
430 } | 434 } |
431 | 435 |
432 static Octave_object | 436 static Octave_object |
433 eval_string (const char *string, int print, int& parse_status, | 437 eval_string (const string& s, int print, int& parse_status, |
434 int nargout) | 438 int nargout) |
435 { | 439 { |
436 begin_unwind_frame ("eval_string"); | 440 begin_unwind_frame ("eval_string"); |
437 | 441 |
438 unwind_protect_int (get_input_from_eval_string); | 442 unwind_protect_int (get_input_from_eval_string); |
439 unwind_protect_int (input_from_command_line_file); | 443 unwind_protect_int (input_from_command_line_file); |
440 unwind_protect_ptr (global_command); | 444 unwind_protect_ptr (global_command); |
441 unwind_protect_ptr (current_eval_string); | 445 unwind_protect_str (current_eval_string); |
442 | 446 |
443 get_input_from_eval_string = 1; | 447 get_input_from_eval_string = 1; |
444 input_from_command_line_file = 0; | 448 input_from_command_line_file = 0; |
445 current_eval_string = string; | 449 current_eval_string = s; |
446 | 450 |
447 YY_BUFFER_STATE old_buf = current_buffer (); | 451 YY_BUFFER_STATE old_buf = current_buffer (); |
448 YY_BUFFER_STATE new_buf = create_buffer (0); | 452 YY_BUFFER_STATE new_buf = create_buffer (0); |
449 | 453 |
450 add_unwind_protect (restore_input_buffer, (void *) old_buf); | 454 add_unwind_protect (restore_input_buffer, (void *) old_buf); |
476 | 480 |
477 return retval; | 481 return retval; |
478 } | 482 } |
479 | 483 |
480 tree_constant | 484 tree_constant |
481 eval_string (const char *string, int print, int& parse_status) | 485 eval_string (const string& s, int print, int& parse_status) |
482 { | 486 { |
483 tree_constant retval; | 487 tree_constant retval; |
484 | 488 |
485 Octave_object tmp = eval_string (string, print, parse_status, 1); | 489 Octave_object tmp = eval_string (s, print, parse_status, 1); |
486 | 490 |
487 retval = tmp(0); | 491 retval = tmp(0); |
488 | 492 |
489 return retval; | 493 return retval; |
490 } | 494 } |
491 | 495 |
492 static Octave_object | 496 static Octave_object |
493 eval_string (const tree_constant& arg, int& parse_status, int nargout) | 497 eval_string (const tree_constant& arg, int& parse_status, int nargout) |
494 { | 498 { |
495 string tstr = arg.string_value (); | 499 string s = arg.string_value (); |
496 const char *string = tstr.c_str (); | |
497 | 500 |
498 if (error_state) | 501 if (error_state) |
499 { | 502 { |
500 error ("eval: expecting string argument"); | 503 error ("eval: expecting string argument"); |
501 return -1.0; | 504 return -1.0; |
502 } | 505 } |
503 | 506 |
504 // Yes Virginia, we always print here... | 507 // Yes Virginia, we always print here... |
505 | 508 |
506 return eval_string (string, 1, parse_status, nargout); | 509 return eval_string (s, 1, parse_status, nargout); |
507 } | 510 } |
508 | 511 |
509 DEFUN ("eval", Feval, Seval, 11, | 512 DEFUN ("eval", Feval, Seval, 11, |
510 "eval (TRY, CATCH)\n\ | 513 "eval (TRY, CATCH)\n\ |
511 \n\ | 514 \n\ |
569 return retval; | 572 return retval; |
570 } | 573 } |
571 | 574 |
572 tree_constant tc_command = args(0); | 575 tree_constant tc_command = args(0); |
573 | 576 |
574 string tstr = tc_command.string_value (); | 577 string tmp = tc_command.string_value (); |
575 const char *tmp_str = tstr.c_str (); | |
576 | 578 |
577 if (error_state) | 579 if (error_state) |
578 { | 580 { |
579 error ("system: expecting string as first argument"); | 581 error ("system: expecting string as first argument"); |
580 } | 582 } |
581 else | 583 else |
582 { | 584 { |
583 iprocstream *cmd = new iprocstream (tmp_str); | 585 iprocstream *cmd = new iprocstream (tmp.c_str ()); |
584 | 586 |
585 add_unwind_protect (cleanup_iprocstream, cmd); | 587 add_unwind_protect (cleanup_iprocstream, cmd); |
586 | 588 |
587 int status = 127; | 589 int status = 127; |
588 | 590 |
616 } | 618 } |
617 else | 619 else |
618 maybe_page_output (output_buf); | 620 maybe_page_output (output_buf); |
619 } | 621 } |
620 else | 622 else |
621 error ("unable to start subprocess for `%s'", tmp_str); | 623 error ("unable to start subprocess for `%s'", tmp.c_str ()); |
622 | 624 |
623 run_unwind_protect (); | 625 run_unwind_protect (); |
624 } | 626 } |
625 | 627 |
626 return retval; | 628 return retval; |