OpenVMS Source Code Demos

SYS_SNDJBCW.C

//=====================================================================================================
// title   : sys_sndjbcw_100.c
// author  : Neil Rieck
// created : 2011-10-25
// platform: HP C V7.3-009 on OpenVMS Alpha V8.4
// notes   : 1. this was a very quick hack
//         : 2. if you are unable to submit using a different legal name, then try it from DCL like so:
//		$ submit script.com /user=OLSEN
//		if you receive an error like this:
//			%SUBMIT-F-CREJOB, error creating job RMS-E-RNF, record not found
//		then try restarting the queue manage (and queues) or just do a reboot.
//=====================================================================================================
#define PROGRAM_VER	"sys_sndjbcw_100.c"			//
#include <stdio.h>						//
#include <stdlib.h>						//
#include <string.h>						//
#define __NEW_STARLET	1					// enable new (strict) starlet for OpenVMS Alpha 7.0 and later
								// http://h41379.www4.hpe.com/doc/82final/5841/5841pro_059.html
#include <starlet.h>						// vms specific - system library
#include <ssdef.h>						// vms specific - system services constants
#include <sjcdef.h>						// vms specific - system job control
#include <jbcmsgdef.h>						// vms specific - job control message
#include <iosbdef.h>						// vms specific - i/o status block
#include <iledef.h>						// vms specific - Item List Entry 3 structure

