/*
 *	Copyright (C) 1984, 1985  SRI International
 *	Copyright (C) 1988, 1989, 1992	TGV, Incorporated
 *
 *	Do "RSCAN" (command line) parsing
 *
 */

#include "vax-mm.h"

Do_Rscan(Command_Line)
char *Command_Line;
{
	register char *cp,*cp1;
	struct tbluk_keyword *t;
	int i,Status;
	static int Count = 0;
	extern char TopLevel[];
	extern int CMD_Get(),CMD_Send(),CMD_MSbboard(),CMD_Take();
	static struct comnd_function TopLevel_Command =
				    {COMND_KEYWORD,0,0,(int)TopLevel};

	/*
	 *	Doing Rscan
	 */
	Doing_Rscan = 1;
	/*
	 *	Parse the 1st token in the command line
	 */
	Setup_String_Parse(Command_Line);
	Status = comnd_jsys(&Command_State,&TopLevel_Command,&t,0);
	if (Status < 0) {
		printf("?Parse error\n");
		exit_MM(0);
	}
	/*
	 *	Setup the non-local goto
	 */
	setjmp(Goto_Top_Level);
	Count++;
	if (Count > 1) exit_MM(0);
	/*
	 *	If its Get, call CMD_Get and return
	 */
	if ((int (*)())t->user_data == CMD_Get) {
		CMD_Get();
		return;
	}
	/*
	 *	If its Send, call CMD_Send and exit
	 *	(Also disable "USE-EDITOR-AUTOMATICALLY")
	 */
	if ((int (*)())t->user_data == CMD_Send) {
		Use_Editor_Automatically = 0;
		CMD_Send();
		exit_MM(0);
	}
	/*
	 *	If its Bboard, call CMD_MSbboard and return
	 */
	if ((int (*)())t->user_data == CMD_MSbboard) {
		CMD_MSbboard();
		return;
	}
	/*
	 *	If its Take, call CMD_Take and return
	 */
	if ((int (*)())t->user_data == CMD_Take) {
		CMD_Take();
		return;
	}
	/*
	 *	Get the default mail file
	 */
	GetFile(Home_File(MM_MAIL_FILE));
	/*
	 *	Execute the command
	 */
	(*(int (*)())t->user_data) ();
	/*
	 *	Exit
	 */
	exit_MM(0);
}
