xref: /csrg-svn/usr.bin/uucp/uux/uux.c (revision 33578)
113695Ssam #ifndef lint
2*33578Srick static char sccsid[] = "@(#)uux.c	5.7 (Berkeley) 02/24/88";
313695Ssam #endif
413695Ssam 
513695Ssam #include "uucp.h"
6*33578Srick #include <sys/stat.h>
713695Ssam 
813695Ssam #define NOSYSPART 0
913695Ssam #define HASSYSPART 1
1013695Ssam 
1125146Sbloom #define LQUOTE	'('
1225146Sbloom #define RQUOTE ')'
1325146Sbloom 
1413695Ssam #define APPCMD(d) {\
1525967Sbloom register char *p; for (p = d; *p != '\0';)\
1625967Sbloom 	{*cmdp++ = *p++;\
1725967Sbloom 		if(cmdp>(sizeof(cmd)+&cmd[0])){\
1825967Sbloom 			fprintf(stderr,"argument list too long\n");\
1925967Sbloom 			cleanup(EX_SOFTWARE);\
2025967Sbloom 		}\
2125967Sbloom 	}\
2225967Sbloom 	*cmdp++ = ' '; *cmdp = '\0';}
2313695Ssam 
2413695Ssam #define GENSEND(f, a, b, c, d, e) {\
2525967Sbloom 	fprintf(f, "S %s %s %s -%s %s 0666\n", a, b, c, d, e); }
2617845Sralph #define GENRCV(f, a, b, c) {fprintf(f, "R %s %s %s - \n", a, b, c);}
2713695Ssam 
2825146Sbloom struct timeb Now;
2925146Sbloom 
3013695Ssam main(argc, argv)
3113695Ssam char *argv[];
3213695Ssam {
3313695Ssam 	char cfile[NAMESIZE];	/* send commands for files from here */
3413695Ssam 	char dfile[NAMESIZE];	/* used for all data files from here */
3513695Ssam 	char rxfile[NAMESIZE];	/* to be sent to xqt file (X. ...) */
3613695Ssam 	char tfile[NAMESIZE];	/* temporary file name */
3713695Ssam 	char tcfile[NAMESIZE];	/* temporary file name */
3813695Ssam 	char t2file[NAMESIZE];	/* temporary file name */
3913695Ssam 	int cflag = 0;		/*  commands in C. file flag  */
4013695Ssam 	int rflag = 0;		/*  C. files for receiving flag  */
4117845Sralph #ifdef DONTCOPY
4217845Sralph 	int Copy = 0;		/* Don't Copy spool files */
4317845Sralph #else !DONTCOPY
4413695Ssam 	int Copy = 1;		/* Copy spool files */
4517845Sralph #endif !DONTCOPY
4617845Sralph 	int Linkit = 0;		/* Try link before copy */
4725967Sbloom 	char buf[2*BUFSIZ];
4825967Sbloom 	char inargs[2*BUFSIZ];
4913695Ssam 	int pipein = 0;
5013695Ssam 	int startjob = 1;
5113695Ssam 	char Grade = 'A';
52*33578Srick 	long Gradedelta = 100000000L;	/* "huge number" */
53*33578Srick 	long size = 0L;
5413695Ssam 	char path[MAXFULLNAME];
5525967Sbloom 	char cmd[2*BUFSIZ];
5613695Ssam 	char *ap, *cmdp;
5725967Sbloom 	char prm[2*BUFSIZ];
5823691Sbloom 	char syspart[MAXBASENAME+1], rest[MAXFULLNAME];
5923691Sbloom 	char Xsys[MAXBASENAME+1], local[MAXBASENAME+1];
6018627Sralph 	char *xsys = Xsys;
6113695Ssam 	FILE *fprx, *fpc, *fpd, *fp;
6213695Ssam 	extern char *getprm(), *lastpart();
6313695Ssam 	extern FILE *ufopen();
6413695Ssam 	int uid, ret;
6513695Ssam 	char redir = '\0';
6613695Ssam 	int nonoti = 0;
6713695Ssam 	int nonzero = 0;
6817845Sralph 	int link_failed;
6917845Sralph 	char *ReturnTo = NULL;
7017845Sralph 	extern int LocalOnly;
7113695Ssam 
7213695Ssam 	strcpy(Progname, "uux");
7313695Ssam 	uucpname(Myname);
7413695Ssam 	umask(WFMASK);
7513695Ssam 	Ofn = 1;
7613695Ssam 	Ifn = 0;
7717845Sralph #ifdef	VMS
7817845Sralph 	arg_fix(argc, argv);
7917845Sralph #endif
8013695Ssam 	while (argc>1 && argv[1][0] == '-') {
8113695Ssam 		switch(argv[1][1]){
8213695Ssam 		case 'p':
8313695Ssam 		case '\0':
8413695Ssam 			pipein = 1;
8513695Ssam 			break;
8613695Ssam 		case 'r':
8713695Ssam 			startjob = 0;
8813695Ssam 			break;
8913695Ssam 		case 'c':
9017845Sralph 			Copy = 0;
9117845Sralph 			Linkit = 0;
9217845Sralph 			break;
9313695Ssam 		case 'l':
9413695Ssam 			Copy = 0;
9517845Sralph 			Linkit = 1;
9613695Ssam 			break;
9717845Sralph 		case 'C':
9817845Sralph 			Copy = 1;
9917845Sralph 			Linkit = 0;
10017845Sralph 			break;
10113695Ssam 		case 'g':
10213695Ssam 			Grade = argv[1][2];
103*33578Srick 			Gradedelta = atol(&argv[1][3]);
10413695Ssam 			break;
10513695Ssam 		case 'x':
10617845Sralph 			chkdebug();
10713695Ssam 			Debug = atoi(&argv[1][2]);
10813695Ssam 			if (Debug <= 0)
10913695Ssam 				Debug = 1;
11013695Ssam 			break;
11113695Ssam 		case 'n':
11213695Ssam 			nonoti = 1;
11313695Ssam 			break;
11413695Ssam 		case 'z':
11513695Ssam 			nonzero = 1;
11613695Ssam 			break;
11717845Sralph 		case 'L':
11817845Sralph 			LocalOnly++;
11917845Sralph 			break;
12017845Sralph 		case 'a':
12117845Sralph 			ReturnTo = &argv[1][2];
12223691Sbloom 			if (prefix(Myname, ReturnTo) && ReturnTo[strlen(Myname)]				== '!')
12323691Sbloom 				ReturnTo = index(ReturnTo, '!') + 1;
12417845Sralph 			break;
12513695Ssam 		default:
12613695Ssam 			fprintf(stderr, "unknown flag %s\n", argv[1]);
12713695Ssam 				break;
12813695Ssam 		}
12913695Ssam 		--argc;  argv++;
13013695Ssam 	}
13125146Sbloom 	ap = getwd(Wrkdir);
13225146Sbloom 	if (ap == 0) {
13325146Sbloom 		fprintf(stderr, "can't get working directory; will try to continue\n");
13425146Sbloom 		strcpy(Wrkdir, "/UNKNOWN");
13517845Sralph 	}
13613695Ssam 
13713695Ssam 	DEBUG(4, "\n\n** %s **\n", "START");
13813695Ssam 
13913695Ssam 	inargs[0] = '\0';
14013695Ssam 	for (argv++; argc > 1; argc--) {
14113695Ssam 		DEBUG(4, "arg - %s:", *argv);
14213695Ssam 		strcat(inargs, " ");
14313695Ssam 		strcat(inargs, *argv++);
14413695Ssam 	}
14513695Ssam 	DEBUG(4, "arg - %s\n", inargs);
14617845Sralph 	ret = subchdir(Spool);
14717845Sralph 	ASSERT(ret >= 0, "CHDIR FAILED", Spool, ret);
14813695Ssam 	uid = getuid();
149*33578Srick 	if (guinfo(uid, User, path) != SUCCESS) {
150*33578Srick 		assert("Can't find username for ", "uid", uid);
151*33578Srick 		DEBUG(1, "Using username", "uucp");
152*33578Srick 		strcpy(User, "uucp");
153*33578Srick 	}
15413695Ssam 
15523691Sbloom 	strncpy(local, Myname, MAXBASENAME);
15613695Ssam 	cmdp = cmd;
15713695Ssam 	*cmdp = '\0';
15813695Ssam 	gename(DATAPRE, local, 'X', rxfile);
15913695Ssam 	fprx = ufopen(rxfile, "w");
16013695Ssam 	ASSERT(fprx != NULL, "CAN'T OPEN", rxfile, 0);
16113695Ssam 	gename(DATAPRE, local, 'T', tcfile);
16213695Ssam 	fpc = ufopen(tcfile, "w");
16313695Ssam 	ASSERT(fpc != NULL, "CAN'T OPEN", tcfile, 0);
16413695Ssam 	fprintf(fprx, "%c %s %s\n", X_USER, User, local);
16513695Ssam 	if (nonoti)
16613695Ssam 		fprintf(fprx, "%c\n", X_NONOTI);
16713695Ssam 	if (nonzero)
16813695Ssam 		fprintf(fprx, "%c\n", X_NONZERO);
16917845Sralph 	if (ReturnTo == NULL || *ReturnTo == '\0')
17017845Sralph 		ReturnTo = User;
17117845Sralph 	fprintf(fprx, "%c %s\n", X_RETURNTO, ReturnTo);
17213695Ssam 
17313695Ssam 	/* find remote system name */
17413695Ssam 	ap = inargs;
17513695Ssam 	xsys[0] = '\0';
17613695Ssam 	while ((ap = getprm(ap, prm)) != NULL) {
17713695Ssam 		if (prm[0] == '>' || prm[0] == '<') {
17813695Ssam 			ap = getprm(ap, prm);
17913695Ssam 			continue;
18013695Ssam 		}
18113695Ssam 
18213695Ssam 		split(prm, xsys, rest);
18313695Ssam 		break;
18413695Ssam 	}
18513695Ssam 	if (xsys[0] == '\0')
18613695Ssam 		strcpy(xsys, local);
18718627Sralph 	if (versys(&xsys) != 0) {
18813695Ssam 		/*  bad system name  */
18913695Ssam 		fprintf(stderr, "bad system name: %s\n", xsys);
19013695Ssam 		fclose(fprx);
19113695Ssam 		fclose(fpc);
19213695Ssam 		cleanup(EX_NOHOST);
19313695Ssam 	}
19413695Ssam 
19525146Sbloom 	strncpy(Rmtname, xsys, MAXBASENAME);
19625146Sbloom 	DEBUG(4, "xsys %s\n", xsys);
19725146Sbloom 
19813695Ssam 	if (pipein) {
19913695Ssam 		gename(DATAPRE, local, 'B', dfile);
20013695Ssam 		fpd = ufopen(dfile, "w");
20113695Ssam 		ASSERT(fpd != NULL, "CAN'T OPEN", dfile, 0);
20213695Ssam 		while (!feof(stdin)) {
20313695Ssam 			ret = fread(buf, 1, BUFSIZ, stdin);
20413695Ssam 			fwrite(buf, 1, ret, fpd);
20525967Sbloom 			if (ferror(stdin)) {
20625967Sbloom 				perror("stdin");
20725967Sbloom 				cleanup(EX_IOERR);
20825967Sbloom 			}
20925967Sbloom 			if (ferror(fpd)) {
21025967Sbloom 				perror(dfile);
21125967Sbloom 				cleanup(EX_IOERR);
21225967Sbloom 			}
213*33578Srick 			size += ret;
21413695Ssam 		}
21513695Ssam 		fclose(fpd);
21617845Sralph 		strcpy(tfile, dfile);
21713695Ssam 		if (strcmp(local, xsys) != SAME) {
21825146Sbloom 			register int Len = strlen(local);
21925146Sbloom 			if (Len > SYSNSIZE)
22025146Sbloom 				Len = SYSNSIZE;
22125146Sbloom 			tfile[Len + 2] = 'S';
22217845Sralph 			GENSEND(fpc, dfile, tfile, User, "", dfile);
22313695Ssam 			cflag++;
22413695Ssam 		}
22517845Sralph 		fprintf(fprx, "%c %s\n", X_RQDFILE, tfile);
22617845Sralph 		fprintf(fprx, "%c %s\n", X_STDIN, tfile);
22713695Ssam 	}
22813695Ssam 	/* parse command */
22913695Ssam 	ap = inargs;
23013695Ssam 	while ((ap = getprm(ap, prm)) != NULL) {
23113695Ssam 		DEBUG(4, "prm - %s\n", prm);
23213695Ssam 		if (prm[0] == '>' || prm[0] == '<') {
23313695Ssam 			redir = prm[0];
23413695Ssam 			continue;
23513695Ssam 		}
23613695Ssam 
23713695Ssam 		if (prm[0] == ';') {
23813695Ssam 			APPCMD(prm);
23913695Ssam 			continue;
24013695Ssam 		}
24113695Ssam 
24213695Ssam 		if (prm[0] == '|' || prm[0] == '^') {
24313695Ssam 			if (cmdp != cmd)
24413695Ssam 				APPCMD(prm);
24513695Ssam 			continue;
24613695Ssam 		}
24713695Ssam 
24813695Ssam 		/* process command or file or option */
24913695Ssam 		ret = split(prm, syspart, rest);
25013695Ssam 		DEBUG(4, "s - %s, ", syspart);
25113695Ssam 		DEBUG(4, "r - %s, ", rest);
25213695Ssam 		DEBUG(4, "ret - %d\n", ret);
25313695Ssam 		if (syspart[0] == '\0')
25413695Ssam 			strcpy(syspart, local);
25513695Ssam 
25613695Ssam 		if (cmdp == cmd && redir == '\0') {
25713695Ssam 			/* command */
25813695Ssam 			APPCMD(rest);
25913695Ssam 			continue;
26013695Ssam 		}
26113695Ssam 
26213695Ssam 		/* process file or option */
26313695Ssam 		DEBUG(4, "file s- %s, ", syspart);
26413695Ssam 		DEBUG(4, "local - %s\n", local);
26513695Ssam 		/* process file */
26613695Ssam 		if (redir == '>') {
26713695Ssam 			if (rest[0] != '~')
26813695Ssam 				if (ckexpf(rest))
26913695Ssam 					cleanup(EX_CANTCREAT);
27013695Ssam 			fprintf(fprx, "%c %s %s\n", X_STDOUT, rest,
27113695Ssam 			 syspart);
27213695Ssam 			redir = '\0';
27313695Ssam 			continue;
27413695Ssam 		}
27513695Ssam 
27613695Ssam 		if (ret == NOSYSPART && redir == '\0') {
27713695Ssam 			/* option */
27813695Ssam 			APPCMD(rest);
27913695Ssam 			continue;
28013695Ssam 		}
28113695Ssam 
282*33578Srick 		if (rest[0] != '\0') {
283*33578Srick 			struct stat stbuf;
284*33578Srick 			if (stat(rest, &stbuf) < 0)
285*33578Srick 				DEBUG(4, "Can't stat %s\n", rest);
286*33578Srick 			else
287*33578Srick 				size += stbuf.st_size;
288*33578Srick 			DEBUG(4, "size = %ld\n", size);
289*33578Srick 		}
290*33578Srick 
29113695Ssam 		if (strcmp(xsys, local) == SAME
29213695Ssam 		 && strcmp(xsys, syspart) == SAME) {
29313695Ssam 			if (ckexpf(rest))
29413695Ssam 				cleanup(EX_CANTCREAT);
29513695Ssam 			if (redir == '<')
29613695Ssam 				fprintf(fprx, "%c %s\n", X_STDIN, rest);
29713695Ssam 			else
29813695Ssam 				APPCMD(rest);
29913695Ssam 			redir = '\0';
30013695Ssam 			continue;
30113695Ssam 		}
30213695Ssam 
30313695Ssam 		if (strcmp(syspart, local) == SAME) {
30413695Ssam 			/*  generate send file */
30513695Ssam 			if (ckexpf(rest))
30613695Ssam 				cleanup(EX_CANTCREAT);
30713695Ssam 			gename(DATAPRE, local, 'A', dfile);
30813695Ssam 			DEBUG(4, "rest %s\n", rest);
30913695Ssam 			if ((chkpth(User, "", rest) || anyread(rest)) != 0) {
31013695Ssam 				fprintf(stderr, "permission denied %s\n", rest);
31113695Ssam 				cleanup(EX_NOINPUT);
31213695Ssam 			}
31317845Sralph 			link_failed = 0;
31417845Sralph 			if (Linkit) {
31517845Sralph 				if (link(subfile(rest), subfile(dfile)) != 0)
31617845Sralph 					link_failed++;
31717845Sralph 				else
31817845Sralph 					GENSEND(fpc, rest, dfile, User, "", dfile);
31917845Sralph 			}
32017845Sralph 			if (Copy || link_failed) {
32113695Ssam 				if (xcp(rest, dfile) != 0) {
32213695Ssam 					fprintf(stderr, "can't copy %s to %s\n", rest, dfile);
32313695Ssam 					cleanup(EX_NOINPUT);
32413695Ssam 				}
32513695Ssam 				GENSEND(fpc, rest, dfile, User, "", dfile);
32613695Ssam 			}
32717845Sralph 			if (!Copy && !Linkit) {
32813695Ssam 				GENSEND(fpc, rest, dfile, User, "c", "D.0");
32913695Ssam 			}
33013695Ssam 			cflag++;
33113695Ssam 			if (redir == '<') {
33213695Ssam 				fprintf(fprx, "%c %s\n", X_STDIN, dfile);
33313695Ssam 				fprintf(fprx, "%c %s\n", X_RQDFILE, dfile);
33418627Sralph 			} else {
33513695Ssam 				APPCMD(lastpart(rest));
33613695Ssam 				fprintf(fprx, "%c %s %s\n", X_RQDFILE,
33713695Ssam 				 dfile, lastpart(rest));
33813695Ssam 			}
33913695Ssam 			redir = '\0';
34013695Ssam 			continue;
34113695Ssam 		}
34213695Ssam 
34313695Ssam 		if (strcmp(local, xsys) == SAME) {
34413695Ssam 			/*  generate local receive  */
34513695Ssam 			gename(CMDPRE, syspart, 'R', tfile);
34613695Ssam 			strcpy(dfile, tfile);
34713695Ssam 			dfile[0] = DATAPRE;
34813695Ssam 			fp = ufopen(tfile, "w");
34913695Ssam 			ASSERT(fp != NULL, "CAN'T OPEN", tfile, 0);
35013695Ssam 			if (ckexpf(rest))
35113695Ssam 				cleanup(EX_CANTCREAT);
35213695Ssam 			GENRCV(fp, rest, dfile, User);
35313695Ssam 			fclose(fp);
35413695Ssam 			rflag++;
35513695Ssam 			if (rest[0] != '~')
35613695Ssam 				if (ckexpf(rest))
35713695Ssam 					cleanup(EX_CANTCREAT);
35813695Ssam 			if (redir == '<') {
35913695Ssam 				fprintf(fprx, "%c %s\n", X_RQDFILE, dfile);
36013695Ssam 				fprintf(fprx, "%c %s\n", X_STDIN, dfile);
36118627Sralph 			} else {
36213695Ssam 				fprintf(fprx, "%c %s %s\n", X_RQDFILE, dfile,
36313695Ssam 				  lastpart(rest));
36413695Ssam 				APPCMD(lastpart(rest));
36513695Ssam 			}
36613695Ssam 
36713695Ssam 			redir = '\0';
36813695Ssam 			continue;
36913695Ssam 		}
37013695Ssam 
37113695Ssam 		if (strcmp(syspart, xsys) != SAME) {
37213695Ssam 			/* generate remote receives */
37313695Ssam 			gename(DATAPRE, syspart, 'R', dfile);
37413695Ssam 			strcpy(tfile, dfile);
37513695Ssam 			tfile[0] = CMDPRE;
37613695Ssam 			fpd = ufopen(dfile, "w");
37713695Ssam 			ASSERT(fpd != NULL, "CAN'T OPEN", dfile, 0);
37813695Ssam 			gename(DATAPRE, local, 'T', t2file);
37913695Ssam 			GENRCV(fpd, rest, t2file, User);
38013695Ssam 			fclose(fpd);
38113695Ssam 			GENSEND(fpc, dfile, tfile, User, "", dfile);
38213695Ssam 			cflag++;
38313695Ssam 			if (redir == '<') {
38413695Ssam 				fprintf(fprx, "%c %s\n", X_RQDFILE, t2file);
38513695Ssam 				fprintf(fprx, "%c %s\n", X_STDIN, t2file);
38618627Sralph 			} else {
38713695Ssam 				fprintf(fprx, "%c %s %s\n", X_RQDFILE, t2file,
38813695Ssam 				  lastpart(rest));
38913695Ssam 				APPCMD(lastpart(rest));
39013695Ssam 			}
39113695Ssam 			redir = '\0';
39213695Ssam 			continue;
39313695Ssam 		}
39413695Ssam 
39513695Ssam 		/* file on remote system */
39613695Ssam 		if (rest[0] != '~')
39713695Ssam 			if (ckexpf(rest))
39813695Ssam 				cleanup(EX_CANTCREAT);
39913695Ssam 		if (redir == '<')
40013695Ssam 			fprintf(fprx, "%c %s\n", X_STDIN, rest);
40113695Ssam 		else
40213695Ssam 			APPCMD(rest);
40313695Ssam 		redir = '\0';
40413695Ssam 		continue;
40513695Ssam 
40613695Ssam 	}
40717845Sralph 	/*
40817845Sralph 	 * clean up trailing ' ' in command.
40917845Sralph 	 */
41017845Sralph 	if (cmdp > cmd && cmdp[0] == '\0' && cmdp[-1] == ' ')
41117845Sralph 		*--cmdp = '\0';
41217845Sralph 	/* block multi-hop uux, which doesn't work */
41317845Sralph 	for (ap = cmd; *ap && *ap != ' '; ap++)
41417845Sralph 		if (*ap == '!') {
41517845Sralph 			fprintf(stderr, "uux handles only adjacent sites.\n");
41617845Sralph 			fprintf(stderr, "Try uusend for multi-hop delivery.\n");
41725967Sbloom 			cleanup(EX_USAGE);
41817845Sralph 		}
41913695Ssam 
42013695Ssam 	fprintf(fprx, "%c %s\n", X_CMD, cmd);
42125967Sbloom 	if (ferror(fprx)) {
42225967Sbloom 		logent(cmd, "COULD NOT QUEUE XQT");
42325967Sbloom 		cleanup(EX_IOERR);
42425967Sbloom 	} else
42525967Sbloom 		logent(cmd, "XQT QUE'D");
42613695Ssam 	fclose(fprx);
42713695Ssam 
428*33578Srick 	if (size > 0 && Gradedelta > 0) {
429*33578Srick 		DEBUG (4, "Grade changed from %c ", Grade);
430*33578Srick 		Grade += size/Gradedelta;
431*33578Srick 		if (Grade > 'z')
432*33578Srick 			Grade = 'z';
433*33578Srick 		DEBUG(4, "to %c\n", Grade);
434*33578Srick 	}
43517845Sralph 	gename(XQTPRE, local, Grade, tfile);
43613695Ssam 	if (strcmp(xsys, local) == SAME) {
43713695Ssam 		/* rti!trt: xmv() works across filesystems, link(II) doesnt */
43813695Ssam 		xmv(rxfile, tfile);
43913695Ssam 		if (startjob)
44013695Ssam 			if (rflag)
44113695Ssam 				xuucico(xsys);
44213695Ssam 			else
44313695Ssam 				xuuxqt();
44413695Ssam 	}
44513695Ssam 	else {
44613695Ssam 		GENSEND(fpc, rxfile, tfile, User, "", rxfile);
44713695Ssam 		cflag++;
44813695Ssam 	}
44913695Ssam 
45025967Sbloom 	if (ferror(fpc))
45125967Sbloom 		cleanup(EX_IOERR);
45213695Ssam 	fclose(fpc);
45313695Ssam 	if (cflag) {
45413695Ssam 		gename(CMDPRE, xsys, Grade, cfile);
45513695Ssam 		/* rti!trt: use xmv() rather than link(II) */
45613695Ssam 		xmv(tcfile, cfile);
45713695Ssam 		if (startjob)
45813695Ssam 			xuucico(xsys);
45913695Ssam 		cleanup(0);
46013695Ssam 	}
46113695Ssam 	else
46213695Ssam 		unlink(subfile(tcfile));
46318627Sralph 	exit(0);
46413695Ssam }
46513695Ssam 
46613695Ssam #define FTABSIZE 30
46713695Ssam char Fname[FTABSIZE][NAMESIZE];
46813695Ssam int Fnamect = 0;
46913695Ssam 
47017845Sralph /*
47117845Sralph  *	cleanup and unlink if error
47213695Ssam  *
47313695Ssam  *	return - none - do exit()
47413695Ssam  */
47513695Ssam 
47613695Ssam cleanup(code)
47713695Ssam int code;
47813695Ssam {
47913695Ssam 	int i;
48013695Ssam 
48113695Ssam 	logcls();
48213695Ssam 	rmlock(CNULL);
48313695Ssam 	if (code) {
48413695Ssam 		for (i = 0; i < Fnamect; i++)
48513695Ssam 			unlink(subfile(Fname[i]));
48613695Ssam 		fprintf(stderr, "uux failed. code %d\n", code);
48713695Ssam 	}
48813695Ssam 	DEBUG(1, "exit code %d\n", code);
48913695Ssam 	exit(code);
49013695Ssam }
49113695Ssam 
49217845Sralph /*
49317845Sralph  *	open file and record name
49413695Ssam  *
49513695Ssam  *	return file pointer.
49613695Ssam  */
49713695Ssam 
49813695Ssam FILE *ufopen(file, mode)
49913695Ssam char *file, *mode;
50013695Ssam {
50113695Ssam 	if (Fnamect < FTABSIZE)
50213695Ssam 		strcpy(Fname[Fnamect++], file);
50313695Ssam 	else
50413695Ssam 		logent("Fname", "TABLE OVERFLOW");
50517845Sralph 	return fopen(subfile(file), mode);
50613695Ssam }
50717845Sralph #ifdef	VMS
50817845Sralph /*
50917845Sralph  * EUNICE bug:
51017845Sralph  *	quotes are not stripped from DCL.  Do it here.
51117845Sralph  *	Note if we are running under Unix shell we don't
51217845Sralph  *	do the right thing.
51317845Sralph  */
51417845Sralph arg_fix(argc, argv)
51517845Sralph char **argv;
51617845Sralph {
51717845Sralph 	register char *cp, *tp;
51817845Sralph 
51917845Sralph 	for (; argc > 0; --argc, argv++) {
52017845Sralph 		cp = *argv;
52117845Sralph 		if (cp == (char *)0 || *cp++ != '"')
52217845Sralph 			continue;
52317845Sralph 		tp = cp;
52417845Sralph 		while (*tp++) ;
52517845Sralph 		tp -= 2;
52617845Sralph 		if (*tp == '"') {
52717845Sralph 			*tp = '\0';
52817845Sralph 			*argv = cp;
52917845Sralph 		}
53017845Sralph 	}
53117845Sralph }
53217845Sralph #endif VMS
53325146Sbloom 
53425146Sbloom /*
53525146Sbloom  *	split into system and file part
53625146Sbloom  *
53725146Sbloom  *	return codes:
53825146Sbloom  *		NOSYSPART
53925146Sbloom  *		HASSYSPART
54025146Sbloom  */
54125146Sbloom 
54225146Sbloom split(name, sys, rest)
54325146Sbloom register char *name, *rest;
54425146Sbloom char *sys;
54525146Sbloom {
54625146Sbloom 	register char *c;
54725146Sbloom 
54825146Sbloom 	if (*name == LQUOTE) {
54925146Sbloom 		if ((c = index(name + 1, RQUOTE)) != NULL) {
55025146Sbloom 		/* strip off quotes */
55125146Sbloom 			name++;
55225146Sbloom 			while (c != name)
55325146Sbloom 				*rest++ = *name++;
55425146Sbloom 			*rest = '\0';
55525146Sbloom 			*sys = '\0';
55625146Sbloom 			return NOSYSPART;
55725146Sbloom 		}
55825146Sbloom 	}
55925146Sbloom 
56025146Sbloom 	if ((c = index(name, '!')) == NULL) {
56125146Sbloom 		strcpy(rest, name);
56225146Sbloom 		*sys = '\0';
56325146Sbloom 		return NOSYSPART;
56425146Sbloom 	}
56525146Sbloom 
56625146Sbloom 	*c++ = '\0';
56725146Sbloom 	strncpy(sys, name, MAXBASENAME);
56825146Sbloom 	sys[MAXBASENAME] = '\0';
56925146Sbloom 
57025146Sbloom 	strcpy(rest, c);
57125146Sbloom 	return HASSYSPART;
57225146Sbloom }
573