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