Move #include from h/mh.h to source files
[mmh] / uip / sortm.c
index 0d8e39d..734b63b 100644 (file)
@@ -9,6 +9,14 @@
 #include <h/mh.h>
 #include <h/tws.h>
 #include <h/utils.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <sys/stat.h>
+#include <locale.h>
+
+#ifdef HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif
 
 static struct swit switches[] = {
 #define DATESW  0
@@ -16,20 +24,18 @@ static struct swit switches[] = {
 #define TEXTSW  1
         { "textfield field", 0 },
 #define NSUBJSW  2
-        { "notextfield", 0 },
-#define SUBJSW  3
-        { "subject", -3 },  /* backward-compatibility */
-#define LIMSW  4
+        { "notextfield", 2 },
+#define LIMSW  3
         { "limit days", 0 },
-#define NLIMSW  5
-        { "nolimit", 0 },
-#define VERBSW  6
+#define NLIMSW  4
+        { "nolimit", 2 },
+#define VERBSW  5
         { "verbose", 0 },
-#define NVERBSW  7
-        { "noverbose", 0 },
-#define VERSIONSW  8
-        { "version", 0 },
-#define HELPSW  9
+#define NVERBSW  6
+        { "noverbose", 2 },
+#define VERSIONSW  7
+        { "Version", 0 },
+#define HELPSW  8
         { "help", 0 },
         { NULL, 0 }
 };
@@ -43,8 +49,8 @@ struct smsg {
 static struct smsg *smsgs;
 int nmsgs;
 
-char *subjsort = (char *) 0;  /* sort on subject if != 0 */
-unsigned long datelimit = 0;
+char *subjsort = NULL;  /* sort on subject if != 0 */
+time_t datelimit = 0;
 int submajor = 0;  /* if true, sort on subject-major */
 int verbose;
 
@@ -75,9 +81,7 @@ main(int argc, char **argv)
        struct msgs *mp;
        struct smsg **dlist;
 
-#ifdef LOCALE
        setlocale(LC_ALL, "");
-#endif
        invo_name = mhbasename(argv[0]);
 
        /* read user profile/context */
@@ -94,17 +98,17 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               done(1);
+                               exit(1);
                        case UNKWNSW:
                                adios(NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               done(1);
+                               exit(0);
                        case VERSIONSW:
                                print_version(invo_name);
-                               done(1);
+                               exit(0);
 
                        case DATESW:
                                if (datesw)
@@ -122,11 +126,8 @@ main(int argc, char **argv)
                                                        argp[-2]);
                                continue;
 
-                       case SUBJSW:
-                               subjsort = "subject";
-                               continue;
                        case NSUBJSW:
-                               subjsort = (char *)0;
+                               subjsort = NULL;
                                continue;
 
                        case LIMSW:
@@ -165,7 +166,7 @@ main(int argc, char **argv)
        }
 
        if (!msgs.size)
-               app_msgarg(&msgs, "all");
+               app_msgarg(&msgs, seq_all);
        if (!datesw)
                datesw = "date";
        if (!folder)
@@ -186,7 +187,7 @@ main(int argc, char **argv)
        /* parse all the message ranges/sequences and set SELECTED */
        for (msgnum = 0; msgnum < msgs.size; msgnum++)
                if (!m_convert(mp, msgs.msgs[msgnum]))
-                       done(1);
+                       exit(1);
        seq_setprev(mp);  /* set the previous sequence */
 
        if ((nmsgs = read_hdrs(mp, datesw)) <= 0)
@@ -281,8 +282,7 @@ main(int argc, char **argv)
        seq_save(mp);  /* synchronize message sequences */
        context_save();  /* save the context file */
        folder_free(mp);  /* free folder/message structure */
-       done(0);
-       return 1;
+       return 0;
 }
 
 static int