13af3a2f4Ssam #ifndef lint
2*1aa9b5b9Sralph static char sccsid[] = "@(#)tp1.c 4.2 06/28/84";
33af3a2f4Ssam #endif
43af3a2f4Ssam
53af3a2f4Ssam #include "tp.h"
63af3a2f4Ssam
main(argc,argv)73af3a2f4Ssam main(argc,argv)
83af3a2f4Ssam char **argv;
93af3a2f4Ssam {
103af3a2f4Ssam register char c,*ptr;
113af3a2f4Ssam extern cmd(), cmr(),cmx(), cmt();
123af3a2f4Ssam
133af3a2f4Ssam tname = tc;
143af3a2f4Ssam command = cmr;
153af3a2f4Ssam if ((narg = rnarg = argc) < 2) narg = 2;
163af3a2f4Ssam else {
173af3a2f4Ssam ptr = argv[1]; /* get first argument */
183af3a2f4Ssam parg = &argv[2]; /* pointer to second argument */
193af3a2f4Ssam while (c = *ptr++) switch(c) {
203af3a2f4Ssam case '0':
213af3a2f4Ssam case '1':
223af3a2f4Ssam case '2':
233af3a2f4Ssam case '3':
243af3a2f4Ssam case '4':
253af3a2f4Ssam case '5':
263af3a2f4Ssam case '6':
273af3a2f4Ssam case '7':
283af3a2f4Ssam tc[8] = c;
293af3a2f4Ssam mt[8] = c;
303af3a2f4Ssam continue;
313af3a2f4Ssam
323af3a2f4Ssam case 'f':
333af3a2f4Ssam tname = *parg++;
343af3a2f4Ssam flags |= flm;
353af3a2f4Ssam narg--; rnarg--;
363af3a2f4Ssam continue;
373af3a2f4Ssam case 'c':
383af3a2f4Ssam flags |= flc; continue;
393af3a2f4Ssam case 'd':
403af3a2f4Ssam setcom(cmd); continue;
413af3a2f4Ssam case 'i':
423af3a2f4Ssam flags |= fli; continue;
433af3a2f4Ssam case 'm':
443af3a2f4Ssam tname = mt;
453af3a2f4Ssam flags |= flm;
463af3a2f4Ssam continue;
473af3a2f4Ssam case 'r':
483af3a2f4Ssam flags &= ~flu; setcom(cmr); continue;
493af3a2f4Ssam case 's':
503af3a2f4Ssam flags |= fls; continue;
513af3a2f4Ssam case 't':
523af3a2f4Ssam setcom(cmt); continue;
533af3a2f4Ssam case 'u':
543af3a2f4Ssam flags |= flu; setcom(cmr); continue;
553af3a2f4Ssam case 'v':
563af3a2f4Ssam flags |= flv; continue;
573af3a2f4Ssam case 'w':
583af3a2f4Ssam flags |= flw; continue;
593af3a2f4Ssam case 'x':
603af3a2f4Ssam setcom(cmx); continue;
613af3a2f4Ssam default:
623af3a2f4Ssam useerr();
633af3a2f4Ssam }
643af3a2f4Ssam }
653af3a2f4Ssam optap();
663af3a2f4Ssam (*command)();
673af3a2f4Ssam }
683af3a2f4Ssam
optap()693af3a2f4Ssam optap()
703af3a2f4Ssam {
713af3a2f4Ssam extern cmr();
723af3a2f4Ssam
733af3a2f4Ssam if ((flags & flm) == 0) { /* DECTAPE */
743af3a2f4Ssam tapsiz = TCSIZ;
753af3a2f4Ssam ndirent = TCDIRS;
763af3a2f4Ssam fio =open(tc,2);
773af3a2f4Ssam } else { /* MAGTAPE */
783af3a2f4Ssam tapsiz = MTSIZ;
793af3a2f4Ssam ndirent = MDIRENT;
803af3a2f4Ssam if(command == cmr) {
813af3a2f4Ssam fio = open(tname,1);
823af3a2f4Ssam if (fio < 0) fio = creat(tname,0666);
833af3a2f4Ssam } else
843af3a2f4Ssam fio = open(tname,0);
853af3a2f4Ssam }
863af3a2f4Ssam if (fio < 0) {
873af3a2f4Ssam printf("Tape open error\n");
883af3a2f4Ssam done();
893af3a2f4Ssam }
903af3a2f4Ssam ndentb = ndirent/TPB;
913af3a2f4Ssam edir = &dir[ndirent];
923af3a2f4Ssam }
933af3a2f4Ssam
943af3a2f4Ssam setcom(newcom)
953af3a2f4Ssam int (*newcom)();
963af3a2f4Ssam {
973af3a2f4Ssam extern cmr();
983af3a2f4Ssam
993af3a2f4Ssam if (command != cmr) useerr();
1003af3a2f4Ssam command = newcom;
1013af3a2f4Ssam }
1023af3a2f4Ssam
useerr()1033af3a2f4Ssam useerr()
1043af3a2f4Ssam {
1053af3a2f4Ssam printf("Bad usage\n");
1063af3a2f4Ssam done();
1073af3a2f4Ssam }
1083af3a2f4Ssam
1093af3a2f4Ssam /*/* COMMANDS */
1103af3a2f4Ssam
cmd()1113af3a2f4Ssam cmd()
1123af3a2f4Ssam {
1133af3a2f4Ssam extern delete();
1143af3a2f4Ssam
1153af3a2f4Ssam if (flags & (flm|flc)) useerr();
1163af3a2f4Ssam if (narg <= 2) useerr();
1173af3a2f4Ssam rddir();
1183af3a2f4Ssam gettape(delete);
1193af3a2f4Ssam wrdir();
1203af3a2f4Ssam check();
1213af3a2f4Ssam }
1223af3a2f4Ssam
cmr()1233af3a2f4Ssam cmr()
1243af3a2f4Ssam {
1253af3a2f4Ssam if (flags & (flc|flm)) clrdir();
1263af3a2f4Ssam else rddir();
1273af3a2f4Ssam getfiles();
1283af3a2f4Ssam update();
1293af3a2f4Ssam check();
1303af3a2f4Ssam }
1313af3a2f4Ssam
cmt()1323af3a2f4Ssam cmt()
1333af3a2f4Ssam {
1343af3a2f4Ssam extern taboc();
1353af3a2f4Ssam
1363af3a2f4Ssam if (flags & (flc|flw)) useerr();
1373af3a2f4Ssam rddir();
1383af3a2f4Ssam if (flags & flv)
1393af3a2f4Ssam printf(" mode uid gid tapa size date time name\n");
1403af3a2f4Ssam gettape(taboc);
1413af3a2f4Ssam check();
1423af3a2f4Ssam }
1433af3a2f4Ssam
cmx()1443af3a2f4Ssam cmx()
1453af3a2f4Ssam {
1463af3a2f4Ssam extern extract();
1473af3a2f4Ssam
1483af3a2f4Ssam if (flags & (flc)) useerr();
1493af3a2f4Ssam rddir();
1503af3a2f4Ssam gettape(extract);
1513af3a2f4Ssam done();
1523af3a2f4Ssam }
1533af3a2f4Ssam
check()1543af3a2f4Ssam check()
1553af3a2f4Ssam {
1563af3a2f4Ssam usage();
1573af3a2f4Ssam done();
1583af3a2f4Ssam }
1593af3a2f4Ssam
done()1603af3a2f4Ssam done()
1613af3a2f4Ssam {
1623af3a2f4Ssam printf("End\n");
1633af3a2f4Ssam exit(0);
1643af3a2f4Ssam }
1653af3a2f4Ssam
encode(pname,dptr)1663af3a2f4Ssam encode(pname,dptr) /* pname points to the pathname
1673af3a2f4Ssam * dptr points to the dir entry */
1683af3a2f4Ssam char *pname;
1693af3a2f4Ssam struct dent *dptr;
1703af3a2f4Ssam {
1713af3a2f4Ssam register char *np;
1723af3a2f4Ssam register n;
173*1aa9b5b9Sralph extern char *malloc();
1743af3a2f4Ssam
1753af3a2f4Ssam if((n=strlen(pname)) > NAMELEN) {
1763af3a2f4Ssam printf("Pathname too long - %s\nFile ignored\n",pname);
1773af3a2f4Ssam clrent(dptr);
1783af3a2f4Ssam }
1793af3a2f4Ssam else {
180*1aa9b5b9Sralph dptr->d_namep = np = malloc(n + 1);
181*1aa9b5b9Sralph if (np == 0) {
182*1aa9b5b9Sralph printf("Out of core\n");
183*1aa9b5b9Sralph done();
184*1aa9b5b9Sralph }
1853af3a2f4Ssam strcpy(np, pname);
1863af3a2f4Ssam }
1873af3a2f4Ssam }
1883af3a2f4Ssam
decode(pname,dptr)1893af3a2f4Ssam decode(pname,dptr) /* dptr points to the dir entry
1903af3a2f4Ssam * name is placed in pname[] */
1913af3a2f4Ssam char *pname;
1923af3a2f4Ssam struct dent *dptr;
1933af3a2f4Ssam {
1943af3a2f4Ssam
1953af3a2f4Ssam strcpy(pname, dptr->d_namep);
1963af3a2f4Ssam }
197