From:	MERC::"uunet!CRVAX.SRI.COM!RELAY-INFO-VAX" 20-APR-1993 21:33:44.05
To:	INFO-VAX@SRI.COM
CC:	
Subj:	Re: Issuing SUBMIT from a program

> How to submit batch jobs from a FORTRAN or C program?
>
> I know two ways:
>
> 1) using sys$sndjbc
> 2) spawning a "submit"
>
> For various reasons I would prefer some other way (IF there is one!)

Attached is PRINTFILE.C in VMS_SHARE format.  This is a routine I wrote
to print a file from a C program.  The routine works by (if necessary)
defining a SYS$PRINT logical name to point to the destination print
queue and then opening and immediately closing the file to be printed.
The call to fopen() includes the RMS options "fop=spl,dlt" to spool
the file to SYS$PRINT and delete it after printing.

= Dr. Frank J. Nagy   "VAX Guru & Wizard, Loose Cannon"  {{Group Leader!}}
= Fermilab Computing Division/Distributed Computing Dept/Special Projects Grp
= HEPnet/SPAN: FNDCD::NAGY (43123::NAGY) or FNAL::NAGY (43009::NAGY)
= Internet: NAGY@FNAL.FNAL.GOV            = BitNet: NAGY@FNAL
=   -or-    NAGY@FNDCD.FNAL.GOV              -or-   NAGY@FNDCD
= USnail: Fermilab POB 500 MS/234 Batavia, IL 60510

$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_UNPACK_VERIFY"))'
$!
$! This archive created by VMS_SHARE Version 8.3
$!   On 20-APR-1993 13:11:33.89   By user NAGY
$!
$! The VMS_SHARE software that created this archive
$!    was written by  Andy Harper, Kings College London UK
$!    -- December 1992
$!
$! Credit is due to these people for their original ideas:
$!    James Gray, Michael Bednarek 
$!
$! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER
$! AND EXECUTE AS A COMMAND PROCEDURE  (  @name  )
$!
$! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:
$!       1. PRINTFILE.C;2
$!
$set="set"
$set symbol/scope=(nolocal,noglobal)
$f=f$parse("SHARE_UNPACK_TEMP","SYS$SCRATCH:."+f$getjpi("","PID"))
$e="write sys$error  ""%UNPACK"", "
$w="write sys$output ""%UNPACK"", "
$ if .not. f$trnlnm("SHARE_UNPACK_LOG") then $ w = "!"
$ if f$getsyi("CPU") .gt. 127 then $ goto start
$ ve=f$getsyi("version")
$ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto start
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ v=f$verify(v)
$ exit 44
$unpack: subroutine ! P1=filename, P2=checksum, P3=attributes
$ if f$parse(P1) .nes. "" then $ goto dirok
$ dn=f$parse(P1,,,"DIRECTORY")
$ w "-I-CREDIR, Creating directory ''dn'"
$ create/dir 'dn'
$ if $status then $ goto dirok
$ e "-E-CREDIRFAIL, Unable to create ''dn' File skipped"
$ delete 'f'*
$ exit
$dirok:
$ x=f$search(P1)
$ if x .eqs. "" then $ goto file_absent
$ e "-W-EXISTS, File ''P1' exists. Skipped"
$ delete 'f'*
$ exit
$file_absent:
$ w "-I-UNPACK, Unpacking file ", P1
$ n=P1
$ if P3 .nes. "" then $ n=f
$ if .not. f$verify() then $ define/user sys$output nl:
$ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='n'
PROCEDURE GetHex(s,p)LOCAL x1,x2;x1:=INDEX(t,SUBSTR(s,p,1))-1;x2:=INDEX(t,
SUBSTR(s,p+1,1))-1;RETURN 16*x1+x2;ENDPROCEDURE;
PROCEDURE SkipPartsep LOOP EXITIF MARK(NONE)=END_OF(b);EXITIF 
INDEX(ERASE_LINE,
"-+-+-+-+-+-+-+-+")=1;ENDLOOP;ENDPROCEDURE;PROCEDURE ProcessLine LOCAL 
c,s,l,b,
n,p;c := ERASE_CHARACTER(1);s := ERASE_LINE;IF c = "X" THEN SPLIT_LINE; ENDIF;
MOVE_HORIZONTAL(-1);l := LENGTH(s);p := 1;LOOP EXITIF p > l;c := 
SUBSTR(s,p,1);
p := p+1;CASE c FROM ' ' TO '`' ['`']: COPY_TEXT(ASCII(GetHex(s,p))); p:=p+2;[
' ']: p:=p+1;[INRANGE,OUTRANGE]: COPY_TEXT(c);ENDCASE;ENDLOOP;ENDPROCEDURE;
PROCEDURE Decode POSITION(BEGINNING_OF(b));LOOP EXITIF MARK(NONE)=END_OF(b);
IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+-")=1 THEN SkipPartSep;ELSE ProcessLine;
MOVE_HORIZONTAL(1);ENDIF;ENDLOOP;ENDPROCEDURE;SET(FACILITY_NAME,"UNPACK");SET(
SUCCESS,OFF);SET(INFORMATIONAL,OFF);t:="0123456789ABCDEF";f:=GET_INFO(
COMMAND_LINE,"file_name");b:=CREATE_BUFFER(f,f);Decode;WRITE_FILE(b,GET_INFO(
COMMAND_LINE,"output_file"));QUIT;
$ if p3 .eqs. "" then $ goto dl
$ open/write fdl &f
$ write fdl "RECORD"
$ write fdl P3
$ close fdl
$ w "-I-CONVRFM, Converting record format to ", P3
$ convert/fdl=&f &f-1 &P1
$dl: delete 'f'*
$ checksum 'P1'
$ if checksum$checksum .nes. P2 then $ -
  e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ exit
