*
* $Id$
*
* $Log$
* Revision 1.1  1996/03/07 15:18:15  mclareni
* Initial revision
*
*
#include "fatmen/pilot.h"
#if !defined(CERNLIB_UNIX)
      INTEGER FUNCTION FMJOB(CHJOB)
      CHARACTER*8 CHJOB
      INTEGER FMUSER
#if defined(CERNLIB_IBMMVS)
      DIMENSION   HJOB(2)
      CALL JOBNAM(HJOB)
      CALL UHTOC(HJOB,4,CHJOB,8)
      FMJOB=0
#endif
#if defined(CERNLIB_IBMVM)
      CHARACTER*255 CHLINE
      FMJOB=0
      CALL JOBNAM(CHJOB)
      IF(CHJOB.EQ.'INTERACT') ICODE = FMUSER(CHJOB)
#endif
#if (defined(CERNLIB_IBMVM))&&(defined(CERNLIB_VMBATCH))
*
*     Previous code does not work for VMBATCH
*
      CALL VMCMS('IDENTIFY (STACK LIFO)',IRC)
      CALL VMRTRM(CHLINE,LLINE)
      CHJOB = CHLINE(1:INDEX(CHLINE,' ')-1)
      IF(CHJOB(1:5).EQ.'VMBAT') THEN
         CALL VMCMS('VMBATCH SERVICE $ID (STACK)',IRC)
         IF(IRC.EQ.0) THEN
            CALL VMRTRM(CHLINE,LLINE)
            CHJOB = 'JOB'//CHLINE(1:LLINE)
         ENDIF
      ENDIF
#endif
#if defined(CERNLIB_VAXVMS)
C     COPIED FROM SETUP
C
      INTEGER*4     SYS$GETQUIW,LIB$MATCH_COND,STATUS
      CHARACTER*80  LINE
      CHARACTER*15  PROCNAM
      CHARACTER*20  STRING
      CHARACTER*60  FILENAME,COMM
      CHARACTER*10  FILETYPE
      CHARACTER*12  USERNAME
 
      INCLUDE '($JPIDEF)'
      INCLUDE '($QUIDEF)'
      INCLUDE '($LNMDEF)'
      INCLUDE '($SSDEF)'
C
      INTEGER*4 LIB$GETJPI
C
      STRUCTURE /ITMLST/
        UNION
          MAP
            INTEGER*2 BUFLEN,ITMCOD
            INTEGER*4 BUFADR,RETADR
          END MAP
          MAP
            INTEGER*4 END_LIST
          END MAP
         END UNION
      END STRUCTURE
C
      STRUCTURE /IOSBLK/
      INTEGER*4 STS,ZEROED
      END STRUCTURE
C
      STRUCTURE /LNMLST/
         UNION
            MAP
            INTEGER*2 BUFFER_LENGTH
              INTEGER*2 ITEM_CODE
            INTEGER*4 BUFFER_ADDRESS
              INTEGER*4 RETURN_LENGTH_ADDRESS
            ENDMAP
            MAP
            INTEGER*4 END_LIST /0/
            ENDMAP
         END UNION
      END STRUCTURE
C
      RECORD /LNMLST/ LNM_LIST(2)
      RECORD /ITMLST/ GETQUI_LIST(4)
      RECORD /IOSBLK/ IOSB
C
      CHARACTER*31 QUEUE_NAME
      CHARACTER*39 JOB_NAME
      INTEGER*2    QUEUE_NAME_LEN,JOB_NAME_LEN
      INTEGER*4    SEARCH_FLAGS,ENTRY_NUMBER
*
*      GET PROCESS NAME PROCESS ID AND USERNAME.
*
      IC = LIB$GETJPI(JPI$_PRCNAM,,,,PROCNAM,%REF(LEN))
      IC = LIB$GETJPI(JPI$_PID,,,IPID,,%REF(LEN))
      IC = LIB$GETJPI(JPI$_USERNAME,,,,USERNAME,%REF(LEN))
*
*      GET MODE (UNKNOWN, NETWORK, BATCH OR INTERACTIVE)
*
      IC = LIB$GETJPI(JPI$_MODE,,,MODE,,%REF(LEN))
      IF (MODE .NE. 2) THEN
*
*     RETURN PROCESS NAME IF NOT IN BATCH
*
         FMJOB=FMUSER(CHJOB)
         RETURN
      ENDIF
*
      GETQUI_LIST(1).BUFLEN = 4
      GETQUI_LIST(1).ITMCOD = QUI$_SEARCH_FLAGS
      GETQUI_LIST(1).BUFADR = %LOC(SEARCH_FLAGS)
      GETQUI_LIST(1).RETADR = 0
      GETQUI_LIST(2).BUFLEN = 31
      GETQUI_LIST(2).ITMCOD = QUI$_QUEUE_NAME
      GETQUI_LIST(2).BUFADR = %LOC(QUEUE_NAME)
      GETQUI_LIST(2).RETADR = %LOC(QUEUE_NAME_LEN)
      GETQUI_LIST(3).BUFLEN = 39
      GETQUI_LIST(3).ITMCOD = QUI$_JOB_NAME
      GETQUI_LIST(3).BUFADR = %LOC(JOB_NAME)
      GETQUI_LIST(3).RETADR = %LOC(JOB_NAME_LEN)
      GETQUI_LIST(4).END_LIST = 0
C
      SEARCH_FLAGS = QUI$M_SEARCH_THIS_JOB
C
      FMJOB = SYS$GETQUIW(,%VAL(QUI$_DISPLAY_JOB),,GETQUI_LIST,IOSB,,)
      IF (.NOT. FMJOB) THEN
         CALL LIB$SIGNAL(%VAL(FMJOB))
         FMJOB = 1
      ELSE
         FMJOB = 0
      ENDIF
*
*     TRUNCATE AT 8 CHARACTERS
*
      LJOB = MIN(LENOCC(JOB_NAME),8)
      CHJOB=JOB_NAME(1:LJOB)
C
#endif
      RETURN
      END
#endif
