GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
sysdep.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1993-2022 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if defined (HAVE_CONFIG_H)
27# include "config.h"
28#endif
29
30#include <cmath>
31#include <cstddef>
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-sysinfo.h"
68#include "mach-info.h"
69#include "oct-env.h"
70#include "uniconv-wrappers.h"
71#include "unistd-wrappers.h"
72
73#include "builtin-defun-decls.h"
74#include "Cell.h"
75#include "defun.h"
76#include "error.h"
77#include "errwarn.h"
78#include "input.h"
79#include "interpreter-private.h"
80#include "octave.h"
81#include "ov.h"
82#include "ovl.h"
83#include "pager.h"
84#include "parse.h"
85#include "sighandlers.h"
86#include "sysdep.h"
87#include "interpreter.h"
88#include "utils.h"
89#include "file-stat.h"
90
91#if ! defined (STDIN_FILENO)
92# define STDIN_FILENO 1
93#endif
94
95#if defined (__MINGW32__) || defined (_MSC_VER)
96
97#define WIN32_LEAN_AND_MEAN
98#include <windows.h>
99#include <tlhelp32.h>
100#include <psapi.h>
101#include <shellapi.h>
102#include <shobjidl.h>
103
104#endif
105
106OCTAVE_NAMESPACE_BEGIN
107
108#if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__)
109
110 static void
111 BSD_init (void)
112 {
113# if defined (HAVE_FLOATINGPOINT_H)
114 // Disable trapping on common exceptions.
115# if ! defined (FP_X_DNML)
116# define FP_X_DNML 0
117# endif
118 fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP));
119# endif
120 }
121
122#endif
123
124#if defined (__MINGW32__) || defined (_MSC_VER)
125
126 static void
127 w32_set_octave_home (void)
128 {
129 std::string bin_dir;
130
131 HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE
132#if defined (TH32CS_SNAPMODULE32)
133 | TH32CS_SNAPMODULE32
134#endif
135 , 0);
136
137 if (h != INVALID_HANDLE_VALUE)
138 {
139 MODULEENTRY32W mod_info;
140
141 ZeroMemory (&mod_info, sizeof (mod_info));
142 mod_info.dwSize = sizeof (mod_info);
143
144 if (Module32FirstW (h, &mod_info))
145 {
146 do
147 {
148 std::string mod_name (sys::u8_from_wstring (mod_info.szModule));
149
150 if (mod_name.find ("octinterp") != std::string::npos)
151 {
152 bin_dir = sys::u8_from_wstring (mod_info.szExePath);
153 if (! bin_dir.empty () && bin_dir.back () != '\\')
154 bin_dir.push_back ('\\');
155 break;
156 }
157 }
158 while (Module32NextW (h, &mod_info));
159 }
160
161 CloseHandle (h);
162 }
163
164 if (! bin_dir.empty ())
165 {
166 std::size_t pos = bin_dir.rfind (R"(\bin\)");
167
168 if (pos != std::string::npos)
169 sys::env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos));
170 }
171 }
172
173 static void
174 w32_init (void)
175 {
176 w32_set_octave_home ();
177
178 command_editor::prefer_env_winsize (true);
179 }
180
181#endif
182
184 {
185#if defined (__MINGW32__) || defined (_MSC_VER)
186
187 SetCurrentProcessExplicitAppUserModelID (L"gnu.octave." VERSION);
188
189#endif
190 }
191
192DEFUN (__open_with_system_app__, args, ,
193 doc: /* -*- texinfo -*-
194@deftypefn {} {} __open_with_system_app__ (@var{file})
195Internal function. Returns 1 on successful system call and 0 otherwise.
196@end deftypefn */)
197{
198 if (args.length () != 1)
199 print_usage ();
200
201 std::string file = args(0).xstring_value ("__open_with_system_app__: argument must be a filename");
202
203#if defined (OCTAVE_USE_WINDOWS_API)
204 std::wstring wfile = sys::u8_to_wstring (file);
205 HINSTANCE status = ShellExecuteW (0, 0, wfile.c_str (), 0, 0, SW_SHOWNORMAL);
206
207 // ShellExecute returns a value greater than 32 if successful.
208 return octave_value (reinterpret_cast<std::ptrdiff_t> (status) > 32);
209#else
210 // Quote file path
211 file = '"' + file + '"';
212
213# if defined (__APPLE__)
214# define FSYSTEM_OPEN_STR "open "
215# else
216# define FSYSTEM_OPEN_STR "xdg-open "
217# endif
219 = Fsystem (ovl (FSYSTEM_OPEN_STR + file + " 2> /dev/null",
220 false, "async"),
221 1);
222# undef FSYSTEM_OPEN_STR
223
224 // Asynchronous Fsystem calls return the new child process identifier,
225 // which must be greater than 1 if successful.
226 return octave_value (tmp(0).double_value () > 1);
227#endif
228}
229
230DEFUN (__is_elevated_process__, args, ,
231 doc: /* -*- texinfo -*-
232@deftypefn {} {@var{retval} =} __is_elevated_process__ ()
233Check if current process has elevated rights.
234
235On Windows, return true if the current process has elevated right. Otherwise,
236return false.
237On non-Windows platforms, this function fails with an error.
238@end deftypefn */)
239{
240#if defined (OCTAVE_USE_WINDOWS_API)
241 if (args.length () != 0)
242 print_usage ();
243
244 bool retval = false;
245 HANDLE h_token = nullptr;
246
247 if (OpenProcessToken (GetCurrentProcess (), TOKEN_QUERY, &h_token))
248 {
249 TOKEN_ELEVATION elevation;
250 DWORD return_length = sizeof (TOKEN_ELEVATION);
251 if (GetTokenInformation (h_token, TokenElevation, &elevation,
252 sizeof (elevation), &return_length))
253 retval = elevation.TokenIsElevated;
254 }
255
256 if (h_token)
257 CloseHandle (h_token);
258
259 return ovl (retval);
260
261#else
262 octave_unused_parameter (args);
263 error ("__is_elevated_process__: "
264 "Function is only supported on Windows platforms.");
265#endif
266}
267
268DEFUN (__wmemory__, args, ,
269 doc: /* -*- texinfo -*-
270@deftypefn {} {[@var{proc}, @var{sys}] =} __wmemory__ ()
271Return memory information on Windows.
272
273On non-Windows platforms, this function fails with an error.
274@end deftypefn */)
275{
276#if defined (OCTAVE_USE_WINDOWS_API)
277 if (args.length () != 0)
278 print_usage ();
279
280 // Get memory usage of the current process
281 octave_scalar_map proc_struct;
282
283 HANDLE h_proc = GetCurrentProcess ();
284 if (h_proc == nullptr)
285 error ("__wmemory__: Couldn't open handle to own process");
286
287 PROCESS_MEMORY_COUNTERS proc_mem_count;
288 if (GetProcessMemoryInfo (h_proc, &proc_mem_count, sizeof (proc_mem_count)))
289 {
290 proc_struct.setfield ("PageFaultCount",
291 proc_mem_count.PageFaultCount);
292 proc_struct.setfield ("PeakWorkingSetSize",
293 proc_mem_count.PeakWorkingSetSize);
294 proc_struct.setfield ("WorkingSetSize",
295 proc_mem_count.WorkingSetSize);
296 proc_struct.setfield ("QuotaPeakPagedPoolUsage",
297 proc_mem_count.QuotaPeakPagedPoolUsage);
298 proc_struct.setfield ("QuotaPagedPoolUsage",
299 proc_mem_count.QuotaPagedPoolUsage);
300 proc_struct.setfield ("QuotaPeakNonPagedPoolUsage",
301 proc_mem_count.QuotaPeakNonPagedPoolUsage);
302 proc_struct.setfield ("QuotaNonPagedPoolUsage",
303 proc_mem_count.QuotaNonPagedPoolUsage);
304 proc_struct.setfield ("PagefileUsage",
305 proc_mem_count.PagefileUsage);
306 proc_struct.setfield ("PeakPagefileUsage",
307 proc_mem_count.PeakPagefileUsage);
308 }
309 else
310 {
311 proc_struct.setfield ("PageFaultCount", 0);
312 proc_struct.setfield ("PeakWorkingSetSize", 0);
313 proc_struct.setfield ("WorkingSetSize", 0);
314 proc_struct.setfield ("QuotaPeakPagedPoolUsage", 0);
315 proc_struct.setfield ("QuotaPagedPoolUsage", 0);
316 proc_struct.setfield ("QuotaPeakNonPagedPoolUsage", 0);
317 proc_struct.setfield ("QuotaNonPagedPoolUsage", 0);
318 proc_struct.setfield ("PagefileUsage", 0);
319 proc_struct.setfield ("PeakPagefileUsage", 0);
320 }
321
322 CloseHandle (h_proc);
323
324 // Get system memory usage
325 octave_scalar_map sys_struct;
326
327 MEMORYSTATUSEX mem_stat;
328
329 mem_stat.dwLength = sizeof (mem_stat);
330
331 if (GlobalMemoryStatusEx (&mem_stat))
332 {
333 sys_struct.setfield ("MemoryLoad", mem_stat.dwMemoryLoad);
334 sys_struct.setfield ("TotalPhys", mem_stat.ullTotalPhys);
335 sys_struct.setfield ("AvailPhys", mem_stat.ullAvailPhys);
336 sys_struct.setfield ("TotalPageFile", mem_stat.ullTotalPageFile);
337 sys_struct.setfield ("AvailPageFile", mem_stat.ullAvailPageFile);
338 sys_struct.setfield ("TotalVirtual", mem_stat.ullTotalVirtual);
339 sys_struct.setfield ("AvailVirtual", mem_stat.ullAvailVirtual);
340 sys_struct.setfield ("AvailExtendedVirtual",
341 mem_stat.ullAvailExtendedVirtual);
342 }
343 else
344 {
345 sys_struct.setfield ("MemoryLoad", 0);
346 sys_struct.setfield ("TotalPhys", 0);
347 sys_struct.setfield ("AvailPhys", 0);
348 sys_struct.setfield ("TotalPageFile", 0);
349 sys_struct.setfield ("AvailPageFile", 0);
350 sys_struct.setfield ("TotalVirtual", 0);
351 sys_struct.setfield ("AvailVirtual", 0);
352 sys_struct.setfield ("AvailExtendedVirtual", 0);
353 }
354
355 return ovl (proc_struct, sys_struct);
356
357#else
358 octave_unused_parameter (args);
359 error ("__wmemory__: Function is only supported on Windows platforms");
360#endif
361}
362
363#if defined (__MINGW32__)
364
365 static void
366 MINGW_init (void)
367 {
368 w32_init ();
369 }
370
371#endif
372
373#if defined (_MSC_VER)
374
375 static void
376 MSVC_init (void)
377 {
378 w32_init ();
379 }
380
381#endif
382
383 // Return TRUE if FILE1 and FILE2 refer to the same (physical) file.
384
385 bool same_file_internal (const std::string& file1, const std::string& file2)
386 {
387#if defined (OCTAVE_USE_WINDOWS_API)
388
389 // FIXME: When Octave switches to C++17, consider replacing this function
390 // by https://en.cppreference.com/w/cpp/filesystem/equivalent.
391
392 bool retval = false;
393
394 std::wstring file1w = sys::u8_to_wstring (file1);
395 std::wstring file2w = sys::u8_to_wstring (file2);
396 const wchar_t *f1 = file1w.c_str ();
397 const wchar_t *f2 = file2w.c_str ();
398
399 bool f1_is_dir = GetFileAttributesW (f1) & FILE_ATTRIBUTE_DIRECTORY;
400 bool f2_is_dir = GetFileAttributesW (f2) & FILE_ATTRIBUTE_DIRECTORY;
401
402 // Windows native code
403 // Reference: http://msdn2.microsoft.com/en-us/library/aa363788.aspx
404
405 DWORD share = FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE;
406
407 HANDLE hfile1
408 = CreateFileW (f1, 0, share, 0, OPEN_EXISTING,
409 f1_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0);
410
411 if (hfile1 != INVALID_HANDLE_VALUE)
412 {
413 HANDLE hfile2
414 = CreateFileW (f2, 0, share, 0, OPEN_EXISTING,
415 f2_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0);
416
417 if (hfile2 != INVALID_HANDLE_VALUE)
418 {
419 BY_HANDLE_FILE_INFORMATION hfi1;
420 BY_HANDLE_FILE_INFORMATION hfi2;
421
422 if (GetFileInformationByHandle (hfile1, &hfi1)
423 && GetFileInformationByHandle (hfile2, &hfi2))
424 {
425 retval = (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber
426 && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh
427 && hfi1.nFileIndexLow == hfi2.nFileIndexLow
428 && hfi1.nFileSizeHigh == hfi2.nFileSizeHigh
429 && hfi1.nFileSizeLow == hfi2.nFileSizeLow
430 && hfi1.ftLastWriteTime.dwLowDateTime
431 == hfi2.ftLastWriteTime.dwLowDateTime
432 && hfi1.ftLastWriteTime.dwHighDateTime
433 == hfi2.ftLastWriteTime.dwHighDateTime);
434 }
435
436 CloseHandle (hfile2);
437 }
438
439 CloseHandle (hfile1);
440 }
441
442 return retval;
443
444#else
445
446 // POSIX Code
447
448 sys::file_stat fs_file1 (file1);
449 sys::file_stat fs_file2 (file2);
450
451 return (fs_file1 && fs_file2
452 && fs_file1.ino () == fs_file2.ino ()
453 && fs_file1.dev () == fs_file2.dev ());
454
455#endif
456 }
457
458 // Return TRUE if NAME refers to an existing drive letter or UNC share
459
460 bool drive_or_unc_share (const std::string& name)
461 {
462#if defined (OCTAVE_USE_WINDOWS_API)
463 std::size_t len = name.length ();
464 bool candidate = false;
465 if (len > 1 && isalpha(name[0]) && name[1]==':'
466 && (len == 2 || (len == 3 && name[2] == '\\')))
467 candidate = true;
468 if (len > 4 && name[0] == '\\' && name[1] == '\\')
469 {
470 // It starts with two slashes. Find the next slash.
471 std::size_t next_slash = name.find ('\\', 3);
472 if (next_slash != std::string::npos && len > next_slash+1)
473 {
474 // Check if it ends with the share
475 std::size_t last_slash = name.find ('\\', next_slash+1);
476 if (last_slash == std::string::npos
477 || (len > next_slash+2 && last_slash == len-1))
478 candidate = true;
479 }
480 }
481
482 if (candidate)
483 {
484 // Open a handle to the file.
485 std::wstring wname = sys::u8_to_wstring (name);
486 HANDLE h
487 = CreateFileW (wname.c_str (), FILE_READ_ATTRIBUTES,
488 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
489 nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS,
490 nullptr);
491 if (h != INVALID_HANDLE_VALUE)
492 {
493 CloseHandle (h);
494 return true;
495 }
496 }
497
498 return false;
499
500#else
501
502 octave_unused_parameter (name);
503
504 return false;
505
506#endif
507 }
508
509 void sysdep_init (void)
510 {
511 // Use a function from libgomp to force loading of OpenMP library.
512 // Otherwise, a dynamically loaded library making use of OpenMP such
513 // as GraphicsMagick will segfault on exit (bug #41699).
514#if defined (HAVE_OMP_GET_NUM_THREADS)
515 omp_get_num_threads ();
516#endif
517
518#if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__)
519 BSD_init ();
520#elif defined (__MINGW32__)
521 MINGW_init ();
522#elif defined (_MSC_VER)
523 MSVC_init ();
524#endif
525 }
526
527 void sysdep_cleanup (void)
528 {
529#if defined (OCTAVE_USE_WINDOWS_API)
530 // Let us fail immediately without displaying any dialog.
531 SetProcessShutdownParameters (0x280, SHUTDOWN_NORETRY);
532#endif
533 }
534
535 // Set terminal in raw mode. From less-177.
536 //
537 // Change terminal to "raw mode", or restore to "normal" mode.
538 // "Raw mode" means
539 // 1. An outstanding read will complete on receipt of a single keystroke.
540 // 2. Input is not echoed.
541 // 3. On output, \n is mapped to \r\n.
542 // 4. \t is NOT expanded into spaces.
543 // 5. Signal-causing characters such as ctrl-C (interrupt),
544 // etc. are NOT disabled.
545 // It doesn't matter whether an input \n is mapped to \r, or vice versa.
546
547 void raw_mode (bool on, bool wait)
548 {
549 static bool curr_on = false;
550
551 int tty_fd = STDIN_FILENO;
552 if (! octave_isatty_wrapper (tty_fd))
553 {
554 interpreter& interp = __get_interpreter__ ("raw_mode");
555
556 if (interp.interactive () && ! application::forced_interactive ())
557 error ("stdin is not a tty!");
558 }
559
560 if (on == curr_on)
561 return;
562
563#if defined (HAVE_TERMIOS_H)
564 {
565 struct termios s;
566 static struct termios save_term;
567
568 if (on)
569 {
570 // Get terminal modes.
571
572 tcgetattr (tty_fd, &s);
573
574 // Save modes and set certain variables dependent on modes.
575
576 save_term = s;
577 // ospeed = s.c_cflag & CBAUD;
578 // erase_char = s.c_cc[VERASE];
579 // kill_char = s.c_cc[VKILL];
580
581 // Set the modes to the way we want them.
582
583 s.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL);
584 s.c_oflag |= (OPOST | ONLCR);
585#if defined (OCRNL)
586 s.c_oflag &= ~(OCRNL);
587#endif
588#if defined (ONOCR)
589 s.c_oflag &= ~(ONOCR);
590#endif
591#if defined (ONLRET)
592 s.c_oflag &= ~(ONLRET);
593#endif
594 s.c_cc[VMIN] = (wait ? 1 : 0);
595 s.c_cc[VTIME] = 0;
596 }
597 else
598 {
599 // Restore saved modes.
600
601 s = save_term;
602 }
603
604 tcsetattr (tty_fd, wait ? TCSAFLUSH : TCSADRAIN, &s);
605 }
606#elif defined (HAVE_TERMIO_H)
607 {
608 struct termio s;
609 static struct termio save_term;
610
611 if (on)
612 {
613 // Get terminal modes.
614
615 ioctl (tty_fd, TCGETA, &s);
616
617 // Save modes and set certain variables dependent on modes.
618
619 save_term = s;
620 // ospeed = s.c_cflag & CBAUD;
621 // erase_char = s.c_cc[VERASE];
622 // kill_char = s.c_cc[VKILL];
623
624 // Set the modes to the way we want them.
625
626 s.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL);
627 s.c_oflag |= (OPOST | ONLCR);
628#if defined (OCRNL)
629 s.c_oflag &= ~(OCRNL);
630#endif
631#if defined (ONOCR)
632 s.c_oflag &= ~(ONOCR);
633#endif
634#if defined (ONLRET)
635 s.c_oflag &= ~(ONLRET);
636#endif
637 s.c_cc[VMIN] = (wait ? 1 : 0);
638 }
639 else
640 {
641 // Restore saved modes.
642
643 s = save_term;
644 }
645
646 ioctl (tty_fd, TCSETAW, &s);
647 }
648#elif defined (HAVE_SGTTY_H)
649 {
650 octave_unused_parameter (wait);
651
652 struct sgttyb s;
653 static struct sgttyb save_term;
654
655 if (on)
656 {
657 // Get terminal modes.
658
659 ioctl (tty_fd, TIOCGETP, &s);
660
661 // Save modes and set certain variables dependent on modes.
662
663 save_term = s;
664 // ospeed = s.sg_ospeed;
665 // erase_char = s.sg_erase;
666 // kill_char = s.sg_kill;
667
668 // Set the modes to the way we want them.
669
670 s.sg_flags |= CBREAK;
671 s.sg_flags &= ~(ECHO);
672 }
673 else
674 {
675 // Restore saved modes.
676
677 s = save_term;
678 }
679
680 ioctl (tty_fd, TIOCSETN, &s);
681 }
682#else
683
684 octave_unused_parameter (wait);
685
686 warn_disabled_feature ("", "raw mode console I/O");
687
688 // Make sure the current mode doesn't toggle.
689 on = curr_on;
690#endif
691
692 curr_on = on;
693 }
694
695 FILE * popen (const char *command, const char *mode)
696 {
697#if defined (__MINGW32__) || defined (_MSC_VER)
698 std::wstring wcommand = sys::u8_to_wstring (command);
699 std::wstring wmode = sys::u8_to_wstring (mode);
700
701 // Use binary mode on Windows if unspecified
702 if (wmode.length () < 2)
703 wmode += L'b';
704
705 return _wpopen (wcommand.c_str (), wmode.c_str ());
706#else
707 return ::popen (command, mode);
708#endif
709 }
710
711 int pclose (FILE *f)
712 {
713#if defined (__MINGW32__) || defined (_MSC_VER)
714 return ::_pclose (f);
715#else
717#endif
718 }
719
720 // Read one character from the terminal.
721
722 int kbhit (bool wait)
723 {
724#if defined (HAVE__KBHIT) && defined (HAVE__GETCH)
725 // This essentially means we are on a Windows system.
726
727 // The value to return when wait is false and no input is ready.
728 static constexpr int eof = std::istream::traits_type::eof ();
729
730 int c;
731
732 if (wait)
733 c = _getch ();
734 else
735 c = (! _kbhit ()) ? eof : _getch ();
736
737#else
738 raw_mode (true, wait);
739
740 // Get current handler.
741 interrupt_handler saved_interrupt_handler
743
744 // Restore it, disabling system call restarts (if possible) so the
745 // read can be interrupted.
746
747 set_interrupt_handler (saved_interrupt_handler, false);
748
749 int c = std::cin.get ();
750
751 if (std::cin.fail () || std::cin.eof ())
752 {
753 std::cin.clear ();
754 clearerr (stdin);
755 }
756
757 // Restore it, enabling system call restarts (if possible).
758 set_interrupt_handler (saved_interrupt_handler, true);
759
760 raw_mode (false, true);
761#endif
762
763 return c;
764 }
765
766 std::string get_P_tmpdir (void)
767 {
768#if defined (OCTAVE_USE_WINDOWS_API)
769
770 std::string retval;
771
772#if defined (P_tmpdir)
773 retval = P_tmpdir;
774#endif
775
776 // Apparently some versions of MinGW and MSVC either don't define
777 // P_tmpdir, or they define it to a single backslash, neither of which
778 // is particularly helpful.
779
780 if (retval.empty () || retval == R"(\)")
781 {
782 retval = sys::env::getenv ("TEMP");
783
784 if (retval.empty ())
785 retval = sys::env::getenv ("TMP");
786
787 if (retval.empty ())
788 retval = R"(c:\temp)";
789 }
790
791 return retval;
792
793#elif defined (P_tmpdir)
794
795 return P_tmpdir;
796
797#else
798
799 return "/tmp";
800
801#endif
802 }
803
804DEFUN (clc, , ,
805 doc: /* -*- texinfo -*-
806@deftypefn {} {} clc ()
807@deftypefnx {} {} home ()
808Clear the terminal screen and move the cursor to the upper left corner.
809@end deftypefn */)
810{
811 bool skip_redisplay = true;
812
813 command_editor::clear_screen (skip_redisplay);
814
815 return ovl ();
816}
817
818DEFALIAS (home, clc);
819
820DEFUN (getenv, args, ,
821 doc: /* -*- texinfo -*-
822@deftypefn {} {} getenv (@var{var})
823Return the value of the environment variable @var{var}.
824
825For example,
826
827@example
828getenv ("PATH")
829@end example
830
831@noindent
832returns a string containing the value of your path.
833@seealso{setenv, unsetenv}
834@end deftypefn */)
835{
836 if (args.length () != 1)
837 print_usage ();
838
839 std::string name = args(0).string_value ();
840
841 return ovl (sys::env::getenv (name));
842}
843
844/*
845%!assert (ischar (getenv ("OCTAVE_HOME")))
846*/
847
848DEFUN (setenv, args, ,
849 doc: /* -*- texinfo -*-
850@deftypefn {} {} setenv (@var{var}, @var{value})
851@deftypefnx {} {} setenv (@var{var})
852@deftypefnx {} {} putenv (@dots{})
853Set the value of the environment variable @var{var} to @var{value}.
854
855If no @var{value} is specified then the variable will be assigned the null
856string.
857@seealso{unsetenv, getenv}
858@end deftypefn */)
859{
860 int nargin = args.length ();
861
862 if (nargin < 1 || nargin > 2)
863 print_usage ();
864
865 std::string var = args(0).xstring_value ("setenv: VAR must be a string");
866
867 std::string val = (nargin == 2
868 ? args(1).xstring_value ("setenv: VALUE must be a string")
869 : "");
870
871 sys::env::putenv (var, val);
872
873 return ovl ();
874}
875
876DEFALIAS (putenv, setenv);
877
878/*
879%!test
880%! setenv ("dummy_variable_that_cannot_matter", "foobar");
881%! assert (getenv ("dummy_variable_that_cannot_matter"), "foobar");
882%! unsetenv ("dummy_variable_that_cannot_matter");
883%! assert (getenv ("dummy_variable_that_cannot_matter"), "");
884*/
885
886DEFUN (unsetenv, args, ,
887 doc: /* -*- texinfo -*-
888@deftypefn {} {@var{status} =} unsetenv (@var{var})
889Delete the environment variable @var{var}.
890
891Return 0 if the variable was deleted, or did not exist, and -1 if an error
892occurred.
893@seealso{setenv, getenv}
894@end deftypefn */)
895{
896 if (args.length () != 1)
897 print_usage ();
898
899 std::string tmp = args(0).string_value ();
900
901 return ovl (sys::unsetenv_wrapper (tmp));
902}
903
904/*
905## Test for unsetenv is in setenv test
906*/
907
908#if defined (OCTAVE_USE_WINDOWS_API)
909
910 static void
911 reg_close_key_wrapper (HKEY key)
912 {
913 RegCloseKey (key);
914 }
915
916 // This function is also used in ov-java.cc, so don't declare static.
917 // Maybe the functions that use it should be here instead?
918
919 LONG
920 get_regkey_value (HKEY h_rootkey, const std::string subkey,
921 const std::string name, octave_value& value)
922 {
923 LONG result;
924 HKEY h_subkey;
925
926 std::wstring wsubkey = sys::u8_to_wstring (subkey);
927 result = RegOpenKeyExW (h_rootkey, wsubkey.c_str (), 0, KEY_READ,
928 &h_subkey);
929
930 if (result != ERROR_SUCCESS)
931 return result;
932
933 unwind_action restore_keys ([=] () { reg_close_key_wrapper (h_subkey); });
934
935 std::wstring wname = sys::u8_to_wstring (name);
936 DWORD length = 0;
937 result = RegQueryValueExW (h_subkey, wname.c_str (), nullptr, nullptr,
938 nullptr, &length);
939 if (result != ERROR_SUCCESS)
940 return result;
941
942 DWORD type = 0;
943 OCTAVE_LOCAL_BUFFER (BYTE, data, length);
944 result = RegQueryValueExW (h_subkey, wname.c_str (), nullptr, &type,
945 data, &length);
946 if (result != ERROR_SUCCESS)
947 return result;
948
949 if (type == REG_DWORD)
950 value = octave_int32 (*(reinterpret_cast<DWORD *> (data)));
951 else if (type == REG_SZ || type == REG_EXPAND_SZ)
952 {
953 // strings in registry might not be zero terminated
954 wchar_t *dataw = reinterpret_cast<wchar_t *> (data);
955 DWORD lengthw = length / sizeof (wchar_t);
956 std::wstring reg_string
957 = std::wstring (dataw, lengthw - (dataw[lengthw-1]==0));
958 value = string_vector (sys::u8_from_wstring (reg_string));
959 }
960
961 return result;
962 }
963
964 static LONG
965 get_regkey_names (HKEY h_rootkey, const std::string subkey,
966 std::list<std::string> &fields)
967 {
968 LONG retval;
969 HKEY h_subkey;
970
971 fields.clear ();
972
973 std::wstring wsubkey = sys::u8_to_wstring (subkey);
974 retval = RegOpenKeyExW (h_rootkey, wsubkey.c_str (), 0, KEY_READ,
975 &h_subkey);
976 if (retval != ERROR_SUCCESS)
977 return retval;
978
979 DWORD idx = 0;
980 const int MAX_VALUE_NAME_SIZE = 32766;
981 wchar_t value_name[MAX_VALUE_NAME_SIZE+1];
982 DWORD value_name_size = MAX_VALUE_NAME_SIZE;
983
984 while (true)
985 {
986 retval = RegEnumValueW (h_subkey, idx, value_name, &value_name_size,
987 nullptr, nullptr, nullptr, nullptr);
988 if (retval != ERROR_SUCCESS)
989 break;
990 fields.push_back (sys::u8_from_wstring (value_name));
991 value_name_size = MAX_VALUE_NAME_SIZE;
992 idx++;
993 }
994
995 if (retval == ERROR_NO_MORE_ITEMS)
996 retval = ERROR_SUCCESS;
997
998 RegCloseKey (h_subkey);
999
1000 return retval;
1001 }
1002
1003#endif
1004
1005DEFUN (winqueryreg, args, ,
1006 doc: /* -*- texinfo -*-
1007@deftypefn {} {@var{value} =} winqueryreg (@var{rootkey}, @var{subkey}, @var{valuename})
1008@deftypefnx {} {@var{value} =} winqueryreg (@var{rootkey}, @var{subkey})
1009@deftypefnx {} {@var{names} =} winqueryreg (@code{"name"}, @var{rootkey}, @var{subkey})
1010
1011Query names or value from the Windows registry.
1012
1013On Windows, return the value of the registry key @var{subkey} from the root key
1014@var{rootkey}. You can specify the name of the queried registry value with the
1015optional argument @var{valuename}. Otherwise, if called with only two
1016arguments or @var{valuename} is empty, then the default value of @var{subkey}
1017is returned. If the registry value is of type @nospell{@qcode{"REG_DWORD"}}
1018then @var{value} is of class int32. If the value is of the type
1019@nospell{@qcode{"REG_SZ"}} or @nospell{@qcode{"REG_EXPAND_SZ"}} a string is
1020returned.
1021
1022If the first argument is @qcode{"name"}, a cell array of strings with the names
1023of the values at that key is returned.
1024
1025The variable @var{rootkey} must be a string with a valid root key identifier:
1026
1027@table @asis
1028@item @nospell{HKCR}
1029@itemx @nospell{HKEY_CLASSES_ROOT}
1030
1031@item @nospell{HKEY_CURRENT_CONFIG}
1032
1033@item @nospell{HKCU}
1034@itemx @nospell{HKEY_CURRENT_USER}
1035
1036@item @nospell{HKLM}
1037@itemx @nospell{HKEY_LOCAL_MACHINE}
1038
1039
1040@item @nospell{HKU}
1041@itemx @nospell{HKEY_USERS}
1042
1043
1044@item @nospell{HKEY_PERFORMANCE_DATA}
1045
1046@end table
1047
1048Examples:
1049
1050Get a list of value names at the key
1051@nospell{@qcode{'HKCU@backslashchar{}Environment'}}:
1052
1053@example
1054@group
1055@var{valuenames} = winqueryreg ("name", "HKEY_CURRENT_USER", ...
1056 "Environment");
1057@end group
1058@end example
1059
1060For each @var{valuenames}, display the value:
1061
1062@example
1063@group
1064for @var{k} = 1:numel (@var{valuenames})
1065 @var{val} = winqueryreg ("HKEY_CURRENT_USER", "Environment", ...
1066 @var{valuenames}@{@var{k}@});
1067 @var{str} = sprintf ("%s = %s", @var{valuenames}@{@var{k}@}, num2str (@var{val}));
1068 disp (@var{str});
1069endfor
1070@end group
1071@end example
1072
1073On non-Windows platforms this function fails with an error.
1074@end deftypefn */)
1075{
1076#if defined (OCTAVE_USE_WINDOWS_API)
1077 if ((args.length () < 2) || (args.length () > 3))
1078 print_usage ();
1079
1080 // Input check
1081 std::string rootkey_name
1082 = args(0).xstring_value ("winqueryreg: the first argument must be 'name' "
1083 "or a valid ROOTKEY identifier");
1084 std::string subkey_name = "";
1085 std::string value_name = "";
1086 bool get_names = false;
1087 if (rootkey_name.compare ("name") == 0)
1088 {
1089 if (args.length () < 3)
1090 error ("winqueryreg: if the first argument is 'name', "
1091 "ROOTKEY and SUBKEY must be given");
1092 get_names = true;
1093 rootkey_name
1094 = args(1).xstring_value ("winqueryreg: ROOTKEY must be a string");
1095 subkey_name
1096 = args(2).xstring_value ("winqueryreg: SUBKEY must be a string");
1097 }
1098 else
1099 {
1100 subkey_name
1101 = args(1).xstring_value ("winqueryreg: SUBKEY must be a string");
1102
1103 if (args.length () == 3)
1104 value_name
1105 = args(2).xstring_value ("winqueryreg: VALUENAME must be a string");
1106 }
1107
1108 // Get rootkey handle
1109 HKEY h_rootkey;
1110 if (rootkey_name == "HKEY_CLASSES_ROOT" || rootkey_name == "HKCR")
1111 h_rootkey = HKEY_CLASSES_ROOT;
1112 else if (rootkey_name == "HKEY_CURRENT_CONFIG")
1113 h_rootkey = HKEY_CURRENT_CONFIG;
1114 else if (rootkey_name == "HKEY_CURRENT_USER" || rootkey_name == "HKCU")
1115 h_rootkey = HKEY_CURRENT_USER;
1116 else if (rootkey_name == "HKEY_LOCAL_MACHINE" || rootkey_name == "HKLM")
1117 h_rootkey = HKEY_LOCAL_MACHINE;
1118 else if (rootkey_name == "HKEY_PERFORMANCE_DATA")
1119 h_rootkey = HKEY_PERFORMANCE_DATA;
1120 else if (rootkey_name == "HKEY_USERS" || rootkey_name == "HKU")
1121 h_rootkey = HKEY_USERS;
1122 else
1123 error ("winqueryreg: ROOTKEY is not a valid root key identifier");
1124
1125 if (get_names)
1126 {
1127 std::list<std::string> fields;
1128
1129 LONG retval = get_regkey_names (h_rootkey, subkey_name, fields);
1130 if (retval != ERROR_SUCCESS)
1131 error ("winqueryreg: error %ld reading names from registry", retval);
1132
1133 Cell fieldnames (dim_vector (1, fields.size ()));
1134 std::size_t i;
1135 std::list<std::string>::const_iterator it;
1136 for (i = 0, it = fields.begin (); it != fields.end (); ++it, ++i)
1137 fieldnames(i) = *it;
1138
1139 return ovl (fieldnames);
1140 }
1141 else
1142 {
1143 octave_value key_val;
1144 LONG retval = get_regkey_value (h_rootkey, subkey_name,
1145 value_name, key_val);
1146 if (retval == ERROR_FILE_NOT_FOUND)
1147 error ("winqueryreg: no value found for '%s' at %s\\%s",
1148 value_name.c_str (), rootkey_name.c_str (),
1149 subkey_name.c_str ());
1150 if (retval != ERROR_SUCCESS)
1151 error ("winqueryreg: error %ld reading the specified key", retval);
1152
1153 return ovl (key_val);
1154 }
1155#else
1156
1157 octave_unused_parameter (args);
1158
1159 error ("winqueryreg: function is only supported on Windows platforms");
1160
1161#endif
1162}
1163
1164/*
1165%!testif ; ispc ()
1166%! assert (ischar (winqueryreg ("HKEY_LOCAL_MACHINE",
1167%! 'SOFTWARE\Microsoft\Windows\CurrentVersion',
1168%! "ProgramFilesDir")));
1169%!testif ; ispc ()
1170%! assert (isa (winqueryreg ("HKEY_LOCAL_MACHINE",
1171%! 'SYSTEM\CurrentControlSet\Control\FileSystem',
1172%! "Win31FileSystem"), "int32"));
1173%!testif ; ispc ()
1174%! assert (iscellstr (winqueryreg ("name", "HKEY_LOCAL_MACHINE",
1175%! 'SOFTWARE\Microsoft\Windows\CurrentVersion')));
1176%!testif ; ispc ()
1177%! fail ('winqueryreg (1, ''SOFTWARE\Microsoft\Windows\CurrentVersion'')',
1178%! "first argument must be 'name' or a valid ROOTKEY identifier");
1179%!testif ; ispc ()
1180%! fail ('winqueryreg ("HKEY_LOCAL_MACHINE", 1)', "SUBKEY must be a string");
1181%!testif ; ispc ()
1182%! fail (['winqueryreg ("HKEY_LOCAL_MACHINE", ', ...
1183%! '''SOFTWARE\Microsoft\Windows\CurrentVersion'', 1)'],
1184%! "VALUENAME must be a string");
1185%!testif ; ispc ()
1186%! fail (['winqueryreg ("FOO", ', ...
1187%! '''SOFTWARE\Microsoft\Windows\CurrentVersion'')'],
1188%! "ROOTKEY is not a valid root key identifier");
1189%!testif ; ispc ()
1190%! fail ('winqueryreg ("HKEY_LOCAL_MACHINE", ''FOO\bar'')',
1191%! "no value found for");
1192%!testif ; ispc ()
1193%! fail (['winqueryreg ("HKEY_LOCAL_MACHINE", ', ...
1194%! '''SOFTWARE\Microsoft\Windows\CurrentVersion'', "foo")'],
1195%! "no value found for");
1196%!testif ; ispc ()
1197%! fail ('winqueryreg ("name", "HKEY_LOCAL_MACHINE")',
1198%! "if the first argument is 'name', ROOTKEY and SUBKEY must be given");
1199%!testif ; ispc ()
1200%! fail (['winqueryreg ("name", 1, ', ...
1201%! '''SOFTWARE\Microsoft\Windows\CurrentVersion'')'],
1202%! "ROOTKEY must be a string");
1203%!testif ; ispc ()
1204%! fail ('winqueryreg ("name", "HKEY_LOCAL_MACHINE", 1)',
1205%! "SUBKEY must be a string");
1206*/
1207
1208// FIXME: perhaps kbhit should also be able to print a prompt?
1209
1210DEFMETHOD (kbhit, interp, args, ,
1211 doc: /* -*- texinfo -*-
1212@deftypefn {} {} kbhit ()
1213@deftypefnx {} {} kbhit (1)
1214Read a single keystroke from the keyboard.
1215
1216If called with an argument, don't wait for a keypress.
1217
1218For example,
1219
1220@example
1221x = kbhit ();
1222@end example
1223
1224@noindent
1225will set @var{x} to the next character typed at the keyboard as soon as
1226it is typed.
1227
1228@example
1229x = kbhit (1);
1230@end example
1231
1232@noindent
1233is identical to the above example, but doesn't wait for a keypress,
1234returning the empty string if no key is available.
1235@seealso{input, pause}
1236@end deftypefn */)
1237{
1238 // FIXME: add timeout and default value args?
1239
1240 Fdrawnow (interp);
1241
1242 int c = kbhit (args.length () == 0);
1243
1244 if (c == -1)
1245 c = 0;
1246
1247 char s[2] = { static_cast<char> (c), '\0' };
1248
1249 return octave_value (s);
1250}
1251
1252// State of the pause system
1253static bool Vpause_enabled = true;
1254
1255DEFMETHOD (pause, interp, args, nargout,
1256 doc: /* -*- texinfo -*-
1257@deftypefn {} {} pause ()
1258@deftypefnx {} {} pause (@var{n})
1259@deftypefnx {} {@var{old_state} =} pause ("on")
1260@deftypefnx {} {@var{old_state} =} pause ("off")
1261@deftypefnx {} {@var{old_state} =} pause ("query")
1262Suspend the execution of the program or change the state of the pause function.
1263
1264If invoked without an input arguments then the program is suspended until a
1265character is typed. If argument @var{n} is a positive real value, it indicates
1266the number of seconds the program shall be suspended, for example:
1267
1268@example
1269@group
1270tic; pause (0.05); toc
1271 @print{} Elapsed time is 0.05039 seconds.
1272@end group
1273@end example
1274
1275The following example prints a message and then waits 5 seconds before
1276clearing the screen.
1277
1278@example
1279@group
1280disp ("wait please...");
1281pause (5);
1282clc;
1283@end group
1284@end example
1285
1286If invoked with a string argument @qcode{"on"}, @qcode{"off"}, or
1287@qcode{"query"}, the state of the pause function is changed or queried. When
1288the state is @qcode{"off"}, the pause function returns immediately. The
1289optional return value contains the previous state of the pause function. In
1290the following example pause is disabled locally:
1291
1292@example
1293@group
1294old_state = pause ("off");
1295tic; pause (0.05); toc
1296 @print{} Elapsed time is 3.00407e-05 seconds.
1297pause (old_state);
1298@end group
1299@end example
1300
1301While the program is suspended Octave still handles figures painting and
1302graphics callbacks execution.
1303
1304@seealso{kbhit}
1305@end deftypefn */)
1306{
1307 octave_value_list retval;
1308
1309 int nargin = args.length ();
1310
1311 if (nargin > 1)
1312 print_usage ();
1313
1314 if (nargin == 1 && args(0).is_string ())
1315 {
1316 bool saved_state = Vpause_enabled;
1317 std::string state = args(0).string_value ();
1318
1319 if (state == "on")
1320 Vpause_enabled = true;
1321 else if (state == "off")
1322 Vpause_enabled = false;
1323 else if (state == "query")
1324 ;// Do nothing
1325 else
1326 error (R"(pause: first argument must be "on", "off", or "query")");
1327
1328 if (nargout > 0 || state == "query")
1329 retval.append (saved_state ? "on" : "off");
1330 }
1331 else if (Vpause_enabled)
1332 {
1333 double dval;
1334
1335 if (nargin == 0)
1336 dval = octave_Inf;
1337 else
1338 dval = args(0).xdouble_value ("pause: N must be a scalar real value");
1339
1340 if (math::isnan (dval))
1341 warning ("pause: NaN is an invalid delay");
1342 else
1343 {
1344 Fdrawnow (interp);
1345
1346 sleep (dval, true);
1347 }
1348 }
1349
1350 return retval;
1351}
1352
1353/*
1354%!test
1355%! pause (1);
1356
1357%!error pause (1, 2)
1358*/
1359
1360// FIXME: maybe this should only return 1 if IEEE floating
1361// point functions really work.
1362
1363DEFUN (isieee, , ,
1364 doc: /* -*- texinfo -*-
1365@deftypefn {} {} isieee ()
1366Return true if your computer @emph{claims} to conform to the IEEE standard
1367for floating point calculations.
1368
1369No actual tests are performed.
1370@end deftypefn */)
1371{
1373
1376}
1377
1378/*
1379%!assert (islogical (isieee ()))
1380*/
1381
1383 doc: /* -*- texinfo -*-
1384@deftypefn {} {} native_float_format ()
1385Return the native floating point format as a string.
1386@end deftypefn */)
1387{
1389
1390 return ovl (mach_info::float_format_as_string (flt_fmt));
1391}
1392
1393/*
1394%!assert (ischar (native_float_format ()))
1395*/
1396
1397DEFUN (tilde_expand, args, ,
1398 doc: /* -*- texinfo -*-
1399@deftypefn {} {} tilde_expand (@var{string})
1400@deftypefnx {} {} tilde_expand (@var{cellstr})
1401Perform tilde expansion on @var{string}.
1402
1403If @var{string} begins with a tilde character, (@samp{~}), all of the
1404characters preceding the first slash (or all characters, if there is no
1405slash) are treated as a possible user name, and the tilde and the following
1406characters up to the slash are replaced by the home directory of the named
1407user. If the tilde is followed immediately by a slash, the tilde is
1408replaced by the home directory of the user running Octave.
1409
1410If the input is a cell array of strings @var{cellstr} then tilde expansion
1411is performed on each string element.
1412
1413Examples:
1414
1415@example
1416@group
1417tilde_expand ("~joeuser/bin")
1418 @result{} "/home/joeuser/bin"
1419tilde_expand ("~/bin")
1420 @result{} "/home/jwe/bin"
1421@end group
1422@end example
1423@end deftypefn */)
1424{
1425 if (args.length () != 1)
1426 print_usage ();
1427
1428 octave_value arg = args(0);
1429
1430 string_vector sv = arg.xstring_vector_value ("tilde_expand: argument must be char or cellstr object");
1431
1433
1434 if (arg.iscellstr ())
1435 return ovl (Cell (arg.dims (), sv));
1436 else
1437 return ovl (sv);
1438}
1439
1440/*
1441%!test
1442%! home = get_home_directory ();
1443%! assert (tilde_expand ("~/foobar"), [home "/foobar"]);
1444%! assert (tilde_expand ("/foo/bar"), "/foo/bar");
1445%! assert (tilde_expand ("foo/bar"), "foo/bar");
1446*/
1447
1448DEFUN (get_home_directory, , ,
1449 doc: /* -*- texinfo -*-
1450@deftypefn {} {@var{homedir} =} get_home_directory ()
1451Return the current home directory.
1452
1453On most systems, this is equivalent to @code{getenv ("HOME")}. On Windows
1454systems, if the environment variable @env{HOME} is not set then it is
1455equivalent to
1456@code{fullfile (getenv ("HOMEDRIVE"), getenv ("HOMEPATH"))}
1457@seealso{getenv}
1458@end deftypefn */)
1459{
1460 return ovl (sys::env::get_home_directory ());
1461}
1462
1463/*
1464%!test
1465%! if (! ispc ())
1466%! assert (get_home_directory (), getenv ("HOME"));
1467%! endif
1468*/
1469
1470DEFUN (__blas_version__, , ,
1471 doc: /* -*- texinfo -*-
1472@deftypefn {} {} __blas_version__ ()
1473Undocumented internal function.
1474@end deftypefn */)
1475{
1476 return ovl (sys::blas_version ());
1477}
1478
1479DEFUN (__lapack_version__, , ,
1480 doc: /* -*- texinfo -*-
1481@deftypefn {} {} __lapack_version__ ()
1482Undocumented internal function.
1483@end deftypefn */)
1484{
1485 return ovl (sys::lapack_version ());
1486}
1487
1488OCTAVE_NAMESPACE_END
Definition: Cell.h:43
static bool forced_interactive(void)
Definition: octave.cc:325
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
bool interactive(void) const
Definition: interpreter.h:171
void setfield(const std::string &key, const octave_value &val)
Definition: oct-map.cc:190
octave_value_list & append(const octave_value &val)
Definition: ovl.cc:98
octave_idx_type length(void) const
Definition: ovl.h:113
bool iscellstr(void) const
Definition: ov.h:652
OCTINTERP_API string_vector xstring_vector_value(const char *fmt,...) const
dim_vector dims(void) const
Definition: ov.h:586
OCTINTERP_API void print_usage(void)
Definition: defun-int.h:72
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
Definition: defun.h:111
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:56
#define DEFALIAS(alias, name)
Macro to define an alias for another existing function name.
Definition: defun.h:160
void warning(const char *fmt,...)
Definition: error.cc:1055
void error(const char *fmt,...)
Definition: error.cc:980
void warn_disabled_feature(const std::string &fcn, const std::string &feature, const std::string &pkg)
Definition: errwarn.cc:318
OCTAVE_EXPORT octave_value_list Fdrawnow(octave::interpreter &interp, const octave_value_list &args, int)
Definition: graphics.cc:13899
QString name
#define octave_Inf
Definition: lo-ieee.h:38
F77_RET_T const F77_DBLE const F77_DBLE * f
std::string bin_dir(void)
Definition: defaults.cc:171
float_format native_float_format(void)
Definition: mach-info.cc:65
@ flt_fmt_ieee_little_endian
Definition: mach-info.h:43
std::string float_format_as_string(float_format flt_fmt)
Definition: mach-info.cc:105
bool isnan(bool)
Definition: lo-mappers.h:178
std::string tilde_expand(const std::string &name)
Definition: file-ops.cc:281
std::string u8_from_wstring(const std::wstring &wchar_string)
Definition: lo-sysdep.cc:513
int unsetenv_wrapper(const std::string &name)
Definition: lo-sysdep.cc:477
std::string lapack_version(void)
Definition: lo-sysinfo.cc:163
std::wstring u8_to_wstring(const std::string &utf8_string)
Definition: lo-sysdep.cc:490
std::string blas_version(void)
Definition: lo-sysinfo.cc:45
static uint32_t state[624]
Definition: randmtzig.cc:192
interpreter & __get_interpreter__(const std::string &who)
octave_int< int32_t > octave_int32
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
Definition: oct-locbuf.h:44
#define ECHO
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211
interrupt_handler set_interrupt_handler(const volatile interrupt_handler &h, bool restart_syscalls)
Definition: sighandlers.cc:349
interrupt_handler ignore_interrupts(void)
Definition: sighandlers.cc:338
int kbhit(bool wait)
Definition: sysdep.cc:722
int pclose(FILE *f)
Definition: sysdep.cc:711
bool same_file_internal(const std::string &file1, const std::string &file2)
Definition: sysdep.cc:385
void sysdep_cleanup(void)
Definition: sysdep.cc:527
OCTAVE_NAMESPACE_BEGIN void set_application_id(void)
Definition: sysdep.cc:183
FILE * popen(const char *command, const char *mode)
Definition: sysdep.cc:695
void raw_mode(bool on, bool wait)
Definition: sysdep.cc:547
static bool Vpause_enabled
Definition: sysdep.cc:1253
std::string get_P_tmpdir(void)
Definition: sysdep.cc:766
void sysdep_init(void)
Definition: sysdep.cc:509
#define FSYSTEM_OPEN_STR
bool drive_or_unc_share(const std::string &name)
Definition: sysdep.cc:460
#define STDIN_FILENO
Definition: sysdep.cc:92
OCTAVE_EXPORT octave_value_list Fsystem(const octave_value_list &args, int nargout)
Definition: toplev.cc:242
int octave_isatty_wrapper(int fd)
void sleep(double seconds, bool do_graphics_events)
Definition: utils.cc:1557
F77_RET_T len
Definition: xerbla.cc:61