;JOBNAM.SBR
;Copyright (C) 1985 by UltraSoft.
;
;Desc:  returns your job name.  works w/MULTI.
;
;Call:  XCALL JOBNAM, name$
;
;Where: name$ = string variable to receive the job name.  The job name is
;               returned as 1-6 characters and a null byte.  A$ must be at
;               least 7 bytes in length.  If the executing job is a MULTI job,
;               the OWNING job's name is returned.
;
;1.0 27-Dec-85 created. /DFP
;1.1 23-Aug-86 for MULTI jobs, return owner job's name.  /DFP

       VMAJOR=1
       VMINOR=1

       OBJNAM  .SBR

       SEARCH  SYS
       SEARCH  SYSSYM

       .OFINI
       .OFDEF  COUNT,  2               ; number of arguments
       .OFDEF  TYPE1,  2               ; type code
       .OFDEF  ADDR1,  4               ; address
       .OFDEF  SIZE1,  4               ; size

       STRING=2                        ; type code for a string

       PHDR    -1,PV$RSM,PH$REE!PH$REU

ENTRY:  CMPW    COUNT(A3),#1            ; 1 argument specified?
       BLT     ARGERR                  ;  no
       CMPW    TYPE1(A3),#STRING       ; string argument specified?
       BNE     TYPERR                  ;  no
       CMP     SIZE1(A3),#7            ; at least 7 bytes long?
       BLT     SIZERR                  ;  no

GETNAM: JOBIDX                          ; index Job Control Block       [1.1]
       MOV     JOBATT(A6),D6           ; get attached job index        [1.1]
       BEQ     10$                     ;  no attached job              [1.1]
       MOV     D6,A6                   ; get owner job address         [1.1]
10$:    LEA     A1,JOBNAM(A6)           ; point A1 to RAD50 job name    [1.1]
       MOV     ADDR1(A3),A2            ; point A2 to A$
       UNPACK                          ; unpack 1st half of job name
       UNPACK                          ; unpack 2nd half of job name

TRIM:   CMPB    -(A2),#40               ; trailing space present?
       BEQ     TRIM                    ;  yes - decrement line index
       CLRB    1(A2)                   ; mark end of string w/NUL
       RTN                             ; return

ARGERR: TYPESP  ?Argument count
       BR      ERROR
TYPERR: TYPESP  ?Argument type
       BR      ERROR
SIZERR: TYPESP  ?Argument size
ERROR:  TYPECR  error in JOBNAM.SBR
       RTN

       END