23 #if defined (HAVE_CONFIG_H) 33 #if defined (HAVE_TERMIOS_H) 35 #elif defined (HAVE_TERMIO_H) 37 #elif defined (HAVE_SGTTY_H) 41 #if defined (HAVE_CONIO_H) 45 #if defined (HAVE_SYS_IOCTL_H) 46 # include <sys/ioctl.h> 49 #if defined (HAVE_FLOATINGPOINT_H) 50 # include <floatingpoint.h> 53 #if defined (HAVE_IEEEFP_H) 57 #if defined (HAVE_OMP_H) 70 #include "builtin-defun-decls.h" 87 #if ! defined (STDIN_FILENO) 88 # define STDIN_FILENO 1 91 #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__) 95 # if defined (HAVE_FLOATINGPOINT_H) 97 # if ! defined (FP_X_DNML) 100 fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP));
105 #if defined (__MINGW32__) || defined (_MSC_VER) 107 #define WIN32_LEAN_AND_MEAN 109 #include <tlhelp32.h> 110 #include <shellapi.h> 113 w32_set_octave_home (
void)
117 HANDLE
h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE
118 #
if defined (TH32CS_SNAPMODULE32)
119 | TH32CS_SNAPMODULE32
123 if (
h != INVALID_HANDLE_VALUE)
125 MODULEENTRY32 mod_info;
127 ZeroMemory (&mod_info,
sizeof (mod_info));
128 mod_info.dwSize =
sizeof (mod_info);
130 if (Module32First (
h, &mod_info))
136 if (mod_name.find (
"octinterp") != std::string::npos)
144 while (Module32Next (
h, &mod_info));
152 size_t pos =
bin_dir.rfind (R
"(\bin\)"); 154 if (pos != std::string::npos)
162 w32_set_octave_home ();
177 #if defined (__MINGW32__) || defined (_MSC_VER) 179 typedef HRESULT (WINAPI *SETCURRENTAPPID)(PCWSTR AppID);
181 HMODULE hShell = LoadLibrary (
"shell32.dll");
185 SETCURRENTAPPID pfnSetCurrentProcessExplicitAppUserModelID =
186 reinterpret_cast<SETCURRENTAPPID
> (GetProcAddress (hShell,
187 "SetCurrentProcessExplicitAppUserModelID"));
189 if (pfnSetCurrentProcessExplicitAppUserModelID)
190 pfnSetCurrentProcessExplicitAppUserModelID (L
"gnu.octave." VERSION);
192 FreeLibrary (hShell);
198 DEFUN (__open_with_system_app__, args, ,
204 if (args.length () != 1)
207 std::string file = args(0).xstring_value (
"__open_with_system_app__: argument must be a filename");
211 #if defined (OCTAVE_USE_WINDOWS_API) 212 HINSTANCE status = ShellExecute (0, 0,
file.c_str (), 0, 0,
216 retval = (
reinterpret_cast<ptrdiff_t
> (status) > 32);
217 #elif defined (__APPLE__) 236 #if defined (__MINGW32__) 244 #if defined (_MSC_VER) 257 #if defined (OCTAVE_USE_WINDOWS_API) 261 const char *f1 = file1.c_str ();
262 const char *f2 = file2.c_str ();
264 bool f1_is_dir = GetFileAttributes (f1) & FILE_ATTRIBUTE_DIRECTORY;
265 bool f2_is_dir = GetFileAttributes (f2) & FILE_ATTRIBUTE_DIRECTORY;
270 DWORD share = FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE;
273 = CreateFile (f1, 0, share, 0, OPEN_EXISTING,
274 f1_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0);
276 if (hfile1 != INVALID_HANDLE_VALUE)
279 = CreateFile (f2, 0, share, 0, OPEN_EXISTING,
280 f2_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0);
282 if (hfile2 != INVALID_HANDLE_VALUE)
284 BY_HANDLE_FILE_INFORMATION hfi1;
285 BY_HANDLE_FILE_INFORMATION hfi2;
287 if (GetFileInformationByHandle (hfile1, &hfi1)
288 && GetFileInformationByHandle (hfile2, &hfi2))
290 retval = (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber
291 && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh
292 && hfi1.nFileIndexLow == hfi2.nFileIndexLow);
295 CloseHandle (hfile2);
298 CloseHandle (hfile1);
310 return (fs_file1 && fs_file2
311 && fs_file1.
ino () == fs_file2.
ino ()
312 && fs_file1.
dev () == fs_file2.
dev ());
323 #if defined (HAVE_OMP_GET_NUM_THREADS) 324 omp_get_num_threads ();
327 #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__) 329 #elif defined (__MINGW32__) 331 #elif defined (_MSC_VER) 339 #if defined (OCTAVE_USE_WINDOWS_API) 341 SetProcessShutdownParameters (0x280, SHUTDOWN_NORETRY);
360 static bool curr_on =
false;
365 if (octave::application::interactive ()
366 && ! octave::application::forced_interactive ())
367 error (
"stdin is not a tty!");
373 #if defined (HAVE_TERMIOS_H) 376 static struct termios save_term;
382 tcgetattr (tty_fd, &
s);
393 s.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL);
394 s.c_oflag |= (OPOST | ONLCR);
396 s.c_oflag &= ~(OCRNL);
399 s.c_oflag &= ~(ONOCR);
402 s.c_oflag &= ~(ONLRET);
404 s.c_cc[VMIN] = (wait ? 1 : 0);
414 tcsetattr (tty_fd, wait ? TCSAFLUSH : TCSADRAIN, &
s);
416 #elif defined (HAVE_TERMIO_H) 419 static struct termio save_term;
425 ioctl (tty_fd, TCGETA, &
s);
436 s.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL);
437 s.c_oflag |= (OPOST | ONLCR);
439 s.c_oflag &= ~(OCRNL);
442 s.c_oflag &= ~(ONOCR);
445 s.c_oflag &= ~(ONLRET);
447 s.c_cc[VMIN] = (wait ? 1 : 0);
456 ioctl (tty_fd, TCSETAW, &
s);
458 #elif defined (HAVE_SGTTY_H) 460 octave_unused_parameter (wait);
463 static struct sgttyb save_term;
469 ioctl (tty_fd, TIOCGETP, &
s);
480 s.sg_flags |= CBREAK;
481 s.sg_flags &= ~(ECHO);
490 ioctl (tty_fd, TIOCSETN, &
s);
494 octave_unused_parameter (wait);
508 #if defined (__MINGW32__) || defined (_MSC_VER) 512 char tmode[3] = {
mode[0],
'b',
'\0'};
514 return _popen (
command, tmode);
526 #if defined (__MINGW32__) || defined (_MSC_VER) 538 #if defined (HAVE__KBHIT) && defined (HAVE__GETCH) 545 c = (! _kbhit ()) ? 0 : _getch ();
559 int c = std::cin.
get ();
561 if (std::cin.fail () || std::cin.eof ())
576 #if defined (OCTAVE_USE_WINDOWS_API) 580 #if defined (P_tmpdir) 601 #elif defined (P_tmpdir) 619 bool skip_redisplay =
true;
628 DEFUN (getenv, args, ,
644 if (args.length () != 1)
656 DEFUN (setenv, args, ,
668 int nargin = args.length ();
673 std::string var = args(0).xstring_value (
"setenv: VAR must be a string");
676 ? args(1).xstring_value (
"setenv: VALUE must be a string")
694 DEFUN (unsetenv, args, ,
704 if (args.length () != 1)
716 #if defined (OCTAVE_USE_WINDOWS_API) 719 reg_close_key_wrapper (HKEY key)
725 get_regkey_value (HKEY h_rootkey,
const std::string subkey,
731 result = RegOpenKeyExA (h_rootkey, subkey.c_str (), 0, KEY_READ, &h_subkey);
732 if (
result != ERROR_SUCCESS)
740 result = RegQueryValueExA (h_subkey,
name.c_str (),
nullptr,
nullptr,
nullptr,
742 if (
result != ERROR_SUCCESS)
747 result = RegQueryValueExA (h_subkey,
name.c_str (),
nullptr, &
type, data,
749 if (
result != ERROR_SUCCESS)
752 if (
type == REG_DWORD)
754 else if (
type == REG_SZ ||
type == REG_EXPAND_SZ)
761 get_regkey_names (HKEY h_rootkey,
const std::string subkey,
762 std::list<std::string> &
fields)
769 retval = RegOpenKeyEx (h_rootkey, subkey.c_str (), 0, KEY_READ, &h_subkey);
770 if (
retval != ERROR_SUCCESS)
774 const int MAX_VALUE_NAME_SIZE = 32766;
775 char value_name[MAX_VALUE_NAME_SIZE+1];
776 DWORD value_name_size = MAX_VALUE_NAME_SIZE;
780 retval = RegEnumValue (h_subkey, idx, value_name, &value_name_size,
781 nullptr,
nullptr,
nullptr,
nullptr);
782 if (
retval != ERROR_SUCCESS)
784 fields.push_back (value_name);
785 value_name_size = MAX_VALUE_NAME_SIZE;
789 if (
retval == ERROR_NO_MORE_ITEMS)
792 RegCloseKey (h_subkey);
798 DEFUN (winqueryreg, args, ,
868 #if defined (OCTAVE_USE_WINDOWS_API) 869 if ((args.length () < 2) || (args.length () > 3))
874 args(0).xstring_value (
"winqueryreg: the first argument must be 'name' " 875 "or a valid ROOTKEY identifier");
878 bool get_names =
false;
879 if (rootkey_name.compare (
"name") == 0)
881 if (args.length () < 3)
882 error (
"winqueryreg: if the first argument is 'name', " 883 "ROOTKEY and SUBKEY must be given");
886 args(1).xstring_value (
"winqueryreg: ROOTKEY must be a string");
888 args(2).xstring_value (
"winqueryreg: SUBKEY must be a string");
893 args(1).xstring_value (
"winqueryreg: SUBKEY must be a string");
894 if (args.length () == 3)
896 args(2).xstring_value (
"winqueryreg: VALUENAME must be a string");
901 if (rootkey_name ==
"HKEY_CLASSES_ROOT" || rootkey_name ==
"HKCR")
902 h_rootkey = HKEY_CLASSES_ROOT;
903 else if (rootkey_name ==
"HKEY_CURRENT_CONFIG")
904 h_rootkey = HKEY_CURRENT_CONFIG;
905 else if (rootkey_name ==
"HKEY_CURRENT_USER" || rootkey_name ==
"HKCU")
906 h_rootkey = HKEY_CURRENT_USER;
907 else if (rootkey_name ==
"HKEY_LOCAL_MACHINE" || rootkey_name ==
"HKLM")
908 h_rootkey = HKEY_LOCAL_MACHINE;
909 else if (rootkey_name ==
"HKEY_PERFORMANCE_DATA")
910 h_rootkey = HKEY_PERFORMANCE_DATA;
911 else if (rootkey_name ==
"HKEY_USERS" || rootkey_name ==
"HKU")
912 h_rootkey = HKEY_USERS;
914 error (
"winqueryreg: ROOTKEY is not a valid root key identifier");
918 std::list<std::string>
fields;
920 LONG
retval = get_regkey_names (h_rootkey, subkey_name,
fields);
921 if (
retval != ERROR_SUCCESS)
922 error (
"winqueryreg: error %d reading names from registry",
retval);
926 std::list<std::string>::const_iterator it;
935 LONG
retval = get_regkey_value (h_rootkey, subkey_name, value_name,
937 if (
retval == ERROR_FILE_NOT_FOUND)
938 error (
"winqueryreg: no value found for '%s' at %s\\%s.",
939 value_name.c_str (), rootkey_name.c_str (),
940 subkey_name.c_str ());
941 if (
retval != ERROR_SUCCESS)
942 error (
"winqueryreg: error %d reading the specified key",
retval);
944 return ovl (key_val);
948 octave_unused_parameter (args);
950 error (
"winqueryreg: function is only supported on Windows platforms");
1001 DEFUN (kbhit, args, ,
1038 char s[2] = {
static_cast<char> (
c),
'\0' };
1076 int nargin = args.length ();
1083 double dval = args(0).double_value ();
1086 warning (
"pause: NaN is an invalid delay");
1184 if (args.length () != 1)
1207 DEFUN (get_home_directory, , ,
1229 DEFUN (__blas_version__, , ,
1238 DEFUN (__lapack_version__, , ,
scalar structure containing the fields
OCTINTERP_API void octave_sleep(double seconds)
For example cd octave end example noindent changes the current working directory to file
static void putenv(const std::string &name, const std::string &value)
FILE * octave_popen(const char *command, const char *mode)
void raw_mode(bool on, bool wait)
int octave_pclose(FILE *f)
scalar structure containing the one value The second produces an empty struct array with one field and no values since being passed an empty cell array of struct array values When the value is a cell array containing a single entry this becomes a scalar struct with that single entry as the value of the field That single entry happens to be an empty cell array Finally if the value is a non scalar cell array then ode fieldnames
OCTINTERP_API void print_usage(void)
void set_application_id(void)
identity matrix If supplied two scalar respectively For allows like xample val
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &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
std::string tilde_expand(const std::string &name)
int octave_kbhit(bool wait)
void add_fcn(void(*fcn)(void))
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
octave::mach_info::float_format flt_fmt
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
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
void sysdep_cleanup(void)
endfor nd group nd example On non Windows platforms this function fails with an error nd deftypefn * error("winqueryreg: function is only supported on Windows platforms")
virtual octave_value get(bool all=false) const
static std::string getenv(const std::string &name)
std::string bin_dir(void)
bool iscellstr(void) const
#define DEFALIAS(alias, name)
Macro to define an alias for another existing function name.
nd deftypefn *std::string name
int octave_isatty_wrapper(int fd)
static std::string get_home_directory(void)
bool same_file_internal(const std::string &file1, const std::string &file2)
return ovl(octave::sys::env::getenv(name))
float_format native_float_format(void)
dim_vector dims(void) const
void warn_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
end example noindent will set var
OCTAVE_EXPORT octave_value_list Fsystem(const octave_value_list &args, int nargout) ar
static bool prefer_env_winsize(bool)
interrupt_handler ignore_interrupts(void)
std::string lapack_version(void)
With real return the complex result
void warning(const char *fmt,...)
octave::unwind_protect frame
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
defaults to zero A value of zero computes the digamma a value the trigamma and so on The digamma function is defined
int octave_unsetenv_wrapper(const char *name)
interrupt_handler set_interrupt_handler(const volatile interrupt_handler &h, bool restart_syscalls)
std::string blas_version(void)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
string_vector xstring_vector_value(const char *fmt,...) const
std::string get_P_tmpdir(void)
Vector representing the dimensions (size) of an Array.
octave_int< int32_t > octave_int32
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
nd group nd example For each display the value
std::string float_format_as_string(float_format flt_fmt)
static void clear_screen(bool skip_redisplay=false)