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_for_exit (void) |
1683
|
171 { |
2926
|
172 command_editor::restore_terminal_state (); |
|
173 |
|
174 // XXX FIXME XXX -- is this needed? Can it cause any trouble? |
1683
|
175 raw_mode (0); |
|
176 |
2926
|
177 command_history::clean_up_and_save (); |
1683
|
178 |
|
179 close_plot_stream (); |
|
180 |
|
181 close_files (); |
|
182 |
|
183 cleanup_tmp_files (); |
|
184 |
|
185 if (!quitting_gracefully && (interactive || forced_interactive)) |
|
186 cout << "\n"; |
3162
|
187 } |
1683
|
188 |
3162
|
189 void |
|
190 clean_up_and_exit (int retval) |
|
191 { |
|
192 clean_up_for_exit (); |
1683
|
193 |
3162
|
194 exit (retval == EOF ? 0 : retval); |
1683
|
195 } |
|
196 |
1957
|
197 DEFUN_TEXT (casesen, args, , |
1683
|
198 "casesen [on|off]") |
|
199 { |
2086
|
200 octave_value_list retval; |
1683
|
201 |
1755
|
202 int argc = args.length () + 1; |
|
203 |
1965
|
204 string_vector argv = args.make_argv ("casesen"); |
1683
|
205 |
1755
|
206 if (error_state) |
|
207 return retval; |
|
208 |
|
209 if (argc == 1 || (argc > 1 && argv[1] == "off")) |
1683
|
210 warning ("casesen: sorry, Octave is always case sensitive"); |
1755
|
211 else if (argc > 1 && argv[1] == "on") |
1683
|
212 ; // ok. |
|
213 else |
|
214 print_usage ("casesen"); |
|
215 |
|
216 return retval; |
|
217 } |
|
218 |
1957
|
219 DEFUN (computer, args, nargout, |
1683
|
220 "computer ():\n\ |
|
221 \n\ |
|
222 Have Octave ask the system, \"What kind of computer are you?\"") |
|
223 { |
2086
|
224 octave_value_list retval; |
1683
|
225 |
|
226 int nargin = args.length (); |
|
227 |
|
228 if (nargin != 0) |
|
229 warning ("computer: ignoring extra arguments"); |
|
230 |
2095
|
231 string msg; |
1683
|
232 |
|
233 if (strcmp (TARGET_HOST_TYPE, "unknown") == 0) |
2095
|
234 msg = "Hi Dave, I'm a HAL-9000"; |
1683
|
235 else |
2095
|
236 msg = TARGET_HOST_TYPE; |
1683
|
237 |
|
238 if (nargout == 0) |
2095
|
239 octave_stdout << msg << "\n"; |
1683
|
240 else |
2095
|
241 retval = msg; |
1683
|
242 |
|
243 return retval; |
|
244 } |
|
245 |
2068
|
246 DEFUN (quit, args, , |
|
247 "quit (STATUS): exit Octave gracefully, returning STATUS to the system.\n\ |
|
248 \n\ |
|
249 STATUS should be an integer value. If STATUS is missing, 0 is assumed.") |
1683
|
250 { |
2086
|
251 octave_value_list retval; |
2068
|
252 |
|
253 int exit_status = 0; |
|
254 |
3020
|
255 quitting_gracefully = true; |
2068
|
256 |
1683
|
257 int nargin = args.length (); |
|
258 |
|
259 if (nargin > 0) |
2068
|
260 { |
|
261 // XXX FIXME XXX -- need a safe uniform way to do this. |
1683
|
262 |
2068
|
263 double tmp = args(0).double_value (); |
1683
|
264 |
2068
|
265 if (! error_state && ! xisnan (tmp)) |
|
266 exit_status = NINT (tmp); |
|
267 } |
|
268 |
|
269 clean_up_and_exit (exit_status); |
|
270 |
1683
|
271 return retval; |
|
272 } |
|
273 |
|
274 DEFALIAS (exit, quit); |
|
275 |
1957
|
276 DEFUN (warranty, , , |
1683
|
277 "warranty (): describe copying conditions") |
|
278 { |
2086
|
279 octave_value_list retval; |
1683
|
280 |
2095
|
281 octave_stdout << "\n" OCTAVE_NAME_VERSION_AND_COPYRIGHT "\n\n\ |
1683
|
282 This program is free software; you can redistribute it and/or modify\n\ |
|
283 it under the terms of the GNU General Public License as published by\n\ |
|
284 the Free Software Foundation; either version 2 of the License, or\n\ |
|
285 (at your option) any later version.\n\ |
|
286 \n\ |
|
287 This program is distributed in the hope that it will be useful,\n\ |
|
288 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\ |
|
289 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\ |
|
290 GNU General Public License for more details.\n\ |
|
291 \n\ |
|
292 You should have received a copy of the GNU General Public License\n\ |
|
293 along with this program. If not, write to the Free Software\n\ |
|
294 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n\ |
|
295 \n"; |
|
296 |
|
297 return retval; |
|
298 } |
|
299 |
|
300 // Execute a shell command. |
|
301 |
3060
|
302 static int cmd_status = 0; |
|
303 |
|
304 static void |
|
305 cmd_death_handler (pid_t, int status) |
|
306 { |
|
307 cmd_status = status; |
|
308 } |
|
309 |
1965
|
310 static void |
|
311 cleanup_iprocstream (void *p) |
|
312 { |
3060
|
313 iprocstream *cmd = static_cast<iprocstream *> (p); |
|
314 |
|
315 octave_child_list::remove (cmd->pid ()); |
|
316 |
|
317 delete cmd; |
1965
|
318 } |
|
319 |
2086
|
320 static octave_value_list |
2321
|
321 run_command_and_return_output (const string& cmd_str) |
2083
|
322 { |
2086
|
323 octave_value_list retval; |
2083
|
324 |
|
325 iprocstream *cmd = new iprocstream (cmd_str.c_str ()); |
|
326 |
3060
|
327 cmd_status = -1; |
2083
|
328 |
3060
|
329 if (cmd) |
2083
|
330 { |
3060
|
331 octave_child_list::insert (cmd->pid (), cmd_death_handler); |
|
332 |
|
333 unwind_protect::add (cleanup_iprocstream, cmd); |
|
334 |
|
335 if (*cmd) |
|
336 { |
|
337 ostrstream output_buf; |
2095
|
338 |
3147
|
339 // XXX FIXME XXX -- sometimes, the subprocess hasn't written |
|
340 // anything before we try to read from the procstream. The |
|
341 // kluge below (simply waiting and trying again) is ugly, |
|
342 // but it seems to work, at least most of the time. It |
|
343 // could probably still fail if the subprocess hasn't |
|
344 // started writing after the snooze. Isn't there a better |
|
345 // way? If there is, you should also fix the code for the |
|
346 // ls function in dirfns.cc. |
|
347 |
3060
|
348 char ch; |
3147
|
349 |
|
350 if (cmd->get (ch)) |
|
351 output_buf.put (ch); |
|
352 else |
|
353 { |
|
354 cmd->clear (); |
|
355 |
|
356 #if defined (HAVE_USLEEP) |
|
357 usleep (100); |
|
358 #else |
|
359 sleep (1); |
|
360 #endif |
|
361 } |
|
362 |
3060
|
363 while (cmd->get (ch)) |
|
364 output_buf.put (ch); |
2083
|
365 |
3060
|
366 cmd->close (); |
|
367 |
|
368 // One way or another, cmd_death_handler should be called |
|
369 // when the process exits, and it will save the exit status |
|
370 // of the command in cmd_status. |
2083
|
371 |
3060
|
372 // The value in cmd_status is as returned by waitpid. If |
|
373 // the process exited normally, extract the actual exit |
|
374 // status of the command. Otherwise, return 127 as a |
|
375 // failure code. |
2083
|
376 |
3060
|
377 if (WIFEXITED (cmd_status)) |
|
378 cmd_status = WEXITSTATUS (cmd_status); |
|
379 else |
|
380 cmd_status = 127; |
2083
|
381 |
3060
|
382 output_buf << ends; |
2145
|
383 |
3060
|
384 char *msg = output_buf.str (); |
2083
|
385 |
3060
|
386 retval(1) = (double) cmd_status; |
|
387 retval(0) = msg; |
2083
|
388 |
3060
|
389 delete [] msg; |
|
390 } |
|
391 |
|
392 unwind_protect::run (); |
2083
|
393 } |
|
394 else |
|
395 error ("unable to start subprocess for `%s'", cmd_str.c_str ()); |
|
396 |
|
397 return retval; |
|
398 } |
|
399 |
1957
|
400 DEFUN (system, args, nargout, |
2083
|
401 "system (STRING [, RETURN_OUTPUT] [, TYPE])\n\ |
|
402 \n\ |
|
403 Execute the shell command specified by STRING.\n\ |
|
404 \n\ |
|
405 If TYPE is \"async\", the process is started in the background and the\n\ |
|
406 pid of the child proces is returned immediately. Otherwise, the\n\ |
|
407 process is started, and Octave waits until it exits. If TYPE argument\n\ |
|
408 is omitted, a value of \"sync\" is assumed.\n\ |
|
409 \n\ |
|
410 If NARGIN == 2 (the actual value of RETURN_OUTPUT is irrelevant) and\n\ |
|
411 the subprocess is started synchronously, or if system() is called with\n\ |
|
412 NARGIN == 1 and NARGOUT > 0, the output from the command is returned.\n\ |
|
413 Otherwise, if the subprocess is executed synchronously, it's output is\n\ |
2321
|
414 sent to the standard output. To send the output of a command executed\n\ |
|
415 with system() through the pager, use a command like\n\ |
|
416 \n\ |
|
417 disp (system (CMD, 1));\n\ |
|
418 \n\ |
|
419 or\n\ |
|
420 \n\ |
2322
|
421 printf (\"%s\\n\", system (CMD, 1));") |
1683
|
422 { |
2086
|
423 octave_value_list retval; |
1683
|
424 |
|
425 int nargin = args.length (); |
|
426 |
2083
|
427 if (nargin > 0 && nargin < 4) |
1683
|
428 { |
2083
|
429 bool return_output = (nargout > 0 || nargin > 1); |
|
430 |
|
431 string cmd_str = args(0).string_value (); |
|
432 |
|
433 enum exec_type { sync, async }; |
|
434 |
|
435 exec_type type = sync; |
|
436 |
|
437 if (! error_state) |
|
438 { |
|
439 if (nargin > 2) |
|
440 { |
|
441 string type_str = args(2).string_value (); |
1683
|
442 |
2083
|
443 if (! error_state) |
|
444 { |
|
445 if (type_str == "sync") |
|
446 type = sync; |
|
447 else if (type_str == "async") |
|
448 type = async; |
|
449 else |
|
450 error ("system: third arg must be \"sync\" or \"async\""); |
|
451 } |
|
452 else |
|
453 error ("system: third argument must be a string"); |
|
454 } |
|
455 } |
|
456 else |
|
457 error ("system: expecting string as first argument"); |
1683
|
458 |
2083
|
459 if (! error_state) |
|
460 { |
|
461 if (type == async) |
|
462 { |
|
463 pid_t pid = fork (); |
|
464 |
|
465 if (pid < 0) |
|
466 error ("system: fork failed -- can't create child process"); |
|
467 else if (pid == 0) |
|
468 { |
|
469 system (cmd_str.c_str ()); |
|
470 exit (0); |
|
471 retval(0) = 0.0; |
|
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 { |
|
509 while (! octave_atexit_functions.empty ()) |
|
510 { |
2086
|
511 octave_value_list fcn = octave_atexit_functions.pop (); |
2077
|
512 |
2942
|
513 feval (fcn, 0); |
2077
|
514 } |
|
515 } |
|
516 |
2162
|
517 DEFUN (atexit, args, , |
2077
|
518 "atexit (NAME): register NAME as a function to call when Octave exits\n\ |
|
519 \n\ |
2802
|
520 Functions are called with no arguments in the reverse of the order in\n\ |
2077
|
521 which they were registered with atexit()") |
|
522 { |
2086
|
523 octave_value_list retval; |
2077
|
524 |
|
525 int nargin = args.length (); |
|
526 |
|
527 if (nargin == 1) |
|
528 { |
2475
|
529 #if defined (HAVE_ATEXIT) || defined (HAVE_ON_EXIT) |
2077
|
530 string arg = args(0).string_value (); |
|
531 |
|
532 if (! error_state) |
|
533 octave_atexit_functions.push (arg); |
|
534 else |
|
535 error ("atexit: argument must be a string"); |
2475
|
536 #else |
|
537 gripe_not_supported ("atexit"); |
|
538 #endif |
2077
|
539 } |
|
540 else |
|
541 print_usage ("atexit"); |
|
542 |
|
543 return retval; |
|
544 } |
|
545 |
2689
|
546 DEFUN (octave_config_info, args, , |
|
547 "octave_config_info (OPTION)\n\ |
|
548 \n\ |
|
549 If OPTION is a string, return the configuration information for the\n\ |
|
550 specified option.\n\ |
|
551 \n\ |
|
552 With no arguments, return a structure containing configuration\n\ |
|
553 information.") |
2162
|
554 { |
2689
|
555 octave_value retval; |
|
556 |
2696
|
557 #if defined (WITH_DYNAMIC_LINKING) && (defined (WITH_DL) || defined (WITH_SHL)) |
2689
|
558 bool octave_supports_dynamic_linking = true; |
|
559 #else |
|
560 bool octave_supports_dynamic_linking = false; |
|
561 #endif |
|
562 |
2162
|
563 Octave_map m; |
|
564 |
3141
|
565 // XXX FIXME XXX -- should we perform OCTAVE_HOME substitution on these? |
|
566 |
2162
|
567 m ["default_pager"] = DEFAULT_PAGER; |
|
568 m ["prefix"] = OCTAVE_PREFIX; |
|
569 m ["exec_prefix"] = OCTAVE_EXEC_PREFIX; |
|
570 m ["datadir"] = OCTAVE_DATADIR; |
2800
|
571 m ["dld"] = static_cast<double> (octave_supports_dynamic_linking); |
2162
|
572 m ["libdir"] = OCTAVE_LIBDIR; |
|
573 m ["bindir"] = OCTAVE_BINDIR; |
|
574 m ["infodir"] = OCTAVE_INFODIR; |
|
575 m ["fcnfiledir"] = OCTAVE_FCNFILEDIR; |
|
576 m ["localfcnfiledir"] = OCTAVE_LOCALFCNFILEDIR; |
|
577 m ["localstartupfiledir"] = OCTAVE_LOCALSTARTUPFILEDIR; |
|
578 m ["startupfiledir"] = OCTAVE_STARTUPFILEDIR; |
|
579 m ["localfcnfilepath"] = OCTAVE_LOCALFCNFILEPATH; |
|
580 m ["archlibdir"] = OCTAVE_ARCHLIBDIR; |
2439
|
581 m ["localarchlibdir"] = OCTAVE_LOCALARCHLIBDIR; |
2162
|
582 m ["octfiledir"] = OCTAVE_OCTFILEDIR; |
|
583 m ["localoctfilepath"] = OCTAVE_LOCALOCTFILEPATH; |
|
584 m ["fcnfilepath"] = OCTAVE_FCNFILEPATH; |
|
585 m ["imagepath"] = OCTAVE_IMAGEPATH; |
3136
|
586 m ["canonical_host_type"] = TARGET_HOST_TYPE; |
2162
|
587 m ["configure_options"] = config_opts; |
|
588 m ["F77"] = F77; |
|
589 m ["FFLAGS"] = FFLAGS; |
|
590 m ["FPICFLAG"] = FPICFLAG; |
|
591 m ["F2C"] = F2C; |
|
592 m ["F2CFLAGS"] = F2CFLAGS; |
|
593 m ["FLIBS"] = FLIBS; |
|
594 m ["CPPFLAGS"] = CPPFLAGS; |
|
595 m ["INCFLAGS"] = INCFLAGS; |
|
596 m ["CC"] = CC " " CC_VERSION; |
|
597 m ["CFLAGS"] = CFLAGS; |
|
598 m ["CPICFLAG"] = CPICFLAG; |
|
599 m ["CXX"] = CXX " " CXX_VERSION; |
|
600 m ["CXXFLAGS"] = CXXFLAGS; |
|
601 m ["CXXPICFLAG"] = CXXPICFLAG; |
|
602 m ["LDFLAGS"] = LDFLAGS; |
|
603 m ["LIBFLAGS"] = LIBFLAGS; |
2675
|
604 m ["RLD_FLAG"] = RLD_FLAG; |
2162
|
605 m ["TERMLIBS"] = TERMLIBS; |
|
606 m ["LIBS"] = LIBS; |
|
607 m ["LEXLIB"] = LEXLIB; |
|
608 m ["LIBPLPLOT"] = LIBPLPLOT; |
|
609 m ["LIBDLFCN"] = LIBDLFCN; |
|
610 m ["DEFS"] = DEFS; |
|
611 |
2689
|
612 int nargin = args.length (); |
|
613 |
|
614 if (nargin == 1) |
|
615 { |
|
616 string arg = args(0).string_value (); |
|
617 |
|
618 if (! error_state) |
|
619 retval = octave_value (m [arg.c_str ()]); |
|
620 } |
|
621 else if (nargin == 0) |
|
622 retval = octave_value (m); |
|
623 else |
|
624 print_usage ("octave_config_info"); |
|
625 |
|
626 return retval; |
2162
|
627 } |
|
628 |
1683
|
629 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE) |
2806
|
630 |
1683
|
631 int debug_new_delete = 0; |
|
632 |
|
633 typedef void (*vfp)(void); |
|
634 extern vfp __new_handler; |
|
635 |
|
636 void * |
|
637 __builtin_new (size_t sz) |
|
638 { |
|
639 void *p; |
|
640 |
|
641 /* malloc (0) is unpredictable; avoid it. */ |
|
642 if (sz == 0) |
|
643 sz = 1; |
2800
|
644 p = malloc (sz); |
1683
|
645 while (p == 0) |
|
646 { |
|
647 (*__new_handler) (); |
2800
|
648 p = malloc (sz); |
1683
|
649 } |
|
650 |
|
651 if (debug_new_delete) |
|
652 cout << "__builtin_new: " << p << endl; |
|
653 |
|
654 return p; |
|
655 } |
|
656 |
|
657 void |
|
658 __builtin_delete (void *ptr) |
|
659 { |
|
660 if (debug_new_delete) |
|
661 cout << "__builtin_delete: " << ptr << endl; |
|
662 |
|
663 if (ptr) |
|
664 free (ptr); |
|
665 } |
2806
|
666 |
1683
|
667 #endif |
|
668 |
2806
|
669 void |
|
670 symbols_of_toplev (void) |
|
671 { |
3141
|
672 DEFCONST (argv, , |
3020
|
673 "the command line arguments this program was invoked with"); |
2806
|
674 |
3020
|
675 DEFCONST (program_invocation_name, |
3141
|
676 octave_env::get_program_invocation_name (), |
3020
|
677 "the full name of the current program or script, including the\n\ |
|
678 directory specification"); |
|
679 |
3141
|
680 DEFCONST (program_name, octave_env::get_program_name (), |
3020
|
681 "the name of the current program or script"); |
2806
|
682 } |
|
683 |
1683
|
684 /* |
|
685 ;;; Local Variables: *** |
|
686 ;;; mode: C++ *** |
|
687 ;;; End: *** |
|
688 */ |