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