      PROGRAM DIRECTORY_MANAGER

CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C                                                                             C
C       The directory manager is a program to allow usage of                  C
C       protected images in a directory and provide a log of                  C
C       such usage.  Commonly used for games directories.                     C
C                                                                             C
C                                                                             C
C       It uses the following logical names:                                  C
C                                                                             C
C       MGR$DIR   points to the directory to be managed.                      C
C       MGR$LOG   points to the log deivce and filename.                      C
C       MGR$DEV   points to a logging device (the console).                   C
C                                                                             C
C                                                                             C
C       There is currently one inconvenience... a ^Y must be                  C
C       keyed in after the image exits to return to DCL.                      C
C                                                                             C
C                                                                             C
C       The directory manager must be installed as follows:                   C
C                                                                             C
C   $ mcr install                                                             C
C   INSTALL> sys$manager:dirmgr.exe/priv=(setprv,detach,oper,bypass)/open     C
C   INSTALL> /exit                                                            C
C                                                                             C
C                                                                             C
C        Ken Dellinger  October 1983           Hughes Aircraft Co.            C
C                                                                             C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC

!
!     Main variables
!
      INTEGER       LENGTH,SUCCESS
      CHARACTER*20  DATETIME
      CHARACTER*50  IMAGENAME,FULLNAME
      CHARACTER*100 LOGOUTPUT,RECORD
!
!     Main constants
!
      CHARACTER*1   CONT_Z      /'26'X/
      CHARACTER*2   INSERT      /'  '/
      CHARACTER*9   DIRECTORY   /'MGR..DIR:'/
      CHARACTER*9   LOGFILE     /'MGR..LOG:'/
      CHARACTER*9   LOGDEV      /'MGR..DEV:'/
      CHARACTER*21  NOTE        /'%DIRMGR-I-IMAGINUSE, '/
      CHARACTER*28  HELP        /'DIRE/NOTRAI MGR..DIR:*.EXE;0'/
!
!     Process information variables (USERNAME)
!
      LOGICAL*4 SYS$GETJPI
      INTEGER*2 JPI1(8),USER_NAME_L
      INTEGER*4 JPI2(4)
      CHARACTER*15 USER_NAME
      EQUIVALENCE (JPI1,JPI2)
      PARAMETER JPI$_USERNAME = '202'X
!
!     Process information variables (TERMINAL)
!
      INTEGER*2 JPI3(8),TERMINAL_NAME_L
      INTEGER*4 JPI4(4)
      CHARACTER*7 TERMINAL_NAME
      EQUIVALENCE (JPI3,JPI4)
      PARAMETER JPI$_TERMINAL = '31D'X
!
!     Process creation variables
!
      LOGICAL*4 SYS$CREPRC
      BYTE PRC4(8)
!
!     Privilege bits for BYPASS,SETPRV,DETACH,OPER
!
      DATA PRC4/'FF'X,'FF'X,'FF'X,'FF'X,'FF'X,'FF'X,'FF'X,'FF'X/
!
!     Process information list (USERNAME)
!
      JPI1(1) = 15                    !Number of elements in name
      JPI1(2) = JPI$_USERNAME         !Want Username
      JPI2(2) = %Loc(USER_NAME)       !Address of user name
      JPI2(3) = %Loc(USER_NAME_L)     !Address of user name length
      JPI2(4) = 0                     !Terminate list
!
!     Get the USERNAME
!
      SUCCESS = sys$getjpi(,,,JPI2,,,)
      if (.NOT.SUCCESS) call sys$exit(SUCCESS)
!
!     Process information list (TERMINAL)
!
      JPI3(1) = 15                    !Number of elements in name
      JPI3(2) = JPI$_TERMINAL         !Want Terminal
      JPI4(2) = %Loc(TERMINAL_NAME)   !Address of terminal name
      JPI4(3) = %Loc(TERMINAL_NAME_L) !Address of terminal name length
      JPI4(4) = 0                     !Terminate list
!
!     Get the TERMINAL NAME
!
      SUCCESS = sys$getjpi(,,,JPI4,,,)
      if (.NOT.SUCCESS) call sys$exit(SUCCESS)
!
!     Get image name
!
0001  SUCCESS = lib$get_foreign( IMAGENAME,'$_File:        ',LENGTH)
      if (LENGTH.LT.1) GOTO 0001
      if (.NOT.SUCCESS) call sys$exit(SUCCESS)
      if (IMAGENAME.EQ.'?') call lib$do_command(HELP)
!
!     Get current date and time
!
      SUCCESS = lib$date_time(DATETIME)
      if (.NOT.SUCCESS) call sys$exit(SUCCESS)
!
!     Concatonate (full-path-name & image) (log & time & user & terminal)
!
      call str$concat(FULLNAME,DIRECTORY,IMAGENAME)
      call str$concat(LOGOUTPUT,NOTE,DATETIME,INSERT,
     1 TERMINAL_NAME,INSERT,USER_NAME,DIRECTORY,IMAGENAME)
!
!     Write message to log file
!
0002  format(A100)
!
!     Open old log file if present
!
      open
     B  (
     1  unit= 1
     2 ,file= LOGFILE
     3 ,status= 'OLD'
     4 ,carriagecontrol= 'LIST'
     5 ,err= 0003
     E  )
      go to 0004
!
!     Open new log file if no old file exists
!
0003  open
     B  (
     1  unit= 1
     2 ,file= LOGFILE
     3 ,status= 'NEW'
     4 ,carriagecontrol= 'LIST'
     E  )
!
!     Read to end of file
!
0004  read(1,2,end=0005)RECORD
      go to 0004
!
!     Write message in log
!
0005  write(1,2)LOGOUTPUT
      close(1)
!
!     Send message to console
!
      call sys$brdcst(LOGOUTPUT,LOGDEV)
!
!     Create process for user
!
      SUCCESS = sys$creprc(,FULLNAME,TERMINAL_NAME
     1 ,TERMINAL_NAME,TERMINAL_NAME,PRC4,
     2 ,,%VAL(4),,,)
      if (.NOT.SUCCESS) call sys$exit(SUCCESS)
!
!     Wait for control Y to exit
!
      call sys$hiber
!
!     The FORTRAN compiler appreciates this
!
      END
