Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Consistent naming
  • Loading branch information
wassup05 committed Jun 19, 2025
commit 62bef00335d30a182901bde7371630cb98a92bfa
30 changes: 15 additions & 15 deletions doc/specs/stdlib_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ The file is removed from the filesystem if the operation is successful. If the o
{!example/system/example_delete_file.f90!}
```

## `joinpath` - Joins the provided paths according to the OS
## `join_path` - Joins the provided paths according to the OS

### Status

Expand All @@ -546,9 +546,9 @@ i.e `\` for windows and `/` for others

### Syntax

`res = ` [[stdlib_system(module):joinpath(interface)]] ` (p1, p2)`
`res = ` [[stdlib_system(module):join_path(interface)]] ` (p1, p2)`

`res = ` [[stdlib_system(module):joinpath(interface)]] ` (p)`
`res = ` [[stdlib_system(module):join_path(interface)]] ` (p)`

### Class
Pure function
Expand All @@ -565,7 +565,7 @@ The resultant path.

## `operator(/)`

Alternative syntax to`joinpath` using an overloaded operator. Join two paths according to the platform specific path-separator.
Alternative syntax to`join_path` using an overloaded operator. Join two paths according to the platform specific path-separator.

### Status

Expand Down Expand Up @@ -595,7 +595,7 @@ The result is an `allocatable` character string
{!example/system/example_path_join.f90!}
```

## `splitpath` - splits a path immediately following the last separator
## `split_path` - splits a path immediately following the last separator

### Status

Expand All @@ -608,7 +608,7 @@ splitting it into most of the times a directory and a file name.

### Syntax

`call `[[stdlib_system(module):splitpath(interface)]]`(p, head, tail)`
`call `[[stdlib_system(module):split_path(interface)]]`(p, head, tail)`

### Class
Subroutine
Expand All @@ -632,10 +632,10 @@ The splitted path. `head` and `tail`.
### Example

```fortran
{!example/system/example_path_splitpath.f90!}
{!example/system/example_path_split_path.f90!}
```

## `basename` - The last part of a path
## `base_name` - The last part of a path

### Status

Expand All @@ -647,7 +647,7 @@ This function returns the last part of a path after removing trailing path separ

### Syntax

`res = ` [[stdlib_system(module):basename(interface)]]`(p)`
`res = ` [[stdlib_system(module):base_name(interface)]]`(p)`

### Class
Function
Expand All @@ -658,7 +658,7 @@ Function

### Behavior

- The `tail` of `stdlib_system(module):splitpath(interface)` is exactly what is returned. Same Behavior.
- The `tail` of `stdlib_system(module):split_path(interface)` is exactly what is returned. Same Behavior.

### Return values

Expand All @@ -667,10 +667,10 @@ A character string.
### Example

```fortran
{!example/system/example_path_basename.f90!}
{!example/system/example_path_base_name.f90!}
```

## `dirname` - Everything except the last part of the path
## `dir_name` - Everything except the last part of the path

### Status

Expand All @@ -682,7 +682,7 @@ This function returns everything except the last part of a path.

### Syntax

`res = ` [[stdlib_system(module):dirname(interface)]]`(p)`
`res = ` [[stdlib_system(module):dir_name(interface)]]`(p)`

### Class
Function
Expand All @@ -693,7 +693,7 @@ Function

### Behavior

- The `head` of `stdlib_system(module):splitpath(interface)` is exactly what is returned. Same Behavior.
- The `head` of `stdlib_system(module):split_path(interface)` is exactly what is returned. Same Behavior.

### Return values

Expand All @@ -702,5 +702,5 @@ A character string.
### Example

```fortran
{!example/system/example_path_dirname.f90!}
{!example/system/example_path_dir_name.f90!}
```
6 changes: 3 additions & 3 deletions example/system/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ADD_EXAMPLE(process_5)
ADD_EXAMPLE(process_6)
ADD_EXAMPLE(process_7)
ADD_EXAMPLE(sleep)
ADD_EXAMPLE(path_basename)
ADD_EXAMPLE(path_dirname)
ADD_EXAMPLE(path_join)
ADD_EXAMPLE(path_splitpath)
ADD_EXAMPLE(path_split_path)
ADD_EXAMPLE(path_base_name)
ADD_EXAMPLE(path_dir_name)
16 changes: 16 additions & 0 deletions example/system/example_path_base_name.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
! Usage of base_name
program example_path_base_name
use stdlib_system, only: base_name, ISWIN
character(len=:), allocatable :: p1

if( ISWIN ) then
p1 = 'C:\Users'
else
p1 = '/home'
endif

print *, 'base name of '// p1 // ' -> ' // base_name(p1)
! base name of C:\Users -> Users
! OR
! base name of /home -> home
end program example_path_base_name
16 changes: 0 additions & 16 deletions example/system/example_path_basename.f90

This file was deleted.

16 changes: 16 additions & 0 deletions example/system/example_path_dir_name.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
! Usage of dir_name
program example_path_dir_name
use stdlib_system, only: dir_name, ISWIN
character(len=:), allocatable :: p1, head, tail

if( ISWIN ) then
p1 = 'C:\Users' ! C:\Users
else
p1 = '/home' ! /home
endif

print *, 'dir_name of '// p1 // ' -> ' // dir_name(p1)
! dir_name of C:\Users -> C:\
! OR
! dir_name of /home -> /
end program example_path_dir_name
16 changes: 0 additions & 16 deletions example/system/example_path_dirname.f90

This file was deleted.

12 changes: 6 additions & 6 deletions example/system/example_path_join.f90
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
! Usage of joinpath, operator(/)
! Usage of join_path, operator(/)
program example_path_join
use stdlib_system, only: joinpath, operator(/), ISWIN
use stdlib_system, only: join_path, operator(/), ISWIN
character(len=:), allocatable :: p1, p2, p3
character(len=20) :: parr(4)

