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 <csetjmp> |
|
29 #include <csignal> |
|
30 #include <cstdlib> |
|
31 #include <cstring> |
|
32 |
1728
|
33 #include <string> |
|
34 |
1683
|
35 #include <fstream.h> |
|
36 #include <iostream.h> |
|
37 #include <strstream.h> |
|
38 |
|
39 #ifdef HAVE_UNISTD_H |
2442
|
40 #ifdef HAVE_SYS_TYPES_H |
1683
|
41 #include <sys/types.h> |
2442
|
42 #endif |
1683
|
43 #include <unistd.h> |
|
44 #endif |
|
45 |
2926
|
46 #include "cmd-edit.h" |
|
47 #include "file-ops.h" |
1683
|
48 #include "lo-error.h" |
2370
|
49 #include "lo-mappers.h" |
3020
|
50 #include "oct-env.h" |
1755
|
51 #include "str-vec.h" |
1683
|
52 |
2492
|
53 #include <defaults.h> |
1683
|
54 #include "defun.h" |
|
55 #include "error.h" |
|
56 #include "file-io.h" |
|
57 #include "input.h" |
|
58 #include "lex.h" |
2492
|
59 #include <oct-conf.h> |
1742
|
60 #include "oct-hist.h" |
2162
|
61 #include "oct-map.h" |
2862
|
62 #include "oct-obj.h" |
1683
|
63 #include "pager.h" |
|
64 #include "parse.h" |
|
65 #include "pathsearch.h" |
|
66 #include "procstream.h" |
2370
|
67 #include "ov.h" |
2985
|
68 #include "pt-jump.h" |
1750
|
69 #include "pt-plot.h" |
2982
|
70 #include "pt-stmt.h" |
1683
|
71 #include "sighandlers.h" |
|
72 #include "sysdep.h" |
2693
|
73 #include "syswait.h" |
1750
|
74 #include "toplev.h" |
1683
|
75 #include "unwind-prot.h" |
|
76 #include "utils.h" |
|
77 #include "variables.h" |
2492
|
78 #include <version.h> |
1683
|
79 |
3020
|
80 // TRUE means we are exiting via the builtin exit or quit functions. |
|
81 static bool quitting_gracefully = false; |
1683
|
82 |
|
83 // Current command to execute. |
|
84 tree_statement_list *global_command = 0; |
|
85 |
|
86 // Pointer to function that is currently being evaluated. |
2891
|
87 octave_user_function *curr_function = 0; |
1683
|
88 |
1907
|
89 // Top level context (?) |
|
90 jmp_buf toplevel; |
|
91 |
|
92 int |
|
93 main_loop (void) |
|
94 { |
|
95 // Allow the user to interrupt us without exiting. |
|
96 |
2016
|
97 octave_save_signal_mask (); |
|
98 |
1907
|
99 if (setjmp (toplevel) != 0) |
|
100 { |
|
101 raw_mode (0); |
|
102 |
|
103 cout << "\n"; |
2016
|
104 |
|
105 octave_restore_signal_mask (); |
1907
|
106 } |
|
107 |
3020
|
108 can_interrupt = true; |
1907
|
109 |
2554
|
110 octave_catch_interrupts (); |
1907
|
111 |
|
112 // The big loop. |
|
113 |
|
114 int retval; |
|
115 do |
|
116 { |
|
117 curr_sym_tab = top_level_sym_tab; |
|
118 |
|
119 reset_parser (); |
|
120 |
|
121 retval = yyparse (); |
|
122 |
|
123 if (retval == 0 && global_command) |
|
124 { |
2898
|
125 global_command->eval (); |
2299
|
126 |
1907
|
127 delete global_command; |
2299
|
128 |
2620
|
129 global_command = 0; |
|
130 |
|
131 if (! (interactive || forced_interactive)) |
|
132 { |
2985
|
133 bool quit = (tree_return_command::returning |
|
134 || tree_break_command::breaking); |
2620
|
135 |
2985
|
136 if (tree_return_command::returning) |
|
137 tree_return_command::returning = 0; |
2620
|
138 |
2985
|
139 if (tree_break_command::breaking) |
|
140 tree_break_command::breaking--; |
2620
|
141 |
|
142 if (quit) |
|
143 break; |
|
144 } |
|
145 |
|
146 if (error_state) |
|
147 { |
|
148 if (! (interactive || forced_interactive)) |
|
149 break; |
|
150 } |
2299
|
151 else |
2620
|
152 { |
|
153 if (octave_completion_matches_called) |
|
154 octave_completion_matches_called = false; |
|
155 else |
2973
|
156 command_editor::increment_current_command_number (); |
2620
|
157 } |
1907
|
158 } |
|
159 } |
|
160 while (retval == 0); |
|
161 |
|
162 return retval; |
|
163 } |
|
164 |
1683
|
165 // Fix up things before exiting. |
|
166 |
|
167 void |
3162
|
168 clean_up_and_exit (int retval) |
|
169 { |
3216
|
170 do_octave_atexit (); |
1683
|
171 |
3162
|
172 exit (retval == EOF ? 0 : retval); |
1683
|
173 } |
|
174 |
1957
|
175 DEFUN_TEXT (casesen, args, , |
1683
|
176 "casesen [on|off]") |
|
177 { |
2086
|
178 octave_value_list retval; |
1683
|
179 |
1755
|
180 int argc = args.length () + 1; |
|
181 |
1965
|
182 string_vector argv = args.make_argv ("casesen"); |
1683
|
183 |
1755
|
184 if (error_state) |
|
185 return retval; |
|
186 |
|
187 if (argc == 1 || (argc > 1 && argv[1] == "off")) |
1683
|
188 warning ("casesen: sorry, Octave is always case sensitive"); |
1755
|
189 else if (argc > 1 && argv[1] == "on") |
1683
|
190 ; // ok. |
|
191 else |
|
192 print_usage ("casesen"); |
|
193 |
|
194 return retval; |
|
195 } |
|
196 |
1957
|
197 DEFUN (computer, args, nargout, |
3301
|
198 "-*- texinfo -*-\n\ |
|
199 @deftypefn {Built-in Function} {} computer ()\n\ |
|
200 Print or return a string of the form @var{cpu}-@var{vendor}-@var{os}\n\ |
|
201 that identifies the kind of computer Octave is running on. If invoked\n\ |
|
202 with an output argument, the value is returned instead of printed. For\n\ |
|
203 example,\n\ |
1683
|
204 \n\ |
3301
|
205 @example\n\ |
|
206 @group\n\ |
|
207 computer ()\n\ |
|
208 @print{} i586-pc-linux-gnu\n\ |
|
209 \n\ |
|
210 x = computer ()\n\ |
|
211 @result{} x = \"i586-pc-linux-gnu\"\n\ |
|
212 @end group\n\ |
|
213 @end example\n\ |
|
214 @end deftypefn") |
1683
|
215 { |
2086
|
216 octave_value_list retval; |
1683
|
217 |
|
218 int nargin = args.length (); |
|
219 |
|
220 if (nargin != 0) |
|
221 warning ("computer: ignoring extra arguments"); |
|
222 |
2095
|
223 string msg; |
1683
|
224 |
3234
|
225 if (strcmp (CANONICAL_HOST_TYPE, "unknown") == 0) |
2095
|
226 msg = "Hi Dave, I'm a HAL-9000"; |
1683
|
227 else |
3234
|
228 msg = CANONICAL_HOST_TYPE; |
1683
|
229 |
|
230 if (nargout == 0) |
2095
|
231 octave_stdout << msg << "\n"; |
1683
|
232 else |
2095
|
233 retval = msg; |
1683
|
234 |
|
235 return retval; |
|
236 } |
|
237 |
3180
|
238 DEFUN (quit, args, nargout, |
3332
|
239 "-*- texinfo -*-\n\ |
|
240 @deftypefn {Built-in Function} {} exit (@var{status})\n\ |
|
241 @deftypefnx {Built-in Function} {} quit (@var{status})\n\ |
|
242 Exit the current Octave session. If the optional integer value\n\ |
|
243 @var{status} is supplied, pass that value to the operating system as the\n\ |
|
244 Octave's exit status.\n\ |
3333
|
245 @end deftypefn") |
1683
|
246 { |
2086
|
247 octave_value_list retval; |
2068
|
248 |
3180
|
249 if (nargout == 0) |
2068
|
250 { |
3180
|
251 int exit_status = 0; |
|
252 |
|
253 quitting_gracefully = true; |
1683
|
254 |
3180
|
255 if (args.length () > 0) |
|
256 { |
3202
|
257 int tmp = args(0).nint_value (); |
1683
|
258 |
3202
|
259 if (! error_state) |
|
260 exit_status = tmp; |
3180
|
261 } |
|
262 |
|
263 clean_up_and_exit (exit_status); |
2068
|
264 } |
3180
|
265 else |
|
266 error ("quit: invalid number of output arguments"); |
2068
|
267 |
1683
|
268 return retval; |
|
269 } |
|
270 |
|
271 DEFALIAS (exit, quit); |
|
272 |
1957
|
273 DEFUN (warranty, , , |
1683
|
274 "warranty (): describe copying conditions") |
|
275 { |
2086
|
276 octave_value_list retval; |
1683
|
277 |
2095
|
278 octave_stdout << "\n" OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\n\ |
1683
|
279 This program is free software; you can redistribute it and/or modify\n\ |
|
280 it under the terms of the GNU General Public License as published by\n\ |
|
281 the Free Software Foundation; either version 2 of the License, or\n\ |
|
282 (at your option) any later version.\n\ |
|
283 \n\ |
|
284 This program is distributed in the hope that it will be useful,\n\ |
|
285 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ |
|
286 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ |
|
287 GNU General Public License for more details.\n\ |
|
288 \n\ |
|
289 You should have received a copy of the GNU General Public License\n\ |
|
290 along with this program. If not, write to the Free Software\n\ |
|
291 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n\ |
|
292 \n"; |
|
293 |
|
294 return retval; |
|
295 } |
|
296 |
|
297 // Execute a shell command. |
|
298 |
1965
|
299 static void |
|
300 cleanup_iprocstream (void *p) |
|
301 { |
3060
|
302 iprocstream *cmd = static_cast<iprocstream *> (p); |
|
303 |
|
304 octave_child_list::remove (cmd->pid ()); |
|
305 |
|
306 delete cmd; |
1965
|
307 } |
|
308 |
2086
|
309 static octave_value_list |
2321
|
310 run_command_and_return_output (const string& cmd_str) |
2083
|
311 { |
2086
|
312 octave_value_list retval; |
2083
|
313 |
|
314 iprocstream *cmd = new iprocstream (cmd_str.c_str ()); |
|
315 |
3060
|
316 if (cmd) |
2083
|
317 { |
3060
|
318 unwind_protect::add (cleanup_iprocstream, cmd); |
|
319 |
|
320 if (*cmd) |
|
321 { |
|
322 ostrstream output_buf; |
2095
|
323 |
3147
|
324 // XXX FIXME XXX -- sometimes, the subprocess hasn't written |
|
325 // anything before we try to read from the procstream. The |
|
326 // kluge below (simply waiting and trying again) is ugly, |
|
327 // but it seems to work, at least most of the time. It |
|
328 // could probably still fail if the subprocess hasn't |
|
329 // started writing after the snooze. Isn't there a better |
|
330 // way? If there is, you should also fix the code for the |
|
331 // ls function in dirfns.cc. |
|
332 |
3060
|
333 char ch; |
3147
|
334 |
|
335 if (cmd->get (ch)) |
|
336 output_buf.put (ch); |
|
337 else |
|
338 { |
|
339 cmd->clear (); |
|
340 |
3308
|
341 octave_usleep (100); |
3147
|
342 } |
|
343 |
3060
|
344 while (cmd->get (ch)) |
|
345 output_buf.put (ch); |
2083
|
346 |
3252
|
347 int cmd_status = cmd->close (); |
2083
|
348 |
3060
|
349 if (WIFEXITED (cmd_status)) |
|
350 cmd_status = WEXITSTATUS (cmd_status); |
|
351 else |
|
352 cmd_status = 127; |
2083
|
353 |
3060
|
354 output_buf << ends; |
2145
|
355 |
3060
|
356 char *msg = output_buf.str (); |
2083
|
357 |
3060
|
358 retval(1) = (double) cmd_status; |
|
359 retval(0) = msg; |
2083
|
360 |
3060
|
361 delete [] msg; |
|
362 } |
|
363 |
|
364 unwind_protect::run (); |
2083
|
365 } |
|
366 else |
|
367 error ("unable to start subprocess for `%s'", cmd_str.c_str ()); |
|
368 |
|
369 return retval; |
|
370 } |
|
371 |
1957
|
372 DEFUN (system, args, nargout, |
3301
|
373 "-*- texinfo -*-\n\ |
|
374 @deftypefn {Built-in Function} {} system (@var{string}, @var{return_output}, @var{type})\n\ |
|
375 Execute a shell command specified by @var{string}. The second\n\ |
|
376 argument is optional. If @var{type} is @code{\"async\"}, the process\n\ |
|
377 is started in the background and the process id of the child process\n\ |
|
378 is returned immediately. Otherwise, the process is started, and\n\ |
|
379 Octave waits until it exits. If @var{type} argument is omitted, a\n\ |
|
380 value of @code{\"sync\"} is assumed.\n\ |
2083
|
381 \n\ |
3301
|
382 If two input arguments are given (the actual value of\n\ |
|
383 @var{return_output} is irrelevant) and the subprocess is started\n\ |
|
384 synchronously, or if @var{system} is called with one input argument and\n\ |
|
385 one or more output arguments, the output from the command is returned.\n\ |
2083
|
386 Otherwise, if the subprocess is executed synchronously, it's output is\n\ |
2321
|
387 sent to the standard output. To send the output of a command executed\n\ |
3301
|
388 with @var{system} through the pager, use a command like\n\ |
2321
|
389 \n\ |
3301
|
390 @example\n\ |
|
391 disp (system (cmd, 1));\n\ |
|
392 @end example\n\ |
2321
|
393 \n\ |
3301
|
394 @noindent\n\ |
2321
|
395 or\n\ |
|
396 \n\ |
3301
|
397 @example\n\ |
|
398 printf (\"%s\n\", system (cmd, 1));\n\ |
|
399 @end example\n\ |
|
400 \n\ |
|
401 The @code{system} function can return two values. The first is any\n\ |
|
402 output from the command that was written to the standard output stream,\n\ |
|
403 and the second is the output status of the command. For example,\n\ |
|
404 \n\ |
|
405 @example\n\ |
|
406 [output, status] = system (\"echo foo; exit 2\");\n\ |
|
407 @end example\n\ |
|
408 \n\ |
|
409 @noindent\n\ |
|
410 will set the variable @code{output} to the string @samp{foo}, and the\n\ |
|
411 variable @code{status} to the integer @samp{2}.\n\ |
|
412 @end deftypefn") |
1683
|
413 { |
2086
|
414 octave_value_list retval; |
1683
|
415 |
|
416 int nargin = args.length (); |
|
417 |
2083
|
418 if (nargin > 0 && nargin < 4) |
1683
|
419 { |
2083
|
420 bool return_output = (nargout > 0 || nargin > 1); |
|
421 |
|
422 string cmd_str = args(0).string_value (); |
|
423 |
|
424 enum exec_type { sync, async }; |
|
425 |
|
426 exec_type type = sync; |
|
427 |
|
428 if (! error_state) |
|
429 { |
|
430 if (nargin > 2) |
|
431 { |
|
432 string type_str = args(2).string_value (); |
1683
|
433 |
2083
|
434 if (! error_state) |
|
435 { |
|
436 if (type_str == "sync") |
|
437 type = sync; |
|
438 else if (type_str == "async") |
|
439 type = async; |
|
440 else |
|
441 error ("system: third arg must be \"sync\" or \"async\""); |
|
442 } |
|
443 else |
|
444 error ("system: third argument must be a string"); |
|
445 } |
|
446 } |
|
447 else |
|
448 error ("system: expecting string as first argument"); |
1683
|
449 |
2083
|
450 if (! error_state) |
|
451 { |
|
452 if (type == async) |
|
453 { |
|
454 pid_t pid = fork (); |
|
455 |
|
456 if (pid < 0) |
|
457 error ("system: fork failed -- can't create child process"); |
|
458 else if (pid == 0) |
|
459 { |
3273
|
460 // XXX FIXME XXX -- should probably replace this |
|
461 // call with something portable. |
|
462 |
|
463 execl ("/bin/sh", "sh", "-c", cmd_str.c_str (), 0); |
|
464 |
|
465 panic_impossible (); |
2083
|
466 } |
|
467 else |
2800
|
468 retval(0) = static_cast<double> (pid); |
2083
|
469 } |
2321
|
470 else if (return_output) |
|
471 retval = run_command_and_return_output (cmd_str); |
2083
|
472 else |
2321
|
473 { |
|
474 int status = system (cmd_str.c_str ()); |
|
475 |
|
476 // The value in status is as returned by waitpid. If |
|
477 // the process exited normally, extract the actual exit |
|
478 // status of the command. Otherwise, return 127 as a |
|
479 // failure code. |
|
480 |
2693
|
481 if (WIFEXITED (status)) |
|
482 status = WEXITSTATUS (status); |
2321
|
483 |
2800
|
484 retval = static_cast<double> (status); |
2321
|
485 } |
2083
|
486 } |
1683
|
487 } |
|
488 else |
2083
|
489 print_usage ("system"); |
1683
|
490 |
|
491 return retval; |
|
492 } |
|
493 |
|
494 DEFALIAS (shell_cmd, system); |
|
495 |
2614
|
496 // XXX FIXME XXX -- this should really be static, but that causes |
|
497 // problems on some systems. |
|
498 SLStack<string> octave_atexit_functions; |
2077
|
499 |
|
500 void |
|
501 do_octave_atexit (void) |
|
502 { |
3216
|
503 static bool deja_vu = false; |
|
504 |
2077
|
505 while (! octave_atexit_functions.empty ()) |
|
506 { |
2086
|
507 octave_value_list fcn = octave_atexit_functions.pop (); |
2077
|
508 |
2942
|
509 feval (fcn, 0); |
3215
|
510 |
|
511 flush_octave_stdout (); |
2077
|
512 } |
3216
|
513 |
|
514 if (! deja_vu) |
|
515 { |
|
516 deja_vu = true; |
|
517 |
|
518 command_editor::restore_terminal_state (); |
|
519 |
|
520 // XXX FIXME XXX -- is this needed? Can it cause any trouble? |
|
521 raw_mode (0); |
|
522 |
|
523 command_history::clean_up_and_save (); |
|
524 |
|
525 close_plot_stream (); |
|
526 |
|
527 close_files (); |
|
528 |
|
529 cleanup_tmp_files (); |
|
530 |
|
531 flush_octave_stdout (); |
|
532 |
|
533 if (!quitting_gracefully && (interactive || forced_interactive)) |
|
534 cout << "\n"; |
|
535 } |
2077
|
536 } |
|
537 |
2162
|
538 DEFUN (atexit, args, , |
3332
|
539 "-*- texinfo -*-\n\ |
|
540 @deftypefn {Built-in Function} {} atexit (@var{fcn})\n\ |
|
541 Register a function to be called when Octave exits. For example,\n\ |
2077
|
542 \n\ |
3332
|
543 @example\n\ |
|
544 @group\n\ |
|
545 function print_flops_at_exit ()\n\ |
|
546 printf (\"\\n%s\\n\", system (\"fortune\"));\n\ |
|
547 fflush (stdout);\n\ |
|
548 endfunction\n\ |
|
549 atexit (\"print_flops_at_exit\");\n\ |
|
550 @end group\n\ |
|
551 @end example\n\ |
|
552 \n\ |
|
553 @noindent\n\ |
|
554 will print a message when Octave exits.\n\ |
3333
|
555 @end deftypefn") |
2077
|
556 { |
2086
|
557 octave_value_list retval; |
2077
|
558 |
|
559 int nargin = args.length (); |
|
560 |
|
561 if (nargin == 1) |
|
562 { |
2475
|
563 #if defined (HAVE_ATEXIT) || defined (HAVE_ON_EXIT) |
2077
|
564 string arg = args(0).string_value (); |
|
565 |
|
566 if (! error_state) |
|
567 octave_atexit_functions.push (arg); |
|
568 else |
|
569 error ("atexit: argument must be a string"); |
2475
|
570 #else |
|
571 gripe_not_supported ("atexit"); |
|
572 #endif |
2077
|
573 } |
|
574 else |
|
575 print_usage ("atexit"); |
|
576 |
|
577 return retval; |
|
578 } |
|
579 |
2689
|
580 DEFUN (octave_config_info, args, , |
3301
|
581 "-*- texinfo -*-\n\ |
|
582 @deftypefn {Built-in Function} {} octave_config_info (@var{option})\n\ |
|
583 Return a structure containing configuration and installation\n\ |
|
584 information for Octave.\n\ |
2689
|
585 \n\ |
3301
|
586 if @var{option} is a string, return the configuration information for the\n\ |
2689
|
587 specified option.\n\ |
|
588 \n\ |
3301
|
589 @end deftypefn") |
2162
|
590 { |
2689
|
591 octave_value retval; |
|
592 |
2696
|
593 #if defined (WITH_DYNAMIC_LINKING) && (defined (WITH_DL) || defined (WITH_SHL)) |
2689
|
594 bool octave_supports_dynamic_linking = true; |
|
595 #else |
|
596 bool octave_supports_dynamic_linking = false; |
|
597 #endif |
|
598 |
2162
|
599 Octave_map m; |
|
600 |
3141
|
601 // XXX FIXME XXX -- should we perform OCTAVE_HOME substitution on these? |
|
602 |
2162
|
603 m ["default_pager"] = DEFAULT_PAGER; |
|
604 m ["prefix"] = OCTAVE_PREFIX; |
|
605 m ["exec_prefix"] = OCTAVE_EXEC_PREFIX; |
|
606 m ["datadir"] = OCTAVE_DATADIR; |
2800
|
607 m ["dld"] = static_cast<double> (octave_supports_dynamic_linking); |
2162
|
608 m ["libdir"] = OCTAVE_LIBDIR; |
|
609 m ["bindir"] = OCTAVE_BINDIR; |
|
610 m ["infodir"] = OCTAVE_INFODIR; |
|
611 m ["fcnfiledir"] = OCTAVE_FCNFILEDIR; |
|
612 m ["localfcnfiledir"] = OCTAVE_LOCALFCNFILEDIR; |
|
613 m ["localstartupfiledir"] = OCTAVE_LOCALSTARTUPFILEDIR; |
|
614 m ["startupfiledir"] = OCTAVE_STARTUPFILEDIR; |
|
615 m ["localfcnfilepath"] = OCTAVE_LOCALFCNFILEPATH; |
|
616 m ["archlibdir"] = OCTAVE_ARCHLIBDIR; |
2439
|
617 m ["localarchlibdir"] = OCTAVE_LOCALARCHLIBDIR; |
2162
|
618 m ["octfiledir"] = OCTAVE_OCTFILEDIR; |
|
619 m ["localoctfilepath"] = OCTAVE_LOCALOCTFILEPATH; |
|
620 m ["fcnfilepath"] = OCTAVE_FCNFILEPATH; |
|
621 m ["imagepath"] = OCTAVE_IMAGEPATH; |
3234
|
622 m ["canonical_host_type"] = CANONICAL_HOST_TYPE; |
2162
|
623 m ["configure_options"] = config_opts; |
|
624 m ["F77"] = F77; |
|
625 m ["FFLAGS"] = FFLAGS; |
|
626 m ["FPICFLAG"] = FPICFLAG; |
|
627 m ["F2C"] = F2C; |
|
628 m ["F2CFLAGS"] = F2CFLAGS; |
|
629 m ["FLIBS"] = FLIBS; |
|
630 m ["CPPFLAGS"] = CPPFLAGS; |
|
631 m ["INCFLAGS"] = INCFLAGS; |
|
632 m ["CC"] = CC " " CC_VERSION; |
|
633 m ["CFLAGS"] = CFLAGS; |
|
634 m ["CPICFLAG"] = CPICFLAG; |
|
635 m ["CXX"] = CXX " " CXX_VERSION; |
|
636 m ["CXXFLAGS"] = CXXFLAGS; |
|
637 m ["CXXPICFLAG"] = CXXPICFLAG; |
|
638 m ["LDFLAGS"] = LDFLAGS; |
|
639 m ["LIBFLAGS"] = LIBFLAGS; |
2675
|
640 m ["RLD_FLAG"] = RLD_FLAG; |
2162
|
641 m ["TERMLIBS"] = TERMLIBS; |
|
642 m ["LIBS"] = LIBS; |
|
643 m ["LEXLIB"] = LEXLIB; |
|
644 m ["LIBPLPLOT"] = LIBPLPLOT; |
|
645 m ["LIBDLFCN"] = LIBDLFCN; |
|
646 m ["DEFS"] = DEFS; |
|
647 |
2689
|
648 int nargin = args.length (); |
|
649 |
|
650 if (nargin == 1) |
|
651 { |
|
652 string arg = args(0).string_value (); |
|
653 |
|
654 if (! error_state) |
|
655 retval = octave_value (m [arg.c_str ()]); |
|
656 } |
|
657 else if (nargin == 0) |
|
658 retval = octave_value (m); |
|
659 else |
|
660 print_usage ("octave_config_info"); |
|
661 |
|
662 return retval; |
2162
|
663 } |
|
664 |
1683
|
665 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE) |
2806
|
666 |
1683
|
667 int debug_new_delete = 0; |
|
668 |
|
669 typedef void (*vfp)(void); |
|
670 extern vfp __new_handler; |
|
671 |
|
672 void * |
|
673 __builtin_new (size_t sz) |
|
674 { |
|
675 void *p; |
|
676 |
|
677 /* malloc (0) is unpredictable; avoid it. */ |
|
678 if (sz == 0) |
|
679 sz = 1; |
2800
|
680 p = malloc (sz); |
1683
|
681 while (p == 0) |
|
682 { |
|
683 (*__new_handler) (); |
2800
|
684 p = malloc (sz); |
1683
|
685 } |
|
686 |
|
687 if (debug_new_delete) |
|
688 cout << "__builtin_new: " << p << endl; |
|
689 |
|
690 return p; |
|
691 } |
|
692 |
|
693 void |
|
694 __builtin_delete (void *ptr) |
|
695 { |
|
696 if (debug_new_delete) |
|
697 cout << "__builtin_delete: " << ptr << endl; |
|
698 |
|
699 if (ptr) |
|
700 free (ptr); |
|
701 } |
2806
|
702 |
1683
|
703 #endif |
|
704 |
2806
|
705 void |
|
706 symbols_of_toplev (void) |
|
707 { |
3141
|
708 DEFCONST (argv, , |
3332
|
709 "-*- texinfo -*-\n\ |
|
710 @defvr {Built-in Variable} argv\n\ |
|
711 The command line arguments passed to Octave are available in this\n\ |
|
712 variable. For example, if you invoked Octave using the command\n\ |
|
713 \n\ |
|
714 @example\n\ |
|
715 octave --no-line-editing --silent\n\ |
|
716 @end example\n\ |
|
717 \n\ |
|
718 @noindent\n\ |
|
719 @code{argv} would be a list of strings with the elements\n\ |
|
720 @code{--no-line-editing} and @code{--silent}.\n\ |
|
721 \n\ |
|
722 If you write an executable Octave script, @code{argv} will contain the\n\ |
|
723 list of arguments passed to the script. @pxref{Executable Octave Programs}.\n\ |
3333
|
724 @end defvr"); |
2806
|
725 |
3020
|
726 DEFCONST (program_invocation_name, |
3141
|
727 octave_env::get_program_invocation_name (), |
3332
|
728 "-*- texinfo -*-\n\ |
|
729 @defvr {Built-in Variable} program_invocation_name\n\ |
|
730 @defvrx {Built-in Variable} program_name\n\ |
|
731 When Octave starts, the value of the built-in variable\n\ |
|
732 @code{program_invocation_name} is automatically set to the name that was\n\ |
|
733 typed at the shell prompt to run Octave, and the value of\n\ |
|
734 @code{program_name} is automatically set to the final component of\n\ |
|
735 @code{program_invocation_name}. For example, if you typed\n\ |
|
736 @samp{@value{OCTAVEHOME}/bin/octave} to start Octave,\n\ |
|
737 @code{program_invocation_name} would have the value\n\ |
|
738 @code{\"@value{OCTAVEHOME}/bin/octave\"}, and @code{program_name} would\n\ |
|
739 have the value @code{\"octave\"}.\n\ |
|
740 \n\ |
|
741 If executing a script from the command line (e.g., @code{octave foo.m})\n\ |
|
742 or using an executable Octave script, the program name is set to the\n\ |
|
743 name of the script. @xref{Executable Octave Programs} for an example of\n\ |
|
744 how to create an executable Octave script.\n\ |
3333
|
745 @end defvr"); |
3020
|
746 |
3141
|
747 DEFCONST (program_name, octave_env::get_program_name (), |
3332
|
748 "-*- texinfo -*-\n\ |
|
749 @defvr {Built-in Variable} program_invocation_name\n\ |
|
750 @defvrx {Built-in Variable} program_name\n\ |
|
751 When Octave starts, the value of the built-in variable\n\ |
|
752 @code{program_invocation_name} is automatically set to the name that was\n\ |
|
753 typed at the shell prompt to run Octave, and the value of\n\ |
|
754 @code{program_name} is automatically set to the final component of\n\ |
|
755 @code{program_invocation_name}. For example, if you typed\n\ |
|
756 @samp{@value{OCTAVEHOME}/bin/octave} to start Octave,\n\ |
|
757 @code{program_invocation_name} would have the value\n\ |
|
758 @code{\"@value{OCTAVEHOME}/bin/octave\"}, and @code{program_name} would\n\ |
|
759 have the value @code{\"octave\"}.\n\ |
|
760 \n\ |
|
761 If executing a script from the command line (e.g., @code{octave foo.m})\n\ |
|
762 or using an executable Octave script, the program name is set to the\n\ |
|
763 name of the script. @xref{Executable Octave Programs} for an example of\n\ |
|
764 how to create an executable Octave script.\n\ |
3333
|
765 @end defvr"); |
|
766 |
2806
|
767 } |
|
768 |
1683
|
769 /* |
|
770 ;;; Local Variables: *** |
|
771 ;;; mode: C++ *** |
|
772 ;;; End: *** |
|
773 */ |