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
| Name | Type | Intent | Attributes | Description |
|---|---|---|---|---|
| low | character(len=*) | in | the file, in lowercase | |
| starts | integer | in | dimension(:) | where the lines to search start |
| stops | integer | in | dimension(:) | where they end |
| from | integer | in | the line to start from | |
| keyword | character(len=*) | in |
| |
| name | character(len=*) | in | the name, in lowercase | |
| found | integer | out | the line where it starts | |
| first | integer | out | where it starts, or 0 | |
| last | integer | out | 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