2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
12 extern struct swit anoyes
[]; /* Std no/yes gans array */
22 struct swit switches
[] = {
32 register char *cp
, **ap
;
33 char *folder
, buf
[128];
35 char *arguments
[50], **argp
;
42 cp
= r1bindex(argv
[0], '/');
43 if((cp
= m_find(cp
)) != NULL
) {
44 ap
= brkstring(cp
= getcpy(cp
), " ", "\n");
45 ap
= copyip(ap
, arguments
);
48 VOID
copyip(argv
+1, ap
);
52 switch(smatch(++cp
, switches
)) {
53 case -2:ambigsw(cp
, switches
); /* ambiguous */
56 case -1:fprintf(stderr
, "rmf: -%s unknown\n", cp
);
59 case 0: help("rmf [+folder] [switches]", switches
);
64 fprintf(stderr
, "Only one folder at a time.\n");
67 folder
= path(cp
+1, TFOLDER
);
69 fprintf(stderr
, "Usage: rmf [+folder]\n");
73 if(!m_find("path")) free(path("./", TFOLDER
));
75 folder
= m_getfolder();
78 subf
= !((!index(folder
, '/')) | (*folder
== '/') | (*folder
== '.'));
79 if(def_fold
&& !subf
) {
80 cp
= concat("Remove folder \"", folder
, "\" ?? ", NULLCP
);
87 if(subf
) { /* make parent "current" */
88 cp
= copy(folder
, buf
);
89 while(cp
> buf
&& *cp
!= '/') --cp
;
92 if(strcmp(m_find(pfolder
), buf
) != 0) {
93 printf("[+%s now current]\n", buf
);
94 m_replace(pfolder
, buf
);
108 register char *maildir
;
112 if(!subf
&& strcmp(m_find(pfolder
), fold
) == 0) /* make default "current"*/
113 if(strcmp(m_find(pfolder
), defalt
) != 0) {
114 printf("[+%s now current]\n", defalt
);
115 VOID
fflush(stdout
); /*??*/
116 m_replace(pfolder
, defalt
);
118 maildir
= m_maildir(fold
);
119 if((cd
= chdir(maildir
)) < 0)
121 if(access(".", 2) == -1) {
122 funnyfold
: if(!m_delete(concat("cur-", fold
, NULLCP
)))
123 printf("[Folder %s de-referenced]\n", fold
);
125 fprintf(stderr
, "You have no profile entry for the %s folder %s\n",
126 cd
< 0 ? "unreadable" : "read-only", fold
);
131 while(read(i
, (char *)&ent
.inum
, sizeof ent
.name
+ sizeof ent
.inum
))
133 if((ent
.name
[0] >= '0' && ent
.name
[0] <= '9') ||
134 ent
.name
[0] == ',' ||
135 (ent
.name
[0] == '.' && ent
.name
[1] && ent
.name
[1] != '.') ||
136 strcmp(ent
.name
, "cur") == 0 ||
137 strcmp(ent
.name
, "@") == 0) {
138 if(unlink(ent
.name
) == -1) {
139 fprintf(stderr
, "Can't unlink %s:%s\n", fold
,ent
.name
);
142 } else if(strcmp(ent
.name
,".") != 0 &&
143 strcmp(ent
.name
,"..") != 0) {
144 fprintf(stderr
, "File \"%s/%s\" not deleted!\n",
149 VOID
chdir(".."); /* Move out of dir to be deleted */
150 if(!leftover
&& removedir(maildir
))
153 fprintf(stderr
, "Folder %s not removed!\n", fold
);
161 register int pid
, wpid
;
164 if((pid
= fork()) == 0) {
167 execl("/bin/rmdir", "rmdir", dir
, 0);
168 execl("/usr/bin/rmdir", "rmdir", dir
, 0);
169 fprintf(stderr
, "Can't exec rmdir!!?\n");
173 fprintf(stderr
, "Can't fork\n");
176 while((wpid
= wait(&status
)) != pid
&& wpid
!= -1) ;
178 fprintf(stderr
, "Bad exit status (%o) from rmdir.\n", status
);