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