]> diplodocus.org Git - nmh/blobdiff - uip/rmf.c
getpass.c: Move interface to own file.
[nmh] / uip / rmf.c
index ec2f8fa0dae2b49f9140f35ab0d3c8eccfbccf40..33f447620f160d569f1a3f2e1133e39e24447bad 100644 (file)
--- a/uip/rmf.c
+++ b/uip/rmf.c
@@ -5,10 +5,25 @@
  * complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/utils.h>
-#include "../sbr/m_maildir.h"
-#include "../sbr/m_mktemp.h"
+#include "h/mh.h"
+#include "sbr/remdir.h"
+#include "sbr/ssequal.h"
+#include "sbr/m_atoi.h"
+#include "sbr/getfolder.h"
+#include "sbr/ext_hook.h"
+#include "sbr/context_save.h"
+#include "sbr/context_replace.h"
+#include "sbr/context_del.h"
+#include "sbr/context_find.h"
+#include "sbr/ambigsw.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 +49,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 +67,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 +88,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 +99,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 +142,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 +157,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 +170,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 +185,7 @@ rmf (char *folder)
                if (strcmp (dp->d_name, ".") == 0
                        || strcmp (dp->d_name, "..") == 0)
                    continue;
-               /* FALLTHRU */
+               break;
 
            case ',': 
                break;
@@ -178,12 +199,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 +219,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 +265,6 @@ rma (char *folder)
            pp = np;
        }
     }
+
+    free(cp);
 }