
#include    jpidef
#include    ssdef
#include    stsdef
#include    descrip
#include    lib$routines
#include    starlet

#define VDE_QUOTA_MIN	    0
#define VDE_QUOTA_ASTLM	    0
#define VDE_QUOTA_BIOLM	    1
#define VDE_QUOTA_BYTLM	    2
#define VDE_QUOTA_DIOLM	    3
#define VDE_QUOTA_ENQLM	    4
#define VDE_QUOTA_FILLM	    5
#define VDE_QUOTA_PGFLQUOTA 6
#define VDE_QUOTA_PRCLM     7
#define VDE_QUOTA_TQLM	    8
#define VDE_QUOTA_MAX	    8
#define STS_WARNING( code )  ((code & ~STS$M_SEVERITY) | STS$K_WARNING)

vde_check_quota()
    {
    typedef unsigned long int u_long;
    typedef unsigned short int u_short;
    $DESCRIPTOR( vdefacnam, "VDE" );
    u_long retstat;
    u_short iosb[4];
    u_long i, j;
    u_long quota_used[VDE_QUOTA_MAX+1];
    u_long quota_have[VDE_QUOTA_MAX+1];
    u_long quota_want[VDE_QUOTA_MAX+1];
    u_long quota_code[VDE_QUOTA_MAX+1];
    u_long quota_msgs[VDE_QUOTA_MAX+2];
    struct il3def
	{
	unsigned short int buflen;
	unsigned short int itmcod;
	unsigned char *bufadr;
	unsigned char *bufrla;
	};
    struct il3def jpi_quotas[(VDE_QUOTA_MAX+1+VDE_QUOTA_MAX+1)];

    for ( i = VDE_QUOTA_MIN; i < VDE_QUOTA_MAX; i++ )
	quota_want[i] = quota_used[i] = 0;

    quota_code[VDE_QUOTA_ASTLM]	    = SS$_EXASTLM;
    quota_code[VDE_QUOTA_BIOLM]	    = SS$_EXBIOLM;
    quota_code[VDE_QUOTA_BYTLM]	    = SS$_EXBYTLM;
    quota_code[VDE_QUOTA_DIOLM]	    = SS$_EXDIOLM;
    quota_code[VDE_QUOTA_ENQLM]	    = SS$_EXENQLM;
    quota_code[VDE_QUOTA_FILLM]	    = SS$_EXFILLM;
    quota_code[VDE_QUOTA_PGFLQUOTA] = SS$_EXPGFLQUOTA;
    quota_code[VDE_QUOTA_PRCLM]	    = SS$_EXPRCLM;
    quota_code[VDE_QUOTA_TQLM]	    = SS$_EXTQELM;

    quota_want[VDE_QUOTA_ASTLM]	    = 250;
    quota_want[VDE_QUOTA_BIOLM]	    = 250;
    quota_want[VDE_QUOTA_BYTLM]	    = 65535;
    quota_want[VDE_QUOTA_DIOLM]	    = 250;
    quota_want[VDE_QUOTA_ENQLM]	    = 250;
    quota_want[VDE_QUOTA_FILLM]	    = 250;
    quota_want[VDE_QUOTA_PGFLQUOTA] = 16384;
    quota_want[VDE_QUOTA_PRCLM]	    = 4;
    quota_want[VDE_QUOTA_TQLM]	    = 250;

    i = 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_ASTLM;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_have[VDE_QUOTA_ASTLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_BIOLM;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_have[VDE_QUOTA_BIOLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_BYTLM;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_have[VDE_QUOTA_BYTLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_DIOLM;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_have[VDE_QUOTA_DIOLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_ENQLM;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_have[VDE_QUOTA_ENQLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_FILLM;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_have[VDE_QUOTA_FILLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_PGFLQUOTA;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_have[VDE_QUOTA_PGFLQUOTA];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_PRCLM;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_have[VDE_QUOTA_PRCLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_TQLM;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_have[VDE_QUOTA_TQLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    /*
    //	Now that we have the quotas, find out how close to the
    //	edge we are -- how much of the quota has been used...
    */
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_ASTCNT;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_used[VDE_QUOTA_ASTLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_BIOCNT;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_used[VDE_QUOTA_BIOLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_BYTCNT;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_used[VDE_QUOTA_BYTLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_DIOCNT;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_used[VDE_QUOTA_DIOLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_ENQCNT;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_used[VDE_QUOTA_ENQLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_FILCNT;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_used[VDE_QUOTA_FILLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_PRCCNT;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_used[VDE_QUOTA_PRCLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 4;
    jpi_quotas[i].itmcod = JPI$_TQCNT;
    jpi_quotas[i].bufadr = (unsigned char *) &quota_used[VDE_QUOTA_TQLM];
    jpi_quotas[i++].bufrla = (void *) 0;
    jpi_quotas[i].buflen = 0;
    jpi_quotas[i].itmcod = 0;
    jpi_quotas[i].bufadr = (void *) 0;
    jpi_quotas[i++].bufrla = (void *) 0;

    /*
    **	Go get the size of the rightslist
    */
    retstat = sys$getjpiw( 0, 0, 0,
	jpi_quotas, iosb, 0, 0, 0 );
    if ( !( $VMS_STATUS_SUCCESS( retstat )) )
	return( retstat );
    if ( !( $VMS_STATUS_SUCCESS( iosb[0] )) )
	return( iosb[0] );

    j = 0;
    quota_msgs[j] = 1;
    quota_msgs[++j] = STS_WARNING( SS$_EXQUOTA );


    /*
    //	Loop through the results of the quota check, and
    //	load the codes for any quota values found to be
    //	insufficient.
    /**	if ( (quota_have[i] - quota_used[i]) < quota_want[i] )
    */    
    for ( i = VDE_QUOTA_MIN; i < VDE_QUOTA_MAX; i++ )
	if ( quota_used[i] < quota_want[i] )
	    {
	    quota_msgs[0]++;
	    quota_msgs[++j] = STS_WARNING( quota_code[i] );
	    }

    /*
    //  See if we found a reason to display the message array.
    //	If we did, then do it.
    */
    if ( quota_msgs[0] > 1 )
	retstat = sys$putmsg( quota_msgs, 0, &vdefacnam, 0 );
	
    return SS$_NORMAL;
    }
