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