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