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