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