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