#module	SHOWIMAGVERS "SRH X1.0-000"
#pragma builtins

/*
** COPYRIGHT (c) 1992 BY
** DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASSACHUSETTS.
** ALL RIGHTS RESERVED.
**
** THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED
** ONLY  IN  ACCORDANCE  OF  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
** INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR  ANY  OTHER
** COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
** OTHER PERSON.  NO TITLE TO AND  OWNERSHIP OF THE  SOFTWARE IS  HEREBY
** TRANSFERRED.
**
** THE INFORMATION IN THIS SOFTWARE IS  SUBJECT TO CHANGE WITHOUT NOTICE
** AND  SHOULD  NOT  BE  CONSTRUED  AS A COMMITMENT BY DIGITAL EQUIPMENT
** CORPORATION.
**
** DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE  OR  RELIABILITY OF ITS
** SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.
*/

/*
**++
**  Facility:
**
**	Examples
**
**  Version: V1.0
**
**  Abstract:
**
**	Example of working with the image header
**
**  Author:
**	Steve Hoffman
**
**  Creation Date:  1-Jan-1990
**
**  Modification History:
**--
*/

#include <descrip.h>
#include <rms.h>
#include <ssdef.h>
#include <stsdef.h>
#define VOX$$K_FN_VOX$RTL   "VOX$RTL"
#define VOX$$K_DN_VOX$RTL   "SYS$SHARE:.EXE"
#define VOX$$K_FN_VOX$CP    "VOX$CP"
#define VOX$$K_DN_VOX$CP    "SYS$SYSTEM:.EXE"
#define VOX$$K_FN_VOX$ACP   "VOX$ACP"
#define VOX$$K_DN_VOX$ACP   "SYS$SYSTEM:.EXE"
#define VOX$$K_FN_VXDRIVER  "VXDRIVER"
#define VOX$$K_DN_VXDRIVER  "SYS$LOADABLE_IMAGES:.EXE"

#define	    IHD$C_NATIVE	-1
#define	    IHD$W_IMGIDOFF	6
#define	    IHI$T_IMGID		40
#define	    IHI$Q_LINKTIME	56
#define	    IHI$S_LINKTIME	56

vox$show_version()
    {
    vox$$decode_ihd( VOX$$K_FN_VOX$RTL, VOX$$K_DN_VOX$RTL );
    vox$$decode_ihd( VOX$$K_FN_VOX$ACP, VOX$$K_DN_VOX$ACP );
    vox$$decode_ihd( VOX$$K_FN_VOX$CP, VOX$$K_DN_VOX$CP );
    vox$$decode_ihd( VOX$$K_FN_VXDRIVER, VOX$$K_DN_VXDRIVER );
    return( SS$_NORMAL );
    }


vox$$decode_ihd( img_fn, img_dn )
char *img_fn, *img_dn;
    {
    unsigned long int retstat;
    unsigned long int offset = 12;
    unsigned long int vbn = 1;
    struct FAB fab = cc$rms_fab;
    struct NAM nam = cc$rms_nam;
    char blk0[ 512 ];
    char ihd[ 1024 ];
    char *ihi;
    unsigned long int hdrvers = 2;
    unsigned long int last_word = 3;
    struct dsc$descriptor_s asctimbuf;

    asctimbuf.dsc$w_length = 23;
    asctimbuf.dsc$b_dtype = DSC$K_DTYPE_T;
    asctimbuf.dsc$b_class = DSC$K_CLASS_S;
    asctimbuf.dsc$a_pointer = calloc( 24, 1 );

    fab.fab$l_nam = &nam;
    nam.nam$l_rsa = calloc( nam.nam$b_rss = NAM$C_MAXRSS, 1 );
    fab.fab$b_fac = FAB$M_GET;
    fab.fab$l_fop = FAB$M_UFO | FAB$M_NAM;
    fab.fab$b_fns = strlen( img_fn );
    fab.fab$l_fna = img_fn;
    fab.fab$b_dns = strlen( img_dn );
    fab.fab$l_dna = img_dn;
    retstat = SYS$OPEN( &fab );
    
    retstat = IMG$DECODE_IHD(
	fab.fab$l_stv, blk0, ihd, &vbn, &offset, &hdrvers, &last_word );

    retstat = SYS$CLOSE( &fab );

    if ( last_word != (unsigned short int) IHD$C_NATIVE )
	printf( "File: %*s is not a native-mode image.\n",
	    nam.nam$b_rsl, nam.nam$l_rsa );

    printf( "File: %*s ",
	    nam.nam$b_rsl, nam.nam$l_rsa );

    ihi = ihd + *(short *)((char *)ihd + IHD$W_IMGIDOFF);
    printf( " ident: %*s\n",
	    (char) ihi[IHI$T_IMGID], &ihi[IHI$T_IMGID+1] );

    retstat = SYS$ASCTIM(
	0, &asctimbuf, &ihi[IHI$Q_LINKTIME], 0 );
    asctimbuf.dsc$a_pointer[23] = 0;
    printf( " linktime: %23s\n", asctimbuf.dsc$a_pointer );

    cfree( asctimbuf.dsc$a_pointer );
    cfree( nam.nam$l_rsa );

    return( SS$_NORMAL );

    }
