fdoc

subroutineset_option

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

Set option key, which must be one (see is_option), from its values as text.

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_option(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
    character(len=:), allocatable :: text
    logical :: flag, ok
    integer :: number

    stat = 0
    if (in_set(LOGICAL_OPTIONS, key)) then
        if (size(values) /= 1) then
            call fail("Could not convert option '"//key//"' to bool: expected a single value")
            return
        end if
        call parse_bool(values(1)%s, flag, ok)
        if (.not. ok) then
            call fail("Could not convert option '"//key//"' to bool: expected 'true'/'false', got: "//values(1)%s)
            return
        end if
        call set_logical(s, key, flag)
    else if (in_set(INTEGER_OPTIONS, key)) then
        call parse_int(values(1)%s, number, ok)
        if (.not. ok) then
            call fail("Could not convert option '"//key//"' to an integer: "//values(1)%s)
            return
        end if
        select case (key)
        case ('graph_maxdepth'); s%graph_maxdepth = number
        case ('graph_maxnodes'); s%graph_maxnodes = number
        case ('graph_project_maxnodes'); s%graph_project_maxnodes = number
        case ('max_frontpage_items'); s%max_frontpage_items = number
        case ('parallel'); s%parallel = number
        end select
    else if (in_set(LIST_OPTIONS, key)) then
        call set_list(s, key, values)
    else if (in_set(MAP_OPTIONS, key)) then
        call set_map(s, key, values, stat, errmsg)
    else
        text = join(values, achar(10))
        call set_text(s, key, text)
    end if

contains

    !> Record a failure.
    subroutine fail(msg)
        character(len=*), intent(in) :: msg     !! what is wrong
        stat = 1
        errmsg = msg
    end subroutine fail

end subroutine set_option

Graphs

Calls

Called by