xref: /csrg-svn/usr.bin/uucp/libuu/subdir.c (revision 13670)
1*13670Ssam #ifndef lint
2*13670Ssam static char sccsid[] = "@(#)subdir.c	5.1 (Berkeley) 07/02/83";
3*13670Ssam #endif
4*13670Ssam 
5*13670Ssam #include "uucp.h"
6*13670Ssam #ifdef	UUDIR
7*13670Ssam /*
8*13670Ssam  * By Tom Truscott, March 1983
9*13670Ssam  * THIS VERSION OF SYSKLUDGE IS FOR USE ONLY
10*13670Ssam  * WITH THE 'UUDIR' VERSION OF UUCP.
11*13670Ssam  *
12*13670Ssam  * There once was a separate 'uudir' package to retrofit
13*13670Ssam  * versions of uucp, but that is no longer recommended.
14*13670Ssam  *
15*13670Ssam  * Prefix table.
16*13670Ssam  * If a prefix is "abc", for example,
17*13670Ssam  * then any file Spool/abc... is mapped to Spool/abc/abc... .
18*13670Ssam  * The first prefix found is used, so D.foo should preceed D. in table.
19*13670Ssam  *
20*13670Ssam  * Each prefix must be a subdirectory of Spool, owned by uucp!
21*13670Ssam  * Remember: use cron to uuclean these directories daily,
22*13670Ssam  * and check them manual every now and then.  Beware complacency!
23*13670Ssam  */
24*13670Ssam 
25*13670Ssam static char *prefix[] = {
26*13670Ssam 	DLocalX,	/* Outbound 'xqt' request files */
27*13670Ssam 	DLocal,		/* Outbound data files */
28*13670Ssam 	"D.",		/* Other "D." files (remember the "."!) */
29*13670Ssam 	"C.",		/* "C." subdirectory */
30*13670Ssam 	"X.",		/* "X." subdirectory */
31*13670Ssam 	"TM.",		/* Temporaries for inbound files */
32*13670Ssam 	0
33*13670Ssam };
34*13670Ssam 
35*13670Ssam /*
36*13670Ssam  * filename mapping kludges to put uucp work files in other directories.
37*13670Ssam  */
38*13670Ssam 
39*13670Ssam #define	BUFLEN	50
40*13670Ssam /* assert(strlen(Spool)+1+14+1+14 <= BUFLEN) */
41*13670Ssam 
42*13670Ssam static	char fn1[BUFLEN], fn2[BUFLEN];	/* remapped filename areas */
43*13670Ssam static	int	inspool;		/* true iff working dir is Spool */
44*13670Ssam 
45*13670Ssam /*
46*13670Ssam  * return (possibly) remapped string s
47*13670Ssam  */
48*13670Ssam char *
49*13670Ssam SubFile(as)
50*13670Ssam char *as;
51*13670Ssam {
52*13670Ssam 	register char *s, **p;
53*13670Ssam 	register int n;
54*13670Ssam 	static char *tptr = NULL;
55*13670Ssam 
56*13670Ssam 	/* Alternate buffers so "link(subfile(a), subfile(b))" works */
57*13670Ssam 	if (tptr != fn1)
58*13670Ssam 		tptr = fn1;
59*13670Ssam 	else
60*13670Ssam 		tptr = fn2;
61*13670Ssam 
62*13670Ssam 	s = as;
63*13670Ssam 	tptr[0] = '\0';
64*13670Ssam 
65*13670Ssam 	/* if s begins with Spool/, copy that to tptr and advance s */
66*13670Ssam 	if (strncmp(s, Spool, n = strlen(Spool)) == 0 && s[n] == '/') {
67*13670Ssam 		if (!inspool) {
68*13670Ssam 			strcpy(tptr, Spool);
69*13670Ssam 			strcat(tptr, "/");
70*13670Ssam 		}
71*13670Ssam 		s += n + 1;
72*13670Ssam 	}
73*13670Ssam 	else
74*13670Ssam 		if (!inspool)
75*13670Ssam 			return(as);
76*13670Ssam 
77*13670Ssam 	/* look for first prefix which matches, and make subdirectory */
78*13670Ssam 	for (p = &prefix[0]; *p; p++) {
79*13670Ssam 		if (strncmp(s, *p, n = strlen(*p))==0 && s[n] && s[n] != '/') {
80*13670Ssam 			strcat(tptr, *p);
81*13670Ssam 			strcat(tptr, "/");
82*13670Ssam 			strcat(tptr, s);
83*13670Ssam 			return(tptr);
84*13670Ssam 		}
85*13670Ssam 	}
86*13670Ssam 	return(as);
87*13670Ssam }
88*13670Ssam 
89*13670Ssam /*
90*13670Ssam  * save away filename
91*13670Ssam  */
92*13670Ssam SubChDir(s)
93*13670Ssam register char *s;
94*13670Ssam {
95*13670Ssam 	inspool = (strcmp(s, Spool) == 0);
96*13670Ssam 	return(chdir(s));
97*13670Ssam }
98*13670Ssam 
99*13670Ssam /*
100*13670Ssam  * return possibly corrected directory for searching
101*13670Ssam  */
102*13670Ssam char *
103*13670Ssam SubDir(d, pre)
104*13670Ssam register char *d, pre;
105*13670Ssam {
106*13670Ssam 	if (strcmp(d, Spool) == 0)
107*13670Ssam 		if (pre == CMDPRE)
108*13670Ssam 			return("/usr/spool/uucp/C.");
109*13670Ssam 		else if (pre == XQTPRE)
110*13670Ssam 			return("/usr/spool/uucp/X.");
111*13670Ssam 	return(d);
112*13670Ssam }
113*13670Ssam #else
114*13670Ssam static int subdir_here;		/* quiet 'ranlib' command */
115*13670Ssam #endif
116