	SUBROUTINE GET_COMMAND
C
C	Get a VAXNET Command.
C
	INCLUDE 'COM.INC/NOLIST'

	CHARACTER*80 COMMAND
	CHARACTER*(*) VAXNETQ
	LOGICAL CHECK_CMD, REPROMPT

	PARAMETER (VAXNETQ = DS//'Vaxnet> ')

	CALL CANCEL_IO		! Cancel outstanding I/O first.
C
C	Request VAXNET command.
C
	ASSIGN 50 TO NEXT_CMD
50	CALL PROMPT_USER(VAXNETQ,%REF(COMMAND),LEN(COMMAND))
	IF (WANTS_HELP) THEN
		COMMAND = 'HELP'
		LBYTE_COUNT = 4
	ENDIF

	IF (LBYTE_COUNT .EQ. 0) GO TO 200
	IF (.NOT. CHECK_CMD(COMMAND(1:LBYTE_COUNT),REPROMPT) .OR. REPROMPT)
	1	GO TO NEXT_CMD	! Get the next command.
200	IF (BATCH_MODE) GO TO NEXT_CMD	! Stay in command loop.
	CALL REENABLE()			! Reenable everything.
	RETURN
	END

	LOGICAL FUNCTION CHECK_CMD(CMD,REPROMPT)
C
C	This routine check for a valid VAXNET command.
C
C	Inputs:
C		CMD - character string descriptor with the command.
C		REPROMPT - logical to determine if VAXNET should
C			   reprompt on a successful command.
C
C	Outputs:
C		Returns success if command was valid.
C		REPROMPT is set .TRUE. to prompt for another command.
C
	INCLUDE 'COM.INC/NOLIST'

	CHARACTER*(*) BAD_CMD, CMD
	INTEGER*4 B, S, E
	LOGICAL REPROMPT

	PARAMETER (BAD_CMD = SS//
	1 '%VAXNET- invalid command, type "HELP" for a list of '
	1 //'valid commands.'//SS//BELL)

	ASSIGN 9900 TO ALL_DONE			! Go here when done.
C
C	Dispatch to command processing routines.  All commands
C	which should prevent VAXNET from re-prompting upon completion
C	should exit via the ALL_DONE label.
C
	CHECK_CMD = .TRUE.			! Presume success.
	REPROMPT = .FALSE.			! Prevent re-prompting.
	B = 1					! Start at first character.
	CALL PARSE_CMD(CMD,B,S,E)		! Parse the command.
	IF	(CMD(1:4) .EQ. 'AUTO') THEN	! Attempt auto login.
		CALL REENABLE()			! Enable CTRL/C AST's.
		CALL AUTO_LOGIN()
		IF (.NOT. CONTROLC_TYPED) GO TO ALL_DONE
	ELSEIF	(CMD(1:1) .EQ. 'B') THEN	! Change the baud rate.
		CALL SETUP_BAUDRATE()
	ELSEIF	(CMD(1:5) .EQ. 'CROSS') THEN	! Initialize cross file.
		CROSS_FILE = .TRUE.		! Set crossfile flag.
		CALL REENABLE()			! Enable CTRL/C AST's.
		CALL WAIT_CROSSFILE()		! Wait for Crossfile.
		IF (.NOT. CONTROLC_TYPED) GO TO ALL_DONE
	ELSEIF	(CMD(1:3) .EQ. 'DEB') THEN	! Enable debug mode.
		DEBUG_MODE = .TRUE.
	ELSEIF	(CMD(1:3) .EQ. 'DIA') THEN	! Want to dial the modem.
		CALL GET_PHONE_NUMBER()		! Get the phone number.
		GO TO 200			! Use common REDIAL code.
	ELSEIF	(CMD(1:1) .EQ. 'D') THEN	! Dumps a file to the remote.
		DUMP_MODE = .TRUE.		! Show we're in dump mode.
		FLOW = OUT			! Show we're going out.
		CALL DUMP_FILE(CMD)		! Dump file(s) to the remote.
		DUMP_MODE = .FALSE.		! No longer in dump mode.
		GO TO ALL_DONE
	ELSEIF	(CMD(1:4) .EQ. 'ECHO') THEN	! Enable local echoing.
		FUNCTION = IO$_TTYREADALL
		LOCAL_ECHO = .TRUE.
	ELSEIF	(CMD(1:2) .EQ. 'EX') THEN	! Exit from Vaxnet.
		CALL FINISH()
	ELSEIF	(CMD(1:1) .EQ. 'G') THEN	! Get a file from the remote.
		FLOW = IN
		CALL GETSEND(CMD)
		GO TO ALL_DONE
	ELSEIF	(CMD(1:4) .EQ. 'HANG') THEN	! Go hangup the modem.
		CALL HANGUP_MODEM()
	ELSEIF	(CMD(1:1) .EQ. 'H') THEN	! Request for Help.
		IF (S .EQ. 0) THEN
		    CALL GET_HELP(' ')		! Get help on everything.
		ELSE
		    CALL GET_HELP(CMD(S:LEN(CMD))) ! Get help on a command.
		ENDIF
	ELSEIF	(CMD(1:1) .EQ. 'I') THEN	! Change interrupt character.
		CALL SETUP_INTERRUPT()
	ELSEIF	(CMD(1:3) .EQ. 'LOC') THEN	! Local logging.
		CALL LOCAL_LOGFILE()
	ELSEIF	(CMD(1:1) .EQ. 'L') THEN	! Open a log file.
		CALL ENABLE_LOGFILE()
	ELSEIF	(CMD(1:3) .EQ. 'MOD') THEN	! Request the modem type.
		CALL GET_MODEM_TYPE()
	ELSEIF	(CMD(1:3) .EQ. 'NOE') THEN	! Disable local echo.
		LOCAL_ECHO = .FALSE.
		FUNCTION = (IO$_TTYREADALL + IO$M_NOECHO)
	ELSEIF  (CMD(1:5) .EQ. 'NODEB') THEN	! Disable the debug flag.
		DEBUG_MODE = .FALSE.
	ELSEIF	(CMD(1:5) .EQ. 'NODEC') THEN	! Disable echo in dump mode.
		ECHO_DUMP = .FALSE.
	ELSEIF	(CMD(1:3) .EQ. 'NOH') THEN	! Disable modem hangup on exit.
		HANGUP = .FALSE.
	ELSEIF	(CMD(1:3) .EQ. 'NOL') THEN	! Disable the log file.
		CALL FLUSH_LOGFILE()		! Flush it first.
		IF (LOGFILE) CLOSE (UNIT=LOG_UNIT)
		LOGFILE = .FALSE.
	ELSEIF	(CMD(1:3) .EQ. 'ONE') THEN	! Enable one character reads.
		READ_ONE = .TRUE.
	ELSEIF	(CMD(1:3) .EQ. 'RED') THEN	! Redial the autodial modem.
200		CALL REENABLE()			! Enable CTRL/C AST's.
		CALL DIAL_MODEM()		! Go dial the modem.
		IF (.NOT. CONTROLC_TYPED .AND. MODEM_ONLINE) THEN
		    IF (CROSS_FILE) CALL WAIT_CROSSFILE()
		    IF (.NOT. CONTROLC_TYPED) CALL AUTO_LOGIN()
		    IF (.NOT. CONTROLC_TYPED) GO TO ALL_DONE
		ENDIF
	ELSEIF	(CMD(1:1) .EQ. 'R') THEN	! Change the remote port.
		CALL GET_PORT()
		IF (.NOT. BACKUP) THEN
			CALL SETUP_BAUDRATE()	! Also setup the baud rate.
		ENDIF
	ELSEIF	(CMD(1:2) .EQ. 'SY') THEN	! Change the system type.
		CALL SETUP_SYSTEM()
		CALL SETUP_REMOTE(.TRUE.)
	ELSEIF	(CMD(1:2) .EQ. 'ST') THEN	! Show Vaxnet status report.
		CALL SHOW_STATUS()
	ELSEIF	(CMD(1:2) .EQ. 'SP') THEN	! Change the baud rate (speed).
		CALL SETUP_BAUDRATE()
	ELSEIF	(CMD(1:1) .EQ. 'S') THEN	! Send a file to the remote.
		FLOW = OUT
		CALL GETSEND(CMD)
		GO TO ALL_DONE
	ELSEIF	(CMD(1:1) .EQ. '$') THEN	! Do a DCL command.
		CALL DO_DCL_COMMAND(CMD)
	ELSE					! Something else (ERROR).
		CALL WRITE_USER(BAD_CMD)
		CHECK_CMD = .FALSE.		! Show invalid command.
	ENDIF
	REPROMPT = .TRUE.			! Re-prompt for another cmd.
9900	RETURN
	END

	SUBROUTINE PARSE_CMD(CMD,BEGIN,START,END)
C
C	This routine parses the command line.
C
C	Inputs:
C		CMD - string descriptor with the command line.
C		BEGIN - beginning position within the command line.
C
C	Outputs:
C		BEGIN - starting position for the next parse.
C		START - starting position of the keyword (0 if none).
C		END - ending position +1 of the keyword (0 if none).
C
	CHARACTER*(*) CMD
	INTEGER*4 BEGIN, START, END, INDEX, SIZE

	START = 0				! Presume no keyword.
	END = 0					! No ending position.
	SIZE = LEN(CMD)				! Get length of command.
	DO 100 I = BEGIN,SIZE
	    INDEX = I				! Copy starting position.
	    IF (CMD(I:I) .EQ. ' ') GO TO 200	! We found a delimiter.
100	CONTINUE
	RETURN
200	DO 300 I = INDEX+1,SIZE
	    INDEX = I				! Save the current index.
	    IF (CMD(I:I) .NE. ' ') GO TO 400	! Skip over all spaces.
300	CONTINUE
	RETURN
400	START = INDEX				! Copy the starting position.
	DO 500 I = INDEX+1,SIZE
	    INDEX = I				! Save the current index.
	    IF (CMD(I:I) .EQ. ' ') GO TO 1000	! Found end of keyword.
500	CONTINUE
	INDEX = SIZE + 1			! Point past end of command.
1000	END = INDEX				! Copy end of the keyword.
	BEGIN = END				! Start here for next parse.
	RETURN
	END

	SUBROUTINE REENABLE
C
C	This routine is called to reenable everything.  It enables
C	CTRL/C AST's, enables the receiver and transmitter for the
C	mainline code for interactive mode, and disables the CTRL/C
C	typed flag.
C
	INCLUDE 'COM.INC/NOLIST'

	CALL SET_CONTROLC_AST()		! Enable CTRL/C AST's.
	RECEIVER_BUSY = .FALSE.		! Enable the receiver (remote).
	XMITTER_BUSY = .FALSE.		! Enable the transmitter (local).
	CONTROLC_TYPED = .FALSE.	! Reset the CTRL/C typed flag.
	RETURN
	END

	SUBROUTINE GET_HELP(TOPIC)
C
C	This subroutine is used to get help from the help library.
C	It will skip past the HELP command, append VAXNET to the front,
C	and pass the rest off to VAX_GET_HELP to output help.
C
	IMPLICIT INTEGER*4 (A-Z)
	CHARACTER*(*) TOPIC, HELP_NAME
	PARAMETER (HELP_NAME = 'VAXNET ')

	CALL VAX_GET_HELP(,,,HELP_NAME//TOPIC)
	RETURN
	END	
