next_positional Subroutine

private pure subroutine next_positional(this, used, idx)

Index of the next unfilled positional, advancing used.

A subroutine rather than a function because it advances the counter, and a pure function may not have an intent(inout) argument.

Arguments

Type IntentOptional Attributes Name
class(cli_t), intent(in) :: this
integer(kind=default_int), intent(inout) :: used

Positionals consumed so far; incremented when one is taken.

integer(kind=default_int), intent(out) :: idx

Index of the positional taken, or 0 when they are all filled.


Called by

proc~~next_positional~~CalledByGraph proc~next_positional next_positional proc~cli_parse_args cli_t%cli_parse_args proc~cli_parse_args->proc~next_positional proc~cli_parse cli_t%cli_parse proc~cli_parse->proc~cli_parse_args

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: i
integer(kind=default_int), private :: seen

Source Code

   pure subroutine next_positional(this, used, idx)
      !! Index of the next unfilled positional, advancing `used`.
      !!
      !! A subroutine rather than a function because it advances the counter,
      !! and a pure function may not have an `intent(inout)` argument.
      class(cli_t), intent(in) :: this
      integer(default_int), intent(inout) :: used
         !! Positionals consumed so far; incremented when one is taken.
      integer(default_int), intent(out) :: idx
         !! Index of the positional taken, or 0 when they are all filled.

      integer(default_int) :: i, seen

      idx = 0_default_int
      seen = 0_default_int
      do i = 1_default_int, this%count
         if (this%entries(i)%kind /= KIND_POSITIONAL) cycle
         seen = seen + 1_default_int
         if (seen > used) then
            used = seen
            idx = i
            return
         end if
      end do
   end subroutine next_positional