Mercurial > octave
annotate liboctave/system/lo-sysdep.cc @ 27918:b442ec6dda5c
use centralized file for copyright info for individual contributors
* COPYRIGHT.md: New file.
* In most other files, use "Copyright (C) YYYY-YYYY The Octave Project
Developers" instead of tracking individual names in separate source
files. The motivation is to reduce the effort required to update the
notices each year.
Until now, the Octave source files contained copyright notices that
list individual contributors. I adopted these file-scope copyright
notices because that is what everyone was doing 30 years ago in the
days before distributed version control systems. But now, with many
contributors and modern version control systems, having these
file-scope copyright notices causes trouble when we update copyright
years or refactor code.
Over time, the file-scope copyright notices may become outdated as new
contributions are made or code is moved from one file to
another. Sometimes people contribute significant patches but do not
add a line claiming copyright. Other times, people add a copyright
notice for their contribution but then a later refactoring moves part
or all of their contribution to another file and the notice is not
moved with the code. As a practical matter, moving such notices is
difficult -- determining what parts are due to a particular
contributor requires a time-consuming search through the project
history. Even managing the yearly update of copyright years is
problematic. We have some contributors who are no longer
living. Should we update the copyright dates for their contributions
when we release new versions? Probably not, but we do still want to
claim copyright for the project as a whole.
To minimize the difficulty of maintaining the copyright notices, I
would like to change Octave's sources to use what is described here:
https://softwarefreedom.org/resources/2012/ManagingCopyrightInformation.html
in the section "Maintaining centralized copyright notices":
The centralized notice approach consolidates all copyright
notices in a single location, usually a top-level file.
This file should contain all of the copyright notices
provided project contributors, unless the contribution was
clearly insignificant. It may also credit -- without a copyright
notice -- anyone who helped with the project but did not
contribute code or other copyrighted material.
This approach captures less information about contributions
within individual files, recognizing that the DVCS is better
equipped to record those details. As we mentioned before, it
does have one disadvantage as compared to the file-scope
approach: if a single file is separated from the distribution,
the recipient won't see the contributors' copyright notices.
But this can be easily remedied by including a single
copyright notice in each file's header, pointing to the
top-level file:
Copyright YYYY-YYYY The Octave Project Developers
See the COPYRIGHT file at the top-level directory
of this distribution or at https://octave.org/COPYRIGHT.html.
followed by the usual GPL copyright statement.
For more background, see the discussion here:
https://lists.gnu.org/archive/html/octave-maintainers/2020-01/msg00009.html
Most files in the following directories have been skipped intentinally
in this changeset:
doc
libgui/qterminal
liboctave/external
m4
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 15:38:17 -0500 |
parents | 84ff9953faa1 |
children | 1891570abac8 |
rev | line source |
---|---|
2926 | 1 /* |
2 | |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
3 Copyright (C) 1996-2019 The Octave Project Developers |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
4 |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
5 See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
6 or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
7 |
2926 | 8 |
9 This file is part of Octave. | |
10 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23804
diff
changeset
|
11 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
12 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:
23804
diff
changeset
|
13 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
14 (at your option) any later version. |
2926 | 15 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
16 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
17 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22402
diff
changeset
|
19 GNU General Public License for more details. |
2926 | 20 |
21 You should have received a copy of the GNU General Public License | |
7016 | 22 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:
23804
diff
changeset
|
23 <https://www.gnu.org/licenses/>. |
2926 | 24 |
25 */ | |
26 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21642
diff
changeset
|
27 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21213
diff
changeset
|
28 # include "config.h" |
2926 | 29 #endif |
30 | |
31 #include <string> | |
7695
eacf87a24f55
lo-sysdep.cc: include windows.h if windows and not cygwin
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
32 |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
33 #include "dir-ops.h" |
5872 | 34 #include "file-ops.h" |
3069 | 35 #include "lo-error.h" |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21828
diff
changeset
|
36 #include "lo-sysdep.h" |
25916
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
37 #include "putenv-wrapper.h" |
25514
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
38 #include "uniconv-wrappers.h" |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21828
diff
changeset
|
39 #include "unistd-wrappers.h" |
25916
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
40 #include "unsetenv-wrapper.h" |
2926 | 41 |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
42 #if defined (OCTAVE_USE_WINDOWS_API) |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
43 # include <windows.h> |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
44 # include <wchar.h> |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
45 |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
46 # include "lo-hash.h" |
26531
481ac37b0e0e
lo-sysdep.cc: Fix static analyzer detected issue (bug #55464).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26506
diff
changeset
|
47 # include "unwind-prot.h" |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
48 #endif |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
49 |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
50 namespace octave |
2926 | 51 { |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
52 namespace sys |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
53 { |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
54 std::string |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
55 getcwd (void) |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
56 { |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
57 std::string retval; |
3069 | 58 |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21828
diff
changeset
|
59 // Using octave_getcwd_wrapper ensures that we have a getcwd that |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
60 // will allocate a buffer as large as necessary if buf and size are |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
61 // both 0. |
3069 | 62 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23696
diff
changeset
|
63 char *tmp = octave_getcwd_wrapper (nullptr, 0); |
2926 | 64 |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
65 if (! tmp) |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
66 (*current_liboctave_error_handler) ("unable to find current directory"); |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
67 |
10250 | 68 retval = tmp; |
69 free (tmp); | |
21136
7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Rik <rik@octave.org>
parents:
19864
diff
changeset
|
70 |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
71 return retval; |
10250 | 72 } |
2926 | 73 |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
74 int |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
75 chdir (const std::string& path_arg) |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
76 { |
23696
08036a7f3660
remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
77 std::string path = sys::file_ops::tilde_expand (path_arg); |
5872 | 78 |
21979
d04da18a407a
use OCTAVE_USE_WINDOWS_API more consistently
John W. Eaton <jwe@octave.org>
parents:
21949
diff
changeset
|
79 #if defined (OCTAVE_USE_WINDOWS_API) |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
80 if (path.length () == 2 && path[1] == ':') |
23804
8057d3f0673d
Use C++11 raw string literals to avoid escaping backslashes in strings.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
81 path += '\\'; |
6244 | 82 #endif |
83 | |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21828
diff
changeset
|
84 return octave_chdir_wrapper (path.c_str ()); |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
85 } |
25514
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
86 |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
87 bool |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
88 get_dirlist (const std::string& dirname, string_vector& dirlist, std::string& msg) |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
89 { |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
90 dirlist = ""; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
91 msg = ""; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
92 #if defined (OCTAVE_USE_WINDOWS_API) |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
93 _WIN32_FIND_DATAW ffd; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
94 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
95 std::string path_name (dirname); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
96 if (path_name.empty ()) |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
97 return true; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
98 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
99 if (path_name.back () == '\\' || path_name.back () == '/') |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
100 path_name.push_back ('*'); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
101 else |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
102 path_name.append (R"(\*)"); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
103 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
104 // Find first file in directory. |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
105 HANDLE hFind = FindFirstFileW (u8_to_wstring (path_name).c_str (), |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
106 &ffd); |
25609
506419b5f817
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
25532
diff
changeset
|
107 if (INVALID_HANDLE_VALUE == hFind) |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
108 { |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
109 DWORD errCode = GetLastError (); |
26163
d478d5d1c8e9
Fix potential segfault on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25916
diff
changeset
|
110 char *errorText = nullptr; |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
111 FormatMessageA (FORMAT_MESSAGE_FROM_SYSTEM | |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
112 FORMAT_MESSAGE_ALLOCATE_BUFFER | |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
113 FORMAT_MESSAGE_IGNORE_INSERTS, |
26163
d478d5d1c8e9
Fix potential segfault on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25916
diff
changeset
|
114 nullptr, errCode, |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
115 MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), |
26163
d478d5d1c8e9
Fix potential segfault on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25916
diff
changeset
|
116 reinterpret_cast <char *> (&errorText), 0, nullptr); |
d478d5d1c8e9
Fix potential segfault on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25916
diff
changeset
|
117 if (errorText != nullptr) |
25516
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
118 { |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
119 msg = std::string (errorText); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
120 LocalFree (errorText); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
121 } |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
122 return false; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
123 } |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
124 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
125 std::list<std::string> dirlist_str; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
126 do |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
127 dirlist_str.push_back (u8_from_wstring (ffd.cFileName)); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
128 while (FindNextFileW (hFind, &ffd) != 0); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
129 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
130 FindClose(hFind); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
131 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
132 dirlist = string_vector (dirlist_str); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
133 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
134 #else |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
135 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
136 dir_entry dir (dirname); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
137 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
138 if (! dir) |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
139 { |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
140 msg = dir.error (); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
141 return false; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
142 } |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
143 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
144 dirlist = dir.read (); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
145 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
146 dir.close (); |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
147 #endif |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
148 |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
149 return true; |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
150 } |
8945a6a6c0eb
Add Unicode support for getting directory listing in Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25514
diff
changeset
|
151 |
25517
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
152 std::FILE * |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
153 fopen (const std::string& filename, const std::string& mode) |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
154 { |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
155 #if defined (OCTAVE_USE_WINDOWS_API) |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
156 return _wfopen (u8_to_wstring (filename).c_str (), |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
157 u8_to_wstring (mode).c_str ()); |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
158 #else |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
159 return std::fopen (filename.c_str (), mode.c_str ()); |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
160 #endif |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
161 } |
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
162 |
25916
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
163 void |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
164 putenv_wrapper (const std::string& name, const std::string& value) |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
165 { |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
166 // This function was adapted from xputenv from Karl Berry's kpathsearch |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
167 // library. |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
168 // FIXME: make this do the right thing if we don't have a SMART_PUTENV. |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
169 |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
170 int new_len = name.length () + value.length () + 2; |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
171 |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
172 // FIXME: This leaks memory, but so would a call to setenv. |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
173 // Short of extreme measures to track memory, altering the environment |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
174 // always leaks memory, but the saving grace is that the leaks are small. |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
175 |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
176 char *new_item = static_cast<char *> (std::malloc (new_len)); |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
177 |
26506
9cf999911dfe
lo-sysdep.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
178 if (new_item) |
9cf999911dfe
lo-sysdep.cc: Fix static analyzer detected issues (bug #55347).
Rik <rik@octave.org>
parents:
26376
diff
changeset
|
179 sprintf (new_item, "%s=%s", name.c_str (), value.c_str ()); |
25916
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
180 |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
181 // As far as I can see there's no way to distinguish between the |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
182 // various errors; putenv doesn't have errno values. |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
183 |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
184 #if defined (OCTAVE_USE_WINDOWS_API) |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
185 wchar_t *wnew_item = u8_to_wchar (new_item); |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26531
diff
changeset
|
186 unwind_protect frame; |
26531
481ac37b0e0e
lo-sysdep.cc: Fix static analyzer detected issue (bug #55464).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26506
diff
changeset
|
187 frame.add_fcn (std::free, static_cast<void *> (new_item)); |
25916
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
188 if (_wputenv (wnew_item) < 0) |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
189 (*current_liboctave_error_handler) ("putenv (%s) failed", new_item); |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
190 #else |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
191 if (octave_putenv_wrapper (new_item) < 0) |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
192 (*current_liboctave_error_handler) ("putenv (%s) failed", new_item); |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
193 #endif |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
194 } |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
195 |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
196 std::string |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
197 getenv_wrapper (const std::string& name) |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
198 { |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
199 #if defined (OCTAVE_USE_WINDOWS_API) |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
200 wchar_t *env = _wgetenv (u8_to_wstring (name).c_str ()); |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
201 return env ? u8_from_wstring (env) : ""; |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
202 #else |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
203 char *env = ::getenv (name.c_str ()); |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
204 return env ? env : ""; |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
205 #endif |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
206 } |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
207 |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
208 int |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
209 unsetenv_wrapper (const std::string& name) |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
210 { |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
211 #if defined (OCTAVE_USE_WINDOWS_API) |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
212 putenv_wrapper (name, ""); |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
213 |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
214 std::wstring wname = u8_to_wstring (name); |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
215 return (SetEnvironmentVariableW (wname.c_str (), nullptr) ? 0 : -1); |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
216 #else |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
217 return octave_unsetenv_wrapper (name.c_str ()); |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
218 #endif |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
219 } |
3f2282954600
Support non-ASCII characters in environment variables on Windows (bug #53922).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25660
diff
changeset
|
220 |
25514
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
221 std::wstring |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
222 u8_to_wstring (const std::string& utf8_string) |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
223 { |
25531
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
224 size_t srclen = utf8_string.length (); |
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
225 const uint8_t *src = reinterpret_cast<const uint8_t *> |
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
226 (utf8_string.c_str ()); |
25514
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
227 |
25531
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
228 size_t length = 0; |
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
229 wchar_t *wchar = reinterpret_cast<wchar_t *> |
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
230 (octave_u8_conv_to_encoding ("wchar_t", src, srclen, |
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
231 &length)); |
25514
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
232 |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
233 std::wstring retval = L""; |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
234 if (wchar != nullptr) |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
235 { |
25531
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
236 retval = std::wstring (wchar, length / sizeof (wchar_t)); |
25514
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
237 free (static_cast<void *> (wchar)); |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
238 } |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
239 |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
240 return retval; |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
241 } |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
242 |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
243 std::string |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
244 u8_from_wstring (const std::wstring& wchar_string) |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
245 { |
25531
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
246 size_t srclen = wchar_string.length () * sizeof (wchar_t); |
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
247 const char *src = reinterpret_cast<const char *> (wchar_string.c_str ()); |
25514
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
248 |
25531
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
249 size_t length = 0; |
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
250 char *mbchar = reinterpret_cast<char *> |
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
251 (octave_u8_conv_from_encoding ("wchar_t", src, srclen, |
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
252 &length)); |
25514
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
253 |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
254 std::string retval = ""; |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
255 if (mbchar != nullptr) |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
256 { |
25531
c2dc2fb6359b
Fix C++ conversion functions between UTF-8 and wchar_t.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25517
diff
changeset
|
257 retval = std::string (mbchar, length); |
25514
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
258 free (static_cast<void *> (mbchar)); |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
259 } |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
260 |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
261 return retval; |
c63f67d87b4a
Add C++ functions to convert between UTF-8 string and wstring (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25054
diff
changeset
|
262 } |
25517
7fbc39a46be8
Add wrapper to fopen for files with non-ASCII chars in path on Windows (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25516
diff
changeset
|
263 |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
264 // At quite a few places in the code we are passing file names as |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
265 // char arrays to external library functions. |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
266 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
267 // When these functions try to locate the corresponding file on the |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
268 // disc, they need to use the wide character API on Windows to |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
269 // correctly open files with non-ASCII characters. |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
270 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
271 // But they have no way of knowing which encoding we are using for |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
272 // the passed string. So they have no way of reliably converting to |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
273 // a wchar_t array. (I.e. there is no possible fix for these |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
274 // functions with current C or C++.) |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
275 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
276 // To solve the dilemma, the function "get_ASCII_filename" first |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
277 // checks whether there are any non-ASCII characters in the passed |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
278 // file name. If there are not, it returns the original name. |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
279 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
280 // Otherwise, it tries to obtain the short file name (8.3 naming |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
281 // scheme) which only consists of ASCII characters and are safe to |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
282 // pass. However, short file names can be disabled for performance |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
283 // reasons on the file system level with NTFS. So there is no |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
284 // guarantee that these exist. |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
285 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
286 // If short file names are not stored, a hard link to the file is |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
287 // created. For this the path to the file is split at the deepest |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
288 // possible level that doesn't contain non-ASCII characters. At |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
289 // that level a hidden folder is created that holds the hard links. |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
290 // That means we need to have write access on that location. A path |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
291 // to that hard link is returned. |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
292 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
293 // If the file system is FAT32, there are no hard links. But FAT32 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
294 // always stores short file names. So we are safe. |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
295 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
296 // ExFAT that is occasionally used on USB sticks and SD cards stores |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
297 // neither short file names nor does it support hard links. So for |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
298 // exFAT with this function, there is (currently) no way to generate |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
299 // a file name that is stripped from non-ASCII characters but still |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
300 // is valid. |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
301 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
302 // For Unixy systems, this function does nothing. |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
303 |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
304 std::string |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
305 get_ASCII_filename (const std::string& orig_file_name) |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
306 { |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
307 #if defined (OCTAVE_USE_WINDOWS_API) |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
308 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
309 // Return file name that only contains ASCII characters that can |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
310 // be used to access the file orig_file_name. The original file |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
311 // must exist in the file system before calling this function. |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
312 // This is useful for passing file names to functions that are not |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
313 // aware of the character encoding we are using. |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
314 |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
315 // 1. Check whether filename contains non-ASCII (UTF-8) characters. |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
316 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
317 std::string::const_iterator first_non_ASCII |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
318 = std::find_if (orig_file_name.begin (), orig_file_name.end (), |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
319 [](char c) { return (c < 0 || c >= 128); }); |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
320 |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
321 if (first_non_ASCII == orig_file_name.end ()) |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
322 return orig_file_name; |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
323 |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
324 // 2. Check if file system stores short filenames (always |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
325 // ASCII-only). |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
326 |
25660
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
327 std::wstring w_orig_file_name_str = u8_to_wstring (orig_file_name); |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
328 const wchar_t *w_orig_file_name = w_orig_file_name_str.c_str (); |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
329 |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
330 // Get full path to file |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
331 wchar_t w_full_file_name[_MAX_PATH]; |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
332 if (_wfullpath (w_full_file_name, w_orig_file_name, _MAX_PATH) == nullptr) |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
333 return orig_file_name; |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
334 |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
335 std::wstring w_full_file_name_str = w_full_file_name; |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
336 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
337 // Get short filename (8.3) from UTF-16 filename. |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
338 |
25660
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
339 long length = GetShortPathNameW (w_full_file_name, nullptr, 0); |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
340 |
25660
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
341 if (length > 0) |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
342 { |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
343 // Dynamically allocate the correct size (terminating null char |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
344 // was included in length). |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
345 |
25660
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
346 wchar_t *w_short_file_name = new wchar_t[length]; |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
347 GetShortPathNameW (w_full_file_name, w_short_file_name, length); |
25609
506419b5f817
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
25532
diff
changeset
|
348 |
25660
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
349 std::wstring w_short_file_name_str |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
350 = std::wstring (w_short_file_name, length); |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
351 std::string short_file_name = u8_from_wstring (w_short_file_name_str); |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
352 |
25660
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
353 if (w_short_file_name_str.compare (0, length-1, w_full_file_name_str) != 0) |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
354 return short_file_name; |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
355 } |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
356 |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
357 // 3. Create hard link with only-ASCII characters. |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
358 // Get longest possible part of path that only contains ASCII chars. |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
359 |
25660
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
360 std::wstring::iterator w_first_non_ASCII |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
361 = std::find_if (w_full_file_name_str.begin (), w_full_file_name_str.end (), |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
362 [](wchar_t c) { return (c < 0 || c >= 128); }); |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
363 std::wstring tmp_substr |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
364 = std::wstring (w_full_file_name_str.begin (), w_first_non_ASCII); |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
365 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
366 size_t pos |
25660
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
367 = tmp_substr.find_last_of (u8_to_wstring (file_ops::dir_sep_chars ())); |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
368 |
25660
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
369 std::string par_dir |
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
370 = u8_from_wstring (w_full_file_name_str.substr (0, pos+1)); |
25609
506419b5f817
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
25532
diff
changeset
|
371 |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
372 // Create .oct_ascii directory. |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
373 // FIXME: We need to have write permission in this location. |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
374 |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
375 std::string oct_ascii_dir = par_dir + ".oct_ascii"; |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
376 std::string test_dir = canonicalize_file_name (oct_ascii_dir); |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
377 |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
378 if (test_dir.empty ()) |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
379 { |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
380 std::string msg; |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26531
diff
changeset
|
381 int status = sys::mkdir (oct_ascii_dir, 0777, msg); |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
382 |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
383 if (status < 0) |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
384 return orig_file_name; |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
385 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
386 // Set hidden property. |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
387 SetFileAttributesA (oct_ascii_dir.c_str (), FILE_ATTRIBUTE_HIDDEN); |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
388 } |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
389 |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
390 // Create file from hash of full filename. |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
391 std::string filename_hash |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
392 = (oct_ascii_dir + file_ops::dir_sep_str () |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26531
diff
changeset
|
393 + crypto::hash ("SHA1", orig_file_name)); |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
394 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
395 std::string abs_filename_hash = canonicalize_file_name (filename_hash); |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
396 |
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
397 if (! abs_filename_hash.empty ()) |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26531
diff
changeset
|
398 sys::unlink (filename_hash); |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
399 |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
400 wchar_t w_filename_hash[filename_hash.length ()+1] = {0}; |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
401 |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
402 for (size_t i=0; i < filename_hash.length (); i++) |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
403 w_filename_hash[i] = filename_hash.at (i); |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
404 |
25660
4de7535ece11
Relative path specifications for non-ASCII files on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
25615
diff
changeset
|
405 if (CreateHardLinkW (w_filename_hash, w_orig_file_name, nullptr)) |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
406 return filename_hash; |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
407 |
25615
ffc858064239
style fixes and commentary for get_ASCII_filename function (bug #54299)
John W. Eaton <jwe@octave.org>
parents:
25609
diff
changeset
|
408 #endif |
25532
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
409 |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
410 return orig_file_name; |
7dad5fa7e88e
Add function for ASCII only file names (bug #49118).
Markus Mützel <markus.muetzel@gmx.de>
parents:
25531
diff
changeset
|
411 } |
21738
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
412 } |
a99c2407f930
use namespace for lo-sysdep.h functions
John W. Eaton <jwe@octave.org>
parents:
21733
diff
changeset
|
413 } |