about summary refs log tree commit diff stats
path: root/WWW
diff options
context:
space:
mode:
Diffstat (limited to 'WWW')
-rw-r--r--WWW/Library/Implementation/HTAnchor.c5
-rw-r--r--WWW/Library/Implementation/HTFTP.c3
-rw-r--r--WWW/Library/Implementation/HTFile.c523
-rw-r--r--WWW/Library/Implementation/HTFile.h7
-rw-r--r--WWW/Library/Implementation/HTMIME.c2
-rw-r--r--WWW/Library/Implementation/HTMLGen.c19
-rw-r--r--WWW/Library/Implementation/HTMLGen.h8
-rw-r--r--WWW/Library/Implementation/HTTCP.c2
-rw-r--r--WWW/Library/Implementation/HTUtils.h18
-rw-r--r--WWW/Library/Implementation/SGML.c4
-rw-r--r--WWW/Library/Implementation/www_tcp.h4
11 files changed, 337 insertions, 258 deletions
diff --git a/WWW/Library/Implementation/HTAnchor.c b/WWW/Library/Implementation/HTAnchor.c
index 8c6a6304..5b6fc7a2 100644
--- a/WWW/Library/Implementation/HTAnchor.c
+++ b/WWW/Library/Implementation/HTAnchor.c
@@ -316,8 +316,9 @@ HTChildAnchor *HTAnchor_findChildAndLink(HTParentAnchor *parent,	/* May not be 0
 	if (ltype == HTInternalLink && *href == '#') {
 	    dest = parent->parent;
 	} else {
-	    const char *relative_to = (parent->inBASE && *href != '#') ?
-	    parent->content_base : parent->address;
+	    const char *relative_to = ((parent->inBASE && *href != '#')
+				       ? parent->content_base
+				       : parent->address);
 	    DocAddress parsed_doc;
 
 	    parsed_doc.address = HTParse(href, relative_to,
diff --git a/WWW/Library/Implementation/HTFTP.c b/WWW/Library/Implementation/HTFTP.c
index 2319043d..5d0712d2 100644
--- a/WWW/Library/Implementation/HTFTP.c
+++ b/WWW/Library/Implementation/HTFTP.c
@@ -2688,7 +2688,7 @@ static int read_directory(HTParentAnchor *parent,
      * directory listings if LONG_LIST was defined on compilation, but we could
      * someday set up an equivalent listing for Unix ftp servers.  - FM
      */
-    need_parent_link = HTDirTitles(target, parent, tildeIsTop);
+    need_parent_link = HTDirTitles(target, parent, format_out, tildeIsTop);
 
     data_read_pointer = data_write_pointer = data_buffer;
 
@@ -2941,6 +2941,7 @@ static int read_directory(HTParentAnchor *parent,
 	    }
 	}
 	END(HTML_PRE);
+	END(HTML_BODY);
 	FREE_TARGET;
 	HTBTreeAndObject_free(bt);
     }
diff --git a/WWW/Library/Implementation/HTFile.c b/WWW/Library/Implementation/HTFile.c
index 7a647b24..1909492f 100644
--- a/WWW/Library/Implementation/HTFile.c
+++ b/WWW/Library/Implementation/HTFile.c
@@ -74,6 +74,11 @@
 #include <LYGlobalDefs.h>
 #include <LYStrings.h>
 #include <LYUtils.h>
