/*
 *	Copyright (C) 1984, 1985  SRI International
 *	Copyright (C) 1991  TGV, Incorporated
 *
 *	Update message file and exit
 *
 */
#include "vax-mm.h"
#include <signal.h>

extern int Set_Changes;
extern Update_Init_File();

CMD_Exit()
{

	/*
	 *	Noise
	 */
	Noise("and update message file");
	/*
	 *	Confirm
	 */
	Confirm();
	/*
	 *	Expunge
	 */
	Expunge();
	/*
	 *	Has the user modified any variables?
	 */
	if (Set_Changes) Update_Init_File(1);
	/*
	 *	Exit
	 */
	exit_MM(0);
}


Control_Z_Exit_MM()
{
	exit_MM(0);
}


/*
 *	Exit from MM
 */
exit_MM(code)
{

	/*
	 *	Print
	 */
	Print(code);
	/*
	 *	Update BBOARD info
	 */
	if (DOING_BBOARD) Set_Bboard_Read_Date1();
	/*
	 *	Check for new mail one last time
	 */
	Init_Mail_Check_Time(0);  Check_For_New_Mail(1);
	/*
	 *	Update the header file
	 */
	Update_Header_File(0);
	/*
	 *	Delete any MAIL-COPY-FILE
	 */
	if (Mail_Copy_File_Exists && (Mail_Copy_File[0] != 0))
		unlink(Mail_Copy_File);
	/*
	 *	If there is a saved editor, kill it!
	 */
	if (Saved_Editor_PID) {
		/*
		 *	Kill the editor (if error mark editor as gone)
		 */
		write(1,"\nWaiting for saved editor to exit... ",37);
		sys$delprc(&Saved_Editor_PID, 0);
		write(1,"done.\n",6);
		Saved_Editor_PID = 0;
	}

	/*
	 *	Exit
	 */
	exit(1);
}
