fdoc

subroutinefind_sourceprivate

subroutine find_source(low, starts, stops, from, keyword, name, found, first, last)

Find the text of the construct keyword name in low, from its first line to its end line.

Arguments

NameTypeIntentAttributesDescription
lowcharacter(len=*)in

the file, in lowercase

startsintegerindimension(:)

where the lines to search start

stopsintegerindimension(:)

where they end

fromintegerin

the line to start from

keywordcharacter(len=*)in

subroutine, function or type

namecharacter(len=*)in

the name, in lowercase

foundintegerout

the line where it starts

firstintegerout

where it starts, or 0

lastintegerout

where it ends

Calls

Source

Show the code
subroutine find_source(low, starts, stops, from, keyword, name, found, first, last)
    character(len=*), intent(in) :: low     !! the file, in lowercase
    integer, intent(in) :: starts(:)        !! where the lines to search start
    integer, intent(in) :: stops(:)         !! where they end
    integer, intent(in) :: from             !! the line to start from
    character(len=*), intent(in) :: keyword !! `subroutine`, `function` or `type`
    character(len=*), intent(in) :: name    !! the name, in lowercase
    integer, intent(out) :: found           !! the line where it starts
    integer, intent(out) :: first           !! where it starts, or 0
    integer, intent(out) :: last            !! where it ends
    integer :: k, at, comment

    first = 0
    last = 0
    found = 0
    do k = from, size(starts)
        associate (line => low(starts(k):stops(k)))
            if (index(line, name) == 0) cycle
            comment = index(line, '!')
            if (comment == 0) comment = len(line) + 1
            at = line_has(line(:comment - 1), keyword, name)
            if (at > 0 .and. first == 0 .and. .not. starts_word(adjustl(line), 'end')) then
                first = starts(k)
                found = k
            else if (first > 0 .and. at > 0 .and. starts_word(adjustl(line), 'end')) then
                last = stops(k)
                return
            end if
        end associate
    end do
    first = 0
end subroutine find_source

Graphs

Calls

Called by