1683
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1683
|
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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include <cassert> |
4489
|
28 #include <cerrno> |
1683
|
29 #include <cstdlib> |
|
30 #include <cstring> |
4221
|
31 #include <new> |
1683
|
32 |
3503
|
33 #include <fstream> |
|
34 #include <iostream> |
1728
|
35 #include <string> |
|
36 |
1683
|
37 #ifdef HAVE_UNISTD_H |
2442
|
38 #ifdef HAVE_SYS_TYPES_H |
1683
|
39 #include <sys/types.h> |
2442
|
40 #endif |
1683
|
41 #include <unistd.h> |
|
42 #endif |
|
43 |
2926
|
44 #include "cmd-edit.h" |
|
45 #include "file-ops.h" |
1683
|
46 #include "lo-error.h" |
2370
|
47 #include "lo-mappers.h" |
4051
|
48 #include "lo-sstream.h" |
3020
|
49 #include "oct-env.h" |
4153
|
50 #include "quit.h" |
1755
|
51 #include "str-vec.h" |
1683
|
52 |
2492
|
53 #include <defaults.h> |
1683
|
54 #include "defun.h" |
|
55 #include "error.h" |
|
56 #include "file-io.h" |
|
57 #include "input.h" |
|
58 #include "lex.h" |
2492
|
59 #include <oct-conf.h> |
1742
|
60 #include "oct-hist.h" |
2162
|
61 #include "oct-map.h" |
2862
|
62 #include "oct-obj.h" |
1683
|
63 #include "pager.h" |
|
64 #include "parse.h" |
|
65 #include "pathsearch.h" |
|
66 #include "procstream.h" |
2370
|
67 #include "ov.h" |
2985
|
68 #include "pt-jump.h" |
2982
|
69 #include "pt-stmt.h" |
1683
|
70 #include "sighandlers.h" |
|
71 #include "sysdep.h" |
2693
|
72 #include "syswait.h" |
1750
|
73 #include "toplev.h" |
1683
|
74 #include "unwind-prot.h" |
|
75 #include "utils.h" |
|
76 #include "variables.h" |
2492
|
77 #include <version.h> |
1683
|
78 |
3020
|
79 // TRUE means we are exiting via the builtin exit or quit functions. |
|
80 static bool quitting_gracefully = false; |
1683
|
81 |
4217
|
82 // TRUE means we are ready to interpret commands, but not everything |
|
83 // is ready for interactive use. |
|
84 bool octave_interpreter_ready = false; |
|
85 |
4172
|
86 // TRUE means we've processed all the init code and we are good to go. |
|
87 bool octave_initialized = false; |
|
88 |
1683
|
89 // Current command to execute. |
|
90 tree_statement_list *global_command = 0; |
|
91 |
|
92 // Pointer to function that is currently being evaluated. |
4748
|
93 octave_function *curr_function = 0; |
1683
|
94 |
4975
|
95 // Pointer to caller of curr_function. |
|
96 octave_function *curr_caller_function = 0; |
|
97 |
4238
|
98 // Pointer to parent function that is currently being evaluated. |
4748
|
99 octave_function *curr_parent_function = 0; |
4238
|
100 |
4180
|
101 static void |
|
102 recover_from_exception (void) |
|
103 { |
|
104 can_interrupt = true; |
4182
|
105 octave_interrupt_immediately = 0; |
4180
|
106 octave_interrupt_state = 0; |
5142
|
107 octave_signal_caught = 0; |
4180
|
108 octave_allocation_error = 0; |
|
109 octave_restore_signal_mask (); |
|
110 octave_catch_interrupts (); |
|
111 } |
|
112 |
1907
|
113 int |
4356
|
114 main_loop (const std::string& fun_to_call) |
1907
|
115 { |
2016
|
116 octave_save_signal_mask (); |
|
117 |
4153
|
118 if (octave_set_current_context) |
1907
|
119 { |
4153
|
120 #if defined (USE_EXCEPTIONS_FOR_INTERRUPTS) |
|
121 panic_impossible (); |
|
122 #else |
|
123 unwind_protect::run_all (); |
1907
|
124 raw_mode (0); |
3531
|
125 std::cout << "\n"; |
2016
|
126 octave_restore_signal_mask (); |
4153
|
127 #endif |
1907
|
128 } |
|
129 |
3020
|
130 can_interrupt = true; |
1907
|
131 |
5142
|
132 octave_signal_hook = octave_signal_handler; |
4429
|
133 octave_interrupt_hook = unwind_protect::run_all; |
|
134 octave_bad_alloc_hook = unwind_protect::run_all; |
|
135 |
2554
|
136 octave_catch_interrupts (); |
1907
|
137 |
4172
|
138 octave_initialized = true; |
|
139 |
4356
|
140 if (! fun_to_call.empty ()) |
|
141 feval (fun_to_call); |
|
142 |
1907
|
143 // The big loop. |
|
144 |
4153
|
145 int retval = 0; |
1907
|
146 do |
|
147 { |
4180
|
148 try |
1907
|
149 { |
4153
|
150 curr_sym_tab = top_level_sym_tab; |
2620
|
151 |
4318
|
152 reset_error_handler (); |
|
153 |
4153
|
154 reset_parser (); |
2620
|
155 |
4753
|
156 // This is the same as yyparse in parse.y. |
|
157 retval = octave_parse (); |
2620
|
158 |
4153
|
159 if (retval == 0) |
|
160 { |
|
161 if (global_command) |
3804
|
162 { |
4153
|
163 global_command->eval (); |
3883
|
164 |
4153
|
165 delete global_command; |
3883
|
166 |
4153
|
167 global_command = 0; |
3883
|
168 |
4171
|
169 OCTAVE_QUIT; |
|
170 |
3883
|
171 if (! (interactive || forced_interactive)) |
|
172 { |
4207
|
173 bool quit = (tree_return_command::returning |
|
174 || tree_break_command::breaking); |
4153
|
175 |
4207
|
176 if (tree_return_command::returning) |
|
177 tree_return_command::returning = 0; |
4153
|
178 |
4207
|
179 if (tree_break_command::breaking) |
|
180 tree_break_command::breaking--; |
4153
|
181 |
|
182 if (quit) |
|
183 break; |
|
184 } |
|
185 |
|
186 if (error_state) |
|
187 { |
|
188 if (! (interactive || forced_interactive)) |
|
189 { |
|
190 // We should exit with a non-zero status. |
|
191 retval = 1; |
|
192 break; |
|
193 } |
|
194 } |
|
195 else |
|
196 { |
|
197 if (octave_completion_matches_called) |
|
198 octave_completion_matches_called = false; |
|
199 else |
|
200 command_editor::increment_current_command_number (); |
3883
|
201 } |
|
202 } |
4153
|
203 else if (parser_end_of_input) |
|
204 break; |
2620
|
205 } |
4153
|
206 } |
4182
|
207 catch (octave_interrupt_exception) |
4153
|
208 { |
4180
|
209 recover_from_exception (); |
4155
|
210 std::cout << "\n"; |
4180
|
211 } |
4181
|
212 catch (std::bad_alloc) |
4180
|
213 { |
|
214 recover_from_exception (); |
|
215 std::cerr |
|
216 << "error: memory exhausted -- trying to return to prompt\n"; |
1907
|
217 } |
|
218 } |
|
219 while (retval == 0); |
|
220 |
|
221 return retval; |
|
222 } |
|
223 |
1683
|
224 // Fix up things before exiting. |
|
225 |
|
226 void |
3162
|
227 clean_up_and_exit (int retval) |
|
228 { |
3216
|
229 do_octave_atexit (); |
1683
|
230 |
3162
|
231 exit (retval == EOF ? 0 : retval); |
1683
|
232 } |
|
233 |
4208
|
234 DEFCMD (casesen, args, , |
3446
|
235 "-*- texinfo -*-\n\ |
|
236 @deffn {Command} casesen arg\n\ |
|
237 Provided for compatibility with Matlab, but does nothing.\n\ |
|
238 @end deffn") |
1683
|
239 { |
2086
|
240 octave_value_list retval; |
1683
|
241 |
1755
|
242 int argc = args.length () + 1; |
|
243 |
1965
|
244 string_vector argv = args.make_argv ("casesen"); |
1683
|
245 |
1755
|
246 if (error_state) |
|
247 return retval; |
|
248 |
|
249 if (argc == 1 || (argc > 1 && argv[1] == "off")) |
1683
|
250 warning ("casesen: sorry, Octave is always case sensitive"); |
1755
|
251 else if (argc > 1 && argv[1] == "on") |
1683
|
252 ; // ok. |
|
253 else |
|
254 print_usage ("casesen"); |
|
255 |
|
256 return retval; |
|
257 } |
|
258 |
3180
|
259 DEFUN (quit, args, nargout, |
3332
|
260 "-*- texinfo -*-\n\ |
|
261 @deftypefn {Built-in Function} {} exit (@var{status})\n\ |
|
262 @deftypefnx {Built-in Function} {} quit (@var{status})\n\ |
|
263 Exit the current Octave session. If the optional integer value\n\ |
|
264 @var{status} is supplied, pass that value to the operating system as the\n\ |
|
265 Octave's exit status.\n\ |
3333
|
266 @end deftypefn") |
1683
|
267 { |
2086
|
268 octave_value_list retval; |
2068
|
269 |
3180
|
270 if (nargout == 0) |
2068
|
271 { |
3180
|
272 int exit_status = 0; |
|
273 |
|
274 quitting_gracefully = true; |
1683
|
275 |
3180
|
276 if (args.length () > 0) |
|
277 { |
3202
|
278 int tmp = args(0).nint_value (); |
1683
|
279 |
3202
|
280 if (! error_state) |
|
281 exit_status = tmp; |
3180
|
282 } |
|
283 |
|
284 clean_up_and_exit (exit_status); |
2068
|
285 } |
3180
|
286 else |
|
287 error ("quit: invalid number of output arguments"); |
2068
|
288 |
1683
|
289 return retval; |
|
290 } |
|
291 |
|
292 DEFALIAS (exit, quit); |
|
293 |
1957
|
294 DEFUN (warranty, , , |
3446
|
295 "-*- texinfo -*-\n\ |
|
296 @deftypefn {Built-in Function} {} warranty ()\n\ |
|
297 Describe the conditions for copying and distributing Octave.\n\ |
|
298 @end deftypefn") |
1683
|
299 { |
2086
|
300 octave_value_list retval; |
1683
|
301 |
3922
|
302 octave_stdout << "\n" \ |
|
303 OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\ |
|
304 \n\ |
1683
|
305 This program is free software; you can redistribute it and/or modify\n\ |
|
306 it under the terms of the GNU General Public License as published by\n\ |
|
307 the Free Software Foundation; either version 2 of the License, or\n\ |
|
308 (at your option) any later version.\n\ |
|
309 \n\ |
|
310 This program is distributed in the hope that it will be useful,\n\ |
|
311 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ |
|
312 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ |
|
313 GNU General Public License for more details.\n\ |
|
314 \n\ |
|
315 You should have received a copy of the GNU General Public License\n\ |
|
316 along with this program. If not, write to the Free Software\n\ |
|
317 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n\ |
|
318 \n"; |
|
319 |
|
320 return retval; |
|
321 } |
|
322 |
|
323 // Execute a shell command. |
|
324 |
1965
|
325 static void |
|
326 cleanup_iprocstream (void *p) |
|
327 { |
3060
|
328 iprocstream *cmd = static_cast<iprocstream *> (p); |
|
329 |
|
330 octave_child_list::remove (cmd->pid ()); |
|
331 |
|
332 delete cmd; |
1965
|
333 } |
|
334 |
2086
|
335 static octave_value_list |
3523
|
336 run_command_and_return_output (const std::string& cmd_str) |
2083
|
337 { |
2086
|
338 octave_value_list retval; |
2083
|
339 |
|
340 iprocstream *cmd = new iprocstream (cmd_str.c_str ()); |
|
341 |
3060
|
342 if (cmd) |
2083
|
343 { |
3060
|
344 unwind_protect::add (cleanup_iprocstream, cmd); |
|
345 |
|
346 if (*cmd) |
|
347 { |
4051
|
348 OSSTREAM output_buf; |
2095
|
349 |
4489
|
350 // XXX FIXME XXX -- Perhaps we should read more than one |
|
351 // character at a time and find a way to avoid the call to |
|
352 // octave_usleep as well? |
3147
|
353 |
4494
|
354 // This is a bit of a kluge... |
|
355 |
|
356 octave_usleep (100); |
|
357 |
3060
|
358 char ch; |
3147
|
359 |
4489
|
360 for (;;) |
3147
|
361 { |
4489
|
362 if (cmd->get (ch)) |
|
363 output_buf.put (ch); |
|
364 else |
|
365 { |
|
366 if (! cmd->eof () && errno == EAGAIN) |
|
367 { |
|
368 cmd->clear (); |
3147
|
369 |
4489
|
370 octave_usleep (100); |
|
371 } |
|
372 else |
|
373 break; |
|
374 } |
3147
|
375 } |
|
376 |
3252
|
377 int cmd_status = cmd->close (); |
2083
|
378 |
3060
|
379 if (WIFEXITED (cmd_status)) |
|
380 cmd_status = WEXITSTATUS (cmd_status); |
|
381 else |
|
382 cmd_status = 127; |
2083
|
383 |
4051
|
384 output_buf << OSSTREAM_ENDS; |
2083
|
385 |
3060
|
386 retval(1) = (double) cmd_status; |
4051
|
387 retval(0) = OSSTREAM_STR (output_buf); |
2083
|
388 |
4051
|
389 OSSTREAM_FREEZE (output_buf); |
3060
|
390 } |
|
391 |
|
392 unwind_protect::run (); |
2083
|
393 } |
|
394 else |
|
395 error ("unable to start subprocess for `%s'", cmd_str.c_str ()); |
|
396 |
|
397 return retval; |
|
398 } |
|
399 |
1957
|
400 DEFUN (system, args, nargout, |
3301
|
401 "-*- texinfo -*-\n\ |
|
402 @deftypefn {Built-in Function} {} system (@var{string}, @var{return_output}, @var{type})\n\ |
|
403 Execute a shell command specified by @var{string}. The second\n\ |
|
404 argument is optional. If @var{type} is @code{\"async\"}, the process\n\ |
|
405 is started in the background and the process id of the child process\n\ |
|
406 is returned immediately. Otherwise, the process is started, and\n\ |
|
407 Octave waits until it exits. If @var{type} argument is omitted, a\n\ |
|
408 value of @code{\"sync\"} is assumed.\n\ |
2083
|
409 \n\ |
3301
|
410 If two input arguments are given (the actual value of\n\ |
|
411 @var{return_output} is irrelevant) and the subprocess is started\n\ |
|
412 synchronously, or if @var{system} is called with one input argument and\n\ |
|
413 one or more output arguments, the output from the command is returned.\n\ |
5097
|
414 Otherwise, if the subprocess is executed synchronously, its output is\n\ |
2321
|
415 sent to the standard output. To send the output of a command executed\n\ |
3301
|
416 with @var{system} through the pager, use a command like\n\ |
2321
|
417 \n\ |
3301
|
418 @example\n\ |
|
419 disp (system (cmd, 1));\n\ |
|
420 @end example\n\ |
2321
|
421 \n\ |
3301
|
422 @noindent\n\ |
2321
|
423 or\n\ |
|
424 \n\ |
3301
|
425 @example\n\ |
|
426 printf (\"%s\n\", system (cmd, 1));\n\ |
|
427 @end example\n\ |
|
428 \n\ |
|
429 The @code{system} function can return two values. The first is any\n\ |
|
430 output from the command that was written to the standard output stream,\n\ |
|
431 and the second is the output status of the command. For example,\n\ |
|
432 \n\ |
|
433 @example\n\ |
|
434 [output, status] = system (\"echo foo; exit 2\");\n\ |
|
435 @end example\n\ |
|
436 \n\ |
|
437 @noindent\n\ |
|
438 will set the variable @code{output} to the string @samp{foo}, and the\n\ |
|
439 variable @code{status} to the integer @samp{2}.\n\ |
|
440 @end deftypefn") |
1683
|
441 { |
2086
|
442 octave_value_list retval; |
1683
|
443 |
3834
|
444 unwind_protect::begin_frame ("Fsystem"); |
|
445 |
1683
|
446 int nargin = args.length (); |
|
447 |
2083
|
448 if (nargin > 0 && nargin < 4) |
1683
|
449 { |
2083
|
450 bool return_output = (nargout > 0 || nargin > 1); |
|
451 |
3523
|
452 std::string cmd_str = args(0).string_value (); |
2083
|
453 |
|
454 enum exec_type { sync, async }; |
|
455 |
|
456 exec_type type = sync; |
|
457 |
|
458 if (! error_state) |
|
459 { |
|
460 if (nargin > 2) |
|
461 { |
3523
|
462 std::string type_str = args(2).string_value (); |
1683
|
463 |
2083
|
464 if (! error_state) |
|
465 { |
|
466 if (type_str == "sync") |
|
467 type = sync; |
|
468 else if (type_str == "async") |
|
469 type = async; |
|
470 else |
|
471 error ("system: third arg must be \"sync\" or \"async\""); |
|
472 } |
|
473 else |
|
474 error ("system: third argument must be a string"); |
|
475 } |
|
476 } |
|
477 else |
3523
|
478 error ("system: expecting std::string as first argument"); |
1683
|
479 |
2083
|
480 if (! error_state) |
|
481 { |
|
482 if (type == async) |
|
483 { |
4086
|
484 #ifdef HAVE_FORK |
2083
|
485 pid_t pid = fork (); |
|
486 |
|
487 if (pid < 0) |
|
488 error ("system: fork failed -- can't create child process"); |
|
489 else if (pid == 0) |
|
490 { |
3273
|
491 // XXX FIXME XXX -- should probably replace this |
|
492 // call with something portable. |
|
493 |
|
494 execl ("/bin/sh", "sh", "-c", cmd_str.c_str (), 0); |
|
495 |
|
496 panic_impossible (); |
2083
|
497 } |
|
498 else |
4254
|
499 retval(0) = pid; |
4086
|
500 #else |
|
501 error ("asynchronous system calls are not supported"); |
|
502 #endif |
2083
|
503 } |
2321
|
504 else if (return_output) |
|
505 retval = run_command_and_return_output (cmd_str); |
2083
|
506 else |
2321
|
507 { |
|
508 int status = system (cmd_str.c_str ()); |
|
509 |
|
510 // The value in status is as returned by waitpid. If |
|
511 // the process exited normally, extract the actual exit |
|
512 // status of the command. Otherwise, return 127 as a |
|
513 // failure code. |
|
514 |
2693
|
515 if (WIFEXITED (status)) |
|
516 status = WEXITSTATUS (status); |
2321
|
517 |
4233
|
518 retval(0) = status; |
2321
|
519 } |
2083
|
520 } |
1683
|
521 } |
|
522 else |
2083
|
523 print_usage ("system"); |
1683
|
524 |
3834
|
525 unwind_protect::run_frame ("Fsystem"); |
|
526 |
1683
|
527 return retval; |
|
528 } |
|
529 |
|
530 DEFALIAS (shell_cmd, system); |
|
531 |
2614
|
532 // XXX FIXME XXX -- this should really be static, but that causes |
|
533 // problems on some systems. |
4214
|
534 std::stack<std::string> octave_atexit_functions; |
2077
|
535 |
|
536 void |
|
537 do_octave_atexit (void) |
|
538 { |
3216
|
539 static bool deja_vu = false; |
|
540 |
2077
|
541 while (! octave_atexit_functions.empty ()) |
|
542 { |
4233
|
543 std::string fcn = octave_atexit_functions.top (); |
4214
|
544 |
|
545 octave_atexit_functions.pop (); |
2077
|
546 |
4233
|
547 feval (fcn, octave_value_list (), 0); |
3215
|
548 |
|
549 flush_octave_stdout (); |
2077
|
550 } |
3216
|
551 |
|
552 if (! deja_vu) |
|
553 { |
|
554 deja_vu = true; |
|
555 |
|
556 command_editor::restore_terminal_state (); |
|
557 |
|
558 // XXX FIXME XXX -- is this needed? Can it cause any trouble? |
|
559 raw_mode (0); |
|
560 |
|
561 command_history::clean_up_and_save (); |
|
562 |
|
563 close_files (); |
|
564 |
|
565 cleanup_tmp_files (); |
|
566 |
|
567 flush_octave_stdout (); |
|
568 |
|
569 if (!quitting_gracefully && (interactive || forced_interactive)) |
3531
|
570 std::cout << "\n"; |
3216
|
571 } |
2077
|
572 } |
|
573 |
2162
|
574 DEFUN (atexit, args, , |
3332
|
575 "-*- texinfo -*-\n\ |
|
576 @deftypefn {Built-in Function} {} atexit (@var{fcn})\n\ |
|
577 Register a function to be called when Octave exits. For example,\n\ |
2077
|
578 \n\ |
3332
|
579 @example\n\ |
|
580 @group\n\ |
3686
|
581 function print_fortune ()\n\ |
3332
|
582 printf (\"\\n%s\\n\", system (\"fortune\"));\n\ |
|
583 fflush (stdout);\n\ |
|
584 endfunction\n\ |
3686
|
585 atexit (\"print_fortune\");\n\ |
3332
|
586 @end group\n\ |
|
587 @end example\n\ |
|
588 \n\ |
|
589 @noindent\n\ |
|
590 will print a message when Octave exits.\n\ |
3333
|
591 @end deftypefn") |
2077
|
592 { |
2086
|
593 octave_value_list retval; |
2077
|
594 |
|
595 int nargin = args.length (); |
|
596 |
|
597 if (nargin == 1) |
|
598 { |
2475
|
599 #if defined (HAVE_ATEXIT) || defined (HAVE_ON_EXIT) |
3523
|
600 std::string arg = args(0).string_value (); |
2077
|
601 |
|
602 if (! error_state) |
|
603 octave_atexit_functions.push (arg); |
|
604 else |
|
605 error ("atexit: argument must be a string"); |
2475
|
606 #else |
|
607 gripe_not_supported ("atexit"); |
|
608 #endif |
2077
|
609 } |
|
610 else |
|
611 print_usage ("atexit"); |
|
612 |
|
613 return retval; |
|
614 } |
|
615 |
2689
|
616 DEFUN (octave_config_info, args, , |
3301
|
617 "-*- texinfo -*-\n\ |
|
618 @deftypefn {Built-in Function} {} octave_config_info (@var{option})\n\ |
|
619 Return a structure containing configuration and installation\n\ |
|
620 information for Octave.\n\ |
2689
|
621 \n\ |
3301
|
622 if @var{option} is a string, return the configuration information for the\n\ |
2689
|
623 specified option.\n\ |
|
624 \n\ |
3301
|
625 @end deftypefn") |
2162
|
626 { |
2689
|
627 octave_value retval; |
|
628 |
4128
|
629 #if defined (ENABLE_DYNAMIC_LINKING) |
2689
|
630 bool octave_supports_dynamic_linking = true; |
|
631 #else |
|
632 bool octave_supports_dynamic_linking = false; |
|
633 #endif |
|
634 |
4357
|
635 static bool initialized = false; |
|
636 static Octave_map m; |
2162
|
637 |
4357
|
638 static const char * const conf_info[] = |
|
639 { |
|
640 "ALL_CFLAGS", OCTAVE_CONF_ALL_CFLAGS, |
|
641 "ALL_CXXFLAGS", OCTAVE_CONF_ALL_CXXFLAGS, |
|
642 "ALL_FFLAGS", OCTAVE_CONF_ALL_FFLAGS, |
|
643 "ALL_LDFLAGS", OCTAVE_CONF_ALL_LDFLAGS, |
|
644 "AR", OCTAVE_CONF_AR, |
|
645 "ARFLAGS", OCTAVE_CONF_ARFLAGS, |
|
646 "BLAS_LIBS", OCTAVE_CONF_BLAS_LIBS, |
|
647 "CC", OCTAVE_CONF_CC, |
|
648 "CC_VERSION", OCTAVE_CONF_CC_VERSION, |
|
649 "CFLAGS", OCTAVE_CONF_CFLAGS, |
|
650 "CPICFLAG", OCTAVE_CONF_CPICFLAG, |
|
651 "CPPFLAGS", OCTAVE_CONF_CPPFLAGS, |
|
652 "CXX", OCTAVE_CONF_CXX, |
|
653 "CXXCPP", OCTAVE_CONF_CXXCPP, |
|
654 "CXXFLAGS", OCTAVE_CONF_CXXFLAGS, |
|
655 "CXXPICFLAG", OCTAVE_CONF_CXXPICFLAG, |
|
656 "CXX_VERSION", OCTAVE_CONF_CXX_VERSION, |
|
657 "DEFAULT_PAGER", OCTAVE_DEFAULT_PAGER, |
4759
|
658 "DL_LD", OCTAVE_CONF_DL_LD, |
|
659 "DL_LDFLAGS", OCTAVE_CONF_DL_LDFLAGS, |
4357
|
660 "DLFCN_INCFLAGS", OCTAVE_CONF_DLFCN_INCFLAGS, |
|
661 "EXEEXT", OCTAVE_CONF_EXEEXT, |
|
662 "F2C", OCTAVE_CONF_F2C, |
|
663 "F2CFLAGS", OCTAVE_CONF_F2CFLAGS, |
|
664 "F77", OCTAVE_CONF_F77, |
|
665 "FC", OCTAVE_CONF_FC, |
|
666 "FFLAGS", OCTAVE_CONF_FFLAGS, |
|
667 "FFTW_LIBS", OCTAVE_CONF_FFTW_LIBS, |
|
668 "FLIBS", OCTAVE_CONF_FLIBS, |
|
669 "FPICFLAG", OCTAVE_CONF_FPICFLAG, |
|
670 "INCFLAGS", OCTAVE_CONF_INCFLAGS, |
|
671 "LDFLAGS", OCTAVE_CONF_LDFLAGS, |
|
672 "LD_CXX", OCTAVE_CONF_LD_CXX, |
|
673 "LD_STATIC_FLAG", OCTAVE_CONF_LD_STATIC_FLAG, |
|
674 "LEX", OCTAVE_CONF_LEX, |
|
675 "LEXLIB", OCTAVE_CONF_LEXLIB, |
|
676 "LFLAGS", OCTAVE_CONF_LFLAGS, |
|
677 "LIBCRUFT", OCTAVE_CONF_LIBCRUFT, |
|
678 "LIBDLFCN", OCTAVE_CONF_LIBDLFCN, |
|
679 "LIBEXT", OCTAVE_CONF_LIBEXT, |
|
680 "LIBFLAGS", OCTAVE_CONF_LIBFLAGS, |
|
681 "LIBOCTAVE", OCTAVE_CONF_LIBOCTAVE, |
|
682 "LIBOCTINTERP", OCTAVE_CONF_LIBOCTINTERP, |
|
683 "LIBPLPLOT", OCTAVE_CONF_LIBPLPLOT, |
|
684 "LIBREADLINE", OCTAVE_CONF_LIBREADLINE, |
|
685 "LIBS", OCTAVE_CONF_LIBS, |
|
686 "LN_S", OCTAVE_CONF_LN_S, |
|
687 "MKOCTFILE_INCFLAGS", OCTAVE_CONF_MKOCTFILE_INCFLAGS, |
|
688 "MKOCTFILE_LFLAGS", OCTAVE_CONF_MKOCTFILE_LFLAGS, |
4759
|
689 "MKOCTFILE_DL_LDFLAGS", OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS, |
4357
|
690 "RANLIB", OCTAVE_CONF_RANLIB, |
|
691 "RDYNAMIC_FLAG", OCTAVE_CONF_RDYNAMIC_FLAG, |
|
692 "RLD_FLAG", OCTAVE_CONF_RLD_FLAG, |
|
693 "RUNTEST", OCTAVE_CONF_RUNTEST, |
|
694 "SED", OCTAVE_CONF_SED, |
|
695 "SHARED_LIBS", OCTAVE_CONF_SHARED_LIBS, |
|
696 "SHLEXT", OCTAVE_CONF_SHLEXT, |
|
697 "SHLEXT_VER", OCTAVE_CONF_SHLEXT_VER, |
|
698 "SH_LD", OCTAVE_CONF_SH_LD, |
|
699 "SH_LDFLAGS", OCTAVE_CONF_SH_LDFLAGS, |
|
700 "SONAME_FLAGS", OCTAVE_CONF_SONAME_FLAGS, |
|
701 "STATIC_LIBS", OCTAVE_CONF_STATIC_LIBS, |
4440
|
702 "DEFS", OCTAVE_CONF_DEFS, |
4357
|
703 "UGLY_DEFS", OCTAVE_CONF_UGLY_DEFS, |
|
704 "ENABLE_DYNAMIC_LINKING", OCTAVE_CONF_ENABLE_DYNAMIC_LINKING, |
|
705 "XTRA_CFLAGS", OCTAVE_CONF_XTRA_CFLAGS, |
|
706 "XTRA_CXXFLAGS", OCTAVE_CONF_XTRA_CXXFLAGS, |
|
707 "YACC", OCTAVE_CONF_YACC, |
|
708 "YFLAGS", OCTAVE_CONF_YFLAGS, |
|
709 "archlibdir", OCTAVE_ARCHLIBDIR, |
|
710 "bindir", OCTAVE_BINDIR, |
|
711 "canonical_host_type", OCTAVE_CANONICAL_HOST_TYPE, |
|
712 "config_opts", OCTAVE_CONF_config_opts, |
|
713 "datadir", OCTAVE_DATADIR, |
|
714 "exec_prefix", OCTAVE_EXEC_PREFIX, |
|
715 "fcnfiledir", OCTAVE_FCNFILEDIR, |
|
716 "fcnfilepath", OCTAVE_FCNFILEPATH, |
|
717 "imagedir", OCTAVE_IMAGEDIR, |
|
718 "imagepath", OCTAVE_IMAGEPATH, |
|
719 "includedir", OCTAVE_INCLUDEDIR, |
|
720 "infodir", OCTAVE_INFODIR, |
|
721 "infofile", OCTAVE_INFOFILE, |
|
722 "libdir", OCTAVE_LIBDIR, |
|
723 "libexecdir", OCTAVE_LIBEXECDIR, |
|
724 "localarchlibdir", OCTAVE_LOCALARCHLIBDIR, |
|
725 "localfcnfiledir", OCTAVE_LOCALFCNFILEDIR, |
|
726 "localfcnfilepath", OCTAVE_LOCALFCNFILEPATH, |
|
727 "localoctfiledir", OCTAVE_LOCALOCTFILEDIR, |
|
728 "localoctfilepath", OCTAVE_LOCALOCTFILEPATH, |
|
729 "localstartupfiledir", OCTAVE_LOCALSTARTUPFILEDIR, |
|
730 "localverarchlibdir", OCTAVE_LOCALVERARCHLIBDIR, |
|
731 "localverfcnfiledir", OCTAVE_LOCALVERFCNFILEDIR, |
|
732 "localveroctfiledir", OCTAVE_LOCALVEROCTFILEDIR, |
|
733 "man1dir", OCTAVE_MAN1DIR, |
|
734 "man1ext", OCTAVE_MAN1EXT, |
|
735 "mandir", OCTAVE_MANDIR, |
|
736 "octfiledir", OCTAVE_OCTFILEDIR, |
|
737 "octincludedir", OCTAVE_OCTINCLUDEDIR, |
|
738 "octlibdir", OCTAVE_OCTLIBDIR, |
|
739 "prefix", OCTAVE_PREFIX, |
|
740 "startupfiledir", OCTAVE_STARTUPFILEDIR, |
|
741 "version", OCTAVE_VERSION, |
|
742 0, 0 |
|
743 }; |
|
744 |
|
745 if (! initialized) |
|
746 { |
4675
|
747 m.assign ("dld", octave_value (octave_supports_dynamic_linking)); |
4357
|
748 |
4697
|
749 oct_mach_info::float_format ff = oct_mach_info::native_float_format (); |
|
750 m.assign ("float_format", |
|
751 octave_value (oct_mach_info::float_format_as_string (ff))); |
|
752 |
|
753 m.assign ("words_big_endian", |
|
754 octave_value (oct_mach_info::words_big_endian ())); |
|
755 |
|
756 m.assign ("words_little_endian", |
|
757 octave_value (oct_mach_info::words_little_endian ())); |
|
758 |
4357
|
759 int i = 0; |
4440
|
760 |
|
761 while (true) |
4357
|
762 { |
|
763 const char *key = conf_info[i++]; |
|
764 |
|
765 if (key) |
4675
|
766 m.assign (key, octave_value (conf_info[i++])); |
4357
|
767 else |
|
768 break; |
|
769 } |
|
770 |
4691
|
771 bool unix_system = true; |
|
772 bool windows_system = false; |
|
773 |
|
774 #if defined (WIN32) |
|
775 windows_system = true; |
|
776 #if !defined (__CYGWIN__) |
|
777 unix_system = false; |
|
778 #endif |
|
779 #endif |
|
780 |
|
781 m.assign ("unix", octave_value (unix_system)); |
|
782 m.assign ("windows", octave_value (windows_system)); |
|
783 |
4357
|
784 initialized = true; |
|
785 } |
2162
|
786 |
2689
|
787 int nargin = args.length (); |
|
788 |
|
789 if (nargin == 1) |
|
790 { |
3523
|
791 std::string arg = args(0).string_value (); |
2689
|
792 |
|
793 if (! error_state) |
4675
|
794 { |
|
795 Cell c = m.contents (arg.c_str ()); |
|
796 retval = c(0); |
|
797 } |
2689
|
798 } |
|
799 else if (nargin == 0) |
4233
|
800 retval = m; |
2689
|
801 else |
|
802 print_usage ("octave_config_info"); |
|
803 |
|
804 return retval; |
2162
|
805 } |
|
806 |
1683
|
807 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE) |
2806
|
808 |
1683
|
809 int debug_new_delete = 0; |
|
810 |
|
811 typedef void (*vfp)(void); |
|
812 extern vfp __new_handler; |
|
813 |
|
814 void * |
|
815 __builtin_new (size_t sz) |
|
816 { |
|
817 void *p; |
|
818 |
|
819 /* malloc (0) is unpredictable; avoid it. */ |
|
820 if (sz == 0) |
|
821 sz = 1; |
2800
|
822 p = malloc (sz); |
1683
|
823 while (p == 0) |
|
824 { |
|
825 (*__new_handler) (); |
2800
|
826 p = malloc (sz); |
1683
|
827 } |
|
828 |
|
829 if (debug_new_delete) |
3538
|
830 std::cout << "__builtin_new: " << p << std::endl; |
1683
|
831 |
|
832 return p; |
|
833 } |
|
834 |
|
835 void |
|
836 __builtin_delete (void *ptr) |
|
837 { |
|
838 if (debug_new_delete) |
3538
|
839 std::cout << "__builtin_delete: " << ptr << std::endl; |
1683
|
840 |
|
841 if (ptr) |
|
842 free (ptr); |
|
843 } |
2806
|
844 |
1683
|
845 #endif |
|
846 |
2806
|
847 void |
|
848 symbols_of_toplev (void) |
|
849 { |
3141
|
850 DEFCONST (argv, , |
3332
|
851 "-*- texinfo -*-\n\ |
|
852 @defvr {Built-in Variable} argv\n\ |
|
853 The command line arguments passed to Octave are available in this\n\ |
|
854 variable. For example, if you invoked Octave using the command\n\ |
|
855 \n\ |
|
856 @example\n\ |
|
857 octave --no-line-editing --silent\n\ |
|
858 @end example\n\ |
|
859 \n\ |
|
860 @noindent\n\ |
3971
|
861 @code{argv} would be a cell array of strings with the elements\n\ |
3332
|
862 @code{--no-line-editing} and @code{--silent}.\n\ |
|
863 \n\ |
|
864 If you write an executable Octave script, @code{argv} will contain the\n\ |
3402
|
865 list of arguments passed to the script. @xref{Executable Octave Programs},\n\ |
|
866 for an example of how to create an executable Octave script.\n\ |
3333
|
867 @end defvr"); |
2806
|
868 |
3020
|
869 DEFCONST (program_invocation_name, |
3141
|
870 octave_env::get_program_invocation_name (), |
3332
|
871 "-*- texinfo -*-\n\ |
|
872 @defvr {Built-in Variable} program_invocation_name\n\ |
|
873 @defvrx {Built-in Variable} program_name\n\ |
|
874 When Octave starts, the value of the built-in variable\n\ |
|
875 @code{program_invocation_name} is automatically set to the name that was\n\ |
|
876 typed at the shell prompt to run Octave, and the value of\n\ |
|
877 @code{program_name} is automatically set to the final component of\n\ |
|
878 @code{program_invocation_name}. For example, if you typed\n\ |
|
879 @samp{@value{OCTAVEHOME}/bin/octave} to start Octave,\n\ |
|
880 @code{program_invocation_name} would have the value\n\ |
|
881 @code{\"@value{OCTAVEHOME}/bin/octave\"}, and @code{program_name} would\n\ |
|
882 have the value @code{\"octave\"}.\n\ |
|
883 \n\ |
|
884 If executing a script from the command line (e.g., @code{octave foo.m})\n\ |
|
885 or using an executable Octave script, the program name is set to the\n\ |
3402
|
886 name of the script. @xref{Executable Octave Programs}, for an example of\n\ |
3332
|
887 how to create an executable Octave script.\n\ |
3333
|
888 @end defvr"); |
3020
|
889 |
3141
|
890 DEFCONST (program_name, octave_env::get_program_name (), |
3332
|
891 "-*- texinfo -*-\n\ |
|
892 @defvr {Built-in Variable} program_invocation_name\n\ |
|
893 @defvrx {Built-in Variable} program_name\n\ |
|
894 When Octave starts, the value of the built-in variable\n\ |
|
895 @code{program_invocation_name} is automatically set to the name that was\n\ |
|
896 typed at the shell prompt to run Octave, and the value of\n\ |
|
897 @code{program_name} is automatically set to the final component of\n\ |
|
898 @code{program_invocation_name}. For example, if you typed\n\ |
|
899 @samp{@value{OCTAVEHOME}/bin/octave} to start Octave,\n\ |
|
900 @code{program_invocation_name} would have the value\n\ |
|
901 @code{\"@value{OCTAVEHOME}/bin/octave\"}, and @code{program_name} would\n\ |
|
902 have the value @code{\"octave\"}.\n\ |
|
903 \n\ |
|
904 If executing a script from the command line (e.g., @code{octave foo.m})\n\ |
|
905 or using an executable Octave script, the program name is set to the\n\ |
3402
|
906 name of the script. @xref{Executable Octave Programs}, for an example of\n\ |
3332
|
907 how to create an executable Octave script.\n\ |
3333
|
908 @end defvr"); |
|
909 |
2806
|
910 } |
|
911 |
1683
|
912 /* |
|
913 ;;; Local Variables: *** |
|
914 ;;; mode: C++ *** |
|
915 ;;; End: *** |
|
916 */ |