if( ISWIN ) then
p1 = 'C:'/'Users'/'User1'/'Desktop'
p2 = joinpath('C:\Users\User1', 'Desktop')
p2 = join_path('C:\Users\User1', 'Desktop')
parr = [character(len=20) :: 'C:', 'Users', 'User1', 'Desktop']
p3 = joinpath(parr)
p3 = join_path(parr)
else
p1 = ''/'home'/'User1'/'Desktop'
p2 = joinpath('/home/User1', 'Desktop')
p2 = join_path('/home/User1', 'Desktop')
parr = [character(len=20) :: '', 'home', 'User1', 'Desktop']
p3 = joinpath(parr)
p3 = join_path(parr)
end if

! (p1 == p2 == p3) = '/home/User1/Desktop' OR 'C:\Users\User1\Desktop'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
! Usage of splitpath, dirname, basename
program example_path_splitpath
use stdlib_system, only: joinpath, splitpath, ISWIN
! Usage of split_path
program example_path_split_path
use stdlib_system, only: join_path, split_path, ISWIN
character(len=:), allocatable :: p1, head, tail

if( ISWIN ) then
p1 = joinpath('C:\Users\User1', 'Desktop') ! C:\Users\User1\Desktop
p1 = join_path('C:\Users\User1', 'Desktop') ! C:\Users\User1\Desktop
else
p1 = joinpath('/home/User1', 'Desktop') ! /home/User1/Desktop
p1 = join_path('/home/User1', 'Desktop') ! /home/User1/Desktop
endif

call splitpath(p1, head, tail)
call split_path(p1, head, tail)
! head = /home/User1 OR C:\Users\User1, tail = Desktop
print *, p1 // " -> " // head // " + " // tail
! C:\Users\User1\Desktop -> C:\Users\User1 + Desktop
! OR
! /home/User1/Desktop -> /home/User1 + Desktop

call splitpath(head, p1, tail)
call split_path(head, p1, tail)
! p1 = /home OR C:\Users, tail = User1
print *, head // " -> " // p1 // " + " // tail
! C:\Users\User1 -> C:\Users + User1
! OR
! /home/User1 -> /home + User1
end program example_path_splitpath
end program example_path_split_path
50 changes: 25 additions & 25 deletions src/stdlib_system.F90
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ module stdlib_system
logical, parameter, public :: ISWIN = .false.
#endif

public :: joinpath
public :: join_path
public :: operator(/)
public :: splitpath
public :: basename
public :: dirname
public :: split_path
public :: base_name
public :: dir_name

!! version: experimental
!!
Expand Down Expand Up @@ -565,12 +565,12 @@ end function process_get_ID

end interface

interface joinpath
interface join_path
!! version: experimental
!!
!!### Summary
!! join the paths provided according to the OS-specific path-separator
!! ([Specification](../page/specs/stdlib_system.html#joinpath))
!! ([Specification](../page/specs/stdlib_system.html#join_path))
!!
module pure function join2(p1, p2) result(path)
character(:), allocatable :: path
Expand All @@ -581,7 +581,7 @@ module pure function joinarr(p) result(path)
character(:), allocatable :: path
character(*), intent(in) :: p(:)
end function joinarr
end interface joinpath
end interface join_path

interface operator(/)
!! version: experimental
Expand All @@ -596,54 +596,54 @@ module pure function join_op(p1, p2) result(path)
end function join_op
end interface operator(/)

interface splitpath
interface split_path
!! version: experimental
!!
!!### Summary
!! splits the path immediately following the final path-separator
!! separating into typically a directory and a file name.
!! ([Specification](../page/specs/stdlib_system.html#splitpath))
!! ([Specification](../page/specs/stdlib_system.html#split_path))
!!
!!### Description
!! If the path is empty `head`='.' and tail=''
!! If the path only consists of separators, `head` is set to the separator and tail is empty
!! If the path is a root directory, `head` is set to that directory and tail is empty
!! `head` ends with a path-separator iff the path appears to be a root directory or a child of the root directory
module subroutine splitpath(p, head, tail)
module subroutine split_path(p, head, tail)
character(*), intent(in) :: p
character(:), allocatable, intent(out) :: head, tail
end subroutine splitpath
end interface splitpath
end subroutine split_path
end interface split_path

interface basename
interface base_name
!! version: experimental
!!
!!### Summary
!! returns the basename (last component) of the provided path
!! ([Specification](../page/specs/stdlib_system.html#basename))
!! returns the base name (last component) of the provided path
!! ([Specification](../page/specs/stdlib_system.html#base_name))
!!
!!### Description
!! The value returned is the `tail` of the interface `splitpath`
module function basename(p) result(base)
!! The value returned is the `tail` of the interface `split_path`
module function base_name(p) result(base)
character(:), allocatable :: base
character(*), intent(in) :: p
end function basename
end interface basename
end function base_name
end interface base_name

interface dirname
interface dir_name
!! version: experimental
!!
!!### Summary
!! returns everything but the last component of the provided path
!! ([Specification](../page/specs/stdlib_system.html#dirname))
!! ([Specification](../page/specs/stdlib_system.html#dir_name))
!!
!!### Description
!! The value returned is the `head` of the interface `splitpath`
module function dirname(p) result(base)
!! The value returned is the `head` of the interface `split_path`
module function dir_name(p) result(base)
character(:), allocatable :: base
character(*), intent(in) :: p
end function dirname
end interface dirname
end function dir_name
end interface dir_name


contains
Expand Down
Loading
Loading