fdoc

subroutineexpand_includesrecursive

recursive subroutine expand_includes(search, directory, text, depth)

Replace include lines in text by the files they name, found in directory or search.

Arguments

NameTypeIntentAttributesDescription
directorycharacter(len=*)in

the directory of the including file

textcharacter(len=:)inoutallocatable

the text

depthintegerin

how many includes deep this is

Calls

Source

Show the code
recursive subroutine expand_includes(search, directory, text, depth)
    type(string_t), intent(in) :: search(:)             !! other directories to look in
    character(len=*), intent(in) :: directory           !! the directory of the including file
    character(len=:), allocatable, intent(inout) :: text  !! the text
    integer, intent(in) :: depth                        !! how many includes deep this is
    type(string_t), allocatable :: lines(:)
    character(len=:), allocatable :: name, found, contents, msg
    logical :: changed
    integer :: k, stat

    if (depth > MAX_INCLUDE_DEPTH) return
    if (index(lowercase(text), 'include') == 0) return
    lines = split_lines(text)
    changed = .false.
    do k = 1, size(lines)
        if (.not. include_name(lines(k)%s, name)) cycle
        found = locate(search, directory, name)
        if (len(found) == 0) then
            call warn('Can not find include file "'//name//'"')
            cycle
        end if
        call read_whole_file(found, contents, stat, msg)
        if (stat /= 0) cycle
        call expand_includes(search, parent_directory(found), contents, depth + 1)
        lines(k)%s = contents
        changed = .true.
    end do
    if (changed) text = join(lines, achar(10))//achar(10)
end subroutine expand_includes

Graphs

Calls

Called by