@@ -47,33 +47,39 @@ program main
47
47
call get_command_argument(first_argument,acceptable_version,status= stat)
48
48
call validate_command_line( stat )
49
49
50
- associate( compiler_version= > compiler_version() )
51
- associate(major_version= >major(compiler_version), acceptable_major= >major(acceptable_version))
52
- if ( major_version > acceptable_major ) then
53
- print * ,.true.
54
- else if ( major_version == acceptable_major ) then
55
- associate(minor_version= >minor(compiler_version), acceptable_minor= >minor(acceptable_version))
56
- if ( minor_version > acceptable_minor ) then
57
- print * ,.true.
58
- else if ( minor_version == acceptable_minor ) then
59
- associate(patch_version= >patch(compiler_version), acceptable_patch= >patch(acceptable_version))
60
- if ( patch_version >= acceptable_patch ) then
61
- print * ,.true.
62
- else
63
- print * ,.false.
64
- end if
65
- end associate
66
- else
67
- print * ,.false.
50
+ print * , patch_meets_minimum( acceptable_version )
51
+
52
+ contains
53
+
54
+ pure function patch_meets_minimum ( required_version ) result( is_acceptable)
55
+ character (len=* ), intent (in ) :: required_version
56
+ logical is_acceptable
57
+
58
+ is_acceptable = .false. ! default result
59
+
60
+ associate( actual_version = > compiler_version() )
61
+ associate(major_version= >major(actual_version), acceptable_major= >major(required_version))
62
+ if (major_version < acceptable_major) return
63
+ if (major_version > acceptable_major) then
64
+ is_acceptable = .true.
65
+ return
66
+ end if
67
+ associate(minor_version= >minor(actual_version), acceptable_minor= >minor(required_version))
68
+ if (minor_version < acceptable_minor) return
69
+ if (minor_version > acceptable_minor) then
70
+ is_acceptable = .true.
71
+ return
68
72
end if
73
+ associate(patch_version= >patch(actual_version), acceptable_patch= >patch(required_version))
74
+ if (patch_version < acceptable_patch) return
75
+ is_acceptable = .true.
76
+ end associate
69
77
end associate
70
- else
71
- print * ,.false.
72
- end if
78
+ end associate
73
79
end associate
74
- end associate
75
80
76
- contains
81
+
82
+ end function
77
83
78
84
subroutine validate_command_line ( command_line_status )
79
85
integer , intent (in ) :: command_line_status
@@ -118,29 +124,31 @@ pure function minor(version_string) result(minor_value)
118
124
end function
119
125
120
126
pure function patch (version_string ) result(patch_value)
127
+ use iso_fortran_env, only : iostat_end
121
128
character (len=* ), intent (in ) :: version_string
122
- integer patch_value
129
+ integer patch_value, io_stat
123
130
character (len= :), allocatable :: trailing_digits
124
131
125
132
associate( first_dot = > scan (version_string, ' .' ) )
126
133
associate( second_dot = > first_dot + scan (version_string(first_dot+1 :), ' .' ) )
127
- associate( first_non_digit = > second_dot + first_printable_non_digit (version_string(second_dot+1 :)) )
128
- trailing_digits = version_string( second_dot+1 : first_non_digit -1 )
129
- read (trailing_digits,* ) patch_value
134
+ associate( next_non_digit = > second_dot + next_printable_non_digit (version_string(second_dot+1 :)) )
135
+ trailing_digits = version_string( second_dot+1 : next_non_digit -1 )
136
+ read (trailing_digits, * , iostat = io_stat ) patch_value
130
137
end associate
131
138
end associate
132
139
end associate
133
140
134
141
end function
135
142
136
- pure function first_printable_non_digit ( string ) result(location)
143
+ pure function next_printable_non_digit ( string ) result(location)
137
144
character (len=* ), intent (in ) :: string
138
145
integer i, location
139
146
integer , parameter :: ASCII_non_digit(* )= [(i,i= 32 ,47 ),(i,i= 58 ,126 )]
140
147
character (len= 1 ), parameter :: non_digit(* )= [( char (ASCII_non_digit(i)) , i= 1 , size (ASCII_non_digit) )]
141
148
character (len= size (non_digit)) non_digit_string
142
149
write (non_digit_string,' (85a)' ) non_digit
143
150
location = scan (string,non_digit_string)
151
+ if (location== 0 ) location= len (string)+ 1
144
152
end function
145
153
146
154
end program
0 commit comments