subroutine push_file_with_mask(files, file_mask, path, build_dir, mask, dep_dirs)
type(string_t), allocatable, intent(inout) :: files(:)
integer(int64), allocatable, intent(inout) :: file_mask(:)
character(len=*), intent(in) :: path
character(len=*), intent(in) :: build_dir
integer(int64), intent(in) :: mask
type(string_t), allocatable, intent(in), optional :: dep_dirs(:)
type(string_t), allocatable :: buf(:)
integer(int64), allocatable :: mbuf(:)
integer :: n, cap, i
if (.not. allocated(files)) then
n = 0
cap = 8
allocate(buf(cap), mbuf(cap))
else
n = size(files)
cap = max(8, n)
allocate(buf(cap), mbuf(cap))
do i = 1, n
buf(i)%s = files(i)%s
mbuf(i) = file_mask(i)
end do
end if
if (present(dep_dirs)) then
call vec_push_unique(buf, mbuf, n, cap, path, build_dir, mask, dep_dirs)
else
call vec_push_unique(buf, mbuf, n, cap, path, build_dir, mask)
end if
call finalize_vec(buf, mbuf, n, files, file_mask)
contains
subroutine finalize_vec(buf, mbuf, n, files, file_mask)
type(string_t), allocatable, intent(inout) :: buf(:)
integer(int64), allocatable, intent(inout) :: mbuf(:)
integer, intent(in) :: n
type(string_t), allocatable, intent(inout) :: files(:)
integer(int64), allocatable, intent(inout) :: file_mask(:)
type(string_t), allocatable :: out(:)
integer(int64), allocatable :: outm(:)
integer :: k
if (allocated(files)) deallocate(files)
if (allocated(file_mask)) deallocate(file_mask)
if (n <= 0) then
allocate(files(0), file_mask(0))
deallocate(buf, mbuf)
return
end if
allocate(out(n), outm(n))
do k = 1, n
call move_alloc(buf(k)%s, out(k)%s)
outm(k) = mbuf(k)
end do
deallocate(buf, mbuf)
call move_alloc(out, files)
call move_alloc(outm, file_mask)
end subroutine finalize_vec
end subroutine push_file_with_mask