1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1
|
21 |
|
22 */ |
|
23 |
240
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
1
|
26 #endif |
|
27 |
1346
|
28 #include <cfloat> |
3124
|
29 #include <cmath> |
1343
|
30 #include <cstddef> |
1346
|
31 #include <cstdio> |
1343
|
32 #include <cstdlib> |
|
33 #include <cstring> |
|
34 |
3503
|
35 #include <iostream> |
1728
|
36 #include <string> |
|
37 |
1350
|
38 #ifdef HAVE_UNISTD_H |
2442
|
39 #ifdef HAVE_SYS_TYPES_H |
529
|
40 #include <sys/types.h> |
2442
|
41 #endif |
529
|
42 #include <unistd.h> |
|
43 #endif |
1
|
44 |
1430
|
45 #if defined (HAVE_TERMIOS_H) |
|
46 #include <termios.h> |
|
47 #elif defined (HAVE_TERMIO_H) |
|
48 #include <termio.h> |
|
49 #elif defined (HAVE_SGTTY_H) |
|
50 #include <sgtty.h> |
4067
|
51 #endif |
|
52 |
|
53 #if defined (HAVE_CONIO_H) |
|
54 #include <conio.h> |
1430
|
55 #endif |
|
56 |
3248
|
57 #if defined (HAVE_SYS_IOCTL_H) |
|
58 #include <sys/ioctl.h> |
|
59 #endif |
|
60 |
1463
|
61 #if defined (HAVE_FLOATINGPOINT_H) |
|
62 #include <floatingpoint.h> |
|
63 #endif |
|
64 |
2508
|
65 #if defined (HAVE_IEEEFP_H) |
|
66 #include <ieeefp.h> |
|
67 #endif |
|
68 |
1463
|
69 #if !defined (HAVE_GETHOSTNAME) && defined (HAVE_SYS_UTSNAME_H) |
|
70 #include <sys/utsname.h> |
|
71 #endif |
|
72 |
2926
|
73 #include "cmd-edit.h" |
|
74 #include "file-ops.h" |
2893
|
75 #include "lo-mappers.h" |
2317
|
76 #include "mach-info.h" |
2926
|
77 #include "oct-env.h" |
5451
|
78 #include "quit.h" |
1769
|
79 |
1352
|
80 #include "defun.h" |
|
81 #include "error.h" |
529
|
82 #include "input.h" |
1755
|
83 #include "oct-obj.h" |
2370
|
84 #include "ov.h" |
3234
|
85 #include "pager.h" |
5770
|
86 #include "sighandlers.h" |
1352
|
87 #include "sysdep.h" |
1755
|
88 #include "toplev.h" |
529
|
89 #include "utils.h" |
|
90 |
|
91 #ifndef STDIN_FILENO |
|
92 #define STDIN_FILENO 1 |
|
93 #endif |
444
|
94 |
2508
|
95 #if defined (__386BSD__) || defined (__FreeBSD__) |
|
96 static void |
|
97 BSD_init (void) |
|
98 { |
|
99 #if defined (HAVE_FLOATINGPOINT_H) |
|
100 // Disable trapping on common exceptions. |
4164
|
101 #ifndef FP_X_DNML |
|
102 #define FP_X_DNML 0 |
|
103 #endif |
2508
|
104 fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP)); |
|
105 #endif |
|
106 } |
|
107 #endif |
|
108 |
6080
|
109 static void |
|
110 w32_set_octave_home (void) |
|
111 { |
|
112 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
|
113 int n = 1024; |
|
114 |
6086
|
115 std::string bin_dir (n, '\0'); |
6080
|
116 |
|
117 while (true) |
|
118 { |
|
119 int status = GetModuleFileName (0, &bin_dir[0], n); |
|
120 |
|
121 if (status < n) |
|
122 { |
|
123 bin_dir.resize (status); |
|
124 break; |
|
125 } |
|
126 else |
|
127 { |
|
128 n *= 2; |
|
129 bin_dir.resize (n); |
|
130 } |
|
131 } |
|
132 |
|
133 if (! bin_dir.empty ()) |
|
134 { |
|
135 size_t pos = bin_dir.rfind ("\\bin\\"); |
|
136 |
|
137 if (pos != NPOS) |
|
138 octave_env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos)); |
|
139 } |
|
140 #endif |
|
141 } |
|
142 |
5451
|
143 void |
|
144 w32_set_quiet_shutdown (void) |
|
145 { |
|
146 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
|
147 // Let the user close the console window or shutdown without the |
|
148 // pesky dialog. |
|
149 // |
5775
|
150 // FIXME -- should this be user configurable? |
5451
|
151 SetProcessShutdownParameters (0x280, SHUTDOWN_NORETRY); |
|
152 #endif |
|
153 } |
|
154 |
|
155 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
|
156 void |
|
157 MINGW_signal_cleanup (void) |
|
158 { |
5455
|
159 w32_set_quiet_shutdown (); |
5451
|
160 |
5455
|
161 w32_raise_final (); |
5451
|
162 } |
|
163 #endif |
|
164 |
|
165 #if defined (__MINGW32__) |
|
166 static void |
|
167 MINGW_init (void) |
|
168 { |
6080
|
169 w32_set_octave_home (); |
|
170 |
5451
|
171 // Init mutex to protect setjmp/longjmp and get main thread context |
|
172 w32_sigint_init (); |
|
173 |
|
174 w32_set_quiet_shutdown (); |
|
175 } |
|
176 #endif |
|
177 |
6080
|
178 #if defined (_MSC_VER) |
|
179 static void |
|
180 MSVC_init (void) |
|
181 { |
|
182 w32_set_octave_home (); |
6135
|
183 |
|
184 // Init mutex to protect setjmp/longjmp and get main thread context |
|
185 w32_sigint_init (); |
|
186 |
|
187 w32_set_quiet_shutdown (); |
6080
|
188 } |
|
189 #endif |
|
190 |
4091
|
191 #if defined (__CYGWIN__) |
|
192 |
|
193 #include <limits.h> |
|
194 #include <sys/cygwin.h> |
|
195 |
|
196 static void |
|
197 CYGWIN_init (void) |
|
198 { |
4470
|
199 // Make sure TMPDIR contains an absolute windows path. Use '/' |
|
200 // rather than '\\' so that sh expansion won't mess file names. |
|
201 |
4091
|
202 std::string tmpdir = octave_env::getenv ("TMPDIR"); |
|
203 |
|
204 if (tmpdir.empty ()) |
4470
|
205 tmpdir = "/tmp"; |
|
206 |
|
207 char buf [PATH_MAX]; |
4091
|
208 |
4470
|
209 if (cygwin32_conv_to_full_win32_path (tmpdir.c_str (), buf) < 0) |
|
210 panic ("CYGWIN_init: unable to convert TMPDIR (= \"%s\") to Windows directory name", |
|
211 tmpdir.c_str ()); |
|
212 else |
|
213 { |
|
214 tmpdir = buf; |
4091
|
215 |
4470
|
216 for (size_t i = 0; i < tmpdir.length (); i++) |
|
217 if (tmpdir[i] == '\\') |
|
218 tmpdir[i] = '/'; |
4091
|
219 } |
4470
|
220 |
|
221 octave_env::putenv ("TMPDIR", tmpdir); |
4091
|
222 } |
|
223 #endif |
|
224 |
4284
|
225 #if defined (__DECCXX) |
|
226 |
|
227 // These don't seem to be instantiated automatically... |
|
228 |
|
229 template std::istream& |
|
230 std::operator >> (std::istream&, std::complex<double>&); |
|
231 |
|
232 template std::string& |
|
233 std::string::append (const std::string&, size_t, size_t); |
|
234 |
|
235 #endif |
|
236 |
2610
|
237 #if defined (NeXT) |
1
|
238 extern "C" |
|
239 { |
|
240 typedef void (*_cplus_fcn_int) (int); |
|
241 extern void (*malloc_error (_cplus_fcn_int)) (int); |
|
242 } |
|
243 |
|
244 static void |
|
245 malloc_handler (int code) |
|
246 { |
|
247 if (code == 5) |
217
|
248 warning ("hopefully recoverable malloc error: freeing wild pointer"); |
1
|
249 else |
2926
|
250 panic ("probably irrecoverable malloc error: code %d", code); |
1
|
251 } |
|
252 |
|
253 static void |
|
254 NeXT_init (void) |
|
255 { |
|
256 malloc_error (malloc_handler); |
|
257 } |
3333
|
258 #endif |
1
|
259 |
2546
|
260 #if defined (__EMX__) |
|
261 OS2_init (void) |
|
262 { |
|
263 _control87 ((EM_INVALID | EM_DENORMAL | EM_ZERODIVIDE | EM_OVERFLOW |
|
264 | EM_UNDERFLOW | EM_INEXACT), MCW_EM); |
|
265 } |
|
266 #endif |
|
267 |
2508
|
268 #if defined (SCO) |
|
269 static void |
|
270 SCO_init (void) |
|
271 { |
|
272 #if defined (HAVE_IEEEFP_H) |
|
273 // Disable trapping on common exceptions. |
|
274 fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP)); |
|
275 #endif |
|
276 } |
|
277 #endif |
|
278 |
1
|
279 void |
|
280 sysdep_init (void) |
|
281 { |
959
|
282 #if defined (__386BSD__) || defined (__FreeBSD__) |
2508
|
283 BSD_init (); |
4091
|
284 #elif defined (__CYGWIN__) |
|
285 CYGWIN_init (); |
5451
|
286 #elif defined (__MINGW32__) |
|
287 MINGW_init (); |
6080
|
288 #elif defined (_MSC_VER) |
|
289 MSVC_init (); |
2610
|
290 #elif defined (NeXT) |
1
|
291 NeXT_init (); |
2610
|
292 #elif defined (__EMX__) |
2546
|
293 OS2_init (); |
2508
|
294 #elif defined (SCO) |
|
295 SCO_init (); |
1
|
296 #endif |
444
|
297 |
|
298 octave_ieee_init (); |
1
|
299 } |
|
300 |
5451
|
301 void |
|
302 sysdep_cleanup (void) |
|
303 { |
|
304 MINGW_SIGNAL_CLEANUP (); |
|
305 } |
|
306 |
767
|
307 // Set terminal in raw mode. From less-177. |
|
308 // |
|
309 // Change terminal to "raw mode", or restore to "normal" mode. |
|
310 // "Raw mode" means |
|
311 // 1. An outstanding read will complete on receipt of a single keystroke. |
|
312 // 2. Input is not echoed. |
|
313 // 3. On output, \n is mapped to \r\n. |
|
314 // 4. \t is NOT expanded into spaces. |
|
315 // 5. Signal-causing characters such as ctrl-C (interrupt), |
|
316 // etc. are NOT disabled. |
|
317 // It doesn't matter whether an input \n is mapped to \r, or vice versa. |
|
318 |
529
|
319 void |
3657
|
320 raw_mode (bool on, bool wait) |
529
|
321 { |
3657
|
322 static bool curr_on = false; |
529
|
323 |
|
324 int tty_fd = STDIN_FILENO; |
|
325 if (! isatty (tty_fd)) |
|
326 { |
|
327 if (interactive) |
|
328 error ("stdin is not a tty!"); |
|
329 return; |
|
330 } |
|
331 |
|
332 if (on == curr_on) |
|
333 return; |
|
334 |
|
335 #if defined (HAVE_TERMIOS_H) |
|
336 { |
|
337 struct termios s; |
|
338 static struct termios save_term; |
|
339 |
|
340 if (on) |
|
341 { |
1358
|
342 // Get terminal modes. |
529
|
343 |
|
344 tcgetattr (tty_fd, &s); |
|
345 |
1358
|
346 // Save modes and set certain variables dependent on modes. |
529
|
347 |
|
348 save_term = s; |
|
349 // ospeed = s.c_cflag & CBAUD; |
|
350 // erase_char = s.c_cc[VERASE]; |
|
351 // kill_char = s.c_cc[VKILL]; |
|
352 |
1358
|
353 // Set the modes to the way we want them. |
529
|
354 |
|
355 s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); |
|
356 s.c_oflag |= (OPOST|ONLCR); |
|
357 #if defined (OCRNL) |
|
358 s.c_oflag &= ~(OCRNL); |
|
359 #endif |
|
360 #if defined (ONOCR) |
|
361 s.c_oflag &= ~(ONOCR); |
|
362 #endif |
|
363 #if defined (ONLRET) |
|
364 s.c_oflag &= ~(ONLRET); |
|
365 #endif |
3658
|
366 s.c_cc[VMIN] = wait ? 1 : 0; |
529
|
367 s.c_cc[VTIME] = 0; |
|
368 } |
|
369 else |
|
370 { |
1358
|
371 // Restore saved modes. |
|
372 |
529
|
373 s = save_term; |
|
374 } |
3658
|
375 |
529
|
376 tcsetattr (tty_fd, TCSAFLUSH, &s); |
|
377 } |
|
378 #elif defined (HAVE_TERMIO_H) |
|
379 { |
|
380 struct termio s; |
|
381 static struct termio save_term; |
|
382 |
|
383 if (on) |
|
384 { |
1358
|
385 // Get terminal modes. |
529
|
386 |
|
387 ioctl (tty_fd, TCGETA, &s); |
|
388 |
1358
|
389 // Save modes and set certain variables dependent on modes. |
529
|
390 |
|
391 save_term = s; |
|
392 // ospeed = s.c_cflag & CBAUD; |
|
393 // erase_char = s.c_cc[VERASE]; |
|
394 // kill_char = s.c_cc[VKILL]; |
|
395 |
1358
|
396 // Set the modes to the way we want them. |
529
|
397 |
|
398 s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); |
|
399 s.c_oflag |= (OPOST|ONLCR); |
|
400 #if defined (OCRNL) |
|
401 s.c_oflag &= ~(OCRNL); |
|
402 #endif |
|
403 #if defined (ONOCR) |
|
404 s.c_oflag &= ~(ONOCR); |
|
405 #endif |
|
406 #if defined (ONLRET) |
|
407 s.c_oflag &= ~(ONLRET); |
|
408 #endif |
3658
|
409 s.c_cc[VMIN] = wait ? 1 : 0; |
529
|
410 } |
|
411 else |
|
412 { |
1358
|
413 // Restore saved modes. |
|
414 |
529
|
415 s = save_term; |
|
416 } |
3658
|
417 |
529
|
418 ioctl (tty_fd, TCSETAW, &s); |
|
419 } |
|
420 #elif defined (HAVE_SGTTY_H) |
|
421 { |
|
422 struct sgttyb s; |
|
423 static struct sgttyb save_term; |
|
424 |
|
425 if (on) |
|
426 { |
1358
|
427 // Get terminal modes. |
529
|
428 |
|
429 ioctl (tty_fd, TIOCGETP, &s); |
|
430 |
1358
|
431 // Save modes and set certain variables dependent on modes. |
529
|
432 |
|
433 save_term = s; |
|
434 // ospeed = s.sg_ospeed; |
|
435 // erase_char = s.sg_erase; |
|
436 // kill_char = s.sg_kill; |
|
437 |
1358
|
438 // Set the modes to the way we want them. |
529
|
439 |
|
440 s.sg_flags |= CBREAK; |
|
441 s.sg_flags &= ~(ECHO); |
|
442 } |
|
443 else |
|
444 { |
1358
|
445 // Restore saved modes. |
|
446 |
529
|
447 s = save_term; |
|
448 } |
3658
|
449 |
529
|
450 ioctl (tty_fd, TIOCSETN, &s); |
|
451 } |
|
452 #else |
4064
|
453 warning ("no support for raw mode console I/O on this system"); |
|
454 |
|
455 // Make sure the current mode doesn't toggle. |
|
456 on = curr_on; |
529
|
457 #endif |
|
458 |
|
459 curr_on = on; |
|
460 } |
|
461 |
767
|
462 // Read one character from the terminal. |
|
463 |
529
|
464 int |
4067
|
465 octave_kbhit (bool wait) |
529
|
466 { |
4067
|
467 #ifdef HAVE__KBHIT |
4081
|
468 int c = (! wait && ! _kbhit ()) ? 0 : std::cin.get (); |
4067
|
469 #else |
3658
|
470 raw_mode (true, wait); |
|
471 |
5770
|
472 // Get current handler. |
|
473 octave_interrupt_handler saved_interrupt_handler |
|
474 = octave_ignore_interrupts (); |
|
475 |
|
476 // Restore it, disabling system call restarts (if possible) so the |
|
477 // read can be interrupted. |
|
478 |
|
479 octave_set_interrupt_handler (saved_interrupt_handler, false); |
|
480 |
3658
|
481 int c = std::cin.get (); |
5770
|
482 |
3658
|
483 if (std::cin.fail () || std::cin.eof ()) |
|
484 std::cin.clear (); |
|
485 |
5770
|
486 // Restore it, enabling system call restarts (if possible). |
|
487 octave_set_interrupt_handler (saved_interrupt_handler, true); |
|
488 |
3658
|
489 raw_mode (false, true); |
4067
|
490 #endif |
3658
|
491 |
529
|
492 return c; |
|
493 } |
|
494 |
1957
|
495 DEFUN (clc, , , |
3332
|
496 "-*- texinfo -*-\n\ |
|
497 @deftypefn {Built-in Function} {} clc ()\n\ |
|
498 @deftypefnx {Built-in Function} {} home ()\n\ |
|
499 Clear the terminal screen and move the cursor to the upper left corner.\n\ |
3333
|
500 @end deftypefn") |
529
|
501 { |
2926
|
502 command_editor::clear_screen (); |
529
|
503 |
2926
|
504 return octave_value_list (); |
529
|
505 } |
|
506 |
549
|
507 DEFALIAS (home, clc); |
|
508 |
1957
|
509 DEFUN (getenv, args, , |
3301
|
510 "-*- texinfo -*-\n\ |
|
511 @deftypefn {Built-in Function} {} getenv (@var{var})\n\ |
|
512 Return the value of the environment variable @var{var}. For example,\n\ |
|
513 \n\ |
|
514 @example\n\ |
|
515 getenv (\"PATH\")\n\ |
|
516 @end example\n\ |
|
517 \n\ |
|
518 @noindent\n\ |
|
519 returns a string containing the value of your path.\n\ |
|
520 @end deftypefn") |
529
|
521 { |
4233
|
522 octave_value retval; |
529
|
523 |
|
524 int nargin = args.length (); |
|
525 |
712
|
526 if (nargin == 1) |
529
|
527 { |
3523
|
528 std::string name = args(0).string_value (); |
636
|
529 |
|
530 if (! error_state) |
2926
|
531 retval = octave_env::getenv (name); |
529
|
532 } |
|
533 else |
5823
|
534 print_usage (); |
529
|
535 |
|
536 return retval; |
|
537 } |
|
538 |
1957
|
539 DEFUN (putenv, args, , |
3301
|
540 "-*- texinfo -*-\n\ |
|
541 @deftypefn {Built-in Function} {} putenv (@var{var}, @var{value})\n\ |
|
542 Set the value of the environment variable @var{var} to @var{value}.\n\ |
|
543 @end deftypefn") |
1706
|
544 { |
2086
|
545 octave_value_list retval; |
1706
|
546 |
|
547 int nargin = args.length (); |
|
548 |
|
549 if (nargin == 2) |
|
550 { |
3523
|
551 std::string var = args(0).string_value (); |
1706
|
552 |
|
553 if (! error_state) |
|
554 { |
3523
|
555 std::string val = args(1).string_value (); |
1706
|
556 |
|
557 if (! error_state) |
2926
|
558 octave_env::putenv (var, val); |
1706
|
559 else |
|
560 error ("putenv: second argument should be a string"); |
|
561 } |
|
562 else |
|
563 error ("putenv: first argument should be a string"); |
|
564 } |
|
565 else |
5823
|
566 print_usage (); |
1706
|
567 |
|
568 return retval; |
|
569 } |
|
570 |
5775
|
571 // FIXME -- perhaps kbhit should also be able to print a prompt? |
3372
|
572 |
3657
|
573 DEFUN (kbhit, args, , |
3372
|
574 "-*- texinfo -*-\n\ |
|
575 @deftypefn {Built-in Function} {} kbhit ()\n\ |
3657
|
576 Read a single keystroke from the keyboard. If called with one\n\ |
|
577 argument, don't wait for a keypress. For example,\n\ |
3372
|
578 \n\ |
|
579 @example\n\ |
|
580 x = kbhit ();\n\ |
|
581 @end example\n\ |
|
582 \n\ |
|
583 @noindent\n\ |
|
584 will set @var{x} to the next character typed at the keyboard as soon as\n\ |
|
585 it is typed.\n\ |
3657
|
586 \n\ |
|
587 @example\n\ |
|
588 x = kbhit (1);\n\ |
|
589 @end example\n\ |
|
590 \n\ |
|
591 @noindent\n\ |
|
592 identical to the above example, but don't wait for a keypress,\n\ |
|
593 returning the empty string if no key is available.\n\ |
3372
|
594 @end deftypefn") |
529
|
595 { |
4233
|
596 octave_value retval; |
529
|
597 |
5775
|
598 // FIXME -- add timeout and default value args? |
529
|
599 |
3676
|
600 if (interactive || forced_interactive) |
529
|
601 { |
4067
|
602 int c = octave_kbhit (args.length () == 0); |
3657
|
603 |
3658
|
604 if (c == -1) |
|
605 c = 0; |
3657
|
606 |
529
|
607 char *s = new char [2]; |
|
608 s[0] = c; |
|
609 s[1] = '\0'; |
|
610 retval = s; |
|
611 } |
|
612 |
|
613 return retval; |
|
614 } |
|
615 |
1957
|
616 DEFUN (pause, args, , |
3301
|
617 "-*- texinfo -*-\n\ |
|
618 @deftypefn {Built-in Function} {} pause (@var{seconds})\n\ |
|
619 Suspend the execution of the program. If invoked without any arguments,\n\ |
|
620 Octave waits until you type a character. With a numeric argument, it\n\ |
|
621 pauses for the given number of seconds. For example, the following\n\ |
|
622 statement prints a message and then waits 5 seconds before clearing the\n\ |
|
623 screen.\n\ |
|
624 \n\ |
|
625 @example\n\ |
|
626 @group\n\ |
|
627 fprintf (stderr, \"wait please...\n\");\n\ |
|
628 pause (5);\n\ |
|
629 clc;\n\ |
|
630 @end group\n\ |
|
631 @end example\n\ |
|
632 @end deftypefn") |
529
|
633 { |
2086
|
634 octave_value_list retval; |
529
|
635 |
|
636 int nargin = args.length (); |
|
637 |
712
|
638 if (! (nargin == 0 || nargin == 1)) |
529
|
639 { |
5823
|
640 print_usage (); |
529
|
641 return retval; |
|
642 } |
|
643 |
1579
|
644 if (nargin == 1) |
529
|
645 { |
1579
|
646 double dval = args(0).double_value (); |
636
|
647 |
1579
|
648 if (! error_state) |
|
649 { |
|
650 if (xisnan (dval)) |
|
651 warning ("pause: NaN is an invalid delay"); |
2630
|
652 else if (xisinf (dval)) |
3234
|
653 { |
|
654 flush_octave_stdout (); |
4067
|
655 octave_kbhit (); |
3234
|
656 } |
1579
|
657 else |
4086
|
658 octave_sleep (dval); |
529
|
659 } |
|
660 } |
1579
|
661 else |
3234
|
662 { |
|
663 flush_octave_stdout (); |
4067
|
664 octave_kbhit (); |
3234
|
665 } |
2630
|
666 |
|
667 return retval; |
|
668 } |
|
669 |
|
670 DEFUN (sleep, args, , |
3301
|
671 "-*- texinfo -*-\n\ |
|
672 @deftypefn {Built-in Function} {} sleep (@var{seconds})\n\ |
|
673 Suspend the execution of the program for the given number of seconds.\n\ |
|
674 @end deftypefn") |
2630
|
675 { |
|
676 octave_value_list retval; |
|
677 |
|
678 if (args.length () == 1) |
1579
|
679 { |
2630
|
680 double dval = args(0).double_value (); |
|
681 |
|
682 if (! error_state) |
|
683 { |
|
684 if (xisnan (dval)) |
|
685 warning ("sleep: NaN is an invalid delay"); |
|
686 else |
4086
|
687 octave_sleep (dval); |
2630
|
688 } |
1579
|
689 } |
2630
|
690 else |
5823
|
691 print_usage (); |
2630
|
692 |
|
693 return retval; |
|
694 } |
|
695 |
|
696 DEFUN (usleep, args, , |
3301
|
697 "-*- texinfo -*-\n\ |
|
698 @deftypefn {Built-in Function} {} usleep (@var{microseconds})\n\ |
|
699 Suspend the execution of the program for the given number of\n\ |
|
700 microseconds. On systems where it is not possible to sleep for periods\n\ |
|
701 of time less than one second, @code{usleep} will pause the execution for\n\ |
|
702 @code{round (@var{microseconds} / 1e6)} seconds.\n\ |
|
703 @end deftypefn") |
2630
|
704 { |
|
705 octave_value_list retval; |
|
706 |
|
707 if (args.length () == 1) |
|
708 { |
|
709 double dval = args(0).double_value (); |
|
710 |
|
711 if (! error_state) |
|
712 { |
|
713 if (xisnan (dval)) |
|
714 warning ("usleep: NaN is an invalid delay"); |
|
715 else |
|
716 { |
|
717 int delay = NINT (dval); |
2631
|
718 |
2630
|
719 if (delay > 0) |
3308
|
720 octave_usleep (delay); |
2630
|
721 } |
|
722 } |
|
723 } |
|
724 else |
5823
|
725 print_usage (); |
529
|
726 |
|
727 return retval; |
|
728 } |
|
729 |
5775
|
730 // FIXME -- maybe this should only return 1 if IEEE floating |
862
|
731 // point functions really work. |
|
732 |
1957
|
733 DEFUN (isieee, , , |
3301
|
734 "-*- texinfo -*-\n\ |
|
735 @deftypefn {Built-in Function} {} isieee ()\n\ |
|
736 Return 1 if your computer claims to conform to the IEEE standard for\n\ |
|
737 floating point calculations.\n\ |
|
738 @end deftypefn") |
862
|
739 { |
4600
|
740 oct_mach_info::float_format flt_fmt = oct_mach_info::native_float_format (); |
2317
|
741 |
4574
|
742 return octave_value (flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian |
|
743 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian); |
862
|
744 } |
|
745 |
4600
|
746 DEFUN (native_float_format, , , |
|
747 "-*- texinfo -*-\n\ |
|
748 @deftypefn {Built-in Function} {} native_float_format ()\n\ |
|
749 Return the native floating point format as a string\n\ |
|
750 @end deftypefn") |
|
751 { |
|
752 oct_mach_info::float_format flt_fmt = oct_mach_info::native_float_format (); |
|
753 |
|
754 return octave_value (oct_mach_info::float_format_as_string (flt_fmt)); |
|
755 } |
|
756 |
1957
|
757 DEFUN (tilde_expand, args, , |
3301
|
758 "-*- texinfo -*-\n\ |
|
759 @deftypefn {Built-in Function} {} tilde_expand (@var{string})\n\ |
|
760 Performs tilde expansion on @var{string}. If @var{string} begins with a\n\ |
|
761 tilde character, (@samp{~}), all of the characters preceding the first\n\ |
|
762 slash (or all characters, if there is no slash) are treated as a\n\ |
|
763 possible user name, and the tilde and the following characters up to the\n\ |
|
764 slash are replaced by the home directory of the named user. If the\n\ |
|
765 tilde is followed immediately by a slash, the tilde is replaced by the\n\ |
|
766 home directory of the user running Octave. For example,\n\ |
|
767 \n\ |
|
768 @example\n\ |
|
769 @group\n\ |
|
770 tilde_expand (\"~joeuser/bin\")\n\ |
|
771 @result{} \"/home/joeuser/bin\"\n\ |
|
772 tilde_expand (\"~/bin\")\n\ |
|
773 @result{} \"/home/jwe/bin\"\n\ |
|
774 @end group\n\ |
|
775 @end example\n\ |
|
776 @end deftypefn") |
1750
|
777 { |
4233
|
778 octave_value retval; |
1750
|
779 |
|
780 int nargin = args.length (); |
|
781 |
|
782 if (nargin == 1) |
6116
|
783 { |
|
784 octave_value arg = args(0); |
|
785 |
|
786 string_vector sv = arg.all_strings (); |
|
787 |
|
788 if (! error_state) |
|
789 { |
|
790 sv = file_ops::tilde_expand (sv); |
|
791 |
|
792 if (arg.is_cellstr ()) |
|
793 retval = Cell (arg.dims (), sv); |
|
794 else |
|
795 retval = sv; |
|
796 } |
|
797 else |
|
798 error ("tilde_expand: expecting argument to be char or cellstr object"); |
|
799 } |
1750
|
800 else |
5823
|
801 print_usage (); |
1750
|
802 |
|
803 return retval; |
|
804 } |
|
805 |
2552
|
806 #if defined (__EMX__) && defined (OS2) |
|
807 |
4208
|
808 DEFCMD (extproc, , , |
2926
|
809 "extproc: ignored by Octave") |
2552
|
810 { |
|
811 return octave_value_list (); |
|
812 } |
|
813 |
|
814 DEFALIAS (EXTPROC, extproc); |
|
815 |
|
816 #endif |
|
817 |
529
|
818 /* |
1
|
819 ;;; Local Variables: *** |
|
820 ;;; mode: C++ *** |
|
821 ;;; End: *** |
|
822 */ |