#ifndef _mh_folderP_h_
#define _mh_folderP_h_

#include <sys/param.h>
#include <sys/types.h>
#include <sys/dir.h>
#include <sys/stat.h>
#include <stdio.h>
#include <sys/file.h>
#include <errno.h>
#include "assert.h"
#include "bool.h"
#include "folder.h"
#include "foldert.h"
#include "memory.h"
#include "al.h"
#include "mh_folder.h"

#ifndef BSD
#define CDIRSIZ  DIRSIZ       /* max directory name length if not using BSD */
#else
#define CDIRSIZ  MAXNAMLEN    /* max directory name length if using BSD     */
#endif

#define BUFSIZE  (512 + CDIRSIZ)
#define OR ||

#ifndef AlMHfold_DEBUG
#define AlMHfold_DEBUG  0
#endif

#define AlMHfolder_bool_str(bool) \
          (bool == Bool_TRUE) ? "Bool_TRUE" : "Bool_FALSE"

#define AlMHfolder_file_err(errno) \
           ((errno == EBADF) \
	    ? "[EBADF]" \
	    : ((errno == EFAULT) \
	       ? "[EFAULT]" \
	       : ((errno == EIO) \
		  ? "[EIO]" \
		  : ((errno == EINTR) \
		     ? "[EINTR]" \
		     : ((errno == EINVAL) \
			? "[EINVAL]" \
			: ((errno == EWOULDBLOCK) \
			   ? "[EWOULDBLOCK]" \
			   : "Unknown Error Code"))))))

#if (AlMHfold_DEBUG == 1)
#define AlMHfolder_debug(str)   printf("%s\n", str)
#define AlMHfolder_debug2(s1, s2)   printf("%s %s\n", s1, s2)
#else
#define AlMHfolder_debug(str) 
#define AlMHfolder_debug2(s1, s2)  
#endif

#ifdef __STDC__
extern char *getenv(const char *);
#else
extern char *getenv();
#endif

#define CVT_FOLDER_TO_FILE(foldername, buffer) \
     do {strcpy(buffer, getenv("HOME"));strcat(buffer,"/Mail/");\
         strcat(buffer,foldername);} while(0)


/****************************************************************************/
struct dir_ob 
 { char *name_buffer;
   char *folder_string;    /* name of current folder for mh */
   Bool opened;            /* flags if a opendir has already been performed */
   char *pathname;         /* full path of a directory */
   int bufsize;  /* amount of memory currently allocated to the name_buffer  */
   char *nbp;    /* current index into the name_buffer (name buffer pointer) */
   int  fd;      /* file data pointer (file id) */
   DIR *dirp;    /* DIR ob pointer (BSD id) */   /* compatible ? */
   struct dir_ob *next; /* linked list to siblings and children (stack)*/
 };

typedef struct mh_data_struct
 { char *file_buffer;
   char *filename;
   struct dir_ob *dir_ob_list;  /* push-down stack of dir_ob */
 } AlMHdata;

#endif     /* end of  #ifndef _mh_folderP_h_  */
