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