about summary refs log tree commit diff stats
path: root/WWW/Library
diff options
context:
space:
mode:
Diffstat (limited to 'WWW/Library')
-rw-r--r--WWW/Library/Implementation/HTAAUtil.c1
-rw-r--r--WWW/Library/Implementation/HTAccess.c9
-rw-r--r--WWW/Library/Implementation/HTAnchor.c17
-rw-r--r--WWW/Library/Implementation/HTCJK.h4
-rw-r--r--WWW/Library/Implementation/HTDOS.c71
-rw-r--r--WWW/Library/Implementation/HTDOS.h3
-rw-r--r--WWW/Library/Implementation/HTFTP.c45
-rw-r--r--WWW/Library/Implementation/HTFWriter.c4
-rw-r--r--WWW/Library/Implementation/HTFile.c53
-rw-r--r--WWW/Library/Implementation/HTFormat.c32
-rw-r--r--WWW/Library/Implementation/HTFormat.h2
-rw-r--r--WWW/Library/Implementation/HTMLDTD.c118
-rw-r--r--WWW/Library/Implementation/HTNews.c169
-rw-r--r--WWW/Library/Implementation/HTParse.c41
-rw-r--r--WWW/Library/Implementation/HTRules.c4
-rw-r--r--WWW/Library/Implementation/HTString.c82
-rw-r--r--WWW/Library/Implementation/HTTCP.c121
-rw-r--r--WWW/Library/Implementation/HTTCP.h4
-rw-r--r--WWW/Library/Implementation/HTTP.c198
-rw-r--r--WWW/Library/Implementation/HTTP.h4
-rw-r--r--WWW/Library/Implementation/HTUtils.h29
-rw-r--r--WWW/Library/Implementation/HTVMS_WaisUI.c2
-rw-r--r--WWW/Library/Implementation/SGML.c439
-rw-r--r--WWW/Library/Implementation/SGML.h4
-rw-r--r--WWW/Library/Implementation/getline.c4
-rw-r--r--WWW/Library/Implementation/makefile.in2
-rw-r--r--WWW/Library/Implementation/www_tcp.h (renamed from WWW/Library/Implementation/tcp.h)20
-rw-r--r--WWW/Library/djgpp/CommonMakefile2
-rw-r--r--WWW/Library/djgpp/makefile.sla6
-rw-r--r--WWW/Library/vms/descrip.mms6
30 files changed, 1200 insertions, 296 deletions
diff --git a/WWW/Library/Implementation/HTAAUtil.c b/WWW/Library/Implementation/HTAAUtil.c
index a0312b49..757f42df 100644
--- a/WWW/Library/Implementation/HTAAUtil.c
+++ b/WWW/Library/Implementation/HTAAUtil.c
@@ -48,6 +48,7 @@
 #include <HTAAUtil.h>	/* Implemented here	*/
 #include <HTAssoc.h>	/* Assoc list		*/
 #include <HTTCP.h>
+#include <HTTP.h>
 
 #include <LYStrings.h>
 #include <LYLeaks.h>
diff --git a/WWW/Library/Implementation/HTAccess.c b/WWW/Library/Implementation/HTAccess.c
index c5f8ef06..a87d14dc 100644
--- a/WWW/Library/Implementation/HTAccess.c
+++ b/WWW/Library/Implementation/HTAccess.c
@@ -355,6 +355,15 @@ PUBLIC BOOL override_proxy ARGS1(
 	    FREE(host);
 	    return YES;
 	}
+#ifdef CJK_EX	/* ASATAKU PROXY HACK */
+	if ((!templ_port || templ_port == port)	 &&
+	    (t_len > 0	&&  t_len <= h_len  &&
+	     isdigit(*no_proxy) && !strncmp(host, no_proxy, t_len))) {
+	    FREE(host);
+	    return YES;
+	}
+#endif	/* ASATAKU PROXY HACK */
+
 	if (*end)
 	    no_proxy = (end + 1);
 	else
diff --git a/WWW/Library/Implementation/HTAnchor.c b/WWW/Library/Implementation/HTAnchor.c
index ba131155..b2a911ed 100644
--- a/WWW/Library/Implementation/HTAnchor.c
+++ b/WWW/Library/Implementation/HTAnchor.c
@@ -103,7 +103,12 @@ PRIVATE HTParentAnchor * HTParentAnchor_new NOARGS
 
 PRIVATE HTChildAnchor * HTChildAnchor_new NOARGS
 {
-    return (HTChildAnchor *)calloc(1, sizeof(HTChildAnchor)); /* zero-filled */
+    HTChildAnchor *p;
+
+    p = (HTChildAnchor *)calloc(1, sizeof(HTChildAnchor)); /* zero-filled */
+    if (p == NULL)
+	outofmem(__FILE__, "HTChildAnchor_new");
+    return p;
 }
 
 
