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
sysdep.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-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 <cfloat>
28 #include <cstddef>
29 #include <cstdio>
30 #include <cstdlib>
31 #include <cstring>
32 
33 #include <iostream>
34 #include <string>
35 
36 #if defined (HAVE_TERMIOS_H)
37 # include <termios.h>
38 #elif defined (HAVE_TERMIO_H)
39 # include <termio.h>
40 #elif defined (HAVE_SGTTY_H)
41 # include <sgtty.h>
42 #endif
43 
44 #if defined (HAVE_CONIO_H)
45 # include <conio.h>
46 #endif
47 
48 #if defined (HAVE_SYS_IOCTL_H)
49 # include <sys/ioctl.h>
50 #endif
51 
52 #if defined (HAVE_FLOATINGPOINT_H)
53 # include <floatingpoint.h>
54 #endif
55 
56 #if defined (HAVE_IEEEFP_H)
57 # include <ieeefp.h>
58 #endif
59 
60 #if defined (HAVE_OMP_H)
61 # include <omp.h>
62 #endif
63 
64 #include "cmd-edit.h"
65 #include "file-ops.h"
66 #include "lo-mappers.h"
67 #include "lo-math.h"
68 #include "mach-info.h"
69 #include "oct-env.h"
70 #include "quit.h"
71 #include "unistd-wrappers.h"
72 #include "unsetenv-wrapper.h"
73 
74 #include "builtin-defun-decls.h"
75 #include "Cell.h"
76 #include "defun.h"
77 #include "display.h"
78 #include "error.h"
79 #include "errwarn.h"
80 #include "input.h"
81 #include "octave.h"
82 #include "ov.h"
83 #include "ovl.h"
84 #include "pager.h"
85 #include "parse.h"
86 #include "sighandlers.h"
87 #include "sysdep.h"
88 #include "interpreter.h"
89 #include "utils.h"
90 #include "file-stat.h"
91 
92 #if ! defined (STDIN_FILENO)
93 # define STDIN_FILENO 1
94 #endif
95 
96 #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__)
97 static void
98 BSD_init (void)
99 {
100 # if defined (HAVE_FLOATINGPOINT_H)
101  // Disable trapping on common exceptions.
102 # if ! defined (FP_X_DNML)
103 # define FP_X_DNML 0
104 # endif
105  fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP));
106 # endif
107 }
108 #endif
109 
110 #if defined (__MINGW32__) || defined (_MSC_VER)
111 
112 #define WIN32_LEAN_AND_MEAN
113 #include <windows.h>
114 #include <tlhelp32.h>
115 #include <shellapi.h>
116 
117 static void
118 w32_set_octave_home (void)
119 {
120  std::string bin_dir;
121 
122  HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE
123 #if defined (TH32CS_SNAPMODULE32)
124  | TH32CS_SNAPMODULE32
125 #endif
126  , 0);
127 
128  if (h != INVALID_HANDLE_VALUE)
129  {
130  MODULEENTRY32 mod_info;
131 
132  ZeroMemory (&mod_info, sizeof (mod_info));
133  mod_info.dwSize = sizeof (mod_info);
134 
135  if (Module32First (h, &mod_info))
136  {
137  do
138  {
139  std::string mod_name (mod_info.szModule);
140 
141  if (mod_name.find ("octinterp") != std::string::npos)
142  {
143  bin_dir = mod_info.szExePath;
144  if (bin_dir[bin_dir.length () - 1] != '\\')
145  bin_dir.append (1, '\\');
146  break;
147  }
148  }
149  while (Module32Next (h, &mod_info));
150  }
151 
152  CloseHandle (h);
153  }
154 
155  if (! bin_dir.empty ())
156  {
157  size_t pos = bin_dir.rfind ("\\bin\\");
158 
159  if (pos != std::string::npos)
160  octave::sys::env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos));
161  }
162 }
163 
164 static void
165 w32_init (void)
166 {
167  w32_set_octave_home ();
168 
170 }
171 
172 static bool
173 w32_shell_execute (const std::string& file)
174 { }
175 
176 #endif
177 
178 // Set app id if we have the SetCurrentProcessExplicitAppUserModelID
179 // available (>= Win7). FIXME: Could we check for existence of this
180 // function in the configure script instead of dynamically loading
181 // shell32.dll?
182 
183 void
185 {
186 #if defined (__MINGW32__) || defined (_MSC_VER)
187 
188  typedef HRESULT (WINAPI *SETCURRENTAPPID)(PCWSTR AppID);
189 
190  HMODULE hShell = LoadLibrary ("shell32.dll");
191 
192  if (hShell != NULL)
193  {
194  SETCURRENTAPPID pfnSetCurrentProcessExplicitAppUserModelID =
195  reinterpret_cast<SETCURRENTAPPID> (GetProcAddress (hShell,
196  "SetCurrentProcessExplicitAppUserModelID"));
197 
198  if (pfnSetCurrentProcessExplicitAppUserModelID)
199  pfnSetCurrentProcessExplicitAppUserModelID (L"gnu.octave");
200 
201  FreeLibrary (hShell);
202  }
203 
204 #endif
205 }
206 
207 DEFUN (__open_with_system_app__, args, ,
208  doc: /* -*- texinfo -*-
209 @deftypefn {} {} __open_with_system_app__ (@var{file})
210 Undocumented internal function.
211 @end deftypefn */)
212 {
213  if (args.length () != 1)
214  print_usage ();
215 
216  std::string file = args(0).xstring_value ("__open_with_system_app__: argument must be a filename");
217 
219 
220 #if defined (OCTAVE_USE_WINDOWS_API)
221  HINSTANCE status = ShellExecute (0, 0, file.c_str (), 0, 0,
222  SW_SHOWNORMAL);
223 
224  // ShellExecute returns a value greater than 32 if successful.
225  retval = (reinterpret_cast<ptrdiff_t> (status) > 32);
226 #elif defined (__APPLE__)
228  = Fsystem (ovl ("open " + file + " 2> /dev/null",
229  false, "async"),
230  1);
231 
232  retval = (tmp(0).double_value () == 0);
233 #else
235  = Fsystem (ovl ("xdg-open " + file + " 2> /dev/null",
236  false, "async"),
237  1);
238 
239  retval = (tmp(0).double_value () == 0);
240 #endif
241 
242  return retval;
243 }
244 
245 #if defined (__MINGW32__)
246 static void
247 MINGW_init (void)
248 {
249  w32_init ();
250 }
251 #endif
252 
253 #if defined (_MSC_VER)
254 static void
255 MSVC_init (void)
256 {
257  w32_init ();
258 }
259 #endif
260 
261 // Return TRUE if FILE1 and FILE2 refer to the same (physical) file.
262 
263 bool
264 same_file_internal (const std::string& file1, const std::string& file2)
265 {
266 #if defined (OCTAVE_USE_WINDOWS_API)
267 
268  bool retval = false;
269 
270  const char *f1 = file1.c_str ();
271  const char *f2 = file2.c_str ();
272 
273  bool f1_is_dir = GetFileAttributes (f1) & FILE_ATTRIBUTE_DIRECTORY;
274  bool f2_is_dir = GetFileAttributes (f2) & FILE_ATTRIBUTE_DIRECTORY;
275 
276  // Windows native code
277  // Reference: http://msdn2.microsoft.com/en-us/library/aa363788.aspx
278 
279  DWORD share = FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE;
280 
281  HANDLE hfile1
282  = CreateFile (f1, 0, share, 0, OPEN_EXISTING,
283  f1_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0);
284 
285  if (hfile1 != INVALID_HANDLE_VALUE)
286  {
287  HANDLE hfile2
288  = CreateFile (f2, 0, share, 0, OPEN_EXISTING,
289  f2_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0);
290 
291  if (hfile2 != INVALID_HANDLE_VALUE)
292  {
293  BY_HANDLE_FILE_INFORMATION hfi1;
294  BY_HANDLE_FILE_INFORMATION hfi2;
295 
296  if (GetFileInformationByHandle (hfile1, &hfi1)
297  && GetFileInformationByHandle (hfile2, &hfi2))
298  {
299  retval = (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber
300  && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh
301  && hfi1.nFileIndexLow == hfi2.nFileIndexLow);
302  }
303 
304  CloseHandle (hfile2);
305  }
306 
307  CloseHandle (hfile1);
308  }
309 
310  return retval;
311 
312 #else
313 
314  // POSIX Code
315 
316  octave::sys::file_stat fs_file1 (file1);
317  octave::sys::file_stat fs_file2 (file2);
318 
319  return (fs_file1 && fs_file2
320  && fs_file1.ino () == fs_file2.ino ()
321  && fs_file1.dev () == fs_file2.dev ());
322 
323 #endif
324 }
325 
326 void
328 {
329  // Use a function from libgomp to force loading of OpenMP library.
330  // Otherwise, a dynamically loaded library making use of OpenMP such
331  // as GraphicsMagick will segfault on exit (bug #41699).
332 #if defined (HAVE_OMP_GET_NUM_THREADS)
333  omp_get_num_threads ();
334 #endif
335 
336 #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__)
337  BSD_init ();
338 #elif defined (__MINGW32__)
339  MINGW_init ();
340 #elif defined (_MSC_VER)
341  MSVC_init ();
342 #endif
343 }
344 
345 void
347 {
348 #if defined (OCTAVE_USE_WINDOWS_API)
349  // Let us fail immediately without displaying any dialog.
350  SetProcessShutdownParameters (0x280, SHUTDOWN_NORETRY);
351 #endif
352 }
353 
354 // Set terminal in raw mode. From less-177.
355 //
356 // Change terminal to "raw mode", or restore to "normal" mode.
357 // "Raw mode" means
358 // 1. An outstanding read will complete on receipt of a single keystroke.
359 // 2. Input is not echoed.
360 // 3. On output, \n is mapped to \r\n.
361 // 4. \t is NOT expanded into spaces.
362 // 5. Signal-causing characters such as ctrl-C (interrupt),
363 // etc. are NOT disabled.
364 // It doesn't matter whether an input \n is mapped to \r, or vice versa.
365 
366 void
367 raw_mode (bool on, bool wait)
368 {
369  static bool curr_on = false;
370 
371  int tty_fd = STDIN_FILENO;
372  if (! octave_isatty_wrapper (tty_fd))
373  {
374  if (octave::application::interactive ()
375  && ! octave::application::forced_interactive ())
376  error ("stdin is not a tty!");
377  }
378 
379  if (on == curr_on)
380  return;
381 
382 #if defined (HAVE_TERMIOS_H)
383  {
384  struct termios s;
385  static struct termios save_term;
386 
387  if (on)
388  {
389  // Get terminal modes.
390 
391  tcgetattr (tty_fd, &s);
392 
393  // Save modes and set certain variables dependent on modes.
394 
395  save_term = s;
396 // ospeed = s.c_cflag & CBAUD;
397 // erase_char = s.c_cc[VERASE];
398 // kill_char = s.c_cc[VKILL];
399 
400  // Set the modes to the way we want them.
401 
402  s.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL);
403  s.c_oflag |= (OPOST | ONLCR);
404 #if defined (OCRNL)
405  s.c_oflag &= ~(OCRNL);
406 #endif
407 #if defined (ONOCR)
408  s.c_oflag &= ~(ONOCR);
409 #endif
410 #if defined (ONLRET)
411  s.c_oflag &= ~(ONLRET);
412 #endif
413  s.c_cc[VMIN] = wait ? 1 : 0;
414  s.c_cc[VTIME] = 0;
415  }
416  else
417  {
418  // Restore saved modes.
419 
420  s = save_term;
421  }
422 
423  tcsetattr (tty_fd, wait ? TCSAFLUSH : TCSADRAIN, &s);
424  }
425 #elif defined (HAVE_TERMIO_H)
426  {
427  struct termio s;
428  static struct termio save_term;
429 
430  if (on)
431  {
432  // Get terminal modes.
433 
434  ioctl (tty_fd, TCGETA, &s);
435 
436  // Save modes and set certain variables dependent on modes.
437 
438  save_term = s;
439 // ospeed = s.c_cflag & CBAUD;
440 // erase_char = s.c_cc[VERASE];
441 // kill_char = s.c_cc[VKILL];
442 
443  // Set the modes to the way we want them.
444 
445  s.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL);
446  s.c_oflag |= (OPOST | ONLCR);
447 #if defined (OCRNL)
448  s.c_oflag &= ~(OCRNL);
449 #endif
450 #if defined (ONOCR)
451  s.c_oflag &= ~(ONOCR);
452 #endif
453 #if defined (ONLRET)
454  s.c_oflag &= ~(ONLRET);
455 #endif
456  s.c_cc[VMIN] = wait ? 1 : 0;
457  }
458  else
459  {
460  // Restore saved modes.
461 
462  s = save_term;
463  }
464 
465  ioctl (tty_fd, TCSETAW, &s);
466  }
467 #elif defined (HAVE_SGTTY_H)
468  {
469  struct sgttyb s;
470  static struct sgttyb save_term;
471 
472  if (on)
473  {
474  // Get terminal modes.
475 
476  ioctl (tty_fd, TIOCGETP, &s);
477 
478  // Save modes and set certain variables dependent on modes.
479 
480  save_term = s;
481 // ospeed = s.sg_ospeed;
482 // erase_char = s.sg_erase;
483 // kill_char = s.sg_kill;
484 
485  // Set the modes to the way we want them.
486 
487  s.sg_flags |= CBREAK;
488  s.sg_flags &= ~(ECHO);
489  }
490  else
491  {
492  // Restore saved modes.
493 
494  s = save_term;
495  }
496 
497  ioctl (tty_fd, TIOCSETN, &s);
498  }
499 #else
500  warn_disabled_feature ("", "raw mode console I/O");
501 
502  // Make sure the current mode doesn't toggle.
503  on = curr_on;
504 #endif
505 
506  curr_on = on;
507 }
508 
509 FILE *
510 octave_popen (const char *command, const char *mode)
511 {
512 #if defined (__MINGW32__) || defined (_MSC_VER)
513  if (mode && mode[0] && ! mode[1])
514  {
515  char tmode[3];
516  tmode[0] = mode[0];
517  tmode[1] = 'b';
518  tmode[2] = 0;
519 
520  return _popen (command, tmode);
521  }
522  else
523  return _popen (command, mode);
524 #else
525  return popen (command, mode);
526 #endif
527 }
528 
529 int
531 {
532 #if defined (__MINGW32__) || defined (_MSC_VER)
533  return _pclose (f);
534 #else
535  return pclose (f);
536 #endif
537 }
538 
539 // Read one character from the terminal.
540 
541 int
542 octave_kbhit (bool wait)
543 {
544 #if defined (HAVE__KBHIT) && defined (HAVE__GETCH)
545  // This essentially means we are on a Windows system.
546  int c;
547 
548  if (wait)
549  c = _getch ();
550  else
551  c = (! _kbhit ()) ? 0 : _getch ();
552 
553 #else
554  raw_mode (true, wait);
555 
556  // Get current handler.
557  octave::interrupt_handler saved_interrupt_handler
559 
560  // Restore it, disabling system call restarts (if possible) so the
561  // read can be interrupted.
562 
563  octave::set_interrupt_handler (saved_interrupt_handler, false);
564 
565  int c = std::cin.get ();
566 
567  if (std::cin.fail () || std::cin.eof ())
568  std::cin.clear ();
569 
570  // Restore it, enabling system call restarts (if possible).
571  octave::set_interrupt_handler (saved_interrupt_handler, true);
572 
573  raw_mode (false, true);
574 #endif
575 
576  return c;
577 }
578 
581 {
582 #if defined (OCTAVE_USE_WINDOWS_API)
583 
585 
586 #if defined (P_tmpdir)
587  retval = P_tmpdir;
588 #endif
589 
590  // Apparently some versions of MinGW and MSVC either don't define
591  // P_tmpdir, or they define it to a single backslash, neither of which
592  // is particularly helpful.
593 
594  if (retval.empty () || retval == "\\")
595  {
596  retval = octave::sys::env::getenv ("TEMP");
597 
598  if (retval.empty ())
599  retval = octave::sys::env::getenv ("TMP");
600 
601  if (retval.empty ())
602  retval = "c:\\temp";
603  }
604 
605  return retval;
606 
607 #elif defined (P_tmpdir)
608 
609  return P_tmpdir;
610 
611 #else
612 
613  return "/tmp";
614 
615 #endif
616 }
617 
618 DEFUN (clc, , ,
619  doc: /* -*- texinfo -*-
620 @deftypefn {} {} clc ()
621 @deftypefnx {} {} home ()
622 Clear the terminal screen and move the cursor to the upper left corner.
623 @end deftypefn */)
624 {
625  bool skip_redisplay = true;
626 
627  octave::command_editor::clear_screen (skip_redisplay);
628 
629  return ovl ();
630 }
631 
632 DEFALIAS (home, clc);
633 
634 DEFUN (getenv, args, ,
635  doc: /* -*- texinfo -*-
636 @deftypefn {} {} getenv (@var{var})
637 Return the value of the environment variable @var{var}.
638 
639 For example,
640 
641 @example
642 getenv ("PATH")
643 @end example
644 
645 @noindent
646 returns a string containing the value of your path.
647 @seealso{setenv, unsetenv}
648 @end deftypefn */)
649 {
650  if (args.length () != 1)
651  print_usage ();
652 
653  std::string name = args(0).string_value ();
654 
655  return ovl (octave::sys::env::getenv (name));
656 }
657 
658 /*
659 %!assert (ischar (getenv ("OCTAVE_HOME")))
660 */
661 
662 DEFUN (setenv, args, ,
663  doc: /* -*- texinfo -*-
664 @deftypefn {} {} setenv (@var{var}, @var{value})
665 @deftypefnx {} {} setenv (@var{var})
666 @deftypefnx {} {} putenv (@dots{})
667 Set the value of the environment variable @var{var} to @var{value}.
668 
669 If no @var{value} is specified then the variable will be assigned the null
670 string.
671 @seealso{unsetenv, getenv}
672 @end deftypefn */)
673 {
674  int nargin = args.length ();
675 
676  if (nargin < 1 || nargin > 2)
677  print_usage ();
678 
679  std::string var = args(0).xstring_value ("setenv: VAR must be a string");
680 
681  std::string val = (nargin == 2
682  ? args(1).xstring_value ("setenv: VALUE must be a string")
683  : "");
684 
685  octave::sys::env::putenv (var, val);
686 
687  return ovl ();
688 }
689 
690 DEFALIAS (putenv, setenv);
691 
692 /*
693 %!test
694 %! setenv ("dummy_variable_that_cannot_matter", "foobar");
695 %! assert (getenv ("dummy_variable_that_cannot_matter"), "foobar");
696 %! unsetenv ("dummy_variable_that_cannot_matter");
697 %! assert (getenv ("dummy_variable_that_cannot_matter"), "");
698 */
699 
700 DEFUN (unsetenv, args, ,
701  doc: /* -*- texinfo -*-
702 @deftypefn {} {@var{status} =} unsetenv (@var{var})
703 Delete the environment variable @var{var}.
704 
705 Return 0 if the variable was deleted, or did not exist, and -1 if an error
706 occurred.
707 @seealso{setenv, getenv}
708 @end deftypefn */)
709 {
710  if (args.length () != 1)
711  print_usage ();
712 
713  std::string tmp = args(0).string_value ();
714 
715  return ovl (octave_unsetenv_wrapper (tmp.c_str ()));
716 }
717 
718 /*
719 ## Test for unsetenv is in setenv test
720 */
721 
722 // FIXME: perhaps kbhit should also be able to print a prompt?
723 
724 DEFUN (kbhit, args, ,
725  doc: /* -*- texinfo -*-
726 @deftypefn {} {} kbhit ()
727 @deftypefnx {} {} kbhit (1)
728 Read a single keystroke from the keyboard.
729 
730 If called with an argument, don't wait for a keypress.
731 
732 For example,
733 
734 @example
735 x = kbhit ();
736 @end example
737 
738 @noindent
739 will set @var{x} to the next character typed at the keyboard as soon as
740 it is typed.
741 
742 @example
743 x = kbhit (1);
744 @end example
745 
746 @noindent
747 is identical to the above example, but doesn't wait for a keypress,
748 returning the empty string if no key is available.
749 @seealso{input, pause}
750 @end deftypefn */)
751 {
752  octave_value retval = "";
753 
754  // FIXME: add timeout and default value args?
755 
756  if (octave::application::interactive ())
757  {
758  Fdrawnow ();
759 
760  int c = octave_kbhit (args.length () == 0);
761 
762  if (c == -1)
763  c = 0;
764 
765  char s[2] = { static_cast<char> (c), '\0' };
766 
767  retval = s;
768  }
769 
770  return retval;
771 }
772 
773 DEFUN (pause, args, ,
774  doc: /* -*- texinfo -*-
775 @deftypefn {} {} pause ()
776 @deftypefnx {} {} pause (@var{n})
777 Suspend the execution of the program for @var{n} seconds.
778 
779 If invoked without an input arguments then the program is suspended until a
780 character is typed.
781 
782 @var{n} is a positive real value and may be a fraction of a second,
783 for example:
784 
785 @example
786 @group
787 tic; pause (0.05); toc
788  @print{} Elapsed time is 0.05039 seconds.
789 @end group
790 @end example
791 
792 The following example prints a message and then waits 5 seconds before
793 clearing the screen.
794 
795 @example
796 @group
797 disp ("wait please...");
798 pause (5);
799 clc;
800 @end group
801 @end example
802 
803 @seealso{kbhit}
804 @end deftypefn */)
805 {
806  int nargin = args.length ();
807 
808  if (nargin > 1)
809  print_usage ();
810 
811  if (nargin == 1)
812  {
813  double dval = args(0).double_value ();
814 
815  if (octave::math::isnan (dval))
816  warning ("pause: NaN is an invalid delay");
817  else
818  {
819  Fdrawnow ();
820 
821  if (octave::math::isinf (dval))
822  {
824  octave_kbhit ();
825  }
826  else
827  octave_sleep (dval);
828  }
829  }
830  else
831  {
832  Fdrawnow ();
834  octave_kbhit ();
835  }
836 
837  return ovl ();
838 }
839 
840 /*
841 %!test
842 %! pause (1);
843 
844 %!error (pause (1, 2))
845 */
846 
847 // FIXME: maybe this should only return 1 if IEEE floating
848 // point functions really work.
849 
850 DEFUN (isieee, , ,
851  doc: /* -*- texinfo -*-
852 @deftypefn {} {} isieee ()
853 Return true if your computer @emph{claims} to conform to the IEEE standard
854 for floating point calculations.
855 
856 No actual tests are performed.
857 @end deftypefn */)
858 {
861 
864 }
865 
866 /*
867 %!assert (islogical (isieee ()))
868 */
869 
870 DEFUN (native_float_format, , ,
871  doc: /* -*- texinfo -*-
872 @deftypefn {} {} native_float_format ()
873 Return the native floating point format as a string.
874 @end deftypefn */)
875 {
878 
880 }
881 
882 /*
883 %!assert (ischar (native_float_format ()))
884 */
885 
886 DEFUN (tilde_expand, args, ,
887  doc: /* -*- texinfo -*-
888 @deftypefn {} {} tilde_expand (@var{string})
889 @deftypefnx {} {} tilde_expand (@var{cellstr})
890 Perform tilde expansion on @var{string}.
891 
892 If @var{string} begins with a tilde character, (@samp{~}), all of the
893 characters preceding the first slash (or all characters, if there is no
894 slash) are treated as a possible user name, and the tilde and the following
895 characters up to the slash are replaced by the home directory of the named
896 user. If the tilde is followed immediately by a slash, the tilde is
897 replaced by the home directory of the user running Octave.
898 
899 If the input is a cell array of strings @var{cellstr} then tilde expansion
900 is performed on each string element.
901 
902 Examples:
903 
904 @example
905 @group
906 tilde_expand ("~joeuser/bin")
907  @result{} "/home/joeuser/bin"
908 tilde_expand ("~/bin")
909  @result{} "/home/jwe/bin"
910 @end group
911 @end example
912 @end deftypefn */)
913 {
914  if (args.length () != 1)
915  print_usage ();
916 
917  octave_value arg = args(0);
918 
919  string_vector sv = arg.xstring_vector_value ("tilde_expand: argument must be char or cellstr object");
920 
922 
923  if (arg.is_cellstr ())
924  return ovl (Cell (arg.dims (), sv));
925  else
926  return ovl (sv);
927 }
928 
929 /*
930 %!test
931 %! home = get_home_directory ();
932 %! assert (tilde_expand ("~/foobar"), [home "/foobar"]);
933 %! assert (tilde_expand ("/foo/bar"), "/foo/bar");
934 %! assert (tilde_expand ("foo/bar"), "foo/bar");
935 */
936 
937 DEFUN (get_home_directory, , ,
938  doc: /* -*- texinfo -*-
939 @deftypefn {} {@var{homedir} =} get_home_directory ()
940 Return the current home directory.
941 
942 On most systems, this is equivalent to @code{getenv ("HOME")}. On Windows
943 systems, if the environment variable @env{HOME} is not set then it is
944 equivalent to
945 @code{fullfile (getenv ("HOMEDRIVE"), getenv ("HOMEPATH"))}
946 @seealso{getenv}
947 @end deftypefn */)
948 {
950 }
951 
952 /*
953 %!test
954 %! if (! ispc ())
955 %! assert (get_home_directory (), getenv ("HOME"));
956 %! endif
957 */
958 
959 // This function really belongs in display.cc, but including defun.h in
960 // that file results in conflicts with symbols from headers that are
961 // needed for X11 and Carbon functions.
962 
963 DEFUN (have_window_system, , ,
964  doc: /* -*- texinfo -*-
965 @deftypefn {} {} have_window_system ()
966 Return true if a window system is available (X11, Windows, or Apple OS X)
967 and false otherwise.
968 @seealso{isguirunning}
969 @end deftypefn */)
970 {
972 }
void flush_octave_stdout(void)
Definition: pager.cc:454
OCTINTERP_API void octave_sleep(double seconds)
Definition: Cell.h:37
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:120
string_vector xstring_vector_value(const char *fmt,...) const
Definition: ov.cc:2123
static void putenv(const std::string &name, const std::string &value)
Definition: oct-env.cc:242
FILE * octave_popen(const char *command, const char *mode)
Definition: sysdep.cc:510
void raw_mode(bool on, bool wait)
Definition: sysdep.cc:367
int octave_pclose(FILE *f)
Definition: sysdep.cc:530
OCTINTERP_API void print_usage(void)
Definition: defun.cc:52
void set_application_id(void)
Definition: sysdep.cc:184
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE const F77_DBLE * f
Return the CPU time used by your Octave session The first output is the total time spent executing your process and is equal to the sum of second and third which are the number of CPU seconds spent executing in user mode and the number of CPU seconds spent executing in system mode
Definition: data.cc:6386
bool isnan(double x)
Definition: lo-mappers.cc:347
int octave_kbhit(bool wait)
Definition: sysdep.cc:542
OCTINTERP_API octave_value_list Fdrawnow(const octave_value_list &=octave_value_list(), int=0)
Definition: graphics.cc:11032
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
void error(const char *fmt,...)
Definition: error.cc:570
#define STDIN_FILENO
Definition: sysdep.cc:93
octave::mach_info::float_format flt_fmt
Definition: load-save.cc:723
to define functions rather than attempting to enter them directly on the command line The block of commands is executed as soon as you exit the editor To avoid executing any simply delete all the lines from the buffer before leaving the editor When invoked with no edit the previously executed command
Definition: oct-hist.cc:587
dev_t dev(void) const
Definition: file-stat.h:118
void sysdep_cleanup(void)
Definition: sysdep.cc:346
s
Definition: file-io.cc:2682
pause(0.05)
static std::string tilde_expand(const std::string &)
Definition: file-ops.cc:301
octave_value arg
Definition: pr-output.cc:3440
static std::string getenv(const std::string &name)
Definition: oct-env.cc:235
OCTINTERP_API octave_value_list Fsystem(const octave_value_list &=octave_value_list(), int=0)
Definition: toplev.cc:199
JNIEnv void * args
Definition: ov-java.cc:67
#define DEFALIAS(alias, name)
Definition: defun.h:65
double h
Definition: graphics.cc:11205
nd deftypefn *std::string name
Definition: sysdep.cc:653
int octave_isatty_wrapper(int fd)
static std::string get_home_directory(void)
Definition: oct-env.cc:143
bool same_file_internal(const std::string &file1, const std::string &file2)
Definition: sysdep.cc:264
return ovl(octave::sys::env::getenv(name))
int nargin
Definition: graphics.cc:10115
void warn_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
Definition: errwarn.cc:308
double tmp
Definition: data.cc:6300
octave_value retval
Definition: data.cc:6294
bool is_cellstr(void) const
Definition: ov.h:548
ino_t ino(void) const
Definition: file-stat.h:117
clc
Definition: sysdep.cc:804
end example noindent will set var
Definition: sysdep.cc:750
static bool prefer_env_winsize(bool)
Definition: cmd-edit.cc:1613
interrupt_handler ignore_interrupts(void)
Definition: sighandlers.cc:572
static std::string float_format_as_string(float_format)
Definition: mach-info.cc:202
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
dim_vector dims(void) const
Definition: ov.h:486
bool isinf(double x)
Definition: lo-mappers.cc:387
#define ECHO
static float_format native_float_format(void)
Definition: mach-info.cc:162
void warning(const char *fmt,...)
Definition: error.cc:788
defaults to zero A value of zero computes the digamma a value the trigamma and so on The digamma function is defined
Definition: psi.cc:68
int octave_unsetenv_wrapper(const char *name)
static bool display_available(void)
Definition: display.h:72
interrupt_handler set_interrupt_handler(const volatile interrupt_handler &h, bool restart_syscalls)
Definition: sighandlers.cc:585
std::string get_P_tmpdir(void)
Definition: sysdep.cc:580
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
void sysdep_init(void)
Definition: sysdep.cc:327
static void clear_screen(bool skip_redisplay=false)
Definition: cmd-edit.cc:1237