#pragma module XABPRO "V1.1-000"

//
//  Copyright 2001 by Compaq Computer Corporation
//
//
//
//  Facility:
//
//	Examples
//
//  Version: V1.1
//
//  Abstract:
//
//	Example of the RMS protection XAB
//
//  Author:
//	Stephen Hoffman
//
//  Creation Date:  1-Jan-1990
//
//  Modification History:
//
//      5-Sep-2001  Stephen Hoffman
//      V1.1        Updated for Compaq C, switched to CLASS_D
//
//

#include <descrip.h>
#include <lib$routines.h>
#include <rms.h>
#include <ssdef.h>
#include <starlet.h>
#include <stdio.h>
#include <stsdef.h>

main()
    {
    struct dsc$descriptor_s fname_d = 
        { 0, DSC$K_DTYPE_T, DSC$K_CLASS_D, NULL };
    $DESCRIPTOR( prompt_d, "FILENAME: ");
    struct FAB fab;
    struct XABPRO xabpro;
    int RetStat;

    RetStat = lib$get_input( &fname_d, &prompt_d, &fname_d.dsc$w_length );

    //	Initialize the FAB and XABPRO structures.
    //
    fab = cc$rms_fab;
    xabpro = cc$rms_xabpro;

    fab.fab$l_fna = fname_d.dsc$a_pointer;
    fab.fab$b_fns = fname_d.dsc$w_length;
    fab.fab$b_fac = FAB$M_PUT;

    //	Open the file, then hook in the XABPRO.
    //
    RetStat = sys$open( &fab );
    printf("$OPEN = 0x0%08.8x\n", RetStat );
    printf("  stv = 0x0%08.8x\n", fab.fab$l_stv );
    if (!$VMS_STATUS_SUCCESS( RetStat ))
      lib$signal( RetStat );

    fab.fab$l_xab = &xabpro;
    xabpro.xab$w_pro = (XAB$M_NOWRITE|XAB$M_NODEL)<<XAB$V_WLD;
    xabpro.xab$l_nxt = 0;

    //	Close the file.
    //
    RetStat = sys$close( &fab );
    printf("$CLOSE = 0x0%08.8x\n", RetStat );
    printf("   stv = 0x0%08.8x\n", fab.fab$l_stv );

    //	Clean up and leave...
    //
    RetStat = lib$sfree1_dd( &fname_d );
    if (!$VMS_STATUS_SUCCESS( RetStat ))
      lib$signal( RetStat );

    return SS$_NORMAL;
    }
