Mercurial > hg > octave-lyh
annotate src/sysdep.cc @ 14383:07c55bceca23 stable
Fix guarded_eval() subfunction in fminunc (bug #35534).
* fminunc.m: Fix guarded_eval() subfunction in fminunc (bug #35534).
author | Olaf Till <olaf.till@uni-jena.de> |
---|---|
date | Wed, 15 Feb 2012 14:44:37 +0100 |
parents | ebcb0f83698f |
children | eff4a5933e28 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13962
diff
changeset
|
3 Copyright (C) 1993-2012 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 | |
240 | 23 #ifdef HAVE_CONFIG_H |
1192 | 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 | |
529 | 36 #include <sys/types.h> |
37 #include <unistd.h> | |
1 | 38 |
1430 | 39 #if defined (HAVE_TERMIOS_H) |
40 #include <termios.h> | |
41 #elif defined (HAVE_TERMIO_H) | |
42 #include <termio.h> | |
43 #elif defined (HAVE_SGTTY_H) | |
44 #include <sgtty.h> | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
45 #endif |
4067 | 46 |
47 #if defined (HAVE_CONIO_H) | |
48 #include <conio.h> | |
1430 | 49 #endif |
50 | |
3248 | 51 #if defined (HAVE_SYS_IOCTL_H) |
52 #include <sys/ioctl.h> | |
53 #endif | |
54 | |
1463 | 55 #if defined (HAVE_FLOATINGPOINT_H) |
56 #include <floatingpoint.h> | |
57 #endif | |
58 | |
2508 | 59 #if defined (HAVE_IEEEFP_H) |
60 #include <ieeefp.h> | |
61 #endif | |
62 | |
2926 | 63 #include "cmd-edit.h" |
64 #include "file-ops.h" | |
2893 | 65 #include "lo-mappers.h" |
7231 | 66 #include "lo-math.h" |
2317 | 67 #include "mach-info.h" |
2926 | 68 #include "oct-env.h" |
5451 | 69 #include "quit.h" |
1769 | 70 |
6208 | 71 #include "Cell.h" |
1352 | 72 #include "defun.h" |
73 #include "error.h" | |
529 | 74 #include "input.h" |
1755 | 75 #include "oct-obj.h" |
2370 | 76 #include "ov.h" |
3234 | 77 #include "pager.h" |
6419 | 78 #include "parse.h" |
5770 | 79 #include "sighandlers.h" |
1352 | 80 #include "sysdep.h" |
1755 | 81 #include "toplev.h" |
529 | 82 #include "utils.h" |
6598 | 83 #include "file-stat.h" |
529 | 84 |
85 #ifndef STDIN_FILENO | |
86 #define STDIN_FILENO 1 | |
87 #endif | |
444 | 88 |
9441
160c564d5d25
initialize floating point values properly for NetBSD systems
Aleksej Saushev <asau@inbox.ru>
parents:
9411
diff
changeset
|
89 #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__) |
2508 | 90 static void |
91 BSD_init (void) | |
92 { | |
93 #if defined (HAVE_FLOATINGPOINT_H) | |
94 // Disable trapping on common exceptions. | |
4164 | 95 #ifndef FP_X_DNML |
96 #define FP_X_DNML 0 | |
97 #endif | |
2508 | 98 fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP)); |
99 #endif | |
100 } | |
101 #endif | |
102 | |
6956 | 103 #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
|
104 |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
105 #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
|
106 #include <tlhelp32.h> |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
107 |
6080 | 108 static void |
109 w32_set_octave_home (void) | |
110 { | |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
111 std::string bin_dir; |
6080 | 112 |
13885
2f42a7b0cf94
Fix MinGW compilation problem with tlhelp32.h
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13771
diff
changeset
|
113 HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE |
2f42a7b0cf94
Fix MinGW compilation problem with tlhelp32.h
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13771
diff
changeset
|
114 #ifdef TH32CS_SNAPMODULE32 |
2f42a7b0cf94
Fix MinGW compilation problem with tlhelp32.h
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13771
diff
changeset
|
115 | TH32CS_SNAPMODULE32 |
2f42a7b0cf94
Fix MinGW compilation problem with tlhelp32.h
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13771
diff
changeset
|
116 #endif |
2f42a7b0cf94
Fix MinGW compilation problem with tlhelp32.h
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13771
diff
changeset
|
117 , 0); |
6080 | 118 |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
119 if (h != INVALID_HANDLE_VALUE) |
6080 | 120 { |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
121 MODULEENTRY32 mod_info; |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
122 |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
123 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
|
124 mod_info.dwSize = sizeof (mod_info); |
13751
be7ff59cbc7a
Fix octinterp DLL searching on Win32.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13282
diff
changeset
|
125 |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
126 if (Module32First (h, &mod_info)) |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
127 { |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
128 do |
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 std::string mod_name (mod_info.szModule); |
6080 | 131 |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
132 if (mod_name.find ("octinterp") != std::string::npos) |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
133 { |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
134 bin_dir = mod_info.szExePath; |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
135 if (bin_dir[bin_dir.length () - 1] != '\\') |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
136 bin_dir.append (1, '\\'); |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
137 break; |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
138 } |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
139 } |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
140 while (Module32Next (h, &mod_info)); |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
141 } |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
142 |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
143 CloseHandle (h); |
6080 | 144 } |
145 | |
146 if (! bin_dir.empty ()) | |
147 { | |
148 size_t pos = bin_dir.rfind ("\\bin\\"); | |
149 | |
8021 | 150 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
151 octave_env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos)); |
6080 | 152 } |
153 } | |
154 | |
6960 | 155 void |
5451 | 156 w32_set_quiet_shutdown (void) |
157 { | |
158 // Let the user close the console window or shutdown without the | |
159 // pesky dialog. | |
160 // | |
5775 | 161 // FIXME -- should this be user configurable? |
5451 | 162 SetProcessShutdownParameters (0x280, SHUTDOWN_NORETRY); |
163 } | |
164 | |
6960 | 165 void |
5451 | 166 MINGW_signal_cleanup (void) |
167 { | |
5455 | 168 w32_set_quiet_shutdown (); |
5451 | 169 |
5455 | 170 w32_raise_final (); |
5451 | 171 } |
172 #endif | |
173 | |
174 #if defined (__MINGW32__) | |
175 static void | |
176 MINGW_init (void) | |
177 { | |
6080 | 178 w32_set_octave_home (); |
179 | |
5451 | 180 // Init mutex to protect setjmp/longjmp and get main thread context |
181 w32_sigint_init (); | |
182 | |
183 w32_set_quiet_shutdown (); | |
184 } | |
185 #endif | |
186 | |
6080 | 187 #if defined (_MSC_VER) |
188 static void | |
189 MSVC_init (void) | |
190 { | |
191 w32_set_octave_home (); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
192 |
6135 | 193 // Init mutex to protect setjmp/longjmp and get main thread context |
194 w32_sigint_init (); | |
195 | |
196 w32_set_quiet_shutdown (); | |
6080 | 197 } |
198 #endif | |
199 | |
4091 | 200 |
6598 | 201 // Return TRUE if FILE1 and FILE2 refer to the same (physical) file. |
202 | |
203 bool | |
204 same_file_internal (const std::string& file1, const std::string& file2) | |
205 { | |
206 #ifdef OCTAVE_USE_WINDOWS_API | |
207 | |
6691 | 208 bool retval = false; |
209 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
210 // Windows native code |
6598 | 211 // Reference: http://msdn2.microsoft.com/en-us/library/aa363788.aspx |
212 | |
6691 | 213 HANDLE hfile1 = CreateFile (file1.c_str (), 0, FILE_SHARE_READ, 0, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
214 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
6691 | 215 |
216 if (hfile1 != INVALID_HANDLE_VALUE) | |
217 { | |
218 HANDLE hfile2 = CreateFile (file2.c_str (), 0, FILE_SHARE_READ, 0, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
219 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
6598 | 220 |
6691 | 221 if (hfile2 != INVALID_HANDLE_VALUE) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
222 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
223 BY_HANDLE_FILE_INFORMATION hfi1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
224 BY_HANDLE_FILE_INFORMATION hfi2; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
225 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
226 if (GetFileInformationByHandle (hfile1, &hfi1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
227 && GetFileInformationByHandle (hfile2, &hfi2)) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
228 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
229 retval = (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
230 && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
231 && hfi1.nFileIndexLow == hfi2.nFileIndexLow); |
6598 | 232 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
233 CloseHandle (hfile2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
234 } |
6691 | 235 |
6598 | 236 CloseHandle (hfile1); |
237 } | |
6691 | 238 |
239 return retval; | |
6598 | 240 |
241 #else | |
242 | |
243 // POSIX Code | |
244 | |
245 file_stat fs_file1 (file1); | |
246 file_stat fs_file2 (file2); | |
247 | |
248 return (fs_file1 && fs_file2 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
249 && fs_file1.ino () == fs_file2.ino () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
250 && fs_file1.dev () == fs_file2.dev ()); |
6598 | 251 |
252 #endif | |
253 } | |
254 | |
1 | 255 void |
256 sysdep_init (void) | |
257 { | |
9441
160c564d5d25
initialize floating point values properly for NetBSD systems
Aleksej Saushev <asau@inbox.ru>
parents:
9411
diff
changeset
|
258 #if defined (__386BSD__) || defined (__FreeBSD__) || defined(__NetBSD__) |
2508 | 259 BSD_init (); |
5451 | 260 #elif defined (__MINGW32__) |
261 MINGW_init (); | |
6080 | 262 #elif defined (_MSC_VER) |
263 MSVC_init (); | |
1 | 264 #endif |
265 } | |
266 | |
5451 | 267 void |
268 sysdep_cleanup (void) | |
269 { | |
270 MINGW_SIGNAL_CLEANUP (); | |
271 } | |
272 | |
767 | 273 // Set terminal in raw mode. From less-177. |
274 // | |
275 // 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
|
276 // "Raw mode" means |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
277 // 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
|
278 // 2. Input is not echoed. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
279 // 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
|
280 // 4. \t is NOT expanded into spaces. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
281 // 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
|
282 // etc. are NOT disabled. |
767 | 283 // It doesn't matter whether an input \n is mapped to \r, or vice versa. |
284 | |
529 | 285 void |
3657 | 286 raw_mode (bool on, bool wait) |
529 | 287 { |
3657 | 288 static bool curr_on = false; |
529 | 289 |
290 int tty_fd = STDIN_FILENO; | |
14160 | 291 if (! gnulib::isatty (tty_fd)) |
529 | 292 { |
293 if (interactive) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
294 error ("stdin is not a tty!"); |
529 | 295 return; |
296 } | |
297 | |
298 if (on == curr_on) | |
299 return; | |
300 | |
301 #if defined (HAVE_TERMIOS_H) | |
302 { | |
303 struct termios s; | |
304 static struct termios save_term; | |
305 | |
306 if (on) | |
307 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
308 // Get terminal modes. |
529 | 309 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
310 tcgetattr (tty_fd, &s); |
529 | 311 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
312 // Save modes and set certain variables dependent on modes. |
529 | 313 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
314 save_term = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
315 // ospeed = s.c_cflag & CBAUD; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
316 // erase_char = s.c_cc[VERASE]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
317 // kill_char = s.c_cc[VKILL]; |
529 | 318 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
319 // Set the modes to the way we want them. |
529 | 320 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
321 s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
322 s.c_oflag |= (OPOST|ONLCR); |
529 | 323 #if defined (OCRNL) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
324 s.c_oflag &= ~(OCRNL); |
529 | 325 #endif |
326 #if defined (ONOCR) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
327 s.c_oflag &= ~(ONOCR); |
529 | 328 #endif |
329 #if defined (ONLRET) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
330 s.c_oflag &= ~(ONLRET); |
529 | 331 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
332 s.c_cc[VMIN] = wait ? 1 : 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
333 s.c_cc[VTIME] = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
334 } |
529 | 335 else |
336 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
337 // Restore saved modes. |
1358 | 338 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
339 s = save_term; |
529 | 340 } |
3658 | 341 |
9411
c9636d98e5cd
fix kbhit(1) to not discard waiting keystrokes
Joe Rothweiler <octaveuser@sensicomm.com>
parents:
9242
diff
changeset
|
342 tcsetattr (tty_fd, wait ? TCSAFLUSH : TCSADRAIN, &s); |
529 | 343 } |
344 #elif defined (HAVE_TERMIO_H) | |
345 { | |
346 struct termio s; | |
347 static struct termio save_term; | |
348 | |
349 if (on) | |
350 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
351 // Get terminal modes. |
529 | 352 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
353 ioctl (tty_fd, TCGETA, &s); |
529 | 354 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
355 // Save modes and set certain variables dependent on modes. |
529 | 356 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
357 save_term = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
358 // ospeed = s.c_cflag & CBAUD; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
359 // erase_char = s.c_cc[VERASE]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
360 // kill_char = s.c_cc[VKILL]; |
529 | 361 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
362 // Set the modes to the way we want them. |
529 | 363 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
364 s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
365 s.c_oflag |= (OPOST|ONLCR); |
529 | 366 #if defined (OCRNL) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
367 s.c_oflag &= ~(OCRNL); |
529 | 368 #endif |
369 #if defined (ONOCR) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
370 s.c_oflag &= ~(ONOCR); |
529 | 371 #endif |
372 #if defined (ONLRET) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
373 s.c_oflag &= ~(ONLRET); |
529 | 374 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
375 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
|
376 } |
529 | 377 else |
378 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
379 // Restore saved modes. |
1358 | 380 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
381 s = save_term; |
529 | 382 } |
3658 | 383 |
529 | 384 ioctl (tty_fd, TCSETAW, &s); |
385 } | |
386 #elif defined (HAVE_SGTTY_H) | |
387 { | |
388 struct sgttyb s; | |
389 static struct sgttyb save_term; | |
390 | |
391 if (on) | |
392 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
393 // Get terminal modes. |
529 | 394 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
395 ioctl (tty_fd, TIOCGETP, &s); |
529 | 396 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
397 // Save modes and set certain variables dependent on modes. |
529 | 398 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
399 save_term = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
400 // ospeed = s.sg_ospeed; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
401 // erase_char = s.sg_erase; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
402 // kill_char = s.sg_kill; |
529 | 403 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
404 // Set the modes to the way we want them. |
529 | 405 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
406 s.sg_flags |= CBREAK; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
407 s.sg_flags &= ~(ECHO); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
408 } |
529 | 409 else |
410 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
411 // Restore saved modes. |
1358 | 412 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
413 s = save_term; |
529 | 414 } |
3658 | 415 |
529 | 416 ioctl (tty_fd, TIOCSETN, &s); |
417 } | |
418 #else | |
4064 | 419 warning ("no support for raw mode console I/O on this system"); |
420 | |
421 // Make sure the current mode doesn't toggle. | |
422 on = curr_on; | |
529 | 423 #endif |
424 | |
425 curr_on = on; | |
426 } | |
427 | |
6726 | 428 FILE * |
429 octave_popen (const char *command, const char *mode) | |
430 { | |
431 #if defined (__MINGW32__) || defined (_MSC_VER) | |
432 if (mode && mode[0] && ! mode[1]) | |
433 { | |
434 char tmode[3]; | |
435 tmode[0] = mode[0]; | |
436 tmode[1] = 'b'; | |
437 tmode[2] = 0; | |
438 | |
439 return _popen (command, tmode); | |
440 } | |
441 else | |
442 return _popen (command, mode); | |
443 #else | |
444 return popen (command, mode); | |
445 #endif | |
446 } | |
447 | |
448 int | |
449 octave_pclose (FILE *f) | |
450 { | |
451 #if defined (__MINGW32__) || defined (_MSC_VER) | |
452 return _pclose (f); | |
453 #else | |
454 return pclose (f); | |
455 #endif | |
456 } | |
457 | |
767 | 458 // Read one character from the terminal. |
459 | |
529 | 460 int |
4067 | 461 octave_kbhit (bool wait) |
529 | 462 { |
4067 | 463 #ifdef HAVE__KBHIT |
4081 | 464 int c = (! wait && ! _kbhit ()) ? 0 : std::cin.get (); |
4067 | 465 #else |
3658 | 466 raw_mode (true, wait); |
467 | |
5770 | 468 // Get current handler. |
469 octave_interrupt_handler saved_interrupt_handler | |
470 = octave_ignore_interrupts (); | |
471 | |
472 // Restore it, disabling system call restarts (if possible) so the | |
473 // read can be interrupted. | |
474 | |
475 octave_set_interrupt_handler (saved_interrupt_handler, false); | |
476 | |
3658 | 477 int c = std::cin.get (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
478 |
3658 | 479 if (std::cin.fail () || std::cin.eof ()) |
480 std::cin.clear (); | |
481 | |
5770 | 482 // Restore it, enabling system call restarts (if possible). |
483 octave_set_interrupt_handler (saved_interrupt_handler, true); | |
484 | |
3658 | 485 raw_mode (false, true); |
4067 | 486 #endif |
3658 | 487 |
529 | 488 return c; |
489 } | |
490 | |
12228
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
491 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
|
492 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
|
493 { |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
494 #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
|
495 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
496 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
|
497 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
498 #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
|
499 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
|
500 #endif |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
501 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
502 // 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
|
503 // 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
|
504 // 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
|
505 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
506 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
|
507 { |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
508 retval = octave_env::getenv ("TEMP"); |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
509 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
510 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
|
511 retval = octave_env::getenv ("TMP"); |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
512 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
513 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
|
514 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
|
515 } |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
516 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
517 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
|
518 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
519 #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
|
520 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
521 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
|
522 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
523 #else |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
524 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
525 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
|
526 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
527 #endif |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
528 } |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
529 |
1957 | 530 DEFUN (clc, , , |
3332 | 531 "-*- texinfo -*-\n\ |
10840 | 532 @deftypefn {Built-in Function} {} clc ()\n\ |
3332 | 533 @deftypefnx {Built-in Function} {} home ()\n\ |
534 Clear the terminal screen and move the cursor to the upper left corner.\n\ | |
3333 | 535 @end deftypefn") |
529 | 536 { |
2926 | 537 command_editor::clear_screen (); |
529 | 538 |
2926 | 539 return octave_value_list (); |
529 | 540 } |
541 | |
549 | 542 DEFALIAS (home, clc); |
543 | |
1957 | 544 DEFUN (getenv, args, , |
3301 | 545 "-*- texinfo -*-\n\ |
546 @deftypefn {Built-in Function} {} getenv (@var{var})\n\ | |
547 Return the value of the environment variable @var{var}. For example,\n\ | |
548 \n\ | |
549 @example\n\ | |
550 getenv (\"PATH\")\n\ | |
551 @end example\n\ | |
552 \n\ | |
553 @noindent\n\ | |
554 returns a string containing the value of your path.\n\ | |
555 @end deftypefn") | |
529 | 556 { |
4233 | 557 octave_value retval; |
529 | 558 |
559 int nargin = args.length (); | |
560 | |
712 | 561 if (nargin == 1) |
529 | 562 { |
3523 | 563 std::string name = args(0).string_value (); |
636 | 564 |
565 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
566 retval = octave_env::getenv (name); |
529 | 567 } |
568 else | |
5823 | 569 print_usage (); |
529 | 570 |
571 return retval; | |
572 } | |
573 | |
1957 | 574 DEFUN (putenv, args, , |
3301 | 575 "-*- texinfo -*-\n\ |
10840 | 576 @deftypefn {Built-in Function} {} putenv (@var{var}, @var{value})\n\ |
7759
84a7f00586aa
Alias setenv to putenv. Allow single arg to putenv
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
577 @deftypefnx {Built-in Function} {} setenv (@var{var}, @var{value})\n\ |
3301 | 578 Set the value of the environment variable @var{var} to @var{value}.\n\ |
579 @end deftypefn") | |
1706 | 580 { |
2086 | 581 octave_value_list retval; |
1706 | 582 |
583 int nargin = args.length (); | |
584 | |
7759
84a7f00586aa
Alias setenv to putenv. Allow single arg to putenv
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
585 if (nargin == 2 || nargin == 1) |
1706 | 586 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
587 std::string var = args(0).string_value (); |
1706 | 588 |
589 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
590 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
591 std::string val = (nargin == 2 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
592 ? args(1).string_value () : std::string ()); |
1706 | 593 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
594 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
595 octave_env::putenv (var, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
596 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12228
diff
changeset
|
597 error ("putenv: VALUE must be a string"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
598 } |
1706 | 599 else |
12483
7a5aacf65f81
Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents:
12228
diff
changeset
|
600 error ("putenv: VAR must be a string"); |
1706 | 601 } |
602 else | |
5823 | 603 print_usage (); |
1706 | 604 |
605 return retval; | |
606 } | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
607 |
7759
84a7f00586aa
Alias setenv to putenv. Allow single arg to putenv
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
608 DEFALIAS (setenv, putenv); |
1706 | 609 |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
610 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
611 %!assert (ischar (getenv ("OCTAVE_HOME"))); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
612 %!test |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
613 %! 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
|
614 %! assert (getenv ("dummy_variable_that_cannot_matter"), "foobar"); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
615 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
616 |
5775 | 617 // FIXME -- perhaps kbhit should also be able to print a prompt? |
3372 | 618 |
3657 | 619 DEFUN (kbhit, args, , |
3372 | 620 "-*- texinfo -*-\n\ |
621 @deftypefn {Built-in Function} {} kbhit ()\n\ | |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
622 Read a single keystroke from the keyboard. If called with one\n\ |
3657 | 623 argument, don't wait for a keypress. For example,\n\ |
3372 | 624 \n\ |
625 @example\n\ | |
626 x = kbhit ();\n\ | |
627 @end example\n\ | |
628 \n\ | |
629 @noindent\n\ | |
630 will set @var{x} to the next character typed at the keyboard as soon as\n\ | |
631 it is typed.\n\ | |
3657 | 632 \n\ |
633 @example\n\ | |
634 x = kbhit (1);\n\ | |
635 @end example\n\ | |
636 \n\ | |
637 @noindent\n\ | |
638 identical to the above example, but don't wait for a keypress,\n\ | |
639 returning the empty string if no key is available.\n\ | |
3372 | 640 @end deftypefn") |
529 | 641 { |
4233 | 642 octave_value retval; |
529 | 643 |
5775 | 644 // FIXME -- add timeout and default value args? |
529 | 645 |
3676 | 646 if (interactive || forced_interactive) |
529 | 647 { |
6423 | 648 feval ("drawnow"); |
649 | |
4067 | 650 int c = octave_kbhit (args.length () == 0); |
3657 | 651 |
3658 | 652 if (c == -1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
653 c = 0; |
3657 | 654 |
529 | 655 char *s = new char [2]; |
656 s[0] = c; | |
657 s[1] = '\0'; | |
658 retval = s; | |
659 } | |
660 | |
661 return retval; | |
662 } | |
663 | |
1957 | 664 DEFUN (pause, args, , |
3301 | 665 "-*- texinfo -*-\n\ |
666 @deftypefn {Built-in Function} {} pause (@var{seconds})\n\ | |
667 Suspend the execution of the program. If invoked without any arguments,\n\ | |
668 Octave waits until you type a character. With a numeric argument, it\n\ | |
669 pauses for the given number of seconds. For example, the following\n\ | |
670 statement prints a message and then waits 5 seconds before clearing the\n\ | |
671 screen.\n\ | |
672 \n\ | |
673 @example\n\ | |
674 @group\n\ | |
6848 | 675 fprintf (stderr, \"wait please...\\n\");\n\ |
3301 | 676 pause (5);\n\ |
677 clc;\n\ | |
678 @end group\n\ | |
679 @end example\n\ | |
680 @end deftypefn") | |
529 | 681 { |
2086 | 682 octave_value_list retval; |
529 | 683 |
684 int nargin = args.length (); | |
685 | |
712 | 686 if (! (nargin == 0 || nargin == 1)) |
529 | 687 { |
5823 | 688 print_usage (); |
529 | 689 return retval; |
690 } | |
691 | |
1579 | 692 if (nargin == 1) |
529 | 693 { |
1579 | 694 double dval = args(0).double_value (); |
636 | 695 |
1579 | 696 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
697 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
698 if (! xisnan (dval)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
699 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
700 feval ("drawnow"); |
6419 | 701 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
702 if (xisinf (dval)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
703 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
704 flush_octave_stdout (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
705 octave_kbhit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
706 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
707 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
708 octave_sleep (dval); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
709 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
710 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
711 warning ("pause: NaN is an invalid delay"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
712 } |
529 | 713 } |
1579 | 714 else |
3234 | 715 { |
6423 | 716 feval ("drawnow"); |
3234 | 717 flush_octave_stdout (); |
4067 | 718 octave_kbhit (); |
3234 | 719 } |
2630 | 720 |
721 return retval; | |
722 } | |
723 | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
724 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
725 %!error (pause (1, 2)); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
726 %!test |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
727 %! pause (1); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
728 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
729 |
2630 | 730 DEFUN (sleep, args, , |
3301 | 731 "-*- texinfo -*-\n\ |
732 @deftypefn {Built-in Function} {} sleep (@var{seconds})\n\ | |
733 Suspend the execution of the program for the given number of seconds.\n\ | |
734 @end deftypefn") | |
2630 | 735 { |
736 octave_value_list retval; | |
737 | |
738 if (args.length () == 1) | |
1579 | 739 { |
2630 | 740 double dval = args(0).double_value (); |
741 | |
742 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
743 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
744 if (xisnan (dval)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
745 warning ("sleep: NaN is an invalid delay"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
746 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
747 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
748 feval ("drawnow"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
749 octave_sleep (dval); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
750 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
751 } |
1579 | 752 } |
2630 | 753 else |
5823 | 754 print_usage (); |
2630 | 755 |
756 return retval; | |
757 } | |
758 | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
759 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
760 %!error (sleep ()); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
761 %!error (sleep (1, 2)); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
762 %!test |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
763 %! sleep (1); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
764 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
765 |
2630 | 766 DEFUN (usleep, args, , |
3301 | 767 "-*- texinfo -*-\n\ |
768 @deftypefn {Built-in Function} {} usleep (@var{microseconds})\n\ | |
769 Suspend the execution of the program for the given number of\n\ | |
770 microseconds. On systems where it is not possible to sleep for periods\n\ | |
771 of time less than one second, @code{usleep} will pause the execution for\n\ | |
772 @code{round (@var{microseconds} / 1e6)} seconds.\n\ | |
773 @end deftypefn") | |
2630 | 774 { |
775 octave_value_list retval; | |
776 | |
777 if (args.length () == 1) | |
778 { | |
779 double dval = args(0).double_value (); | |
780 | |
781 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
782 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
783 if (xisnan (dval)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
784 warning ("usleep: NaN is an invalid delay"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
785 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
786 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
787 feval ("drawnow"); |
6423 | 788 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
789 int delay = NINT (dval); |
2631 | 790 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
791 if (delay > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
792 octave_usleep (delay); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
793 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
794 } |
2630 | 795 } |
796 else | |
5823 | 797 print_usage (); |
529 | 798 |
799 return retval; | |
800 } | |
801 | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
802 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
803 %!error (usleep ()); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
804 %!error (usleep (1, 2)); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
805 %!test |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
806 %! usleep (1000); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
807 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
808 |
5775 | 809 // FIXME -- maybe this should only return 1 if IEEE floating |
862 | 810 // point functions really work. |
811 | |
1957 | 812 DEFUN (isieee, , , |
3301 | 813 "-*- texinfo -*-\n\ |
814 @deftypefn {Built-in Function} {} isieee ()\n\ | |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11234
diff
changeset
|
815 Return true if your computer @emph{claims} to conform to the IEEE standard\n\ |
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11234
diff
changeset
|
816 for floating point calculations. No actual tests are performed.\n\ |
3301 | 817 @end deftypefn") |
862 | 818 { |
4600 | 819 oct_mach_info::float_format flt_fmt = oct_mach_info::native_float_format (); |
2317 | 820 |
4574 | 821 return octave_value (flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
822 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian); |
862 | 823 } |
824 | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
825 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
826 %!assert (islogical (isieee ())); |
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 |
4600 | 829 DEFUN (native_float_format, , , |
830 "-*- texinfo -*-\n\ | |
831 @deftypefn {Built-in Function} {} native_float_format ()\n\ | |
832 Return the native floating point format as a string\n\ | |
833 @end deftypefn") | |
834 { | |
835 oct_mach_info::float_format flt_fmt = oct_mach_info::native_float_format (); | |
836 | |
837 return octave_value (oct_mach_info::float_format_as_string (flt_fmt)); | |
838 } | |
839 | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
840 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
841 %!assert (ischar (native_float_format ())); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
842 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
843 |
1957 | 844 DEFUN (tilde_expand, args, , |
3301 | 845 "-*- texinfo -*-\n\ |
846 @deftypefn {Built-in Function} {} tilde_expand (@var{string})\n\ | |
11572
7d6d8c1e471f
Grammarcheck Texinfo for files in src directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
847 Perform tilde expansion on @var{string}. If @var{string} begins with a\n\ |
3301 | 848 tilde character, (@samp{~}), all of the characters preceding the first\n\ |
849 slash (or all characters, if there is no slash) are treated as a\n\ | |
850 possible user name, and the tilde and the following characters up to the\n\ | |
851 slash are replaced by the home directory of the named user. If the\n\ | |
852 tilde is followed immediately by a slash, the tilde is replaced by the\n\ | |
10840 | 853 home directory of the user running Octave. For example:\n\ |
3301 | 854 \n\ |
855 @example\n\ | |
856 @group\n\ | |
857 tilde_expand (\"~joeuser/bin\")\n\ | |
858 @result{} \"/home/joeuser/bin\"\n\ | |
859 tilde_expand (\"~/bin\")\n\ | |
860 @result{} \"/home/jwe/bin\"\n\ | |
861 @end group\n\ | |
862 @end example\n\ | |
863 @end deftypefn") | |
1750 | 864 { |
4233 | 865 octave_value retval; |
1750 | 866 |
867 int nargin = args.length (); | |
868 | |
869 if (nargin == 1) | |
6116 | 870 { |
871 octave_value arg = args(0); | |
872 | |
873 string_vector sv = arg.all_strings (); | |
874 | |
875 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
876 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
877 sv = file_ops::tilde_expand (sv); |
6116 | 878 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
879 if (arg.is_cellstr ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
880 retval = Cell (arg.dims (), sv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
881 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
882 retval = sv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
883 } |
6116 | 884 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
885 error ("tilde_expand: expecting argument to be char or cellstr object"); |
6116 | 886 } |
1750 | 887 else |
5823 | 888 print_usage (); |
1750 | 889 |
890 return retval; | |
891 } | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
892 |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
893 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
894 %!test |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
895 %! if (isempty (getenv ("HOME"))) |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
896 %! setenv ("HOME", "foobar"); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
897 %! endif |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
898 %! home = getenv ("HOME"); |
13962
efa658122cc9
Fix tilde_expand %!test bug on MinGW (Bug #33862)
Rik <octave@nomad.inbox5.com>
parents:
13885
diff
changeset
|
899 %! assert (tilde_expand ("~/foobar"), strcat (home, "/foobar")); |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
900 %! 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
|
901 %! 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
|
902 */ |