2! PROGRAM : NPRSRV.BAS - Network Print Request Server 5! VERSION : V1.0 6! EDIT : 00 7! EDIT DATE : 06-Jul-87 10 EXTEND 11 ! & & & ! C O P Y R I G H T & & & ! Copyright (C) 1987 by Terence M. Kennedy & ! & ! & ! This software is furnished under a license and may be used and & ! copied only in accordance with 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 either & ! Terence M. Kennedy or Saint Peter's College. & ! & !******************************************************************* & & 20 ! & & & ! M O D I F I C A T I O N H I S T O R Y & & & ! VER/ED EDIT DATE REASON & ! 00 06-Jul-87 Original Version & & & 30 ! & & & ! V A R I A B L E U S A G E & & & ! VARIABLE USAGE & ! A$ Dummy for SYS calls & ! A%(30%) Holds results of SYS calls & ! FRMNAM$ PBS form name & ! HLDFLG% PBS hold flag & ! INDEX% File lookup index & ! JOBCNT% PBS job count (copies) & ! cvtflg% PBS no convert (0 vs O) flag & ! fedflg% PBS no feed (skipover) flag & ! trnflg% PBS no truncate flag & ! OFILE$ Name of file to print before queueing & ! PRIRTY% PBS job priority & ! QFILE$ Name of file to print after queueing & ! QUENAM$ PBS queue name & ! URP$ User Request Packet issued to PBS & & 100 ! Entry - set up for business & & gosub 32300 ! Set up error trap, print signon & \ dim a%(30%) ! Stores SYS call data & 1000 ! Main loop - see if we have any files to process & index%=0% ! Start with first file 1010 change sys(chr$(6%)+chr$(17%)+chr$(index%)+chr$(swap%(index%))+ & string$(2%,0%)+chr$(229%)+chr$(185%)+chr$(229%)+chr$(185%)+ & chr$(18%)+chr$(90%)) to a% ! Lookup *.NPR & \ index%=index%+1% ! Get ready for next file & \ goto 1010 if a%(30%)<>0% ! Skip if it's still open by NFT & \ ofile$=rad$(a%(7%)+swap%(a%(8%)))+rad$(a%(9%)+swap%(a%(10%))) & \ qfile$=ofile$+".NPQ" ! Construct new filename & \ ofile$=ofile$+".NPR" ! Construct old filename & \ gosub 10000 ! Go issue PBS request for it & \ goto 1000 ! and try for another & 1030 print "** yawn..." & \ sleep(30%) ! No files found, wait a while & \ goto 1000 ! and loop & 10000 print "** we should be printing ";ofile$ & \ name ofile$ as qfile$ ! Rename so we don't see again & \ quenam$="NET$PRINT" ! PBS default queue name & \ frmnam$="NORMAL" ! PBS default form name & \ prirty%=0% ! PBS default priority & \ jobcnt%=1% ! PBS default job count & \ hldflg%=0% ! PBS default hold flag & \ cvtflg%=0% ! PBS default convert flag & \ fedflg%=1% ! PBS default feed flag & \ trnflg%=0% ! PBS default no truncate flag & \ open qfile$ for input as file #1% & \ input line #1%,comnd$ ! Open file and read command string & \ close #1% ! Close quickly & \ comnd$=cvt$$(comnd$,189%) ! Compress, upcase it & \ goto 10100 if left(comnd$,6%)<>"NPRINT" & \ quenam$=fna$("/QU*EUE",quenam$) ! Get queue name if present & \ frmnam$=fna$("/FO*RMS",frmnam$) ! likewise form name, & \ prirty%=fnn%("/PR*IORITY",prirty%) ! priority, & \ jobcnt%=fnn%("/JO*B_COUNT",jobcnt%) ! copies (method 1), & \ jobcnt%=fnn%("/JO*BCOUNT",jobcnt%) ! copies (method 2), & \ hldflg%=fnb%("/HO*LD",hldflg%) ! hold, & \ cvtflg%=fnb%("/CO*NVERT",cvtflg%) ! convert, & \ fedflg%=fnb%("/FE*ED",fedflg%) ! feed, & \ trnflg%=fnb%("/TR*UNCATE",trnflg%) ! and truncate & 10100 quenam$=fno$(quenam$) ! All parsed, pad as required & \ frmnam$=fno$(frmnam$) & \ qfile$=fno$(qfile$) & \ print "Constructed command is:" & \ print " PRINT ";QFILE$;"/QUEUE=";quenam$;"/FORMS=";frmnam$; & "/PRIORITY=";num1$(prirty%);"/JOB_COUNT=";num1$(jobcnt%);" -" & \ print " /"; & \ print "NO"; if hldflg%=0% & \ print "HOLD/"; & \ print "NO"; if cvtflg%=0% & \ print "CONVERT/"; & \ print "NO"; if fedflg%=0% & \ print "FEED/"; & \ print "NO"; if trnflg%=0% & \ print "TRUNCATE/NOFLAG_PAGES/DELETE" & \ print & 10110 urp$=chr$(1%)+chr$(6%)+"NPRSRV"+chr$(2%)+chr$(len(quenam$))+ & quenam$+chr$(4%)+chr$(prirty%)+chr$(5%)+chr$(jobcnt%)+ & chr$(6%)+chr$(len(frmnam$))+frmnam$+chr$(12%)+chr$(hldflg%)+ & chr$(128%)+chr$(len(qfile$))+qfile$+chr$(130%)+chr$(cvtflg%)+ & chr$(132%)+chr$(1%)+chr$(133%)+chr$(fedflg%)+chr$(134%)+chr$(0%)+ & chr$(135%)+chr$(trnflg%) ! Build request packet 10120 a$=sys(chr$(6%)+chr$(22%)+chr$(-11%)+chr$(128%+5%)+ & string$(8%,0%)+cvt%$(swap%(len(urp$)))+string$(14%,0%)+chr$(1%)+ & string$(11%,0%)+urp$) ! Issue PBS request & \ return & 32300 ! Initialize error handling, define functions, print signon message & & on error goto 32500 ! Set up error handling & \ def* fne$(erno%) & \ fne$=cvt$$(right(sys(chr$(6%)+chr$(9%)+chr$(erno%)),3%),5%) & \ fnend ! Function to return error msg & \ def* fna$(template$,default$) ! Alpha keyword scan & \ reqd%=instr(1%,template$,"*") ! Get required part & \ reqd$=left(template$,reqd%-1%) & \ optl%=instr(1%,comnd$,reqd$) ! Get optional part & \ optl$=mid(template$,reqd%+1%,len(template$)) & \ goto 32310 if optl%=0% ! Not found, exit & \ rest$=mid(comnd$,optl%+reqd%-1%,len(comnd$)) ! Where to continue & \ for i%=1% to len(optl$)+1% ! Loop on each char & \ goto 32320 if mid(rest$,i%,1%)="=" ! If delimiter found & \ goto 32310 if mid(optl$,i%,1%)<>mid(rest$,i%,1%)! Bad keyword & \ next i% & \ goto 32320 ! If running on 32310 fna$=default$ ! return default value & \ goto 32340 32320 temp$=mid(rest$,i%+1%,len(rest$)) ! Rest of input string & \ term%=instr(1%,temp$,"/") ! Look for delimiter & \ goto 32330 if term%<>0% ! if found & \ term%=instr(1%,temp$," ") ! And again & \ goto 32330 if term%<>0% ! if found & \ fna$=temp$ ! Return all & \ goto 32340 ! and exit 32330 fna$=mid(temp$,1%,term%-1%) ! Return component 32340 fnend & \ def* fnn%(template$,default%) ! Alpha keyword scan & \ reqd%=instr(1%,template$,"*") ! Get required part & \ reqd$=left(template$,reqd%-1%) & \ optl%=instr(1%,comnd$,reqd$) ! Get optional part & \ optl$=mid(template$,reqd%+1%,len(template$)) & \ goto 32350 if optl%=0% ! Not found, exit & \ rest$=mid(comnd$,optl%+reqd%-1%,len(comnd$)) ! Where to continue & \ for i%=1% to len(optl$)+1% ! Loop on each char & \ goto 32360 if mid(rest$,i%,1%)="=" ! If delimiter found & \ goto 32350 if mid(optl$,i%,1%)<>mid(rest$,i%,1%)! Bad keyword & \ next i% & \ goto 32360 ! If running on & 32350 fnn%=default% ! return default value & \ goto 32380 32360 temp$=mid(rest$,i%+1%,len(rest$)) ! Rest of input string & \ term%=instr(1%,temp$,"/") ! Look for delimiter & \ goto 32370 if term%<>0% ! if found & \ term%=instr(1%,temp$," ") ! And again & \ goto 32370 if term%<>0% ! if found & \ fnn%=val(temp$) & \ goto 32380 ! and exit 32370 fnn%=val(mid(temp$,1%,term%-1%)) ! Return component & 32380 fnend & \ def* fnb%(template$,default%) ! Alpha keyword scan & \ reqd%=instr(1%,template$,"*") ! Get required part & \ reqd$=mid(template$,2%,reqd%-2%) ! Strip off the '/' & \ print "reqd$=";reqd$ & \ optl%=instr(1%,comnd$,reqd$) ! Get optional part & \ goto 32390 if optl%=0% ! Not found, exit & \ goto 32410 if mid(comnd$,optl%-3%,3%)="/no" & \ goto 32400 & 32390 fnb%=default% ! return default value & \ goto 32420 32400 fnb%=1% ! return positive & \ goto 32420 32410 fnb%=0% ! return negative & \ goto 32420 32420 fnend & \ def* fno$(a$) & \ fno$=a$ & \ fno$=a$+chr$(0%) if len(a$)/2.<>int(len(a$)/2.) & \ fnend ! Function to pad arguments & \ print "NPRSRV V1.0-00 "; ! print program ID, system name & \ print fne$(0%) & \ print & \ return & 32500 ! Error handlers & ! & erno%=err ! Error number & \ resume 1030 if erl=1010% ! Control-C detected & \ resume 32350 if erl=32360% ! Bad numeric parameter & \ resume 32350 if erl=32370% ! Likewise & 32510 print fne$(erno%);" at line";erl! One we don't do, print and stop & \ resume 32767 & 32767 end ! Not as simple as it looked, eh?