nmh-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nmh-commits] nmh ./ChangeLog sbr/m_draft.c sbr/utils.c uip/f...


From: Josh Bressers
Subject: [Nmh-commits] nmh ./ChangeLog sbr/m_draft.c sbr/utils.c uip/f...
Date: Mon, 20 Feb 2006 03:09:08 +0000

CVSROOT:        /sources/nmh
Module name:    nmh
Branch:         
Changes by:     Josh Bressers <address@hidden>  06/02/20 03:09:08

Modified files:
        .              : ChangeLog 
        sbr            : m_draft.c utils.c 
        uip            : folder.c inc.c mhstoresbr.c popi.c refile.c 

Log message:
        * sbr/m_draft.c, sbr/utils.c, uip/folder.c, uip/inc.c, uip/mhstoresbr.c,
        uip/popi.c, uip/refile.c: Add create_folder() function, replacing 
duplicate
        code during folder creation.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/ChangeLog.diff?tr1=1.234&tr2=1.235&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/sbr/m_draft.c.diff?tr1=1.3&tr2=1.4&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/sbr/utils.c.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/folder.c.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/inc.c.diff?tr1=1.20&tr2=1.21&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/mhstoresbr.c.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/popi.c.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/refile.c.diff?tr1=1.9&tr2=1.10&r1=text&r2=text

Patches:
Index: nmh/ChangeLog
diff -u nmh/ChangeLog:1.234 nmh/ChangeLog:1.235
--- nmh/ChangeLog:1.234 Sat Feb 18 16:26:37 2006
+++ nmh/ChangeLog       Mon Feb 20 03:09:07 2006
@@ -1,13 +1,19 @@
+2006-02-19  Josh Bressers <address@hidden>
+
+       * sbr/m_draft.c, sbr/utils.c, uip/folder.c, uip/inc.c,
+       uip/mhstoresbr.c, uip/popi.c, uip/refile.c: Add create_folder()
+       function, replacing duplicate code during folder creation.
+
 2006-02-18  David Levine <address@hidden>
 
-        * h/mime.h, h/mhparse.h, uip/mhbuildsbr.c, uip/mhfree.c,
-        man/mhbuild.man, docs/TODO:  added support for an optional
-        Content-Disposition header in mhbuild (only).  Its contents
-        are supplied between {}, positioned after the optional [], in
-        a mhbuild directive.  If the contents do not contain a
-        "filename=" parameter, and the directive has a filename, or
-        something else that ends with "name=", then that will be used
-        to add a "filename=" parameter to the header.
+       * h/mime.h, h/mhparse.h, uip/mhbuildsbr.c, uip/mhfree.c,
+       man/mhbuild.man, docs/TODO:  added support for an optional
+       Content-Disposition header in mhbuild (only).  Its contents
+       are supplied between {}, positioned after the optional [], in
+       a mhbuild directive.  If the contents do not contain a
+       "filename=" parameter, and the directive has a filename, or
+       something else that ends with "name=", then that will be used
+       to add a "filename=" parameter to the header.
 
 2006-02-12  David Levine <address@hidden>
 
