1*48652Sbostic /*- 2*48652Sbostic * Copyright (c) 1985 The Regents of the University of California. 3*48652Sbostic * All rights reserved. 4*48652Sbostic * 5*48652Sbostic * %sccs.include.proprietary.c% 6*48652Sbostic */ 7*48652Sbostic 813670Ssam #ifndef lint 9*48652Sbostic static char sccsid[] = "@(#)subdir.c 5.6 (Berkeley) 04/24/91"; 10*48652Sbostic #endif /* not lint */ 1113670Ssam 1213670Ssam #include "uucp.h" 1323673Sbloom 1423673Sbloom /*LINTLIBRARY*/ 1523673Sbloom 1613670Ssam /* 1713670Ssam * By Tom Truscott, March 1983 1813670Ssam * 1913670Ssam * Prefix table. 2013670Ssam * If a prefix is "abc", for example, 2113670Ssam * then any file Spool/abc... is mapped to Spool/abc/abc... . 2213670Ssam * The first prefix found is used, so D.foo should preceed D. in table. 2313670Ssam * 2413670Ssam * Each prefix must be a subdirectory of Spool, owned by uucp! 2513670Ssam * Remember: use cron to uuclean these directories daily, 2618622Sralph * and check them manually every now and then. Beware complacency! 2713670Ssam */ 2813670Ssam 2923673Sbloom static char *dprefix[] = { 3013670Ssam DLocalX, /* Outbound 'xqt' request files */ 3113670Ssam DLocal, /* Outbound data files */ 3213670Ssam "D.", /* Other "D." files (remember the "."!) */ 3313670Ssam "C.", /* "C." subdirectory */ 3413670Ssam "X.", /* "X." subdirectory */ 3513670Ssam "TM.", /* Temporaries for inbound files */ 3613670Ssam 0 3713670Ssam }; 3813670Ssam 3913670Ssam /* 4013670Ssam * filename mapping kludges to put uucp work files in other directories. 4113670Ssam */ 4213670Ssam 4313670Ssam #define BUFLEN 50 4413670Ssam 4513670Ssam static char fn1[BUFLEN], fn2[BUFLEN]; /* remapped filename areas */ 4613670Ssam static int inspool; /* true iff working dir is Spool */ 4713670Ssam 4813670Ssam /* 4913670Ssam * return (possibly) remapped string s 5013670Ssam */ 5113670Ssam char * 5217838Sralph subfile(as) 5313670Ssam char *as; 5413670Ssam { 5513670Ssam register char *s, **p; 5613670Ssam register int n; 5713670Ssam static char *tptr = NULL; 5813670Ssam 5913670Ssam /* Alternate buffers so "link(subfile(a), subfile(b))" works */ 6013670Ssam if (tptr != fn1) 6113670Ssam tptr = fn1; 6213670Ssam else 6313670Ssam tptr = fn2; 6413670Ssam 6513670Ssam s = as; 6613670Ssam tptr[0] = '\0'; 6713670Ssam 6813670Ssam /* if s begins with Spool/, copy that to tptr and advance s */ 6913670Ssam if (strncmp(s, Spool, n = strlen(Spool)) == 0 && s[n] == '/') { 7013670Ssam if (!inspool) { 7113670Ssam strcpy(tptr, Spool); 7213670Ssam strcat(tptr, "/"); 7313670Ssam } 7413670Ssam s += n + 1; 7513670Ssam } 7613670Ssam else 7713670Ssam if (!inspool) 7818622Sralph return as; 7913670Ssam 8013670Ssam /* look for first prefix which matches, and make subdirectory */ 8123673Sbloom for (p = &dprefix[0]; *p; p++) { 8213670Ssam if (strncmp(s, *p, n = strlen(*p))==0 && s[n] && s[n] != '/') { 8313670Ssam strcat(tptr, *p); 8413670Ssam strcat(tptr, "/"); 8513670Ssam strcat(tptr, s); 8618622Sralph return tptr; 8713670Ssam } 8813670Ssam } 8918622Sralph return as; 9013670Ssam } 9113670Ssam 9213670Ssam /* 9313670Ssam * save away filename 9413670Ssam */ 9517838Sralph subchdir(s) 9613670Ssam register char *s; 9713670Ssam { 9813670Ssam inspool = (strcmp(s, Spool) == 0); 9918622Sralph return chdir(s); 10013670Ssam } 10113670Ssam 10213670Ssam /* 10313670Ssam * return possibly corrected directory for searching 10413670Ssam */ 10533571Srick static char xdir[BUFSIZ]; 10613670Ssam char * 10717838Sralph subdir(d, pre) 10813670Ssam register char *d, pre; 10913670Ssam { 11013670Ssam if (strcmp(d, Spool) == 0) 11113670Ssam if (pre == CMDPRE) 11218622Sralph return CMDSDIR; 11333571Srick else if (pre == XQTPRE) { 11433571Srick if (xdir[0] == '\0') 11533571Srick sprintf(xdir,"%s/X.",Spool); 11633571Srick return xdir; 11733571Srick 11833571Srick } 11918622Sralph return d; 12013670Ssam } 121