Fortran · 1457 bytes Raw Blame History
1 module builtin_interface
2 use shell_types
3 implicit none
4
5 ! Abstract interface for builtin execution
6 ! This allows executor to call builtins without directly depending on the builtins module
7 abstract interface
8 logical function is_builtin_func(cmd_name) result(is_builtin)
9 character(len=*), intent(in) :: cmd_name
10 end function is_builtin_func
11
12 subroutine execute_builtin_sub(cmd, shell)
13 import :: command_t, shell_state_t
14 type(command_t), intent(in) :: cmd
15 type(shell_state_t), intent(inout) :: shell
16 end subroutine execute_builtin_sub
17 end interface
18
19 ! Function pointers that will be set by the builtins module
20 procedure(is_builtin_func), pointer :: is_builtin_ptr => null()
21 procedure(execute_builtin_sub), pointer :: execute_builtin_ptr => null()
22
23 contains
24
25 ! Wrapper functions that executor will call
26 logical function is_builtin(cmd_name) result(res)
27 character(len=*), intent(in) :: cmd_name
28 if (associated(is_builtin_ptr)) then
29 res = is_builtin_ptr(cmd_name)
30 else
31 res = .false.
32 end if
33 end function is_builtin
34
35 subroutine execute_builtin(cmd, shell)
36 type(command_t), intent(in) :: cmd
37 type(shell_state_t), intent(inout) :: shell
38 if (associated(execute_builtin_ptr)) then
39 call execute_builtin_ptr(cmd, shell)
40 else
41 shell%last_exit_status = 127 ! Command not found
42 end if
43 end subroutine execute_builtin
44
45 end module builtin_interface