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" |
1750
|
69 #include "pt-plot.h" |
2982
|
70 #include "pt-stmt.h" |
1683
|
71 #include "sighandlers.h" |
|
72 #include "sysdep.h" |
2693
|
73 #include "syswait.h" |
1750
|
74 #include "toplev.h" |
1683
|
75 #include "unwind-prot.h" |
|
76 #include "utils.h" |
|
77 #include "variables.h" |
2492
|
78 #include <version.h> |
1683
|
79 |
3020
|
80 // TRUE means we are exiting via the builtin exit or quit functions. |
|
81 static bool quitting_gracefully = false; |
1683
|
82 |
4217
|
83 // TRUE means we are ready to interpret commands, but not everything |
|
84 // is ready for interactive use. |
|
85 bool octave_interpreter_ready = false; |
|
86 |
4172
|
87 // TRUE means we've processed all the init code and we are good to go. |
|
88 bool octave_initialized = false; |
|
89 |
1683
|
90 // Current command to execute. |
|
91 tree_statement_list *global_command = 0; |
|
92 |
|
93 // Pointer to function that is currently being evaluated. |
4748
|
94 octave_function *curr_function = 0; |
1683
|
95 |
4238
|
96 // Pointer to parent function that is currently being evaluated. |
4748
|
97 octave_function *curr_parent_function = 0; |
4238
|
98 |
4180
|
99 static void |
|
100 recover_from_exception (void) |
|
101 { |
|
102 can_interrupt = true; |
4182
|
103 octave_interrupt_immediately = 0; |
4180
|
104 octave_interrupt_state = 0; |
|
105 octave_allocation_error = 0; |
|
106 octave_restore_signal_mask (); |
|
107 octave_catch_interrupts (); |
|
108 } |
|
109 |
1907
|
110 int |
4356
|
111 main_loop (const std::string& fun_to_call) |
1907
|
112 { |
2016
|
113 octave_save_signal_mask (); |
|
114 |
4153
|
115 if (octave_set_current_context) |
1907
|
116 { |
4153
|
117 #if defined (USE_EXCEPTIONS_FOR_INTERRUPTS) |
|
118 panic_impossible (); |
|
119 #else |
|
120 unwind_protect::run_all (); |
1907
|
121 raw_mode (0); |
3531
|
122 std::cout << "\n"; |
2016
|
123 octave_restore_signal_mask (); |
4153
|
124 #endif |
1907
|
125 } |
|
126 |
3020
|
127 can_interrupt = true; |
1907
|
128 |
4429
|
129 octave_interrupt_hook = unwind_protect::run_all; |
|
130 octave_bad_alloc_hook = unwind_protect::run_all; |
|
131 |
2554
|
132 octave_catch_interrupts (); |
1907
|
133 |
4172
|
134 octave_initialized = true; |
|
135 |
4356
|
136 if (! fun_to_call.empty ()) |
|
137 feval (fun_to_call); |
|
138 |
1907
|
139 // The big loop. |
|
140 |
4153
|
141 int retval = 0; |
1907
|
142 do |
|
143 { |
4180
|
144 try |
1907
|
145 { |
4153
|
146 curr_sym_tab = top_level_sym_tab; |
2620
|
147 |
4318
|
148 reset_error_handler (); |
|
149 |
4153
|
150 reset_parser (); |
2620
|
151 |
4753
|
152 // This is the same as yyparse in parse.y. |
|
153 retval = octave_parse (); |
2620
|
154 |
4153
|
155 if (retval == 0) |
|
156 { |
|
157 if (global_command) |
3804
|
158 { |
4153
|
159 global_command->eval (); |
3883
|
160 |
4153
|
161 delete global_command; |
3883
|
162 |
4153
|
163 global_command = 0; |
3883
|
164 |
4171
|
165 OCTAVE_QUIT; |
|
166 |
3883
|
167 if (! (interactive || forced_interactive)) |
|
168 { |
4207
|
169 bool quit = (tree_return_command::returning |
|
170 || tree_break_command::breaking); |
4153
|
171 |
4207
|
172 if (tree_return_command::returning) |
|
173 tree_return_command::returning = 0; |
4153
|
174 |
4207
|
175 if (tree_break_command::breaking) |
|
176 tree_break_command::breaking--; |
4153
|
177 |
|
178 if (quit) |
|
179 break; |
|
180 } |
|
181 |
|
182 if (error_state) |
|
183 { |
|
184 if (! (interactive || forced_interactive)) |
|
185 { |
|
186 // We should exit with a non-zero status. |
|
187 retval = 1; |
|
188 break; |
|
189 } |
|
190 } |
|
191 else |
|
192 { |
|
193 if (octave_completion_matches_called) |
|
194 octave_completion_matches_called = false; |
|
195 else |
|
196 command_editor::increment_current_command_number (); |
3883
|
197 } |
|
198 } |
4153
|
199 else if (parser_end_of_input) |
|
200 break; |
2620
|
201 } |
4153
|
202 } |
4182
|
203 catch (octave_interrupt_exception) |
4153
|
204 { |
4180
|
205 recover_from_exception (); |
4155
|
206 std::cout << "\n"; |
4180
|
207 } |
4181
|
208 catch (std::bad_alloc) |
4180
|
209 { |
|
210 recover_from_exception (); |
|
211 std::cerr |
|
212 << "error: memory exhausted -- trying to return to prompt\n"; |
1907
|
213 } |
|
214 } |
|
215 while (retval == 0); |
|
216 |
|
217 return retval; |
|
218 } |
|
219 |
1683
|
220 // Fix up things before exiting. |
|
221 |
|
222 void |
3162
|
223 clean_up_and_exit (int retval) |
|
224 { |
3216
|
225 do_octave_atexit (); |
1683
|
226 |
3162
|
227 exit (retval == EOF ? 0 : retval); |
1683
|
228 } |
|
229 |
4208
|
230 DEFCMD (casesen, args, , |
3446
|
231 "-*- texinfo -*-\n\ |
|
232 @deffn {Command} casesen arg\n\ |
|
233 Provided for compatibility with Matlab, but does nothing.\n\ |
|
234 @end deffn") |
1683
|
235 { |
2086
|
236 octave_value_list retval; |
1683
|
237 |
1755
|
238 int argc = args.length () + 1; |
|
239 |
1965
|
240 string_vector argv = args.make_argv ("casesen"); |
1683
|
241 |
1755
|
242 if (error_state) |
|
243 return retval; |
|
244 |
|
245 if (argc == 1 || (argc > 1 && argv[1] == "off")) |
1683
|
246 warning ("casesen: sorry, Octave is always case sensitive"); |
1755
|
247 else if (argc > 1 && argv[1] == "on") |
1683
|
248 ; // ok. |
|
249 else |
|
250 print_usage ("casesen"); |
|
251 |
|
252 return retval; |
|
253 } |
|
254 |
3180
|
255 DEFUN (quit, args, nargout, |
3332
|
256 "-*- texinfo -*-\n\ |
|
257 @deftypefn {Built-in Function} {} exit (@var{status})\n\ |
|
258 @deftypefnx {Built-in Function} {} quit (@var{status})\n\ |
|
259 Exit the current Octave session. If the optional integer value\n\ |
|
260 @var{status} is supplied, pass that value to the operating system as the\n\ |
|
261 Octave's exit status.\n\ |
3333
|
262 @end deftypefn") |
1683
|
263 { |
2086
|
264 octave_value_list retval; |
2068
|
265 |
3180
|
266 if (nargout == 0) |
2068
|
267 { |
3180
|
268 int exit_status = 0; |
|
269 |
|
270 quitting_gracefully = true; |
1683
|
271 |
3180
|
272 if (args.length () > 0) |
|
273 { |
3202
|
274 int tmp = args(0).nint_value (); |
1683
|
275 |
3202
|
276 if (! error_state) |
|
277 exit_status = tmp; |
3180
|
278 } |
|
279 |
|
280 clean_up_and_exit (exit_status); |
2068
|
281 } |
3180
|
282 else |
|
283 error ("quit: invalid number of output arguments"); |
2068
|
284 |
1683
|
285 return retval; |
|
286 } |
|
287 |
|
288 DEFALIAS (exit, quit); |
|
289 |
1957
|
290 DEFUN (warranty, , , |
3446
|
291 "-*- texinfo -*-\n\ |
|
292 @deftypefn {Built-in Function} {} warranty ()\n\ |
|
293 Describe the conditions for copying and distributing Octave.\n\ |
|
294 @end deftypefn") |
1683
|
295 { |
2086
|
296 octave_value_list retval; |
1683
|
297 |
3922
|
298 octave_stdout << "\n" \ |
|
299 OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\ |
|
300 \n\ |
1683
|
301 This program is free software; you can redistribute it and/or modify\n\ |
|
302 it under the terms of the GNU General Public License as published by\n\ |
|
303 the Free Software Foundation; either version 2 of the License, or\n\ |
|
304 (at your option) any later version.\n\ |
|
305 \n\ |
|
306 This program is distributed in the hope that it will be useful,\n\ |
|
307 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ |
|
308 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ |
|
309 GNU General Public License for more details.\n\ |
|
310 \n\ |
|
311 You should have received a copy of the GNU General Public License\n\ |
|
312 along with this program. If not, write to the Free Software\n\ |
|
313 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n\ |
|
314 \n"; |
|
315 |
|
316 return retval; |
|
317 } |
|
318 |
|
319 // Execute a shell command. |
|
320 |
1965
|
321 static void |
|
322 cleanup_iprocstream (void *p) |
|
323 { |
3060
|
324 iprocstream *cmd = static_cast<iprocstream *> (p); |
|
325 |
|
326 octave_child_list::remove (cmd->pid ()); |
|
327 |
|
328 delete cmd; |
1965
|
329 } |
|
330 |
2086
|
331 static octave_value_list |
3523
|
332 run_command_and_return_output (const std::string& cmd_str) |
2083
|
333 { |
2086
|
334 octave_value_list retval; |
2083
|
335 |
|
336 iprocstream *cmd = new iprocstream (cmd_str.c_str ()); |
|
337 |
3060
|
338 if (cmd) |
2083
|
339 { |
3060
|
340 unwind_protect::add (cleanup_iprocstream, cmd); |
|
341 |
|
342 if (*cmd) |
|
343 { |
4051
|
344 OSSTREAM output_buf; |
2095
|
345 |
4489
|
346 // XXX FIXME XXX -- Perhaps we should read more than one |
|
347 // character at a time and find a way to avoid the call to |
|
348 // octave_usleep as well? |
3147
|
349 |
4494
|
350 // This is a bit of a kluge... |
|
351 |
|
352 octave_usleep (100); |
|
353 |
3060
|
354 char ch; |
3147
|
355 |
4489
|
356 for (;;) |
3147
|
357 { |
4489
|
358 if (cmd->get (ch)) |
|
359 output_buf.put (ch); |
|
360 else |
|
361 { |
|
362 if (! cmd->eof () && errno == EAGAIN) |
|
363 { |
|
364 cmd->clear (); |
3147
|
365 |
4489
|
366 octave_usleep (100); |
|
367 } |
|
368 else |
|
369 break; |
|
370 } |
3147
|
371 } |
|
372 |
3252
|
373 int cmd_status = cmd->close (); |
2083
|
374 |
3060
|
375 if (WIFEXITED (cmd_status)) |
|
376 cmd_status = WEXITSTATUS (cmd_status); |
|
377 else |
|
378 cmd_status = 127; |
2083
|
379 |
4051
|
380 output_buf << OSSTREAM_ENDS; |
2083
|
381 |
3060
|
382 retval(1) = (double) cmd_status; |
4051
|
383 retval(0) = OSSTREAM_STR (output_buf); |
2083
|
384 |
4051
|
385 OSSTREAM_FREEZE (output_buf); |
3060
|
386 } |
|
387 |
|
388 unwind_protect::run (); |
2083
|
389 } |
|
390 else |
|
391 error ("unable to start subprocess for `%s'", cmd_str.c_str ()); |
|
392 |
|
393 return retval; |
|
394 } |
|
395 |
1957
|
396 DEFUN (system, args, nargout, |
3301
|
397 "-*- texinfo -*-\n\ |
|
398 @deftypefn {Built-in Function} {} system (@var{string}, @var{return_output}, @var{type})\n\ |
|
399 Execute a shell command specified by @var{string}. The second\n\ |
|
400 argument is optional. If @var{type} is @code{\"async\"}, the process\n\ |
|
401 is started in the background and the process id of the child process\n\ |
|
402 is returned immediately. Otherwise, the process is started, and\n\ |
|
403 Octave waits until it exits. If @var{type} argument is omitted, a\n\ |
|
404 value of @code{\"sync\"} is assumed.\n\ |
2083
|
405 \n\ |
3301
|
406 If two input arguments are given (the actual value of\n\ |
|
407 @var{return_output} is irrelevant) and the subprocess is started\n\ |
|
408 synchronously, or if @var{system} is called with one input argument and\n\ |
|
409 one or more output arguments, the output from the command is returned.\n\ |
2083
|
410 Otherwise, if the subprocess is executed synchronously, it's output is\n\ |
2321
|
411 sent to the standard output. To send the output of a command executed\n\ |
3301
|
412 with @var{system} through the pager, use a command like\n\ |
2321
|
413 \n\ |
3301
|
414 @example\n\ |
|
415 disp (system (cmd, 1));\n\ |
|
416 @end example\n\ |
2321
|
417 \n\ |
3301
|
418 @noindent\n\ |
2321
|
419 or\n\ |
|
420 \n\ |
3301
|
421 @example\n\ |
|
422 printf (\"%s\n\", system (cmd, 1));\n\ |
|
423 @end example\n\ |
|
424 \n\ |
|
425 The @code{system} function can return two values. The first is any\n\ |
|
426 output from the command that was written to the standard output stream,\n\ |
|
427 and the second is the output status of the command. For example,\n\ |
|
428 \n\ |
|
429 @example\n\ |
|
430 [output, status] = system (\"echo foo; exit 2\");\n\ |
|
431 @end example\n\ |
|
432 \n\ |
|
433 @noindent\n\ |
|
434 will set the variable @code{output} to the string @samp{foo}, and the\n\ |
|
435 variable @code{status} to the integer @samp{2}.\n\ |
|
436 @end deftypefn") |
1683
|
437 { |
2086
|
438 octave_value_list retval; |
1683
|
439 |
3834
|
440 unwind_protect::begin_frame ("Fsystem"); |
|
441 |
1683
|
442 int nargin = args.length (); |
|
443 |
2083
|
444 if (nargin > 0 && nargin < 4) |
1683
|
445 { |
2083
|
446 bool return_output = (nargout > 0 || nargin > 1); |
|
447 |
3523
|
448 std::string cmd_str = args(0).string_value (); |
2083
|
449 |
|
450 enum exec_type { sync, async }; |
|
451 |
|
452 exec_type type = sync; |
|
453 |
|
454 if (! error_state) |
|
455 { |
|
456 if (nargin > 2) |
|
457 { |
3523
|
458 std::string type_str = args(2).string_value (); |
1683
|
459 |
2083
|
460 if (! error_state) |
|
461 { |
|
462 if (type_str == "sync") |
|
463 type = sync; |
|
464 else if (type_str == "async") |
|
465 type = async; |
|
466 else |
|
467 error ("system: third arg must be \"sync\" or \"async\""); |
|
468 } |
|
469 else |
|
470 error ("system: third argument must be a string"); |
|
471 } |
|
472 } |
|
473 else |
3523
|
474 error ("system: expecting std::string as first argument"); |
1683
|
475 |
2083
|
476 if (! error_state) |
|
477 { |
|
478 if (type == async) |
|
479 { |
4086
|
480 #ifdef HAVE_FORK |
2083
|
481 pid_t pid = fork (); |
|
482 |
|
483 if (pid < 0) |
|
484 error ("system: fork failed -- can't create child process"); |
|
485 else if (pid == 0) |
|
486 { |
3273
|
487 // XXX FIXME XXX -- should probably replace this |
|
488 // call with something portable. |
|
489 |
|
490 execl ("/bin/sh", "sh", "-c", cmd_str.c_str (), 0); |
|
491 |
|
492 panic_impossible (); |
2083
|
493 } |
|
494 else |
4254
|
495 retval(0) = pid; |
4086
|
496 #else |
|
497 error ("asynchronous system calls are not supported"); |
|
498 #endif |
2083
|
499 } |
2321
|
500 else if (return_output) |
|
501 retval = run_command_and_return_output (cmd_str); |
2083
|
502 else |
2321
|
503 { |
|
504 int status = system (cmd_str.c_str ()); |
|
505 |
|
506 // The value in status is as returned by waitpid. If |
|
507 // the process exited normally, extract the actual exit |
|
508 // status of the command. Otherwise, return 127 as a |
|
509 // failure code. |
|
510 |
2693
|
511 if (WIFEXITED (status)) |
|
512 status = WEXITSTATUS (status); |
2321
|
513 |
4233
|
514 retval(0) = status; |
2321
|
515 } |
2083
|
516 } |
1683
|
517 } |
|
518 else |
2083
|
519 print_usage ("system"); |
1683
|
520 |
3834
|
521 unwind_protect::run_frame ("Fsystem"); |
|
522 |
1683
|
523 return retval; |
|
524 } |
|
525 |
|
526 DEFALIAS (shell_cmd, system); |
|
527 |
2614
|
528 // XXX FIXME XXX -- this should really be static, but that causes |
|
529 // problems on some systems. |
4214
|
530 std::stack<std::string> octave_atexit_functions; |
2077
|
531 |
|
532 void |
|
533 do_octave_atexit (void) |
|
534 { |
3216
|
535 static bool deja_vu = false; |
|
536 |
2077
|
537 while (! octave_atexit_functions.empty ()) |
|
538 { |
4233
|
539 std::string fcn = octave_atexit_functions.top (); |
4214
|
540 |
|
541 octave_atexit_functions.pop (); |
2077
|
542 |
4233
|
543 feval (fcn, octave_value_list (), 0); |
3215
|
544 |
|
545 flush_octave_stdout (); |
2077
|
546 } |
3216
|
547 |
|
548 if (! deja_vu) |
|
549 { |
|
550 deja_vu = true; |
|
551 |
|
552 command_editor::restore_terminal_state (); |
|
553 |
|
554 // XXX FIXME XXX -- is this needed? Can it cause any trouble? |
|
555 raw_mode (0); |
|
556 |
|
557 command_history::clean_up_and_save (); |
|
558 |
|
559 close_plot_stream (); |
|
560 |
|
561 close_files (); |
|
562 |
|
563 cleanup_tmp_files (); |
|
564 |
|
565 flush_octave_stdout (); |
|
566 |
|
567 if (!quitting_gracefully && (interactive || forced_interactive)) |
3531
|
568 std::cout << "\n"; |
3216
|
569 } |
2077
|
570 } |
|
571 |
2162
|
572 DEFUN (atexit, args, , |
3332
|
573 "-*- texinfo -*-\n\ |
|
574 @deftypefn {Built-in Function} {} atexit (@var{fcn})\n\ |
|
575 Register a function to be called when Octave exits. For example,\n\ |
2077
|
576 \n\ |
3332
|
577 @example\n\ |
|
578 @group\n\ |
3686
|
579 function print_fortune ()\n\ |
3332
|
580 printf (\"\\n%s\\n\", system (\"fortune\"));\n\ |
|
581 fflush (stdout);\n\ |
|
582 endfunction\n\ |
3686
|
583 atexit (\"print_fortune\");\n\ |
3332
|
584 @end group\n\ |
|
585 @end example\n\ |
|
586 \n\ |
|
587 @noindent\n\ |
|
588 will print a message when Octave exits.\n\ |
3333
|
589 @end deftypefn") |
2077
|
590 { |
2086
|
591 octave_value_list retval; |
2077
|
592 |
|
593 int nargin = args.length (); |
|
594 |
|
595 if (nargin == 1) |
|
596 { |
2475
|
597 #if defined (HAVE_ATEXIT) || defined (HAVE_ON_EXIT) |
3523
|
598 std::string arg = args(0).string_value (); |
2077
|
599 |
|
600 if (! error_state) |
|
601 octave_atexit_functions.push (arg); |
|
602 else |
|
603 error ("atexit: argument must be a string"); |
2475
|
604 #else |
|
605 gripe_not_supported ("atexit"); |
|
606 #endif |
2077
|
607 } |
|
608 else |
|
609 print_usage ("atexit"); |
|
610 |
|
611 return retval; |
|
612 } |
|
613 |
2689
|
614 DEFUN (octave_config_info, args, , |
3301
|
615 "-*- texinfo -*-\n\ |
|
616 @deftypefn {Built-in Function} {} octave_config_info (@var{option})\n\ |
|
617 Return a structure containing configuration and installation\n\ |
|
618 information for Octave.\n\ |
2689
|
619 \n\ |
3301
|
620 if @var{option} is a string, return the configuration information for the\n\ |
2689
|
621 specified option.\n\ |
|
622 \n\ |
3301
|
623 @end deftypefn") |
2162
|
624 { |
2689
|
625 octave_value retval; |
|
626 |
4128
|
627 #if defined (ENABLE_DYNAMIC_LINKING) |
2689
|
628 bool octave_supports_dynamic_linking = true; |
|
629 #else |
|
630 bool octave_supports_dynamic_linking = false; |
|
631 #endif |
|
632 |
4357
|
633 static bool initialized = false; |
|
634 static Octave_map m; |
2162
|
635 |
4357
|
636 static const char * const conf_info[] = |
|
637 { |
|
638 "ALL_CFLAGS", OCTAVE_CONF_ALL_CFLAGS, |
|
639 "ALL_CXXFLAGS", OCTAVE_CONF_ALL_CXXFLAGS, |
|
640 "ALL_FFLAGS", OCTAVE_CONF_ALL_FFLAGS, |
|
641 "ALL_LDFLAGS", OCTAVE_CONF_ALL_LDFLAGS, |
|
642 "AR", OCTAVE_CONF_AR, |
|
643 "ARFLAGS", OCTAVE_CONF_ARFLAGS, |
|
644 "BLAS_LIBS", OCTAVE_CONF_BLAS_LIBS, |
|
645 "CC", OCTAVE_CONF_CC, |
|
646 "CC_VERSION", OCTAVE_CONF_CC_VERSION, |
|
647 "CFLAGS", OCTAVE_CONF_CFLAGS, |
|
648 "CPICFLAG", OCTAVE_CONF_CPICFLAG, |
|
649 "CPPFLAGS", OCTAVE_CONF_CPPFLAGS, |
|
650 "CXX", OCTAVE_CONF_CXX, |
|
651 "CXXCPP", OCTAVE_CONF_CXXCPP, |
|
652 "CXXFLAGS", OCTAVE_CONF_CXXFLAGS, |
|
653 "CXXPICFLAG", OCTAVE_CONF_CXXPICFLAG, |
|
654 "CXX_VERSION", OCTAVE_CONF_CXX_VERSION, |
|
655 "DEFAULT_PAGER", OCTAVE_DEFAULT_PAGER, |
4759
|
656 "DL_LD", OCTAVE_CONF_DL_LD, |
|
657 "DL_LDFLAGS", OCTAVE_CONF_DL_LDFLAGS, |
4357
|
658 "DLFCN_INCFLAGS", OCTAVE_CONF_DLFCN_INCFLAGS, |
|
659 "EXEEXT", OCTAVE_CONF_EXEEXT, |
|
660 "F2C", OCTAVE_CONF_F2C, |
|
661 "F2CFLAGS", OCTAVE_CONF_F2CFLAGS, |
|
662 "F77", OCTAVE_CONF_F77, |
|
663 "FC", OCTAVE_CONF_FC, |
|
664 "FFLAGS", OCTAVE_CONF_FFLAGS, |
|
665 "FFTW_LIBS", OCTAVE_CONF_FFTW_LIBS, |
|
666 "FLIBS", OCTAVE_CONF_FLIBS, |
|
667 "FPICFLAG", OCTAVE_CONF_FPICFLAG, |
|
668 "GLOB_INCFLAGS", OCTAVE_CONF_GLOB_INCFLAGS, |
|
669 "INCFLAGS", OCTAVE_CONF_INCFLAGS, |
|
670 "LDFLAGS", OCTAVE_CONF_LDFLAGS, |
|
671 "LD_CXX", OCTAVE_CONF_LD_CXX, |
|
672 "LD_STATIC_FLAG", OCTAVE_CONF_LD_STATIC_FLAG, |
|
673 "LEX", OCTAVE_CONF_LEX, |
|
674 "LEXLIB", OCTAVE_CONF_LEXLIB, |
|
675 "LFLAGS", OCTAVE_CONF_LFLAGS, |
|
676 "LIBCRUFT", OCTAVE_CONF_LIBCRUFT, |
|
677 "LIBDLFCN", OCTAVE_CONF_LIBDLFCN, |
|
678 "LIBEXT", OCTAVE_CONF_LIBEXT, |
|
679 "LIBFLAGS", OCTAVE_CONF_LIBFLAGS, |
|
680 "LIBGLOB", OCTAVE_CONF_LIBGLOB, |
|
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 */ |