nmh-commits
[Top][All Lists]
Advanced

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

[Nmh-commits] nmh h/utils.h sbr/utils.c uip/comp.c uip/dist.c...


From: Joel Reicher
Subject: [Nmh-commits] nmh h/utils.h sbr/utils.c uip/comp.c uip/dist.c...
Date: Fri, 14 Apr 2006 14:10:16 +0000

CVSROOT:        /sources/nmh
Module name:    nmh
Branch:         
Changes by:     Joel Reicher <address@hidden>   06/04/14 14:10:16

Modified files:
        h              : utils.h 
        sbr            : utils.c 
        uip            : comp.c dist.c forw.c 

Log message:
        Created function open_form() to open form file or fallback to default
        components file, with error handling. Replaced duplicated code with call
        to this function.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/h/utils.h.diff?tr1=1.7&tr2=1.8&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/sbr/utils.c.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/comp.c.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/dist.c.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/nmh/nmh/uip/forw.c.diff?tr1=1.7&tr2=1.8&r1=text&r2=text

Patches:
Index: nmh/h/utils.h
diff -u nmh/h/utils.h:1.7 nmh/h/utils.h:1.8
--- nmh/h/utils.h:1.7   Tue Apr 11 14:09:11 2006
+++ nmh/h/utils.h       Fri Apr 14 14:10:15 2006
@@ -2,7 +2,7 @@
 /*
  * utils.h -- utility prototypes
  *
- * $Id: utils.h,v 1.7 2006/04/11 14:09:11 jjr Exp $
+ * $Id: utils.h,v 1.8 2006/04/14 14:10:15 jjr Exp $
  */
 
 void *mh_xmalloc(size_t);
@@ -18,3 +18,4 @@
 };
 
 void app_msgarg(struct msgs_array *, char *);
+int open_form(char **, char *);
Index: nmh/sbr/utils.c
diff -u nmh/sbr/utils.c:1.8 nmh/sbr/utils.c:1.9
--- nmh/sbr/utils.c:1.8 Tue Apr 11 14:09:11 2006
+++ nmh/sbr/utils.c     Fri Apr 14 14:10:16 2006
@@ -2,7 +2,7 @@
 /*
  * utils.c -- various utility routines
  *
- * $Id: utils.c,v 1.8 2006/04/11 14:09:11 jjr Exp $
+ * $Id: utils.c,v 1.9 2006/04/14 14:10:16 jjr 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 <fcntl.h>
 #include <errno.h>
 
 /*
@@ -184,3 +185,19 @@
                msgs->msgs = mh_xrealloc(msgs->msgs, 
(msgs->max+=MAXMSGS)*sizeof(*msgs->msgs));
        msgs->msgs[msgs->size++] = cp;
 }
+
+/* Open a form or components file */
+int
+open_form(char **form, char *def)
+{
+       int in;
+       if (*form) {
+               if ((in = open (etcpath (*form), O_RDONLY)) == NOTOK)
+                       adios (*form, "unable to open form file");
+       } else {
+               if ((in = open (etcpath (def), O_RDONLY)) == NOTOK)
+                       adios (def, "unable to open default components file");
+               *form = def;
+       }
+       return in;
+}
Index: nmh/uip/comp.c
diff -u nmh/uip/comp.c:1.4 nmh/uip/comp.c:1.5
--- nmh/uip/comp.c:1.4  Tue Jul  2 22:09:14 2002
+++ nmh/uip/comp.c      Fri Apr 14 14:10:16 2006
@@ -2,7 +2,7 @@
 /*
  * comp.c -- compose a message
  *
- * $Id: comp.c,v 1.4 2002/07/02 22:09:14 kenh Exp $
+ * $Id: comp.c,v 1.5 2006/04/14 14:10:16 jjr 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
@@ -10,6 +10,7 @@
  */
 
 #include <h/mh.h>
+#include <h/utils.h>
 #include <fcntl.h>
 
 static struct swit switches[] = {
@@ -227,19 +228,8 @@
 
        if ((in = open (form = getcpy (m_name (mp->lowsel)), O_RDONLY)) == 
NOTOK)
            adios (form, "unable to open message");
-    } else {
-       /*
-        * Open a component or forms file
-        */
-       if (form) {
-           if ((in = open (etcpath (form), O_RDONLY)) == NOTOK)
-               adios (form, "unable to open form file");
-       } else {
-           if ((in = open (etcpath (components), O_RDONLY)) == NOTOK)
-               adios (components, "unable to open default components file");
-           form = components;
-       }
-    }
+    } else
+       in = open_form(&form, components);
 
 try_it_again:
     strncpy (drft, m_draft (dfolder, file, use, &isdf), sizeof(drft));
Index: nmh/uip/dist.c
diff -u nmh/uip/dist.c:1.4 nmh/uip/dist.c:1.5
--- nmh/uip/dist.c:1.4  Tue Jul  2 22:09:14 2002
+++ nmh/uip/dist.c      Fri Apr 14 14:10:16 2006
@@ -2,7 +2,7 @@
 /*
  * dist.c -- re-distribute a message
  *
- * $Id: dist.c,v 1.4 2002/07/02 22:09:14 kenh Exp $
+ * $Id: dist.c,v 1.5 2006/04/14 14:10:16 jjr 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
@@ -10,6 +10,7 @@
  */
 
 #include <h/mh.h>
+#include <h/utils.h>
 #include <fcntl.h>
 
 static struct swit switches[] = {
@@ -195,14 +196,7 @@
     if (file && (msg || folder))
        adios (NULL, "can't mix files and folders/msgs");
 
-    if (form) {
-       if ((in = open (etcpath (form), O_RDONLY)) == NOTOK)
-           adios (form, "unable to open form file");
-    } else {
-       if ((in = open (etcpath (distcomps), O_RDONLY)) == NOTOK)
-           adios (distcomps, "unable to open default components file");
-       form = distcomps;
-    }
+    in = open_form(&form, distcomps);
 
 try_it_again:
     strncpy (drft, m_draft (dfolder, dmsg, NOUSE, &isdf), sizeof(drft));
Index: nmh/uip/forw.c
diff -u nmh/uip/forw.c:1.7 nmh/uip/forw.c:1.8
--- nmh/uip/forw.c:1.7  Mon Jan  2 03:17:42 2006
+++ nmh/uip/forw.c      Fri Apr 14 14:10:16 2006
@@ -2,7 +2,7 @@
 /*
  * forw.c -- forward a message, or group of messages.
  *
- * $Id: forw.c,v 1.7 2006/01/02 03:17:42 bress Exp $
+ * $Id: forw.c,v 1.8 2006/04/14 14:10:16 jjr 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,16 +393,8 @@
        if (!form)
            form = digestcomps;
        in = build_form (form, digest, volume, issue);
-    } else {
-       if (form) {
-           if ((in = open (etcpath (form), O_RDONLY)) == NOTOK)
-               adios (form, "unable to open form file");
-       } else {
-           if ((in = open (etcpath (forwcomps), O_RDONLY)) == NOTOK)
-               adios (forwcomps, "unable to open default components file");
-           form = forwcomps;
-       }
-    }
+    } else
+       in = open_form(&form, forwcomps);
 
     if ((out = creat (drft, m_gmprot ())) == NOTOK)
        adios (drft, "unable to create");




reply via email to

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