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