pkgcfg_list_all Function

public function pkgcfg_list_all(error, descriptions) result(modules)

Return whole list of available pkg-cfg packages

Extract list

Arguments

Type IntentOptional Attributes Name
type(error_t), intent(out), allocatable :: error

Error handler

type(string_t), intent(out), optional, allocatable :: descriptions(:)

An optional list of package descriptions

Return Value type(string_t), allocatable, (:)

A list of all available packages


Source Code

function pkgcfg_list_all(error,descriptions) result(modules)
    
    !> Error handler
    type(error_t), allocatable, intent(out) :: error
    
    !> A list of all available packages 
    type(string_t), allocatable :: modules(:)    
    
    !> An optional list of package descriptions
    type(string_t), optional, allocatable, intent(out) :: descriptions(:)
    
    integer :: exitcode,i,spc
    logical :: success
    character(len=:), allocatable :: lines(:)
    type(string_t) :: log    
    type(string_t), allocatable :: mods(:),descr(:)
    character(*), parameter :: CRLF = achar(13)//new_line('a')
        
    call run_wrapper(wrapper=string_t('pkg-config'), &
                     args=[string_t('--list-all')], &
                     exitcode=exitcode,cmd_success=success,screen_output=log) 
                     
    if (.not.(success .and. exitcode==0)) then 
        call fatal_error(error,'cannot get pkg-config modules')
        allocate(modules(0))
        return
    end if
                    
    !> Extract list 
    call split(log%s,lines,CRLF)
    allocate(mods(size(lines)),descr(size(lines)))
    
    do i=1,size(lines)
        
        ! Module names have no spaces
        spc = index(lines(i),' ')
        
        if (spc>0) then 
            
            mods(i)  = string_t(trim(adjustl(lines(i)(1:spc))))
            descr(i) = string_t(trim(adjustl(lines(i)(spc+1:))))
            
        else
            
            mods(i)  = string_t(trim(adjustl(lines(i))))
            descr(i) = string_t("")
            
        end if
        
    end do
    
    call move_alloc(from=mods,to=modules)
    if (present(descriptions)) call move_alloc(from=descr,to=descriptions)
    
end function pkgcfg_list_all