xref: /titanic_44/usr/src/cmd/bnu/gtcfile.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate #ident	"%Z%%M%	%I%	%E% SMI"	/* from SVR4 bnu:gtcfile.c 2.5 */
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate #include "uucp.h"
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #define NCSAVE	30	/* no more than 30 saved C files, please */
31*7c478bd9Sstevel@tonic-gate static int ncsave;
32*7c478bd9Sstevel@tonic-gate static struct cs_struct csave[NCSAVE];
33*7c478bd9Sstevel@tonic-gate int Dfileused = FALSE;
34*7c478bd9Sstevel@tonic-gate static char jobid[NAMESIZE];
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate extern void wfcommit(), wfremove(), putdfiles();
37*7c478bd9Sstevel@tonic-gate extern int job_size(), fgrade(), retseq();
38*7c478bd9Sstevel@tonic-gate 
39*7c478bd9Sstevel@tonic-gate /*	commitall()
40*7c478bd9Sstevel@tonic-gate  *
41*7c478bd9Sstevel@tonic-gate  *	commit any and all saved C files
42*7c478bd9Sstevel@tonic-gate  *
43*7c478bd9Sstevel@tonic-gate  *	returns
44*7c478bd9Sstevel@tonic-gate  *		nothing
45*7c478bd9Sstevel@tonic-gate  */
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate void
commitall()48*7c478bd9Sstevel@tonic-gate commitall()
49*7c478bd9Sstevel@tonic-gate {
50*7c478bd9Sstevel@tonic-gate 	char sys[NAMESIZE+5];
51*7c478bd9Sstevel@tonic-gate 	char cmfile[NAMESIZE+5];
52*7c478bd9Sstevel@tonic-gate 	int i;
53*7c478bd9Sstevel@tonic-gate 	int n;
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < ncsave; i++) {
56*7c478bd9Sstevel@tonic-gate 		if (Sgrades) {
57*7c478bd9Sstevel@tonic-gate 			if ((job_size(&csave[i]) == FAIL) ||
58*7c478bd9Sstevel@tonic-gate 			    (fgrade(&csave[i]) == FAIL)) {
59*7c478bd9Sstevel@tonic-gate 				wfremove(csave[i].file);
60*7c478bd9Sstevel@tonic-gate 				continue;
61*7c478bd9Sstevel@tonic-gate 			}
62*7c478bd9Sstevel@tonic-gate 		}
63*7c478bd9Sstevel@tonic-gate 		else {
64*7c478bd9Sstevel@tonic-gate 			Dfileused = TRUE;
65*7c478bd9Sstevel@tonic-gate 			csave[i].grade = Grade;
66*7c478bd9Sstevel@tonic-gate 		}
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 		/* make new file name for for the job */
69*7c478bd9Sstevel@tonic-gate 
70*7c478bd9Sstevel@tonic-gate 		if (Sgrades) {
71*7c478bd9Sstevel@tonic-gate 			n = retseq(csave[i].sys);
72*7c478bd9Sstevel@tonic-gate 			(void) sprintf(cmfile, "%c.%.*s%c%.4x", *csave[i].file,
73*7c478bd9Sstevel@tonic-gate 				SYSNSIZE, csave[i].sys, csave[i].grade, n);
74*7c478bd9Sstevel@tonic-gate 		}
75*7c478bd9Sstevel@tonic-gate 		else
76*7c478bd9Sstevel@tonic-gate 			(void) strncpy(cmfile, csave[i].file, NAMESIZE-1);
77*7c478bd9Sstevel@tonic-gate 		cmfile[NAMESIZE-1] = '\0';
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate 		DEBUG(9, "User job queued to %c queue\n", csave[i].grade);
80*7c478bd9Sstevel@tonic-gate 		(void) sprintf(sys, "/%c", csave[i].grade);
81*7c478bd9Sstevel@tonic-gate 		(void) strcat(csave[i].sys, sys);
82*7c478bd9Sstevel@tonic-gate 		if (Dfileused) {
83*7c478bd9Sstevel@tonic-gate 			putdfiles(csave[i]);
84*7c478bd9Sstevel@tonic-gate 			Dfileused = FALSE;
85*7c478bd9Sstevel@tonic-gate 		}
86*7c478bd9Sstevel@tonic-gate 		wfcommit(csave[i].file, cmfile, csave[i].sys);
87*7c478bd9Sstevel@tonic-gate 		(void) strncpy(csave[i].file, cmfile, NAMESIZE);
88*7c478bd9Sstevel@tonic-gate 	}
89*7c478bd9Sstevel@tonic-gate 
90*7c478bd9Sstevel@tonic-gate 	ncsave = 0;
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate 	/* set real jobid */
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 	(void) strncpy(jobid, BASENAME(csave[0].file, '.'), NAMESIZE);
95*7c478bd9Sstevel@tonic-gate 	return;
96*7c478bd9Sstevel@tonic-gate }
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate /*
99*7c478bd9Sstevel@tonic-gate  *	gtcfile - copy into file the name of the saved C file for system sys
100*7c478bd9Sstevel@tonic-gate  *
101*7c478bd9Sstevel@tonic-gate  *	returns
102*7c478bd9Sstevel@tonic-gate  *		SUCCESS	-> found one
103*7c478bd9Sstevel@tonic-gate  *		FAIL	-> none saved
104*7c478bd9Sstevel@tonic-gate  *
105*7c478bd9Sstevel@tonic-gate  */
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate int
gtcfile(file,sys)108*7c478bd9Sstevel@tonic-gate gtcfile(file, sys)
109*7c478bd9Sstevel@tonic-gate char	*file, *sys;
110*7c478bd9Sstevel@tonic-gate {
111*7c478bd9Sstevel@tonic-gate 	register int	i;
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < ncsave; i++)
114*7c478bd9Sstevel@tonic-gate 		if (strncmp(sys, csave[i].sys, SYSNSIZE) == SAME) {
115*7c478bd9Sstevel@tonic-gate 			(void) strncpy(file, csave[i].file, NAMESIZE-1);
116*7c478bd9Sstevel@tonic-gate 			return(SUCCESS);
117*7c478bd9Sstevel@tonic-gate 		}
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate 	return(FAIL);
120*7c478bd9Sstevel@tonic-gate }
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate /*
123*7c478bd9Sstevel@tonic-gate  *	jid - returns the real job id of this uucp file transfer
124*7c478bd9Sstevel@tonic-gate  *
125*7c478bd9Sstevel@tonic-gate  *	returns
126*7c478bd9Sstevel@tonic-gate  *		jobid
127*7c478bd9Sstevel@tonic-gate  *
128*7c478bd9Sstevel@tonic-gate  */
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate char *
jid()131*7c478bd9Sstevel@tonic-gate jid()
132*7c478bd9Sstevel@tonic-gate {
133*7c478bd9Sstevel@tonic-gate 	return(jobid);
134*7c478bd9Sstevel@tonic-gate }
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate /*
137*7c478bd9Sstevel@tonic-gate  *	svcfile  - save the name of a C. file for system sys for re-using
138*7c478bd9Sstevel@tonic-gate  *	returns
139*7c478bd9Sstevel@tonic-gate  *		none
140*7c478bd9Sstevel@tonic-gate  */
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate void
svcfile(file,sys,grd)143*7c478bd9Sstevel@tonic-gate svcfile(file, sys, grd)
144*7c478bd9Sstevel@tonic-gate char	*file, *sys, *grd;
145*7c478bd9Sstevel@tonic-gate {
146*7c478bd9Sstevel@tonic-gate 	ASSERT(ncsave < NCSAVE, "TOO MANY SAVED C FILES", "", ncsave);
147*7c478bd9Sstevel@tonic-gate 	(void) strncpy(csave[ncsave].file, BASENAME(file, '/'), NAMESIZE-1);
148*7c478bd9Sstevel@tonic-gate 	(void) strncpy(csave[ncsave].sys, sys, NAMESIZE-1);
149*7c478bd9Sstevel@tonic-gate 	(void) strncpy (csave[ncsave].sgrade, grd, NAMESIZE-1);
150*7c478bd9Sstevel@tonic-gate 	ncsave++;
151*7c478bd9Sstevel@tonic-gate 	return;
152*7c478bd9Sstevel@tonic-gate }
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate void
wfabort()155*7c478bd9Sstevel@tonic-gate wfabort()
156*7c478bd9Sstevel@tonic-gate {
157*7c478bd9Sstevel@tonic-gate 	register int	i;
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < ncsave; i++)
160*7c478bd9Sstevel@tonic-gate 		wfremove(csave[i].file);
161*7c478bd9Sstevel@tonic-gate 	ncsave = 0;
162*7c478bd9Sstevel@tonic-gate 	return;
163*7c478bd9Sstevel@tonic-gate }
164*7c478bd9Sstevel@tonic-gate 
165*7c478bd9Sstevel@tonic-gate /*
166*7c478bd9Sstevel@tonic-gate  *	wfcommit - move wfile1 in current directory to SPOOL/sys/dir/wfile2
167*7c478bd9Sstevel@tonic-gate  *	return
168*7c478bd9Sstevel@tonic-gate  *		none
169*7c478bd9Sstevel@tonic-gate  */
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate void
wfcommit(wfile1,wfile2,sys)172*7c478bd9Sstevel@tonic-gate wfcommit(wfile1, wfile2, sys)
173*7c478bd9Sstevel@tonic-gate char	*wfile1, *wfile2, *sys;
174*7c478bd9Sstevel@tonic-gate {
175*7c478bd9Sstevel@tonic-gate 	char	cmitfile[MAXFULLNAME];
176*7c478bd9Sstevel@tonic-gate 	char	remote[NAMESIZE];
177*7c478bd9Sstevel@tonic-gate 	char	*fileBase;
178*7c478bd9Sstevel@tonic-gate 	char	*p;
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate 	/* make remote directory if it does not exist */
181*7c478bd9Sstevel@tonic-gate 
182*7c478bd9Sstevel@tonic-gate 	(void) strncpy(remote, sys, NAMESIZE);
183*7c478bd9Sstevel@tonic-gate 	if ((p = strchr(remote, '/')) != NULL) {
184*7c478bd9Sstevel@tonic-gate 		*p++ = '\0';
185*7c478bd9Sstevel@tonic-gate 
186*7c478bd9Sstevel@tonic-gate 		DEBUG(6, "create remote spool area %s\n", remote);
187*7c478bd9Sstevel@tonic-gate 		mkremdir(remote);
188*7c478bd9Sstevel@tonic-gate 	}
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate 	if (p != NULL)
191*7c478bd9Sstevel@tonic-gate 		DEBUG(6, "create service grade directory %s under remote spool\n", p);
192*7c478bd9Sstevel@tonic-gate 	else
193*7c478bd9Sstevel@tonic-gate 		DEBUG(6, "create remote spool area %s\n", sys);
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate 	mkremdir(sys);
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate 	DEBUG(6, "commit %s ", wfile1);
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate 	fileBase = BASENAME(wfile2, '/');
200*7c478bd9Sstevel@tonic-gate 	sprintf(cmitfile, "%s/%s", RemSpool, fileBase);
201*7c478bd9Sstevel@tonic-gate 	DEBUG(6, "to %s\n", cmitfile);
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate 	ASSERT(access(cmitfile, 0) != 0, Fl_EXISTS, cmitfile, 0);
204*7c478bd9Sstevel@tonic-gate 	ASSERT(xmv(wfile1, cmitfile) == 0, Ct_LINK, cmitfile, errno);
205*7c478bd9Sstevel@tonic-gate 	return;
206*7c478bd9Sstevel@tonic-gate }
207