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