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