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