      .title   symjob
;
;     being a collection of symbiont request routines
;
      $smrdef
      $msgdef
      jlun = 19
buff: .blkb 100
bdesc:   .long 0
      .address buff
rdesc:   .long 1
      .address read
ndesc:   .long namelen
      .address name
nldesc:  .long 0
      .address name
lun:     .long jlun
chan:    .word 0
result:  .blkb 8
         namelen = 80
name:    .blkb namelen
read: .ascii   /R/
;
;
IFLAG:   .long 0
share:   $crembx_s   chan=chan   ; create a mailbox for response
      blbc  r0,error             ; couldn't create mailbox
      $sndsmb_s   msgbuf=bdesc,chan=chan  ; send symbiont request
      blbc  r0,error             ; couldn't send message
      pushal   iflag
      calls #1,lib$get_ef        ; get an event flag
      blbs  r0,rloop
      $exit_s  r0
rloop:$qiow_s efn=iflag,chan=chan,func=#io$_readvblk,p1=result,p2=#8 ; read mbx
      blbc  r0,error
      cmpw  result,#msg$_smbrsp  ; was this from symbiont ?
      bneq  rloop                ; NO. try another read. 
      pushal   iflag
      calls #1,lib$free_ef
      $dassgn_s  chan=chan         ; YES. get rid of channel.
      blbc  r0,error             ; check for error
      movl  result+4,r0          ; put result into r0
      rsb
error:   rsb
;
;
;     CALL IFERR(JOB_RELEASE(queuename,jobid),
;        'UNABLE TO RELEASE JOB')
;
;        where queuename is the name of the queue,
;        and jobid is the job_id.
;
job_release::
      .word ^m<r2,r3,r4,r5>
      moval buff,r3              ; r3 will move through the buffer 
      movw  #smr$k_release,(r3)+ ; first stick in release request 
      moval @4(ap),r0            ; r0 has addr of descriptor
      movb  (r0),(r3)+           ; insert queuename count
      movc5 (r0),@4(r0),#^a/ /,#15,(r3)  ; insert queuename
      movw  @8(ap),(r3)+         ; throw in the job id.
      subl3 #buff,r3,bdesc       ; set length of desc.
      jsb   share                ; jump to shared code
      ret
;
;
;     CALL IFERR(JOB_REMOVE(queuename,jobid),
;        'UNABLE TO RELEASE JOB')
;
;        where queuename is the name of the queue,
;        and jobid is the job_id.
;
job_remove::
      .word ^m<r2,r3,r4,r5>
      moval buff,r3              ; r3 will move through the buffer 
      movw  #smr$k_rmvjob,(r3)+ ; first stick in remove request 
      moval @4(ap),r0            ; r0 has addr of descriptor
      movb  (r0),(r3)+           ; insert queuename count
      movc5 (r0),@4(r0),#^a/ /,#15,(r3)  ; insert queuename
      movw  @8(ap),(r3)+         ; throw in the job id.
      subl3 #buff,r3,bdesc       ; set length of desc.
      jsb   share                ; jump to shared code
      ret
;
;
;     CALL IFERR(JOB_ENTER(queuename,filename,delete,hold,
;     .   nofeed,jobid[,formtype])
;
;     where queuename is the name of the queue, filename is the name
;        of the file,
;        delete, hold, and plot are logical variables indicating
;        whether the file is to be deleted, held, or is a plot file,
;        and jobid is returned with the job number.
;        Formtype is an optional formstype for the file.
;
;
job_enter:: .word ^m<r2,r3,r4,r5,r6>
      movl  #jlun,lun 
      pushal   @8(ap)            ; push filename desc.
      pushal   rdesc             ; push 'R' desc.
      pushal   lun               ; push lun number
      calls    #3,d_open         ; open the file
      blbs     r0,common         ; success
      jmp      baderr            ; unable to open file
;
;
;     CALL IFERR(JOB_ENLUN(queuename,iolun,delete,hold,
;     .   nofeed,jobid[,formtype])
;
;     where queuename is the name of the queue, iolun is the iolun number
;        of the file,
;        delete, hold, and plot are logical variables indicating
;        whether the file is to be deleted, held, or is a plot file,
;        and jobid is returned with the job number.
;        Note that JOB_ENLUN is just like JOB_ENTER except that
;        it assumes you have the file in question already open
;        on iolun.  In many cases this is in fact the case.
;        Formtype is an optional formstype for the file.
;
;
job_enlun:: .word ^m<r2,r3,r4,r5,r6>
      movl     @8(ap),lun
common:
      moval buff,r3              ; r3 will move through the buffer 
      movw  #smr$k_enter,(r3)+   ; first stick in enter request 
      moval @4(ap),r0            ; r0 has addr of descriptor
      movb  (r0),(r3)+           ; insert queuename count
      movc5 (r0),@4(r0),#^a/ /,#15,(r3)  ; insert queuename
      pushal   (r3)              ; push buff addr.
      pushal   lun               ; push lun number
      calls    #2,d_fid          ; get fid stuff
      addl2    #28,r3            ; skip over stuff we just got
      pushal   nldesc            ; push result length param.
      pushal   ndesc             ; push name buffer desc addr.
      pushal   lun               ; push lun number
      calls    #3,d_name         ; get full file name
      locc     #^a/]/,nldesc,name  ; find end of directory string
      decl     r0                ; r0 has filename length
      movb     r0,(r3)+          ; store filename length count
      incl     r1                ; r1 is addr of filename
      movc5    r0,(r1),#^a/ /,#19,(r3)   ; store filename
      pushal   lun
      calls    #1,d_clos         ; close unit
      blbc     @12(ap),nodel     ; if delete flag clear don't set it
      movb     #smo$k_delete,(r3)+
nodel:   blbc  @16(ap),nohold    ; if hold flag clear don't set it
      movb     #smo$k_hold,(r3)+
nohold:  blbc  @20(ap),nofeed    ; if nofeed flag clear don't set it
      movb     #smo$k_nofeed,(r3)+
nofeed:  cmpb  0(ap),#7          ; did they specify a formstype ?
      bneq     noform            ; nope
      movb     #smo$k_formtype,(r3)+
      movb     @28(ap),(r3)+
noform:  subl3 #buff,r3,bdesc    ; set length of desc.
      jsb   share                ; jump to shared code
      movzwl   result+2,@24(ap)  ; return job number
      ret
baderr:
      ret
      .end
