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