public subroutine split_append(argv, str, join_spaced, keep_quotes, ok)
Split a command fragment into argv tokens with the OS-native lexer and
append them to argv. fortran-shlex is not reentrant, so the split runs
in a critical region. join_spaced/keep_quotes apply to the POSIX lexer;
the Windows lexer already returns final argv tokens.
Arguments
| Type |
Intent | Optional | Attributes |
|
Name |
|
|
type(string_t),
|
intent(inout), |
|
allocatable
|
:: |
argv(:) |
|
|
character(len=*),
|
intent(in) |
|
|
:: |
str |
|
|
logical,
|
intent(in) |
|
|
:: |
join_spaced |
|
|
logical,
|
intent(in) |
|
|
:: |
keep_quotes |
|
|
logical,
|
intent(inout) |
|
|
:: |
ok |
|
Variables
| Type |
Visibility | Attributes |
|
Name |
| Initial | |
|
integer,
|
public |
|
:: |
k |
|
|
|
|
character(len=:),
|
public, |
allocatable
|
:: |
parts(:) |
|
|
|
Source Code
subroutine split_append(argv, str, join_spaced, keep_quotes, ok)
type(string_t), allocatable, intent(inout) :: argv(:)
character(len=*), intent(in) :: str
logical, intent(in) :: join_spaced, keep_quotes
logical, intent(inout) :: ok
character(len=:), allocatable :: parts(:)
integer :: k
if (.not.ok) return
! fortran-shlex is not reentrant, and the deferred-length parts(:) result it
! returns must be consumed before another thread re-enters the lexer. Hold the
! lock across both the split and the readback into argv.
!$omp critical(fpm_shlex_split)
if (os_is_unix()) then
parts = sh_split(str, join_spaced=join_spaced, keep_quotes=keep_quotes, success=ok)
else
parts = ms_split(str, success=ok)
end if
if (ok) then
do k = 1, size(parts)
if (len_trim(parts(k)) == 0) cycle
if (os_is_unix()) then
call add_strings(argv, string_t(clean_shlex_token(parts(k))))
else
call add_strings(argv, string_t(trim(parts(k))))
end if
end do
end if
!$omp end critical(fpm_shlex_split)
end subroutine split_append