GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
toplev.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1995-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://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 "str-vec.h"
46 #include "wait-for-input.h"
47 
48 #include "build-env.h"
50 #include "call-stack.h"
51 #include "defaults.h"
52 #include "defun.h"
53 #include "error.h"
54 #include "file-io.h"
55 #include "octave.h"
56 #include "oct-map.h"
57 #include "ovl.h"
58 #include "ov.h"
59 #include "pager.h"
60 #include "procstream.h"
61 #include "sysdep.h"
62 #include "unwind-prot.h"
63 #include "utils.h"
64 #include <version.h>
65 
66 #if ! defined (SHELL_PATH)
67 # define SHELL_PATH "/bin/sh"
68 #endif
69 
70 DEFUN (warranty, , ,
71  doc: /* -*- texinfo -*-
72 @deftypefn {} {} warranty ()
73 Describe the conditions for copying and distributing Octave.
74 @end deftypefn */)
75 {
77 \n\
78 GNU Octave is free software; you can redistribute it and/or modify\n\
79 it under the terms of the GNU General Public License as published by\n\
80 the Free Software Foundation; either version 3 of the License, or\n\
81 (at your option) any later version.\n\
82 \n\
83 GNU Octave is distributed in the hope that it will be useful,\n\
84 but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
85 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
86 GNU General Public License for more details.\n\
87 \n\
88 You should have received a copy of the GNU General Public License\n\
89 along with this program. If not, see <http://www.gnu.org/licenses/>.\n\
90 \n";
91 
92  return ovl ();
93 }
94 
95 // Execute a shell command.
96 
97 static octave_value_list
99 {
102 
103  iprocstream *cmd = new iprocstream (cmd_str.c_str ());
104 
105  frame.add_delete (cmd);
106  frame.add_fcn (octave::child_list::remove, cmd->pid ());
107 
108  if (! *cmd)
109  error ("system: unable to start subprocess for '%s'", cmd_str.c_str ());
110 
111  int fid = cmd->file_number ();
112 
113  std::ostringstream output_buf;
114 
115  char ch;
116 
117  for (;;)
118  {
119  if (cmd->get (ch))
120  output_buf.put (ch);
121  else
122  {
123  if (! cmd->eof () && errno == EAGAIN)
124  {
125  cmd->clear ();
126 
127  if (octave_wait_for_input (fid) != 1)
128  break;
129  }
130  else
131  break;
132  }
133  }
134 
135  int cmd_status = cmd->close ();
136 
137  if (octave::sys::wifexited (cmd_status))
138  cmd_status = octave::sys::wexitstatus (cmd_status);
139  else
140  cmd_status = 127;
141 
142  retval = ovl (cmd_status, output_buf.str ());
143 
144  return retval;
145 }
146 
148 
150  doc: /* -*- texinfo -*-
151 @deftypefn {} {} system ("@var{string}")
152 @deftypefnx {} {} system ("@var{string}", @var{return_output})
153 @deftypefnx {} {} system ("@var{string}", @var{return_output}, @var{type})
154 @deftypefnx {} {[@var{status}, @var{output}] =} system (@dots{})
155 Execute a shell command specified by @var{string}.
156 
157 If the optional argument @var{type} is @qcode{"async"}, the process is
158 started in the background and the process ID of the child process is
159 returned immediately. Otherwise, the child process is started and Octave
160 waits until it exits. If the @var{type} argument is omitted, it defaults to
161 the value @qcode{"sync"}.
162 
163 If @var{system} is called with one or more output arguments, or if the
164 optional argument @var{return_output} is true and the subprocess is started
165 synchronously, then the output from the command is returned as a variable.
166 Otherwise, if the subprocess is executed synchronously, its output is sent
167 to the standard output. To send the output of a command executed with
168 @code{system} through the pager, use a command like
169 
170 @example
171 @group
172 [~, text] = system ("cmd");
173 disp (text);
174 @end group
175 @end example
176 
177 @noindent
178 or
179 
180 @example
181 printf ("%s\n", nthargout (2, "system", "cmd"));
182 @end example
183 
184 The @code{system} function can return two values. The first is the
185 exit status of the command and the second is any output from the
186 command that was written to the standard output stream. For example,
187 
188 @example
189 [status, output] = system ("echo foo; exit 2");
190 @end example
191 
192 @noindent
193 will set the variable @code{output} to the string @samp{foo}, and the
194 variable @code{status} to the integer @samp{2}.
195 
196 For commands run asynchronously, @var{status} is the process id of the
197 command shell that is started to run the command.
198 @seealso{unix, dos}
199 @end deftypefn */)
200 {
201  int nargin = args.length ();
202 
203  if (nargin == 0 || nargin > 3)
204  print_usage ();
205 
207  if (nargin == 3)
208  {
209  std::string type_str = args(2).xstring_value ("system: TYPE must be a string");
210 
211  if (type_str == "sync")
212  type = et_sync;
213  else if (type_str == "async")
214  type = et_async;
215  else
216  error ("system: TYPE must be \"sync\" or \"async\"");
217  }
218 
220 
221  // FIXME: Is this unwind_protect frame needed anymore (12/16/15)?
223 
224  bool return_output = (nargin == 1 && nargout > 1);
225 
226  if (nargin > 1)
227  {
228  try
229  {
230  return_output = args(1).is_true ();
231  }
232  catch (octave::execution_exception& e)
233  {
234  error (e, "system: RETURN_OUTPUT must be boolean value true or false");
235  }
236  }
237 
238  if (return_output && type == et_async)
239  error ("system: can't return output from commands run asynchronously");
240 
241  std::string cmd_str = args(0).xstring_value ("system: first argument must be a string");
242 
243 #if defined (OCTAVE_USE_WINDOWS_API)
244  // Work around weird double-quote handling on Windows systems.
245  if (type == et_sync)
246  cmd_str = "\"" + cmd_str + "\"";
247 #endif
248 
249  if (type == et_async)
250  retval(0) = octave_async_system_wrapper (cmd_str.c_str ());
251  else if (return_output)
252  retval = run_command_and_return_output (cmd_str);
253  else
254  {
255  int status = system (cmd_str.c_str ());
256 
257  // The value in status is as returned by waitpid. If
258  // the process exited normally, extract the actual exit
259  // status of the command. Otherwise, return 127 as a
260  // failure code.
261 
262  if (octave::sys::wifexited (status))
263  status = octave::sys::wexitstatus (status);
264 
265  retval(0) = status;
266  }
267 
268  return retval;
269 }
270 
271 /*
272 %!test
273 %! cmd = ls_command ();
274 %! [status, output] = system (cmd);
275 %! assert (status, 0);
276 %! assert (ischar (output));
277 %! assert (! isempty (output));
278 
279 %!error system ()
280 %!error system (1, 2, 3)
281 */
282 
283 static octave_value
284 find_config_info (const octave_scalar_map& m, const std::string& key)
285 {
286  if (m.isfield (key))
287  {
288  Cell c = m.contents (key);
289 
290  if (! c.is_empty ())
291  return c(0);
292  }
293 
294  return octave_value ();
295 }
296 
297 DEFUN (__octave_config_info__, args, ,
298  doc: /* -*- texinfo -*-
299 @deftypefn {} {} __octave_config_info__ ()
300 @deftypefnx {} {} __octave_config_info__ (@var{option})
301 Return a structure containing configuration and installation information for
302 Octave.
303 
304 If @var{option} is a string, return the configuration information for the
305 specified option.
306 
307 @seealso{computer}
308 @end deftypefn */)
309 {
310 #if defined (ENABLE_DYNAMIC_LINKING)
311  bool octave_supports_dynamic_linking = true;
312 #else
313  bool octave_supports_dynamic_linking = false;
314 #endif
315 
316  static bool initialized = false;
317 
318  struct conf_info_struct
319  {
320  const char *key;
322  };
323 
324  static const conf_info_struct conf_info[] =
325  {
326  { "DEFAULT_PAGER", OCTAVE_DEFAULT_PAGER },
327 
328 #if defined (OCTAVE_ENABLE_64)
329  { "ENABLE_64", true },
330 #else
331  { "ENABLE_64", false },
332 #endif
333 
334 #if defined (OCTAVE_ENABLE_ATOMIC_REFCOUNT)
335  { "ENABLE_ATOMIC_REFCOUNT", true },
336 #else
337  { "ENABLE_ATOMIC_REFCOUNT", false },
338 #endif
339 
340 #if defined (OCTAVE_ENABLE_BOUNDS_CHECK)
341  { "ENABLE_BOUNDS_CHECK", true },
342 #else
343  { "ENABLE_BOUNDS_CHECK", false },
344 #endif
345 
346 #if defined (ENABLE_DOCS)
347  { "ENABLE_DOCS", true },
348 #else
349  { "ENABLE_DOCS", false },
350 #endif
351 
352 #if defined (ENABLE_DYNAMIC_LINKING)
353  { "ENABLE_DYNAMIC_LINKING", true },
354 #else
355  { "ENABLE_DYNAMIC_LINKING", false },
356 #endif
357 
358 #if defined (OCTAVE_ENABLE_FLOAT_TRUNCATE)
359  { "ENABLE_FLOAT_TRUNCATE", true },
360 #else
361  { "ENABLE_FLOAT_TRUNCATE", false },
362 #endif
363 
364 #if defined (ENABLE_JIT)
365  { "ENABLE_JIT", true },
366 #else
367  { "ENABLE_JIT", false },
368 #endif
369 
370 #if defined (OCTAVE_ENABLE_OPENMP)
371  { "ENABLE_OPENMP", true },
372 #else
373  { "ENABLE_OPENMP", false },
374 #endif
375 
376  { "api_version", OCTAVE_API_VERSION },
377  { "archlibdir", subst_octave_home (OCTAVE_ARCHLIBDIR) },
378  { "bindir", subst_octave_home (OCTAVE_BINDIR) },
379  { "canonical_host_type", OCTAVE_CANONICAL_HOST_TYPE },
380  { "datadir", subst_octave_home (OCTAVE_DATADIR) },
381  { "datarootdir", subst_octave_home (OCTAVE_DATAROOTDIR) },
382  { "exec_prefix", subst_octave_home (OCTAVE_EXEC_PREFIX) },
383  { "fcnfiledir", subst_octave_home (OCTAVE_FCNFILEDIR) },
384  { "fftw_version", octave_fftw_version () },
385  { "fftwf_version", octave_fftwf_version () },
386  { "imagedir", subst_octave_home (OCTAVE_IMAGEDIR) },
387  { "includedir", subst_octave_home (OCTAVE_INCLUDEDIR) },
388  { "infodir", subst_octave_home (OCTAVE_INFODIR) },
389  { "infofile", subst_octave_home (OCTAVE_INFOFILE) },
390  { "libdir", subst_octave_home (OCTAVE_LIBDIR) },
391  { "libexecdir", subst_octave_home (OCTAVE_LIBEXECDIR) },
392  // Each library and executable has its own definition of the hg
393  // id. We check for consistency when Octave starts so we just
394  // store and report one of them here.
395  { "hg_id", liboctinterp_hg_id () },
396  { "localapiarchlibdir", subst_octave_home (OCTAVE_LOCALAPIARCHLIBDIR) },
397  { "localapifcnfiledir", subst_octave_home (OCTAVE_LOCALAPIFCNFILEDIR) },
398  { "localapioctfiledir", subst_octave_home (OCTAVE_LOCALAPIOCTFILEDIR) },
399  { "localarchlibdir", subst_octave_home (OCTAVE_LOCALARCHLIBDIR) },
400  { "localfcnfiledir", subst_octave_home (OCTAVE_LOCALFCNFILEDIR) },
401  { "localoctfiledir", subst_octave_home (OCTAVE_LOCALOCTFILEDIR) },
402  { "localstartupfiledir", subst_octave_home (OCTAVE_LOCALSTARTUPFILEDIR) },
403  { "localverarchlibdir", subst_octave_home (OCTAVE_LOCALVERARCHLIBDIR) },
404  { "localverfcnfiledir", subst_octave_home (OCTAVE_LOCALVERFCNFILEDIR) },
405  { "localveroctfiledir", subst_octave_home (OCTAVE_LOCALVEROCTFILEDIR) },
406  { "man1dir", subst_octave_home (OCTAVE_MAN1DIR) },
407  { "man1ext", OCTAVE_MAN1EXT },
408  { "mandir", subst_octave_home (OCTAVE_MANDIR) },
409  { "octdatadir", subst_octave_home (OCTAVE_OCTDATADIR) },
410  { "octfiledir", subst_octave_home (OCTAVE_OCTFILEDIR) },
411  { "octetcdir", subst_octave_home (OCTAVE_OCTETCDIR) },
412  { "octincludedir", subst_octave_home (OCTAVE_OCTINCLUDEDIR) },
413  { "octlibdir", subst_octave_home (OCTAVE_OCTLIBDIR) },
414  { "octtestsdir", subst_octave_home (OCTAVE_OCTTESTSDIR) },
415  { "prefix", subst_octave_home (OCTAVE_PREFIX) },
416  { "release_date", OCTAVE_RELEASE_DATE },
417  { "startupfiledir", subst_octave_home (OCTAVE_STARTUPFILEDIR) },
418  { "version", OCTAVE_VERSION },
419  { 0, octave_value () }
420  };
421 
422  struct build_info_struct
423  {
424  const char *key;
425  const char *val;
426  };
427 
428  static const build_info_struct build_info[] =
429  {
430  { "AMD_CPPFLAGS", octave::build_env::AMD_CPPFLAGS },
431  { "AMD_LDFLAGS", octave::build_env::AMD_LDFLAGS },
432  { "AMD_LIBS", octave::build_env::AMD_LIBS },
433  { "AR", octave::build_env::AR },
434  { "ARFLAGS", octave::build_env::ARFLAGS },
435  { "ARPACK_CPPFLAGS", octave::build_env::ARPACK_CPPFLAGS },
436  { "ARPACK_LDFLAGS", octave::build_env::ARPACK_LDFLAGS },
437  { "ARPACK_LIBS", octave::build_env::ARPACK_LIBS },
438  { "BLAS_LIBS", octave::build_env::BLAS_LIBS },
439  { "CAMD_CPPFLAGS", octave::build_env::CAMD_CPPFLAGS },
440  { "CAMD_LDFLAGS", octave::build_env::CAMD_LDFLAGS },
441  { "CAMD_LIBS", octave::build_env::CAMD_LIBS },
442  { "CARBON_LIBS", octave::build_env::CARBON_LIBS },
443  { "CC", octave::build_env::CC },
444  { "CCOLAMD_CPPFLAGS", octave::build_env::CCOLAMD_CPPFLAGS },
445  { "CCOLAMD_LDFLAGS", octave::build_env::CCOLAMD_LDFLAGS },
446  { "CCOLAMD_LIBS", octave::build_env::CCOLAMD_LIBS },
447  { "CFLAGS", octave::build_env::CFLAGS },
448  { "CHOLMOD_CPPFLAGS", octave::build_env::CHOLMOD_CPPFLAGS },
449  { "CHOLMOD_LDFLAGS", octave::build_env::CHOLMOD_LDFLAGS },
450  { "CHOLMOD_LIBS", octave::build_env::CHOLMOD_LIBS },
451  { "COLAMD_CPPFLAGS", octave::build_env::COLAMD_CPPFLAGS },
452  { "COLAMD_LDFLAGS", octave::build_env::COLAMD_LDFLAGS },
453  { "COLAMD_LIBS", octave::build_env::COLAMD_LIBS },
454  { "CPICFLAG", octave::build_env::CPICFLAG },
455  { "CPPFLAGS", octave::build_env::CPPFLAGS },
456  { "CURL_CPPFLAGS", octave::build_env::CURL_CPPFLAGS },
457  { "CURL_LDFLAGS", octave::build_env::CURL_LDFLAGS },
458  { "CURL_LIBS", octave::build_env::CURL_LIBS },
459  { "CXSPARSE_CPPFLAGS", octave::build_env::CXSPARSE_CPPFLAGS },
460  { "CXSPARSE_LDFLAGS", octave::build_env::CXSPARSE_LDFLAGS },
461  { "CXSPARSE_LIBS", octave::build_env::CXSPARSE_LIBS },
462  { "CXX", octave::build_env::CXX },
463  { "CXXCPP", octave::build_env::CXXCPP },
464  { "CXXFLAGS", octave::build_env::CXXFLAGS },
465  { "CXXPICFLAG", octave::build_env::CXXPICFLAG },
466  { "DEFS", octave::build_env::DEFS },
467  { "DL_LD", octave::build_env::DL_LD },
468  { "DL_LDFLAGS", octave::build_env::DL_LDFLAGS },
469  { "DL_LIBS", octave::build_env::DL_LIBS },
470  { "GCC_VERSION", octave::build_env::GCC_VERSION },
471  { "GXX_VERSION", octave::build_env::GXX_VERSION },
472  { "EXEEXT", octave::build_env::EXEEXT },
473  { "F77", octave::build_env::F77 },
474  { "F77_FLOAT_STORE_FLAG", octave::build_env::F77_FLOAT_STORE_FLAG },
475  { "F77_INTEGER_8_FLAG", octave::build_env::F77_INTEGER_8_FLAG },
476  { "FFLAGS", octave::build_env::FFLAGS },
477  { "FFTW3_CPPFLAGS", octave::build_env::FFTW3_CPPFLAGS },
478  { "FFTW3_LDFLAGS", octave::build_env::FFTW3_LDFLAGS },
479  { "FFTW3_LIBS", octave::build_env::FFTW3_LIBS },
480  { "FFTW3F_CPPFLAGS", octave::build_env::FFTW3F_CPPFLAGS },
481  { "FFTW3F_LDFLAGS", octave::build_env::FFTW3F_LDFLAGS },
482  { "FFTW3F_LIBS", octave::build_env::FFTW3F_LIBS },
483  { "FLIBS", octave::build_env::FLIBS },
484  { "FLTK_CPPFLAGS", octave::build_env::FLTK_CPPFLAGS },
485  { "FLTK_LDFLAGS", octave::build_env::FLTK_LDFLAGS },
486  { "FLTK_LIBS", octave::build_env::FLTK_LIBS },
487  { "FONTCONFIG_CPPFLAGS", octave::build_env::FONTCONFIG_CPPFLAGS },
488  { "FONTCONFIG_LIBS", octave::build_env::FONTCONFIG_LIBS },
489  { "FPICFLAG", octave::build_env::FPICFLAG },
490  { "FT2_CPPFLAGS", octave::build_env::FT2_CPPFLAGS },
491  { "FT2_LIBS", octave::build_env::FT2_LIBS },
492  { "GLPK_CPPFLAGS", octave::build_env::GLPK_CPPFLAGS },
493  { "GLPK_LDFLAGS", octave::build_env::GLPK_LDFLAGS },
494  { "GLPK_LIBS", octave::build_env::GLPK_LIBS },
495  { "GNUPLOT", octave::build_env::GNUPLOT },
496  { "HDF5_CPPFLAGS", octave::build_env::HDF5_CPPFLAGS },
497  { "HDF5_LDFLAGS", octave::build_env::HDF5_LDFLAGS },
498  { "HDF5_LIBS", octave::build_env::HDF5_LIBS },
499  { "LAPACK_LIBS", octave::build_env::LAPACK_LIBS },
500  { "LDFLAGS", octave::build_env::LDFLAGS },
501  { "LD_CXX", octave::build_env::LD_CXX },
502  { "LD_STATIC_FLAG", octave::build_env::LD_STATIC_FLAG },
503  { "LEX", octave::build_env::LEX },
504  { "LEXLIB", octave::build_env::LEXLIB },
505  { "LFLAGS", octave::build_env::LFLAGS },
506  { "LIBOCTAVE", octave::build_env::LIBOCTAVE },
507  { "LIBOCTINTERP", octave::build_env::LIBOCTINTERP },
508  { "LIBS", octave::build_env::LIBS },
509  { "LLVM_CPPFLAGS", octave::build_env::LLVM_CPPFLAGS },
510  { "LLVM_LDFLAGS", octave::build_env::LLVM_LDFLAGS },
511  { "LLVM_LIBS", octave::build_env::LLVM_LIBS },
512  { "LN_S", octave::build_env::LN_S },
513  { "MAGICK_CPPFLAGS", octave::build_env::MAGICK_CPPFLAGS },
514  { "MAGICK_LDFLAGS", octave::build_env::MAGICK_LDFLAGS },
515  { "MAGICK_LIBS", octave::build_env::MAGICK_LIBS },
516  { "MKOCTFILE_DL_LDFLAGS", octave::build_env::MKOCTFILE_DL_LDFLAGS },
517  { "OCTAVE_LINK_DEPS", octave::build_env::OCTAVE_LINK_DEPS },
518  { "OCTAVE_LINK_OPTS", octave::build_env::OCTAVE_LINK_OPTS },
519  { "OCT_LINK_DEPS", octave::build_env::OCT_LINK_DEPS },
520  { "OCT_LINK_OPTS", octave::build_env::OCT_LINK_OPTS },
521  { "OPENGL_LIBS", octave::build_env::OPENGL_LIBS },
522  { "OSMESA_CPPFLAGS", octave::build_env::OSMESA_CPPFLAGS },
523  { "OSMESA_LDFLAGS", octave::build_env::OSMESA_LDFLAGS },
524  { "OSMESA_LIBS", octave::build_env::OSMESA_LIBS },
525  { "PCRE_CPPFLAGS", octave::build_env::PCRE_CPPFLAGS },
526  { "PCRE_LIBS", octave::build_env::PCRE_LIBS },
527  { "PTHREAD_CFLAGS", octave::build_env::PTHREAD_CFLAGS },
528  { "PTHREAD_LIBS", octave::build_env::PTHREAD_LIBS },
529  { "QHULL_CPPFLAGS", octave::build_env::QHULL_CPPFLAGS },
530  { "QHULL_LDFLAGS", octave::build_env::QHULL_LDFLAGS },
531  { "QHULL_LIBS", octave::build_env::QHULL_LIBS },
532  { "QRUPDATE_CPPFLAGS", octave::build_env::QRUPDATE_CPPFLAGS },
533  { "QRUPDATE_LDFLAGS", octave::build_env::QRUPDATE_LDFLAGS },
534  { "QRUPDATE_LIBS", octave::build_env::QRUPDATE_LIBS },
535  { "QT_CPPFLAGS", octave::build_env::QT_CPPFLAGS },
536  { "QT_LDFLAGS", octave::build_env::QT_LDFLAGS },
537  { "QT_LIBS", octave::build_env::QT_LIBS },
538  { "RANLIB", octave::build_env::RANLIB },
539  { "RDYNAMIC_FLAG", octave::build_env::RDYNAMIC_FLAG },
540  { "READLINE_LIBS", octave::build_env::READLINE_LIBS },
541  { "SED", octave::build_env::SED },
542  { "SHARED_LIBS", octave::build_env::SHARED_LIBS },
543  { "SH_LD", octave::build_env::SH_LD },
544  { "SH_LDFLAGS", octave::build_env::SH_LDFLAGS },
545  { "STATIC_LIBS", octave::build_env::STATIC_LIBS },
546  { "SUITESPARSE_CONFIG_LIBS", octave::build_env::SUITESPARSE_CONFIG_LIBS },
547  { "TERM_LIBS", octave::build_env::TERM_LIBS },
548  { "UMFPACK_CPPFLAGS", octave::build_env::UMFPACK_CPPFLAGS },
549  { "UMFPACK_LDFLAGS", octave::build_env::UMFPACK_LDFLAGS },
550  { "UMFPACK_LIBS", octave::build_env::UMFPACK_LIBS },
551  { "WARN_CFLAGS", octave::build_env::WARN_CFLAGS },
552  { "WARN_CXXFLAGS", octave::build_env::WARN_CXXFLAGS },
553  { "X11_INCFLAGS", octave::build_env::X11_INCFLAGS },
554  { "X11_LIBS", octave::build_env::X11_LIBS },
555  { "XTRA_CFLAGS", octave::build_env::XTRA_CFLAGS },
556  { "XTRA_CXXFLAGS", octave::build_env::XTRA_CXXFLAGS },
557  { "YACC", octave::build_env::YACC },
558  { "YFLAGS", octave::build_env::YFLAGS },
559  { "Z_CPPFLAGS", octave::build_env::Z_CPPFLAGS },
560  { "Z_LDFLAGS", octave::build_env::Z_LDFLAGS },
561  { "Z_LIBS", octave::build_env::Z_LIBS },
562  { "config_opts", octave::build_env::config_opts },
563  { 0, 0 },
564  };
565 
566  static octave_scalar_map config;
567  static octave_scalar_map build_env;
568  static octave_scalar_map build_features = octave::build_env::features ();
569 
570  if (! initialized)
571  {
572  int i;
573 
574  i = 0;
575  while (true)
576  {
577  const build_info_struct& elt = build_info[i++];
578 
579  const char *key = elt.key;
580 
581  if (key)
582  build_env.assign (key, elt.val);
583  else
584  break;
585  }
586 
587  i = 0;
588  while (true)
589  {
590  const conf_info_struct& elt = conf_info[i++];
591 
592  const char *key = elt.key;
593 
594  if (key)
595  config.assign (key, elt.val);
596  else
597  break;
598  }
599 
600  bool unix_system = true;
601  bool mac_system = false;
602  bool windows_system = false;
603 
604 #if defined (__WIN32__)
605  windows_system = true;
606 #if ! defined (__CYGWIN__)
607  unix_system = false;
608 #endif
609 #endif
610 
611 #if defined (OCTAVE_USE_OS_X_API)
612  mac_system = true;
613 #endif
614 
615  config.assign ("unix", octave_value (unix_system));
616  config.assign ("mac", octave_value (mac_system));
617  config.assign ("windows", octave_value (windows_system));
618 
619  config.assign ("dld", octave_value (octave_supports_dynamic_linking));
620 
622  config.assign ("float_format",
624 
625  config.assign ("words_big_endian",
627 
628  config.assign ("words_little_endian",
630 
631  config.assign ("build_environment", octave_value (build_env));
632 
633  config.assign ("build_features", octave_value (build_features));
634 
635  initialized = true;
636  }
637 
638  int nargin = args.length ();
639 
640  if (nargin > 1)
641  print_usage ();
642 
644 
645  if (nargin == 1)
646  {
647  std::string arg = args(0).xstring_value ("__octave_config_info__: OPTION argument must be a string");
648 
649  octave_value info = find_config_info (config, arg);
650 
651  if (info.is_undefined ())
652  info = find_config_info (build_env, arg);
653 
654  if (info.is_undefined ())
655  info = find_config_info (build_features, arg);
656 
657  if (info.is_undefined ())
658  error ("__octave_config_info__: no info for '%s'", arg.c_str ());
659 
660  return info;
661  }
662  else
663  retval = ovl (config);
664 
665  return retval;
666 }
667 
668 /*
669 %!assert (ischar (__octave_config_info__ ("version")))
670 %!assert (__octave_config_info__ ("version"), OCTAVE_VERSION ())
671 %!test
672 %! x = __octave_config_info__ ();
673 %! assert (isstruct (x));
674 %! assert (! isempty (x));
675 %! assert (x.version, OCTAVE_VERSION ());
676 
677 %!error __octave_config_info__ (1, 2)
678 */
679 
680 #if defined (__GNUG__) && defined (DEBUG_NEW_DELETE)
681 
682 int debug_new_delete = 0;
683 
684 typedef void (*vfp)(void);
685 extern vfp __new_handler;
686 
687 void *
688 __builtin_new (size_t sz)
689 {
690  void *p;
691 
692  // malloc (0) is unpredictable; avoid it.
693  if (sz == 0)
694  sz = 1;
695  p = std::malloc (sz);
696  while (p == 0)
697  {
698  (*__new_handler) ();
699  p = std::malloc (sz);
700  }
701 
702  if (debug_new_delete)
703  std::cerr << "__builtin_new: " << p << std::endl;
704 
705  return p;
706 }
707 
708 void
709 __builtin_delete (void *ptr)
710 {
711  if (debug_new_delete)
712  std::cerr << "__builtin_delete: " << ptr << std::endl;
713 
714  if (ptr)
715  free (ptr);
716 }
717 
718 #endif
const char * CXXPICFLAG
Definition: build-env.cc:102
#define OCTAVE_FCNFILEDIR
Definition: defaults.h:70
const char * SED
Definition: build-env.cc:266
const char * RDYNAMIC_FLAG
Definition: build-env.cc:262
const char * OSMESA_CPPFLAGS
Definition: build-env.cc:226
bool is_empty(void) const
Definition: Array.h:575
const char * UMFPACK_LDFLAGS
Definition: build-env.cc:282
const char * X11_INCFLAGS
Definition: build-env.cc:290
bool isfield(const std::string &name) const
Definition: oct-map.h:206
Definition: Cell.h:37
const char * YACC
Definition: build-env.cc:298
const char * LIBOCTAVE
Definition: build-env.cc:190
#define OCTAVE_DATADIR
Definition: defaults.h:50
const char * MAGICK_CPPFLAGS
Definition: build-env.cc:198
const char * DL_LIBS
Definition: build-env.cc:114
const char * QT_LIBS
Definition: build-env.cc:258
const char * FLTK_LDFLAGS
Definition: build-env.cc:146
const char * OPENGL_LIBS
Definition: build-env.cc:224
const char * FFTW3_CPPFLAGS
Definition: build-env.cc:130
#define OCTAVE_LOCALVEROCTFILEDIR
Definition: defaults.h:138
const char * SH_LD
Definition: build-env.cc:270
const char * F77
Definition: build-env.cc:122
static std::string subst_octave_home(const std::string &s)
Definition: shared-fcns.h:100
const char * CAMD_LIBS
Definition: build-env.cc:56
const char * LIBOCTINTERP
Definition: build-env.cc:192
std::string liboctinterp_hg_id(void)
OCTAVE_EXPORT octave_value_list isa nd deftypefn *return ovl(args(0).is_integer_type())
const char * GLPK_LIBS
Definition: build-env.cc:164
OCTINTERP_API void print_usage(void)
Definition: defun.cc:52
const char * UMFPACK_CPPFLAGS
Definition: build-env.cc:280
const char * F77_FLOAT_STORE_FLAG
Definition: build-env.cc:124
const char * SUITESPARSE_CONFIG_LIBS
Definition: build-env.cc:276
#define OCTAVE_LOCALFCNFILEDIR
Definition: defaults.h:114
const char * SH_LDFLAGS
Definition: build-env.cc:272
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
const char * LLVM_LDFLAGS
Definition: build-env.cc:206
const octave_value & contents(const_iterator p) const
Definition: oct-map.h:190
const char * Z_LIBS
Definition: build-env.cc:306
#define OCTAVE_OCTETCDIR
Definition: defaults.h:162
octave_scalar_map features(void)
const char * CC
Definition: build-env.cc:60
#define OCTAVE_LOCALSTARTUPFILEDIR
Definition: defaults.h:122
const char * COLAMD_LDFLAGS
Definition: build-env.cc:78
const char * OSMESA_LDFLAGS
Definition: build-env.cc:228
const char * OSMESA_LIBS
Definition: build-env.cc:230
static void remove(pid_t pid)
Definition: child-list.cc:91
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
const char * F77_INTEGER_8_FLAG
Definition: build-env.cc:126
const char * QHULL_LDFLAGS
Definition: build-env.cc:244
#define OCTAVE_LOCALARCHLIBDIR
Definition: defaults.h:110
const char * config_opts
Definition: build-env.cc:308
void error(const char *fmt,...)
Definition: error.cc:570
const char * QRUPDATE_CPPFLAGS
Definition: build-env.cc:248
const char * SHARED_LIBS
Definition: build-env.cc:268
#define OCTAVE_INFOFILE
Definition: defaults.h:86
const char * FFTW3F_LDFLAGS
Definition: build-env.cc:138
const char * PTHREAD_CFLAGS
Definition: build-env.cc:238
const char * LIBS
Definition: build-env.cc:194
#define OCTAVE_STARTUPFILEDIR
Definition: defaults.h:186
#define OCTAVE_OCTTESTSDIR
Definition: defaults.h:178
const char * FONTCONFIG_LIBS
Definition: build-env.cc:152
const char * PCRE_LIBS
Definition: build-env.cc:234
#define OCTAVE_OCTFILEDIR
Definition: defaults.h:158
const char * LLVM_CPPFLAGS
Definition: build-env.cc:204
const char * MAGICK_LIBS
Definition: build-env.cc:202
const char * FFLAGS
Definition: build-env.cc:128
const char * OCTAVE_LINK_DEPS
Definition: build-env.cc:212
#define OCTAVE_API_VERSION
Definition: version.h:45
EAGAIN
Definition: syscalls.cc:248
#define OCTAVE_ARCHLIBDIR
Definition: main.cc:53
const char * CHOLMOD_CPPFLAGS
Definition: build-env.cc:70
const char * FFTW3F_LIBS
Definition: build-env.cc:140
const char * Z_CPPFLAGS
Definition: build-env.cc:302
const char * FONTCONFIG_CPPFLAGS
Definition: build-env.cc:150
#define OCTAVE_CANONICAL_HOST_TYPE
Definition: defaults.h:34
i e
Definition: data.cc:2724
const char * XTRA_CFLAGS
Definition: build-env.cc:294
const char * CURL_LIBS
Definition: build-env.cc:90
const char * CXSPARSE_CPPFLAGS
Definition: build-env.cc:92
const char * CPPFLAGS
Definition: build-env.cc:84
const char * XTRA_CXXFLAGS
Definition: build-env.cc:296
static bool words_little_endian(void)
Definition: mach-info.cc:176
octave_value arg
Definition: pr-output.cc:3440
const char * CXXCPP
Definition: build-env.cc:98
const char * QRUPDATE_LDFLAGS
Definition: build-env.cc:250
const char * CURL_LDFLAGS
Definition: build-env.cc:88
const char * AMD_LIBS
Definition: build-env.cc:38
#define OCTAVE_DATAROOTDIR
Definition: defaults.h:54
const char * CCOLAMD_CPPFLAGS
Definition: build-env.cc:62
const char * OCTAVE_LINK_OPTS
Definition: build-env.cc:214
const char * LLVM_LIBS
Definition: build-env.cc:208
int close(void)
Definition: procstream.cc:57
const char * LEX
Definition: build-env.cc:186
#define OCTAVE_MAN1DIR
Definition: defaults.h:142
const char * CXSPARSE_LIBS
Definition: build-env.cc:96
#define OCTAVE_PREFIX
Definition: main.cc:61
const char * COLAMD_LIBS
Definition: build-env.cc:80
#define OCTAVE_RELEASE_DATE
Definition: version.h:47
const char * GCC_VERSION
Definition: build-env.cc:118
#define OCTAVE_OCTLIBDIR
Definition: defaults.h:174
JNIEnv void * args
Definition: ov-java.cc:67
const char * CXSPARSE_LDFLAGS
Definition: build-env.cc:94
const char * LDFLAGS
Definition: build-env.cc:178
pid_t octave_async_system_wrapper(const char *cmd)
const char * DEFS
Definition: build-env.cc:108
#define OCTAVE_MANDIR
Definition: defaults.h:150
const char * X11_LIBS
Definition: build-env.cc:292
const char * FT2_CPPFLAGS
Definition: build-env.cc:156
void add_delete(T *obj)
const char * FFTW3_LDFLAGS
Definition: build-env.cc:132
const char * CAMD_CPPFLAGS
Definition: build-env.cc:52
const char * WARN_CFLAGS
Definition: build-env.cc:286
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:935
void add_fcn(void(*fcn)(void))
const char * LD_STATIC_FLAG
Definition: build-env.cc:182
#define OCTAVE_DEFAULT_PAGER
Definition: defaults.h:38
const char * OCT_LINK_DEPS
Definition: build-env.cc:220
static bool words_big_endian(void)
Definition: mach-info.cc:169
const char * LFLAGS
Definition: build-env.cc:188
const char * FLIBS
Definition: build-env.cc:142
std::string octave_fftwf_version(void)
Definition: oct-fftw.cc:1148
const char * CXXFLAGS
Definition: build-env.cc:100
nd deftypefn *octave_map m
Definition: ov-struct.cc:2058
const char * OCT_LINK_OPTS
Definition: build-env.cc:222
int nargin
Definition: graphics.cc:10115
const char * ARPACK_LIBS
Definition: build-env.cc:48
const char * FT2_LIBS
Definition: build-env.cc:158
const char * ARPACK_CPPFLAGS
Definition: build-env.cc:44
int wexitstatus(int status)
#define OCTAVE_INCLUDEDIR
Definition: defaults.h:78
const char * HDF5_CPPFLAGS
Definition: build-env.cc:168
const char * AMD_CPPFLAGS
Definition: build-env.cc:34
const char * HDF5_LDFLAGS
Definition: build-env.cc:170
const char * CHOLMOD_LIBS
Definition: build-env.cc:74
const char * HDF5_LIBS
Definition: build-env.cc:172
const char * CCOLAMD_LIBS
Definition: build-env.cc:66
#define OCTAVE_BINDIR
Definition: main.cc:57
const char * GNUPLOT
Definition: build-env.cc:166
octave_value retval
Definition: data.cc:6294
#define OCTAVE_IMAGEDIR
Definition: defaults.h:74
const char * QRUPDATE_LIBS
Definition: build-env.cc:252
idx type
Definition: ov.cc:3129
static std::string float_format_as_string(float_format)
Definition: mach-info.cc:202
#define OCTAVE_LOCALAPIFCNFILEDIR
Definition: defaults.h:102
sz
Definition: data.cc:5342
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
Definition: lu.cc:138
#define OCTAVE_LOCALOCTFILEDIR
Definition: defaults.h:118
#define OCTAVE_LOCALVERARCHLIBDIR
Definition: defaults.h:130
#define OCTAVE_LIBDIR
Definition: defaults.h:90
const char * LEXLIB
Definition: build-env.cc:184
const char * CURL_CPPFLAGS
Definition: build-env.cc:86
bool wifexited(int status)
#define OCTAVE_VERSION
Definition: main.cc:49
const char * BLAS_LIBS
Definition: build-env.cc:50
const char * STATIC_LIBS
Definition: build-env.cc:274
const char * ARFLAGS
Definition: build-env.cc:40
const char * FFTW3_LIBS
Definition: build-env.cc:134
static float_format native_float_format(void)
Definition: mach-info.cc:162
const char * UMFPACK_LIBS
Definition: build-env.cc:284
octave::unwind_protect frame
Definition: graphics.cc:11584
#define OCTAVE_OCTDATADIR
Definition: defaults.h:154
const char * LN_S
Definition: build-env.cc:196
#define OCTAVE_LOCALAPIOCTFILEDIR
Definition: defaults.h:106
const char * EXEEXT
Definition: build-env.cc:116
const char * MAGICK_LDFLAGS
Definition: build-env.cc:200
pid_t pid(void) const
Definition: procstream.h:59
const char * GLPK_LDFLAGS
Definition: build-env.cc:162
const char * CAMD_LDFLAGS
Definition: build-env.cc:54
const char * PCRE_CPPFLAGS
Definition: build-env.cc:232
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 text mode reading and writing automatically converts linefeeds to the appropriate line end character for the system(carriage-return linefeed on Windows, carriage-return on Macintosh).The default when no mode is specified is binary mode.Additionally
#define octave_stdout
Definition: pager.h:146
static octave_value_list run_command_and_return_output(const std::string &cmd_str)
Definition: toplev.cc:98
const char * ARPACK_LDFLAGS
Definition: build-env.cc:46
const char * Z_LDFLAGS
Definition: build-env.cc:304
std::string octave_fftw_version(void)
Definition: oct-fftw.cc:1138
int octave_wait_for_input(int fid)
const char * CPICFLAG
Definition: build-env.cc:82
void free(void *)
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
#define OCTAVE_EXEC_PREFIX
Definition: defaults.h:66
p
Definition: lu.cc:138
void assign(const std::string &k, const octave_value &val)
Definition: oct-map.h:223
const char * CFLAGS
Definition: build-env.cc:68
const char * LAPACK_LIBS
Definition: build-env.cc:176
const char * CARBON_LIBS
Definition: build-env.cc:58
const char * QHULL_LIBS
Definition: build-env.cc:246
#define OCTAVE_MAN1EXT
Definition: defaults.h:146
const char * CCOLAMD_LDFLAGS
Definition: build-env.cc:64
bool is_undefined(void) const
Definition: ov.h:539
std::string octave_name_version_and_copyright(void)
Definition: version.cc:69
const char * MKOCTFILE_DL_LDFLAGS
Definition: build-env.cc:210
const char * DL_LD
Definition: build-env.cc:110
const char * FPICFLAG
Definition: build-env.cc:154
const char * AR
Definition: build-env.cc:42
const char * READLINE_LIBS
Definition: build-env.cc:264
const char * RANLIB
Definition: build-env.cc:260
#define OCTAVE_OCTINCLUDEDIR
Definition: defaults.h:170
const char * FFTW3F_CPPFLAGS
Definition: build-env.cc:136
#define OCTAVE_LOCALAPIARCHLIBDIR
Definition: defaults.h:126
void * malloc(size_t)
const char * GXX_VERSION
Definition: build-env.cc:120
const char * QHULL_CPPFLAGS
Definition: build-env.cc:242
#define OCTAVE_LIBEXECDIR
Definition: defaults.h:94
const char * WARN_CXXFLAGS
Definition: build-env.cc:288
const char * GLPK_CPPFLAGS
Definition: build-env.cc:160
const char * YFLAGS
Definition: build-env.cc:300
const char * CXX
Definition: build-env.cc:104
const char * TERM_LIBS
Definition: build-env.cc:278
const char * AMD_LDFLAGS
Definition: build-env.cc:36
system_exec_type
Definition: toplev.cc:147
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:854
const char * FLTK_CPPFLAGS
Definition: build-env.cc:144
const char * CHOLMOD_LDFLAGS
Definition: build-env.cc:72
int file_number(void) const
Definition: procstream.h:61
const char * FLTK_LIBS
Definition: build-env.cc:148
#define OCTAVE_LOCALVERFCNFILEDIR
Definition: defaults.h:134
const char * PTHREAD_LIBS
Definition: build-env.cc:240
const char * QT_CPPFLAGS
Definition: build-env.cc:254
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
const char * LD_CXX
Definition: build-env.cc:180
const char * COLAMD_CPPFLAGS
Definition: build-env.cc:76
const char * QT_LDFLAGS
Definition: build-env.cc:256
const char * DL_LDFLAGS
Definition: build-env.cc:112
#define OCTAVE_INFODIR
Definition: defaults.h:82