Mercurial > octave
annotate libinterp/corefcn/sysdep.cc @ 21910:4d723ba06b4a
provide wrappers for some unistd.h functions
* liboctave/wrappers/unistd-wrappers.c,
liboctave/wrappers/unistd-wrappers.h: New files.
* liboctave/wrappers/module.mk: Update.
* gl2ps-print.cc, oct-hist.cc, oct-procbuf.cc, oct-tex-lexer.in.ll,
sysdep.cc, octave.cc, parse-tree/lex.ll, file-ops.cc, lo-sysdep.cc,
oct-env.cc, oct-syscalls.cc, cmd-edit.cc, kpse.cc:
Use wrappers instead of calling unistd.h functions directly.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 14 Jun 2016 18:10:04 -0400 |
parents | 00f1249f2483 |
children | baeffde5c87d |
rev | line source |
---|---|
1 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19540
diff
changeset
|
3 Copyright (C) 1993-2015 John W. Eaton |
1 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21662
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
1 | 25 #endif |
26 | |
1346 | 27 #include <cfloat> |
1343 | 28 #include <cstddef> |
1346 | 29 #include <cstdio> |
1343 | 30 #include <cstdlib> |
31 #include <cstring> | |
32 | |
3503 | 33 #include <iostream> |
1728 | 34 #include <string> |
35 | |
1430 | 36 #if defined (HAVE_TERMIOS_H) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21115
diff
changeset
|
37 # include <termios.h> |
1430 | 38 #elif defined (HAVE_TERMIO_H) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21115
diff
changeset
|
39 # include <termio.h> |
1430 | 40 #elif defined (HAVE_SGTTY_H) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21115
diff
changeset
|
41 # include <sgtty.h> |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
42 #endif |
4067 | 43 |
44 #if defined (HAVE_CONIO_H) | |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21115
diff
changeset
|
45 # include <conio.h> |
1430 | 46 #endif |
47 | |
3248 | 48 #if defined (HAVE_SYS_IOCTL_H) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21115
diff
changeset
|
49 # include <sys/ioctl.h> |
3248 | 50 #endif |
51 | |
1463 | 52 #if defined (HAVE_FLOATINGPOINT_H) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21115
diff
changeset
|
53 # include <floatingpoint.h> |
1463 | 54 #endif |
55 | |
2508 | 56 #if defined (HAVE_IEEEFP_H) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21115
diff
changeset
|
57 # include <ieeefp.h> |
2508 | 58 #endif |
59 | |
21554
9f0088f3f335
call openmp function at initialization (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20788
diff
changeset
|
60 #if defined (HAVE_OMP_H) |
21556 | 61 # include <omp.h> |
21554
9f0088f3f335
call openmp function at initialization (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20788
diff
changeset
|
62 #endif |
9f0088f3f335
call openmp function at initialization (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20788
diff
changeset
|
63 |
2926 | 64 #include "cmd-edit.h" |
65 #include "file-ops.h" | |
2893 | 66 #include "lo-mappers.h" |
7231 | 67 #include "lo-math.h" |
2317 | 68 #include "mach-info.h" |
2926 | 69 #include "oct-env.h" |
5451 | 70 #include "quit.h" |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
71 #include "unistd-wrappers.h" |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
72 #include "unsetenv-wrapper.h" |
1769 | 73 |
6208 | 74 #include "Cell.h" |
15423
53d073233fa4
call more built-in functions directly
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
75 #include "builtins.h" |
1352 | 76 #include "defun.h" |
17851
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
77 #include "display.h" |
1352 | 78 #include "error.h" |
21115
629643522cc0
include errwarn.h in all files that use gripe_disabled_feature
John W. Eaton <jwe@octave.org>
parents:
21109
diff
changeset
|
79 #include "errwarn.h" |
529 | 80 #include "input.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
81 #include "ovl.h" |
2370 | 82 #include "ov.h" |
3234 | 83 #include "pager.h" |
6419 | 84 #include "parse.h" |
5770 | 85 #include "sighandlers.h" |
1352 | 86 #include "sysdep.h" |
1755 | 87 #include "toplev.h" |
529 | 88 #include "utils.h" |
6598 | 89 #include "file-stat.h" |
529 | 90 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21662
diff
changeset
|
91 #if ! defined (STDIN_FILENO) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21115
diff
changeset
|
92 # define STDIN_FILENO 1 |
529 | 93 #endif |
444 | 94 |
9441
160c564d5d25
initialize floating point values properly for NetBSD systems
Aleksej Saushev <asau@inbox.ru>
parents:
9411
diff
changeset
|
95 #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__) |
2508 | 96 static void |
97 BSD_init (void) | |
98 { | |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21115
diff
changeset
|
99 # if defined (HAVE_FLOATINGPOINT_H) |
2508 | 100 // Disable trapping on common exceptions. |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21662
diff
changeset
|
101 # if ! defined (FP_X_DNML) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21115
diff
changeset
|
102 # define FP_X_DNML 0 |
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21115
diff
changeset
|
103 # endif |
2508 | 104 fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP)); |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21115
diff
changeset
|
105 # endif |
2508 | 106 } |
107 #endif | |
108 | |
6956 | 109 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
110 |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
111 #define WIN32_LEAN_AND_MEAN |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
112 #include <tlhelp32.h> |
19271
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19270
diff
changeset
|
113 #include <windows.h> |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
114 |
6080 | 115 static void |
116 w32_set_octave_home (void) | |
117 { | |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
118 std::string bin_dir; |
6080 | 119 |
13885
2f42a7b0cf94
Fix MinGW compilation problem with tlhelp32.h
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13771
diff
changeset
|
120 HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21662
diff
changeset
|
121 #if defined (TH32CS_SNAPMODULE32) |
13885
2f42a7b0cf94
Fix MinGW compilation problem with tlhelp32.h
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13771
diff
changeset
|
122 | TH32CS_SNAPMODULE32 |
2f42a7b0cf94
Fix MinGW compilation problem with tlhelp32.h
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13771
diff
changeset
|
123 #endif |
2f42a7b0cf94
Fix MinGW compilation problem with tlhelp32.h
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13771
diff
changeset
|
124 , 0); |
6080 | 125 |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
126 if (h != INVALID_HANDLE_VALUE) |
6080 | 127 { |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
128 MODULEENTRY32 mod_info; |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
129 |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
130 ZeroMemory (&mod_info, sizeof (mod_info)); |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
131 mod_info.dwSize = sizeof (mod_info); |
13751
be7ff59cbc7a
Fix octinterp DLL searching on Win32.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13282
diff
changeset
|
132 |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
133 if (Module32First (h, &mod_info)) |
14445 | 134 { |
135 do | |
136 { | |
137 std::string mod_name (mod_info.szModule); | |
6080 | 138 |
14445 | 139 if (mod_name.find ("octinterp") != std::string::npos) |
140 { | |
141 bin_dir = mod_info.szExePath; | |
142 if (bin_dir[bin_dir.length () - 1] != '\\') | |
143 bin_dir.append (1, '\\'); | |
144 break; | |
145 } | |
146 } | |
147 while (Module32Next (h, &mod_info)); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
148 } |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
149 |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
150 CloseHandle (h); |
6080 | 151 } |
152 | |
153 if (! bin_dir.empty ()) | |
154 { | |
155 size_t pos = bin_dir.rfind ("\\bin\\"); | |
156 | |
8021 | 157 if (pos != std::string::npos) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
158 octave::sys::env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos)); |
6080 | 159 } |
160 } | |
161 | |
6960 | 162 void |
5451 | 163 w32_set_quiet_shutdown (void) |
164 { | |
165 // Let the user close the console window or shutdown without the | |
166 // pesky dialog. | |
167 // | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
168 // FIXME: should this be user configurable? |
5451 | 169 SetProcessShutdownParameters (0x280, SHUTDOWN_NORETRY); |
170 } | |
171 | |
6960 | 172 void |
5451 | 173 MINGW_signal_cleanup (void) |
174 { | |
5455 | 175 w32_set_quiet_shutdown (); |
5451 | 176 } |
19302
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18674
diff
changeset
|
177 |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18674
diff
changeset
|
178 static void |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18674
diff
changeset
|
179 w32_init (void) |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18674
diff
changeset
|
180 { |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18674
diff
changeset
|
181 w32_set_octave_home (); |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18674
diff
changeset
|
182 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
183 octave::command_editor::prefer_env_winsize (true); |
19302
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18674
diff
changeset
|
184 } |
19774
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
185 |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
186 static bool |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
187 w32_shell_execute (const std::string& file) |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
188 { |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
189 } |
5451 | 190 #endif |
191 | |
19856
5c1a38089f89
Change open_with_system_app to internal function.
Rik <rik@octave.org>
parents:
19849
diff
changeset
|
192 DEFUN (__open_with_system_app__, args, , |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19857
diff
changeset
|
193 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
194 @deftypefn {} {} __open_with_system_app__ (@var{file})\n\ |
19271
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19270
diff
changeset
|
195 Undocumented internal function.\n\ |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19270
diff
changeset
|
196 @end deftypefn") |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19270
diff
changeset
|
197 { |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
198 if (args.length () != 1) |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
199 print_usage (); |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
200 |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
201 std::string file = args(0).xstring_value ("__open_with_system_app__: argument must be a filename"); |
19271
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19270
diff
changeset
|
202 |
19774
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
203 octave_value retval; |
19271
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19270
diff
changeset
|
204 |
19774
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
205 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
206 HINSTANCE status = ShellExecute (0, 0, file.c_str (), 0, 0, |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
207 SW_SHOWNORMAL); |
19271
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19270
diff
changeset
|
208 |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
209 // ShellExecute returns a value greater than 32 if successful. |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
210 retval = (reinterpret_cast<ptrdiff_t> (status) > 32); |
20961
f55251db0833
Add support for the Mac OS X "open" command.
Ben Abbott <bpabbott@mac.com>
parents:
20941
diff
changeset
|
211 #elif defined (__APPLE__) |
f55251db0833
Add support for the Mac OS X "open" command.
Ben Abbott <bpabbott@mac.com>
parents:
20941
diff
changeset
|
212 octave_value_list tmp |
f55251db0833
Add support for the Mac OS X "open" command.
Ben Abbott <bpabbott@mac.com>
parents:
20941
diff
changeset
|
213 = Fsystem (ovl ("open " + file + " 2> /dev/null", |
f55251db0833
Add support for the Mac OS X "open" command.
Ben Abbott <bpabbott@mac.com>
parents:
20941
diff
changeset
|
214 false, "async"), |
f55251db0833
Add support for the Mac OS X "open" command.
Ben Abbott <bpabbott@mac.com>
parents:
20941
diff
changeset
|
215 1); |
19271
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19270
diff
changeset
|
216 |
20961
f55251db0833
Add support for the Mac OS X "open" command.
Ben Abbott <bpabbott@mac.com>
parents:
20941
diff
changeset
|
217 retval = (tmp(0).double_value () == 0); |
19774
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
218 #else |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
219 octave_value_list tmp |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
220 = Fsystem (ovl ("xdg-open " + file + " 2> /dev/null", |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
221 false, "async"), |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
222 1); |
19774
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
223 |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
224 retval = (tmp(0).double_value () == 0); |
19774
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
225 #endif |
19271
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19270
diff
changeset
|
226 |
19774
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
227 return retval; |
19271
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19270
diff
changeset
|
228 } |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19270
diff
changeset
|
229 |
5451 | 230 #if defined (__MINGW32__) |
231 static void | |
232 MINGW_init (void) | |
233 { | |
19302
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18674
diff
changeset
|
234 w32_init (); |
5451 | 235 } |
236 #endif | |
237 | |
6080 | 238 #if defined (_MSC_VER) |
239 static void | |
240 MSVC_init (void) | |
241 { | |
19302
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18674
diff
changeset
|
242 w32_init (); |
6080 | 243 } |
244 #endif | |
245 | |
4091 | 246 |
6598 | 247 // Return TRUE if FILE1 and FILE2 refer to the same (physical) file. |
248 | |
249 bool | |
250 same_file_internal (const std::string& file1, const std::string& file2) | |
251 { | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21662
diff
changeset
|
252 #if defined (OCTAVE_USE_WINDOWS_API) |
6598 | 253 |
6691 | 254 bool retval = false; |
255 | |
16564
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
256 const char *f1 = file1.c_str (); |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
257 const char *f2 = file2.c_str (); |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
258 |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
259 bool f1_is_dir = GetFileAttributes (f1) & FILE_ATTRIBUTE_DIRECTORY; |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
260 bool f2_is_dir = GetFileAttributes (f2) & FILE_ATTRIBUTE_DIRECTORY; |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
261 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
262 // Windows native code |
6598 | 263 // Reference: http://msdn2.microsoft.com/en-us/library/aa363788.aspx |
264 | |
16564
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
265 DWORD share = FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE; |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
266 |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
267 HANDLE hfile1 |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
268 = CreateFile (f1, 0, share, 0, OPEN_EXISTING, |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
269 f1_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0); |
6691 | 270 |
271 if (hfile1 != INVALID_HANDLE_VALUE) | |
272 { | |
16564
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
273 HANDLE hfile2 |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
274 = CreateFile (f2, 0, share, 0, OPEN_EXISTING, |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
275 f2_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0); |
6598 | 276 |
6691 | 277 if (hfile2 != INVALID_HANDLE_VALUE) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
278 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
279 BY_HANDLE_FILE_INFORMATION hfi1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
280 BY_HANDLE_FILE_INFORMATION hfi2; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
281 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
282 if (GetFileInformationByHandle (hfile1, &hfi1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
283 && GetFileInformationByHandle (hfile2, &hfi2)) |
16564
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
284 { |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
285 retval = (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
286 && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
287 && hfi1.nFileIndexLow == hfi2.nFileIndexLow); |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
288 } |
6598 | 289 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
290 CloseHandle (hfile2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
291 } |
6691 | 292 |
6598 | 293 CloseHandle (hfile1); |
294 } | |
6691 | 295 |
296 return retval; | |
6598 | 297 |
298 #else | |
299 | |
300 // POSIX Code | |
301 | |
21736
0504351a45e6
use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
302 octave::sys::file_stat fs_file1 (file1); |
0504351a45e6
use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
303 octave::sys::file_stat fs_file2 (file2); |
6598 | 304 |
305 return (fs_file1 && fs_file2 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
306 && fs_file1.ino () == fs_file2.ino () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
307 && fs_file1.dev () == fs_file2.dev ()); |
6598 | 308 |
309 #endif | |
310 } | |
311 | |
1 | 312 void |
313 sysdep_init (void) | |
314 { | |
21557
f6663c49870c
Add comment clarifying why omp_get_num_threads is called in sysdep.cc.
Rik <rik@octave.org>
parents:
21556
diff
changeset
|
315 // Use a function from libgomp to force loading of OpenMP library. |
f6663c49870c
Add comment clarifying why omp_get_num_threads is called in sysdep.cc.
Rik <rik@octave.org>
parents:
21556
diff
changeset
|
316 // Otherwise, a dynamically loaded library making use of OpenMP such |
f6663c49870c
Add comment clarifying why omp_get_num_threads is called in sysdep.cc.
Rik <rik@octave.org>
parents:
21556
diff
changeset
|
317 // as GraphicsMagick will segfault on exit (bug #41699). |
21554
9f0088f3f335
call openmp function at initialization (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20788
diff
changeset
|
318 #if defined (HAVE_OMP_GET_NUM_THREADS) |
9f0088f3f335
call openmp function at initialization (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20788
diff
changeset
|
319 omp_get_num_threads (); |
9f0088f3f335
call openmp function at initialization (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20788
diff
changeset
|
320 #endif |
9f0088f3f335
call openmp function at initialization (bug #47372)
John W. Eaton <jwe@octave.org>
parents:
20788
diff
changeset
|
321 |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14445
diff
changeset
|
322 #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__) |
2508 | 323 BSD_init (); |
5451 | 324 #elif defined (__MINGW32__) |
325 MINGW_init (); | |
6080 | 326 #elif defined (_MSC_VER) |
327 MSVC_init (); | |
1 | 328 #endif |
329 } | |
330 | |
5451 | 331 void |
332 sysdep_cleanup (void) | |
333 { | |
334 MINGW_SIGNAL_CLEANUP (); | |
335 } | |
336 | |
767 | 337 // Set terminal in raw mode. From less-177. |
338 // | |
339 // Change terminal to "raw mode", or restore to "normal" mode. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
340 // "Raw mode" means |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
341 // 1. An outstanding read will complete on receipt of a single keystroke. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
342 // 2. Input is not echoed. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
343 // 3. On output, \n is mapped to \r\n. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
344 // 4. \t is NOT expanded into spaces. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
345 // 5. Signal-causing characters such as ctrl-C (interrupt), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
346 // etc. are NOT disabled. |
767 | 347 // It doesn't matter whether an input \n is mapped to \r, or vice versa. |
348 | |
529 | 349 void |
3657 | 350 raw_mode (bool on, bool wait) |
529 | 351 { |
3657 | 352 static bool curr_on = false; |
529 | 353 |
354 int tty_fd = STDIN_FILENO; | |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21888
diff
changeset
|
355 if (! octave_isatty_wrapper (tty_fd)) |
529 | 356 { |
19849
1c9ed5b4c73d
input.h: change meaning of interactive and forced_interactive global variables.
Carnë Draug <carandraug@octave.org>
parents:
19774
diff
changeset
|
357 if (interactive && ! forced_interactive) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
358 error ("stdin is not a tty!"); |
529 | 359 } |
360 | |
361 if (on == curr_on) | |
362 return; | |
363 | |
364 #if defined (HAVE_TERMIOS_H) | |
365 { | |
366 struct termios s; | |
367 static struct termios save_term; | |
368 | |
369 if (on) | |
370 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
371 // Get terminal modes. |
529 | 372 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
373 tcgetattr (tty_fd, &s); |
529 | 374 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
375 // Save modes and set certain variables dependent on modes. |
529 | 376 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
377 save_term = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
378 // ospeed = s.c_cflag & CBAUD; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
379 // erase_char = s.c_cc[VERASE]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
380 // kill_char = s.c_cc[VKILL]; |
529 | 381 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
382 // Set the modes to the way we want them. |
529 | 383 |
21662
5b9868c2e212
maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents:
21557
diff
changeset
|
384 s.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL); |
5b9868c2e212
maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents:
21557
diff
changeset
|
385 s.c_oflag |= (OPOST | ONLCR); |
529 | 386 #if defined (OCRNL) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
387 s.c_oflag &= ~(OCRNL); |
529 | 388 #endif |
389 #if defined (ONOCR) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
390 s.c_oflag &= ~(ONOCR); |
529 | 391 #endif |
392 #if defined (ONLRET) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
393 s.c_oflag &= ~(ONLRET); |
529 | 394 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
395 s.c_cc[VMIN] = wait ? 1 : 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
396 s.c_cc[VTIME] = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
397 } |
529 | 398 else |
399 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
400 // Restore saved modes. |
1358 | 401 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
402 s = save_term; |
529 | 403 } |
3658 | 404 |
9411
c9636d98e5cd
fix kbhit(1) to not discard waiting keystrokes
Joe Rothweiler <octaveuser@sensicomm.com>
parents:
9242
diff
changeset
|
405 tcsetattr (tty_fd, wait ? TCSAFLUSH : TCSADRAIN, &s); |
529 | 406 } |
407 #elif defined (HAVE_TERMIO_H) | |
408 { | |
409 struct termio s; | |
410 static struct termio save_term; | |
411 | |
412 if (on) | |
413 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
414 // Get terminal modes. |
529 | 415 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
416 ioctl (tty_fd, TCGETA, &s); |
529 | 417 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
418 // Save modes and set certain variables dependent on modes. |
529 | 419 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
420 save_term = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
421 // ospeed = s.c_cflag & CBAUD; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
422 // erase_char = s.c_cc[VERASE]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
423 // kill_char = s.c_cc[VKILL]; |
529 | 424 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
425 // Set the modes to the way we want them. |
529 | 426 |
21662
5b9868c2e212
maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents:
21557
diff
changeset
|
427 s.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL); |
5b9868c2e212
maint: Octave coding convention cleanups.
Rik <rik@octave.org>
parents:
21557
diff
changeset
|
428 s.c_oflag |= (OPOST | ONLCR); |
529 | 429 #if defined (OCRNL) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
430 s.c_oflag &= ~(OCRNL); |
529 | 431 #endif |
432 #if defined (ONOCR) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
433 s.c_oflag &= ~(ONOCR); |
529 | 434 #endif |
435 #if defined (ONLRET) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
436 s.c_oflag &= ~(ONLRET); |
529 | 437 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
438 s.c_cc[VMIN] = wait ? 1 : 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
439 } |
529 | 440 else |
441 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
442 // Restore saved modes. |
1358 | 443 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
444 s = save_term; |
529 | 445 } |
3658 | 446 |
529 | 447 ioctl (tty_fd, TCSETAW, &s); |
448 } | |
449 #elif defined (HAVE_SGTTY_H) | |
450 { | |
451 struct sgttyb s; | |
452 static struct sgttyb save_term; | |
453 | |
454 if (on) | |
455 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
456 // Get terminal modes. |
529 | 457 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
458 ioctl (tty_fd, TIOCGETP, &s); |
529 | 459 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
460 // Save modes and set certain variables dependent on modes. |
529 | 461 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
462 save_term = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
463 // ospeed = s.sg_ospeed; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
464 // erase_char = s.sg_erase; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
465 // kill_char = s.sg_kill; |
529 | 466 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
467 // Set the modes to the way we want them. |
529 | 468 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
469 s.sg_flags |= CBREAK; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
470 s.sg_flags &= ~(ECHO); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
471 } |
529 | 472 else |
473 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
474 // Restore saved modes. |
1358 | 475 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
476 s = save_term; |
529 | 477 } |
3658 | 478 |
529 | 479 ioctl (tty_fd, TIOCSETN, &s); |
480 } | |
481 #else | |
21109
bd1752782e56
Use err_disabled_feature, warn_disabled_feature throughout code base.
Rik <rik@octave.org>
parents:
21078
diff
changeset
|
482 warn_disabled_feature ("", "raw mode console I/O"); |
4064 | 483 |
484 // Make sure the current mode doesn't toggle. | |
485 on = curr_on; | |
529 | 486 #endif |
487 | |
488 curr_on = on; | |
489 } | |
490 | |
6726 | 491 FILE * |
492 octave_popen (const char *command, const char *mode) | |
493 { | |
494 #if defined (__MINGW32__) || defined (_MSC_VER) | |
495 if (mode && mode[0] && ! mode[1]) | |
496 { | |
497 char tmode[3]; | |
498 tmode[0] = mode[0]; | |
499 tmode[1] = 'b'; | |
500 tmode[2] = 0; | |
501 | |
502 return _popen (command, tmode); | |
503 } | |
504 else | |
505 return _popen (command, mode); | |
506 #else | |
507 return popen (command, mode); | |
508 #endif | |
509 } | |
510 | |
511 int | |
512 octave_pclose (FILE *f) | |
513 { | |
514 #if defined (__MINGW32__) || defined (_MSC_VER) | |
515 return _pclose (f); | |
516 #else | |
517 return pclose (f); | |
518 #endif | |
519 } | |
520 | |
767 | 521 // Read one character from the terminal. |
522 | |
529 | 523 int |
4067 | 524 octave_kbhit (bool wait) |
529 | 525 { |
20788
a2b96b523472
Rewrite a8ee668e7fd7 to use #if defined rather than #ifdef.
Rik <rik@octave.org>
parents:
20786
diff
changeset
|
526 #if defined (HAVE__KBHIT) && defined (HAVE__GETCH) |
20786
a8ee668e7fd7
Fix kbhit and pause on Windows systems.
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
527 // This essentially means we are on a Windows system. |
a8ee668e7fd7
Fix kbhit and pause on Windows systems.
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
528 int c; |
a8ee668e7fd7
Fix kbhit and pause on Windows systems.
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
529 |
a8ee668e7fd7
Fix kbhit and pause on Windows systems.
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
530 if (wait) |
a8ee668e7fd7
Fix kbhit and pause on Windows systems.
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
531 c = _getch (); |
a8ee668e7fd7
Fix kbhit and pause on Windows systems.
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
532 else |
a8ee668e7fd7
Fix kbhit and pause on Windows systems.
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
533 c = (! _kbhit ()) ? 0 : _getch (); |
a8ee668e7fd7
Fix kbhit and pause on Windows systems.
Rik <rik@octave.org>
parents:
20181
diff
changeset
|
534 |
4067 | 535 #else |
3658 | 536 raw_mode (true, wait); |
537 | |
5770 | 538 // Get current handler. |
539 octave_interrupt_handler saved_interrupt_handler | |
540 = octave_ignore_interrupts (); | |
541 | |
542 // Restore it, disabling system call restarts (if possible) so the | |
543 // read can be interrupted. | |
544 | |
545 octave_set_interrupt_handler (saved_interrupt_handler, false); | |
546 | |
3658 | 547 int c = std::cin.get (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
548 |
3658 | 549 if (std::cin.fail () || std::cin.eof ()) |
550 std::cin.clear (); | |
551 | |
5770 | 552 // Restore it, enabling system call restarts (if possible). |
553 octave_set_interrupt_handler (saved_interrupt_handler, true); | |
554 | |
3658 | 555 raw_mode (false, true); |
4067 | 556 #endif |
3658 | 557 |
529 | 558 return c; |
559 } | |
560 | |
12228
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
561 std::string |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
562 get_P_tmpdir (void) |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
563 { |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
564 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
565 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
566 std::string retval; |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
567 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
568 #if defined (P_tmpdir) |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
569 retval = P_tmpdir; |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
570 #endif |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
571 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
572 // Apparently some versions of MinGW and MSVC either don't define |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
573 // P_tmpdir, or they define it to a single backslash, neither of which |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
574 // is particularly helpful. |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
575 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
576 if (retval.empty () || retval == "\\") |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
577 { |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
578 retval = octave::sys::env::getenv ("TEMP"); |
12228
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
579 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
580 if (retval.empty ()) |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
581 retval = octave::sys::env::getenv ("TMP"); |
12228
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
582 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
583 if (retval.empty ()) |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
584 retval = "c:\\temp"; |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
585 } |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
586 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
587 return retval; |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
588 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
589 #elif defined (P_tmpdir) |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
590 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
591 return P_tmpdir; |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
592 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
593 #else |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
594 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
595 return "/tmp"; |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
596 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
597 #endif |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
598 } |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
599 |
1957 | 600 DEFUN (clc, , , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
601 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
602 @deftypefn {} {} clc ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
603 @deftypefnx {} {} home ()\n\ |
3332 | 604 Clear the terminal screen and move the cursor to the upper left corner.\n\ |
3333 | 605 @end deftypefn") |
529 | 606 { |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16404
diff
changeset
|
607 bool skip_redisplay = true; |
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16404
diff
changeset
|
608 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
609 octave::command_editor::clear_screen (skip_redisplay); |
529 | 610 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
611 return ovl (); |
529 | 612 } |
613 | |
549 | 614 DEFALIAS (home, clc); |
615 | |
1957 | 616 DEFUN (getenv, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
617 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
618 @deftypefn {} {} getenv (@var{var})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
619 Return the value of the environment variable @var{var}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
620 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
621 For example,\n\ |
3301 | 622 \n\ |
623 @example\n\ | |
624 getenv (\"PATH\")\n\ | |
625 @end example\n\ | |
626 \n\ | |
627 @noindent\n\ | |
628 returns a string containing the value of your path.\n\ | |
19167
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
629 @seealso{setenv, unsetenv}\n\ |
3301 | 630 @end deftypefn") |
529 | 631 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20799
diff
changeset
|
632 if (args.length () != 1) |
5823 | 633 print_usage (); |
529 | 634 |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
635 std::string name = args(0).string_value (); |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
636 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
637 return ovl (octave::sys::env::getenv (name)); |
529 | 638 } |
639 | |
19167
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
640 /* |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
641 %!assert (ischar (getenv ("OCTAVE_HOME"))) |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
642 */ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
643 |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
644 DEFUN (setenv, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
645 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
646 @deftypefn {} {} setenv (@var{var}, @var{value})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
647 @deftypefnx {} {} setenv (@var{var})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
648 @deftypefnx {} {} putenv (@dots{})\n\ |
3301 | 649 Set the value of the environment variable @var{var} to @var{value}.\n\ |
19167
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
650 \n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
651 If no @var{value} is specified then the variable will be assigned the null\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
652 string.\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
653 @seealso{unsetenv, getenv}\n\ |
3301 | 654 @end deftypefn") |
1706 | 655 { |
656 int nargin = args.length (); | |
657 | |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
658 if (nargin < 1 || nargin > 2) |
5823 | 659 print_usage (); |
1706 | 660 |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
661 std::string var = args(0).xstring_value ("setenv: VAR must be a string"); |
1706 | 662 |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
663 std::string val = (nargin == 2 |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
664 ? args(1).xstring_value ("setenv: VALUE must be a string") |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20990
diff
changeset
|
665 : ""); |
20582
ba2b07c13913
use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
666 |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
667 octave::sys::env::putenv (var, val); |
1706 | 668 |
21078
49852ff04747
maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents:
21017
diff
changeset
|
669 return ovl (); |
1706 | 670 } |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
671 |
19167
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
672 DEFALIAS (putenv, setenv); |
1706 | 673 |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
674 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
675 %!test |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
676 %! setenv ("dummy_variable_that_cannot_matter", "foobar"); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
677 %! assert (getenv ("dummy_variable_that_cannot_matter"), "foobar"); |
19167
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
678 %! unsetenv ("dummy_variable_that_cannot_matter"); |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
679 %! assert (getenv ("dummy_variable_that_cannot_matter"), ""); |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
680 */ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
681 |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
682 DEFUN (unsetenv, args, , |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
683 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
684 @deftypefn {} {@var{status} =} unsetenv (@var{var})\n\ |
19167
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
685 Delete the environment variable @var{var}.\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
686 \n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
687 Return 0 if the variable was deleted, or did not exist, and -1 if an error\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
688 occurred.\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
689 @seealso{setenv, getenv}\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
690 @end deftypefn") |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
691 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20799
diff
changeset
|
692 if (args.length () != 1) |
19167
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
693 print_usage (); |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
694 |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
695 std::string tmp = args(0).string_value (); |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
696 |
21888
00f1249f2483
create wrappers for some gnulib functions
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
697 return ovl (octave_unsetenv_wrapper (tmp.c_str ())); |
19167
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
698 } |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
699 |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
700 /* |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18674
diff
changeset
|
701 ## Test for unsetenv is in setenv test |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
702 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
703 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
704 // FIXME: perhaps kbhit should also be able to print a prompt? |
3372 | 705 |
3657 | 706 DEFUN (kbhit, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
707 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
708 @deftypefn {} {} kbhit ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
709 @deftypefnx {} {} kbhit (1)\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
710 Read a single keystroke from the keyboard.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
711 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
712 If called with an argument, don't wait for a keypress.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
713 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
714 For example,\n\ |
3372 | 715 \n\ |
716 @example\n\ | |
717 x = kbhit ();\n\ | |
718 @end example\n\ | |
719 \n\ | |
720 @noindent\n\ | |
721 will set @var{x} to the next character typed at the keyboard as soon as\n\ | |
722 it is typed.\n\ | |
3657 | 723 \n\ |
724 @example\n\ | |
725 x = kbhit (1);\n\ | |
726 @end example\n\ | |
727 \n\ | |
728 @noindent\n\ | |
16053
119ce9f5e1a3
doc: Add seealso links between input, yes_or_no, kbhit.
Rik <rik@octave.org>
parents:
16015
diff
changeset
|
729 is identical to the above example, but doesn't wait for a keypress,\n\ |
3657 | 730 returning the empty string if no key is available.\n\ |
18674
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
731 @seealso{input, pause}\n\ |
3372 | 732 @end deftypefn") |
529 | 733 { |
4233 | 734 octave_value retval; |
529 | 735 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
736 // FIXME: add timeout and default value args? |
529 | 737 |
19849
1c9ed5b4c73d
input.h: change meaning of interactive and forced_interactive global variables.
Carnë Draug <carandraug@octave.org>
parents:
19774
diff
changeset
|
738 if (interactive) |
529 | 739 { |
15423
53d073233fa4
call more built-in functions directly
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
740 Fdrawnow (); |
6423 | 741 |
4067 | 742 int c = octave_kbhit (args.length () == 0); |
3657 | 743 |
3658 | 744 if (c == -1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
745 c = 0; |
3657 | 746 |
16092
def3b111cff8
avoid gcc warning about int to char conversion
John W. Eaton <jwe@octave.org>
parents:
16053
diff
changeset
|
747 char s[2] = { static_cast<char> (c), '\0' }; |
16015 | 748 |
529 | 749 retval = s; |
750 } | |
751 | |
752 return retval; | |
753 } | |
754 | |
1957 | 755 DEFUN (pause, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
756 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
757 @deftypefn {} {} pause ()\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
758 @deftypefnx {} {} pause (@var{n})\n\ |
18674
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
759 Suspend the execution of the program for @var{n} seconds.\n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
760 \n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
761 If invoked without an input arguments then the program is suspended until a\n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
762 character is typed.\n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
763 \n\ |
20923
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
764 @var{n} is a positive real value and may be a fraction of a second,\n\ |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
765 for example:\n\ |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
766 \n\ |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
767 @example\n\ |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
768 @group\n\ |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
769 tic; pause (0.05); toc\n\ |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
770 @print{} Elapsed time is 0.05039 seconds.\n\ |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
771 @end group\n\ |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
772 @end example\n\ |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
773 \n\ |
18674
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
774 The following example prints a message and then waits 5 seconds before\n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
775 clearing the screen.\n\ |
3301 | 776 \n\ |
777 @example\n\ | |
778 @group\n\ | |
20923
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
779 disp (\"wait please...\");\n\ |
3301 | 780 pause (5);\n\ |
781 clc;\n\ | |
782 @end group\n\ | |
783 @end example\n\ | |
20923
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
784 \n\ |
58263bea2fdf
Unified "sleep" functions to "octave_sleep" in C++ and "pause" in Octave.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
20853
diff
changeset
|
785 @seealso{kbhit}\n\ |
3301 | 786 @end deftypefn") |
529 | 787 { |
788 int nargin = args.length (); | |
789 | |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
790 if (nargin > 1) |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
791 print_usage (); |
529 | 792 |
1579 | 793 if (nargin == 1) |
529 | 794 { |
1579 | 795 double dval = args(0).double_value (); |
636 | 796 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21748
diff
changeset
|
797 if (octave::math::isnan (dval)) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20923
diff
changeset
|
798 warning ("pause: NaN is an invalid delay"); |
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20923
diff
changeset
|
799 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
800 { |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20181
diff
changeset
|
801 Fdrawnow (); |
6419 | 802 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21748
diff
changeset
|
803 if (octave::math::isinf (dval)) |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20181
diff
changeset
|
804 { |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20181
diff
changeset
|
805 flush_octave_stdout (); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20181
diff
changeset
|
806 octave_kbhit (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
807 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
808 else |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20181
diff
changeset
|
809 octave_sleep (dval); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
810 } |
529 | 811 } |
1579 | 812 else |
3234 | 813 { |
15423
53d073233fa4
call more built-in functions directly
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
814 Fdrawnow (); |
3234 | 815 flush_octave_stdout (); |
4067 | 816 octave_kbhit (); |
3234 | 817 } |
2630 | 818 |
20941
a4f5da7c5463
maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
819 return ovl (); |
2630 | 820 } |
821 | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
822 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
823 %!test |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
824 %! pause (1); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
825 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
826 %!error (pause (1, 2)) |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
827 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
828 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
829 // FIXME: maybe this should only return 1 if IEEE floating |
862 | 830 // point functions really work. |
831 | |
1957 | 832 DEFUN (isieee, , , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
833 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
834 @deftypefn {} {} isieee ()\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11234
diff
changeset
|
835 Return true if your computer @emph{claims} to conform to the IEEE standard\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
836 for floating point calculations.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
837 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
838 No actual tests are performed.\n\ |
3301 | 839 @end deftypefn") |
862 | 840 { |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
841 octave::mach_info::float_format flt_fmt = octave::mach_info::native_float_format (); |
2317 | 842 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
843 return ovl (flt_fmt == octave::mach_info::flt_fmt_ieee_little_endian |
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
844 || flt_fmt == octave::mach_info::flt_fmt_ieee_big_endian); |
862 | 845 } |
846 | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
847 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
848 %!assert (islogical (isieee ())) |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
849 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
850 |
4600 | 851 DEFUN (native_float_format, , , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
852 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
853 @deftypefn {} {} native_float_format ()\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
854 Return the native floating point format as a string.\n\ |
4600 | 855 @end deftypefn") |
856 { | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
857 octave::mach_info::float_format flt_fmt = octave::mach_info::native_float_format (); |
4600 | 858 |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21736
diff
changeset
|
859 return ovl (octave::mach_info::float_format_as_string (flt_fmt)); |
4600 | 860 } |
861 | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
862 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
863 %!assert (ischar (native_float_format ())) |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
864 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
865 |
1957 | 866 DEFUN (tilde_expand, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
867 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
868 @deftypefn {} {} tilde_expand (@var{string})\n\ |
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
869 @deftypefnx {} {} tilde_expand (@var{cellstr})\n\ |
20172
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
870 Perform tilde expansion on @var{string}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
871 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
872 If @var{string} begins with a tilde character, (@samp{~}), all of the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
873 characters preceding the first slash (or all characters, if there is no\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
874 slash) are treated as a possible user name, and the tilde and the following\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
875 characters up to the slash are replaced by the home directory of the named\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
876 user. If the tilde is followed immediately by a slash, the tilde is\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
877 replaced by the home directory of the user running Octave.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20064
diff
changeset
|
878 \n\ |
20711
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
879 If the input is a cell array of strings @var{cellstr} then tilde expansion\n\ |
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
880 is performed on each string element.\n\ |
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
881 \n\ |
7b608fadc663
Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents:
20704
diff
changeset
|
882 Examples:\n\ |
3301 | 883 \n\ |
884 @example\n\ | |
885 @group\n\ | |
886 tilde_expand (\"~joeuser/bin\")\n\ | |
887 @result{} \"/home/joeuser/bin\"\n\ | |
888 tilde_expand (\"~/bin\")\n\ | |
889 @result{} \"/home/jwe/bin\"\n\ | |
890 @end group\n\ | |
891 @end example\n\ | |
892 @end deftypefn") | |
1750 | 893 { |
20819
f428cbe7576f
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20799
diff
changeset
|
894 if (args.length () != 1) |
5823 | 895 print_usage (); |
1750 | 896 |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
897 octave_value arg = args(0); |
6116 | 898 |
20990
fc9cca99b2de
Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents:
20961
diff
changeset
|
899 string_vector sv = arg.xstring_vector_value ("tilde_expand: argument must be char or cellstr object"); |
6116 | 900 |
21733
cb0fdd941d84
use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
901 sv = octave::sys::file_ops::tilde_expand (sv); |
20799
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
902 |
c349d4c91ce2
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20789
diff
changeset
|
903 if (arg.is_cellstr ()) |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20923
diff
changeset
|
904 return ovl (Cell (arg.dims (), sv)); |
1750 | 905 else |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20923
diff
changeset
|
906 return ovl (sv); |
1750 | 907 } |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
908 |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
909 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
910 %!test |
20016
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
911 %! home = get_home_directory (); |
20064
ab7582167810
Fix failing BIST test for tilde_expand() on Windows (bug #44796).
Rik <rik@octave.org>
parents:
20024
diff
changeset
|
912 %! assert (tilde_expand ("~/foobar"), [home "/foobar"]); |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
913 %! assert (tilde_expand ("/foo/bar"), "/foo/bar"); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
914 %! assert (tilde_expand ("foo/bar"), "foo/bar"); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
915 */ |
17851
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
916 |
20016
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
917 DEFUN (get_home_directory, , , |
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
918 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
919 @deftypefn {} {@var{homedir} =} get_home_directory ()\n\ |
20024
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20016
diff
changeset
|
920 Return the current home directory.\n\ |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20016
diff
changeset
|
921 \n\ |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20016
diff
changeset
|
922 On most systems, this is equivalent to @code{getenv (\"HOME\")}. On Windows\n\ |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20016
diff
changeset
|
923 systems, if the environment variable @env{HOME} is not set then it is\n\ |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20016
diff
changeset
|
924 equivalent to\n\ |
20016
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
925 @code{fullfile (getenv (\"HOMEDRIVE\"), getenv (\"HOMEPATH\"))}\n\ |
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
926 @seealso{getenv}\n\ |
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
927 @end deftypefn") |
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
928 { |
21732
6a1eded90355
use namespace for system env class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
929 return ovl (octave::sys::env::get_home_directory ()); |
20016
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
930 } |
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
19861
diff
changeset
|
931 |
20024
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20016
diff
changeset
|
932 /* |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20016
diff
changeset
|
933 %!test |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20016
diff
changeset
|
934 %! if (! ispc ()) |
20181
aa36fb998a4d
maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents:
20172
diff
changeset
|
935 %! assert (get_home_directory (), getenv ("HOME")); |
20024
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20016
diff
changeset
|
936 %! endif |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20016
diff
changeset
|
937 */ |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20016
diff
changeset
|
938 |
17851
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
939 // This function really belongs in display.cc, but including defun.h in |
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
940 // that file results in conflicts with symbols from headers that are |
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
941 // needed for X11 and Carbon functions. |
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
942 |
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
943 DEFUN (have_window_system, , , |
19861
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19857
diff
changeset
|
944 "-*- texinfo -*-\n\ |
20853
1142cf6abc0d
2015 Code Sprint: remove class of function from docstring for all C++ files.
Rik <rik@octave.org>
parents:
20831
diff
changeset
|
945 @deftypefn {} {} have_window_system ()\n\ |
18674
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
946 Return true if a window system is available (X11, Windows, or Apple OS X)\n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
947 and false otherwise.\n\ |
19857
bf511802add7
doc: Add have_window_system() to documentation.
Rik <rik@octave.org>
parents:
19856
diff
changeset
|
948 @seealso{isguirunning}\n\ |
17851
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
949 @end deftypefn") |
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
950 { |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20923
diff
changeset
|
951 return ovl (display_info::display_available ()); |
17851
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
952 } |