+
+#ifdef USE_PRETTYSRC
+# include <LYPrettySrc.h>
+#endif
+
 #include <LYLeaks.h>
 
 typedef struct _HTSuffix {
@@ -251,7 +256,6 @@ static void LYListFmtParse(const char *fmtstr,
     StrAllocCopy(str, fmtstr);
     s = str;
     end = str + strlen(str);
-    START(HTML_PRE);
     while (*s) {
 	start = s;
 	while (*s) {
@@ -464,7 +468,6 @@ static void LYListFmtParse(const char *fmtstr,
 	s++;
     }
     FREE(buf);
-    END(HTML_PRE);
     PUTC('\n');
     FREE(str);
 }
@@ -1372,7 +1375,7 @@ void HTDirEntry(HTStructured * target, const char *tail,
 	}
     }
 
-    if (tail == NULL || *tail == '\0') {
+    if (isEmpty(tail)) {
 	/*
 	 * Handle extra slash at end of path.
 	 */
@@ -1393,6 +1396,37 @@ void HTDirEntry(HTStructured * target, const char *tail,
     FREE(escaped);
 }
 
+static BOOL view_structured(HTFormat format_out)
+{
+    BOOL result = FALSE;
+
+#ifdef USE_PRETTYSRC
+    if (psrc_view
+	|| (format_out == HTAtom_for("www/dump")))
+	result = TRUE;
+#else
+    if (format_out == WWW_SOURCE)
+	result = TRUE;
+#endif
+    return result;
+}
+
+/*
+ * Write a DOCTYPE to the given stream if we happen to want to see the
+ * source view, or are dumping source.  This is not needed when the source
+ * is not visible, since the document is rendered from a HTStructured object.
+ */
+void HTStructured_doctype(HTStructured * target, HTFormat format_out)
+{
+    if (view_structured(format_out))
+	PUTS("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");
+}
+
+void HTStructured_meta(HTStructured * target, HTFormat format_out)
+{
+    if (view_structured(format_out))
+	PUTS("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n");
+}
 /*	Output parent directory entry.
  *	------------------------------
  *
@@ -1407,6 +1441,7 @@ void HTDirEntry(HTStructured * target, const char *tail,
  *	to the parent directory.  Otherwise, it returns FALSE. - FM
  */
 BOOL HTDirTitles(HTStructured * target, HTParentAnchor *anchor,
+		 HTFormat format_out,
 		 BOOL tildeIsTop)
 {
     const char *logical = anchor->address;
@@ -1475,6 +1510,8 @@ BOOL HTDirTitles(HTStructured * target, HTParentAnchor *anchor,
 	HTUnEscape(printable);
 #endif /* DIRED_SUPPORT */
 
+	HTStructured_doctype(target, format_out);
+
 	START(HTML_HEAD);
 	PUTC('\n');
 	START(HTML_TITLE);
@@ -1482,9 +1519,13 @@ BOOL HTDirTitles(HTStructured * target, HTParentAnchor *anchor,
 	PUTS(SEGMENT_DIRECTORY);
 	END(HTML_TITLE);
 	PUTC('\n');
+	HTStructured_meta(target, format_out);
 	END(HTML_HEAD);
 	PUTC('\n');
 
+	START(HTML_BODY);
+	PUTC('\n');
+
 #ifdef DIRED_SUPPORT
 	START(HTML_H2);
 	PUTS(*printable ? SEGMENT_CURRENT_DIR : "");
@@ -1727,17 +1768,24 @@ static int print_local_dir(DIR *dp, char *localname,
 			   HTStream *sink)
 {
     HTStructured *target;	/* HTML object */
+    HTBTree *bt;
     HTStructuredClass targetClass;
     STRUCT_DIRENT *dirbuf;
     char *pathname = NULL;
     char *tail = NULL;
+    char *p;
     BOOL present[HTML_A_ATTRIBUTES];
     char *tmpfilename = NULL;
     BOOL need_parent_link = FALSE;
+    BOOL preformatted = FALSE;
     int status;
     int i;
     struct stat *actual_info;
 
+#ifdef DISP_PARTIAL
+    int num_of_entries = 0;	/* lines counter */
+#endif
+
 #ifdef S_IFLNK
     struct stat link_info;
 #endif
@@ -1747,27 +1795,9 @@ static int print_local_dir(DIR *dp, char *localname,
     pathname = HTParse(anchor->address, "",
 		       PARSE_PATH + PARSE_PUNCTUATION);
 
-    if (!strcmp(pathname, "/")) {
-	/*
-	 * Root path.
-	 */
-	StrAllocCopy(tail, "/foo/..");
-    } else {
-	char *p = strrchr(pathname, '/');	/* find last slash */
-
-	if (!p) {
-	    /*
-	     * This probably should not happen, but be prepared if it does.  -
-	     * KW
-	     */
-	    StrAllocCopy(tail, "/foo/..");
-	} else {
-	    /*
-	     * Take slash off the beginning.
-	     */
-	    StrAllocCopy(tail, (p + 1));
-	}
-    }
+    if ((p = strrchr(pathname, '/')) == 0)
+	p = "/";
+    StrAllocCopy(tail, (p + 1));
     FREE(pathname);
 
     if (UCLYhndl_HTFile_for_unspec >= 0) {
@@ -1789,7 +1819,7 @@ static int print_local_dir(DIR *dp, char *localname,
      * defined and NO_PARENT_DIR_REFERENCE is not defined so that need we to
      * create the link via an LYListFmtParse() call.  - FM
      */
-    need_parent_link = HTDirTitles(target, anchor, FALSE);
+    need_parent_link = HTDirTitles(target, anchor, format_out, FALSE);
 
 #ifdef DIRED_SUPPORT
     if (!isLYNXCGI(anchor->address)) {
@@ -1800,288 +1830,306 @@ static int print_local_dir(DIR *dp, char *localname,
     if (HTDirReadme == HT_DIR_README_TOP)
 	do_readme(target, localname);
 
-    {
-	HTBTree *bt = HTBTree_new(dired_cmp);
-	int num_of_entries = 0;	/* lines counter */
+    bt = HTBTree_new(dired_cmp);
 
-	_HTProgress(READING_DIRECTORY);
-	status = HT_LOADED;	/* assume we don't get interrupted */
-	while ((dirbuf = readdir(dp)) != NULL) {
-	    /*
-	     * While there are directory entries to be read...
-	     */
-	    DIRED *data = NULL;
+    _HTProgress(READING_DIRECTORY);
+    status = HT_LOADED;		/* assume we don't get interrupted */
+    while ((dirbuf = readdir(dp)) != NULL) {
+	/*
+	 * While there are directory entries to be read...
+	 */
+	DIRED *data = NULL;
 
 #if !(defined(DOSPATH) || defined(__EMX__))
-	    if (dirbuf->d_ino == 0)
-		/*
-		 * If the entry is not being used, skip it.
-		 */
-		continue;
-#endif
+	if (dirbuf->d_ino == 0)
 	    /*
-	     * Skip self, parent if handled in HTDirTitles() or if
-	     * NO_PARENT_DIR_REFERENCE is not defined, and any dot files if
-	     * no_dotfiles is set or show_dotfiles is not set.  - FM
+	     * If the entry is not being used, skip it.
 	     */
-	    if (!strcmp(dirbuf->d_name, ".") /* self       */ ||
-		(!strcmp(dirbuf->d_name, "..") /* parent */ &&
-		 need_parent_link == FALSE) ||
-		((strcmp(dirbuf->d_name, "..")) &&
-		 (dirbuf->d_name[0] == '.' &&
-		  (no_dotfiles || !show_dotfiles))))
-		continue;
+	    continue;
+#endif
+	/*
+	 * Skip self, parent if handled in HTDirTitles() or if
+	 * NO_PARENT_DIR_REFERENCE is not defined, and any dot files if
+	 * no_dotfiles is set or show_dotfiles is not set.  - FM
+	 */
+	if (!strcmp(dirbuf->d_name, ".") /* self       */ ||
+	    (!strcmp(dirbuf->d_name, "..") /* parent */ &&
+	     need_parent_link == FALSE) ||
+	    ((strcmp(dirbuf->d_name, "..")) &&
+	     (dirbuf->d_name[0] == '.' &&
+	      (no_dotfiles || !show_dotfiles))))
+	    continue;
 
-	    StrAllocCopy(tmpfilename, localname);
-	    /*
-	     * If filename is not root directory, add trailing separator.
-	     */
-	    LYAddPathSep(&tmpfilename);
+	StrAllocCopy(tmpfilename, localname);
+	/*
+	 * If filename is not root directory, add trailing separator.
+	 */
+	LYAddPathSep(&tmpfilename);
 
-	    StrAllocCat(tmpfilename, dirbuf->d_name);
-	    data = (DIRED *) malloc(sizeof(DIRED) + strlen(dirbuf->d_name) + 4);
-	    if (data == NULL) {
-		status = HT_PARTIAL_CONTENT;
-		break;
-	    }
-	    LYTrimPathSep(tmpfilename);
+	StrAllocCat(tmpfilename, dirbuf->d_name);
+	data = (DIRED *) malloc(sizeof(DIRED) + strlen(dirbuf->d_name) + 4);
+	if (data == NULL) {
+	    status = HT_PARTIAL_CONTENT;
+	    break;
+	}
+	LYTrimPathSep(tmpfilename);
 
-	    actual_info = &(data->file_info);
+	actual_info = &(data->file_info);
 #ifdef S_IFLNK
-	    if (lstat(tmpfilename, actual_info) < 0) {
-		actual_info->st_mode = 0;
-	    } else {
-		if (S_ISLNK(actual_info->st_mode)) {
-		    actual_info = &link_info;
-		    if (stat(tmpfilename, actual_info) < 0)
-			actual_info->st_mode = 0;
-		}
+	if (lstat(tmpfilename, actual_info) < 0) {
+	    actual_info->st_mode = 0;
+	} else {
+	    if (S_ISLNK(actual_info->st_mode)) {
+		actual_info = &link_info;
+		if (stat(tmpfilename, actual_info) < 0)
+		    actual_info->st_mode = 0;
 	    }
+	}
 #else
-	    if (stat(tmpfilename, actual_info) < 0)
-		actual_info->st_mode = 0;
+	if (stat(tmpfilename, actual_info) < 0)
+	    actual_info->st_mode = 0;
 #endif
 
-	    strcpy(data->file_name, dirbuf->d_name);
+	strcpy(data->file_name, dirbuf->d_name);
 #ifndef DIRED_SUPPORT
-	    if (S_ISDIR(actual_info->st_mode)) {
-		data->sort_tags = 'D';
-	    } else {
-		data->sort_tags = 'F';
-		/* D & F to have first directories, then files */
-	    }
+	if (S_ISDIR(actual_info->st_mode)) {
+	    data->sort_tags = 'D';
+	} else {
+	    data->sort_tags = 'F';
+	    /* D & F to have first directories, then files */
+	}
 #else
-	    if (S_ISDIR(actual_info->st_mode)) {
-		if (dir_list_style == MIXED_STYLE) {
-		    data->sort_tags = ' ';
-		    LYAddPathSep0(data->file_name);
-		} else if (!strcmp(dirbuf->d_name, "..")) {
-		    data->sort_tags = 'A';
-		} else {
-		    data->sort_tags = 'D';
-		}
-	    } else if (dir_list_style == MIXED_STYLE) {
+	if (S_ISDIR(actual_info->st_mode)) {
+	    if (dir_list_style == MIXED_STYLE) {
 		data->sort_tags = ' ';
-	    } else if (dir_list_style == FILES_FIRST) {
-		data->sort_tags = 'C';
-		/* C & D to have first files, then directories */
+		LYAddPathSep0(data->file_name);
+	    } else if (!strcmp(dirbuf->d_name, "..")) {
+		data->sort_tags = 'A';
 	    } else {
-		data->sort_tags = 'F';
+		data->sort_tags = 'D';
 	    }
+	} else if (dir_list_style == MIXED_STYLE) {
+	    data->sort_tags = ' ';
+	} else if (dir_list_style == FILES_FIRST) {
+	    data->sort_tags = 'C';
+	    /* C & D to have first files, then directories */
+	} else {
+	    data->sort_tags = 'F';
+	}
 #endif /* !DIRED_SUPPORT */
-	    /*
-	     * Sort dirname in the tree bt.
-	     */
-	    HTBTree_add(bt, data);
+	/*
+	 * Sort dirname in the tree bt.
+	 */
+	HTBTree_add(bt, data);
 
 #ifdef DISP_PARTIAL
-	    /* optimize for expensive operation: */
-	    if (num_of_entries % (partial_threshold > 0 ?
-				  partial_threshold : display_lines)
-		== 0) {
-		if (HTCheckForInterrupt()) {
-		    status = HT_PARTIAL_CONTENT;
-		    break;
-		}
+	/* optimize for expensive operation: */
+	if (num_of_entries % (partial_threshold > 0 ?
+			      partial_threshold : display_lines)
+	    == 0) {
+	    if (HTCheckForInterrupt()) {
+		status = HT_PARTIAL_CONTENT;
+		break;
 	    }
-	    num_of_entries++;
+	}
+	num_of_entries++;
 #endif /* DISP_PARTIAL */
 
-	}			/* end while directory entries left to read */
+    }				/* end while directory entries left to read */
 
-	if (status != HT_PARTIAL_CONTENT)
-	    _HTProgress(OPERATION_OK);
-	else
-	    CTRACE((tfp, "Reading the directory interrupted by user\n"));
+    if (status != HT_PARTIAL_CONTENT)
+	_HTProgress(OPERATION_OK);
+    else
+	CTRACE((tfp, "Reading the directory interrupted by user\n"));
 
-	/*
-	 * Run through tree printing out in order.
-	 */
-	{
-	    HTBTElement *next_element = HTBTree_next(bt, NULL);
+    /*
+     * Run through tree printing out in order.
+     */
+    {
+	HTBTElement *next_element = HTBTree_next(bt, NULL);
 
-	    /* pick up the first element of the list */
-	    int num_of_entries_output = 0;	/* lines counter */
+	/* pick up the first element of the list */
+	int num_of_entries_output = 0;	/* lines counter */
 
-	    char state;
+	char state;
 
-	    /* I for initial (.. file),
-	       D for directory file,
-	       F for file */
+	/* I for initial (.. file),
+	   D for directory file,
+	   F for file */
 
 #ifdef DIRED_SUPPORT
-	    char test;
+	char test;
 #endif /* DIRED_SUPPORT */
-	    state = 'I';
+	state = 'I';
 
-	    while (next_element != NULL) {
-		DIRED *entry;
+	while (next_element != NULL) {
+	    DIRED *entry;
 
 #ifndef DISP_PARTIAL
-		if (num_of_entries_output % HTMAX(display_lines, 10) == 0) {
-		    if (HTCheckForInterrupt()) {
-			_HTProgress(TRANSFER_INTERRUPTED);
-			status = HT_PARTIAL_CONTENT;
-			break;
-		    }
+	    if (num_of_entries_output % HTMAX(display_lines, 10) == 0) {
+		if (HTCheckForInterrupt()) {
+		    _HTProgress(TRANSFER_INTERRUPTED);
+		    status = HT_PARTIAL_CONTENT;
+		    break;
 		}
+	    }
 #endif
-		StrAllocCopy(tmpfilename, localname);
-		/*
-		 * If filename is not root directory.
-		 */
-		LYAddPathSep(&tmpfilename);
+	    StrAllocCopy(tmpfilename, localname);
+	    /*
+	     * If filename is not root directory.
+	     */
+	    LYAddPathSep(&tmpfilename);
 
-		entry = (DIRED *) (HTBTree_object(next_element));
-		/*
-		 * Append the current entry's filename to the path.
-		 */
-		StrAllocCat(tmpfilename, entry->file_name);
-		HTSimplify(tmpfilename);
-		/*
-		 * Output the directory entry.
-		 */
-		if (strcmp(DIRED_NAME(HTBTree_object(next_element)), "..")) {
+	    entry = (DIRED *) (HTBTree_object(next_element));
+	    /*
+	     * Append the current entry's filename to the path.
+	     */
+	    StrAllocCat(tmpfilename, entry->file_name);
+	    HTSimplify(tmpfilename);
+	    /*
+	     * Output the directory entry.
+	     */
+	    if (strcmp(DIRED_NAME(HTBTree_object(next_element)), "..")) {
 #ifdef DIRED_SUPPORT
-		    test = (DIRED_BLOK(HTBTree_object(next_element))
-			    == 'D' ? 'D' : 'F');
-		    if (state != test) {
+		test = (DIRED_BLOK(HTBTree_object(next_element))
+			== 'D' ? 'D' : 'F');
+		if (state != test) {
 #ifndef LONG_LIST
-			if (dir_list_style == FILES_FIRST) {
-			    if (state == 'F') {
-				END(HTML_DIR);
-				PUTC('\n');
-			    }
-			} else if (dir_list_style != MIXED_STYLE)
-			    if (state == 'D') {
-				END(HTML_DIR);
-				PUTC('\n');
-			    }
-#endif /* !LONG_LIST */
-			state =
-			    (char) (DIRED_BLOK(HTBTree_object(next_element))
-				    == 'D' ? 'D' : 'F');
-			START(HTML_H2);
-			if (dir_list_style != MIXED_STYLE) {
-			    START(HTML_EM);
-			    PUTS(state == 'D'
-				 ? LABEL_SUBDIRECTORIES
-				 : LABEL_FILES);
-			    END(HTML_EM);
+		    if (dir_list_style == FILES_FIRST) {
+			if (state == 'F') {
+			    END(HTML_DIR);
+			    PUTC('\n');
 			}
-			END(HTML_H2);
-			PUTC('\n');
-#ifndef LONG_LIST
-			START(HTML_DIR);
-			PUTC('\n');
-#endif /* !LONG_LIST */
-		    }
-#else
-		    if (state != DIRED_BLOK(HTBTree_object(next_element))) {
-#ifndef LONG_LIST
+		    } else if (dir_list_style != MIXED_STYLE)
 			if (state == 'D') {
 			    END(HTML_DIR);
 			    PUTC('\n');
 			}
 #endif /* !LONG_LIST */
-			state =
-			    (char) (DIRED_BLOK(HTBTree_object(next_element))
-				    == 'D' ? 'D' : 'F');
-			START(HTML_H2);
+		    state =
+			(char) (DIRED_BLOK(HTBTree_object(next_element))
+				== 'D' ? 'D' : 'F');
+		    if (preformatted) {
+			END(HTML_PRE);
+			PUTC('\n');
+			preformatted = FALSE;
+		    }
+		    START(HTML_H2);
+		    if (dir_list_style != MIXED_STYLE) {
 			START(HTML_EM);
 			PUTS(state == 'D'
 			     ? LABEL_SUBDIRECTORIES
 			     : LABEL_FILES);
 			END(HTML_EM);
-			END(HTML_H2);
-			PUTC('\n');
+		    }
+		    END(HTML_H2);
+		    PUTC('\n');
 #ifndef LONG_LIST
-			START(HTML_DIR);
+		    START(HTML_DIR);
+		    PUTC('\n');
+#endif /* !LONG_LIST */
+		}
+#else
+		if (state != DIRED_BLOK(HTBTree_object(next_element))) {
+#ifndef LONG_LIST
+		    if (state == 'D') {
+			END(HTML_DIR);
 			PUTC('\n');
+		    }
 #endif /* !LONG_LIST */
+		    state =
+			(char) (DIRED_BLOK(HTBTree_object(next_element))
+				== 'D' ? 'D' : 'F');
+		    if (preformatted) {
+			END(HTML_PRE);
+			PUTC('\n');
+			preformatted = FALSE;
 		    }
-#endif /* DIRED_SUPPORT */
+		    START(HTML_H2);
+		    START(HTML_EM);
+		    PUTS(state == 'D'
+			 ? LABEL_SUBDIRECTORIES
+			 : LABEL_FILES);
+		    END(HTML_EM);
+		    END(HTML_H2);
+		    PUTC('\n');
 #ifndef LONG_LIST
-		    START(HTML_LI);
+		    START(HTML_DIR);
+		    PUTC('\n');
 #endif /* !LONG_LIST */
 		}
+#endif /* DIRED_SUPPORT */
+#ifndef LONG_LIST
+		START(HTML_LI);
+#endif /* !LONG_LIST */
+	    }
+	    if (!preformatted) {
+		START(HTML_PRE);
+		PUTC('\n');
+		preformatted = TRUE;
+	    }
 #ifdef LONG_LIST
-		LYListFmtParse(list_format, entry, tmpfilename, target, tail);
+	    LYListFmtParse(list_format, entry, tmpfilename, target, tail);
 #else
-		HTDirEntry(target, tail, entry->file_name);
-		PUTS(entry->file_name);
-		END(HTML_A);
-		MAYBE_END(HTML_LI);
-		PUTC('\n');
+	    HTDirEntry(target, tail, entry->file_name);
+	    PUTS(entry->file_name);
+	    END(HTML_A);
+	    MAYBE_END(HTML_LI);
+	    PUTC('\n');
 #endif /* LONG_LIST */
 
-		next_element = HTBTree_next(bt, next_element);
-		/* pick up the next element of the list;
-		   if none, return NULL */
+	    next_element = HTBTree_next(bt, next_element);
+	    /* pick up the next element of the list;
+	       if none, return NULL */
 
-		/* optimize for expensive operation: */
+	    /* optimize for expensive operation: */
 #ifdef DISP_PARTIAL
-		if (num_of_entries_output %
-		    (partial_threshold > 0 ? partial_threshold : display_lines)
-		    == 0) {
-		    /* num_of_entries, num_of_entries_output... */
-		    /* HTReadProgress...(bytes, 0); */
-		    HTDisplayPartial();
-
-		    if (HTCheckForInterrupt()) {
-			_HTProgress(TRANSFER_INTERRUPTED);
-			status = HT_PARTIAL_CONTENT;
-			break;
-		    }
+	    if (num_of_entries_output %
+		(partial_threshold > 0 ? partial_threshold : display_lines)
+		== 0) {
+		/* num_of_entries, num_of_entries_output... */
+		/* HTReadProgress...(bytes, 0); */
+		HTDisplayPartial();
+
+		if (HTCheckForInterrupt()) {
+		    _HTProgress(TRANSFER_INTERRUPTED);
+		    status = HT_PARTIAL_CONTENT;
+		    break;
 		}
-		num_of_entries_output++;
+	    }
+	    num_of_entries_output++;
 #endif /* DISP_PARTIAL */
 
-	    }			/* end while next_element */
+	}			/* end while next_element */
 
-	    if (status == HT_LOADED) {
-		if (state == 'I') {
-		    START(HTML_P);
-		    PUTS("Empty Directory");
-		}
+	if (status == HT_LOADED) {
+	    if (state == 'I') {
+		START(HTML_P);
+		PUTS("Empty Directory");
+	    }
 #ifndef LONG_LIST
-		else
-		    END(HTML_DIR);
+	    else
+		END(HTML_DIR);
 #endif /* !LONG_LIST */
-	    }
-	}			/* end printing out the tree in order */
+	}
+    }				/* end printing out the tree in order */
+    if (preformatted) {
+	END(HTML_PRE);
+	PUTC('\n');
+    }
+    END(HTML_BODY);
+    PUTC('\n');
 
-	FREE(tmpfilename);
-	FREE(tail);
-	HTBTreeAndObject_free(bt);
+    FREE(tmpfilename);
+    FREE(tail);
+    HTBTreeAndObject_free(bt);
 
-	if (status == HT_LOADED) {
-	    if (HTDirReadme == HT_DIR_README_BOTTOM)
-		do_readme(target, localname);
-	    FREE_TARGET;
-	} else {
-	    ABORT_TARGET;
-	}
+    if (status == HT_LOADED) {
+	if (HTDirReadme == HT_DIR_README_BOTTOM)
+	    do_readme(target, localname);
+	FREE_TARGET;
+    } else {
+	ABORT_TARGET;
     }
     HTFinishDisplayPartial();
     return status;		/* document loaded, maybe partial */
@@ -2401,13 +2449,16 @@ int HTLoadFile(const char *addr,
 {
     char *filename = NULL;
     char *acc_method = NULL;
-    char *ftp_newhost;
     HTFormat format;
     char *nodename = NULL;
     char *newname = NULL;	/* Simplified name of file */
     HTAtom *myEncoding = NULL;	/* enc of this file, may be gzip etc. */
     int status = -1;
 
+#ifndef DISABLE_FTP
+    char *ftp_newhost;
+#endif
+
 #ifdef VMS
     struct stat stat_info;
 #endif /* VMS */
diff --git a/WWW/Library/Implementation/HTFile.h b/WWW/Library/Implementation/HTFile.h
index 146857ff..38f407f2 100644
--- a/WWW/Library/Implementation/HTFile.h
+++ b/WWW/Library/Implementation/HTFile.h
@@ -65,6 +65,12 @@ extern "C" {
     extern char *HTCacheFileName(const char *name);
 
 /*
+ *  Generate fragments of HTML for source-view:
+ */
+    extern void HTStructured_doctype(HTStructured * target, HTFormat format_out);
+
+    extern void HTStructured_meta(HTStructured * target, HTFormat format_out);
+/*
  *  Output directory titles
  *
  * This is (like the next one) used by HTFTP. It is common code to generate
@@ -74,6 +80,7 @@ extern "C" {
  * FALSE otherwise - KW
  */
     extern BOOL HTDirTitles(HTStructured * target, HTParentAnchor *anchor,
+			    HTFormat format_out,
 			    BOOL tildeIsTop);
 
 /*
diff --git a/WWW/Library/Implementation/HTMIME.c b/WWW/Library/Implementation/HTMIME.c
index 61b92f65..28814c65 100644
--- a/WWW/Library/Implementation/HTMIME.c
+++ b/WWW/Library/Implementation/HTMIME.c
@@ -308,7 +308,7 @@ static int pumpData(HTStream *me)
 						UCT_SETBY_DEFAULT);
 		    }
 		    if ((p_in->enc != UCT_ENC_CJK)
-#ifndef EXP_JAPANESEUTF8_SUPPORT
+#ifdef EXP_JAPANESEUTF8_SUPPORT
 			&& ((p_in->enc != UCT_ENC_UTF8)
 			    || (p_out->enc != UCT_ENC_CJK))
 #endif
diff --git a/WWW/Library/Implementation/HTMLGen.c b/WWW/Library/Implementation/HTMLGen.c
index 361c47fc..00c79499 100644
--- a/WWW/Library/Implementation/HTMLGen.c
+++ b/WWW/Library/Implementation/HTMLGen.c
@@ -307,8 +307,8 @@ static void HTMLGen_write(HTStructured * me, const char *s,
 /*	Start Element
  *	-------------
  *
- *	Within the opening tag, there may be spaces
- *	and the line may be broken at these spaces.
+ * Within the opening tag, there may be spaces and the line may be broken at
+ * these spaces.
  */
 static int HTMLGen_start_element(HTStructured * me, int element_number,
 				 const BOOL *present,
@@ -362,8 +362,7 @@ static int HTMLGen_start_element(HTStructured * me, int element_number,
 		fprintf(tfp, " ca=%d\n", hashStyles[hcode].color);
 	}
 
-	if (displayStyles[element_number + STARTAT].color > -2)		/* actually set */
-	{
+	if (displayStyles[element_number + STARTAT].color > -2) {
 	    CTRACE2(TRACE_STYLE,
 		    (tfp, "CSSTRIM: start_element: top <%s>\n",
 		     HTML_dtd.tags[element_number].name));
@@ -514,13 +513,11 @@ static int HTMLGen_start_element(HTStructured * me, int element_number,
 /*		End Element
  *		-----------
  *
- */
-/*	When we end an element, the style must be returned to that
- *	in effect before that element.	Note that anchors (etc?)
- *	don't have an associated style, so that we must scan down the
- *	stack for an element with a defined style. (In fact, the styles
- *	should be linked to the whole stack not just the top one.)
- *	TBL 921119
+ * When we end an element, the style must be returned to that in effect before
+ * that element.  Note that anchors (etc?) don't have an associated style, so
+ * that we must scan down the stack for an element with a defined style.  (In
+ * fact, the styles should be linked to the whole stack not just the top one.)
+ * TBL 921119
  */
 static int HTMLGen_end_element(HTStructured * me, int element_number,
 			       char **insert GCC_UNUSED)
diff --git a/WWW/Library/Implementation/HTMLGen.h b/WWW/Library/Implementation/HTMLGen.h
index 9e8b84b7..f2db3d40 100644
--- a/WWW/Library/Implementation/HTMLGen.h
+++ b/WWW/Library/Implementation/HTMLGen.h
@@ -1,8 +1,8 @@
 /*                  /Net/dxcern/userd/timbl/hypertext/WWW/Library/Implementation/HTMLGen.html
                                       HTML GENERATOR
                                              
-   This module converts structed stream into stream.  That is, given a stream to write to,
-   it will give you a structured stream to
+   This module converts structed stream into stream.  That is, given a stream
+   to write to, it will give you a structured stream to
    
  */
 #ifndef HTMLGEN_H
@@ -14,9 +14,7 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-/* Subclass:
-*//* extern const HTStructuredClass HTMLGeneration; *//* Special Creation:
- */ extern HTStructured *HTMLGenerator(HTStream *output);
+    extern HTStructured *HTMLGenerator(HTStream *output);
 
     extern HTStream *HTPlainToHTML(HTPresentation *pres,
 				   HTParentAnchor *anchor,
diff --git a/WWW/Library/Implementation/HTTCP.c b/WWW/Library/Implementation/HTTCP.c
index 25cdb170..91669582 100644
--- a/WWW/Library/Implementation/HTTCP.c
+++ b/WWW/Library/Implementation/HTTCP.c
@@ -612,6 +612,7 @@ extern int h_errno;
  * Even though it is a small amount, we cannot count on reading the whole
  * struct via a pipe in one read -TD
  */
+#ifdef NSL_FORK
 static unsigned readit(int fd, char *buffer, unsigned length)
 {
     unsigned result = 0;
@@ -629,6 +630,7 @@ static unsigned readit(int fd, char *buffer, unsigned length)
     }
     return result;
 }
+#endif /* NSL_FORK */
 
 /*	Resolve an internet hostname, like gethostbyname
  *	------------------------------------------------
diff --git a/WWW/Library/Implementation/HTUtils.h b/WWW/Library/Implementation/HTUtils.h
index 0a049577..0939c4ef 100644
--- a/WWW/Library/Implementation/HTUtils.h
+++ b/WWW/Library/Implementation/HTUtils.h
@@ -170,12 +170,24 @@ char *alloca();
 #undef FILE_DOES_NOT_EXIST	/* see <w32api/winnt.h> */
 #endif
 
-#if defined(_WINDOWS) && !defined(__CYGWIN__)	/* SCW */
+/*
+ * VS .NET 2003 includes winsock.h unconditionally from windows.h,
+ * so we do not want to include windows.h if we want winsock2.h
+ */
+#if defined(_WINDOWS) && !defined(__CYGWIN__)
+
+#if defined(USE_WINSOCK2_H)
+#include <winsock2.h>		/* includes windows.h, in turn windef.h */
+#else
 #include <windows.h>		/* #include "windef.h" */
+#endif
+
 #define BOOLEAN_DEFINED
+
 #if !_WIN_CC			/* 1999/09/29 (Wed) 22:00:53 */
 #include <dos.h>
 #endif
+
 #undef sleep			/* 1998/06/23 (Tue) 16:54:53 */
 extern void sleep(unsigned __seconds);
 
@@ -338,9 +350,13 @@ typedef char BOOLEAN;		/* Logical value */
 #define BOOLEAN_DEFINED
 #endif /* _WINDOWS */
 
+#if defined(_MSC_VER) && (_MSC_VER >= 1300)
+/* it declares BOOL/BOOLEAN as BYTE/int */
+#else
 #ifndef BOOL
 #define BOOL BOOLEAN
 #endif
+#endif
 
 #ifndef YES
 #define YES (BOOLEAN)1
diff --git a/WWW/Library/Implementation/SGML.c b/WWW/Library/Implementation/SGML.c
index 48e0587d..235c898f 100644
--- a/WWW/Library/Implementation/SGML.c
+++ b/WWW/Library/Implementation/SGML.c
@@ -228,7 +228,9 @@ struct _HTStream {
 #endif
 };
 
-#ifndef NO_LYNX_TRACE
+#ifdef NO_LYNX_TRACE
+#define state_name(n) "state"
+#else
 static const char *state_name(sgml_state n)
 {
     const char *result = "?";
diff --git a/WWW/Library/Implementation/www_tcp.h b/WWW/Library/Implementation/www_tcp.h
index bf99ce76..a8179aff 100644
--- a/WWW/Library/Implementation/www_tcp.h
+++ b/WWW/Library/Implementation/www_tcp.h
@@ -204,6 +204,10 @@ extern int ws_netread(int fd, char *buf, int len);
 #error Define "WIN32_LEAN_AND_MEAN" in your makefile
 #endif
 
+#ifdef _WINSOCKAPI_
+#error windows.h included before winsock2.h
+#endif
+
 #if defined(_MSC_VER) && (!defined(_WIN32_WINNT) || _WIN32_WINNT < 0x0501)
 /*
  * Needed to pull in the real getaddrinfo() and not the inline version