xref: /titanic_54/usr/src/cmd/bnu/anlwrk.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:anlwrk.c 2.6 */
27*7c478bd9Sstevel@tonic-gate /*
28*7c478bd9Sstevel@tonic-gate 	This module contains routines that find C. files
29*7c478bd9Sstevel@tonic-gate 	in a system spool directory, return the next C. file
30*7c478bd9Sstevel@tonic-gate 	to process, and break up the C. line into arguments
31*7c478bd9Sstevel@tonic-gate 	for processing.
32*7c478bd9Sstevel@tonic-gate */
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #include "uucp.h"
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #define BOOKMARK_PRE	'A'
37*7c478bd9Sstevel@tonic-gate #define CLEAN_RETURN(fp) {\
38*7c478bd9Sstevel@tonic-gate 	if (fp != NULL) \
39*7c478bd9Sstevel@tonic-gate 		(void) fclose(fp); \
40*7c478bd9Sstevel@tonic-gate 	fp = NULL; \
41*7c478bd9Sstevel@tonic-gate 	return(0); \
42*7c478bd9Sstevel@tonic-gate 	/* NOTREACHED */ \
43*7c478bd9Sstevel@tonic-gate }
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /* C.princetN0026 - ('C' + '.') - "princet" */
46*7c478bd9Sstevel@tonic-gate #define SUFSIZE	(MAXBASENAME - 2 - SYSNSIZE)
47*7c478bd9Sstevel@tonic-gate #define LLEN 50
48*7c478bd9Sstevel@tonic-gate #define MAXRQST 250
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate static void insert();
51*7c478bd9Sstevel@tonic-gate static int  anlwrk(), bldflst();
52*7c478bd9Sstevel@tonic-gate extern int  iswrk(), gtwvec(), gnamef();
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate static char  Filent[LLEN][NAMESIZE]; /* array of C. file names (text)        */
55*7c478bd9Sstevel@tonic-gate static char *Fptr[LLEN];	     /* pointers to names in Filent          */
56*7c478bd9Sstevel@tonic-gate static short Nnext;		     /* index of next C. file in Fptr list   */
57*7c478bd9Sstevel@tonic-gate static short Nfiles = 0;	     /* Number of files in Filent	     */
58*7c478bd9Sstevel@tonic-gate 
59*7c478bd9Sstevel@tonic-gate /*
60*7c478bd9Sstevel@tonic-gate  * read a line from the workfile (C.file)
61*7c478bd9Sstevel@tonic-gate  *	file	-> work file  (Input/Output)  made '\0' after work completion
62*7c478bd9Sstevel@tonic-gate  *	wvec	-> address of array to return arguments (Output)
63*7c478bd9Sstevel@tonic-gate  *	wcount	-> maximum # of arguments to return in wvec
64*7c478bd9Sstevel@tonic-gate  *		NOTE: wvec should be large enough to accept wcount + 1 pointers
65*7c478bd9Sstevel@tonic-gate  *		since NULL is inserted after last item.
66*7c478bd9Sstevel@tonic-gate  * returns:
67*7c478bd9Sstevel@tonic-gate  *	0	   ->  no more work in this file
68*7c478bd9Sstevel@tonic-gate  *	positive # -> number of arguments
69*7c478bd9Sstevel@tonic-gate  */
70*7c478bd9Sstevel@tonic-gate static int
71*7c478bd9Sstevel@tonic-gate anlwrk(file, wvec, wcount)
72*7c478bd9Sstevel@tonic-gate char *file, **wvec;
73*7c478bd9Sstevel@tonic-gate {
74*7c478bd9Sstevel@tonic-gate 	register i;
75*7c478bd9Sstevel@tonic-gate 	register FILE *p_bookmark;    /* pointer to afile 		    */
76*7c478bd9Sstevel@tonic-gate 	static   FILE *fp = NULL;    /* currently opened C. file pointer    */
77*7c478bd9Sstevel@tonic-gate 	static char afile[NAMESIZE]; /* file with line count for book marks */
78*7c478bd9Sstevel@tonic-gate 	static char str[MAXRQST];    /* the string which  wvec points to    */
79*7c478bd9Sstevel@tonic-gate 	static short acount;
80*7c478bd9Sstevel@tonic-gate 	struct stat stbuf;
81*7c478bd9Sstevel@tonic-gate 	int	nargs;		/* return value == # args in the line */
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate 	if (file[0] == '\0') {
84*7c478bd9Sstevel@tonic-gate 		if (fp != NULL)
85*7c478bd9Sstevel@tonic-gate 			errent("anlwrk",
86*7c478bd9Sstevel@tonic-gate 			   "attempt made to use old workfile was thwarted", 0,
87*7c478bd9Sstevel@tonic-gate 			   __FILE__, __LINE__);
88*7c478bd9Sstevel@tonic-gate 		CLEAN_RETURN(fp);
89*7c478bd9Sstevel@tonic-gate 		/* NOTREACHED */
90*7c478bd9Sstevel@tonic-gate 	}
91*7c478bd9Sstevel@tonic-gate 	if (fp == NULL) {
92*7c478bd9Sstevel@tonic-gate 		fp = fopen(file, "r");
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 		if (fp == NULL){ /* can't open C. file! */
95*7c478bd9Sstevel@tonic-gate 			errent(Ct_OPEN,file,errno, __FILE__, __LINE__);
96*7c478bd9Sstevel@tonic-gate 			/* this may not work, but we'll try it */
97*7c478bd9Sstevel@tonic-gate 			/* It will fail if the C. name is more than */
98*7c478bd9Sstevel@tonic-gate 			/* the standard 14 characters - if this is the */
99*7c478bd9Sstevel@tonic-gate 			/* tocorrupt will exit with ASSERT */
100*7c478bd9Sstevel@tonic-gate 			toCorrupt(file);
101*7c478bd9Sstevel@tonic-gate 			return(0);
102*7c478bd9Sstevel@tonic-gate 		}
103*7c478bd9Sstevel@tonic-gate 		(void) fstat(fileno(fp), &stbuf);
104*7c478bd9Sstevel@tonic-gate 		Nstat.t_qtime = stbuf.st_mtime;
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate 		(void) strncpy(afile, BASENAME(file, '/'), NAMESIZE);
107*7c478bd9Sstevel@tonic-gate 		afile[NAMESIZE-1] = NULLCHAR;
108*7c478bd9Sstevel@tonic-gate 		*afile = BOOKMARK_PRE; /* make up name by replacing C with A */
109*7c478bd9Sstevel@tonic-gate 		acount = 0;
110*7c478bd9Sstevel@tonic-gate 		p_bookmark = fopen(afile, "r");
111*7c478bd9Sstevel@tonic-gate 		if (p_bookmark != NULL) {
112*7c478bd9Sstevel@tonic-gate 			/* get count of already completed work */
113*7c478bd9Sstevel@tonic-gate 			i = fscanf(p_bookmark, "%hd", &acount);
114*7c478bd9Sstevel@tonic-gate 			(void) fclose(p_bookmark);
115*7c478bd9Sstevel@tonic-gate 			if (i <= 0)
116*7c478bd9Sstevel@tonic-gate 				acount = 0;
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate 			/* skip lines which have already been processed */
119*7c478bd9Sstevel@tonic-gate 			for (i = 0; i < acount; i++) {
120*7c478bd9Sstevel@tonic-gate 				if (fgets(str, MAXRQST, fp) == NULL)
121*7c478bd9Sstevel@tonic-gate 					break;
122*7c478bd9Sstevel@tonic-gate 			}
123*7c478bd9Sstevel@tonic-gate 		}
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	}
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate 	if (fgets(str, MAXRQST, fp) == NULL) {
128*7c478bd9Sstevel@tonic-gate 		ASSERT(unlink(file) == 0, Ct_UNLINK, file, errno);
129*7c478bd9Sstevel@tonic-gate 		(void) unlink(afile);
130*7c478bd9Sstevel@tonic-gate 		DEBUG(4,"Finished Processing file: %s\n",file);
131*7c478bd9Sstevel@tonic-gate 		*file = '\0';
132*7c478bd9Sstevel@tonic-gate 		CLEAN_RETURN(fp);
133*7c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
134*7c478bd9Sstevel@tonic-gate 	}
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 	nargs = getargs(str, wvec, wcount);
137*7c478bd9Sstevel@tonic-gate 
138*7c478bd9Sstevel@tonic-gate 	/* sanity checks for C. file */
139*7c478bd9Sstevel@tonic-gate 	if ((str[0] != 'R' && str[0] != 'S')	/* legal wrktypes are R and S */
140*7c478bd9Sstevel@tonic-gate 	 || (str[0] == 'R' && nargs < 6)	/* R lines need >= 6 entries */
141*7c478bd9Sstevel@tonic-gate 	 || (str[0] == 'S' && nargs < 7)) {	/* S lines need >= 7 entries */
142*7c478bd9Sstevel@tonic-gate 		/* bad C. file - stash it */
143*7c478bd9Sstevel@tonic-gate 		toCorrupt(file);
144*7c478bd9Sstevel@tonic-gate 		(void) unlink(afile);
145*7c478bd9Sstevel@tonic-gate 		*file = '\0';
146*7c478bd9Sstevel@tonic-gate 		CLEAN_RETURN(fp);
147*7c478bd9Sstevel@tonic-gate 		/*NOTREACHED*/
148*7c478bd9Sstevel@tonic-gate 	}
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate 	p_bookmark = fopen(afile, "w"); /* update bookmark file */
151*7c478bd9Sstevel@tonic-gate 	if (p_bookmark == NULL)
152*7c478bd9Sstevel@tonic-gate 	    errent(Ct_OPEN, afile, errno, __FILE__, __LINE__);
153*7c478bd9Sstevel@tonic-gate 	else {
154*7c478bd9Sstevel@tonic-gate 	    chmod(afile, CFILEMODE);
155*7c478bd9Sstevel@tonic-gate 	    (void) fprintf(p_bookmark, "%d", acount);
156*7c478bd9Sstevel@tonic-gate 	    (void) fclose(p_bookmark);
157*7c478bd9Sstevel@tonic-gate 	}
158*7c478bd9Sstevel@tonic-gate 	acount++;
159*7c478bd9Sstevel@tonic-gate 	return(nargs);
160*7c478bd9Sstevel@tonic-gate }
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate /*
163*7c478bd9Sstevel@tonic-gate  * Check the list of work files (C.sys).
164*7c478bd9Sstevel@tonic-gate  * If it is empty or the present work is exhausted, it
165*7c478bd9Sstevel@tonic-gate  * will call bldflst to generate a new list.
166*7c478bd9Sstevel@tonic-gate  *
167*7c478bd9Sstevel@tonic-gate  * If there are no more jobs in the current job grade,
168*7c478bd9Sstevel@tonic-gate  * it will call findgrade to get the new job grade to process.
169*7c478bd9Sstevel@tonic-gate  *
170*7c478bd9Sstevel@tonic-gate  *	file	-> address of array to return full pathname in
171*7c478bd9Sstevel@tonic-gate  * returns:
172*7c478bd9Sstevel@tonic-gate  *	0	-> no more work (or some error)
173*7c478bd9Sstevel@tonic-gate  *	1	-> there is work
174*7c478bd9Sstevel@tonic-gate  */
175*7c478bd9Sstevel@tonic-gate extern int
176*7c478bd9Sstevel@tonic-gate iswrk(file)
177*7c478bd9Sstevel@tonic-gate char *file;
178*7c478bd9Sstevel@tonic-gate {
179*7c478bd9Sstevel@tonic-gate 	char newspool[MAXFULLNAME];
180*7c478bd9Sstevel@tonic-gate 	char lockname[MAXFULLNAME];
181*7c478bd9Sstevel@tonic-gate 	char gradedir[2*MAXBASENAME];
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate 	if (Nfiles == 0) {
184*7c478bd9Sstevel@tonic-gate 		/* If Role is MASTER and JobGrade is null, then
185*7c478bd9Sstevel@tonic-gate 		 * there is no work for the remote.
186*7c478bd9Sstevel@tonic-gate 		 *
187*7c478bd9Sstevel@tonic-gate 		 * In the case of uucico slave, the job grade
188*7c478bd9Sstevel@tonic-gate 		 * to process should be determined before building
189*7c478bd9Sstevel@tonic-gate 		 * the work list.
190*7c478bd9Sstevel@tonic-gate 		 */
191*7c478bd9Sstevel@tonic-gate 		if (Role == MASTER) {
192*7c478bd9Sstevel@tonic-gate 		    if (*JobGrade == NULLCHAR)
193*7c478bd9Sstevel@tonic-gate 			return(0);
194*7c478bd9Sstevel@tonic-gate 
195*7c478bd9Sstevel@tonic-gate 		    if (bldflst() != 0) {
196*7c478bd9Sstevel@tonic-gate 			(void) sprintf(file, "%s/%s", RemSpool, Fptr[Nnext]);
197*7c478bd9Sstevel@tonic-gate 			Nfiles--;
198*7c478bd9Sstevel@tonic-gate 			Nnext++;
199*7c478bd9Sstevel@tonic-gate 			return(1);
200*7c478bd9Sstevel@tonic-gate 		    }
201*7c478bd9Sstevel@tonic-gate 		    (void) sprintf(lockname, "%.*s.%s", SYSNSIZE, Rmtname, JobGrade);
202*7c478bd9Sstevel@tonic-gate 		    delock(LOCKPRE, lockname);
203*7c478bd9Sstevel@tonic-gate 		} else {
204*7c478bd9Sstevel@tonic-gate 		    (void) sprintf(lockname, "%ld", (long) getpid());
205*7c478bd9Sstevel@tonic-gate 		    delock(LOCKPRE, lockname);
206*7c478bd9Sstevel@tonic-gate 		}
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate 		(void) sprintf(newspool, "%s/%s", SPOOL, Rmtname);
209*7c478bd9Sstevel@tonic-gate 		ASSERT(chdir(newspool) == 0, Ct_CHDIR, newspool, errno);
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate 		findgrade(newspool, JobGrade);
212*7c478bd9Sstevel@tonic-gate 		DEBUG(4, "Job grade to process - %s\n", JobGrade);
213*7c478bd9Sstevel@tonic-gate 		if (*JobGrade == NULLCHAR)
214*7c478bd9Sstevel@tonic-gate 		    return(0);
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate 		(void) sprintf(lockname, "%.*s.%s", SYSNSIZE, Rmtname, JobGrade);
217*7c478bd9Sstevel@tonic-gate 		(void) umlock(LOCKPRE, lockname);
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate 		/* Make the new job grade directory the working directory
220*7c478bd9Sstevel@tonic-gate 		 * and set RemSpool.
221*7c478bd9Sstevel@tonic-gate 		 */
222*7c478bd9Sstevel@tonic-gate 		(void) sprintf(gradedir, "%s/%s", Rmtname, JobGrade);
223*7c478bd9Sstevel@tonic-gate 		chremdir(gradedir);
224*7c478bd9Sstevel@tonic-gate 		bldflst();
225*7c478bd9Sstevel@tonic-gate 	}
226*7c478bd9Sstevel@tonic-gate 
227*7c478bd9Sstevel@tonic-gate 	(void) sprintf(file, "%s/%s", RemSpool, Fptr[Nnext]);
228*7c478bd9Sstevel@tonic-gate 	Nfiles--;
229*7c478bd9Sstevel@tonic-gate 	Nnext++;
230*7c478bd9Sstevel@tonic-gate 	return(1);
231*7c478bd9Sstevel@tonic-gate }
232*7c478bd9Sstevel@tonic-gate 
233*7c478bd9Sstevel@tonic-gate 
234*7c478bd9Sstevel@tonic-gate /*
235*7c478bd9Sstevel@tonic-gate  * build list of work files for given system using an insertion sort
236*7c478bd9Sstevel@tonic-gate  * Nfiles, Nnext, RemSpool and Rmtname are global
237*7c478bd9Sstevel@tonic-gate  *
238*7c478bd9Sstevel@tonic-gate  * return:
239*7c478bd9Sstevel@tonic-gate  *	number of C. files in list - (Nfiles)
240*7c478bd9Sstevel@tonic-gate  */
241*7c478bd9Sstevel@tonic-gate static int
242*7c478bd9Sstevel@tonic-gate bldflst()
243*7c478bd9Sstevel@tonic-gate {
244*7c478bd9Sstevel@tonic-gate 	register DIR *pdir;
245*7c478bd9Sstevel@tonic-gate 	char filename[NAMESIZE];
246*7c478bd9Sstevel@tonic-gate 	char prefix[SYSNSIZE+3];
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate 	Nnext = Nfiles = 0;
249*7c478bd9Sstevel@tonic-gate 	if ((pdir = opendir(RemSpool)) == NULL)
250*7c478bd9Sstevel@tonic-gate 		return(0);
251*7c478bd9Sstevel@tonic-gate 
252*7c478bd9Sstevel@tonic-gate 	(void) sprintf(prefix, "C.%.*s", SYSNSIZE, Rmtname);
253*7c478bd9Sstevel@tonic-gate 	while (gnamef(pdir, filename) ) {
254*7c478bd9Sstevel@tonic-gate 		if (!PREFIX(prefix, filename))
255*7c478bd9Sstevel@tonic-gate 		    	continue;
256*7c478bd9Sstevel@tonic-gate 		if ((strlen(filename)-strlen(prefix)) != SUFSIZE) {
257*7c478bd9Sstevel@tonic-gate 			errent("bldflst: Funny filename", filename, 0,
258*7c478bd9Sstevel@tonic-gate 			   __FILE__, __LINE__);
259*7c478bd9Sstevel@tonic-gate 			continue;
260*7c478bd9Sstevel@tonic-gate 		}
261*7c478bd9Sstevel@tonic-gate 		insert(filename);
262*7c478bd9Sstevel@tonic-gate 	}
263*7c478bd9Sstevel@tonic-gate 	closedir(pdir);
264*7c478bd9Sstevel@tonic-gate 	return(Nfiles);
265*7c478bd9Sstevel@tonic-gate }
266*7c478bd9Sstevel@tonic-gate 
267*7c478bd9Sstevel@tonic-gate /*
268*7c478bd9Sstevel@tonic-gate  * get work return
269*7c478bd9Sstevel@tonic-gate  *	file	-> place to deposit file name
270*7c478bd9Sstevel@tonic-gate  *	wrkvec	-> array to return arguments
271*7c478bd9Sstevel@tonic-gate  *	wcount	-> max number of args for wrkvec
272*7c478bd9Sstevel@tonic-gate  * returns:
273*7c478bd9Sstevel@tonic-gate  *	nargs  	->  number of arguments
274*7c478bd9Sstevel@tonic-gate  *	0 	->  no arguments - fail
275*7c478bd9Sstevel@tonic-gate  */
276*7c478bd9Sstevel@tonic-gate extern int
277*7c478bd9Sstevel@tonic-gate gtwvec(file, wrkvec, wcount)
278*7c478bd9Sstevel@tonic-gate char *file, **wrkvec;
279*7c478bd9Sstevel@tonic-gate {
280*7c478bd9Sstevel@tonic-gate 	register int nargs;
281*7c478bd9Sstevel@tonic-gate 
282*7c478bd9Sstevel@tonic-gate 	DEBUG(7, "gtwvec: dir %s\n", RemSpool);
283*7c478bd9Sstevel@tonic-gate 	while ((nargs = anlwrk(file, wrkvec, wcount)) == 0) {
284*7c478bd9Sstevel@tonic-gate 		if (!iswrk(file))
285*7c478bd9Sstevel@tonic-gate 			return(0);
286*7c478bd9Sstevel@tonic-gate 	}
287*7c478bd9Sstevel@tonic-gate 	DEBUG(7, "        return - %d\n", nargs);
288*7c478bd9Sstevel@tonic-gate 	return(nargs);
289*7c478bd9Sstevel@tonic-gate }
290*7c478bd9Sstevel@tonic-gate 
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate /*
293*7c478bd9Sstevel@tonic-gate  * insert - insert file name in sorted list
294*7c478bd9Sstevel@tonic-gate  * return - none
295*7c478bd9Sstevel@tonic-gate  */
296*7c478bd9Sstevel@tonic-gate static void
297*7c478bd9Sstevel@tonic-gate insert(file)
298*7c478bd9Sstevel@tonic-gate char *file;
299*7c478bd9Sstevel@tonic-gate {
300*7c478bd9Sstevel@tonic-gate 	register i, j;
301*7c478bd9Sstevel@tonic-gate 	register char *p;
302*7c478bd9Sstevel@tonic-gate 
303*7c478bd9Sstevel@tonic-gate 	DEBUG(7, "insert(%s)  ", file);
304*7c478bd9Sstevel@tonic-gate 	for (i = Nfiles; i>0; i--) {
305*7c478bd9Sstevel@tonic-gate 	    if (strcmp(file, Fptr[i-1]) > 0)
306*7c478bd9Sstevel@tonic-gate 		break;
307*7c478bd9Sstevel@tonic-gate 	}
308*7c478bd9Sstevel@tonic-gate 	if (i == LLEN) /* if this is off the end get out */
309*7c478bd9Sstevel@tonic-gate 	    return;
310*7c478bd9Sstevel@tonic-gate 
311*7c478bd9Sstevel@tonic-gate 	/* get p (pointer) to where the text of name will go */
312*7c478bd9Sstevel@tonic-gate 	if (Nfiles == LLEN)	/* last possible entry */
313*7c478bd9Sstevel@tonic-gate 	    /* put in text of last and decrement Nfiles for make hole */
314*7c478bd9Sstevel@tonic-gate 	    p = strcpy(Fptr[--Nfiles], file);
315*7c478bd9Sstevel@tonic-gate 	else
316*7c478bd9Sstevel@tonic-gate 	    p = strcpy(Filent[Nfiles], file);	/* copy to next free  */
317*7c478bd9Sstevel@tonic-gate 
318*7c478bd9Sstevel@tonic-gate 	/* make a hole for new entry */
319*7c478bd9Sstevel@tonic-gate 	for (j = Nfiles; j >i; j--)
320*7c478bd9Sstevel@tonic-gate 	    Fptr[j] = Fptr[j-1];
321*7c478bd9Sstevel@tonic-gate 
322*7c478bd9Sstevel@tonic-gate 	DEBUG(7, "insert %s ", p);
323*7c478bd9Sstevel@tonic-gate 	DEBUG(7, "at %d\n", i);
324*7c478bd9Sstevel@tonic-gate 	Fptr[i] = p;
325*7c478bd9Sstevel@tonic-gate 	Nfiles++;
326*7c478bd9Sstevel@tonic-gate 	return;
327*7c478bd9Sstevel@tonic-gate }
328