$ endsubroutine
$start:
$!
$ create 'f'
X#module`20`20PrintFile`20`20"V0.0"
X
X/*
X`20**********************************************************************
X`20**********************************************************************
X`20****`09`09`09`09`09`09`09`09`20`20`20****`20
X`20****`09`09`09`09`09`09`09`09`20`20`20****`20
X`20****`09`20`20`20`20`20`20`09EPICURE`20Beamline`20Control`20System`09`09`09
V`20`20`20****`20
X`20****`09`09Copyright`20(c)`20Fermilab,`201987`09`09`09`20`20`20****`20
X`20****`09`09`09`09`09`09`09`09`20`20`20****`20
X`20****`09`09Extended`20Run-Time`20Library`20Routine`09`20`20`20`20`20`20`20
V`20`20`20`20****`20
X`20****`09`09`09`09`09`09`09`09`20`20`20****`20
X`20****`09`09`09`09`09`09`09`09`20`20`20****`20
X`20**********************************************************************
X`20**********************************************************************
X
X`20Functional`20Description:
X`20`20`20`20This`20module`20provides`20a`20routine`20to`20print`20a`20disk`20
f
Vile`20in`20a`20particular
X`20`20`20`20print`20queue.
X
X`20Environment:
X`20`20`20`20Normal`20user-mode`20routine;`20no`20special`20privileges`20requi
r
Ved.
X`20`20`20`20User`20must`20have`20Read`20and`20Delete`20access`20to`20the`20fi
l
Ve.
X
X`20Published`20Information:
X
X`20Change`20Requests:
X`20==========================================================================
=
V==
X`20Author:`20Frank`20J.`20Nagy`09`09Fermilab`20Research`20Division`20EED/Cont
r
Vols
X`20Modification`20History:
X
X`20V0.0`0907-Mar-89`20`20FJN`09Created`20after`20success`20with`20Q2UP.C`20an
d
V`20discussion`20with
X`09`09`09Jack`20and`20Ed.
X*/
X
X/******************
X`20*`20Include`20Files:`20*
X`20******************/
X#include`20`20vaxtypes`09`09`09/*`20VAX`20C`20Type`20extensions`20*/
X#include`20`20descrip`09`09`09/*`20VAX`20Descriptors`20*/
X#include`20`20descrip2`09`09`09/*`20Additional`20descriptor`20defs.`20*/
X#include`20`20errno`09`09`09`09/*`20VAX`20C`20error`20numbers`20*/
X#include`20`20psldef`09`09`09/*`20Access`20mode`20definitions`20*/
X#include`20`20ssdef`09`09`09`09/*`20System`20status`20codes`20*/
X#include`20`20stdio`09`09`09`09/*`20VAX`20C`20standard`20I/O`20*/
X#include`20`20vaxargs`09`09`09/*`20VAX`20C`20argument`20count`20*/
X
X/********************************
X`20*`20Local`20definitions`20and`20types:`20*
X`20********************************/
Xtypedef`20unsigned`20long`20status;`09`09/*`20Condition`20code`20status`20typ
e
V`20*/
X
X#define`09NAME_MAX`20`20`20`2064`09`09`09/*`20Queue`20name`20maximum`20length
V`20*/
X
X/*****************************
X`20*`20Module`20Local`20Own`20Storage:`20*
X`20*****************************/
Xstatic`20readonly`20char`20defaultspec`5B`5D`20=`20"dna=SYS$DISK:`5B`5D.LIS";
Xstatic`20readonly`20$DESCRIPTOR(`20d_sysprint,`20"SYS$PRINT");
Xstatic`20readonly`20$DESCRIPTOR(`20d_process,`20"LNM$PROCESS");
X
X/**********************************************
X`20*`20Global`20Procedure`20and`20Function`20definitions:`20*
X`20**********************************************/
Xextern`20status`20lib_crelnm();`09`09/*`20Create`20logical`20name`20routine
V`20*/
Xextern`20status`20sys$dellnm();`09`09/*`20Delete`20logical`20name`20service
V`20*/
Xextern`20void`20str$upcase(),`20str$trim();`09/*`20String`20processing`20rout
i
Vnes`20*/
X
Xextern`20int`20strlen();`09`09`09/*`20Length`20of`20NUL-terminated`20string
V`20*/
X
X`0C
X/*+1elib_print_file
X`5Csubnam
X`20`20elib_print_file
X`5Csubcal
X`20`20`20status`20=`20elib_print_file(`20filespec`20`5B,queuename`5D`20)
X`5Csubcalend
X`5Csubtxt
XPrint`20the`20specified`20file.`20`20Fixed`20defaults`20of`20"SYS$DISK:`5B`5D
