Apply include/ignore rules to the watch list.
include patterns are empty, all files are included by default.include patterns are present, only matching files are kept.ignore patterns match a file, it is removed even if included.The masks array (when present) is filtered in sync with files.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| type(string_t), | intent(inout), | allocatable | :: | files(:) | ||
| type(string_t), | intent(in), | allocatable | :: | include(:) | ||
| type(string_t), | intent(in), | allocatable | :: | ignore(:) | ||
| integer(kind=int64), | intent(inout), | optional, | allocatable | :: | masks(:) |
subroutine filter_watch_files(files, include, ignore, masks) type(string_t), allocatable, intent(inout) :: files(:) type(string_t), allocatable, intent(in) :: include(:), ignore(:) integer(int64), allocatable, intent(inout), optional :: masks(:) logical, allocatable :: keep(:) type(string_t), allocatable :: out(:) integer(int64), allocatable :: outm(:) integer :: i, k, n, m if (.not. allocated(files)) return n = size(files) allocate(keep(n)) do i = 1, n keep(i) = should_keep(files(i)%s, include, ignore) end do m = count(keep) allocate(out(m)) if (present(masks)) then if (.not. allocated(masks)) then allocate(masks(n)) masks = 0_int64 end if allocate(outm(m)) end if k = 0 do i = 1, n if (.not. keep(i)) cycle k = k + 1 out(k)%s = files(i)%s if (present(masks)) outm(k) = masks(i) end do call move_alloc(out, files) if (present(masks)) call move_alloc(outm, masks) deallocate(keep) contains logical function should_keep(path, include_pats, ignore_pats) result(ok) character(len=*), intent(in) :: path type(string_t), allocatable, intent(in) :: include_pats(:), ignore_pats(:) character(len=:), allocatable :: b b = basename(trim(path)) if (b == "fpm.toml") then ok = .true. return end if ok = match_include(path, include_pats) .and. (.not. match_any(path, ignore_pats)) end function should_keep logical function match_any(path, pats) result(ok) character(len=*), intent(in) :: path type(string_t), allocatable, intent(in) :: pats(:) integer :: j character(len=:), allocatable :: pat ok = .false. if (.not. allocated(pats)) return do j = 1, size(pats) if (len_trim(pats(j)%s) == 0) cycle pat = normalize_path(trim(pats(j)%s)) if (glob(pat, trim(path))) then ok = .true. return end if end do end function match_any logical function match_include(path, pats) result(ok) character(len=*), intent(in) :: path type(string_t), allocatable, intent(in) :: pats(:) if (.not. allocated(pats)) then ok = .true. return end if if (size(pats) == 0) then ok = .true. return end if ok = match_any(path, pats) end function match_include end subroutine filter_watch_files