Parse restart-related flags and apply manifest defaults.
This routine also applies --watch-low-cpu to the sleep implementation
so supervisor delays do not busy-wait.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| logical, | intent(out) | :: | auto_restart | |||
| real, | intent(out) | :: | restart_delay | |||
| integer, | intent(out) | :: | restart_max | |||
| logical, | intent(out) | :: | is_child | |||
| character(len=:), | intent(out), | allocatable | :: | self_exe |
subroutine parse_restart_flags(auto_restart, restart_delay, restart_max, is_child, self_exe) logical, intent(out) :: auto_restart, is_child real, intent(out) :: restart_delay integer, intent(out) :: restart_max character(len=:), allocatable, intent(out) :: self_exe integer :: narg, i character(len=:), allocatable :: a, v call get_restart_defaults(auto_restart, restart_delay, restart_max, self_exe) is_child = .false. narg = command_argument_count() i = 1 do while (i <= narg) a = get_arg(i) if (a == "--watch-low-cpu") then call set_low_cpu(.true.) i = i + 1 cycle end if if (a == "--watch-no-low-cpu") then call set_low_cpu(.false.) i = i + 1 cycle end if if (starts_with(a, "--watch-low-cpu=")) then v = a(len("--watch-low-cpu=")+1:) call set_low_cpu(parse_bool(v, .true.)) i = i + 1 cycle end if if (a == "--watch-auto-restart") then auto_restart = .true. i = i + 1 cycle end if if (a == "--watch-child") then is_child = .true. i = i + 1 cycle end if if (starts_with(a, "--watch-restart-delay=")) then v = a(len("--watch-restart-delay=")+1:) restart_delay = parse_real(v, restart_delay) i = i + 1 cycle end if if (starts_with(a, "--watch-restart-max=")) then v = a(len("--watch-restart-max=")+1:) restart_max = parse_int(v, restart_max) i = i + 1 cycle end if if (starts_with(a, "--watch-self=")) then self_exe = trim(a(len("--watch-self=")+1:)) i = i + 1 cycle end if if (a == "--watch-restart-delay") then if (i+1 <= narg) then v = get_arg(i+1) restart_delay = parse_real(v, restart_delay) i = i + 2 else i = i + 1 end if cycle end if if (a == "--watch-restart-max") then if (i+1 <= narg) then v = get_arg(i+1) restart_max = parse_int(v, restart_max) i = i + 2 else i = i + 1 end if cycle end if if (a == "--watch-self") then if (i+1 <= narg) then self_exe = trim(get_arg(i+1)) i = i + 2 else i = i + 1 end if cycle end if i = i + 1 end do contains pure logical function parse_bool(s, default) result(vb) character(len=*), intent(in) :: s logical, intent(in) :: default character(len=:), allocatable :: t t = trim(adjustl(lower_ascii(s))) select case (t) case ("1","true","on","yes","y","t") vb = .true. case ("0","false","off","no","n","f") vb = .false. case default vb = default end select end function parse_bool pure function lower_ascii(s) result(r) character(len=*), intent(in) :: s character(len=len(s)) :: r integer :: k, c, da da = iachar('a') - iachar('A') do k = 1, len(s) c = iachar(s(k:k)) if (c >= iachar('A') .and. c <= iachar('Z')) then r(k:k) = achar(c + da) else r(k:k) = s(k:k) end if end do end function lower_ascii end subroutine parse_restart_flags