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