*** htfile.c	Sun Nov 24 01:45:22 1996
--- i:htfile.c	Mon Jul 17 19:28:29 1995
***************
*** 17,29 ****
  */
  
  #ifndef VMS
! //#define LONG_LIST  /* Define this for long style unix listings (ls -l) */
  /* #define NO_PARENT_DIR_REFERENCE  /* Define this for no parent links */
  #endif /* !VMS */
  
- #include "HTAccess.h"
  #include "HTUtils.h"
  #include "HTFile.h"		/* Implemented here */
  
  #define INFINITY 512		/* file name length @@ FIXME */
  #define MULTI_SUFFIX ".multi"   /* Extension for scanning formats */
--- 17,38 ----
  */
  
  #ifndef VMS
! /* #define LONG_LIST  /* Define this for long style unix listings (ls -l) */
  /* #define NO_PARENT_DIR_REFERENCE  /* Define this for no parent links */
  #endif /* !VMS */
  
  #include "HTUtils.h"
  #include "HTFile.h"		/* Implemented here */
+ #ifdef VMS
+ #include <stat.h>
+ #endif /* VMS */
+ 
+ #ifndef VMS
+ #ifdef LONG_LIST
+ #include <pwd.h>
+ #include <grp.h>
+ #endif /* LONG_LIST */
+ #endif /* !VMS */
    
  #define INFINITY 512		/* file name length @@ FIXME */
  #define MULTI_SUFFIX ".multi"   /* Extension for scanning formats */
***************
*** 32,49 ****
  
  #define FREE(x) if (x) {free(x); x = NULL;}
  
  #include "HTParse.h"
  #include "tcp.h"
  #include "HTTCP.h"
  #include "HTFTP.h"
! #include "HTGOPHER.h"
  #include "HTAnchor.h"
  #include "HTAtom.h"
  #include "HTWriter.h"
  #include "HTFWriter.h"
  #include "HTInit.h"
  #include "HTBTree.h"
