xref: /csrg-svn/usr.bin/uucp/uux/uux.c (revision 35224)
113695Ssam #ifndef lint
2*35224Sbostic static char sccsid[] = "@(#)uux.c	5.13	(Berkeley) 07/22/88";
313695Ssam #endif
413695Ssam 
513695Ssam #include "uucp.h"
633578Srick #include <sys/stat.h>
734674Srick #include <sysexits.h>
813695Ssam 
913695Ssam #define NOSYSPART 0
1013695Ssam #define HASSYSPART 1
1113695Ssam 
1225146Sbloom #define LQUOTE	'('
1325146Sbloom #define RQUOTE ')'
1425146Sbloom 
1513695Ssam #define APPCMD(d) {\
1625967Sbloom register char *p; for (p = d; *p != '\0';)\
1725967Sbloom 	{*cmdp++ = *p++;\
1825967Sbloom 		if(cmdp>(sizeof(cmd)+&cmd[0])){\
1925967Sbloom 			fprintf(stderr,"argument list too long\n");\
2034674Srick 			cleanup(EX_SOFTWARE);\
2125967Sbloom 		}\
2225967Sbloom 	}\
2325967Sbloom 	*cmdp++ = ' '; *cmdp = '\0';}
2413695Ssam 
2513695Ssam #define GENSEND(f, a, b, c, d, e) {\
2625967Sbloom 	fprintf(f, "S %s %s %s -%s %s 0666\n", a, b, c, d, e); }
2717845Sralph #define GENRCV(f, a, b, c) {fprintf(f, "R %s %s %s - \n", a, b, c);}
2813695Ssam 
2925146Sbloom struct timeb Now;
3025146Sbloom 
3113695Ssam main(argc, argv)
3233965Srick int argc;
3333965Srick char **argv;
3413695Ssam {
3513695Ssam 	char cfile[NAMESIZE];	/* send commands for files from here */
3613695Ssam 	char dfile[NAMESIZE];	/* used for all data files from here */
3713695Ssam 	char rxfile[NAMESIZE];	/* to be sent to xqt file (X. ...) */
3813695Ssam 	char tfile[NAMESIZE];	/* temporary file name */
3913695Ssam 	char tcfile[NAMESIZE];	/* temporary file name */
4013695Ssam 	char t2file[NAMESIZE];	/* temporary file name */
4113695Ssam 	int cflag = 0;		/*  commands in C. file flag  */
4213695Ssam 	int rflag = 0;		/*  C. files for receiving flag  */
4317845Sralph #ifdef DONTCOPY
4417845Sralph 	int Copy = 0;		/* Don't Copy spool files */
4517845Sralph #else !DONTCOPY
4613695Ssam 	int Copy = 1;		/* Copy spool files */
4717845Sralph #endif !DONTCOPY
4817845Sralph 	int Linkit = 0;		/* Try link before copy */
4925967Sbloom 	char buf[2*BUFSIZ];
5025967Sbloom 	char inargs[2*BUFSIZ];
5113695Ssam 	int pipein = 0;
5213695Ssam 	int startjob = 1;
5313695Ssam 	char Grade = 'A';
5433578Srick 	long Gradedelta = 100000000L;	/* "huge number" */
5533578Srick 	long size = 0L;
5613695Ssam 	char path[MAXFULLNAME];
5725967Sbloom 	char cmd[2*BUFSIZ];
5813695Ssam 	char *ap, *cmdp;
5925967Sbloom 	char prm[2*BUFSIZ];
6023691Sbloom 	char syspart[MAXBASENAME+1], rest[MAXFULLNAME];
6123691Sbloom 	char Xsys[MAXBASENAME+1], local[MAXBASENAME+1];
6218627Sralph 	char *xsys = Xsys;
6313695Ssam 	FILE *fprx, *fpc, *fpd, *fp;
6413695Ssam 	extern char *getprm(), *lastpart();
6513695Ssam 	extern FILE *ufopen();
6633965Srick 	int uid, ret, c;
6713695Ssam 	char redir = '\0';
6813695Ssam 	int nonoti = 0;
6913695Ssam 	int nonzero = 0;
7017845Sralph 	int link_failed;
7117845Sralph 	char *ReturnTo = NULL;
7217845Sralph 	extern int LocalOnly;
7333965Srick 	extern char *optarg;
7433965Srick 	extern int optind;
7513695Ssam 
7613695Ssam 	strcpy(Progname, "uux");
7713695Ssam 	uucpname(Myname);
7813695Ssam 	umask(WFMASK);
7913695Ssam 	Ofn = 1;
8013695Ssam 	Ifn = 0;
8117845Sralph #ifdef	VMS
8217845Sralph 	arg_fix(argc, argv);
8317845Sralph #endif
84*35224Sbostic 	while ((c = getopt(argc, argv, "-prclCg:x:nzLa:")) != EOF)
8533965Srick 		switch (c) {
86*35224Sbostic 		case '-':
87*35224Sbostic 			/* FALLTHROUGH */
8813695Ssam 		case 'p':
8913695Ssam 			pipein = 1;
9013695Ssam 			break;
9113695Ssam 		case 'r':
9213695Ssam 			startjob = 0;
9313695Ssam 			break;
9413695Ssam 		case 'c':
9517845Sralph 			Copy = 0;
9617845Sralph 			Linkit = 0;
9717845Sralph 			break;
9813695Ssam 		case 'l':
9913695Ssam 			Copy = 0;
10017845Sralph 			Linkit = 1;
10113695Ssam 			break;
10217845Sralph 		case 'C':
10317845Sralph 			Copy = 1;
10417845Sralph 			Linkit = 0;
10517845Sralph 			break;
10613695Ssam 		case 'g':
10733965Srick 			Grade = *optarg;
10833965Srick 			Gradedelta = atol(optarg+1);
10913695Ssam 			break;
11013695Ssam 		case 'x':
11117845Sralph 			chkdebug();
11233965Srick 			Debug = atoi(optarg);
11313695Ssam 			if (Debug <= 0)
11413695Ssam 				Debug = 1;
11513695Ssam 			break;
11613695Ssam 		case 'n':
11713695Ssam 			nonoti = 1;
11813695Ssam 			break;
11913695Ssam 		case 'z':
12013695Ssam 			nonzero = 1;
12113695Ssam 			break;
12217845Sralph 		case 'L':
12317845Sralph 			LocalOnly++;
12417845Sralph 			break;
12517845Sralph 		case 'a':
12633965Srick 			ReturnTo = optarg;
12723691Sbloom 			if (prefix(Myname, ReturnTo) && ReturnTo[strlen(Myname)]				== '!')
12823691Sbloom 				ReturnTo = index(ReturnTo, '!') + 1;
12917845Sralph 			break;
13033965Srick 		case '?':
13113695Ssam 		default:
13233965Srick 			break;
13313695Ssam 		}
13433965Srick 
13525146Sbloom 	ap = getwd(Wrkdir);
13625146Sbloom 	if (ap == 0) {
13725146Sbloom 		fprintf(stderr, "can't get working directory; will try to continue\n");
13825146Sbloom 		strcpy(Wrkdir, "/UNKNOWN");
13917845Sralph 	}
14013695Ssam 
14113695Ssam 	DEBUG(4, "\n\n** %s **\n", "START");
14213695Ssam 
14313695Ssam 	inargs[0] = '\0';
14433965Srick 	while (optind < argc) {
14533965Srick 		DEBUG(4, "arg - %s:", argv[optind]);
14613695Ssam 		strcat(inargs, " ");
14733965Srick 		strcat(inargs, argv[optind++]);
14813695Ssam 	}
14913695Ssam 	DEBUG(4, "arg - %s\n", inargs);
15033965Srick 	if (subchdir(Spool) < 0) {
15133965Srick 		syslog(LOG_WARNING, "chdir(%s) failed: %m", Spool);
15233965Srick 		cleanup(1);
15333965Srick 	}
15413695Ssam 	uid = getuid();
15533578Srick 	if (guinfo(uid, User, path) != SUCCESS) {
15633965Srick 		syslog(LOG_WARNING, "Can't find username for uid %d", uid);
15733578Srick 		DEBUG(1, "Using username", "uucp");
15833578Srick 		strcpy(User, "uucp");
15933578Srick 	}
16013695Ssam 
16123691Sbloom 	strncpy(local, Myname, MAXBASENAME);
16213695Ssam 	cmdp = cmd;
16313695Ssam 	*cmdp = '\0';
16413695Ssam 	gename(DATAPRE, local, 'X', rxfile);
16513695Ssam 	fprx = ufopen(rxfile, "w");
16633965Srick 	if (fprx == NULL) {
16733965Srick 		syslog(LOG_WARNING, "fopen(%s) failed: %m", rxfile);
16833965Srick 		cleanup(1);
16933965Srick 	}
17013695Ssam 	gename(DATAPRE, local, 'T', tcfile);
17113695Ssam 	fpc = ufopen(tcfile, "w");
17233965Srick 	if (fpc == NULL) {
17333965Srick 		syslog(LOG_WARNING, "fopen(%s) failed: %m", tcfile);
17433965Srick 		cleanup(1);
17533965Srick 	}
17613695Ssam 	fprintf(fprx, "%c %s %s\n", X_USER, User, local);
17713695Ssam 	if (nonoti)
17813695Ssam 		fprintf(fprx, "%c\n", X_NONOTI);
17913695Ssam 	if (nonzero)
18013695Ssam 		fprintf(fprx, "%c\n", X_NONZERO);
18117845Sralph 	if (ReturnTo == NULL || *ReturnTo == '\0')
18217845Sralph 		ReturnTo = User;
18317845Sralph 	fprintf(fprx, "%c %s\n", X_RETURNTO, ReturnTo);
18413695Ssam 
18513695Ssam 	/* find remote system name */
18613695Ssam 	ap = inargs;
18713695Ssam 	xsys[0] = '\0';
18813695Ssam 	while ((ap = getprm(ap, prm)) != NULL) {
18913695Ssam 		if (prm[0] == '>' || prm[0] == '<') {
19013695Ssam 			ap = getprm(ap, prm);
19113695Ssam 			continue;
19213695Ssam 		}
19313695Ssam 
19413695Ssam 		split(prm, xsys, rest);
19513695Ssam 		break;
19613695Ssam 	}
19713695Ssam 	if (xsys[0] == '\0')
19813695Ssam 		strcpy(xsys, local);
19918627Sralph 	if (versys(&xsys) != 0) {
20013695Ssam 		/*  bad system name  */
20113695Ssam 		fprintf(stderr, "bad system name: %s\n", xsys);
20213695Ssam 		fclose(fprx);
20313695Ssam 		fclose(fpc);
20434674Srick 		cleanup(EX_NOHOST);
20513695Ssam 	}
20613695Ssam 
20725146Sbloom 	strncpy(Rmtname, xsys, MAXBASENAME);
20825146Sbloom 	DEBUG(4, "xsys %s\n", xsys);
20925146Sbloom 
21013695Ssam 	if (pipein) {
21113695Ssam 		gename(DATAPRE, local, 'B', dfile);
21213695Ssam 		fpd = ufopen(dfile, "w");
21333965Srick 		if (fpd == NULL) {
21433965Srick 			syslog(LOG_WARNING, "fopen(%s) failed: %m", dfile);
21533965Srick 			cleanup(1);
21633965Srick 		}
21713695Ssam 		while (!feof(stdin)) {
21813695Ssam 			ret = fread(buf, 1, BUFSIZ, stdin);
21913695Ssam 			fwrite(buf, 1, ret, fpd);
22025967Sbloom 			if (ferror(stdin)) {
22125967Sbloom 				perror("stdin");
22234674Srick 				cleanup(EX_IOERR);
22325967Sbloom 			}
22425967Sbloom 			if (ferror(fpd)) {
22525967Sbloom 				perror(dfile);
22634674Srick 				cleanup(EX_IOERR);
22725967Sbloom 			}
22833578Srick 			size += ret;
22913695Ssam 		}
23013695Ssam 		fclose(fpd);
23117845Sralph 		strcpy(tfile, dfile);
23213695Ssam 		if (strcmp(local, xsys) != SAME) {
23325146Sbloom 			register int Len = strlen(local);
23425146Sbloom 			if (Len > SYSNSIZE)
23525146Sbloom 				Len = SYSNSIZE;
23625146Sbloom 			tfile[Len + 2] = 'S';
23717845Sralph 			GENSEND(fpc, dfile, tfile, User, "", dfile);
23813695Ssam 			cflag++;
23913695Ssam 		}
24017845Sralph 		fprintf(fprx, "%c %s\n", X_RQDFILE, tfile);
24117845Sralph 		fprintf(fprx, "%c %s\n", X_STDIN, tfile);
24213695Ssam 	}
24313695Ssam 	/* parse command */
24413695Ssam 	ap = inargs;
24513695Ssam 	while ((ap = getprm(ap, prm)) != NULL) {
24613695Ssam 		DEBUG(4, "prm - %s\n", prm);
24713695Ssam 		if (prm[0] == '>' || prm[0] == '<') {
24813695Ssam 			redir = prm[0];
24913695Ssam 			continue;
25013695Ssam 		}
25113695Ssam 
25213695Ssam 		if (prm[0] == ';') {
25313695Ssam 			APPCMD(prm);
25413695Ssam 			continue;
25513695Ssam 		}
25613695Ssam 
25713695Ssam 		if (prm[0] == '|' || prm[0] == '^') {
25813695Ssam 			if (cmdp != cmd)
25913695Ssam 				APPCMD(prm);
26013695Ssam 			continue;
26113695Ssam 		}
26213695Ssam 
26313695Ssam 		/* process command or file or option */
26413695Ssam 		ret = split(prm, syspart, rest);
26513695Ssam 		DEBUG(4, "s - %s, ", syspart);
26613695Ssam 		DEBUG(4, "r - %s, ", rest);
26713695Ssam 		DEBUG(4, "ret - %d\n", ret);
26813695Ssam 		if (syspart[0] == '\0')
26913695Ssam 			strcpy(syspart, local);
27013695Ssam 
27113695Ssam 		if (cmdp == cmd && redir == '\0') {
27213695Ssam 			/* command */
27313695Ssam 			APPCMD(rest);
27413695Ssam 			continue;
27513695Ssam 		}
27613695Ssam 
27713695Ssam 		/* process file or option */
27813695Ssam 		DEBUG(4, "file s- %s, ", syspart);
27913695Ssam 		DEBUG(4, "local - %s\n", local);
28013695Ssam 		/* process file */
28113695Ssam 		if (redir == '>') {
28213695Ssam 			if (rest[0] != '~')
28313695Ssam 				if (ckexpf(rest))
28434674Srick 					cleanup(EX_CANTCREAT);
28513695Ssam 			fprintf(fprx, "%c %s %s\n", X_STDOUT, rest,
28613695Ssam 			 syspart);
28713695Ssam 			redir = '\0';
28813695Ssam 			continue;
28913695Ssam 		}
29013695Ssam 
29113695Ssam 		if (ret == NOSYSPART && redir == '\0') {
29213695Ssam 			/* option */
29313695Ssam 			APPCMD(rest);
29413695Ssam 			continue;
29513695Ssam 		}
29613695Ssam 
29733578Srick 		if (rest[0] != '\0') {
29833578Srick 			struct stat stbuf;
29933578Srick 			if (stat(rest, &stbuf) < 0)
30033578Srick 				DEBUG(4, "Can't stat %s\n", rest);
30133578Srick 			else
30233578Srick 				size += stbuf.st_size;
30333578Srick 			DEBUG(4, "size = %ld\n", size);
30433578Srick 		}
30533578Srick 
30613695Ssam 		if (strcmp(xsys, local) == SAME
30713695Ssam 		 && strcmp(xsys, syspart) == SAME) {
30813695Ssam 			if (ckexpf(rest))
30934674Srick 				cleanup(EX_CANTCREAT);
31013695Ssam 			if (redir == '<')
31113695Ssam 				fprintf(fprx, "%c %s\n", X_STDIN, rest);
31213695Ssam 			else
31313695Ssam 				APPCMD(rest);
31413695Ssam 			redir = '\0';
31513695Ssam 			continue;
31613695Ssam 		}
31713695Ssam 
31813695Ssam 		if (strcmp(syspart, local) == SAME) {
31913695Ssam 			/*  generate send file */
32013695Ssam 			if (ckexpf(rest))
32134674Srick 				cleanup(EX_CANTCREAT);
32213695Ssam 			gename(DATAPRE, local, 'A', dfile);
32313695Ssam 			DEBUG(4, "rest %s\n", rest);
32413695Ssam 			if ((chkpth(User, "", rest) || anyread(rest)) != 0) {
32513695Ssam 				fprintf(stderr, "permission denied %s\n", rest);
32634674Srick 				cleanup(EX_NOINPUT);
32713695Ssam 			}
32817845Sralph 			link_failed = 0;
32917845Sralph 			if (Linkit) {
33017845Sralph 				if (link(subfile(rest), subfile(dfile)) != 0)
33117845Sralph 					link_failed++;
33217845Sralph 				else
33317845Sralph 					GENSEND(fpc, rest, dfile, User, "", dfile);
33417845Sralph 			}
33517845Sralph 			if (Copy || link_failed) {
33613695Ssam 				if (xcp(rest, dfile) != 0) {
33713695Ssam 					fprintf(stderr, "can't copy %s to %s\n", rest, dfile);
33834674Srick 					cleanup(EX_NOINPUT);
33913695Ssam 				}
34013695Ssam 				GENSEND(fpc, rest, dfile, User, "", dfile);
34113695Ssam 			}
34217845Sralph 			if (!Copy && !Linkit) {
34313695Ssam 				GENSEND(fpc, rest, dfile, User, "c", "D.0");
34413695Ssam 			}
34513695Ssam 			cflag++;
34613695Ssam 			if (redir == '<') {
34713695Ssam 				fprintf(fprx, "%c %s\n", X_STDIN, dfile);
34813695Ssam 				fprintf(fprx, "%c %s\n", X_RQDFILE, dfile);
34918627Sralph 			} else {
35013695Ssam 				APPCMD(lastpart(rest));
35113695Ssam 				fprintf(fprx, "%c %s %s\n", X_RQDFILE,
35213695Ssam 				 dfile, lastpart(rest));
35313695Ssam 			}
35413695Ssam 			redir = '\0';
35513695Ssam 			continue;
35613695Ssam 		}
35713695Ssam 
35813695Ssam 		if (strcmp(local, xsys) == SAME) {
35913695Ssam 			/*  generate local receive  */
36013695Ssam 			gename(CMDPRE, syspart, 'R', tfile);
36113695Ssam 			strcpy(dfile, tfile);
36213695Ssam 			dfile[0] = DATAPRE;
36313695Ssam 			fp = ufopen(tfile, "w");
36433965Srick 			if (fp == NULL) {
36533965Srick 				syslog(LOG_WARNING, "fopen(%s) failed: %m",
36633965Srick 					tfile);
36733965Srick 				cleanup(1);
36833965Srick 			}
36913695Ssam 			if (ckexpf(rest))
37034674Srick 				cleanup(EX_CANTCREAT);
37113695Ssam 			GENRCV(fp, rest, dfile, User);
37213695Ssam 			fclose(fp);
37313695Ssam 			rflag++;
37413695Ssam 			if (rest[0] != '~')
37513695Ssam 				if (ckexpf(rest))
37634674Srick 					cleanup(EX_CANTCREAT);
37713695Ssam 			if (redir == '<') {
37813695Ssam 				fprintf(fprx, "%c %s\n", X_RQDFILE, dfile);
37913695Ssam 				fprintf(fprx, "%c %s\n", X_STDIN, dfile);
38018627Sralph 			} else {
38113695Ssam 				fprintf(fprx, "%c %s %s\n", X_RQDFILE, dfile,
38213695Ssam 				  lastpart(rest));
38313695Ssam 				APPCMD(lastpart(rest));
38413695Ssam 			}
38513695Ssam 
38613695Ssam 			redir = '\0';
38713695Ssam 			continue;
38813695Ssam 		}
38913695Ssam 
39013695Ssam 		if (strcmp(syspart, xsys) != SAME) {
39113695Ssam 			/* generate remote receives */
39213695Ssam 			gename(DATAPRE, syspart, 'R', dfile);
39313695Ssam 			strcpy(tfile, dfile);
39413695Ssam 			tfile[0] = CMDPRE;
39513695Ssam 			fpd = ufopen(dfile, "w");
39633965Srick 			if (fpd == NULL) {
39733965Srick 				syslog(LOG_WARNING, "fopen(%s) failed: %m",
39833965Srick 					dfile);
39933965Srick 				cleanup(1);
40033965Srick 			}
40113695Ssam 			gename(DATAPRE, local, 'T', t2file);
40213695Ssam 			GENRCV(fpd, rest, t2file, User);
40313695Ssam 			fclose(fpd);
40413695Ssam 			GENSEND(fpc, dfile, tfile, User, "", dfile);
40513695Ssam 			cflag++;
40613695Ssam 			if (redir == '<') {
40713695Ssam 				fprintf(fprx, "%c %s\n", X_RQDFILE, t2file);
40813695Ssam 				fprintf(fprx, "%c %s\n", X_STDIN, t2file);
40918627Sralph 			} else {
41013695Ssam 				fprintf(fprx, "%c %s %s\n", X_RQDFILE, t2file,
41113695Ssam 				  lastpart(rest));
41213695Ssam 				APPCMD(lastpart(rest));
41313695Ssam 			}
41413695Ssam 			redir = '\0';
41513695Ssam 			continue;
41613695Ssam 		}
41713695Ssam 
41813695Ssam 		/* file on remote system */
41913695Ssam 		if (rest[0] != '~')
42013695Ssam 			if (ckexpf(rest))
42134674Srick 				cleanup(EX_CANTCREAT);
42213695Ssam 		if (redir == '<')
42313695Ssam 			fprintf(fprx, "%c %s\n", X_STDIN, rest);
42413695Ssam 		else
42513695Ssam 			APPCMD(rest);
42613695Ssam 		redir = '\0';
42713695Ssam 		continue;
42813695Ssam 
42913695Ssam 	}
43017845Sralph 	/*
43117845Sralph 	 * clean up trailing ' ' in command.
43217845Sralph 	 */
43317845Sralph 	if (cmdp > cmd && cmdp[0] == '\0' && cmdp[-1] == ' ')
43417845Sralph 		*--cmdp = '\0';
43517845Sralph 	/* block multi-hop uux, which doesn't work */
43617845Sralph 	for (ap = cmd; *ap && *ap != ' '; ap++)
43717845Sralph 		if (*ap == '!') {
43817845Sralph 			fprintf(stderr, "uux handles only adjacent sites.\n");
43917845Sralph 			fprintf(stderr, "Try uusend for multi-hop delivery.\n");
44034674Srick 			cleanup(EX_USAGE);
44117845Sralph 		}
44213695Ssam 
44313695Ssam 	fprintf(fprx, "%c %s\n", X_CMD, cmd);
44425967Sbloom 	if (ferror(fprx)) {
44525967Sbloom 		logent(cmd, "COULD NOT QUEUE XQT");
44634674Srick 		cleanup(EX_IOERR);
44725967Sbloom 	} else
44825967Sbloom 		logent(cmd, "XQT QUE'D");
44913695Ssam 	fclose(fprx);
45013695Ssam 
45133578Srick 	if (size > 0 && Gradedelta > 0) {
45233578Srick 		DEBUG (4, "Grade changed from %c ", Grade);
45333578Srick 		Grade += size/Gradedelta;
45433578Srick 		if (Grade > 'z')
45533578Srick 			Grade = 'z';
45633578Srick 		DEBUG(4, "to %c\n", Grade);
45733578Srick 	}
45817845Sralph 	gename(XQTPRE, local, Grade, tfile);
45913695Ssam 	if (strcmp(xsys, local) == SAME) {
46013695Ssam 		/* rti!trt: xmv() works across filesystems, link(II) doesnt */
46113695Ssam 		xmv(rxfile, tfile);
46213695Ssam 		if (startjob)
46313695Ssam 			if (rflag)
46413695Ssam 				xuucico(xsys);
46513695Ssam 			else
46613695Ssam 				xuuxqt();
46713695Ssam 	}
46813695Ssam 	else {
46913695Ssam 		GENSEND(fpc, rxfile, tfile, User, "", rxfile);
47013695Ssam 		cflag++;
47113695Ssam 	}
47213695Ssam 
47325967Sbloom 	if (ferror(fpc))
47434674Srick 		cleanup(EX_IOERR);
47513695Ssam 	fclose(fpc);
47613695Ssam 	if (cflag) {
47713695Ssam 		gename(CMDPRE, xsys, Grade, cfile);
47813695Ssam 		/* rti!trt: use xmv() rather than link(II) */
47913695Ssam 		xmv(tcfile, cfile);
48013695Ssam 		if (startjob)
48113695Ssam 			xuucico(xsys);
48213695Ssam 		cleanup(0);
48313695Ssam 	}
48413695Ssam 	else
48513695Ssam 		unlink(subfile(tcfile));
48618627Sralph 	exit(0);
48713695Ssam }
48813695Ssam 
48913695Ssam #define FTABSIZE 30
49013695Ssam char Fname[FTABSIZE][NAMESIZE];
49113695Ssam int Fnamect = 0;
49213695Ssam 
49317845Sralph /*
49417845Sralph  *	cleanup and unlink if error
49513695Ssam  *
49613695Ssam  *	return - none - do exit()
49713695Ssam  */
49813695Ssam 
49913695Ssam cleanup(code)
50013695Ssam int code;
50113695Ssam {
50213695Ssam 	int i;
50313695Ssam 
50413695Ssam 	logcls();
50513695Ssam 	rmlock(CNULL);
50613695Ssam 	if (code) {
50713695Ssam 		for (i = 0; i < Fnamect; i++)
50813695Ssam 			unlink(subfile(Fname[i]));
50913695Ssam 		fprintf(stderr, "uux failed. code %d\n", code);
51013695Ssam 	}
51113695Ssam 	DEBUG(1, "exit code %d\n", code);
51213695Ssam 	exit(code);
51313695Ssam }
51413695Ssam 
51517845Sralph /*
51617845Sralph  *	open file and record name
51713695Ssam  *
51813695Ssam  *	return file pointer.
51913695Ssam  */
52013695Ssam 
52113695Ssam FILE *ufopen(file, mode)
52213695Ssam char *file, *mode;
52313695Ssam {
52413695Ssam 	if (Fnamect < FTABSIZE)
52513695Ssam 		strcpy(Fname[Fnamect++], file);
52613695Ssam 	else
52713695Ssam 		logent("Fname", "TABLE OVERFLOW");
52817845Sralph 	return fopen(subfile(file), mode);
52913695Ssam }
53017845Sralph #ifdef	VMS
53117845Sralph /*
53217845Sralph  * EUNICE bug:
53317845Sralph  *	quotes are not stripped from DCL.  Do it here.
53417845Sralph  *	Note if we are running under Unix shell we don't
53517845Sralph  *	do the right thing.
53617845Sralph  */
53717845Sralph arg_fix(argc, argv)
53817845Sralph char **argv;
53917845Sralph {
54017845Sralph 	register char *cp, *tp;
54117845Sralph 
54217845Sralph 	for (; argc > 0; --argc, argv++) {
54317845Sralph 		cp = *argv;
54417845Sralph 		if (cp == (char *)0 || *cp++ != '"')
54517845Sralph 			continue;
54617845Sralph 		tp = cp;
54717845Sralph 		while (*tp++) ;
54817845Sralph 		tp -= 2;
54917845Sralph 		if (*tp == '"') {
55017845Sralph 			*tp = '\0';
55117845Sralph 			*argv = cp;
55217845Sralph 		}
55317845Sralph 	}
55417845Sralph }
55517845Sralph #endif VMS
55625146Sbloom 
55725146Sbloom /*
55825146Sbloom  *	split into system and file part
55925146Sbloom  *
56025146Sbloom  *	return codes:
56125146Sbloom  *		NOSYSPART
56225146Sbloom  *		HASSYSPART
56325146Sbloom  */
56425146Sbloom 
56525146Sbloom split(name, sys, rest)
56625146Sbloom register char *name, *rest;
56725146Sbloom char *sys;
56825146Sbloom {
56925146Sbloom 	register char *c;
57025146Sbloom 
57125146Sbloom 	if (*name == LQUOTE) {
57225146Sbloom 		if ((c = index(name + 1, RQUOTE)) != NULL) {
57325146Sbloom 		/* strip off quotes */
57425146Sbloom 			name++;
57525146Sbloom 			while (c != name)
57625146Sbloom 				*rest++ = *name++;
57725146Sbloom 			*rest = '\0';
57825146Sbloom 			*sys = '\0';
57925146Sbloom 			return NOSYSPART;
58025146Sbloom 		}
58125146Sbloom 	}
58225146Sbloom 
58325146Sbloom 	if ((c = index(name, '!')) == NULL) {
58425146Sbloom 		strcpy(rest, name);
58525146Sbloom 		*sys = '\0';
58625146Sbloom 		return NOSYSPART;
58725146Sbloom 	}
58825146Sbloom 
58925146Sbloom 	*c++ = '\0';
59025146Sbloom 	strncpy(sys, name, MAXBASENAME);
59125146Sbloom 	sys[MAXBASENAME] = '\0';
59225146Sbloom 
59325146Sbloom 	strcpy(rest, c);
59425146Sbloom 	return HASSYSPART;
59525146Sbloom }
596