date and time created 88/10/22 15:35:06 by bostic
[unix-history] / usr / src / old / tp / tp1.c
CommitLineData
53f9bd51 1#ifndef lint
9f44317d 2static char sccsid[] = "@(#)tp1.c 4.2 %G%";
53f9bd51
SL
3#endif
4
5#include "tp.h"
6
7main(argc,argv)
8char **argv;
9{
10 register char c,*ptr;
11 extern cmd(), cmr(),cmx(), cmt();
12
13 tname = tc;
14 command = cmr;
15 if ((narg = rnarg = argc) < 2) narg = 2;
16 else {
17 ptr = argv[1]; /* get first argument */
18 parg = &argv[2]; /* pointer to second argument */
19 while (c = *ptr++) switch(c) {
20 case '0':
21 case '1':
22 case '2':
23 case '3':
24 case '4':
25 case '5':
26 case '6':
27 case '7':
28 tc[8] = c;
29 mt[8] = c;
30 continue;
31
32 case 'f':
33 tname = *parg++;
34 flags |= flm;
35 narg--; rnarg--;
36 continue;
37 case 'c':
38 flags |= flc; continue;
39 case 'd':
40 setcom(cmd); continue;
41 case 'i':
42 flags |= fli; continue;
43 case 'm':
44 tname = mt;
45 flags |= flm;
46 continue;
47 case 'r':
48 flags &= ~flu; setcom(cmr); continue;
49 case 's':
50 flags |= fls; continue;
51 case 't':
52 setcom(cmt); continue;
53 case 'u':
54 flags |= flu; setcom(cmr); continue;
55 case 'v':
56 flags |= flv; continue;
57 case 'w':
58 flags |= flw; continue;
59 case 'x':
60 setcom(cmx); continue;
61 default:
62 useerr();
63 }
64 }
65 optap();
53f9bd51
SL
66 (*command)();
67}
68
69optap()
70{
71 extern cmr();
72
73 if ((flags & flm) == 0) { /* DECTAPE */
74 tapsiz = TCSIZ;
75 ndirent = TCDIRS;
76 fio =open(tc,2);
77 } else { /* MAGTAPE */
78 tapsiz = MTSIZ;
79 ndirent = MDIRENT;
80 if(command == cmr) {
81 fio = open(tname,1);
82 if (fio < 0) fio = creat(tname,0666);
83 } else
84 fio = open(tname,0);
85 }
86 if (fio < 0) {
87 printf("Tape open error\n");
88 done();
89 }
90 ndentb = ndirent/TPB;
91 edir = &dir[ndirent];
92}
93
94setcom(newcom)
95int (*newcom)();
96{
97 extern cmr();
98
99 if (command != cmr) useerr();
100 command = newcom;
101}
102
103useerr()
104{
105 printf("Bad usage\n");
106 done();
107}
108
109/*\f/* COMMANDS */
110
111cmd()
112{
113 extern delete();
114
115 if (flags & (flm|flc)) useerr();
116 if (narg <= 2) useerr();
117 rddir();
118 gettape(delete);
119 wrdir();
120 check();
121}
122
123cmr()
124{
125 if (flags & (flc|flm)) clrdir();
126 else rddir();
127 getfiles();
128 update();
129 check();
130}
131
132cmt()
133{
134 extern taboc();
135
136 if (flags & (flc|flw)) useerr();
137 rddir();
138 if (flags & flv)
139 printf(" mode uid gid tapa size date time name\n");
140 gettape(taboc);
141 check();
142}
143
144cmx()
145{
146 extern extract();
147
148 if (flags & (flc)) useerr();
149 rddir();
150 gettape(extract);
151 done();
152}
153
154check()
155{
156 usage();
157 done();
158}
159
160done()
161{
162 printf("End\n");
163 exit(0);
164}
165
166encode(pname,dptr) /* pname points to the pathname
53f9bd51
SL
167 * dptr points to the dir entry */
168char *pname;
169struct dent *dptr;
170{
171 register char *np;
172 register n;
9f44317d 173 extern char *malloc();
53f9bd51 174
53f9bd51
SL
175 if((n=strlen(pname)) > NAMELEN) {
176 printf("Pathname too long - %s\nFile ignored\n",pname);
177 clrent(dptr);
178 }
179 else {
9f44317d
RC
180 dptr->d_namep = np = malloc(n + 1);
181 if (np == 0) {
182 printf("Out of core\n");
183 done();
184 }
53f9bd51
SL
185 strcpy(np, pname);
186 }
187}
188
189decode(pname,dptr) /* dptr points to the dir entry
190 * name is placed in pname[] */
191char *pname;
192struct dent *dptr;
193{
194
195 strcpy(pname, dptr->d_namep);
196}