X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/0509728c8a506f287fa3483d8e8ffaf8fb66d41d..04ee0c3f6ad7e4177cc43a0c57f046013a4fbac9:/uip/rmf.c diff --git a/uip/rmf.c b/uip/rmf.c index ec2f8fa0..eaa01b71 100644 --- a/uip/rmf.c +++ b/uip/rmf.c @@ -5,10 +5,15 @@ * complete copyright information. */ -#include -#include -#include "../sbr/m_maildir.h" -#include "../sbr/m_mktemp.h" +#include "h/mh.h" +#include "sbr/path.h" +#include "sbr/print_version.h" +#include "sbr/print_help.h" +#include "sbr/error.h" +#include "h/done.h" +#include "h/utils.h" +#include "sbr/m_maildir.h" +#include "sbr/m_mktemp.h" #define RMF_SWITCHES \ X("interactive", 0, INTRSW) \ @@ -34,11 +39,13 @@ static void rma (char *); int main (int argc, char **argv) { - int defolder = 0, interactive = -1; + bool defolder = false; + int interactive = -1; char *cp, *folder = NULL, newfolder[BUFSIZ]; char buf[BUFSIZ], **argp, **arguments; + char *fp; - if (nmh_init(argv[0], 1)) { return 1; } + if (nmh_init(argv[0], true, true)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; @@ -50,7 +57,7 @@ main (int argc, char **argv) ambigsw (cp, switches); done (1); case UNKWNSW: - adios (NULL, "-%s unknown", cp); + die("-%s unknown", cp); case HELPSW: snprintf (buf, sizeof(buf), "%s [+folder] [switches]", @@ -71,11 +78,10 @@ main (int argc, char **argv) } if (*cp == '+' || *cp == '@') { if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); + die("only one folder at a time!"); + folder = pluspath (cp); } else { - adios (NULL, "usage: %s [+folder] [switches]", invo_name); + die("usage: %s [+folder] [switches]", invo_name); } } @@ -83,10 +89,12 @@ main (int argc, char **argv) free (path ("./", TFOLDER)); if (!folder) { folder = getfolder (1); - defolder++; + defolder = true; } - if (strcmp (m_mailpath (folder), pwd ()) == 0) - adios (NULL, "sorry, you can't remove the current working directory"); + fp = m_mailpath(folder); + if (!strcmp(fp, pwd())) + die("sorry, you can't remove the current working directory"); + free(fp); if (interactive == -1) interactive = defolder; @@ -124,7 +132,9 @@ main (int argc, char **argv) static int rmf (char *folder) { - int i, others; + int i; + bool others; + char *fp; char *maildir; char cur[BUFSIZ]; struct dirent *dp; @@ -137,8 +147,9 @@ rmf (char *folder) /* FALLTHRU */ case NOTOK: - snprintf (cur, sizeof(cur), "atr-%s-%s", - current, m_mailpath (folder)); + fp = m_mailpath(folder); + snprintf (cur, sizeof(cur), "atr-%s-%s", current, fp); + free(fp); if (!context_del (cur)) { printf ("[+%s de-referenced]\n", folder); return OK; @@ -149,8 +160,8 @@ rmf (char *folder) } if ((dd = opendir (".")) == NULL) - adios (NULL, "unable to read folder +%s", folder); - others = 0; + die("unable to read folder +%s", folder); + others = false; /* * Run the external delete hook program. @@ -164,7 +175,7 @@ rmf (char *folder) if (strcmp (dp->d_name, ".") == 0 || strcmp (dp->d_name, "..") == 0) continue; - /* FALLTHRU */ + break; case ',': break; @@ -178,12 +189,12 @@ rmf (char *folder) inform("file \"%s/%s\" not deleted, continuing...", folder, dp->d_name); - others++; + others = true; continue; } if (m_unlink (dp->d_name) == NOTOK) { admonish (dp->d_name, "unable to unlink %s:", folder); - others++; + others = true; } } @@ -198,7 +209,7 @@ rmf (char *folder) if (chdir ("..") < 0) { advise ("..", "chdir"); } - if (others == 0 && remdir (maildir)) + if (!others && remdir (maildir)) return OK; inform("folder +%s not removed", folder); @@ -244,4 +255,6 @@ rma (char *folder) pp = np; } } + + free(cp); }