Skip to content

Commit 65f85e1

Browse files
committed
remove pre-processor parameters
1 parent 1c87df9 commit 65f85e1

File tree

9 files changed

+39
-44
lines changed

9 files changed

+39
-44
lines changed

CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU AND CMAKE_Fortran_COMPILER_VERSION VER
3131
message(FATAL_ERROR "GCC Version 9 or newer required")
3232
endif()
3333

34-
# Convert CMAKE_SYSTEM_NAME to uppercase
35-
string(TOUPPER "${CMAKE_SYSTEM_NAME}" SYSTEM_NAME_UPPER)
36-
37-
# Pass the uppercase system name as a macro
38-
add_compile_options(-D${SYSTEM_NAME_UPPER})
39-
4034
# --- compiler feature checks
4135
include(CheckFortranSourceCompiles)
4236
include(CheckFortranSourceRuns)

config/fypp_deployment.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
import platform
32
import fypp
43
import argparse
54
from joblib import Parallel, delayed
@@ -116,7 +115,6 @@ def fpm_build(args,unknown):
116115
for idx, arg in enumerate(unknown):
117116
if arg.startswith("--flag"):
118117
flags= flags + unknown[idx+1]
119-
flags = flags + "-D{}".format(platform.system().upper())
120118
#==========================================
121119
# build with fpm
122120
subprocess.run("fpm build"+

example/system/example_path_base_name.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
! Usage of base_name
22
program example_path_base_name
3-
use stdlib_system, only: base_name, ISWIN
3+
use stdlib_system, only: base_name, OS_TYPE, OS_WINDOWS
44
character(len=:), allocatable :: p1
55

6-
if( ISWIN ) then
6+
if(OS_TYPE() == OS_WINDOWS) then
77
p1 = 'C:\Users'
88
else
99
p1 = '/home'

example/system/example_path_dir_name.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
! Usage of dir_name
22
program example_path_dir_name
3-
use stdlib_system, only: dir_name, ISWIN
3+
use stdlib_system, only: dir_name, OS_TYPE, OS_WINDOWS
44
character(len=:), allocatable :: p1, head, tail
55

6-
if( ISWIN ) then
6+
if(OS_TYPE() == OS_WINDOWS) then
77
p1 = 'C:\Users' ! C:\Users
88
else
99
p1 = '/home' ! /home

example/system/example_path_join.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
! Usage of join_path, operator(/)
22
program example_path_join
3-
use stdlib_system, only: join_path, operator(/), ISWIN
3+
use stdlib_system, only: join_path, operator(/), OS_TYPE, OS_WINDOWS
44
character(len=:), allocatable :: p1, p2, p3
55
character(len=20) :: parr(4)
66

7-
if( ISWIN ) then
7+
if(OS_TYPE() == OS_WINDOWS) then
88
p1 = 'C:'/'Users'/'User1'/'Desktop'
99
p2 = join_path('C:\Users\User1', 'Desktop')
1010
parr = [character(len=20) :: 'C:', 'Users', 'User1', 'Desktop']

example/system/example_path_split_path.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
! Usage of split_path
22
program example_path_split_path
3-
use stdlib_system, only: join_path, split_path, ISWIN
3+
use stdlib_system, only: join_path, split_path, OS_TYPE, OS_WINDOWS
44
character(len=:), allocatable :: p1, head, tail
55

6-
if( ISWIN ) then
6+
if(OS_TYPE() == OS_WINDOWS) then
77
p1 = join_path('C:\Users\User1', 'Desktop') ! C:\Users\User1\Desktop
88
else
99
p1 = join_path('/home/User1', 'Desktop') ! /home/User1/Desktop

src/stdlib_system.F90

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,7 @@ module stdlib_system
8585
public :: is_windows
8686

8787
!! Public path related functions and interfaces
88-
#ifdef WINDOWS
89-
character(len=1), parameter, public :: pathsep = '\'
90-
logical, parameter, public :: ISWIN = .true.
91-
#else
92-
character(len=1), parameter, public :: pathsep = '/'
93-
logical, parameter, public :: ISWIN = .false.
94-
#endif
95-
88+
public :: path_sep
9689
public :: join_path
9790
public :: operator(/)
9891
public :: split_path
@@ -572,12 +565,12 @@ end function process_get_ID
572565
!! join the paths provided according to the OS-specific path-separator
573566
!! ([Specification](../page/specs/stdlib_system.html#join_path))
574567
!!
575-
module pure function join2(p1, p2) result(path)
568+
module function join2(p1, p2) result(path)
576569
character(:), allocatable :: path
577570
character(*), intent(in) :: p1, p2
578571
end function join2
579572

580-
module pure function joinarr(p) result(path)
573+
module function joinarr(p) result(path)
581574
character(:), allocatable :: path
582575
character(*), intent(in) :: p(:)
583576
end function joinarr
@@ -590,7 +583,7 @@ end function joinarr
590583
!! A binary operator to join the paths provided according to the OS-specific path-separator
591584
!! ([Specification](../page/specs/stdlib_system.html#operator(/)))
592585
!!
593-
module pure function join_op(p1, p2) result(path)
586+
module function join_op(p1, p2) result(path)
594587
character(:), allocatable :: path
595588
character(*), intent(in) :: p1, p2
596589
end function join_op
@@ -866,4 +859,12 @@ subroutine delete_file(path, err)
866859
end if
867860
end subroutine delete_file
868861

862+
character function path_sep()
863+
if (OS_TYPE() == OS_WINDOWS) then
864+
path_sep = '\'
865+
else
866+
path_sep = '/'
867+
end if
868+
end function path_sep
869+
869870
end module stdlib_system

src/stdlib_system_path.f90

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
use stdlib_ascii, only: reverse
33
use stdlib_strings, only: chomp, find, join
44
contains
5-
module pure function join2(p1, p2) result(path)
5+
module function join2(p1, p2) result(path)
66
character(:), allocatable :: path
77
character(*), intent(in) :: p1, p2
88

9-
path = trim(p1) // pathsep // trim(p2)
9+
path = trim(p1) // path_sep() // trim(p2)
1010
end function join2
1111

12-
module pure function joinarr(p) result(path)
12+
module function joinarr(p) result(path)
1313
character(:), allocatable :: path
1414
character(*), intent(in) :: p(:)
1515

16-
path = join(p, pathsep)
16+
path = join(p, path_sep())
1717
end function joinarr
1818

19-
module pure function join_op(p1, p2) result(path)
19+
module function join_op(p1, p2) result(path)
2020
character(:), allocatable :: path
2121
character(*), intent(in) :: p1, p2
2222

@@ -28,6 +28,8 @@ module subroutine split_path(p, head, tail)
2828
character(:), allocatable, intent(out) :: head, tail
2929
character(:), allocatable :: temp
3030
integer :: i
31+
character(len=1) :: sep
32+
sep = path_sep()
3133

3234
! Empty string, return (.,'')
3335
if (trim(p) == '') then
@@ -37,28 +39,28 @@ module subroutine split_path(p, head, tail)
3739
end if
3840

3941
! Remove trailing path separators
40-
temp = trim(chomp(trim(p), pathsep))
42+
temp = trim(chomp(trim(p), sep))
4143

4244
if (temp == '') then
43-
head = pathsep
45+
head = sep
4446
tail = ''
4547
return
4648
end if
4749

48-
i = find(reverse(temp), pathsep)
50+
i = find(reverse(temp), sep)
4951

5052
! if no `pathsep`, then it probably was a root dir like `C:\`
5153
if (i == 0) then
52-
head = temp // pathsep
54+
head = temp // sep
5355
tail = ''
5456
return
5557
end if
5658

5759
head = temp(:len(temp)-i)
5860

5961
! child of a root directory
60-
if (find(head, pathsep) == 0) then
61-
head = head // pathsep
62+
if (find(head, sep) == 0) then
63+
head = head // sep
6264
end if
6365

6466
tail = temp(len(temp)-i+2:)

test/system/test_path.f90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module test_path
22
use testdrive, only : new_unittest, unittest_type, error_type, check, skip_test
3-
use stdlib_system, only: join_path, operator(/), split_path, ISWIN
3+
use stdlib_system, only: join_path, operator(/), split_path, OS_TYPE, OS_WINDOWS
44
implicit none
55
contains
66
!> Collect all exported unit tests
@@ -32,7 +32,7 @@ subroutine test_join_path(error)
3232
character(len=:), allocatable :: path
3333
character(len=20) :: paths(5)
3434

35-
if (ISWIN) then
35+
if (OS_TYPE() == OS_WINDOWS) then
3636
path = join_path('C:\Users', 'Alice')
3737
call checkpath(error, 'join_path', 'C:\Users\Alice', path)
3838
if (allocated(error)) return
@@ -43,8 +43,8 @@ subroutine test_join_path(error)
4343
call checkpath(error, 'join_path', 'C:\Users\Bob\Pictures\2025', path)
4444
if (allocated(error)) return
4545

46-
path = join_path('C:\Users\John Doe', 'Pictures\2025') ! path with spaces
47-
call checkpath(error, 'join_path', 'C:\Users\John Doe\Pictures\2025', path)
46+
path = join_path('"C:\Users\John Doe"', 'Pictures\2025') ! path with spaces
47+
call checkpath(error, 'join_path', '"C:\Users\John Doe"\Pictures\2025', path)
4848
if (allocated(error)) return
4949
else
5050
path = join_path('/home', 'Alice')
@@ -64,7 +64,7 @@ subroutine test_join_path_op(error)
6464
type(error_type), allocatable, intent(out) :: error
6565
character(len=:), allocatable :: path
6666

67-
if (ISWIN) then
67+
if (OS_TYPE() == OS_WINDOWS) then
6868
path = 'C:'/'Users'/'Alice'/'Desktop'
6969
call checkpath(error, 'join_path operator', 'C:\Users\Alice\Desktop', path)
7070
if (allocated(error)) return
@@ -85,7 +85,7 @@ subroutine test_split_path(error)
8585
call checkpath(error, 'split_path-tail', '', tail)
8686
if (allocated(error)) return
8787

88-
if (ISWIN) then
88+
if (OS_TYPE() == OS_WINDOWS) then
8989
call split_path('\\\\', head, tail)
9090
call checkpath(error, 'split_path-head', '\', head)
9191
if (allocated(error)) return

0 commit comments

Comments
 (0)