sourcery_command_line_s.f90 Source File


This file depends on

sourcefile~~sourcery_command_line_s.f90~~EfferentGraph sourcefile~sourcery_command_line_s.f90 sourcery_command_line_s.f90 sourcefile~sourcery_command_line_m.f90 sourcery_command_line_m.f90 sourcefile~sourcery_command_line_s.f90->sourcefile~sourcery_command_line_m.f90

Source Code

submodule(sourcery_command_line_m) sourcery_command_line_s
  implicit none

contains

  module procedure argument_present
      !! list of acceptable arguments
      !! sample list: [character(len=len(longest_argument)):: "--benchmark", "-b", "/benchmark", "/b"]
      !! where dashes support Linux/macOS and slashes support Windows
    integer :: i, argnum, arglen
      !! loop counter, argument position, argument length
    character(len=32) arg
      !! argument position

      !! acceptable argument lengths (used to preclude extraneous trailing characters)

    associate(acceptable_length => [(len(trim(acceptable_argument(i))), i = 1, size(acceptable_argument))])

      found = .false.

      do argnum = 1,command_argument_count()

        call get_command_argument(argnum, arg, arglen)

        if (any( &
          [(arg==acceptable_argument(i) .and. arglen==acceptable_length(i), i = 1, size(acceptable_argument))] &
        )) then
          found = .true.
        end if

      end do

    end associate

  end procedure

  module procedure flag_value

    integer argnum, arglen, flag_value_length
    character(len=:), allocatable :: arg

    associate(argcount => command_argument_count())
      if (argcount==0) then
        flag_value=""
      else
        flag_search: &
        do argnum = 1,argcount

          if (allocated(arg)) deallocate(arg)

          call get_command_argument(argnum, length=arglen)
          allocate(character(len=arglen) :: arg)
          call get_command_argument(argnum, arg)

          if (arg==flag) then
            call get_command_argument(argnum+1, length=flag_value_length)
            allocate(character(len=flag_value_length) :: flag_value)
            call get_command_argument(argnum+1, flag_value)
            exit flag_search
          end if
        end do flag_search
      end if
    end associate

  end procedure

end submodule