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