!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
module cubedag_language
  use cubetools_parameters
  use cubetools_structure
  use cubedag_debug
  use cubedag_messaging
  use cubedag_find
  use cubedag_free
  use cubedag_history
  use cubedag_list
  use cubedag_memory
  use cubedag_remove
  use cubedag_snapshot
  use cubedag_undo
  !
  public :: cubedag_register_language
  private
  !
  integer(kind=lang_k) :: langid
  !
contains
  !
  subroutine cubedag_register_language(error)
    !----------------------------------------------------------------------
    ! Register the DAG\ language. This language provides interactions
    ! with the DAG. In particular, there is no access to the node data.
    !----------------------------------------------------------------------
    logical, intent(inout) :: error
    !
    call cubetools_register_language(&
         'DAG',&
         'J.Pety, S.Bardeau, V.deSouzaMagalhaes',&
         'Commands to manage the DAG',&
         strg_emp,&
         'gag_doc:hlp/cube-help-dag.hlp',&
         cubedag_execute_command,&
         langid,&
         error)
    if (error) return
    !
    call find%register(error)
    if (error) return
    call free%register(error)
    if (error) return
    call history%register(error)
    if (error) return
    call list%register(error)
    if (error) return
    call memory%register(error)
    if (error) return
    call remove%register(error)
    if (error) return
    call snapshot%register(error)
    if (error) return
    call undo%register(error)
    if (error) return
    if (cube_dev_mode()) then
      call debug%register(error)
      if (error) return
    endif
    !
    call cubetools_register_dict(error)
    if (error) return
  end subroutine cubedag_register_language
  !
  subroutine cubedag_execute_command(line,comm,error)
    !use cubeadm_opened
    use cubeadm_timing
    !----------------------------------------------------------------------
    ! Execute a command of the DAG\ language
    !----------------------------------------------------------------------
    character(len=*), intent(in)    :: line
    character(len=*), intent(in)    :: comm
    logical,          intent(inout) :: error
    !
    character(len=*), parameter :: rname='EXECUTE>COMMAND'
    !
    error = .false.
    if (comm.eq.'DAG?') then
       call cubetools_list_language_commands(langid,error)
       if (error) return
    else
       call cubeadm_timing_init()
       call cubetools_execute_command(line,langid,comm,error)
       if (error) continue ! To ensure error recovery in the call to cubedag_finish_all
       !call cubeadm_finish_all(comm,line,error)
       !if (error) continue ! To ensure error recovery in timing
       call cubeadm_timing_final(comm)
    endif
  end subroutine cubedag_execute_command
end module cubedag_language
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
