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