113670Ssam #ifndef lint 2*33571Srick static char sccsid[] = "@(#)subdir.c 5.5 (Berkeley) 02/24/88"; 313670Ssam #endif 413670Ssam 513670Ssam #include "uucp.h" 623673Sbloom 723673Sbloom /*LINTLIBRARY*/ 823673Sbloom 913670Ssam /* 1013670Ssam * By Tom Truscott, March 1983 1113670Ssam * 1213670Ssam * Prefix table. 1313670Ssam * If a prefix is "abc", for example, 1413670Ssam * then any file Spool/abc... is mapped to Spool/abc/abc... . 1513670Ssam * The first prefix found is used, so D.foo should preceed D. in table. 1613670Ssam * 1713670Ssam * Each prefix must be a subdirectory of Spool, owned by uucp! 1813670Ssam * Remember: use cron to uuclean these directories daily, 1918622Sralph * and check them manually every now and then. Beware complacency! 2013670Ssam */ 2113670Ssam 2223673Sbloom static char *dprefix[] = { 2313670Ssam DLocalX, /* Outbound 'xqt' request files */ 2413670Ssam DLocal, /* Outbound data files */ 2513670Ssam "D.", /* Other "D." files (remember the "."!) */ 2613670Ssam "C.", /* "C." subdirectory */ 2713670Ssam "X.", /* "X." subdirectory */ 2813670Ssam "TM.", /* Temporaries for inbound files */ 2913670Ssam 0 3013670Ssam }; 3113670Ssam 3213670Ssam /* 3313670Ssam * filename mapping kludges to put uucp work files in other directories. 3413670Ssam */ 3513670Ssam 3613670Ssam #define BUFLEN 50 3713670Ssam 3813670Ssam static char fn1[BUFLEN], fn2[BUFLEN]; /* remapped filename areas */ 3913670Ssam static int inspool; /* true iff working dir is Spool */ 4013670Ssam 4113670Ssam /* 4213670Ssam * return (possibly) remapped string s 4313670Ssam */ 4413670Ssam char * 4517838Sralph subfile(as) 4613670Ssam char *as; 4713670Ssam { 4813670Ssam register char *s, **p; 4913670Ssam register int n; 5013670Ssam static char *tptr = NULL; 5113670Ssam 5213670Ssam /* Alternate buffers so "link(subfile(a), subfile(b))" works */ 5313670Ssam if (tptr != fn1) 5413670Ssam tptr = fn1; 5513670Ssam else 5613670Ssam tptr = fn2; 5713670Ssam 5813670Ssam s = as; 5913670Ssam tptr[0] = '\0'; 6013670Ssam 6113670Ssam /* if s begins with Spool/, copy that to tptr and advance s */ 6213670Ssam if (strncmp(s, Spool, n = strlen(Spool)) == 0 && s[n] == '/') { 6313670Ssam if (!inspool) { 6413670Ssam strcpy(tptr, Spool); 6513670Ssam strcat(tptr, "/"); 6613670Ssam } 6713670Ssam s += n + 1; 6813670Ssam } 6913670Ssam else 7013670Ssam if (!inspool) 7118622Sralph return as; 7213670Ssam 7313670Ssam /* look for first prefix which matches, and make subdirectory */ 7423673Sbloom for (p = &dprefix[0]; *p; p++) { 7513670Ssam if (strncmp(s, *p, n = strlen(*p))==0 && s[n] && s[n] != '/') { 7613670Ssam strcat(tptr, *p); 7713670Ssam strcat(tptr, "/"); 7813670Ssam strcat(tptr, s); 7918622Sralph return tptr; 8013670Ssam } 8113670Ssam } 8218622Sralph return as; 8313670Ssam } 8413670Ssam 8513670Ssam /* 8613670Ssam * save away filename 8713670Ssam */ 8817838Sralph subchdir(s) 8913670Ssam register char *s; 9013670Ssam { 9113670Ssam inspool = (strcmp(s, Spool) == 0); 9218622Sralph return chdir(s); 9313670Ssam } 9413670Ssam 9513670Ssam /* 9613670Ssam * return possibly corrected directory for searching 9713670Ssam */ 98*33571Srick static char xdir[BUFSIZ]; 9913670Ssam char * 10017838Sralph subdir(d, pre) 10113670Ssam register char *d, pre; 10213670Ssam { 10313670Ssam if (strcmp(d, Spool) == 0) 10413670Ssam if (pre == CMDPRE) 10518622Sralph return CMDSDIR; 106*33571Srick else if (pre == XQTPRE) { 107*33571Srick if (xdir[0] == '\0') 108*33571Srick sprintf(xdir,"%s/X.",Spool); 109*33571Srick return xdir; 110*33571Srick 111*33571Srick } 11218622Sralph return d; 11313670Ssam } 114