@@ -149,6 +154,12 @@ PRIVATE BOOL HTIdentical ARGS2(
 	CONST char *,	t)
 {
     if (s && t) {  /* Make sure they point to something */
+#ifdef SH_EX	/* 1998/04/28 (Tue) 22:02:58 */
+	if (*s == 'P' || *t == 'P') {
+	    if (strcmp(s + 1, "Name") == 0 || strcmp(t + 1, "Name") == 0)
+		return NO;
+	}
+#endif
 	for (; *s && *t; s++, t++) {
 	    if (*s != *t) {
 		return(NO);
@@ -202,9 +213,7 @@ PUBLIC HTChildAnchor * HTAnchor_findChild ARGS2(
     }
 
     child = HTChildAnchor_new();
-    if (child == NULL)
-	outofmem(__FILE__, "HTChildAnchor_new");
-    CTRACE(tfp, "new Anchor %p named `%s' is child of %p\n",
+    CTRACE(tfp, "HTAnchor: New Anchor %p named `%s' is child of %p\n",
 		(void *)child,
 		tag ? tag : (CONST char *)"",
 		(void *)parent); /* int for apollo */
diff --git a/WWW/Library/Implementation/HTCJK.h b/WWW/Library/Implementation/HTCJK.h
index 8765461d..95221e38 100644
--- a/WWW/Library/Implementation/HTCJK.h
+++ b/WWW/Library/Implementation/HTCJK.h
@@ -41,12 +41,12 @@
 #define IS_EUC_LOS(lo)	((0x21<=lo)&&(lo<=0x7E))	/* standard */
 #define IS_EUC_LOX(lo)	((0xA1<=lo)&&(lo<=0xFE))	/* extended */
 #define IS_EUC_HI(hi)	((0xA1<=hi)&&(hi<=0xFE))
-#define IS_EUC(hi,lo) IS_EUC_HI(hi) && (IS_EUC_LOS(lo) || IS_EUC_LOX(lo))
+#define IS_EUC(hi,lo) (IS_EUC_HI(hi) && (IS_EUC_LOS(lo) || IS_EUC_LOX(lo)))
 
 #define IS_BIG5_LOS(lo)	((0x40<=lo)&&(lo<=0x7E))	/* standard */
 #define IS_BIG5_LOX(lo)	((0xA1<=lo)&&(lo<=0xFE))	/* extended */
 #define IS_BIG5_HI(hi)	((0xA1<=hi)&&(hi<=0xFE))
-#define IS_BIG5(hi,lo) IS_BIG5_HI(hi) && (IS_BIG5_LOS(lo) || IS_BIG5_LOX(lo))
+#define IS_BIG5(hi,lo) (IS_BIG5_HI(hi) && (IS_BIG5_LOS(lo) || IS_BIG5_LOX(lo)))
 
 typedef enum _HTkcode {NOKANJI, EUC, SJIS, JIS} HTkcode;
 typedef enum _HTCJKlang {NOCJK, JAPANESE, CHINESE, KOREAN, TAIPEI} HTCJKlang;
diff --git a/WWW/Library/Implementation/HTDOS.c b/WWW/Library/Implementation/HTDOS.c
index 8b8231f0..a1b5cb4b 100644
--- a/WWW/Library/Implementation/HTDOS.c
+++ b/WWW/Library/Implementation/HTDOS.c
@@ -5,6 +5,12 @@
 #include <HTUtils.h>
 #include <HTDOS.h>
 
+#ifdef _WINDOWS
+#include <HTString.h>
+#include <stdio.h>
+#include <windows.h>
+#endif
+
 /*
  * Make a copy of the source argument in the result, allowing some extra
  * space so we can append directly onto the result without reallocating.
@@ -28,14 +34,42 @@ PRIVATE char * copy_plus ARGS2(char **, result, char *, source)
 */
 char * HTDOS_wwwName ARGS1(char *, dosname)
 {
-    static char *wwwname;
+    static char *wwwname = NULL;
     char *cp_url = copy_plus(&wwwname, dosname);
+    int wwwname_len;
 
+#ifdef SH_EX
+    char ch;
+
+    while ((ch = *dosname) != '\0') {
+	switch (ch) {
+	case '\\':
+	/* convert dos backslash to unix-style */
+	    *cp_url++ = '/';
+	    break;
+	case ' ':
+	    *cp_url++ = '%';
+	    *cp_url++ = '2';
+	    *cp_url++ = '0';
+	    break;
+      default:
+	    *cp_url++ = ch;
+	    break;;
+      }
+      dosname++;
+    }
+    *cp_url = '\0';
+#else
     for ( ; *cp_url != '\0' ; cp_url++)
 	if(*cp_url == '\\')
 	    *cp_url = '/';   /* convert dos backslash to unix-style */
+#endif
+
+    wwwname_len = strlen(wwwname);
+    if (wwwname_len > 1)
+	cp_url--;	/* point last char */
 
-    if(strlen(wwwname) > 3 && *cp_url == '/')
+    if (wwwname_len > 3 && *cp_url == '/')
 	*cp_url = '\0';
 
 #ifdef NOTUSED
@@ -59,10 +93,15 @@ char * HTDOS_wwwName ARGS1(char *, dosname)
 */
 char * HTDOS_name ARGS1(char *, wwwname)
 {
-    static char *cp_url;
-    char *result;
+#ifdef _WINDOWS	/* 1998/04/02 (Thu) 08:47:20 */
+    extern char windows_drive[];
+    char temp_buff[LY_MAXPATH];
+#endif
+    static char *cp_url = NULL;
+    char *result, *ret;
     int joe;
 
+    CTRACE(tfp, "HTDOS_name changed `%s'\n", wwwname);
     copy_plus(&cp_url, wwwname);
 
     for (joe = 0; cp_url[joe] != '\0'; joe++)	{
@@ -79,6 +118,26 @@ char * HTDOS_name ARGS1(char *, wwwname)
 	result = cp_url+1;
     }
 
-    CTRACE(tfp, "HTDOS_name changed `%s' to `%s'\n", wwwname, result);
-    return (result);
+#ifdef _WINDOWS	/* 1998/04/02 (Thu) 08:59:48 */
+    if (strchr(result, '\\') && strchr(result, ':')==NULL) {
+	sprintf(temp_buff, "%s\\%s", windows_drive, result);
+	ret = NULL;
+	StrAllocCopy(ret, temp_buff);
+	free(cp_url);
+    } else {
+	char *p;
+	p = strchr(result, ':');
+	if (p && (strcmp(p, ":\\") == 0)) {
+	    p[2] = '.';
+	    p[3] = '\0';
+	}
+	ret = result;
+    }
+#else
+    ret = result;
+#endif
+
+    CTRACE(tfp, "HTDOS_name changed `%s' to `%s'\n", wwwname, ret);
+    return (ret);
 }
+
diff --git a/WWW/Library/Implementation/HTDOS.h b/WWW/Library/Implementation/HTDOS.h
index 37a61386..a4c68446 100644
--- a/WWW/Library/Implementation/HTDOS.h
+++ b/WWW/Library/Implementation/HTDOS.h
@@ -31,5 +31,8 @@ char * HTDOS_wwwName PARAMS((char * dosname));
 */
 char * HTDOS_name PARAMS((char * wwwname));
 
+#ifdef __WIN32__
+char * HTDOS_short_name (char * fn);
+#endif
 
 #endif /*  HTDOS_H */
diff --git a/WWW/Library/Implementation/HTFTP.c b/WWW/Library/Implementation/HTFTP.c
index 86544009..208020da 100644
--- a/WWW/Library/Implementation/HTFTP.c
+++ b/WWW/Library/Implementation/HTFTP.c
@@ -78,6 +78,8 @@ BUGS:	@@@	Limit connection cache size!
 #include <HTUtils.h>
 
 #include <HTAlert.h>
+#include <HTTCP.h>
+#include <HTTP.h>
 
 #include <HTFTP.h>	/* Implemented here */
 
@@ -2631,7 +2633,14 @@ AgainForMultiNet:
 
 	    BytesReceived += chunk->size;
 	    if (BytesReceived > BytesReported + 1024) {
+#ifdef _WINDOWS
+		extern int ws_read_per_sec;
+
+		sprintf(NumBytes,gettext("Transferred %d bytes (%5d)"),
+				BytesReceived, ws_read_per_sec);
+#else
 		sprintf(NumBytes, TRANSFERRED_X_BYTES, BytesReceived);
+#endif
 		HTProgress(NumBytes);
 		BytesReported = BytesReceived;
 	    }
@@ -2682,6 +2691,14 @@ unload_btree:
 	/* Run through tree printing out in order
 	 */
 	{
+#ifdef SH_EX	/* 1997/10/18 (Sat) 14:14:28 */
+	    char *p, name_buff[256];
+	    int  name_len, dot_len;
+
+#define	FNAME_WIDTH	30
+#define	FILE_GAP	2
+
+#endif
 	    HTBTElement * ele;
 	    int i;
 	    for (ele = HTBTree_next(bt, NULL);
@@ -2705,16 +2722,44 @@ unload_btree:
 
 		/* start the anchor */
 		HTDirEntry(target, lastpath, entry_info->filename);
+#ifdef SH_EX	/* 1997/10/18 (Sat) 16:00 */
+		name_len = strlen(entry_info->filename);
+
+		sprintf(name_buff, "%-30s", entry_info->filename);
+
+		if (name_len < FNAME_WIDTH) {
+		    dot_len = FNAME_WIDTH - FILE_GAP - name_len;
+		    if (dot_len > 0) {
+			p = name_buff + name_len + 1;
+			while (dot_len--)
+			    *p++ = '.';
+		    }
+		} else {
+		    name_buff[FNAME_WIDTH] = '\0';
+		}
+
+		PUTS(name_buff);
+#else
 		PUTS(entry_info->filename);
+#endif
 		END(HTML_A);
 
 		if (entry_info->size) {
+#ifdef SH_EX	/* 1998/02/02 (Mon) 16:34:52 */
+		    if (entry_info->size < 1024)
+			sprintf(string_buffer, "%6d bytes",
+					       entry_info->size);
+		    else
+			sprintf(string_buffer, "%6d Kb",
+					        entry_info->size/1024);
+#else
 		    if (entry_info->size < 1024)
 			sprintf(string_buffer, "  %d bytes",
 					       entry_info->size);
 		    else
 			sprintf(string_buffer, "  %dKb",
 						entry_info->size/1024);
+#endif
 		    PUTS(string_buffer);
 		}
 
diff --git a/WWW/Library/Implementation/HTFWriter.c b/WWW/Library/Implementation/HTFWriter.c
index b101e95c..468916de 100644
--- a/WWW/Library/Implementation/HTFWriter.c
+++ b/WWW/Library/Implementation/HTFWriter.c
@@ -256,7 +256,7 @@ PUBLIC HTStream* HTSaveAndExecute ARGS3(
     tmpnam (fnam);
     if (suffix) strcat(fnam, suffix);
 
-    me->fp = fopen (fnam, "w");
+    me->fp = fopen (fnam, "wb");
     if (!me->fp) {
 	HTAlert(CANNOT_OPEN_TEMP);
         FREE(fnam);
@@ -333,7 +333,7 @@ PUBLIC HTStream* HTSaveLocally ARGS3(
 
     FREE(fnam);
 
-    me->fp = fopen (answer, "w");
+    me->fp = fopen (answer, "wb");
     if (!me->fp) {
 	HTAlert(CANNOT_OPEN_OUTPUT);
         FREE(answer);
diff --git a/WWW/Library/Implementation/HTFile.c b/WWW/Library/Implementation/HTFile.c
index f4699191..8a213373 100644
--- a/WWW/Library/Implementation/HTFile.c
+++ b/WWW/Library/Implementation/HTFile.c
@@ -140,10 +140,7 @@ PRIVATE HTSuffix unknown_suffix = { "*.*", NULL, NULL, NULL, 1.0};
 
 
 #ifdef _WINDOWS
-int exists(char *filename)
-{
- return (access(filename,0)==0);
-}
+#define exists(p)	(access(p,0)==0)
 #endif
 
 
@@ -207,12 +204,22 @@ PRIVATE void LYListFmtParse ARGS5(
 	char *datestr;
 	int len;
 #define SEC_PER_YEAR	(60 * 60 * 24 * 365)
+
+#ifdef _WINDOWS	/* 1998/01/06 (Tue) 21:20:53 */
+	static char *pbits[] = {
+		"---", "--x", "-w-", "-wx",
+		"r--", "r-x", "rw-", "rwx", 
+		0 };
+#define PBIT(a, n, s)  pbits[((a) >> (n)) & 0x7] 
+
+#else
 	static char *pbits[] = { "---", "--x", "-w-", "-wx",
 		"r--", "r-x", "rw-", "rwx", 0 };
 	static char *psbits[] = { "--S", "--s", "-wS", "-ws",
 		"r-S", "r-s", "rwS", "rws", 0 };
 #define PBIT(a, n, s)  (s) ? psbits[((a) >> (n)) & 0x7] : \
 	pbits[((a) >> (n)) & 0x7]
+#endif
 #ifdef S_ISVTX
 	static char *ptbits[] = { "--T", "--t", "-wT", "-wt",
 		"r-T", "r-t", "rwT", "rwt", 0 };
@@ -221,8 +228,13 @@ PRIVATE void LYListFmtParse ARGS5(
 #define PTBIT(a, s)  PBIT(a, 0, 0)
 #endif
 
+#ifdef _WINDOWS
+	if (stat(file, &st) < 0)
+		fmtstr = "    %a";	/* can't stat so just do anchor */
+#else
 	if (lstat(file, &st) < 0)
 		fmtstr = "    %a";	/* can't stat so just do anchor */
+#endif
 
 	StrAllocCopy(str, fmtstr);
 	s = str;
@@ -340,7 +352,11 @@ PRIVATE void LYListFmtParse ARGS5(
 
 		case 'p':	/* unix-style permission bits */
 			switch(st.st_mode & S_IFMT) {
+#if defined(_MSC_VER) && defined(_S_IFIFO)
+			case _S_IFIFO: type = 'p'; break;
+#else
 			case S_IFIFO: type = 'p'; break;
+#endif
 			case S_IFCHR: type = 'c'; break;
 			case S_IFDIR: type = 'd'; break;
 			case S_IFREG: type = '-'; break;
@@ -361,13 +377,23 @@ PRIVATE void LYListFmtParse ARGS5(
 #endif /* S_IFSOCK */
 			default: type = '?'; break;
 			}
+#ifdef _WINDOWS
+			sprintf(tmp, "%c%s", type, 
+				PBIT(st.st_mode, 6, st.st_mode & S_IRWXU));
+#else
 			sprintf(tmp, "%c%s%s%s", type,
 				PBIT(st.st_mode, 6, st.st_mode & S_ISUID),
 				PBIT(st.st_mode, 3, st.st_mode & S_ISGID),
 				PTBIT(st.st_mode,   st.st_mode & S_ISVTX));
+#endif
 			FormatStr(&buf, start, tmp);
 			break;
 
+#ifdef _WINDOWS
+		case 'o':	/* owner */
+		case 'g':	/* group */
+			break;
+#else
 		case 'o':	/* owner */
 			name = HTAA_UidToName (st.st_uid);
 			if (*name) {
@@ -385,6 +411,7 @@ PRIVATE void LYListFmtParse ARGS5(
 				FormatNum(&buf, start, (int) st.st_gid);
 			}
 			break;
+#endif
 
 		case 'l':	/* link count */
 			FormatNum(&buf, start, (int) st.st_nlink);
@@ -665,7 +692,12 @@ PUBLIC char * HTnameOfFile_WWW ARGS3(
 	else
 	    home = HTVMS_wwwName(home);
 #else
-	if ((home = getenv("HOME")) == 0)
+#if defined(_WINDOWS)	/* 1997/10/16 (Thu) 20:42:51 */
+	home =  (char *)Home_Dir();
+#else
+	home = getenv("HOME");
+#endif
+	if (home == 0)
 	    home = "/tmp";
 #endif /* VMS */
 	HTSprintf0(&result, "%s/WWW/%s/%s%s", home, acc_method, host, path);
@@ -1078,7 +1110,7 @@ PUBLIC float HTFileValue ARGS1(
 	    return suff->quality;		/* OK -- found */
 	}
     }
-    return 0.3;		/* Dunno! */
+    return (float)0.3;		/* Dunno! */
 }
 
 /*	Determine write access to a file.
@@ -1178,7 +1210,7 @@ PUBLIC HTStream * HTFileSaveStream ARGS1(
     CONST char * addr = HTAnchor_address((HTAnchor*)anchor);
     char *  localname = HTLocalName(addr);
 
-    FILE* fp = fopen(localname, "w");
+    FILE* fp = fopen(localname, "wb");
     if (!fp)
 	return NULL;
 
@@ -1369,9 +1401,10 @@ PUBLIC BOOL HTDirTitles ARGS3(
 	HTSprintf0(&relative, "%s/..", current);
 
 #ifdef DOSPATH
-	if (local_link)
+	if (local_link) {
 	    if (strlen(parent) == 3 )
 		StrAllocCat(relative, "/.");
+	}
 #endif
 
 #if !defined (VMS)
@@ -1951,7 +1984,7 @@ PUBLIC int HTLoadFile ARGS4(
 	FREE(newname);
 	FREE(acc_method);
     }
-#ifdef VMS
+#if defined(VMS) || defined(DOSPATH)
     HTUnEscape(filename);
 #endif /* VMS */
 
@@ -2420,7 +2453,7 @@ PUBLIC int HTLoadFile ARGS4(
 */
 #endif /* HAVE_READDIR */
 	{
-#  ifdef __EMX__
+#  if defined(__EMX__) || defined(WIN_EX)
 	    int len = strlen(localname);
 	    int bin = ((len > 3) && !strcasecomp(localname + len - 3, ".gz"));
 	    FILE * fp = fopen(localname, (bin ? "rb" : "r"));
diff --git a/WWW/Library/Implementation/HTFormat.c b/WWW/Library/Implementation/HTFormat.c
index b2c933ef..f44bd543 100644
--- a/WWW/Library/Implementation/HTFormat.c
+++ b/WWW/Library/Implementation/HTFormat.c
@@ -396,9 +396,11 @@ PUBLIC HTStream * HTStreamStack ARGS4(
 
     /* don't return on WWW_SOURCE some people might like
      * to make use of the source!!!!  LJM
-     *//*
+     */
+#if 0
     if (rep_out == WWW_SOURCE || rep_out == rep_in)
-	return sink;  LJM */
+	return sink;	/*  LJM */
+#endif
 
     if (rep_out == rep_in)
 	return sink;
@@ -594,6 +596,12 @@ PUBLIC int HTCopy ARGS4(
     HTStreamClass targetClass;
     int bytes;
     int rv = 0;
+#ifdef _WINDOWS	/* 1997/11/11 (Tue) 15:18:16 */
+    long file_length;
+    extern int bytes_already_read;
+    
+    file_length = anchor->content_length;
+#endif
 
     /*	Push the data down the stream
     */
@@ -638,6 +646,9 @@ PUBLIC int HTCopy ARGS4(
 		    rv = -1;
 		goto finished;
 	    } else if (SOCKET_ERRNO == ENOTCONN ||
+#ifdef _WINDOWS	/* 1997/11/10 (Mon) 16:57:18 */
+		       SOCKET_ERRNO == ETIMEDOUT || 
+#endif
 		       SOCKET_ERRNO == ECONNRESET ||
 		       SOCKET_ERRNO == EPIPE) {
 		/*
@@ -818,11 +829,12 @@ PUBLIC int HTMemCopy ARGS2(
 	HTChunk *,		chunk,
 	HTStream *,		sink)
 {
-    HTStreamClass targetClass = *(sink->isa);
+    HTStreamClass targetClass;
     int bytes = 0;
     CONST char *data = chunk->data;
     int rv = HT_OK;
 
+    targetClass = *(sink->isa);
     HTReadProgress(0, 0);
     for (;;) {
 	/* Push the data down the stream a piece at a time, in case we're
@@ -1078,9 +1090,12 @@ PUBLIC int HTParseFile ARGS5(
     HTStreamClass targetClass;
     int rv;
 
-    stream = HTStreamStack(rep_in,
-			format_out,
-			sink , anchor);
+#ifdef SH_EX		/* 1998/01/04 (Sun) 16:04:09 */
+    if (fp == NULL)
+	return HT_LOADED;
+#endif
+
+    stream = HTStreamStack(rep_in, format_out, sink, anchor);
 
     if (!stream) {
 	char *buffer = 0;
@@ -1211,9 +1226,7 @@ PUBLIC int HTParseGzFile ARGS5(
     HTStreamClass targetClass;
     int rv;
 
-    stream = HTStreamStack(rep_in,
-			format_out,
-			sink , anchor);
+    stream = HTStreamStack(rep_in, format_out, sink, anchor);
 
     if (!stream) {
 	char *buffer = 0;
@@ -1334,4 +1347,3 @@ PUBLIC HTStream * HTNetToText ARGS1(HTStream *, sink)
     me->sink = sink;
     return me;
 }
-
diff --git a/WWW/Library/Implementation/HTFormat.h b/WWW/Library/Implementation/HTFormat.h
index 42aeea50..4d119a66 100644
--- a/WWW/Library/Implementation/HTFormat.h
+++ b/WWW/Library/Implementation/HTFormat.h
@@ -282,7 +282,7 @@ extern float HTStackValue PARAMS((
         float                   initial_value,
         long int                length));
 
-#define NO_VALUE_FOUND  -1e20           /* returned if none found */
+#define NO_VALUE_FOUND  -1e20	/* returned if none found */
 
 /*	Display the page while transfer in progress
 **	-------------------------------------------
diff --git a/WWW/Library/Implementation/HTMLDTD.c b/WWW/Library/Implementation/HTMLDTD.c
index b5b6706e..ddea0b49 100644
--- a/WWW/Library/Implementation/HTMLDTD.c
+++ b/WWW/Library/Implementation/HTMLDTD.c
@@ -8,6 +8,7 @@
 #include <HTUtils.h>
 #include <HTMLDTD.h>
 #include <LYLeaks.h>
+#include <LYJustify.h>
 
 /*
  *     Character entities like &nbsp now excluded from our DTD tables,
@@ -86,7 +87,7 @@ static CONST char* entities[] = {
   "frac12",	/* fraction 1/2 */
   "frac14",	/* fraction 1/4 */
   "frac34",	/* fraction 3/4 */
-  "gt", 	/* greater than */
+  "gt",		/* greater than */
   "hibar",	/* spacing macron */
   "iacute",	/* small i, acute accent */
   "icirc",	/* small i, circumflex accent */
@@ -95,7 +96,7 @@ static CONST char* entities[] = {
   "iquest",	/* inverted question mark */
   "iuml",	/* small i, dieresis or umlaut mark */
   "laquo",	/* angle quotation mark, left */
-  "lt", 	/* less than */
+  "lt",		/* less than */
   "macr",	/* spacing macron */
   "mdash",	/* dash the width of emsp */
   "micro",	/* micro sign */
@@ -279,7 +280,7 @@ static attr body_attr[] = {			/* BODY attributes */
 	{ 0               T(N) } /* Terminate list */
 };
 
-static attr bodytext_attr[] = { 		/* BODYTEXT attributes */
+static attr bodytext_attr[] = {			/* BODYTEXT attributes */
 	{ "CLASS"         T(c) },
 	{ "CLEAR"         T(N) },
 	{ "DATA"          T(N) },
@@ -427,7 +428,7 @@ static attr fig_attr[] = {			/* FIG attributes */
 	{ 0               T(N) }	/* Terminate list */
 };
 
-static attr fieldset_attr[] = { 		/* FIELDSET attributes */
+static attr fieldset_attr[] = {			/* FIELDSET attributes */
 	{ "CLASS"         T(c) },
 	{ "CLEAR"         T(N) },
 	{ "DIR"           T(N) },
@@ -494,7 +495,7 @@ static attr frame_attr[] = {			/* FRAME attributes */
 	{ 0               T(N) }	/* Terminate list */
 };
 
-static attr frameset_attr[] = { 		/* FRAMESET attributes */
+static attr frameset_attr[] = {			/* FRAMESET attributes */
 	{ "COLS"          T(N) },
 	{ "ROWS"          T(N) },
 	{ 0               T(N) }	/* Terminate list */
@@ -511,7 +512,7 @@ static attr gen_attr[] = {			/* Minimum HTML 3.0 */
 	{ 0               T(N) }	/* Terminate list */
 };
 
-static attr glossary_attr[] = { 		/* DL (and DLC) attributes */
+static attr glossary_attr[] = {			/* DL (and DLC) attributes */
 	{ "CLASS"         T(c) },
 	{ "CLEAR"         T(N) },
 	{ "COMPACT"       T(N) },
@@ -993,7 +994,7 @@ static attr td_attr[] = {			/* TD and TH attributes */
 	{ 0               T(N) }	/* Terminate list */
 };
 
-static attr textarea_attr[] = { 		/* TEXTAREA attributes */
+static attr textarea_attr[] = {			/* TEXTAREA attributes */
 	{ "ACCEPT-CHARSET" T(N) },	/* RFC 2070 HTML i18n - kw */
 	{ "ALIGN"         T(N) },
 	{ "CLASS"         T(c) },
@@ -1076,7 +1077,7 @@ static attr ulist_attr[] = {			/* UL attributes */
    BASEFONT, APPLET, OBJECT, EMBED, SCRIPT, MAP, MARQUEE, HR, ISINDEX, BGSOUND, TAB,?IMG,
    1 e?      2	     2 l     1 e    2 l     8	 4	  4 E 1? E     1 E	! E ?1 E
    IMAGE, BR, plus NOEMBED, SERVER, SPACER, AUDIOSCOPE, and SIDEBAR; ?area
-   1 n	  1 E	     n	      n       n       n 	      n       8 E
+   1 n	  1 E	     n	      n	      n	      n		      n	      8 E
 
    %text;
 
@@ -1148,7 +1149,7 @@ static attr ulist_attr[] = {			/* UL attributes */
  /* { "BIG"	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED }, */
 #define T_BIG		0x0001, 0x8B04F,0x8FFFF,0xA778F,0xF7FBF,0x00001,0x00014
  /* { "BLINK"	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED }, */
-#define T_BLINK 	0x0001, 0x8B04F,0x8FFFF,0xA778F,0xF7FAF,0x00001,0x00014
+#define T_BLINK		0x0001, 0x8B04F,0x8FFFF,0xA778F,0xF7FAF,0x00001,0x00014
  /* { "BLOCKQUOTE", bq_attr,	HTML_BQ_ATTRIBUTES,	SGML_MIXED }, */
 #define T_BLOCKQUOTE	0x0200, 0xAFBCF,0xAFFFF,0xB6680,0xB6FAF,0x8031F,0x00000
  /* { "BODY"	, body_attr,	HTML_BODY_ATTRIBUTES,	SGML_MIXED }, */
@@ -1195,7 +1196,7 @@ static attr ulist_attr[] = {			/* UL attributes */
  /* { "EM"	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED }, */
 #define T_EM		0x0002, 0x8B04F,0x8FFFF,0xA778F,0xF7FAF,0x00003,0x00010
  /* { "EMBED"	, embed_attr,	HTML_EMBED_ATTRIBUTES,	SGML_EMPTY }, */
-#define T_EMBED 	0x2000, 0x8F107,0x8FFF7,0xB6FBF,0xB7FBF,0x1FF7F,0x00001
+#define T_EMBED		0x2000, 0x8F107,0x8FFF7,0xB6FBF,0xB7FBF,0x1FF7F,0x00001
  /* { "FIELDSET", fieldset_attr,HTML_FIELDSET_ATTRIBUTES, SGML_MIXED }, */
 #define T_FIELDSET	0x0200, 0x0FB42,0x0FF5F,0x07787,0x37FF7,0x8805F,0x00000
  /* { "FIG"	, fig_attr,	HTML_FIG_ATTRIBUTES,	SGML_MIXED }, */
@@ -1207,7 +1208,7 @@ static attr ulist_attr[] = {			/* UL attributes */
  /* { "FORM"	, form_attr,	HTML_FORM_ATTRIBUTES,	SGML_EMPTY }, */
 #define T_FORM		0x0080, 0x0FF6F,0x0FF7F,0x36E07,0x33F07,0x88DFF,0x00000
  /* { "FRAME"	, frame_attr,	HTML_FRAME_ATTRIBUTES,	SGML_EMPTY }, */
-#define T_FRAME 	0x10000,0x00000,0x00000,0x10000,0x10000,0x9FFFF,0x00001
+#define T_FRAME		0x10000,0x00000,0x00000,0x10000,0x10000,0x9FFFF,0x00001
  /* { "FRAMESET", frameset_attr,HTML_FRAMESET_ATTRIBUTES, SGML_MIXED }, */
 #define T_FRAMESET	0x10000,0x90000,0x90000,0x90000,0x93000,0x9FFFF,0x00000
  /* { "H1"	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED }, */
@@ -1235,7 +1236,7 @@ static attr ulist_attr[] = {			/* UL attributes */
  /* { "IMG"	, img_attr,	HTML_IMG_ATTRIBUTES,	SGML_EMPTY }, */
 #define T_IMG		0x1000, 0x00000,0x00000,0x3779F,0x37FBF,0x80000,0x00001
  /* { "INPUT"	, input_attr,	HTML_INPUT_ATTRIBUTES,	SGML_EMPTY }, */
-#define T_INPUT 	0x0040, 0x00000,0x00000,0x03F87,0x37F87,0x8904F,0x00001
+#define T_INPUT		0x0040, 0x00000,0x00000,0x03F87,0x37F87,0x8904F,0x00001
  /* { "INS"	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED }, */
 #define T_INS		0x0002, 0x8B04F,0x8FFFF,0xA778F,0xF7FBF,0x00003,0x00000
  /* { "ISINDEX" , isindex_attr, HTML_ISINDEX_ATTRIBUTES,SGML_EMPTY }, */
@@ -1245,7 +1246,7 @@ static attr ulist_attr[] = {			/* UL attributes */
  /* { "KEYGEN"	, keygen_attr,	HTML_KEYGEN_ATTRIBUTES, SGML_EMPTY }, */
 #define T_KEYGEN	0x0040, 0x00000,0x00000,0x07FB7,0x37FB7,0x80070,0x00001
  /* { "LABEL"	, label_attr,	HTML_LABEL_ATTRIBUTES,	SGML_MIXED }, */
-#define T_LABEL 	0x0020, 0x9FFFF,0x9FFFF,0x9FFFF,0x9FFFF,0x00007,0x00000
+#define T_LABEL		0x0020, 0x9FFFF,0x9FFFF,0x9FFFF,0x9FFFF,0x00007,0x00000
 #define T_LEGEND	0x0002, 0x0B04F,0x0FF7F,0x00200,0x37FA7,0x00003,0x00000
  /* { "LH"	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_EMPTY }, */
 #define T_LH		0x0400, 0x0BB7F,0x8FFFF,0x00800,0x97FFF,0x8071F,0x00001
@@ -1282,7 +1283,7 @@ static attr ulist_attr[] = {			/* UL attributes */
  /* { "P"	, p_attr,	HTML_P_ATTRIBUTES,	SGML_EMPTY }, */
 #define T_P		0x0100, 0x0B04F,0x8FFFF,0x36680,0xB6FA7,0x80117,0x00001
  /* { "PARAM"	, param_attr,	HTML_PARAM_ATTRIBUTES,	SGML_EMPTY }, */
-#define T_PARAM 	0x1000, 0x00000,0x00000,0x33500,0x37FFF,0x81560,0x00001
+#define T_PARAM		0x1000, 0x00000,0x00000,0x33500,0x37FFF,0x81560,0x00001
  /* { "PLAINTEXT", gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_LITTERAL }, */
 #define T_PLAINTEXT	0x10000,0xFFFFF,0xFFFFF,0x90000,0x90000,0x3FFFF,0x00001
  /* { "PRE"	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED }, */
@@ -1299,7 +1300,7 @@ static attr ulist_attr[] = {			/* UL attributes */
 #define T_SELECT	0x0040, 0x08000,0x08000,0x03FAF,0x13FBF,0x80F5F,0x00008
 #define T_SHY		0x1000, 0x00000,0x00000,0x3779F,0x77FBF,0x8101F,0x00001
  /* { "SMALL"	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED }, */
-#define T_SMALL 	0x0001, 0x8B04F,0x8FFFF,0xA778F,0xF7FBF,0x00001,0x00014
+#define T_SMALL		0x0001, 0x8B04F,0x8FFFF,0xA778F,0xF7FBF,0x00001,0x00014
  /* { "SPAN"	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED }, */
 #define T_SPAN		0x0002, 0x8B04F,0x8FFFF,0xA778F,0xF7FBF,0x80003,0x00000
  /* { "SPOT"	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_EMPTY }, */
@@ -1309,7 +1310,7 @@ static attr ulist_attr[] = {			/* UL attributes */
  /* { "STRONG"	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED }, */
 #define T_STRONG	0x0002, 0x8B04F,0x8FFFF,0xA778F,0xF7FAF,0x00003,0x00010
  /* { "STYLE"	, style_attr,	HTML_STYLE_ATTRIBUTES,	SGML_LITTERAL }, */
-#define T_STYLE 	0x40000,0x00000,0x00000,0x7638F,0x76FAF,0x8001F,0x00000
+#define T_STYLE		0x40000,0x00000,0x00000,0x7638F,0x76FAF,0x8001F,0x00000
  /* { "SUB"	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED }, */
 #define T_SUB		0x0004, 0x8B05F,0x8FFFF,0x8779F,0xF7FBF,0x00007,0x00000
  /* { "SUP"	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED }, */
@@ -1317,9 +1318,9 @@ static attr ulist_attr[] = {			/* UL attributes */
  /* { "TAB"	, tab_attr,	HTML_TAB_ATTRIBUTES,	SGML_EMPTY }, */
 #define T_TAB		0x1000, 0x00000,0x00000,0x3778F,0x57FAF,0x00001,0x00001
  /* { "TABLE"	, table_attr,	HTML_TABLE_ATTRIBUTES,	SGML_MIXED }, */
-#define T_TABLE 	0x0800, 0x0F1E0,0x8FFFF,0x36680,0xB6FA7,0x8C57F,0x00000
+#define T_TABLE		0x0800, 0x0F1E0,0x8FFFF,0x36680,0xB6FA7,0x8C57F,0x00000
  /* { "TBODY"	, tr_attr,	HTML_TR_ATTRIBUTES,	SGML_EMPTY }, */
-#define T_TBODY 	0x0020, 0x00020,0x8FFFF,0x00880,0xB7FB7,0x8C75F,0x00003
+#define T_TBODY		0x0020, 0x00020,0x8FFFF,0x00880,0xB7FB7,0x8C75F,0x00003
  /* { "TD"	, td_attr,	HTML_TD_ATTRIBUTES,	SGML_EMPTY }, */
 #define T_TD		0x0400, 0x0FBCF,0x8FFFF,0x00020,0xB7FB7,0x8C75F,0x00001
  /* { "TEXTAREA", textarea_attr,HTML_TEXTAREA_ATTRIBUTES, SGML_LITTERAL }, */
@@ -1327,13 +1328,13 @@ static attr ulist_attr[] = {			/* UL attributes */
  /* { "TEXTFLOW", bodytext_attr,HTML_BODYTEXT_ATTRIBUTES, SGML_MIXED }, */
 #define T_TEXTFLOW	0x20000,0x8FBFF,0x9FFFF,0x977B0,0xB7FB7,0x9B00F,0x00003
  /* { "TFOOT"	, tr_attr,	HTML_TR_ATTRIBUTES,	SGML_EMPTY }, */
-#define T_TFOOT 	0x0020, 0x00020,0x8FFFF,0x00800,0xB7FB7,0x8CF5F,0x00001
+#define T_TFOOT		0x0020, 0x00020,0x8FFFF,0x00800,0xB7FB7,0x8CF5F,0x00001
  /* { "TH"	, td_attr,	HTML_TD_ATTRIBUTES,	SGML_EMPTY }, */
 #define T_TH		0x0400, 0x0FBCF,0x0FFFF,0x00020,0xB7FB7,0x8CF5F,0x00001
  /* { "THEAD"	, tr_attr,	HTML_TR_ATTRIBUTES,	SGML_EMPTY }, */
-#define T_THEAD 	0x0020, 0x00020,0x8FFFF,0x00800,0xB7FB7,0x8CF5F,0x00001
+#define T_THEAD		0x0020, 0x00020,0x8FFFF,0x00800,0xB7FB7,0x8CF5F,0x00001
  /* { "TITLE",	  gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_RCDATA }, */
-#define T_TITLE 	0x40000,0x00000,0x00000,0x50000,0x50000,0x0031F,0x00004
+#define T_TITLE		0x40000,0x00000,0x00000,0x50000,0x50000,0x0031F,0x00004
  /* { "TR"	, tr_attr,	HTML_TR_ATTRIBUTES,	SGML_EMPTY }, */
 #define T_TR		0x0020, 0x00400,0x8FFFF,0x00820,0xB7FB7,0x8C75F,0x00001
  /* { "TT"	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED }, */
@@ -1361,14 +1362,24 @@ static attr ulist_attr[] = {			/* UL attributes */
 **  of the tags_old[] table (otherwise unchanged from original Lynx treatment)
 **  with the tags_new[] table below. - kw
 **
-**    Name,	Attributes,	No. of attributes,     content,   extra info...
+**    Name*,	Attributes,	No. of attributes,     content,   extra info...
 */
 #ifdef USE_COLOR_STYLE
-#define P(x) x , (sizeof x) -1
-#define NULL_HTTag NULL, 0
+#define P_(x) x , (sizeof x) -1
+#define NULL_HTTag_ NULL, 0
 #else
-#define P(x) x
-#define NULL_HTTag NULL
+#define P_(x) x
+#define NULL_HTTag_ NULL
+#endif
+
+#ifdef EXP_JUSTIFY_ELTS
+#define P(x) P_(x), 1
+#define P0(x) P_(x), 0
+#define NULL_HTTag NULL_HTTag_,0
+#else
+#define P(x) P_(x)
+#define P0(x) P_(x)
+#define NULL_HTTag NULL_HTTag_
 #endif
 
 static CONST HTTag tags_old[HTML_ELEMENTS] = {
@@ -1381,7 +1392,7 @@ static CONST HTTag tags_old[HTML_ELEMENTS] = {
  { P("AU")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_AU},
  { P("AUTHOR")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_AUTHOR},
  { P("B")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_EMPTY,T_B},
- { P("BANNER")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_BANNER},
+ { P0("BANNER")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_BANNER},
  { P("BASE")	, base_attr,	HTML_BASE_ATTRIBUTES,	SGML_EMPTY,T_BASE},
  { P("BASEFONT"), font_attr,	HTML_FONT_ATTRIBUTES,	SGML_EMPTY,T_BASEFONT},
  { P("BDO")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_BDO},
@@ -1395,7 +1406,7 @@ static CONST HTTag tags_old[HTML_ELEMENTS] = {
  { P("BR")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_EMPTY,T_BR},
  { P("BUTTON")	, button_attr,	HTML_BUTTON_ATTRIBUTES, SGML_MIXED,T_BUTTON},
  { P("CAPTION") , caption_attr, HTML_CAPTION_ATTRIBUTES, SGML_MIXED,T_CAPTION},
- { P("CENTER")	, div_attr,	HTML_DIV_ATTRIBUTES,	SGML_MIXED,T_CENTER},
+ { P0("CENTER")	, div_attr,	HTML_DIV_ATTRIBUTES,	SGML_MIXED,T_CENTER},
  { P("CITE")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_EMPTY,T_CITE},
  { P("CODE")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_CODE},
  { P("COL")	, col_attr,	HTML_COL_ATTRIBUTES,	SGML_EMPTY,T_COL},
@@ -1419,12 +1430,12 @@ static CONST HTTag tags_old[HTML_ELEMENTS] = {
  { P("FORM")	, form_attr,	HTML_FORM_ATTRIBUTES,	SGML_EMPTY,T_FORM},
  { P("FRAME")	, frame_attr,	HTML_FRAME_ATTRIBUTES,	SGML_EMPTY,T_FRAME},
  { P("FRAMESET"), frameset_attr,HTML_FRAMESET_ATTRIBUTES, SGML_MIXED,T_FRAMESET},
- { P("H1")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H1},
- { P("H2")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H2},
- { P("H3")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H3},
- { P("H4")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H4},
- { P("H5")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H5},
- { P("H6")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H6},
+ { P0("H1")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H1},
+ { P0("H2")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H2},
+ { P0("H3")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H3},
+ { P0("H4")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H4},
+ { P0("H5")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H5},
+ { P0("H6")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H6},
  { P("HEAD")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_HEAD},
  { P("HR")	, hr_attr,	HTML_HR_ATTRIBUTES,	SGML_EMPTY,T_HR},
  { P("HTML")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_HTML},
@@ -1458,10 +1469,10 @@ static CONST HTTag tags_old[HTML_ELEMENTS] = {
  { P("P")	, p_attr,	HTML_P_ATTRIBUTES,	SGML_EMPTY,T_P},
  { P("PARAM")	, param_attr,	HTML_PARAM_ATTRIBUTES,	SGML_EMPTY,T_PARAM},
  { P("PLAINTEXT"), gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_LITTERAL,T_PLAINTEXT},
- { P("PRE")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_PRE},
+ { P0("PRE")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_PRE},
  { P("Q")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_Q},
  { P("S")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_S},
- { P("SAMP")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_SAMP},
+ { P0("SAMP")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_SAMP},
  { P("SCRIPT")	, script_attr,	HTML_SCRIPT_ATTRIBUTES, SGML_LITTERAL,T_SCRIPT},
  { P("SELECT")	, select_attr,	HTML_SELECT_ATTRIBUTES, SGML_MIXED,T_SELECT},
  { P("SHY")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_EMPTY,T_SHY},
@@ -1474,7 +1485,7 @@ static CONST HTTag tags_old[HTML_ELEMENTS] = {
  { P("SUB")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_SUB},
  { P("SUP")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_SUP},
  { P("TAB")	, tab_attr,	HTML_TAB_ATTRIBUTES,	SGML_EMPTY,T_TAB},
- { P("TABLE")	, table_attr,	HTML_TABLE_ATTRIBUTES,	SGML_MIXED,T_TABLE},
+ { P0("TABLE")	, table_attr,	HTML_TABLE_ATTRIBUTES,	SGML_MIXED,T_TABLE},
  { P("TBODY")	, tr_attr,	HTML_TR_ATTRIBUTES,	SGML_EMPTY,T_TBODY},
  { P("TD")	, td_attr,	HTML_TD_ATTRIBUTES,	SGML_EMPTY,T_TD},
  { P("TEXTAREA"), textarea_attr,HTML_TEXTAREA_ATTRIBUTES, SGML_LITTERAL,T_TEXTAREA},
@@ -1489,7 +1500,7 @@ static CONST HTTag tags_old[HTML_ELEMENTS] = {
  { P("UL")	, ulist_attr,	HTML_UL_ATTRIBUTES,	SGML_MIXED,T_UL},
  { P("VAR")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_VAR},
  { P("WBR")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_EMPTY,T_WBR},
- { P("XMP")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_LITTERAL,T_XMP},
+ { P0("XMP")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_LITTERAL,T_XMP},
 };
 
 static CONST HTTag tags_new[HTML_ELEMENTS] = {
@@ -1502,7 +1513,7 @@ static CONST HTTag tags_new[HTML_ELEMENTS] = {
  { P("AU")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_AU},
  { P("AUTHOR")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_AUTHOR},
  { P("B")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_B},
- { P("BANNER")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_BANNER},
+ { P0("BANNER")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_BANNER},
  { P("BASE")	, base_attr,	HTML_BASE_ATTRIBUTES,	SGML_EMPTY,T_BASE},
  { P("BASEFONT"), font_attr,	HTML_FONT_ATTRIBUTES,	SGML_EMPTY,T_BASEFONT},
  { P("BDO")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_BDO},
@@ -1516,7 +1527,7 @@ static CONST HTTag tags_new[HTML_ELEMENTS] = {
  { P("BR")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_EMPTY,T_BR},
  { P("BUTTON")	, button_attr,	HTML_BUTTON_ATTRIBUTES, SGML_MIXED,T_BUTTON},
  { P("CAPTION") , caption_attr, HTML_CAPTION_ATTRIBUTES, SGML_MIXED,T_CAPTION},
- { P("CENTER")	, div_attr,	HTML_DIV_ATTRIBUTES,	SGML_MIXED,T_CENTER},
+ { P0("CENTER")	, div_attr,	HTML_DIV_ATTRIBUTES,	SGML_MIXED,T_CENTER},
  { P("CITE")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_CITE},
  { P("CODE")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_CODE},
  { P("COL")	, col_attr,	HTML_COL_ATTRIBUTES,	SGML_EMPTY,T_COL},
@@ -1540,12 +1551,12 @@ static CONST HTTag tags_new[HTML_ELEMENTS] = {
  { P("FORM")	, form_attr,	HTML_FORM_ATTRIBUTES,	SGML_MIXED,T_FORM},
  { P("FRAME")	, frame_attr,	HTML_FRAME_ATTRIBUTES,	SGML_EMPTY,T_FRAME},
  { P("FRAMESET"), frameset_attr,HTML_FRAMESET_ATTRIBUTES, SGML_ELEMENT,T_FRAMESET},
- { P("H1")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H1},
- { P("H2")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H2},
- { P("H3")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H3},
- { P("H4")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H4},
- { P("H5")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H5},
- { P("H6")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H6},
+ { P0("H1")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H1},
+ { P0("H2")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H2},
+ { P0("H3")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H3},
+ { P0("H4")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H4},
+ { P0("H5")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H5},
+ { P0("H6")	, h_attr,	HTML_H_ATTRIBUTES,	SGML_MIXED,T_H6},
  { P("HEAD")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_ELEMENT,T_HEAD},
  { P("HR")	, hr_attr,	HTML_HR_ATTRIBUTES,	SGML_EMPTY,T_HR},
  { P("HTML")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_HTML},
@@ -1579,10 +1590,10 @@ static CONST HTTag tags_new[HTML_ELEMENTS] = {
  { P("P")	, p_attr,	HTML_P_ATTRIBUTES,	SGML_MIXED,T_P},
  { P("PARAM")	, param_attr,	HTML_PARAM_ATTRIBUTES,	SGML_EMPTY,T_PARAM},
  { P("PLAINTEXT"), gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_LITTERAL,T_PLAINTEXT},
- { P("PRE")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_PRE},
+ { P0("PRE")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_PRE},
  { P("Q")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_Q},
  { P("S")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_S},
- { P("SAMP")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_SAMP},
+ { P0("SAMP")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_SAMP},
  { P("SCRIPT")	, script_attr,	HTML_SCRIPT_ATTRIBUTES, SGML_LITTERAL,T_SCRIPT},
  { P("SELECT")	, select_attr,	HTML_SELECT_ATTRIBUTES, SGML_ELEMENT,T_SELECT},
  { P("SHY")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_EMPTY,T_SHY},
@@ -1595,7 +1606,7 @@ static CONST HTTag tags_new[HTML_ELEMENTS] = {
  { P("SUB")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_SUB},
  { P("SUP")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_SUP},
  { P("TAB")	, tab_attr,	HTML_TAB_ATTRIBUTES,	SGML_EMPTY,T_TAB},
- { P("TABLE")	, table_attr,	HTML_TABLE_ATTRIBUTES,	SGML_ELEMENT,T_TABLE},
+ { P0("TABLE")	, table_attr,	HTML_TABLE_ATTRIBUTES,	SGML_ELEMENT,T_TABLE},
  { P("TBODY")	, tr_attr,	HTML_TR_ATTRIBUTES,	SGML_ELEMENT,T_TBODY},
  { P("TD")	, td_attr,	HTML_TD_ATTRIBUTES,	SGML_MIXED,T_TD},
  { P("TEXTAREA"), textarea_attr,HTML_TEXTAREA_ATTRIBUTES, SGML_LITTERAL,T_TEXTAREA},
@@ -1610,9 +1621,12 @@ static CONST HTTag tags_new[HTML_ELEMENTS] = {
  { P("UL")	, ulist_attr,	HTML_UL_ATTRIBUTES,	SGML_MIXED,T_UL},
  { P("VAR")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_MIXED,T_VAR},
  { P("WBR")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_EMPTY,T_WBR},
- { P("XMP")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_LITTERAL,T_XMP},
+ { P0("XMP")	, gen_attr,	HTML_GEN_ATTRIBUTES,	SGML_LITTERAL,T_XMP},
 };
+
 #undef P
+#undef P0
+#undef P_
 
 /* Dummy space, will be filled with the contents of either tags_new
    or tags_old on calling HTSwitchDTD - kw */
@@ -1668,7 +1682,7 @@ struct _HTStructured {
 };
 
 PUBLIC void HTStartAnchor ARGS3(
-	HTStructured *, 	obj,
+	HTStructured *,		obj,
 	CONST char *,		name,
 	CONST char *,		href)
 {
@@ -1692,7 +1706,7 @@ PUBLIC void HTStartAnchor ARGS3(
 }
 
 PUBLIC void HTStartIsIndex ARGS3(
-	HTStructured *, 	obj,
+	HTStructured *,		obj,
 	CONST char *,		prompt,
 	CONST char *,		href)
 {
diff --git a/WWW/Library/Implementation/HTNews.c b/WWW/Library/Implementation/HTNews.c
index 32f4e3a6..3719d2ff 100644
--- a/WWW/Library/Implementation/HTNews.c
+++ b/WWW/Library/Implementation/HTNews.c
@@ -564,14 +564,14 @@ PRIVATE char * author_name ARGS1 (char *,email)
     StrAllocCopy(name, email);
     CTRACE(tfp,"Trying to find name in: %s\n",name);
 
-    if ((p = strchr(name, '(')) && (e = strchr(name, ')'))) {
+    if ((p = strrchr(name, '(')) && (e = strrchr(name, ')'))) {
 	if (e > p) {
 	    *e = '\0';			/* Chop off everything after the ')'  */
 	    return HTStrip(p+1);	/* Remove leading and trailing spaces */
 	}
     }
 
-    if ((p = strchr(name, '<')) && (e = strchr(name, '>'))) {
+    if ((p = strrchr(name, '<')) && (e = strrchr(name, '>'))) {
 	if (e > p) {
 	    strcpy(p, e+1);		/* Remove <...> */
 	    return HTStrip(name);	/* Remove leading and trailing spaces */
@@ -600,8 +600,8 @@ PRIVATE char * author_address ARGS1(char *,email)
     StrAllocCopy(address, email);
     CTRACE(tfp,"Trying to find address in: %s\n",address);
 
-    if ((p = strchr(address, '<'))) {
-	if ((e = strchr(p, '>')) && (at = strchr(p, '@'))) {
+    if ((p = strrchr(address, '<'))) {
+	if ((e = strrchr(p, '>')) && (at = strrchr(p, '@'))) {
 	    if (at < e) {
 		*e = '\0';		 /* Remove > */
 		return HTStrip(p+1);  /* Remove leading and trailing spaces */
@@ -609,15 +609,15 @@ PRIVATE char * author_address ARGS1(char *,email)
 	}
     }
 
-    if ((p = strchr(address, '(')) &&
-	(e = strchr(address, ')')) && (at = strchr(address, '@'))) {
+    if ((p = strrchr(address, '(')) &&
+	(e = strrchr(address, ')')) && (at = strchr(address, '@'))) {
 	if (e > p && at < e) {
 	    *p = '\0';			/* Chop off everything after the ')'  */
 	    return HTStrip(address);	/* Remove leading and trailing spaces */
 	}
     }
 
-    if ((at = strchr(address, '@')) && at > address) {
+    if ((at = strrchr(address, '@')) && at > address) {
 	p = (at - 1);
 	e = (at + 1);
 	while (p > address && !isspace((unsigned char)*p))
@@ -838,7 +838,12 @@ PRIVATE void post_article ARGS1(
     **	Open the temporary file with the
     **	nntp headers and message body. - FM
     */
-    if ((fd = fopen((postfile ? postfile : ""), "r")) == NULL) {
+#ifdef DOSPATH
+    if ((fd = fopen((postfile ? postfile : ""), "rt")) == NULL)
+#else
+    if ((fd = fopen((postfile ? postfile : ""), "r")) == NULL)
+#endif
+    {
 	HTAlert(FAILED_CANNOT_OPEN_POST);
 	return;
     }
@@ -940,6 +945,83 @@ PRIVATE void post_article ARGS1(
     }
 }
 
+#ifdef SH_EX	/* for MIME */
+#define NEWS_DEBUG 0
+#if NEWS_DEBUG
+/* for DEBUG 1997/11/07 (Fri) 17:20:16 */
+void debug_print(unsigned char *p)
+{
+    while (*p) {
+	if (*p == '\0')
+	    break;
+	if (*p == 0x1b)
+	   printf("[ESC]");
+	else if (*p == '\n')
+	   printf("[NL]");
+	else if (*p < ' ' || *p >= 0x80) 
+	   printf("(%02x)", *p);
+	else
+	   putchar(*p);
+       p++;
+    }
+    printf("]\n");
+}
+#endif
+
+#ifdef NOTUSED_CHARTRANS
+static char *decode_mime(char *str)
+{
+    return HTmmdecode(str, str);
+}
+#else
+static char *decode_mime(char *str)
+{
+    char temp[LINE_LENGTH+256];
+    char *p, *q;
+
+    if (str == NULL)
+	return "";
+
+    if (HTCJK != JAPANESE)
+	return str;
+
+    strcpy(temp, str);
+    q = temp;
+    for (;;) {
+	p = strchr(q, '=');
+	if (p == NULL)
+	    break;
+	if (p && p[1] == '?') {
+	    HTmmdecode(p, p);
+	    q = p + 2;
+	} else {
+	    q = p + 1;
+	}
+    }
+#if NEWS_DEBUG
+    printf("new=[");
+    debug_print(temp);
+#endif
+    HTrjis(temp, temp);
+    strcpy(str, temp);
+
+    return str;
+}
+#endif /* NOTUSED_CHARTRANS */
+#else /* !SH_EX */
+static char *decode_mime ARGS1(char *, str)
+{
+#ifdef NOTUSED_CHARTRANS
+    return HTmmdecode(str, str);
+#else
+    HTmmdecode(str, str);
+    HTrjis(str, str);
+    return str;
+#endif
+}
+#endif
+
+
 /*	Read in an Article					read_article
 **	------------------
 **
@@ -1025,38 +1107,22 @@ PRIVATE int read_article ARGS1(
 
 		} else if (match(full_line, "SUBJECT:")) {
 		    StrAllocCopy(subject, HTStrip(strchr(full_line,':')+1));
-		    if (HTCJK == JAPANESE) {
-			HTmmdecode(subject, subject);
-			HTrjis(subject, subject);
-		    }
-		    if (*subject) {
-			HTAnchor_setSubject(thisanchor, subject);
-		    }
-
+		    decode_mime(subject);
 		} else if (match(full_line, "DATE:")) {
 		    StrAllocCopy(date, HTStrip(strchr(full_line,':')+1));
 
 		} else if (match(full_line, "ORGANIZATION:")) {
 		    StrAllocCopy(organization,
 				 HTStrip(strchr(full_line,':')+1));
-		    if (HTCJK == JAPANESE) {
-			HTmmdecode(organization, organization);
-			HTrjis(organization, organization);
-		    }
+		    decode_mime(organization);
 
 		} else if (match(full_line, "FROM:")) {
 		    StrAllocCopy(from, HTStrip(strchr(full_line,':')+1));
-		    if (HTCJK == JAPANESE) {
-			HTmmdecode(from, from);
-			HTrjis(from, from);
-		    }
+		    decode_mime(from);
 
 		} else if (match(full_line, "REPLY-TO:")) {
 		    StrAllocCopy(replyto, HTStrip(strchr(full_line,':')+1));
-		    if (HTCJK == JAPANESE) {
-			HTmmdecode(replyto, replyto);
-			HTrjis(replyto, replyto);
-		    }
+		    decode_mime(replyto);
 
 		} else if (match(full_line, "NEWSGROUPS:")) {
 		    StrAllocCopy(newsgroups, HTStrip(strchr(full_line,':')+1));
@@ -1341,6 +1407,9 @@ PRIVATE int read_article ARGS1(
 	if (((char)ich == LF) || (p == &line[LINE_LENGTH])) {
 	    *p++ = '\0';			/* Terminate the string */
 	    CTRACE(tfp, "B %s", line);
+#if NEWS_DEBUG	/* 1997/11/09 (Sun) 15:56:11 */
+	    debug_print(line);	/* @@@ */
+#endif
 	    if (line[0] == '.') {
 		/*
 		**  End of article?
@@ -1379,8 +1448,8 @@ PRIVATE int read_article ARGS1(
 		    char *p2;
 
 		    while ((p2 = strstr(l, "rticle <")) != NULL) {
-			char *q  = strchr(p2,'>');
-			char *at = strchr(p2, '@');
+			char *q  = strrchr(p2,'>');
+			char *at = strrchr(p2, '@');
 			if (q && at && at<q) {
 			    char c = q[1];
 			    q[1] = 0;		/* chop up */
@@ -1892,11 +1961,8 @@ PRIVATE int read_group ARGS3(
 			case 's':
 			    if (match(line, "SUBJECT:")) {
 				strcpy(subject, line+9);/* Save subject */
-				if (HTCJK == JAPANESE) {
-				    HTmmdecode(subject, subject);
-				    HTrjis(subject, subject);
+				decode_mime(subject);
 				}
-			    }
 			    break;
 
 			case 'M':
@@ -1914,10 +1980,7 @@ PRIVATE int read_group ARGS3(
 				char * p2;
 				strcpy(author,
 					author_name(strchr(line,':')+1));
-				if (HTCJK == JAPANESE) {
-				    HTmmdecode(author, author);
-				    HTrjis(author, author);
-				}
+				decode_mime(author);
 				p2 = author + strlen(author) - 1;
 				if (*p2==LF)
 				    *p2 = '\0'; /* Chop off newline */
@@ -1938,7 +2001,11 @@ PRIVATE int read_group ARGS3(
 
 		PUTC('\n');
 		START(HTML_LI);
+#ifdef SH_EX	/* for MIME */
+		sprintf(buffer, "\"%s\"", decode_mime(subject));
+#else
 		sprintf(buffer, "\"%s\"", subject);
+#endif
 		if (reference) {
 		    write_anchor(buffer, reference);
 		    FREE(reference);
@@ -1949,7 +2016,11 @@ PRIVATE int read_group ARGS3(
 		     PUTS(" - ");
 		     if (LYListNewsDates)
 			 START(HTML_I);
+#ifdef SH_EX	/* for MIME */
+		     PUTS(decode_mime(author));
+#else
 		     PUTS(author);
+#endif
 		     if (LYListNewsDates)
 			 END(HTML_I);
 		     author[0] = '\0';
@@ -2349,10 +2420,10 @@ PRIVATE int HTLoadNews ARGS4(
 	    strcat(command, groupName);
 	} else {
 	    strcpy(command, "ARTICLE ");
-	    if (strchr(p1, '<') == 0)
+	    if (strrchr(p1, '<') == 0)
 		strcat(command,"<");
 	    strcat(command, p1);
-	    if (strchr(p1, '>') == 0)
+	    if (strrchr(p1, '>') == 0)
 		strcat(command,">");
 	}
 
@@ -2556,7 +2627,8 @@ PRIVATE int HTLoadNews ARGS4(
 		return(HT_NOT_LOADED);
 	    }
 	    if (postfile == NULL) {
-		postfile = LYNewsPost(ListArg, (reply_wanted || sreply_wanted));
+		postfile = LYNewsPost(ListArg,
+				(BOOLEAN)(reply_wanted || sreply_wanted));
 	    }
 	    if (postfile == NULL) {
 		HTProgress(CANCELLED);
@@ -2603,6 +2675,12 @@ PRIVATE int HTLoadNews ARGS4(
 	}
 
 Send_NNTP_command:
+#ifdef NEWS_DEB
+	if (postfile)
+	    printf("postfile = %s, command = %s", postfile, command);
+	else
+	    printf("command = %s", command);
+#endif
 	if ((status = response(command)) == HT_INTERRUPTED) {
 	    _HTProgress(CONNECTION_INTERRUPTED);
 	    break;
@@ -2763,10 +2841,11 @@ Send_NNTP_command:
 	return status;
     } /* Retry loop */
 
-    /* HTAlert(gettext("Sorry, could not load requested news.")); */
-
-/*    NXRunAlertPanel(NULL, "Sorry, could not load `%s'.",
-	    NULL,NULL,NULL, arg);No -- message earlier wil have covered it */
+#if 0
+    HTAlert(gettext("Sorry, could not load requested news."));
+    NXRunAlertPanel(NULL, "Sorry, could not load `%s'.", NULL,NULL,NULL, arg);
+    /* No -- message earlier wil have covered it */
+#endif
 
     if (!(post_wanted || reply_wanted ||
 	  spost_wanted || sreply_wanted)) {
diff --git a/WWW/Library/Implementation/HTParse.c b/WWW/Library/Implementation/HTParse.c
index 9e75b8db..1122d3a1 100644
--- a/WWW/Library/Implementation/HTParse.c
+++ b/WWW/Library/Implementation/HTParse.c
@@ -187,7 +187,8 @@ PUBLIC char * HTParse ARGS3(
     char * acc_method;
     struct struct_parts given, related;
 
-    CTRACE(tfp, "HTParse: aName:%s   relatedName:%s\n", aName, relatedName);
+    CTRACE(tfp, "HTParse: aName:`%s'\n", aName);
+    CTRACE(tfp, "   relatedName:`%s'\n", relatedName);
 
     if (wanted & (PARSE_STRICTPATH | PARSE_QUERY)) { /* if detail wanted... */
 	if ((wanted & (PARSE_STRICTPATH | PARSE_QUERY))
@@ -371,7 +372,7 @@ PUBLIC char * HTParse ARGS3(
 	    if (wanted & PARSE_PUNCTUATION)
 		strcat(result, "/");
 	    strcat(result, given.absolute);
-	    CTRACE(tfp, "1\n");
+	    CTRACE(tfp, "HTParse: (ABS)\n");
 	} else if (related.absolute) {		/* Adopt path not name */
 	    strcat(result, "/");
 	    strcat(result, related.absolute);
@@ -385,13 +386,13 @@ PUBLIC char * HTParse ARGS3(
 		strcat(result, given.relative); /* Add given one */
 		HTSimplify (result);
 	    }
-	    CTRACE(tfp, "2\n");
+	    CTRACE(tfp, "HTParse: (Related-ABS)\n");
 	} else if (given.relative) {
 	    strcat(result, given.relative);		/* what we've got */
-	    CTRACE(tfp, "3\n");
+	    CTRACE(tfp, "HTParse: (REL)\n");
 	} else if (related.relative) {
 	    strcat(result, related.relative);
-	    CTRACE(tfp, "4\n");
+	    CTRACE(tfp, "HTParse: (Related-REL)\n");
 	} else {  /* No inheritance */
 	    if (strncasecomp(aName, "lynxcgi:", 8) &&
 		strncasecomp(aName, "lynxexec:", 9) &&
@@ -400,7 +401,7 @@ PUBLIC char * HTParse ARGS3(
 	    }
 	    if (!strcmp(result, "news:/"))
 		result[5] = '*';
-	    CTRACE(tfp, "5\n");
+	    CTRACE(tfp, "HTParse: (No inheritance)\n");
 	}
 	if (want_detail) {
 	    p = strchr(tail, '?');	/* Search part? */
@@ -664,7 +665,8 @@ PUBLIC char * HTRelative ARGS2(
 	    strcat(result, "../");
 	strcat(result, last_slash+1);
     }
-    CTRACE(tfp, "HT: `%s' expressed relative to\n    `%s' is\n   `%s'.",
+    CTRACE(tfp,
+        "HTparse: `%s' expressed relative to\n   `%s' is\n   `%s'.\n",
 		aName, relatedName, result);
     return result;
 }
@@ -797,16 +799,21 @@ PUBLIC char * HTUnEscape ARGS1(
 	    p[1] && p[2] &&
 	    isxdigit((unsigned char)p[1]) &&
 	    isxdigit((unsigned char)p[2])) {
-	    p++;
-	    if (*p)
-	        *q = from_hex(*p++) * 16;
-	    if (*p)
-		/*
-		** Careful!  FROMASCII() may evaluate its arg more than once!
-		*/  /* S/390 -- gil -- 0221 */
-		*q =           *q + from_hex(*p++) ;
-		*q = FROMASCII(*q                 );
-	    q++;
+	      if (iscntrl(FROMASCII(from_hex(p[1])*16 + from_hex(p[2])))) {
+		*q++ = *p++;     /* Ignore control codes.  --HN [98/09/08] */
+	      } else {
+		p++;
+		if (*p)
+		    *q = from_hex(*p++) * 16;
+		if (*p) {
+		    /*
+		    ** Careful! FROMASCII() may evaluate its arg more than once!
+		    */  /* S/390 -- gil -- 0221 */
+		    *q = *q + from_hex(*p++) ;
+		}
+		*q = FROMASCII(*q);
+		q++;
+	      }
 	} else {
 	    *q++ = *p++;
 	}
diff --git a/WWW/Library/Implementation/HTRules.c b/WWW/Library/Implementation/HTRules.c
index 6140765e..53945fe0 100644
--- a/WWW/Library/Implementation/HTRules.c
+++ b/WWW/Library/Implementation/HTRules.c
@@ -189,7 +189,7 @@ PRIVATE BOOL rule_cond_ok ARGS1(
 	return result;
     else
 	return (!result);
-	
+
 }
 /*	Translate by rules					HTTranslate()
 **	------------------
@@ -479,7 +479,7 @@ PUBLIC int  HTSetConfiguration ARGS1(
 			    &quality, &secs, &secs_per_byte, &maxbytes);
 	else status = 0;
 	HTSetPresentation(word2, word3,
-		    status >= 1? quality		: 1.0,
+		    status >= 1 ? quality		: 1.0,
 		    status >= 2 ? secs			: 0.0,
 		    status >= 3 ? secs_per_byte 	: 0.0,
 		    status >= 4 ? maxbytes		: 0 );
diff --git a/WWW/Library/Implementation/HTString.c b/WWW/Library/Implementation/HTString.c
index 039c0e64..7ab09c78 100644
--- a/WWW/Library/Implementation/HTString.c
+++ b/WWW/Library/Implementation/HTString.c
@@ -19,7 +19,11 @@ PUBLIC int WWW_TraceFlag = 0;	/* Global trace flag for ALL W3 code */
 #define VC "unknown"
 #endif /* !VC */
 
+#ifdef _WINDOWS
+CONST char * HTLibraryVersion = "2.14FM"; /* String for help screen etc */
+#else
 PUBLIC CONST char * HTLibraryVersion = VC; /* String for help screen etc */
+#endif
 
 /*
 **     strcasecomp8 is a variant of strcasecomp (below)
@@ -73,8 +77,82 @@ PUBLIC int strncasecomp8 ARGS3(
     }
     /*NOTREACHED*/
 }
+
 #ifndef VM		/* VM has these already it seems */
 
+#ifdef SH_EX	/* 1997/12/23 (Tue) 16:40:31 */
+
+/*
+ * This array is designed for mapping upper and lower case letter
+ * together for a case independent comparison.  The mappings are
+ * based upon ascii character sequences.
+ */
+static unsigned char charmap[] = {
+	'\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
+	'\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
+	'\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
+	'\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
+	'\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
+	'\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
+	'\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
+	'\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
+	'\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
+	'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
+	'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
+	'\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
+	'\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
+	'\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
+	'\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
+	'\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
+	'\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
+	'\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
+	'\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
+	'\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
+	'\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
+	'\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
+	'\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
+	'\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
+	'\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
+	'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
+	'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\327',
+	'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\337',
+	'\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
+	'\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
+	'\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
+	'\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
+};
+
+PUBLIC int strcasecomp ARGS2(
+	CONST char*,	s1,
+	CONST char*,	s2)
+{
+    register unsigned char *cm = charmap;
+    register unsigned char *us1 = (unsigned char *)s1;
+    register unsigned char *us2 = (unsigned char *)s2;
+
+    while (cm[*us1] == cm[*us2++])
+	if (*us1++ == '\0')
+	    return(0);
+    return (cm[*us1] - cm[*--us2]);
+}
+
+PUBLIC int strncasecomp ARGS3(
+	CONST char*,	a,
+	CONST char*,	b,
+	int,		n)
+{
+    register unsigned char *cm = charmap;
+    register unsigned char *us1 = (unsigned char *)a;
+    register unsigned char *us2 = (unsigned char *)b;
+
+    while ((long)(--n) >= 0 && cm[*us1] == cm[*us2++])
+	if (*us1++ == '\0')
+	    return(0);
+    return ((long)n < 0 ? 0 : cm[*us1] - cm[*--us2]);
+}
+
+#else
+
 /*	Strings of any length
 **	---------------------
 */
@@ -120,6 +198,8 @@ PUBLIC int strncasecomp ARGS3(
     }
     /*NOTREACHED*/
 }
+
+#endif	/* SH_EX */
 #endif /* VM */
 
 #ifdef NOT_ASCII
@@ -683,6 +763,8 @@ PUBLIC char * HTSprintf0 (va_alist)
 	char **		pstr = va_arg(ap, char **);
 	CONST char *	fmt  = va_arg(ap, CONST char *);
 #endif
+	if (pstr != 0)
+	    *pstr = 0;
 	result = StrAllocVsprintf(pstr, 0, fmt, &ap);
     }
     va_end(ap);
diff --git a/WWW/Library/Implementation/HTTCP.c b/WWW/Library/Implementation/HTTCP.c
index a0f6948a..bd68d5be 100644
--- a/WWW/Library/Implementation/HTTCP.c
+++ b/WWW/Library/Implementation/HTTCP.c
@@ -114,15 +114,24 @@ extern int sys_nerr;
 #endif	/* !PCNFS */
 
 #ifdef _WINDOWS_NSL
-	 char host[512];
-	 struct hostent  *phost;	/* Pointer to host - See netdb.h */
-	 int donelookup;
+char host[512];
+struct hostent  *phost;	/* Pointer to host - See netdb.h */
+int donelookup;
 
 unsigned long _fork_func (void *arglist)
 {
-	 phost = gethostbyname(host);
-	 donelookup = TRUE;
-	 return (unsigned long)(phost);
+#ifdef SH_EX
+    unsigned long addr;
+    addr = (unsigned long)inet_addr(host);
+    if ((int)addr != -1)
+	phost = gethostbyaddr((char *)&addr, sizeof (addr), AF_INET);
+    else
+	phost = gethostbyname(host);
+#else
+    phost = gethostbyname(host);
+#endif
+    donelookup = TRUE;
+    return (unsigned long)(phost);
 }
 #endif /* _WINDOWS_NSL */
 
@@ -674,8 +683,12 @@ PUBLIC struct hostent * LYGetHostByName ARGS1(
     if (!valid_hostname(host)) {
 	lynx_nsl_status = HT_NOT_ACCEPTABLE;
 #ifdef NO_RECOVERY
+#ifdef _WINDOWS
+	WSASetLastError(NO_RECOVERY);
+#else
 	h_errno = NO_RECOVERY;
 #endif
+#endif
 	return NULL;
     }
 
@@ -1061,43 +1074,51 @@ PUBLIC struct hostent * LYGetHostByName ARGS1(
 
 #ifdef _WINDOWS_NSL
     {
-#ifdef __BORLANDC__
-		HANDLE hThread, dwThreadID;
-#else
-		unsigned long hThread, dwThreadID;
-#endif /* __BORLANDC__ */
-		phost = (struct hostent *) NULL;
-		hThread = CreateThread((void *)NULL, 4096UL,
-#ifdef __BORLANDC__
-			 (LPTHREAD_START_ROUTINE)_fork_func,
-#else
-			 (unsigned long (*)())_fork_func,
-#endif /* __BORLANDC__ */
-			 (void *)NULL, 0UL, (unsigned long *)&dwThreadID);
-		if (!hThread)
-			 MessageBox((void *)NULL, "CreateThread",
-				"CreateThread Failed", 0L);
-
-		donelookup = FALSE;
-		while (!donelookup)
-			if (HTCheckForInterrupt())
-			 {
-			  /* Note that host is a character array and is not freed */
-			  /* to avoid possible subthread problems: */
-			  if (!CloseHandle(hThread))
-				 MessageBox((void *)NULL, "CloseHandle","CloseHandle Failed",
-						0L);
-			  lynx_nsl_status = HT_INTERRUPTED;
-			  return NULL;
-			};
-		if (phost) {
-		    lynx_nsl_status = HT_OK;
-		    result_phost = phost;
-		} else {
-		    lynx_nsl_status = HT_ERROR;
-		    goto failed;
+	char buff[256];
+	LPSTR szIPAddr;	/* IP address as a dotted decimal string */
+	IN_ADDR addr;
+	IN_ADDR *p;
+
+	HANDLE hThread, dwThreadID;
+
+	if (!system_is_NT) {	/* for Windows9x */
+	    unsigned long t;
+	    t = (unsigned long)inet_addr((char *)host);
+	    if ((int)t != -1)
+		phost = gethostbyaddr((char *)&t, sizeof (t), AF_INET);
+	    else
+		phost = gethostbyname((char *)host);
+	} else {		/* for Windows NT */
+	    phost = (struct hostent *) NULL;
+	    hThread = CreateThread((void *)NULL, 4096UL,
+		(LPTHREAD_START_ROUTINE)_fork_func,
+		(void *)NULL, 0UL, (unsigned long *)&dwThreadID);
+	    if (!hThread)
+		MessageBox((void *)NULL, "CreateThread",
+			   "CreateThread Failed", 0L);
+
+	    donelookup = FALSE;
+	    while (!donelookup) {
+		if (HTCheckForInterrupt()) {
+		    /* Note that host is a character array and is not freed */
+		    /* to avoid possible subthread problems: */
+		    if (!CloseHandle(hThread)) {
+			MessageBox((void *)NULL,
+				   "CloseHandle","CloseHandle Failed", 0L);
+		    }
+		    lynx_nsl_status = HT_INTERRUPTED;
+		    return NULL;
 		}
-    };
+	    }
+	}
+	if (phost) {
+	    lynx_nsl_status = HT_OK;
+	    result_phost = phost;
+	} else {
+	    lynx_nsl_status = HT_ERROR;
+	    goto failed;
+	}
+    }
 
 #else /* !NSL_FORK, !_WINDOWS_NSL: */
     {
@@ -1698,7 +1719,11 @@ PUBLIC int HTDoConnect ARGS4(
 	    if (HTCheckForInterrupt()) {
 		CTRACE(tfp, "*** INTERRUPTED in middle of connect.\n");
 		status = HT_INTERRUPTED;
+#ifdef _WINDOWS
+		WSASetLastError(EINTR);
+#else
 		SOCKET_ERRNO = EINTR;
+#endif
 		break;
 	    }
 	}
@@ -1771,7 +1796,11 @@ PUBLIC int HTDoRead ARGS3(
 	return -1;
 
     if (HTCheckForInterrupt()) {
+#ifdef _WINDOWS
+	WSASetLastError(EINTR);
+#else
 	SOCKET_ERRNO = EINTR;
+#endif
 	return (HT_INTERRUPTED);
     }
 
@@ -1786,7 +1815,11 @@ PUBLIC int HTDoRead ARGS3(
 	*/
 	if (tries++ >= 180000) {
 	    HTAlert(gettext("Socket read failed for 180,000 tries."));
+#ifdef _WINDOWS
+	    WSASetLastError(EINTR);
+#else
 	    SOCKET_ERRNO = EINTR;
+#endif
 	    return HT_INTERRUPTED;
 	}
 
@@ -1814,7 +1847,11 @@ PUBLIC int HTDoRead ARGS3(
 	} else if (ret > 0) {
 	    ready = 1;
 	} else if (HTCheckForInterrupt()) {
+#ifdef _WINDOWS
+	    WSASetLastError(EINTR);
+#else
 	    SOCKET_ERRNO = EINTR;
+#endif
 	    return HT_INTERRUPTED;
 	}
     }
diff --git a/WWW/Library/Implementation/HTTCP.h b/WWW/Library/Implementation/HTTCP.h
index 4e43ed27..d22cac8d 100644
--- a/WWW/Library/Implementation/HTTCP.h
+++ b/WWW/Library/Implementation/HTTCP.h
@@ -33,7 +33,7 @@ extern CONST char * HTInetString PARAMS((struct sockaddr_in* mysin));
 ** On return:
 **      returns a negative status in the unix way.
 */
-#ifdef __STDC__
+#if defined(__STDC__) || defined(__BORLANDC__) || defined(_MSC_VER)
         extern int HTInetStatus(char *where);
 #else
         extern int HTInetStatus();
@@ -104,7 +104,7 @@ extern struct hostent * LYGetHostByName PARAMS((
 **               *sin is filled in.  If no port is specified in str, that
 **               field is left unchanged in *sin.
 */
-#ifdef __STDC__
+#if defined(__STDC__) || defined(__BORLANDC__) || defined(_MSC_VER)
         extern int HTParseInet(struct sockaddr_in * mysin, CONST char * str);
         /*!! had to change this to get it to compile. CTB */
 #else
diff --git a/WWW/Library/Implementation/HTTP.c b/WWW/Library/Implementation/HTTP.c
index 2dd3ac84..ff9a5534 100644
--- a/WWW/Library/Implementation/HTTP.c
+++ b/WWW/Library/Implementation/HTTP.c
@@ -7,6 +7,9 @@
 */
 
 #include <HTUtils.h>
+#ifdef __DJGPP__
+#include <tcp.h>
+#endif /* __DJGPP__ */
 #include <HTTP.h>
 #include <LYUtils.h>
 
@@ -68,6 +71,179 @@ extern BOOL dump_output_immediately;  /* TRUE if no interactive user */
 #define HTTP_NETWRITE(a, b, c, d)  NETWRITE(a, b, c)
 #define HTTP_NETCLOSE(a, b)  (void)NETCLOSE(a)
 
+#ifdef _WINDOWS		/* 1997/11/06 (Thu) 13:00:08 */
+
+#define	BOX_TITLE	"Lynx " __FILE__
+#define	BOX_FLAG	(MB_ICONINFORMATION | MB_SETFOREGROUND)
+
+typedef struct {
+	int fd;
+	char *buf;
+	int len;
+} recv_data_t;
+
+PUBLIC int ws_read_per_sec = 0;
+PRIVATE int ws_errno = 0;
+
+PRIVATE DWORD g_total_times = 0;
+PRIVATE DWORD g_total_bytes = 0;
+
+
+PUBLIC char * str_speed(void)
+{
+    static char buff[32];
+
+    if (ws_read_per_sec > 1000)
+	sprintf(buff, "%d.%03dkB", ws_read_per_sec / 1000, 
+			(ws_read_per_sec % 1000) );
+    else
+	sprintf(buff, "%3d", ws_read_per_sec);
+
+    return buff;
+}
+
+/* The same like read, but takes care of EINTR and uses select to
+   timeout the stale connections.  */
+
+PRIVATE int ws_read(int fd, char *buf, int len)
+{
+     int res;
+     int retry = 3;
+
+     do {
+	res = recv(fd, buf, len, 0);
+	if (WSAEWOULDBLOCK == WSAGetLastError()) {
+	  Sleep(100);
+	  if (retry-- > 0)
+	    continue;
+	}
+     } while (res == SOCKET_ERROR && SOCKET_ERRNO == EINTR);
+
+     return res;
+}
+
+PRIVATE void _thread_func (void *p)
+{
+    int i, val, ret;
+    recv_data_t *q = (recv_data_t *)p;
+
+    i = 0;
+    i++;
+    val = ws_read(q->fd, q->buf, q->len);
+
+    if (val == SOCKET_ERROR) {
+	ws_errno = WSAGetLastError();
+#if 0
+	char buff[256];
+	sprintf(buff, "Thread read: %d, error (%ld), fd = %d, len = %d",
+		i, ws_errno, q->fd, q->len);
+	MessageBox(NULL, buff, BOX_TITLE, BOX_FLAG);
+#endif
+	ret = -1;
+    } else {
+	ret = val;
+    }
+
+    ExitThread((DWORD)ret);
+}
+
+/* The same like read, but takes care of EINTR and uses select to
+   timeout the stale connections.  */
+
+PUBLIC int ws_netread(int fd, char *buf, int len)
+{
+    int i;
+    char buff[256];
+
+     /* 1998/03/30 (Mon) 09:01:21 */
+    HANDLE hThread;
+    DWORD dwThreadID;
+    DWORD exitcode = 0;
+    DWORD ret_val, val, process_time, now_TickCount, save_TickCount;
+
+    static recv_data_t para;
+
+    extern int win32_check_interrupt(void);	/* LYUtil.c */
+    extern int lynx_timeout;			/* LYMain.c */
+    extern int AlertSecs;			/* LYMain.c */
+    extern CRITICAL_SECTION critSec_READ;	/* LYMain.c */
+
+#define TICK	5
+#define STACK_SIZE	0x2000uL
+
+    InitializeCriticalSection(&critSec_READ);
+
+    para.fd = fd;
+    para.buf = buf;
+    para.len = len;
+
+    ws_read_per_sec = 0;
+    save_TickCount = GetTickCount();
+
+    hThread = CreateThread((void *)NULL, STACK_SIZE,
+		 (LPTHREAD_START_ROUTINE)_thread_func,
+		 (void *)&para, 0UL, &dwThreadID);
+
+    if (hThread == 0) {
+	HTInfoMsg("CreateThread Failed (read)");
+	goto read_exit;
+    }
+
+    i = 0;
+    while (1) {
+	val = WaitForSingleObject(hThread, 1000/TICK);
+	i++;
+	if (val == WAIT_FAILED) {
+	    HTInfoMsg("Wait Failed");
+	    ret_val = -1;
+	    break;
+	} else if (val == WAIT_TIMEOUT) {
+	    i++;
+	    if (i/TICK > (AlertSecs + 2)) {
+		sprintf(buff, "Read Waiting (%2d.%01d) for %d Bytes",
+			i/TICK, (i%TICK) * 10 / TICK, len);
+		SetConsoleTitle(buff);
+	    }
+	    if (win32_check_interrupt() || ((i/TICK) > lynx_timeout)) {
+		if (CloseHandle(hThread) == FALSE) {
+		    HTInfoMsg("Thread terminate Failed");
+		}
+		WSASetLastError(ETIMEDOUT);
+		ret_val = HT_INTERRUPTED;
+		break;
+	    }
+	} else if (val == WAIT_OBJECT_0) {
+	    if (GetExitCodeThread(hThread, &exitcode) == FALSE) {
+		exitcode = -1;
+	    }
+	    if (CloseHandle(hThread) == FALSE) {
+		HTInfoMsg("Thread terminate Failed");
+	    }
+	    now_TickCount = GetTickCount();
+	    if (now_TickCount > save_TickCount)
+		process_time = now_TickCount - save_TickCount;
+	    else
+		process_time = now_TickCount + (0xffffffff - save_TickCount);
+
+	    g_total_times += process_time;
+	    g_total_bytes += exitcode;
+	    
+	    if (g_total_bytes > 2000000) {
+		ws_read_per_sec = g_total_bytes / (g_total_times/1000);
+	    } else {
+		ws_read_per_sec = g_total_bytes * 1000 / g_total_times;
+	    }
+	    ret_val = exitcode;
+	    break;
+	}
+    }	/* end while(1) */
+
+    read_exit:
+    LeaveCriticalSection(&critSec_READ);
+    return ret_val;
+}
+#endif
+
 
 /*		Load Document from HTTP Server			HTLoadHTTP()
 **		==============================
@@ -109,6 +285,7 @@ PRIVATE int HTLoadHTTP ARGS4 (
   BOOL had_header;		/* Have we had at least one header? */
   char *line_buffer;
   char *line_kept_clean;
+  int real_length_of_line;
   BOOL extensions;		/* Assume good HTTP server */
   char line[INIT_LINE_SIZE];
   char temp[80];
@@ -178,8 +355,15 @@ try_again:
        goto done;
    }
    if (status < 0) {
-	CTRACE(tfp, "HTTP: Unable to connect to remote host for `%s' (errno = %d).\n",
+#ifdef _WINDOWS
+      CTRACE(tfp, "HTTP: Unable to connect to remote host for `%s'\n"
+			  " (status = %d, sock_errno = %d).\n",
+			  url, status, SOCKET_ERRNO);
+#else
+      CTRACE(tfp,
+	    "HTTP: Unable to connect to remote host for `%s' (errno = %d).\n",
 	    url, SOCKET_ERRNO);
+#endif
       HTAlert(gettext("Unable to connect to remote host."));
       status = HT_NOT_LOADED;
       goto done;
@@ -674,8 +858,7 @@ try_again:
 	    if (line_buffer == NULL)
 		outofmem(__FILE__, "HTLoadHTTP");
 	}
-	CTRACE (tfp, "HTTP: Trying to read %d\n",
-		     buffer_length - length - 1);
+	CTRACE(tfp, "HTTP: Trying to read %d\n", buffer_length - length - 1);
 	status = HTTP_NETREAD(s, line_buffer + length,
 			      buffer_length - length - 1, handle);
 	CTRACE (tfp, "HTTP: Read %d\n", status);
@@ -692,6 +875,9 @@ try_again:
 		goto clean_up;
 	    } else if  (status < 0 &&
 			(SOCKET_ERRNO == ENOTCONN ||
+#ifdef _WINDOWS	/* 1997/11/09 (Sun) 16:59:58 */
+			 SOCKET_ERRNO == ETIMEDOUT ||
+#endif
 			 SOCKET_ERRNO == ECONNRESET ||
 			 SOCKET_ERRNO == EPIPE) &&
 			!already_retrying && !do_post) {
@@ -745,6 +931,7 @@ try_again:
 	    if (line_kept_clean == NULL)
 		outofmem(__FILE__, "HTLoadHTTP");
 	    memcpy(line_kept_clean, line_buffer, buffer_length);
+	    real_length_of_line = length + status;
 	}
 
 	eol = strchr(line_buffer + length, LF);
@@ -1720,7 +1907,12 @@ Cookie2_continuation:
       **  It was a HEAD request, or we want the headers and source.
       */
       start_of_data = line_kept_clean;
+#ifdef SH_EX	/* FIX BUG by kaz@maczuka.hitachi.ibaraki.jp */
+/* GIF file contains \0, so strlen does not return the data length */
+      length = real_length_of_line;
+#else
       length = rawlength;
+#endif
       format_in = HTAtom_for("text/plain");
   }
 
diff --git a/WWW/Library/Implementation/HTTP.h b/WWW/Library/Implementation/HTTP.h
index cd6925f2..1079557f 100644
--- a/WWW/Library/Implementation/HTTP.h
+++ b/WWW/Library/Implementation/HTTP.h
@@ -24,6 +24,10 @@ extern char * redirecting_url;
 extern BOOL permanent_redirection;
 extern BOOL redirect_post_content;
 
+#ifdef _WINDOWS
+extern int ws_netread(int fd, char *buf, int len);
+#endif /* _WINDOWS */
+
 #endif /* HTTP_H */
 
 /*
diff --git a/WWW/Library/Implementation/HTUtils.h b/WWW/Library/Implementation/HTUtils.h
index dd0a51e7..f5237989 100644
--- a/WWW/Library/Implementation/HTUtils.h
+++ b/WWW/Library/Implementation/HTUtils.h
@@ -1,7 +1,7 @@
 /*                                       Utility macros for the W3 code library
                                   MACROS FOR GENERAL USE
 
-   See also: the system dependent file "tcp.h", which is included here.
+   See also: the system dependent file "www_tcp.h", which is included here.
 
  */
 
@@ -40,7 +40,7 @@
 #define DISP_PARTIAL	/* experimental */
 #endif
 
-#if defined(__STDC__) || defined(VMS)
+#if defined(__STDC__) || defined(VMS) || defined(_WINDOWS)
 #define ANSI_VARARGS 1
 #undef HAVE_STDARG_H
 #define HAVE_STDARG_H 1
@@ -102,13 +102,24 @@
 #define	GCC_UNUSED /* nothing */
 #endif
 
-#ifdef _WINDOWS                         /* SCW */
-#include <windef.h>
+#if defined(__CYGWIN__)			/* 1998/12/31 (Thu) 16:13:46 */
+#include <windows.h>		/* #include "windef.h" */
+#define BOOLEAN_DEFINED
+#endif
+
+#if defined(_WINDOWS) && !defined(__CYGWIN__)	/* SCW */
+#include <windows.h>		/* #include "windef.h" */
 #define BOOLEAN_DEFINED
-#define va_arg
 #include <dos.h>
+#undef sleep			/* 1998/06/23 (Tue) 16:54:53 */
+extern void sleep(unsigned __seconds);
 #define popen _popen
 #define pclose _pclose
+
+#if defined(_MSC_VER)
+typedef unsigned short mode_t;
+#endif
+
 #endif /* _WINDOWS */
 
 #ifdef __EMX__
@@ -201,7 +212,7 @@ Macros for declarations
 #define PUBLIC                  /* Accessible outside this module     */
 #define PRIVATE static          /* Accessible only within this module */
 
-#ifdef __STDC__
+#if defined(__STDC__) || defined(__BORLANDC__) || defined(_MSC_VER)
 #define CONST const             /* "const" only exists in STDC */
 #define NOPARAMS (void)
 #define PARAMS(parameter_list) parameter_list
@@ -268,7 +279,7 @@ Macros for declarations
 OFTEN USED INTEGER MACROS
 
   Min and Max functions
-  
+
  */
 #ifndef HTMIN
 #define HTMIN(a,b) ((a) <= (b) ? (a) : (b))
@@ -412,7 +423,7 @@ Upper- and Lowercase macros
 #define TOUPPER(c) (islower((unsigned char)c) ? toupper((unsigned char)c) : ((unsigned char)c))
 #endif /* TOLOWER */
 
-#define FREE(x) if (x) {free(x); x = NULL;}
+#define FREE(x) if (x != 0) {free((char *)x); x = NULL;}
 
 /*
 
@@ -433,7 +444,7 @@ The local equivalents of CR and LF
 
 extern FILE *TraceFP NOPARAMS;
 
-#include <tcp.h>
+#include <www_tcp.h>
 
 /*
  * We force this include-ordering since socks.h contains redefinitions of
diff --git a/WWW/Library/Implementation/HTVMS_WaisUI.c b/WWW/Library/Implementation/HTVMS_WaisUI.c
index 1f9ffccc..f5c5954e 100644
--- a/WWW/Library/Implementation/HTVMS_WaisUI.c
+++ b/WWW/Library/Implementation/HTVMS_WaisUI.c
@@ -40,7 +40,7 @@
 #include <HTVMS_WaisProt.h>
 #include <HTTCP.h>
 
-#undef MAXINT	/* we don't need it here, and tcp.h may conflict */
+#undef MAXINT	/* we don't need it here, and www_tcp.h may conflict */
 #include <math.h>
 
 #include <LYexit.h>
diff --git a/WWW/Library/Implementation/SGML.c b/WWW/Library/Implementation/SGML.c
index 7d436284..7efb4d9b 100644
--- a/WWW/Library/Implementation/SGML.c
+++ b/WWW/Library/Implementation/SGML.c
@@ -39,6 +39,10 @@
 # include <LYPrettySrc.h>
 #endif
 
+#ifdef CJK_EX	/* 1997/12/12 (Fri) 16:54:58 */
+extern HTkcode last_kcode;
+#endif
+
 #define INVALID (-1)
 
 #ifdef USE_PSRC
@@ -224,8 +228,13 @@ PRIVATE void HTMLSRC_apply_markup ARGS3(
     }
 }
 
+#ifdef __STDC__
 #  define PSRCSTART(x)	HTMLSRC_apply_markup(context,HTL_##x,START)
 #  define PSRCSTOP(x)  HTMLSRC_apply_markup(context,HTL_##x,STOP)
+#else
+#  define PSRCSTART(x)	HTMLSRC_apply_markup(context,HTL_/**/x,START)
+#  define PSRCSTOP(x)  HTMLSRC_apply_markup(context,HTL_/**/x,STOP)
+#endif
 
 PRIVATE BOOL cur_attr_is_href;
 PRIVATE BOOL cur_attr_is_name;
@@ -1132,7 +1141,7 @@ PRIVATE void start_element ARGS1(
 		!strcasecomp(new_tag->name, "FIELDSET") ||
 		!strcasecomp(new_tag->name, "LABEL") ||
 		!strcasecomp(new_tag->name, "LEGEND") ||
-		!strcasecomp(new_tag->name, "FORM")) {
+		!strcasecomp(new_tag->name, "FORM"))
 #else
 	    switch (e) {
 		case HTML_INPUT:  case HTML_TEXTAREA: case HTML_SELECT:
@@ -1143,8 +1152,9 @@ PRIVATE void start_element ARGS1(
 		default:
 		    break;
 	    }
-	    if (ok) {
+	    if (ok)
 #endif
+	    {
 		/*
 		**  It is another form-related start tag, so terminate
 		**  the current SELECT block and fall through. - FM
@@ -1180,10 +1190,10 @@ PRIVATE void start_element ARGS1(
 	N->next = context->element_stack;
 	N->tag = new_tag;
 	context->element_stack = N;
-#if !OPT
-    } else if (!strcasecomp(new_tag->name, "META")) {
-#else
+#if OPT
     } else if (e == HTML_META ) {
+#else
+    } else if (!strcasecomp(new_tag->name, "META")) {
 #endif
 	/*
 	**  Check for result of META tag. - KW & FM
@@ -1360,7 +1370,11 @@ PRIVATE void SGML_character ARGS2(
     char * p;
     BOOLEAN chk;	/* Helps (?) walk through all the else ifs... */
     UCode_t clong, uck = 0; /* Enough bits for UCS4 ... */
+#ifdef CJK_EX
+    unsigned char c;
+#else
     char c;
+#endif
     char saved_char_in = '\0';
 
     /*
@@ -1369,6 +1383,10 @@ PRIVATE void SGML_character ARGS2(
     **	we can revert back to the unchanged c_in. - KW
     */
 #define unsign_c clong
+#ifdef CJK_EX	/* 1997/12/12 (Fri) 18:08:48 */
+    static unsigned char sjis_1st = '\0';
+    unsigned char sjis_hi, sjis_lo;
+#endif
 
     c = c_in;
     clong = (unsigned char)c;	/* a.k.a. unsign_c */
@@ -1579,6 +1597,25 @@ top1:
 	HTCJK == NOCJK)
 	return;
 
+#ifdef CJK_EX	/* 1998/11/24 (Tue) 17:02:31 */
+    if (HTCJK == JAPANESE && last_kcode == SJIS) {
+	if (sjis_1st == '\0' && (IS_SJIS_HI1(c) || IS_SJIS_HI2(c))) {
+	    sjis_1st = c;
+	} else if (sjis_1st && IS_SJIS_LO(c)) {
+	    sjis_1st = '\0';
+	} else {
+	    if (context->state == S_text) {
+		if (0xA1 <= (unsigned char)c && (unsigned char)c <= 0xDF) {
+		    JISx0201TO0208_SJIS(c, &sjis_hi, &sjis_lo);
+		    PUTC(sjis_hi);
+		    PUTC(sjis_lo);
+		    return;
+		}
+	    }
+	}
+    }
+#endif
+
     /*
     **	Ignore 127 if we don't have HTPassHighCtrlRaw
     **	or HTCJK set. - FM
@@ -3276,6 +3313,17 @@ top1:
 		PSRCSTOP(attrval);
 	    } else
 #endif
+#ifdef CJK_EX	/* Quick hack. - JH7AYN */
+	    {   char jis_buf[512];
+		if (string->data[0] == '$') {
+		  if (string->data[1] == 'B' || string->data[1] == '@') {
+		    jis_buf[0] = '\033';
+		    strcpy(jis_buf + 1, string->data);
+		    TO_EUC(jis_buf, string->data);
+		  }
+		}
+	    }
+#endif
 	    handle_attribute_value(context, string->data);
 	    string->size = 0;
 	    if (c == '>') {		/* End of tag */
@@ -3494,11 +3542,11 @@ top1:
 #endif
 		context->current_tag = t;
 #if OPT
+		if (tag_OK
 #ifdef EXTENDED_HTMLDTD
-		if (tag_OK && Old_DTD) {
-#else
-		if (tag_OK) {
+		 && Old_DTD
 #endif
+		 ) {
 		   switch (e) {
 		     case HTML_DD: case HTML_DT: case HTML_LI: case HTML_LH :
 		     case HTML_TD: case HTML_TH: case HTML_TR: case HTML_THEAD:
@@ -3524,9 +3572,10 @@ top1:
 		} else
 #endif /* EXTENDED_HTMLDTD */
 
-
-#if !OPT
 		if (tag_OK &&
+#if OPT
+		    (branch == 0)
+#else
 		    (!strcasecomp(string->data, "DD") ||
 		     !strcasecomp(string->data, "DT") ||
 		     !strcasecomp(string->data, "LI") ||
@@ -3537,10 +3586,9 @@ top1:
 		     !strcasecomp(string->data, "THEAD") ||
 		     !strcasecomp(string->data, "TFOOT") ||
 		     !strcasecomp(string->data, "TBODY") ||
-		     !strcasecomp(string->data, "COLGROUP"))) {
-#else
-		if (tag_OK && branch == 0) {
+		     !strcasecomp(string->data, "COLGROUP"))
 #endif
+		 ) {
 		    /*
 		    **	Don't treat these end tags as invalid,
 		    **	nor act on them. - FM
@@ -3555,8 +3603,10 @@ top1:
 			context->state = S_text;
 		    }
 		    break;
-#if !OPT
 		} else if (tag_OK &&
+#if OPT
+			   (branch == 1)
+#else
 			   (!strcasecomp(string->data, "A") ||
 			    !strcasecomp(string->data, "B") ||
 			    !strcasecomp(string->data, "BLINK") ||
@@ -3568,10 +3618,9 @@ top1:
 			    !strcasecomp(string->data, "P") ||
 			    !strcasecomp(string->data, "STRONG") ||
 			    !strcasecomp(string->data, "TT") ||
-			    !strcasecomp(string->data, "U"))) {
-#else
-		} else if (tag_OK && branch == 1) {
+			    !strcasecomp(string->data, "U"))
 #endif
+		) {
 		    /*
 		    **	Handle end tags for container elements declared
 		    **	as SGML_EMPTY to prevent "expected tag substitution"
@@ -3844,10 +3893,10 @@ top1:
 		if (!WHITE(c)) {
 		    seen_letter_in_junk_tag = TRUE;
 		    PUTC(c);
-		};
+		}
 	    } else
 		PUTC(c);
-	};
+	}
 #endif
 
     } /* switch on context->state */
@@ -4009,8 +4058,8 @@ PUBLIC HTStream* SGML_new  ARGS3(
 #ifdef USE_PSRC
     if (psrc_view) {
 	psrc_view = FALSE;
-	SGML_string(context, "<HTML><HEAD><TITLE>source</TITLE></HEAD>"
-			     "<BODY><PRE>") ;
+	SGML_string(context,
+		    "<HTML><HEAD><TITLE>source</TITLE></HEAD><BODY><PRE>");
 	psrc_view = TRUE;
 	psrc_convert_string = FALSE;
 	sgml_in_psrc_was_initialized = TRUE;
@@ -4132,6 +4181,21 @@ PUBLIC void JISx0201TO0208_EUC ARGS4(
     }
 }
 
+PRIVATE int IS_SJIS_STR ARGS1(CONST unsigned char *, str)
+{
+    CONST unsigned char *s;
+    unsigned char ch;
+    int is_sjis = 0;
+
+    s = str;
+    while ((ch = *s++) != '\0') {
+	if (ch & 0x80)
+	    if (IS_SJIS(ch, *s, is_sjis))
+		return 1;
+    }
+    return 0;
+}
+
 PUBLIC unsigned char * SJIS_TO_JIS1 ARGS3(
 	register unsigned char,		HI,
 	register unsigned char,		LO,
@@ -4177,8 +4241,9 @@ PUBLIC unsigned char * EUC_TO_SJIS1 ARGS3(
 	unsigned char,			LO,
 	register unsigned char *,	SJCODE)
 {
-    if (HI == 0x8E) JISx0201TO0208_EUC(HI, LO, &HI, &LO);
-    JIS_TO_SJIS1(HI&0x7F, LO&0x7F, SJCODE);
+    if (HI == 0x8E)
+	JISx0201TO0208_EUC(HI, LO, &HI, &LO);
+    JIS_TO_SJIS1(HI & 0x7F, LO & 0x7F, SJCODE);
     return SJCODE;
 }
 
@@ -4189,8 +4254,8 @@ PUBLIC void JISx0201TO0208_SJIS ARGS3(
 {
     unsigned char SJCODE[2];
 
-    JISx0201TO0208_EUC(216, I, OHI, OLO);
-    JIS_TO_SJIS1(*OHI&0x7F, *OLO&0x7F, SJCODE);
+    JISx0201TO0208_EUC(0x8E, I, OHI, OLO);
+    JIS_TO_SJIS1(*OHI & 0x7F, *OLO & 0x7F, SJCODE);
     *OHI = SJCODE[0];
     *OLO = SJCODE[1];
 }
@@ -4213,17 +4278,17 @@ PUBLIC unsigned char * SJIS_TO_EUC ARGS2(
     register unsigned char hi, lo, *sp, *dp;
     register int in_sjis = 0;
 
-    for (sp = src, dp = dst; (0 != (hi = sp[0]));) {
+    in_sjis = IS_SJIS_STR(src);
+    for (sp = src, dp = dst; (hi = sp[0]) != '\0';) {
 	lo = sp[1];
 	if (TREAT_SJIS && IS_SJIS(hi, lo, in_sjis)) {
-	    SJIS_TO_JIS1(hi,lo,dp);
+	    SJIS_TO_JIS1(hi, lo, dp);
 	    dp[0] |= 0x80;
 	    dp[1] |= 0x80;
 	    dp += 2;
 	    sp += 2;
-	} else {
+	} else
 	    *dp++ = *sp++;
-	}
     }
     *dp = 0;
     return dst;
@@ -4238,7 +4303,7 @@ PUBLIC unsigned char * EUC_TO_SJIS ARGS2(
     for (sp = src, dp = dst; *sp;) {
 	if (*sp & 0x80) {
 	    if (sp[1] && (sp[1] & 0x80)) {
-		JIS_TO_SJIS1(sp[0]&0x7F, sp[1]&0x7F, dp);
+		JIS_TO_SJIS1(sp[0] & 0x7F, sp[1] & 0x7F, dp);
 		dp += 2;
 		sp += 2;
 	    } else {
@@ -4252,7 +4317,9 @@ PUBLIC unsigned char * EUC_TO_SJIS ARGS2(
     return dst;
 }
 
-PUBLIC unsigned char * EUC_TO_JIS ARGS4(
+#define Strcpy(a,b)	(strcpy((char*)a,(CONST char*)b),&a[strlen((CONST char*)a)])
+
+PUBLIC unsigned char *EUC_TO_JIS ARGS4(
 	unsigned char *,	src,
 	unsigned char *,	dst,
 	CONST char *,		toK,
@@ -4262,15 +4329,20 @@ PUBLIC unsigned char * EUC_TO_JIS ARGS4(
     register unsigned char cch;
     register unsigned char *sp = src;
     register unsigned char *dp = dst;
-    register int i;
+    int is_JIS = 0;
 
-    while (0 != (cch = *sp++)) {
+    while ((cch = *sp++) != '\0') {
 	if (cch & 0x80) {
+	    if (!IS_EUC(cch, *sp)) {
+		if (cch == 0xA0 && is_JIS)	/* ignore NBSP */
+		    continue;
+		is_JIS++;
+		*dp++ = cch;
+		continue;
+	    }
 	    if (!kana_mode) {
 		kana_mode = ~kana_mode;
-		for (i = 0; toK[i]; i++) {
-		    *dp++ = (unsigned char)toK[i];
-		}
+		dp = Strcpy(dp, toK);
 	    }
 	    if (*sp & 0x80) {
 		*dp++ = cch & ~0x80;
@@ -4279,70 +4351,244 @@ PUBLIC unsigned char * EUC_TO_JIS ARGS4(
 	} else {
 	    if (kana_mode) {
 		kana_mode = ~kana_mode;
-		for (i = 0; toA[i]; i++) {
-		    *dp++ = (unsigned char)toA[i];
-		    *dp = '\0';
-		}
+		dp = Strcpy(dp, toA);
 	    }
 	    *dp++ = cch;
 	}
     }
-    if (kana_mode) {
-	for (i = 0; toA[i]; i++) {
-	    *dp++ = (unsigned char)toA[i];
-	}
-    }
+    if (kana_mode)
+	dp = Strcpy(dp, toA);
 
     if (dp)
 	*dp = 0;
     return dst;
 }
 
-PUBLIC unsigned char * TO_EUC ARGS2(
+#define	IS_JIS7(c1,c2)	(0x20<(c1)&&(c1)<0x7F && 0x20<(c2)&&(c2)<0x7F)
+#define SO		('N'-0x40)
+#define SI		('O'-0x40)
+
+PUBLIC int repair_JIS = 0;
+
+PRIVATE CONST unsigned char *repairJIStoEUC ARGS2(
+	CONST unsigned char *,	src,
+	unsigned char **,	dstp)
+{
+    CONST unsigned char *s;
+    unsigned char *d, ch1, ch2;
+
+    d = *dstp;
+    s = src;
+    while ((ch1 = s[0]) && (ch2 = s[1])) {
+	s += 2;
+	if (ch1 == '(')
+	    if (ch2 == 'B' || ch2 == 'J') {
+		*dstp = d;
+		return s;
+	    }
+	if (!IS_JIS7(ch1, ch2))
+	    return 0;
+
+	*d++ = 0x80 | ch1;
+	*d++ = 0x80 | ch2;
+    }
+    return 0;
+}
+
+#if 0	/* NOTUSED */
+
+static struct {
+    char *ee;
+    char de;
+} entities[] = {
+    {"&lt;", '<' },
+    {"&gt;", '>' },
+    {"&amp;", '&'},
+    {"&quot;", '"'},
+    {NULL, 0}
+};
+
+PRIVATE int isHTMLentity ARGS2(
+	char *, str,
+	int *, chp)
+{
+    int ei, ej;
+    char *es, ec;
+    int off;
+
+    off = *str == '&' ? 0 : 1;
+    for (ei = 0; (es = entities[ei].ee) != '\0'; ei++) {
+	for (ej = 0; (ec = es[off + ej]) != '\0'; ej++) {
+	    if (ec != str[ej])
+		break;
+	    if (ec == ';') {
+		*chp = entities[ei].de;
+		return ej + 1;
+	    }
+	}
+    }
+    return 0;
+}
+
+#define sputc(sp,ch)	(sp?(*sp++ = ch):ch)
+
+PUBLIC int FIX_2022 ARGS3(
+	char *, src,
+	char *, dst,
+	char *, ctype)
+{
+    int in2B;
+    char ch1, ch2, *sp, *dp;
+    int bad;
+    int isHTML, len, ech;
+
+    in2B = 0;
+    sp = src;
+    dp = dst;
+    bad = 0;
+
+    isHTML = strcasecomp(ctype, "text/html") == 0;
+
+    while ((ch1 = *sp++) != '\0') {
+	if (ch1 == ESC) {
+	    if (*sp == TO_2BCODE) {
+		if (sp[1] == 'B' || sp[1] == '@') {
+		    in2B = 1;
+		    sputc(dp, ch1);
+		    sputc(dp, *sp++);
+		    sputc(dp, *sp++);
+		    continue;
+		}
+	    } else if (*sp == TO_1BCODE) {
+		if (sp[1] == 'B' || sp[1] == 'J') {
+		    in2B = 0;
+		    sputc(dp, ch1);
+		    sputc(dp, *sp++);
+		    sputc(dp, *sp++);
+		    continue;
+		}
+	    }
+	}
+	if (in2B) {
+	    if ((ch1 <= 0x20)
+		|| (sp[0] <= 0x20)
+		|| (ch1 == '<' && sp[0] == '/')
+		|| (sp[0] == '<' && sp[1] == '/')) {
+		in2B = 0;
+		sputc(dp, ESC);
+		sputc(dp, TO_1BCODE);
+		sputc(dp, 'B');
+		sputc(dp, ch1);
+		bad = 1;
+		continue;
+	    }
+	    if (isHTML && ch1 == '&')
+		if ((len = isHTMLentity(sp, &ech)) != '\0')
+		    if (sp[len] != 0) {
+			ch1 = ech;
+			sp += len;
+			bad = 1;
+		    }
+	    ch2 = *sp++;
+
+	    if (isHTML && ch2 == '&')
+		if ((len = isHTMLentity(sp, &ech)) != '\0')
+		    if (sp[len] != 0) {
+			ch2 = ech;
+			sp += len;
+			bad = 1;
+		    }
+	    sputc(dp, ch1);
+	    sputc(dp, ch2);
+	} else {
+	    sputc(dp, ch1);
+	}
+    }
+    sputc(dp, 0);
+    return bad;
+}
+
+#endif
+
+PUBLIC unsigned char *TO_EUC ARGS2(
 	CONST unsigned char *,	jis,
 	unsigned char *,	euc)
 {
     register CONST unsigned char *s;
-    register unsigned char *d, c, jis_stat;
+    register unsigned char c, jis_stat;
+    unsigned char *d;
     register int to1B, to2B;
     register int in_sjis = 0;
+    static int nje;
+    int n8bits;
+    int is_JIS;
 
+    nje++;
+    n8bits = 0;
     s = jis;
     d = euc;
     jis_stat = 0;
     to2B = TO_2BCODE;
     to1B = TO_1BCODE;
-
-    while (0 != (c = *s++)) {
+    in_sjis = IS_SJIS_STR(jis);
+    is_JIS = 0;
+
+    while ((c = *s++) != '\0') {
+	if (c == 0x80)
+	    continue;		/* ignore it */
+	if (c == 0xA0 && is_JIS)
+	    continue;		/* ignore Non-breaking space */
+
+	if (c == to2B && jis_stat == 0 && repair_JIS) {
+	    if (*s == 'B' || *s == '@') {
+		CONST unsigned char *ts;
+		if ((ts = repairJIStoEUC(s + 1, &d)) != NULL) {
+		    s = ts;
+		    continue;
+		}
+	    }
+	}
 	if (c == ESC) {
 	    if (*s == to2B) {
-		if ((s[1] == 'B') || (s[1] == '@') || (s[1] == 'A')) {
+		if ((s[1] == 'B') || (s[1] == '@')) {
 		    jis_stat = 0x80;
 		    s += 2;
-		    continue;
-		} else if ((s[1] == '(') && s[2] && (s[2] == 'C')) {
-		    jis_stat = 0x80;
-		    s += 3;
+		    is_JIS++;
 		    continue;
 		}
-	    } else {
-		if (*s == to1B) {
-		    if ((s[1]=='B') || (s[1]=='J') ||
-			(s[1]=='H') || (s[1]=='T')) {
-			jis_stat = 0;
-			s += 2;
-			continue;
-		    }
+		jis_stat = 0;
+	    } else if (*s == to1B) {
+		jis_stat = 0;
+		if ((s[1] == 'B') || (s[1] == 'J') || (s[1] == 'H')) {
+		    s += 2;
+		    continue;
 		}
+	    } else if (*s == ',') {	/* MULE */
+		jis_stat = 0;
 	    }
 	}
-	if (IS_SJIS(c,*s,in_sjis)) {
+	if (c & 0x80)
+	    n8bits++;
+
+	if (IS_SJIS(c, *s, in_sjis)) {
 	    SJIS_TO_EUC1(c, *s, d);
 	    d += 2;
 	    s++;
+	    is_JIS++;
+	} else if (jis_stat) {
+	    if (c <= 0x20 || 0x7F <= c) {
+		*d++ = c;
+		if (c == '\n')
+		    jis_stat = 0;
+	    } else {
+		if (IS_JIS7(c, *s)) {
+		    *d++ = jis_stat | c;
+		    *d++ = jis_stat | *s++;
+		} else
+		    *d++ = c;
+	    }
 	} else {
-	    if (jis_stat && (0x20 < c)) {
-		*d++ = jis_stat | c;
+	    if (n8bits == 0 && (c == SI || c == SO)) {
 	    } else {
 		*d++ = c;
 	    }
@@ -4352,22 +4598,47 @@ PUBLIC unsigned char * TO_EUC ARGS2(
     return euc;
 }
 
+#define non94(ch) ((ch) <= 0x20 || (ch) == 0x7F)
+
+PRIVATE int is_EUC_JP ARGS1(unsigned char *, euc)
+{
+    unsigned char *cp;
+    int ch1, ch2;
+
+    for (cp = euc; (ch1 = *cp) != '\0'; cp++) {
+	if (ch1 & 0x80) {
+	    ch2 = cp[1] & 0xFF;
+	    if ((ch2 & 0x80) == 0) {
+		/* sv1log("NOT_EUC1[%x][%x]\n",ch1,ch2); */
+		return 0;
+	    }
+	    if (non94(ch1 & 0x7F) || non94(ch2 & 0x7F)) {
+		/* sv1log("NOT_EUC2[%x][%x]\n",ch1,ch2); */
+		return 0;
+	    }
+	    cp++;
+	}
+    }
+    return 1;
+}
+
 PUBLIC void TO_SJIS ARGS2(
 	CONST unsigned char *,	any,
 	unsigned char *,	sjis)
 {
     unsigned char *euc;
 
-    if (!any || !sjis)
-	return;
-
-    euc = (unsigned char*)malloc(strlen((CONST char *)any)+1);
-    if (euc == NULL)
+    euc = malloc(strlen(any) + 1);
+#ifdef CJK_EX
+    if (!euc)
 	outofmem(__FILE__, "TO_SJIS");
-
+#endif
     TO_EUC(any, euc);
-    EUC_TO_SJIS(euc, sjis);
-    FREE(euc);
+    if (is_EUC_JP(euc))
+	EUC_TO_SJIS(euc, sjis);
+    else
+	strcpy(sjis, any);
+    free(euc);
 }
 
 PUBLIC void TO_JIS ARGS2(
@@ -4376,14 +4647,24 @@ PUBLIC void TO_JIS ARGS2(
 {
     unsigned char *euc;
 
-    if (!any || !jis)
+    if (any[0] == 0) {
+	jis[0] = 0;
 	return;
-
-    euc = (unsigned char*)malloc(strlen((CONST char *)any)+1);
-    if (euc == NULL)
+    }
+    euc = malloc(strlen(any) + 1);
+#ifdef CJK_EX
+    if (!euc)
 	outofmem(__FILE__, "TO_JIS");
-
+#endif
     TO_EUC(any, euc);
+#if 0
+    if (is_EUC_JP(euc))
+	EUC_TO_JIS(euc, jis, TO_KANJI, TO_ASCII);
+    else
+	strcpy(jis, any);
+#endif
+    is_EUC_JP(euc);
     EUC_TO_JIS(euc, jis, TO_KANJI, TO_ASCII);
-    FREE(euc);
+
+    free(euc);
 }
diff --git a/WWW/Library/Implementation/SGML.h b/WWW/Library/Implementation/SGML.h
index 9ae3ae36..1a1334ba 100644
--- a/WWW/Library/Implementation/SGML.h
+++ b/WWW/Library/Implementation/SGML.h
@@ -19,6 +19,7 @@
 
 #include <HTStream.h>
 #include <HTAnchor.h>
+#include <LYJustify.h>
 
 /*
 
@@ -113,6 +114,9 @@ struct _tag{
 #ifdef USE_COLOR_STYLE
     int		name_len;		/* The length of the name */
 #endif
+#ifdef EXP_JUSTIFY_ELTS
+    BOOL	can_justify;		/* justification allowed?*/
+#endif
     attr *	attributes;		/* The list of acceptable attributes */
     int		number_of_attributes;	/* Number of possible attributes */
     SGMLContent contents;		/* End only on end tag @@ */
diff --git a/WWW/Library/Implementation/getline.c b/WWW/Library/Implementation/getline.c
index 3168b9ec..370c5a6e 100644
--- a/WWW/Library/Implementation/getline.c
+++ b/WWW/Library/Implementation/getline.c
@@ -39,7 +39,11 @@ unsigned int len;
 
    if (lineptr == NULL || n == NULL)
    {
+#ifdef _WINDOWS
+      WSASetLastError(EINVAL);
+#else
       SOCKET_ERRNO = EINVAL;
+#endif
       return -1;
    }
 
diff --git a/WWW/Library/Implementation/makefile.in b/WWW/Library/Implementation/makefile.in
index 19def689..96803c91 100644
--- a/WWW/Library/Implementation/makefile.in
+++ b/WWW/Library/Implementation/makefile.in
@@ -135,7 +135,7 @@ HFILES = $(CMN)HTParse.h $(CMN)HTAccess.h $(CMN)HTTP.h $(CMN)HTFile.h \
 	$(CMN)HTFormat.h $(CMN)HTInit.h \
 	$(CMN)HTMIME.h $(CMN)HTNews.h \
 	$(CMN)HTGopher.h \
-	$(CMN)HTUtils.h $(CMN)tcp.h $(CMN)HText.h \
+	$(CMN)HTUtils.h $(CMN)www_tcp.h $(CMN)HText.h \
 	$(CMN)HTTelnet.h $(CMN)HTFinger.h \
 	$(CMN)HTWAIS.h  $(CMN)HTWSRC.h \
 	$(CMN)HTAABrow.h \
diff --git a/WWW/Library/Implementation/tcp.h b/WWW/Library/Implementation/www_tcp.h
index fe977bca..b9e3bbf5 100644
--- a/WWW/Library/Implementation/tcp.h
+++ b/WWW/Library/Implementation/www_tcp.h
@@ -67,6 +67,11 @@ typedef struct sockaddr_in SockA;  /* See netinet/in.h */
 #undef HAVE_SYS_FILIO_H
 #endif /* DJGPP or __BORLANDC__ */
 
+#if defined(_MSC_VER)
+#define HAVE_DIRENT_H
+#undef HAVE_SYS_FILIO_H
+#endif /* _MSC_VER */
+
 #ifdef HAVE_DIRENT_H
 # include <dirent.h>
 # define D_NAMLEN(dirent) strlen((dirent)->d_name)
@@ -159,7 +164,7 @@ IBM-PC running Windows NT
 #undef NETWRITE
 #undef NETCLOSE
 #undef IOCTL
-#define NETREAD(s,b,l)  recv((s),(b),(l),0)
+#define NETREAD(s,b,l)  ws_netread((s),(b),(l))	/* 1997/11/06 (Thu) */
 #define NETWRITE(s,b,l) send((s),(b),(l),0)
 #define NETCLOSE(s)     closesocket(s)
 #define IOCTL				ioctlsocket
@@ -171,6 +176,13 @@ IBM-PC running Windows NT
 #include <direct.h>
 #include <winsock.h>
 typedef struct sockaddr_in SockA;  /* See netinet/in.h */
+
+#if defined(_MSC_VER)
+#undef EINTR
+#undef EAGAIN
+#endif /* _MSC_VER */
+
+#define EWOULDBLOCK          (WSABASEERR+35)	/* ADD by JH7AYN */
 #define EINPROGRESS          (WSABASEERR+36)
 #define EALREADY             (WSABASEERR+37)
 #define EISCONN              (WSABASEERR+56)
@@ -178,7 +190,10 @@ typedef struct sockaddr_in SockA;  /* See netinet/in.h */
 #define EAGAIN               (WSABASEERR+1002)
 #define ENOTCONN             (WSABASEERR+57)
 #define ECONNRESET           (WSABASEERR+54)
+#define ETIMEDOUT             WSAETIMEDOUT	/* 1997/11/10 (Mon) */
 #define EINVAL                22
+#undef  SOCKET_ERRNO	/* 1997/10/19 (Sun) 18:01:46 */
+#define SOCKET_ERRNO          WSAGetLastError()
 #define INCLUDES_DONE
 #define TCP_INCLUDES_DONE
 #endif  /* WINDOWS */
@@ -485,6 +500,7 @@ struct timeval {
 #undef SELECT
 #define TCP_INCLUDES_DONE
 #define NO_IOCTL
+#define DECL_ERRNO
 #include <errno.h>
 #include <sys/types.h>
 #include <socket.h>
@@ -495,7 +511,9 @@ struct timeval {
 #define NETREAD read_s
 #undef NETCLOSE
 #define NETCLOSE close_s
+#ifndef WATT32
 #define getsockname getsockname_s
+#endif /* WATT32 */
 #ifdef HAVE_GETTEXT
 #define gettext gettext__
 #endif
diff --git a/WWW/Library/djgpp/CommonMakefile b/WWW/Library/djgpp/CommonMakefile
index f4bdad38..676052d9 100644
--- a/WWW/Library/djgpp/CommonMakefile
+++ b/WWW/Library/djgpp/CommonMakefile
@@ -116,7 +116,7 @@ HFILES = $(CMN)HTParse.h $(CMN)HTAccess.h $(CMN)HTTP.h $(CMN)HTFile.h \
 	$(CMN)HTFormat.h $(CMN)HTInit.h \
 	$(CMN)HTMIME.h $(CMN)HTNews.h \
 	$(CMN)HTGopher.h \
-	$(CMN)HTUtils.h $(CMN)tcp.h $(CMN)HText.h \
+	$(CMN)HTUtils.h $(CMN)www_tcp.h $(CMN)HText.h \
 	$(CMN)HTTelnet.h $(CMN)HTFinger.h \
 	$(CMN)HTWAIS.h  $(CMN)HTWSRC.h \
 	$(CMN)HTAAUtil.h $(CMN)HTAABrow.h \
diff --git a/WWW/Library/djgpp/makefile.sla b/WWW/Library/djgpp/makefile.sla
index 78b63da9..bc9439e1 100644
--- a/WWW/Library/djgpp/makefile.sla
+++ b/WWW/Library/djgpp/makefile.sla
@@ -8,10 +8,10 @@ WWW_MACH = djgpp
 #ASIS_MACH = hardware/os
 
 CFLAGS = -O3 -DUSE_SLANG -DUSE_ZLIB -DDOSPATH -DNOUSERS -DDISP_PARTIAL \
--DDIRED_SUPPORT -DSOURCE_CACHE -DUSE_PSRC -DNOPORT \
+-DDIRED_SUPPORT -DSOURCE_CACHE -DUSE_PSRC \
+-DWATT32 \
 -I../Implementation \
--I../../../djgpp/tcplib/include \
--I../../../djgpp/tcplib/include/tcp \
+-I../../../djgpp/watt32/inc -I../../../djgpp/watt32/inc/sys \
 -I../../../src \
 -I../../.. $(SLANGINC) $(INTLFLAGS)
 LFLAGS =
diff --git a/WWW/Library/vms/descrip.mms b/WWW/Library/vms/descrip.mms
index 6bbdaaba..ddac73f3 100644
--- a/WWW/Library/vms/descrip.mms
+++ b/WWW/Library/vms/descrip.mms
@@ -163,7 +163,7 @@ CFLAGS = $(DEBUGFLAGS) /Define = ($(EXTRADEFINES), MULTINET) $(INCLUDES)
 CC = gcc
 .endif
 
-!HEADERS = HTUtils.h, HTStream.h, tcp.h, HText.h -
+!HEADERS = HTUtils.h, HTStream.h, www_tcp.h, HText.h -
 !        HTParse.h, HTAccess.h, HTTP.h, HTFile.h, -
 !	HTBTree.h, HTTCP.h, SGML.h, -
 !	HTML.h, HTMLDTD.h, HTChunk.h, HTPlain.h, -
@@ -212,7 +212,7 @@ clean :
 ! Simple Dependencies
 
 
-!HTString.obj :	HTString.c HTString.h tcp.h Version.make HTUtils.h
+!HTString.obj :	HTString.c HTString.h www_tcp.h Version.make HTUtils.h
 !HTAtom.obj :	HTAtom.c HTAtom.h HTUtils.h HTString.h
 !HTChunk.obj :	HTChunk.c HTChunk.h HTUtils.h
 !HTList.obj :	HTList.c HTList.h HTUtils.h
@@ -235,7 +235,7 @@ clean :
 !HTNews.obj :	HTNews.c HTNews.h HTUtils.h HTList.h
 !HTParse.obj :	HTParse.c HTParse.h HTUtils.h
 !HTStyle.obj :	HTStyle.c HTStyle.h HTUtils.h
-!HTTCP.obj :	HTTCP.c HTTCP.h HTUtils.h tcp.h
+!HTTCP.obj :	HTTCP.c HTTCP.h HTUtils.h www_tcp.h
 !HTTP.obj :	HTTP.c HTTP.h HTUtils.h
 !SGML.obj :	SGML.c SGML.h HTUtils.h
 !HTAABrow.obj :	HTAABrow.c HTUtils.h