! #include <dirent.h>
  
  typedef struct _HTSuffix {
  	char *		suffix;
--- 41,65 ----
  
  #define FREE(x) if (x) {free(x); x = NULL;}
  
+ #ifdef VMS
+ #include "HTVMSUtils.h"
+ #endif /* VMS */
+ 
  #include "HTParse.h"
  #include "tcp.h"
  #include "HTTCP.h"
+ #ifndef DECNET
  #include "HTFTP.h"
! #endif /* !DECNET */
  #include "HTAnchor.h"
  #include "HTAtom.h"
  #include "HTWriter.h"
  #include "HTFWriter.h"
  #include "HTInit.h"
  #include "HTBTree.h"
! 
! #include "LYexit.h"
! #include "LYLeaks.h"
  
  typedef struct _HTSuffix {
  	char *		suffix;
***************
*** 61,76 ****
  #endif /* NGROUPS */
  
  
! #define STRUCT_DIRENT struct direct
! 
! #define GOT_READ_DIR 1
  #define STRUCT_DIRENT struct dirent
  
  #include "HTML.h"		/* For directory object building */
  
- #include "LYexit.h"
- #include "LYLeaks.h"
- 
  #define PUTC(c) (*target->isa->put_character)(target, c)
  #define PUTS(s) (*target->isa->put_string)(target, s)
  #define START(e) (*target->isa->start_element)(target, e, 0, 0)
--- 77,90 ----
  #endif /* NGROUPS */
  
  
! #ifdef USE_DIRENT		/* Set this for Sys V systems */
  #define STRUCT_DIRENT struct dirent
+ #else
+ #define STRUCT_DIRENT struct direct
+ #endif /* USE_DIRENT */
  
  #include "HTML.h"		/* For directory object building */
  
  #define PUTC(c) (*target->isa->put_character)(target, c)
  #define PUTS(s) (*target->isa->put_string)(target, s)
  #define START(e) (*target->isa->start_element)(target, e, 0, 0)
***************
*** 88,97 ****
--- 102,123 ----
  
  PUBLIC int HTDirAccess = HT_DIR_OK;
  
+ #ifdef DIRED_SUPPORT
+ PUBLIC int HTDirReadme = HT_DIR_README_NONE;
+ #define FILES_FIRST 1
+ #define MIXED_STYLE 2
+ extern BOOLEAN lynx_edit_mode;
+ extern BOOLEAN dir_list_style;
+ #else
  PUBLIC int HTDirReadme = HT_DIR_README_TOP;
+ #endif /* DIRED_SUPPORT */
  
  PRIVATE char *HTMountRoot = "/Net/";		/* Where to find mounts */
+ #ifdef VMS
+ PRIVATE char *HTCacheRoot = "/WWW$SCRATCH";   /* Where to cache things */
+ #else
  PRIVATE char *HTCacheRoot = "/tmp/W3_Cache_";   /* Where to cache things */
+ #endif /* VMS */
  
  /* PRIVATE char *HTSaveRoot  = "$(HOME)/WWW/";*/    /* Where to save things */
  
***************
*** 195,200 ****
--- 221,229 ----
  }
  
  
+ 
+ 
+ 
  /*	Send README file
  **
  **  If a README file exists, then it is inserted into the document here.
***************
*** 216,224 ****
  	HTStructuredClass targetClass;
  	
  	targetClass =  *target->isa;	/* (Can't init agregate in K&R) */
- 
- { extern void *vp_msdosmem;extern void **vpp_msdosmem;vp_msdosmem = NULL;vpp_msdosmem = NULL;}
- 
  	START(HTML_PRE);
  	for(;;){
  	    char c = fgetc(fp);
--- 245,250 ----
***************
*** 247,253 ****
  #endif /* GOT_READ_DIR */
  
  
- #ifdef FIXME
  /*	Make the cache file name for a W3 document
  **	------------------------------------------
  **	Make up a suitable name for saving the node in
--- 273,278 ----
***************
*** 275,282 ****
      FREE(host);
      return result;
  }
- #endif //fixme
  
  /*	Open a file for write, creating the path
  **	----------------------------------------
  */
--- 300,307 ----
      FREE(host);
      return result;
  }
  
+ 
  /*	Open a file for write, creating the path
  **	----------------------------------------
  */
***************
*** 310,322 ****
  	if ((0==strcasecomp(host, HTHostName())) ||
  	    (0==strcasecomp(host, "localhost")) || !*host) {
  	    FREE(host);
- #ifdef DT
  	    if (TRACE) fprintf(stderr, "Node `%s' means path `%s'\n", name, path);
- #endif
-             {
-                  extern void urltodos(char *);
-                  urltodos(path);
-             }
  	    return(path);
  	} else {
  	    char * result = (char *)malloc(
--- 335,341 ----
***************
*** 325,334 ****
  	    sprintf(result, "%s%s%s", "/Net/", host, path);
  	    FREE(host);
              FREE(path);
- #ifdef DT
  	    if (TRACE) fprintf(stderr, "Node `%s' means file `%s'\n", name, result);
- #endif
- 
  	    return result;
  	}
      } else {  /* other access */
--- 344,350 ----
***************
*** 382,391 ****
  	if (result == NULL) outofmem(__FILE__, "WWW_nameOfFile");
  	sprintf(result, "file://%s%s", HTHostName(), name);
      }
- #ifdef DT
      if (TRACE) fprintf(stderr, "File `%s'\n\tmeans node `%s'\n", name, result);
- #endif
- 
      return result;
  }
  
--- 398,404 ----
***************
*** 537,547 ****
  	suff = HTList_objectAt(HTSuffixes, i);
  	ls = strlen(suff->suffix);
  	if ((ls <= lf) && 0==strcmp(suff->suffix, filename + lf - ls)) {
- #ifdef DT
  	    if (TRACE) fprintf(stderr, "File: Value of %s is %.3f\n",
  			       filename, suff->quality);
- #endif
- 
  	    return suff->quality;		/* OK -- found */
  	}
      }
--- 550,557 ----
***************
*** 569,577 ****
  #ifdef PCNFS
  #define NO_GROUPS
  #endif /* PCNFS */
- #ifdef MSDOS
- #define NO_GROUPS
- #endif /* MSDOS */
  
  PUBLIC BOOL HTEditable ARGS1 (CONST char *,filename)
  {
--- 579,584 ----
***************
*** 590,596 ****
      ngroups = getgroups(NGROUPS, groups);	/* Groups to which I belong  */
      myUid = geteuid();				/* Get my user identifier */
  
- #ifdef DT
      if (TRACE) {
          int i;
  	fprintf(stderr, 
--- 597,602 ----
***************
*** 601,607 ****
  	for (i=0; i<ngroups; i++) fprintf(stderr, " %d", groups[i]);
  	fprintf(stderr, ")\n");
      }
- #endif
  
      if (fileStatus.st_mode & 0002)		/* I can write anyway? */
      	return YES;
--- 607,612 ----
***************
*** 617,626 ****
  		return YES;
  	}
      }
- #ifdef DT
      if (TRACE) fprintf(stderr, "\tFile is not editable.\n");
- #endif
- 
      return NO;					/* If no excuse, can't do */
  #endif /* NO_GROUPS */
  }
