! Copyright (C) TOYODA Eizi, 2000.  All rights reserved.
! gtprint - °õ»ú¥Ä¡¼¥ë

program gtprint
    use gtool
    use dc_trace, only: setdebug
    implicit none
    type(VSTRING):: argument
    type(VSTRING):: attrname, fn, ior, v
    type(VSTRING):: value
    character(STRING):: varname
    type(GT_VARIABLE):: var
    integer:: i
    integer:: showcount = 0
continue
    do, i = 1, GtArgCount()
        call GtArgGet(i, argument)
	if (argument == "-debug") then
	    call setdebug
	    cycle
	endif
        call UrlSplit(argument, attr=attrname)
        if (attrname == '') then
            varname = argument
            call Open(var, varname)
            call put_line(var)
            call Close(var)
        else
            call UrlSplit(argument, file=fn, var=v, iorange=ior)
            varname = UrlMerge(fn, v, iorange=ior)
            call Open(var, varname)
            call get_attr(var, vchar(attrname, len(attrname)), value)
            call put_line(value)
            call Close(var)
        endif
        showcount = showcount + 1
    enddo
    if (showcount == 0) then
        write(*, *) 'usage: gtprint [varname|attrname] ...'
    endif
end program
