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