Mercurial > octave-nkf
annotate src/sysdep.cc @ 11232:88e4ea8b2c19
eliminate special cases for NeXT systems
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Nov 2010 21:01:54 -0500 |
parents | 2f29b765c0ef |
children | 1dfbcc9eee92 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2003, |
8920 | 4 2005, 2006, 2007, 2008, 2009 John W. Eaton |
1 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
1 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
1 | 21 |
22 */ | |
23 | |
240 | 24 #ifdef HAVE_CONFIG_H |
1192 | 25 #include <config.h> |
1 | 26 #endif |
27 | |
1346 | 28 #include <cfloat> |
1343 | 29 #include <cstddef> |
1346 | 30 #include <cstdio> |
1343 | 31 #include <cstdlib> |
32 #include <cstring> | |
33 | |
3503 | 34 #include <iostream> |
1728 | 35 #include <string> |
36 | |
529 | 37 #include <sys/types.h> |
38 #include <unistd.h> | |
1 | 39 |
1430 | 40 #if defined (HAVE_TERMIOS_H) |
41 #include <termios.h> | |
42 #elif defined (HAVE_TERMIO_H) | |
43 #include <termio.h> | |
44 #elif defined (HAVE_SGTTY_H) | |
45 #include <sgtty.h> | |
4067 | 46 #endif |
47 | |
48 #if defined (HAVE_CONIO_H) | |
49 #include <conio.h> | |
1430 | 50 #endif |
51 | |
3248 | 52 #if defined (HAVE_SYS_IOCTL_H) |
53 #include <sys/ioctl.h> | |
54 #endif | |
55 | |
1463 | 56 #if defined (HAVE_FLOATINGPOINT_H) |
57 #include <floatingpoint.h> | |
58 #endif | |
59 | |
2508 | 60 #if defined (HAVE_IEEEFP_H) |
61 #include <ieeefp.h> | |
62 #endif | |
63 | |
2926 | 64 #include "cmd-edit.h" |
65 #include "file-ops.h" | |
2893 | 66 #include "lo-mappers.h" |
7231 | 67 #include "lo-math.h" |
2317 | 68 #include "mach-info.h" |
2926 | 69 #include "oct-env.h" |
5451 | 70 #include "quit.h" |
1769 | 71 |
6208 | 72 #include "Cell.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) |
6080 | 105 static void |
106 w32_set_octave_home (void) | |
107 { | |
108 int n = 1024; | |
109 | |
6086 | 110 std::string bin_dir (n, '\0'); |
6080 | 111 |
112 while (true) | |
113 { | |
6954 | 114 HMODULE hMod = GetModuleHandle ("octinterp"); |
115 int status = GetModuleFileName (hMod, &bin_dir[0], n); | |
6080 | 116 |
117 if (status < n) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
118 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
119 bin_dir.resize (status); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
120 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
121 } |
6080 | 122 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
123 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
124 n *= 2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
125 bin_dir.resize (n); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
126 } |
6080 | 127 } |
128 | |
129 if (! bin_dir.empty ()) | |
130 { | |
131 size_t pos = bin_dir.rfind ("\\bin\\"); | |
132 | |
8021 | 133 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
134 octave_env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos)); |
6080 | 135 } |
136 } | |
137 | |
6960 | 138 void |
5451 | 139 w32_set_quiet_shutdown (void) |
140 { | |
141 // Let the user close the console window or shutdown without the | |
142 // pesky dialog. | |
143 // | |
5775 | 144 // FIXME -- should this be user configurable? |
5451 | 145 SetProcessShutdownParameters (0x280, SHUTDOWN_NORETRY); |
146 } | |
147 | |
6960 | 148 void |
5451 | 149 MINGW_signal_cleanup (void) |
150 { | |
5455 | 151 w32_set_quiet_shutdown (); |
5451 | 152 |
5455 | 153 w32_raise_final (); |
5451 | 154 } |
155 #endif | |
156 | |
157 #if defined (__MINGW32__) | |
158 static void | |
159 MINGW_init (void) | |
160 { | |
6080 | 161 w32_set_octave_home (); |
162 | |
5451 | 163 // Init mutex to protect setjmp/longjmp and get main thread context |
164 w32_sigint_init (); | |
165 | |
166 w32_set_quiet_shutdown (); | |
167 } | |
168 #endif | |
169 | |
6080 | 170 #if defined (_MSC_VER) |
171 static void | |
172 MSVC_init (void) | |
173 { | |
174 w32_set_octave_home (); | |
6135 | 175 |
176 // Init mutex to protect setjmp/longjmp and get main thread context | |
177 w32_sigint_init (); | |
178 | |
179 w32_set_quiet_shutdown (); | |
6080 | 180 } |
181 #endif | |
182 | |
4091 | 183 |
6598 | 184 // Return TRUE if FILE1 and FILE2 refer to the same (physical) file. |
185 | |
186 bool | |
187 same_file_internal (const std::string& file1, const std::string& file2) | |
188 { | |
189 #ifdef OCTAVE_USE_WINDOWS_API | |
190 | |
6691 | 191 bool retval = false; |
192 | |
6598 | 193 // Windows native code |
194 // Reference: http://msdn2.microsoft.com/en-us/library/aa363788.aspx | |
195 | |
6691 | 196 HANDLE hfile1 = CreateFile (file1.c_str (), 0, FILE_SHARE_READ, 0, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
197 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
6691 | 198 |
199 if (hfile1 != INVALID_HANDLE_VALUE) | |
200 { | |
201 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
|
202 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
6598 | 203 |
6691 | 204 if (hfile2 != INVALID_HANDLE_VALUE) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
205 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
206 BY_HANDLE_FILE_INFORMATION hfi1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
207 BY_HANDLE_FILE_INFORMATION hfi2; |
6691 | 208 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
209 if (GetFileInformationByHandle (hfile1, &hfi1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
210 && GetFileInformationByHandle (hfile2, &hfi2)) |
6598 | 211 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
212 retval = (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
213 && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
214 && hfi1.nFileIndexLow == hfi2.nFileIndexLow); |
6598 | 215 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
216 CloseHandle (hfile2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
217 } |
6691 | 218 |
6598 | 219 CloseHandle (hfile1); |
220 } | |
6691 | 221 |
222 return retval; | |
6598 | 223 |
224 #else | |
225 | |
226 // POSIX Code | |
227 | |
228 file_stat fs_file1 (file1); | |
229 file_stat fs_file2 (file2); | |
230 | |
231 return (fs_file1 && fs_file2 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
232 && fs_file1.ino () == fs_file2.ino () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
233 && fs_file1.dev () == fs_file2.dev ()); |
6598 | 234 |
235 #endif | |
236 } | |
237 | |
4284 | 238 #if defined (__DECCXX) |
239 | |
240 // These don't seem to be instantiated automatically... | |
241 | |
242 template std::istream& | |
243 std::operator >> (std::istream&, std::complex<double>&); | |
244 | |
245 template std::string& | |
246 std::string::append (const std::string&, size_t, size_t); | |
247 | |
248 #endif | |
249 | |
1 | 250 void |
251 sysdep_init (void) | |
252 { | |
9441
160c564d5d25
initialize floating point values properly for NetBSD systems
Aleksej Saushev <asau@inbox.ru>
parents:
9411
diff
changeset
|
253 #if defined (__386BSD__) || defined (__FreeBSD__) || defined(__NetBSD__) |
2508 | 254 BSD_init (); |
5451 | 255 #elif defined (__MINGW32__) |
256 MINGW_init (); | |
6080 | 257 #elif defined (_MSC_VER) |
258 MSVC_init (); | |
1 | 259 #endif |
444 | 260 |
261 octave_ieee_init (); | |
1 | 262 } |
263 | |
5451 | 264 void |
265 sysdep_cleanup (void) | |
266 { | |
267 MINGW_SIGNAL_CLEANUP (); | |
268 } | |
269 | |
767 | 270 // Set terminal in raw mode. From less-177. |
271 // | |
272 // Change terminal to "raw mode", or restore to "normal" mode. | |
273 // "Raw mode" means | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
274 // 1. An outstanding read will complete on receipt of a single keystroke. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
275 // 2. Input is not echoed. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
276 // 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
|
277 // 4. \t is NOT expanded into spaces. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
278 // 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
|
279 // etc. are NOT disabled. |
767 | 280 // It doesn't matter whether an input \n is mapped to \r, or vice versa. |
281 | |
529 | 282 void |
3657 | 283 raw_mode (bool on, bool wait) |
529 | 284 { |
3657 | 285 static bool curr_on = false; |
529 | 286 |
287 int tty_fd = STDIN_FILENO; | |
288 if (! isatty (tty_fd)) | |
289 { | |
290 if (interactive) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
291 error ("stdin is not a tty!"); |
529 | 292 return; |
293 } | |
294 | |
295 if (on == curr_on) | |
296 return; | |
297 | |
298 #if defined (HAVE_TERMIOS_H) | |
299 { | |
300 struct termios s; | |
301 static struct termios save_term; | |
302 | |
303 if (on) | |
304 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
305 // Get terminal modes. |
529 | 306 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
307 tcgetattr (tty_fd, &s); |
529 | 308 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
309 // Save modes and set certain variables dependent on modes. |
529 | 310 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
311 save_term = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
312 // ospeed = s.c_cflag & CBAUD; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
313 // erase_char = s.c_cc[VERASE]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
314 // kill_char = s.c_cc[VKILL]; |
529 | 315 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
316 // Set the modes to the way we want them. |
529 | 317 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
318 s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
319 s.c_oflag |= (OPOST|ONLCR); |
529 | 320 #if defined (OCRNL) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
321 s.c_oflag &= ~(OCRNL); |
529 | 322 #endif |
323 #if defined (ONOCR) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
324 s.c_oflag &= ~(ONOCR); |
529 | 325 #endif |
326 #if defined (ONLRET) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
327 s.c_oflag &= ~(ONLRET); |
529 | 328 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
329 s.c_cc[VMIN] = wait ? 1 : 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
330 s.c_cc[VTIME] = 0; |
529 | 331 } |
332 else | |
333 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
334 // Restore saved modes. |
1358 | 335 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
336 s = save_term; |
529 | 337 } |
3658 | 338 |
9411
c9636d98e5cd
fix kbhit(1) to not discard waiting keystrokes
Joe Rothweiler <octaveuser@sensicomm.com>
parents:
9242
diff
changeset
|
339 tcsetattr (tty_fd, wait ? TCSAFLUSH : TCSADRAIN, &s); |
529 | 340 } |
341 #elif defined (HAVE_TERMIO_H) | |
342 { | |
343 struct termio s; | |
344 static struct termio save_term; | |
345 | |
346 if (on) | |
347 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
348 // Get terminal modes. |
529 | 349 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
350 ioctl (tty_fd, TCGETA, &s); |
529 | 351 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
352 // Save modes and set certain variables dependent on modes. |
529 | 353 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
354 save_term = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
355 // ospeed = s.c_cflag & CBAUD; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
356 // erase_char = s.c_cc[VERASE]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
357 // kill_char = s.c_cc[VKILL]; |
529 | 358 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
359 // Set the modes to the way we want them. |
529 | 360 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
361 s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
362 s.c_oflag |= (OPOST|ONLCR); |
529 | 363 #if defined (OCRNL) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
364 s.c_oflag &= ~(OCRNL); |
529 | 365 #endif |
366 #if defined (ONOCR) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
367 s.c_oflag &= ~(ONOCR); |
529 | 368 #endif |
369 #if defined (ONLRET) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
370 s.c_oflag &= ~(ONLRET); |
529 | 371 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
372 s.c_cc[VMIN] = wait ? 1 : 0; |
529 | 373 } |
374 else | |
375 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
376 // Restore saved modes. |
1358 | 377 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
378 s = save_term; |
529 | 379 } |
3658 | 380 |
529 | 381 ioctl (tty_fd, TCSETAW, &s); |
382 } | |
383 #elif defined (HAVE_SGTTY_H) | |
384 { | |
385 struct sgttyb s; | |
386 static struct sgttyb save_term; | |
387 | |
388 if (on) | |
389 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
390 // Get terminal modes. |
529 | 391 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
392 ioctl (tty_fd, TIOCGETP, &s); |
529 | 393 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
394 // Save modes and set certain variables dependent on modes. |
529 | 395 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
396 save_term = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
397 // ospeed = s.sg_ospeed; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
398 // erase_char = s.sg_erase; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
399 // kill_char = s.sg_kill; |
529 | 400 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
401 // Set the modes to the way we want them. |
529 | 402 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
403 s.sg_flags |= CBREAK; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
404 s.sg_flags &= ~(ECHO); |
529 | 405 } |
406 else | |
407 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
408 // Restore saved modes. |
1358 | 409 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
410 s = save_term; |
529 | 411 } |
3658 | 412 |
529 | 413 ioctl (tty_fd, TIOCSETN, &s); |
414 } | |
415 #else | |
4064 | 416 warning ("no support for raw mode console I/O on this system"); |
417 | |
418 // Make sure the current mode doesn't toggle. | |
419 on = curr_on; | |
529 | 420 #endif |
421 | |
422 curr_on = on; | |
423 } | |
424 | |
6726 | 425 FILE * |
426 octave_popen (const char *command, const char *mode) | |
427 { | |
428 #if defined (__MINGW32__) || defined (_MSC_VER) | |
429 if (mode && mode[0] && ! mode[1]) | |
430 { | |
431 char tmode[3]; | |
432 tmode[0] = mode[0]; | |
433 tmode[1] = 'b'; | |
434 tmode[2] = 0; | |
435 | |
436 return _popen (command, tmode); | |
437 } | |
438 else | |
439 return _popen (command, mode); | |
440 #else | |
441 return popen (command, mode); | |
442 #endif | |
443 } | |
444 | |
445 int | |
446 octave_pclose (FILE *f) | |
447 { | |
448 #if defined (__MINGW32__) || defined (_MSC_VER) | |
449 return _pclose (f); | |
450 #else | |
451 return pclose (f); | |
452 #endif | |
453 } | |
454 | |
767 | 455 // Read one character from the terminal. |
456 | |
529 | 457 int |
4067 | 458 octave_kbhit (bool wait) |
529 | 459 { |
4067 | 460 #ifdef HAVE__KBHIT |
4081 | 461 int c = (! wait && ! _kbhit ()) ? 0 : std::cin.get (); |
4067 | 462 #else |
3658 | 463 raw_mode (true, wait); |
464 | |
5770 | 465 // Get current handler. |
466 octave_interrupt_handler saved_interrupt_handler | |
467 = octave_ignore_interrupts (); | |
468 | |
469 // Restore it, disabling system call restarts (if possible) so the | |
470 // read can be interrupted. | |
471 | |
472 octave_set_interrupt_handler (saved_interrupt_handler, false); | |
473 | |
3658 | 474 int c = std::cin.get (); |
5770 | 475 |
3658 | 476 if (std::cin.fail () || std::cin.eof ()) |
477 std::cin.clear (); | |
478 | |
5770 | 479 // Restore it, enabling system call restarts (if possible). |
480 octave_set_interrupt_handler (saved_interrupt_handler, true); | |
481 | |
3658 | 482 raw_mode (false, true); |
4067 | 483 #endif |
3658 | 484 |
529 | 485 return c; |
486 } | |
487 | |
1957 | 488 DEFUN (clc, , , |
3332 | 489 "-*- texinfo -*-\n\ |
10840 | 490 @deftypefn {Built-in Function} {} clc ()\n\ |
3332 | 491 @deftypefnx {Built-in Function} {} home ()\n\ |
492 Clear the terminal screen and move the cursor to the upper left corner.\n\ | |
3333 | 493 @end deftypefn") |
529 | 494 { |
2926 | 495 command_editor::clear_screen (); |
529 | 496 |
2926 | 497 return octave_value_list (); |
529 | 498 } |
499 | |
549 | 500 DEFALIAS (home, clc); |
501 | |
1957 | 502 DEFUN (getenv, args, , |
3301 | 503 "-*- texinfo -*-\n\ |
504 @deftypefn {Built-in Function} {} getenv (@var{var})\n\ | |
505 Return the value of the environment variable @var{var}. For example,\n\ | |
506 \n\ | |
507 @example\n\ | |
508 getenv (\"PATH\")\n\ | |
509 @end example\n\ | |
510 \n\ | |
511 @noindent\n\ | |
512 returns a string containing the value of your path.\n\ | |
513 @end deftypefn") | |
529 | 514 { |
4233 | 515 octave_value retval; |
529 | 516 |
517 int nargin = args.length (); | |
518 | |
712 | 519 if (nargin == 1) |
529 | 520 { |
3523 | 521 std::string name = args(0).string_value (); |
636 | 522 |
523 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
524 retval = octave_env::getenv (name); |
529 | 525 } |
526 else | |
5823 | 527 print_usage (); |
529 | 528 |
529 return retval; | |
530 } | |
531 | |
1957 | 532 DEFUN (putenv, args, , |
3301 | 533 "-*- texinfo -*-\n\ |
10840 | 534 @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
|
535 @deftypefnx {Built-in Function} {} setenv (@var{var}, @var{value})\n\ |
3301 | 536 Set the value of the environment variable @var{var} to @var{value}.\n\ |
537 @end deftypefn") | |
1706 | 538 { |
2086 | 539 octave_value_list retval; |
1706 | 540 |
541 int nargin = args.length (); | |
542 | |
7759
84a7f00586aa
Alias setenv to putenv. Allow single arg to putenv
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
543 if (nargin == 2 || nargin == 1) |
1706 | 544 { |
3523 | 545 std::string var = args(0).string_value (); |
1706 | 546 |
547 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
548 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
549 std::string val = (nargin == 2 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
550 ? args(1).string_value () : std::string ()); |
1706 | 551 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
552 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
553 octave_env::putenv (var, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
554 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
555 error ("putenv: second argument should be a string"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
556 } |
1706 | 557 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
558 error ("putenv: first argument should be a string"); |
1706 | 559 } |
560 else | |
5823 | 561 print_usage (); |
1706 | 562 |
563 return retval; | |
564 } | |
7759
84a7f00586aa
Alias setenv to putenv. Allow single arg to putenv
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
565 DEFALIAS (setenv, putenv); |
1706 | 566 |
5775 | 567 // FIXME -- perhaps kbhit should also be able to print a prompt? |
3372 | 568 |
3657 | 569 DEFUN (kbhit, args, , |
3372 | 570 "-*- texinfo -*-\n\ |
571 @deftypefn {Built-in Function} {} kbhit ()\n\ | |
9039
51dc9691f23f
Cleanup documentation files errors.texi, debug.texi, io.texi
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
572 Read a single keystroke from the keyboard. If called with one\n\ |
3657 | 573 argument, don't wait for a keypress. For example,\n\ |
3372 | 574 \n\ |
575 @example\n\ | |
576 x = kbhit ();\n\ | |
577 @end example\n\ | |
578 \n\ | |
579 @noindent\n\ | |
580 will set @var{x} to the next character typed at the keyboard as soon as\n\ | |
581 it is typed.\n\ | |
3657 | 582 \n\ |
583 @example\n\ | |
584 x = kbhit (1);\n\ | |
585 @end example\n\ | |
586 \n\ | |
587 @noindent\n\ | |
588 identical to the above example, but don't wait for a keypress,\n\ | |
589 returning the empty string if no key is available.\n\ | |
3372 | 590 @end deftypefn") |
529 | 591 { |
4233 | 592 octave_value retval; |
529 | 593 |
5775 | 594 // FIXME -- add timeout and default value args? |
529 | 595 |
3676 | 596 if (interactive || forced_interactive) |
529 | 597 { |
6423 | 598 feval ("drawnow"); |
599 | |
4067 | 600 int c = octave_kbhit (args.length () == 0); |
3657 | 601 |
3658 | 602 if (c == -1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
603 c = 0; |
3657 | 604 |
529 | 605 char *s = new char [2]; |
606 s[0] = c; | |
607 s[1] = '\0'; | |
608 retval = s; | |
609 } | |
610 | |
611 return retval; | |
612 } | |
613 | |
1957 | 614 DEFUN (pause, args, , |
3301 | 615 "-*- texinfo -*-\n\ |
616 @deftypefn {Built-in Function} {} pause (@var{seconds})\n\ | |
617 Suspend the execution of the program. If invoked without any arguments,\n\ | |
618 Octave waits until you type a character. With a numeric argument, it\n\ | |
619 pauses for the given number of seconds. For example, the following\n\ | |
620 statement prints a message and then waits 5 seconds before clearing the\n\ | |
621 screen.\n\ | |
622 \n\ | |
623 @example\n\ | |
624 @group\n\ | |
6848 | 625 fprintf (stderr, \"wait please...\\n\");\n\ |
3301 | 626 pause (5);\n\ |
627 clc;\n\ | |
628 @end group\n\ | |
629 @end example\n\ | |
630 @end deftypefn") | |
529 | 631 { |
2086 | 632 octave_value_list retval; |
529 | 633 |
634 int nargin = args.length (); | |
635 | |
712 | 636 if (! (nargin == 0 || nargin == 1)) |
529 | 637 { |
5823 | 638 print_usage (); |
529 | 639 return retval; |
640 } | |
641 | |
1579 | 642 if (nargin == 1) |
529 | 643 { |
1579 | 644 double dval = args(0).double_value (); |
636 | 645 |
1579 | 646 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
647 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
648 if (! xisnan (dval)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
649 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
650 feval ("drawnow"); |
6419 | 651 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
652 if (xisinf (dval)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
653 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
654 flush_octave_stdout (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
655 octave_kbhit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
656 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
657 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
658 octave_sleep (dval); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
659 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
660 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
661 warning ("pause: NaN is an invalid delay"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
662 } |
529 | 663 } |
1579 | 664 else |
3234 | 665 { |
6423 | 666 feval ("drawnow"); |
3234 | 667 flush_octave_stdout (); |
4067 | 668 octave_kbhit (); |
3234 | 669 } |
2630 | 670 |
671 return retval; | |
672 } | |
673 | |
674 DEFUN (sleep, args, , | |
3301 | 675 "-*- texinfo -*-\n\ |
676 @deftypefn {Built-in Function} {} sleep (@var{seconds})\n\ | |
677 Suspend the execution of the program for the given number of seconds.\n\ | |
678 @end deftypefn") | |
2630 | 679 { |
680 octave_value_list retval; | |
681 | |
682 if (args.length () == 1) | |
1579 | 683 { |
2630 | 684 double dval = args(0).double_value (); |
685 | |
686 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
687 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
688 if (xisnan (dval)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
689 warning ("sleep: NaN is an invalid delay"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
690 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
691 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
692 feval ("drawnow"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
693 octave_sleep (dval); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
694 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
695 } |
1579 | 696 } |
2630 | 697 else |
5823 | 698 print_usage (); |
2630 | 699 |
700 return retval; | |
701 } | |
702 | |
703 DEFUN (usleep, args, , | |
3301 | 704 "-*- texinfo -*-\n\ |
705 @deftypefn {Built-in Function} {} usleep (@var{microseconds})\n\ | |
706 Suspend the execution of the program for the given number of\n\ | |
707 microseconds. On systems where it is not possible to sleep for periods\n\ | |
708 of time less than one second, @code{usleep} will pause the execution for\n\ | |
709 @code{round (@var{microseconds} / 1e6)} seconds.\n\ | |
710 @end deftypefn") | |
2630 | 711 { |
712 octave_value_list retval; | |
713 | |
714 if (args.length () == 1) | |
715 { | |
716 double dval = args(0).double_value (); | |
717 | |
718 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
719 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
720 if (xisnan (dval)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
721 warning ("usleep: NaN is an invalid delay"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
722 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
723 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
724 feval ("drawnow"); |
6423 | 725 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
726 int delay = NINT (dval); |
2631 | 727 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
728 if (delay > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
729 octave_usleep (delay); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
730 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
731 } |
2630 | 732 } |
733 else | |
5823 | 734 print_usage (); |
529 | 735 |
736 return retval; | |
737 } | |
738 | |
5775 | 739 // FIXME -- maybe this should only return 1 if IEEE floating |
862 | 740 // point functions really work. |
741 | |
1957 | 742 DEFUN (isieee, , , |
3301 | 743 "-*- texinfo -*-\n\ |
744 @deftypefn {Built-in Function} {} isieee ()\n\ | |
745 Return 1 if your computer claims to conform to the IEEE standard for\n\ | |
746 floating point calculations.\n\ | |
747 @end deftypefn") | |
862 | 748 { |
4600 | 749 oct_mach_info::float_format flt_fmt = oct_mach_info::native_float_format (); |
2317 | 750 |
4574 | 751 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
|
752 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian); |
862 | 753 } |
754 | |
4600 | 755 DEFUN (native_float_format, , , |
756 "-*- texinfo -*-\n\ | |
757 @deftypefn {Built-in Function} {} native_float_format ()\n\ | |
758 Return the native floating point format as a string\n\ | |
759 @end deftypefn") | |
760 { | |
761 oct_mach_info::float_format flt_fmt = oct_mach_info::native_float_format (); | |
762 | |
763 return octave_value (oct_mach_info::float_format_as_string (flt_fmt)); | |
764 } | |
765 | |
1957 | 766 DEFUN (tilde_expand, args, , |
3301 | 767 "-*- texinfo -*-\n\ |
768 @deftypefn {Built-in Function} {} tilde_expand (@var{string})\n\ | |
769 Performs tilde expansion on @var{string}. If @var{string} begins with a\n\ | |
770 tilde character, (@samp{~}), all of the characters preceding the first\n\ | |
771 slash (or all characters, if there is no slash) are treated as a\n\ | |
772 possible user name, and the tilde and the following characters up to the\n\ | |
773 slash are replaced by the home directory of the named user. If the\n\ | |
774 tilde is followed immediately by a slash, the tilde is replaced by the\n\ | |
10840 | 775 home directory of the user running Octave. For example:\n\ |
3301 | 776 \n\ |
777 @example\n\ | |
778 @group\n\ | |
779 tilde_expand (\"~joeuser/bin\")\n\ | |
780 @result{} \"/home/joeuser/bin\"\n\ | |
781 tilde_expand (\"~/bin\")\n\ | |
782 @result{} \"/home/jwe/bin\"\n\ | |
783 @end group\n\ | |
784 @end example\n\ | |
785 @end deftypefn") | |
1750 | 786 { |
4233 | 787 octave_value retval; |
1750 | 788 |
789 int nargin = args.length (); | |
790 | |
791 if (nargin == 1) | |
6116 | 792 { |
793 octave_value arg = args(0); | |
794 | |
795 string_vector sv = arg.all_strings (); | |
796 | |
797 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
798 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
799 sv = file_ops::tilde_expand (sv); |
6116 | 800 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
801 if (arg.is_cellstr ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
802 retval = Cell (arg.dims (), sv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
803 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
804 retval = sv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
805 } |
6116 | 806 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
807 error ("tilde_expand: expecting argument to be char or cellstr object"); |
6116 | 808 } |
1750 | 809 else |
5823 | 810 print_usage (); |
1750 | 811 |
812 return retval; | |
813 } |