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