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