[comp.mail.mh] Creating Hierarchical folders in MH

marvit%hplpm@HPLABS.HP.COM (Peter Marvit) (01/10/90)

I forgot which mailing list this should go, so mh-users it will be.  John
Romine, if you're listening, did you get my full package of patches via
ftp? 

Below is a context diff for sbr/makedir.c which allows automatic creation
of hierarchical folders of nearly arbitrary depth.  It is ifdef'ed for
BSD42 and hpux, since it's been testing only on those systems.  However, it
should work on others.

	-Peter "Shreds and patches, a wand'ring minstrel I" Marvit

------------------------------ CUT HERE -------------------------------
*** makedir.c.ORIG	Thu Oct 29 15:00:45 1987
--- makedir.c	Wed Oct 11 13:45:30 1989
***************
*** 1,4
  /* makedir.c - make a directory */
  
  #include "../h/mh.h"
  #include <stdio.h>

--- 1,7 -----
  /* makedir.c - make a directory */
+ /* Originally, this was just a dumb create.  A recursive directory create was
+    added for BSD and HP-UX (since that's where it has been tested).  
+ */
  
  #include "../h/mh.h"
  #include <stdio.h>
***************
*** 3,9
  #include "../h/mh.h"
  #include <stdio.h>
  
! 
  makedir (dir)
  register char *dir;
  {

--- 6,17 -----
  #include "../h/mh.h"
  #include <stdio.h>
  
! #if defined (BSD42)  || defined (hpux)
! #include <errno.h>
! #include <sys/param.h>
! #include <sys/file.h>
! #endif BDS42
! 	
  makedir (dir)
  register char *dir;
  {
***************
*** 9,14
  {
      int     pid;
      register char  *cp;
  
      m_update ();
      (void) fflush (stdout);

--- 17,26 -----
  {
      int     pid;
      register char  *cp;
+ #if defined (BSD42)  || defined (hpux)
+     register char  *c;
+     register char path[MAXPATHLEN];
+ #endif BSD42
  
      m_update ();
      (void) fflush (stdout);
***************
*** 13,19
      m_update ();
      (void) fflush (stdout);
  
! #ifdef	BSD42
      if (getuid () == geteuid ()) {
  	if (mkdir (dir, 0755) == NOTOK) {
  	    advise (dir, "unable to create directory");

--- 25,31 -----
      m_update ();
      (void) fflush (stdout);
  
! #ifdef	BSD42 ||  defined (hpux)
      if (getuid () == geteuid ()) {
  	    c = strcpy(path, dir);     
  
***************
*** 15,24
  
  #ifdef	BSD42
      if (getuid () == geteuid ()) {
! 	if (mkdir (dir, 0755) == NOTOK) {
! 	    advise (dir, "unable to create directory");
! 	    return 0;
! 	}
      }
      else
  #endif	BSD42

--- 27,53 -----
  
  #ifdef	BSD42 ||  defined (hpux)
      if (getuid () == geteuid ()) {
! 	    c = strcpy(path, dir);     
! 
! 	    while ((c = strchr((c + 1), '/')) != NULL) {	
! 		    *c = (char)0;
! 		    if (access(path, X_OK)) {
! 			    if (errno != ENOENT){
! 				    advise (dir, "unable to create directory");
! 				    return 0;
! 			    }			    
! 			    if (mkdir(path, 0775)) {
! 				    advise (dir, "unable to create directory");
! 				    return 0;
! 			    }
! 		    }
! 		    *c = '/';
! 	    }
!  
! 	    if (mkdir (dir, 0755) == NOTOK) {
! 		    advise (dir, "unable to create directory");
! 		    return 0;
! 	    }
      }
      else
  #endif	BSD42