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 |
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 { |
3523
|
344 std::ostrstream 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 |
3538
|
376 output_buf << std::ends; |
2145
|
377 |
3060
|
378 char *msg = output_buf.str (); |
2083
|
379 |
3060
|
380 retval(1) = (double) cmd_status; |
|
381 retval(0) = msg; |
2083
|
382 |
3060
|
383 delete [] msg; |
|
384 } |
|
385 |
|
386 unwind_protect::run (); |
2083
|
387 } |
|
388 else |
|
389 error ("unable to start subprocess for `%s'", cmd_str.c_str ()); |
|
390 |
|
391 return retval; |
|
392 } |
|
393 |
3834
|
394 static void |
|
395 restore_texmfdbs_envvar (void *ptr) |
|
396 { |
|
397 std::string *s = static_cast<std::string *> (ptr); |
|
398 |
|
399 octave_env::putenv ("TEXMFDBS", *s); |
|
400 } |
|
401 |
1957
|
402 DEFUN (system, args, nargout, |
3301
|
403 "-*- texinfo -*-\n\ |
|
404 @deftypefn {Built-in Function} {} system (@var{string}, @var{return_output}, @var{type})\n\ |
|
405 Execute a shell command specified by @var{string}. The second\n\ |
|
406 argument is optional. If @var{type} is @code{\"async\"}, the process\n\ |
|
407 is started in the background and the process id of the child process\n\ |
|
408 is returned immediately. Otherwise, the process is started, and\n\ |
|
409 Octave waits until it exits. If @var{type} argument is omitted, a\n\ |
|
410 value of @code{\"sync\"} is assumed.\n\ |
2083
|
411 \n\ |
3301
|
412 If two input arguments are given (the actual value of\n\ |
|
413 @var{return_output} is irrelevant) and the subprocess is started\n\ |
|
414 synchronously, or if @var{system} is called with one input argument and\n\ |
|
415 one or more output arguments, the output from the command is returned.\n\ |
2083
|
416 Otherwise, if the subprocess is executed synchronously, it's output is\n\ |
2321
|
417 sent to the standard output. To send the output of a command executed\n\ |
3301
|
418 with @var{system} through the pager, use a command like\n\ |
2321
|
419 \n\ |
3301
|
420 @example\n\ |
|
421 disp (system (cmd, 1));\n\ |
|
422 @end example\n\ |
2321
|
423 \n\ |
3301
|
424 @noindent\n\ |
2321
|
425 or\n\ |
|
426 \n\ |
3301
|
427 @example\n\ |
|
428 printf (\"%s\n\", system (cmd, 1));\n\ |
|
429 @end example\n\ |
|
430 \n\ |
|
431 The @code{system} function can return two values. The first is any\n\ |
|
432 output from the command that was written to the standard output stream,\n\ |
|
433 and the second is the output status of the command. For example,\n\ |
|
434 \n\ |
|
435 @example\n\ |
|
436 [output, status] = system (\"echo foo; exit 2\");\n\ |
|
437 @end example\n\ |
|
438 \n\ |
|
439 @noindent\n\ |
|
440 will set the variable @code{output} to the string @samp{foo}, and the\n\ |
|
441 variable @code{status} to the integer @samp{2}.\n\ |
|
442 @end deftypefn") |
1683
|
443 { |
2086
|
444 octave_value_list retval; |
1683
|
445 |
3834
|
446 unwind_protect::begin_frame ("Fsystem"); |
|
447 |
1683
|
448 int nargin = args.length (); |
|
449 |
2083
|
450 if (nargin > 0 && nargin < 4) |
1683
|
451 { |
2083
|
452 bool return_output = (nargout > 0 || nargin > 1); |
|
453 |
3523
|
454 std::string cmd_str = args(0).string_value (); |
2083
|
455 |
|
456 enum exec_type { sync, async }; |
|
457 |
|
458 exec_type type = sync; |
|
459 |
|
460 if (! error_state) |
|
461 { |
|
462 if (nargin > 2) |
|
463 { |
3523
|
464 std::string type_str = args(2).string_value (); |
1683
|
465 |
2083
|
466 if (! error_state) |
|
467 { |
|
468 if (type_str == "sync") |
|
469 type = sync; |
|
470 else if (type_str == "async") |
|
471 type = async; |
|
472 else |
|
473 error ("system: third arg must be \"sync\" or \"async\""); |
|
474 } |
|
475 else |
|
476 error ("system: third argument must be a string"); |
|
477 } |
|
478 } |
|
479 else |
3523
|
480 error ("system: expecting std::string as first argument"); |
1683
|
481 |
2083
|
482 if (! error_state) |
|
483 { |
3834
|
484 // The value of TEXMFDBS that Octave puts in the environment |
|
485 // will cause trouble if we are asked to run TeX, so we |
|
486 // should reset it to whatever it was before Octave started. |
|
487 // |
|
488 // XXX FIXME XXX -- it would be better to fix the |
|
489 // kpathsearch library to not always do TeX-specific |
|
490 // things... |
|
491 |
3841
|
492 static std::string odb; |
3834
|
493 |
|
494 odb = octave_env::getenv ("TEXMFDBS"); |
|
495 |
|
496 unwind_protect::add (restore_texmfdbs_envvar, &odb); |
|
497 |
|
498 octave_env::putenv ("TEXMFDBS", octave_original_texmfdbs); |
|
499 |
2083
|
500 if (type == async) |
|
501 { |
|
502 pid_t pid = fork (); |
|
503 |
|
504 if (pid < 0) |
|
505 error ("system: fork failed -- can't create child process"); |
|
506 else if (pid == 0) |
|
507 { |
3273
|
508 // XXX FIXME XXX -- should probably replace this |
|
509 // call with something portable. |
|
510 |
|
511 execl ("/bin/sh", "sh", "-c", cmd_str.c_str (), 0); |
|
512 |
|
513 panic_impossible (); |
2083
|
514 } |
|
515 else |
2800
|
516 retval(0) = static_cast<double> (pid); |
2083
|
517 } |
2321
|
518 else if (return_output) |
|
519 retval = run_command_and_return_output (cmd_str); |
2083
|
520 else |
2321
|
521 { |
|
522 int status = system (cmd_str.c_str ()); |
|
523 |
|
524 // The value in status is as returned by waitpid. If |
|
525 // the process exited normally, extract the actual exit |
|
526 // status of the command. Otherwise, return 127 as a |
|
527 // failure code. |
|
528 |
2693
|
529 if (WIFEXITED (status)) |
|
530 status = WEXITSTATUS (status); |
2321
|
531 |
2800
|
532 retval = static_cast<double> (status); |
2321
|
533 } |
2083
|
534 } |
1683
|
535 } |
|
536 else |
2083
|
537 print_usage ("system"); |
1683
|
538 |
3834
|
539 unwind_protect::run_frame ("Fsystem"); |
|
540 |
1683
|
541 return retval; |
|
542 } |
|
543 |
|
544 DEFALIAS (shell_cmd, system); |
|
545 |
2614
|
546 // XXX FIXME XXX -- this should really be static, but that causes |
|
547 // problems on some systems. |
3523
|
548 SLStack<std::string> octave_atexit_functions; |
2077
|
549 |
|
550 void |
|
551 do_octave_atexit (void) |
|
552 { |
3216
|
553 static bool deja_vu = false; |
|
554 |
2077
|
555 while (! octave_atexit_functions.empty ()) |
|
556 { |
2086
|
557 octave_value_list fcn = octave_atexit_functions.pop (); |
2077
|
558 |
2942
|
559 feval (fcn, 0); |
3215
|
560 |
|
561 flush_octave_stdout (); |
2077
|
562 } |
3216
|
563 |
|
564 if (! deja_vu) |
|
565 { |
|
566 deja_vu = true; |
|
567 |
|
568 command_editor::restore_terminal_state (); |
|
569 |
|
570 // XXX FIXME XXX -- is this needed? Can it cause any trouble? |
|
571 raw_mode (0); |
|
572 |
|
573 command_history::clean_up_and_save (); |
|
574 |
|
575 close_plot_stream (); |
|
576 |
|
577 close_files (); |
|
578 |
|
579 cleanup_tmp_files (); |
|
580 |
|
581 flush_octave_stdout (); |
|
582 |
|
583 if (!quitting_gracefully && (interactive || forced_interactive)) |
3531
|
584 std::cout << "\n"; |
3216
|
585 } |
2077
|
586 } |
|
587 |
2162
|
588 DEFUN (atexit, args, , |
3332
|
589 "-*- texinfo -*-\n\ |
|
590 @deftypefn {Built-in Function} {} atexit (@var{fcn})\n\ |
|
591 Register a function to be called when Octave exits. For example,\n\ |
2077
|
592 \n\ |
3332
|
593 @example\n\ |
|
594 @group\n\ |
3686
|
595 function print_fortune ()\n\ |
3332
|
596 printf (\"\\n%s\\n\", system (\"fortune\"));\n\ |
|
597 fflush (stdout);\n\ |
|
598 endfunction\n\ |
3686
|
599 atexit (\"print_fortune\");\n\ |
3332
|
600 @end group\n\ |
|
601 @end example\n\ |
|
602 \n\ |
|
603 @noindent\n\ |
|
604 will print a message when Octave exits.\n\ |
3333
|
605 @end deftypefn") |
2077
|
606 { |
2086
|
607 octave_value_list retval; |
2077
|
608 |
|
609 int nargin = args.length (); |
|
610 |
|
611 if (nargin == 1) |
|
612 { |
2475
|
613 #if defined (HAVE_ATEXIT) || defined (HAVE_ON_EXIT) |
3523
|
614 std::string arg = args(0).string_value (); |
2077
|
615 |
|
616 if (! error_state) |
|
617 octave_atexit_functions.push (arg); |
|
618 else |
|
619 error ("atexit: argument must be a string"); |
2475
|
620 #else |
|
621 gripe_not_supported ("atexit"); |
|
622 #endif |
2077
|
623 } |
|
624 else |
|
625 print_usage ("atexit"); |
|
626 |
|
627 return retval; |
|
628 } |
|
629 |
2689
|
630 DEFUN (octave_config_info, args, , |
3301
|
631 "-*- texinfo -*-\n\ |
|
632 @deftypefn {Built-in Function} {} octave_config_info (@var{option})\n\ |
|
633 Return a structure containing configuration and installation\n\ |
|
634 information for Octave.\n\ |
2689
|
635 \n\ |
3301
|
636 if @var{option} is a string, return the configuration information for the\n\ |
2689
|
637 specified option.\n\ |
|
638 \n\ |
3301
|
639 @end deftypefn") |
2162
|
640 { |
2689
|
641 octave_value retval; |
|
642 |
2696
|
643 #if defined (WITH_DYNAMIC_LINKING) && (defined (WITH_DL) || defined (WITH_SHL)) |
2689
|
644 bool octave_supports_dynamic_linking = true; |
|
645 #else |
|
646 bool octave_supports_dynamic_linking = false; |
|
647 #endif |
|
648 |
2162
|
649 Octave_map m; |
|
650 |
3584
|
651 m ["ALL_CFLAGS"] = OCTAVE_CONF_ALL_CFLAGS; |
|
652 m ["ALL_CXXFLAGS"] = OCTAVE_CONF_ALL_CXXFLAGS; |
|
653 m ["ALL_FFLAGS"] = OCTAVE_CONF_ALL_FFLAGS; |
|
654 m ["ALL_LDFLAGS"] = OCTAVE_CONF_ALL_LDFLAGS; |
|
655 m ["AR"] = OCTAVE_CONF_AR; |
|
656 m ["ARFLAGS"] = OCTAVE_CONF_ARFLAGS; |
3726
|
657 m ["BLAS_LIBS"] = OCTAVE_CONF_BLAS_LIBS; |
3584
|
658 m ["CC"] = OCTAVE_CONF_CC; |
|
659 m ["CC_VERSION"] = OCTAVE_CONF_CC_VERSION; |
|
660 m ["CFLAGS"] = OCTAVE_CONF_CFLAGS; |
|
661 m ["CPICFLAG"] = OCTAVE_CONF_CPICFLAG; |
|
662 m ["CPPFLAGS"] = OCTAVE_CONF_CPPFLAGS; |
|
663 m ["CXX"] = OCTAVE_CONF_CXX; |
|
664 m ["CXXCPP"] = OCTAVE_CONF_CXXCPP; |
|
665 m ["CXXFLAGS"] = OCTAVE_CONF_CXXFLAGS; |
|
666 m ["CXXPICFLAG"] = OCTAVE_CONF_CXXPICFLAG; |
|
667 m ["CXX_VERSION"] = OCTAVE_CONF_CXX_VERSION; |
|
668 m ["DEFAULT_PAGER"] = OCTAVE_DEFAULT_PAGER; |
|
669 m ["DLFCN_INCFLAGS"] = OCTAVE_CONF_DLFCN_INCFLAGS; |
3892
|
670 m ["EXEEXT"] = OCTAVE_CONF_EXEEXT; |
3584
|
671 m ["F2C"] = OCTAVE_CONF_F2C; |
|
672 m ["F2CFLAGS"] = OCTAVE_CONF_F2CFLAGS; |
|
673 m ["F77"] = OCTAVE_CONF_F77; |
|
674 m ["FC"] = OCTAVE_CONF_FC; |
|
675 m ["FFLAGS"] = OCTAVE_CONF_FFLAGS; |
3859
|
676 m ["FFTW_LIBS"] = OCTAVE_CONF_FFTW_LIBS; |
3584
|
677 m ["FLIBS"] = OCTAVE_CONF_FLIBS; |
|
678 m ["FPICFLAG"] = OCTAVE_CONF_FPICFLAG; |
|
679 m ["GLOB_INCFLAGS"] = OCTAVE_CONF_GLOB_INCFLAGS; |
|
680 m ["INCFLAGS"] = OCTAVE_CONF_INCFLAGS; |
|
681 m ["LDFLAGS"] = OCTAVE_CONF_LDFLAGS; |
3859
|
682 m ["LD_CXX"] = OCTAVE_CONF_LD_CXX; |
3584
|
683 m ["LD_STATIC_FLAG"] = OCTAVE_CONF_LD_STATIC_FLAG; |
|
684 m ["LEX"] = OCTAVE_CONF_LEX; |
|
685 m ["LEXLIB"] = OCTAVE_CONF_LEXLIB; |
|
686 m ["LFLAGS"] = OCTAVE_CONF_LFLAGS; |
|
687 m ["LIBCRUFT"] = OCTAVE_CONF_LIBCRUFT; |
|
688 m ["LIBDLFCN"] = OCTAVE_CONF_LIBDLFCN; |
|
689 m ["LIBEXT"] = OCTAVE_CONF_LIBEXT; |
|
690 m ["LIBFLAGS"] = OCTAVE_CONF_LIBFLAGS; |
|
691 m ["LIBGLOB"] = OCTAVE_CONF_LIBGLOB; |
|
692 m ["LIBKPATHSEA"] = OCTAVE_CONF_LIBKPATHSEA; |
3859
|
693 m ["LIBOCT_PATHSEARCH"] = OCTAVE_CONF_LIBOCT_PATHSEARCH; |
|
694 m ["LIBOCT_READLINE"] = OCTAVE_CONF_LIBOCT_READLINE; |
3584
|
695 m ["LIBOCTAVE"] = OCTAVE_CONF_LIBOCTAVE; |
|
696 m ["LIBOCTINTERP"] = OCTAVE_CONF_LIBOCTINTERP; |
|
697 m ["LIBPLPLOT"] = OCTAVE_CONF_LIBPLPLOT; |
|
698 m ["LIBS"] = OCTAVE_CONF_LIBS; |
|
699 m ["LN_S"] = OCTAVE_CONF_LN_S; |
3591
|
700 m ["MKOCTFILE_INCFLAGS"] = OCTAVE_CONF_MKOCTFILE_INCFLAGS; |
3859
|
701 m ["MKOCTFILE_LFLAGS"] = OCTAVE_CONF_MKOCTFILE_LFLAGS; |
3584
|
702 m ["OCTAVE_LITE"] = OCTAVE_CONF_OCTAVE_LITE; |
|
703 m ["RANLIB"] = OCTAVE_CONF_RANLIB; |
|
704 m ["RDYNAMIC_FLAG"] = OCTAVE_CONF_RDYNAMIC_FLAG; |
|
705 m ["RLD_FLAG"] = OCTAVE_CONF_RLD_FLAG; |
|
706 m ["RUNTEST"] = OCTAVE_CONF_RUNTEST; |
|
707 m ["SHARED_LIBS"] = OCTAVE_CONF_SHARED_LIBS; |
|
708 m ["SHLEXT"] = OCTAVE_CONF_SHLEXT; |
|
709 m ["SHLEXT_VER"] = OCTAVE_CONF_SHLEXT_VER; |
|
710 m ["SH_LD"] = OCTAVE_CONF_SH_LD; |
|
711 m ["SH_LDFLAGS"] = OCTAVE_CONF_SH_LDFLAGS; |
|
712 m ["SONAME_FLAGS"] = OCTAVE_CONF_SONAME_FLAGS; |
|
713 m ["STATIC_LIBS"] = OCTAVE_CONF_STATIC_LIBS; |
|
714 m ["UGLY_DEFS"] = OCTAVE_CONF_DEFS; |
|
715 m ["UGLY_DEFS"] = OCTAVE_CONF_UGLY_DEFS; |
|
716 m ["WITH_DL"] = OCTAVE_CONF_WITH_DL; |
|
717 m ["WITH_DYNAMIC_LINKING"] = OCTAVE_CONF_WITH_DYNAMIC_LINKING; |
|
718 m ["WITH_SHL"] = OCTAVE_CONF_WITH_SHL; |
|
719 m ["XTRA_CFLAGS"] = OCTAVE_CONF_XTRA_CFLAGS; |
|
720 m ["XTRA_CXXFLAGS"] = OCTAVE_CONF_XTRA_CXXFLAGS; |
|
721 m ["YACC"] = OCTAVE_CONF_YACC; |
|
722 m ["YFLAGS"] = OCTAVE_CONF_YFLAGS; |
|
723 m ["archlibdir"] = OCTAVE_ARCHLIBDIR; |
|
724 m ["bindir"] = OCTAVE_BINDIR; |
|
725 m ["canonical_host_type"] = OCTAVE_CANONICAL_HOST_TYPE; |
|
726 m ["config_opts"] = OCTAVE_CONF_config_opts; |
2162
|
727 m ["datadir"] = OCTAVE_DATADIR; |
2800
|
728 m ["dld"] = static_cast<double> (octave_supports_dynamic_linking); |
3584
|
729 m ["exec_prefix"] = OCTAVE_EXEC_PREFIX; |
2162
|
730 m ["fcnfiledir"] = OCTAVE_FCNFILEDIR; |
|
731 m ["fcnfilepath"] = OCTAVE_FCNFILEPATH; |
3584
|
732 m ["imagedir"] = OCTAVE_IMAGEDIR; |
2162
|
733 m ["imagepath"] = OCTAVE_IMAGEPATH; |
3584
|
734 m ["includedir"] = OCTAVE_INCLUDEDIR; |
|
735 m ["infodir"] = OCTAVE_INFODIR; |
|
736 m ["infofile"] = OCTAVE_INFOFILE; |
|
737 m ["libdir"] = OCTAVE_LIBDIR; |
|
738 m ["libexecdir"] = OCTAVE_LIBEXECDIR; |
|
739 m ["localarchlibdir"] = OCTAVE_LOCALARCHLIBDIR; |
|
740 m ["localfcnfiledir"] = OCTAVE_LOCALFCNFILEDIR; |
|
741 m ["localfcnfilepath"] = OCTAVE_LOCALFCNFILEPATH; |
|
742 m ["localoctfiledir"] = OCTAVE_LOCALOCTFILEDIR; |
|
743 m ["localoctfilepath"] = OCTAVE_LOCALOCTFILEPATH; |
|
744 m ["localstartupfiledir"] = OCTAVE_LOCALSTARTUPFILEDIR; |
3597
|
745 m ["localverarchlibdir"] = OCTAVE_LOCALVERARCHLIBDIR; |
|
746 m ["localverfcnfiledir"] = OCTAVE_LOCALVERFCNFILEDIR; |
|
747 m ["localveroctfiledir"] = OCTAVE_LOCALVEROCTFILEDIR; |
3584
|
748 m ["man1dir"] = OCTAVE_MAN1DIR; |
|
749 m ["man1ext"] = OCTAVE_MAN1EXT; |
|
750 m ["mandir"] = OCTAVE_MANDIR; |
|
751 m ["octfiledir"] = OCTAVE_OCTFILEDIR; |
|
752 m ["octincludedir"] = OCTAVE_OCTINCLUDEDIR; |
|
753 m ["octlibdir"] = OCTAVE_OCTLIBDIR; |
|
754 m ["prefix"] = OCTAVE_PREFIX; |
|
755 m ["startupfiledir"] = OCTAVE_STARTUPFILEDIR; |
|
756 m ["version"] = OCTAVE_VERSION; |
2162
|
757 |
2689
|
758 int nargin = args.length (); |
|
759 |
|
760 if (nargin == 1) |
|
761 { |
3523
|
762 std::string arg = args(0).string_value (); |
2689
|
763 |
|
764 if (! error_state) |
|
765 retval = octave_value (m [arg.c_str ()]); |
|
766 } |
|
767 else if (nargin == 0) |
|
768 retval = octave_value (m); |
|
769 else |
|
770 print_usage ("octave_config_info"); |
|
771 |
|
772 return retval; |
2162
|
773 } |
|
774 |
1683
|
775 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE) |
2806
|
776 |
1683
|
777 int debug_new_delete = 0; |
|
778 |
|
779 typedef void (*vfp)(void); |
|
780 extern vfp __new_handler; |
|
781 |
|
782 void * |
|
783 __builtin_new (size_t sz) |
|
784 { |
|
785 void *p; |
|
786 |
|
787 /* malloc (0) is unpredictable; avoid it. */ |
|
788 if (sz == 0) |
|
789 sz = 1; |
2800
|
790 p = malloc (sz); |
1683
|
791 while (p == 0) |
|
792 { |
|
793 (*__new_handler) (); |
2800
|
794 p = malloc (sz); |
1683
|
795 } |
|
796 |
|
797 if (debug_new_delete) |
3538
|
798 std::cout << "__builtin_new: " << p << std::endl; |
1683
|
799 |
|
800 return p; |
|
801 } |
|
802 |
|
803 void |
|
804 __builtin_delete (void *ptr) |
|
805 { |
|
806 if (debug_new_delete) |
3538
|
807 std::cout << "__builtin_delete: " << ptr << std::endl; |
1683
|
808 |
|
809 if (ptr) |
|
810 free (ptr); |
|
811 } |
2806
|
812 |
1683
|
813 #endif |
|
814 |
2806
|
815 void |
|
816 symbols_of_toplev (void) |
|
817 { |
3141
|
818 DEFCONST (argv, , |
3332
|
819 "-*- texinfo -*-\n\ |
|
820 @defvr {Built-in Variable} argv\n\ |
|
821 The command line arguments passed to Octave are available in this\n\ |
|
822 variable. For example, if you invoked Octave using the command\n\ |
|
823 \n\ |
|
824 @example\n\ |
|
825 octave --no-line-editing --silent\n\ |
|
826 @end example\n\ |
|
827 \n\ |
|
828 @noindent\n\ |
|
829 @code{argv} would be a list of strings with the elements\n\ |
|
830 @code{--no-line-editing} and @code{--silent}.\n\ |
|
831 \n\ |
|
832 If you write an executable Octave script, @code{argv} will contain the\n\ |
3402
|
833 list of arguments passed to the script. @xref{Executable Octave Programs},\n\ |
|
834 for an example of how to create an executable Octave script.\n\ |
3333
|
835 @end defvr"); |
2806
|
836 |
3020
|
837 DEFCONST (program_invocation_name, |
3141
|
838 octave_env::get_program_invocation_name (), |
3332
|
839 "-*- texinfo -*-\n\ |
|
840 @defvr {Built-in Variable} program_invocation_name\n\ |
|
841 @defvrx {Built-in Variable} program_name\n\ |
|
842 When Octave starts, the value of the built-in variable\n\ |
|
843 @code{program_invocation_name} is automatically set to the name that was\n\ |
|
844 typed at the shell prompt to run Octave, and the value of\n\ |
|
845 @code{program_name} is automatically set to the final component of\n\ |
|
846 @code{program_invocation_name}. For example, if you typed\n\ |
|
847 @samp{@value{OCTAVEHOME}/bin/octave} to start Octave,\n\ |
|
848 @code{program_invocation_name} would have the value\n\ |
|
849 @code{\"@value{OCTAVEHOME}/bin/octave\"}, and @code{program_name} would\n\ |
|
850 have the value @code{\"octave\"}.\n\ |
|
851 \n\ |
|
852 If executing a script from the command line (e.g., @code{octave foo.m})\n\ |
|
853 or using an executable Octave script, the program name is set to the\n\ |
3402
|
854 name of the script. @xref{Executable Octave Programs}, for an example of\n\ |
3332
|
855 how to create an executable Octave script.\n\ |
3333
|
856 @end defvr"); |
3020
|
857 |
3141
|
858 DEFCONST (program_name, octave_env::get_program_name (), |
3332
|
859 "-*- texinfo -*-\n\ |
|
860 @defvr {Built-in Variable} program_invocation_name\n\ |
|
861 @defvrx {Built-in Variable} program_name\n\ |
|
862 When Octave starts, the value of the built-in variable\n\ |
|
863 @code{program_invocation_name} is automatically set to the name that was\n\ |
|
864 typed at the shell prompt to run Octave, and the value of\n\ |
|
865 @code{program_name} is automatically set to the final component of\n\ |
|
866 @code{program_invocation_name}. For example, if you typed\n\ |
|
867 @samp{@value{OCTAVEHOME}/bin/octave} to start Octave,\n\ |
|
868 @code{program_invocation_name} would have the value\n\ |
|
869 @code{\"@value{OCTAVEHOME}/bin/octave\"}, and @code{program_name} would\n\ |
|
870 have the value @code{\"octave\"}.\n\ |
|
871 \n\ |
|
872 If executing a script from the command line (e.g., @code{octave foo.m})\n\ |
|
873 or using an executable Octave script, the program name is set to the\n\ |
3402
|
874 name of the script. @xref{Executable Octave Programs}, for an example of\n\ |
3332
|
875 how to create an executable Octave script.\n\ |
3333
|
876 @end defvr"); |
|
877 |
2806
|
878 } |
|
879 |
1683
|
880 /* |
|
881 ;;; Local Variables: *** |
|
882 ;;; mode: C++ *** |
|
883 ;;; End: *** |
|
884 */ |