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