annotate libinterp/corefcn/sysdep.cc @ 27577:f90564fb99e0

maint: merge stable to default.
author Kai T. Ohlhus <k.ohlhus@gmail.com>
date Mon, 28 Oct 2019 20:03:04 +0900
parents edeacebc8800 3b50efa29be4
children b5e88a4bce43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 26162
diff changeset
3 Copyright (C) 1993-2019 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
4
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24442
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22417
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24442
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22417
diff changeset
10 (at your option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22417
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22417
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22417
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22417
diff changeset
15 GNU General Public License for more details.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6960
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24442
diff changeset
19 <https://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
20
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21662
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
24 # include "config.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26
23662
bd77ab816e43 eliminate obsolete file lo-math.h
John W. Eaton <jwe@octave.org>
parents: 23575
diff changeset
27 #include <cmath>
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1318
diff changeset
28 #include <cstddef>
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1318
diff changeset
29
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3372
diff changeset
30 #include <iostream>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1711
diff changeset
31 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1711
diff changeset
32
1430
045e70a15a8f [project @ 1995-09-19 07:05:37 by jwe]
jwe
parents: 1415
diff changeset
33 #if defined (HAVE_TERMIOS_H)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21115
diff changeset
34 # include <termios.h>
1430
045e70a15a8f [project @ 1995-09-19 07:05:37 by jwe]
jwe
parents: 1415
diff changeset
35 #elif defined (HAVE_TERMIO_H)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21115
diff changeset
36 # include <termio.h>
1430
045e70a15a8f [project @ 1995-09-19 07:05:37 by jwe]
jwe
parents: 1415
diff changeset
37 #elif defined (HAVE_SGTTY_H)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21115
diff changeset
38 # include <sgtty.h>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
39 #endif
4067
e97fb79fc1d5 [project @ 2002-09-26 22:43:25 by jwe]
jwe
parents: 4064
diff changeset
40
e97fb79fc1d5 [project @ 2002-09-26 22:43:25 by jwe]
jwe
parents: 4064
diff changeset
41 #if defined (HAVE_CONIO_H)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21115
diff changeset
42 # include <conio.h>
1430
045e70a15a8f [project @ 1995-09-19 07:05:37 by jwe]
jwe
parents: 1415
diff changeset
43 #endif
045e70a15a8f [project @ 1995-09-19 07:05:37 by jwe]
jwe
parents: 1415
diff changeset
44
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3234
diff changeset
45 #if defined (HAVE_SYS_IOCTL_H)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21115
diff changeset
46 # include <sys/ioctl.h>
3248
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3234
diff changeset
47 #endif
68259f410026 [project @ 1999-07-13 03:34:54 by jwe]
jwe
parents: 3234
diff changeset
48
1463
592291d9dfbb [project @ 1995-09-22 07:18:44 by jwe]
jwe
parents: 1430
diff changeset
49 #if defined (HAVE_FLOATINGPOINT_H)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21115
diff changeset
50 # include <floatingpoint.h>
1463
592291d9dfbb [project @ 1995-09-22 07:18:44 by jwe]
jwe
parents: 1430
diff changeset
51 #endif
592291d9dfbb [project @ 1995-09-22 07:18:44 by jwe]
jwe
parents: 1430
diff changeset
52
2508
f8d5dbbbc50a [project @ 1996-11-13 17:21:07 by jwe]
jwe
parents: 2493
diff changeset
53 #if defined (HAVE_IEEEFP_H)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21115
diff changeset
54 # include <ieeefp.h>
2508
f8d5dbbbc50a [project @ 1996-11-13 17:21:07 by jwe]
jwe
parents: 2493
diff changeset
55 #endif
f8d5dbbbc50a [project @ 1996-11-13 17:21:07 by jwe]
jwe
parents: 2493
diff changeset
56
21554
9f0088f3f335 call openmp function at initialization (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20788
diff changeset
57 #if defined (HAVE_OMP_H)
21556
12f207a534aa maint: merge stable to default.
John W. Eaton <jwe@octave.org>
parents: 21301 21554
diff changeset
58 # include <omp.h>
21554
9f0088f3f335 call openmp function at initialization (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20788
diff changeset
59 #endif
9f0088f3f335 call openmp function at initialization (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20788
diff changeset
60
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2893
diff changeset
61 #include "cmd-edit.h"
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2893
diff changeset
62 #include "file-ops.h"
2893
9fd1df4b464a [project @ 1997-04-28 02:07:38 by jwe]
jwe
parents: 2847
diff changeset
63 #include "lo-mappers.h"
24714
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
64 #include "lo-sysinfo.h"
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2086
diff changeset
65 #include "mach-info.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2893
diff changeset
66 #include "oct-env.h"
25530
197126863d95 sysdep.cc: Use wide character versions of Windows API functions (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25311
diff changeset
67 #include "uniconv-wrappers.h"
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21888
diff changeset
68 #include "unistd-wrappers.h"
1769
bc7ae9be3378 [project @ 1996-01-23 06:49:08 by jwe]
jwe
parents: 1755
diff changeset
69
22097
5ad67277b007 include builtin-defun-decls.h as needed
John W. Eaton <jwe@octave.org>
parents: 22096
diff changeset
70 #include "builtin-defun-decls.h"
6208
323be5eeed1f [project @ 2006-12-06 20:23:18 by jwe]
jwe
parents: 6135
diff changeset
71 #include "Cell.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
72 #include "defun.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
73 #include "error.h"
21115
629643522cc0 include errwarn.h in all files that use gripe_disabled_feature
John W. Eaton <jwe@octave.org>
parents: 21109
diff changeset
74 #include "errwarn.h"
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
75 #include "input.h"
27301
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
76 #include "interpreter-private.h"
22089
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 22051
diff changeset
77 #include "octave.h"
c2c668b3051b use classes for octave application and interpreter
John W. Eaton <jwe@octave.org>
parents: 22051
diff changeset
78 #include "ov.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20939
diff changeset
79 #include "ovl.h"
3234
be8e0ba13644 [project @ 1999-01-29 03:52:30 by jwe]
jwe
parents: 3124
diff changeset
80 #include "pager.h"
6419
73fcbac81f33 [project @ 2007-03-20 17:18:24 by jwe]
jwe
parents: 6208
diff changeset
81 #include "parse.h"
5770
6a9244f89a2a [project @ 2006-04-18 17:44:33 by jwe]
jwe
parents: 5455
diff changeset
82 #include "sighandlers.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
83 #include "sysdep.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22089
diff changeset
84 #include "interpreter.h"
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
85 #include "utils.h"
6598
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6423
diff changeset
86 #include "file-stat.h"
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
87
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21662
diff changeset
88 #if ! defined (STDIN_FILENO)
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21115
diff changeset
89 # define STDIN_FILENO 1
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
90 #endif
444
ba637cc5c5f3 [project @ 1994-06-02 17:15:07 by jwe]
jwe
parents: 401
diff changeset
91
22019
2d8e9bdf5683 Dont use OCTAVE_USE_WINDOWS_API for w32_XXXX function definitions (Bug #48352)
John Donoghue
parents: 21989
diff changeset
92 #if defined (__MINGW32__) || defined (_MSC_VER)
13771
80b30e186b73 [Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13751
diff changeset
93
80b30e186b73 [Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13751
diff changeset
94 #define WIN32_LEAN_AND_MEAN
21949
baeffde5c87d fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
95 #include <windows.h>
13771
80b30e186b73 [Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13751
diff changeset
96 #include <tlhelp32.h>
21949
baeffde5c87d fix build for Windows systems
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
97 #include <shellapi.h>
13771
80b30e186b73 [Win32] Use Toolhelp32 APi to find octinterp module path.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 13751
diff changeset
98
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5395
diff changeset
99 #endif
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5395
diff changeset
100
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
101 namespace octave
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
102 {
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
103 #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
104
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
105 static void
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
106 BSD_init (void)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
107 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
108 # if defined (HAVE_FLOATINGPOINT_H)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
109 // Disable trapping on common exceptions.
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
110 # if ! defined (FP_X_DNML)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
111 # define FP_X_DNML 0
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
112 # endif
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
113 fpsetmask (~(FP_X_OFL|FP_X_INV|FP_X_DZ|FP_X_DNML|FP_X_UFL|FP_X_IMP));
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
114 # endif
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
115 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
116
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
117 #endif
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
118
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
119 #if defined (__MINGW32__) || defined (_MSC_VER)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
120
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
121 static void
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
122 w32_set_octave_home (void)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
123 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
124 std::string bin_dir;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
125
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
126 HANDLE h = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
127 #if defined (TH32CS_SNAPMODULE32)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
128 | TH32CS_SNAPMODULE32
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
129 #endif
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
130 , 0);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
131
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
132 if (h != INVALID_HANDLE_VALUE)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
133 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
134 MODULEENTRY32W mod_info;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
135
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
136 ZeroMemory (&mod_info, sizeof (mod_info));
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
137 mod_info.dwSize = sizeof (mod_info);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
138
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
139 if (Module32FirstW (h, &mod_info))
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
140 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
141 do
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
142 {
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
143 std::string mod_name (sys::u8_from_wstring (mod_info.szModule));
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
144
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
145 if (mod_name.find ("octinterp") != std::string::npos)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
146 {
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
147 bin_dir = sys::u8_from_wstring (mod_info.szExePath);
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
148 if (! bin_dir.empty () && bin_dir.back () != '\\')
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
149 bin_dir.push_back ('\\');
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
150 break;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
151 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
152 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
153 while (Module32NextW (h, &mod_info));
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
154 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
155
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
156 CloseHandle (h);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
157 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
158
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
159 if (! bin_dir.empty ())
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
160 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
161 size_t pos = bin_dir.rfind (R"(\bin\)");
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
162
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
163 if (pos != std::string::npos)
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
164 sys::env::putenv ("OCTAVE_HOME", bin_dir.substr (0, pos));
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
165 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
166 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
167
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
168 static void
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
169 w32_init (void)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
170 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
171 w32_set_octave_home ();
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
172
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
173 command_editor::prefer_env_winsize (true);
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
174 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
175
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
176 #endif
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
177
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
178 // Set app id if we have the SetCurrentProcessExplicitAppUserModelID
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
179 // available (>= Win7). FIXME: Could we check for existence of this
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
180 // function in the configure script instead of dynamically loading
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
181 // shell32.dll?
22165
20e684ec108e move system dependent code to sysdep.cc
John W. Eaton <jwe@octave.org>
parents: 22141
diff changeset
182
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
183 void set_application_id (void)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
184 {
22165
20e684ec108e move system dependent code to sysdep.cc
John W. Eaton <jwe@octave.org>
parents: 22141
diff changeset
185 #if defined (__MINGW32__) || defined (_MSC_VER)
20e684ec108e move system dependent code to sysdep.cc
John W. Eaton <jwe@octave.org>
parents: 22141
diff changeset
186
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
187 typedef HRESULT (WINAPI *SETCURRENTAPPID)(PCWSTR AppID);
22165
20e684ec108e move system dependent code to sysdep.cc
John W. Eaton <jwe@octave.org>
parents: 22141
diff changeset
188
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
189 HMODULE hShell = LoadLibrary ("shell32.dll");
22165
20e684ec108e move system dependent code to sysdep.cc
John W. Eaton <jwe@octave.org>
parents: 22141
diff changeset
190
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
191 if (hShell)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
192 {
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
193 SETCURRENTAPPID pfnSetCurrentProcessExplicitAppUserModelID
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
194 = reinterpret_cast<SETCURRENTAPPID> (GetProcAddress (hShell, "SetCurrentProcessExplicitAppUserModelID"));
22165
20e684ec108e move system dependent code to sysdep.cc
John W. Eaton <jwe@octave.org>
parents: 22141
diff changeset
195
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
196 if (pfnSetCurrentProcessExplicitAppUserModelID)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
197 pfnSetCurrentProcessExplicitAppUserModelID (L"gnu.octave." VERSION);
22165
20e684ec108e move system dependent code to sysdep.cc
John W. Eaton <jwe@octave.org>
parents: 22141
diff changeset
198
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
199 FreeLibrary (hShell);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
200 }
22165
20e684ec108e move system dependent code to sysdep.cc
John W. Eaton <jwe@octave.org>
parents: 22141
diff changeset
201
20e684ec108e move system dependent code to sysdep.cc
John W. Eaton <jwe@octave.org>
parents: 22141
diff changeset
202 #endif
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
203 }
22165
20e684ec108e move system dependent code to sysdep.cc
John W. Eaton <jwe@octave.org>
parents: 22141
diff changeset
204 }
20e684ec108e move system dependent code to sysdep.cc
John W. Eaton <jwe@octave.org>
parents: 22141
diff changeset
205
19856
5c1a38089f89 Change open_with_system_app to internal function.
Rik <rik@octave.org>
parents: 19849
diff changeset
206 DEFUN (__open_with_system_app__, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
207 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
208 @deftypefn {} {} __open_with_system_app__ (@var{file})
27143
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
209 Internal function. Returns 1 on successful system call and 0 otherwise.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
210 @end deftypefn */)
19271
030d56f67363 implement the open function
John W. Eaton <jwe@octave.org>
parents: 19270
diff changeset
211 {
20799
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
212 if (args.length () != 1)
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
213 print_usage ();
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
214
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
215 std::string file = args(0).xstring_value ("__open_with_system_app__: argument must be a filename");
19271
030d56f67363 implement the open function
John W. Eaton <jwe@octave.org>
parents: 19270
diff changeset
216
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21966
diff changeset
217 #if defined (OCTAVE_USE_WINDOWS_API)
27143
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
218 HINSTANCE status
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
219 = ShellExecuteW (0, 0, octave::sys::u8_to_wstring (file).c_str (),
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
220 0, 0, SW_SHOWNORMAL);
19271
030d56f67363 implement the open function
John W. Eaton <jwe@octave.org>
parents: 19270
diff changeset
221
20799
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
222 // ShellExecute returns a value greater than 32 if successful.
27143
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
223 return octave_value (reinterpret_cast<ptrdiff_t> (status) > 32);
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
224 #else
27346
1effc78e7cd1 open.m: Allow files with space in their path to be open.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27335
diff changeset
225 // Quote file path
1effc78e7cd1 open.m: Allow files with space in their path to be open.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27335
diff changeset
226 file = "\"" + file + "\"";
1effc78e7cd1 open.m: Allow files with space in their path to be open.
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 27335
diff changeset
227
27143
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
228 # if defined (__APPLE__)
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
229 # define FSYSTEM_OPEN_STR "open "
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
230 # else
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
231 # define FSYSTEM_OPEN_STR "xdg-open "
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
232 # endif
20961
f55251db0833 Add support for the Mac OS X "open" command.
Ben Abbott <bpabbott@mac.com>
parents: 20941
diff changeset
233 octave_value_list tmp
27143
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
234 = Fsystem (ovl (FSYSTEM_OPEN_STR + file + " 2> /dev/null",
20961
f55251db0833 Add support for the Mac OS X "open" command.
Ben Abbott <bpabbott@mac.com>
parents: 20941
diff changeset
235 false, "async"),
f55251db0833 Add support for the Mac OS X "open" command.
Ben Abbott <bpabbott@mac.com>
parents: 20941
diff changeset
236 1);
27143
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
237 # undef FSYSTEM_OPEN_STR
19271
030d56f67363 implement the open function
John W. Eaton <jwe@octave.org>
parents: 19270
diff changeset
238
27143
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
239 // Asynchronous Fsystem calls return the new child process identifier,
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
240 // which must be greater than 1 if successful.
64ff1053ffbf F__open_with_system_app__: Consistent return value for all platforms.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27126
diff changeset
241 return octave_value (tmp(0).double_value () > 1);
19774
904912f18357 make open_with_system_app a built-in function
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
242 #endif
19271
030d56f67363 implement the open function
John W. Eaton <jwe@octave.org>
parents: 19270
diff changeset
243 }
030d56f67363 implement the open function
John W. Eaton <jwe@octave.org>
parents: 19270
diff changeset
244
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
245 namespace octave
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
246 {
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5395
diff changeset
247 #if defined (__MINGW32__)
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
248
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
249 static void
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
250 MINGW_init (void)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
251 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
252 w32_init ();
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
253 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
254
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5395
diff changeset
255 #endif
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5395
diff changeset
256
6080
40ab35ab651c [project @ 2006-10-25 03:26:36 by jwe]
jwe
parents: 5823
diff changeset
257 #if defined (_MSC_VER)
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
258
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
259 static void
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
260 MSVC_init (void)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
261 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
262 w32_init ();
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
263 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
264
6080
40ab35ab651c [project @ 2006-10-25 03:26:36 by jwe]
jwe
parents: 5823
diff changeset
265 #endif
40ab35ab651c [project @ 2006-10-25 03:26:36 by jwe]
jwe
parents: 5823
diff changeset
266
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
267 // Return TRUE if FILE1 and FILE2 refer to the same (physical) file.
6598
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6423
diff changeset
268
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
269 bool same_file_internal (const std::string& file1, const std::string& file2)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
270 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21662
diff changeset
271 #if defined (OCTAVE_USE_WINDOWS_API)
6598
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6423
diff changeset
272
27576
3b50efa29be4 improve file equaliy check for MS Windows (bug #55161).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27420
diff changeset
273 // FIXME: When Octave switches to C++17, consider replacing this function
3b50efa29be4 improve file equaliy check for MS Windows (bug #55161).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27420
diff changeset
274 // by https://en.cppreference.com/w/cpp/filesystem/equivalent.
3b50efa29be4 improve file equaliy check for MS Windows (bug #55161).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27420
diff changeset
275
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
276 bool retval = false;
6691
c6ee6c342699 [project @ 2007-06-05 05:50:10 by jwe]
jwe
parents: 6677
diff changeset
277
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
278 std::wstring file1w = sys::u8_to_wstring (file1);
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
279 std::wstring file2w = sys::u8_to_wstring (file2);
25714
ad0b4817c09d Fix lifetime issue with C string references from C++ strings (bug #54398)
Markus Mützel <markus.muetzel@gmx.de>
parents: 25655
diff changeset
280 const wchar_t *f1 = file1w.c_str ();
ad0b4817c09d Fix lifetime issue with C string references from C++ strings (bug #54398)
Markus Mützel <markus.muetzel@gmx.de>
parents: 25655
diff changeset
281 const wchar_t *f2 = file2w.c_str ();
16564
aa5299a1d770 * sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents: 16537
diff changeset
282
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
283 bool f1_is_dir = GetFileAttributesW (f1) & FILE_ATTRIBUTE_DIRECTORY;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
284 bool f2_is_dir = GetFileAttributesW (f2) & FILE_ATTRIBUTE_DIRECTORY;
16564
aa5299a1d770 * sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents: 16537
diff changeset
285
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
286 // Windows native code
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
287 // Reference: http://msdn2.microsoft.com/en-us/library/aa363788.aspx
6598
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6423
diff changeset
288
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
289 DWORD share = FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE;
16564
aa5299a1d770 * sysdep.cc (same_file_internal): Handle directories on Windows systems.
John W. Eaton <jwe@octave.org>
parents: 16537
diff changeset
290
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
291 HANDLE hfile1
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
292 = CreateFileW (f1, 0, share, 0, OPEN_EXISTING,
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
293 f1_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0);
6691
c6ee6c342699 [project @ 2007-06-05 05:50:10 by jwe]
jwe
parents: 6677
diff changeset
294
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
295 if (hfile1 != INVALID_HANDLE_VALUE)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
296 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
297 HANDLE hfile2
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
298 = CreateFileW (f2, 0, share, 0, OPEN_EXISTING,
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
299 f2_is_dir ? FILE_FLAG_BACKUP_SEMANTICS : 0, 0);
6598
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6423
diff changeset
300
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
301 if (hfile2 != INVALID_HANDLE_VALUE)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
302 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
303 BY_HANDLE_FILE_INFORMATION hfi1;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
304 BY_HANDLE_FILE_INFORMATION hfi2;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
305
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
306 if (GetFileInformationByHandle (hfile1, &hfi1)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
307 && GetFileInformationByHandle (hfile2, &hfi2))
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
308 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
309 retval = (hfi1.dwVolumeSerialNumber == hfi2.dwVolumeSerialNumber
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
310 && hfi1.nFileIndexHigh == hfi2.nFileIndexHigh
27576
3b50efa29be4 improve file equaliy check for MS Windows (bug #55161).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27420
diff changeset
311 && hfi1.nFileIndexLow == hfi2.nFileIndexLow
3b50efa29be4 improve file equaliy check for MS Windows (bug #55161).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27420
diff changeset
312 && hfi1.nFileSizeHigh == hfi2.nFileSizeHigh
3b50efa29be4 improve file equaliy check for MS Windows (bug #55161).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27420
diff changeset
313 && hfi1.nFileSizeLow == hfi2.nFileSizeLow
3b50efa29be4 improve file equaliy check for MS Windows (bug #55161).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27420
diff changeset
314 && hfi1.ftLastWriteTime.dwLowDateTime
3b50efa29be4 improve file equaliy check for MS Windows (bug #55161).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27420
diff changeset
315 == hfi2.ftLastWriteTime.dwLowDateTime
3b50efa29be4 improve file equaliy check for MS Windows (bug #55161).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27420
diff changeset
316 && hfi1.ftLastWriteTime.dwHighDateTime
3b50efa29be4 improve file equaliy check for MS Windows (bug #55161).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 27420
diff changeset
317 == hfi2.ftLastWriteTime.dwHighDateTime);
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
318 }
6598
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6423
diff changeset
319
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
320 CloseHandle (hfile2);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
321 }
6691
c6ee6c342699 [project @ 2007-06-05 05:50:10 by jwe]
jwe
parents: 6677
diff changeset
322
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
323 CloseHandle (hfile1);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
324 }
6691
c6ee6c342699 [project @ 2007-06-05 05:50:10 by jwe]
jwe
parents: 6677
diff changeset
325
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
326 return retval;
6598
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6423
diff changeset
327
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6423
diff changeset
328 #else
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6423
diff changeset
329
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
330 // POSIX Code
6598
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6423
diff changeset
331
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
332 sys::file_stat fs_file1 (file1);
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
333 sys::file_stat fs_file2 (file2);
6598
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6423
diff changeset
334
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
335 return (fs_file1 && fs_file2
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
336 && fs_file1.ino () == fs_file2.ino ()
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
337 && fs_file1.dev () == fs_file2.dev ());
6598
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6423
diff changeset
338
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6423
diff changeset
339 #endif
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
340 }
6598
ce819776ee76 [project @ 2007-04-27 17:34:27 by jwe]
jwe
parents: 6423
diff changeset
341
26843
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
342 // Return TRUE if NAME refers to an existing drive letter or UNC share
26995
ab5bfee22d18 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26844
diff changeset
343
26843
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
344 bool drive_or_unc_share (const std::string& name)
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
345 {
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
346 #if defined (OCTAVE_USE_WINDOWS_API)
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
347 size_t len = name.length ();
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
348 bool candidate = false;
26995
ab5bfee22d18 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26844
diff changeset
349 if (len > 1 && isalpha(name[0]) && name[1]==':'
26844
d8712d26d086 Fix error in previous commit.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26843
diff changeset
350 && (len == 2 || (len == 3 && name[2] == '\\')))
26843
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
351 candidate = true;
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
352 if (len > 4 && name[0] == '\\' && name[1] == '\\')
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
353 {
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
354 // It starts with two slashes. Find the next slash.
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
355 size_t next_slash = name.find ("\\", 3);
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
356 if (next_slash != -1 && len > next_slash+1)
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
357 {
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
358 // Check if it ends with the share
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
359 size_t last_slash = name.find ("\\", next_slash+1);
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
360 if (last_slash == -1 || (len > next_slash+2 && last_slash == len-1))
26843
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
361 candidate = true;
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
362 }
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
363 }
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
364
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
365 if (candidate)
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
366 {
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
367 // Open a handle to the file.
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
368 std::wstring wname = sys::u8_to_wstring (name);
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
369 HANDLE h
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
370 = CreateFileW (wname.c_str (), FILE_READ_ATTRIBUTES,
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
371 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
372 nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS,
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
373 nullptr);
26843
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
374 if (h != INVALID_HANDLE_VALUE)
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
375 {
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
376 CloseHandle (h);
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
377 return true;
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
378 }
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
379 }
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
380
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
381 return false;
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
382
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
383 #else
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
384
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
385 octave_unused_parameter (name);
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
386
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
387 return false;
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
388
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
389 #endif
f07542e3a9b9 Fix "exist" for drive letters and UNC shares on Windows (bug #55824).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26617
diff changeset
390 }
26995
ab5bfee22d18 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26844
diff changeset
391
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
392 void sysdep_init (void)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
393 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
394 // Use a function from libgomp to force loading of OpenMP library.
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
395 // Otherwise, a dynamically loaded library making use of OpenMP such
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
396 // as GraphicsMagick will segfault on exit (bug #41699).
21554
9f0088f3f335 call openmp function at initialization (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20788
diff changeset
397 #if defined (HAVE_OMP_GET_NUM_THREADS)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
398 omp_get_num_threads ();
21554
9f0088f3f335 call openmp function at initialization (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20788
diff changeset
399 #endif
9f0088f3f335 call openmp function at initialization (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20788
diff changeset
400
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14445
diff changeset
401 #if defined (__386BSD__) || defined (__FreeBSD__) || defined (__NetBSD__)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
402 BSD_init ();
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5395
diff changeset
403 #elif defined (__MINGW32__)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
404 MINGW_init ();
6080
40ab35ab651c [project @ 2006-10-25 03:26:36 by jwe]
jwe
parents: 5823
diff changeset
405 #elif defined (_MSC_VER)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
406 MSVC_init ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
407 #endif
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
408 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
409
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
410 void sysdep_cleanup (void)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
411 {
21989
6bce4d23af6b eliminate OCTAVE_USE_WINDOWS_API and OCTAVE_USE_OS_X_API from header files
John W. Eaton <jwe@octave.org>
parents: 21979
diff changeset
412 #if defined (OCTAVE_USE_WINDOWS_API)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
413 // Let us fail immediately without displaying any dialog.
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
414 SetProcessShutdownParameters (0x280, SHUTDOWN_NORETRY);
21989
6bce4d23af6b eliminate OCTAVE_USE_WINDOWS_API and OCTAVE_USE_OS_X_API from header files
John W. Eaton <jwe@octave.org>
parents: 21979
diff changeset
415 #endif
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
416 }
5451
ed08548b9054 [project @ 2005-09-15 19:52:50 by jwe]
jwe
parents: 5395
diff changeset
417
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
418 // Set terminal in raw mode. From less-177.
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
419 //
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
420 // Change terminal to "raw mode", or restore to "normal" mode.
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
421 // "Raw mode" means
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
422 // 1. An outstanding read will complete on receipt of a single keystroke.
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
423 // 2. Input is not echoed.
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
424 // 3. On output, \n is mapped to \r\n.
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
425 // 4. \t is NOT expanded into spaces.
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
426 // 5. Signal-causing characters such as ctrl-C (interrupt),
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
427 // etc. are NOT disabled.
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
428 // It doesn't matter whether an input \n is mapped to \r, or vice versa.
767
42731861ee09 [project @ 1994-10-05 21:26:54 by jwe]
jwe
parents: 712
diff changeset
429
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
430 void raw_mode (bool on, bool wait)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
431 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
432 static bool curr_on = false;
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
433
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
434 int tty_fd = STDIN_FILENO;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
435 if (! octave_isatty_wrapper (tty_fd))
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
436 {
27301
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
437 interpreter& interp = __get_interpreter__ ("raw_mode");
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
438
a2b1ba6c92d5 eliminate unnecessary application::interative function
John W. Eaton <jwe@octave.org>
parents: 27277
diff changeset
439 if (interp.interactive () && ! application::forced_interactive ())
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
440 error ("stdin is not a tty!");
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
441 }
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
442
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
443 if (on == curr_on)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
444 return;
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
445
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
446 #if defined (HAVE_TERMIOS_H)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
447 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
448 struct termios s;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
449 static struct termios save_term;
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
450
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
451 if (on)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
452 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
453 // Get terminal modes.
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
454
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
455 tcgetattr (tty_fd, &s);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
456
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
457 // Save modes and set certain variables dependent on modes.
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
458
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
459 save_term = s;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
460 // ospeed = s.c_cflag & CBAUD;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
461 // erase_char = s.c_cc[VERASE];
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
462 // kill_char = s.c_cc[VKILL];
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
463
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
464 // Set the modes to the way we want them.
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
465
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
466 s.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
467 s.c_oflag |= (OPOST | ONLCR);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
468 #if defined (OCRNL)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
469 s.c_oflag &= ~(OCRNL);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
470 #endif
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
471 #if defined (ONOCR)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
472 s.c_oflag &= ~(ONOCR);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
473 #endif
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
474 #if defined (ONLRET)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
475 s.c_oflag &= ~(ONLRET);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
476 #endif
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
477 s.c_cc[VMIN] = (wait ? 1 : 0);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
478 s.c_cc[VTIME] = 0;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
479 }
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
480 else
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
481 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
482 // Restore saved modes.
1358
dc9c01f66a19 [project @ 1995-09-05 21:10:01 by jwe]
jwe
parents: 1352
diff changeset
483
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
484 s = save_term;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
485 }
3658
808f399398c9 [project @ 2000-04-11 19:45:44 by jwe]
jwe
parents: 3657
diff changeset
486
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
487 tcsetattr (tty_fd, wait ? TCSAFLUSH : TCSADRAIN, &s);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
488 }
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
489 #elif defined (HAVE_TERMIO_H)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
490 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
491 struct termio s;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
492 static struct termio save_term;
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
493
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
494 if (on)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
495 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
496 // Get terminal modes.
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
497
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
498 ioctl (tty_fd, TCGETA, &s);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
499
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
500 // Save modes and set certain variables dependent on modes.
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
501
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
502 save_term = s;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
503 // ospeed = s.c_cflag & CBAUD;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
504 // erase_char = s.c_cc[VERASE];
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
505 // kill_char = s.c_cc[VKILL];
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
506
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
507 // Set the modes to the way we want them.
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
508
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
509 s.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
510 s.c_oflag |= (OPOST | ONLCR);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
511 #if defined (OCRNL)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
512 s.c_oflag &= ~(OCRNL);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
513 #endif
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
514 #if defined (ONOCR)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
515 s.c_oflag &= ~(ONOCR);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
516 #endif
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
517 #if defined (ONLRET)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
518 s.c_oflag &= ~(ONLRET);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
519 #endif
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
520 s.c_cc[VMIN] = (wait ? 1 : 0);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
521 }
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
522 else
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
523 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
524 // Restore saved modes.
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
525
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
526 s = save_term;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
527 }
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
528
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
529 ioctl (tty_fd, TCSETAW, &s);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
530 }
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
531 #elif defined (HAVE_SGTTY_H)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
532 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
533 octave_unused_parameter (wait);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
534
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
535 struct sgttyb s;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
536 static struct sgttyb save_term;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
537
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
538 if (on)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
539 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
540 // Get terminal modes.
1358
dc9c01f66a19 [project @ 1995-09-05 21:10:01 by jwe]
jwe
parents: 1352
diff changeset
541
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
542 ioctl (tty_fd, TIOCGETP, &s);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
543
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
544 // Save modes and set certain variables dependent on modes.
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
545
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
546 save_term = s;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
547 // ospeed = s.sg_ospeed;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
548 // erase_char = s.sg_erase;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
549 // kill_char = s.sg_kill;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
550
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
551 // Set the modes to the way we want them.
3658
808f399398c9 [project @ 2000-04-11 19:45:44 by jwe]
jwe
parents: 3657
diff changeset
552
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
553 s.sg_flags |= CBREAK;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
554 s.sg_flags &= ~(ECHO);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
555 }
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
556 else
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
557 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
558 // Restore saved modes.
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
559
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
560 s = save_term;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
561 }
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
562
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
563 ioctl (tty_fd, TIOCSETN, &s);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
564 }
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
565 #else
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
566
24118
f87c9f5c0f43 maint: silence several compiler warnings when building for Windows
Mike Miller <mtmiller@octave.org>
parents: 23812
diff changeset
567 octave_unused_parameter (wait);
f87c9f5c0f43 maint: silence several compiler warnings when building for Windows
Mike Miller <mtmiller@octave.org>
parents: 23812
diff changeset
568
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
569 warn_disabled_feature ("", "raw mode console I/O");
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
570
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
571 // Make sure the current mode doesn't toggle.
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
572 on = curr_on;
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
573 #endif
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
574
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
575 curr_on = on;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
576 }
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
577
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
578 FILE * popen (const char *command, const char *mode)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
579 {
6726
6b7ba4a31876 [project @ 2007-06-14 20:16:44 by jwe]
jwe
parents: 6691
diff changeset
580 #if defined (__MINGW32__) || defined (_MSC_VER)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
581 wchar_t *wcommand = u8_to_wchar (command);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
582 wchar_t *wmode = u8_to_wchar (mode);
25530
197126863d95 sysdep.cc: Use wide character versions of Windows API functions (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25311
diff changeset
583
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
584 unwind_protect frame;
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
585 frame.add_fcn (::free, static_cast<void *> (wcommand));
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
586 frame.add_fcn (::free, static_cast<void *> (wmode));
25530
197126863d95 sysdep.cc: Use wide character versions of Windows API functions (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25311
diff changeset
587
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
588 if (wmode && wmode[0] && ! wmode[1])
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
589 {
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
590 // Use binary mode on Windows if unspecified
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
591 wchar_t tmode[3] = {wmode[0], L'b', L'\0'};
6726
6b7ba4a31876 [project @ 2007-06-14 20:16:44 by jwe]
jwe
parents: 6691
diff changeset
592
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
593 return _wpopen (wcommand, tmode);
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
594 }
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
595 else
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
596 return _wpopen (wcommand, wmode);
6726
6b7ba4a31876 [project @ 2007-06-14 20:16:44 by jwe]
jwe
parents: 6691
diff changeset
597 #else
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
598 return ::popen (command, mode);
6726
6b7ba4a31876 [project @ 2007-06-14 20:16:44 by jwe]
jwe
parents: 6691
diff changeset
599 #endif
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
600 }
6726
6b7ba4a31876 [project @ 2007-06-14 20:16:44 by jwe]
jwe
parents: 6691
diff changeset
601
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
602 int pclose (FILE *f)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
603 {
6726
6b7ba4a31876 [project @ 2007-06-14 20:16:44 by jwe]
jwe
parents: 6691
diff changeset
604 #if defined (__MINGW32__) || defined (_MSC_VER)
25655
be7ba25bb5bf Fix Windows cross-build after 85c3e315bd43.
Markus Mützel <markus.muetzel@gmx.de>
parents: 25649
diff changeset
605 return ::_pclose (f);
6726
6b7ba4a31876 [project @ 2007-06-14 20:16:44 by jwe]
jwe
parents: 6691
diff changeset
606 #else
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
607 return ::pclose (f);
6726
6b7ba4a31876 [project @ 2007-06-14 20:16:44 by jwe]
jwe
parents: 6691
diff changeset
608 #endif
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
609 }
6726
6b7ba4a31876 [project @ 2007-06-14 20:16:44 by jwe]
jwe
parents: 6691
diff changeset
610
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
611 // Read one character from the terminal.
767
42731861ee09 [project @ 1994-10-05 21:26:54 by jwe]
jwe
parents: 712
diff changeset
612
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
613 int kbhit (bool wait)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
614 {
20788
a2b96b523472 Rewrite a8ee668e7fd7 to use #if defined rather than #ifdef.
Rik <rik@octave.org>
parents: 20786
diff changeset
615 #if defined (HAVE__KBHIT) && defined (HAVE__GETCH)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
616 // This essentially means we are on a Windows system.
27045
7894624afc47 Fix pause() with no arguments called on Windows (bug #55943)
Mike Miller <mtmiller@octave.org>
parents: 27011
diff changeset
617
7894624afc47 Fix pause() with no arguments called on Windows (bug #55943)
Mike Miller <mtmiller@octave.org>
parents: 27011
diff changeset
618 // The value to return when wait is false and no input is ready.
7894624afc47 Fix pause() with no arguments called on Windows (bug #55943)
Mike Miller <mtmiller@octave.org>
parents: 27011
diff changeset
619 static constexpr int eof = std::istream::traits_type::eof ();
7894624afc47 Fix pause() with no arguments called on Windows (bug #55943)
Mike Miller <mtmiller@octave.org>
parents: 27011
diff changeset
620
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
621 int c;
20786
a8ee668e7fd7 Fix kbhit and pause on Windows systems.
Rik <rik@octave.org>
parents: 20181
diff changeset
622
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
623 if (wait)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
624 c = _getch ();
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
625 else
27045
7894624afc47 Fix pause() with no arguments called on Windows (bug #55943)
Mike Miller <mtmiller@octave.org>
parents: 27011
diff changeset
626 c = (! _kbhit ()) ? eof : _getch ();
20786
a8ee668e7fd7 Fix kbhit and pause on Windows systems.
Rik <rik@octave.org>
parents: 20181
diff changeset
627
4067
e97fb79fc1d5 [project @ 2002-09-26 22:43:25 by jwe]
jwe
parents: 4064
diff changeset
628 #else
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
629 raw_mode (true, wait);
3658
808f399398c9 [project @ 2000-04-11 19:45:44 by jwe]
jwe
parents: 3657
diff changeset
630
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
631 // Get current handler.
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
632 interrupt_handler saved_interrupt_handler
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
633 = ignore_interrupts ();
5770
6a9244f89a2a [project @ 2006-04-18 17:44:33 by jwe]
jwe
parents: 5455
diff changeset
634
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
635 // Restore it, disabling system call restarts (if possible) so the
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
636 // read can be interrupted.
5770
6a9244f89a2a [project @ 2006-04-18 17:44:33 by jwe]
jwe
parents: 5455
diff changeset
637
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
638 set_interrupt_handler (saved_interrupt_handler, false);
5770
6a9244f89a2a [project @ 2006-04-18 17:44:33 by jwe]
jwe
parents: 5455
diff changeset
639
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
640 int c = std::cin.get ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
641
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
642 if (std::cin.fail () || std::cin.eof ())
27011
c3716220d5b9 fix pause and kbhit with glibc 2.28 end-of-file state behavior (bug #55029)
Mike Miller <mtmiller@octave.org>
parents: 26617
diff changeset
643 {
c3716220d5b9 fix pause and kbhit with glibc 2.28 end-of-file state behavior (bug #55029)
Mike Miller <mtmiller@octave.org>
parents: 26617
diff changeset
644 std::cin.clear ();
c3716220d5b9 fix pause and kbhit with glibc 2.28 end-of-file state behavior (bug #55029)
Mike Miller <mtmiller@octave.org>
parents: 26617
diff changeset
645 clearerr (stdin);
c3716220d5b9 fix pause and kbhit with glibc 2.28 end-of-file state behavior (bug #55029)
Mike Miller <mtmiller@octave.org>
parents: 26617
diff changeset
646 }
3658
808f399398c9 [project @ 2000-04-11 19:45:44 by jwe]
jwe
parents: 3657
diff changeset
647
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
648 // Restore it, enabling system call restarts (if possible).
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
649 set_interrupt_handler (saved_interrupt_handler, true);
5770
6a9244f89a2a [project @ 2006-04-18 17:44:33 by jwe]
jwe
parents: 5455
diff changeset
650
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
651 raw_mode (false, true);
4067
e97fb79fc1d5 [project @ 2002-09-26 22:43:25 by jwe]
jwe
parents: 4064
diff changeset
652 #endif
3658
808f399398c9 [project @ 2000-04-11 19:45:44 by jwe]
jwe
parents: 3657
diff changeset
653
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
654 return c;
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
655 }
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
656
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
657 std::string get_P_tmpdir (void)
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
658 {
21979
d04da18a407a use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents: 21966
diff changeset
659 #if defined (OCTAVE_USE_WINDOWS_API)
12228
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
660
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
661 std::string retval;
12228
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
662
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
663 #if defined (P_tmpdir)
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
664 retval = P_tmpdir;
12228
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
665 #endif
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
666
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
667 // Apparently some versions of MinGW and MSVC either don't define
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
668 // P_tmpdir, or they define it to a single backslash, neither of which
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
669 // is particularly helpful.
12228
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
670
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
671 if (retval.empty () || retval == R"(\)")
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
672 {
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
673 retval = sys::env::getenv ("TEMP");
12228
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
674
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
675 if (retval.empty ())
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
676 retval = sys::env::getenv ("TMP");
12228
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
677
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
678 if (retval.empty ())
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
679 retval = R"(c:\temp)";
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
680 }
12228
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
681
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
682 return retval;
12228
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
683
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
684 #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
685
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
686 return P_tmpdir;
12228
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
687
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
688 #else
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
689
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
690 return "/tmp";
12228
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
691
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
692 #endif
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
693 }
12228
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
694 }
0f70c5db58c3 try to get better value than \ for P_tmpdir on Windows systems
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
695
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
696 DEFUN (clc, , ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
697 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
698 @deftypefn {} {} clc ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
699 @deftypefnx {} {} home ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
700 Clear the terminal screen and move the cursor to the upper left corner.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
701 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
702 {
16537
106a38d7b396 optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents: 16404
diff changeset
703 bool skip_redisplay = true;
106a38d7b396 optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents: 16404
diff changeset
704
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
705 octave::command_editor::clear_screen (skip_redisplay);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
706
20941
a4f5da7c5463 maint: Replace "octave_value_list ()" with "ovl ()".
Rik <rik@octave.org>
parents: 20940
diff changeset
707 return ovl ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
708 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
709
549
75a371805554 [project @ 1994-07-22 19:44:41 by jwe]
jwe
parents: 545
diff changeset
710 DEFALIAS (home, clc);
75a371805554 [project @ 1994-07-22 19:44:41 by jwe]
jwe
parents: 545
diff changeset
711
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
712 DEFUN (getenv, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
713 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
714 @deftypefn {} {} getenv (@var{var})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
715 Return the value of the environment variable @var{var}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
716
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
717 For example,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
718
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
719 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
720 getenv ("PATH")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
721 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
722
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
723 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
724 returns a string containing the value of your path.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
725 @seealso{setenv, unsetenv}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
726 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
727 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20799
diff changeset
728 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
729 print_usage ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
730
20799
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
731 std::string name = args(0).string_value ();
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
732
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
733 return ovl (octave::sys::env::getenv (name));
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
734 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
735
19167
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
736 /*
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
737 %!assert (ischar (getenv ("OCTAVE_HOME")))
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
738 */
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
739
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
740 DEFUN (setenv, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
741 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
742 @deftypefn {} {} setenv (@var{var}, @var{value})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
743 @deftypefnx {} {} setenv (@var{var})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
744 @deftypefnx {} {} putenv (@dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
745 Set the value of the environment variable @var{var} to @var{value}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
746
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
747 If no @var{value} is specified then the variable will be assigned the null
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
748 string.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
749 @seealso{unsetenv, getenv}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
750 @end deftypefn */)
1706
6bb0c67bbf24 [project @ 1996-01-07 05:40:05 by jwe]
jwe
parents: 1670
diff changeset
751 {
6bb0c67bbf24 [project @ 1996-01-07 05:40:05 by jwe]
jwe
parents: 1670
diff changeset
752 int nargin = args.length ();
6bb0c67bbf24 [project @ 1996-01-07 05:40:05 by jwe]
jwe
parents: 1670
diff changeset
753
20799
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
754 if (nargin < 1 || nargin > 2)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
755 print_usage ();
1706
6bb0c67bbf24 [project @ 1996-01-07 05:40:05 by jwe]
jwe
parents: 1670
diff changeset
756
20799
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
757 std::string var = args(0).xstring_value ("setenv: VAR must be a string");
1706
6bb0c67bbf24 [project @ 1996-01-07 05:40:05 by jwe]
jwe
parents: 1670
diff changeset
758
20799
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
759 std::string val = (nargin == 2
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
760 ? args(1).xstring_value ("setenv: VALUE must be a string")
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20990
diff changeset
761 : "");
20582
ba2b07c13913 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
762
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
763 octave::sys::env::putenv (var, val);
1706
6bb0c67bbf24 [project @ 1996-01-07 05:40:05 by jwe]
jwe
parents: 1670
diff changeset
764
21078
49852ff04747 maint: Remove unnecessary declarations of retval.
Rik <rik@octave.org>
parents: 21017
diff changeset
765 return ovl ();
1706
6bb0c67bbf24 [project @ 1996-01-07 05:40:05 by jwe]
jwe
parents: 1670
diff changeset
766 }
12825
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
767
19167
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
768 DEFALIAS (putenv, setenv);
1706
6bb0c67bbf24 [project @ 1996-01-07 05:40:05 by jwe]
jwe
parents: 1670
diff changeset
769
12825
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
770 /*
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
771 %!test
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
772 %! 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
773 %! assert (getenv ("dummy_variable_that_cannot_matter"), "foobar");
19167
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
774 %! unsetenv ("dummy_variable_that_cannot_matter");
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
775 %! assert (getenv ("dummy_variable_that_cannot_matter"), "");
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
776 */
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
777
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
778 DEFUN (unsetenv, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
779 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
780 @deftypefn {} {@var{status} =} unsetenv (@var{var})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
781 Delete the environment variable @var{var}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
782
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
783 Return 0 if the variable was deleted, or did not exist, and -1 if an error
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
784 occurred.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
785 @seealso{setenv, getenv}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
786 @end deftypefn */)
19167
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
787 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20799
diff changeset
788 if (args.length () != 1)
19167
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
789 print_usage ();
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
790
20799
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
791 std::string tmp = args(0).string_value ();
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
792
25916
3f2282954600 Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents: 25714
diff changeset
793 return ovl (octave::sys::unsetenv_wrapper (tmp));
19167
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
794 }
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
795
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
796 /*
6f0290863d50 Add new function unsetenv from gnulib to Octave.
Rik <rik@octave.org>
parents: 18674
diff changeset
797 ## 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
798 */
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
799
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
800 #if defined (OCTAVE_USE_WINDOWS_API)
24710
a979bb895b64 avoid reinterpret_cast on function pointer in previous change
John W. Eaton <jwe@octave.org>
parents: 24709
diff changeset
801
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
802 namespace octave
24710
a979bb895b64 avoid reinterpret_cast on function pointer in previous change
John W. Eaton <jwe@octave.org>
parents: 24709
diff changeset
803 {
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
804 static void
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
805 reg_close_key_wrapper (HKEY key)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
806 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
807 RegCloseKey (key);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
808 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
809
27126
3d9e72cac668 allow Windows build to work again
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
810 // This function is also used in ov-java.cc, so don't declare static.
3d9e72cac668 allow Windows build to work again
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
811 // Maybe the functions that use it should be here instead?
3d9e72cac668 allow Windows build to work again
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
812
3d9e72cac668 allow Windows build to work again
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
813 LONG
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
814 get_regkey_value (HKEY h_rootkey, const std::string subkey,
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
815 const std::string name, octave_value& value)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
816 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
817 LONG result;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
818 HKEY h_subkey;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
819
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
820 result = RegOpenKeyExW (h_rootkey,
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
821 sys::u8_to_wstring (subkey).c_str (), 0,
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
822 KEY_READ, &h_subkey);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
823 if (result != ERROR_SUCCESS)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
824 return result;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
825
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
826 unwind_protect frame;
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
827
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
828 frame.add_fcn (reg_close_key_wrapper, h_subkey);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
829
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
830 DWORD length = 0;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
831 result = RegQueryValueExW (h_subkey,
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
832 sys::u8_to_wstring (name).c_str (),
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
833 nullptr, nullptr, nullptr, &length);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
834 if (result != ERROR_SUCCESS)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
835 return result;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
836
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
837 DWORD type = 0;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
838 OCTAVE_LOCAL_BUFFER (BYTE, data, length);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
839 result = RegQueryValueExW (h_subkey,
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
840 sys::u8_to_wstring (name).c_str (),
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
841 nullptr, &type, data, &length);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
842 if (result != ERROR_SUCCESS)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
843 return result;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
844
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
845 if (type == REG_DWORD)
27421
edeacebc8800 maint: merge stable to default.
Rik <rik@octave.org>
parents: 27346 27420
diff changeset
846 value = octave_int32 (*(reinterpret_cast<DWORD *> (data)));
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
847 else if (type == REG_SZ || type == REG_EXPAND_SZ)
27276
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27143
diff changeset
848 value = string_vector (sys::u8_from_wstring (reinterpret_cast<wchar_t *> (data)));
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
849
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
850 return result;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
851 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
852
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
853 static LONG
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
854 get_regkey_names (HKEY h_rootkey, const std::string subkey,
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
855 std::list<std::string> &fields)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
856 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
857 LONG retval;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
858 HKEY h_subkey;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
859
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
860 fields.clear ();
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
861
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
862 retval = RegOpenKeyExW (h_rootkey,
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
863 sys::u8_to_wstring (subkey).c_str (), 0,
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
864 KEY_READ, &h_subkey);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
865 if (retval != ERROR_SUCCESS)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
866 return retval;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
867
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
868 DWORD idx = 0;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
869 const int MAX_VALUE_NAME_SIZE = 32766;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
870 wchar_t value_name[MAX_VALUE_NAME_SIZE+1];
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
871 DWORD value_name_size = MAX_VALUE_NAME_SIZE;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
872
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
873 while (true)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
874 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
875 retval = RegEnumValueW (h_subkey, idx, value_name, &value_name_size,
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
876 nullptr, nullptr, nullptr, nullptr);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
877 if (retval != ERROR_SUCCESS)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
878 break;
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27101
diff changeset
879 fields.push_back (sys::u8_from_wstring (value_name));
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
880 value_name_size = MAX_VALUE_NAME_SIZE;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
881 idx++;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
882 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
883
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
884 if (retval == ERROR_NO_MORE_ITEMS)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
885 retval = ERROR_SUCCESS;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
886
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
887 RegCloseKey (h_subkey);
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
888
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
889 return retval;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
890 }
24710
a979bb895b64 avoid reinterpret_cast on function pointer in previous change
John W. Eaton <jwe@octave.org>
parents: 24709
diff changeset
891 }
a979bb895b64 avoid reinterpret_cast on function pointer in previous change
John W. Eaton <jwe@octave.org>
parents: 24709
diff changeset
892
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
893 #endif
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
894
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
895 DEFUN (winqueryreg, args, ,
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
896 doc: /* -*- texinfo -*-
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
897 @deftypefn {} {@var{value} =} winqueryreg (@var{rootkey}, @var{subkey}, @var{valuename})
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
898 @deftypefnx {} {@var{value} =} winqueryreg (@var{rootkey}, @var{subkey})
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
899 @deftypefnx {} {@var{names} =} winqueryreg (@code{"name"}, @var{rootkey}, @var{subkey})
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
900
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
901 Query names or value from the Windows registry.
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
902
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
903 On Windows, return the value of the registry key @var{subkey} from the root key
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
904 @var{rootkey}. You can specify the name of the queried registry value with the
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
905 optional argument @var{valuename}. Otherwise, if called with only two
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
906 arguments or @var{valuename} is empty, then the default value of @var{subkey}
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
907 is returned. If the registry value is of type @nospell{@qcode{"REG_DWORD"}}
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
908 then @var{value} is of class int32. If the value is of the type
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
909 @nospell{@qcode{"REG_SZ"}} or @nospell{@qcode{"REG_EXPAND_SZ"}} a string is
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
910 returned.
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
911
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
912 If the first argument is @qcode{"name"}, a cell array of strings with the names
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
913 of the values at that key is returned.
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
914
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
915 The variable @var{rootkey} must be a string with a valid root key identifier:
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
916
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
917 @table @asis
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
918 @item @nospell{HKCR}
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
919 @itemx @nospell{HKEY_CLASSES_ROOT}
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
920
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
921 @item @nospell{HKEY_CURRENT_CONFIG}
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
922
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
923 @item @nospell{HKCU}
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
924 @itemx @nospell{HKEY_CURRENT_USER}
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
925
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
926 @item @nospell{HKLM}
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
927 @itemx @nospell{HKEY_LOCAL_MACHINE}
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
928
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
929
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
930 @item @nospell{HKU}
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
931 @itemx @nospell{HKEY_USERS}
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
932
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
933
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
934 @item @nospell{HKEY_PERFORMANCE_DATA}
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
935
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
936 @end table
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
937
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
938 Examples:
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
939
25003
2365c2661b3c doc: Spellcheck documentation ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24720
diff changeset
940 Get a list of value names at the key @nospell{@qcode{'HKCU\Environment'}}:
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
941
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
942 @example
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
943 @group
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
944 @var{valuenames} = winqueryreg ("name", "HKEY_CURRENT_USER", ...
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
945 "Environment");
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
946 @end group
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
947 @end example
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
948
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
949 For each @var{valuenames}, display the value:
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
950
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
951 @example
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
952 @group
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
953 for @var{k} = 1:numel (@var{valuenames})
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
954 @var{val} = winqueryreg ("HKEY_CURRENT_USER", "Environment", ...
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
955 @var{valuenames}@{@var{k}@});
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
956 @var{str} = sprintf ("%s = %s", @var{valuenames}@{@var{k}@}, num2str (@var{val}));
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
957 disp (@var{str});
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
958 endfor
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
959 @end group
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
960 @end example
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
961
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
962 On non-Windows platforms this function fails with an error.
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
963 @end deftypefn */)
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
964 {
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
965 #if defined (OCTAVE_USE_WINDOWS_API)
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
966 if ((args.length () < 2) || (args.length () > 3))
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
967 print_usage ();
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
968
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
969 // Input check
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
970 std::string rootkey_name
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
971 = args(0).xstring_value ("winqueryreg: the first argument must be 'name' "
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
972 "or a valid ROOTKEY identifier");
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
973 std::string subkey_name = "";
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
974 std::string value_name = "";
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
975 bool get_names = false;
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
976 if (rootkey_name.compare ("name") == 0)
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
977 {
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
978 if (args.length () < 3)
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
979 error ("winqueryreg: if the first argument is 'name', "
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
980 "ROOTKEY and SUBKEY must be given");
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
981 get_names = true;
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
982 rootkey_name
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
983 = args(1).xstring_value ("winqueryreg: ROOTKEY must be a string");
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
984 subkey_name
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
985 = args(2).xstring_value ("winqueryreg: SUBKEY must be a string");
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
986 }
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
987 else
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
988 {
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
989 subkey_name
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
990 = args(1).xstring_value ("winqueryreg: SUBKEY must be a string");
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
991
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
992 if (args.length () == 3)
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
993 value_name
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
994 = args(2).xstring_value ("winqueryreg: VALUENAME must be a string");
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
995 }
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
996
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
997 // Get rootkey handle
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
998 HKEY h_rootkey;
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
999 if (rootkey_name == "HKEY_CLASSES_ROOT" || rootkey_name == "HKCR")
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1000 h_rootkey = HKEY_CLASSES_ROOT;
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1001 else if (rootkey_name == "HKEY_CURRENT_CONFIG")
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1002 h_rootkey = HKEY_CURRENT_CONFIG;
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1003 else if (rootkey_name == "HKEY_CURRENT_USER" || rootkey_name == "HKCU")
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1004 h_rootkey = HKEY_CURRENT_USER;
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1005 else if (rootkey_name == "HKEY_LOCAL_MACHINE" || rootkey_name == "HKLM")
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1006 h_rootkey = HKEY_LOCAL_MACHINE;
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1007 else if (rootkey_name == "HKEY_PERFORMANCE_DATA")
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1008 h_rootkey = HKEY_PERFORMANCE_DATA;
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1009 else if (rootkey_name == "HKEY_USERS" || rootkey_name == "HKU")
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1010 h_rootkey = HKEY_USERS;
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1011 else
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1012 error ("winqueryreg: ROOTKEY is not a valid root key identifier");
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1013
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1014 if (get_names)
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1015 {
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1016 std::list<std::string> fields;
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1017
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
1018 LONG retval = octave::get_regkey_names (h_rootkey, subkey_name, fields);
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1019 if (retval != ERROR_SUCCESS)
26162
ef1ef6364a6a Silence compiler warnings about incorrect format specifiers cross-compiling (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26046
diff changeset
1020 error ("winqueryreg: error %ld reading names from registry", retval);
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1021
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1022 Cell fieldnames (dim_vector (1, fields.size ()));
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1023 size_t i;
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1024 std::list<std::string>::const_iterator it;
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1025 for (i = 0, it = fields.begin (); it != fields.end (); ++it, ++i)
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1026 fieldnames(i) = *it;
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1027
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1028 return ovl (fieldnames);
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1029 }
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1030 else
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1031 {
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1032 octave_value key_val;
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
1033 LONG retval = octave::get_regkey_value (h_rootkey, subkey_name,
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27046
diff changeset
1034 value_name, key_val);
24720
48f22c5b22aa winqueryreg: Fix error on Windows XP (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24714
diff changeset
1035 if (retval == ERROR_FILE_NOT_FOUND)
48f22c5b22aa winqueryreg: Fix error on Windows XP (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24714
diff changeset
1036 error ("winqueryreg: no value found for '%s' at %s\\%s.",
48f22c5b22aa winqueryreg: Fix error on Windows XP (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24714
diff changeset
1037 value_name.c_str (), rootkey_name.c_str (),
48f22c5b22aa winqueryreg: Fix error on Windows XP (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24714
diff changeset
1038 subkey_name.c_str ());
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1039 if (retval != ERROR_SUCCESS)
26162
ef1ef6364a6a Silence compiler warnings about incorrect format specifiers cross-compiling (bug #55046).
Markus Mützel <markus.muetzel@gmx.de>
parents: 26046
diff changeset
1040 error ("winqueryreg: error %ld reading the specified key", retval);
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1041
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1042 return ovl (key_val);
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1043 }
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1044 #else
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1045
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1046 octave_unused_parameter (args);
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1047
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1048 error ("winqueryreg: function is only supported on Windows platforms");
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1049
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1050 #endif
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1051 }
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1052
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1053 /*
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1054 %!testif ; ispc ()
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1055 %! assert (ischar (winqueryreg ("HKEY_LOCAL_MACHINE",
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1056 %! 'SOFTWARE\Microsoft\Windows\CurrentVersion',
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1057 %! "ProgramFilesDir")));
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1058 %!testif ; ispc ()
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1059 %! assert (isa (winqueryreg ("HKEY_LOCAL_MACHINE",
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1060 %! 'SYSTEM\CurrentControlSet\Control\FileSystem',
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1061 %! "Win31FileSystem"), "int32"));
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1062 %!testif ; ispc ()
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1063 %! assert (iscellstr (winqueryreg ("name", "HKEY_LOCAL_MACHINE",
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1064 %! 'SOFTWARE\Microsoft\Windows\CurrentVersion')));
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1065 %!testif ; ispc ()
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1066 %! fail ('winqueryreg (1, ''SOFTWARE\Microsoft\Windows\CurrentVersion'')',
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1067 %! "first argument must be 'name' or a valid ROOTKEY identifier");
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1068 %!testif ; ispc ()
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1069 %! fail ('winqueryreg ("HKEY_LOCAL_MACHINE", 1)', "SUBKEY must be a string");
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1070 %!testif ; ispc ()
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1071 %! fail (['winqueryreg ("HKEY_LOCAL_MACHINE", ', ...
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1072 %! '''SOFTWARE\Microsoft\Windows\CurrentVersion'', 1)'],
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1073 %! "VALUENAME must be a string");
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1074 %!testif ; ispc ()
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1075 %! fail (['winqueryreg ("FOO", ', ...
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1076 %! '''SOFTWARE\Microsoft\Windows\CurrentVersion'')'],
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1077 %! "ROOTKEY is not a valid root key identifier");
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1078 %!testif ; ispc ()
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1079 %! fail ('winqueryreg ("HKEY_LOCAL_MACHINE", ''FOO\bar'')',
24720
48f22c5b22aa winqueryreg: Fix error on Windows XP (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24714
diff changeset
1080 %! "no value found for");
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1081 %!testif ; ispc ()
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1082 %! fail (['winqueryreg ("HKEY_LOCAL_MACHINE", ', ...
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1083 %! '''SOFTWARE\Microsoft\Windows\CurrentVersion'', "foo")'],
24720
48f22c5b22aa winqueryreg: Fix error on Windows XP (bug #50463).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24714
diff changeset
1084 %! "no value found for");
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1085 %!testif ; ispc ()
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1086 %! fail ('winqueryreg ("name", "HKEY_LOCAL_MACHINE")',
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1087 %! "if the first argument is 'name', ROOTKEY and SUBKEY must be given");
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1088 %!testif ; ispc ()
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1089 %! fail (['winqueryreg ("name", 1, ', ...
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1090 %! '''SOFTWARE\Microsoft\Windows\CurrentVersion'')'],
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1091 %! "ROOTKEY must be a string");
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1092 %!testif ; ispc ()
24665
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1093 %! fail ('winqueryreg ("name", "HKEY_LOCAL_MACHINE", 1)',
4a9793818fca Use Octave coding conventions in cset a829062fdea4.
Rik <rik@octave.org>
parents: 24664
diff changeset
1094 %! "SUBKEY must be a string");
24664
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1095 */
a829062fdea4 Add function "winqueryreg" (bug #52935).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24534
diff changeset
1096
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1097 // FIXME: perhaps kbhit should also be able to print a prompt?
3372
f16c2ce14886 [project @ 1999-11-23 19:07:09 by jwe]
jwe
parents: 3333
diff changeset
1098
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27301
diff changeset
1099 DEFMETHOD (kbhit, interp, args, ,
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27301
diff changeset
1100 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1101 @deftypefn {} {} kbhit ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1102 @deftypefnx {} {} kbhit (1)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1103 Read a single keystroke from the keyboard.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1104
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1105 If called with an argument, don't wait for a keypress.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1106
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1107 For example,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1108
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1109 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1110 x = kbhit ();
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1111 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1112
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1113 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1114 will set @var{x} to the next character typed at the keyboard as soon as
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1115 it is typed.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1116
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1117 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1118 x = kbhit (1);
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1119 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1120
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1121 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1122 is identical to the above example, but doesn't wait for a keypress,
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1123 returning the empty string if no key is available.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1124 @seealso{input, pause}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1125 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
1126 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1127 // FIXME: add timeout and default value args?
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
1128
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27301
diff changeset
1129 Fdrawnow (interp);
6423
a90b54016b12 [project @ 2007-03-21 13:15:03 by jwe]
jwe
parents: 6419
diff changeset
1130
25649
85c3e315bd43 move libinterp/corefcn/sysdep functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 25646
diff changeset
1131 int c = octave::kbhit (args.length () == 0);
3657
a908150a3a32 [project @ 2000-04-11 19:02:03 by jwe]
jwe
parents: 3531
diff changeset
1132
25311
10ec5795bd06 allow kbhit to work in command-line scripts (bug #53412)
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
1133 if (c == -1)
10ec5795bd06 allow kbhit to work in command-line scripts (bug #53412)
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
1134 c = 0;
16015
d910b9211cca Plug memory leak in kbhit().
Rik <rik@octave.org>
parents: 15423
diff changeset
1135
25311
10ec5795bd06 allow kbhit to work in command-line scripts (bug #53412)
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
1136 char s[2] = { static_cast<char> (c), '\0' };
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
1137
25311
10ec5795bd06 allow kbhit to work in command-line scripts (bug #53412)
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
1138 return octave_value (s);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
1139 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
1140
26026
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1141 // State of the pause system
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1142 static bool Vpause_enabled = true;
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1143
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27301
diff changeset
1144 DEFMETHOD (pause, interp, args, nargout,
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27301
diff changeset
1145 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1146 @deftypefn {} {} pause ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1147 @deftypefnx {} {} pause (@var{n})
26046
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 26026
diff changeset
1148 @deftypefnx {} {@var{old_state} =} pause ("on")
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 26026
diff changeset
1149 @deftypefnx {} {@var{old_state} =} pause ("off")
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 26026
diff changeset
1150 @deftypefnx {} {@var{old_state} =} pause ("query")
26026
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1151 Suspend the execution of the program or change the state of the pause function.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1152
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1153 If invoked without an input arguments then the program is suspended until a
26046
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 26026
diff changeset
1154 character is typed. If argument @var{n} is a positive real value, it indicates
26026
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1155 the number of seconds the program shall be suspended, for example:
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1156
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1157 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1158 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1159 tic; pause (0.05); toc
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1160 @print{} Elapsed time is 0.05039 seconds.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1161 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1162 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1163
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1164 The following example prints a message and then waits 5 seconds before
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1165 clearing the screen.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1166
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1167 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1168 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1169 disp ("wait please...");
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1170 pause (5);
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1171 clc;
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1172 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1173 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1174
26046
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 26026
diff changeset
1175 If invoked with a string argument @qcode{"on"}, @qcode{"off"}, or
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 26026
diff changeset
1176 @qcode{"query"}, the state of the pause function is changed or queried. When
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 26026
diff changeset
1177 the state is @qcode{"off"}, the pause function returns immediately. The
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 26026
diff changeset
1178 optional return value contains the previous state of the pause function. In
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 26026
diff changeset
1179 the following example pause is disabled locally:
26026
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1180
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1181 @example
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1182 @group
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1183 old_state = pause ("off");
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1184 tic; pause (0.05); toc
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1185 @print{} Elapsed time is 3.00407e-05 seconds.
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1186 pause (old_state);
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1187 @end group
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1188 @end example
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1189
26046
ff0aa19333c9 doc: grammarcheck C++ files in libinterp/ directory.
Rik <rik@octave.org>
parents: 26026
diff changeset
1190 While the program is suspended Octave still handles figures painting and
25961
f7b205562f1d Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25916
diff changeset
1191 graphics callbacks execution.
f7b205562f1d Allow graphics events to be processed while pause is active (bug #53729)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25916
diff changeset
1192
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1193 @seealso{kbhit}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1194 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
1195 {
26026
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1196 octave_value_list retval;
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1197
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
1198 int nargin = args.length ();
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1199
20799
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
1200 if (nargin > 1)
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
1201 print_usage ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 505
diff changeset
1202
26026
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1203 if (nargin == 1 && args(0).is_string ())
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1204 {
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1205 bool saved_state = Vpause_enabled;
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1206 std::string state = args(0).string_value ();
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1207
26026
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1208 if (state == "on")
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1209 Vpause_enabled = true;
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1210 else if (state == "off")
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1211 Vpause_enabled = false;
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1212 else if (state == "query")
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1213 ;// Do nothing
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1214 else
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1215 error ("pause: first argument must be \"on\", \"off\" or \"query\"");
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1216
26026
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1217 if (nargout > 0 || state == "query")
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1218 retval.append (saved_state ? "on" : "off");
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1219 }
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1220 else if (Vpause_enabled)
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1221 {
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1222 double dval;
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1223
26026
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1224 if (nargin == 0)
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1225 dval = octave_Inf;
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1226 else
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1227 dval = args(0).xdouble_value ("pause: N must be a scalar real value");
6419
73fcbac81f33 [project @ 2007-03-20 17:18:24 by jwe]
jwe
parents: 6208
diff changeset
1228
26026
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1229 if (octave::math::isnan (dval))
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1230 warning ("pause: NaN is an invalid delay");
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1231 else
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1232 {
27335
50216d7a2f6b eliminate static wrapper functions in gh_manager class
John W. Eaton <jwe@octave.org>
parents: 27301
diff changeset
1233 Fdrawnow (interp);
26617
98afb8bbd1f6 maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
1234
26026
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1235 octave::sleep (dval, true);
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1236 }
3234
be8e0ba13644 [project @ 1999-01-29 03:52:30 by jwe]
jwe
parents: 3124
diff changeset
1237 }
26026
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1238
511295347a27 Allow pause state to be changed (bug #53723)
Pantxo Diribarne <pantxo.diribarne@gmail.com>
parents: 25961
diff changeset
1239 return retval;
2630
fdee6fe3e73b [project @ 1997-01-27 19:08:47 by jwe]
jwe
parents: 2610
diff changeset
1240 }
fdee6fe3e73b [project @ 1997-01-27 19:08:47 by jwe]
jwe
parents: 2610
diff changeset
1241
12825
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
1242 /*
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
1243 %!test
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
1244 %! pause (1);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14160
diff changeset
1245
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14160
diff changeset
1246 %!error (pause (1, 2))
12825
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
1247 */
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
1248
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1249 // FIXME: maybe this should only return 1 if IEEE floating
862
61d83ce7368c [project @ 1994-10-31 20:39:30 by jwe]
jwe
parents: 844
diff changeset
1250 // point functions really work.
61d83ce7368c [project @ 1994-10-31 20:39:30 by jwe]
jwe
parents: 844
diff changeset
1251
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
1252 DEFUN (isieee, , ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1253 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1254 @deftypefn {} {} isieee ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1255 Return true if your computer @emph{claims} to conform to the IEEE standard
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1256 for floating point calculations.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1257
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1258 No actual tests are performed.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1259 @end deftypefn */)
862
61d83ce7368c [project @ 1994-10-31 20:39:30 by jwe]
jwe
parents: 844
diff changeset
1260 {
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
1261 octave::mach_info::float_format flt_fmt
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
1262 = octave::mach_info::native_float_format ();
2317
8c09c04f7747 [project @ 1996-07-14 22:30:15 by jwe]
jwe
parents: 2086
diff changeset
1263
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
1264 return ovl (flt_fmt == octave::mach_info::flt_fmt_ieee_little_endian
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
1265 || flt_fmt == octave::mach_info::flt_fmt_ieee_big_endian);
862
61d83ce7368c [project @ 1994-10-31 20:39:30 by jwe]
jwe
parents: 844
diff changeset
1266 }
61d83ce7368c [project @ 1994-10-31 20:39:30 by jwe]
jwe
parents: 844
diff changeset
1267
12825
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
1268 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14160
diff changeset
1269 %!assert (islogical (isieee ()))
12825
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
1270 */
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
1271
4600
3680bb30de0b [project @ 2003-11-12 18:25:53 by jwe]
jwe
parents: 4574
diff changeset
1272 DEFUN (native_float_format, , ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1273 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1274 @deftypefn {} {} native_float_format ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1275 Return the native floating point format as a string.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1276 @end deftypefn */)
4600
3680bb30de0b [project @ 2003-11-12 18:25:53 by jwe]
jwe
parents: 4574
diff changeset
1277 {
27277
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
1278 octave::mach_info::float_format flt_fmt
db687716fed6 style fixes: generally aim to break long lines before operators, not after
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
1279 = octave::mach_info::native_float_format ();
4600
3680bb30de0b [project @ 2003-11-12 18:25:53 by jwe]
jwe
parents: 4574
diff changeset
1280
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
1281 return ovl (octave::mach_info::float_format_as_string (flt_fmt));
4600
3680bb30de0b [project @ 2003-11-12 18:25:53 by jwe]
jwe
parents: 4574
diff changeset
1282 }
3680bb30de0b [project @ 2003-11-12 18:25:53 by jwe]
jwe
parents: 4574
diff changeset
1283
12825
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
1284 /*
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14160
diff changeset
1285 %!assert (ischar (native_float_format ()))
12825
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
1286 */
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
1287
1957
0e6a0a271998 [project @ 1996-02-15 01:08:15 by jwe]
jwe
parents: 1884
diff changeset
1288 DEFUN (tilde_expand, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1289 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1290 @deftypefn {} {} tilde_expand (@var{string})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1291 @deftypefnx {} {} tilde_expand (@var{cellstr})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1292 Perform tilde expansion on @var{string}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1293
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1294 If @var{string} begins with a tilde character, (@samp{~}), all of the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1295 characters preceding the first slash (or all characters, if there is no
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1296 slash) are treated as a possible user name, and the tilde and the following
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1297 characters up to the slash are replaced by the home directory of the named
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1298 user. If the tilde is followed immediately by a slash, the tilde is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1299 replaced by the home directory of the user running Octave.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1300
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1301 If the input is a cell array of strings @var{cellstr} then tilde expansion
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1302 is performed on each string element.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1303
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1304 Examples:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1305
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1306 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1307 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1308 tilde_expand ("~joeuser/bin")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1309 @result{} "/home/joeuser/bin"
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1310 tilde_expand ("~/bin")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1311 @result{} "/home/jwe/bin"
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1312 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1313 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1314 @end deftypefn */)
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
1315 {
20819
f428cbe7576f eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20799
diff changeset
1316 if (args.length () != 1)
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1317 print_usage ();
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
1318
20799
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
1319 octave_value arg = args(0);
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 6086
diff changeset
1320
20990
fc9cca99b2de Deprecate all_strings, replace with string_vector_value.
Rik <rik@octave.org>
parents: 20961
diff changeset
1321 string_vector sv = arg.xstring_vector_value ("tilde_expand: argument must be char or cellstr object");
6116
b64fb24bf4a0 [project @ 2006-10-27 18:04:49 by jwe]
jwe
parents: 6086
diff changeset
1322
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
1323 sv = octave::sys::file_ops::tilde_expand (sv);
20799
c349d4c91ce2 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20789
diff changeset
1324
23575
e95738a119da maint: Deprecate is_cellstr and replace with iscellstr.
Rik <rik@octave.org>
parents: 23459
diff changeset
1325 if (arg.iscellstr ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20923
diff changeset
1326 return ovl (Cell (arg.dims (), sv));
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
1327 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20923
diff changeset
1328 return ovl (sv);
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
1329 }
12825
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
1330
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
1331 /*
a1dcb854a4f9 codesprint: new tests for sysdep.cc functions
John W. Eaton <jwe@octave.org>
parents: 12483
diff changeset
1332 %!test
20016
47d420d769ba * sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
1333 %! home = get_home_directory ();
20064
ab7582167810 Fix failing BIST test for tilde_expand() on Windows (bug #44796).
Rik <rik@octave.org>
parents: 20024
diff changeset
1334 %! 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
1335 %! 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
1336 %! 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
1337 */
17851
af685269e06c avoid symbol conflicts in display.cc
John W. Eaton <jwe@octave.org>
parents: 17787
diff changeset
1338
20016
47d420d769ba * sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
1339 DEFUN (get_home_directory, , ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1340 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1341 @deftypefn {} {@var{homedir} =} get_home_directory ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1342 Return the current home directory.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1343
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1344 On most systems, this is equivalent to @code{getenv ("HOME")}. On Windows
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1345 systems, if the environment variable @env{HOME} is not set then it is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1346 equivalent to
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1347 @code{fullfile (getenv ("HOMEDRIVE"), getenv ("HOMEPATH"))}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1348 @seealso{getenv}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21949
diff changeset
1349 @end deftypefn */)
20016
47d420d769ba * sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
1350 {
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
1351 return ovl (octave::sys::env::get_home_directory ());
20016
47d420d769ba * sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
1352 }
47d420d769ba * sysdep.cc (Fget_home_directory): New function.
John W. Eaton <jwe@octave.org>
parents: 19861
diff changeset
1353
20024
cf9b94a89620 Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents: 20016
diff changeset
1354 /*
cf9b94a89620 Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents: 20016
diff changeset
1355 %!test
cf9b94a89620 Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents: 20016
diff changeset
1356 %! if (! ispc ())
20181
aa36fb998a4d maint: Remove unnecessary whitespace at end of lines.
Rik <rik@octave.org>
parents: 20172
diff changeset
1357 %! assert (get_home_directory (), getenv ("HOME"));
20024
cf9b94a89620 Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents: 20016
diff changeset
1358 %! endif
cf9b94a89620 Document get_home_directory in Octave manual and NEWS file.
Rik <rik@octave.org>
parents: 20016
diff changeset
1359 */
24714
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1360
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1361 DEFUN (__blas_version__, , ,
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1362 doc: /* -*- texinfo -*-
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1363 @deftypefn {} {} __blas_version__ ()
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1364 Undocumented internal function.
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1365 @end deftypefn */)
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1366 {
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1367 return ovl (octave::sys::blas_version ());
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1368 }
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1369
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1370 DEFUN (__lapack_version__, , ,
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1371 doc: /* -*- texinfo -*-
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1372 @deftypefn {} {} __lapack_version__ ()
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1373 Undocumented internal function.
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1374 @end deftypefn */)
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1375 {
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1376 return ovl (octave::sys::lapack_version ());
d2c727a438ab Add "-blas" and "-lapack" options to "version" (bug #45659).
Markus Mützel <markus.muetzel@gmx.de>
parents: 24710
diff changeset
1377 }