Skip to content

Commit

Permalink
Fix selection problems
Browse files Browse the repository at this point in the history
  • Loading branch information
aradi committed Apr 7, 2024
1 parent 63d79da commit 42b1f22
Show file tree
Hide file tree
Showing 2 changed files with 163 additions and 81 deletions.
34 changes: 24 additions & 10 deletions src/fortuno/argumentparser.f90
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ module fortuno_argumentparser
end type argument_value


! Workaround:gfortran:13.2
! Needs user defined structure constructor to deal with class(*) field
interface argument_value
module procedure new_argument_value
end interface


!> Collection of all argument values obtained after command line had been prased
type :: argument_values
private
Expand Down Expand Up @@ -174,7 +181,7 @@ subroutine argument_parser_parse_args(this, argumentvalues, logger, exitcode)
if (matches) then
select case (argdef%argtype)
case (argtypes%bool)
argumentvalues%argvals = [argumentvalues%argvals, argument_value(name=argdef%name)]
argumentvalues%argvals = [argumentvalues%argvals, argument_value(argdef%name)]
case default
call logger%log_error("Unknown argument type")
exitcode = 1
Expand All @@ -194,15 +201,8 @@ subroutine argument_parser_parse_args(this, argumentvalues, logger, exitcode)
associate (argdef => this%argdefs(nargdefs))
! If the last argdef was not an option, store all position arguments under this name
if (.not. allocated(argdef%longopt) .and. argdef%shortopt == "") then
! argumentvalues%argvals = [argumentvalues%argvals,&
! & argument_value(name=argdef%name, argval=string_list(posargs))]
! Workaround:gfortran:13.2
block
class(*), allocatable :: tmp
tmp = string_list(posargs)
argumentvalues%argvals = [argumentvalues%argvals,&
& argument_value(name=argdef%name, argval=tmp)]
end block
argumentvalues%argvals = [argumentvalues%argvals,&
& argument_value(argdef%name, argval=string_list(posargs))]
else if (size(posargs) > 1) then
call logger%log_error("Superfluous positional arguments found")
exitcode = 1
Expand Down Expand Up @@ -270,6 +270,20 @@ subroutine argument_values_get_value_stringlist(this, name, val)
end subroutine argument_values_get_value_stringlist


!> User defined structure constructor for argument_value
function new_argument_value(name, argval) result(this)
character(*), intent(in) :: name
class(*), optional, intent(in) :: argval
type(argument_value) :: this

this%name = name
if (present(argval)) then
allocate(this%argval, source=argval)
end if

end function new_argument_value


!! Returns the command line arguments as an array of strings.
subroutine get_command_line_args_(cmdargs)
type(string), allocatable :: cmdargs(:)
Expand Down
Loading

0 comments on commit 42b1f22

Please sign in to comment.