Added support for optional Content_Disposition header in mhbuild directive.s
[mmh] / uip / anno.c
index b92abdc..9fbb37f 100644 (file)
@@ -46,6 +46,7 @@
  */
 
 #include <h/mh.h>
+#include <h/utils.h>
 
 /*
  * We allocate space for messages (msgs array)
@@ -81,6 +82,10 @@ static struct swit switches[] = {
     { "number", 2 },
 #define        APPENDSW                12
     { "append", 1 },
+#define        PRESERVESW              13
+    { "preserve", 1 },
+#define        NOPRESERVESW            14
+    { "nopreserve", 3 },
     { NULL, 0 }
 };
 
@@ -100,7 +105,7 @@ main (int argc, char **argv)
     char **argp, **arguments, **msgs;
     struct msgs *mp;
     int                append = 0;             /* append annotations instead of default prepend */
-    int                delete = -1;            /* delete header element if set */
+    int                delete = -2;            /* delete header element if set */
     char       *draft = (char *)0;     /* draft file name */
     int                isdf = 0;               /* return needed for m_draft() */
     int                list = 0;               /* list header elements if set */
@@ -123,8 +128,7 @@ main (int argc, char **argv)
      */
     nummsgs = 0;
     maxmsgs = MAXMSGS;
-    if (!(msgs = (char **) malloc ((size_t) (maxmsgs * sizeof(*msgs)))))
-       adios (NULL, "unable to allocate storage");
+    msgs = (char **) mh_xmalloc ((size_t) (maxmsgs * sizeof(*msgs)));
 
     while ((cp = *argp++)) {
        if (*cp == '-') {
@@ -190,9 +194,16 @@ main (int argc, char **argv)
 
                    if (argp - arguments == argc - 1 || **argp == '-')
                        number = 1;
+                   
+                   else {
+                       if (strcmp(*argp, "all") == 0)
+                           number = -1;
 
-                   else if (!(number = atoi(*argp++)))
-                       adios (NULL, "missing argument to %s", argp[-2]);
+                       else if (!(number = atoi(*argp)))
+                           adios (NULL, "missing argument to %s", argp[-2]);
+
+                       argp++;
+                   }
 
                    delete = number;
                    continue;
@@ -200,6 +211,14 @@ main (int argc, char **argv)
                case APPENDSW:          /* append annotations instead of default prepend */
                    append = 1;
                    continue;
+
+               case PRESERVESW:        /* preserve access and modification times on annotated message */
+                   annopreserve(1);
+                   continue;
+
+               case NOPRESERVESW:      /* don't preserve access and modification times on annotated message (default) */
+                   annopreserve(0);
+                   continue;
            }
        }
        if (*cp == '+' || *cp == '@') {
@@ -214,9 +233,8 @@ main (int argc, char **argv)
             */
            if (nummsgs >= maxmsgs) {
                maxmsgs += MAXMSGS;
-               if (!(msgs = (char **) realloc (msgs,
-                       (size_t) (maxmsgs * sizeof(*msgs)))))
-                   adios (NULL, "unable to reallocate msgs storage");
+               msgs = (char **) mh_xrealloc (msgs,
+                   (size_t) (maxmsgs * sizeof(*msgs)));
            }
            msgs[nummsgs++] = cp;
        }