#!/bin/csh -f
#*****************************************************************************
#                                                                            *
#            Copyright (C) 1993, Alias Research, Inc.                        *
#                                                                            *
#    These coded instructions,  statements and  computer programs contain    *
#    unpublished information proprietary to Alias Research, Inc.  and are    *
#    protected by the Canadian and US Federal copyright law. They may not    *
#    be disclosed to third parties  or copied  or duplicated, in whole or    *
#    in part,  without the prior written consent of Alias Research,  Inc.    *
#                                                                            *
# Unpublished-rights reserved under the Copyright Laws of the United States. *
#                                                                            *
#****************************************************************************/
#
#       $Source: /tmp_mnt/repo/root/v/alias3.2.2/src/Gifts/bin/RCS/drender_delete.csh.sgi,v $
#       $Author: psantan $ $Date: 93/06/28 10:22:59 $
#
#

if (! $?ALIAS_LOCATION ) then
    echo "ALIAS_LOCATION environment variable must be set to install drender"
    exit -1
else
    set NT_DR=${ALIAS_WORKENV}/user_data/demo/misc_data/ddelete.pst
    set NT_TMP=/usr/tmp/DRL.$$

    pst ${NT_DR}
    if ( $status == "1" ) then
        exit 1
    endif

    set NT_LIST_TYPE=`pstget ${NT_DR} '*.dellist' 'all jobs'`
    set NT_JOB=`pstget ${NT_DR} '*.job' 'all'`

    if ( ${NT_JOB} == "all" || ${NT_JOB} == "ALL" || ${NT_JOB} == "" ) then
        set NT_FILTER=""
    else
        set NT_FILTER="+${NT_JOB}+"
    endif

    if ( "${NT_LIST_TYPE}" == "pending jobs" || "${NT_LIST_TYPE}" == "all jobs" ) then

        echo "*** D-Render deleting pending jobs     ***"
        pushd ${NT_MASTER_DIR}/queue > /dev/null
        if ( "$status" != "0" ) then 
            goto error
        endif
        /bin/ls -rt ${NT_MASTER_DIR}/queue  > ${NT_TMP}
        if ( ${NT_FILTER} != "" ) then
            cat ${NT_TMP} | grep ${NT_FILTER} | xargs /bin/rm -f
        else
            cat ${NT_TMP} | xargs /bin/rm -f
        endif
        popd > /dev/null
    endif

    if ( "${NT_LIST_TYPE}" == "failed jobs" || "${NT_LIST_TYPE}" == "all jobs" ) then

        echo "*** D-Render deleting failed jobs     ***"
        pushd ${NT_MASTER_DIR}/failed > /dev/null
        if ( "$status" != "0" ) then 
            goto error
        endif
        /bin/ls -rt ${NT_MASTER_DIR}/failed  > ${NT_TMP}
        if ( ${NT_FILTER} != "" ) then
            cat ${NT_TMP} | grep ${NT_FILTER} | xargs /bin/rm -f
        else
            cat ${NT_TMP} | xargs /bin/rm -f
        endif
        popd > /dev/null
    endif

    if ( "${NT_LIST_TYPE}" == "completed jobs" || "${NT_LIST_TYPE}" == "all jobs" ) then

        echo "*** D-Render deleting completed jobs     ***"
        pushd ${NT_MASTER_DIR}/completed > /dev/null
        if ( "$status" != "0" ) then 
            goto error
        endif
        /bin/ls -rt ${NT_MASTER_DIR}/completed  > ${NT_TMP}
        if ( ${NT_FILTER} != "" ) then
            cat ${NT_TMP} | grep ${NT_FILTER} | xargs /bin/rm -f
        else
            cat ${NT_TMP} | xargs /bin/rm -f
        endif
        popd > /dev/null
    endif

    if ( "${NT_LIST_TYPE}" == "running jobs" || "${NT_LIST_TYPE}" == "all jobs" ) then

        echo "*** D-Render deleting running jobs     ***"
        echo "Note: this will not stop running jobs."
        pushd ${NT_MASTER_DIR}/running > /dev/null
        if ( "$status" != "0" ) then 
            goto error
        endif
        /bin/ls -rt ${NT_MASTER_DIR}/running  > ${NT_TMP}
        if ( ${NT_FILTER} != "" ) then
            cat ${NT_TMP} | grep ${NT_FILTER} | xargs /bin/rm -f
        else
            cat ${NT_TMP} | xargs /bin/rm -f
        endif
        popd > /dev/null
    endif

    /bin/rm -f ${NT_TMP}
endif

exit 0

:error
    echo "Could not change to Drender Location"
    exit 1 




