/* 
 *   Copyright (c) 1990 Rodney Volz
 *   ALL RIGHTS RESERVED 
 * 
 *   THIS SOFTWARE PRODUCT CONTAINS THE
 *   UNPUBLISHED SOURCE CODE OF RODNEY VOLZ
 *
 *   The copyright notices above do not evidence
 *   intended publication of such source code.
 *
 */

/*
 * MERCURY UUCP SOURCECODE [uux.c]
 */


#ifndef MWC
#include "uulib.c"
overlay "main"
#else
#include "define.h"
#endif


main(argc,argv)	/* UUX */
int argc;
char *argv[];
{
	static char s[LLEN],s2[LLEN],s3[LLEN];
	static char host[LLEN],com[LLEN],usr[LLEN],myname[LLEN];
	char tmpdir[LLEN];
	int outh;
	
	getconf(21,tmpdir);
	
	getprof(1,usr);
	getconf(2,myname);

	send(VERSION);
	cr(1);
	
	strcpy(argv[argc - 1],s);

	if ((strlen(s) <1))
	{
		send("Usage: uux <host>!<command>");
		cr(1);
		return(-1);
	}

	
	if (linstr(s,'!') == -1)
	{
		beep();
		send("No target host specified.");
		cr(1);
		return(-1);
	}
	
	strcpys(s,host,0,linstr(s,'!') - 1);
	strcpys(s,com,linstr(s,'!') + 1,strlen(s));

	strcpy("uux: ",s2);
	stradd(host,s2);
	stradd("!",s2);
	stradd(com,s2);
	log(s2,"uux");
	
	strcpy(tmpdir,s);
	mktmp(s);
	
	outh = open(s,1);
	if (outh <= 0)
	{
		beep();
		send("Couldn't create output file:");
		cr(1);
		send(s);
		cr(1);
		return(-1);
	}
	
	strcpy("U ",s2);
	stradd(usr,s2);
	stradd(" ",s2);
	stradd(myname,s2);
	
	uu_putline(outh,s2);
	uu_putline(outh,"n");
	uu_putline(outh,"Z");
	
	strcpy("R ",s2);
	stradd(usr,s2);
	uu_putline(outh,s2);
	
	strcpy("C ",s2);
	stradd(com,s2);
	
	uu_putline(outh,s2);
	
	close(outh);
	
	strcpy("\\",s2);
	mktmp(s2);
	strcpys(s2,s3,1,strlen(s2));
	strcpy("X.",s2);
	stradd(s3,s2);
	
	if (sys_uucp(s,s2,host) == -1)
	{
		send("uux failed.");
		cr(1);
		return(-1);
	}
}

