! Printer/plotter/etc despooler for new filestore. ! Process runs autonomously in the filestore machine. It is wakened ! by the scheduler every so often. It has a look round the designated ! spool directory, takes each of the files there, prints them and ! deletes them when done... %include "CONFIG.INC" %include "COMMON" %include "UTILITY.INC" %include "SCHEDULE.INC" %include "ERRORS.INC" %constinteger LF = 10 %constinteger FF = 12 %constinteger CR = 13 %ownrecord(common fm)%name common %externalrecord(common fm)%mapspec common area %externalintegerspec ether context %externalintegerfnspec FS logon(%string(255) ownername, %string(255) password, %integername Uno) %externalintegerfnspec FS logoff(%integer Uno) %externalintegerfnspec FS openr(%integer Uno, %string(255) filename, %integername Xno, block count, pad count) %externalintegerfnspec FS readsq(%integer Xno, %integername bytes, %record(buffer fm)%name buffer) %externalintegerfnspec FS close(%integer Xno) %externalintegerfnspec FS delete(%integer Uno, %string(255) filename) %routine show error(%integer status) write(status ! 16_FFFF0000, 0) %end %externalroutine spooler main entry %owninteger spooler ID = 0 %string(15)%array files(1 : 128) %string(15) our directory, our password %integer Uno, status, our qsart, flags %integer file limit, bytes, next, i, j %integer us, our context, our wait flag, buff, txbuff %record(buffer fm)%name b, txb %routine put symbol(%integer sym) %if sym >= 0 %start %if txbuff = 0 %start txbuff = claim buffer txb == common_buffer(txbuff) txb_bytes = 0 %finish txb_b(txb_bytes) = sym txb_bytes = txb_bytes + 1 %finish %if tx buff # 0 %and (sym < 0 %or txb_bytes = 512) %start txb_text = "" txb_sync = our wait flag txb_context = our qsart send qsart buffer(txbuff) txbuff = 0 wait for(our wait flag) %finish %end %integerfn get symbol(%integer Xno) %integer status, ch %if next >= b_bytes %start ether context = our context status = FS readSQ(Xno, bytes, b) %if status # success %start pdate printstring(our directory) printstring(" failed to read Xno "); write(Xno, 0) printstring(" -- "); show error(status) newline %result = -1 %finish next = 0 %finish %result = -1 %if b_bytes = 0 ch = b_b(next) next = next + 1 %result = ch %end %routine get files %integer i, status, Xno, bc, pc, ch %string(15) n file limit = 0 ether context = our context status = FS openR(Uno, "DIRECTORY", Xno, bc, pc) %if status # success %start pdate printstring("*** Failed to open ") printstring(our directory) printstring(":DIRECTORY -- "); show error(status) newline %return %finish n = "" %cycle ch = get symbol(Xno) %exit %if ch < 0 %if ch = nl %start file limit = file limit + 1 files(file limit) = n n = "" %else n = n . to string(ch) %finish %repeat ether context = our context status = FS Close(Xno) %if status # success %start pdate printstring("*** Failed to close ") printstring(our directory) printstring(":DIRECTORY -- "); show error(status) newline %finish %end %routine print one(%integer which) %integer Xno, bc, pc, ch, status, sym, last %return %if files(which) = "$$$........." %or %c charno(files(which), length(files(which))) = '!' %if flags & spool report # 0 %or common_diags & spool diags # 0 %start pdate printstring("Print ") printstring(our directory); print symbol(':') printstring(files(which)) newline %finish ether context = our context status = FS openR(Uno, files(which), Xno, bc, pc) %if status # success %start pdate printstring("Failed to open ") printstring(our directory); print symbol(':') printstring(files(which)) printstring(" -- "); show error(status) newline %return %finish next = 999 txbuff = 0 last = -1 %cycle sym = get symbol(Xno) %if flags & spool transparent = 0 %start %if sym < 0 %start put symbol(FF) %unless last = FF put symbol(-1) %exit %else %if sym = LF put symbol(CR) %unless last = CR put symbol(LF) %else %if sym = FF put symbol(FF) %unless last = FF %else put symbol(sym) %if ' ' <= sym <= '~' %finish %else put symbol(sym) %finish last = sym %repeat ether context = our context status = FS close(Xno) %if status # success %start pdate printstring("Failed to close ") printstring(our directory); print symbol(':') printstring(files(which)) printstring(" -- "); show error(status) newline %return %finish ether context = our context status = FS delete(Uno, files(which)) %if status # success %start pdate printstring("Failed to delete ") printstring(our directory); print symbol(':') printstring(files(which)) printstring(" -- "); show error(status) newline %return %finish %end common == common area !D common_diags = common_diags ! spool diags ! 64 spooler ID = spooler ID + 1 us = spooler ID our context = -100 - us our wait flag = spooler base - 1 + us our qsart = spool qsarts(us) our directory = spool directories(us) our password = spool passes(us) flags = spool flags(us) buff = claim buffer b == common_buffer(buff) pdate printstring(our directory) printstring(" starting") newline %cycle wait for(our wait flag) ether context = our context status = FS logon(our directory, our password, Uno) %if status # success %start pdate printstring(our directory) printstring(" failed to log on -- ") show error(status) newline %else next = 999 get files print one(i) %for i = file limit, -1, 1 ether context = our context status = FS logoff(Uno) %if status # success %start pdate printstring(our directory) printstring(" failed to log off -- "); show error(status) newline %finish %finish %repeat %end %end %of %file