--- 622,628 ----
***************
*** 638,644 ****
      CONST char * addr = HTAnchor_address((HTAnchor*)anchor);
      char *  localname = HTLocalName(addr);
      
!     FILE* fp = fopen(localname, "wb");
      if (!fp) return NULL;
      
      return HTFWriter_new(fp);
--- 640,646 ----
      CONST char * addr = HTAnchor_address((HTAnchor*)anchor);
      char *  localname = HTLocalName(addr);
      
!     FILE* fp = fopen(localname, "w");
      if (!fp) return NULL;
      
      return HTFWriter_new(fp);
***************
*** 653,661 ****
  		 CONST char *,  entry)
  {
      char * relative;
!     char * escaped;
  
-     escaped = HTEscape(entry, URL_XPALPHAS);
  
  	/* handle extra slash at end of path */
      if(*tail == '\0') {
--- 655,662 ----
  		 CONST char *,  entry)
  {
      char * relative;
!     char * escaped = HTEscape(entry, URL_XPALPHAS);
  
  
  	/* handle extra slash at end of path */
      if(*tail == '\0') {
***************
*** 680,708 ****
  		 HTAnchor * , anchor)
  
  {
- 
      char * logical = HTAnchor_address(anchor);
      char * path = HTParse(logical, "", PARSE_PATH + PARSE_PUNCTUATION);
      char * current;
  
- //printf("\n\n%s %s\n\n",path,current);
- 
      current = strrchr(path, '/');	/* last part or "" */
  
      {
        char * printable = NULL;
  
        StrAllocCopy(printable, (current + 1));
! 
! {extern void *vp_msdosmem;extern void **vpp_msdosmem;vp_msdosmem = NULL;vpp_msdosmem = NULL;}
  
-       START(HTML_HTML);
- {extern void *vp_msdosmem;extern void **vpp_msdosmem;vp_msdosmem = NULL;vpp_msdosmem = NULL;}
        START(HTML_HEAD);
        PUTS("\n");
        HTUnEscape(printable);
- 
- { extern void *vp_msdosmem;extern void **vpp_msdosmem;vp_msdosmem = NULL;vpp_msdosmem = NULL;}
        START(HTML_TITLE);
        PUTS(*printable ? printable : "Welcome ");
        PUTS(" directory");
--- 681,704 ----
  		 HTAnchor * , anchor)
  
  {
      char * logical = HTAnchor_address(anchor);
      char * path = HTParse(logical, "", PARSE_PATH + PARSE_PUNCTUATION);
      char * current;
  
      current = strrchr(path, '/');	/* last part or "" */
  
      {
        char * printable = NULL;
  
+ #ifdef DIRED_SUPPORT
+       StrAllocCopy(printable, path);
+ #else 
        StrAllocCopy(printable, (current + 1));
! #endif /* DIRED_SUPPORT */
  
        START(HTML_HEAD);
        PUTS("\n");
        HTUnEscape(printable);
        START(HTML_TITLE);
        PUTS(*printable ? printable : "Welcome ");
        PUTS(" directory");
***************
*** 711,721 ****
        END(HTML_HEAD);
        PUTS("\n");
  
! {extern void *vp_msdosmem;extern void **vpp_msdosmem;vp_msdosmem = NULL;vpp_msdosmem = NULL;}
        START(HTML_H1);
        PUTS(*printable ? printable : "Welcome");
        END(HTML_H1);
        PUTS("\n");
        FREE(printable);
      }
  
--- 707,724 ----
        END(HTML_HEAD);
        PUTS("\n");
  
! #ifdef DIRED_SUPPORT
!       START(HTML_H2);
!       PUTS(*printable ? "Current directory is " : "");
!       PUTS(*printable ? printable : "Welcome");
!       END(HTML_H2);
!       PUTS("\n");
! #else
        START(HTML_H1);
        PUTS(*printable ? printable : "Welcome");
        END(HTML_H1);
        PUTS("\n");
+ #endif /* DIRED_SUPPORT */
        FREE(printable);
      }
  
***************
*** 723,729 ****
      /*  Make link back to parent directory
       */
  
!     if (strlen(current) > 1) {   /* was a slash AND something else too */
  	char * parent;
  	char * relative;
  	*current++ = 0;
--- 726,732 ----
      /*  Make link back to parent directory
       */
  
!     if (current && current[1]) {   /* was a slash AND something else too */
          char * parent;
  	char * relative;
  	*current++ = 0;
***************
*** 731,742 ****
  
  	relative = (char*) malloc(strlen(current) + 4);
  	if (relative == NULL) outofmem(__FILE__, "DirRead");
- 
- 	if (strlen(parent) < 4)
- 	    sprintf(relative, "%s/.././", current);
- 	else
  	    sprintf(relative, "%s/..", current);
- 
  #ifndef VMS
  	{
  	    /*
--- 734,740 ----
***************
*** 761,779 ****
  	    }
  	}
  #endif /* !VMS */
! 
! 
! 	HTStartAnchor(target, NULL, relative);
  	FREE(relative);
  
  #ifdef DIRED_SUPPORT
  	if (dir_list_style != MIXED_STYLE)
  #endif /* DIRED_SUPPORT */
- 
  	    PUTS("Up to ");
- 
  	if (parent) {
- 
  #ifdef DIRED_SUPPORT
  	   if (dir_list_style == MIXED_STYLE) {
  	      PUTS("../");
--- 759,772 ----
  	    }
  	}
  #endif /* !VMS */
! 	HTStartAnchor(target, "", relative);
  	FREE(relative);
  
  #ifdef DIRED_SUPPORT
  	if (dir_list_style != MIXED_STYLE)
  #endif /* DIRED_SUPPORT */
  	    PUTS("Up to ");
  	if (parent) {
  #ifdef DIRED_SUPPORT
  	   if (dir_list_style == MIXED_STYLE) {
  	      PUTS("../");
***************
*** 787,796 ****
  	      PUTS(printable);
  	      FREE(printable);
  	   }
  	}
- //	  else {
- //	  PUTS("/");
- //	}
  
  	END(HTML_A);
      }
--- 780,788 ----
  	      PUTS(printable);
  	      FREE(printable);
  	   }
+ 	} else {
+ 	  PUTS("/");
  	}
  
  	END(HTML_A);
      }
***************
*** 831,837 ****
      struct stat stat_info;
  #endif /* VMS */
  
- 
      FREE(nodename);	/* From prev call - Leak fixed AL 6 Feb 1994 */
  
  /*	Reduce the filename to a basic form (hopefully unique!)
--- 823,828 ----
***************
*** 859,866 ****
--- 850,935 ----
          FREE(access);
      }
  
+ #ifdef VMS
+ /*
+ **	Check to see if the 'filename' is in fact a directory.  If it is
+ **	create a new hypertext object containing a list of files and 
+ **	subdirectories contained in the directory.  All of these are links
+ **      to the directories or files listed.
+ */
+     HTUnEscape(filename);
+     if (HTStat(filename, &stat_info) == -1) {
+ 	if (TRACE)
+ 	    fprintf(stderr, "HTLoadFile.. Can't stat %s\n", filename);
+     } else {
+ 	if (((stat_info.st_mode) & S_IFMT) == S_IFDIR) {
+ 	    if (HTDirAccess == HT_DIR_FORBID) {
+ 		FREE(filename);
+ 		return HTLoadError(sink, 403,
+ 		"Directory browsing is not allowed.");
+ 	    }
+ 
+ 	    if (HTDirAccess == HT_DIR_SELECTIVE) {
+ 		char * enable_file_name = 
+ 		    malloc(strlen(filename)+ 1 +
+ 		    strlen(HT_DIR_ENABLE_FILE) + 1);
+ 		strcpy(enable_file_name, filename);
+ 		strcat(enable_file_name, "/");
+ 		strcat(enable_file_name, HT_DIR_ENABLE_FILE);
+ 		if (HTStat(enable_file_name, &stat_info) == -1) {
+ 		    FREE(filename);
+ 		    return HTLoadError(sink, 403,
+ 		    "Selective access is not enabled for this directory");
+ 		}
+ 	    }
+ 
+ 	    FREE(filename);
+ 	    return HTVMSBrowseDir(addr, anchor, format_out, sink);
+ 	}
+     }
+ 
      format = HTFileFormat(filename, &encoding);
  
+ /* Assume that the file is in Unix-style syntax if it contains a '/'
+    after the leading one @@ */
+     {
+         FILE * fp;
+ 	char * vmsname = strchr(filename + 1, '/') ?
+ 	  HTVMS_name(nodename, filename) : filename + 1;
+ 	fp = fopen(vmsname, "r", "shr=put", "shr=upd");
+ 	
+ /*	If the file wasn't VMS syntax, then perhaps it is ultrix
+ */
+ 	if (!fp) {
+ 	    char ultrixname[INFINITY];
+ 	    if (TRACE) fprintf(stderr, "HTFile: Can't open as %s\n", vmsname);
+ 	    sprintf(ultrixname, "%s::\"%s\"", nodename, filename);
+   	    fp = fopen(ultrixname, "r", "shr=put", "shr=upd");
+ 	    if (!fp) {
+ 		if (TRACE) fprintf(stderr, 
+ 				   "HTFile: Can't open as %s\n", ultrixname);
+ 	    }
+ 	}
+         if (fp)
+         {
+ 	    if (HTEditable(vmsname)) {
+ 		HTAtom * put = HTAtom_for("PUT");
+ 		HTList * methods = HTAnchor_methods(anchor);
+ 		if (HTList_indexOf(methods, put) == (-1)) {
+ 	   	    HTList_addObject(methods, put);
+ 	        }
+ 	    }
+ 	    HTParseFile(format, format_out, anchor, fp, sink);
+ 	    fclose(fp);
+ 	    FREE(filename);
+             return HT_LOADED;
+         }  /* If successfull open */
+ 	FREE(filename);
+     }
+ 
+ #else /* Unix: */
+ 
+     format = HTFileFormat(filename, &encoding);
      FREE(filename);
      
  /*	For unix, we try to translate the name into the name of a transparently
***************
*** 889,899 ****
  	pbits[((a) >> (n)) & 0x7]
  #endif /* LONG_LIST */
  
-     if(strlen(localname)==3)
- 	StrAllocCat(localname,"foo\\..");
- 
- //printf("\n\n%s\n\n",localname);
- 
  #ifdef GOT_READ_DIR
  
  /*			  Multiformat handling
--- 958,963 ----
***************
*** 929,940 ****
  
  	    while ((dirbuf = readdir(dp))!=0) {
  		/* while there are directory entries to be read */
! //		if (dirbuf->d_ino == 0)
! //		    continue;	/* if the entry is not being used, skip it */
  
  		if (
  #if !defined(SVR4) && !defined(ISC) && !defined(SCO)
! //                    (int)dirbuf->d_namlen > baselen &&      /* Match? */
  #endif /* !SVR4 && !ISC && !SCO */
  		    !strncmp(dirbuf->d_name, base, baselen)) {
  		    HTFormat rep = HTFileFormat(dirbuf->d_name, &encoding);
--- 993,1004 ----
  	    
  	    while ((dirbuf = readdir(dp))!=0) {
  		/* while there are directory entries to be read */
! 		if (dirbuf->d_ino == 0)
! 		    continue;	/* if the entry is not being used, skip it */
  
  		if (
  #if !defined(SVR4) && !defined(ISC) && !defined(SCO)
!                     (int)dirbuf->d_namlen > baselen &&      /* Match? */
  #endif /* !SVR4 && !ISC && !SCO */
  		    !strncmp(dirbuf->d_name, base, baselen)) {	
  		    HTFormat rep = HTFileFormat(dirbuf->d_name, &encoding);
***************
*** 942,953 ****
  						HTFileValue(dirbuf->d_name),
  						0.0  /* @@@@@@ */);
  		    if (value != NO_VALUE_FOUND) {
- #ifdef DT
  			if (TRACE) fprintf(stderr,
  				"HTFile: value of presenting %s is %f\n",
  				HTAtom_name(rep), value);
- #endif
- 
  			if  (value > best) {
  			    best_rep = rep;
  			    best = value;
--- 1006,1014 ----
***************
*** 973,980 ****
  	    }
  	    /*NOTREACHED*/
  	} /* if multi suffix */
- 
- 
  /*
  **	Check to see if the 'localname' is in fact a directory.  If it is
  **	create a new hypertext object containing a list of files and
--- 1034,1039 ----
***************
*** 988,998 ****
  
  	if (stat(localname,&dir_info) == -1) {     /* get file information */
  				       /* if can't read file information */
- #ifdef DT
  	    if (TRACE) fprintf(stderr, "HTFile: can't stat %s\n", localname);
- #endif
  
- 
  	}  else {		/* Stat was OK */
  
  
--- 1047,1054 ----
***************
*** 1014,1025 ****
  		char * tmpfilename = NULL;
  		struct stat file_info;
  
- #ifdef DT
  		if (TRACE)
  		    fprintf(stderr,"%s is a directory\n",localname);
- #endif
  
- 
  /*	Check directory access.
  **	Selective access means only those directories containing a
  **	marker file can be browsed
--- 1070,1078 ----
***************
*** 1056,1072 ****
   /*	Directory access is allowed and possible
   */
  		logical = HTAnchor_address((HTAnchor*)anchor);
- 
  		pathname = HTParse(logical, "",
  					PARSE_PATH + PARSE_PUNCTUATION);
- //		if(pathname[strlen(pathname)-1] == '/')
- //		    pathname[strlen(pathname)-1] = '\0';
  
  		{
  		  char * p = strrchr(pathname, '/');  /* find lastslash */
  		  StrAllocCopy(tail, p+1); /* take slash off the beginning */
  		}
- 
  		FREE(pathname);
  
  		target = HTML_new(anchor, format_out, sink);
--- 1109,1124 ----
   /*	Directory access is allowed and possible
   */
  		logical = HTAnchor_address((HTAnchor*)anchor);
          	pathname = HTParse(logical, "", 
  					PARSE_PATH + PARSE_PUNCTUATION);
  
+     		if(!strcmp(pathname,"/"))  /* root path */
+         	    StrAllocCopy (tail, "/foo/..");
+     	    	else
      		  {
          	    char * p = strrchr(pathname, '/');  /* find lastslash */
          	    StrAllocCopy(tail, p+1); /* take slash off the beginning */
      		  }
      		FREE(pathname);
  		
  		target = HTML_new(anchor, format_out, sink);
***************
*** 1078,1097 ****
  		}
  
  		HTDirTitles(target, (HTAnchor *)anchor);
! /*
  		if (HTDirReadme == HT_DIR_README_TOP)
  		    do_readme(target, localname);
- */
  		{
  		    HTBTree * bt = HTBTree_new((HTComparer)strcasecomp);
  		    while ((dirbuf = readdir(dp))!=0)
  		    {
  			/* while there are directory entries to be read */
  			HTBTElement * dirname = NULL;
  
! //		        if (dirbuf->d_ino == 0)
  			    /* if the entry is not being used, skip it */
! //			    continue;
  
  			if ((*(dirbuf->d_name)=='.') ||
  				(*(dirbuf->d_name)==','))
--- 1130,1153 ----
  		}
  		
                  HTDirTitles(target, (HTAnchor *)anchor);
! 
! #ifdef DIRED_SUPPORT
! 		HTAnchor_setFormat((HTParentAnchor *) anchor, WWW_DIRED);
! 		lynx_edit_mode = TRUE;
! #endif /* DIRED_SUPPORT */
                  if (HTDirReadme == HT_DIR_README_TOP)
  		    do_readme(target, localname);
  		{
  		    HTBTree * bt = HTBTree_new((HTComparer)strcasecomp);
+ 
  		    while ((dirbuf = readdir(dp))!=0)
  		    {
  			/* while there are directory entries to be read */
  		        HTBTElement * dirname = NULL;
  
! 		        if (dirbuf->d_ino == 0)
  			    /* if the entry is not being used, skip it */
! 			    continue;
  
  			if ((*(dirbuf->d_name)=='.') ||
  				(*(dirbuf->d_name)==','))
***************
*** 1103,1109 ****
  					strlen(dirbuf->d_name) + 4);
  			if (dirname == NULL) outofmem(__FILE__,"DirRead");
  			StrAllocCopy(tmpfilename,localname);
- 
  			if (strcmp(localname,"/"))
  			    /* if filename is not root directory */
  			    StrAllocCat(tmpfilename,"/");
--- 1159,1164 ----
***************
*** 1111,1120 ****
--- 1166,1189 ----
  			StrAllocCat(tmpfilename,dirbuf->d_name);
  			stat(tmpfilename, &file_info);
  			if (((file_info.st_mode) & S_IFMT) == S_IFDIR)
+ #ifndef DIRED_SUPPORT
  		            sprintf((char *)dirname,"D%s",dirbuf->d_name);
  			else
  			    sprintf((char *)dirname,"F%s",dirbuf->d_name);
  			    /* D & F to have first directories, then files */
+ #else
+ 			    if (dir_list_style == MIXED_STYLE)
+ 			        sprintf((char *)dirname," %s/",dirbuf->d_name);
+ 			    else
+ 			        sprintf((char *)dirname,"D%s",dirbuf->d_name);
+ 			else if (dir_list_style == MIXED_STYLE)
+ 			    sprintf((char *)dirname," %s",dirbuf->d_name);
+ 			else if (dir_list_style == FILES_FIRST)
+ 			    sprintf((char *)dirname,"C%s",dirbuf->d_name);
+ 			    /* C & D to have first files, then directories */
+ 			else
+ 			    sprintf((char *)dirname,"F%s",dirbuf->d_name);
+ #endif /* !DIRED_SUPPORT */
  			HTBTree_add(bt,dirname); /* Sort dirname in the tree bt */
  		    }
  
***************
*** 1128,1133 ****
--- 1197,1205 ----
  			       D for directory file,
  			       F for file */
  			
+ #ifdef DIRED_SUPPORT
+ 			char test;
+ #endif /* DIRED_SUPPORT */
  			state = 'I';
  
  			while (next_element != NULL)
***************
*** 1148,1176 ****
  			    if (strcmp((char *)
  					     (HTBTree_object(next_element)),"D.."))
  			    {
  				if (state != *(char *)(HTBTree_object(next_element)))
  				{
  				    if (state == 'D')
  					END(HTML_DIR);
  				    state = *(char *)
  					(HTBTree_object(next_element))=='D'?'D':'F';
- { extern void *vp_msdosmem;extern void **vpp_msdosmem;vp_msdosmem = NULL;vpp_msdosmem = NULL;}
  				    START(HTML_H2);
  				    PUTS(state == 'D'?"Subdirectories:":"Files");
  				    END(HTML_H2);
- { extern void *vp_msdosmem;extern void **vpp_msdosmem;vp_msdosmem = NULL;vpp_msdosmem = NULL;}
  				    START(HTML_DIR);
  				}
- { extern void *vp_msdosmem;extern void **vpp_msdosmem;vp_msdosmem = NULL;vpp_msdosmem = NULL;}
  				START(HTML_LI);
  			    }
  			    entry = (char*)HTBTree_object(next_element)+1;
  			    file_extra = NULL;
  #ifdef LONG_LIST
- { extern void *vp_msdosmem;extern void **vpp_msdosmem;vp_msdosmem = NULL;vpp_msdosmem = NULL;}
  			    START(HTML_PRE);
! //			    if(lstat(tmpfilename, &st) != -1) {
! 			    if(stat(tmpfilename, &st) != -1) {
  			      char link_name[1025];
  			      int file_len;
  
--- 1220,1260 ----
  			    if (strcmp((char *)
  					     (HTBTree_object(next_element)),"D.."))
  			    {			    
+ #ifdef DIRED_SUPPORT
+ 			        test = *(char *) (HTBTree_object(next_element))=='D'?'D':'F';
+ 				if (state != test)
+ 				{
+ 				    if (dir_list_style == FILES_FIRST) {
+ 				       if (state == 'F')
+   					  END(HTML_DIR); 
+ 				    } else if (dir_list_style != MIXED_STYLE)
+ 				       if (state == 'D')
+   					  END(HTML_DIR); 
+ 				    state = *(char *)
+ 				        (HTBTree_object(next_element))=='D'?'D':'F';
+ 				    START(HTML_H2);
+ 				    if (dir_list_style != MIXED_STYLE)
+ 				       PUTS(state == 'D'?"Directories:":"Files");
+ #else
  				if (state != *(char *)(HTBTree_object(next_element))) 
  				{
  				    if (state == 'D')
  				        END(HTML_DIR);
  				    state = *(char *)
  				        (HTBTree_object(next_element))=='D'?'D':'F';
  				    START(HTML_H2);
  				    PUTS(state == 'D'?"Subdirectories:":"Files");
+ #endif /* DIRED_SUPPORT */
  				    END(HTML_H2);
  				    START(HTML_DIR);
  				}
  			        START(HTML_LI);
  			    }
  			    entry = (char*)HTBTree_object(next_element)+1;
  			    file_extra = NULL;
  #ifdef LONG_LIST
  			    START(HTML_PRE);
! 			    if(lstat(tmpfilename, &st) != -1) {
  			      char link_name[1025];
  			      int file_len;
  
***************
*** 1181,1187 ****
  			      case S_IFDIR: type = 'd'; break;
  			      case S_IFBLK: type = 'b'; break;
  			      case S_IFREG: type = '-'; break;
- /*
  			      case S_IFLNK:
  				type = 'l';
  				if ((file_len = readlink(tmpfilename,
--- 1265,1270 ----
***************
*** 1193,1223 ****
  				    StrAllocCat(file_extra, link_name);
  				}
  				break;
! */
! //			      case S_IFSOCK: type = 's'; break;
  			      default: type = '?'; break;
  			      }
! 			      sprintf(buf, "    %c%s  %3d ", type,
! //			      sprintf(buf, "    %c%s%s%s  %3d ", type,
! //        			PBIT(st.st_mode, 6, st.st_mode & S_ISUID),
! //        			PBIT(st.st_mode, 3, st.st_mode & S_ISGID),
  				PBIT(st.st_mode, 0, 0),
  				st.st_nlink);
  			      PUTS(buf);
  
  			      /* user */
! //			      p = getpwuid(st.st_uid);
! //			      if(p)
! //				sprintf(buf, "%-8.8s ", p->pw_name);
! //			      else
  				sprintf(buf, "%-8d ", st.st_uid);
  			      PUTS(buf);
  
  			      /* group */
! //			      g = getgrgid(st.st_gid);
! //			      if(g)
! //				sprintf(buf, "%-8.8s ", g->gr_name);
! //			      else
  				sprintf(buf, "%-8d ", st.st_gid);
  			      PUTS(buf);
  
--- 1276,1304 ----
  				    StrAllocCat(file_extra, link_name);
  				}
  				break;
! 			      case S_IFSOCK: type = 's'; break;
  			      default: type = '?'; break;
  			      }
! 			      sprintf(buf, "    %c%s%s%s  %3d ", type,
!         			PBIT(st.st_mode, 6, st.st_mode & S_ISUID),
!         			PBIT(st.st_mode, 3, st.st_mode & S_ISGID), 
          			PBIT(st.st_mode, 0, 0),
  				st.st_nlink);
  			      PUTS(buf);
  
  			      /* user */
! 			      p = getpwuid(st.st_uid);
! 			      if(p) 
! 				sprintf(buf, "%-8.8s ", p->pw_name);
! 			      else
  				sprintf(buf, "%-8d ", st.st_uid);
  			      PUTS(buf);
  
  			      /* group */
! 			      g = getgrgid(st.st_gid);
! 			      if(g)
! 				sprintf(buf, "%-8.8s ", g->gr_name);
! 			      else
  				sprintf(buf, "%-8d ", st.st_gid);
  			      PUTS(buf);
  
***************
*** 1238,1246 ****
  			      PUTS(buf);
  			    }
  #endif /* LONG_LIST */
- 
  			    HTDirEntry(target, tail, entry);
! /* dir here */			    PUTS(entry);
      			    END(HTML_A);
  			    if (file_extra) {
  				PUTS(file_extra);
--- 1319,1326 ----
  			      PUTS(buf);
  			    }
  #endif /* LONG_LIST */
  			    HTDirEntry(target, tail, entry);
! 			    PUTS(entry);
      			    END(HTML_A);
  			    if (file_extra) {
  				PUTS(file_extra);
***************
*** 1256,1262 ****
  			}
  			if (state == 'I')
  			{
- { extern void *vp_msdosmem;extern void **vpp_msdosmem;vp_msdosmem = NULL;vpp_msdosmem = NULL;}
  			    START(HTML_P);
  			    PUTS("Empty Directory");
  			}
--- 1336,1341 ----
***************
*** 1270,1279 ****
  		    FREE(tmpfilename);
  		    FREE(tail);
  		    HTBTreeAndObject_free(bt);
! /*
  		    if (HTDirReadme == HT_DIR_README_BOTTOM)
  			  do_readme(target, localname);
- */
  		    FREE_TARGET;
  		    FREE(localname);
  		    return HT_LOADED;	/* document loaded */
--- 1349,1357 ----
  		    FREE(tmpfilename);
  		    FREE(tail);
  		    HTBTreeAndObject_free(bt);
! 
  		    if (HTDirReadme == HT_DIR_README_BOTTOM)
  			  do_readme(target, localname);
  		    FREE_TARGET;
  		    FREE(localname);
  		    return HT_LOADED;	/* document loaded */
***************
*** 1288,1300 ****
  #endif /* GOT_READ_DIR */
  open_file:
  	{
!             FILE * fp = fopen(localname,"rb");
  
- #ifdef DT
  	    if(TRACE) fprintf (stderr, "HTFile: Opening `%s' gives %p\n",
  				localname, (void*)fp);
- #endif
- 
  	    if (fp) {		/* Good! */
  		if (HTEditable(localname)) {
  		    HTAtom * put = HTAtom_for("PUT");
--- 1366,1375 ----
  #endif /* GOT_READ_DIR */
  open_file:
  	{
! 	    FILE * fp = fopen(localname,"r");
  
  	    if(TRACE) fprintf (stderr, "HTFile: Opening `%s' gives %p\n",
  				localname, (void*)fp);
  	    if (fp) {		/* Good! */
  		if (HTEditable(localname)) {
  		    HTAtom * put = HTAtom_for("PUT");
***************
*** 1311,1316 ****
--- 1386,1392 ----
  	}    /* scope of fp */
      }  /* local unix file system */    
  #endif /* !NO_UNIX_IO */
+ #endif /* VMS */
  
  #ifndef DECNET
  /*	Now, as transparently mounted access has failed, we try FTP.
***************
*** 1334,1344 ****
  /*	All attempts have failed.
  */
      {
- #ifdef DT
      	if (TRACE)
  	    fprintf(stderr, "Can't open `%s', errno=%d\n", addr, SOCKET_ERRNO);
- #endif
- 
  
  	return HTLoadError(sink, 403, "Can't access requested file.");
      }
--- 1410,1417 ----
