//  Copyright 2006 Hewlett-Packard Development Company, L.P.
//
//  An example of calling $creprc to spawn a subprocess.
//  (Also see lib$spawn, though that call requires a CLI.)
//
//  Author: Stephen Hoffman, HP OpenVMS Engineering
//
#pragma module srh_creprc "V1.0"

/*
**++
**  FACILITY:  examples
**
**  MODULE DESCRIPTION:
**
**      performs a lib$spawn, but doesn't need a cli around
**
**  AUTHORS:
**
**      steve hoffman
**
**  CREATION DATE:  2-jul-1993
**
**  DESIGN ISSUES:
**
**      while this routine performs the indicated task of spawning
**	a subprocess, note that use of the sys$sndjbc() system service
**	to submit the specified procedure may also be appropriate.
**
**  MODIFICATION HISTORY:
**
**      19-Apr-2000, Hoffman, updated for Compaq C
**
**      {@tbs@}...
**--
*/

#include <descrip.h>
#include <pqldef.h>
#include <ssdef.h>
#include <starlet.h>
#include <stddef.h>
#include <stdio.h>
#include <stsdef.h>

int srh_creprc( struct dsc$descriptor_s *cmdspec_a,
    struct dsc$descriptor_s *logspec_a,
    unsigned long int *pid_a,
    struct dsc$descriptor_s *prcnam_a )
    {
    unsigned long int retstat;
    struct dsc$descriptor *logspec;
    struct dsc$descriptor *prcnam;
    $DESCRIPTOR( nla0, "_NLA0:" );
    $DESCRIPTOR( loginout, "SYS$SYSTEM:LOGINOUT.EXE" );
    $DESCRIPTOR( srh, "SRH" );
    unsigned long int *pid;
    unsigned long int pid_bogus;
    unsigned long int baspri = 4;
    unsigned long int mbxunt = 0;
    unsigned long int uic = 0;
    unsigned long int stsflgs = 0;
    struct
	{
	unsigned char pql_code;
	unsigned long int pql_value;
	} pql[] =
	    {
	    {	PQL$_ASTLM,        600	    },
	    {	PQL$_BIOLM,        100	    },
	    {	PQL$_BYTLM,        131072   },
	    {	PQL$_CPULM,        0	    },
	    {	PQL$_DIOLM,        100	    },
	    {	PQL$_FILLM,        50	    },
	    {	PQL$_PGFLQUOTA,    40960    },
	    {	PQL$_PRCLM,        16	    },
	    {	PQL$_TQELM,        600	    },
	    {	PQL$_WSDEFAULT,    512	    },
	    {	PQL$_WSQUOTA,      2048	    },
	    {	PQL$_ENQLM,        600	    },
	    {	PQL$_WSEXTENT,     4096	    },
	    {	PQL$_JTQUOTA,      4096	    },
	    {	PQL$_LISTEND,      0	    }
	    };

    /*
    **	Allow the log file specification and the process name
    **	specification to be defaulted.
    */
    logspec = ((int) logspec_a) ? (void *) logspec_a : (void *) &nla0;
    prcnam = ((int) prcnam_a) ? (void *) prcnam_a : (void *) &srh;
    pid = ((int) pid_a) ? pid_a : &pid_bogus;

    /*
    **	Perform the process creation.
    */	
    retstat = sys$creprc( pid,
	&loginout, cmdspec_a, logspec, &nla0, 0,
	pql, prcnam, baspri, uic, mbxunt, stsflgs );

    return retstat;

    }
main()
    {
    unsigned long int retstat;
    $DESCRIPTOR( log, "SYS$MANAGER:X.LOG" );
    $DESCRIPTOR( cmd, "SYS$MANAGER:LOGIN.COM" );
    
    retstat = srh_creprc( &cmd, &log, NULL, NULL );
    return SS$_NORMAL;
    }