Index: nmh/sbr/m_draft.c
diff -u nmh/sbr/m_draft.c:1.3 nmh/sbr/m_draft.c:1.4
--- nmh/sbr/m_draft.c:1.3       Tue Sep 30 16:58:43 2003
+++ nmh/sbr/m_draft.c   Mon Feb 20 03:09:08 2006
@@ -2,7 +2,7 @@
 /*
  * m_draft.c -- construct the name of a draft message
  *
- * $Id: m_draft.c,v 1.3 2003/09/30 16:58:43 gbburkhardt Exp $
+ * $Id: m_draft.c,v 1.4 2006/02/20 03:09:08 bress Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -34,16 +34,8 @@
     
     chdir (m_maildir (""));
     strncpy (buffer, m_maildir (folder), sizeof(buffer));
-    if (stat (buffer, &st) == -1) {
-       if (errno != ENOENT)
-           adios (buffer, "error on folder");
-       cp = concat ("Create folder \"", buffer, "\"? ", NULL);
-       if (!getanswer (cp))
-           done (0);
-       free (cp);
-       if (!makedir (buffer))
-           adios (NULL, "unable to create folder %s", buffer);
-    }
+
+    create_folder (buffer, 0, done);
 
     if (chdir (buffer) == -1)
        adios (buffer, "unable to change directory to");
Index: nmh/sbr/utils.c
diff -u nmh/sbr/utils.c:1.5 nmh/sbr/utils.c:1.6
--- nmh/sbr/utils.c:1.5 Fri Jan  6 21:51:44 2006
+++ nmh/sbr/utils.c     Mon Feb 20 03:09:08 2006
@@ -2,7 +2,7 @@
 /*
  * utils.c -- various utility routines
  *
- * $Id: utils.c,v 1.5 2006/01/06 21:51:44 bress Exp $
+ * $Id: utils.c,v 1.6 2006/02/20 03:09:08 bress Exp $
  *
  * This code is Copyright (c) 2006, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -12,6 +12,7 @@
 #include <h/mh.h>
 #include <h/utils.h>
 #include <stdlib.h>
+#include <errno.h>
 
 /*
  * Safely call malloc
@@ -111,3 +112,32 @@
 
     return cp;
 }
+
+/*
+ * create_folder
+ *      Check to see if a folder exists, if not, prompt the user to create
+ *      it.
+ */
+void create_folder(char *folder, int autocreate, void (*done_callback)())
+{
+    struct stat st;
+    extern int errno;
+    char *cp;
+
+    if (stat (folder, &st) == -1) {
+        if (errno != ENOENT)
+            adios (folder, "error on folder");
+        if (autocreate == 0) {
+            /* ask before creating folder */
+            cp = concat ("Create folder \"", folder, "\"? ", NULL);
+            if (!getanswer (cp))
+                done_callback (1);
+            free (cp);
+        } else if (autocreate == -1) {
+            /* do not create, so exit */
+            done_callback (1);
+        }
+        if (!makedir (folder))
+            adios (NULL, "unable to create folder %s", folder);
+    }
+}
Index: nmh/uip/folder.c
diff -u nmh/uip/folder.c:1.8 nmh/uip/folder.c:1.9
--- nmh/uip/folder.c:1.8        Mon Jan  2 03:25:18 2006
+++ nmh/uip/folder.c    Mon Feb 20 03:09:08 2006
@@ -4,7 +4,7 @@
  *             -- push/pop a folder onto/from the folder stack
  *             -- list the folder stack
  *
- * $Id: folder.c,v 1.8 2006/01/02 03:25:18 bress Exp $
+ * $Id: folder.c,v 1.9 2006/02/20 03:09:08 bress Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -393,22 +393,7 @@
         * Check if folder exists.  If not, then see if
         * we should create it, or just exit.
         */
