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 #include <ctime> |
|
33 |
1728
|
34 #include <string> |
|
35 |
1683
|
36 #include <fstream.h> |
|
37 #include <iostream.h> |
|
38 #include <strstream.h> |
|
39 |
|
40 #ifdef HAVE_UNISTD_H |
2442
|
41 #ifdef HAVE_SYS_TYPES_H |
1683
|
42 #include <sys/types.h> |
2442
|
43 #endif |
1683
|
44 #include <unistd.h> |
|
45 #endif |
|
46 |
2926
|
47 #include "cmd-edit.h" |
|
48 #include "file-ops.h" |
1683
|
49 #include "lo-error.h" |
2370
|
50 #include "lo-mappers.h" |
3020
|
51 #include "oct-env.h" |
1755
|
52 #include "str-vec.h" |
1683
|
53 |
2492
|
54 #include <defaults.h> |
1683
|
55 #include "defun.h" |
|
56 #include "dynamic-ld.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 |
|
105 cout << "\n"; |
2016
|
106 |
|
107 octave_restore_signal_mask (); |
1907
|
108 } |
|
109 |
3020
|
110 can_interrupt = true; |
1907
|
111 |
2554
|
112 octave_catch_interrupts (); |
1907
|
113 |
|
114 // The big loop. |
|
115 |
|
116 int retval; |
|
117 do |
|
118 { |
|
119 curr_sym_tab = top_level_sym_tab; |
|
120 |
|
121 reset_parser (); |
|
122 |
|
123 retval = yyparse (); |
|
124 |
|
125 if (retval == 0 && global_command) |
|
126 { |
2898
|
127 global_command->eval (); |
2299
|
128 |
1907
|
129 delete global_command; |
2299
|
130 |
2620
|
131 global_command = 0; |
|
132 |
|
133 if (! (interactive || forced_interactive)) |
|
134 { |
2985
|
135 bool quit = (tree_return_command::returning |
|
136 || tree_break_command::breaking); |
2620
|
137 |
2985
|
138 if (tree_return_command::returning) |
|
139 tree_return_command::returning = 0; |
2620
|
140 |
2985
|
141 if (tree_break_command::breaking) |
|
142 tree_break_command::breaking--; |
2620
|
143 |
|
144 if (quit) |
|
145 break; |
|
146 } |
|
147 |
|
148 if (error_state) |
|
149 { |
|
150 if (! (interactive || forced_interactive)) |
|
151 break; |
|
152 } |
2299
|
153 else |
2620
|
154 { |
|
155 if (octave_completion_matches_called) |
|
156 octave_completion_matches_called = false; |
|
157 else |
2973
|
158 command_editor::increment_current_command_number (); |
2620
|
159 } |
1907
|
160 } |
|
161 } |
|
162 while (retval == 0); |
|
163 |
|
164 return retval; |
|
165 } |
|
166 |
1683
|
167 // Fix up things before exiting. |
|
168 |
|
169 void |
3162
|
170 clean_up_and_exit (int retval) |
|
171 { |
3216
|
172 do_octave_atexit (); |
1683
|
173 |
3162
|
174 exit (retval == EOF ? 0 : retval); |
1683
|
175 } |
|
176 |
1957
|
177 DEFUN_TEXT (casesen, args, , |
1683
|
178 "casesen [on|off]") |
|
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, |
1683
|
200 "computer ():\n\ |
|
201 \n\ |
|
202 Have Octave ask the system, \"What kind of computer are you?\"") |
|
203 { |
2086
|
204 octave_value_list retval; |
1683
|
205 |
|
206 int nargin = args.length (); |
|
207 |
|
208 if (nargin != 0) |
|
209 warning ("computer: ignoring extra arguments"); |
|
210 |
2095
|
211 string msg; |
1683
|
212 |
3234
|
213 if (strcmp (CANONICAL_HOST_TYPE, "unknown") == 0) |
2095
|
214 msg = "Hi Dave, I'm a HAL-9000"; |
1683
|
215 else |
3234
|
216 msg = CANONICAL_HOST_TYPE; |
1683
|
217 |
|
218 if (nargout == 0) |
2095
|
219 octave_stdout << msg << "\n"; |
1683
|
220 else |
2095
|
221 retval = msg; |
1683
|
222 |
|
223 return retval; |
|
224 } |
|
225 |
3180
|
226 DEFUN (quit, args, nargout, |
2068
|
227 "quit (STATUS): exit Octave gracefully, returning STATUS to the system.\n\ |
|
228 \n\ |
|
229 STATUS should be an integer value. If STATUS is missing, 0 is assumed.") |
1683
|
230 { |
2086
|
231 octave_value_list retval; |
2068
|
232 |
3180
|
233 if (nargout == 0) |
2068
|
234 { |
3180
|
235 int exit_status = 0; |
|
236 |
|
237 quitting_gracefully = true; |
1683
|
238 |
3180
|
239 if (args.length () > 0) |
|
240 { |
3202
|
241 int tmp = args(0).nint_value (); |
1683
|
242 |
3202
|
243 if (! error_state) |
|
244 exit_status = tmp; |
3180
|
245 } |
|
246 |
|
247 clean_up_and_exit (exit_status); |
2068
|
248 } |
3180
|
249 else |
|
250 error ("quit: invalid number of output arguments"); |
2068
|
251 |
1683
|
252 return retval; |
|
253 } |
|
254 |
|
255 DEFALIAS (exit, quit); |
|
256 |
1957
|
257 DEFUN (warranty, , , |
1683
|
258 "warranty (): describe copying conditions") |
|
259 { |
2086
|
260 octave_value_list retval; |
1683
|
261 |
2095
|
262 octave_stdout << "\n" OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\n\ |
1683
|
263 This program is free software; you can redistribute it and/or modify\n\ |
|
264 it under the terms of the GNU General Public License as published by\n\ |
|
265 the Free Software Foundation; either version 2 of the License, or\n\ |
|
266 (at your option) any later version.\n\ |
|
267 \n\ |
|
268 This program is distributed in the hope that it will be useful,\n\ |
|
269 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ |
|
270 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ |
|
271 GNU General Public License for more details.\n\ |
|
272 \n\ |
|
273 You should have received a copy of the GNU General Public License\n\ |
|
274 along with this program. If not, write to the Free Software\n\ |
|
275 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n\ |
|
276 \n"; |
|
277 |
|
278 return retval; |
|
279 } |
|
280 |
|
281 // Execute a shell command. |
|
282 |
3060
|
283 static int cmd_status = 0; |
|
284 |
|
285 static void |
|
286 cmd_death_handler (pid_t, int status) |
|
287 { |
|
288 cmd_status = status; |
|
289 } |
|
290 |
1965
|
291 static void |
|
292 cleanup_iprocstream (void *p) |
|
293 { |
3060
|
294 iprocstream *cmd = static_cast<iprocstream *> (p); |
|
295 |
|
296 octave_child_list::remove (cmd->pid ()); |
|
297 |
|
298 delete cmd; |
1965
|
299 } |
|
300 |
2086
|
301 static octave_value_list |
2321
|
302 run_command_and_return_output (const string& cmd_str) |
2083
|
303 { |
2086
|
304 octave_value_list retval; |
2083
|
305 |
|
306 iprocstream *cmd = new iprocstream (cmd_str.c_str ()); |
|
307 |
3060
|
308 cmd_status = -1; |
2083
|
309 |
3060
|
310 if (cmd) |
2083
|
311 { |
3060
|
312 octave_child_list::insert (cmd->pid (), cmd_death_handler); |
|
313 |
|
314 unwind_protect::add (cleanup_iprocstream, cmd); |
|
315 |
|
316 if (*cmd) |
|
317 { |
|
318 ostrstream output_buf; |
2095
|
319 |
3147
|
320 // XXX FIXME XXX -- sometimes, the subprocess hasn't written |
|
321 // anything before we try to read from the procstream. The |
|
322 // kluge below (simply waiting and trying again) is ugly, |
|
323 // but it seems to work, at least most of the time. It |
|
324 // could probably still fail if the subprocess hasn't |
|
325 // started writing after the snooze. Isn't there a better |
|
326 // way? If there is, you should also fix the code for the |
|
327 // ls function in dirfns.cc. |
|
328 |
3060
|
329 char ch; |
3147
|
330 |
|
331 if (cmd->get (ch)) |
|
332 output_buf.put (ch); |
|
333 else |
|
334 { |
|
335 cmd->clear (); |
|
336 |
|
337 #if defined (HAVE_USLEEP) |
|
338 usleep (100); |
|
339 #else |
|
340 sleep (1); |
|
341 #endif |
|
342 } |
|
343 |
3060
|
344 while (cmd->get (ch)) |
|
345 output_buf.put (ch); |
2083
|
346 |
3060
|
347 cmd->close (); |
|
348 |
|
349 // One way or another, cmd_death_handler should be called |
|
350 // when the process exits, and it will save the exit status |
|
351 // of the command in cmd_status. |
2083
|
352 |
3060
|
353 // The value in cmd_status is as returned by waitpid. If |
|
354 // the process exited normally, extract the actual exit |
|
355 // status of the command. Otherwise, return 127 as a |
|
356 // failure code. |
2083
|
357 |
3060
|
358 if (WIFEXITED (cmd_status)) |
|
359 cmd_status = WEXITSTATUS (cmd_status); |
|
360 else |
|
361 cmd_status = 127; |
2083
|
362 |
3060
|
363 output_buf << ends; |
2145
|
364 |
3060
|
365 char *msg = output_buf.str (); |
2083
|
366 |
3060
|
367 retval(1) = (double) cmd_status; |
|
368 retval(0) = msg; |
2083
|
369 |
3060
|
370 delete [] msg; |
|
371 } |
|
372 |
|
373 unwind_protect::run (); |
2083
|
374 } |
|
375 else |
|
376 error ("unable to start subprocess for `%s'", cmd_str.c_str ()); |
|
377 |
|
378 return retval; |
|
379 } |
|
380 |
1957
|
381 DEFUN (system, args, nargout, |
2083
|
382 "system (STRING [, RETURN_OUTPUT] [, TYPE])\n\ |
|
383 \n\ |
|
384 Execute the shell command specified by STRING.\n\ |
|
385 \n\ |
|
386 If TYPE is \"async\", the process is started in the background and the\n\ |
|
387 pid of the child proces is returned immediately. Otherwise, the\n\ |
|
388 process is started, and Octave waits until it exits. If TYPE argument\n\ |
|
389 is omitted, a value of \"sync\" is assumed.\n\ |
|
390 \n\ |
|
391 If NARGIN == 2 (the actual value of RETURN_OUTPUT is irrelevant) and\n\ |
|
392 the subprocess is started synchronously, or if system() is called with\n\ |
|
393 NARGIN == 1 and NARGOUT > 0, the output from the command is returned.\n\ |
|
394 Otherwise, if the subprocess is executed synchronously, it's output is\n\ |
2321
|
395 sent to the standard output. To send the output of a command executed\n\ |
|
396 with system() through the pager, use a command like\n\ |
|
397 \n\ |
|
398 disp (system (CMD, 1));\n\ |
|
399 \n\ |
|
400 or\n\ |
|
401 \n\ |
2322
|
402 printf (\"%s\\n\", system (CMD, 1));") |
1683
|
403 { |
2086
|
404 octave_value_list retval; |
1683
|
405 |
|
406 int nargin = args.length (); |
|
407 |
2083
|
408 if (nargin > 0 && nargin < 4) |
1683
|
409 { |
2083
|
410 bool return_output = (nargout > 0 || nargin > 1); |
|
411 |
|
412 string cmd_str = args(0).string_value (); |
|
413 |
|
414 enum exec_type { sync, async }; |
|
415 |
|
416 exec_type type = sync; |
|
417 |
|
418 if (! error_state) |
|
419 { |
|
420 if (nargin > 2) |
|
421 { |
|
422 string type_str = args(2).string_value (); |
1683
|
423 |
2083
|
424 if (! error_state) |
|
425 { |
|
426 if (type_str == "sync") |
|
427 type = sync; |
|
428 else if (type_str == "async") |
|
429 type = async; |
|
430 else |
|
431 error ("system: third arg must be \"sync\" or \"async\""); |
|
432 } |
|
433 else |
|
434 error ("system: third argument must be a string"); |
|
435 } |
|
436 } |
|
437 else |
|
438 error ("system: expecting string as first argument"); |
1683
|
439 |
2083
|
440 if (! error_state) |
|
441 { |
|
442 if (type == async) |
|
443 { |
|
444 pid_t pid = fork (); |
|
445 |
|
446 if (pid < 0) |
|
447 error ("system: fork failed -- can't create child process"); |
|
448 else if (pid == 0) |
|
449 { |
|
450 system (cmd_str.c_str ()); |
|
451 exit (0); |
|
452 retval(0) = 0.0; |
|
453 } |
|
454 else |
2800
|
455 retval(0) = static_cast<double> (pid); |
2083
|
456 } |
2321
|
457 else if (return_output) |
|
458 retval = run_command_and_return_output (cmd_str); |
2083
|
459 else |
2321
|
460 { |
|
461 int status = system (cmd_str.c_str ()); |
|
462 |
|
463 // The value in status is as returned by waitpid. If |
|
464 // the process exited normally, extract the actual exit |
|
465 // status of the command. Otherwise, return 127 as a |
|
466 // failure code. |
|
467 |
2693
|
468 if (WIFEXITED (status)) |
|
469 status = WEXITSTATUS (status); |
2321
|
470 |
2800
|
471 retval = static_cast<double> (status); |
2321
|
472 } |
2083
|
473 } |
1683
|
474 } |
|
475 else |
2083
|
476 print_usage ("system"); |
1683
|
477 |
|
478 return retval; |
|
479 } |
|
480 |
|
481 DEFALIAS (shell_cmd, system); |
|
482 |
2614
|
483 // XXX FIXME XXX -- this should really be static, but that causes |
|
484 // problems on some systems. |
|
485 SLStack<string> octave_atexit_functions; |
2077
|
486 |
|
487 void |
|
488 do_octave_atexit (void) |
|
489 { |
3216
|
490 static bool deja_vu = false; |
|
491 |
2077
|
492 while (! octave_atexit_functions.empty ()) |
|
493 { |
2086
|
494 octave_value_list fcn = octave_atexit_functions.pop (); |
2077
|
495 |
2942
|
496 feval (fcn, 0); |
3215
|
497 |
|
498 flush_octave_stdout (); |
2077
|
499 } |
3216
|
500 |
|
501 if (! deja_vu) |
|
502 { |
|
503 deja_vu = true; |
|
504 |
|
505 command_editor::restore_terminal_state (); |
|
506 |
|
507 // XXX FIXME XXX -- is this needed? Can it cause any trouble? |
|
508 raw_mode (0); |
|
509 |
|
510 command_history::clean_up_and_save (); |
|
511 |
|
512 close_plot_stream (); |
|
513 |
|
514 close_files (); |
|
515 |
|
516 cleanup_tmp_files (); |
|
517 |
|
518 flush_octave_stdout (); |
|
519 |
|
520 if (!quitting_gracefully && (interactive || forced_interactive)) |
|
521 cout << "\n"; |
|
522 } |
2077
|
523 } |
|
524 |
2162
|
525 DEFUN (atexit, args, , |
2077
|
526 "atexit (NAME): register NAME as a function to call when Octave exits\n\ |
|
527 \n\ |
2802
|
528 Functions are called with no arguments in the reverse of the order in\n\ |
2077
|
529 which they were registered with atexit()") |
|
530 { |
2086
|
531 octave_value_list retval; |
2077
|
532 |
|
533 int nargin = args.length (); |
|
534 |
|
535 if (nargin == 1) |
|
536 { |
2475
|
537 #if defined (HAVE_ATEXIT) || defined (HAVE_ON_EXIT) |
2077
|
538 string arg = args(0).string_value (); |
|
539 |
|
540 if (! error_state) |
|
541 octave_atexit_functions.push (arg); |
|
542 else |
|
543 error ("atexit: argument must be a string"); |
2475
|
544 #else |
|
545 gripe_not_supported ("atexit"); |
|
546 #endif |
2077
|
547 } |
|
548 else |
|
549 print_usage ("atexit"); |
|
550 |
|
551 return retval; |
|
552 } |
|
553 |
2689
|
554 DEFUN (octave_config_info, args, , |
|
555 "octave_config_info (OPTION)\n\ |
|
556 \n\ |
|
557 If OPTION is a string, return the configuration information for the\n\ |
|
558 specified option.\n\ |
|
559 \n\ |
|
560 With no arguments, return a structure containing configuration\n\ |
|
561 information.") |
2162
|
562 { |
2689
|
563 octave_value retval; |
|
564 |
2696
|
565 #if defined (WITH_DYNAMIC_LINKING) && (defined (WITH_DL) || defined (WITH_SHL)) |
2689
|
566 bool octave_supports_dynamic_linking = true; |
|
567 #else |
|
568 bool octave_supports_dynamic_linking = false; |
|
569 #endif |
|
570 |
2162
|
571 Octave_map m; |
|
572 |
3141
|
573 // XXX FIXME XXX -- should we perform OCTAVE_HOME substitution on these? |
|
574 |
2162
|
575 m ["default_pager"] = DEFAULT_PAGER; |
|
576 m ["prefix"] = OCTAVE_PREFIX; |
|
577 m ["exec_prefix"] = OCTAVE_EXEC_PREFIX; |
|
578 m ["datadir"] = OCTAVE_DATADIR; |
2800
|
579 m ["dld"] = static_cast<double> (octave_supports_dynamic_linking); |
2162
|
580 m ["libdir"] = OCTAVE_LIBDIR; |
|
581 m ["bindir"] = OCTAVE_BINDIR; |
|
582 m ["infodir"] = OCTAVE_INFODIR; |
|
583 m ["fcnfiledir"] = OCTAVE_FCNFILEDIR; |
|
584 m ["localfcnfiledir"] = OCTAVE_LOCALFCNFILEDIR; |
|
585 m ["localstartupfiledir"] = OCTAVE_LOCALSTARTUPFILEDIR; |
|
586 m ["startupfiledir"] = OCTAVE_STARTUPFILEDIR; |
|
587 m ["localfcnfilepath"] = OCTAVE_LOCALFCNFILEPATH; |
|
588 m ["archlibdir"] = OCTAVE_ARCHLIBDIR; |
2439
|
589 m ["localarchlibdir"] = OCTAVE_LOCALARCHLIBDIR; |
2162
|
590 m ["octfiledir"] = OCTAVE_OCTFILEDIR; |
|
591 m ["localoctfilepath"] = OCTAVE_LOCALOCTFILEPATH; |
|
592 m ["fcnfilepath"] = OCTAVE_FCNFILEPATH; |
|
593 m ["imagepath"] = OCTAVE_IMAGEPATH; |
3234
|
594 m ["canonical_host_type"] = CANONICAL_HOST_TYPE; |
2162
|
595 m ["configure_options"] = config_opts; |
|
596 m ["F77"] = F77; |
|
597 m ["FFLAGS"] = FFLAGS; |
|
598 m ["FPICFLAG"] = FPICFLAG; |
|
599 m ["F2C"] = F2C; |
|
600 m ["F2CFLAGS"] = F2CFLAGS; |
|
601 m ["FLIBS"] = FLIBS; |
|
602 m ["CPPFLAGS"] = CPPFLAGS; |
|
603 m ["INCFLAGS"] = INCFLAGS; |
|
604 m ["CC"] = CC " " CC_VERSION; |
|
605 m ["CFLAGS"] = CFLAGS; |
|
606 m ["CPICFLAG"] = CPICFLAG; |
|
607 m ["CXX"] = CXX " " CXX_VERSION; |
|
608 m ["CXXFLAGS"] = CXXFLAGS; |
|
609 m ["CXXPICFLAG"] = CXXPICFLAG; |
|
610 m ["LDFLAGS"] = LDFLAGS; |
|
611 m ["LIBFLAGS"] = LIBFLAGS; |
2675
|
612 m ["RLD_FLAG"] = RLD_FLAG; |
2162
|
613 m ["TERMLIBS"] = TERMLIBS; |
|
614 m ["LIBS"] = LIBS; |
|
615 m ["LEXLIB"] = LEXLIB; |
|
616 m ["LIBPLPLOT"] = LIBPLPLOT; |
|
617 m ["LIBDLFCN"] = LIBDLFCN; |
|
618 m ["DEFS"] = DEFS; |
|
619 |
2689
|
620 int nargin = args.length (); |
|
621 |
|
622 if (nargin == 1) |
|
623 { |
|
624 string arg = args(0).string_value (); |
|
625 |
|
626 if (! error_state) |
|
627 retval = octave_value (m [arg.c_str ()]); |
|
628 } |
|
629 else if (nargin == 0) |
|
630 retval = octave_value (m); |
|
631 else |
|
632 print_usage ("octave_config_info"); |
|
633 |
|
634 return retval; |
2162
|
635 } |
|
636 |
1683
|
637 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE) |
2806
|
638 |
1683
|
639 int debug_new_delete = 0; |
|
640 |
|
641 typedef void (*vfp)(void); |
|
642 extern vfp __new_handler; |
|
643 |
|
644 void * |
|
645 __builtin_new (size_t sz) |
|
646 { |
|
647 void *p; |
|
648 |
|
649 /* malloc (0) is unpredictable; avoid it. */ |
|
650 if (sz == 0) |
|
651 sz = 1; |
2800
|
652 p = malloc (sz); |
1683
|
653 while (p == 0) |
|
654 { |
|
655 (*__new_handler) (); |
2800
|
656 p = malloc (sz); |
1683
|
657 } |
|
658 |
|
659 if (debug_new_delete) |
|
660 cout << "__builtin_new: " << p << endl; |
|
661 |
|
662 return p; |
|
663 } |
|
664 |
|
665 void |
|
666 __builtin_delete (void *ptr) |
|
667 { |
|
668 if (debug_new_delete) |
|
669 cout << "__builtin_delete: " << ptr << endl; |
|
670 |
|
671 if (ptr) |
|
672 free (ptr); |
|
673 } |
2806
|
674 |
1683
|
675 #endif |
|
676 |
2806
|
677 void |
|
678 symbols_of_toplev (void) |
|
679 { |
3141
|
680 DEFCONST (argv, , |
3020
|
681 "the command line arguments this program was invoked with"); |
2806
|
682 |
3020
|
683 DEFCONST (program_invocation_name, |
3141
|
684 octave_env::get_program_invocation_name (), |
3020
|
685 "the full name of the current program or script, including the\n\ |
|
686 directory specification"); |
|
687 |
3141
|
688 DEFCONST (program_name, octave_env::get_program_name (), |
3020
|
689 "the name of the current program or script"); |
2806
|
690 } |
|
691 |
1683
|
692 /* |
|
693 ;;; Local Variables: *** |
|
694 ;;; mode: C++ *** |
|
695 ;;; End: *** |
|
696 */ |