	PROGRAM wake
C
C Program to implement the WAKE foreign command to wake a HIBERNATE'ing
C process:
C
C+ WAKE
C
C The WAKE (foreign) command is used to wakeup a sleeping process.  The
C process may have gone to sleep using the HIBERNATE foreign command or
C by calling the $WAKE system service from inside its image.
C
C		WAKE{/IDENTIFICATION=pid} {process-name}
C
C Define via:
C		WAKE :== $WAKE
C
C Any user can WAKE one of his/her subprocesses.  GROUP privilege is
C needed to WAKE detached processes of users with the same group number
C while WORLD privilege allows any process to be awakened.
C Note that the process name can only be used when dealing with
C subprocesses or processes owned by users in the same group.
C
C-
C
	IMPLICIT INTEGER*4 (A - Z)
	PARAMETER DCL$_IVKEYW = '00038060'X	!Invalid keyword
C
	CHARACTER*80 command
	CHARACTER*16 qualifier
	INTEGER*4 pid,SYS$WAKE
C
	DATA qualifier/'/IDENTIFICATION'/
C
C Get the command line after the verb (WAKE)
C
	status = LIB$GET_FOREIGN(command,'Process? ',length)
	IF (.NOT.status) CALL LIB$STOP(%VAL(status))
C
C Convert the entire command line to uppercase
C
	status = STR$UPCASE(command,command(1:length))
	IF (.NOT.status) CALL LIB$STOP(%VAL(status))
C
C Find out if the /IDENT... qualifier was used
C
	start = LIB$LOCC('/',command(1:length))
	IF (start.NE.0) THEN
	    endstr = LIB$LOCC('=',command(start:length))
	    IF (endstr.EQ.0) CALL LIB$STOP(%VAL(DCL$_IVKEYW))
C
C Check size and content of string for proper keyword
C
	    size = endstr-start
	    IF (size.LT.3) CALL LIB$STOP(%VAL(DCL$_IVKEYW))
	    IF (command(start:endstr-1).NE.qualifier(1:size))
	1	CALL LIB$STOP(%VAL(DCL$_IVKEYW))
C
C Get process id in hexadecimal
C
	    status = ots$cvt_tz_l(command(endstr+1:length),pid)
	    IF (.NOT.status) CALL LIB$STOP(%VAL(status))
C
C now wake the requested process with the process id
C
	    status = SYS$WAKE(pid,)
	    IF (.NOT.status) CALL LIB$STOP(%VAL(status))
C
	    ELSE
C
C No qualifier, try to get process name from command line
C
	    IF (length.NE.0) THEN
C
C now wake the requested process using the process name
C
		pid = 0
		status = SYS$WAKE(pid,command(1:length))
		IF (.NOT.status) CALL LIB$STOP(%VAL(status))
C
		ENDIF
C
	    ENDIF
C
	END
