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