1
|
1 // sysdep.cc -*- C++ -*- |
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1993, 1994, 1995 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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
21 |
|
22 */ |
|
23 |
661
|
24 /* |
|
25 |
|
26 The function gethostname was adapted from a similar function from GNU |
|
27 Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free |
|
28 Software Foundation, Inc. |
|
29 |
|
30 */ |
|
31 |
240
|
32 #ifdef HAVE_CONFIG_H |
1192
|
33 #include <config.h> |
1
|
34 #endif |
|
35 |
1346
|
36 #include <cfloat> |
1343
|
37 #include <cstddef> |
1346
|
38 #include <cstdio> |
1343
|
39 #include <cstdlib> |
|
40 #include <cstring> |
|
41 |
1728
|
42 #include <string> |
|
43 |
1742
|
44 #include <iostream.h> |
|
45 |
1350
|
46 #ifdef HAVE_UNISTD_H |
529
|
47 #include <sys/types.h> |
|
48 #include <unistd.h> |
|
49 #endif |
1
|
50 |
1430
|
51 #if defined (HAVE_TERMIOS_H) |
|
52 #include <termios.h> |
|
53 #elif defined (HAVE_TERMIO_H) |
|
54 #include <termio.h> |
|
55 #elif defined (HAVE_SGTTY_H) |
|
56 #include <sgtty.h> |
|
57 #else |
|
58 LOSE! LOSE! |
|
59 #endif |
|
60 |
1463
|
61 #if defined (HAVE_FLOATINGPOINT_H) |
|
62 #include <floatingpoint.h> |
|
63 #endif |
|
64 |
|
65 #if !defined (HAVE_GETHOSTNAME) && defined (HAVE_SYS_UTSNAME_H) |
|
66 #include <sys/utsname.h> |
|
67 #endif |
|
68 |
|
69 #include <readline/readline.h> |
1750
|
70 #include <readline/tilde.h> |
1463
|
71 |
|
72 extern char *term_clrpag; |
|
73 extern "C" void _rl_output_character_function (); |
|
74 |
1769
|
75 #include "oct-math.h" |
|
76 |
1352
|
77 #include "defun.h" |
|
78 #include "error.h" |
1847
|
79 #include "f77-fcn.h" |
542
|
80 #include "help.h" |
529
|
81 #include "input.h" |
1742
|
82 #include "mappers.h" |
1755
|
83 #include "oct-obj.h" |
|
84 #include "pathlen.h" |
|
85 #include "pt-const.h" |
1352
|
86 #include "sysdep.h" |
1755
|
87 #include "toplev.h" |
529
|
88 #include "utils.h" |
|
89 |
1463
|
90 extern "C" double F77_FCN (d1mach, D1MACH) (const int&); |
529
|
91 |
|
92 #ifndef STDIN_FILENO |
|
93 #define STDIN_FILENO 1 |
|
94 #endif |
444
|
95 |
|
96 // Octave's idea of infinity. |
|
97 double octave_Inf; |
|
98 |
|
99 // Octave's idea of not a number. |
|
100 double octave_NaN; |
1
|
101 |
1226
|
102 // The floating point format on this system. |
|
103 floating_point_format native_float_format = OCTAVE_UNKNOWN_FLT_FMT; |
|
104 |
1415
|
105 // Nonzero if the machine we are running on is big-endian. |
|
106 int octave_words_big_endian; |
|
107 |
1
|
108 #ifdef NeXT |
|
109 extern "C" |
|
110 { |
|
111 typedef void (*_cplus_fcn_int) (int); |
|
112 extern void (*malloc_error (_cplus_fcn_int)) (int); |
|
113 } |
|
114 |
|
115 static void |
|
116 malloc_handler (int code) |
|
117 { |
|
118 if (code == 5) |
217
|
119 warning ("hopefully recoverable malloc error: freeing wild pointer"); |
1
|
120 else |
|
121 { |
|
122 panic ("probably irrecoverable malloc error: code %d", code); |
|
123 } |
|
124 } |
|
125 |
|
126 static void |
|
127 NeXT_init (void) |
|
128 { |
|
129 malloc_error (malloc_handler); |
|
130 } |
|
131 #endif |
|
132 |
1226
|
133 union equiv |
|
134 { |
|
135 double d; |
|
136 int i[2]; |
|
137 }; |
|
138 |
|
139 struct float_params |
|
140 { |
|
141 floating_point_format fp_fmt; |
|
142 equiv fp_par[4]; |
|
143 }; |
|
144 |
|
145 #define INIT_FLT_PAR(fp, fmt, sm1, sm2, lrg1, lrg2, rt1, rt2, dv1, dv2) \ |
|
146 do \ |
|
147 { \ |
|
148 fp.fp_fmt = (fmt); \ |
|
149 fp.fp_par[0].i[0] = (sm1); fp.fp_par[0].i[1] = (sm2); \ |
|
150 fp.fp_par[1].i[0] = (lrg1); fp.fp_par[1].i[1] = (lrg2); \ |
|
151 fp.fp_par[2].i[0] = (rt1); fp.fp_par[2].i[1] = (rt2); \ |
|
152 fp.fp_par[3].i[0] = (dv1); fp.fp_par[3].i[1] = (dv2); \ |
|
153 } \ |
|
154 while (0) |
|
155 |
|
156 static int |
|
157 equiv_compare (const equiv *std, const equiv *v, int len) |
|
158 { |
|
159 int i; |
|
160 for (i = 0; i < len; i++) |
|
161 if (v[i].i[0] != std[i].i[0] || v[i].i[1] != std[i].i[1]) |
|
162 return 0; |
|
163 return 1; |
|
164 } |
|
165 |
444
|
166 static void |
|
167 octave_ieee_init (void) |
|
168 { |
|
169 #if defined (HAVE_ISINF) || defined (HAVE_FINITE) |
|
170 |
|
171 // Some version of gcc on some old version of Linux used to crash when |
|
172 // trying to make Inf and NaN. |
|
173 |
|
174 #if defined (HAVE_INFINITY) |
470
|
175 octave_Inf = (double) infinity (); |
967
|
176 #elif defined (linux) |
444
|
177 octave_Inf = HUGE_VAL; |
967
|
178 #elif defined (__alpha__) |
529
|
179 extern unsigned int DINFINITY[2]; |
|
180 octave_Inf = (*((double *) (DINFINITY))); |
|
181 #else |
444
|
182 double tmp = 1e+10; |
|
183 octave_Inf = tmp; |
|
184 for (;;) |
|
185 { |
|
186 octave_Inf *= 1e+10; |
|
187 if (octave_Inf == tmp) |
|
188 break; |
|
189 tmp = octave_Inf; |
|
190 } |
|
191 #endif |
529
|
192 |
1384
|
193 #endif |
|
194 |
|
195 #if defined (HAVE_ISNAN) |
|
196 |
444
|
197 #if defined (HAVE_QUIET_NAN) |
470
|
198 octave_NaN = (double) quiet_nan (); |
967
|
199 #elif defined (linux) |
444
|
200 octave_NaN = NAN; |
967
|
201 #elif defined (__alpha__) |
529
|
202 extern unsigned int DQNAN[2]; |
|
203 octave_NaN = (*((double *) (DQNAN))); |
|
204 #else |
444
|
205 octave_NaN = octave_Inf / octave_Inf; |
|
206 #endif |
|
207 |
|
208 #endif |
1226
|
209 |
|
210 float_params fp[5]; |
|
211 |
|
212 INIT_FLT_PAR (fp[0], OCTAVE_IEEE_BIG, |
|
213 1048576, 0, |
|
214 2146435071, -1, |
|
215 1017118720, 0, |
|
216 1018167296, 0); |
|
217 |
|
218 INIT_FLT_PAR (fp[1], OCTAVE_IEEE_LITTLE, |
|
219 0, 1048576, |
|
220 -1, 2146435071, |
|
221 0, 1017118720, |
|
222 0, 1018167296); |
|
223 |
|
224 INIT_FLT_PAR (fp[2], OCTAVE_VAX_D, |
|
225 128, 0, |
|
226 -32769, -1, |
|
227 9344, 0, |
|
228 9344, 0); |
|
229 |
|
230 INIT_FLT_PAR (fp[3], OCTAVE_VAX_G, |
|
231 16, 0, |
|
232 -32769, -1, |
|
233 15552, 0, |
|
234 15552, 0); |
|
235 |
|
236 INIT_FLT_PAR (fp[4], OCTAVE_UNKNOWN_FLT_FMT, |
|
237 0, 0, |
|
238 0, 0, |
|
239 0, 0, |
|
240 0, 0); |
|
241 |
|
242 equiv mach_fp_par[4]; |
|
243 |
1255
|
244 mach_fp_par[0].d = F77_FCN (d1mach, D1MACH) (1); |
|
245 mach_fp_par[1].d = F77_FCN (d1mach, D1MACH) (2); |
|
246 mach_fp_par[2].d = F77_FCN (d1mach, D1MACH) (3); |
|
247 mach_fp_par[3].d = F77_FCN (d1mach, D1MACH) (4); |
1226
|
248 |
|
249 int i = 0; |
|
250 do |
|
251 { |
|
252 if (equiv_compare (fp[i].fp_par, mach_fp_par, 4)) |
|
253 { |
|
254 native_float_format = fp[i].fp_fmt; |
|
255 break; |
|
256 } |
|
257 } |
|
258 while (fp[++i].fp_fmt != OCTAVE_UNKNOWN_FLT_FMT); |
|
259 |
|
260 if (native_float_format == OCTAVE_UNKNOWN_FLT_FMT) |
|
261 panic ("unrecognized floating point format!"); |
444
|
262 } |
|
263 |
1415
|
264 static void |
|
265 ten_little_endians (void) |
|
266 { |
|
267 // Are we little or big endian? From Harbison & Steele. |
|
268 |
|
269 union |
|
270 { |
|
271 long l; |
|
272 char c[sizeof (long)]; |
|
273 } u; |
|
274 |
|
275 u.l = 1; |
|
276 |
|
277 octave_words_big_endian = (u.c[sizeof (long) - 1] == 1); |
|
278 } |
|
279 |
505
|
280 #if defined (EXCEPTION_IN_MATH) |
|
281 extern "C" |
|
282 int |
|
283 matherr (struct exception *x) |
|
284 { |
1358
|
285 // Possibly print our own message someday. Should probably be |
|
286 // user-switchable. |
505
|
287 |
|
288 switch (x->type) |
|
289 { |
|
290 case DOMAIN: |
|
291 case SING: |
|
292 case OVERFLOW: |
|
293 case UNDERFLOW: |
|
294 case TLOSS: |
|
295 case PLOSS: |
|
296 default: |
|
297 break; |
|
298 } |
|
299 |
1358
|
300 // But don't print the system message. |
505
|
301 |
|
302 return 1; |
|
303 } |
1466
|
304 #endif |
505
|
305 |
1
|
306 void |
|
307 sysdep_init (void) |
|
308 { |
959
|
309 #if defined (__386BSD__) || defined (__FreeBSD__) |
998
|
310 #if defined (HAVE_FLOATINGPOINT_H) |
1358
|
311 // Disable trapping on common exceptions. |
401
|
312 fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP)); |
|
313 #endif |
959
|
314 #endif |
401
|
315 |
1
|
316 #ifdef NeXT |
|
317 NeXT_init (); |
|
318 #endif |
444
|
319 |
|
320 octave_ieee_init (); |
1415
|
321 |
|
322 ten_little_endians (); |
1
|
323 } |
|
324 |
767
|
325 // Set terminal in raw mode. From less-177. |
|
326 // |
|
327 // Change terminal to "raw mode", or restore to "normal" mode. |
|
328 // "Raw mode" means |
|
329 // 1. An outstanding read will complete on receipt of a single keystroke. |
|
330 // 2. Input is not echoed. |
|
331 // 3. On output, \n is mapped to \r\n. |
|
332 // 4. \t is NOT expanded into spaces. |
|
333 // 5. Signal-causing characters such as ctrl-C (interrupt), |
|
334 // etc. are NOT disabled. |
|
335 // It doesn't matter whether an input \n is mapped to \r, or vice versa. |
|
336 |
529
|
337 void |
|
338 raw_mode (int on) |
|
339 { |
|
340 static int curr_on = 0; |
|
341 |
|
342 int tty_fd = STDIN_FILENO; |
|
343 if (! isatty (tty_fd)) |
|
344 { |
|
345 if (interactive) |
|
346 error ("stdin is not a tty!"); |
|
347 return; |
|
348 } |
|
349 |
|
350 if (on == curr_on) |
|
351 return; |
|
352 |
|
353 #if defined (HAVE_TERMIOS_H) |
|
354 { |
|
355 struct termios s; |
|
356 static struct termios save_term; |
|
357 |
|
358 if (on) |
|
359 { |
1358
|
360 // Get terminal modes. |
529
|
361 |
|
362 tcgetattr (tty_fd, &s); |
|
363 |
1358
|
364 // Save modes and set certain variables dependent on modes. |
529
|
365 |
|
366 save_term = s; |
|
367 // ospeed = s.c_cflag & CBAUD; |
|
368 // erase_char = s.c_cc[VERASE]; |
|
369 // kill_char = s.c_cc[VKILL]; |
|
370 |
1358
|
371 // Set the modes to the way we want them. |
529
|
372 |
|
373 s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); |
|
374 s.c_oflag |= (OPOST|ONLCR); |
|
375 #if defined (OCRNL) |
|
376 s.c_oflag &= ~(OCRNL); |
|
377 #endif |
|
378 #if defined (ONOCR) |
|
379 s.c_oflag &= ~(ONOCR); |
|
380 #endif |
|
381 #if defined (ONLRET) |
|
382 s.c_oflag &= ~(ONLRET); |
|
383 #endif |
|
384 s.c_cc[VMIN] = 1; |
|
385 s.c_cc[VTIME] = 0; |
|
386 } |
|
387 else |
|
388 { |
1358
|
389 // Restore saved modes. |
|
390 |
529
|
391 s = save_term; |
|
392 } |
|
393 tcsetattr (tty_fd, TCSAFLUSH, &s); |
|
394 } |
|
395 #elif defined (HAVE_TERMIO_H) |
|
396 { |
|
397 struct termio s; |
|
398 static struct termio save_term; |
|
399 |
|
400 if (on) |
|
401 { |
1358
|
402 // Get terminal modes. |
529
|
403 |
|
404 ioctl (tty_fd, TCGETA, &s); |
|
405 |
1358
|
406 // Save modes and set certain variables dependent on modes. |
529
|
407 |
|
408 save_term = s; |
|
409 // ospeed = s.c_cflag & CBAUD; |
|
410 // erase_char = s.c_cc[VERASE]; |
|
411 // kill_char = s.c_cc[VKILL]; |
|
412 |
1358
|
413 // Set the modes to the way we want them. |
529
|
414 |
|
415 s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); |
|
416 s.c_oflag |= (OPOST|ONLCR); |
|
417 #if defined (OCRNL) |
|
418 s.c_oflag &= ~(OCRNL); |
|
419 #endif |
|
420 #if defined (ONOCR) |
|
421 s.c_oflag &= ~(ONOCR); |
|
422 #endif |
|
423 #if defined (ONLRET) |
|
424 s.c_oflag &= ~(ONLRET); |
|
425 #endif |
|
426 s.c_cc[VMIN] = 1; |
|
427 s.c_cc[VTIME] = 0; |
|
428 } |
|
429 else |
|
430 { |
1358
|
431 // Restore saved modes. |
|
432 |
529
|
433 s = save_term; |
|
434 } |
|
435 ioctl (tty_fd, TCSETAW, &s); |
|
436 } |
|
437 #elif defined (HAVE_SGTTY_H) |
|
438 { |
|
439 struct sgttyb s; |
|
440 static struct sgttyb save_term; |
|
441 |
|
442 if (on) |
|
443 { |
1358
|
444 // Get terminal modes. |
529
|
445 |
|
446 ioctl (tty_fd, TIOCGETP, &s); |
|
447 |
1358
|
448 // Save modes and set certain variables dependent on modes. |
529
|
449 |
|
450 save_term = s; |
|
451 // ospeed = s.sg_ospeed; |
|
452 // erase_char = s.sg_erase; |
|
453 // kill_char = s.sg_kill; |
|
454 |
1358
|
455 // Set the modes to the way we want them. |
529
|
456 |
|
457 s.sg_flags |= CBREAK; |
|
458 s.sg_flags &= ~(ECHO); |
|
459 } |
|
460 else |
|
461 { |
1358
|
462 // Restore saved modes. |
|
463 |
529
|
464 s = save_term; |
|
465 } |
|
466 ioctl (tty_fd, TIOCSETN, &s); |
|
467 } |
|
468 #else |
|
469 LOSE! LOSE! |
|
470 #endif |
|
471 |
|
472 curr_on = on; |
|
473 } |
|
474 |
767
|
475 // Read one character from the terminal. |
|
476 |
529
|
477 int |
|
478 kbhit (void) |
|
479 { |
|
480 int c; |
|
481 raw_mode (1); |
|
482 c = cin.get (); |
|
483 raw_mode (0); |
|
484 return c; |
|
485 } |
|
486 |
1755
|
487 string |
|
488 octave_getcwd (void) |
1111
|
489 { |
1755
|
490 string retval; |
|
491 char buf[MAXPATHLEN]; |
|
492 |
1113
|
493 #if defined (__EMX__) |
1755
|
494 char *tmp = _getcwd2 (buf, MAXPATHLEN); |
1111
|
495 #else |
1755
|
496 char *tmp = getcwd (buf, MAXPATHLEN); |
1111
|
497 #endif |
1755
|
498 |
|
499 if (tmp) |
|
500 retval = tmp; |
|
501 |
|
502 return retval; |
1111
|
503 } |
|
504 |
|
505 int |
1755
|
506 octave_chdir (const string& path) |
1111
|
507 { |
1113
|
508 #if defined (__EMX__) |
1111
|
509 int retval = -1; |
|
510 |
1755
|
511 if (path.length () == 2 && path[1] == ':') |
1111
|
512 { |
1755
|
513 char *upper_case_dir_name = strupr (path.c_str ()); |
1111
|
514 _chdrive (upper_case_dir_name[0]); |
|
515 if (_getdrive () == upper_case_dir_name[0]) |
|
516 retval = _chdir2 ("/"); |
|
517 } |
|
518 else |
1755
|
519 retval = _chdir2 (path.c_str ()); |
1111
|
520 |
|
521 return retval; |
|
522 #else |
1755
|
523 return chdir (path.c_str ()); |
1111
|
524 #endif |
|
525 } |
|
526 |
1488
|
527 DEFUN ("clc", Fclc, Sclc, 00, |
529
|
528 "clc (): clear screen") |
|
529 { |
|
530 Octave_object retval; |
|
531 |
|
532 rl_beg_of_line (); |
|
533 rl_kill_line (1); |
|
534 |
|
535 #if ! defined (_GO32_) |
|
536 if (term_clrpag) |
|
537 tputs (term_clrpag, 1, _rl_output_character_function); |
|
538 else |
|
539 crlf (); |
|
540 #else |
|
541 crlf (); |
|
542 #endif |
|
543 |
|
544 fflush (rl_outstream); |
|
545 |
|
546 return retval; |
|
547 } |
|
548 |
549
|
549 DEFALIAS (home, clc); |
|
550 |
1488
|
551 DEFUN ("getenv", Fgetenv, Sgetenv, 10, |
529
|
552 "getenv (STRING): get environment variable values") |
|
553 { |
|
554 Octave_object retval; |
|
555 |
|
556 int nargin = args.length (); |
|
557 |
712
|
558 if (nargin == 1) |
529
|
559 { |
1728
|
560 string tstr = args(0).string_value (); |
|
561 const char *name = tstr.c_str (); |
636
|
562 |
|
563 if (! error_state) |
|
564 { |
|
565 char *value = getenv (name); |
|
566 if (value) |
|
567 retval = value; |
|
568 else |
|
569 retval = ""; |
|
570 } |
529
|
571 } |
|
572 else |
|
573 print_usage ("getenv"); |
|
574 |
|
575 return retval; |
|
576 } |
|
577 |
1706
|
578 DEFUN ("putenv", Fputenv, Sputenv, 10, |
|
579 "putenv (VAR, VALUE): define environment variable VAR=VALUE") |
|
580 { |
|
581 Octave_object retval; |
|
582 |
|
583 int nargin = args.length (); |
|
584 |
|
585 if (nargin == 2) |
|
586 { |
1755
|
587 string var = args(0).string_value (); |
1706
|
588 |
|
589 if (! error_state) |
|
590 { |
1755
|
591 string val = args(1).string_value (); |
1706
|
592 |
|
593 if (! error_state) |
1755
|
594 oct_putenv (var.c_str (), val.c_str ()); |
1706
|
595 else |
|
596 error ("putenv: second argument should be a string"); |
|
597 } |
|
598 else |
|
599 error ("putenv: first argument should be a string"); |
|
600 } |
|
601 else |
|
602 print_usage ("putenv"); |
|
603 |
|
604 return retval; |
|
605 } |
|
606 |
1488
|
607 DEFUN ("kbhit", Fkbhit, Skbhit, 00, |
529
|
608 "kbhit: get a single character from the terminal") |
|
609 { |
|
610 Octave_object retval; |
|
611 |
1358
|
612 // XXX FIXME XXX -- add timeout and default value args? |
529
|
613 |
|
614 if (interactive) |
|
615 { |
|
616 int c = kbhit (); |
|
617 char *s = new char [2]; |
|
618 s[0] = c; |
|
619 s[1] = '\0'; |
|
620 retval = s; |
|
621 } |
|
622 |
|
623 return retval; |
|
624 } |
|
625 |
1488
|
626 DEFUN ("pause", Fpause, Spause, 10, |
529
|
627 "pause (seconds): suspend program execution") |
|
628 { |
|
629 Octave_object retval; |
|
630 |
|
631 int nargin = args.length (); |
|
632 |
712
|
633 if (! (nargin == 0 || nargin == 1)) |
529
|
634 { |
|
635 print_usage ("pause"); |
|
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"); |
|
647 else |
|
648 { |
|
649 int delay = NINT (dval); |
|
650 if (delay > 0) |
|
651 sleep (delay); |
|
652 } |
529
|
653 } |
|
654 } |
1579
|
655 else |
|
656 { |
|
657 if (kbhit () == EOF) |
|
658 clean_up_and_exit (0); |
|
659 } |
529
|
660 |
|
661 return retval; |
|
662 } |
|
663 |
862
|
664 // XXX FIXME XXX -- maybe this should only return 1 if IEEE floating |
|
665 // point functions really work. |
|
666 |
1488
|
667 DEFUN ("isieee", Fisieee, Sisieee, 00, |
862
|
668 "isieee (): return 1 if host uses IEEE floating point") |
|
669 { |
1226
|
670 return (double) (native_float_format == OCTAVE_IEEE_LITTLE |
|
671 || native_float_format == OCTAVE_IEEE_BIG); |
862
|
672 } |
|
673 |
529
|
674 #if !defined (HAVE_GETHOSTNAME) && defined (HAVE_SYS_UTSNAME_H) |
|
675 int |
|
676 gethostname (char *name, int namelen) |
|
677 { |
|
678 int i; |
|
679 struct utsname ut; |
|
680 |
|
681 --namelen; |
|
682 |
|
683 uname (&ut); |
|
684 i = strlen (ut.nodename) + 1; |
|
685 strncpy (name, ut.nodename, i < namelen ? i : namelen); |
|
686 name[namelen] = '\0'; |
|
687 |
|
688 return 0; |
|
689 } |
|
690 #endif |
|
691 |
1750
|
692 // The check for error state allows us to do this: |
|
693 // |
|
694 // string foo = oct_tilde_expand (args(0).string_value ()); |
|
695 // |
|
696 // without having to use a temporary and check error_state before |
|
697 // calling oct_tilde_expand. |
|
698 |
|
699 string |
|
700 oct_tilde_expand (const string& name) |
|
701 { |
|
702 string retval; |
|
703 |
|
704 if (! error_state) |
|
705 { |
|
706 char *tmp = tilde_expand (name.c_str ()); |
|
707 retval = tmp; |
|
708 delete [] tmp; |
|
709 } |
|
710 |
|
711 return retval; |
|
712 } |
|
713 |
|
714 DEFUN ("tilde_expand", Ftilde_expand, Stilde_expand, 10, |
|
715 "tilde_expand (STRING): perform tilde expansion on STRING") |
|
716 { |
|
717 Octave_object retval; |
|
718 |
|
719 int nargin = args.length (); |
|
720 |
|
721 if (nargin == 1) |
|
722 retval = oct_tilde_expand (args(0).string_value ()); |
|
723 else |
|
724 print_usage ("tilde_expand"); |
|
725 |
|
726 return retval; |
|
727 } |
|
728 |
529
|
729 /* |
1
|
730 ;;; Local Variables: *** |
|
731 ;;; mode: C++ *** |
|
732 ;;; page-delimiter: "^/\\*" *** |
|
733 ;;; End: *** |
|
734 */ |