xref: /csrg-svn/usr.bin/uucp/uux/uux.c (revision 34674)
113695Ssam #ifndef lint
2*34674Srick static char sccsid[] = "@(#)uux.c	5.12	(Berkeley) 06/08/88";
313695Ssam #endif
413695Ssam 
513695Ssam #include "uucp.h"
633578Srick #include <sys/stat.h>
7*34674Srick #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");\
20*34674Srick 			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
8433965Srick 	while ((c = getopt(argc, argv, "prclCg:x:nzLa:")) != EOF ||
8533965Srick 		*argv[optind] == '-')
8633965Srick 		switch (c) {
8733965Srick 		case EOF:
8833965Srick 			/* getopt doesn't like "-" as an argument... */
8933965Srick 			optind++;
9033965Srick 			/* NO BREAK */
9113695Ssam 		case 'p':
9213695Ssam 			pipein = 1;
9313695Ssam 			break;
9413695Ssam 		case 'r':
9513695Ssam 			startjob = 0;
9613695Ssam 			break;
9713695Ssam 		case 'c':
9817845Sralph 			Copy = 0;
9917845Sralph 			Linkit = 0;
10017845Sralph 			break;
10113695Ssam 		case 'l':
10213695Ssam 			Copy = 0;
10317845Sralph 			Linkit = 1;
10413695Ssam 			break;
10517845Sralph 		case 'C':
10617845Sralph 			Copy = 1;
10717845Sralph 			Linkit = 0;
10817845Sralph 			break;
10913695Ssam 		case 'g':
11033965Srick 			Grade = *optarg;
11133965Srick 			Gradedelta = atol(optarg+1);
11213695Ssam 			break;
11313695Ssam 		case 'x':
11417845Sralph 			chkdebug();
11533965Srick 			Debug = atoi(optarg);
11613695Ssam 			if (Debug <= 0)
11713695Ssam 				Debug = 1;
11813695Ssam 			break;
11913695Ssam 		case 'n':
12013695Ssam 			nonoti = 1;
12113695Ssam 			break;
12213695Ssam 		case 'z':
12313695Ssam 			nonzero = 1;
12413695Ssam 			break;
12517845Sralph 		case 'L':
12617845Sralph 			LocalOnly++;
12717845Sralph 			break;
12817845Sralph 		case 'a':
12933965Srick 			ReturnTo = optarg;
13023691Sbloom 			if (prefix(Myname, ReturnTo) && ReturnTo[strlen(Myname)]				== '!')
13123691Sbloom 				ReturnTo = index(ReturnTo, '!') + 1;
13217845Sralph 			break;
13333965Srick 		case '?':
13413695Ssam 		default:
13533965Srick 			fprintf(stderr, "unknown flag %s\n", argv[optind-1]);
13633965Srick 			break;
13713695Ssam 		}
13833965Srick 
13925146Sbloom 	ap = getwd(Wrkdir);
14025146Sbloom 	if (ap == 0) {
14125146Sbloom 		fprintf(stderr, "can't get working directory; will try to continue\n");
14225146Sbloom 		strcpy(Wrkdir, "/UNKNOWN");
14317845Sralph 	}
14413695Ssam 
14513695Ssam 	DEBUG(4, "\n\n** %s **\n", "START");
14613695Ssam 
14713695Ssam 	inargs[0] = '\0';
14833965Srick 	while (optind < argc) {
14933965Srick 		DEBUG(4, "arg - %s:", argv[optind]);
15013695Ssam 		strcat(inargs, " ");
15133965Srick 		strcat(inargs, argv[optind++]);
15213695Ssam 	}
15313695Ssam 	DEBUG(4, "arg - %s\n", inargs);
15433965Srick 	if (subchdir(Spool) < 0) {
15533965Srick 		syslog(LOG_WARNING, "chdir(%s) failed: %m", Spool);
15633965Srick 		cleanup(1);
15733965Srick 	}
15813695Ssam 	uid = getuid();
15933578Srick 	if (guinfo(uid, User, path) != SUCCESS) {
16033965Srick 		syslog(LOG_WARNING, "Can't find username for uid %d", uid);
16133578Srick 		DEBUG(1, "Using username", "uucp");
16233578Srick 		strcpy(User, "uucp");
16333578Srick 	}
16413695Ssam 
16523691Sbloom 	strncpy(local, Myname, MAXBASENAME);
16613695Ssam 	cmdp = cmd;
16713695Ssam 	*cmdp = '\0';
16813695Ssam 	gename(DATAPRE, local, 'X', rxfile);
16913695Ssam 	fprx = ufopen(rxfile, "w");
17033965Srick 	if (fprx == NULL) {
17133965Srick 		syslog(LOG_WARNING, "fopen(%s) failed: %m", rxfile);
17233965Srick 		cleanup(1);
17333965Srick 	}
17413695Ssam 	gename(DATAPRE, local, 'T', tcfile);
17513695Ssam 	fpc = ufopen(tcfile, "w");
17633965Srick 	if (fpc == NULL) {
17733965Srick 		syslog(LOG_WARNING, "fopen(%s) failed: %m", tcfile);
17833965Srick 		cleanup(1);
17933965Srick 	}
18013695Ssam 	fprintf(fprx, "%c %s %s\n", X_USER, User, local);
18113695Ssam 	if (nonoti)
18213695Ssam 		fprintf(fprx, "%c\n", X_NONOTI);
18313695Ssam 	if (nonzero)
18413695Ssam 		fprintf(fprx, "%c\n", X_NONZERO);
18517845Sralph 	if (ReturnTo == NULL || *ReturnTo == '\0')
18617845Sralph 		ReturnTo = User;
18717845Sralph 	fprintf(fprx, "%c %s\n", X_RETURNTO, ReturnTo);
18813695Ssam 
18913695Ssam 	/* find remote system name */
19013695Ssam 	ap = inargs;
19113695Ssam 	xsys[0] = '\0';
19213695Ssam 	while ((ap = getprm(ap, prm)) != NULL) {
19313695Ssam 		if (prm[0] == '>' || prm[0] == '<') {
19413695Ssam 			ap = getprm(ap, prm);
19513695Ssam 			continue;
19613695Ssam 		}
19713695Ssam 
19813695Ssam 		split(prm, xsys, rest);
19913695Ssam 		break;
20013695Ssam 	}
20113695Ssam 	if (xsys[0] == '\0')
20213695Ssam 		strcpy(xsys, local);
20318627Sralph 	if (versys(&xsys) != 0) {
20413695Ssam 		/*  bad system name  */
20513695Ssam 		fprintf(stderr, "bad system name: %s\n", xsys);
20613695Ssam 		fclose(fprx);
20713695Ssam 		fclose(fpc);
208*34674Srick 		cleanup(EX_NOHOST);
20913695Ssam 	}
21013695Ssam 
21125146Sbloom 	strncpy(Rmtname, xsys, MAXBASENAME);
21225146Sbloom 	DEBUG(4, "xsys %s\n", xsys);
21325146Sbloom 
21413695Ssam 	if (pipein) {
21513695Ssam 		gename(DATAPRE, local, 'B', dfile);
21613695Ssam 		fpd = ufopen(dfile, "w");
21733965Srick 		if (fpd == NULL) {
21833965Srick 			syslog(LOG_WARNING, "fopen(%s) failed: %m", dfile);
21933965Srick 			cleanup(1);
22033965Srick 		}
22113695Ssam 		while (!feof(stdin)) {
22213695Ssam 			ret = fread(buf, 1, BUFSIZ, stdin);
22313695Ssam 			fwrite(buf, 1, ret, fpd);
22425967Sbloom 			if (ferror(stdin)) {
22525967Sbloom 				perror("stdin");
226*34674Srick 				cleanup(EX_IOERR);
22725967Sbloom 			}
22825967Sbloom 			if (ferror(fpd)) {
22925967Sbloom 				perror(dfile);
230*34674Srick 				cleanup(EX_IOERR);
23125967Sbloom 			}
23233578Srick 			size += ret;
23313695Ssam 		}
23413695Ssam 		fclose(fpd);
23517845Sralph 		strcpy(tfile, dfile);
23613695Ssam 		if (strcmp(local, xsys) != SAME) {
23725146Sbloom 			register int Len = strlen(local);
23825146Sbloom 			if (Len > SYSNSIZE)
23925146Sbloom 				Len = SYSNSIZE;
24025146Sbloom 			tfile[Len + 2] = 'S';
24117845Sralph 			GENSEND(fpc, dfile, tfile, User, "", dfile);
24213695Ssam 			cflag++;
24313695Ssam 		}
24417845Sralph 		fprintf(fprx, "%c %s\n", X_RQDFILE, tfile);
24517845Sralph 		fprintf(fprx, "%c %s\n", X_STDIN, tfile);
24613695Ssam 	}
24713695Ssam 	/* parse command */
24813695Ssam 	ap = inargs;
24913695Ssam 	while ((ap = getprm(ap, prm)) != NULL) {
25013695Ssam 		DEBUG(4, "prm - %s\n", prm);
25113695Ssam 		if (prm[0] == '>' || prm[0] == '<') {
25213695Ssam 			redir = prm[0];
25313695Ssam 			continue;
25413695Ssam 		}
25513695Ssam 
25613695Ssam 		if (prm[0] == ';') {
25713695Ssam 			APPCMD(prm);
25813695Ssam 			continue;
25913695Ssam 		}
26013695Ssam 
26113695Ssam 		if (prm[0] == '|' || prm[0] == '^') {
26213695Ssam 			if (cmdp != cmd)
26313695Ssam 				APPCMD(prm);
26413695Ssam 			continue;
26513695Ssam 		}
26613695Ssam 
26713695Ssam 		/* process command or file or option */
26813695Ssam 		ret = split(prm, syspart, rest);
26913695Ssam 		DEBUG(4, "s - %s, ", syspart);
27013695Ssam 		DEBUG(4, "r - %s, ", rest);
27113695Ssam 		DEBUG(4, "ret - %d\n", ret);
27213695Ssam 		if (syspart[0] == '\0')
27313695Ssam 			strcpy(syspart, local);
27413695Ssam 
27513695Ssam 		if (cmdp == cmd && redir == '\0') {
27613695Ssam 			/* command */
27713695Ssam 			APPCMD(rest);
27813695Ssam 			continue;
27913695Ssam 		}
28013695Ssam 
28113695Ssam 		/* process file or option */
28213695Ssam 		DEBUG(4, "file s- %s, ", syspart);
28313695Ssam 		DEBUG(4, "local - %s\n", local);
28413695Ssam 		/* process file */
28513695Ssam 		if (redir == '>') {
28613695Ssam 			if (rest[0] != '~')
28713695Ssam 				if (ckexpf(rest))
288*34674Srick 					cleanup(EX_CANTCREAT);
28913695Ssam 			fprintf(fprx, "%c %s %s\n", X_STDOUT, rest,
29013695Ssam 			 syspart);
29113695Ssam 			redir = '\0';
29213695Ssam 			continue;
29313695Ssam 		}
29413695Ssam 
29513695Ssam 		if (ret == NOSYSPART && redir == '\0') {
29613695Ssam 			/* option */
29713695Ssam 			APPCMD(rest);
29813695Ssam 			continue;
29913695Ssam 		}
30013695Ssam 
30133578Srick 		if (rest[0] != '\0') {
30233578Srick 			struct stat stbuf;
30333578Srick 			if (stat(rest, &stbuf) < 0)
30433578Srick 				DEBUG(4, "Can't stat %s\n", rest);
30533578Srick 			else
30633578Srick 				size += stbuf.st_size;
30733578Srick 			DEBUG(4, "size = %ld\n", size);
30833578Srick 		}
30933578Srick 
31013695Ssam 		if (strcmp(xsys, local) == SAME
31113695Ssam 		 && strcmp(xsys, syspart) == SAME) {
31213695Ssam 			if (ckexpf(rest))
313*34674Srick 				cleanup(EX_CANTCREAT);
31413695Ssam 			if (redir == '<')
31513695Ssam 				fprintf(fprx, "%c %s\n", X_STDIN, rest);
31613695Ssam 			else
31713695Ssam 				APPCMD(rest);
31813695Ssam 			redir = '\0';
31913695Ssam 			continue;
32013695Ssam 		}
32113695Ssam 
32213695Ssam 		if (strcmp(syspart, local) == SAME) {
32313695Ssam 			/*  generate send file */
32413695Ssam 			if (ckexpf(rest))
325*34674Srick 				cleanup(EX_CANTCREAT);
32613695Ssam 			gename(DATAPRE, local, 'A', dfile);
32713695Ssam 			DEBUG(4, "rest %s\n", rest);
32813695Ssam 			if ((chkpth(User, "", rest) || anyread(rest)) != 0) {
32913695Ssam 				fprintf(stderr, "permission denied %s\n", rest);
330*34674Srick 				cleanup(EX_NOINPUT);
33113695Ssam 			}
33217845Sralph 			link_failed = 0;
33317845Sralph 			if (Linkit) {
33417845Sralph 				if (link(subfile(rest), subfile(dfile)) != 0)
33517845Sralph 					link_failed++;
33617845Sralph 				else
33717845Sralph 					GENSEND(fpc, rest, dfile, User, "", dfile);
33817845Sralph 			}
33917845Sralph 			if (Copy || link_failed) {
34013695Ssam 				if (xcp(rest, dfile) != 0) {
34113695Ssam 					fprintf(stderr, "can't copy %s to %s\n", rest, dfile);
342*34674Srick 					cleanup(EX_NOINPUT);
34313695Ssam 				}
34413695Ssam 				GENSEND(fpc, rest, dfile, User, "", dfile);
34513695Ssam 			}
34617845Sralph 			if (!Copy && !Linkit) {
34713695Ssam 				GENSEND(fpc, rest, dfile, User, "c", "D.0");
34813695Ssam 			}
34913695Ssam 			cflag++;
35013695Ssam 			if (redir == '<') {
35113695Ssam 				fprintf(fprx, "%c %s\n", X_STDIN, dfile);
35213695Ssam 				fprintf(fprx, "%c %s\n", X_RQDFILE, dfile);
35318627Sralph 			} else {
35413695Ssam 				APPCMD(lastpart(rest));
35513695Ssam 				fprintf(fprx, "%c %s %s\n", X_RQDFILE,
35613695Ssam 				 dfile, lastpart(rest));
35713695Ssam 			}
35813695Ssam 			redir = '\0';
35913695Ssam 			continue;
36013695Ssam 		}
36113695Ssam 
36213695Ssam 		if (strcmp(local, xsys) == SAME) {
36313695Ssam 			/*  generate local receive  */
36413695Ssam 			gename(CMDPRE, syspart, 'R', tfile);
36513695Ssam 			strcpy(dfile, tfile);
36613695Ssam 			dfile[0] = DATAPRE;
36713695Ssam 			fp = ufopen(tfile, "w");
36833965Srick 			if (fp == NULL) {
36933965Srick 				syslog(LOG_WARNING, "fopen(%s) failed: %m",
37033965Srick 					tfile);
37133965Srick 				cleanup(1);
37233965Srick 			}
37313695Ssam 			if (ckexpf(rest))
374*34674Srick 				cleanup(EX_CANTCREAT);
37513695Ssam 			GENRCV(fp, rest, dfile, User);
37613695Ssam 			fclose(fp);
37713695Ssam 			rflag++;
37813695Ssam 			if (rest[0] != '~')
37913695Ssam 				if (ckexpf(rest))
380*34674Srick 					cleanup(EX_CANTCREAT);
38113695Ssam 			if (redir == '<') {
38213695Ssam 				fprintf(fprx, "%c %s\n", X_RQDFILE, dfile);
38313695Ssam 				fprintf(fprx, "%c %s\n", X_STDIN, dfile);
38418627Sralph 			} else {
38513695Ssam 				fprintf(fprx, "%c %s %s\n", X_RQDFILE, dfile,
38613695Ssam 				  lastpart(rest));
38713695Ssam 				APPCMD(lastpart(rest));
38813695Ssam 			}
38913695Ssam 
39013695Ssam 			redir = '\0';
39113695Ssam 			continue;
39213695Ssam 		}
39313695Ssam 
39413695Ssam 		if (strcmp(syspart, xsys) != SAME) {
39513695Ssam 			/* generate remote receives */
39613695Ssam 			gename(DATAPRE, syspart, 'R', dfile);
39713695Ssam 			strcpy(tfile, dfile);
39813695Ssam 			tfile[0] = CMDPRE;
39913695Ssam 			fpd = ufopen(dfile, "w");
40033965Srick 			if (fpd == NULL) {
40133965Srick 				syslog(LOG_WARNING, "fopen(%s) failed: %m",
40233965Srick 					dfile);
40333965Srick 				cleanup(1);
40433965Srick 			}
40513695Ssam 			gename(DATAPRE, local, 'T', t2file);
40613695Ssam 			GENRCV(fpd, rest, t2file, User);
40713695Ssam 			fclose(fpd);
40813695Ssam 			GENSEND(fpc, dfile, tfile, User, "", dfile);
40913695Ssam 			cflag++;
41013695Ssam 			if (redir == '<') {
41113695Ssam 				fprintf(fprx, "%c %s\n", X_RQDFILE, t2file);
41213695Ssam 				fprintf(fprx, "%c %s\n", X_STDIN, t2file);
41318627Sralph 			} else {
41413695Ssam 				fprintf(fprx, "%c %s %s\n", X_RQDFILE, t2file,
41513695Ssam 				  lastpart(rest));
41613695Ssam 				APPCMD(lastpart(rest));
41713695Ssam 			}
41813695Ssam 			redir = '\0';
41913695Ssam 			continue;
42013695Ssam 		}
42113695Ssam 
42213695Ssam 		/* file on remote system */
42313695Ssam 		if (rest[0] != '~')
42413695Ssam 			if (ckexpf(rest))
425*34674Srick 				cleanup(EX_CANTCREAT);
42613695Ssam 		if (redir == '<')
42713695Ssam 			fprintf(fprx, "%c %s\n", X_STDIN, rest);
42813695Ssam 		else
42913695Ssam 			APPCMD(rest);
43013695Ssam 		redir = '\0';
43113695Ssam 		continue;
43213695Ssam 
43313695Ssam 	}
43417845Sralph 	/*
43517845Sralph 	 * clean up trailing ' ' in command.
43617845Sralph 	 */
43717845Sralph 	if (cmdp > cmd && cmdp[0] == '\0' && cmdp[-1] == ' ')
43817845Sralph 		*--cmdp = '\0';
43917845Sralph 	/* block multi-hop uux, which doesn't work */
44017845Sralph 	for (ap = cmd; *ap && *ap != ' '; ap++)
44117845Sralph 		if (*ap == '!') {
44217845Sralph 			fprintf(stderr, "uux handles only adjacent sites.\n");
44317845Sralph 			fprintf(stderr, "Try uusend for multi-hop delivery.\n");
444*34674Srick 			cleanup(EX_USAGE);
44517845Sralph 		}
44613695Ssam 
44713695Ssam 	fprintf(fprx, "%c %s\n", X_CMD, cmd);
44825967Sbloom 	if (ferror(fprx)) {
44925967Sbloom 		logent(cmd, "COULD NOT QUEUE XQT");
450*34674Srick 		cleanup(EX_IOERR);
45125967Sbloom 	} else
45225967Sbloom 		logent(cmd, "XQT QUE'D");
45313695Ssam 	fclose(fprx);
45413695Ssam 
45533578Srick 	if (size > 0 && Gradedelta > 0) {
45633578Srick 		DEBUG (4, "Grade changed from %c ", Grade);
45733578Srick 		Grade += size/Gradedelta;
45833578Srick 		if (Grade > 'z')
45933578Srick 			Grade = 'z';
46033578Srick 		DEBUG(4, "to %c\n", Grade);
46133578Srick 	}
46217845Sralph 	gename(XQTPRE, local, Grade, tfile);
46313695Ssam 	if (strcmp(xsys, local) == SAME) {
46413695Ssam 		/* rti!trt: xmv() works across filesystems, link(II) doesnt */
46513695Ssam 		xmv(rxfile, tfile);
46613695Ssam 		if (startjob)
46713695Ssam 			if (rflag)
46813695Ssam 				xuucico(xsys);
46913695Ssam 			else
47013695Ssam 				xuuxqt();
47113695Ssam 	}
47213695Ssam 	else {
47313695Ssam 		GENSEND(fpc, rxfile, tfile, User, "", rxfile);
47413695Ssam 		cflag++;
47513695Ssam 	}
47613695Ssam 
47725967Sbloom 	if (ferror(fpc))
478*34674Srick 		cleanup(EX_IOERR);
47913695Ssam 	fclose(fpc);
48013695Ssam 	if (cflag) {
48113695Ssam 		gename(CMDPRE, xsys, Grade, cfile);
48213695Ssam 		/* rti!trt: use xmv() rather than link(II) */
48313695Ssam 		xmv(tcfile, cfile);
48413695Ssam 		if (startjob)
48513695Ssam 			xuucico(xsys);
48613695Ssam 		cleanup(0);
48713695Ssam 	}
48813695Ssam 	else
48913695Ssam 		unlink(subfile(tcfile));
49018627Sralph 	exit(0);
49113695Ssam }
49213695Ssam 
49313695Ssam #define FTABSIZE 30
49413695Ssam char Fname[FTABSIZE][NAMESIZE];
49513695Ssam int Fnamect = 0;
49613695Ssam 
49717845Sralph /*
49817845Sralph  *	cleanup and unlink if error
49913695Ssam  *
50013695Ssam  *	return - none - do exit()
50113695Ssam  */
50213695Ssam 
50313695Ssam cleanup(code)
50413695Ssam int code;
50513695Ssam {
50613695Ssam 	int i;
50713695Ssam 
50813695Ssam 	logcls();
50913695Ssam 	rmlock(CNULL);
51013695Ssam 	if (code) {
51113695Ssam 		for (i = 0; i < Fnamect; i++)
51213695Ssam 			unlink(subfile(Fname[i]));
51313695Ssam 		fprintf(stderr, "uux failed. code %d\n", code);
51413695Ssam 	}
51513695Ssam 	DEBUG(1, "exit code %d\n", code);
51613695Ssam 	exit(code);
51713695Ssam }
51813695Ssam 
51917845Sralph /*
52017845Sralph  *	open file and record name
52113695Ssam  *
52213695Ssam  *	return file pointer.
52313695Ssam  */
52413695Ssam 
52513695Ssam FILE *ufopen(file, mode)
52613695Ssam char *file, *mode;
52713695Ssam {
52813695Ssam 	if (Fnamect < FTABSIZE)
52913695Ssam 		strcpy(Fname[Fnamect++], file);
53013695Ssam 	else
53113695Ssam 		logent("Fname", "TABLE OVERFLOW");
53217845Sralph 	return fopen(subfile(file), mode);
53313695Ssam }
53417845Sralph #ifdef	VMS
53517845Sralph /*
53617845Sralph  * EUNICE bug:
53717845Sralph  *	quotes are not stripped from DCL.  Do it here.
53817845Sralph  *	Note if we are running under Unix shell we don't
53917845Sralph  *	do the right thing.
54017845Sralph  */
54117845Sralph arg_fix(argc, argv)
54217845Sralph char **argv;
54317845Sralph {
54417845Sralph 	register char *cp, *tp;
54517845Sralph 
54617845Sralph 	for (; argc > 0; --argc, argv++) {
54717845Sralph 		cp = *argv;
54817845Sralph 		if (cp == (char *)0 || *cp++ != '"')
54917845Sralph 			continue;
55017845Sralph 		tp = cp;
55117845Sralph 		while (*tp++) ;
55217845Sralph 		tp -= 2;
55317845Sralph 		if (*tp == '"') {
55417845Sralph 			*tp = '\0';
55517845Sralph 			*argv = cp;
55617845Sralph 		}
55717845Sralph 	}
55817845Sralph }
55917845Sralph #endif VMS
56025146Sbloom 
56125146Sbloom /*
56225146Sbloom  *	split into system and file part
56325146Sbloom  *
56425146Sbloom  *	return codes:
56525146Sbloom  *		NOSYSPART
56625146Sbloom  *		HASSYSPART
56725146Sbloom  */
56825146Sbloom 
56925146Sbloom split(name, sys, rest)
57025146Sbloom register char *name, *rest;
57125146Sbloom char *sys;
57225146Sbloom {
57325146Sbloom 	register char *c;
57425146Sbloom 
57525146Sbloom 	if (*name == LQUOTE) {
57625146Sbloom 		if ((c = index(name + 1, RQUOTE)) != NULL) {
57725146Sbloom 		/* strip off quotes */
57825146Sbloom 			name++;
57925146Sbloom 			while (c != name)
58025146Sbloom 				*rest++ = *name++;
58125146Sbloom 			*rest = '\0';
58225146Sbloom 			*sys = '\0';
58325146Sbloom 			return NOSYSPART;
58425146Sbloom 		}
58525146Sbloom 	}
58625146Sbloom 
58725146Sbloom 	if ((c = index(name, '!')) == NULL) {
58825146Sbloom 		strcpy(rest, name);
58925146Sbloom 		*sys = '\0';
59025146Sbloom 		return NOSYSPART;
59125146Sbloom 	}
59225146Sbloom 
59325146Sbloom 	*c++ = '\0';
59425146Sbloom 	strncpy(sys, name, MAXBASENAME);
59525146Sbloom 	sys[MAXBASENAME] = '\0';
59625146Sbloom 
59725146Sbloom 	strcpy(rest, c);
59825146Sbloom 	return HASSYSPART;
59925146Sbloom }
600