fdoc

subroutineset_mapprivate

subroutine set_map(s, key, values, stat, errmsg)

Set a map option from strings of the form key<sep>value. Empty strings are ignored.

Arguments

NameTypeIntentAttributesDescription
stype(settings_t)inout

the settings

keycharacter(len=*)in

the option

valuestype(string_t)indimension(:)

its values

statintegerout

nonzero on failure

errmsgcharacter(len=:)outallocatable

what is wrong

Calls

Source

Show the code
subroutine set_map(s, key, values, stat, errmsg)
    type(settings_t), intent(inout) :: s                !! the settings
    character(len=*), intent(in) :: key                 !! the option
    type(string_t), intent(in) :: values(:)             !! its values
    integer, intent(out) :: stat                        !! nonzero on failure
    character(len=:), allocatable, intent(out) :: errmsg  !! what is wrong
    type(map_entry_t), allocatable :: entries(:)
    type(file_type_t), allocatable :: files(:)
    type(string_t), allocatable :: words(:)
    character :: sep
    integer :: k, at

    stat = 0
    if (key == 'extra_filetypes') then
        allocate (files(0))
        do k = 1, size(values)
            if (len(values(k)%s) == 0) cycle
            words = split_words(values(k)%s)
            if (size(words) < 2 .or. size(words) > 3) then
                stat = 1
                errmsg = "Unexpected format for 'extra_filetype': expected 'extension comment [lexer]', got "//values(k)%s
                return
            end if
            files = [files, file_type_t(words(1)%s, words(2)%s)]
            if (size(words) == 3) files(size(files))%lexer = words(3)%s
        end do
        call move_alloc(files, s%extra_filetypes)
        return
    end if

    sep = merge(':', '=', key == 'extra_mods')
    allocate (entries(0))
    do k = 1, size(values)
        if (len(values(k)%s) == 0) cycle
        at = index(values(k)%s, sep)
        if (at == 0) then
            stat = 1
            errmsg = "Error setting option '"//key//"': expected '"//sep//"' in '"//values(k)%s//"'"
            return
        end if
        call add_entry(entries, strip(values(k)%s(:at - 1)), strip(values(k)%s(at + 1:)))
    end do
    select case (key)
    case ('alias'); call move_alloc(entries, s%alias)
    case ('external'); call move_alloc(entries, s%external)
    case ('extra_mods'); call move_alloc(entries, s%extra_mods)
    end select
end subroutine set_map

Graphs

Calls

Called by