GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
toplev.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1995-2024 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <cerrno>
31 #include <cstdlib>
32 
33 #include <new>
34 #include <sstream>
35 #include <string>
36 
37 #if defined (OCTAVE_USE_WINDOWS_API)
38 # define WIN32_LEAN_AND_MEAN 1
39 # include <windows.h>
40 #endif
41 
42 #include "async-system-wrapper.h"
43 #include "child-list.h"
44 #include "lo-error.h"
45 #include "oct-fftw.h"
46 #include "oct-locbuf.h"
47 #include "oct-syscalls.h"
48 #include "signal-wrappers.h"
49 #include "str-vec.h"
50 #include "wait-for-input.h"
51 
52 #include "build-env.h"
54 #include "defaults.h"
55 #include "defun.h"
56 #include "error.h"
57 #include "help.h"
58 #include "interpreter-private.h"
59 #include "octave.h"
60 #include "oct-map.h"
61 #include "ovl.h"
62 #include "ov.h"
63 #include "pager.h"
64 #include "procstream.h"
65 #include "sysdep.h"
66 #include "unwind-prot.h"
67 #include "utils.h"
68 #include "version.h"
69 
70 #if ! defined (SHELL_PATH)
71 # define SHELL_PATH "/bin/sh"
72 #endif
73 
75 
76 #define STRINGIFY(s) STRINGIFY1(s)
77 #define STRINGIFY1(s) #s
78 
79 DEFUN (warranty, , ,
80  doc: /* -*- texinfo -*-
81 @deftypefn {} {} warranty ()
82 Describe the conditions for copying and distributing Octave.
83 @end deftypefn */)
84 {
86 \n\
87 GNU Octave is free software: you can redistribute it and/or modify it\n\
88 under the terms of the GNU General Public License as published by\n\
89 the Free Software Foundation, either version 3 of the License, or\n\
90 (at your option) any later version.\n\
91 \n\
92 GNU Octave is distributed in the hope that it will be useful, but\n\
93 WITHOUT ANY WARRANTY; without even the implied warranty of\n\
94 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
95 GNU General Public License for more details.\n\
96 \n\
97 You should have received a copy of the GNU General Public License\n\
98 along with GNU Octave; see the file COPYING. If not, see\n\
99 <https://www.gnu.org/licenses/>.\n\
100 \n";
101 
102  return ovl ();
103 }
104 
105 // Execute a shell command.
106 
107 static octave_value_list
108 run_command_and_return_output (const std::string& cmd_str)
109 {
110  octave_value_list retval;
111  unwind_protect frame;
112 
113  iprocstream *cmd = new iprocstream (cmd_str.c_str ());
114  frame.add_delete (cmd);
115 
116  child_list& kids = __get_child_list__ ();
117  frame.add (&child_list::remove, kids, cmd->pid ());
118 
119  if (! *cmd)
120  error ("system: unable to start subprocess for '%s'", cmd_str.c_str ());
121 
122  int fid = cmd->file_number ();
123 
124  std::ostringstream output_buf;
125 
126  char ch;
127 
128  for (;;)
129  {
130  if (cmd->get (ch))
131  output_buf.put (ch);
132  else
133  {
134  if (! cmd->eof () && errno == EAGAIN)
135  {
136  cmd->clear ();
137 
138  if (octave_wait_for_input (fid) != 1)
139  break;
140  }
141  else
142  break;
143  }
144  }
145 
146  int cmd_status = cmd->close ();
147 
148  if (sys::wifexited (cmd_status))
149  cmd_status = sys::wexitstatus (cmd_status);
150  else
151  cmd_status = 127;
152 
153  retval = ovl (cmd_status, output_buf.str ());
154 
155  return retval;
156 }
157 
158 // Combine alloc+get in one action.
159 
160 static void *
161 get_signal_mask ()
162 {
163  void *mask = octave_alloc_signal_mask ();
164 
165  octave_get_signal_mask (mask);
166 
167  return mask;
168 }
169 
170 // Combine set+free in one action.
171 
172 static void
173 restore_signal_mask (void *mask)
174 {
175  octave_set_signal_mask (mask);
176 
178 }
179 
181 
182 DEFUN (system, args, nargout,
183  doc: /* -*- texinfo -*-
184 @deftypefn {} {} system ("@var{string}")
185 @deftypefnx {} {} system ("@var{string}", @var{return_output})
186 @deftypefnx {} {} system ("@var{string}", @var{return_output}, @var{type})
187 @deftypefnx {} {[@var{status}, @var{output}] =} system (@dots{})
188 Execute a shell command specified by @var{string}.
189 
190 If @var{system} is called with one or more output arguments, or if the optional
191 argument @var{return_output} is true and the subprocess is started
192 synchronously, then the output from the command is returned as a variable.
193 Otherwise, if the subprocess is executed synchronously, its output is sent to
194 the standard output. To send the output of a command executed with
195 @code{system} through the pager, use a command like
196 
197 @example
198 @group
199 [~, text] = system ("cmd");
200 more on;
201 disp (text);
202 @end group
203 @end example
204 
205 @noindent
206 or
207 
208 @example
209 @group
210 more on;
211 printf ("%s\n", nthargout (2, "system", "cmd"));
212 @end group
213 @end example
214 
215 If the optional argument @var{type} is @qcode{"async"}, the process is started
216 in the background and the process ID of the child process is returned
217 immediately. Otherwise, the child process is started and Octave waits until it
218 exits. If the @var{type} argument is omitted, it defaults to the value
219 @qcode{"sync"}.
220 
221 The @code{system} function can return two values. The first is the exit status
222 of the command and the second is any output from the command that was written
223 to the standard output stream. For example,
224 
225 @example
226 [status, output] = system ("echo foo & exit 2");
227 @end example
228 
229 @noindent
230 will set the variable @var{output} to the string @samp{foo}, and the variable
231 @var{status} to the integer @samp{2}.
232 
233 For commands run asynchronously, @var{status} is the process id of the command
234 shell that is started to run the command.
235 
236 The shell used for executing commands varies with operating system and is
237 typically @file{/bin/sh} for UNIX systems and @nospell{@file{cmd.exe}} for
238 Windows systems.
239 @seealso{unix, dos}
240 @end deftypefn */)
241 {
242  int nargin = args.length ();
243 
244  if (nargin == 0 || nargin > 3)
245  print_usage ();
246 
247  system_exec_type type = et_sync;
248  if (nargin == 3)
249  {
250  std::string type_str = args(2).xstring_value ("system: TYPE must be a string");
251 
252  if (type_str == "sync")
253  type = et_sync;
254  else if (type_str == "async")
255  type = et_async;
256  else
257  error (R"(system: TYPE must be "sync" or "async")");
258  }
259 
260  octave_value_list retval;
261 
262  bool return_output = (nargin == 1 && nargout > 1);
263 
264  if (nargin > 1)
265  {
266  try
267  {
268  return_output = args(1).is_true ();
269  }
270  catch (execution_exception& ee)
271  {
272  error (ee, "system: RETURN_OUTPUT must be boolean value true or false");
273  }
274  }
275 
276  if (return_output && type == et_async)
277  error ("system: can't return output from commands run asynchronously");
278 
279  std::string cmd_str = args(0).xstring_value ("system: first argument must be a string");
280 
281 #if defined (OCTAVE_USE_WINDOWS_API)
282  // Work around weird double-quote handling on Windows systems.
283  if (type == et_sync)
284  cmd_str = '"' + cmd_str + '"';
285 #endif
286 
287  unwind_action restore_mask
288  ([] (void *mask) { restore_signal_mask (mask); }, get_signal_mask ());
289 
291  octave_unblock_signal_by_name ("SIGTSTP");
292 
293  if (type == et_async)
294  retval(0) = octave_async_system_wrapper (cmd_str.c_str ());
295  else if (return_output)
296  retval = run_command_and_return_output (cmd_str);
297  else
298  {
299  int status = sys::system (cmd_str);
300 
301  // The value in status is as returned by waitpid. If
302  // the process exited normally, extract the actual exit
303  // status of the command. Otherwise, return 127 as a
304  // failure code.
305 
306  if (sys::wifexited (status))
307  status = sys::wexitstatus (status);
308 
309  retval(0) = status;
310  }
311 
312  return retval;
313 }
314 
315 /*
316 %!test
317 %! cmd = ls_command ();
318 %! [status, output] = system (cmd);
319 %! assert (status, 0);
320 %! assert (ischar (output));
321 %! assert (! isempty (output));
322 
323 %!error system ()
324 %!error system (1, 2, 3)
325 */
326 
327 static octave_value
328 find_config_info (const octave_scalar_map& m, const std::string& key)
329 {
330  if (m.isfield (key))
331  {
332  Cell c = m.contents (key);
333 
334  if (! c.isempty ())
335  return c(0);
336  }
337 
338  return octave_value ();
339 }
340 
341 DEFUN (__octave_config_info__, args, ,
342  doc: /* -*- texinfo -*-
343 @deftypefn {} {@var{S} =} __octave_config_info__ ()
344 @deftypefnx {} {@var{S} =} __octave_config_info__ (@var{option})
345 Return a structure containing configuration and installation information for
346 Octave.
347 
348 If @var{option} is a string, return the configuration information for the
349 specified option.
350 
351 @seealso{computer}
352 @end deftypefn */)
353 {
354  static octave_scalar_map config;
355  static octave_scalar_map build_env;
356  static octave_scalar_map build_features;
357 
358  static bool initialized = false;
359 
360  if (! initialized)
361  {
362  std::map<std::string, octave_value> conf_info_map
363  = {{ "DEFAULT_PAGER", config::default_pager () },
364 
365 #if defined (OCTAVE_ENABLE_64)
366  { "ENABLE_64", true },
367 #else
368  { "ENABLE_64", false },
369 #endif
370 
371 #if defined (OCTAVE_ENABLE_COMMAND_LINE_PUSH_PARSER)
372  { "ENABLE_COMMAND_LINE_PUSH_PARSER", true },
373 #else
374  { "ENABLE_COMMAND_LINE_PUSH_PARSER", false },
375 #endif
376 
377 #if defined (ENABLE_DOCS)
378  { "ENABLE_DOCS", true },
379 #else
380  { "ENABLE_DOCS", false },
381 #endif
382 
383 #if defined (OCTAVE_ENABLE_FLOAT_TRUNCATE)
384  { "ENABLE_FLOAT_TRUNCATE", true },
385 #else
386  { "ENABLE_FLOAT_TRUNCATE", false },
387 #endif
388 
389 #if defined (OCTAVE_ENABLE_OPENMP)
390  { "ENABLE_OPENMP", true },
391 #else
392  { "ENABLE_OPENMP", false },
393 #endif
394 
395  { "api_version", OCTAVE_API_VERSION },
396  { "archlibdir", config::arch_lib_dir () },
397  { "bindir", config::bin_dir () },
398  { "canonical_host_type", config::canonical_host_type () },
399  { "datadir", config::data_dir () },
400  { "datarootdir", config::dataroot_dir () },
401  { "fcnfiledir", config::fcn_file_dir () },
402  { "fftw_version", fftw_version () },
403  { "fftwf_version", fftwf_version () },
404  { "imagedir", config::image_dir () },
405  { "includedir", config::include_dir () },
406  { "infodir", config::info_dir () },
407  { "libdir", config::lib_dir () },
408  { "libexecdir", config::libexec_dir () },
409  // Each library and executable has its own definition of the hg
410  // id. We check for consistency when Octave starts so we just
411  // store and report one of them here.
412  { "hg_id", liboctinterp_hg_id () },
413  { "localapiarchlibdir", config::local_api_arch_lib_dir () },
414  { "localapifcnfiledir", config::local_api_fcn_file_dir () },
415  { "localapioctfiledir", config::local_api_oct_file_dir () },
416  { "localarchlibdir", config::local_arch_lib_dir () },
417  { "localfcnfiledir", config::local_fcn_file_dir () },
418  { "localoctfiledir", config::local_oct_file_dir () },
419  { "localstartupfiledir", config::local_startupfile_dir () },
420  { "localverarchlibdir", config::local_ver_arch_lib_dir () },
421  { "localverfcnfiledir", config::local_ver_fcn_file_dir () },
422  { "localveroctfiledir", config::local_ver_oct_file_dir () },
423  { "major_version", STRINGIFY (OCTAVE_MAJOR_VERSION) },
424  { "man1dir", config::man1_dir () },
425  { "man1ext", config::man1_ext () },
426  { "mandir", config::man_dir () },
427  { "minor_version", STRINGIFY (OCTAVE_MINOR_VERSION) },
428  { "octdatadir", config::oct_data_dir () },
429  { "octdocdir", config::oct_doc_dir () },
430  { "octetcdir", config::oct_etc_dir () },
431  { "octfiledir", config::oct_file_dir () },
432  { "octfontsdir", config::oct_fonts_dir () },
433  { "octincludedir", config::oct_include_dir () },
434  { "octlibdir", config::oct_lib_dir () },
435  { "octtestsdir", config::oct_tests_dir () },
436  { "patch_version", STRINGIFY (OCTAVE_PATCH_VERSION) },
437  { "release_date", OCTAVE_RELEASE_DATE },
438  { "startupfiledir", config::startupfile_dir () },
439  { "version", OCTAVE_VERSION }
440  };
441 
442  std::map<std::string, octave_value> build_env_map
443  = {{ "AMD_CPPFLAGS", build_env::AMD_CPPFLAGS },
444  { "AMD_LDFLAGS", build_env::AMD_LDFLAGS },
445  { "AMD_LIBS", build_env::AMD_LIBS },
446  { "AR", build_env::AR },
447  { "ARFLAGS", build_env::ARFLAGS },
448  { "ARPACK_CPPFLAGS", build_env::ARPACK_CPPFLAGS },
449  { "ARPACK_LDFLAGS", build_env::ARPACK_LDFLAGS },
450  { "ARPACK_LIBS", build_env::ARPACK_LIBS },
451  { "BLAS_LIBS", build_env::BLAS_LIBS },
452  { "CAMD_CPPFLAGS", build_env::CAMD_CPPFLAGS },
453  { "CAMD_LDFLAGS", build_env::CAMD_LDFLAGS },
454  { "CAMD_LIBS", build_env::CAMD_LIBS },
455  { "CARBON_LIBS", build_env::CARBON_LIBS },
456  { "CC", build_env::CC },
457  { "CCOLAMD_CPPFLAGS", build_env::CCOLAMD_CPPFLAGS },
458  { "CCOLAMD_LDFLAGS", build_env::CCOLAMD_LDFLAGS },
459  { "CCOLAMD_LIBS", build_env::CCOLAMD_LIBS },
460  { "CFLAGS", build_env::CFLAGS },
461  { "CHOLMOD_CPPFLAGS", build_env::CHOLMOD_CPPFLAGS },
462  { "CHOLMOD_LDFLAGS", build_env::CHOLMOD_LDFLAGS },
463  { "CHOLMOD_LIBS", build_env::CHOLMOD_LIBS },
464  { "COLAMD_CPPFLAGS", build_env::COLAMD_CPPFLAGS },
465  { "COLAMD_LDFLAGS", build_env::COLAMD_LDFLAGS },
466  { "COLAMD_LIBS", build_env::COLAMD_LIBS },
467  { "CPICFLAG", build_env::CPICFLAG },
468  { "CPPFLAGS", build_env::CPPFLAGS },
469  { "CURL_CPPFLAGS", build_env::CURL_CPPFLAGS },
470  { "CURL_LDFLAGS", build_env::CURL_LDFLAGS },
471  { "CURL_LIBS", build_env::CURL_LIBS },
472  { "CXSPARSE_CPPFLAGS", build_env::CXSPARSE_CPPFLAGS },
473  { "CXSPARSE_LDFLAGS", build_env::CXSPARSE_LDFLAGS },
474  { "CXSPARSE_LIBS", build_env::CXSPARSE_LIBS },
475  { "CXX", build_env::CXX },
476  { "CXXCPP", build_env::CXXCPP },
477  { "CXXFLAGS", build_env::CXXFLAGS },
478  { "CXXPICFLAG", build_env::CXXPICFLAG },
479  { "DEFS", build_env::DEFS },
480  { "DL_LDFLAGS", build_env::DL_LDFLAGS },
481  { "GCC_VERSION", build_env::GCC_VERSION },
482  { "GXX_VERSION", build_env::GXX_VERSION },
483  { "EXEEXT", build_env::EXEEXT },
484  { "F77", build_env::F77 },
485  { "F77_FLOAT_STORE_FLAG", build_env::F77_FLOAT_STORE_FLAG },
486  { "F77_INTEGER_8_FLAG", build_env::F77_INTEGER_8_FLAG },
487  { "FFLAGS", build_env::FFLAGS },
488  { "FFTW3_CPPFLAGS", build_env::FFTW3_CPPFLAGS },
489  { "FFTW3_LDFLAGS", build_env::FFTW3_LDFLAGS },
490  { "FFTW3_LIBS", build_env::FFTW3_LIBS },
491  { "FFTW3F_CPPFLAGS", build_env::FFTW3F_CPPFLAGS },
492  { "FFTW3F_LDFLAGS", build_env::FFTW3F_LDFLAGS },
493  { "FFTW3F_LIBS", build_env::FFTW3F_LIBS },
494  { "FLIBS", build_env::FLIBS },
495  { "FLTK_CPPFLAGS", build_env::FLTK_CPPFLAGS },
496  { "FLTK_LDFLAGS", build_env::FLTK_LDFLAGS },
497  { "FLTK_LIBS", build_env::FLTK_LIBS },
498  { "FONTCONFIG_CPPFLAGS", build_env::FONTCONFIG_CPPFLAGS },
499  { "FONTCONFIG_LIBS", build_env::FONTCONFIG_LIBS },
500  { "FPICFLAG", build_env::FPICFLAG },
501  { "FT2_CPPFLAGS", build_env::FT2_CPPFLAGS },
502  { "FT2_LIBS", build_env::FT2_LIBS },
503  { "GLPK_CPPFLAGS", build_env::GLPK_CPPFLAGS },
504  { "GLPK_LDFLAGS", build_env::GLPK_LDFLAGS },
505  { "GLPK_LIBS", build_env::GLPK_LIBS },
506  { "GNUPLOT", build_env::GNUPLOT },
507  { "HDF5_CPPFLAGS", build_env::HDF5_CPPFLAGS },
508  { "HDF5_LDFLAGS", build_env::HDF5_LDFLAGS },
509  { "HDF5_LIBS", build_env::HDF5_LIBS },
510  { "LAPACK_LIBS", build_env::LAPACK_LIBS },
511  { "LDFLAGS", build_env::LDFLAGS },
512  { "LD_STATIC_FLAG", build_env::LD_STATIC_FLAG },
513  { "LEX", build_env::LEX },
514  { "LEXLIB", build_env::LEXLIB },
515  { "LFLAGS", build_env::LFLAGS },
516  { "LIBOCTAVE", build_env::LIBOCTAVE },
517  { "LIBOCTINTERP", build_env::LIBOCTINTERP },
518  { "LIBS", build_env::LIBS },
519  { "LN_S", build_env::LN_S },
520  { "MAGICK_CPPFLAGS", build_env::MAGICK_CPPFLAGS },
521  { "MAGICK_LDFLAGS", build_env::MAGICK_LDFLAGS },
522  { "MAGICK_LIBS", build_env::MAGICK_LIBS },
523  { "MKOCTFILE_DL_LDFLAGS", build_env::MKOCTFILE_DL_LDFLAGS },
524  { "OCTAVE_LINK_DEPS", build_env::OCTAVE_LINK_DEPS },
525  { "OCTAVE_LINK_OPTS", build_env::OCTAVE_LINK_OPTS },
526  { "OCT_LINK_DEPS", build_env::OCT_LINK_DEPS },
527  { "OCT_LINK_OPTS", build_env::OCT_LINK_OPTS },
528  { "OPENGL_LIBS", build_env::OPENGL_LIBS },
529  { "PCRE_CPPFLAGS", build_env::PCRE_CPPFLAGS },
530  { "PCRE_LDFLAGS", build_env::PCRE_LDFLAGS },
531  { "PCRE_LIBS", build_env::PCRE_LIBS },
532  { "PTHREAD_CFLAGS", build_env::PTHREAD_CFLAGS },
533  { "PTHREAD_LIBS", build_env::PTHREAD_LIBS },
534  { "QHULL_CPPFLAGS", build_env::QHULL_CPPFLAGS },
535  { "QHULL_LDFLAGS", build_env::QHULL_LDFLAGS },
536  { "QHULL_LIBS", build_env::QHULL_LIBS },
537  { "QRUPDATE_CPPFLAGS", build_env::QRUPDATE_CPPFLAGS },
538  { "QRUPDATE_LDFLAGS", build_env::QRUPDATE_LDFLAGS },
539  { "QRUPDATE_LIBS", build_env::QRUPDATE_LIBS },
540  { "QT_CPPFLAGS", build_env::QT_CPPFLAGS },
541  { "QT_LDFLAGS", build_env::QT_LDFLAGS },
542  { "QT_LIBS", build_env::QT_LIBS },
543  { "RANLIB", build_env::RANLIB },
544  { "RDYNAMIC_FLAG", build_env::RDYNAMIC_FLAG },
545  { "READLINE_LIBS", build_env::READLINE_LIBS },
546  { "SHARED_LIBS", build_env::SHARED_LIBS },
547  { "SH_LDFLAGS", build_env::SH_LDFLAGS },
548  { "STATIC_LIBS", build_env::STATIC_LIBS },
549  { "SUITESPARSECONFIG_LIBS", build_env::SUITESPARSECONFIG_LIBS },
550  { "UMFPACK_CPPFLAGS", build_env::UMFPACK_CPPFLAGS },
551  { "UMFPACK_LDFLAGS", build_env::UMFPACK_LDFLAGS },
552  { "UMFPACK_LIBS", build_env::UMFPACK_LIBS },
553  { "WARN_CFLAGS", build_env::WARN_CFLAGS },
554  { "WARN_CXXFLAGS", build_env::WARN_CXXFLAGS },
555  { "X11_INCFLAGS", build_env::X11_INCFLAGS },
556  { "X11_LIBS", build_env::X11_LIBS },
557  { "XTRA_CFLAGS", build_env::XTRA_CFLAGS },
558  { "XTRA_CXXFLAGS", build_env::XTRA_CXXFLAGS },
559  { "YACC", build_env::YACC },
560  { "YFLAGS", build_env::YFLAGS },
561  { "Z_CPPFLAGS", build_env::Z_CPPFLAGS },
562  { "Z_LDFLAGS", build_env::Z_LDFLAGS },
563  { "Z_LIBS", build_env::Z_LIBS },
564  { "config_opts", build_env::config_opts }
565  };
566 
567  config = octave_scalar_map (conf_info_map);
568  build_env = octave_scalar_map (build_env_map);
569  build_features = build_env::features ();
570 
571  bool unix_system = true;
572  bool mac_system = false;
573  bool windows_system = false;
574 
575 #if defined (__WIN32__)
576  windows_system = true;
577 #if ! defined (__CYGWIN__)
578  unix_system = false;
579 #endif
580 #endif
581 
582 #if defined (OCTAVE_USE_OS_X_API)
583  mac_system = true;
584 #endif
585 
586  config.assign ("unix", octave_value (unix_system));
587  config.assign ("mac", octave_value (mac_system));
588  config.assign ("windows", octave_value (windows_system));
589 
591  config.assign ("float_format",
593 
594  config.assign ("words_big_endian",
596 
597  config.assign ("words_little_endian",
599 
600  config.assign ("build_environment", octave_value (build_env));
601 
602  config.assign ("build_features", octave_value (build_features));
603 
604  initialized = true;
605  }
606 
607  int nargin = args.length ();
608 
609  if (nargin > 1)
610  print_usage ();
611 
612  octave_value_list retval;
613 
614  if (nargin == 1)
615  {
616  std::string arg = args(0).xstring_value ("__octave_config_info__: OPTION argument must be a string");
617 
618  octave_value info = find_config_info (config, arg);
619 
620  if (info.is_undefined ())
621  info = find_config_info (build_env, arg);
622 
623  if (info.is_undefined ())
624  info = find_config_info (build_features, arg);
625 
626  if (info.is_undefined ())
627  error ("__octave_config_info__: no info for '%s'", arg.c_str ());
628 
629  return info;
630  }
631  else
632  retval = ovl (config);
633 
634  return retval;
635 }
636 
637 /*
638 %!assert (ischar (__octave_config_info__ ("version")))
639 %!assert (__octave_config_info__ ("version"), OCTAVE_VERSION ())
640 %!test
641 %! x = __octave_config_info__ ();
642 %! assert (isstruct (x));
643 %! assert (! isempty (x));
644 %! assert (x.version, OCTAVE_VERSION ());
645 
646 %!error __octave_config_info__ (1, 2)
647 */
648 
649 OCTAVE_END_NAMESPACE(octave)
650 
651 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE)
652 
653 int debug_new_delete = 0;
654 
655 typedef void (*vfp)();
656 extern vfp __new_handler;
657 
658 void *
659 __builtin_new (std::size_t sz)
660 {
661  void *p;
662 
663  // malloc (0) is unpredictable; avoid it.
664  if (sz == 0)
665  sz = 1;
666  p = std::malloc (sz);
667  while (p == 0)
668  {
669  (*__new_handler) ();
670  p = std::malloc (sz);
671  }
672 
673  if (debug_new_delete)
674  std::cerr << "__builtin_new: " << p << std::endl;
675 
676  return p;
677 }
678 
679 void
680 __builtin_delete (void *ptr)
681 {
682  if (debug_new_delete)
683  std::cerr << "__builtin_delete: " << ptr << std::endl;
684 
685  free (ptr);
686 }
687 
688 #endif
pid_t octave_async_system_wrapper(const char *cmd)
octave_scalar_map features()
const char * LDFLAGS
Definition: build-env.cc:184
const char * QT_CPPFLAGS
Definition: build-env.cc:248
const char * RANLIB
Definition: build-env.cc:254
const char * Z_LIBS
Definition: build-env.cc:312
const char * LIBS
Definition: build-env.cc:198
const char * PTHREAD_LIBS
Definition: build-env.cc:234
const char * UMFPACK_LIBS
Definition: build-env.cc:290
const char * AMD_LIBS
Definition: build-env.cc:42
const char * LN_S
Definition: build-env.cc:200
const char * CHOLMOD_LDFLAGS
Definition: build-env.cc:76
const char * CURL_LIBS
Definition: build-env.cc:94
const char * CAMD_LIBS
Definition: build-env.cc:60
const char * YFLAGS
Definition: build-env.cc:306
const char * STATIC_LIBS
Definition: build-env.cc:264
const char * AR
Definition: build-env.cc:46
const char * AMD_LDFLAGS
Definition: build-env.cc:40
const char * LIBOCTAVE
Definition: build-env.cc:194
const char * FLTK_CPPFLAGS
Definition: build-env.cc:144
const char * MAGICK_LDFLAGS
Definition: build-env.cc:204
const char * HDF5_CPPFLAGS
Definition: build-env.cc:168
const char * CARBON_LIBS
Definition: build-env.cc:62
const char * config_opts
Definition: build-env.cc:314
const char * CPICFLAG
Definition: build-env.cc:86
const char * FFLAGS
Definition: build-env.cc:128
const char * GCC_VERSION
Definition: build-env.cc:118
const char * X11_LIBS
Definition: build-env.cc:298
const char * FONTCONFIG_LIBS
Definition: build-env.cc:152
const char * GLPK_LIBS
Definition: build-env.cc:164
const char * COLAMD_LIBS
Definition: build-env.cc:84
const char * ARPACK_LDFLAGS
Definition: build-env.cc:50
const char * HDF5_LIBS
Definition: build-env.cc:172
const char * GLPK_CPPFLAGS
Definition: build-env.cc:160
const char * COLAMD_LDFLAGS
Definition: build-env.cc:82
const char * OCT_LINK_OPTS
Definition: build-env.cc:220
const char * OCTAVE_LINK_OPTS
Definition: build-env.cc:212
const char * AMD_CPPFLAGS
Definition: build-env.cc:38
const char * CXSPARSE_LIBS
Definition: build-env.cc:100
const char * QRUPDATE_LDFLAGS
Definition: build-env.cc:244
const char * CC
Definition: build-env.cc:64
const char * QRUPDATE_LIBS
Definition: build-env.cc:246
const char * F77_INTEGER_8_FLAG
Definition: build-env.cc:126
const char * FFTW3_CPPFLAGS
Definition: build-env.cc:130
const char * BLAS_LIBS
Definition: build-env.cc:54
const char * QT_LDFLAGS
Definition: build-env.cc:250
const char * CPPFLAGS
Definition: build-env.cc:88
const char * CAMD_CPPFLAGS
Definition: build-env.cc:56
const char * DL_LDFLAGS
Definition: build-env.cc:114
const char * FLIBS
Definition: build-env.cc:142
const char * WARN_CXXFLAGS
Definition: build-env.cc:294
const char * XTRA_CFLAGS
Definition: build-env.cc:300
const char * FLTK_LDFLAGS
Definition: build-env.cc:146
const char * DEFS
Definition: build-env.cc:112
const char * FFTW3_LIBS
Definition: build-env.cc:134
const char * COLAMD_CPPFLAGS
Definition: build-env.cc:80
const char * OCT_LINK_DEPS
Definition: build-env.cc:218
const char * CXXCPP
Definition: build-env.cc:102
const char * PCRE_LDFLAGS
Definition: build-env.cc:226
const char * EXEEXT
Definition: build-env.cc:116
const char * F77
Definition: build-env.cc:122
const char * Z_LDFLAGS
Definition: build-env.cc:310
const char * MKOCTFILE_DL_LDFLAGS
Definition: build-env.cc:208
const char * MAGICK_LIBS
Definition: build-env.cc:206
const char * FFTW3_LDFLAGS
Definition: build-env.cc:132
const char * FFTW3F_CPPFLAGS
Definition: build-env.cc:136
const char * FT2_LIBS
Definition: build-env.cc:158
const char * SUITESPARSECONFIG_LIBS
Definition: build-env.cc:266
const char * WARN_CFLAGS
Definition: build-env.cc:292
const char * LD_STATIC_FLAG
Definition: build-env.cc:186
const char * RDYNAMIC_FLAG
Definition: build-env.cc:256
const char * CHOLMOD_LIBS
Definition: build-env.cc:78
const char * LAPACK_LIBS
Definition: build-env.cc:182
const char * UMFPACK_CPPFLAGS
Definition: build-env.cc:286
const char * HDF5_LDFLAGS
Definition: build-env.cc:170
const char * CXXFLAGS
Definition: build-env.cc:104
const char * QHULL_LDFLAGS
Definition: build-env.cc:238
const char * CXX
Definition: build-env.cc:108
const char * X11_INCFLAGS
Definition: build-env.cc:296
const char * FFTW3F_LDFLAGS
Definition: build-env.cc:138
const char * GNUPLOT
Definition: build-env.cc:166
const char * FT2_CPPFLAGS
Definition: build-env.cc:156
const char * CHOLMOD_CPPFLAGS
Definition: build-env.cc:74
const char * ARPACK_LIBS
Definition: build-env.cc:52
const char * OPENGL_LIBS
Definition: build-env.cc:222
const char * READLINE_LIBS
Definition: build-env.cc:258
const char * CXSPARSE_LDFLAGS
Definition: build-env.cc:98
const char * GLPK_LDFLAGS
Definition: build-env.cc:162
const char * Z_CPPFLAGS
Definition: build-env.cc:308
const char * PCRE_CPPFLAGS
Definition: build-env.cc:224
const char * FONTCONFIG_CPPFLAGS
Definition: build-env.cc:150
const char * OCTAVE_LINK_DEPS
Definition: build-env.cc:210
const char * FFTW3F_LIBS
Definition: build-env.cc:140
const char * QRUPDATE_CPPFLAGS
Definition: build-env.cc:242
const char * CCOLAMD_LIBS
Definition: build-env.cc:70
const char * LFLAGS
Definition: build-env.cc:192
const char * QHULL_LIBS
Definition: build-env.cc:240
const char * CAMD_LDFLAGS
Definition: build-env.cc:58
const char * YACC
Definition: build-env.cc:304
const char * CXXPICFLAG
Definition: build-env.cc:106
const char * CURL_CPPFLAGS
Definition: build-env.cc:90
const char * GXX_VERSION
Definition: build-env.cc:120
const char * CXSPARSE_CPPFLAGS
Definition: build-env.cc:96
const char * CURL_LDFLAGS
Definition: build-env.cc:92
const char * CCOLAMD_CPPFLAGS
Definition: build-env.cc:66
const char * FLTK_LIBS
Definition: build-env.cc:148
const char * PTHREAD_CFLAGS
Definition: build-env.cc:232
const char * CFLAGS
Definition: build-env.cc:72
const char * LIBOCTINTERP
Definition: build-env.cc:196
const char * PCRE_LIBS
Definition: build-env.cc:228
const char * XTRA_CXXFLAGS
Definition: build-env.cc:302
const char * ARPACK_CPPFLAGS
Definition: build-env.cc:48
const char * LEX
Definition: build-env.cc:190
const char * SHARED_LIBS
Definition: build-env.cc:260
const char * CCOLAMD_LDFLAGS
Definition: build-env.cc:68
const char * F77_FLOAT_STORE_FLAG
Definition: build-env.cc:124
const char * UMFPACK_LDFLAGS
Definition: build-env.cc:288
const char * FPICFLAG
Definition: build-env.cc:154
const char * SH_LDFLAGS
Definition: build-env.cc:262
const char * QT_LIBS
Definition: build-env.cc:252
const char * LEXLIB
Definition: build-env.cc:188
const char * QHULL_CPPFLAGS
Definition: build-env.cc:236
const char * MAGICK_CPPFLAGS
Definition: build-env.cc:202
const char * ARFLAGS
Definition: build-env.cc:44
bool isempty() const
Size of the specified dimension.
Definition: Array.h:651
Definition: Cell.h:43
void add(F &&fcn, Args &&... args)
void add_delete(T *obj)
void remove(pid_t pid)
Definition: child-list.cc:35
void assign(const std::string &k, const octave_value &val)
Definition: oct-map.h:230
bool is_undefined() const
Definition: ov.h:595
int file_number() const
Definition: procstream.h:69
pid_t pid() const
Definition: procstream.h:67
void octave_unblock_async_signals()
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::string startupfile_dir()
std::string man_dir()
std::string dataroot_dir()
std::string oct_doc_dir()
std::string default_pager()
std::string local_ver_arch_lib_dir()
std::string local_oct_file_dir()
std::string local_startupfile_dir()
std::string canonical_host_type()
std::string oct_fonts_dir()
std::string lib_dir()
std::string local_fcn_file_dir()
std::string include_dir()
std::string local_api_oct_file_dir()
std::string local_arch_lib_dir()
std::string info_dir()
std::string oct_tests_dir()
std::string fcn_file_dir()
std::string bin_dir()
std::string local_api_fcn_file_dir()
std::string local_ver_fcn_file_dir()
std::string man1_dir()
std::string oct_etc_dir()
std::string local_ver_oct_file_dir()
std::string local_api_arch_lib_dir()
std::string man1_ext()
std::string libexec_dir()
std::string image_dir()
std::string oct_file_dir()
std::string oct_data_dir()
std::string oct_include_dir()
std::string oct_lib_dir()
std::string data_dir()
std::string arch_lib_dir()
void print_usage(void)
Definition: defun-int.h:72
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:56
void() error(const char *fmt,...)
Definition: error.cc:988
child_list & __get_child_list__()
std::string liboctinterp_hg_id()
int system(const std::string &cmd_str)
Definition: lo-sysdep.cc:60
bool words_little_endian()
Definition: mach-info.cc:83
std::string float_format_as_string(float_format flt_fmt)
Definition: mach-info.cc:111
bool words_big_endian()
Definition: mach-info.cc:75
float_format native_float_format()
Definition: mach-info.cc:67
float_format
Definition: mach-info.h:38
#define OCTAVE_VERSION
Definition: main.cc:63
T octave_idx_type m
Definition: mx-inlines.cc:781
std::string fftwf_version()
Definition: oct-fftw.cc:1144
std::string fftw_version()
Definition: oct-fftw.cc:1134
process_execution_result run_command_and_return_output(const std::string &cmd_str)
Definition: oct-process.cc:51
bool wifexited(int status)
int wexitstatus(int status)
void * malloc(unsigned)
void free(void *)
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:219
#define octave_stdout
Definition: pager.h:309
void octave_unblock_signal_by_name(const char *signame)
void octave_set_signal_mask(void *mask)
void octave_free_signal_mask(void *mask)
void octave_get_signal_mask(void *mask)
void * octave_alloc_signal_mask(void)
#define STRINGIFY(s)
Definition: toplev.cc:76
system_exec_type
Definition: toplev.cc:180
@ et_sync
Definition: toplev.cc:180
@ et_async
Definition: toplev.cc:180
std::string octave_name_version_and_copyright(bool html)
Definition: version.cc:70
#define OCTAVE_MINOR_VERSION
Definition: version.h:37
#define OCTAVE_PATCH_VERSION
Definition: version.h:39
#define OCTAVE_MAJOR_VERSION
Definition: version.h:35
#define OCTAVE_RELEASE_DATE
Definition: version.h:51
#define OCTAVE_API_VERSION
Definition: version.h:49
int octave_wait_for_input(int fid)