subroutine get_options(self, args, table)
type(targ_type), intent(in) :: self
type(arg_type), allocatable, intent(inout) :: args(:)
type(arg_type), allocatable :: tmp(:)
type(toml_table), allocatable, intent(out) :: table
type(toml_array), pointer :: array
character(len=:), allocatable :: arg
integer :: iarg, ipos, iopt, ii
logical :: getopts
table = toml_table()
allocate(tmp(size(args)))
getopts = .true.
ipos = 0
iarg = 0
do while(iarg < size(args))
iarg = iarg + 1
call move_alloc(args(iarg)%arg, arg)
if (getopts) then
getopts = arg /= "--"
if (.not.getopts) cycle
call match_option(self, arg, iopt)
if (iopt > 0) then
select case(self%opt(iopt)%require)
case(0)
call set_value(table, self%opt(iopt)%name, .true.)
case(1)
iarg = iarg + 1
if (iarg <= size(args)) then
call set_value(table, self%opt(iopt)%name, args(iarg)%arg)
end if
case default
if (iarg + self%opt(iopt)%require <= size(args)) then
call add_array(table, self%opt(iopt)%name, array)
do ii = 1, self%opt(iopt)%require
call set_value(array, ii, args(iarg+ii)%arg)
end do
iarg = iarg + self%opt(iopt)%require
end if
end select
cycle
end if
end if
ipos = ipos + 1
call move_alloc(arg, tmp(ipos)%arg)
end do
deallocate(args)
allocate(args(ipos))
do ipos = 1, size(args)
call move_alloc(tmp(ipos)%arg, args(ipos)%arg)
end do
end subroutine get_options