Mercurial > hg > octave-nkf
annotate libinterp/corefcn/sysdep.cc @ 20382:4f45eaf83908 stable
doc: Update more docstrings to have one sentence summary as first line.
Reviewed libinterp/corefcn directory.
* libinterp/corefcn/__ilu__.cc, libinterp/corefcn/balance.cc,
libinterp/corefcn/besselj.cc, libinterp/corefcn/betainc.cc,
libinterp/corefcn/bitfcns.cc, libinterp/corefcn/bsxfun.cc,
libinterp/corefcn/cellfun.cc, libinterp/corefcn/colloc.cc,
libinterp/corefcn/conv2.cc, libinterp/corefcn/data.cc,
libinterp/corefcn/debug.cc, libinterp/corefcn/defaults.cc,
libinterp/corefcn/det.cc, libinterp/corefcn/dirfns.cc,
libinterp/corefcn/dlmread.cc, libinterp/corefcn/dot.cc,
libinterp/corefcn/eig.cc, libinterp/corefcn/error.cc,
libinterp/corefcn/fft2.cc, libinterp/corefcn/fftn.cc,
libinterp/corefcn/file-io.cc, libinterp/corefcn/filter.cc,
libinterp/corefcn/find.cc, libinterp/corefcn/gammainc.cc,
libinterp/corefcn/gcd.cc, libinterp/corefcn/getgrent.cc,
libinterp/corefcn/getpwent.cc, libinterp/corefcn/getrusage.cc,
libinterp/corefcn/graphics.cc, libinterp/corefcn/help.cc,
libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc,
libinterp/corefcn/inv.cc, libinterp/corefcn/kron.cc,
libinterp/corefcn/load-path.cc, libinterp/corefcn/load-save.cc,
libinterp/corefcn/lookup.cc, libinterp/corefcn/ls-oct-ascii.cc,
libinterp/corefcn/lsode.cc, libinterp/corefcn/lu.cc,
libinterp/corefcn/luinc.cc, libinterp/corefcn/mappers.cc,
libinterp/corefcn/matrix_type.cc, libinterp/corefcn/max.cc,
libinterp/corefcn/md5sum.cc, libinterp/corefcn/mgorth.cc,
libinterp/corefcn/nproc.cc, libinterp/corefcn/oct-hist.cc,
libinterp/corefcn/ordschur.cc, libinterp/corefcn/pager.cc,
libinterp/corefcn/pinv.cc, libinterp/corefcn/pr-output.cc,
libinterp/corefcn/pt-jit.cc, libinterp/corefcn/quad.cc,
libinterp/corefcn/quadcc.cc, libinterp/corefcn/qz.cc,
libinterp/corefcn/rand.cc, libinterp/corefcn/rcond.cc,
libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc,
libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sparse.cc,
libinterp/corefcn/spparms.cc, libinterp/corefcn/str2double.cc,
libinterp/corefcn/strfind.cc, libinterp/corefcn/strfns.cc,
libinterp/corefcn/sub2ind.cc, libinterp/corefcn/svd.cc,
libinterp/corefcn/symtab.cc, libinterp/corefcn/syscalls.cc,
libinterp/corefcn/sysdep.cc, libinterp/corefcn/time.cc,
libinterp/corefcn/toplev.cc, libinterp/corefcn/tril.cc,
libinterp/corefcn/tsearch.cc, libinterp/corefcn/typecast.cc,
libinterp/corefcn/urlwrite.cc, libinterp/corefcn/utils.cc,
libinterp/corefcn/variables.cc, scripts/polynomial/spline.m:
Update more docstrings to have one sentence summary as first line.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 09 May 2015 17:19:30 -0700 |
parents | ab7582167810 |
children | aa36fb998a4d |
rev | line source |
---|---|
1 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19737
diff
changeset
|
3 Copyright (C) 1993-2015 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1 | 20 |
21 */ | |
22 | |
240 | 23 #ifdef HAVE_CONFIG_H |
1192 | 24 #include <config.h> |
1 | 25 #endif |
26 | |
1346 | 27 #include <cfloat> |
1343 | 28 #include <cstddef> |
1346 | 29 #include <cstdio> |
1343 | 30 #include <cstdlib> |
31 #include <cstring> | |
32 | |
3503 | 33 #include <iostream> |
1728 | 34 #include <string> |
35 | |
529 | 36 #include <sys/types.h> |
37 #include <unistd.h> | |
1 | 38 |
1430 | 39 #if defined (HAVE_TERMIOS_H) |
40 #include <termios.h> | |
41 #elif defined (HAVE_TERMIO_H) | |
42 #include <termio.h> | |
43 #elif defined (HAVE_SGTTY_H) | |
44 #include <sgtty.h> | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
45 #endif |
4067 | 46 |
47 #if defined (HAVE_CONIO_H) | |
48 #include <conio.h> | |
1430 | 49 #endif |
50 | |
3248 | 51 #if defined (HAVE_SYS_IOCTL_H) |
52 #include <sys/ioctl.h> | |
53 #endif | |
54 | |
1463 | 55 #if defined (HAVE_FLOATINGPOINT_H) |
56 #include <floatingpoint.h> | |
57 #endif | |
58 | |
2508 | 59 #if defined (HAVE_IEEEFP_H) |
60 #include <ieeefp.h> | |
61 #endif | |
62 | |
2926 | 63 #include "cmd-edit.h" |
64 #include "file-ops.h" | |
2893 | 65 #include "lo-mappers.h" |
7231 | 66 #include "lo-math.h" |
2317 | 67 #include "mach-info.h" |
2926 | 68 #include "oct-env.h" |
5451 | 69 #include "quit.h" |
1769 | 70 |
6208 | 71 #include "Cell.h" |
15423
53d073233fa4
call more built-in functions directly
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
72 #include "builtins.h" |
1352 | 73 #include "defun.h" |
17851
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
74 #include "display.h" |
1352 | 75 #include "error.h" |
529 | 76 #include "input.h" |
1755 | 77 #include "oct-obj.h" |
2370 | 78 #include "ov.h" |
3234 | 79 #include "pager.h" |
6419 | 80 #include "parse.h" |
5770 | 81 #include "sighandlers.h" |
1352 | 82 #include "sysdep.h" |
1755 | 83 #include "toplev.h" |
529 | 84 #include "utils.h" |
6598 | 85 #include "file-stat.h" |
529 | 86 |
87 #ifndef STDIN_FILENO | |
88 #define STDIN_FILENO 1 | |
89 #endif | |
444 | 90 |
9441
160c564d5d25
initialize floating point values properly for NetBSD systems
Aleksej Saushev <asau@inbox.ru>
parents:
9411
diff
changeset
|
91 #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__) |
2508 | 92 static void |
93 BSD_init (void) | |
94 { | |
95 #if defined (HAVE_FLOATINGPOINT_H) | |
96 // Disable trapping on common exceptions. | |
4164 | 97 #ifndef FP_X_DNML |
98 #define FP_X_DNML 0 | |
99 #endif | |
2508 | 100 fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP)); |
101 #endif | |
102 } | |
103 #endif | |
104 | |
6956 | 105 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
106 |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
107 #define WIN32_LEAN_AND_MEAN |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
108 #include <tlhelp32.h> |
19463
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
109 #include <windows.h> |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
110 |
6080 | 111 static void |
112 w32_set_octave_home (void) | |
113 { | |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
114 std::string bin_dir; |
6080 | 115 |
13885
2f42a7b0cf94
Fix MinGW compilation problem with tlhelp32.h
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13771
diff
changeset
|
116 HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE |
2f42a7b0cf94
Fix MinGW compilation problem with tlhelp32.h
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13771
diff
changeset
|
117 #ifdef TH32CS_SNAPMODULE32 |
2f42a7b0cf94
Fix MinGW compilation problem with tlhelp32.h
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13771
diff
changeset
|
118 | TH32CS_SNAPMODULE32 |
2f42a7b0cf94
Fix MinGW compilation problem with tlhelp32.h
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13771
diff
changeset
|
119 #endif |
2f42a7b0cf94
Fix MinGW compilation problem with tlhelp32.h
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13771
diff
changeset
|
120 , 0); |
6080 | 121 |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
122 if (h != INVALID_HANDLE_VALUE) |
6080 | 123 { |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
124 MODULEENTRY32 mod_info; |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
125 |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
126 ZeroMemory (&mod_info, sizeof (mod_info)); |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
127 mod_info.dwSize = sizeof (mod_info); |
13751
be7ff59cbc7a
Fix octinterp DLL searching on Win32.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13282
diff
changeset
|
128 |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
129 if (Module32First (h, &mod_info)) |
14445 | 130 { |
131 do | |
132 { | |
133 std::string mod_name (mod_info.szModule); | |
6080 | 134 |
14445 | 135 if (mod_name.find ("octinterp") != std::string::npos) |
136 { | |
137 bin_dir = mod_info.szExePath; | |
138 if (bin_dir[bin_dir.length () - 1] != '\\') | |
139 bin_dir.append (1, '\\'); | |
140 break; | |
141 } | |
142 } | |
143 while (Module32Next (h, &mod_info)); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
144 } |
13771
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
145 |
80b30e186b73
[Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13751
diff
changeset
|
146 CloseHandle (h); |
6080 | 147 } |
148 | |
149 if (! bin_dir.empty ()) | |
150 { | |
151 size_t pos = bin_dir.rfind ("\\bin\\"); | |
152 | |
8021 | 153 if (pos != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
154 octave_env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos)); |
6080 | 155 } |
156 } | |
157 | |
6960 | 158 void |
5451 | 159 w32_set_quiet_shutdown (void) |
160 { | |
161 // Let the user close the console window or shutdown without the | |
162 // pesky dialog. | |
163 // | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
164 // FIXME: should this be user configurable? |
5451 | 165 SetProcessShutdownParameters (0x280, SHUTDOWN_NORETRY); |
166 } | |
167 | |
6960 | 168 void |
5451 | 169 MINGW_signal_cleanup (void) |
170 { | |
5455 | 171 w32_set_quiet_shutdown (); |
5451 | 172 } |
19494
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18829
diff
changeset
|
173 |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18829
diff
changeset
|
174 static void |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18829
diff
changeset
|
175 w32_init (void) |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18829
diff
changeset
|
176 { |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18829
diff
changeset
|
177 w32_set_octave_home (); |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18829
diff
changeset
|
178 |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18829
diff
changeset
|
179 command_editor::prefer_env_winsize (true); |
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18829
diff
changeset
|
180 } |
19979
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
181 |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
182 static bool |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
183 w32_shell_execute (const std::string& file) |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
184 { |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
185 } |
5451 | 186 #endif |
187 | |
20061
5c1a38089f89
Change open_with_system_app to internal function.
Rik <rik@octave.org>
parents:
20054
diff
changeset
|
188 DEFUN (__open_with_system_app__, args, , |
20068
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
20062
diff
changeset
|
189 "-*- texinfo -*-\n\ |
20061
5c1a38089f89
Change open_with_system_app to internal function.
Rik <rik@octave.org>
parents:
20054
diff
changeset
|
190 @deftypefn {Loadable Function} {} __open_with_system_app__ (@var{file})\n\ |
19463
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
191 Undocumented internal function.\n\ |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
192 @end deftypefn") |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
193 { |
19979
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
194 octave_value retval; |
19463
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
195 |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
196 if (args.length () == 1) |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
197 { |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
198 std::string file = args(0).string_value (); |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
199 |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
200 if (! error_state) |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
201 { |
19979
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
202 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
203 HINSTANCE status = ShellExecute (0, 0, file.c_str (), 0, 0, |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
204 SW_SHOWNORMAL); |
19463
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
205 |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
206 // ShellExecute returns a value greater than 32 if successful. |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
207 retval = (reinterpret_cast<ptrdiff_t> (status) > 32); |
19979
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
208 #else |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
209 octave_value_list tmp |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
210 = Fsystem (ovl ("xdg-open " + file + " 2> /dev/null", |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
211 false, "async"), |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
212 1); |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
213 |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
214 retval = (tmp(0).double_value () == 0); |
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
215 #endif |
19463
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
216 } |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
217 else |
20061
5c1a38089f89
Change open_with_system_app to internal function.
Rik <rik@octave.org>
parents:
20054
diff
changeset
|
218 error ("__open_with_system_app__: argument must be a file name"); |
19463
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
219 } |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
220 else |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
221 print_usage (); |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
222 |
19979
904912f18357
make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
223 return retval; |
19463
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
224 } |
030d56f67363
implement the open function
John W. Eaton <jwe@octave.org>
parents:
19462
diff
changeset
|
225 |
5451 | 226 #if defined (__MINGW32__) |
227 static void | |
228 MINGW_init (void) | |
229 { | |
19494
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18829
diff
changeset
|
230 w32_init (); |
5451 | 231 } |
232 #endif | |
233 | |
6080 | 234 #if defined (_MSC_VER) |
235 static void | |
236 MSVC_init (void) | |
237 { | |
19494
37159a873c96
preserve text on Windows terminal resize (bug #41893; patch #8532)
John W. Eaton <jwe@octave.org>
parents:
18829
diff
changeset
|
238 w32_init (); |
6080 | 239 } |
240 #endif | |
241 | |
4091 | 242 |
6598 | 243 // Return TRUE if FILE1 and FILE2 refer to the same (physical) file. |
244 | |
245 bool | |
246 same_file_internal (const std::string& file1, const std::string& file2) | |
247 { | |
248 #ifdef OCTAVE_USE_WINDOWS_API | |
249 | |
6691 | 250 bool retval = false; |
251 | |
16564
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
252 const char *f1 = file1.c_str (); |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
253 const char *f2 = file2.c_str (); |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
254 |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
255 bool f1_is_dir = GetFileAttributes (f1) & FILE_ATTRIBUTE_DIRECTORY; |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
256 bool f2_is_dir = GetFileAttributes (f2) & FILE_ATTRIBUTE_DIRECTORY; |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
257 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
258 // Windows native code |
6598 | 259 // Reference: http://msdn2.microsoft.com/en-us/library/aa363788.aspx |
260 | |
16564
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
261 DWORD share = FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE; |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
262 |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
263 HANDLE hfile1 |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
264 = CreateFile (f1, 0, share, 0, OPEN_EXISTING, |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
265 f1_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0); |
6691 | 266 |
267 if (hfile1 != INVALID_HANDLE_VALUE) | |
268 { | |
16564
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
269 HANDLE hfile2 |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
270 = CreateFile (f2, 0, share, 0, OPEN_EXISTING, |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
271 f2_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0); |
6598 | 272 |
6691 | 273 if (hfile2 != INVALID_HANDLE_VALUE) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
274 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
275 BY_HANDLE_FILE_INFORMATION hfi1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
276 BY_HANDLE_FILE_INFORMATION hfi2; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
277 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
278 if (GetFileInformationByHandle (hfile1, &hfi1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
279 && GetFileInformationByHandle (hfile2, &hfi2)) |
16564
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
280 { |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
281 retval = (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
282 && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
283 && hfi1.nFileIndexLow == hfi2.nFileIndexLow); |
aa5299a1d770
* sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents:
16537
diff
changeset
|
284 } |
6598 | 285 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
286 CloseHandle (hfile2); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
287 } |
6691 | 288 |
6598 | 289 CloseHandle (hfile1); |
290 } | |
6691 | 291 |
292 return retval; | |
6598 | 293 |
294 #else | |
295 | |
296 // POSIX Code | |
297 | |
298 file_stat fs_file1 (file1); | |
299 file_stat fs_file2 (file2); | |
300 | |
301 return (fs_file1 && fs_file2 | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
302 && fs_file1.ino () == fs_file2.ino () |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
303 && fs_file1.dev () == fs_file2.dev ()); |
6598 | 304 |
305 #endif | |
306 } | |
307 | |
1 | 308 void |
309 sysdep_init (void) | |
310 { | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14445
diff
changeset
|
311 #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__) |
2508 | 312 BSD_init (); |
5451 | 313 #elif defined (__MINGW32__) |
314 MINGW_init (); | |
6080 | 315 #elif defined (_MSC_VER) |
316 MSVC_init (); | |
1 | 317 #endif |
318 } | |
319 | |
5451 | 320 void |
321 sysdep_cleanup (void) | |
322 { | |
323 MINGW_SIGNAL_CLEANUP (); | |
324 } | |
325 | |
767 | 326 // Set terminal in raw mode. From less-177. |
327 // | |
328 // Change terminal to "raw mode", or restore to "normal" mode. | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
329 // "Raw mode" means |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
330 // 1. An outstanding read will complete on receipt of a single keystroke. |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
331 // 2. Input is not echoed. |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
332 // 3. On output, \n is mapped to \r\n. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
333 // 4. \t is NOT expanded into spaces. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
334 // 5. Signal-causing characters such as ctrl-C (interrupt), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
335 // etc. are NOT disabled. |
767 | 336 // It doesn't matter whether an input \n is mapped to \r, or vice versa. |
337 | |
529 | 338 void |
3657 | 339 raw_mode (bool on, bool wait) |
529 | 340 { |
3657 | 341 static bool curr_on = false; |
529 | 342 |
343 int tty_fd = STDIN_FILENO; | |
14160 | 344 if (! gnulib::isatty (tty_fd)) |
529 | 345 { |
20054
1c9ed5b4c73d
input.h: change meaning of interactive and forced_interactive global variables.
Carnë Draug <carandraug@octave.org>
parents:
19979
diff
changeset
|
346 if (interactive && ! forced_interactive) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
347 error ("stdin is not a tty!"); |
529 | 348 return; |
349 } | |
350 | |
351 if (on == curr_on) | |
352 return; | |
353 | |
354 #if defined (HAVE_TERMIOS_H) | |
355 { | |
356 struct termios s; | |
357 static struct termios save_term; | |
358 | |
359 if (on) | |
360 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
361 // Get terminal modes. |
529 | 362 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
363 tcgetattr (tty_fd, &s); |
529 | 364 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
365 // Save modes and set certain variables dependent on modes. |
529 | 366 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
367 save_term = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
368 // ospeed = s.c_cflag & CBAUD; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
369 // erase_char = s.c_cc[VERASE]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
370 // kill_char = s.c_cc[VKILL]; |
529 | 371 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
372 // Set the modes to the way we want them. |
529 | 373 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
374 s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
375 s.c_oflag |= (OPOST|ONLCR); |
529 | 376 #if defined (OCRNL) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
377 s.c_oflag &= ~(OCRNL); |
529 | 378 #endif |
379 #if defined (ONOCR) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
380 s.c_oflag &= ~(ONOCR); |
529 | 381 #endif |
382 #if defined (ONLRET) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
383 s.c_oflag &= ~(ONLRET); |
529 | 384 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
385 s.c_cc[VMIN] = wait ? 1 : 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
386 s.c_cc[VTIME] = 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
387 } |
529 | 388 else |
389 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
390 // Restore saved modes. |
1358 | 391 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
392 s = save_term; |
529 | 393 } |
3658 | 394 |
9411
c9636d98e5cd
fix kbhit(1) to not discard waiting keystrokes
Joe Rothweiler <octaveuser@sensicomm.com>
parents:
9242
diff
changeset
|
395 tcsetattr (tty_fd, wait ? TCSAFLUSH : TCSADRAIN, &s); |
529 | 396 } |
397 #elif defined (HAVE_TERMIO_H) | |
398 { | |
399 struct termio s; | |
400 static struct termio save_term; | |
401 | |
402 if (on) | |
403 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
404 // Get terminal modes. |
529 | 405 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
406 ioctl (tty_fd, TCGETA, &s); |
529 | 407 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
408 // Save modes and set certain variables dependent on modes. |
529 | 409 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
410 save_term = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
411 // ospeed = s.c_cflag & CBAUD; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
412 // erase_char = s.c_cc[VERASE]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
413 // kill_char = s.c_cc[VKILL]; |
529 | 414 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
415 // Set the modes to the way we want them. |
529 | 416 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
417 s.c_lflag &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
418 s.c_oflag |= (OPOST|ONLCR); |
529 | 419 #if defined (OCRNL) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
420 s.c_oflag &= ~(OCRNL); |
529 | 421 #endif |
422 #if defined (ONOCR) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
423 s.c_oflag &= ~(ONOCR); |
529 | 424 #endif |
425 #if defined (ONLRET) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
426 s.c_oflag &= ~(ONLRET); |
529 | 427 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
428 s.c_cc[VMIN] = wait ? 1 : 0; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
429 } |
529 | 430 else |
431 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
432 // Restore saved modes. |
1358 | 433 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
434 s = save_term; |
529 | 435 } |
3658 | 436 |
529 | 437 ioctl (tty_fd, TCSETAW, &s); |
438 } | |
439 #elif defined (HAVE_SGTTY_H) | |
440 { | |
441 struct sgttyb s; | |
442 static struct sgttyb save_term; | |
443 | |
444 if (on) | |
445 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
446 // Get terminal modes. |
529 | 447 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
448 ioctl (tty_fd, TIOCGETP, &s); |
529 | 449 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
450 // Save modes and set certain variables dependent on modes. |
529 | 451 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
452 save_term = s; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
453 // ospeed = s.sg_ospeed; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
454 // erase_char = s.sg_erase; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
455 // kill_char = s.sg_kill; |
529 | 456 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
457 // Set the modes to the way we want them. |
529 | 458 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
459 s.sg_flags |= CBREAK; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
460 s.sg_flags &= ~(ECHO); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
461 } |
529 | 462 else |
463 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
464 // Restore saved modes. |
1358 | 465 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
466 s = save_term; |
529 | 467 } |
3658 | 468 |
529 | 469 ioctl (tty_fd, TIOCSETN, &s); |
470 } | |
471 #else | |
4064 | 472 warning ("no support for raw mode console I/O on this system"); |
473 | |
474 // Make sure the current mode doesn't toggle. | |
475 on = curr_on; | |
529 | 476 #endif |
477 | |
478 curr_on = on; | |
479 } | |
480 | |
6726 | 481 FILE * |
482 octave_popen (const char *command, const char *mode) | |
483 { | |
484 #if defined (__MINGW32__) || defined (_MSC_VER) | |
485 if (mode && mode[0] && ! mode[1]) | |
486 { | |
487 char tmode[3]; | |
488 tmode[0] = mode[0]; | |
489 tmode[1] = 'b'; | |
490 tmode[2] = 0; | |
491 | |
492 return _popen (command, tmode); | |
493 } | |
494 else | |
495 return _popen (command, mode); | |
496 #else | |
497 return popen (command, mode); | |
498 #endif | |
499 } | |
500 | |
501 int | |
502 octave_pclose (FILE *f) | |
503 { | |
504 #if defined (__MINGW32__) || defined (_MSC_VER) | |
505 return _pclose (f); | |
506 #else | |
507 return pclose (f); | |
508 #endif | |
509 } | |
510 | |
767 | 511 // Read one character from the terminal. |
512 | |
529 | 513 int |
4067 | 514 octave_kbhit (bool wait) |
529 | 515 { |
4067 | 516 #ifdef HAVE__KBHIT |
4081 | 517 int c = (! wait && ! _kbhit ()) ? 0 : std::cin.get (); |
4067 | 518 #else |
3658 | 519 raw_mode (true, wait); |
520 | |
5770 | 521 // Get current handler. |
522 octave_interrupt_handler saved_interrupt_handler | |
523 = octave_ignore_interrupts (); | |
524 | |
525 // Restore it, disabling system call restarts (if possible) so the | |
526 // read can be interrupted. | |
527 | |
528 octave_set_interrupt_handler (saved_interrupt_handler, false); | |
529 | |
3658 | 530 int c = std::cin.get (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
531 |
3658 | 532 if (std::cin.fail () || std::cin.eof ()) |
533 std::cin.clear (); | |
534 | |
5770 | 535 // Restore it, enabling system call restarts (if possible). |
536 octave_set_interrupt_handler (saved_interrupt_handler, true); | |
537 | |
3658 | 538 raw_mode (false, true); |
4067 | 539 #endif |
3658 | 540 |
529 | 541 return c; |
542 } | |
543 | |
12228
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
544 std::string |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
545 get_P_tmpdir (void) |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
546 { |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
547 #if defined (__WIN32__) && ! defined (_POSIX_VERSION) |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
548 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
549 std::string retval; |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
550 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
551 #if defined (P_tmpdir) |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
552 retval = P_tmpdir; |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
553 #endif |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
554 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
555 // Apparently some versions of MinGW and MSVC either don't define |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
556 // P_tmpdir, or they define it to a single backslash, neither of which |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
557 // is particularly helpful. |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
558 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
559 if (retval.empty () || retval == "\\") |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
560 { |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
561 retval = octave_env::getenv ("TEMP"); |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
562 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
563 if (retval.empty ()) |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
564 retval = octave_env::getenv ("TMP"); |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
565 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
566 if (retval.empty ()) |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
567 retval = "c:\\temp"; |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
568 } |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
569 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
570 return retval; |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
571 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
572 #elif defined (P_tmpdir) |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
573 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
574 return P_tmpdir; |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
575 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
576 #else |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
577 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
578 return "/tmp"; |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
579 |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
580 #endif |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
581 } |
0f70c5db58c3
try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
582 |
1957 | 583 DEFUN (clc, , , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
584 "-*- texinfo -*-\n\ |
10840 | 585 @deftypefn {Built-in Function} {} clc ()\n\ |
3332 | 586 @deftypefnx {Built-in Function} {} home ()\n\ |
587 Clear the terminal screen and move the cursor to the upper left corner.\n\ | |
3333 | 588 @end deftypefn") |
529 | 589 { |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16404
diff
changeset
|
590 bool skip_redisplay = true; |
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16404
diff
changeset
|
591 |
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16404
diff
changeset
|
592 command_editor::clear_screen (skip_redisplay); |
529 | 593 |
2926 | 594 return octave_value_list (); |
529 | 595 } |
596 | |
549 | 597 DEFALIAS (home, clc); |
598 | |
1957 | 599 DEFUN (getenv, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
600 "-*- texinfo -*-\n\ |
3301 | 601 @deftypefn {Built-in Function} {} getenv (@var{var})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
602 Return the value of the environment variable @var{var}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
603 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
604 For example,\n\ |
3301 | 605 \n\ |
606 @example\n\ | |
607 getenv (\"PATH\")\n\ | |
608 @end example\n\ | |
609 \n\ | |
610 @noindent\n\ | |
611 returns a string containing the value of your path.\n\ | |
19359
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
612 @seealso{setenv, unsetenv}\n\ |
3301 | 613 @end deftypefn") |
529 | 614 { |
4233 | 615 octave_value retval; |
529 | 616 |
617 int nargin = args.length (); | |
618 | |
712 | 619 if (nargin == 1) |
529 | 620 { |
3523 | 621 std::string name = args(0).string_value (); |
636 | 622 |
623 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
624 retval = octave_env::getenv (name); |
529 | 625 } |
626 else | |
5823 | 627 print_usage (); |
529 | 628 |
629 return retval; | |
630 } | |
631 | |
19359
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
632 /* |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
633 %!assert (ischar (getenv ("OCTAVE_HOME"))) |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
634 */ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
635 |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
636 DEFUN (setenv, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
637 "-*- texinfo -*-\n\ |
19359
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
638 @deftypefn {Built-in Function} {} setenv (@var{var}, @var{value})\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
639 @deftypefnx {Built-in Function} {} setenv (@var{var})\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
640 @deftypefnx {Built-in Function} {} putenv (@dots{})\n\ |
3301 | 641 Set the value of the environment variable @var{var} to @var{value}.\n\ |
19359
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
642 \n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
643 If no @var{value} is specified then the variable will be assigned the null\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
644 string.\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
645 @seealso{unsetenv, getenv}\n\ |
3301 | 646 @end deftypefn") |
1706 | 647 { |
2086 | 648 octave_value_list retval; |
1706 | 649 |
650 int nargin = args.length (); | |
651 | |
7759
84a7f00586aa
Alias setenv to putenv. Allow single arg to putenv
David Bateman <dbateman@free.fr>
parents:
7231
diff
changeset
|
652 if (nargin == 2 || nargin == 1) |
1706 | 653 { |
19600
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19503
diff
changeset
|
654 if (args(0).is_string ()) |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19503
diff
changeset
|
655 { |
03067dab10ca
Use stricter input validation when looking for a string as input (bug #42651).
Rik <rik@octave.org>
parents:
19503
diff
changeset
|
656 std::string var = args(0).string_value (); |
1706 | 657 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
658 std::string val = (nargin == 2 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
659 ? args(1).string_value () : std::string ()); |
1706 | 660 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
661 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
662 octave_env::putenv (var, val); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
663 else |
19359
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
664 error ("setenv: VALUE must be a string"); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
665 } |
1706 | 666 else |
19359
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
667 error ("setenv: VAR must be a string"); |
1706 | 668 } |
669 else | |
5823 | 670 print_usage (); |
1706 | 671 |
672 return retval; | |
673 } | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
674 |
19359
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
675 DEFALIAS (putenv, setenv); |
1706 | 676 |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
677 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
678 %!test |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
679 %! setenv ("dummy_variable_that_cannot_matter", "foobar"); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
680 %! assert (getenv ("dummy_variable_that_cannot_matter"), "foobar"); |
19359
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
681 %! unsetenv ("dummy_variable_that_cannot_matter"); |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
682 %! assert (getenv ("dummy_variable_that_cannot_matter"), ""); |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
683 */ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
684 |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
685 DEFUN (unsetenv, args, , |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
686 "-*- texinfo -*-\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
687 @deftypefn {Built-in Function} {@var{status} =} unsetenv (@var{var})\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
688 Delete the environment variable @var{var}.\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
689 \n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
690 Return 0 if the variable was deleted, or did not exist, and -1 if an error\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
691 occurred.\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
692 @seealso{setenv, getenv}\n\ |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
693 @end deftypefn") |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
694 { |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
695 octave_value retval; |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
696 |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
697 int nargin = args.length (); |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
698 |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
699 if (nargin == 1) |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
700 { |
19737
146f1daa805b
avoid valgrind warnings about using freed memory
John W. Eaton <jwe@octave.org>
parents:
19600
diff
changeset
|
701 std::string tmp = args(0).string_value (); |
19359
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
702 |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
703 if (! error_state) |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
704 { |
19737
146f1daa805b
avoid valgrind warnings about using freed memory
John W. Eaton <jwe@octave.org>
parents:
19600
diff
changeset
|
705 int status = gnulib::unsetenv (tmp.c_str ()); |
19359
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
706 retval = status; |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
707 } |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
708 } |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
709 else |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
710 print_usage (); |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
711 |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
712 return retval; |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
713 } |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
714 |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
715 /* |
6f0290863d50
Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents:
18829
diff
changeset
|
716 ## Test for unsetenv is in setenv test |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
717 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
718 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
719 // FIXME: perhaps kbhit should also be able to print a prompt? |
3372 | 720 |
3657 | 721 DEFUN (kbhit, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
722 "-*- texinfo -*-\n\ |
16053
119ce9f5e1a3
doc: Add seealso links between input, yes_or_no, kbhit.
Rik <rik@octave.org>
parents:
16015
diff
changeset
|
723 @deftypefn {Built-in Function} {} kbhit ()\n\ |
119ce9f5e1a3
doc: Add seealso links between input, yes_or_no, kbhit.
Rik <rik@octave.org>
parents:
16015
diff
changeset
|
724 @deftypefnx {Built-in Function} {} kbhit (1)\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
725 Read a single keystroke from the keyboard.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
726 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
727 If called with an argument, don't wait for a keypress.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
728 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
729 For example,\n\ |
3372 | 730 \n\ |
731 @example\n\ | |
732 x = kbhit ();\n\ | |
733 @end example\n\ | |
734 \n\ | |
735 @noindent\n\ | |
736 will set @var{x} to the next character typed at the keyboard as soon as\n\ | |
737 it is typed.\n\ | |
3657 | 738 \n\ |
739 @example\n\ | |
740 x = kbhit (1);\n\ | |
741 @end example\n\ | |
742 \n\ | |
743 @noindent\n\ | |
16053
119ce9f5e1a3
doc: Add seealso links between input, yes_or_no, kbhit.
Rik <rik@octave.org>
parents:
16015
diff
changeset
|
744 is identical to the above example, but doesn't wait for a keypress,\n\ |
3657 | 745 returning the empty string if no key is available.\n\ |
18829
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
746 @seealso{input, pause}\n\ |
3372 | 747 @end deftypefn") |
529 | 748 { |
4233 | 749 octave_value retval; |
529 | 750 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
751 // FIXME: add timeout and default value args? |
529 | 752 |
20054
1c9ed5b4c73d
input.h: change meaning of interactive and forced_interactive global variables.
Carnë Draug <carandraug@octave.org>
parents:
19979
diff
changeset
|
753 if (interactive) |
529 | 754 { |
15423
53d073233fa4
call more built-in functions directly
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
755 Fdrawnow (); |
6423 | 756 |
4067 | 757 int c = octave_kbhit (args.length () == 0); |
3657 | 758 |
3658 | 759 if (c == -1) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
760 c = 0; |
3657 | 761 |
16092
def3b111cff8
avoid gcc warning about int to char conversion
John W. Eaton <jwe@octave.org>
parents:
16053
diff
changeset
|
762 char s[2] = { static_cast<char> (c), '\0' }; |
16015 | 763 |
529 | 764 retval = s; |
765 } | |
766 | |
767 return retval; | |
768 } | |
769 | |
1957 | 770 DEFUN (pause, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
771 "-*- texinfo -*-\n\ |
18829
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
772 @deftypefn {Built-in Function} {} pause ()\n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
773 @deftypefnx {Built-in Function} {} pause (@var{n})\n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
774 Suspend the execution of the program for @var{n} seconds.\n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
775 \n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
776 @var{n} is a positive real value and may be a fraction of a second.\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
777 \n\ |
18829
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
778 If invoked without an input arguments then the program is suspended until a\n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
779 character is typed.\n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
780 \n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
781 The following example prints a message and then waits 5 seconds before\n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
782 clearing the screen.\n\ |
3301 | 783 \n\ |
784 @example\n\ | |
785 @group\n\ | |
6848 | 786 fprintf (stderr, \"wait please...\\n\");\n\ |
3301 | 787 pause (5);\n\ |
788 clc;\n\ | |
789 @end group\n\ | |
790 @end example\n\ | |
18829
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
791 @seealso{kbhit, sleep}\n\ |
3301 | 792 @end deftypefn") |
529 | 793 { |
2086 | 794 octave_value_list retval; |
529 | 795 |
796 int nargin = args.length (); | |
797 | |
712 | 798 if (! (nargin == 0 || nargin == 1)) |
529 | 799 { |
5823 | 800 print_usage (); |
529 | 801 return retval; |
802 } | |
803 | |
1579 | 804 if (nargin == 1) |
529 | 805 { |
1579 | 806 double dval = args(0).double_value (); |
636 | 807 |
1579 | 808 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
809 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
810 if (! xisnan (dval)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
811 { |
15423
53d073233fa4
call more built-in functions directly
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
812 Fdrawnow (); |
6419 | 813 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
814 if (xisinf (dval)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
815 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
816 flush_octave_stdout (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
817 octave_kbhit (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
818 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
819 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
820 octave_sleep (dval); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
821 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
822 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
823 warning ("pause: NaN is an invalid delay"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
824 } |
529 | 825 } |
1579 | 826 else |
3234 | 827 { |
15423
53d073233fa4
call more built-in functions directly
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
828 Fdrawnow (); |
3234 | 829 flush_octave_stdout (); |
4067 | 830 octave_kbhit (); |
3234 | 831 } |
2630 | 832 |
833 return retval; | |
834 } | |
835 | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
836 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
837 %!test |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
838 %! pause (1); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
839 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
840 %!error (pause (1, 2)) |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
841 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
842 |
2630 | 843 DEFUN (sleep, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
844 "-*- texinfo -*-\n\ |
3301 | 845 @deftypefn {Built-in Function} {} sleep (@var{seconds})\n\ |
846 Suspend the execution of the program for the given number of seconds.\n\ | |
18829
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
847 @seealso{usleep, pause}\n\ |
3301 | 848 @end deftypefn") |
2630 | 849 { |
850 octave_value_list retval; | |
851 | |
852 if (args.length () == 1) | |
1579 | 853 { |
2630 | 854 double dval = args(0).double_value (); |
855 | |
856 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
857 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
858 if (xisnan (dval)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
859 warning ("sleep: NaN is an invalid delay"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
860 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
861 { |
15423
53d073233fa4
call more built-in functions directly
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
862 Fdrawnow (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
863 octave_sleep (dval); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
864 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
865 } |
1579 | 866 } |
2630 | 867 else |
5823 | 868 print_usage (); |
2630 | 869 |
870 return retval; | |
871 } | |
872 | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
873 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
874 %!test |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
875 %! sleep (1); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
876 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
877 %!error (sleep ()) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
878 %!error (sleep (1, 2)) |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
879 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
880 |
2630 | 881 DEFUN (usleep, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
882 "-*- texinfo -*-\n\ |
3301 | 883 @deftypefn {Built-in Function} {} usleep (@var{microseconds})\n\ |
884 Suspend the execution of the program for the given number of\n\ | |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
885 microseconds.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
886 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
887 On systems where it is not possible to sleep for periods of time less than\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
888 one second, @code{usleep} will pause the execution for @code{round\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
889 (@var{microseconds} / 1e6)} seconds.\n\ |
18829
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
890 @seealso{sleep, pause}\n\ |
3301 | 891 @end deftypefn") |
2630 | 892 { |
893 octave_value_list retval; | |
894 | |
895 if (args.length () == 1) | |
896 { | |
897 double dval = args(0).double_value (); | |
898 | |
899 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
900 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
901 if (xisnan (dval)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
902 warning ("usleep: NaN is an invalid delay"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
903 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
904 { |
15423
53d073233fa4
call more built-in functions directly
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
905 Fdrawnow (); |
6423 | 906 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
907 int delay = NINT (dval); |
2631 | 908 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
909 if (delay > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
910 octave_usleep (delay); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
911 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
912 } |
2630 | 913 } |
914 else | |
5823 | 915 print_usage (); |
529 | 916 |
917 return retval; | |
918 } | |
919 | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
920 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
921 %!test |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
922 %! usleep (1000); |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
923 |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
924 %!error (usleep ()) |
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
925 %!error (usleep (1, 2)) |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
926 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
927 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
928 // FIXME: maybe this should only return 1 if IEEE floating |
862 | 929 // point functions really work. |
930 | |
1957 | 931 DEFUN (isieee, , , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
932 "-*- texinfo -*-\n\ |
3301 | 933 @deftypefn {Built-in Function} {} isieee ()\n\ |
11431
0d9640d755b1
Improve docstrings for all isXXX functions.
Rik <octave@nomad.inbox5.com>
parents:
11234
diff
changeset
|
934 Return true if your computer @emph{claims} to conform to the IEEE standard\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
935 for floating point calculations.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
936 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
937 No actual tests are performed.\n\ |
3301 | 938 @end deftypefn") |
862 | 939 { |
4600 | 940 oct_mach_info::float_format flt_fmt = oct_mach_info::native_float_format (); |
2317 | 941 |
4574 | 942 return octave_value (flt_fmt == oct_mach_info::flt_fmt_ieee_little_endian |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
943 || flt_fmt == oct_mach_info::flt_fmt_ieee_big_endian); |
862 | 944 } |
945 | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
946 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
947 %!assert (islogical (isieee ())) |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
948 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
949 |
4600 | 950 DEFUN (native_float_format, , , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
951 "-*- texinfo -*-\n\ |
4600 | 952 @deftypefn {Built-in Function} {} native_float_format ()\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
953 Return the native floating point format as a string.\n\ |
4600 | 954 @end deftypefn") |
955 { | |
956 oct_mach_info::float_format flt_fmt = oct_mach_info::native_float_format (); | |
957 | |
958 return octave_value (oct_mach_info::float_format_as_string (flt_fmt)); | |
959 } | |
960 | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
961 /* |
14429
eff4a5933e28
Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14160
diff
changeset
|
962 %!assert (ischar (native_float_format ())) |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
963 */ |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
964 |
1957 | 965 DEFUN (tilde_expand, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
966 "-*- texinfo -*-\n\ |
3301 | 967 @deftypefn {Built-in Function} {} tilde_expand (@var{string})\n\ |
20382
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
968 Perform tilde expansion on @var{string}.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
969 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
970 If @var{string} begins with a tilde character, (@samp{~}), all of the\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
971 characters preceding the first slash (or all characters, if there is no\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
972 slash) are treated as a possible user name, and the tilde and the following\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
973 characters up to the slash are replaced by the home directory of the named\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
974 user. If the tilde is followed immediately by a slash, the tilde is\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
975 replaced by the home directory of the user running Octave.\n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
976 \n\ |
4f45eaf83908
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
20274
diff
changeset
|
977 For example:\n\ |
3301 | 978 \n\ |
979 @example\n\ | |
980 @group\n\ | |
981 tilde_expand (\"~joeuser/bin\")\n\ | |
982 @result{} \"/home/joeuser/bin\"\n\ | |
983 tilde_expand (\"~/bin\")\n\ | |
984 @result{} \"/home/jwe/bin\"\n\ | |
985 @end group\n\ | |
986 @end example\n\ | |
987 @end deftypefn") | |
1750 | 988 { |
4233 | 989 octave_value retval; |
1750 | 990 |
991 int nargin = args.length (); | |
992 | |
993 if (nargin == 1) | |
6116 | 994 { |
995 octave_value arg = args(0); | |
996 | |
997 string_vector sv = arg.all_strings (); | |
998 | |
999 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
1000 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
1001 sv = file_ops::tilde_expand (sv); |
6116 | 1002 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
1003 if (arg.is_cellstr ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
1004 retval = Cell (arg.dims (), sv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
1005 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
1006 retval = sv; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
1007 } |
6116 | 1008 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10266
diff
changeset
|
1009 error ("tilde_expand: expecting argument to be char or cellstr object"); |
6116 | 1010 } |
1750 | 1011 else |
5823 | 1012 print_usage (); |
1750 | 1013 |
1014 return retval; | |
1015 } | |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1016 |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1017 /* |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1018 %!test |
20226
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
20068
diff
changeset
|
1019 %! home = get_home_directory (); |
20274
ab7582167810
Fix failing BIST test for tilde_expand() on Windows (bug #44796).
Rik <rik@octave.org>
parents:
20234
diff
changeset
|
1020 %! assert (tilde_expand ("~/foobar"), [home "/foobar"]); |
12825
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1021 %! assert (tilde_expand ("/foo/bar"), "/foo/bar"); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1022 %! assert (tilde_expand ("foo/bar"), "foo/bar"); |
a1dcb854a4f9
codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents:
12483
diff
changeset
|
1023 */ |
17851
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1024 |
20226
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
20068
diff
changeset
|
1025 DEFUN (get_home_directory, , , |
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
20068
diff
changeset
|
1026 "-*- texinfo -*-\n\ |
20234
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20226
diff
changeset
|
1027 @deftypefn {Built-in Function} {@var{homedir} =} get_home_directory ()\n\ |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20226
diff
changeset
|
1028 Return the current home directory.\n\ |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20226
diff
changeset
|
1029 \n\ |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20226
diff
changeset
|
1030 On most systems, this is equivalent to @code{getenv (\"HOME\")}. On Windows\n\ |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20226
diff
changeset
|
1031 systems, if the environment variable @env{HOME} is not set then it is\n\ |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20226
diff
changeset
|
1032 equivalent to\n\ |
20226
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
20068
diff
changeset
|
1033 @code{fullfile (getenv (\"HOMEDRIVE\"), getenv (\"HOMEPATH\"))}\n\ |
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
20068
diff
changeset
|
1034 @seealso{getenv}\n\ |
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
20068
diff
changeset
|
1035 @end deftypefn") |
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
20068
diff
changeset
|
1036 { |
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
20068
diff
changeset
|
1037 return octave_value (octave_env::get_home_directory ()); |
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
20068
diff
changeset
|
1038 } |
47d420d769ba
* sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents:
20068
diff
changeset
|
1039 |
20234
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20226
diff
changeset
|
1040 /* |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20226
diff
changeset
|
1041 %!test |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20226
diff
changeset
|
1042 %! if (! ispc ()) |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20226
diff
changeset
|
1043 %! assert (get_home_directory (), getenv ("HOME")); |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20226
diff
changeset
|
1044 %! endif |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20226
diff
changeset
|
1045 */ |
cf9b94a89620
Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents:
20226
diff
changeset
|
1046 |
17851
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1047 // This function really belongs in display.cc, but including defun.h in |
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1048 // that file results in conflicts with symbols from headers that are |
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1049 // needed for X11 and Carbon functions. |
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1050 |
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1051 DEFUN (have_window_system, , , |
20068
19755f4fc851
maint: Cleanup C++ code to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
20062
diff
changeset
|
1052 "-*- texinfo -*-\n\ |
17851
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1053 @deftypefn {Built-in Function} {} have_window_system ()\n\ |
18829
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
1054 Return true if a window system is available (X11, Windows, or Apple OS X)\n\ |
7bccc182e2f7
doc: Update pause documentation and add seealso links between related functions.
Rik <rik@octave.org>
parents:
17851
diff
changeset
|
1055 and false otherwise.\n\ |
20062
bf511802add7
doc: Add have_window_system() to documentation.
Rik <rik@octave.org>
parents:
20061
diff
changeset
|
1056 @seealso{isguirunning}\n\ |
17851
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1057 @end deftypefn") |
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1058 { |
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1059 return octave_value (display_info::display_available ()); |
af685269e06c
avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
1060 } |