cla__do_find_subc Subroutine

private subroutine cla__do_find_subc(cla)

Processes the debug command, reads a subcommand and a sub-subcommand, and calls the corresponding procedure.

Type Bound

cla_t

Arguments

Type IntentOptional Attributes Name
class(cla_t), intent(inout) :: cla

Source Code

   subroutine cla__do_find_subc(cla)
      use :: forgex_cli_find_m
      implicit none
      class(cla_t), intent(inout) :: cla
      logical :: is_exactly
      integer :: pattern_offset
      character(:), allocatable :: text

      pattern_offset = 4

      call cla%init_find()
      call cla%read_subc()
      if (cla%sub_cmd%get_name() == '') then
         call print_help_find
      else if (cla%sub_cmd%get_name() == SUBC_MATCH) then
         call cla%init_find_match()
      endif

      call cla%read_subsubc()
      if (cla%sub_sub_cmd%get_name() == '') then
         select case (cla%sub_cmd%get_name())
         case (SUBC_MATCH)
            call print_help_find_match
         end select
      end if

      call cla%get_patterns(pattern_offset)

      if (.not. allocated(cla%patterns)) then
         select case(cla%sub_sub_cmd%get_name())
         case (ENGINE_LAZY_DFA)
            call print_help_find_match_lazy_dfa
         case (ENGINE_DENSE_DFA)
            call print_help_find_match_dense_dfa
         case (ENGINE_FORGEX_API)
            call print_help_find_match_forgex_api
         end select
      end if

      if ( cla%sub_sub_cmd%get_name() == ENGINE_LAZY_DFA  &
           .or. cla%sub_sub_cmd%get_name() == ENGINE_DENSE_DFA &
           .or. cla%sub_sub_cmd%get_name() == ENGINE_FORGEX_API) then
         if (size(cla%patterns) /= 3 .and. size(cla%patterns) /= 2) then
            write(stderr, "(a, i0, a)") "Three arguments are expected, but ", size(cla%patterns), " were given."
            stop
         else if (cla%patterns(2)%p /= OP_MATCH .and. cla%patterns(2)%p /= OP_IN) then
            write(stderr, "(a)") "Operator "//OP_MATCH//" or "//OP_IN//" are expected, but "//cla%patterns(2)%p//" was given."
            stop
         end if

         if (cla%patterns(2)%p == OP_MATCH) then
            is_exactly = .true.
         else if (cla%patterns(2)%p == OP_IN) then
            is_exactly = .false.
         else
            write(stderr, '(a)') "Unknown operator: "//cla%patterns(2)%p
         end if
      else
         call print_help_find_match
      end if

      if (size(cla%patterns) == 2) then
         text = ''
      else
         text = cla%patterns(3)%p
      end if

      select case (cla%sub_sub_cmd%get_name())
      case (ENGINE_LAZY_DFA)
         call do_find_match_lazy_dfa(cla%flags, cla%patterns(1)%p, text, is_exactly)
      case (ENGINE_DENSE_DFA)
         call do_find_match_dense_dfa(cla%flags, cla%patterns(1)%p, text, is_exactly)
      case (ENGINE_FORGEX_API)
         call do_find_match_forgex(cla%flags, cla%patterns(1)%p, text, is_exactly)
      case default
         call print_help_find_match
      end select

   end subroutine cla__do_find_subc