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