Skip to content

Commit b2f5bcc

Browse files
committed
oct: relative, proximate [skip ci]
1 parent 4691b76 commit b2f5bcc

File tree

6 files changed

+62
-4
lines changed

6 files changed

+62
-4
lines changed

+stdlib/proximate_to.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%% PROXIMATE_TO relative path to base
1+
%% PROXIMATE_TO relative path to base (requires MEX)
22
%
33
%%% Inputs
44
% * base (1,1) string
@@ -10,4 +10,4 @@
1010

1111
function proximate_to(~,~)
1212
error("buildtool mex")
13-
end
13+
end

+stdlib/relative_to.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
%% RELATIVE_TO relative path to base
1+
%% RELATIVE_TO relative path to base (requires MEX)
22
%
33
%%% Inputs
44
% * base (1,1) string

octave_build.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
% Build C++-based .oct file for GNU Octave
2+
function octave_build(overwrite)
3+
if nargin < 1, overwrite = false; end
24

35
assert(stdlib.isoctave(), "for GNU Octave only")
46

@@ -13,6 +15,8 @@
1315
fullfile(d, "is_wsl.cpp"), ...
1416
fullfile(d, "is_rosetta.cpp"), ...
1517
fullfile(d, "is_admin.cpp"), ...
18+
fullfile(d, "proximate_to.cpp"), ...
19+
fullfile(d, "relative_to.cpp"), ...
1620
};
1721

1822

@@ -21,6 +25,10 @@
2125
src = s{1};
2226
[~, n] = fileparts(src);
2327

28+
if ~overwrite && isfile(fullfile(t, [n, ".oct"]))
29+
continue
30+
end
31+
2432
disp(["mkoctfile: ", src, " => ", n, ".oct"])
2533
mkoctfile(src, ["-I", inc], "--output", fullfile(t, n))
2634
end

src/octave/drop_slash.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <string>
44

5-
#include "os.cpp"
5+
#include "pure.cpp"
66
#include "normalize.cpp"
77

88

src/octave/proximate_to.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <octave/oct.h>
2+
3+
#include <string>
4+
#include <filesystem>
5+
#include <system_error>
6+
7+
8+
DEFUN_DLD (proximate_to, args, nargout,
9+
"path proximate to base path")
10+
{
11+
if (args.length() != 2){
12+
octave_stdout << "Oct: Two inputs required\n";
13+
return octave_value("");
14+
}
15+
16+
std::error_code ec;
17+
18+
std::string out = std::filesystem::proximate(args(1).string_value(),
19+
args(0).string_value(), ec).generic_string();
20+
21+
if(ec)
22+
octave_stdout << ec.message() << "\n";
23+
24+
return octave_value(out);
25+
}

src/octave/relative_to.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <octave/oct.h>
2+
3+
#include <string>
4+
#include <filesystem>
5+
#include <system_error>
6+
7+
8+
DEFUN_DLD (relative_to, args, nargout,
9+
"path relative to base path")
10+
{
11+
if (args.length() != 2){
12+
octave_stdout << "Oct: Two inputs required\n";
13+
return octave_value("");
14+
}
15+
16+
std::error_code ec;
17+
18+
std::string out = std::filesystem::relative(args(1).string_value(),
19+
args(0).string_value(), ec).generic_string();
20+
21+
if(ec)
22+
octave_stdout << ec.message() << "\n";
23+
24+
return octave_value(out);
25+
}

0 commit comments

Comments
 (0)