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 |
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 |
5142
|
132 octave_signal_hook = octave_signal_handler; |
4429
|
133 octave_interrupt_hook = unwind_protect::run_all; |
|
134 octave_bad_alloc_hook = unwind_protect::run_all; |
|
135 |
2554
|
136 octave_catch_interrupts (); |
1907
|
137 |
4172
|
138 octave_initialized = true; |
|
139 |
1907
|
140 // The big loop. |
|
141 |
4153
|
142 int retval = 0; |
1907
|
143 do |
|
144 { |
4180
|
145 try |
1907
|
146 { |
4153
|
147 curr_sym_tab = top_level_sym_tab; |
2620
|
148 |
4318
|
149 reset_error_handler (); |
|
150 |
4153
|
151 reset_parser (); |
2620
|
152 |
4753
|
153 // This is the same as yyparse in parse.y. |
|
154 retval = octave_parse (); |
2620
|
155 |
4153
|
156 if (retval == 0) |
|
157 { |
|
158 if (global_command) |
3804
|
159 { |
4153
|
160 global_command->eval (); |
3883
|
161 |
4153
|
162 delete global_command; |
3883
|
163 |
4153
|
164 global_command = 0; |
3883
|
165 |
4171
|
166 OCTAVE_QUIT; |
|
167 |
3883
|
168 if (! (interactive || forced_interactive)) |
|
169 { |
4207
|
170 bool quit = (tree_return_command::returning |
|
171 || tree_break_command::breaking); |
4153
|
172 |
4207
|
173 if (tree_return_command::returning) |
|
174 tree_return_command::returning = 0; |
4153
|
175 |
4207
|
176 if (tree_break_command::breaking) |
|
177 tree_break_command::breaking--; |
4153
|
178 |
|
179 if (quit) |
|
180 break; |
|
181 } |
|
182 |
|
183 if (error_state) |
|
184 { |
|
185 if (! (interactive || forced_interactive)) |
|
186 { |
|
187 // We should exit with a non-zero status. |
|
188 retval = 1; |
|
189 break; |
|
190 } |
|
191 } |
|
192 else |
|
193 { |
|
194 if (octave_completion_matches_called) |
|
195 octave_completion_matches_called = false; |
|
196 else |
|
197 command_editor::increment_current_command_number (); |
3883
|
198 } |
|
199 } |
4153
|
200 else if (parser_end_of_input) |
|
201 break; |
2620
|
202 } |
4153
|
203 } |
4182
|
204 catch (octave_interrupt_exception) |
4153
|
205 { |
4180
|
206 recover_from_exception (); |
4155
|
207 std::cout << "\n"; |
4180
|
208 } |
4181
|
209 catch (std::bad_alloc) |
4180
|
210 { |
|
211 recover_from_exception (); |
|
212 std::cerr |
|
213 << "error: memory exhausted -- trying to return to prompt\n"; |
1907
|
214 } |
|
215 } |
|
216 while (retval == 0); |
|
217 |
|
218 return retval; |
|
219 } |
|
220 |
1683
|
221 // Fix up things before exiting. |
|
222 |
|
223 void |
3162
|
224 clean_up_and_exit (int retval) |
|
225 { |
3216
|
226 do_octave_atexit (); |
1683
|
227 |
3162
|
228 exit (retval == EOF ? 0 : retval); |
1683
|
229 } |
|
230 |
4208
|
231 DEFCMD (casesen, args, , |
3446
|
232 "-*- texinfo -*-\n\ |
|
233 @deffn {Command} casesen arg\n\ |
|
234 Provided for compatibility with Matlab, but does nothing.\n\ |
|
235 @end deffn") |
1683
|
236 { |
2086
|
237 octave_value_list retval; |
1683
|
238 |
1755
|
239 int argc = args.length () + 1; |
|
240 |
1965
|
241 string_vector argv = args.make_argv ("casesen"); |
1683
|
242 |
1755
|
243 if (error_state) |
|
244 return retval; |
|
245 |
|
246 if (argc == 1 || (argc > 1 && argv[1] == "off")) |
1683
|
247 warning ("casesen: sorry, Octave is always case sensitive"); |
1755
|
248 else if (argc > 1 && argv[1] == "on") |
1683
|
249 ; // ok. |
|
250 else |
|
251 print_usage ("casesen"); |
|
252 |
|
253 return retval; |
|
254 } |
|
255 |
3180
|
256 DEFUN (quit, args, nargout, |
3332
|
257 "-*- texinfo -*-\n\ |
|
258 @deftypefn {Built-in Function} {} exit (@var{status})\n\ |
|
259 @deftypefnx {Built-in Function} {} quit (@var{status})\n\ |
|
260 Exit the current Octave session. If the optional integer value\n\ |
|
261 @var{status} is supplied, pass that value to the operating system as the\n\ |
|
262 Octave's exit status.\n\ |
3333
|
263 @end deftypefn") |
1683
|
264 { |
2086
|
265 octave_value_list retval; |
2068
|
266 |
3180
|
267 if (nargout == 0) |
2068
|
268 { |
3180
|
269 int exit_status = 0; |
|
270 |
|
271 quitting_gracefully = true; |
1683
|
272 |
3180
|
273 if (args.length () > 0) |
|
274 { |
3202
|
275 int tmp = args(0).nint_value (); |
1683
|
276 |
3202
|
277 if (! error_state) |
|
278 exit_status = tmp; |
3180
|
279 } |
|
280 |
|
281 clean_up_and_exit (exit_status); |
2068
|
282 } |
3180
|
283 else |
|
284 error ("quit: invalid number of output arguments"); |
2068
|
285 |
1683
|
286 return retval; |
|
287 } |
|
288 |
|
289 DEFALIAS (exit, quit); |
|
290 |
1957
|
291 DEFUN (warranty, , , |
3446
|
292 "-*- texinfo -*-\n\ |
|
293 @deftypefn {Built-in Function} {} warranty ()\n\ |
|
294 Describe the conditions for copying and distributing Octave.\n\ |
|
295 @end deftypefn") |
1683
|
296 { |
2086
|
297 octave_value_list retval; |
1683
|
298 |
3922
|
299 octave_stdout << "\n" \ |
|
300 OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\ |
|
301 \n\ |
1683
|
302 This program is free software; you can redistribute it and/or modify\n\ |
|
303 it under the terms of the GNU General Public License as published by\n\ |
|
304 the Free Software Foundation; either version 2 of the License, or\n\ |
|
305 (at your option) any later version.\n\ |
|
306 \n\ |
|
307 This program is distributed in the hope that it will be useful,\n\ |
|
308 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ |
|
309 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ |
|
310 GNU General Public License for more details.\n\ |
|
311 \n\ |
|
312 You should have received a copy of the GNU General Public License\n\ |
|
313 along with this program. If not, write to the Free Software\n\ |
|
314 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n\ |
|
315 \n"; |
|
316 |
|
317 return retval; |
|
318 } |
|
319 |
|
320 // Execute a shell command. |
|
321 |
1965
|
322 static void |
|
323 cleanup_iprocstream (void *p) |
|
324 { |
3060
|
325 iprocstream *cmd = static_cast<iprocstream *> (p); |
|
326 |
|
327 octave_child_list::remove (cmd->pid ()); |
|
328 |
|
329 delete cmd; |
1965
|
330 } |
|
331 |
2086
|
332 static octave_value_list |
3523
|
333 run_command_and_return_output (const std::string& cmd_str) |
2083
|
334 { |
2086
|
335 octave_value_list retval; |
2083
|
336 |
|
337 iprocstream *cmd = new iprocstream (cmd_str.c_str ()); |
|
338 |
3060
|
339 if (cmd) |
2083
|
340 { |
3060
|
341 unwind_protect::add (cleanup_iprocstream, cmd); |
|
342 |
|
343 if (*cmd) |
|
344 { |
4051
|
345 OSSTREAM output_buf; |
2095
|
346 |
4489
|
347 // XXX FIXME XXX -- Perhaps we should read more than one |
|
348 // character at a time and find a way to avoid the call to |
|
349 // octave_usleep as well? |
3147
|
350 |
4494
|
351 // This is a bit of a kluge... |
|
352 |
|
353 octave_usleep (100); |
|
354 |
3060
|
355 char ch; |
3147
|
356 |
4489
|
357 for (;;) |
3147
|
358 { |
4489
|
359 if (cmd->get (ch)) |
|
360 output_buf.put (ch); |
|
361 else |
|
362 { |
|
363 if (! cmd->eof () && errno == EAGAIN) |
|
364 { |
|
365 cmd->clear (); |
3147
|
366 |
4489
|
367 octave_usleep (100); |
|
368 } |
|
369 else |
|
370 break; |
|
371 } |
3147
|
372 } |
|
373 |
3252
|
374 int cmd_status = cmd->close (); |
2083
|
375 |
3060
|
376 if (WIFEXITED (cmd_status)) |
|
377 cmd_status = WEXITSTATUS (cmd_status); |
|
378 else |
|
379 cmd_status = 127; |
2083
|
380 |
4051
|
381 output_buf << OSSTREAM_ENDS; |
2083
|
382 |
3060
|
383 retval(1) = (double) cmd_status; |
4051
|
384 retval(0) = OSSTREAM_STR (output_buf); |
2083
|
385 |
4051
|
386 OSSTREAM_FREEZE (output_buf); |
3060
|
387 } |
|
388 |
|
389 unwind_protect::run (); |
2083
|
390 } |
|
391 else |
|
392 error ("unable to start subprocess for `%s'", cmd_str.c_str ()); |
|
393 |
|
394 return retval; |
|
395 } |
|
396 |
1957
|
397 DEFUN (system, args, nargout, |
3301
|
398 "-*- texinfo -*-\n\ |
|
399 @deftypefn {Built-in Function} {} system (@var{string}, @var{return_output}, @var{type})\n\ |
|
400 Execute a shell command specified by @var{string}. The second\n\ |
|
401 argument is optional. If @var{type} is @code{\"async\"}, the process\n\ |
|
402 is started in the background and the process id of the child process\n\ |
|
403 is returned immediately. Otherwise, the process is started, and\n\ |
|
404 Octave waits until it exits. If @var{type} argument is omitted, a\n\ |
|
405 value of @code{\"sync\"} is assumed.\n\ |
2083
|
406 \n\ |
3301
|
407 If two input arguments are given (the actual value of\n\ |
|
408 @var{return_output} is irrelevant) and the subprocess is started\n\ |
|
409 synchronously, or if @var{system} is called with one input argument and\n\ |
|
410 one or more output arguments, the output from the command is returned.\n\ |
5097
|
411 Otherwise, if the subprocess is executed synchronously, its output is\n\ |
2321
|
412 sent to the standard output. To send the output of a command executed\n\ |
3301
|
413 with @var{system} through the pager, use a command like\n\ |
2321
|
414 \n\ |
3301
|
415 @example\n\ |
|
416 disp (system (cmd, 1));\n\ |
|
417 @end example\n\ |
2321
|
418 \n\ |
3301
|
419 @noindent\n\ |
2321
|
420 or\n\ |
|
421 \n\ |
3301
|
422 @example\n\ |
|
423 printf (\"%s\n\", system (cmd, 1));\n\ |
|
424 @end example\n\ |
|
425 \n\ |
|
426 The @code{system} function can return two values. The first is any\n\ |
|
427 output from the command that was written to the standard output stream,\n\ |
|
428 and the second is the output status of the command. For example,\n\ |
|
429 \n\ |
|
430 @example\n\ |
|
431 [output, status] = system (\"echo foo; exit 2\");\n\ |
|
432 @end example\n\ |
|
433 \n\ |
|
434 @noindent\n\ |
|
435 will set the variable @code{output} to the string @samp{foo}, and the\n\ |
|
436 variable @code{status} to the integer @samp{2}.\n\ |
|
437 @end deftypefn") |
1683
|
438 { |
2086
|
439 octave_value_list retval; |
1683
|
440 |
3834
|
441 unwind_protect::begin_frame ("Fsystem"); |
|
442 |
1683
|
443 int nargin = args.length (); |
|
444 |
2083
|
445 if (nargin > 0 && nargin < 4) |
1683
|
446 { |
2083
|
447 bool return_output = (nargout > 0 || nargin > 1); |
|
448 |
3523
|
449 std::string cmd_str = args(0).string_value (); |
2083
|
450 |
|
451 enum exec_type { sync, async }; |
|
452 |
|
453 exec_type type = sync; |
|
454 |
|
455 if (! error_state) |
|
456 { |
|
457 if (nargin > 2) |
|
458 { |
3523
|
459 std::string type_str = args(2).string_value (); |
1683
|
460 |
2083
|
461 if (! error_state) |
|
462 { |
|
463 if (type_str == "sync") |
|
464 type = sync; |
|
465 else if (type_str == "async") |
|
466 type = async; |
|
467 else |
|
468 error ("system: third arg must be \"sync\" or \"async\""); |
|
469 } |
|
470 else |
|
471 error ("system: third argument must be a string"); |
|
472 } |
|
473 } |
|
474 else |
3523
|
475 error ("system: expecting std::string as first argument"); |
1683
|
476 |
2083
|
477 if (! error_state) |
|
478 { |
|
479 if (type == async) |
|
480 { |
4086
|
481 #ifdef HAVE_FORK |
2083
|
482 pid_t pid = fork (); |
|
483 |
|
484 if (pid < 0) |
|
485 error ("system: fork failed -- can't create child process"); |
|
486 else if (pid == 0) |
|
487 { |
3273
|
488 // XXX FIXME XXX -- should probably replace this |
|
489 // call with something portable. |
|
490 |
|
491 execl ("/bin/sh", "sh", "-c", cmd_str.c_str (), 0); |
|
492 |
|
493 panic_impossible (); |
2083
|
494 } |
|
495 else |
4254
|
496 retval(0) = pid; |
4086
|
497 #else |
|
498 error ("asynchronous system calls are not supported"); |
|
499 #endif |
2083
|
500 } |
2321
|
501 else if (return_output) |
|
502 retval = run_command_and_return_output (cmd_str); |
2083
|
503 else |
2321
|
504 { |
|
505 int status = system (cmd_str.c_str ()); |
|
506 |
|
507 // The value in status is as returned by waitpid. If |
|
508 // the process exited normally, extract the actual exit |
|
509 // status of the command. Otherwise, return 127 as a |
|
510 // failure code. |
|
511 |
2693
|
512 if (WIFEXITED (status)) |
|
513 status = WEXITSTATUS (status); |
2321
|
514 |
4233
|
515 retval(0) = status; |
2321
|
516 } |
2083
|
517 } |
1683
|
518 } |
|
519 else |
2083
|
520 print_usage ("system"); |
1683
|
521 |
3834
|
522 unwind_protect::run_frame ("Fsystem"); |
|
523 |
1683
|
524 return retval; |
|
525 } |
|
526 |
|
527 DEFALIAS (shell_cmd, system); |
|
528 |
2614
|
529 // XXX FIXME XXX -- this should really be static, but that causes |
|
530 // problems on some systems. |
4214
|
531 std::stack<std::string> octave_atexit_functions; |
2077
|
532 |
|
533 void |
|
534 do_octave_atexit (void) |
|
535 { |
3216
|
536 static bool deja_vu = false; |
|
537 |
2077
|
538 while (! octave_atexit_functions.empty ()) |
|
539 { |
4233
|
540 std::string fcn = octave_atexit_functions.top (); |
4214
|
541 |
|
542 octave_atexit_functions.pop (); |
2077
|
543 |
4233
|
544 feval (fcn, octave_value_list (), 0); |
3215
|
545 |
|
546 flush_octave_stdout (); |
2077
|
547 } |
3216
|
548 |
|
549 if (! deja_vu) |
|
550 { |
|
551 deja_vu = true; |
|
552 |
|
553 command_editor::restore_terminal_state (); |
|
554 |
|
555 // XXX FIXME XXX -- is this needed? Can it cause any trouble? |
|
556 raw_mode (0); |
|
557 |
|
558 command_history::clean_up_and_save (); |
|
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, |
4759
|
655 "DL_LD", OCTAVE_CONF_DL_LD, |
|
656 "DL_LDFLAGS", OCTAVE_CONF_DL_LDFLAGS, |
4357
|
657 "DLFCN_INCFLAGS", OCTAVE_CONF_DLFCN_INCFLAGS, |
|
658 "EXEEXT", OCTAVE_CONF_EXEEXT, |
|
659 "F2C", OCTAVE_CONF_F2C, |
|
660 "F2CFLAGS", OCTAVE_CONF_F2CFLAGS, |
|
661 "F77", OCTAVE_CONF_F77, |
|
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, |
|
667 "INCFLAGS", OCTAVE_CONF_INCFLAGS, |
|
668 "LDFLAGS", OCTAVE_CONF_LDFLAGS, |
|
669 "LD_CXX", OCTAVE_CONF_LD_CXX, |
|
670 "LD_STATIC_FLAG", OCTAVE_CONF_LD_STATIC_FLAG, |
|
671 "LEX", OCTAVE_CONF_LEX, |
|
672 "LEXLIB", OCTAVE_CONF_LEXLIB, |
|
673 "LFLAGS", OCTAVE_CONF_LFLAGS, |
|
674 "LIBCRUFT", OCTAVE_CONF_LIBCRUFT, |
|
675 "LIBDLFCN", OCTAVE_CONF_LIBDLFCN, |
|
676 "LIBEXT", OCTAVE_CONF_LIBEXT, |
|
677 "LIBFLAGS", OCTAVE_CONF_LIBFLAGS, |
|
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, |
4759
|
686 "MKOCTFILE_DL_LDFLAGS", OCTAVE_CONF_MKOCTFILE_DL_LDFLAGS, |
4357
|
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 */ |