-       if (stat (strncpy (buf, m_maildir (folder), sizeof(buf)), &st) == -1) {
-           if (errno != ENOENT)
-               adios (buf, "error on folder");
-           if (fcreat == 0) {
-               /* ask before creating folder */
-               cp = concat ("Create folder \"", buf, "\"? ", NULL);
-               if (!getanswer (cp))
-                   done (1);
-               free (cp);
-           } else if (fcreat == -1) {
-               /* do not create, so exit */
-               done (1);
-           }
-           if (!makedir (buf))
-               adios (NULL, "unable to create folder %s", buf);
-       }
+        create_folder (m_maildir (folder), fcreat, done);
 
        if (get_folder_info (folder, msg) && argfolder) {
            /* update current folder */
Index: nmh/uip/inc.c
diff -u nmh/uip/inc.c:1.20 nmh/uip/inc.c:1.21
--- nmh/uip/inc.c:1.20  Thu Jan 27 16:34:20 2005
+++ nmh/uip/inc.c       Mon Feb 20 03:09:08 2006
@@ -2,7 +2,7 @@
 /*
  * inc.c -- incorporate messages from a maildrop into a folder
  *
- * $Id: inc.c,v 1.20 2005/01/27 16:34:20 opk Exp $
+ * $Id: inc.c,v 1.21 2006/02/20 03:09:08 bress Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -562,16 +562,10 @@
     if ((maildir_copy = strdup(maildir)) == (char *)0)
         adios (maildir, "error allocating memory to copy maildir");
 
-    if (stat (maildir, &st) == NOTOK) {
-       if (errno != ENOENT)
-           adios (maildir, "error on folder");
-       cp = concat ("Create folder \"", maildir, "\"? ", NULL);
-       if (noisy && !getanswer (cp))
-           done (1);
-       free (cp);
-       if (!makedir (maildir))
-           adios (NULL, "unable to create folder %s", maildir);
-    }
+    if (noisy)
+        create_folder(maildir, 0, done);
+    else
+        done (1);
 
     if (chdir (maildir) == NOTOK)
        adios (maildir, "unable to change directory to");
Index: nmh/uip/mhstoresbr.c
diff -u nmh/uip/mhstoresbr.c:1.11 nmh/uip/mhstoresbr.c:1.12
--- nmh/uip/mhstoresbr.c:1.11   Fri Jan  6 21:51:44 2006
+++ nmh/uip/mhstoresbr.c        Mon Feb 20 03:09:08 2006
@@ -2,7 +2,7 @@
 /*
  * mhstoresbr.c -- routines to save/store the contents of MIME messages
  *
- * $Id: mhstoresbr.c,v 1.11 2006/01/06 21:51:44 bress Exp $
+ * $Id: mhstoresbr.c,v 1.12 2006/02/20 03:09:08 bress Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -75,7 +75,6 @@
 static int ct_compar (CT *, CT *);
 static int store_content (CT, CT);
 static int output_content_file (CT, int);
-static int check_folder (char *);
 static int output_content_folder (char *, char *);
 static int parse_format_string (CT, char *, char *, int, char *);
 static void get_storeproc (CT);
@@ -571,8 +570,7 @@
            folder = getfolder (1);
 
        /* Check if folder exists */
-       if (check_folder (folder) == NOTOK)
-           return NOTOK;
+       create_folder(folder, 0, exit);
 
        /* Record the folder name */
        ct->c_folder = add (folder, NULL);
@@ -864,47 +862,6 @@
 
 
 /*
- * Check if folder exists, and create
- * if necessary.
- */
-
-static int
-check_folder (char *folder)
-{
-    char *folderdir;
-    struct stat st;
-
-    /* expand path to the folder */
-    folderdir = m_mailpath (folder);
-
-    /* Check if folder exists */
-    if (stat (folderdir, &st) == NOTOK) {
-       int answer;
-       char *ep;
-
-       if (errno != ENOENT) {
-           advise (folderdir, "error on folder");
-           return NOTOK;
-       }
-
-       ep = concat ("Create folder \"", folderdir, "\"? ", NULL);
-       answer = getanswer (ep);
-       free (ep);
-
-       if (!answer)
-           return NOTOK;
-
-       if (!makedir (folderdir)) {
-           advise (NULL, "unable to create folder %s", folderdir);
-           return NOTOK;
-       }
-    }
-
-    return OK;
-}
-
-
-/*
  * Add a file to a folder.
  *
  * Return the new message number of the file
Index: nmh/uip/popi.c
diff -u nmh/uip/popi.c:1.9 nmh/uip/popi.c:1.10
--- nmh/uip/popi.c:1.9  Mon Jan  2 03:17:42 2006
+++ nmh/uip/popi.c      Mon Feb 20 03:09:08 2006
@@ -2,7 +2,7 @@
 /*
  * popi.c -- POP initiator for MPOP
  *
- * $Id: popi.c,v 1.9 2006/01/02 03:17:42 bress Exp $
+ * $Id: popi.c,v 1.10 2006/02/20 03:09:08 bress Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -229,16 +229,7 @@
        folder = getfolder (0);
     maildir = m_maildir (folder);
 
-    if (stat (maildir, &st) == NOTOK) {
-       if (errno != ENOENT)
-           adios (maildir, "error on folder");
-       cp = concat ("Create folder \"", maildir, "\"? ", NULL);
-       if (noisy && !getanswer (cp))
-           done (1);
-       free (cp);
-       if (!makedir (maildir))
-           adios (NULL, "unable to create folder %s", maildir);
-    }
+    create_folder(maildir, 0, done);
 
     if (chdir (maildir) == NOTOK)
        adios (maildir, "unable to change directory to");
Index: nmh/uip/refile.c
diff -u nmh/uip/refile.c:1.9 nmh/uip/refile.c:1.10
--- nmh/uip/refile.c:1.9        Mon Jan  2 03:25:18 2006
+++ nmh/uip/refile.c    Mon Feb 20 03:09:08 2006
@@ -3,7 +3,7 @@
  * refile.c -- move or link message(s) from a source folder
  *          -- into one or more destination folders
  *
- * $Id: refile.c,v 1.9 2006/01/02 03:25:18 bress Exp $
+ * $Id: refile.c,v 1.10 2006/02/20 03:09:08 bress Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -312,16 +312,7 @@
        chdir (m_maildir (""));
        strncpy (nmaildir, m_maildir (fp->f_name), sizeof(nmaildir));
 
-       if (stat (nmaildir, &st) == NOTOK) {
-           if (errno != ENOENT)
-               adios (nmaildir, "error on folder");
-           cp = concat ("Create folder \"", nmaildir, "\"? ", NULL);
-           if (!getanswer (cp))
-               done (1);
-           free (cp);
-           if (!makedir (nmaildir))
-               adios (NULL, "unable to create folder %s", nmaildir);
-       }
+    create_folder (nmaildir, 0, done);
 
        if (chdir (nmaildir) == NOTOK)
            adios (nmaildir, "unable to change directory to");




reply via email to

[Prev in Thread] Current Thread [Next in Thread]