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