//
//	variables
//
char cmdfile[255];							// script name
char logfile[255];							// log file name
char queuename[31];							// queue name
char username[12];							// user name
char dcl_parameter1[30];						// DCL P1
char dcl_parameter2[30];						// DCL P2
char dcl_parameter3[30];						// DCL P3
char dcl_parameter4[30];						// DCL P4
char dcl_parameter5[30];						// DCL P5
char dcl_parameter6[30];						// DCL P6
char dcl_parameter7[30];						// DCL P7
char dcl_parameter8[30];						// DCL P8
//
//	main
//
int main() {
	int  rc;							// return code
	int  i;								// insert count
	IOSB iosb;							// i/o status block
	//
	//	populate some strings with stuff we need
	//
	sprintf(queuename	,"SYS$BATCH");				// every system has one of these
	sprintf(cmdfile		,"csmis$bstt:test_script.com");		// use this script
	sprintf(logfile		,"csmis$bstt:test_script.log");		// write to this log file
	sprintf(username	,"CSMIS_BSTT");				// submit on behalf of this user
	sprintf(dcl_parameter1	,"THIS IS P1");				//
	sprintf(dcl_parameter2	,"THIS IS P2");				//
	sprintf(dcl_parameter3	,"THIS IS P3");				//
	sprintf(dcl_parameter4	,"\"\"");				// empty quotes
	dcl_parameter5[0] = '\0';					// nothing
	dcl_parameter6[0] = '\0';					// nothing
	dcl_parameter7[0] = '\0';					// nothing
	dcl_parameter8[0] = '\0';					// nothing
	//
	//	this item list contains a number of 4-entry lines followed by a terminator
	//
	//	1 unsigned short	buffer length		0 = no buffer
	//	2 unsigned short	item code		0 = list terminator
	//	3 void *		buffer address		0 = no buffer
	//	4 unsigned short *	return len adress	0 = ignore
	//
	static ILE3 sjcitms[19];					// make as large as necessary
	//
	i = 0;								// init
#if (1==1)
	sjcitms[i].ile3$w_length	= strlen(username);		// submit on behalf of this user
	sjcitms[i].ile3$w_code		= SJC$_USERNAME;		//
	sjcitms[i].ile3$ps_bufaddr      = username;			//
	sjcitms[i].ile3$ps_retlen_addr	= NULL;				//
	i = i + 1;							// prep for next insert
#endif
	sjcitms[i].ile3$w_length	= strlen(queuename);		// pass this queue name
	sjcitms[i].ile3$w_code		= SJC$_QUEUE;			//
	sjcitms[i].ile3$ps_bufaddr      = queuename;			//
	sjcitms[i].ile3$ps_retlen_addr	= NULL;				//
	i = i + 1;							// prep for next insert

	sjcitms[i].ile3$w_length	= strlen(cmdfile);		// execute this DCL script
	sjcitms[i].ile3$w_code		= SJC$_FILE_SPECIFICATION;
	sjcitms[i].ile3$ps_bufaddr      = cmdfile;			//
	sjcitms[i].ile3$ps_retlen_addr	= NULL;				//
	i = i + 1;							// prep for next insert

	sjcitms[i].ile3$w_length	= strlen(logfile);		// write to this log file
	sjcitms[i].ile3$w_code		= SJC$_LOG_SPECIFICATION;
	sjcitms[i].ile3$ps_bufaddr      = logfile;			//
	sjcitms[i].ile3$ps_retlen_addr	= NULL;				//
	i = i + 1;							// prep for next insert

	sjcitms[i].ile3$w_length	= 0;				// no not print
	sjcitms[i].ile3$w_code		= SJC$_NO_LOG_SPOOL;		//
	sjcitms[i].ile3$ps_bufaddr      = 0;				//
	sjcitms[i].ile3$ps_retlen_addr	= NULL;				//
	i = i + 1;							// prep for next insert

	if (strlen(dcl_parameter1)>0) {					//
	    sjcitms[i].ile3$w_length	  = strlen(dcl_parameter1);	// execute this DCL script
	    sjcitms[i].ile3$w_code	  = SJC$_PARAMETER_1;		//
	    sjcitms[i].ile3$ps_bufaddr    = dcl_parameter1;		//
	    sjcitms[i].ile3$ps_retlen_addr= NULL;			//
	    i = i + 1;							// prep for next insert
	}else{
	    goto no_more_params;
	}
	if (strlen(dcl_parameter2)>0) {					//
	    sjcitms[i].ile3$w_length	  = strlen(dcl_parameter2);	// execute this DCL script
	    sjcitms[i].ile3$w_code	  = SJC$_PARAMETER_2;		//
	    sjcitms[i].ile3$ps_bufaddr    = dcl_parameter2;		//
	    sjcitms[i].ile3$ps_retlen_addr= NULL;			//
	    i = i + 1;							// prep for next insert
	}else{
	    goto no_more_params;
	}
	if (strlen(dcl_parameter3)>0) {					//
	    sjcitms[i].ile3$w_length	  = strlen(dcl_parameter3);	// execute this DCL script
	    sjcitms[i].ile3$w_code	  = SJC$_PARAMETER_3;		//
	    sjcitms[i].ile3$ps_bufaddr    = dcl_parameter3;		//
	    sjcitms[i].ile3$ps_retlen_addr= NULL;			//
	    i = i + 1;							// prep for next insert
	}else{
	    goto no_more_params;
	}
	if (strlen(dcl_parameter4)>0) {					//
	    sjcitms[i].ile3$w_length	  = strlen(dcl_parameter4);	// execute this DCL script
	    sjcitms[i].ile3$w_code	  = SJC$_PARAMETER_4;		//
	    sjcitms[i].ile3$ps_bufaddr    = dcl_parameter4;		//
	    sjcitms[i].ile3$ps_retlen_addr= NULL;			//
	    i = i + 1;							// prep for next insert
	}else{
	    goto no_more_params;
	}
	if (strlen(dcl_parameter5)>0) {					//
	    sjcitms[i].ile3$w_length	  = strlen(dcl_parameter5);	// execute this DCL script
	    sjcitms[i].ile3$w_code	  = SJC$_PARAMETER_5;		//
	    sjcitms[i].ile3$ps_bufaddr    = dcl_parameter5;		//
	    sjcitms[i].ile3$ps_retlen_addr= NULL;			//
	    i = i + 1;							// prep for next insert
	}else{
	    goto no_more_params;
	}
	if (strlen(dcl_parameter6)>0) {					//
	    sjcitms[i].ile3$w_length	  = strlen(dcl_parameter6);	// execute this DCL script
	    sjcitms[i].ile3$w_code	  = SJC$_PARAMETER_6;		//
	    sjcitms[i].ile3$ps_bufaddr    = dcl_parameter6;		//
	    sjcitms[i].ile3$ps_retlen_addr= NULL;			//
	    i = i + 1;							// prep for next insert
	}else{
	    goto no_more_params;
	}
	if (strlen(dcl_parameter7)>0) {					//
	    sjcitms[i].ile3$w_length	  = strlen(dcl_parameter7);	// execute this DCL script
	    sjcitms[i].ile3$w_code	  = SJC$_PARAMETER_7;		//
	    sjcitms[i].ile3$ps_bufaddr    = dcl_parameter7;		//
	    sjcitms[i].ile3$ps_retlen_addr= NULL;			//
	    i = i + 1;							// prep for next insert
	}else{
	    goto no_more_params;
	}
	if (strlen(dcl_parameter8)>0) {					//
	    sjcitms[i].ile3$w_length	  = strlen(dcl_parameter8);	// execute this DCL script
	    sjcitms[i].ile3$w_code	  = SJC$_PARAMETER_8;		//
	    sjcitms[i].ile3$ps_bufaddr    = dcl_parameter8;		//
	    sjcitms[i].ile3$ps_retlen_addr= NULL;			//
	    i = i + 1;							// prep for next insert
	}
	no_more_params:

	sjcitms[i].ile3$w_length	= 0;				// list terminator
	sjcitms[i].ile3$w_code		= 0;				//
	sjcitms[i].ile3$ps_bufaddr      = 0;				//
	sjcitms[i].ile3$ps_retlen_addr	= 0;				//

	rc = sys$sndjbcw(
		0,
		SJC$_ENTER_FILE,
		0,
		sjcitms,
		&iosb,
		0,
		0);
	if ((rc & 7)!=SS$_NORMAL) {					//
	    printf("-e-sys$sndjbcw-rc:: %d\n", rc);			//
	    return(rc);							// abort with the error code
	}
	//
	//	just because the job submitted properly
	//	doesn't mean it executed properly, so check iosb
	//
	if ((iosb.iosb$w_status & 7)!=SS$_NORMAL) {			//
	    printf("-e-sys$sndjbcw-iosb-rc: %d\n", iosb.iosb$w_status);	//
	    return(rc);							//
	}
	//
	//	adios
	//
	return(SS$_NORMAL);						// vms-success
}