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