GNU Octave  8.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-2023 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 *
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
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  { "QT_OPENGL_LIBS", build_env::QT_OPENGL_LIBS },
544  { "RANLIB", build_env::RANLIB },
545  { "RDYNAMIC_FLAG", build_env::RDYNAMIC_FLAG },
546  { "READLINE_LIBS", build_env::READLINE_LIBS },
547  { "SHARED_LIBS", build_env::SHARED_LIBS },
548  { "SH_LDFLAGS", build_env::SH_LDFLAGS },
549  { "STATIC_LIBS", build_env::STATIC_LIBS },
550  { "SUITESPARSECONFIG_LIBS", build_env::SUITESPARSECONFIG_LIBS },
551  { "UMFPACK_CPPFLAGS", build_env::UMFPACK_CPPFLAGS },
552  { "UMFPACK_LDFLAGS", build_env::UMFPACK_LDFLAGS },
553  { "UMFPACK_LIBS", build_env::UMFPACK_LIBS },
554  { "WARN_CFLAGS", build_env::WARN_CFLAGS },
555  { "WARN_CXXFLAGS", build_env::WARN_CXXFLAGS },
556  { "X11_INCFLAGS", build_env::X11_INCFLAGS },
557  { "X11_LIBS", build_env::X11_LIBS },
558  { "XTRA_CFLAGS", build_env::XTRA_CFLAGS },
559  { "XTRA_CXXFLAGS", build_env::XTRA_CXXFLAGS },
560  { "YACC", build_env::YACC },
561  { "YFLAGS", build_env::YFLAGS },
562  { "Z_CPPFLAGS", build_env::Z_CPPFLAGS },
563  { "Z_LDFLAGS", build_env::Z_LDFLAGS },
564  { "Z_LIBS", build_env::Z_LIBS },
565  { "config_opts", build_env::config_opts }
566  };
567 
568  config = octave_scalar_map (conf_info_map);
569  build_env = octave_scalar_map (build_env_map);
570  build_features = build_env::features ();
571 
572  bool unix_system = true;
573  bool mac_system = false;
574  bool windows_system = false;
575 
576 #if defined (__WIN32__)
577  windows_system = true;
578 #if ! defined (__CYGWIN__)
579  unix_system = false;
580 #endif
581 #endif
582 
583 #if defined (OCTAVE_USE_OS_X_API)
584  mac_system = true;
585 #endif
586 
587  config.assign ("unix", octave_value (unix_system));
588  config.assign ("mac", octave_value (mac_system));
589  config.assign ("windows", octave_value (windows_system));
590 
592  config.assign ("float_format",
594 
595  config.assign ("words_big_endian",
597 
598  config.assign ("words_little_endian",
600 
601  config.assign ("build_environment", octave_value (build_env));
602 
603  config.assign ("build_features", octave_value (build_features));
604 
605  initialized = true;
606  }
607 
608  int nargin = args.length ();
609 
610  if (nargin > 1)
611  print_usage ();
612 
613  octave_value_list retval;
614 
615  if (nargin == 1)
616  {
617  std::string arg = args(
618  0).xstring_value ("__octave_config_info__: OPTION argument must be a string");
619 
620  octave_value info = find_config_info (config, arg);
621 
622  if (info.is_undefined ())
623  info = find_config_info (build_env, arg);
624 
625  if (info.is_undefined ())
626  info = find_config_info (build_features, arg);
627 
628  if (info.is_undefined ())
629  error ("__octave_config_info__: no info for '%s'", arg.c_str ());
630 
631  return info;
632  }
633  else
634  retval = ovl (config);
635 
636  return retval;
637 }
638 
639 /*
640 %!assert (ischar (__octave_config_info__ ("version")))
641 %!assert (__octave_config_info__ ("version"), OCTAVE_VERSION ())
642 %!test
643 %! x = __octave_config_info__ ();
644 %! assert (isstruct (x));
645 %! assert (! isempty (x));
646 %! assert (x.version, OCTAVE_VERSION ());
647 
648 %!error __octave_config_info__ (1, 2)
649 */
650 
652 
653 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE)
654 
655 int debug_new_delete = 0;
656 
657 typedef void (*vfp)(void);
658 extern vfp __new_handler;
659 
660 void *
661 __builtin_new (std::size_t sz)
662 {
663  void *p;
664 
665  // malloc (0) is unpredictable; avoid it.
666  if (sz == 0)
667  sz = 1;
668  p = std::malloc (sz);
669  while (p == 0)
670  {
671  (*__new_handler) ();
672  p = std::malloc (sz);
673  }
674 
675  if (debug_new_delete)
676  std::cerr << "__builtin_new: " << p << std::endl;
677 
678  return p;
679 }
680 
681 void
682 __builtin_delete (void *ptr)
683 {
684  if (debug_new_delete)
685  std::cerr << "__builtin_delete: " << ptr << std::endl;
686 
687  free (ptr);
688 }
689 
690 #endif
OCTAVE_END_NAMESPACE(octave)
pid_t octave_async_system_wrapper(const char *cmd)
OCTINTERP_API const char * YACC
OCTINTERP_API const char * OCT_LINK_OPTS
OCTINTERP_API const char * FONTCONFIG_CPPFLAGS
OCTINTERP_API const char * LIBOCTINTERP
OCTINTERP_API const char * CC
Definition: build-env.in.cc:64
OCTINTERP_API const char * ARPACK_LDFLAGS
Definition: build-env.in.cc:50
OCTINTERP_API const char * CURL_LDFLAGS
Definition: build-env.in.cc:92
OCTINTERP_API const char * MAGICK_LIBS
OCTINTERP_API const char * EXEEXT
OCTINTERP_API const char * CHOLMOD_LDFLAGS
Definition: build-env.in.cc:76
OCTINTERP_API const char * FFLAGS
OCTINTERP_API const char * F77_INTEGER_8_FLAG
OCTINTERP_API const char * QRUPDATE_LDFLAGS
OCTINTERP_API const char * CHOLMOD_CPPFLAGS
Definition: build-env.in.cc:74
OCTINTERP_API const char * Z_LDFLAGS
OCTINTERP_API const char * FFTW3_LDFLAGS
OCTINTERP_API const char * RDYNAMIC_FLAG
OCTINTERP_API const char * ARPACK_LIBS
Definition: build-env.in.cc:52
OCTINTERP_API const char * LDFLAGS
OCTINTERP_API const char * CPICFLAG
Definition: build-env.in.cc:86
OCTINTERP_API const char * WARN_CFLAGS
OCTINTERP_API const char * FONTCONFIG_LIBS
OCTINTERP_API const char * UMFPACK_LIBS
OCTINTERP_API const char * OCTAVE_LINK_DEPS
OCTINTERP_API const char * LIBS
OCTINTERP_API const char * CXXPICFLAG
OCTINTERP_API const char * FLTK_LIBS
OCTINTERP_API const char * Z_LIBS
OCTINTERP_API const char * LEX
OCTINTERP_API const char * FT2_LIBS
OCTINTERP_API octave_scalar_map features(void)
OCTINTERP_API const char * CXXFLAGS
OCTINTERP_API const char * GNUPLOT
OCTINTERP_API const char * FFTW3F_CPPFLAGS
OCTINTERP_API const char * F77_FLOAT_STORE_FLAG
OCTINTERP_API const char * MKOCTFILE_DL_LDFLAGS
OCTINTERP_API const char * WARN_CXXFLAGS
OCTINTERP_API const char * MAGICK_LDFLAGS
OCTINTERP_API const char * QRUPDATE_LIBS
OCTINTERP_API const char * CAMD_CPPFLAGS
Definition: build-env.in.cc:56
OCTINTERP_API const char * FFTW3_LIBS
OCTINTERP_API const char * CHOLMOD_LIBS
Definition: build-env.in.cc:78
OCTINTERP_API const char * QRUPDATE_CPPFLAGS
OCTINTERP_API const char * X11_LIBS
OCTINTERP_API const char * XTRA_CXXFLAGS
OCTINTERP_API const char * COLAMD_LDFLAGS
Definition: build-env.in.cc:82
OCTINTERP_API const char * STATIC_LIBS
OCTINTERP_API const char * FFTW3F_LDFLAGS
OCTINTERP_API const char * CURL_CPPFLAGS
Definition: build-env.in.cc:90
OCTINTERP_API const char * CURL_LIBS
Definition: build-env.in.cc:94
OCTINTERP_API const char * AR
Definition: build-env.in.cc:46
OCTINTERP_API const char * SHARED_LIBS
OCTINTERP_API const char * CCOLAMD_CPPFLAGS
Definition: build-env.in.cc:66
OCTINTERP_API const char * ARPACK_CPPFLAGS
Definition: build-env.in.cc:48
OCTINTERP_API const char * UMFPACK_CPPFLAGS
OCTINTERP_API const char * DL_LDFLAGS
OCTINTERP_API const char * OCTAVE_LINK_OPTS
OCTINTERP_API const char * COLAMD_LIBS
Definition: build-env.in.cc:84
OCTINTERP_API const char * X11_INCFLAGS
OCTINTERP_API const char * AMD_LIBS
Definition: build-env.in.cc:42
OCTINTERP_API const char * COLAMD_CPPFLAGS
Definition: build-env.in.cc:80
OCTINTERP_API const char * PTHREAD_CFLAGS
OCTINTERP_API const char * FLIBS
OCTINTERP_API const char * CXSPARSE_CPPFLAGS
Definition: build-env.in.cc:96
OCTINTERP_API const char * HDF5_LDFLAGS
OCTINTERP_API const char * GCC_VERSION
OCTINTERP_API const char * CAMD_LIBS
Definition: build-env.in.cc:60
OCTINTERP_API const char * DEFS
OCTINTERP_API const char * CXX
OCTINTERP_API const char * BLAS_LIBS
Definition: build-env.in.cc:54
OCTINTERP_API const char * FFTW3_CPPFLAGS
OCTINTERP_API const char * FLTK_CPPFLAGS
OCTINTERP_API const char * LN_S
OCTINTERP_API const char * QHULL_LIBS
OCTINTERP_API const char * CARBON_LIBS
Definition: build-env.in.cc:62
OCTINTERP_API const char * GLPK_CPPFLAGS
OCTINTERP_API const char * LEXLIB
OCTINTERP_API const char * QT_LIBS
OCTINTERP_API const char * HDF5_CPPFLAGS
OCTINTERP_API const char * ARFLAGS
Definition: build-env.in.cc:44
OCTINTERP_API const char * FLTK_LDFLAGS
OCTINTERP_API const char * CCOLAMD_LIBS
Definition: build-env.in.cc:70
OCTINTERP_API const char * LFLAGS
OCTINTERP_API const char * CPPFLAGS
Definition: build-env.in.cc:88
OCTINTERP_API const char * FPICFLAG
OCTINTERP_API const char * GXX_VERSION
OCTINTERP_API const char * PCRE_LIBS
OCTINTERP_API const char * LAPACK_LIBS
OCTINTERP_API const char * YFLAGS
OCTINTERP_API const char * SH_LDFLAGS
OCTINTERP_API const char * OPENGL_LIBS
OCTINTERP_API const char * QHULL_CPPFLAGS
OCTINTERP_API const char * UMFPACK_LDFLAGS
OCTINTERP_API const char * PTHREAD_LIBS
OCTINTERP_API const char * HDF5_LIBS
OCTINTERP_API const char * F77
OCTINTERP_API const char * FFTW3F_LIBS
OCTINTERP_API const char * CFLAGS
Definition: build-env.in.cc:72
OCTINTERP_API const char * CXSPARSE_LDFLAGS
Definition: build-env.in.cc:98
OCTINTERP_API const char * READLINE_LIBS
OCTINTERP_API const char * LD_STATIC_FLAG
OCTINTERP_API const char * GLPK_LIBS
OCTINTERP_API const char * Z_CPPFLAGS
OCTINTERP_API const char * SUITESPARSECONFIG_LIBS
OCTINTERP_API const char * RANLIB
OCTINTERP_API const char * MAGICK_CPPFLAGS
OCTINTERP_API const char * QT_CPPFLAGS
OCTINTERP_API const char * OCT_LINK_DEPS
OCTINTERP_API const char * XTRA_CFLAGS
OCTINTERP_API const char * CXXCPP
OCTINTERP_API const char * LIBOCTAVE
OCTINTERP_API const char * QHULL_LDFLAGS
OCTINTERP_API const char * AMD_CPPFLAGS
Definition: build-env.in.cc:38
OCTINTERP_API const char * config_opts
OCTINTERP_API const char * PCRE_LDFLAGS
OCTINTERP_API const char * QT_LDFLAGS
OCTINTERP_API const char * GLPK_LDFLAGS
OCTINTERP_API const char * FT2_CPPFLAGS
OCTINTERP_API const char * AMD_LDFLAGS
Definition: build-env.in.cc:40
OCTINTERP_API const char * CXSPARSE_LIBS
OCTINTERP_API const char * QT_OPENGL_LIBS
OCTINTERP_API const char * CCOLAMD_LDFLAGS
Definition: build-env.in.cc:68
OCTINTERP_API const char * CAMD_LDFLAGS
Definition: build-env.in.cc:58
OCTINTERP_API const char * PCRE_CPPFLAGS
OCTARRAY_OVERRIDABLE_FUNC_API bool isempty(void) 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:238
bool is_undefined(void) const
Definition: ov.h:640
int file_number(void) const
Definition: procstream.h:67
int close(void)
Definition: procstream.cc:62
pid_t pid(void) const
Definition: procstream.h:65
void octave_unblock_async_signals(void)
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::string local_fcn_file_dir(void)
Definition: defaults.cc:307
std::string oct_tests_dir(void)
Definition: defaults.cc:379
std::string local_ver_oct_file_dir(void)
Definition: defaults.cc:259
std::string canonical_host_type(void)
Definition: defaults.cc:135
std::string local_api_fcn_file_dir(void)
Definition: defaults.cc:299
std::string man1_dir(void)
Definition: defaults.cc:395
std::string startupfile_dir(void)
Definition: defaults.cc:426
std::string default_pager(void)
Definition: defaults.cc:150
std::string oct_doc_dir(void)
Definition: defaults.cc:331
std::string image_dir(void)
Definition: defaults.cc:410
std::string local_oct_file_dir(void)
Definition: defaults.cc:275
std::string fcn_file_dir(void)
Definition: defaults.cc:315
std::string man_dir(void)
Definition: defaults.cc:387
std::string include_dir(void)
Definition: defaults.cc:195
std::string oct_file_dir(void)
Definition: defaults.cc:283
std::string data_dir(void)
Definition: defaults.cc:179
std::string dataroot_dir(void)
Definition: defaults.cc:187
std::string man1_ext(void)
Definition: defaults.cc:403
std::string libexec_dir(void)
Definition: defaults.cc:211
std::string local_startupfile_dir(void)
Definition: defaults.cc:418
std::string info_dir(void)
Definition: defaults.cc:227
std::string oct_etc_dir(void)
Definition: defaults.cc:339
std::string local_arch_lib_dir(void)
Definition: defaults.cc:251
std::string local_ver_arch_lib_dir(void)
Definition: defaults.cc:235
std::string lib_dir(void)
Definition: defaults.cc:203
std::string local_api_arch_lib_dir(void)
Definition: defaults.cc:243
std::string oct_include_dir(void)
Definition: defaults.cc:355
std::string oct_data_dir(void)
Definition: defaults.cc:323
std::string bin_dir(void)
Definition: defaults.cc:171
std::string local_api_oct_file_dir(void)
Definition: defaults.cc:267
std::string local_ver_fcn_file_dir(void)
Definition: defaults.cc:291
std::string arch_lib_dir(void)
Definition: defaults.cc:219
std::string oct_lib_dir(void)
Definition: defaults.cc:363
std::string oct_fonts_dir(void)
Definition: defaults.cc:347
OCTINTERP_API 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:979
child_list & __get_child_list__(void)
OCTINTERP_API std::string liboctinterp_hg_id(void)
int system(const std::string &cmd_str)
Definition: lo-sysdep.cc:59
bool words_little_endian(void)
Definition: mach-info.cc:79
bool words_big_endian(void)
Definition: mach-info.cc:72
std::string float_format_as_string(float_format flt_fmt)
Definition: mach-info.cc:105
float_format native_float_format(void)
Definition: mach-info.cc:65
float_format
Definition: mach-info.h:38
#define OCTAVE_VERSION
Definition: main.in.cc:63
T octave_idx_type m
Definition: mx-inlines.cc:773
std::string fftwf_version(void)
Definition: oct-fftw.cc:1148
std::string fftw_version(void)
Definition: oct-fftw.cc:1138
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:211
#define octave_stdout
Definition: pager.h:314
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)
static octave_value_list run_command_and_return_output(const std::string &cmd_str)
Definition: toplev.cc:108
#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
static void * get_signal_mask(void)
Definition: toplev.cc:161
static void restore_signal_mask(void *mask)
Definition: toplev.cc:173
static octave_value find_config_info(const octave_scalar_map &m, const std::string &key)
Definition: toplev.cc:328
std::string octave_name_version_and_copyright(void)
Definition: version.cc:71
int octave_wait_for_input(int fid)