Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c561108

Browse files
committed
separated examples according to OS and functions
1 parent ea71960 commit c561108

File tree

6 files changed

+72
-38
lines changed

6 files changed

+72
-38
lines changed

‎doc/specs/stdlib_system.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ Subroutine
628628

629629
- If `p` is empty, `head` is set to `.` and `tail` is empty
630630
- If `p` consists entirely of path-separators. `head` is set to the path-separator and `tail` is empty
631-
- `head` ends in a path-separator iff and only if `p` appears to be a root directory or child of one
631+
- `head` ends in a path-separator if and only if `p` appears to be a root directory or child of one
632632

633633
### Return values
634634

‎example/system/CMakeLists.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ ADD_EXAMPLE(process_6)
1212
ADD_EXAMPLE(process_7)
1313
ADD_EXAMPLE(sleep)
1414
ADD_EXAMPLE(path_1)
15+
ADD_EXAMPLE(path_1_windows)
16+
ADD_EXAMPLE(path_2)
17+
ADD_EXAMPLE(path_2_windows)

‎example/system/example_path_1.f90‎

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,17 @@
1-
program example_path
2-
use stdlib_system, only: joinpath, operator(/), splitpath, ISWIN, dirname, basename
3-
character(len=:), allocatable :: p1, p2, head, tail
1+
! Usage of joinpath, operator(/)
2+
program example_join
3+
use stdlib_system, only: joinpath, operator(/)
4+
character(len=:), allocatable :: p1, p2, p3
45
character(len=20) :: parr(4)
56

6-
if (ISWIN) then
7-
p1 = 'C:'/'Users'/'User1'/'Desktop'
8-
parr = [character(len=20) :: 'C:', 'Users', 'User1', 'Desktop']
9-
p2 = joinpath(parr)
7+
p1 = ''/'home'/'User1'/'Desktop'
8+
p2 = joinpath('/home/User1', 'Desktop')
109

11-
! p1 == p2 = 'C:\Users\User1\Desktop'
12-
print *, p1
13-
print *, "p1 == p2: ", p1 == p2
10+
parr = [character(len=20) :: '', 'home', 'User1', 'Desktop']
11+
p3 = joinpath(parr)
1412

15-
call splitpath(p1, head, tail)
16-
print *, p1 // " -> " // head // " + " // tail
17-
18-
call splitpath(head, p1, tail)
19-
print *, head // " -> " // p1 // " + " // tail
20-
21-
print *, 'dirname of '// p1 // ' -> ' // dirname(p1)
22-
print *, 'basename of '// p1 // ' -> ' // basename(p1)
23-
else
24-
p1 = ''/'home'/'User1'/'Desktop'
25-
parr = [character(len=20) :: '', 'home', 'User1', 'Desktop']
26-
p2 = joinpath(parr)
27-
28-
! p1 == p2 = '/home/User1/Desktop'
29-
print *, p1
30-
print *, "p1 == p2: ", p1 == p2
31-
32-
call splitpath(p1, head, tail)
33-
print *, p1 // " -> " // head // " + " // tail
34-
35-
call splitpath(head, p1, tail)
36-
print *, head // " -> " // p1 // " + " // tail
37-
38-
print *, 'dirname of '// p1 // ' -> ' // dirname(p1)
39-
print *, 'basename of '// p1 // ' -> ' // basename(p1)
40-
end if
41-
end program example_path
13+
! (p1 == p2 == p3) = '/home/User1/Desktop'
14+
print *, p1 ! /home/User1/Desktop
15+
print *, "p1 == p2: ", p1 == p2 ! T
16+
print *, "p2 == p3: ", p2 == p3 ! T
17+
end program example_join
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
! Usage of joinpath, operator(/)
2+
! Only Windows
3+
program example_join_windows
4+
use stdlib_system, only: joinpath, operator(/)
5+
character(len=:), allocatable :: p1, p2, p3
6+
character(len=20) :: parr(4)
7+
8+
p1 = 'C:'/'Users'/'User1'/'Desktop'
9+
p2 = joinpath('C:\Users\User1', 'Desktop')
10+
11+
parr = [character(len=20) :: 'C:', 'Users', 'User1', 'Desktop']
12+
p3 = joinpath(parr)
13+
14+
! (p1 == p2 == p3) = 'C:\Users\User1\Desktop'
15+
print *, p1 ! C:\Users\User1\Desktop
16+
print *, "p1 == p2: ", p1 == p2 ! T
17+
print *, "p2 == p3: ", p2 == p3 ! T
18+
end program example_join_windows

‎example/system/example_path_2.f90‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
! Usage of splitpath, dirname, basename
2+
program example_splitpath
3+
use stdlib_system, only: joinpath, splitpath, dirname, basename
4+
character(len=:), allocatable :: p1, head, tail
5+
6+
p1 = joinpath('/home/User1', 'Desktop') ! /home/User1/Desktop
7+
8+
call splitpath(p1, head, tail)
9+
! head = /home/User1, tail = Desktop
10+
print *, p1 // " -> " // head // " + " // tail ! /home/User1/Desktop -> /home/User1 + Desktop
11+
12+
call splitpath(head, p1, tail)
13+
! p1 = /home, tail = User1
14+
print *, head // " -> " // p1 // " + " // tail ! /home/User1 -> /home + User1
15+
16+
print *, 'dirname of '// p1 // ' -> ' // dirname(p1) ! dirname of /home -> /
17+
print *, 'basename of '// p1 // ' -> ' // basename(p1) ! basename of /home -> home
18+
end program example_splitpath
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
! Usage of splitpath, dirname, basename
2+
! Only Windows
3+
program example_splitpath_windows
4+
use stdlib_system, only: joinpath, splitpath, dirname, basename
5+
character(len=:), allocatable :: p1, head, tail
6+
7+
p1 = joinpath('C:\Users\User1', 'Desktop') ! C:\Users\User1\Desktop
8+
9+
call splitpath(p1, head, tail)
10+
! head = C:\Users\User1, tail = Desktop
11+
print *, p1 // " -> " // head // " + " // tail ! C:\Users\User1\Desktop -> C:\Users\User1 + Desktop
12+
13+
call splitpath(head, p1, tail)
14+
! p1 = C:\Users, tail = User1
15+
print *, head // " -> " // p1 // " + " // tail ! C:\Users\User1 -> C:\Users + User1
16+
17+
print *, 'dirname of '// p1 // ' -> ' // dirname(p1) ! dirname of C:\Users -> C:\
18+
print *, 'basename of '// p1 // ' -> ' // basename(p1) ! basename of C:\Users -> Users
19+
end program example_splitpath_windows

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /