]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/RCS/rmf.c,v
sbr/mts.c: Delete mmdlm2; use same-valued mmdlm1 instead.
[nmh] / docs / historical / mh-6.8.5 / uip / RCS / rmf.c,v
1 head 2.7;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 2.7
9 date 92.12.15.00.20.22; author jromine; state Exp;
10 branches;
11 next 2.6;
12
13 2.6
14 date 92.11.04.01.00.16; author jromine; state Exp;
15 branches;
16 next 2.5;
17
18 2.5
19 date 92.05.19.21.05.09; author jromine; state Exp;
20 branches;
21 next 2.4;
22
23 2.4
24 date 92.02.04.00.03.28; author jromine; state Exp;
25 branches;
26 next 2.3;
27
28 2.3
29 date 90.11.05.12.22.03; author mh; state Exp;
30 branches;
31 next 2.2;
32
33 2.2
34 date 90.04.05.14.57.11; author sources; state Exp;
35 branches;
36 next 2.1;
37
38 2.1
39 date 90.02.06.13.30.19; author sources; state Exp;
40 branches;
41 next 2.0;
42
43 2.0
44 date 89.11.17.15.58.10; author sources; state Exp;
45 branches;
46 next 1.1;
47
48 1.1
49 date 89.06.26.14.36.40; author sources; state Exp;
50 branches;
51 next ;
52
53
54 desc
55 @@
56
57
58 2.7
59 log
60 @endif sugar
61 @
62 text
63 @/* rmf.c - remove a folder */
64 #ifndef lint
65 static char ident[] = "@@(#)$Id: rmf.c,v 2.6 1992/11/04 01:00:16 jromine Exp jromine $";
66 #endif /* lint */
67
68 #include "../h/mh.h"
69 #include "../h/local.h"
70 #include <stdio.h>
71 #ifdef LOCALE
72 #include <locale.h>
73 #endif
74
75 /* \f */
76
77 static struct swit switches[] = {
78 #define INTRSW 0
79 "interactive", 0,
80 #define NINTRSW 1
81 "nointeractive", 0,
82
83 #define HELPSW 2
84 "help", 4,
85
86 NULL, 0
87 };
88
89 static int rmf();
90 static rma();
91 /* \f */
92
93 /* ARGSUSED */
94
95 main (argc, argv)
96 int argc;
97 char *argv[];
98 {
99 int defolder = 0,
100 interactive = -1;
101 char *cp,
102 *folder = NULL,
103 newfolder[BUFSIZ],
104 buf[100],
105 **ap,
106 **argp,
107 *arguments[MAXARGS];
108
109 #ifdef LOCALE
110 setlocale(LC_ALL, "");
111 #endif
112 invo_name = r1bindex (argv[0], '/');
113 if ((cp = m_find (invo_name)) != NULL) {
114 ap = brkstring (cp = getcpy (cp), " ", "\n");
115 ap = copyip (ap, arguments);
116 }
117 else
118 ap = arguments;
119 (void) copyip (argv + 1, ap);
120 argp = arguments;
121
122 /* \f */
123
124 while (cp = *argp++) {
125 if (*cp == '-')
126 switch (smatch (++cp, switches)) {
127 case AMBIGSW:
128 ambigsw (cp, switches);
129 done (1);
130 case UNKWNSW:
131 adios (NULLCP, "-%s unknown", cp);
132 case HELPSW:
133 (void) sprintf (buf, "%s [+folder] [switches]", invo_name);
134 help (buf, switches);
135 done (1);
136
137 case INTRSW:
138 interactive = 1;
139 continue;
140 case NINTRSW:
141 interactive = 0;
142 continue;
143 }
144 if (*cp == '+' || *cp == '@@') {
145 if (folder)
146 adios (NULLCP, "only one folder at a time!");
147 else
148 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
149 }
150 else
151 adios (NULLCP, "usage: %s [+folder] [switches]", invo_name);
152 }
153
154 /* \f */
155
156 if (!m_find ("path"))
157 free (path ("./", TFOLDER));
158 if (!folder) {
159 folder = m_getfolder ();
160 defolder++;
161 }
162 if (strcmp (m_mailpath (folder), pwd ()) == 0)
163 adios (NULLCP, "sorry, you can't remove the current working directory");
164
165 if (interactive == -1)
166 interactive = defolder;
167
168 if (index (folder, '/') && (*folder != '/') && (*folder != '.')) {
169 for (cp = copy (folder, newfolder); cp > newfolder && *cp != '/'; cp--)
170 continue;
171 if (cp > newfolder)
172 *cp = '\0';
173 else
174 (void) strcpy (newfolder, (cp = m_find (inbox)) ? cp : defalt);
175 }
176 else
177 (void) strcpy (newfolder, (cp = m_find (inbox)) ? cp : defalt);
178
179 if (interactive) {
180 cp = concat ("Remove folder \"", folder, "\"? ", NULLCP);
181 if (!getanswer (cp))
182 done (0);
183 free (cp);
184 }
185
186 if (rmf (folder) == OK && strcmp (m_find (pfolder), newfolder)) {
187 printf ("[+%s now current]\n", newfolder);
188 m_replace (pfolder, newfolder);
189 }
190 m_update ();
191
192 done (0);
193 }
194
195 /* \f */
196
197 static int rmf (folder)
198 register char *folder;
199 {
200 int i,
201 j,
202 others;
203 register char *maildir;
204 char cur[BUFSIZ];
205 #ifdef SYS5DIR
206 register struct dirent *dp;
207 #else /* SYS5DIR */
208 register struct direct *dp;
209 #endif /* SYS5DIR */
210 register DIR * dd;
211
212 #ifdef COMPAT
213 (void) m_delete (concat (current, "-", m_mailpath (folder), NULLCP));
214 #endif /* COMPAT */
215 switch (i = chdir (maildir = m_maildir (folder))) {
216 case OK:
217 if (access (".", 2) != NOTOK && access ("..", 2) != NOTOK)
218 break; /* fall otherwise */
219
220 case NOTOK:
221 (void) sprintf (cur, "atr-%s-%s", current, m_mailpath (folder));
222 if (!m_delete (cur)) {
223 printf ("[+%s de-referenced]\n", folder);
224 return OK;
225 }
226 advise (NULLCP, "you have no profile entry for the %s folder +%s",
227 i == NOTOK ? "unreadable" : "read-only", folder);
228 return NOTOK;
229 }
230
231 if ((dd = opendir (".")) == NULL)
232 adios (NULLCP, "unable to read folder +%s", folder);
233 others = 0;
234
235 j = strlen (SBACKUP);
236 while (dp = readdir (dd)) {
237 switch (dp -> d_name[0]) {
238 case '.':
239 if (strcmp (dp -> d_name, ".") == 0
240 || strcmp (dp -> d_name, "..") == 0)
241 continue; /* else fall */
242
243 case ',':
244 #ifdef MHE
245 case '+':
246 #endif /* MHE */
247 #ifdef UCI
248 case '_':
249 case '#':
250 #endif /* UCI */
251 break;
252
253 default:
254 if (m_atoi (dp -> d_name))
255 break;
256 #ifdef COMPAT
257 if (strcmp (dp -> d_name, current) == 0)
258 break;
259 #endif /* COMPAT */
260 if (strcmp (dp -> d_name, LINK) == 0
261 || strncmp (dp -> d_name, SBACKUP, j) == 0)
262 break;
263
264 admonish (NULLCP, "file \"%s/%s\" not deleted",
265 folder, dp -> d_name);
266 others++;
267 continue;
268 }
269 if (unlink (dp -> d_name) == NOTOK) {
270 admonish (dp -> d_name, "unable to unlink %s:", folder);
271 others++;
272 }
273 }
274
275 closedir (dd);
276
277 rma (folder);
278
279 (void) chdir ("..");
280 if (others == 0 && remdir (maildir))
281 return OK;
282
283 advise (NULLCP, "folder +%s not removed", folder);
284 return NOTOK;
285 }
286
287 /* \f */
288
289 static rma (folder)
290 register char *folder;
291 {
292 register int alen,
293 j,
294 plen;
295 register char *cp;
296 register struct node *np,
297 *pp;
298
299 alen = strlen ("atr-");
300 plen = strlen (cp = m_mailpath (folder)) + 1;
301
302 m_getdefs ();
303 for (np = m_defs, pp = NULL; np; np = np -> n_next)
304 if (ssequal ("atr-", np -> n_name)
305 && (j = strlen (np -> n_name) - plen) > alen
306 && *(np -> n_name + j) == '-'
307 && strcmp (cp, np -> n_name + j + 1) == 0) {
308 if (!np -> n_context)
309 admonish (NULLCP, "bug: m_delete(key=\"%s\")", np -> n_name);
310 if (pp) {
311 pp -> n_next = np -> n_next;
312 np = pp;
313 }
314 else
315 m_defs = np -> n_next;
316 ctxflags |= CTXMOD;
317 }
318 else
319 pp = np;
320 }
321 @
322
323
324 2.6
325 log
326 @LOCALE
327 @
328 text
329 @d3 2
330 a4 2
331 static char ident[] = "@@(#)$Id: rmf.c,v 2.5 1992/05/19 21:05:09 jromine Exp jromine $";
332 #endif lint
333 d145 1
334 a145 1
335 #else SYS5DIR
336 d147 1
337 a147 1
338 #endif SYS5DIR
339 d152 1
340 a152 1
341 #endif COMPAT
342 d184 1
343 a184 1
344 #endif MHE
345 d188 1
346 a188 1
347 #endif UCI
348 d197 1
349 a197 1
350 #endif COMPAT
351 @
352
353
354 2.5
355 log
356 @AIX
357 @
358 text
359 @d3 1
360 a3 1
361 static char ident[] = "@@(#)$Id: rmf.c,v 2.4 1992/02/04 00:03:28 jromine Exp jromine $";
362 d9 3
363 d47 3
364 @
365
366
367 2.4
368 log
369 @contributed patch
370 @
371 text
372 @d3 1
373 a3 1
374 static char ident[] = "@@(#)$Id: rmf.c,v 2.3 1990/11/05 12:22:03 mh Exp jromine $";
375 d21 1
376 a21 1
377 NULL, NULL
378 d104 1
379 a104 1
380 *cp = NULL;
381 @
382
383
384 2.3
385 log
386 @fix typo
387 @
388 text
389 @d3 1
390 a3 1
391 static char ident[] = "@@(#)$Id: rmf.c,v 2.2 90/04/05 14:57:11 sources Exp Locker: mh $";
392 d106 1
393 a106 1
394 (void) strcpy (newfolder, defalt);
395 d109 1
396 a109 1
397 (void) strcpy (newfolder, defalt);
398 @
399
400
401 2.2
402 log
403 @add ID
404 @
405 text
406 @d3 1
407 a3 1
408 static char ident[] = "@@(#)$Id:$";
409 d16 1
410 a16 1
411 "nointerative", 0,
412 @
413
414
415 2.1
416 log
417 @ANSI Compilance
418 @
419 text
420 @d2 3
421 @
422
423
424 2.0
425 log
426 @changes for SUN40 shared libraries and NNTP under bbc
427 @
428 text
429 @d21 2
430 @
431
432
433 1.1
434 log
435 @Initial revision
436 @
437 text
438 @d132 3
439 d136 1
440 @