36 #include <sys/types.h>
39 #if defined (HAVE_TERMIOS_H)
41 #elif defined (HAVE_TERMIO_H)
43 #elif defined (HAVE_SGTTY_H)
47 #if defined (HAVE_CONIO_H)
51 #if defined (HAVE_SYS_IOCTL_H)
52 #include <sys/ioctl.h>
55 #if defined (HAVE_FLOATINGPOINT_H)
56 #include <floatingpoint.h>
59 #if defined (HAVE_IEEEFP_H)
88 #define STDIN_FILENO 1
91 #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__)
95 #if defined (HAVE_FLOATINGPOINT_H)
100 fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP));
105 #if defined (__WIN32__) && ! defined (_POSIX_VERSION)
107 #define WIN32_LEAN_AND_MEAN
108 #include <tlhelp32.h>
111 w32_set_octave_home (
void)
115 HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE
116 #ifdef TH32CS_SNAPMODULE32
117 | TH32CS_SNAPMODULE32
121 if (h != INVALID_HANDLE_VALUE)
123 MODULEENTRY32 mod_info;
125 ZeroMemory (&mod_info,
sizeof (mod_info));
126 mod_info.dwSize =
sizeof (mod_info);
128 if (Module32First (h, &mod_info))
132 std::string mod_name (mod_info.szModule);
134 if (mod_name.find (
"octinterp") != std::string::npos)
136 bin_dir = mod_info.szExePath;
137 if (bin_dir[bin_dir.length () - 1] !=
'\\')
138 bin_dir.append (1,
'\\');
142 while (Module32Next (h, &mod_info));
148 if (! bin_dir.empty ())
150 size_t pos = bin_dir.rfind (
"\\bin\\");
152 if (pos != std::string::npos)
164 SetProcessShutdownParameters (0x280, SHUTDOWN_NORETRY);
168 MINGW_signal_cleanup (
void)
174 #if defined (__MINGW32__)
178 w32_set_octave_home ();
182 #if defined (_MSC_VER)
186 w32_set_octave_home ();
196 #ifdef OCTAVE_USE_WINDOWS_API
200 const char *f1 = file1.c_str ();
201 const char *f2 = file2.c_str ();
203 bool f1_is_dir = GetFileAttributes (f1) & FILE_ATTRIBUTE_DIRECTORY;
204 bool f2_is_dir = GetFileAttributes (f2) & FILE_ATTRIBUTE_DIRECTORY;
209 DWORD share = FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE;
212 = CreateFile (f1, 0, share, 0, OPEN_EXISTING,
213 f1_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0);
215 if (hfile1 != INVALID_HANDLE_VALUE)
218 = CreateFile (f2, 0, share, 0, OPEN_EXISTING,
219 f2_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0);
221 if (hfile2 != INVALID_HANDLE_VALUE)
223 BY_HANDLE_FILE_INFORMATION hfi1;
224 BY_HANDLE_FILE_INFORMATION hfi2;
226 if (GetFileInformationByHandle (hfile1, &hfi1)
227 && GetFileInformationByHandle (hfile2, &hfi2))
229 retval = (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber
230 && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh
231 && hfi1.nFileIndexLow == hfi2.nFileIndexLow);
234 CloseHandle (hfile2);
237 CloseHandle (hfile1);
249 return (fs_file1 && fs_file2
250 && fs_file1.
ino () == fs_file2.
ino ()
251 && fs_file1.
dev () == fs_file2.
dev ());
259 #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__)
261 #elif defined (__MINGW32__)
263 #elif defined (_MSC_VER)
289 static bool curr_on =
false;
295 error (
"stdin is not a tty!");
302 #if defined (HAVE_TERMIOS_H)
305 static struct termios save_term;
311 tcgetattr (tty_fd, &s);
322 s.c_lflag &= ~(ICANON|
ECHO|ECHOE|ECHOK|ECHONL);
323 s.c_oflag |= (OPOST|ONLCR);
325 s.c_oflag &= ~(OCRNL);
328 s.c_oflag &= ~(ONOCR);
331 s.c_oflag &= ~(ONLRET);
333 s.c_cc[VMIN] = wait ? 1 : 0;
343 tcsetattr (tty_fd, wait ? TCSAFLUSH : TCSADRAIN, &s);
345 #elif defined (HAVE_TERMIO_H)
348 static struct termio save_term;
354 ioctl (tty_fd, TCGETA, &s);
365 s.c_lflag &= ~(ICANON|
ECHO|ECHOE|ECHOK|ECHONL);
366 s.c_oflag |= (OPOST|ONLCR);
368 s.c_oflag &= ~(OCRNL);
371 s.c_oflag &= ~(ONOCR);
374 s.c_oflag &= ~(ONLRET);
376 s.c_cc[VMIN] = wait ? 1 : 0;
385 ioctl (tty_fd, TCSETAW, &s);
387 #elif defined (HAVE_SGTTY_H)
390 static struct sgttyb save_term;
396 ioctl (tty_fd, TIOCGETP, &s);
407 s.sg_flags |= CBREAK;
408 s.sg_flags &= ~(
ECHO);
417 ioctl (tty_fd, TIOCSETN, &s);
420 warning (
"no support for raw mode console I/O on this system");
432 #if defined (__MINGW32__) || defined (_MSC_VER)
433 if (mode && mode[0] && ! mode[1])
440 return _popen (command, tmode);
443 return _popen (command, mode);
445 return popen (command, mode);
452 #if defined (__MINGW32__) || defined (_MSC_VER)
465 int c = (! wait && ! _kbhit ()) ? 0 : std::cin.
get ();
478 int c = std::cin.get ();
480 if (std::cin.fail () || std::cin.eof ())
495 #if defined (__WIN32__) && ! defined (_POSIX_VERSION)
499 #if defined (P_tmpdir)
507 if (retval.empty () || retval ==
"\\")
520 #elif defined (P_tmpdir)
533 @deftypefn {Built-in Function} {} clc ()\n\
534 @deftypefnx {Built-in Function} {} home ()\n\
535 Clear the terminal screen and move the cursor to the upper left corner.\n\
538 bool skip_redisplay =
true;
547 DEFUN (getenv, args, ,
549 @deftypefn {Built-in Function} {} getenv (@var{var})\n\
550 Return the value of the environment variable @var{var}. For example,\n\
557 returns a string containing the value of your path.\n\
562 int nargin = args.
length ();
566 std::string name = args(0).string_value ();
577 DEFUN (putenv, args, ,
579 @deftypefn {Built-in Function} {} putenv (@var{var}, @var{value})\n\
580 @deftypefnx {Built-in Function} {} setenv (@var{var}, @var{value})\n\
581 Set the value of the environment variable @var{var} to @var{value}.\n\
586 int nargin = args.
length ();
588 if (nargin == 2 || nargin == 1)
590 std::string var = args(0).string_value ();
594 std::string val = (nargin == 2
595 ? args(1).string_value () : std::string ());
600 error (
"putenv: VALUE must be a string");
603 error (
"putenv: VAR must be a string");
622 DEFUN (kbhit, args, ,
624 @deftypefn {Built-in Function} {} kbhit ()\n\
625 @deftypefnx {Built-in Function} {} kbhit (1)\n\
626 Read a single keystroke from the keyboard. If called with an\n\
627 argument, don't wait for a keypress. For example,\n\
634 will set @var{x} to the next character typed at the keyboard as soon as\n\
642 is identical to the above example, but doesn't wait for a keypress,\n\
643 returning the empty string if no key is available.\n\
660 char s[2] = {
static_cast<char> (c),
'\0' };
668 DEFUN (pause, args, ,
670 @deftypefn {Built-in Function} {} pause (@var{seconds})\n\
671 Suspend the execution of the program. If invoked without any arguments,\n\
672 Octave waits until you type a character. With a numeric argument, it\n\
673 pauses for the given number of seconds. For example, the following\n\
674 statement prints a message and then waits 5 seconds before clearing the\n\
679 fprintf (stderr, \"wait please...\\n\");\n\
688 int nargin = args.
length ();
690 if (! (nargin == 0 || nargin == 1))
698 double dval = args(0).double_value ();
715 warning (
"pause: NaN is an invalid delay");
735 DEFUN (sleep, args, ,
737 @deftypefn {Built-in Function} {} sleep (@var{seconds})\n\
738 Suspend the execution of the program for the given number of seconds.\n\
743 if (args.length () == 1)
745 double dval = args(0).double_value ();
750 warning (
"sleep: NaN is an invalid delay");
772 DEFUN (usleep, args, ,
774 @deftypefn {Built-in Function} {} usleep (@var{microseconds})\n\
775 Suspend the execution of the program for the given number of\n\
776 microseconds. On systems where it is not possible to sleep for periods\n\
777 of time less than one second, @code{usleep} will pause the execution for\n\
778 @code{round (@var{microseconds} / 1e6)} seconds.\n\
783 if (args.length () == 1)
785 double dval = args(0).double_value ();
790 warning (
"usleep: NaN is an invalid delay");
795 int delay =
NINT (dval);
821 @deftypefn {Built-in Function} {} isieee ()\n\
822 Return true if your computer @emph{claims} to conform to the IEEE standard\n\
823 for floating point calculations. No actual tests are performed.\n\
836 DEFUN (native_float_format, , ,
838 @deftypefn {Built-in Function} {} native_float_format ()\n\
839 Return the native floating point format as a string\n\
851 DEFUN (tilde_expand, args, ,
853 @deftypefn {Built-in Function} {} tilde_expand (@var{string})\n\
854 Perform tilde expansion on @var{string}. If @var{string} begins with a\n\
855 tilde character, (@samp{~}), all of the characters preceding the first\n\
856 slash (or all characters, if there is no slash) are treated as a\n\
857 possible user name, and the tilde and the following characters up to the\n\
858 slash are replaced by the home directory of the named user. If the\n\
859 tilde is followed immediately by a slash, the tilde is replaced by the\n\
860 home directory of the user running Octave. For example:\n\
864 tilde_expand (\"~joeuser/bin\")\n\
865 @result{} \"/home/joeuser/bin\"\n\
866 tilde_expand (\"~/bin\")\n\
867 @result{} \"/home/jwe/bin\"\n\
874 int nargin = args.
length ();
892 error (
"tilde_expand: expecting argument to be char or cellstr object");
915 DEFUN (have_window_system, , ,
917 @deftypefn {Built-in Function} {} have_window_system ()\n\
918 Return true if Octave a window system is available (X11, Windows,\n\
919 or Apple OS X) and false otherwise.\n\