tokenize Subroutine

subroutine tokenize(com)

Arguments

Type IntentOptional Attributes Name
character, intent(in) :: com

Contents

Source Code


Variables

Type Visibility Attributes Name Initial
character(len=:), public, allocatable :: command
integer, public :: end
integer, public :: start

Source Code

  subroutine tokenize(com)
    character(*), intent(in)      :: com
    integer                       :: start, end
    character(len=:), allocatable :: command
    
    call clear_ll(tokens)
    if (len_trim(com) == 0) then
        return
    end if
    start = 1
    ! Ensure there are no leading and trailing spaces
    command = trim(adjustl(com))
    end = index(command,' ')
    end = merge(len(command),end-1,end==0)
    do
        call append(tokens,command(start:end))
        if (end == len(command)) exit
        start = end + nsp(command(end+1:))
        end = index(command(start:),' ') - 1
        end = merge(len(command),end+start-1,end == -1)
     end do
  end subroutine tokenize