about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--CHANGES8
-rw-r--r--WWW/Library/Implementation/HTAABrow.c71
-rw-r--r--WWW/Library/Implementation/HTAAProt.c121
-rw-r--r--WWW/Library/Implementation/HTAAServ.c129
-rw-r--r--WWW/Library/Implementation/HTAAUtil.c15
-rw-r--r--WWW/Library/Implementation/HTACL.c18
-rw-r--r--WWW/Library/Implementation/HTAccess.c100
-rw-r--r--WWW/Library/Implementation/HTAnchor.c29
-rw-r--r--WWW/Library/Implementation/HTAssoc.c4
-rw-r--r--WWW/Library/Implementation/HTAtom.c6
-rw-r--r--WWW/Library/Implementation/HTAuth.c18
-rw-r--r--WWW/Library/Implementation/HTFTP.c319
-rw-r--r--WWW/Library/Implementation/HTFWriter.c3
-rw-r--r--WWW/Library/Implementation/HTFile.c88
-rw-r--r--WWW/Library/Implementation/HTFinger.c37
-rw-r--r--WWW/Library/Implementation/HTFormat.c74
-rw-r--r--WWW/Library/Implementation/HTGopher.c72
-rw-r--r--WWW/Library/Implementation/HTGroup.c60
-rw-r--r--WWW/Library/Implementation/HTHistory.c18
-rw-r--r--WWW/Library/Implementation/HTList.c17
-rw-r--r--WWW/Library/Implementation/HTMIME.c541
-rw-r--r--WWW/Library/Implementation/HTMLDTD.c2
-rw-r--r--WWW/Library/Implementation/HTNews.c127
-rw-r--r--WWW/Library/Implementation/HTParse.c25
-rw-r--r--WWW/Library/Implementation/HTPasswd.c16
-rw-r--r--WWW/Library/Implementation/HTPlain.c15
-rw-r--r--WWW/Library/Implementation/HTRules.c152
-rw-r--r--WWW/Library/Implementation/HTStyle.c10
-rw-r--r--WWW/Library/Implementation/HTTCP.c105
-rw-r--r--WWW/Library/Implementation/HTTP.c156
-rw-r--r--WWW/Library/Implementation/HTTelnet.c46
-rw-r--r--WWW/Library/Implementation/HTUtils.h11
-rw-r--r--WWW/Library/Implementation/HTVMSUtils.c24
-rw-r--r--WWW/Library/Implementation/HTWAIS.c67
-rw-r--r--WWW/Library/Implementation/HTWSRC.c5
-rw-r--r--WWW/Library/Implementation/HTWriter.c6
-rw-r--r--WWW/Library/Implementation/SGML.c188
-rw-r--r--src/GridText.c240
-rw-r--r--src/HTFWriter.c7
-rw-r--r--src/HTInit.c129
-rw-r--r--src/HTML.c261
-rw-r--r--src/LYBookmark.c296
-rw-r--r--src/LYCgi.c34
-rw-r--r--src/LYCharUtils.c39
-rw-r--r--src/LYCookie.c149
-rw-r--r--src/LYCurses.c30
-rw-r--r--src/LYDownload.c25
-rw-r--r--src/LYEdit.c10
-rw-r--r--src/LYExtern.c2
-rw-r--r--src/LYGetFile.c53
-rw-r--r--src/LYHistory.c121
-rw-r--r--src/LYList.c2
-rw-r--r--src/LYLocal.c25
-rw-r--r--src/LYMail.c32
-rw-r--r--src/LYMain.c56
-rw-r--r--src/LYMainLoop.c55
-rw-r--r--src/LYPrint.c11
-rw-r--r--src/LYReadCFG.c24
-rw-r--r--src/LYShowInfo.c94
-rw-r--r--src/LYStrings.c47
-rw-r--r--src/LYStyle.c33
-rw-r--r--src/LYUpload.c51
-rw-r--r--src/LYUtils.c160
-rw-r--r--src/LYexit.c3
-rw-r--r--src/UCAuto.c14
-rw-r--r--src/UCdomap.c72
-rw-r--r--userdefs.h2
67 files changed, 1770 insertions, 3010 deletions
diff --git a/CHANGES b/CHANGES
index 53ea67af..c16b13c3 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,14 @@
 Changes since Lynx 2.8 release
 ================================================================================
 
+1998-04-23 (2.8.1dev.7)
+* fix core-dump when pressing '.' on a page with no links (patch by
+  Jan Hlav\'{a}\v{c}ek <lahvak@math.ohio-state.edu>).
+* initial changes to use macros CTRACE and tfp to replace explicit use of
+  stderr for the trace log.  Remaining work is required for some complex
+  expressions, switching file pointers and for perror-substitute. - TD
+* ifdef's for OS/2 EMX, mostly pathname tweaks (patch by Jason F. McBrayer
+  <jmcbray@mailhost.tcs.tulane.edu>).
 1998-04-18 (2.8.1dev.6)
 * correct misplaced ifdef in LYMail.c, which caused Cc to not work (patch
   by LE).
diff --git a/WWW/Library/Implementation/HTAABrow.c b/WWW/Library/Implementation/HTAABrow.c
index 38c6ca50..1be48c4a 100644
--- a/WWW/Library/Implementation/HTAABrow.c
+++ b/WWW/Library/Implementation/HTAABrow.c
@@ -341,32 +341,29 @@ PRIVATE HTAASetup *HTAASetup_lookup ARGS4(
 
 	HTList *cur = server->setups;
 
-	if (TRACE)
-	    fprintf(stderr, "%s %s (%s:%d:%s)\n",
-			    "HTAASetup_lookup: resolving setup for",
-			    (IsProxy ? "proxy" : "server"),
-			    hostname, portnumber, docname);
+	CTRACE(tfp, "%s %s (%s:%d:%s)\n",
+		    "HTAASetup_lookup: resolving setup for",
+		    (IsProxy ? "proxy" : "server"),
+		    hostname, portnumber, docname);
 
 	while (NULL != (setup = (HTAASetup*)HTList_nextObject(cur))) {
 	    if (HTAA_templateMatch(setup->template, docname)) {
-		if (TRACE)
-		    fprintf(stderr, "%s `%s' %s `%s'\n",
-				    "HTAASetup_lookup:", docname,
-				    "matched template", setup->template);
+		CTRACE(tfp, "%s `%s' %s `%s'\n",
+			    "HTAASetup_lookup:", docname,
+			    "matched template", setup->template);
 		return setup;
+	    } else {
+	        CTRACE(tfp, "%s `%s' %s `%s'\n",
+			    "HTAASetup_lookup:", docname,
+			    "did NOT match template", setup->template);
 	    }
-	    else if (TRACE)
-	        fprintf(stderr, "%s `%s' %s `%s'\n",
-				"HTAASetup_lookup:", docname,
-				"did NOT match template", setup->template);
 	} /* while setups remain */
     } /* if valid parameters and server found */
 
-    if (TRACE)
-        fprintf(stderr, "%s `%s' %s\n",
-		        "HTAASetup_lookup: No template matched",
-		        (docname ? docname : "(null)"),
-		        "(so probably not protected)");
+    CTRACE(tfp, "%s `%s' %s\n",
+		 "HTAASetup_lookup: No template matched",
+		 (docname ? docname : "(null)"),
+		 "(so probably not protected)");
 
     return NULL;	/* NULL in parameters, or not found */
 }
@@ -605,10 +602,9 @@ PRIVATE char *compose_auth_string ARGS3(
     	  realm->username && *realm->username &&
 	  realm->password) || setup->retry) { 
 	if (!realm) {
-	    if (TRACE)
-	        fprintf(stderr, "%s `%s' %s\n",
-			        "compose_auth_string: realm:", realmname,
-			        "not found -- creating");
+	    CTRACE(tfp, "%s `%s' %s\n",
+			"compose_auth_string: realm:", realmname,
+			"not found -- creating");
 	    realm = HTAARealm_new(setup->server->realms,
 				  realmname, NULL, NULL);
 	}
@@ -860,9 +856,8 @@ PUBLIC char *HTAA_composeAuth ARGS4(
     **  on server-side.  Life is hard.)
     */
     if (HTAAForwardAuth) {
-	if (TRACE)
-	    fprintf(stderr, "HTAA_composeAuth: %s\n",
-			    "Forwarding received authorization");
+	CTRACE(tfp, "HTAA_composeAuth: %s\n",
+		    "Forwarding received authorization");
 	StrAllocCopy(HTAA_composeAuthResult, HTAAForwardAuth);
 	HTAAForwardAuth_reset();	/* Just a precaution */
 	return HTAA_composeAuthResult;
@@ -875,9 +870,7 @@ PUBLIC char *HTAA_composeAuth ARGS4(
 	**  Proxy Authorization required. - AJL
 	*/
 
-	if (TRACE)
-	    fprintf(stderr, 
-		    "Composing Proxy Authorization for %s:%d/%s\n",
+	CTRACE(tfp, "Composing Proxy Authorization for %s:%d/%s\n",
 		    hostname, portnumber, docname);
 
 	if (proxy_portnumber != portnumber ||
@@ -952,9 +945,7 @@ PUBLIC char *HTAA_composeAuth ARGS4(
 	/*
 	**  Normal WWW authorization.
 	*/
-	if (TRACE)
-	    fprintf(stderr, 
-		    "Composing Authorization for %s:%d/%s\n",
+	CTRACE(tfp, "Composing Authorization for %s:%d/%s\n",
 		    hostname, portnumber, docname);
 
 	if (current_portnumber != portnumber ||
@@ -1087,13 +1078,11 @@ PUBLIC BOOL HTAA_shouldRetryWithAuth ARGS5(
     /*
     **  Read server reply header lines
     */
-    if (TRACE)
-	fprintf(stderr, "Server reply header lines:\n");
+    CTRACE(tfp, "Server reply header lines:\n");
 
     HTAA_setupReader(start_of_headers, length, handle, soc);
     while (NULL != (line = HTAA_getUnfoldedLine())  &&  *line != '\0') {
-	if (TRACE)
-	    fprintf(stderr, "%s\n", line);
+	CTRACE(tfp, "%s\n", line);
 
 	if (strchr(line, ':')) {	/* Valid header line */
 
@@ -1133,9 +1122,8 @@ PUBLIC BOOL HTAA_shouldRetryWithAuth ARGS5(
 		    }
 		    scheme_specifics[scheme] = HTAA_parseArgList(args);
 		    num_schemes++;
-		}
-		else if (TRACE) {
-		    fprintf(stderr, "Unknown scheme `%s' %s\n",
+		} else {
+		    CTRACE(tfp, "Unknown scheme `%s' %s\n",
 			    (arg1 ? arg1 : "(null)"),
 			    (IsProxy ?
 			     "in Proxy-Authenticate: field" :
@@ -1145,14 +1133,13 @@ PUBLIC BOOL HTAA_shouldRetryWithAuth ARGS5(
 
 	    else if (!IsProxy &&
 		     0==strcasecomp(fieldname, "WWW-Protection-Template:")) {
-		if (TRACE)
-		    fprintf(stderr, "Protection template set to `%s'\n", arg1);
+		CTRACE(tfp, "Protection template set to `%s'\n", arg1);
 		StrAllocCopy(template, arg1);
 	    }
 
 	} /* if a valid header line */
-	else if (TRACE) {
-	    fprintf(stderr, "Invalid header line `%s' ignored\n", line);
+	else {
+	    CTRACE(tfp, "Invalid header line `%s' ignored\n", line);
 	} /* else invalid header line */
 
 	FREE(line);
diff --git a/WWW/Library/Implementation/HTAAProt.c b/WWW/Library/Implementation/HTAAProt.c
index 6bf8ab3f..e1d6f61f 100644
--- a/WWW/Library/Implementation/HTAAProt.c
+++ b/WWW/Library/Implementation/HTAAProt.c
@@ -125,22 +125,21 @@ PUBLIC int HTAA_getUid NOARGS
     if (current_prot  &&  current_prot->uid_name) {
 	if (isNumber(current_prot->uid_name)) {
 	    if (NULL != (pw = getpwuid(atoi(current_prot->uid_name)))) {
-		if (TRACE) fprintf(stderr, 
-				   "%s(%s) returned (%s:%s:%d:%d:...)\n",
-				   "HTAA_getUid: getpwuid",
-				   current_prot->uid_name,
-				   pw->pw_name, pw->pw_passwd,
-				   pw->pw_uid, pw->pw_gid);
+		CTRACE(tfp, "%s(%s) returned (%s:%s:%d:%d:...)\n",
+			    "HTAA_getUid: getpwuid",
+			    current_prot->uid_name,
+			    pw->pw_name, pw->pw_passwd,
+			    pw->pw_uid, pw->pw_gid);
 		return pw->pw_uid;	
 	    }
 	}
 	else {	/* User name (not a number) */
 	    if (NULL != (pw = getpwnam(current_prot->uid_name))) {
-		if (TRACE) fprintf(stderr, "%s(\"%s\") %s (%s:%s:%d:%d:...)\n",
-				   "HTAA_getUid: getpwnam",
-				   current_prot->uid_name, "returned",
-				   pw->pw_name, pw->pw_passwd,
-				   pw->pw_uid, pw->pw_gid);
+		CTRACE(tfp, "%s(\"%s\") %s (%s:%s:%d:%d:...)\n",
+			    "HTAA_getUid: getpwnam",
+			    current_prot->uid_name, "returned",
+			    pw->pw_name, pw->pw_passwd,
+			    pw->pw_uid, pw->pw_gid);
 		return pw->pw_uid;
 	    }
 	}
@@ -149,8 +148,8 @@ PUBLIC int HTAA_getUid NOARGS
     ** Ok, then let's get uid for nobody.
     */
     if (NULL != (pw = getpwnam("nobody"))) {
-	if (TRACE) fprintf(stderr, "HTAA_getUid: Uid for `nobody' is %d\n",
-			   pw->pw_uid);
+	CTRACE(tfp, "HTAA_getUid: Uid for `nobody' is %d\n",
+		    pw->pw_uid);
 	return pw->pw_uid;
     }
     /*
@@ -177,11 +176,10 @@ PUBLIC int HTAA_getGid NOARGS
 	if (isNumber(current_prot->gid_name)) {
 	    if (NULL != (gr = getgrgid(atoi(current_prot->gid_name)))) {
 #ifndef __EMX__	/* no gr_passwd */
-		if (TRACE) fprintf(stderr,
-				   "%s(%s) returned (%s:%s:%d:...)\n",
-				   "HTAA_getGid: getgrgid",
-				   current_prot->gid_name,
-				   gr->gr_name, gr->gr_passwd, gr->gr_gid);
+		CTRACE(tfp, "%s(%s) returned (%s:%s:%d:...)\n",
+			    "HTAA_getGid: getgrgid",
+			    current_prot->gid_name,
+			    gr->gr_name, gr->gr_passwd, gr->gr_gid);
 #endif
 		return gr->gr_gid;
 	    }
@@ -189,11 +187,10 @@ PUBLIC int HTAA_getGid NOARGS
 	else {	/* Group name (not number) */
 	    if (NULL != (gr = getgrnam(current_prot->gid_name))) {
 #ifndef __EMX__	/* no gr_passwd */
-		if (TRACE) fprintf(stderr, 
-				   "%s(\"%s\") returned (%s:%s:%d:...)\n",
-				   "HTAA_getGid: getgrnam",
-				   current_prot->gid_name,
-				   gr->gr_name, gr->gr_passwd, gr->gr_gid);
+		CTRACE(tfp, "%s(\"%s\") returned (%s:%s:%d:...)\n",
+			    "HTAA_getGid: getgrnam",
+			    current_prot->gid_name,
+			    gr->gr_name, gr->gr_passwd, gr->gr_gid);
 #endif
 		return gr->gr_gid;
 	    }
@@ -203,8 +200,8 @@ PUBLIC int HTAA_getGid NOARGS
     ** Ok, then let's get gid for nogroup.
     */
     if (NULL != (gr = getgrnam("nogroup"))) {
-	if (TRACE) fprintf(stderr, "HTAA_getGid: Gid for `nogroup' is %d\n",
-			   gr->gr_gid);
+	CTRACE(tfp, "HTAA_getGid: Gid for `nogroup' is %d\n",
+		    gr->gr_gid);
 	return gr->gr_gid;
     }
     /*
@@ -294,15 +291,16 @@ PRIVATE void HTAA_parseProtFile ARGS2(HTAAProt *, prot,
 			    if (!prot->valid_schemes)
 				prot->valid_schemes = HTList_new();
 			    HTList_addObject(prot->valid_schemes,(void*)scheme);
-			    if (TRACE) fprintf(stderr, "%s %s `%s'\n",
-					       "HTAA_parseProtFile: valid",
-					       "authentication scheme:",
-					       HTAAScheme_name(scheme));
+			    CTRACE(tfp, "%s %s `%s'\n",
+				        "HTAA_parseProtFile: valid",
+				        "authentication scheme:",
+				        HTAAScheme_name(scheme));
+			} else {
+			    CTRACE(tfp, "%s %s `%s'\n",
+					"HTAA_parseProtFile: unknown",
+					"authentication scheme:",
+					HTlex_buffer);
 			}
-			else if (TRACE) fprintf(stderr, "%s %s `%s'\n",
-						"HTAA_parseProtFile: unknown",
-						"authentication scheme:",
-						HTlex_buffer);
 			
 			if (LEX_ITEM_SEP != (lex_item = lex(fp)))
 			    break;
@@ -322,10 +320,10 @@ PRIVATE void HTAA_parseProtFile ARGS2(HTAAProt *, prot,
 		    lex_item=LEX_REC_SEP; /*groupdef parser read this already*/
 		    if (TRACE) {
 			if (prot->mask_group) {
-			    fprintf(stderr,
+			    fprintf(tfp,
 				    "HTAA_parseProtFile: Mask group:\n");
 			    HTAA_printGroupDef(prot->mask_group);
-			} else fprintf(stderr, "HTAA_parseProtFile: %s\n",
+			} else fprintf(tfp, "HTAA_parseProtFile: %s\n",
 				       "Mask group syntax error");
 		    }
 		} /* if "Mask" */
@@ -337,20 +335,19 @@ PRIVATE void HTAA_parseProtFile ARGS2(HTAAProt *, prot,
 			    prot->values = HTAssocList_new();
 			HTAssocList_add(prot->values, fieldname, HTlex_buffer);
 			lex_item = lex(fp);  /* Read record separator */
-			if (TRACE) fprintf(stderr, 
-					   "%s `%s' bound to value `%s'\n",
-					   "HTAA_parseProtFile: Name",
-					   fieldname, HTlex_buffer);
+			CTRACE(tfp, "%s `%s' bound to value `%s'\n",
+				    "HTAA_parseProtFile: Name",
+				    fieldname, HTlex_buffer);
 		    }
 		} /* else name-value pair */
 
 	    } /* if valid field */
 
 	    if (lex_item != LEX_EOF  &&  lex_item != LEX_REC_SEP) {
-		if (TRACE) fprintf(stderr, "%s %s %d (that line ignored)\n",
-				   "HTAA_parseProtFile: Syntax error",
-				   "in protection setup file at line",
-				   HTlex_line);
+		CTRACE(tfp, "%s %s %d (that line ignored)\n",
+			    "HTAA_parseProtFile: Syntax error",
+			    "in protection setup file at line",
+			    HTlex_line);
 		do {
 		    lex_item = lex(fp);
 		} while (lex_item != LEX_EOF && lex_item != LEX_REC_SEP);
@@ -405,12 +402,11 @@ PRIVATE HTAAProt *HTAAProt_new ARGS3(CONST char *,	cur_docname,
     }
     if (cache_item) {
 	prot = cache_item->prot;
-	if (TRACE) fprintf(stderr, "%s `%s' already in cache\n",
-			   "HTAAProt_new: Protection file", prot_filename);
+	CTRACE(tfp, "%s `%s' already in cache\n",
+		    "HTAAProt_new: Protection file", prot_filename);
     } else {
-	if (TRACE) fprintf(stderr,
-			   "HTAAProt_new: Loading protection file `%s'\n",
-			   prot_filename);
+	CTRACE(tfp, "HTAAProt_new: Loading protection file `%s'\n",
+		    prot_filename);
 
 	if (!(prot = (HTAAProt*)calloc(1, sizeof(HTAAProt))))
 	    outofmem(__FILE__, "HTAAProt_new");
@@ -433,10 +429,11 @@ PRIVATE HTAAProt *HTAAProt_new ARGS3(CONST char *,	cur_docname,
 	    cache_item->prot_filename = NULL;
 	    StrAllocCopy(cache_item->prot_filename, prot_filename);
 	    HTList_addObject(prot_cache, (void*)cache_item);
+	} else {
+	    CTRACE(tfp, "HTAAProt_new: %s `%s'\n",
+			"Unable to open protection setup file",
+			(prot_filename ? prot_filename : "(null)"));
 	}
-	else if (TRACE) fprintf(stderr, "HTAAProt_new: %s `%s'\n",
-				"Unable to open protection setup file",
-				(prot_filename ? prot_filename : "(null)"));
     }
 
     if (cur_docname)
@@ -475,9 +472,9 @@ PUBLIC void HTAA_setDefaultProtection ARGS3(CONST char *,	cur_docname,
     if (prot_filename) {
 	default_prot = HTAAProt_new(cur_docname, prot_filename, ids);
     } else {
-	if (TRACE) fprintf(stderr, "%s %s\n",
-			   "HTAA_setDefaultProtection: ERROR: Protection file",
-			   "not specified (obligatory for DefProt rule)!!\n");
+	CTRACE(tfp, "%s %s\n",
+		    "HTAA_setDefaultProtection: ERROR: Protection file",
+		    "not specified (obligatory for DefProt rule)!!\n");
     }
 }
 
@@ -513,15 +510,15 @@ PUBLIC void HTAA_setCurrentProtection ARGS3(CONST char *,	cur_docname,
 	if (default_prot) {
 	    current_prot = default_prot;
 	    HTAA_setIds(current_prot, ids);
-	    if (TRACE) fprintf(stderr, "%s %s %s\n",
-			       "HTAA_setCurrentProtection: Protection file",
-			       "not specified for Protect rule",
-			       "-- using default protection");
+	    CTRACE(tfp, "%s %s %s\n",
+		        "HTAA_setCurrentProtection: Protection file",
+		        "not specified for Protect rule",
+		        "-- using default protection");
 	} else {
-	    if (TRACE) fprintf(stderr, "%s %s %s\n",
-			       "HTAA_setCurrentProtection: ERROR: Protection",
-			       "file not specified for Protect rule, and",
-			       "default protection is not set!!");
+	    CTRACE(tfp, "%s %s %s\n",
+		        "HTAA_setCurrentProtection: ERROR: Protection",
+		        "file not specified for Protect rule, and",
+		        "default protection is not set!!");
 	}
     }
 }
diff --git a/WWW/Library/Implementation/HTAAServ.c b/WWW/Library/Implementation/HTAAServ.c
index 98779830..5f61cb76 100644
--- a/WWW/Library/Implementation/HTAAServ.c
+++ b/WWW/Library/Implementation/HTAAServ.c
@@ -229,14 +229,12 @@ PRIVATE HTAAFailReasonType check_authorization ARGS4(CONST char *,  pathname,
     htaa_user = NULL;
 
     if (!pathname) {
-	if (TRACE)
-	    fprintf(stderr, "HTAA_checkAuthorization: Forbidden by rule\n");
+	CTRACE(tfp, "HTAA_checkAuthorization: Forbidden by rule\n");
 	return HTAA_BY_RULE;
     }
-    if (TRACE)
-	fprintf(stderr, "%s `%s' %s %s\n",
-			"HTAA_checkAuthorization: translated path:",
-			pathname, "method:", HTAAMethod_name(method));
+    CTRACE(tfp, "%s `%s' %s %s\n",
+		"HTAA_checkAuthorization: translated path:",
+		pathname, "method:", HTAAMethod_name(method));
 
     /*
     ** Get protection setting (set up by callbacks from rule system)
@@ -263,10 +261,9 @@ PRIVATE HTAAFailReasonType check_authorization ARGS4(CONST char *,  pathname,
 		    htaa_user = HTAA_authenticate(scheme,
 						  scheme_specifics,
 						  prot);
-		    if (TRACE)
-			fprintf(stderr, "Authentication returned: %s\n",
-					(htaa_user ? htaa_user->username
-						   : "NOT-AUTHENTICATED"));
+		    CTRACE(tfp, "Authentication returned: %s\n",
+				(htaa_user ? htaa_user->username
+					   : "NOT-AUTHENTICATED"));
 		}
 		HTAA_resolveGroupReferences(prot->mask_group, group_def_list);
 		reason = HTAA_userAndInetInGroup(prot->mask_group,
@@ -274,14 +271,13 @@ PRIVATE HTAAFailReasonType check_authorization ARGS4(CONST char *,  pathname,
 						  ? htaa_user->username : "",
 						 HTClientHost,
 						 NULL);
-		if (TRACE) {
-		    if (reason != HTAA_OK)
-			fprintf(stderr, "%s %s %s %s\n",
+		if (reason != HTAA_OK) {
+		    CTRACE(tfp, "%s %s %s %s\n",
 				"HTAA_checkAuthorization: access denied",
 				"by mask (no ACL, only Protect rule)",
 				"host", HTClientHost);
-		    else
-			fprintf(stderr, "%s %s %s %s\n",
+		} else {
+		    CTRACE(tfp, "%s %s %s %s\n",
 				"HTAA_checkAuthorization: request from",
 				HTClientHost,
 				"accepted by only mask match (no ACL, only",
@@ -290,17 +286,15 @@ PRIVATE HTAAFailReasonType check_authorization ARGS4(CONST char *,  pathname,
 		return reason;
 	    }
 	    else {	/* 403 Forbidden */
-		if (TRACE)
-		    fprintf(stderr, "%s %s\n",
-				    "HTAA_checkAuthorization: Protected, but",
-				    "no mask group nor ACL -- forbidden");
+		CTRACE(tfp, "%s %s\n",
+			    "HTAA_checkAuthorization: Protected, but",
+			    "no mask group nor ACL -- forbidden");
 		return HTAA_NO_ACL;
 	    }
 	}
 	else { /* No protect rule and no ACL => OK 200 */
-	    if (TRACE)
-		fprintf(stderr, "HTAA_checkAuthorization: %s\n",
-				"no protect rule nor ACL -- ok\n");
+	    CTRACE(tfp, "HTAA_checkAuthorization: %s\n",
+			"no protect rule nor ACL -- ok\n");
 	    return HTAA_OK;
 	}
     }
@@ -309,15 +303,13 @@ PRIVATE HTAAFailReasonType check_authorization ARGS4(CONST char *,  pathname,
     ** Now we know that ACL exists
     */
     if (!prot) {		/* Not protected by "protect" rule */
-	if (TRACE)
-	    fprintf(stderr, "HTAA_checkAuthorization: default protection\n");
+	CTRACE(tfp, "HTAA_checkAuthorization: default protection\n");
 	prot = HTAA_getDefaultProtection(); /* Also sets current protection */
 
 	if (!prot) {		/* @@ Default protection not set ?? */
-	    if (TRACE)
-		fprintf(stderr, "%s %s\n",
-				"HTAA_checkAuthorization: default protection",
-				"not set (internal server error)!!");
+	    CTRACE(tfp, "%s %s\n",
+			"HTAA_checkAuthorization: default protection",
+			"not set (internal server error)!!");
 	    return HTAA_SETUP_ERROR;
 	}
     }
@@ -337,10 +329,9 @@ PRIVATE HTAAFailReasonType check_authorization ARGS4(CONST char *,  pathname,
 	    htaa_user = HTAA_authenticate(scheme,
 					  scheme_specifics,
 					  prot);
-	    if (TRACE)
-		fprintf(stderr, "Authentication returned: %s\n",
-				(htaa_user
-				 ? htaa_user->username : "NOT-AUTHENTICATED"));
+	    CTRACE(tfp, "Authentication returned: %s\n",
+			(htaa_user
+			 ? htaa_user->username : "NOT-AUTHENTICATED"));
 	}
 	/*
 	** Check mask group
@@ -352,20 +343,18 @@ PRIVATE HTAAFailReasonType check_authorization ARGS4(CONST char *,  pathname,
 					   HTClientHost,
 					   NULL);
 	    if (reason != HTAA_OK) {
-		if (TRACE)
-		    fprintf(stderr, "%s %s %s\n",
-				    "HTAA_checkAuthorization: access denied",
-				    "by mask, host:", HTClientHost);
+		CTRACE(tfp, "%s %s %s\n",
+			    "HTAA_checkAuthorization: access denied",
+			    "by mask, host:", HTClientHost);
 		return reason;
 	    }
 	    else {
-		if (TRACE)
-		    fprintf(stderr, "%s %s %s %s %s\n",
-				    "HTAA_checkAuthorization: request from",
-				    HTClientHost,
-				    "accepted by just mask group match",
-				    "(no ACL, only Protect rule, and only",
-				    "mask enabled)");
+		CTRACE(tfp, "%s %s %s %s %s\n",
+			    "HTAA_checkAuthorization: request from",
+			    HTClientHost,
+			    "accepted by just mask group match",
+			    "(no ACL, only Protect rule, and only",
+			    "mask enabled)");
 		/* And continue authorization checking */
 	    }
 	}
@@ -376,9 +365,8 @@ PRIVATE HTAAFailReasonType check_authorization ARGS4(CONST char *,  pathname,
 	*/
 	allowed_groups = HTAA_getAclEntry(acl_file, pathname, method);
 	if (!allowed_groups) {
-	    if (TRACE)
-		fprintf(stderr, "%s `%s' %s\n",
-				"No entry for file", pathname, "in ACL");
+	    CTRACE(tfp, "%s `%s' %s\n",
+			"No entry for file", pathname, "in ACL");
 	    HTAA_closeAcl(acl_file);
 	    return HTAA_NO_ENTRY;  /* Forbidden -- no entry in the ACL */
 	}
@@ -458,9 +446,8 @@ PUBLIC int HTAA_checkAuthorization ARGS4(CONST char *,	url,
     ** be a security hole.
     */
     if (strstr(local_copy, "/../")) {
-	if (TRACE)
-	    fprintf(stderr, "HTAA_checkAuthorization: %s (`%s')\n",
-			    "Illegal attempt to use /../", url);
+	CTRACE(tfp, "HTAA_checkAuthorization: %s (`%s')\n",
+		    "Illegal attempt to use /../", url);
 	HTAAFailReason = HTAA_DOTDOT;
     }
     else {
@@ -482,8 +469,7 @@ PUBLIC int HTAA_checkAuthorization ARGS4(CONST char *,	url,
 	}
 
 	if (!pathname) {		/* Forbidden by rule */
-	    if (TRACE)
-		fprintf(stderr, "HTAA_checkAuthorization: Forbidden by rule\n");
+	    CTRACE(tfp, "HTAA_checkAuthorization: Forbidden by rule\n");
 	    HTAAFailReason = HTAA_BY_RULE;
 	}
 	else if (HTAAFailReason != HTAA_HTBIN) {
@@ -500,9 +486,7 @@ PUBLIC int HTAA_checkAuthorization ARGS4(CONST char *,	url,
 	    }
 	    else {  /* Not local access */
 		HTAAFailReason = HTAA_OK_GATEWAY;
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTAA_checkAuthorization: %s (%s access)\n",
+		CTRACE(tfp, "HTAA_checkAuthorization: %s (%s access)\n",
 			    "Gatewaying -- skipping authorization check",
 			    acc_method);
 	    }
@@ -521,15 +505,14 @@ PUBLIC int HTAA_checkAuthorization ARGS4(CONST char *,	url,
 		htaa_user && htaa_user->username
 		? htaa_user->username : "");
 	fflush(htaa_logfile);	/* Actually update it on disk */
-	if (TRACE)
-	    fprintf(stderr, "Log: %24.24s %s %s %s %s %s\n",
-			    ctime(&theTime),
-			    HTClientHost ? HTClientHost : "local",
-			    method_name,
-			    url,
-			    status_name(HTAAFailReason),
-			    htaa_user && htaa_user->username
-			    ? htaa_user->username : "");
+	CTRACE(tfp, "Log: %24.24s %s %s %s %s %s\n",
+		    ctime(&theTime),
+		    HTClientHost ? HTClientHost : "local",
+		    method_name,
+		    url,
+		    status_name(HTAAFailReason),
+		    htaa_user && htaa_user->username
+		    ? htaa_user->username : "");
     }
 
     switch (HTAAFailReason) {
@@ -636,15 +619,14 @@ PUBLIC char *HTAA_composeAuthHeaders NOARGS
     HTAAProt *prot = HTAA_getCurrentProtection();
 
     if (!prot) {
-	if (TRACE)
-	    fprintf(stderr, "%s %s\n",
-			    "HTAA_composeAuthHeaders: Document not protected",
-			    "-- why was this function called??");
+	CTRACE(tfp, "%s %s\n",
+		    "HTAA_composeAuthHeaders: Document not protected",
+		    "-- why was this function called??");
 	return NULL;
+    } else {
+	CTRACE(tfp, "HTAA_composeAuthHeaders: for file `%s'\n",
+		    prot->filename);
     }
-    else if (TRACE)
-	fprintf(stderr, "HTAA_composeAuthHeaders: for file `%s'\n",
-			prot->filename);
 
     FREE(result);	/* From previous call */
     if (!(result = (char*)malloc(4096)))	/* @@ */
@@ -663,9 +645,10 @@ PUBLIC char *HTAA_composeAuthHeaders NOARGS
 		}
 		strcat(result, "\r\n");
 	    } /* scheme name found */
-	    else if (TRACE)
-		fprintf(stderr, "HTAA_composeAuthHeaders: %s %d\n",
-				"No name found for scheme number", scheme);
+	    else {
+		CTRACE(tfp, "HTAA_composeAuthHeaders: %s %d\n",
+			    "No name found for scheme number", scheme);
+	    }
 	} /* scheme valid for requested document */
     } /* for every scheme */
 
diff --git a/WWW/Library/Implementation/HTAAUtil.c b/WWW/Library/Implementation/HTAAUtil.c
index b10dcde0..7857ec52 100644
--- a/WWW/Library/Implementation/HTAAUtil.c
+++ b/WWW/Library/Implementation/HTAAUtil.c
@@ -217,8 +217,7 @@ PUBLIC BOOL HTAAMethod_inList ARGS2(HTAAMethod, method,
     char *item;
 
     while (NULL != (item = (char*)HTList_nextObject(cur))) {
-	if (TRACE)
-	    fprintf(stderr, " %s", item);
+	CTRACE(tfp, " %s", item);
 	if (method == HTAAMethod_enum(item))
 	    return YES;
     }
@@ -367,9 +366,8 @@ PUBLIC char *HTAA_makeProtectionTemplate ARGS1(CONST char *, docname)
     else
 	StrAllocCopy(template, "*");
 
-    if (TRACE)
-	fprintf(stderr, "make_template: made template `%s' for file `%s'\n",
-			template, docname);
+    CTRACE(tfp, "make_template: made template `%s' for file `%s'\n",
+		template, docname);
 
     return template;
 }
@@ -549,10 +547,9 @@ PUBLIC char *HTAA_getUnfoldedLine NOARGS
     BOOL peek_for_folding = NO;
 
     if (in_soc < 0) {
-	if (TRACE)
-	    fprintf(stderr, "%s %s\n",
-			    "HTAA_getUnfoldedLine: buffer not initialized",
-			    "with function HTAA_setupReader()");
+	CTRACE(tfp, "%s %s\n",
+		    "HTAA_getUnfoldedLine: buffer not initialized",
+		    "with function HTAA_setupReader()");
 	return NULL;
     }
 
diff --git a/WWW/Library/Implementation/HTACL.c b/WWW/Library/Implementation/HTACL.c
index fe4e02e4..2dbc79d6 100644
--- a/WWW/Library/Implementation/HTACL.c
+++ b/WWW/Library/Implementation/HTACL.c
@@ -180,14 +180,10 @@ PUBLIC GroupDef *HTAA_getAclEntry ARGS3(FILE *, 	acl_file,
 #endif /* not VMS */
 	    HTList *methods = HTList_new();
 	    HTAAFile_readList(acl_file, methods, MAX_METHODNAME_LEN);
-	    if (TRACE) {
-		fprintf(stderr,
-			"Filename '%s' matched template '%s', allowed methods:",
+	    CTRACE(tfp, "Filename '%s' matched template '%s', allowed methods:",
 			filename, buf);
-	    }
 	    if (HTAAMethod_inList(method, methods)) {	/* right method? */
-		if (TRACE)
-		    fprintf(stderr, " METHOD OK\n");
+		CTRACE(tfp, " METHOD OK\n");
 		HTList_delete(methods);
 		methods = NULL;
 		FREE(buf);
@@ -197,18 +193,15 @@ PUBLIC GroupDef *HTAA_getAclEntry ARGS3(FILE *, 	acl_file,
 		** separator so we don't call HTAAFile_nextRec().
 		*/
 		return group_def;
-	    } else if (TRACE) {
-		fprintf(stderr, " METHOD NOT FOUND\n");
+	    } else {
+		CTRACE(tfp, " METHOD NOT FOUND\n");
 	    }
 	    HTList_delete(methods);
 	    methods = NULL;
 	}	/* if template match */
 	else {
-	    if (TRACE) {
-		fprintf(stderr,
-			"Filename '%s' didn't match template '%s'\n",
+	    CTRACE(tfp, "Filename '%s' didn't match template '%s'\n",
 			filename, buf);
-	    }
 	}
 
 	HTAAFile_nextRec(acl_file);
@@ -218,4 +211,3 @@ PUBLIC GroupDef *HTAA_getAclEntry ARGS3(FILE *, 	acl_file,
     return NULL;	/* No entry for requested file */
 			/* (or an empty entry).        */
 }
-
diff --git a/WWW/Library/Implementation/HTAccess.c b/WWW/Library/Implementation/HTAccess.c
index df7f99c2..90d446d9 100644
--- a/WWW/Library/Implementation/HTAccess.c
+++ b/WWW/Library/Implementation/HTAccess.c
@@ -352,8 +352,7 @@ PRIVATE int get_physical ARGS2(
     }
     if (anchor->isISMAPScript == TRUE) {
 	StrAllocCat(physical, "?0,0");
-	if (TRACE)
-	    fprintf(stderr, "HTAccess: Appending '?0,0' coordinate pair.\n");
+	CTRACE(tfp, "HTAccess: Appending '?0,0' coordinate pair.\n");
     }
     HTAnchor_setPhysical(anchor, physical);
     FREE(physical);			/* free our copy */
@@ -361,8 +360,7 @@ PRIVATE int get_physical ARGS2(
     if (anchor->isISMAPScript == TRUE) {
 	StrAllocCopy(physical, addr);
 	StrAllocCat(physical, "?0,0");
-	if (TRACE)
-	    fprintf(stderr, "HTAccess: Appending '?0,0' coordinate pair.\n");
+	CTRACE(tfp, "HTAccess: Appending '?0,0' coordinate pair.\n");
 	HTAnchor_setPhysical(anchor, physical);
 	FREE(physical); 		/* free our copy */
     } else {
@@ -451,10 +449,10 @@ PRIVATE int get_physical ARGS2(
 	proxy = (char *)getenv(gateway_parameter);
 	FREE(gateway_parameter);
 
-	if (TRACE && gateway)
-	    fprintf(stderr, "Gateway found: %s\n", gateway);
-	if (TRACE && proxy)
-	    fprintf(stderr, "proxy server found: %s\n", proxy);
+	if (gateway)
+	    CTRACE(tfp, "Gateway found: %s\n", gateway);
+	if (proxy)
+	    CTRACE(tfp, "proxy server found: %s\n", proxy);
 
 	/*
 	**  Proxy servers have precedence over gateway servers.
@@ -667,8 +665,7 @@ PRIVATE BOOL HTLoadDocument ARGS4(
     BOOL ForcingNoCache = LYforce_no_cache;
     static int redirection_attempts = 0;
 
-    if (TRACE)
-	fprintf (stderr, "HTAccess: loading document %s\n", address_to_load);
+    CTRACE (tfp, "HTAccess: loading document %s\n", address_to_load);
 
     /*
     **	Free use_this_url_instead and reset permanent_redirection
@@ -724,11 +721,9 @@ PRIVATE BOOL HTLoadDocument ARGS4(
 	       !strncmp(cp, "Location=", 9)) {
 	    DocAddress NewDoc;
 
-	    if (TRACE) {
-		fprintf (stderr, "HTAccess: '%s' is a redirection URL.\n",
-				  anchor->address);
-		fprintf (stderr, "HTAccess: Redirecting to '%s'\n", cp+9);
-	    }
+	    CTRACE (tfp, "HTAccess: '%s' is a redirection URL.\n",
+			  anchor->address);
+	    CTRACE (tfp, "HTAccess: Redirecting to '%s'\n", cp+9);
 
 	    /*
 	    **	Don't exceed the redirection_attempts limit. - FM
@@ -826,8 +821,7 @@ PRIVATE BOOL HTLoadDocument ARGS4(
 	     strncmp(full_address, "LYNXIMGMAP:", 11)))
 #endif /* TRACK_INTERNAL_LINKS */
 	{
-	    if (TRACE)
-		fprintf(stderr, "HTAccess: Document already in memory.\n");
+	    CTRACE(tfp, "HTAccess: Document already in memory.\n");
 	    HText_select(text);
 
 #ifdef DIRED_SUPPORT
@@ -844,9 +838,7 @@ PRIVATE BOOL HTLoadDocument ARGS4(
 	    reloading = TRUE;
 #endif
 	    ForcingNoCache = YES;
-	    if (TRACE) {
-		fprintf(stderr, "HTAccess: Auto-reloading document.\n");
-	    }
+	    CTRACE(tfp, "HTAccess: Auto-reloading document.\n");
 	}
     }
 
@@ -861,9 +853,7 @@ PRIVATE BOOL HTLoadDocument ARGS4(
 	FREE(anchor->title);
     }
     status = HTLoad(address_to_load, anchor, format_out, sink);
-    if (TRACE) {
-	fprintf(stderr, "HTAccess:  status=%d\n", status);
-    }
+    CTRACE(tfp, "HTAccess:  status=%d\n", status);
 
     /*
     **	Log the access if necessary.
@@ -877,8 +867,7 @@ PRIVATE BOOL HTLoadDocument ARGS4(
 		status < 0 ? "FAIL" : "GET",
 		full_address);
 	fflush(HTlogfile);	/* Actually update it on disk */
-	if (TRACE)
-	    fprintf(stderr, "Log: %24.24s %s %s %s\n",
+	CTRACE(tfp, "Log: %24.24s %s %s %s\n",
 		    ctime(&theTime),
 		    HTClientHost ? HTClientHost : "local",
 		    status < 0 ? "FAIL" : "GET",
@@ -907,12 +896,10 @@ PRIVATE BOOL HTLoadDocument ARGS4(
 	**  in LYGetFile.c when the status is HT_REDIRECTING.  This may
 	**  seem bizarre, but it works like a charm! - FM
 	*/
-	if (TRACE) {
-	    fprintf(stderr, "HTAccess: '%s' is a redirection URL.\n",
-			    address_to_load);
-	    fprintf(stderr, "HTAccess: Redirecting to '%s'\n",
-			     redirecting_url);
-	}
+	CTRACE(tfp, "HTAccess: '%s' is a redirection URL.\n",
+		    address_to_load);
+	CTRACE(tfp, "HTAccess: Redirecting to '%s'\n",
+		     redirecting_url);
 	/*
 	**  Prevent circular references.
 	*/
@@ -952,46 +939,32 @@ PRIVATE BOOL HTLoadDocument ARGS4(
     permanent_redirection = FALSE;
 
     if (status == HT_LOADED) {
-	if (TRACE) {
-	    fprintf(stderr, "HTAccess: `%s' has been accessed.\n",
-	    full_address);
-	}
+	CTRACE(tfp, "HTAccess: `%s' has been accessed.\n",
+		    full_address);
 	return YES;
     }
     if (status == HT_PARTIAL_CONTENT) {
 	HTAlert("Loading incomplete.");
-	if (TRACE) {
-	    fprintf(stderr, "HTAccess: `%s' has been accessed, partial content.\n",
-	    full_address);
-	}
+	CTRACE(tfp, "HTAccess: `%s' has been accessed, partial content.\n",
+		    full_address);
 	return YES;
     }
 
     if (status == HT_NO_DATA) {
-	if (TRACE) {
-	    fprintf(stderr,
-	    "HTAccess: `%s' has been accessed, No data left.\n",
-	    full_address);
-	}
+	CTRACE(tfp, "HTAccess: `%s' has been accessed, No data left.\n",
+		    full_address);
 	return NO;
     }
 
     if (status == HT_NOT_LOADED) {
-	if (TRACE) {
-	    fprintf(stderr,
-	    "HTAccess: `%s' has been accessed, No data loaded.\n",
-	    full_address);
-	}
+	CTRACE(tfp, "HTAccess: `%s' has been accessed, No data loaded.\n",
+		    full_address);
 	return NO;
     }
 
     if (status == HT_INTERRUPTED) {
-	if (TRACE) {
-	    fprintf(stderr,
-	    "HTAccess: `%s' has been accessed, transfer interrupted.\n",
-	    full_address);
-	}
-/*	_HTProgress("Data transfer interrupted."); */
+	CTRACE(tfp, "HTAccess: `%s' has been accessed, transfer interrupted.\n",
+		    full_address);
 	return NO;
     }
 
@@ -1002,8 +975,7 @@ PRIVATE BOOL HTLoadDocument ARGS4(
 	StrAllocCat(temp, "'");
 	_HTProgress(temp);
 	FREE(temp);
-	if (TRACE) fprintf(stderr,
-		"HTAccess: Can't access `%s'\n", full_address);
+	CTRACE(tfp, "HTAccess: Can't access `%s'\n", full_address);
 	HTLoadError(sink, 500, "Unable to access document.");
 	return NO;
     }
@@ -1012,11 +984,11 @@ PRIVATE BOOL HTLoadDocument ARGS4(
     **	If you get this, then please find which routine is returning
     **	a positive unrecognised error code!
     */
-    fprintf(stderr,
+    fprintf(tfp,
  "**** HTAccess: socket or file number returned by obsolete load routine!\n");
-    fprintf(stderr,
+    fprintf(tfp,
  "**** HTAccess: Internal software error. Please mail lynx_dev@sig.net!\n");
-    fprintf(stderr, "**** HTAccess: Status returned was: %d\n",status);
+    fprintf(tfp, "**** HTAccess: Status returned was: %d\n",status);
     exit(-1);
 
 } /* HTLoadDocument */
@@ -1343,9 +1315,7 @@ PUBLIC HTParentAnchor * HTHomeAnchor NOARGS
 	if (fp) {
 	    fclose(fp);
 	} else {
-	    if (TRACE)
-		fprintf(stderr,
-			"HTBrowse: No local home document ~/%s or %s\n",
+	    CTRACE(tfp, "HTBrowse: No local home document ~/%s or %s\n",
 			PERSONAL_DEFAULT, LOCAL_DEFAULT_FILE);
 	    FREE(my_home_document);
 	}
@@ -1357,9 +1327,7 @@ PUBLIC HTParentAnchor * HTHomeAnchor NOARGS
 		  "file:",
 		  PARSE_ACCESS|PARSE_HOST|PARSE_PATH|PARSE_PUNCTUATION);
     if (my_home_document) {
-	if (TRACE)
-	    fprintf(stderr,
-		    "HTAccess: Using custom home page %s i.e. address %s\n",
+	CTRACE(tfp, "HTAccess: Using custom home page %s i.e. address %s\n",
 		    my_home_document, ref);
 	FREE(my_home_document);
     }
diff --git a/WWW/Library/Implementation/HTAnchor.c b/WWW/Library/Implementation/HTAnchor.c
index 9c8b10cd..14e258f6 100644
--- a/WWW/Library/Implementation/HTAnchor.c
+++ b/WWW/Library/Implementation/HTAnchor.c
@@ -172,8 +172,7 @@ PUBLIC HTChildAnchor * HTAnchor_findChild ARGS2(
     HTList *kids;
 
     if (!parent) {
-	if (TRACE)
-	    fprintf(stderr, "HTAnchor_findChild called with NULL parent.\n");
+	CTRACE(tfp, "HTAnchor_findChild called with NULL parent.\n");
 	return NULL;
     }
     if ((kids = parent->children) != 0) {
@@ -187,9 +186,7 @@ PUBLIC HTChildAnchor * HTAnchor_findChild ARGS2(
 #else
 		if (HTIdentical(child->tag, tag)) {  /* Case sensitive - FM */
 #endif /* CASE_INSENSITIVE_ANCHORS */
-		    if (TRACE)
-			fprintf(stderr,
-	      "Child anchor %p of parent %p with name `%s' already exists.\n",
+		    CTRACE(tfp, "Child anchor %p of parent %p with name `%s' already exists.\n",
 				(void *)child, (void *)parent, tag);
 		    return child;
 		}
@@ -200,9 +197,7 @@ PUBLIC HTChildAnchor * HTAnchor_findChild ARGS2(
     }
 
     child = HTChildAnchor_new();
-    if (TRACE)
-	fprintf(stderr,
-		"new Anchor %p named `%s' is child of %p\n",
+    CTRACE(tfp, "new Anchor %p named `%s' is child of %p\n",
 		(void *)child,
 		tag ? tag : (CONST char *)"",
 		(void *)parent); /* int for apollo */
@@ -228,8 +223,7 @@ PUBLIC HTChildAnchor * HTAnchor_findChildAndLink ARGS4(
 {
     HTChildAnchor * child = HTAnchor_findChild(parent, tag);
 
-    if (TRACE)
-	fprintf(stderr,"Entered HTAnchor_findChildAndLink\n");
+    CTRACE(tfp,"Entered HTAnchor_findChildAndLink\n");
 
     if (href && *href) {
 	char *relative_to = HTAnchor_address((HTAnchor *)parent);
@@ -306,8 +300,7 @@ PUBLIC HTAnchor * HTAnchor_findAddress ARGS1(
     /* Anchor tag specified ? */
     char *tag = HTParse(newdoc->address, "", PARSE_ANCHOR);
 
-    if (TRACE)
-	fprintf(stderr,"Entered HTAnchor_findAddress\n");
+    CTRACE(tfp,"Entered HTAnchor_findAddress\n");
 
     /*
     **	If the address represents a sub-anchor, we recursively load its
@@ -371,9 +364,7 @@ PUBLIC HTAnchor * HTAnchor_findAddress ARGS1(
 		foundAnchor->isHEAD == newdoc->isHEAD)
 #endif /* CASE_INSENSITIVE_ANCHORS */
 	    {
-		if (TRACE)
-		    fprintf(stderr,
-			    "Anchor %p with address `%s' already exists.\n",
+		CTRACE(tfp, "Anchor %p with address `%s' already exists.\n",
 			    (void *)foundAnchor, newdoc->address);
 		 return (HTAnchor *)foundAnchor;
 	     }
@@ -383,9 +374,7 @@ PUBLIC HTAnchor * HTAnchor_findAddress ARGS1(
 	**  Node not found: create new anchor.
 	*/
 	foundAnchor = HTParentAnchor_new();
-	if (TRACE)
-	    fprintf(stderr,
-		    "New anchor %p has hash %d and address `%s'\n",
+	CTRACE(tfp, "New anchor %p has hash %d and address `%s'\n",
 		    (void *)foundAnchor, hash, newdoc->address);
 	StrAllocCopy(foundAnchor->address, newdoc->address);
 	if (newdoc->post_data)
@@ -1041,9 +1030,7 @@ PUBLIC BOOL HTAnchor_link ARGS3(
 {
     if (!(source && destination))
 	return NO;  /* Can't link to/from non-existing anchor */
-    if (TRACE)
-	fprintf(stderr,
-		"Linking anchor %p to anchor %p\n", source, destination);
+    CTRACE(tfp, "Linking anchor %p to anchor %p\n", source, destination);
     if (!source->mainLink.dest) {
 	source->mainLink.dest = destination;
 	source->mainLink.type = type;
diff --git a/WWW/Library/Implementation/HTAssoc.c b/WWW/Library/Implementation/HTAssoc.c
index 0736a269..dff739be 100644
--- a/WWW/Library/Implementation/HTAssoc.c
+++ b/WWW/Library/Implementation/HTAssoc.c
@@ -66,8 +66,8 @@ PUBLIC void HTAssocList_add ARGS3(HTAssocList *,	alist,
 	if (value)
 	    StrAllocCopy(assoc->value, value);
 	HTList_addObject(alist, (void*)assoc);
-    } else if (TRACE) {
-        fprintf(stderr, "HTAssoc_add: ERROR: assoc list NULL!!\n");
+    } else {
+        CTRACE(tfp, "HTAssoc_add: ERROR: assoc list NULL!!\n");
     }
 }
 
diff --git a/WWW/Library/Implementation/HTAtom.c b/WWW/Library/Implementation/HTAtom.c
index e5aee433..1fd6d9c1 100644
--- a/WWW/Library/Implementation/HTAtom.c
+++ b/WWW/Library/Implementation/HTAtom.c
@@ -67,8 +67,7 @@ PUBLIC HTAtom * HTAtom_for ARGS1(CONST char *, string)
     */
     for (a = hash_table[hash]; a; a = a->next) {
 	if (0 == strcasecomp(a->name, string)) {
-    	    /* if (TRACE) fprintf(stderr,
-	    	"HTAtom: Old atom %p for `%s'\n", a, string); */
+    	    /* CTRACE(tfp, "HTAtom: Old atom %p for `%s'\n", a, string); */
 	    return a;				/* Found: return it */
 	}
     }
@@ -85,8 +84,7 @@ PUBLIC HTAtom * HTAtom_for ARGS1(CONST char *, string)
     a->next = hash_table[hash];		/* Put onto the head of list */
     hash_table[hash] = a;
 #ifdef NOT_DEFINED
-    if (TRACE)
-	fprintf(stderr, "HTAtom: New atom %p for `%s'\n", a, string);
+    CTRACE(tfp, "HTAtom: New atom %p for `%s'\n", a, string);
 #endif /* NOT_DEFINED */
     return a;
 }
diff --git a/WWW/Library/Implementation/HTAuth.c b/WWW/Library/Implementation/HTAuth.c
index b8b4d010..573a24b7 100644
--- a/WWW/Library/Implementation/HTAuth.c
+++ b/WWW/Library/Implementation/HTAuth.c
@@ -99,8 +99,7 @@ PRIVATE HTAAUser *decompose_auth_string ARGS2(char *,		authstring,
 */
     username = cleartext;
     if (!(password = strchr(cleartext, ':'))) {
-	if (TRACE)
-	    fprintf(stderr, "%s %s\n",
+	CTRACE(tfp, "%s %s\n",
 		    "decompose_auth_string: password field",
 		    "missing in authentication string.\n");
 	return NULL;
@@ -116,9 +115,9 @@ PRIVATE HTAAUser *decompose_auth_string ARGS2(char *,		authstring,
 	    (*(timestamp++)   ='\0'), !(browsers_key=strchr(timestamp,':')) ||
 	    (*(browsers_key++)='\0')) {
 
-	    if (TRACE) fprintf(stderr, "%s %s\n",
-			       "decompose_auth_string: Pubkey scheme",
-			       "fields missing in authentication string");
+	    CTRACE(tfp, "%s %s\n",
+		        "decompose_auth_string: Pubkey scheme",
+		        "fields missing in authentication string");
 	    return NULL;
 	}
     }
@@ -132,13 +131,12 @@ PRIVATE HTAAUser *decompose_auth_string ARGS2(char *,		authstring,
     user->timestamp  = timestamp;
     user->secret_key = browsers_key;
 
-    if (TRACE) {
-	if (scheme==HTAA_BASIC)
-	    fprintf(stderr, "decompose_auth_string: %s (%s,%s)\n",
+    if (scheme == HTAA_BASIC) {
+	CTRACE(tfp, "decompose_auth_string: %s (%s,%s)\n",
 		    "Basic scheme authentication string:",
 		    username, password);
-	else
-	    fprintf(stderr, "decompose_auth_string: %s (%s,%s,%s,%s,%s)\n",
+    } else {
+	CTRACE(tfp, "decompose_auth_string: %s (%s,%s,%s,%s,%s)\n",
 		    "Pubkey scheme authentication string:",
 		    username, password, i_net_adr, timestamp, browsers_key);
     }
diff --git a/WWW/Library/Implementation/HTFTP.c b/WWW/Library/Implementation/HTFTP.c
index 48d0aa36..38ceddd4 100644
--- a/WWW/Library/Implementation/HTFTP.c
+++ b/WWW/Library/Implementation/HTFTP.c
@@ -338,7 +338,7 @@ PRIVATE int close_connection ARGS1(
     connection * scan;
     int status = NETCLOSE(con->socket);
     if (TRACE) {
-	fprintf(stderr, "HTFTP: Closing control socket %d\n", con->socket);
+	CTRACE(tfp, "HTFTP: Closing control socket %d\n", con->socket);
 #ifdef UNIX
 	if (status != 0)
 	    perror("HTFTP:close_connection");
@@ -375,8 +375,7 @@ PRIVATE void help_message_cache_add ARGS1(
     else
 	StrAllocCopy(help_message_buffer, string);
 
-    if (TRACE)
-	fprintf(stderr,"Adding message to help cache: %s\n",string);
+    CTRACE(tfp,"Adding message to help cache: %s\n",string);
 }
 
 PRIVATE char *help_message_cache_non_empty NOARGS
@@ -417,14 +416,12 @@ PRIVATE int response ARGS1(
     int status;
 
     if (!control) {
-	  if (TRACE)
-	      fprintf(stderr, "HTFTP: No control connection set up!!\n");
-	  return -99;
+	CTRACE(tfp, "HTFTP: No control connection set up!!\n");
+	return -99;
     }
 
     if (cmd) {
-	if (TRACE)
-	    fprintf(stderr, "  Tx: %s", cmd);
+	CTRACE(tfp, "  Tx: %s", cmd);
 #ifdef NOT_ASCII
 	{
 	    char * p;
@@ -435,9 +432,7 @@ PRIVATE int response ARGS1(
 #endif /* NOT_ASCII */
 	status = NETWRITE(control->socket, cmd, (int)strlen(cmd));
 	if (status < 0) {
-	    if (TRACE)
-		fprintf(stderr,
-			"HTFTP: Error %d sending command: closing socket %d\n",
+	    CTRACE(tfp, "HTFTP: Error %d sending command: closing socket %d\n",
 			status, control->socket);
 	    close_connection(control);
 	    return status;
@@ -452,19 +447,15 @@ PRIVATE int response ARGS1(
 
 		char continuation;
 
-		if (interrupted_in_htgetcharacter)
-		  {
-		    if (TRACE)
-		      fprintf (stderr,
-			"HTFTP: Interrupted in HTGetCharacter, apparently.\n");
+		if (interrupted_in_htgetcharacter) {
+		    CTRACE (tfp, "HTFTP: Interrupted in HTGetCharacter, apparently.\n");
 		    NETCLOSE (control->socket);
 		    control->socket = -1;
 		    return HT_INTERRUPTED;
-		  }
+		}
 
 		*p = '\0';			/* Terminate the string */
-		if (TRACE)
-		    fprintf(stderr, "    Rx: %s", response_text);
+		CTRACE(tfp, "    Rx: %s", response_text);
 
 		/* Check for login or help messages */
 		if (!strncmp(response_text,"230-",4) ||
@@ -484,19 +475,15 @@ PRIVATE int response ARGS1(
 		break;
 	    } /* if end of line */
 
-	    if (interrupted_in_htgetcharacter)
-	       {
-		    if (TRACE)
-		      fprintf (stderr,
-			"HTFTP: Interrupted in HTGetCharacter, apparently.\n");
-		    NETCLOSE (control->socket);
-		    control->socket = -1;
-		    return HT_INTERRUPTED;
-	       }
+	    if (interrupted_in_htgetcharacter) {
+		CTRACE (tfp, "HTFTP: Interrupted in HTGetCharacter, apparently.\n");
+		NETCLOSE (control->socket);
+		control->socket = -1;
+		return HT_INTERRUPTED;
+	    }
 
 	    if (*(p-1) == (char) EOF) {
-		if (TRACE)
-		    fprintf(stderr, "Error on rx: closing socket %d\n",
+		CTRACE(tfp, "Error on rx: closing socket %d\n",
 			    control->socket);
 		strcpy(response_text, "000 *** TCP read error on response\n");
 		close_connection(control);
@@ -507,8 +494,7 @@ PRIVATE int response ARGS1(
     } while (continuation_response != -1);
 
     if (result == 421) {
-	if (TRACE)
-	    fprintf(stderr, "HTFTP: They close so we close socket %d\n",
+	CTRACE(tfp, "HTFTP: They close so we close socket %d\n",
 		    control->socket);
 	close_connection(control);
 	return -1;
@@ -564,8 +550,7 @@ PRIVATE void get_ftp_pwd ARGS2(
 	if (*ServerType == TCPC_SERVER) {
 	    *ServerType = ((response_text[5] == '/') ?
 					  NCSA_SERVER : TCPC_SERVER);
-	     if (TRACE)
-		 fprintf(stderr, "HTFTP: Treating as %s server.\n",
+	    CTRACE(tfp, "HTFTP: Treating as %s server.\n",
 			 ((*ServerType == NCSA_SERVER) ?
 						 "NCSA" : "TCPC"));
 	} else if (response_text[5] == '/') {
@@ -574,25 +559,21 @@ PRIVATE void get_ftp_pwd ARGS2(
 	     */
 	    if (set_mac_binary(*ServerType)) {
 		*ServerType = NCSA_SERVER;
-		if (TRACE)
-		    fprintf(stderr, "HTFTP: Treating as NCSA server.\n");
+		CTRACE(tfp, "HTFTP: Treating as NCSA server.\n");
 	    } else {
 		 *ServerType = UNIX_SERVER;
 		 *UseList = TRUE;
-		 if (TRACE)
-		     fprintf(stderr, "HTFTP: Treating as Unix server.\n");
+		 CTRACE(tfp, "HTFTP: Treating as Unix server.\n");
 	    }
 	    return;
 	} else if (response_text[strlen(response_text)-1] == ']') {
 	    /* path names ending with ] imply VMS, right? */
 	    *ServerType = VMS_SERVER;
 	    *UseList = TRUE;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as VMS server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as VMS server.\n");
 	} else {
 	    *ServerType = GENERIC_SERVER;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as Generic server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as Generic server.\n");
 	}
 
 	if ((*ServerType == NCSA_SERVER) ||
@@ -713,42 +694,35 @@ PRIVATE int get_connection ARGS2(
 	    FREE(p1);
     } /* scope of p1 */
 
-  status = HTDoConnect (arg, "FTP", IPPORT_FTP, (int *)&con->socket);
+    status = HTDoConnect (arg, "FTP", IPPORT_FTP, (int *)&con->socket);
 
-  if (status < 0)
-    {
-      if (TRACE)
-	{
-	  if (status == HT_INTERRUPTED)
-	    fprintf (stderr,
-		     "HTFTP: Interrupted on connect\n");
-	  else
-	    fprintf(stderr,
-		    "HTFTP: Unable to connect to remote host for `%s'.\n",
-		    arg);
+    if (status < 0) {
+	if (status == HT_INTERRUPTED) {
+	    CTRACE (tfp, "HTFTP: Interrupted on connect\n");
+	} else {
+	    CTRACE(tfp, "HTFTP: Unable to connect to remote host for `%s'.\n",
+		        arg);
 	}
-      if (status == HT_INTERRUPTED) {
-	_HTProgress ("Connection interrupted.");
-	status = HT_NOT_LOADED;
-      } else {
-	HTAlert("Unable to connect to FTP host.");
-      }
-      if (con->socket != -1)
+	if (status == HT_INTERRUPTED) {
+	    _HTProgress ("Connection interrupted.");
+	    status = HT_NOT_LOADED;
+	} else {
+	    HTAlert("Unable to connect to FTP host.");
+	}
+	if (con->socket != -1)
 	{
 	  NETCLOSE(con->socket);
 	}
 
-      FREE(username);
-      if (control == con)
-	  control = NULL;
-      FREE(con);
-      return status;			/* Bad return */
+	FREE(username);
+	if (control == con)
+	    control = NULL;
+	FREE(con);
+	return status;			/* Bad return */
     }
 
-    if (TRACE) {
-	fprintf(stderr, "FTP connected, socket %d  control %ld\n",
-			con->socket, (long)con);
-    }
+    CTRACE(tfp, "FTP connected, socket %d  control %ld\n",
+		con->socket, (long)con);
     control = con;		/* Current control connection */
 
     /* Initialise buffering for control connection */
@@ -760,16 +734,13 @@ PRIVATE int get_connection ARGS2(
 */
     status = response((char *)0);	/* Get greeting */
 
-    if (status == HT_INTERRUPTED)
-      {
-	if (TRACE)
-	  fprintf (stderr,
-		   "HTFTP: Interrupted at beginning of login.\n");
+    if (status == HT_INTERRUPTED) {
+	CTRACE (tfp, "HTFTP: Interrupted at beginning of login.\n");
 	_HTProgress ("Connection interrupted.");
 	NETCLOSE(control->socket);
 	control->socket = -1;
 	return HT_INTERRUPTED;
-      }
+    }
     server_type = GENERIC_SERVER;	/* reset */
     if (status == 2) {		/* Send username */
 	char *cp;		/* look at greeting text */
@@ -800,16 +771,13 @@ PRIVATE int get_connection ARGS2(
 	}
 	status = response(command);
 	FREE(command);
-	if (status == HT_INTERRUPTED)
-	  {
-	    if (TRACE)
-	      fprintf (stderr,
-		       "HTFTP: Interrupted while sending username.\n");
+	if (status == HT_INTERRUPTED) {
+	    CTRACE (tfp, "HTFTP: Interrupted while sending username.\n");
 	    _HTProgress ("Connection interrupted.");
 	    NETCLOSE(control->socket);
 	    control->socket = -1;
 	    return HT_INTERRUPTED;
-	  }
+	}
     }
     if (status == 3) {		/* Send password */
 	if (password) {
@@ -866,16 +834,14 @@ PRIVATE int get_connection ARGS2(
 	}
 	status = response(command);
 	FREE(command);
-	if (status == HT_INTERRUPTED)
-	  {
-	    if (TRACE)
-	      fprintf (stderr,
+	if (status == HT_INTERRUPTED) {
+	    CTRACE (tfp,
 		       "HTFTP: Interrupted while sending password.\n");
 	    _HTProgress ("Connection interrupted.");
 	    NETCLOSE(control->socket);
 	    control->socket = -1;
 	    return HT_INTERRUPTED;
-	  }
+	}
     }
     FREE(username);
 
@@ -883,25 +849,21 @@ PRIVATE int get_connection ARGS2(
 	char temp[80];
 	sprintf(temp, "ACCT noaccount%c%c", CR, LF);
 	status = response(temp);
-	if (status == HT_INTERRUPTED)
-	  {
-	    if (TRACE)
-	      fprintf (stderr,
-		       "HTFTP: Interrupted while sending password.\n");
+	if (status == HT_INTERRUPTED) {
+	    CTRACE (tfp, "HTFTP: Interrupted while sending password.\n");
 	    _HTProgress ("Connection interrupted.");
 	    NETCLOSE(control->socket);
 	    control->socket = -1;
 	    return HT_INTERRUPTED;
-	  }
+	}
 
     }
     if (status != 2) {
-	if (TRACE)
-	    fprintf(stderr, "HTFTP: Login fail: %s", response_text);
+	CTRACE(tfp, "HTFTP: Login fail: %s", response_text);
 	/* if (control->socket > 0) close_connection(control->socket); */
 	return -1;		/* Bad return */
     }
-    if (TRACE) fprintf(stderr, "HTFTP: Logged in.\n");
+    CTRACE(tfp, "HTFTP: Logged in.\n");
 
     /** Check for host type **/
     if (server_type != NETPRESENZ_SERVER)
@@ -913,88 +875,71 @@ PRIVATE int get_connection ARGS2(
 		    "UNIX Type: L8 MAC-OS MachTen", 28) == 0) {
 	    server_type = MACHTEN_SERVER;
 	    use_list = TRUE;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as MachTen server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as MachTen server.\n");
 
 	} else if (strstr(response_text+4, "UNIX") != NULL ||
 		   strstr(response_text+4, "Unix") != NULL) {
 	    server_type = UNIX_SERVER;
 	    use_list = TRUE;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as Unix server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as Unix server.\n");
 
 	} else if (strstr(response_text+4, "MSDOS") != NULL) {
 	    server_type = MSDOS_SERVER;
 	    use_list = TRUE;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTFTP: Treating as MSDOS (Unix emulation) server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as MSDOS (Unix emulation) server.\n");
 
 	} else if (strncmp(response_text+4, "VMS", 3) == 0) {
 	    server_type = VMS_SERVER;
 	    use_list = TRUE;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as VMS server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as VMS server.\n");
 
 	} else if ((strncmp(response_text+4, "VM/CMS", 6) == 0) ||
 		   (strncmp(response_text+4, "VM ", 3) == 0)) {
 	    server_type = CMS_SERVER;
 	    use_list = TRUE;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as CMS server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as CMS server.\n");
 
 	} else if (strncmp(response_text+4, "DCTS", 4) == 0) {
 	    server_type = DCTS_SERVER;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as DCTS server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as DCTS server.\n");
 
 	} else if (strstr(response_text+4, "MAC-OS TCP/Connect II") != NULL) {
 	    server_type = TCPC_SERVER;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Looks like a TCPC server.\n");
+	    CTRACE(tfp, "HTFTP: Looks like a TCPC server.\n");
 	    get_ftp_pwd(&server_type, &use_list);
 	    unsure_type = TRUE;
 
 	} else if (server_type == NETPRESENZ_SERVER) { /* already set above */
 	    use_list = TRUE;
 	    set_mac_binary(server_type);
-	    if (TRACE)
-		fprintf(stderr,
-			"HTFTP: Treating as NetPresenz (MACOS) server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as NetPresenz (MACOS) server.\n");
 
 	} else if (strncmp(response_text+4, "MACOS Peter's Server", 20) == 0) {
 	    server_type = PETER_LEWIS_SERVER;
 	    use_list = TRUE;
 	    set_mac_binary(server_type);
-	    if (TRACE)
-		fprintf(stderr,
-			"HTFTP: Treating as Peter Lewis (MACOS) server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as Peter Lewis (MACOS) server.\n");
 
 	} else if (strncmp(response_text+4, "Windows_NT", 10) == 0) {
 	    server_type = WINDOWS_NT_SERVER;
 	    use_list = TRUE;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as Window_NT server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as Window_NT server.\n");
 
 	} else if (strncmp(response_text+4, "MS Windows", 10) == 0) {
 	    server_type = MS_WINDOWS_SERVER;
 	    use_list = TRUE;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Treating as MS Windows server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as MS Windows server.\n");
 
 	} else if (strncmp(response_text+4,
 			   "MACOS AppleShare IP FTP Server", 30) == 0) {
 	    server_type = APPLESHARE_SERVER;
 	    use_list = TRUE;
 	    set_mac_binary(server_type);
-	    if (TRACE)
-		fprintf(stderr,
-			"HTFTP: Treating as AppleShare server.\n");
+	    CTRACE(tfp, "HTFTP: Treating as AppleShare server.\n");
 
 	} else	{
 	    server_type = GENERIC_SERVER;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Ugh!  A Generic server.\n");
+	    CTRACE(tfp, "HTFTP: Ugh!  A Generic server.\n");
 	    get_ftp_pwd(&server_type, &use_list);
 	    unsure_type = TRUE;
 	 }
@@ -1013,8 +958,7 @@ PRIVATE int get_connection ARGS2(
 		close_connection(control->socket);
 	    return -status;		/* Bad return */
 	}
-	if (TRACE)
-	    fprintf(stderr, "HTFTP: Port defined.\n");
+	CTRACE(tfp, "HTFTP: Port defined.\n");
     }
 #endif /* NOTREPEAT_PORT */
     return con->socket; 		/* Good return */
@@ -1033,8 +977,7 @@ PRIVATE int close_master_socket NOARGS
     int status;
     FD_CLR(master_socket, &open_sockets);
     status = NETCLOSE(master_socket);
-    if (TRACE)
-	fprintf(stderr, "HTFTP: Closed master socket %d\n", master_socket);
+    CTRACE(tfp, "HTFTP: Closed master socket %d\n", master_socket);
     master_socket = -1;
     if (status < 0)
 	return HTInetStatus("close master socket");
@@ -1079,8 +1022,7 @@ PRIVATE int get_listen_socket NOARGS
     if (new_socket < 0)
 	return HTInetStatus("socket for master socket");
 
-    if (TRACE)
-	fprintf(stderr, "HTFTP: Opened master socket number %d\n", new_socket);
+    CTRACE(tfp, "HTFTP: Opened master socket number %d\n", new_socket);
 
 /*  Search for a free port.
 */
@@ -1115,9 +1057,7 @@ PRIVATE int get_listen_socket NOARGS
 			    /* Cast to generic sockaddr */
 		    sizeof(soc_address))) == 0)
 		break;
-	    if (TRACE)
-		fprintf(stderr,
-			"TCP bind attempt to port %d yields %d, errno=%d\n",
+	    CTRACE(tfp, "TCP bind attempt to port %d yields %d, errno=%d\n",
 		port_number, status, SOCKET_ERRNO);
 	} /* for */
     }
@@ -1592,11 +1532,10 @@ PRIVATE void parse_vms_dir_entry ARGS2(
     }
 
     /** Wrap it up **/
-    if (TRACE)
-	fprintf(stderr, "HTFTP: VMS filename: %s  date: %s  size: %d\n",
-			entry_info->filename,
-			entry_info->date ? entry_info->date : "",
-			entry_info->size);
+    CTRACE(tfp, "HTFTP: VMS filename: %s  date: %s  size: %d\n",
+		entry_info->filename,
+		entry_info->date ? entry_info->date : "",
+		entry_info->size);
     return;
 } /* parse_vms_dir_entry() */
 
@@ -1673,11 +1612,10 @@ PRIVATE void parse_ms_windows_dir_entry ARGS2(
     }
 
     /** Wrap it up **/
-    if (TRACE)
-	fprintf(stderr, "HTFTP: MS Windows filename: %s  date: %s  size: %d\n",
-			entry_info->filename,
-			entry_info->date ? entry_info->date : "",
-			entry_info->size);
+    CTRACE(tfp, "HTFTP: MS Windows filename: %s  date: %s  size: %d\n",
+		entry_info->filename,
+		entry_info->date ? entry_info->date : "",
+		entry_info->size);
     return;
 } /* parse_ms_windows_dir_entry */
 
@@ -1795,11 +1733,10 @@ PRIVATE void parse_windows_nt_dir_entry ARGS2(
     }
 
     /** Wrap it up **/
-    if (TRACE)
-	fprintf(stderr, "HTFTP: Windows NT filename: %s  date: %s  size: %d\n",
-			entry_info->filename,
-			entry_info->date ? entry_info->date : "",
-			entry_info->size);
+    CTRACE(tfp, "HTFTP: Windows NT filename: %s  date: %s  size: %d\n",
+		entry_info->filename,
+		entry_info->date ? entry_info->date : "",
+		entry_info->size);
     return;
 } /* parse_windows_nt_dir_entry */
 #endif /* NOTDEFINED */
@@ -1954,11 +1891,10 @@ PRIVATE void parse_cms_dir_entry ARGS2(
     }
 
     /** Wrap it up. **/
-    if (TRACE)
-	fprintf(stderr, "HTFTP: VM/CMS filename: %s  date: %s  size: %d\n",
-			entry_info->filename,
-			entry_info->date ? entry_info->date : "",
-			entry_info->size);
+    CTRACE(tfp, "HTFTP: VM/CMS filename: %s  date: %s  size: %d\n",
+		entry_info->filename,
+		entry_info->date ? entry_info->date : "",
+		entry_info->size);
     return;
 } /* parse_cms_dir_entry */
 
@@ -2531,15 +2467,13 @@ AgainForMultiNet:
 	    if (c == (char) EOF && chunk->size == 1)
 	    /* 1 means empty: includes terminating 0 */
 		break;
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Line in %s is %s\n",
-				lastpath, chunk->data);
+	    CTRACE(tfp, "HTFTP: Line in %s is %s\n",
+			lastpath, chunk->data);
 
 	    entry_info = parse_dir_entry(chunk->data, &first);
 	    if (entry_info->display) {
-		if (TRACE)
-		    fprintf(stderr, "Adding file to BTree: %s\n",
-				    entry_info->filename);
+		CTRACE(tfp, "Adding file to BTree: %s\n",
+			    entry_info->filename);
 		HTBTree_add(bt, (EntryInfo *)entry_info);
 	    } else {
 		FREE(entry_info);
@@ -2695,22 +2629,19 @@ PUBLIC int HTFTPLoad ARGS4(
 	{
 	    status = response(port_command);
 	    if (status == HT_INTERRUPTED) {
-	      if (TRACE)
-		fprintf (stderr,
-			 "HTFTP: Interrupted in response (port_command)\n");
-	      _HTProgress ("Connection interrupted.");
-	      NETCLOSE (control->socket);
-	      control->socket = -1;
-	      close_master_socket ();
-	      return HT_INTERRUPTED;
+		CTRACE (tfp, "HTFTP: Interrupted in response (port_command)\n");
+		_HTProgress ("Connection interrupted.");
+		NETCLOSE (control->socket);
+		control->socket = -1;
+		close_master_socket ();
+		return HT_INTERRUPTED;
 	    }
 	    if (status != 2) {		/* Could have timed out */
 		if (status < 0)
 		    continue;		/* try again - net error*/
 		return -status; 	/* bad reply */
 	    }
-	    if (TRACE)
-		fprintf(stderr, "HTFTP: Port defined.\n");
+	    CTRACE(tfp, "HTFTP: Port defined.\n");
 	}
 #endif /* REPEAT_PORT */
 #else	/* Use PASV */
@@ -2738,13 +2669,12 @@ PUBLIC int HTFTPLoad ARGS4(
 	   status = sscanf(p+1, "%d,%d,%d,%d,%d,%d",
 		   &h0, &h1, &h2, &h3, &p0, &p1);
 	   if (status < 4) {
-	       fprintf(stderr, "HTFTP: PASV reply has no inet address!\n");
+	       fprintf(tfp, "HTFTP: PASV reply has no inet address!\n");
 	       return -99;
 	   }
 	   passive_port = (p0<<8) + p1;
-	   if (TRACE)
-	       fprintf(stderr, "HTFTP: Server is listening on port %d\n",
-				passive_port);
+	   CTRACE(tfp, "HTFTP: Server is listening on port %d\n",
+			passive_port);
 
 
 /*	Open connection for data:
@@ -2759,8 +2689,7 @@ PUBLIC int HTFTPLoad ARGS4(
 		return status;			/* Bad return */
 	    }
 
-	    if (TRACE)
-		fprintf(stderr, "FTP data connected, socket %d\n", data_soc);
+	    CTRACE(tfp, "FTP data connected, socket %d\n", data_soc);
 	}
 #endif /* use PASV */
 	status = 0;
@@ -2787,10 +2716,7 @@ PUBLIC int HTFTPLoad ARGS4(
 		init_help_message_cache();  /* to free memory */
 		NETCLOSE(control->socket);
 		control->socket = -1;
-		if (TRACE) {
-		    fprintf(stderr,
-		     "HTFTP: Rejecting path due to illegal escaped slash.\n");
-		}
+		CTRACE(tfp, "HTFTP: Rejecting path due to illegal escaped slash.\n");
 		return -1;
 	    }
 	}
@@ -2825,13 +2751,12 @@ PUBLIC int HTFTPLoad ARGS4(
 		    *(filename+1) = '\0';
 		}
 	    }
-	    if (TRACE && *type != '\0') {
-		fprintf(stderr, "HTFTP: type=%s\n", type);
+	    if (*type != '\0') {
+		CTRACE(tfp, "HTFTP: type=%s\n", type);
 	    }
 	}
 	HTUnEscape(filename);
-	if (TRACE)
-	    fprintf(stderr, "HTFTP: UnEscaped %s\n", filename);
+	CTRACE(tfp, "HTFTP: UnEscaped %s\n", filename);
 	if (filename[1] == '~') {
 	    /*
 	    ** Check if translation of HOME as tilde is supported,
@@ -2949,10 +2874,7 @@ PUBLIC int HTFTPLoad ARGS4(
 		init_help_message_cache();  /* to free memory */
 		NETCLOSE(control->socket);
 		control->socket = -1;
-		if (TRACE) {
-		    fprintf(stderr,
-		     "HTFTP: Rejecting path due to non-Unix-style syntax.\n");
-		}
+		CTRACE(tfp, "HTFTP: Rejecting path due to non-Unix-style syntax.\n");
 		return -1;
 	    }
 	    /** Handle any unescaped "/%2F" path **/
@@ -2962,21 +2884,15 @@ PUBLIC int HTFTPLoad ARGS4(
 		for (i = 0; filename[(i+1)]; i++)
 		    filename[i] = filename[(i+1)];
 		filename[i] = '\0';
-		if (TRACE) {
-		    fprintf(stderr, "HTFTP: Trimmed '%s'\n", filename);
-		}
+		CTRACE(tfp, "HTFTP: Trimmed '%s'\n", filename);
 		cp = HTMake_VMS_name("", filename);
-		if (TRACE) {
-		    fprintf(stderr, "HTFTP: VMSized '%s'\n", cp);
-		}
+		CTRACE(tfp, "HTFTP: VMSized '%s'\n", cp);
 		if ((cp1=strrchr(cp, ']')) != NULL) {
 		    cp1++;
 		    for (i = 0; cp1[i]; i++)
 			filename[i] = cp1[i];
 		    filename[i] = '\0';
-		    if (TRACE) {
-			fprintf(stderr, "HTFTP: Filename '%s'\n", filename);
-		    }
+		    CTRACE(tfp, "HTFTP: Filename '%s'\n", filename);
 		    *cp1 = '\0';
 		    sprintf(command, "CWD %s%c%c", cp, CR, LF);
 		    status = response (command);
@@ -3017,9 +2933,7 @@ PUBLIC int HTFTPLoad ARGS4(
 			for (i = 0; cp1[i]; i++)
 			    filename[i] = cp1[i];
 			filename[i] = '\0';
-			if (TRACE) {
-			    fprintf(stderr, "HTFTP: Filename '%s'\n", filename);
-			}
+			CTRACE(tfp, "HTFTP: Filename '%s'\n", filename);
 			*cp1 = '\0';
 			strcat(cp, "[");
 			strcat(cp, filename);
@@ -3359,8 +3273,7 @@ listen:
 	/* Reset buffering to control connection DD 921208 */
 
 	status = NETCLOSE(data_soc);
-	if (TRACE)
-	    fprintf(stderr, "HTFTP: Closing data socket %d\n", data_soc);
+	CTRACE(tfp, "HTFTP: Closing data socket %d\n", data_soc);
 	if (status < 0 && rv != HT_INTERRUPTED && rv != -1) {
 	    (void) HTInetStatus("close");	/* Comment only */
 	    data_soc = -1;			/* invalidate it */
diff --git a/WWW/Library/Implementation/HTFWriter.c b/WWW/Library/Implementation/HTFWriter.c
index 8de75085..74d09866 100644
--- a/WWW/Library/Implementation/HTFWriter.c
+++ b/WWW/Library/Implementation/HTFWriter.c
@@ -153,8 +153,7 @@ PRIVATE void HTFWriter_abort ARGS2(HTStream *, me, HTError, e)
 {
     fclose(me->fp);
     if (me->end_command) {		/* Temp file */
-	if (TRACE) fprintf(stderr,
-		"HTFWriter: Aborting: file not executed.\n");
+	CTRACE(tfp, "HTFWriter: Aborting: file not executed.\n");
 	FREE(me->end_command);
 	if (me->remove_command) {
 	    system(me->remove_command);
diff --git a/WWW/Library/Implementation/HTFile.c b/WWW/Library/Implementation/HTFile.c
index 3bc93f1e..0e405b82 100644
--- a/WWW/Library/Implementation/HTFile.c
+++ b/WWW/Library/Implementation/HTFile.c
@@ -578,21 +578,32 @@ PUBLIC char * HTLocalName ARGS1(
 	if ((0 == strcasecomp(host, HTHostName())) ||
 	    (0 == strcasecomp(host, "localhost")) || !*host) {
 	    FREE(host);
-	    if (TRACE)
-		fprintf(stderr, "Node `%s' means path `%s'\n", name, path);
+	    CTRACE(tfp, "Node `%s' means path `%s'\n", name, path);
 #ifdef DOSPATH
 	    {
 		char *ret_path = NULL;
 		StrAllocCopy(ret_path, HTDOS_name(path));
-		if (TRACE) {
-		    fprintf(stderr, "HTDOS_name changed `%s' to `%s'\n",
+		CTRACE(tfp, "HTDOS_name changed `%s' to `%s'\n",
+			    path, ret_path);
+		FREE(path);
+		return(ret_path);
+	    }
+#else
+#ifdef __EMX__
+	    {
+		char *ret_path = NULL;
+		if (path[0] == '/') /* pesky leading slash */
+		    StrAllocCopy(ret_path, path+1);
+		else
+		    StrAllocCopy(ret_path, path);
+		CTRACE(tfp, "EMX hack changed `%s' to `%s'\n",
 			    path, ret_path);
-		}
 		FREE(path);
 		return(ret_path);
 	    }
 #else
 	    return(path);
+#endif /* __EMX__ */
 #endif /* DOSPATH */
 	} else {
 	    char * result = (char *)malloc(
@@ -602,8 +613,7 @@ PUBLIC char * HTLocalName ARGS1(
 	    sprintf(result, "%s%s%s", "/Net/", host, path);
 	    FREE(host);
 	    FREE(path);
-	    if (TRACE)
-		fprintf(stderr, "Node `%s' means file `%s'\n", name, result);
+	    CTRACE(tfp, "Node `%s' means file `%s'\n", name, result);
 	    return result;
 	}
     } else {  /* other access */
@@ -662,8 +672,7 @@ PUBLIC char * WWW_nameOfFile ARGS1(
 	    outofmem(__FILE__, "WWW_nameOfFile");
 	sprintf(result, "file://%s%s", HTHostName(), name);
     }
-    if (TRACE)
-	fprintf(stderr, "File `%s'\n\tmeans node `%s'\n", name, result);
+    CTRACE(tfp, "File `%s'\n\tmeans node `%s'\n", name, result);
     return result;
 }
 
@@ -866,9 +875,7 @@ PUBLIC HTFormat HTCharsetFormat ARGS3(
 	cp[i] = TOLOWER(cp[i]);
     if (((cp1 = strchr(cp, ';')) != NULL) &&
 	(cp2 = strstr(cp1, "charset")) != NULL) {
-	if (TRACE)
-	    fprintf(stderr,
-		    "HTCharsetFormat: Extended MIME Content-Type is %s\n",
+	CTRACE(tfp, "HTCharsetFormat: Extended MIME Content-Type is %s\n",
 		    format->name);
 	cp2 += 7;
 	while (*cp2 == ' ' || *cp2 == '=')
@@ -1032,9 +1039,8 @@ PUBLIC float HTFileValue ARGS1(
 	suff = (HTSuffix *)HTList_objectAt(HTSuffixes, i);
 	ls = strlen(suff->suffix);
 	if ((ls <= lf) && 0==strcmp(suff->suffix, filename + lf - ls)) {
-	    if (TRACE)
-		fprintf(stderr, "File: Value of %s is %.3f\n",
-				filename, suff->quality);
+	    CTRACE(tfp, "File: Value of %s is %.3f\n",
+			filename, suff->quality);
 	    return suff->quality;		/* OK -- found */
 	}
     }
@@ -1099,14 +1105,14 @@ PUBLIC BOOL HTEditable ARGS1(
 
     if (TRACE) {
 	int i2;
-	fprintf(stderr,
+	fprintf(tfp,
 	    "File mode is 0%o, uid=%d, gid=%d. My uid=%d, %d groups (",
 	    (unsigned int) fileStatus.st_mode, fileStatus.st_uid,
 	    fileStatus.st_gid,
 	    myUid, ngroups);
 	for (i2 = 0; i2 < ngroups; i2++)
-	    fprintf(stderr, " %d", groups[i2]);
-	fprintf(stderr, ")\n");
+	    fprintf(tfp, " %d", groups[i2]);
+	fprintf(tfp, ")\n");
     }
 
     if (fileStatus.st_mode & 0002)		/* I can write anyway? */
@@ -1123,8 +1129,7 @@ PUBLIC BOOL HTEditable ARGS1(
 		return YES;
 	}
     }
-    if (TRACE)
-	fprintf(stderr, "\tFile is not editable.\n");
+    CTRACE(tfp, "\tFile is not editable.\n");
     return NO;					/* If no excuse, can't do */
 #endif /* NO_GROUPS */
 }
@@ -1527,8 +1532,7 @@ PUBLIC int HTLoadFile ARGS4(
     **	to the directories or files listed.
     */
     if (HTStat(filename, &stat_info) == -1) {
-	if (TRACE)
-	    fprintf(stderr, "HTLoadFile: Can't stat %s\n", filename);
+	CTRACE(tfp, "HTLoadFile: Can't stat %s\n", filename);
     } else {
 	if (((stat_info.st_mode) & S_IFMT) == S_IFDIR) {
 	    if (HTDirAccess == HT_DIR_FORBID) {
@@ -1576,14 +1580,12 @@ PUBLIC int HTLoadFile ARGS4(
 	*/
 	if (!fp) {
 	    char ultrixname[INFINITY];
-	    if (TRACE)
-		fprintf(stderr, "HTLoadFile: Can't open as %s\n", vmsname);
+	    CTRACE(tfp, "HTLoadFile: Can't open as %s\n", vmsname);
 	    sprintf(ultrixname, "%s::\"%s\"", nodename, filename);
 	    fp = fopen(ultrixname, "r", "shr=put", "shr=upd");
 	    if (!fp) {
-		if (TRACE)
-		    fprintf(stderr, "HTLoadFile: Can't open as %s\n",
-				    ultrixname);
+		CTRACE(tfp, "HTLoadFile: Can't open as %s\n",
+			    ultrixname);
 	    }
 	}
 	if (fp) {
@@ -1623,9 +1625,7 @@ PUBLIC int HTLoadFile ARGS4(
 			*semicolon = ';';
 		    gzfp = gzopen(vmsname, "rb");
 
-		    if (TRACE)
-			fprintf(stderr,
-				"HTLoadFile: gzopen of `%s' gives %p\n",
+		    CTRACE(tfp, "HTLoadFile: gzopen of `%s' gives %p\n",
 				vmsname, (void*)gzfp);
 		    use_gzread = YES;
 		} else
@@ -1671,9 +1671,7 @@ PUBLIC int HTLoadFile ARGS4(
 				*semicolon = ';';
 			    gzfp = gzopen(vmsname, "rb");
 
-			    if (TRACE)
-				fprintf(stderr,
-				       "HTLoadFile: gzopen of `%s' gives %p\n",
+			    CTRACE(tfp, "HTLoadFile: gzopen of `%s' gives %p\n",
 					vmsname, (void*)gzfp);
 			    use_gzread = YES;
 			}
@@ -1846,9 +1844,7 @@ PUBLIC int HTLoadFile ARGS4(
 			}
 		    }
 		    if (value != NO_VALUE_FOUND) {
-			if (TRACE)
-			    fprintf(stderr,
-				 "HTLoadFile: value of presenting %s is %f\n",
+			CTRACE(tfp, "HTLoadFile: value of presenting %s is %f\n",
 				    HTAtom_name(rep), value);
 			if  (value > best) {
 			    best_rep = rep;
@@ -1894,8 +1890,7 @@ PUBLIC int HTLoadFile ARGS4(
 #endif
 	{
 				       /* if can't read file information */
-	    if (TRACE)
-		fprintf(stderr, "HTLoadFile: can't stat %s\n", localname);
+	    CTRACE(tfp, "HTLoadFile: can't stat %s\n", localname);
 
 	}  else {		/* Stat was OK */
 
@@ -1919,8 +1914,7 @@ PUBLIC int HTLoadFile ARGS4(
 		BOOL need_parent_link = FALSE;
 		struct stat file_info;
 
-		if (TRACE)
-		    fprintf(stderr, "%s is a directory\n", localname);
+		CTRACE(tfp, "%s is a directory\n", localname);
 
 		/*
 		**  Check directory access.
@@ -2244,8 +2238,7 @@ PUBLIC int HTLoadFile ARGS4(
 	{
 	    FILE * fp = fopen(localname, "r");
 
-	    if (TRACE)
-		fprintf (stderr, "HTLoadFile: Opening `%s' gives %p\n",
+	    CTRACE (tfp, "HTLoadFile: Opening `%s' gives %p\n",
 				 localname, (void*)fp);
 	    if (fp) {		/* Good! */
 		int len;
@@ -2274,9 +2267,7 @@ PUBLIC int HTLoadFile ARGS4(
 			fclose(fp);
 			gzfp = gzopen(localname, "rb");
 
-			if (TRACE)
-			    fprintf(stderr,
-				    "HTLoadFile: gzopen of `%s' gives %p\n",
+			CTRACE(tfp, "HTLoadFile: gzopen of `%s' gives %p\n",
 				    localname, (void*)gzfp);
 			use_gzread = YES;
 		    } else
@@ -2315,9 +2306,7 @@ PUBLIC int HTLoadFile ARGS4(
 			    fclose(fp);
 			    gzfp = gzopen(localname, "rb");
 
-			    if (TRACE)
-				fprintf(stderr,
-				       "HTLoadFile: gzopen of `%s' gives %p\n",
+			    CTRACE(tfp, "HTLoadFile: gzopen of `%s' gives %p\n",
 					localname, (void*)gzfp);
 			    use_gzread = YES;
 			}
@@ -2404,8 +2393,7 @@ PUBLIC int HTLoadFile ARGS4(
     **	All attempts have failed.
     */
     {
-	if (TRACE)
-	    fprintf(stderr, "Can't open `%s', errno=%d\n", addr, SOCKET_ERRNO);
+	CTRACE(tfp, "Can't open `%s', errno=%d\n", addr, SOCKET_ERRNO);
 
 	return HTLoadError(sink, 403, "Can't access requested file.");
     }
diff --git a/WWW/Library/Implementation/HTFinger.c b/WWW/Library/Implementation/HTFinger.c
index 042d137c..89c5540c 100644
--- a/WWW/Library/Implementation/HTFinger.c
+++ b/WWW/Library/Implementation/HTFinger.c
@@ -37,8 +37,6 @@
 
 #include <LYLeaks.h>
 
-/* #define TRACE 1 */
-
 #define FINGER_PORT 79		/* See rfc742 */
 #define BIG 1024		/* Bug */
 
@@ -129,13 +127,10 @@ PRIVATE int response ARGS5(
 
     /* Send the command.
     */
-    if (TRACE) 
-        fprintf(stderr, "HTFinger command to be sent: %s", command);
+    CTRACE(tfp, "HTFinger command to be sent: %s", command);
     status = NETWRITE(s, (char *)command, length);
     if (status < 0) {
-        if (TRACE)
-	    fprintf(stderr,
-                    "HTFinger: Unable to send command. Disconnecting.\n");
+	CTRACE(tfp, "HTFinger: Unable to send command. Disconnecting.\n");
         NETCLOSE(s);
         s = -1;
         return status;
@@ -148,8 +143,7 @@ PRIVATE int response ARGS5(
 
     /* Create the results report.
     */
-    if (TRACE)
-	fprintf(stderr,"HTFinger: Reading finger information\n");
+    CTRACE(tfp,"HTFinger: Reading finger information\n");
     START(HTML_HTML);
     PUTS("\n");
     START(HTML_HEAD);
@@ -190,10 +184,7 @@ PRIVATE int response ARGS5(
     while ((ch=NEXT_CHAR) != (char)EOF) {
 
 	if (interrupted_in_htgetcharacter) {
-	    if (TRACE) {
-	        fprintf(stderr,
-		  "HTFinger: Interrupted in HTGetCharacter, apparently.\n");
-	    }
+	    CTRACE(tfp, "HTFinger: Interrupted in HTGetCharacter, apparently.\n");
 	    _HTProgress ("Connection interrupted.");
 	    goto end_html;
         }
@@ -270,9 +261,7 @@ PUBLIC int HTLoadFinger ARGS4(
     int port;				/* Port number from URL */
     int status;				/* tcp return */
   
-    if (TRACE) {
-        fprintf(stderr, "HTFinger: Looking for %s\n", (arg ? arg : "NULL"));
-    }
+    CTRACE(tfp, "HTFinger: Looking for %s\n", (arg ? arg : "NULL"));
   
     if (!(arg && *arg)) {
         HTAlert("Could not load data.");
@@ -391,17 +380,13 @@ PUBLIC int HTLoadFinger ARGS4(
     /* Now, let's get a stream setup up from the FingerHost:
     ** CONNECTING to finger host
     */
-    if (TRACE)
-        fprintf(stderr, "HTFinger: doing HTDoConnect on '%s'\n", str);
+    CTRACE(tfp, "HTFinger: doing HTDoConnect on '%s'\n", str);
     status = HTDoConnect(str, "finger", FINGER_PORT, &s);
-    if (TRACE)
-        fprintf(stderr, "HTFinger: Done DoConnect; status %d\n", status);
+    CTRACE(tfp, "HTFinger: Done DoConnect; status %d\n", status);
 
     if (status == HT_INTERRUPTED) {
         /* Interrupt cleanly */
-	if (TRACE)
-	    fprintf(stderr,
-	    	  "HTFinger: Interrupted on connect; recovering cleanly.\n");
+	CTRACE(tfp, "HTFinger: Interrupted on connect; recovering cleanly.\n");
 	HTProgress ("Connection interrupted.");
 	FREE(str);
 	FREE(command);
@@ -410,15 +395,13 @@ PUBLIC int HTLoadFinger ARGS4(
     if (status < 0) {
         NETCLOSE(s);
 	s = -1;
-	if (TRACE) 
-	    fprintf(stderr, "HTFinger: Unable to connect to finger host.\n");
+	CTRACE(tfp, "HTFinger: Unable to connect to finger host.\n");
         HTAlert("Could not access finger host.");
 	FREE(str);
 	FREE(command);
 	return HT_NOT_LOADED;	/* FAIL */
     }
-    if (TRACE)
-        fprintf(stderr, "HTFinger: Connected to finger host '%s'.\n", str);
+    CTRACE(tfp, "HTFinger: Connected to finger host '%s'.\n", str);
     FREE(str);
 
     /* Send the command, and process response if successful.
diff --git a/WWW/Library/Implementation/HTFormat.c b/WWW/Library/Implementation/HTFormat.c
index baffca71..cdd2fa9b 100644
--- a/WWW/Library/Implementation/HTFormat.c
+++ b/WWW/Library/Implementation/HTFormat.c
@@ -235,14 +235,11 @@ PUBLIC char HTGetCharacter NOARGS
 		if (status == 0)
 		    return (char)EOF;
 		if (status == HT_INTERRUPTED) {
-		    if (TRACE)
-			fprintf(stderr,
-				"HTFormat: Interrupted in HTGetCharacter\n");
+		    CTRACE(tfp, "HTFormat: Interrupted in HTGetCharacter\n");
 		    interrupted_in_htgetcharacter = 1;
 		    return (char)EOF;
 		}
-		if (TRACE)
-		    fprintf(stderr, "HTFormat: File read error %d\n", status);
+		CTRACE(tfp, "HTFormat: File read error %d\n", status);
 		return (char)EOF; /* -1 is returned by UCX
 				     at end of HTTP link */
 	    }
@@ -266,9 +263,8 @@ PRIVATE int half_match ARGS2(char *,trial_type, char *,target)
     if (!cp || *(cp+1) != '*')
 	return 0;
 
-    if (TRACE)
-	fprintf(stderr,"HTFormat: comparing %s and %s for half match\n",
-						      trial_type, target);
+    CTRACE(tfp, "HTFormat: comparing %s and %s for half match\n",
+	        trial_type, target);
 
 	/* main type matches */
     if (!strncmp(trial_type, target, (cp-trial_type)-1))
@@ -295,9 +291,7 @@ PRIVATE HTPresentation * HTFindPresentation ARGS3(
 {
     HTAtom * wildcard = HTAtom_for("*");
 
-    if (TRACE)
-	fprintf(stderr,
-		"HTFormat: Looking up presentation for %s to %s\n",
+    CTRACE(tfp, "HTFormat: Looking up presentation for %s to %s\n",
 		HTAtom_name(rep_in), HTAtom_name(rep_out));
 
     /* don't do anymore do it in the Lynx code at startup LJM */
@@ -316,9 +310,7 @@ PRIVATE HTPresentation * HTFindPresentation ARGS3(
 	    pres = (HTPresentation *)HTList_objectAt(HTPresentations, i);
 	    if (pres->rep == rep_in) {
 		if (pres->rep_out == rep_out) {
-		    if (TRACE)
-			fprintf(stderr,
-				"FindPresentation: found exact match: %s\n",
+		    CTRACE(tfp, "FindPresentation: found exact match: %s\n",
 				HTAtom_name(pres->rep));
 		    return pres;
 
@@ -328,9 +320,7 @@ PRIVATE HTPresentation * HTFindPresentation ARGS3(
 		    if (!strong_wildcard_match)
 			strong_wildcard_match = pres;
 		    /* otherwise use the first one */
-		    if (TRACE)
-			fprintf(stderr,
-			     "StreamStack: found strong wildcard match: %s\n",
+		    CTRACE(tfp, "StreamStack: found strong wildcard match: %s\n",
 				HTAtom_name(pres->rep));
 		}
 
@@ -343,9 +333,7 @@ PRIVATE HTPresentation * HTFindPresentation ARGS3(
 		    if (!strong_subtype_wildcard_match)
 			strong_subtype_wildcard_match = pres;
 		    /* otherwise use the first one */
-		    if (TRACE)
-			fprintf(stderr,
-		     "StreamStack: found strong subtype wildcard match: %s\n",
+		    CTRACE(tfp, "StreamStack: found strong subtype wildcard match: %s\n",
 				HTAtom_name(pres->rep));
 		}
 	    }
@@ -355,9 +343,7 @@ PRIVATE HTPresentation * HTFindPresentation ARGS3(
 		    if (!weak_wildcard_match)
 			weak_wildcard_match = pres;
 		    /* otherwise use the first one */
-		    if (TRACE)
-			fprintf(stderr,
-			    "StreamStack: found weak wildcard match: %s\n",
+		    CTRACE(tfp, "StreamStack: found weak wildcard match: %s\n",
 				HTAtom_name(pres->rep_out));
 		}
 		if (pres->rep_out == wildcard) {
@@ -403,9 +389,7 @@ PUBLIC HTStream * HTStreamStack ARGS4(
     HTPresentation temp;
     HTPresentation *match;
 
-    if (TRACE)
-	fprintf(stderr,
-		"HTFormat: Constructing stream stack for %s to %s\n",
+    CTRACE(tfp, "HTFormat: Constructing stream stack for %s to %s\n",
 		HTAtom_name(rep_in), HTAtom_name(rep_out));
 
     /* don't return on WWW_SOURCE some people might like
@@ -419,13 +403,9 @@ PUBLIC HTStream * HTStreamStack ARGS4(
 
     if ((match = HTFindPresentation(rep_in, rep_out, &temp))) {
 	if (match == &temp) {
-	    if (TRACE)
-		fprintf(stderr,
-			"StreamStack: Using %s\n", HTAtom_name(temp.rep_out));
+	    CTRACE(tfp, "StreamStack: Using %s\n", HTAtom_name(temp.rep_out));
 	} else {
-	    if (TRACE)
-		fprintf(stderr,
-			"StreamStack: found exact match: %s\n",
+	    CTRACE(tfp, "StreamStack: found exact match: %s\n",
 			HTAtom_name(match->rep));
 	}
 	return (*match->converter)(match, anchor, sink);
@@ -466,9 +446,7 @@ PUBLIC float HTStackValue ARGS4(
 {
     HTAtom * wildcard = HTAtom_for("*");
 
-    if (TRACE)
-	fprintf(stderr,
-		"HTFormat: Evaluating stream stack for %s worth %.3f to %s\n",
+    CTRACE(tfp, "HTFormat: Evaluating stream stack for %s worth %.3f to %s\n",
 		HTAtom_name(rep_in), initial_value, HTAtom_name(rep_out));
 
     if (rep_out == WWW_SOURCE || rep_out == rep_in)
@@ -579,8 +557,7 @@ PUBLIC int HTCopy ARGS4(
 		    *  Treat what we've gotten already
 		    *  as the complete transmission. - FM
 		    */
-		   if (TRACE)
-		       fprintf(stderr,
+		   CTRACE(tfp,
 	    "HTCopy: Unexpected server disconnect. Treating as completed.\n");
 		   status = 0;
 		   break;
@@ -649,9 +626,7 @@ PUBLIC int HTFileCopy ARGS2(
 		rv = HT_LOADED;
 		break;
 	    }
-	    if (TRACE)
-		fprintf(stderr,
-			"HTFormat: Read error, read returns %d\n",
+	    CTRACE(tfp, "HTFormat: Read error, read returns %d\n",
 			ferror(fp));
 	    if (bytes) {
 		rv = HT_PARTIAL_CONTENT;
@@ -734,13 +709,11 @@ PRIVATE int HTGzFileCopy ARGS2(
 		rv = HT_LOADED;
 		break;
 	    }
-	    if (TRACE) {
-		fprintf(stderr,
-			"HTGzFileCopy: Read error, gzread returns %d\n",
+	    CTRACE(tfp, "HTGzFileCopy: Read error, gzread returns %d\n",
 			status);
-		fprintf(stderr,
-			"gzerror   : %s\n",
+	    CTRACE(tfp, "gzerror   : %s\n",
 			gzerror(gzfp, &gzerrnum));
+	    if (TRACE) {
 		if (gzerrnum == Z_ERRNO)
 		    perror("gzerror   ");
 	    }
@@ -862,8 +835,7 @@ PUBLIC int HTParseSocket ARGS5(
 	}
 	sprintf(buffer, "Sorry, can't convert from %s to %s.",
 		HTAtom_name(rep_in), HTAtom_name(format_out));
-	if (TRACE)
-	    fprintf(stderr, "HTFormat: %s\n", buffer);
+	CTRACE(tfp, "HTFormat: %s\n", buffer);
 	return HTLoadError(sink, 501, buffer); /* returns -501 */
     }
 
@@ -911,8 +883,7 @@ PUBLIC int HTParseFile ARGS5(
 	}
 	sprintf(buffer, "Sorry, can't convert from %s to %s.",
 		HTAtom_name(rep_in), HTAtom_name(format_out));
-	if (TRACE)
-	    fprintf(stderr, "HTFormat(in HTParseFile): %s\n", buffer);
+	CTRACE(tfp, "HTFormat(in HTParseFile): %s\n", buffer);
 	return HTLoadError(sink, 501, buffer);
     }
 
@@ -950,7 +921,7 @@ PRIVATE int HTCloseGzFile ARGS1(
 	if (gzres == Z_ERRNO) {
 	    perror("gzclose   ");
 	} else if (gzres != Z_OK) {
-	    fprintf(stderr, "gzclose   : error number %d\n", gzres);
+	    CTRACE(tfp, "gzclose   : error number %d\n", gzres);
 	}
     }
     return(gzres);
@@ -981,8 +952,7 @@ PUBLIC int HTParseGzFile ARGS5(
 	}
 	sprintf(buffer, "Sorry, can't convert from %s to %s.",
 		HTAtom_name(rep_in), HTAtom_name(format_out));
-	if (TRACE)
-	    fprintf(stderr, "HTFormat(in HTParseGzFile): %s\n", buffer);
+	CTRACE(tfp, "HTFormat(in HTParseGzFile): %s\n", buffer);
 	return HTLoadError(sink, 501, buffer);
     }
 
diff --git a/WWW/Library/Implementation/HTGopher.c b/WWW/Library/Implementation/HTGopher.c
index e168ac8e..ddc6a0aa 100644
--- a/WWW/Library/Implementation/HTGopher.c
+++ b/WWW/Library/Implementation/HTGopher.c
@@ -196,8 +196,7 @@ PRIVATE void write_anchor ARGS2(CONST char *,text, CONST char *,addr)
     present[HTML_A_TITLE] = YES;
     ((CONST char **)value)[HTML_A_TITLE] = text;
 
-    if(TRACE)
-	fprintf(stderr,"HTGopher: adding URL: %s\n",addr);
+    CTRACE(tfp,"HTGopher: adding URL: %s\n",addr);
 
     HT_Is_Gopher_URL = TRUE;  /* tell HTML.c that this is a Gopher URL */
     (*targetClass.start_element)(target, HTML_A, present,
@@ -258,9 +257,7 @@ PRIVATE void parse_menu ARGS2(
     while ((ch=NEXT_CHAR) != (char)EOF) {
 
 	if (interrupted_in_htgetcharacter) {
-	    if (TRACE)
-		fprintf(stderr,
-		    "HTGopher: Interrupted in HTGetCharacter, apparently.\n");
+	    CTRACE(tfp, "HTGopher: Interrupted in HTGetCharacter, apparently.\n");
 	    goto end_html;
 	}
 
@@ -273,8 +270,7 @@ PRIVATE void parse_menu ARGS2(
 	    bytes += p-line;	/* add size */
 	    p = line;		/* Scan it to parse it */
 	    port = 0;		/* Flag "not parsed" */
-	    if (TRACE)
-		fprintf(stderr, "HTGopher: Menu item: %s\n", line);
+	    CTRACE(tfp, "HTGopher: Menu item: %s\n", line);
 	    gtype = *p++;
 
 	    if (bytes > BytesReported + 1024) {
@@ -428,8 +424,7 @@ PRIVATE void parse_menu ARGS2(
 		else
 		    PUTS(name);
 	    } else { /* parse error */
-		if (TRACE)
-		    fprintf(stderr, "HTGopher: Bad menu item.\n");
+		CTRACE(tfp, "HTGopher: Bad menu item.\n");
 		PUTS(line);
 
 	    } /* parse error */
@@ -950,10 +945,7 @@ PRIVATE int parse_cso_fields ARGS2(
     */
     while ((ch = NEXT_CHAR) != (char)EOF) {
 	if (interrupted_in_htgetcharacter) {
-	    if (TRACE) {
-		fprintf(stderr,
-		  "HTLoadCSO: Interrupted in HTGetCharacter, apparently.\n");
-	    }
+	    CTRACE(tfp, "HTLoadCSO: Interrupted in HTGetCharacter, apparently.\n");
 	    free_CSOfields();
 	    buf[0] = '\0';
 	    return HT_INTERRUPTED;
@@ -1254,10 +1246,7 @@ PRIVATE int generate_cso_report ARGS2(
     while (!stop && (ch = NEXT_CHAR) != (char)EOF) {
 	if (interrupted_in_htgetcharacter) {
 	    buf[0] = '\0';
-	    if (TRACE) {
-		fprintf(stderr,
-		  "HTLoadCSO: Interrupted in HTGetCharacter, apparently.\n");
-	    }
+	    CTRACE(tfp, "HTLoadCSO: Interrupted in HTGetCharacter, apparently.\n");
 	    _HTProgress ("Connection interrupted.");
 	    goto end_CSOreport;
 	}
@@ -1499,8 +1488,7 @@ PRIVATE int HTLoadCSO ARGS4(
 	return -3;		/* Bad if no name sepcified	*/
     if (!*arg)
 	return -2;		/* Bad if name had zero length	*/
-    if (TRACE)
-	fprintf(stderr, "HTLoadCSO: Looking for %s\n", arg);
+    CTRACE(tfp, "HTLoadCSO: Looking for %s\n", arg);
 
     /*
     **	Set up a socket to the server for the data.
@@ -1510,16 +1498,12 @@ PRIVATE int HTLoadCSO ARGS4(
 	/*
 	**  Interrupt cleanly.
 	*/
-	if (TRACE)
-	    fprintf(stderr,
-		 "HTLoadCSO: Interrupted on connect; recovering cleanly.\n");
+	CTRACE(tfp, "HTLoadCSO: Interrupted on connect; recovering cleanly.\n");
 	_HTProgress ("Connection interrupted.");
 	return HT_NOT_LOADED;
     }
     if (status < 0) {
-	if (TRACE)
-	    fprintf(stderr,
-		    "HTLoadCSO: Unable to connect to remote host for `%s'.\n",
+	CTRACE(tfp, "HTLoadCSO: Unable to connect to remote host for `%s'.\n",
 		    arg);
 	return HTInetStatus("connect");
     }
@@ -1529,16 +1513,13 @@ PRIVATE int HTLoadCSO ARGS4(
     if ((command = (char *)malloc(12)) == NULL)
 	outofmem(__FILE__, "HTLoadCSO");
     sprintf(command, "fields%c%c", CR, LF);
-    if (TRACE)
-	fprintf(stderr,
-		"HTLoadCSO: Connected, writing command `%s' to socket %d\n",
+    CTRACE(tfp, "HTLoadCSO: Connected, writing command `%s' to socket %d\n",
 		command, s);
     _HTProgress ("Sending CSO/PH request.");
     status = NETWRITE(s, command, (int)strlen(command));
     FREE(command);
     if (status < 0) {
-	if (TRACE)
-	    fprintf(stderr, "HTLoadCSO: Unable to send command.\n");
+	CTRACE(tfp, "HTLoadCSO: Unable to send command.\n");
 	return HTInetStatus("send");
     }
     _HTProgress ("CSO/PH request sent; waiting for response.");
@@ -1715,15 +1696,12 @@ PRIVATE int HTLoadCSO ARGS4(
     (*Target->isa->put_block)(Target, command, clen);
     strcpy(buf, "</H2>\n");
     (*Target->isa->put_block)(Target, buf, strlen(buf));
-    if (TRACE)
-	fprintf(stderr,
-		"HTLoadCSO: Writing command `%s' to socket %d\n",
+    CTRACE(tfp, "HTLoadCSO: Writing command `%s' to socket %d\n",
 		command, s);
     status = NETWRITE(s, command, clen);
     FREE(command);
     if (status < 0) {
-	if (TRACE)
-	    fprintf(stderr, "HTLoadCSO: Unable to send command.\n");
+	CTRACE(tfp, "HTLoadCSO: Unable to send command.\n");
 	free_CSOfields();
 	return HTInetStatus("send");
     }
@@ -1761,8 +1739,7 @@ PRIVATE int HTLoadGopher ARGS4(
 	return -3;		/* Bad if no name sepcified	*/
     if (!*arg)
 	return -2;		/* Bad if name had zero length	*/
-    if (TRACE)
-	fprintf(stderr, "HTGopher: Looking for %s\n", arg);
+    CTRACE(tfp, "HTGopher: Looking for %s\n", arg);
 
     /*
     **	If it's a port 105 GOPHER_CSO gtype with no ISINDEX token ('?'),
@@ -1775,8 +1752,7 @@ PRIVATE int HTLoadGopher ARGS4(
 	if ((len = strlen(arg)) > 5) {
 	    if (0 == strcmp((CONST char *)&arg[len-6], ":105/2")) {
 		/* Use CSO gateway. */
-		if (TRACE)
-		    fprintf(stderr, "HTGopher: Passing to CSO/PH gateway.\n");
+		CTRACE(tfp, "HTGopher: Passing to CSO/PH gateway.\n");
 		return HTLoadCSO(arg, anAnchor, format_out, sink);
 	    }
 	}
@@ -1786,8 +1762,7 @@ PRIVATE int HTLoadGopher ARGS4(
     **	If it's a port 79/0[/...] URL, use the finger gateway. - FM
     */
     if (strstr(arg, ":79/0") != NULL) {
-	if (TRACE)
-	    fprintf(stderr, "HTGopher: Passing to finger gateway.\n");
+	CTRACE(tfp, "HTGopher: Passing to finger gateway.\n");
 	return HTLoadFinger(arg, anAnchor, format_out, sink);
     }
 
@@ -1884,17 +1859,13 @@ PRIVATE int HTLoadGopher ARGS4(
 	/*
 	**  Interrupt cleanly.
 	*/
-	if (TRACE)
-	    fprintf(stderr,
-		    "HTGopher: Interrupted on connect; recovering cleanly.\n");
+	CTRACE(tfp, "HTGopher: Interrupted on connect; recovering cleanly.\n");
 	_HTProgress ("Connection interrupted.");
 	FREE(command);
 	return HT_NOT_LOADED;
     }
     if (status < 0) {
-	if (TRACE)
-	    fprintf(stderr,
-		    "HTGopher: Unable to connect to remote host for `%s'.\n",
+	CTRACE(tfp, "HTGopher: Unable to connect to remote host for `%s'.\n",
 		    arg);
 	FREE(command);
 	return HTInetStatus("connect");
@@ -1902,9 +1873,7 @@ PRIVATE int HTLoadGopher ARGS4(
 
     HTInitInput(s);		/* Set up input buffering */
 
-    if (TRACE)
-	fprintf(stderr,
-		"HTGopher: Connected, writing command `%s' to socket %d\n",
+    CTRACE(tfp, "HTGopher: Connected, writing command `%s' to socket %d\n",
 		command, s);
 
 #ifdef NOT_ASCII
@@ -1921,8 +1890,7 @@ PRIVATE int HTLoadGopher ARGS4(
     status = NETWRITE(s, command, (int)strlen(command));
     FREE(command);
     if (status < 0) {
-	if (TRACE)
-	    fprintf(stderr, "HTGopher: Unable to send command.\n");
+	CTRACE(tfp, "HTGopher: Unable to send command.\n");
 	return HTInetStatus("send");
     }
 
diff --git a/WWW/Library/Implementation/HTGroup.c b/WWW/Library/Implementation/HTGroup.c
index d48c298d..71fd1445 100644
--- a/WWW/Library/Implementation/HTGroup.c
+++ b/WWW/Library/Implementation/HTGroup.c
@@ -82,8 +82,7 @@ PRIVATE void syntax_error ARGS3(FILE *,	 fp,
 	if (cnt < 40) buffer[cnt++] = ch;
     buffer[cnt] = (char)0;
 
-    if (TRACE)
-	fprintf(stderr, "%s %d before: '%s'\nHTGroup.c: %s (got %s)\n",
+    CTRACE(tfp, "%s %d before: '%s'\nHTGroup.c: %s (got %s)\n",
 		"HTGroup.c: Syntax error in rule file at line",
 		HTlex_line, buffer, msg, lex_verbose(lex_item));
     HTlex_line++;
@@ -397,7 +396,7 @@ PRIVATE GroupDefList *parse_group_file ARGS1(FILE *, fp)
 PRIVATE void print_item ARGS1(Item *, item)
 {
     if (!item)
-	fprintf(stderr, "\tNULL-ITEM\n");
+	fprintf(tfp, "\tNULL-ITEM\n");
     else {
 	UserDefList *cur1 = item->user_def_list;
 	AddressDefList *cur2 = item->address_def_list;
@@ -405,20 +404,20 @@ PRIVATE void print_item ARGS1(Item *, item)
 	Ref *addr_ref = (Ref*)HTList_nextObject(cur2);
 
 	if (user_ref) {
-	    fprintf(stderr, "\t[%s%s", user_ref->name,
+	    fprintf(tfp, "\t[%s%s", user_ref->name,
 		    (user_ref->translation ? "*REF*" : ""));
 	    while (NULL != (user_ref = (Ref*)HTList_nextObject(cur1)))
-		fprintf(stderr, "; %s%s", user_ref->name,
+		fprintf(tfp, "; %s%s", user_ref->name,
 			(user_ref->translation ? "*REF*" : ""));
-	    fprintf(stderr, "] ");
-	} else fprintf(stderr, "\tANYBODY ");
+	    fprintf(tfp, "] ");
+	} else fprintf(tfp, "\tANYBODY ");
 
 	if (addr_ref) {
-	    fprintf(stderr, "@ [%s", addr_ref->name);
+	    fprintf(tfp, "@ [%s", addr_ref->name);
 	    while (NULL != (addr_ref = (Ref*)HTList_nextObject(cur2)))
-		fprintf(stderr, "; %s", addr_ref->name);
-	    fprintf(stderr, "]\n");
-	} else fprintf(stderr, "@ ANYADDRESS\n");
+		fprintf(tfp, "; %s", addr_ref->name);
+	    fprintf(tfp, "]\n");
+	} else fprintf(tfp, "@ ANYADDRESS\n");
     }
 }
 
@@ -429,7 +428,7 @@ PRIVATE void print_item_list ARGS1(ItemList *, item_list)
     Item *item;
 
     if (!item_list)
-	fprintf(stderr, "EMPTY");
+	fprintf(tfp, "EMPTY");
     else while (NULL != (item = (Item*)HTList_nextObject(cur)))
 	print_item(item);
 }
@@ -438,15 +437,15 @@ PRIVATE void print_item_list ARGS1(ItemList *, item_list)
 PUBLIC void HTAA_printGroupDef ARGS1(GroupDef *, group_def)
 {
     if (!group_def) {
-	fprintf(stderr, "\nNULL RECORD\n");
+	fprintf(tfp, "\nNULL RECORD\n");
 	return;
     }
 
-    fprintf(stderr, "\nGroup %s:\n",
+    fprintf(tfp, "\nGroup %s:\n",
 	    (group_def->group_name ? group_def->group_name : "NULL"));
 
     print_item_list(group_def->item_list);
-    fprintf(stderr, "\n");
+    fprintf(tfp, "\n");
 }
 
 
@@ -483,6 +482,7 @@ PRIVATE BOOL part_match ARGS2(CONST char *, tcur,
     char actual[4];
     CONST char *cur;
     int cnt;
+    BOOL status;
 
     if (!tcur || !icur) return NO;
 
@@ -498,14 +498,11 @@ PRIVATE BOOL part_match ARGS2(CONST char *, tcur,
 	actual[cnt++] = *(cur++);
     actual[cnt] = (char)0;
 
-    if (TRACE) {
-	BOOL status = HTAA_templateMatch(required, actual);
-	fprintf(stderr, "part_match: req: '%s' act: '%s' match: %s\n",
+    status = HTAA_templateMatch(required, actual);
+    CTRACE(tfp, "part_match: req: '%s' act: '%s' match: %s\n",
 		required, actual, (status ? "yes" : "no"));
-	return status;
-    }
 
-    return HTAA_templateMatch(required, actual);
+    return status;
 }
 
 
@@ -656,21 +653,21 @@ PUBLIC GroupDefList *HTAA_readGroupFile ARGS1(CONST char *, filename)
 
 	while (NULL != (group_cache = (GroupCache*)HTList_nextObject(cur))) {
 	    if (!strcmp(filename, group_cache->group_filename)) {
-		if (TRACE) fprintf(stderr, "%s '%s' %s\n",
-				   "HTAA_readGroupFile: group file",
-				   filename, "already found in cache");
+		CTRACE(tfp, "%s '%s' %s\n",
+			    "HTAA_readGroupFile: group file",
+			    filename, "already found in cache");
 		return group_cache->group_list;
 	    } /* if cache match */
 	} /* while cached files remain */
     } /* cache exists */
 
-    if (TRACE) fprintf(stderr, "HTAA_readGroupFile: reading group file `%s'\n",
-		       filename);
+    CTRACE(tfp, "HTAA_readGroupFile: reading group file `%s'\n",
+	        filename);
 
     if (!(fp = fopen(filename, "r"))) {
-	if (TRACE) fprintf(stderr, "%s '%s'\n",
-			   "HTAA_readGroupFile: unable to open group file",
-			   filename);
+	CTRACE(tfp, "%s '%s'\n",
+		    "HTAA_readGroupFile: unable to open group file",
+		    filename);
 	return NULL;
     }
 
@@ -683,10 +680,9 @@ PUBLIC GroupDefList *HTAA_readGroupFile ARGS1(CONST char *, filename)
     HTList_addObject(group_cache_list, (void*)group_cache);
     fclose(fp);
 
-    if (TRACE) {
-	fprintf(stderr, "Read group file '%s', results follow:\n", filename);
+    CTRACE(tfp, "Read group file '%s', results follow:\n", filename);
+    if (TRACE)
 	print_group_def_list(group_cache->group_list);
-    }
 
     return group_cache->group_list;
 }
diff --git a/WWW/Library/Implementation/HTHistory.c b/WWW/Library/Implementation/HTHistory.c
index 232e4341..bbb87d0a 100644
--- a/WWW/Library/Implementation/HTHistory.c
+++ b/WWW/Library/Implementation/HTHistory.c
@@ -71,10 +71,9 @@ HTAnchor * HTHistory_moveBy
       }
       return destination;
     } else {
-      if (TRACE) fprintf(stderr, 
-      		"HTHistory_moveBy: offset by %+d goes out of list %p.\n",
-		offset, (void*)kids);
-      return NULL;
+        CTRACE(tfp, "HTHistory_moveBy: offset by %+d goes out of list %p.\n",
+		    offset, (void*)kids);
+        return NULL;
     }
   } else {  /* Was a parent */
     return NULL;  /* FIXME we could possibly follow the next link... */
@@ -148,10 +147,11 @@ int HTHistory_count
 */
 
 void HTHistory_leavingFrom
-  ARGS1 (HTAnchor *,anchor)
+    ARGS1 (HTAnchor *,anchor)
 {
-  if (HTList_removeLastObject (history))
-    HTList_addObject (history, anchor);
-  else
-    if (TRACE) fprintf(stderr, "HTHistory_leavingFrom: empty history !\n");
+    if (HTList_removeLastObject (history)) {
+        HTList_addObject (history, anchor);
+    } else {
+        CTRACE(tfp, "HTHistory_leavingFrom: empty history !\n");
+    }
 }
diff --git a/WWW/Library/Implementation/HTList.c b/WWW/Library/Implementation/HTList.c
index 28958181..90b2769c 100644
--- a/WWW/Library/Implementation/HTList.c
+++ b/WWW/Library/Implementation/HTList.c
@@ -63,10 +63,9 @@ PUBLIC void HTList_addObject ARGS2(
 	newNode->next = me->next;
 	me->next = newNode;
 
-    } else if (TRACE) {
-        fprintf(stderr,
-		"HTList: Trying to add object %p to a nonexisting list\n",
-		newObject);
+    } else {
+        CTRACE(tfp, "HTList: Trying to add object %p to a nonexisting list\n",
+		    newObject);
     }
 
     return;
@@ -106,20 +105,14 @@ PUBLIC void HTList_insertObjectAt ARGS3(
     int Pos = pos;
 
     if (!temp) {
-	if (TRACE) {
-	    fprintf(stderr,
-		    "HTList: Trying to add object %p to a nonexisting list\n",
+	CTRACE(tfp, "HTList: Trying to add object %p to a nonexisting list\n",
 		    newObject);
-	}
 	return;
     }
     if (Pos < 0) {
 	Pos = 0;
-	if (TRACE) {
-	    fprintf(stderr,
-		    "HTList: Treating negative object position %d as %d.\n",
+	CTRACE(tfp, "HTList: Treating negative object position %d as %d.\n",
 		    pos, Pos);
-	}
     }
 
     prevNode = temp;
diff --git a/WWW/Library/Implementation/HTMIME.c b/WWW/Library/Implementation/HTMIME.c
index 44a554eb..f619eb81 100644
--- a/WWW/Library/Implementation/HTMIME.c
+++ b/WWW/Library/Implementation/HTMIME.c
@@ -232,17 +232,13 @@ PRIVATE void HTMIME_put_character ARGS2(
 	case 'a':
 	case 'A':
 	    me->state = miA;
-	    if (TRACE)
-		fprintf(stderr,
-		       "HTMIME: Got 'A' at beginning of line, state now A\n");
+	    CTRACE(tfp, "HTMIME: Got 'A' at beginning of line, state now A\n");
 	    break;
 
 	case 'c':
 	case 'C':
 	    me->state = miC;
-	    if (TRACE)
-		fprintf (stderr,
-		       "HTMIME: Got 'C' at beginning of line, state now C\n");
+	    CTRACE (tfp, "HTMIME: Got 'C' at beginning of line, state now C\n");
 	    break;
 
 	case 'd':
@@ -250,17 +246,13 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "ate:";
 	    me->if_ok = miDATE;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf (stderr,
-	      "HTMIME: Got 'D' at beginning of line, checking for 'ate:'\n");
+	    CTRACE (tfp, "HTMIME: Got 'D' at beginning of line, checking for 'ate:'\n");
 	    break;
 
 	case 'e':
 	case 'E':
 	    me->state = miE;
-	    if (TRACE)
-		fprintf (stderr,
-		       "HTMIME: Got 'E' at beginning of line, state now E\n");
+	    CTRACE (tfp, "HTMIME: Got 'E' at beginning of line, state now E\n");
 	    break;
 
 	case 'k':
@@ -268,25 +260,19 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "eep-alive:";
 	    me->if_ok = miKEEP_ALIVE;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-	 "HTMIME: Got 'K' at beginning of line, checking for 'eep-alive:'\n");
+	    CTRACE(tfp, "HTMIME: Got 'K' at beginning of line, checking for 'eep-alive:'\n");
 	    break;
 
 	case 'l':
 	case 'L':
 	    me->state = miL;
-	    if (TRACE)
-		fprintf (stderr,
-		       "HTMIME: Got 'L' at beginning of line, state now L\n");
+	    CTRACE (tfp, "HTMIME: Got 'L' at beginning of line, state now L\n");
 	    break;
 
 	case 'p':
 	case 'P':
 	    me->state = miP;
-	    if (TRACE)
-		fprintf (stderr,
-		       "HTMIME: Got 'P' at beginning of line, state now P\n");
+	    CTRACE (tfp, "HTMIME: Got 'P' at beginning of line, state now P\n");
 	    break;
 
 	case 'r':
@@ -294,49 +280,37 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "etry-after:";
 	    me->if_ok = miRETRY_AFTER;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-	 "HTMIME: Got 'R' at beginning of line, checking for 'etry-after'\n");
+	    CTRACE(tfp, "HTMIME: Got 'R' at beginning of line, checking for 'etry-after'\n");
 	    break;
 
 	case 's':
 	case 'S':
 	    me->state = miS;
-	    if (TRACE)
-		fprintf (stderr,
-		       "HTMIME: Got 'S' at beginning of line, state now S\n");
+	    CTRACE (tfp, "HTMIME: Got 'S' at beginning of line, state now S\n");
 	    break;
 
 	case 't':
 	case 'T':
 	    me->state = miT;
-	    if (TRACE)
-		fprintf (stderr,
-		       "HTMIME: Got 'T' at beginning of line, state now T\n");
+	    CTRACE (tfp, "HTMIME: Got 'T' at beginning of line, state now T\n");
 	    break;
 
 	case 'u':
 	case 'U':
 	    me->state = miU;
-	    if (TRACE)
-		fprintf (stderr,
-		       "HTMIME: Got 'U' at beginning of line, state now U\n");
+	    CTRACE (tfp, "HTMIME: Got 'U' at beginning of line, state now U\n");
 	    break;
 
 	case 'v':
 	case 'V':
 	    me->state = miV;
-	    if (TRACE)
-		fprintf (stderr,
-		       "HTMIME: Got 'V' at beginning of line, state now V\n");
+	    CTRACE (tfp, "HTMIME: Got 'V' at beginning of line, state now V\n");
 	    break;
 
 	case 'w':
 	case 'W':
 	    me->state = miW;
-	    if (TRACE)
-		fprintf (stderr,
-		       "HTMIME: Got 'W' at beginning of line, state now W\n");
+	    CTRACE (tfp, "HTMIME: Got 'W' at beginning of line, state now W\n");
 	    break;
 
 	case '\n':			/* Blank line: End of Header! */
@@ -345,9 +319,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 		if (strchr(HTAtom_name(me->format), ';') != NULL) {
 		    char *cp = NULL, *cp1, *cp2, *cp3 = NULL, *cp4;
 
-		    if (TRACE)
-			fprintf(stderr,
-				"HTMIME: Extended MIME Content-Type is %s\n",
+		    CTRACE(tfp, "HTMIME: Extended MIME Content-Type is %s\n",
 				HTAtom_name(me->format));
 		    StrAllocCopy(cp, HTAtom_name(me->format));
 		    /*
@@ -546,26 +518,17 @@ PRIVATE void HTMIME_put_character ARGS2(
 		StrAllocCopy(me->anchor->content_type,
 			     HTAtom_name(me->format));
 		if (!me->compression_encoding) {
-		    if (TRACE) {
-			fprintf(stderr,
-		    "HTMIME: MIME Content-Type is '%s', converting to '%s'\n",
-			 HTAtom_name(me->format), HTAtom_name(me->targetRep));
-		    }
+		    CTRACE(tfp, "HTMIME: MIME Content-Type is '%s', converting to '%s'\n",
+				HTAtom_name(me->format), HTAtom_name(me->targetRep));
 		} else {
 		    /*
 		    **	Change the format to that for "www/compressed"
 		    **	and set up a stream to deal with it. - FM
 		    */
-		    if (TRACE) {
-			fprintf(stderr,
-	     "HTMIME: MIME Content-Type is '%s',\n", HTAtom_name(me->format));
-		    }
+		    CTRACE(tfp, "HTMIME: MIME Content-Type is '%s',\n", HTAtom_name(me->format));
 		    me->format = HTAtom_for("www/compressed");
-		    if (TRACE) {
-			fprintf(stderr,
-			 "        Treating as '%s'.  Converting to '%s'\n",
-			 HTAtom_name(me->format), HTAtom_name(me->targetRep));
-		    }
+		    CTRACE(tfp, "        Treating as '%s'.  Converting to '%s'\n",
+				HTAtom_name(me->format), HTAtom_name(me->targetRep));
 		}
 		if (me->set_cookie != NULL || me->set_cookie2 != NULL) {
 		    LYSetCookie(me->set_cookie,
@@ -577,8 +540,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 		me->target = HTStreamStack(me->format, me->targetRep,
 					   me->sink , me->anchor);
 		if (!me->target) {
-		    if (TRACE)
-			fprintf(stderr, "HTMIME: Can't translate! ** \n");
+		    CTRACE(tfp, "HTMIME: Can't translate! ** \n");
 		    me->target = me->sink;	/* Cheat */
 		}
 		if (me->target) {
@@ -610,9 +572,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "cept-ranges:";
 	    me->if_ok = miACCEPT_RANGES;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		    "HTMIME: Was A, found C, checking for 'cept-ranges:'\n");
+	    CTRACE(tfp, "HTMIME: Was A, found C, checking for 'cept-ranges:'\n");
 	    break;
 
 	case 'g':
@@ -620,23 +580,18 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "e:";
 	    me->if_ok = miAGE;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was A, found G, checking for 'e:'\n");
+	    CTRACE(tfp, "HTMIME: Was A, found G, checking for 'e:'\n");
 	    break;
 
 	case 'l':
 	case 'L':
 	    me->state = miAL;
-	    if (TRACE)
-		fprintf(stderr, "HTMIME: Was A, found L, state now AL'\n");
+	    CTRACE(tfp, "HTMIME: Was A, found L, state now AL'\n");
 	    break;
 
 	default:
-	   if (TRACE)
-	       fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
-		       c, "'g' or 'l'");
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
+			c, "'g' or 'l'");
 	    goto bad_field_name;
 	    break;
 
@@ -650,9 +605,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "ow:";
 	    me->if_ok = miALLOW;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		      "HTMIME: Was AL, found L, checking for 'ow:'\n");
+	    CTRACE(tfp, "HTMIME: Was AL, found L, checking for 'ow:'\n");
 	    break;
 
 	case 't':
@@ -660,15 +613,11 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "ernates:";
 	    me->if_ok = miALTERNATES;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was AL, found T, checking for 'ernates:'\n");
+	    CTRACE(tfp, "HTMIME: Was AL, found T, checking for 'ernates:'\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, "'l' or 't'");
 	    goto bad_field_name;
 	    break;
@@ -683,23 +632,18 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "che-control:";
 	    me->if_ok = miCACHE_CONTROL;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		     "HTMIME: Was C, found A, checking for 'che-control:'\n");
+	    CTRACE(tfp, "HTMIME: Was C, found A, checking for 'che-control:'\n");
 	    break;
 
 	case 'o':
 	case 'O':
 	    me->state = miCO;
-	    if (TRACE)
-		fprintf(stderr, "HTMIME: Was C, found O, state now CO'\n");
+	    CTRACE(tfp, "HTMIME: Was C, found O, state now CO'\n");
 	    break;
 
 	default:
-	   if (TRACE)
-	       fprintf(stderr,
-		    "HTMIME: Bad character `%c' found where `%s' expected\n",
-		       c, "'a' or 'o'");
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
+			c, "'a' or 'o'");
 	    goto bad_field_name;
 	    break;
 
@@ -711,9 +655,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	case 'n':
 	case 'N':
 	    me->state = miCON;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was CO, found N, state now CON\n");
+	    CTRACE(tfp, "HTMIME: Was CO, found N, state now CON\n");
 	    break;
 
 	case 'o':
@@ -721,15 +663,11 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "kie:";
 	    me->if_ok = miCOOKIE;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was CO, found O, checking for 'kie:'\n");
+	    CTRACE(tfp, "HTMIME: Was CO, found O, checking for 'kie:'\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, "'n' or 'o'");
 	    goto bad_field_name;
 	    break;
@@ -744,9 +682,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "ection:";
 	    me->if_ok = miCONNECTION;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		      "HTMIME: Was CON, found N, checking for 'ection:'\n");
+	    CTRACE(tfp, "HTMIME: Was CON, found N, checking for 'ection:'\n");
 	    break;
 
 	case 't':
@@ -754,15 +690,11 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "ent-";
 	    me->if_ok = miCONTENT_;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was CON, found T, checking for 'ent-'\n");
+	    CTRACE(tfp, "HTMIME: Was CON, found T, checking for 'ent-'\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, "'n' or 't'");
 	    goto bad_field_name;
 	    break;
@@ -777,9 +709,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "ag:";
 	    me->if_ok = miETAG;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was E, found T, checking for 'ag:'\n");
+	    CTRACE(tfp, "HTMIME: Was E, found T, checking for 'ag:'\n");
 	    break;
 
 	case 'x':
@@ -787,15 +717,11 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "pires:";
 	    me->if_ok = miEXPIRES;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was E, found X, checking for 'pires:'\n");
+	    CTRACE(tfp, "HTMIME: Was E, found X, checking for 'pires:'\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, "'t' or 'x'");
 	    goto bad_field_name;
 	    break;
@@ -810,9 +736,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "st-modified:";
 	    me->if_ok = miLAST_MODIFIED;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		     "HTMIME: Was L, found A, checking for 'st-modified:'\n");
+	    CTRACE(tfp, "HTMIME: Was L, found A, checking for 'st-modified:'\n");
 	    break;
 
 	case 'i':
@@ -820,9 +744,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "nk:";
 	    me->if_ok = miLINK;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		     "HTMIME: Was L, found I, checking for 'nk:'\n");
+	    CTRACE(tfp, "HTMIME: Was L, found I, checking for 'nk:'\n");
 	    break;
 
 	case 'o':
@@ -830,15 +752,11 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "cation:";
 	    me->if_ok = miLOCATION;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was L, found O, checking for 'cation:'\n");
+	    CTRACE(tfp, "HTMIME: Was L, found O, checking for 'cation:'\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, "'a', 'i' or 'o'");
 	    goto bad_field_name;
 	    break;
@@ -851,8 +769,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	case 'r':
 	case 'R':
 	    me->state = miPR;
-	    if (TRACE)
-		fprintf(stderr, "HTMIME: Was P, found R, state now PR'\n");
+	    CTRACE(tfp, "HTMIME: Was P, found R, state now PR'\n");
 	    break;
 
 	case 'u':
@@ -860,15 +777,11 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "blic:";
 	    me->if_ok = miPUBLIC;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was P, found U, checking for 'blic:'\n");
+	    CTRACE(tfp, "HTMIME: Was P, found U, checking for 'blic:'\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, "'r' or 'u'");
 	    goto bad_field_name;
 	    break;
@@ -883,9 +796,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "gma:";
 	    me->if_ok = miPRAGMA;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was PR, found A, checking for 'gma'\n");
+	    CTRACE(tfp, "HTMIME: Was PR, found A, checking for 'gma'\n");
 	    break;
 
 	case 'o':
@@ -893,15 +804,11 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "xy-authenticate:";
 	    me->if_ok = miPROXY_AUTHENTICATE;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		 "HTMIME: Was PR, found O, checking for 'xy-authenticate'\n");
+	    CTRACE(tfp, "HTMIME: Was PR, found O, checking for 'xy-authenticate'\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, "'a' or 'o'");
 	    goto bad_field_name;
 	    break;
@@ -916,21 +823,17 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "fe:";
 	    me->if_ok = miSAFE;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr, "HTMIME: Was S, found A, checking for 'fe:'\n");
+	    CTRACE(tfp, "HTMIME: Was S, found A, checking for 'fe:'\n");
 	    break;
 
 	case 'e':
 	case 'E':
 	    me->state = miSE;
-	    if (TRACE)
-		fprintf(stderr, "HTMIME: Was S, found E, state now SE'\n");
+	    CTRACE(tfp, "HTMIME: Was S, found E, state now SE'\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, "'a' or 'e'");
 	    goto bad_field_name;
 	    break;
@@ -945,9 +848,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "ver:";
 	    me->if_ok = miSERVER;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was SE, found R, checking for 'ver'\n");
+	    CTRACE(tfp, "HTMIME: Was SE, found R, checking for 'ver'\n");
 	    break;
 
 	case 't':
@@ -955,15 +856,11 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "-cookie";
 	    me->if_ok = miSET_COOKIE;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		 "HTMIME: Was SE, found T, checking for '-cookie'\n");
+	    CTRACE(tfp, "HTMIME: Was SE, found T, checking for '-cookie'\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, "'r' or 't'");
 	    goto bad_field_name;
 	    break;
@@ -976,24 +873,18 @@ PRIVATE void HTMIME_put_character ARGS2(
 	case ':':
 	    me->field = miSET_COOKIE1;		/* remember it */
 	    me->state = miSKIP_GET_VALUE;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was SET_COOKIE, found :, processing\n");
+	    CTRACE(tfp, "HTMIME: Was SET_COOKIE, found :, processing\n");
 	    break;
 
 	case '2':
 	    me->check_pointer = ":";
 	    me->if_ok = miSET_COOKIE2;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		 "HTMIME: Was SET_COOKIE, found 2, checking for ':'\n");
+	    CTRACE(tfp, "HTMIME: Was SET_COOKIE, found 2, checking for ':'\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, "':' or '2'");
 	    goto bad_field_name;
 	    break;
@@ -1008,9 +899,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "tle:";
 	    me->if_ok = miTITLE;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was T, found I, checking for 'tle:'\n");
+	    CTRACE(tfp, "HTMIME: Was T, found I, checking for 'tle:'\n");
 	    break;
 
 	case 'r':
@@ -1018,15 +907,11 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "ansfer-encoding:";
 	    me->if_ok = miTRANSFER_ENCODING;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		 "HTMIME: Was T, found R, checking for 'ansfer-encoding'\n");
+	    CTRACE(tfp, "HTMIME: Was T, found R, checking for 'ansfer-encoding'\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, "'i' or 'r'");
 	    goto bad_field_name;
 	    break;
@@ -1041,9 +926,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "grade:";
 	    me->if_ok = miUPGRADE;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was U, found P, checking for 'grade:'\n");
+	    CTRACE(tfp, "HTMIME: Was U, found P, checking for 'grade:'\n");
 	    break;
 
 	case 'r':
@@ -1051,15 +934,11 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "i:";
 	    me->if_ok = miURI;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was U, found R, checking for 'i:'\n");
+	    CTRACE(tfp, "HTMIME: Was U, found R, checking for 'i:'\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, "'p' or 'r'");
 	    goto bad_field_name;
 	    break;
@@ -1074,9 +953,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "ry:";
 	    me->if_ok = miVARY;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was V, found A, checking for 'ry:'\n");
+	    CTRACE(tfp, "HTMIME: Was V, found A, checking for 'ry:'\n");
 	    break;
 
 	case 'i':
@@ -1084,15 +961,11 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "a:";
 	    me->if_ok = miVIA;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was V, found I, checking for 'a:'\n");
+	    CTRACE(tfp, "HTMIME: Was V, found I, checking for 'a:'\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, "'a' or 'i'");
 	    goto bad_field_name;
 	    break;
@@ -1107,9 +980,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "rning:";
 	    me->if_ok = miWARNING;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was W, found A, checking for 'rning:'\n");
+	    CTRACE(tfp, "HTMIME: Was W, found A, checking for 'rning:'\n");
 	    break;
 
 	case 'w':
@@ -1117,15 +988,11 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "w-authenticate:";
 	    me->if_ok = miWWW_AUTHENTICATE;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		  "HTMIME: Was W, found W, checking for 'w-authenticate:'\n");
+	    CTRACE(tfp, "HTMIME: Was W, found W, checking for 'w-authenticate:'\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, "'a' or 'w'");
 	    goto bad_field_name;
 	    break;
@@ -1138,27 +1005,22 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    if (!*me->check_pointer)
 		me->state = me->if_ok;
 	} else {		/* Error */
-	    if (TRACE)
-		fprintf(stderr,
-		    "HTMIME: Bad character `%c' found where `%s' expected\n",
+	    CTRACE(tfp, "HTMIME: Bad character `%c' found where `%s' expected\n",
 			c, me->check_pointer - 1);
 	    goto bad_field_name;
 	}
 	break;
 
     case miCONTENT_:
-	if (TRACE)
-	   fprintf (stderr,
-		 "HTMIME: in case CONTENT_\n");
+	CTRACE (tfp, "HTMIME: in case CONTENT_\n");
+
 	switch(c) {
 	case 'b':
 	case 'B':
 	    me->check_pointer = "ase:";
 	    me->if_ok = miCONTENT_BASE;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		      "HTMIME: Was CONTENT_, found B, checking for 'ase:'\n");
+	    CTRACE(tfp, "HTMIME: Was CONTENT_, found B, checking for 'ase:'\n");
 	    break;
 
 	case 'd':
@@ -1166,9 +1028,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "isposition:";
 	    me->if_ok = miCONTENT_DISPOSITION;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		"HTMIME: Was CONTENT_, found D, checking for 'isposition:'\n");
+	    CTRACE(tfp, "HTMIME: Was CONTENT_, found D, checking for 'isposition:'\n");
 	    break;
 
 	case 'e':
@@ -1176,9 +1036,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "ncoding:";
 	    me->if_ok = miCONTENT_ENCODING;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		  "HTMIME: Was CONTENT_, found E, checking for 'ncoding:'\n");
+	    CTRACE(tfp, "HTMIME: Was CONTENT_, found E, checking for 'ncoding:'\n");
 	    break;
 
 	case 'f':
@@ -1186,17 +1044,13 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "eatures:";
 	    me->if_ok = miCONTENT_FEATURES;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		  "HTMIME: Was CONTENT_, found F, checking for 'eatures:'\n");
+	    CTRACE(tfp, "HTMIME: Was CONTENT_, found F, checking for 'eatures:'\n");
 	    break;
 
 	case 'l':
 	case 'L':
 	    me->state = miCONTENT_L;
-	    if (TRACE)
-		fprintf (stderr,
-		     "HTMIME: Was CONTENT_, found L, state now CONTENT_L\n");
+	    CTRACE (tfp, "HTMIME: Was CONTENT_, found L, state now CONTENT_L\n");
 	    break;
 
 	case 'm':
@@ -1204,9 +1058,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "d5:";
 	    me->if_ok = miCONTENT_MD5;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		      "HTMIME: Was CONTENT_, found M, checking for 'd5:'\n");
+	    CTRACE(tfp, "HTMIME: Was CONTENT_, found M, checking for 'd5:'\n");
 	    break;
 
 	case 'r':
@@ -1214,23 +1066,17 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "ange:";
 	    me->if_ok = miCONTENT_RANGE;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		    "HTMIME: Was CONTENT_, found R, checking for 'ange:'\n");
+	    CTRACE(tfp, "HTMIME: Was CONTENT_, found R, checking for 'ange:'\n");
 	    break;
 
 	case 't':
 	case 'T':
 	    me->state = miCONTENT_T;
-	    if (TRACE)
-		fprintf(stderr,
-		    "HTMIME: Was CONTENT_, found T, state now CONTENT_T\n");
+	    CTRACE(tfp, "HTMIME: Was CONTENT_, found T, state now CONTENT_T\n");
 	    break;
 
 	default:
-	    if (TRACE)
-		fprintf(stderr,
-			"HTMIME: Was CONTENT_, found nothing; bleah\n");
+	    CTRACE(tfp, "HTMIME: Was CONTENT_, found nothing; bleah\n");
 	    goto bad_field_name;
 	    break;
 
@@ -1238,18 +1084,15 @@ PRIVATE void HTMIME_put_character ARGS2(
 	break;
 
     case miCONTENT_L:
-      if (TRACE)
-	fprintf (stderr,
-		 "HTMIME: in case CONTENT_L\n");
+	CTRACE (tfp, "HTMIME: in case CONTENT_L\n");
+
       switch(c) {
 	case 'a':
 	case 'A':
 	    me->check_pointer = "nguage:";
 	    me->if_ok = miCONTENT_LANGUAGE;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Was CONTENT_L, found A, checking for 'nguage:'\n");
+	    CTRACE(tfp, "HTMIME: Was CONTENT_L, found A, checking for 'nguage:'\n");
 	    break;
 
 	case 'e':
@@ -1257,9 +1100,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "ngth:";
 	    me->if_ok = miCONTENT_LENGTH;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Was CONTENT_L, found E, checking for 'ngth:'\n");
+	    CTRACE(tfp, "HTMIME: Was CONTENT_L, found E, checking for 'ngth:'\n");
 	    break;
 
 	case 'o':
@@ -1267,15 +1108,11 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "cation:";
 	    me->if_ok = miCONTENT_LOCATION;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Was CONTENT_L, found O, checking for 'cation:'\n");
+	    CTRACE(tfp, "HTMIME: Was CONTENT_L, found O, checking for 'cation:'\n");
 	    break;
 
 	default:
-	  if (TRACE)
-	    fprintf (stderr,
-		     "HTMIME: Was CONTENT_L, found nothing; bleah\n");
+	    CTRACE (tfp, "HTMIME: Was CONTENT_L, found nothing; bleah\n");
 	    goto bad_field_name;
 	    break;
 
@@ -1283,18 +1120,15 @@ PRIVATE void HTMIME_put_character ARGS2(
 	break;
 
     case miCONTENT_T:
-      if (TRACE)
-	fprintf (stderr,
-		 "HTMIME: in case CONTENT_T\n");
+	CTRACE (tfp, "HTMIME: in case CONTENT_T\n");
+
       switch(c) {
 	case 'r':
 	case 'R':
 	    me->check_pointer = "ansfer-encoding:";
 	    me->if_ok = miCONTENT_TRANSFER_ENCODING;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-	 "HTMIME: Was CONTENT_T, found R, checking for 'ansfer-encoding:'\n");
+	    CTRACE(tfp, "HTMIME: Was CONTENT_T, found R, checking for 'ansfer-encoding:'\n");
 	    break;
 
 	case 'y':
@@ -1302,15 +1136,11 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    me->check_pointer = "pe:";
 	    me->if_ok = miCONTENT_TYPE;
 	    me->state = miCHECK;
-	    if (TRACE)
-		fprintf(stderr,
-		   "HTMIME: Was CONTENT_T, found Y, checking for 'pe:'\n");
+	    CTRACE(tfp, "HTMIME: Was CONTENT_T, found Y, checking for 'pe:'\n");
 	    break;
 
 	default:
-	  if (TRACE)
-	    fprintf (stderr,
-		     "HTMIME: Was CONTENT_T, found nothing; bleah\n");
+	    CTRACE (tfp, "HTMIME: Was CONTENT_T, found nothing; bleah\n");
 	    goto bad_field_name;
 	    break;
 
@@ -1391,37 +1221,27 @@ PRIVATE void HTMIME_put_character ARGS2(
 	    switch (me->field) {
 	    case miACCEPT_RANGES:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Accept-Ranges: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Accept-Ranges: '%s'\n",
 			    me->value);
 		break;
 	    case miAGE:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Age: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Age: '%s'\n",
 			    me->value);
 		break;
 	    case miALLOW:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Allow: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Allow: '%s'\n",
 			    me->value);
 		break;
 	    case miALTERNATES:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Alternates: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Alternates: '%s'\n",
 			    me->value);
 		break;
 	    case miCACHE_CONTROL:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Cache-Control: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Cache-Control: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1474,23 +1294,17 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miCOOKIE:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Cookie: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Cookie: '%s'\n",
 			    me->value);
 		break;
 	    case miCONNECTION:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Connection: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Connection: '%s'\n",
 			    me->value);
 		break;
 	    case miCONTENT_BASE:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Content-Base: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Content-Base: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1501,9 +1315,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miCONTENT_DISPOSITION:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Content-Disposition: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Content-Disposition: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1553,9 +1365,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miCONTENT_ENCODING:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-		       "HTMIME: PICKED UP Content-Encoding: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Content-Encoding: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value) ||
 		    !strcasecomp(me->value, "identity"))
@@ -1574,9 +1384,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 		    **	Some server indicated "8bit", "7bit" or "binary"
 		    **	inappropriately.  We'll ignore it. - FM
 		    */
-		    if (TRACE)
-			fprintf(stderr,
-				"                Ignoring it!\n");
+		    CTRACE(tfp, "                Ignoring it!\n");
 		} else {
 		    /*
 		    **	Save it to use as a flag for setting
@@ -1587,16 +1395,12 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miCONTENT_FEATURES:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Content-Features: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Content-Features: '%s'\n",
 			    me->value);
 		break;
 	    case miCONTENT_LANGUAGE:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Content-Language: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Content-Language: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1609,9 +1413,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miCONTENT_LENGTH:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Content-Length: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Content-Length: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1621,16 +1423,12 @@ PRIVATE void HTMIME_put_character ARGS2(
 		me->anchor->content_length = atoi(me->value);
 		if (me->anchor->content_length < 0)
 		    me->anchor->content_length = 0;
-		if (TRACE)
-		    fprintf(stderr,
-			    "        Converted to integer: '%d'\n",
+		CTRACE(tfp, "        Converted to integer: '%d'\n",
 			    me->anchor->content_length);
 		break;
 	    case miCONTENT_LOCATION:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Content-Location: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Content-Location: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1641,9 +1439,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miCONTENT_MD5:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Content-MD5: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Content-MD5: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1654,16 +1450,12 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miCONTENT_RANGE:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Content-Range: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Content-Range: '%s'\n",
 			    me->value);
 		break;
 	    case miCONTENT_TRANSFER_ENCODING:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			"HTMIME: PICKED UP Content-Transfer-Encoding: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Content-Transfer-Encoding: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1677,9 +1469,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miCONTENT_TYPE:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Content-Type: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Content-Type: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1697,9 +1487,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miDATE:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Date: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Date: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1710,16 +1498,12 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miETAG:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP ETag: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP ETag: '%s'\n",
 			    me->value);
 		break;
 	    case miEXPIRES:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Expires: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Expires: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1730,16 +1514,12 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miKEEP_ALIVE:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Keep-Alive: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Keep-Alive: '%s'\n",
 			    me->value);
 		break;
 	    case miLAST_MODIFIED:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Last-Modified: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Last-Modified: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1750,23 +1530,17 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miLINK:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Link: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Link: '%s'\n",
 			    me->value);
 		break;
 	    case miLOCATION:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Location: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Location: '%s'\n",
 			    me->value);
 		break;
 	    case miPRAGMA:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Pragma: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Pragma: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1778,30 +1552,22 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miPROXY_AUTHENTICATE:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Proxy-Authenticate: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Proxy-Authenticate: '%s'\n",
 			    me->value);
 		break;
 	    case miPUBLIC:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Public: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Public: '%s'\n",
 			    me->value);
 		break;
 	    case miRETRY_AFTER:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Retry-After: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Retry-After: '%s'\n",
 			    me->value);
 		break;
 	    case miSAFE:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Safe: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Safe: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1815,9 +1581,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miSERVER:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Server: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Server: '%s'\n",
 			    me->value);
 		if (!(me->value && *me->value))
 		    break;
@@ -1828,9 +1592,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miSET_COOKIE1:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Set-Cookie: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Set-Cookie: '%s'\n",
 			    me->value);
 		if (me->set_cookie == NULL) {
 		    StrAllocCopy(me->set_cookie, me->value);
@@ -1841,9 +1603,7 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miSET_COOKIE2:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Set-Cookie2: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Set-Cookie2: '%s'\n",
 			    me->value);
 		if (me->set_cookie2 == NULL) {
 		    StrAllocCopy(me->set_cookie2, me->value);
@@ -1854,58 +1614,42 @@ PRIVATE void HTMIME_put_character ARGS2(
 		break;
 	    case miTITLE:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Title: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Title: '%s'\n",
 			    me->value);
 		break;
 	    case miTRANSFER_ENCODING:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Transfer-Encoding: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Transfer-Encoding: '%s'\n",
 			    me->value);
 		break;
 	    case miUPGRADE:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Upgrade: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Upgrade: '%s'\n",
 			    me->value);
 		break;
 	    case miURI:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP URI: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP URI: '%s'\n",
 			    me->value);
 		break;
 	    case miVARY:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Vary: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Vary: '%s'\n",
 			    me->value);
 		break;
 	    case miVIA:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Via: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Via: '%s'\n",
 			    me->value);
 		break;
 	    case miWARNING:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP Warning: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP Warning: '%s'\n",
 			    me->value);
 		break;
 	    case miWWW_AUTHENTICATE:
 		HTMIME_TrimDoubleQuotes(me->value);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTMIME: PICKED UP WWW-Authenticate: '%s'\n",
+		CTRACE(tfp, "HTMIME: PICKED UP WWW-Authenticate: '%s'\n",
 			    me->value);
 		break;
 	    default:		/* Should never get here */
@@ -1934,8 +1678,7 @@ PRIVATE void HTMIME_put_character ARGS2(
     return;
 
 value_too_long:
-    if (TRACE)
-	fprintf(stderr, "HTMIME: *** Syntax error. (string too long)\n");
+    CTRACE(tfp, "HTMIME: *** Syntax error. (string too long)\n");
 
 bad_field_name: 			/* Ignore it */
     me->state = miJUNK_LINE;
@@ -1960,8 +1703,7 @@ PRIVATE void HTMIME_put_string ARGS2(
 	(*me->targetClass.put_string)(me->target,s);
 
     } else if (me->state != MIME_IGNORE) {
-	if (TRACE)
-	    fprintf(stderr, "HTMIME:  %s\n", s);
+	CTRACE(tfp, "HTMIME:  %s\n", s);
 
 	for (p=s; *p; p++)
 	    HTMIME_put_character(me, *p);
@@ -1983,8 +1725,7 @@ PRIVATE void HTMIME_write ARGS3(
 	(*me->targetClass.put_block)(me->target, s, l);
 
     } else {
-	if (TRACE)
-	    fprintf(stderr, "HTMIME:  %.*s\n", l, s);
+	CTRACE(tfp, "HTMIME:  %.*s\n", l, s);
 
 	for (p = s; p < s+l; p++)
 	    HTMIME_put_character(me, *p);
diff --git a/WWW/Library/Implementation/HTMLDTD.c b/WWW/Library/Implementation/HTMLDTD.c
index bf7a54b7..4b0049d6 100644
--- a/WWW/Library/Implementation/HTMLDTD.c
+++ b/WWW/Library/Implementation/HTMLDTD.c
@@ -1597,7 +1597,7 @@ PUBLIC void HTSwitchDTD ARGS1(
     BOOL,		new)
 {
     if (TRACE)
-	fprintf(stderr,"HTMLDTD: Copying DTD element info of size %d, %d * %d\n",
+	CTRACE(tfp,"HTMLDTD: Copying DTD element info of size %d, %d * %d\n",
 		new ? sizeof(tags_new) : sizeof(tags_old),
 		HTML_ELEMENTS, sizeof(HTTag));
     if (new)
diff --git a/WWW/Library/Implementation/HTNews.c b/WWW/Library/Implementation/HTNews.c
index 89048385..d450d901 100644
--- a/WWW/Library/Implementation/HTNews.c
+++ b/WWW/Library/Implementation/HTNews.c
@@ -189,17 +189,16 @@ PRIVATE BOOL initialize NOARGS
 #else
     if (getenv("NNTPSERVER")) {
 	StrAllocCopy(HTNewsHost, (char *)getenv("NNTPSERVER"));
-	if (TRACE) fprintf(stderr, "HTNews: NNTPSERVER defined as `%s'\n",
-		HTNewsHost);
+	CTRACE(tfp, "HTNews: NNTPSERVER defined as `%s'\n",
+		    HTNewsHost);
     } else {
 	char server_name[256];
 	FILE* fp = fopen(SERVER_FILE, "r");
 	if (fp) {
 	    if (fscanf(fp, "%s", server_name)==1) {
 		StrAllocCopy(HTNewsHost, server_name);
-		if (TRACE) fprintf(stderr,
-		"HTNews: File %s defines news host as `%s'\n",
-			SERVER_FILE, HTNewsHost);
+		CTRACE(tfp, "HTNews: File %s defines news host as `%s'\n",
+			    SERVER_FILE, HTNewsHost);
 	    }
 	    fclose(fp);
 	}
@@ -232,7 +231,7 @@ PRIVATE int response ARGS1(CONST char *,command)
     if (command) {
 	int status;
 	int length = strlen(command);
-	if (TRACE) fprintf(stderr, "NNTP command to be sent: %s", command);
+	CTRACE(tfp, "NNTP command to be sent: %s", command);
 #ifdef NOT_ASCII
 	{
 	    CONST char	* p;
@@ -247,8 +246,7 @@ PRIVATE int response ARGS1(CONST char *,command)
 	status = NEWS_NETWRITE(s, (char *)command, length);
 #endif /* NOT_ASCII */
 	if (status < 0){
-	    if (TRACE) fprintf(stderr,
-		"HTNews: Unable to send command. Disconnecting.\n");
+	    CTRACE(tfp, "HTNews: Unable to send command. Disconnecting.\n");
 	    NEWS_NETCLOSE(s);
 	    s = -1;
 	    return status;
@@ -259,24 +257,19 @@ PRIVATE int response ARGS1(CONST char *,command)
 	if (((*p++ = NEXT_CHAR) == LF) ||
 	    (p == &response_text[LINE_LENGTH])) {
 	    *--p = '\0';			/* Terminate the string */
-	    if (TRACE)
-		fprintf(stderr, "NNTP Response: %s\n", response_text);
+	    CTRACE(tfp, "NNTP Response: %s\n", response_text);
 	    sscanf(response_text, "%d", &result);
 	    return result;
 	} /* if end of line */
 
 	if ((ch = *(p-1)) == (char)EOF) {
 	    *(p-1) = '\0';
-	    if (TRACE) {
-		if (interrupted_in_htgetcharacter) {
-		    fprintf(stderr,
-			    "HTNews: Interrupted on read, closing socket %d\n",
+	    if (interrupted_in_htgetcharacter) {
+		CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
 			    s);
-		} else {
-		    fprintf(stderr,
-			    "HTNews: EOF on read, closing socket %d\n",
+	    } else {
+		CTRACE(tfp, "HTNews: EOF on read, closing socket %d\n",
 			    s);
-		}
 	    }
 	    NEWS_NETCLOSE(s);	/* End of file, close socket */
 	    s = -1;
@@ -560,8 +553,7 @@ PRIVATE char * author_name ARGS1 (char *,email)
     char *p, *e;
 
     StrAllocCopy(name, email);
-    if (TRACE)
-	fprintf(stderr,"Trying to find name in: %s\n",name);
+    CTRACE(tfp,"Trying to find name in: %s\n",name);
 
     if ((p = strchr(name, '(')) && (e = strchr(name, ')'))) {
 	if (e > p) {
@@ -598,8 +590,7 @@ PRIVATE char * author_address ARGS1(char *,email)
     char *p, *at, *e;
 
     StrAllocCopy(address, email);
-    if (TRACE)
-	fprintf(stderr,"Trying to find address in: %s\n",address);
+    CTRACE(tfp,"Trying to find address in: %s\n",address);
 
     if ((p = strchr(address, '<'))) {
 	if ((e = strchr(p, '>')) && (at = strchr(p, '@'))) {
@@ -770,9 +761,7 @@ PRIVATE void write_anchors ARGS1 (char *,text)
 */
 PRIVATE void abort_socket NOARGS
 {
-    if (TRACE)
-	fprintf(stderr,
-		"HTNews: EOF on read, closing socket %d\n", s);
+    CTRACE(tfp, "HTNews: EOF on read, closing socket %d\n", s);
     NEWS_NETCLOSE(s);	/* End of file, close socket */
     PUTS("Network Error: connection lost");
     PUTC('\n');
@@ -983,9 +972,7 @@ PRIVATE int read_article NOARGS
 	    if (ch == (char)EOF) {
 		if (interrupted_in_htgetcharacter) {
 		    interrupted_in_htgetcharacter = 0;
-		    if (TRACE)
-			fprintf(stderr,
-			   "HTNews: Interrupted on read, closing socket %d\n",
+		    CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
 				s);
 		    NEWS_NETCLOSE(s);
 		    s = -1;
@@ -996,8 +983,7 @@ PRIVATE int read_article NOARGS
 	    }
 	    if ((ch == LF) || (p == &line[LINE_LENGTH])) {
 		*--p = '\0';			/* Terminate the string */
-		if (TRACE)
-		    fprintf(stderr, "H %s\n", line);
+		CTRACE(tfp, "H %s\n", line);
 
 		if (line[0] == '\t' || line[0] == ' ') {
 		    int i = 0;
@@ -1253,9 +1239,7 @@ PRIVATE int read_article NOARGS
 	if (ch == (char)EOF) {
 	    if (interrupted_in_htgetcharacter) {
 		interrupted_in_htgetcharacter = 0;
-		if (TRACE)
-		    fprintf(stderr,
-			  "HTNews: Interrupted on read, closing socket %d\n",
+		CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
 			    s);
 		NEWS_NETCLOSE(s);
 		s = -1;
@@ -1266,8 +1250,7 @@ PRIVATE int read_article NOARGS
 	}
 	if ((ch == LF) || (p == &line[LINE_LENGTH])) {
 	    *p++ = '\0';			/* Terminate the string */
-	    if (TRACE)
-		fprintf(stderr, "B %s", line);
+	    CTRACE(tfp, "B %s", line);
 	    if (line[0] == '.') {
 		/*
 		**  End of article?
@@ -1460,9 +1443,7 @@ PRIVATE int read_list ARGS1(char *, arg)
 	if (ch == (char)EOF) {
 	    if (interrupted_in_htgetcharacter) {
 		interrupted_in_htgetcharacter = 0;
-		if (TRACE)
-		    fprintf(stderr,
-			  "HTNews: Interrupted on read, closing socket %d\n",
+		CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
 			    s);
 		NEWS_NETCLOSE(s);
 		s = -1;
@@ -1482,9 +1463,7 @@ PRIVATE int read_list ARGS1(char *, arg)
 		continue;
 	    }
 	} else if (p == &line[LINE_LENGTH]) {
-	    if (TRACE) {
-		fprintf(stderr, "b %.*s%c[...]\n", (LINE_LENGTH), line, ch);
-	    }
+	    CTRACE(tfp, "b %.*s%c[...]\n", (LINE_LENGTH), line, ch);
 	    *p = '\0';
 	    if (ch == LF) {
 		;		/* Will be dealt with below */
@@ -1494,9 +1473,7 @@ PRIVATE int read_list ARGS1(char *, arg)
 	    } else if (strchr(line, ' ') == NULL &&
 		       strchr(line, '\t') == NULL) {
 		/* No separator found */
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTNews..... group name too long, discarding.\n");
+		CTRACE(tfp, "HTNews..... group name too long, discarding.\n");
 		skip_this_line = YES; /* ignore whole line */
 		continue;
 	    } else {
@@ -1508,8 +1485,7 @@ PRIVATE int read_list ARGS1(char *, arg)
 	if (ch == LF) {
 	    skip_rest_of_line = NO;	/* done, reset flag */
 	    *p = '\0';			/* Terminate the string */
-	    if (TRACE)
-		fprintf(stderr, "B %s", line);
+	    CTRACE(tfp, "B %s", line);
 	    if (line[0] == '.') {
 		/*
 		**  End of article?
@@ -1617,9 +1593,7 @@ PRIVATE int read_group ARGS3(
     PUTC('\n');
 
     sscanf(response_text, " %d %d %d %d", &status, &count, &first, &last);
-    if (TRACE)
-	fprintf(stderr,
-		"Newsgroup status=%d, count=%d, (%d-%d) required:(%d-%d)\n",
+    CTRACE(tfp, "Newsgroup status=%d, count=%d, (%d-%d) required:(%d-%d)\n",
 		status, count, first, last, first_required, last_required);
     if (last == 0) {
 	PUTS("\nNo articles in this group.\n");
@@ -1642,9 +1616,8 @@ PRIVATE int read_group ARGS3(
     if (last_required-first_required+1 > HTNewsMaxChunk) { /* Trim this block */
 	first_required = last_required-HTNewsChunkSize+1;
     }
-    if (TRACE)
-	fprintf(stderr, "    Chunk will be (%d-%d)\n",
-			first_required, last_required);
+    CTRACE(tfp, "    Chunk will be (%d-%d)\n",
+		first_required, last_required);
 
     /*
     **	Set window title.
@@ -1667,8 +1640,7 @@ PRIVATE int read_group ARGS3(
 	    before = first_required-HTNewsChunkSize;
 	sprintf(buffer, "%s%s/%d-%d", NewsHREF, groupName,
 				      before, first_required-1);
-	if (TRACE)
-	    fprintf(stderr, "    Block before is %s\n", buffer);
+	CTRACE(tfp, "    Block before is %s\n", buffer);
 	PUTC('(');
 	start_anchor(buffer);
 	PUTS("Earlier articles");
@@ -1696,9 +1668,7 @@ PRIVATE int read_group ARGS3(
 		if (ch == (char)EOF) {
 		    if (interrupted_in_htgetcharacter) {
 			interrupted_in_htgetcharacter = 0;
-			if (TRACE)
-			    fprintf(stderr,
-			   "HTNews: Interrupted on read, closing socket %d\n",
+			CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
 				    s);
 			NEWS_NETCLOSE(s);
 			s = -1;
@@ -1709,8 +1679,7 @@ PRIVATE int read_group ARGS3(
 		}
 		if ((ch == '\n') || (p == &line[LINE_LENGTH])) {
 		    *p = '\0';		/* Terminate the string */
-		    if (TRACE)
-			fprintf(stderr, "X %s", line);
+		    CTRACE(tfp, "X %s", line);
 		    if (line[0] == '.') {
 			/*
 			**  End of article?
@@ -1802,9 +1771,7 @@ PRIVATE int read_group ARGS3(
 		    if (ch == (char)EOF) {
 			if (interrupted_in_htgetcharacter) {
 			    interrupted_in_htgetcharacter = 0;
-			    if (TRACE)
-				fprintf(stderr,
-			   "HTNews: Interrupted on read, closing socket %d\n",
+			    CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
 					s);
 			    NEWS_NETCLOSE(s);
 			    s = -1;
@@ -1818,8 +1785,7 @@ PRIVATE int read_group ARGS3(
 
 			*--p = '\0';		/* Terminate  & chop LF*/
 			p = line;		/* Restart at beginning */
-			if (TRACE)
-			    fprintf(stderr, "G %s\n", line);
+			CTRACE(tfp, "G %s\n", line);
 			switch(line[0]) {
 
 			case '.':
@@ -1913,9 +1879,7 @@ PRIVATE int read_group ARGS3(
 		*/
 	    } else if (status == HT_INTERRUPTED) {
 		interrupted_in_htgetcharacter = 0;
-		if (TRACE)
-		    fprintf(stderr,
-			  "HTNews: Interrupted on read, closing socket %d\n",
+		CTRACE(tfp, "HTNews: Interrupted on read, closing socket %d\n",
 			    s);
 		NEWS_NETCLOSE(s);
 		s = -1;
@@ -1957,8 +1921,7 @@ PRIVATE int read_group ARGS3(
 	else
 	    sprintf(buffer, "%s%s/%d-%d", NewsHREF, groupName,
 					  last_required+1, after);
-	if (TRACE)
-	    fprintf(stderr, "    Block after is %s\n", buffer);
+	CTRACE(tfp, "    Block after is %s\n", buffer);
 	PUTC('(');
 	start_anchor(buffer);
 	PUTS("Later articles");
@@ -2029,7 +1992,7 @@ PRIVATE int HTLoadNews ARGS4(
 		  format_out == HTAtom_for("www/dump"));
     rawtext = NO;
 
-    if (TRACE) fprintf(stderr, "HTNews: Looking for %s\n", arg);
+    CTRACE(tfp, "HTNews: Looking for %s\n", arg);
 
     if (!initialized)
 	initialized = initialize();
@@ -2230,9 +2193,7 @@ PRIVATE int HTLoadNews ARGS4(
 	    command[258] = '\0';
 	    FREE(cp);
 	    sprintf(proxycmd, "GET %.251s%c%c%c%c", command, CR, LF, CR, LF);
-	    if (TRACE)
-		fprintf(stderr,
-			"HTNews: Proxy command is '%.*s'\n",
+	    CTRACE(tfp, "HTNews: Proxy command is '%.*s'\n",
 			(int)(strlen(proxycmd) - 4), proxycmd);
 	    strcat(command, "/");
 	    StrAllocCopy(ProxyHREF, NewsHREF);
@@ -2374,8 +2335,7 @@ PRIVATE int HTLoadNews ARGS4(
 	    } else {
 		sprintf (url, "%.259s", NewsHREF);
 	    }
-	    if (TRACE)
-		fprintf (stderr, "News: doing HTDoConnect on '%s'\n", url);
+	    CTRACE (tfp, "News: doing HTDoConnect on '%s'\n", url);
 
 	    _HTProgress("Connecting to NewsHost ...");
 
@@ -2384,9 +2344,7 @@ PRIVATE int HTLoadNews ARGS4(
 		/*
 		**  Interrupt cleanly.
 		*/
-		if (TRACE)
-		    fprintf(stderr,
-		     "HTNews: Interrupted on connect; recovering cleanly.\n");
+		CTRACE(tfp, "HTNews: Interrupted on connect; recovering cleanly.\n");
 		_HTProgress("Connection interrupted.");
 		if (!(post_wanted || reply_wanted ||
 		      spost_wanted || sreply_wanted)) {
@@ -2412,9 +2370,7 @@ PRIVATE int HTLoadNews ARGS4(
 		char message[256];
 		NEWS_NETCLOSE(s);
 		s = -1;
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTNews: Unable to connect to news host.\n");
+		CTRACE(tfp, "HTNews: Unable to connect to news host.\n");
 		if (retries < 1)
 		    continue;
 		sprintf(message, "Could not access %s.", NewsHost);
@@ -2434,15 +2390,12 @@ PRIVATE int HTLoadNews ARGS4(
 		}
 		return HTLoadError(stream, 500, message);
 	    } else {
-		if (TRACE)
-		    fprintf(stderr, "HTNews: Connected to news host %s.\n",
-				    NewsHost);
+		CTRACE(tfp, "HTNews: Connected to news host %s.\n",
+			    NewsHost);
 		HTInitInput(s); 	/* set up buffering */
 		if (proxycmd[0]) {
 		    status = NEWS_NETWRITE(s, proxycmd, strlen(proxycmd));
-		    if (TRACE)
-			fprintf(stderr,
-			     "HTNews: Proxy command returned status '%d'.\n",
+		    CTRACE(tfp, "HTNews: Proxy command returned status '%d'.\n",
 				status);
 		}
 		if (((status = response(NULL)) / 100) != 2) {
diff --git a/WWW/Library/Implementation/HTParse.c b/WWW/Library/Implementation/HTParse.c
index 97d3f5ea..d75b1fde 100644
--- a/WWW/Library/Implementation/HTParse.c
+++ b/WWW/Library/Implementation/HTParse.c
@@ -190,9 +190,7 @@ PUBLIC char * HTParse ARGS3(
     char * acc_method;
     struct struct_parts given, related;
 
-    if (TRACE)
-	fprintf(stderr,
-		"HTParse: aName:%s   relatedName:%s\n", aName, relatedName);
+    CTRACE(tfp, "HTParse: aName:%s   relatedName:%s\n", aName, relatedName);
 
     /*
     **	Allocate the output string.
@@ -365,8 +363,7 @@ PUBLIC char * HTParse ARGS3(
 	    if (wanted & PARSE_PUNCTUATION)
 		strcat(result, "/");
 	    strcat(result, given.absolute);
-	    if (TRACE)
-		fprintf(stderr, "1\n");
+	    CTRACE(tfp, "1\n");
 	} else if (related.absolute) {		/* Adopt path not name */
 	    strcat(result, "/");
 	    strcat(result, related.absolute);
@@ -380,16 +377,13 @@ PUBLIC char * HTParse ARGS3(
 		strcat(result, given.relative); /* Add given one */
 		HTSimplify (result);
 	    }
-	    if (TRACE)
-		fprintf(stderr, "2\n");
+	    CTRACE(tfp, "2\n");
 	} else if (given.relative) {
 	    strcat(result, given.relative);		/* what we've got */
-	    if (TRACE)
-		fprintf(stderr, "3\n");
+	    CTRACE(tfp, "3\n");
 	} else if (related.relative) {
 	    strcat(result, related.relative);
-	    if (TRACE)
-		fprintf(stderr, "4\n");
+	    CTRACE(tfp, "4\n");
 	} else {  /* No inheritance */
 	    if (strncasecomp(aName, "lynxcgi:", 8) &&
 		strncasecomp(aName, "lynxexec:", 9) &&
@@ -398,8 +392,7 @@ PUBLIC char * HTParse ARGS3(
 	    }
 	    if (!strcmp(result, "news:/"))
 		result[5] = '*';
-	    if (TRACE)
-		fprintf(stderr, "5\n");
+	    CTRACE(tfp, "5\n");
 	}
     }
 
@@ -414,8 +407,7 @@ PUBLIC char * HTParse ARGS3(
 	    strcat(result, (given.anchor) ?
 			     given.anchor : related.anchor);
 	}
-    if (TRACE)
-	fprintf(stderr, "HTParse: result:%s\n", result);
+    CTRACE(tfp, "HTParse: result:%s\n", result);
     FREE(rel);
     FREE(name);
 
@@ -647,8 +639,7 @@ PUBLIC char * HTRelative ARGS2(
 	    strcat(result, "../");
 	strcat(result, last_slash+1);
     }
-    if (TRACE)
-	fprintf(stderr, "HT: `%s' expressed relative to\n    `%s' is\n   `%s'.",
+    CTRACE(tfp, "HT: `%s' expressed relative to\n    `%s' is\n   `%s'.",
 		aName, relatedName, result);
     return result;
 }
diff --git a/WWW/Library/Implementation/HTPasswd.c b/WWW/Library/Implementation/HTPasswd.c
index 45a53aee..f8494417 100644
--- a/WWW/Library/Implementation/HTPasswd.c
+++ b/WWW/Library/Implementation/HTPasswd.c
@@ -176,9 +176,7 @@ PUBLIC BOOL HTAA_passwdMatch ARGS2(CONST char *, password,
 
     status = strncmp(result, encrypted, strlen(encrypted));
 
-    if (TRACE)
-	fprintf(stderr,
-		"%s `%s' (encrypted: `%s') with: `%s' => %s\n",
+    CTRACE(tfp, "%s `%s' (encrypted: `%s') with: `%s' => %s\n",
 		"HTAA_passwdMatch: Matching password:",
 		password, result, encrypted,
 		(status==0 ? "OK" : "INCORRECT"));
@@ -266,16 +264,14 @@ PUBLIC BOOL HTAA_checkPassword ARGS3(CONST char *, username,
     else			fp = fopen(PASSWD_FILE,"r");
 
     if (!fp) {
-	if (TRACE) fprintf(stderr, "%s `%s'\n",
-			   "HTAA_checkPassword: Unable to open password file",
-			   (filename && *filename ? filename : PASSWD_FILE));
+	CTRACE(tfp, "%s `%s'\n",
+		    "HTAA_checkPassword: Unable to open password file",
+		    (filename && *filename ? filename : PASSWD_FILE));
 	return NO;
     }
     do {
 	if (2 == (status = HTAAFile_readPasswdRec(fp,user,pw))) {
-	    if (TRACE)
-		fprintf(stderr,
-			"HTAAFile_validateUser: %s \"%s\" %s \"%s:%s\"\n",
+	    CTRACE(tfp, "HTAAFile_validateUser: %s \"%s\" %s \"%s:%s\"\n",
 			"Matching username:", username,
 			"against passwd record:", user, pw);
 	    if (username  &&  user  &&  !strcmp(username,user)) {
@@ -292,7 +288,7 @@ PUBLIC BOOL HTAA_checkPassword ARGS3(CONST char *, username,
 
     fclose(fp);
     
-    if (TRACE) fprintf(stderr, "HTAAFile_checkPassword: (%s,%s) %scorrect\n",
+    CTRACE(tfp, "HTAAFile_checkPassword: (%s,%s) %scorrect\n",
 		       username, password, ((status != EOF) ? "" : "in"));
 
     if (status == EOF)  return NO;  /* We traversed to the end without luck */
diff --git a/WWW/Library/Implementation/HTPlain.c b/WWW/Library/Implementation/HTPlain.c
index 14b89bf8..363ad9e3 100644
--- a/WWW/Library/Implementation/HTPlain.c
+++ b/WWW/Library/Implementation/HTPlain.c
@@ -417,11 +417,8 @@ PRIVATE void HTPlain_write ARGS3(HTStream *, me, CONST char*, s, int, l)
 		   (uck = UCTransUniChar(code,
 					 me->outUCLYhndl)) >= 32 &&
 		   uck < 256) {
-	    if (TRACE) {
-		fprintf(stderr,
-			"UCTransUniChar returned 0x%.2lX:'%c'.\n",
+	    CTRACE(tfp, "UCTransUniChar returned 0x%.2lX:'%c'.\n",
 			uck, FROMASCII((char)uck));
-	    }
 	    HText_appendCharacter(me->text, ((char)(uck & 0xff)));
 	} else if (chk &&
 		   (uck == -4 ||
@@ -494,18 +491,12 @@ PRIVATE void HTPlain_write ARGS3(HTStream *, me, CONST char*, s, int, l)
 	    /*
 	    **	Ignore 8204 (zwnj) or 8205 (zwj), if we get to here. - FM
 	    */
-	    if (TRACE) {
-		fprintf(stderr,
-			"HTPlain_write: Ignoring '%ld'.\n", code);
-	    }
+	    CTRACE(tfp, "HTPlain_write: Ignoring '%ld'.\n", code);
 	} else if (code == 8206 || code == 8207) {
 	    /*
 	    **	Ignore 8206 (lrm) or 8207 (rlm), if we get to here. - FM
 	    */
-	    if (TRACE) {
-		fprintf(stderr,
-			"HTPlain_write: Ignoring '%ld'.\n", code);
-	    }
+	    CTRACE(tfp, "HTPlain_write: Ignoring '%ld'.\n", code);
 #endif /* NOTDEFINED */
 	} else if (me->T.trans_from_uni && code > 255) {
 	    if (PASSHI8BIT && PASSHICTRL && LYRawMode &&
diff --git a/WWW/Library/Implementation/HTRules.c b/WWW/Library/Implementation/HTRules.c
index 24604e29..b6abe661 100644
--- a/WWW/Library/Implementation/HTRules.c
+++ b/WWW/Library/Implementation/HTRules.c
@@ -7,10 +7,10 @@
 **	10 Aug 91	Authorisation added after Daniel Martin (pass, fail)
 **			Rule order in file changed
 **			Comments allowed with # on 1st char of rule line
-**      17 Jun 92       Bug fix: pass and fail failed if didn't contain '*' TBL
-**       1 Sep 93       Bug fix: no memory check - Nathan Torkington
-**                      BYTE_ADDRESSING removed - Arthur Secret
-**	11 Sep 93  MD	Changed %i into %d in debug printf. 
+**	17 Jun 92	Bug fix: pass and fail failed if didn't contain '*' TBL
+**	 1 Sep 93	Bug fix: no memory check - Nathan Torkington
+**			BYTE_ADDRESSING removed - Arthur Secret
+**	11 Sep 93  MD	Changed %i into %d in debug printf.
 **			VMS does not recognize %i.
 **			Bug Fix: in case of PASS, only one parameter to printf.
 **	19 Sep 93  AL	Added Access Authorization stuff.
@@ -43,7 +43,7 @@ typedef struct _rule {
 **	----------------
 */
 PUBLIC char *HTBinDir = NULL;	/* Physical /htbin directory path.	*/
-                                /* In future this should not be global.	*/
+				/* In future this should not be global. */
 PUBLIC char *HTSearchScript = NULL;	/* Search script name.		*/
 
 
@@ -61,11 +61,11 @@ PRIVATE rule * rule_tail = 0;	/* Pointer to last on list */
 **	--------------------
 **
 **  On entry,
-**	pattern		points to 0-terminated string containing a single "*"
+**	pattern 	points to 0-terminated string containing a single "*"
 **	equiv		points to the equivalent string with * for the
 **			place where the text matched by * goes.
 **  On exit,
-**	returns		0 if success, -1 if error.
+**	returns 	0 if success, -1 if error.
 */
 
 #ifdef __STDC__
@@ -77,33 +77,32 @@ int HTAddRule(op, pattern, equiv)
     char *	equiv;
 #endif
 { /* BYTE_ADDRESSING removed and memory check - AS - 1 Sep 93 */
-    rule *      temp;
-    char *      pPattern;
+    rule *	temp;
+    char *	pPattern;
 
     temp = (rule *)malloc(sizeof(*temp));
-    if (temp==NULL) 
-	outofmem(__FILE__, "HTAddRule"); 
+    if (temp==NULL)
+	outofmem(__FILE__, "HTAddRule");
     pPattern = (char *)malloc(strlen(pattern)+1);
-    if (pPattern==NULL) 
-	outofmem(__FILE__, "HTAddRule"); 
+    if (pPattern==NULL)
+	outofmem(__FILE__, "HTAddRule");
     if (equiv) {		/* Two operands */
 	char *	pEquiv = (char *)malloc(strlen(equiv)+1);
-	if (pEquiv==NULL) 
-	    outofmem(__FILE__, "HTAddRule"); 
-        temp->equiv = pEquiv;
-        strcpy(pEquiv, equiv);
+	if (pEquiv==NULL)
+	    outofmem(__FILE__, "HTAddRule");
+	temp->equiv = pEquiv;
+	strcpy(pEquiv, equiv);
     } else {
-        temp->equiv = 0;
+	temp->equiv = 0;
     }
     temp->pattern = pPattern;
     temp->op = op;
 
     strcpy(pPattern, pattern);
-    if (TRACE) {
-       if (equiv)
-          fprintf(stderr, "Rule: For `%s' op %d `%s'\n", pattern, op, equiv);
-       else
-          fprintf(stderr, "Rule: For `%s' op %d\n", pattern, op);
+    if (equiv) {
+	CTRACE(tfp, "Rule: For `%s' op %d `%s'\n", pattern, op, equiv);
+    } else {
+	CTRACE(tfp, "Rule: For `%s' op %d\n", pattern, op);
     }
 
 #ifdef PUT_ON_HEAD
@@ -116,17 +115,17 @@ int HTAddRule(op, pattern, equiv)
     rule_tail = temp;
 #endif
 
-        
+
     return 0;
 }
 
 
-/*	Clear all rules						HTClearRules()
+/*	Clear all rules 					HTClearRules()
 **	---------------
 **
 ** On exit,
 **	There are no rules
-**	returns		0 if success, -1 if error.
+**	returns 	0 if success, -1 if error.
 **
 ** See also
 **	HTAddRule()
@@ -138,7 +137,7 @@ int HTClearRules()
 #endif
 {
     while (rules) {
-    	rule * temp = rules;
+	rule * temp = rules;
 	rules = temp->next;
 	FREE(temp->pattern);
 	FREE(temp->equiv);
@@ -160,7 +159,7 @@ int HTClearRules()
 ** On entry,
 **	required	points to a string whose equivalent value is neeed
 ** On exit,
-**	returns		the address of the equivalent string allocated from
+**	returns 	the address of the equivalent string allocated from
 **			the heap which the CALLER MUST FREE. If no translation
 **			occured, then it is a copy of te original.
 ** NEW FEATURES:
@@ -185,7 +184,7 @@ char * HTTranslate(required)
     HTAA_clearProtections();	/* Reset from previous call -- AL */
 
     for(r = rules; r; r = r->next) {
-        char * p = r->pattern;
+	char * p = r->pattern;
 	int m=0;   /* Number of characters matched against wildcard */
 	CONST char * q = current;
 	for(;*p && *q; p++, q++) {   /* Find first mismatch */
@@ -194,9 +193,9 @@ char * HTTranslate(required)
 
 	if (*p == '*') {		/* Match up to wildcard */
 	    m = strlen(q) - strlen(p+1); /* Amount to match to wildcard */
-	    if(m<0) continue;           /* tail is too short to match */
+	    if(m<0) continue;		/* tail is too short to match */
 	    if (0!=strcmp(q+m, p+1)) continue;	/* Tail mismatch */
-	} else 				/* Not wildcard */
+	} else				/* Not wildcard */
 	    if (*p != *q) continue;	/* plain mismatch: go to next rule */
 
 	switch (r->op) {		/* Perform operation */
@@ -210,13 +209,12 @@ char * HTTranslate(required)
 		char *eff_ids = NULL;
 		char *prot_file = NULL;
 
-		if (TRACE) fprintf(stderr,
-				   "HTRule: `%s' matched %s %s: `%s'\n",
-				   current,
-				   (r->op==HT_Protect ? "Protect" : "DefProt"),
-				   "rule, setup",
-				   (r->equiv ? r->equiv :
-				    (r->op==HT_Protect ?"DEFAULT" :"NULL!!")));
+		CTRACE(tfp, "HTRule: `%s' matched %s %s: `%s'\n",
+			    current,
+			    (r->op==HT_Protect ? "Protect" : "DefProt"),
+			    "rule, setup",
+			    (r->equiv ? r->equiv :
+			     (r->op==HT_Protect ?"DEFAULT" :"NULL!!")));
 
 		if (r->equiv) {
 		    StrAllocCopy(local_copy, r->equiv);
@@ -238,57 +236,56 @@ char * HTTranslate(required)
 #endif /* ACCESS_AUTH */
 
 	case HT_Pass:				/* Authorised */
-    		if (!r->equiv) {
-		    if (TRACE) fprintf(stderr, "HTRule: Pass `%s'\n", current);
+		if (!r->equiv) {
+		    CTRACE(tfp, "HTRule: Pass `%s'\n", current);
 		    return current;
-	        }
+		}
 		/* Else fall through ...to map and pass */
-		
+
 	case HT_Map:
 	    if (*p == *q) { /* End of both strings, no wildcard */
-    	          if (TRACE) fprintf(stderr,
-			       "For `%s' using `%s'\n", current, r->equiv);  
-	          StrAllocCopy(current, r->equiv); /* use entire translation */
+		  CTRACE(tfp, "For `%s' using `%s'\n", current, r->equiv);
+		  StrAllocCopy(current, r->equiv); /* use entire translation */
 	    } else {
 		  char * ins = strchr(r->equiv, '*');	/* Insertion point */
-	          if (ins) {	/* Consistent rule!!! */
+		  if (ins) {	/* Consistent rule!!! */
 			char * temp = (char *)malloc(
 				strlen(r->equiv)-1 + m + 1);
-			if (temp==NULL) 
+			if (temp==NULL)
 			    outofmem(__FILE__, "HTTranslate"); /* NT & AS */
-			strncpy(temp, 	r->equiv, ins-r->equiv);
+			strncpy(temp,	r->equiv, ins-r->equiv);
 			/* Note: temp may be unterminated now! */
 			strncpy(temp+(ins-r->equiv), q, m);  /* Matched bit */
 			strcpy (temp+(ins-r->equiv)+m, ins+1);	/* Last bit */
-    			if (TRACE) fprintf(stderr, "For `%s' using `%s'\n",
-						current, temp);
+			CTRACE(tfp, "For `%s' using `%s'\n",
+				    current, temp);
 			FREE(current);
-			current = temp;			/* Use this */
+			current = temp; 		/* Use this */
 
 		    } else {	/* No insertion point */
 			char * temp = (char *)malloc(strlen(r->equiv)+1);
-			if (temp==NULL) 
+			if (temp==NULL)
 			    outofmem(__FILE__, "HTTranslate"); /* NT & AS */
 			strcpy(temp, r->equiv);
-    			if (TRACE) fprintf(stderr, "For `%s' using `%s'\n",
+			CTRACE(tfp, "For `%s' using `%s'\n",
 						current, temp);
 			FREE(current);
-			current = temp;			/* Use this */
+			current = temp; 		/* Use this */
 		    } /* If no insertion point exists */
 		}
 		if (r->op == HT_Pass) {
-		    if (TRACE) fprintf(stderr, "HTRule: ...and pass `%s'\n",
-		    		       current);
+		    CTRACE(tfp, "HTRule: ...and pass `%s'\n",
+				current);
 		    return current;
 		}
 		break;
 
 	case HT_Invalid:
 	case HT_Fail:				/* Unauthorised */
-    		    if (TRACE) fprintf(stderr, "HTRule: *** FAIL `%s'\n",
-		    		       current);
-		    return (char *)0;
-		    		    
+		CTRACE(tfp, "HTRule: *** FAIL `%s'\n",
+			    current);
+		return (char *)0;
+
 	} /* if tail matches ... switch operation */
 
     } /* loop over rules */
@@ -313,7 +310,7 @@ PUBLIC int  HTSetConfiguration ARGS1(CONST char *, config)
     float quality, secs, secs_per_byte;
     int maxbytes;
     int status;
-    
+
     StrAllocCopy(line, config);
     {
 	char * p = strchr(line, '#');	/* Chop off comments */
@@ -322,9 +319,9 @@ PUBLIC int  HTSetConfiguration ARGS1(CONST char *, config)
     pointer = line;
     word1 = HTNextField(&pointer);
     if (!word1) {
-    	FREE(line);
+	FREE(line);
 	return 0;
-    } ;	/* Comment only or blank */
+    } ; /* Comment only or blank */
 
     word2 = HTNextField(&pointer);
 
@@ -341,7 +338,7 @@ PUBLIC int  HTSetConfiguration ARGS1(CONST char *, config)
     }
 
     if (0==strcasecomp(word1, "suffix")) {
-        char * encoding = HTNextField(&pointer);
+	char * encoding = HTNextField(&pointer);
 	if (pointer) status = sscanf(pointer, "%f", &quality);
 	else status = 0;
 	HTSetSuffix(word2,	word3,
@@ -349,12 +346,12 @@ PUBLIC int  HTSetConfiguration ARGS1(CONST char *, config)
 				status >= 1? quality : 1.0);
 
     } else if (0==strcasecomp(word1, "presentation")) {
-        if (pointer) status = sscanf(pointer, "%f%f%f%d",
+	if (pointer) status = sscanf(pointer, "%f%f%f%d",
 			    &quality, &secs, &secs_per_byte, &maxbytes);
-        else status = 0;
+	else status = 0;
 	HTSetPresentation(word2, word3,
-		    status >= 1? quality 		: 1.0,
-		    status >= 2 ? secs 			: 0.0,
+		    status >= 1? quality		: 1.0,
+		    status >= 2 ? secs			: 0.0,
 		    status >= 3 ? secs_per_byte 	: 0.0,
 		    status >= 4 ? maxbytes		: 0 );
 
@@ -366,17 +363,17 @@ PUBLIC int  HTSetConfiguration ARGS1(CONST char *, config)
 	StrAllocCopy(HTSearchScript, word2);	/* Search script name */
 
     } else {
-	op =	0==strcasecomp(word1, "map")  ?	HT_Map
-	    :	0==strcasecomp(word1, "pass") ?	HT_Pass
-	    :	0==strcasecomp(word1, "fail") ?	HT_Fail
-	    :   0==strcasecomp(word1, "defprot") ? HT_DefProt
+	op =	0==strcasecomp(word1, "map")  ? HT_Map
+	    :	0==strcasecomp(word1, "pass") ? HT_Pass
+	    :	0==strcasecomp(word1, "fail") ? HT_Fail
+	    :	0==strcasecomp(word1, "defprot") ? HT_DefProt
 	    :	0==strcasecomp(word1, "protect") ? HT_Protect
 	    :						HT_Invalid;
 	if (op==HT_Invalid) {
 	    fprintf(stderr, "HTRule: Bad rule `%s'\n", config);
-	} else {  
+	} else {
 	    HTAddRule(op, word2, word3);
-	} 
+	}
     }
     FREE(line);
     return 0;
@@ -391,7 +388,7 @@ PUBLIC int  HTSetConfiguration ARGS1(CONST char *, config)
 ** On exit,
 **	Any existing rules will have been kept.
 **	Any new rules will have been loaded.
-**	Returns		0 if no error, 0 if error!
+**	Returns 	0 if no error, 0 if error!
 **
 ** Bugs:
 **	The strings may not contain spaces.
@@ -401,10 +398,9 @@ int HTLoadRules ARGS1(CONST char *, filename)
 {
     FILE * fp = fopen(filename, "r");
     char line[LINE_LENGTH+1];
-    
+
     if (!fp) {
-        if (TRACE) fprintf(stderr,
-			   "HTRules: Can't open rules file %s\n", filename);
+	CTRACE(tfp, "HTRules: Can't open rules file %s\n", filename);
 	return -1; /* File open error */
     }
     for(;;) {
diff --git a/WWW/Library/Implementation/HTStyle.c b/WWW/Library/Implementation/HTStyle.c
index 8fc72093..963303d9 100644
--- a/WWW/Library/Implementation/HTStyle.c
+++ b/WWW/Library/Implementation/HTStyle.c
@@ -184,7 +184,7 @@ HTStyle * HTStyleNamed ARGS2 (HTStyleSheet *,self, CONST char *,name)
     HTStyle * scan;
     for (scan=self->styles; scan; scan=scan->next)
 	if (0==strcmp(scan->name, name)) return scan;
-    if (TRACE) fprintf(stderr, "StyleSheet: No style named `%s'\n", name);
+    CTRACE(tfp, "StyleSheet: No style named `%s'\n", name);
     return NULL;
 }
 
@@ -235,8 +235,8 @@ HTStyle * HTStyleForRun (HTStyleSheet *self, NXRun *run)
 	    }
 	}
     }
-    if (TRACE) fprintf(stderr, "HTStyleForRun: Best match for style is %d out of 18\n",
-			 bestMatch);
+    CTRACE(tfp, "HTStyleForRun: Best match for style is %d out of 18\n",
+		 bestMatch);
     return best;
 }
 #endif /* NEXT_SUPRESS */
@@ -325,7 +325,7 @@ HTStyleSheet * HTStyleSheetRead(HTStyleSheet * self, NXStream * stream)
     HTStyle * style;
     char styleName[80];
     NXScanf(stream, " %d ", &numStyles);
-    if (TRACE) fprintf(stderr, "Stylesheet: Reading %d styles\n", numStyles);
+    CTRACE(tfp, "Stylesheet: Reading %d styles\n", numStyles);
     for (i=0; i<numStyles; i++) {
 	NXScanf(stream, "%s", styleName);
 	style = HTStyleNamed(self, styleName);
@@ -353,7 +353,7 @@ HTStyleSheet * HTStyleSheetWrite(HTStyleSheet * self, NXStream * stream)
     for(style=self->styles; style; style=style->next) numStyles++;
     NXPrintf(stream, "%d\n", numStyles);
 
-    if (TRACE) fprintf(stderr, "StyleSheet: Writing %d styles\n", numStyles);
+    CTRACE(tfp, "StyleSheet: Writing %d styles\n", numStyles);
     for (style=self->styles; style; style=style->next) {
 	NXPrintf(stream, "%s ", style->name);
 	(void) HTStyleWrite(style, stream);
diff --git a/WWW/Library/Implementation/HTTCP.c b/WWW/Library/Implementation/HTTCP.c
index 9749e530..c7baf292 100644
--- a/WWW/Library/Implementation/HTTCP.c
+++ b/WWW/Library/Implementation/HTTCP.c
@@ -334,15 +334,11 @@ PUBLIC int HTParseInet ARGS2(
 #endif /* _WINDOWS_NSL */
 
     if (!str) {
-	if (TRACE) {
-	    fprintf(stderr, "HTParseInet: Can't parse `NULL'.\n");
-	}
+	CTRACE(tfp, "HTParseInet: Can't parse `NULL'.\n");
 	return -1;
     }
     if (HTCheckForInterrupt()) {
-	if (TRACE) {
-	    fprintf (stderr, "HTParseInet: INTERRUPTED for '%s'.\n", str);
-	}
+	CTRACE (tfp, "HTParseInet: INTERRUPTED for '%s'.\n", str);
 	return -1;
     }
 #ifdef _WINDOWS_NSL
@@ -370,8 +366,8 @@ PUBLIC int HTParseInet ARGS2(
 	    struct servent * serv = getservbyname(port, (char*)0);
 	    if (serv) {
 		soc_in->sin_port = serv->s_port;
-	    } else if (TRACE) {
-		fprintf(stderr, "TCP: Unknown service %s\n", port);
+	    } else {
+		CTRACE(tfp, "TCP: Unknown service %s\n", port);
 	    }
 #endif /* SUPPRESS */
 	}
@@ -384,11 +380,8 @@ PUBLIC int HTParseInet ARGS2(
     */
     soc_in->sdn_nam.n_len = min(DN_MAXNAML, strlen(host));  /* <=6 in phase 4 */
     strncpy(soc_in->sdn_nam.n_name, host, soc_in->sdn_nam.n_len + 1);
-    if (TRACE) {
-	fprintf(stderr,
-		"DECnet: Parsed address as object number %d on host %.6s...\n",
+    CTRACE(tfp, "DECnet: Parsed address as object number %d on host %.6s...\n",
 		soc_in->sdn_objnum, host);
-    }
 #else  /* parse Internet host: */
 
     if (*host >= '0' && *host <= '9') {   /* Test for numeric node address: */
@@ -429,10 +422,7 @@ PUBLIC int HTParseInet ARGS2(
 #endif /* _WINDOWS_NSL */
     } else {		    /* Alphanumeric node name: */
 #ifdef MVS	/* Outstanding problem with crash in MVS gethostbyname */
-	if (TRACE) {
-	    fprintf(stderr,
-		    "HTParseInet: Calling gethostbyname(%s)\n", host);
-	}
+	CTRACE(tfp, "HTParseInet: Calling gethostbyname(%s)\n", host);
 #endif /* MVS */
 
 #ifdef NSL_FORK
@@ -488,10 +478,7 @@ PUBLIC int HTParseInet ARGS2(
 		**  Abort if interrupt key pressed.
 		*/
 		if (HTCheckForInterrupt()) {
-		    if (TRACE) {
-			fprintf(stderr,
-				"HTParseInet: INTERRUPTED gethostbyname.\n");
-		    }
+		    CTRACE(tfp, "HTParseInet: INTERRUPTED gethostbyname.\n");
 		    kill(fpid , SIGKILL);
 		    waitpid(fpid, NULL, 0);
 		    FREE(host);
@@ -507,47 +494,34 @@ PUBLIC int HTParseInet ARGS2(
 	    if (waitret <= 0) {
 		waitret = waitpid(fpid, &cst1, WNOHANG);
 	    }
-	    if (TRACE) {
-		if (WIFEXITED(cst1)) {
-		    fprintf(stderr,
-		      "HTParseInet: NSL_FORK child %d exited, status 0x%x.\n",
+	    if (WIFEXITED(cst1)) {
+		CTRACE(tfp, "HTParseInet: NSL_FORK child %d exited, status 0x%x.\n",
 			    (int)waitret, cst1);
-		} else if (WIFSIGNALED(cst1)) {
-		    fprintf(stderr,
-		  "HTParseInet: NSL_FORK child %d got signal, status 0x%x!\n",
+	    } else if (WIFSIGNALED(cst1)) {
+		CTRACE(tfp, "HTParseInet: NSL_FORK child %d got signal, status 0x%x!\n",
 			    (int)waitret, cst1);
 #ifdef WCOREDUMP
-		    if (WCOREDUMP(cst1)) {
-			fprintf(stderr,
-			      "HTParseInet: NSL_FORK child %d dumped core!\n",
+		if (WCOREDUMP(cst1)) {
+		    CTRACE(tfp, "HTParseInet: NSL_FORK child %d dumped core!\n",
 				(int)waitret);
 		    }
 #endif /* WCOREDUMP */
-		} else if (WIFSTOPPED(cst1)) {
-		    fprintf(stderr,
-		  "HTParseInet: NSL_FORK child %d is stopped, status 0x%x!\n",
+	    } else if (WIFSTOPPED(cst1)) {
+		CTRACE(tfp, "HTParseInet: NSL_FORK child %d is stopped, status 0x%x!\n",
 			    (int)waitret, cst1);
-		}
 	    }
 	    /*
 	    **	Read as much as we can - should be the address.
 	    */
 	    IOCTL(pfd[0], FIONREAD, &cstat);
 	    if (cstat < 4) {
-		if (TRACE) {
-		    fprintf(stderr,
-		       "HTParseInet: NSL_FORK child returns only %d bytes.\n",
+		CTRACE(tfp, "HTParseInet: NSL_FORK child returns only %d bytes.\n",
 			    cstat);
-		    fprintf(stderr,
-			"             Trying again without forking.\n");
-		}
+		CTRACE(tfp, "             Trying again without forking.\n");
 		phost = gethostbyname(host);	/* See netdb.h */
 		if (!OK_HOST(phost)) {
-		    if (TRACE) {
-			fprintf(stderr,
-			 "HTParseInet: Can't find internet node name `%s'.\n",
+		    CTRACE(tfp, "HTParseInet: Can't find internet node name `%s'.\n",
 				host);
-		    }
 		    memset((void *)&soc_in->sin_addr, 0, sizeof(soc_in->sin_addr));
 		} else {
 		    memcpy((void *)&soc_in->sin_addr,
@@ -563,11 +537,8 @@ PUBLIC int HTParseInet ARGS2(
 	    close(pfd[1]);
 	}
 	if (soc_in->sin_addr.s_addr == 0) {
-	    if (TRACE) {
-		fprintf(stderr,
-			"HTParseInet: Can't find internet node name `%s'.\n",
+	    CTRACE(tfp, "HTParseInet: Can't find internet node name `%s'.\n",
 			host);
-	    }
 #ifndef _WINDOWS_NSL
 	    FREE(host);
 #endif /* _WINDOWS_NSL */
@@ -577,10 +548,7 @@ PUBLIC int HTParseInet ARGS2(
 	FREE(host);
 #endif /* _WINDOWS_NSL */
 #ifdef MVS
-	if (TRACE) {
-	    fprintf(stderr,
-		    "HTParseInet: gethostbyname() returned %d\n", phost);
-	}
+	CTRACE(tfp, "HTParseInet: gethostbyname() returned %d\n", phost);
 #endif /* MVS */
 
 #else /* Not NSL_FORK: */
@@ -588,10 +556,8 @@ PUBLIC int HTParseInet ARGS2(
 	soc_in->sin_addr.s_addr = htonl(resolve(host));
 	FREE(host);
 	if (soc_in->sin_addr.s_addr == 0) {
-		 if (TRACE)
-			  fprintf(stderr,
-			 "HTTPAccess: Can't find internet node name `%s'.\n",host);
-		 return -1;  /* Fail? */
+	    CTRACE(tfp, "HTTPAccess: Can't find internet node name `%s'.\n",host);
+	    return -1;  /* Fail? */
 	}
 #else
 #ifdef _WINDOWS_NSL
@@ -627,17 +593,11 @@ PUBLIC int HTParseInet ARGS2(
 	phost = gethostbyname(host);	/* See netdb.h */
 #endif /* _WINDOWS_NSL */
 #ifdef MVS
-	if (TRACE) {
-	    fprintf(stderr,
-		    "HTParseInet: gethostbyname() returned %d\n", phost);
-	}
+	CTRACE(tfp, "HTParseInet: gethostbyname() returned %d\n", phost);
 #endif /* MVS */
 	if (!phost) {
-	    if (TRACE) {
-		fprintf(stderr,
-			"HTParseInet: Can't find internet node name `%s'.\n",
+	    CTRACE(tfp, "HTParseInet: Can't find internet node name `%s'.\n",
 			host);
-	    }
 #ifndef _WINDOWS_NSL
 	    FREE(host);
 #endif /* _WINDOWS_NSL */
@@ -663,15 +623,12 @@ PUBLIC int HTParseInet ARGS2(
 #endif /* NSL_FORK */
     }
 
-    if (TRACE) {
-	fprintf(stderr,
-	   "HTParseInet: Parsed address as port %d, IP address %d.%d.%d.%d\n",
+    CTRACE(tfp, "HTParseInet: Parsed address as port %d, IP address %d.%d.%d.%d\n",
 		(int)ntohs(soc_in->sin_port),
 		(int)*((unsigned char *)(&soc_in->sin_addr)+0),
 		(int)*((unsigned char *)(&soc_in->sin_addr)+1),
 		(int)*((unsigned char *)(&soc_in->sin_addr)+2),
 		(int)*((unsigned char *)(&soc_in->sin_addr)+3));
-    }
 #endif	/* Internet vs. Decnet */
 
     return 0;	/* OK */
@@ -729,15 +686,14 @@ PRIVATE void get_host_details NOARGS
 #ifdef NEED_HOST_ADDRESS		/* no -- needs name server! */
     phost = gethostbyname(name);	/* See netdb.h */
     if (!OK_HOST(phost)) {
-	if (TRACE) fprintf(stderr,
-		"TCP: Can't find my own internet node address for `%s'!!\n",
-		name);
+	CTRACE(tfp, "TCP: Can't find my own internet node address for `%s'!!\n",
+		    name);
 	return;  /* Fail! */
     }
     StrAllocCopy(hostname, phost->h_name);
     memcpy(&HTHostAddress, &phost->h_addr, phost->h_length);
-    if (TRACE) fprintf(stderr, "     Name server says that I am `%s' = %s\n",
-	    hostname, HTInetString(&HTHostAddress));
+    CTRACE(tfp, "     Name server says that I am `%s' = %s\n",
+		hostname, HTInetString(&HTHostAddress));
 #endif /* NEED_HOST_ADDRESS */
 
 #endif /* !DECNET */
@@ -995,8 +951,7 @@ PUBLIC int HTDoConnect ARGS4(
 		}
 	    }
 	    if (HTCheckForInterrupt()) {
-		if (TRACE)
-		    fprintf(stderr, "*** INTERRUPTED in middle of connect.\n");
+		CTRACE(tfp, "*** INTERRUPTED in middle of connect.\n");
 		status = HT_INTERRUPTED;
 		SOCKET_ERRNO = EINTR;
 		break;
diff --git a/WWW/Library/Implementation/HTTP.c b/WWW/Library/Implementation/HTTP.c
index 996ebd4b..4cd22539 100644
--- a/WWW/Library/Implementation/HTTP.c
+++ b/WWW/Library/Implementation/HTTP.c
@@ -35,8 +35,6 @@
 #include <LYGlobalDefs.h>
 #include <LYLeaks.h>
 
-/* #define TRACE 1 */
-
 struct _HTStream
 {
   HTStreamClass * isa;
@@ -186,17 +184,13 @@ try_again:
       /*
       **  Interrupt cleanly.
       */
-      if (TRACE)
-	  fprintf (stderr,
-		   "HTTP: Interrupted on connect; recovering cleanly.\n");
-      _HTProgress ("Connection interrupted.");
-      status = HT_NOT_LOADED;
-      goto done;
-  }
-  if (status < 0) {
-      if (TRACE)
-	  fprintf(stderr,
-	    "HTTP: Unable to connect to remote host for `%s' (errno = %d).\n",
+       CTRACE (tfp, "HTTP: Interrupted on connect; recovering cleanly.\n");
+       _HTProgress ("Connection interrupted.");
+       status = HT_NOT_LOADED;
+       goto done;
+   }
+   if (status < 0) {
+	CTRACE(tfp, "HTTP: Unable to connect to remote host for `%s' (errno = %d).\n",
 	    url, SOCKET_ERRNO);
       HTAlert("Unable to connect to remote host.");
       status = HT_NOT_LOADED;
@@ -441,8 +435,7 @@ try_again:
 		*/
 		sprintf(line, "%s%c%c", auth, CR, LF);
 		StrAllocCat(command, line);
-		if (TRACE)
-		    fprintf(stderr, "HTTP: Sending authorization: %s\n", auth);
+		CTRACE(tfp, "HTTP: Sending authorization: %s\n", auth);
 	    } else if (auth && *auth == '\0') {
 		/*
 		**  If auth is a zero-length string, the user either
@@ -466,9 +459,7 @@ try_again:
 		    goto done;
 		}
 	    } else {
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTTP: Not sending authorization (yet).\n");
+		CTRACE(tfp, "HTTP: Not sending authorization (yet).\n");
 	    }
 	    /*
 	    **	Add 'Cookie:' header, if it's HTTP or HTTPS
@@ -501,9 +492,7 @@ try_again:
 		*/
 		StrAllocCat(command, "Cookie2: $Version=\"1\"");
 		StrAllocCat(command, crlf);
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTTP: Sending Cookie2: $Version =\"1\"\n");
+		CTRACE(tfp, "HTTP: Sending Cookie2: $Version =\"1\"\n");
 	    }
 	    if (*cookie != '\0') {
 		/*
@@ -514,8 +503,7 @@ try_again:
 		StrAllocCat(command, "Cookie: ");
 		StrAllocCat(command, cookie);
 		StrAllocCat(command, crlf);
-		if (TRACE)
-		    fprintf(stderr, "HTTP: Sending Cookie: %s\n", cookie);
+		CTRACE(tfp, "HTTP: Sending Cookie: %s\n", cookie);
 	    }
 	    FREE(cookie);
 	}
@@ -540,9 +528,7 @@ try_again:
 	    */
 	    sprintf(line, "%s%c%c", auth, CR, LF);
 	    StrAllocCat(command, line);
-	    if (TRACE)
-		fprintf(stderr,
-			(auth_proxy ?
+	    CTRACE(tfp, (auth_proxy ?
 			 "HTTP: Sending proxy authorization: %s\n" :
 			 "HTTP: Sending authorization: %s\n"),
 			auth);
@@ -569,9 +555,7 @@ try_again:
 		goto done;
 	    }
 	} else {
-	    if (TRACE)
-		fprintf(stderr,
-			(auth_proxy ?
+	    CTRACE(tfp, (auth_proxy ?
 			 "HTTP: Not sending proxy authorization (yet).\n" :
 			 "HTTP: Not sending authorization (yet).\n"));
 	}
@@ -581,12 +565,10 @@ try_again:
       auth_proxy = NO;
   }
 
-  if (do_post)
-    {
-      if (TRACE)
-	  fprintf (stderr, "HTTP: Doing post, content-type '%s'\n",
-		   anAnchor->post_content_type ? anAnchor->post_content_type
-					       : "lose");
+    if (do_post) {
+	CTRACE (tfp, "HTTP: Doing post, content-type '%s'\n",
+		     anAnchor->post_content_type ? anAnchor->post_content_type
+						 : "lose");
       sprintf (line, "Content-type: %s%c%c",
 	       anAnchor->post_content_type ? anAnchor->post_content_type
 					   : "lose", CR, LF);
@@ -609,12 +591,9 @@ try_again:
   else
       StrAllocCat(command, crlf);	/* Blank line means "end" of headers */
 
-  if (TRACE) {
-      fprintf (stderr,
-	       "Writing:\n%s%s----------------------------------\n",
+  CTRACE (tfp, "Writing:\n%s%s----------------------------------\n",
 	       command,
 	       (anAnchor->post_data ? crlf : ""));
-  }
 
   _HTProgress ("Sending HTTP request.");
 
@@ -622,8 +601,7 @@ try_again:
   FREE(command);
   if (status <= 0) {
       if (status == 0) {
-	  if (TRACE)
-	      fprintf (stderr, "HTTP: Got status 0 in initial write\n");
+	  CTRACE (tfp, "HTTP: Got status 0 in initial write\n");
 	  /* Do nothing. */
       } else if ((SOCKET_ERRNO == ENOTCONN ||
 		  SOCKET_ERRNO == ECONNRESET ||
@@ -633,18 +611,14 @@ try_again:
 	    /*
 	    **	Arrrrgh, HTTP 0/1 compability problem, maybe.
 	    */
-	    if (TRACE)
-		fprintf (stderr,
-		 "HTTP: BONZO ON WRITE Trying again with HTTP0 request.\n");
+	    CTRACE (tfp, "HTTP: BONZO ON WRITE Trying again with HTTP0 request.\n");
 	    _HTProgress ("Retrying as HTTP0 request.");
 	    HTTP_NETCLOSE(s, handle);
 	    extensions = NO;
 	    already_retrying = TRUE;
 	    goto try_again;
       } else {
-	  if (TRACE)
-	      fprintf (stderr,
-	   "HTTP: Hit unexpected network WRITE error; aborting connection.\n");
+	  CTRACE (tfp, "HTTP: Hit unexpected network WRITE error; aborting connection.\n");
 	  HTTP_NETCLOSE(s, handle);
 	  status = -1;
 	  HTAlert("Unexpected network write error; connection aborted.");
@@ -652,8 +626,7 @@ try_again:
       }
   }
 
-  if (TRACE)
-      fprintf (stderr, "HTTP: WRITE delivered OK\n");
+  CTRACE (tfp, "HTTP: WRITE delivered OK\n");
   _HTProgress ("HTTP request sent; waiting for response.");
 
   /*	Read the first line of the response
@@ -675,21 +648,18 @@ try_again:
 	    line_buffer =
 	      (char *)realloc(line_buffer, (buffer_length * sizeof(char)));
 	}
-	if (TRACE)
-	    fprintf (stderr, "HTTP: Trying to read %d\n",
+	CTRACE (tfp, "HTTP: Trying to read %d\n",
 		     buffer_length - length - 1);
 	status = HTTP_NETREAD(s, line_buffer + length,
 			      buffer_length - length - 1, handle);
-	if (TRACE)
-	    fprintf (stderr, "HTTP: Read %d\n", status);
+	CTRACE (tfp, "HTTP: Read %d\n", status);
 	if (status <= 0) {
 	    /*
 	     *	Retry if we get nothing back too.
 	     *	Bomb out if we get nothing twice.
 	     */
 	    if (status == HT_INTERRUPTED) {
-		if (TRACE)
-		    fprintf (stderr, "HTTP: Interrupted initial read.\n");
+		CTRACE (tfp, "HTTP: Interrupted initial read.\n");
 		_HTProgress ("Connection interrupted.");
 		HTTP_NETCLOSE(s, handle);
 		status = HT_NO_DATA;
@@ -702,9 +672,7 @@ try_again:
 		/*
 		**  Arrrrgh, HTTP 0/1 compability problem, maybe.
 		*/
-		if (TRACE)
-		    fprintf (stderr,
-			"HTTP: BONZO Trying again with HTTP0 request.\n");
+		CTRACE (tfp, "HTTP: BONZO Trying again with HTTP0 request.\n");
 		HTTP_NETCLOSE(s, handle);
 		FREE(line_buffer);
 		FREE(line_kept_clean);
@@ -714,9 +682,7 @@ try_again:
 		_HTProgress ("Retrying as HTTP0 request.");
 		goto try_again;
 	    } else {
-		if (TRACE)
-		    fprintf (stderr,
-  "HTTP: Hit unexpected network read error; aborting connection; status %d.\n",
+		CTRACE (tfp, "HTTP: Hit unexpected network read error; aborting connection; status %d.\n",
 			   status);
 		HTAlert("Unexpected network read error; connection aborted.");
 		HTTP_NETCLOSE(s, handle);
@@ -771,8 +737,7 @@ try_again:
   /*	We now have a terminated unfolded line. Parse it.
   **	-------------------------------------------------
   */
-  if (TRACE)
-      fprintf(stderr, "HTTP: Rx: %s\n", line_buffer);
+  CTRACE(tfp, "HTTP: Rx: %s\n", line_buffer);
 
   /*
   **  Kludge to work with old buggy servers and the VMS Help gateway.
@@ -788,8 +753,7 @@ try_again:
       FREE(line_kept_clean);
       extensions = NO;
       already_retrying = TRUE;
-      if (TRACE)
-	  fprintf(stderr, "HTTP: close socket %d to retry with HTTP0\n", s);
+      CTRACE(tfp, "HTTP: close socket %d to retry with HTTP0\n", s);
       HTTP_NETCLOSE(s, handle);
       /* print a progress message */
       _HTProgress ("Retrying as HTTP0 request.");
@@ -808,8 +772,7 @@ try_again:
 		    server_version,
 		    &server_status);
 
-    if (TRACE)
-	fprintf (stderr, "HTTP: Scanned %d fields from line_buffer\n", fields);
+    CTRACE (tfp, "HTTP: Scanned %d fields from line_buffer\n", fields);
 
     if (http_error_file) {     /* Make the status code externally available */
 	FILE *error_file;
@@ -841,8 +804,7 @@ try_again:
 	 */
 	HTAtom * encoding;
 
-	if (TRACE)
-	    fprintf (stderr, "--- Talking HTTP0.\n");
+	CTRACE (tfp, "--- Talking HTTP0.\n");
 
 	format_in = HTFileFormat(url, &encoding, NULL);
 	/*
@@ -851,27 +813,19 @@ try_again:
 	**  without looking at content.
 	*/
 	if (!strncmp(HTAtom_name(format_in), "text/plain",10)) {
-	    if (TRACE)
-		fprintf(stderr,
-			   "HTTP: format_in being changed to text/HTML\n");
+	    CTRACE(tfp, "HTTP: format_in being changed to text/HTML\n");
 	    format_in = WWW_HTML;
 	}
 	if (!IsUnityEnc(encoding)) {
 	    /*
 	    **	Change the format to that for "www/compressed".
 	    */
-	    if (TRACE) {
-		fprintf(stderr,
-			"HTTP: format_in is '%s',\n", HTAtom_name(format_in));
-	    }
+	    CTRACE(tfp, "HTTP: format_in is '%s',\n", HTAtom_name(format_in));
 	    StrAllocCopy(anAnchor->content_type, HTAtom_name(format_in));
 	    StrAllocCopy(anAnchor->content_encoding, HTAtom_name(encoding));
 	    format_in = HTAtom_for("www/compressed");
-	    if (TRACE) {
-		fprintf(stderr,
-			"        Treating as '%s' with encoding '%s'\n",
+	    CTRACE(tfp, "        Treating as '%s' with encoding '%s'\n",
 			"www/compressed", HTAtom_name(encoding));
-	    }
 	}
 
 	start_of_data = line_kept_clean;
@@ -880,8 +834,7 @@ try_again:
 	**  Set up to decode full HTTP/1.n response. - FM
 	*/
 	format_in = HTAtom_for("www/mime");
-	if (TRACE)
-	    fprintf (stderr, "--- Talking HTTP1.\n");
+	CTRACE (tfp, "--- Talking HTTP1.\n");
 
 	/*
 	**  We set start_of_data to "" when !eol here because there
@@ -1133,8 +1086,7 @@ try_again:
 		  /*
 		   *  Impatient user. - FM
 		   */
-		  if (TRACE)
-		      fprintf (stderr, "HTTP: Interrupted followup read.\n");
+		  CTRACE (tfp, "HTTP: Interrupted followup read.\n");
 		  _HTProgress ("Connection interrupted.");
 		  status = HT_INTERRUPTED;
 		  goto clean_up;
@@ -1147,9 +1099,7 @@ try_again:
 		       *  Don't make the redirection permanent
 		       *  if we have POST content. - FM
 		       */
-		      if (TRACE)
-			  fprintf(stderr,
-	 "HTTP: Have POST content. Treating 301 (Permanent) as Temporary.\n");
+		      CTRACE(tfp, "HTTP: Have POST content. Treating 301 (Permanent) as Temporary.\n");
 		      HTAlert(
 	 "Have POST content. Treating Permanent Redirection as Temporary.\n");
 		  } else {
@@ -1367,9 +1317,7 @@ Cookie2_continuation:
 			     *	thus is probably something in the body, so
 			     *	we'll show the user what was returned. - FM
 			     */
-			    if (TRACE)
-				fprintf(stderr,
-					"HTTP: 'Location:' is zero-length!\n");
+			    CTRACE(tfp, "HTTP: 'Location:' is zero-length!\n");
 			    if (cp1)
 				*cp1 = LF;
 			    if (cp2)
@@ -1388,9 +1336,7 @@ Cookie2_continuation:
 			 *  seek the document at that Location. - FM
 			 */
 			HTProgress(line_buffer);
-			if (TRACE)
-			    fprintf(stderr,
-				    "HTTP: Picked up location '%s'\n",
+			CTRACE(tfp, "HTTP: Picked up location '%s'\n",
 				    redirecting_url);
 			if (cp1)
 			    *cp1 = LF;
@@ -1408,9 +1354,7 @@ Cookie2_continuation:
 			     *	Append our URL. - FM
 			     */
 			    StrAllocCat(redirecting_url, anAnchor->address);
-			    if (TRACE)
-				fprintf(stderr,
-					"HTTP: Proxy URL is '%s'\n",
+			    CTRACE(tfp, "HTTP: Proxy URL is '%s'\n",
 					redirecting_url);
 			}
 			if (!do_post ||
@@ -1474,8 +1418,7 @@ Cookie2_continuation:
 	       *  header, so we'll show the user what we got, if
 	       *  anything. - FM
 	       */
-	      if (TRACE)
-		  fprintf (stderr, "HTTP: Failed to pick up location.\n");
+	      CTRACE (tfp, "HTTP: Failed to pick up location.\n");
 	      doing_redirect = FALSE;
 	      permanent_redirection = FALSE;
 	      start_of_data = line_kept_clean;
@@ -1532,10 +1475,9 @@ Cookie2_continuation:
 			goto clean_up;
 		    }
 
-		    if (TRACE)
-			fprintf(stderr, "%s %d %s\n",
-			      "HTTP: close socket", s,
-			      "to retry with Access Authorization");
+		    CTRACE(tfp, "%s %d %s\n",
+				"HTTP: close socket", s,
+				"to retry with Access Authorization");
 
 		    _HTProgress (
 			"Retrying with access authorization information.");
@@ -1583,10 +1525,9 @@ Cookie2_continuation:
 			goto clean_up;
 		    }
 
-		    if (TRACE)
-			fprintf(stderr, "%s %d %s\n",
-			      "HTTP: close socket", s,
-			      "to retry with Proxy Authorization");
+		    CTRACE(tfp, "%s %d %s\n",
+				"HTTP: close socket", s,
+				"to retry with Proxy Authorization");
 
 		    _HTProgress (
 			"Retrying with proxy authorization information.");
@@ -1779,8 +1720,7 @@ Cookie2_continuation:
       (*target->isa->_abort)(target, NULL);
       HTTP_NETCLOSE(s, handle);
       if (!already_retrying && !do_post) {
-	  if (TRACE)
-	      fprintf (stderr, "HTTP: Trying again with HTTP0 request.\n");
+	  CTRACE (tfp, "HTTP: Trying again with HTTP0 request.\n");
 	  /*
 	  **  May as well consider it an interrupt -- right?
 	  */
diff --git a/WWW/Library/Implementation/HTTelnet.c b/WWW/Library/Implementation/HTTelnet.c
index 3a03eb33..d842f230 100644
--- a/WWW/Library/Implementation/HTTelnet.c
+++ b/WWW/Library/Implementation/HTTelnet.c
@@ -91,8 +91,7 @@ PRIVATE int remote_session ARGS2(char *, acc_method, char *, host)
 	    *port++ = '\0';	/* Split */
 
     if (!hostname || *hostname == '\0') {
-	if (TRACE)
-	    fprintf(stderr, "HTTelnet: No host specified!\n");
+	CTRACE(tfp, "HTTelnet: No host specified!\n");
 	return HT_NO_DATA;
     }
 
@@ -149,8 +148,7 @@ PRIVATE int remote_session ARGS2(char *, acc_method, char *, host)
 		hostname,
 		port ? port : "");
 
-	if (TRACE)
-	    fprintf(stderr, "HTTelnet: Command is: %s\n\n", command);
+	CTRACE(tfp, "HTTelnet: Command is: %s\n\n", command);
 	system(command);
 	return HT_NO_DATA;		/* Ok - it was done but no data */
 #define TELNET_DONE
@@ -176,8 +174,7 @@ PRIVATE int remote_session ARGS2(char *, acc_method, char *, host)
 		port ? port : "");
 	}
 
-	if (TRACE)
-	    fprintf(stderr, "HTTelnet: Normal: Command is: %s\n\n", command);
+	CTRACE(tfp, "HTTelnet: Normal: Command is: %s\n\n", command);
 #ifdef __DJGPP__
        __djgpp_set_ctrl_c(0);
        _go32_want_ctrl_break(1);
@@ -216,8 +213,7 @@ PRIVATE int remote_session ARGS2(char *, acc_method, char *, host)
 		hostname);
 	}
 
-	if (TRACE)
-	    fprintf(stderr, "HTTelnet: Command is: %s\n\n", command);
+	CTRACE(tfp, "HTTelnet: Command is: %s\n\n", command);
 	system(command);
 	return HT_NO_DATA;		/* Ok - it was done but no data */
 #define TELNET_DONE
@@ -272,8 +268,7 @@ PRIVATE int remote_session ARGS2(char *, acc_method, char *, host)
 		}
 	    }
 
-	    if (TRACE)
-		fprintf(stderr, "HTTelnet: Command is: %s\n\n", command);
+	    CTRACE(tfp, "HTTelnet: Command is: %s\n\n", command);
 	    system(command);
 	    return HT_NO_DATA;		/* Ok - it was done but no data */
 	}
@@ -300,8 +295,7 @@ PRIVATE int remote_session ARGS2(char *, acc_method, char *, host)
 		port ? port : "");
 	}
 
-	if (TRACE)
-	    fprintf(stderr, "HTTelnet: Command is: %s\n\n", command);
+	CTRACE(tfp, "HTTelnet: Command is: %s\n\n", command);
 	system(command);
 	return HT_NO_DATA;		/* Ok - it was done but no data */
 #define TELNET_DONE
@@ -313,8 +307,7 @@ PRIVATE int remote_session ARGS2(char *, acc_method, char *, host)
 		port ? "/PORT=" : "",
 		port ? port : "",
 		hostname);
-	    if (TRACE)
-		fprintf(stderr, "HTTelnet: Command is: %s\n\n", command);
+	    CTRACE(tfp, "HTTelnet: Command is: %s\n\n", command);
 	    system(command);
 	}
 	else {
@@ -358,8 +351,7 @@ PRIVATE int remote_session ARGS2(char *, acc_method, char *, host)
 		hostname);
 	}
 
-	if (TRACE)
-	    fprintf(stderr, "HTTelnet: Command is: %s\n\n", command);
+	CTRACE(tfp, "HTTelnet: Command is: %s\n\n", command);
 	system(command);
 	return HT_NO_DATA;		/* Ok - it was done but no data */
     }
@@ -400,8 +392,7 @@ PRIVATE int remote_session ARGS2(char *, acc_method, char *, host)
 	    }
 	}
 
-	if (TRACE)
-	    fprintf(stderr, "HTTelnet: Command is: %s\n\n", command);
+	CTRACE(tfp, "HTTelnet: Command is: %s\n\n", command);
 	system(command);
 	return HT_NO_DATA;		/* Ok - it was done but no data */
     }
@@ -424,8 +415,7 @@ PRIVATE int remote_session ARGS2(char *, acc_method, char *, host)
 		port ? port : "");
 	}
 
-	if (TRACE)
-	    fprintf(stderr, "HTTelnet: Command is: %s\n\n", command);
+	CTRACE(tfp, "HTTelnet: Command is: %s\n\n", command);
 	system(command);
 	return HT_NO_DATA;		/* Ok - it was done but no data */
     }
@@ -435,8 +425,7 @@ PRIVATE int remote_session ARGS2(char *, acc_method, char *, host)
 		port ? "/PORT=" : "",
 		port ? port : "",
 		hostname);
-	    if (TRACE)
-		fprintf(stderr, "HTTelnet: Command is: %s\n\n", command);
+	    CTRACE(tfp, "HTTelnet: Command is: %s\n\n", command);
 	    system(command);
 	}
 	else {
@@ -458,8 +447,7 @@ PRIVATE int remote_session ARGS2(char *, acc_method, char *, host)
 		port ? "/PORT=" : "",
 		port ? port : "",
 		hostname);
-	    if (TRACE)
-		fprintf(stderr, "HTTelnet: Command is: %s\n\n", command);
+	    CTRACE(tfp, "HTTelnet: Command is: %s\n\n", command);
 	    system(command);
 	}
 	else {
@@ -486,8 +474,7 @@ PRIVATE int remote_session ARGS2(char *, acc_method, char *, host)
 	if (login_protocol == telnet) { 		/* telnet only */
 	    sprintf(command, "TELNET  %s",	/* @@ Bug: port ignored */
 		hostname);
-	    if (TRACE)
-		fprintf(stderr, "HTTelnet: Command is: %s\n\n", command);
+	    CTRACE(tfp, "HTTelnet: Command is: %s\n\n", command);
 	    system(command);
 	    return HT_NO_DATA;		/* Ok - it was done but no data */
 	}
@@ -549,9 +536,7 @@ ARGS4
     int status;
 
     if (sink) {
-	if (TRACE)
-	    fprintf(stderr,
-	   "HTTelnet: Can't output a live session -- must be interactive!\n");
+	CTRACE(tfp, "HTTelnet: Can't output a live session -- must be interactive!\n");
 	return HT_NO_DATA;
     }
     acc_method =  HTParse(addr, "file:", PARSE_ACCESS);
@@ -559,8 +544,7 @@ ARGS4
     host = HTParse(addr, "", PARSE_HOST);
     if (!host || *host == '\0') {
 	status = HT_NO_DATA;
-	if (TRACE)
-	    fprintf(stderr, "HTTelnet: No host specified!\n");
+	CTRACE(tfp, "HTTelnet: No host specified!\n");
     } else {
 	status = remote_session(acc_method, host);
     }
diff --git a/WWW/Library/Implementation/HTUtils.h b/WWW/Library/Implementation/HTUtils.h
index d96a6cb7..fa3677d2 100644
--- a/WWW/Library/Implementation/HTUtils.h
+++ b/WWW/Library/Implementation/HTUtils.h
@@ -74,7 +74,7 @@
 #define HAVE_UTMP 1
 #endif
 
-#endif
+#endif /* HAVE_CONFIG_H */ 
 
 #ifndef	GCC_UNUSED
 #define	GCC_UNUSED /* nothing */
@@ -88,6 +88,15 @@
 #define popen _popen
 #define pclose _pclose
 #endif /* _WINDOWS */
+ 
+#ifdef __EMX__ 
+#include <unistd.h> /* should be re-include protected under EMX */ 
+#include <stdlib.h> /* should be re-include protected under EMX */ 
+#define getcwd _getcwd2 
+#define chdir _chdir2 
+ 
+#endif 
+ 
 
 #ifdef SHORT_NAMES
 #define WWW_TraceFlag HTTrFlag
diff --git a/WWW/Library/Implementation/HTVMSUtils.c b/WWW/Library/Implementation/HTVMSUtils.c
index ca800517..69198b65 100644
--- a/WWW/Library/Implementation/HTVMSUtils.c
+++ b/WWW/Library/Implementation/HTVMSUtils.c
@@ -106,12 +106,10 @@ unsigned long Prv[2], PreviousPrv[2];
    Prv[1] = 0;
    Result = sys$setprv(1,&Prv,0,&PreviousPrv);
 
-   if (TRACE) {
-      if (Result == SS$_NORMAL) {
-         if (!(PreviousPrv[0] & PRV$M_SYSPRV)) {
-            fprintf(stderr, "HTVMS_enableSysPrv: Enabled SYSPRV\n");
-         }
-      }
+   if (Result == SS$_NORMAL) {
+       if (!(PreviousPrv[0] & PRV$M_SYSPRV)) {
+           CTRACE(tfp, "HTVMS_enableSysPrv: Enabled SYSPRV\n");
+       }
    }
 }
 
@@ -134,12 +132,10 @@ unsigned long Prv[2], PreviousPrv[2];
    Prv[1] = 0;
    Result = sys$setprv(0,&Prv,0,&PreviousPrv);
 
-   if (TRACE) {
-      if (Result == SS$_NORMAL) {
-         if (PreviousPrv[0] & PRV$M_SYSPRV) {
-            fprintf(stderr, "HTVMS_disableSysPrv: Disabled SYSPRV\n");
-         }
-      }
+   if (Result == SS$_NORMAL) {
+       if (PreviousPrv[0] & PRV$M_SYSPRV) {
+           CTRACE(tfp, "HTVMS_disableSysPrv: Disabled SYSPRV\n");
+       }
    }
 }
 
@@ -900,7 +896,7 @@ PUBLIC int HTVMSBrowseDir ARGS4(
     extern BOOLEAN no_dotfiles, show_dotfiles;
 
     HTUnEscape(pathname);
-    CTRACE(stderr,"HTVMSBrowseDir: Browsing `%s\'\n", pathname);
+    CTRACE(tfp,"HTVMSBrowseDir: Browsing `%s\'\n", pathname);
 
     /*
      *  Require at least two elements (presumably a device and directory)
@@ -1178,7 +1174,7 @@ PUBLIC int HTVMSBrowseDir ARGS4(
 	    /* Now, update the BTree etc. */
 	    if(entry_info->display)
 	      {
-		 CTRACE(stderr,"Adding file to BTree: %s\n",
+		 CTRACE(tfp,"Adding file to BTree: %s\n",
 						      entry_info->filename);
 	         HTBTree_add(bt, (VMSEntryInfo *)entry_info); 
 	      }
diff --git a/WWW/Library/Implementation/HTWAIS.c b/WWW/Library/Implementation/HTWAIS.c
index 627086ab..11bc6bad 100644
--- a/WWW/Library/Implementation/HTWAIS.c
+++ b/WWW/Library/Implementation/HTWAIS.c
@@ -272,22 +272,20 @@ PRIVATE char * WWW_from_WAIS ARGS1(
     int i, l;
     if (TRACE) {
 	char *p;
-	fprintf(stderr, "WAIS id (%d bytes) is ", (int)docid->size);
+	fprintf(tfp, "WAIS id (%d bytes) is ", (int)docid->size);
 	for (p = docid->bytes; p < docid->bytes+docid->size; p++) {
 	    if ((*p >= ' ') && (*p<= '~')) /* Assume ASCII! */
-		fprintf(stderr, "%c", *p);
+		fprintf(tfp, "%c", *p);
 	    else
-		fprintf(stderr, "<%x>", (unsigned)*p);
+		fprintf(tfp, "<%x>", (unsigned)*p);
 	}
-	fprintf(stderr, "\n");
+	fprintf(tfp, "\n");
     }
     for (p = docid->bytes;
 	 (p < docid->bytes+docid->size) && (q < &buf[BIG]);) {
-	if (TRACE)
-	    fprintf(stderr, "    Record type %d, length %d\n", p[0], p[1]);
+	CTRACE(tfp, "    Record type %d, length %d\n", p[0], p[1]);
 	if (*p > 10) {
-	    if (TRACE)
-		fprintf(stderr, "Eh? DOCID record type of %d!\n", *p);
+	    CTRACE(tfp, "Eh? DOCID record type of %d!\n", *p);
 	    return 0;
 	}
 	{	/* Bug fix -- allow any byte value 15 Apr 93 */
@@ -316,8 +314,7 @@ PRIVATE char * WWW_from_WAIS ARGS1(
 	*q++= ';';		/* Terminate field */
     }
     *q++ = 0;			/* Terminate string */
-    if (TRACE)
-	fprintf(stderr, "WWW form of id: %s\n", buf);
+    CTRACE(tfp, "WWW form of id: %s\n", buf);
     {
 	char * result = (char *)malloc(strlen(buf)+1);
 	if (!result)
@@ -347,8 +344,8 @@ PRIVATE any * WAIS_from_WWW ARGS2(
     char *q;	/* Poisition of "=" */
     char *s;	/* Position of semicolon */
     int n;	/* size */
-    if (TRACE)
-	fprintf(stderr, "WWW id (to become WAIS id): %s\n", docname);
+
+    CTRACE(tfp, "WWW id (to become WAIS id): %s\n", docname);
     for (n = 0, p = docname; *p; p++) { /* Count sizes of strings */
 	n++;
 	if (*p == ';')
@@ -404,14 +401,14 @@ PRIVATE any * WAIS_from_WWW ARGS2(
 
     if (TRACE) {
 	char *p;
-	fprintf(stderr, "WAIS id (%d bytes) is ", (int)docid->size);
+	fprintf(tfp, "WAIS id (%d bytes) is ", (int)docid->size);
 	for (p = docid->bytes; p < docid->bytes+docid->size; p++) {
 	    if ((*p >= ' ') && (*p<= '~')) /* Assume ASCII! */
-		fprintf(stderr, "%c", *p);
+		fprintf(tfp, "%c", *p);
 	    else
-		fprintf(stderr, "<%x>", (unsigned)*p);
+		fprintf(tfp, "<%x>", (unsigned)*p);
 	}
-	fprintf(stderr, "\n");
+	fprintf(tfp, "\n");
     }
     return docid;		/* Ok */
 
@@ -473,8 +470,7 @@ PRIVATE void display_search_response ARGS4(
 
     BOOL archie =  strstr(database, "archie")!=0;	/* Specical handling */
 
-    if (TRACE)
-	fprintf(stderr, "HTWAIS: Displaying search response\n");
+    CTRACE(tfp, "HTWAIS: Displaying search response\n");
     PUTS("Index ");
     START(HTML_EM);
     PUTS(database);
@@ -512,9 +508,7 @@ PRIVATE void display_search_response ARGS4(
 		/*
 		**  Make a printable string out of the document id.
 		*/
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTWAIS:  %2ld: Score: %4ld, lines:%4ld '%s'\n",
+		CTRACE(tfp, "HTWAIS:  %2ld: Score: %4ld, lines:%4ld '%s'\n",
 			    i,
 			    (long int)(info->DocHeaders[k]->Score),
 			    (long int)(info->DocHeaders[k]->Lines),
@@ -706,8 +700,7 @@ PUBLIC int HTLoadWAIS ARGS4(
     if (!ok)
 	return HTLoadError(sink, 500, "Syntax error in WAIS URL");
 
-    if (TRACE)
-	fprintf(stderr, "HTWAIS: Parsed OK\n");
+    CTRACE(tfp, "HTWAIS: Parsed OK\n");
 
     service = strchr(names, ':');
     if (service)
@@ -724,19 +717,16 @@ PUBLIC int HTLoadWAIS ARGS4(
 
     } else if (!(key && !*key)) {
 	int status;
-	if (TRACE)
-	fprintf (stderr, "===WAIS=== calling mosaic_connect_to_server\n");
+	CTRACE (tfp, "===WAIS=== calling mosaic_connect_to_server\n");
 	status = mosaic_connect_to_server(server_name,
 					  atoi(service),
 					  &connection);
 	if (status == 0) {
-	    if (TRACE)
-		fprintf (stderr, "===WAIS=== connection failed\n");
+	    CTRACE (tfp, "===WAIS=== connection failed\n");
 	    FREE(names);
 	    return HT_NOT_LOADED;
 	} else if (status == -1) {
-	    if (TRACE)
-		fprintf (stderr, "===WAIS=== connection interrupted\n");
+	    CTRACE (tfp, "===WAIS=== connection interrupted\n");
 	    FREE(names);
 	    return HT_NOT_LOADED;
 	}
@@ -809,10 +799,9 @@ PUBLIC int HTLoadWAIS ARGS4(
 		server_name, service, www_database);
 
 	fp = fopen(filename, "r");	/* Have we found this already? */
-	if (TRACE) fprintf(stderr,
-		"HTWAIS: Description of server %s %s.\n",
-		filename,
-		fp ? "exists already" : "does NOT exist!");
+	CTRACE(tfp, "HTWAIS: Description of server %s %s.\n",
+		    filename,
+		    fp ? "exists already" : "does NOT exist!");
 
 	if (fp) {
 	    char c;
@@ -865,8 +854,8 @@ PUBLIC int HTLoadWAIS ARGS4(
 	PUTS("\n");
 
 	request_buffer_length = MAX_MESSAGE_LEN; /* Amount left */
-	if (TRACE) fprintf(stderr, "HTWAIS: Search for `%s' in `%s'\n",
-		keywords, wais_database);
+	CTRACE(tfp, "HTWAIS: Search for `%s' in `%s'\n",
+		    keywords, wais_database);
 	if(NULL ==
 	generate_search_apdu(request_message + HEADER_LENGTH,
 				&request_buffer_length,
@@ -924,9 +913,8 @@ PUBLIC int HTLoadWAIS ARGS4(
 	any   doc_chunk;
 	any * docid = &doc_chunk;
 
-	if (TRACE) fprintf(stderr,
-		"HTWAIS: Retrieve document id `%s' type `%s' length %ld\n",
-		docname, doctype, document_length);
+	CTRACE(tfp, "HTWAIS: Retrieve document id `%s' type `%s' length %ld\n",
+		    docname, doctype, document_length);
 
 	format_in =
 	  !strcmp(doctype, "WSRC") ? HTAtom_for("application/x-wais-source") :
@@ -962,8 +950,7 @@ PUBLIC int HTLoadWAIS ARGS4(
 	    char *type = s_strdup(doctype);	/* Gets freed I guess */
 #endif /* VMS */
 	    request_buffer_length = MAX_MESSAGE_LEN; /* Amount left */
-	    if (TRACE)
-		fprintf(stderr, "HTWAIS: Slice number %ld\n", count);
+	    CTRACE(tfp, "HTWAIS: Slice number %ld\n", count);
 
 	    if (HTCheckForInterrupt()) {
 		HTAlert ("Data transfer interrupted.");
diff --git a/WWW/Library/Implementation/HTWSRC.c b/WWW/Library/Implementation/HTWSRC.c
index baf759c9..e5a7f830 100644
--- a/WWW/Library/Implementation/HTWSRC.c
+++ b/WWW/Library/Implementation/HTWSRC.c
@@ -162,9 +162,8 @@ PRIVATE void WSRCParser_put_character ARGS2(HTStream*, me, char, c)
 		}
 	    }
 	    if (!par_name[me->param_number]) {	/* Unknown field */
-		if (TRACE) fprintf(stderr,
-		    "HTWSRC: Unknown field `%s' in source file\n",
-		    me->param);
+		CTRACE(tfp, "HTWSRC: Unknown field `%s' in source file\n",
+			    me->param);
 		me->param_number = PAR_UNKNOWN;
 		me->state = before_value;	/* Could be better ignore */
 		return;
diff --git a/WWW/Library/Implementation/HTWriter.c b/WWW/Library/Implementation/HTWriter.c
index 601bdb0a..1e405cbb 100644
--- a/WWW/Library/Implementation/HTWriter.c
+++ b/WWW/Library/Implementation/HTWriter.c
@@ -52,8 +52,7 @@ PRIVATE void flush ARGS1(HTStream *, me)
 	status = NETWRITE(me->soc, me->buffer,	/* Put timeout? @@@ */
 			write_pointer - read_pointer);
 	if (status<0) {
-	    if(TRACE) fprintf(stderr,
-	    "HTWrite: Error: write() on socket returns %d !!!\n", status);
+	    CTRACE(tfp, "HTWrite: Error: write() on socket returns %d !!!\n", status);
 	    return;
 	}
 	read_pointer = read_pointer + status;
@@ -108,8 +107,7 @@ PRIVATE void HTWriter_write ARGS3(HTStream *, me, CONST char*, s, int, l)
 	int status = NETWRITE(me->soc, (char *)read_pointer,
 			write_pointer - read_pointer);
 	if (status<0) {
-	    if(TRACE) fprintf(stderr,
-	    "HTWriter_write: Error on socket output stream!!!\n");
+	    CTRACE(tfp, "HTWriter_write: Error on socket output stream!!!\n");
 	    return;
 	}
 	read_pointer = read_pointer + status;
diff --git a/WWW/Library/Implementation/SGML.c b/WWW/Library/Implementation/SGML.c
index 90210c13..21937698 100644
--- a/WWW/Library/Implementation/SGML.c
+++ b/WWW/Library/Implementation/SGML.c
@@ -282,17 +282,15 @@ PRIVATE void handle_attribute_name ARGS2(
 	    FREE(context->value[i]);
 #ifdef USE_COLOR_STYLE
 	    current_is_class=(!strcasecomp("class", s));
-	    if (TRACE)
-		fprintf(stderr, "SGML: found attribute %s, %d\n", s, current_is_class);
+	    CTRACE(tfp, "SGML: found attribute %s, %d\n", s, current_is_class);
 #endif
 	    return;
 	} /* if */
 
     } /* for */
 
-    if (TRACE)
-	fprintf(stderr, "SGML: Unknown attribute %s for tag %s\n",
-	    s, context->current_tag->name);
+    CTRACE(tfp, "SGML: Unknown attribute %s for tag %s\n",
+		s, context->current_tag->name);
     context->current_attribute_number = INVALID;	/* Invalid */
 }
 
@@ -310,18 +308,15 @@ PRIVATE void handle_attribute_value ARGS2(
 	if (current_is_class)
 	{
 	    strncpy (class_string, s, TEMPSTRINGSIZE);
-	    if (TRACE)
-		fprintf(stderr, "SGML: class is '%s'\n", s);
+	    CTRACE(tfp, "SGML: class is '%s'\n", s);
 	}
 	else
 	{
-	    if (TRACE)
-		fprintf(stderr, "SGML: attribute value is '%s'\n", s);
+	    CTRACE(tfp, "SGML: attribute value is '%s'\n", s);
 	}
 #endif
     } else {
-	if (TRACE)
-	    fprintf(stderr, "SGML: Attribute value %s ignored\n", s);
+	CTRACE(tfp, "SGML: Attribute value %s ignored\n", s);
     }
     context->current_attribute_number = INVALID; /* can't have two assignments! */
 }
@@ -512,9 +507,7 @@ PRIVATE void handle_entity ARGS2(
     */
     if (!strcmp(s, "zwnj") ||
 	!strcmp(s, "zwj")) {
-	if (TRACE) {
-	    fprintf(stderr, "handle_entity: Ignoring '%s'.\n", s);
-	}
+	CTRACE(tfp, "handle_entity: Ignoring '%s'.\n", s);
 	FoundEntity = TRUE;
 	return;
     }
@@ -524,9 +517,7 @@ PRIVATE void handle_entity ARGS2(
     */
     if (!strcmp(s, "lrm") ||
 	!strcmp(s, "rlm")) {
-	if (TRACE) {
-	    fprintf(stderr, "handle_entity: Ignoring '%s'.\n", s);
-	}
+	CTRACE(tfp, "handle_entity: Ignoring '%s'.\n", s);
 	FoundEntity = TRUE;
 	return;
     }
@@ -553,8 +544,7 @@ PRIVATE void handle_entity ARGS2(
     /*
     **	If entity string not found, display as text.
     */
-    if (TRACE)
-	fprintf(stderr, "SGML: Unknown entity '%s'\n", s);
+    CTRACE(tfp, "SGML: Unknown entity '%s'\n", s);
     PUTC('&');
     for (p = s; *p; p++) {
 	PUTC(*p);
@@ -572,8 +562,7 @@ PRIVATE void handle_comment ARGS1(
 {
     CONST char *s = context->string->data;
 
-    if (TRACE)
-	fprintf(stderr, "SGML Comment:\n<%s>\n", s);
+    CTRACE(tfp, "SGML Comment:\n<%s>\n", s);
 
     if (context->csi == NULL &&
 	strncmp(s, "!--#", 4) == 0 &&
@@ -593,8 +582,7 @@ PRIVATE void handle_identifier ARGS1(
 {
     CONST char *s = context->string->data;
 
-    if (TRACE)
-	fprintf(stderr, "SGML Identifier\n<%s>\n", s);
+    CTRACE(tfp, "SGML Identifier\n<%s>\n", s);
 
     return;
 }
@@ -608,8 +596,7 @@ PRIVATE void handle_doctype ARGS1(
 {
     CONST char *s = context->string->data;
 
-    if (TRACE)
-	fprintf(stderr, "SGML Doctype\n<%s>\n", s);
+    CTRACE(tfp, "SGML Doctype\n<%s>\n", s);
 
     return;
 }
@@ -623,8 +610,7 @@ PRIVATE void handle_marked ARGS1(
 {
     CONST char *s = context->string->data;
 
-    if (TRACE)
-	fprintf(stderr, "SGML Marked Section:\n<%s>\n", s);
+    CTRACE(tfp, "SGML Marked Section:\n<%s>\n", s);
 
     return;
 }
@@ -638,8 +624,7 @@ PRIVATE void handle_sgmlent ARGS1(
 {
     CONST char *s = context->string->data;
 
-    if (TRACE)
-	fprintf(stderr, "SGML Entity Declaration:\n<%s>\n", s);
+    CTRACE(tfp, "SGML Entity Declaration:\n<%s>\n", s);
 
     return;
 }
@@ -653,8 +638,7 @@ PRIVATE void handle_sgmlele ARGS1(
 {
     CONST char *s = context->string->data;
 
-    if (TRACE)
-	fprintf(stderr, "SGML Element Declaration:\n<%s>\n", s);
+    CTRACE(tfp, "SGML Element Declaration:\n<%s>\n", s);
 
     return;
 }
@@ -668,8 +652,7 @@ PRIVATE void handle_sgmlatt ARGS1(
 {
     CONST char *s = context->string->data;
 
-    if (TRACE)
-	fprintf(stderr, "SGML Attribute Declaration:\n<%s>\n", s);
+    CTRACE(tfp, "SGML Attribute Declaration:\n<%s>\n", s);
 
     return;
 }
@@ -765,8 +748,7 @@ PRIVATE void end_element ARGS2(
 	       (stackpos > 1 || (!extra_action_taken && stackpos == 0))) {
 	    canclose_check = can_close(old_tag, context->element_stack->tag);
 	    if (canclose_check != close_NO) {
-		if (TRACE)
-		    fprintf(stderr, "SGML: End </%s> \t<- %s end </%s>\n",
+		CTRACE(tfp, "SGML: End </%s> \t<- %s end </%s>\n",
 			    context->element_stack->tag->name,
 			    canclose_check == close_valid ? "supplied," : "forced by",
 			    old_tag->name);
@@ -774,8 +756,7 @@ PRIVATE void end_element ARGS2(
 		extra_action_taken = YES;
 		stackpos = is_on_stack(context, old_tag);
 	    } else {
-		if (TRACE)
-		    fprintf(stderr, "SGML: Still open %s \t<- invalid end </%s>\n",
+		CTRACE(tfp, "SGML: Still open %s \t<- invalid end </%s>\n",
 			    context->element_stack->tag->name,
 			    old_tag->name);
 		return;
@@ -783,8 +764,7 @@ PRIVATE void end_element ARGS2(
 	}
 
 	if (stackpos == 0 && old_tag->contents != SGML_EMPTY) {
-	    if (TRACE)
-		fprintf(stderr, "SGML: Still open %s, no open %s for </%s>\n",
+	    CTRACE(tfp, "SGML: Still open %s, no open %s for </%s>\n",
 			context->element_stack ?
 			context->element_stack->tag->name : "none",
 			old_tag->name,
@@ -792,8 +772,7 @@ PRIVATE void end_element ARGS2(
 	    return;
 	}
 	if (stackpos > 1) {
-	    if (TRACE)
-		fprintf(stderr, "SGML: Nesting <%s>...<%s> \t<- invalid end </%s>\n",
+	    CTRACE(tfp, "SGML: Nesting <%s>...<%s> \t<- invalid end </%s>\n",
 			old_tag->name,
 			context->element_stack->tag->name,
 			old_tag->name);
@@ -818,23 +797,18 @@ PRIVATE void end_element ARGS2(
 	    /*
 	    **	Ignore the end tag. - FM
 	    */
-	    if (TRACE) {
-		fprintf(stderr,
-			"SGML: Ignoring end tag </%s> in SELECT block.\n",
+	    CTRACE(tfp, "SGML: Ignoring end tag </%s> in SELECT block.\n",
 			old_tag->name);
-	    }
 	    return;
 	}
     }
     /*
     **	Handle the end tag. - FM
     */
-    if (TRACE)
-	fprintf(stderr, "SGML: End </%s>\n", old_tag->name);
+    CTRACE(tfp, "SGML: End </%s>\n", old_tag->name);
     if (old_tag->contents == SGML_EMPTY) {
-	if (TRACE)
-	    fprintf(stderr, "SGML: Illegal end tag </%s> found.\n",
-			    old_tag->name);
+	CTRACE(tfp, "SGML: Illegal end tag </%s> found.\n",
+		    old_tag->name);
 	return;
     }
 #ifdef WIND_DOWN_STACK
@@ -847,13 +821,11 @@ PRIVATE void end_element ARGS2(
 
 	if (old_tag != t) {		/* Mismatch: syntax error */
 	    if (context->element_stack->next) { /* This is not the last level */
-		if (TRACE) fprintf(stderr,
-		"SGML: Found </%s> when expecting </%s>. </%s> assumed.\n",
-		    old_tag->name, t->name, t->name);
+		CTRACE(tfp, "SGML: Found </%s> when expecting </%s>. </%s> assumed.\n",
+			    old_tag->name, t->name, t->name);
 	    } else {			/* last level */
-		if (TRACE) fprintf(stderr,
-		    "SGML: Found </%s> when expecting </%s>. </%s> Ignored.\n",
-		    old_tag->name, t->name, old_tag->name);
+		CTRACE(tfp, "SGML: Found </%s> when expecting </%s>. </%s> Ignored.\n",
+			    old_tag->name, t->name, old_tag->name);
 		return; 		/* Ignore */
 	    }
 	}
@@ -872,9 +844,8 @@ PRIVATE void end_element ARGS2(
 	/* Syntax error path only */
 
     }
-    if (TRACE)
-	fprintf(stderr, "SGML: Extra end tag </%s> found and ignored.\n",
-			old_tag->name);
+    CTRACE(tfp, "SGML: Extra end tag </%s> found and ignored.\n",
+		old_tag->name);
 }
 
 
@@ -901,8 +872,7 @@ PRIVATE void start_element ARGS1(
 					      direct_container))) {
 	    canclose_check = can_close(new_tag, context->element_stack->tag);
 	    if (canclose_check != close_NO) {
-		if (TRACE)
-		    fprintf(stderr, "SGML: End </%s> \t<- %s start <%s>\n",
+		CTRACE(tfp, "SGML: End </%s> \t<- %s start <%s>\n",
 			    context->element_stack->tag->name,
 			    canclose_check == close_valid ? "supplied," : "forced by",
 			    new_tag->name);
@@ -911,8 +881,7 @@ PRIVATE void start_element ARGS1(
 		if (canclose_check  == close_error)
 		    direct_container = NO;
 	    } else {
-		if (TRACE)
-		    fprintf(stderr, "SGML: Still open %s \t<- invalid start <%s>\n",
+		CTRACE(tfp, "SGML: Still open %s \t<- invalid start <%s>\n",
 			    context->element_stack->tag->name,
 			    new_tag->name);
 	    }
@@ -921,8 +890,7 @@ PRIVATE void start_element ARGS1(
 	    (context->element_stack->tag->flags & Tgf_strict) &&
 	    !(valid = element_valid_within(new_tag, context->element_stack->tag,
 					   direct_container))) {
-	    if (TRACE)
-		fprintf(stderr, "SGML: Still open %s \t<- ignoring start <%s>\n",
+	    CTRACE(tfp, "SGML: Still open %s \t<- ignoring start <%s>\n",
 			context->element_stack->tag->name,
 			new_tag->name);
 	    return;
@@ -935,8 +903,7 @@ PRIVATE void start_element ARGS1(
 	    for (; i< new_tag->number_of_attributes && !has_attributes; i++)
 		has_attributes = context->present[i];
 	    if (!has_attributes) {
-		if (TRACE)
-		    fprintf(stderr, "SGML: Still open %s, converting invalid <%s> to </%s>\n",
+		CTRACE(tfp, "SGML: Still open %s, converting invalid <%s> to </%s>\n",
 			    context->element_stack->tag->name,
 			    new_tag->name,
 			    new_tag->name);
@@ -951,8 +918,7 @@ PRIVATE void start_element ARGS1(
 						   new_tag,
 						   context->element_stack->tag,
 						   direct_container))) {
-	    if (TRACE)
-		fprintf(stderr, "SGML: Still open %s \t<- invalid start <%s>\n",
+	    CTRACE(tfp, "SGML: Still open %s \t<- invalid start <%s>\n",
 			context->element_stack->tag->name,
 			new_tag->name);
 	}
@@ -998,18 +964,14 @@ PRIVATE void start_element ARGS1(
 		**  It is another form-related start tag, so terminate
 		**  the current SELECT block and fall through. - FM
 		*/
-		if (TRACE)
-		    fprintf(stderr,
-		       "SGML: Faking SELECT end tag before <%s> start tag.\n",
+		CTRACE(tfp, "SGML: Faking SELECT end tag before <%s> start tag.\n",
 			    new_tag->name);
 		end_element(context, SGMLFindTag(context->dtd, "SELECT"));
 	    } else {
 		/*
 		**  Ignore the start tag. - FM
 		*/
-		if (TRACE)
-		    fprintf(stderr,
-			  "SGML: Ignoring start tag <%s> in SELECT block.\n",
+		CTRACE(tfp, "SGML: Ignoring start tag <%s> in SELECT block.\n",
 			    new_tag->name);
 		return;
 	    }
@@ -1018,8 +980,7 @@ PRIVATE void start_element ARGS1(
     /*
     **	Handle the start tag. - FM
     */
-    if (TRACE)
-	fprintf(stderr, "SGML: Start <%s>\n", new_tag->name);
+    CTRACE(tfp, "SGML: Start <%s>\n", new_tag->name);
     (*context->actions->start_element)(
 	context->target,
 	new_tag - context->dtd->tags,
@@ -1533,11 +1494,8 @@ top1:
 		   (uck = UCTransUniChar(unsign_c,
 					 context->outUCLYhndl)) >= 32 &&
 		   uck < 256) {
-	    if (TRACE) {
-		fprintf(stderr,
-			"UCTransUniChar returned 0x%.2lX:'%c'.\n",
+	    CTRACE(tfp, "UCTransUniChar returned 0x%.2lX:'%c'.\n",
 			uck, FROMASCII((char)uck));
-	    }
 	    /*
 	    **	We got one octet from the conversions, so use it. - FM
 	    */
@@ -1749,10 +1707,8 @@ top1:
 		*/
 		char temp[8];
 
-		if (TRACE) {
-		    fprintf(stderr,
-		"SGML_character: Handling 'zwnj' entity as 'WBR' element.\n");
-		}
+		CTRACE(tfp, "SGML_character: Handling 'zwnj' entity as 'WBR' element.\n");
+
 		if (c != ';') {
 		    sprintf(temp, "<WBR>%c", c);
 		} else {
@@ -1981,10 +1937,8 @@ top1:
 		    */
 		    char temp[8];
 
-		    if (TRACE) {
-			fprintf(stderr,
-      "SGML_character: Handling '8204' (zwnj) reference as 'WBR' element.\n");
-		    }
+		    CTRACE(tfp, "SGML_character: Handling '8204' (zwnj) reference as 'WBR' element.\n");
+
 		    /*
 		    **	Include the terminator if it is not
 		    **	the standard semi-colon. - FM
@@ -2085,7 +2039,7 @@ top1:
 			LYstrncpy(replace_buf,
 				  string->data,
 				  (string->size < 64 ? string->size : 63));
-			fprintf(stderr,
+			fprintf(tfp,
 				"SGML_character: Ignoring '%s%s'.\n",
 				(context->isHex ? "&#x" : "&#"),
 				replace_buf);
@@ -2266,9 +2220,8 @@ top1:
 	    */
 	    HTTag * t;
 	    if (c == '/') {
-		if (TRACE)
-		    if (string->size!=0)
-			fprintf(stderr,"SGML: `<%s/' found!\n", string->data);
+		if (string->size != 0)
+		    CTRACE(tfp,"SGML: `<%s/' found!\n", string->data);
 		context->state = S_end;
 		break;
 	    }
@@ -2286,21 +2239,18 @@ top1:
 		for (i = 0; i < 3; i++) /* recover */
 		    PUTC(string->data[i]);
 		PUTC(c);
-		if (TRACE)
-		    fprintf(stderr, "SGML: Treating <%s%c as text\n",
+		CTRACE(tfp, "SGML: Treating <%s%c as text\n",
 			    string->data, c);
 		string->size = 0;
 		context->state = S_text;
 		break;
 	    } else if (!t) {
-		if (TRACE)
-		    fprintf(stderr, "SGML: *** Invalid element %s\n",
+		CTRACE(tfp, "SGML: *** Invalid element %s\n",
 			    string->data);
 		context->state = (c == '>') ? S_text : S_junk_tag;
 		break;
 	    } else if (t == context->unknown_tag) {
-		if (TRACE)
-		    fprintf(stderr, "SGML: *** Unknown element %s\n",
+		CTRACE(tfp, "SGML: *** Unknown element %s\n",
 			    string->data);
 		/*
 		**  Fall through and treat like valid
@@ -2655,8 +2605,7 @@ top1:
 	if (WHITE(c))
 	    break;		/* Before attribute value */
 	if (c == '>') { 	/* End of tag */
-	    if (TRACE)
-		fprintf(stderr, "SGML: found = but no value\n");
+	    CTRACE(tfp, "SGML: found = but no value\n");
 	    if (context->current_tag->name)
 		start_element(context);
 	    context->state = S_text;
@@ -2802,8 +2751,7 @@ top1:
 		t = SGMLFindTag(dtd, string->data);
 	    }
 	    if (!t || t == context->unknown_tag) {
-		if (TRACE)
-		    fprintf(stderr, "Unknown end tag </%s>\n", string->data);
+		CTRACE(tfp, "Unknown end tag </%s>\n", string->data);
 	    } else {
 		BOOL tag_OK = (c == '>' || WHITE(c));
 		context->current_tag = t;
@@ -2831,9 +2779,7 @@ top1:
 		    **	Don't treat these end tags as invalid,
 		    **	nor act on them. - FM
 		    */
-		    if (TRACE)
-			fprintf(stderr,
-				"SGML: `</%s%c' found!  Ignoring it.\n",
+		    CTRACE(tfp, "SGML: `</%s%c' found!  Ignoring it.\n",
 				string->data, c);
 		    string->size = 0;
 		    context->current_attribute_number = INVALID;
@@ -2871,27 +2817,19 @@ top1:
 			    /*
 			    **	It is not at FORM end tag, so ignore it. - FM
 			    */
-			    if (TRACE) {
-				fprintf(stderr,
-			    "SGML: Ignoring end tag </%s> in SELECT block.\n",
+			    CTRACE(tfp, "SGML: Ignoring end tag </%s> in SELECT block.\n",
 					string->data);
-			    }
 			} else {
 			    /*
 			    **	End the SELECT block and then
 			    **	handle the FORM end tag. - FM
 			    */
-			    if (TRACE) {
-				fprintf(stderr,
-			"SGML: Faking SELECT end tag before </%s> end tag.\n",
+			    CTRACE(tfp, "SGML: Faking SELECT end tag before </%s> end tag.\n",
 					string->data);
-			    }
 			    end_element(context,
 					SGMLFindTag(context->dtd, "SELECT"));
-			    if (TRACE) {
-				fprintf(stderr,
-					"SGML: End </%s>\n", string->data);
-			    }
+			    CTRACE(tfp, "SGML: End </%s>\n", string->data);
+
 			    (*context->actions->end_element)
 				(context->target,
 				 (context->current_tag - context->dtd->tags),
@@ -2902,9 +2840,7 @@ top1:
 			**  Treat a P end tag like a P start tag (Ugh,
 			**  what a hack! 8-). - FM
 			*/
-			if (TRACE)
-			    fprintf(stderr,
-				    "SGML: `</%s%c' found!  Treating as '<%s%c'.\n",
+			CTRACE(tfp, "SGML: `</%s%c' found!  Treating as '<%s%c'.\n",
 				    string->data, c, string->data, c);
 			{
 			    int i;
@@ -2917,10 +2853,8 @@ top1:
 			if (context->current_tag->name)
 			    start_element(context);
 		    } else {
-			if (TRACE) {
-			    fprintf(stderr,
-				    "SGML: End </%s>\n", string->data);
-			}
+			CTRACE(tfp, "SGML: End </%s>\n", string->data);
+
 			(*context->actions->end_element)
 			    (context->target,
 			     (context->current_tag - context->dtd->tags),
@@ -2945,8 +2879,8 @@ top1:
 	    string->size = 0;
 	    context->current_attribute_number = INVALID;
 	    if (c != '>') {
-		if (TRACE && !WHITE(c))
-		    fprintf(stderr,"SGML: `</%s%c' found!\n", string->data, c);
+		if (!WHITE(c))
+		    CTRACE(tfp,"SGML: `</%s%c' found!\n", string->data, c);
 		context->state = S_junk_tag;
 	    } else {
 		context->state = S_text;
diff --git a/src/GridText.c b/src/GridText.c
index fcbe065e..c2f70164 100644
--- a/src/GridText.c
+++ b/src/GridText.c
@@ -54,12 +54,12 @@ unsigned int cached_styles[CACHEH][CACHEW];
 #ifdef USE_COLOR_STYLE_UNUSED
 void LynxClearScreenCache NOARGS
 {
-	int i,j;
-if (TRACE)
-	fprintf(stderr, "flushing cached screen styles\n");
-	for (i=0;i<CACHEH;i++)
-		for (j=0;j<CACHEW;j++)
-			cached_styles[i][j]=s_a;
+    int i,j;
+
+    CTRACE(tfp, "flushing cached screen styles\n");
+    for (i=0;i<CACHEH;i++)
+	for (j=0;j<CACHEW;j++)
+	    cached_styles[i][j]=s_a;
 }
 #endif /* USE_COLOR_STYLE */
 
@@ -312,9 +312,8 @@ PRIVATE void * LY_check_calloc ARGS2(
 	HText * t = HTList_objectAt(loaded_texts, i);
 	if (t == HTMainText)
 	    t = NULL;		/* shouldn't happen */
-	if (TRACE) {
-	    fprintf(stderr,
-		    "\r *** Emergency freeing document %d/%d for '%s'%s!\n",
+	{
+	CTRACE(tfp, "\r *** Emergency freeing document %d/%d for '%s'%s!\n",
 		    i + 1, n,
 		    ((t && t->node_anchor &&
 		      t->node_anchor->address) ?
@@ -408,8 +407,7 @@ PUBLIC HText *	HText_new ARGS1(
 
 #if defined(VMS) && defined (VAXC) && !defined(__DECC)
     status = lib$stat_vm(&VMType, &VMTotal);
-    if (TRACE)
-	fprintf(stderr, "GridText: VMTotal = %d\n", VMTotal);
+    CTRACE(tfp, "GridText: VMTotal = %d\n", VMTotal);
 #endif /* VMS && VAXC && !__DECC */
 
     if (!loaded_texts)	{
@@ -425,12 +423,11 @@ PUBLIC HText *	HText_new ARGS1(
      *  and free it before reloading. - Dick Wesseling (ftu@fi.ruu.nl)
      */
     if (anchor->document) {
-       HTList_removeObject(loaded_texts, anchor->document);
-       if (TRACE)
-	   fprintf(stderr, "GridText: Auto-uncaching\n") ;
-       ((HText *)anchor->document)->node_anchor = NULL;
-       HText_free((HText *)anchor->document);
-       anchor->document = NULL;
+	HTList_removeObject(loaded_texts, anchor->document);
+	CTRACE(tfp, "GridText: Auto-uncaching\n") ;
+	((HText *)anchor->document)->node_anchor = NULL;
+	HText_free((HText *)anchor->document);
+	anchor->document = NULL;
     }
 
     HTList_addObject(loaded_texts, self);
@@ -440,13 +437,11 @@ PUBLIC HText *	HText_new ARGS1(
 #else
     if (HTList_count(loaded_texts) > HTCacheSize) {
 #endif /* VMS && VAXC && !__DECC */
-	if (TRACE)
-	    fprintf(stderr, "GridText: Freeing off cached doc.\n");
+	CTRACE(tfp, "GridText: Freeing off cached doc.\n");
 	HText_free((HText *)HTList_removeFirstObject(loaded_texts));
 #if defined(VMS) && defined (VAXC) && !defined(__DECC)
 	status = lib$stat_vm(&VMType, &VMTotal);
-	if (TRACE)
-	    fprintf(stderr, "GridText: VMTotal reduced to %d\n", VMTotal);
+	CTRACE(tfp, "GridText: VMTotal reduced to %d\n", VMTotal);
 #endif /* VMS && VAXC && !__DECC */
     }
 
@@ -1386,8 +1381,8 @@ PRIVATE void display_page ARGS3(
 			    link_dest_intl = HTAnchor_followTypedLink(
 				(HTAnchor *)Anchor_ptr->anchor, LINK_INTERNAL);
 			    if (link_dest_intl && link_dest_intl != link_dest) {
-				if (TRACE)
-				    fprintf(stderr,
+
+				CTRACE(tfp,
 				    "display_page: unexpected typed link to %s!\n",
 					    link_dest_intl->parent->address);
 				link_dest_intl = NULL;
@@ -1478,9 +1473,8 @@ PRIVATE void display_page ARGS3(
 		/*
 		 *  Not showing anchor.
 		 */
-		if (TRACE &&
-		    Anchor_ptr->hightext && *Anchor_ptr->hightext)
-		    fprintf(stderr,
+		if (Anchor_ptr->hightext && *Anchor_ptr->hightext)
+		    CTRACE(tfp,
 			    "\nGridText: Not showing link, hightext=%s\n",
 			    Anchor_ptr->hightext);
 	    }
@@ -1501,8 +1495,7 @@ PRIVATE void display_page ARGS3(
 		_statusline(MAXLINKS_REACHED);
 		sleep(AlertSecs);
 	    }
-	    if (TRACE)
-	        fprintf(stderr, "\ndisplay_page: MAXLINKS reached.\n");
+	    CTRACE(tfp, "\ndisplay_page: MAXLINKS reached.\n");
 	    break;
 	}
     }
@@ -1608,8 +1601,7 @@ PRIVATE void split_line ARGS2(
     ctrl_chars_on_this_line = 0; /*reset since we are going to a new line*/
     text->LastChar = ' ';
 
-    if (TRACE)
-	fprintf(stderr,"GridText: split_line called\n");
+    CTRACE(tfp,"GridText: split_line called\n");
 
     text->Lines++;
 
@@ -1696,8 +1688,8 @@ PRIVATE void split_line ARGS2(
 	}
     }
     if (previous->numstyles > 0 && previous->styles[LastStyle].direction) {
-	if (TRACE)
-	    fprintf(stderr, "%s\n%s%s\n",
+
+	CTRACE(tfp, "%s\n%s%s\n",
 		    "........... Too many character styles on line:",
 		    "........... ", previous->data);
     }
@@ -2005,8 +1997,8 @@ PUBLIC void HText_setStyle ARGS2(
 	return; 			/* Safety */
     after = text->style->spaceAfter;
     before = style->spaceBefore;
-    if (TRACE)
-	fprintf(stderr, "GridText: Change to style %s\n", style->name);
+
+    CTRACE(tfp, "GridText: Change to style %s\n", style->name);
 
     blank_lines (text, ((after > before) ? after : before));
 
@@ -2692,15 +2684,15 @@ PUBLIC void HText_endAnchor ARGS2(
 	    a = text->last_anchor;
 	}
     }
-    if (TRACE)
-	fprintf(stderr, "HText_endAnchor: number:%d link_type:%d\n",
+
+    CTRACE(tfp, "HText_endAnchor: number:%d link_type:%d\n",
 			a->number, a->link_type);
     if (a->link_type == INPUT_ANCHOR) {
 	/*
 	 *  Shouldn't happen, but put test here anyway to be safe. - LE
 	 */
-	if (TRACE)
-	    fprintf(stderr,
+
+	CTRACE(tfp,
 	   "HText_endAnchor: internal error: last anchor was input field!\n");
 	return;
     }
@@ -3139,8 +3131,8 @@ PUBLIC void HText_endAppend ARGS1(
 
     if (!text)
 	return;
-    if (TRACE)
-	fprintf(stderr,"Gridtext: Entering HText_endAppend\n");
+
+    CTRACE(tfp,"Gridtext: Entering HText_endAppend\n");
 
     /*
      *  Create a  blank line at the bottom.
@@ -3171,8 +3163,8 @@ PUBLIC void HText_endAppend ARGS1(
     while (text->last_line->data[0] == '\0' && text->Lines > 2) {
 	HTLine *next_to_the_last_line = text->last_line->prev;
 
-	if (TRACE)
-	    fprintf(stderr, "GridText: Removing bottom blank line: %s\n",
+
+	CTRACE(tfp, "GridText: Removing bottom blank line: %s\n",
 			    text->last_line->data);
 	/*
 	 *  line_ptr points to the first line.
@@ -3183,10 +3175,8 @@ PUBLIC void HText_endAppend ARGS1(
 	text->last_line = next_to_the_last_line;
 	text->Lines--;
 #ifdef NOTUSED_BAD_FOR_SCREEN
-	if (TRACE) {
-	    fprintf(stderr, "GridText: New bottom line: %s\n",
+	CTRACE(tfp, "GridText: New bottom line: %s\n",
 			    text->last_line->data);
-	}
 #endif
     }
 
@@ -3214,8 +3204,8 @@ re_parse:
 	}
 	if (anchor_ptr->line_pos < 0)
 	    anchor_ptr->line_pos = 0;
-	if (TRACE)
-	    fprintf(stderr, "Gridtext: Anchor found on line:%d col:%d\n",
+
+	CTRACE(tfp, "Gridtext: Anchor found on line:%d col:%d\n",
 			    cur_line, anchor_ptr->line_pos);
 
 	/*
@@ -3236,8 +3226,7 @@ re_parse:
 	    anchor_ptr->extent = 0;
 	}
 #ifdef NOTUSED_BAD_FOR_SCREEN
-	if (TRACE)
-	    fprintf(stderr, "anchor text: '%s'   pos: %d\n",
+	CTRACE(tfp, "anchor text: '%s'   pos: %d\n",
 			    line_ptr->data, anchor_ptr->line_pos);
 #endif
 	/*
@@ -3248,14 +3237,12 @@ re_parse:
 	    cur_line < text->Lines) {
 	    anchor_ptr->start += (cur_shift + 1);
 	    cur_shift = 0;
-	    if (TRACE)
-		fprintf(stderr, "found anchor at end of line\n");
+	    CTRACE(tfp, "found anchor at end of line\n");
 	    goto re_parse;
 	}
 	cur_shift = 0;
 #ifdef NOTUSED_BAD_FOR_SCREEN
-	if (TRACE)
-	    fprintf(stderr, "anchor text: '%s'   pos: %d\n",
+	CTRACE(tfp, "anchor text: '%s'   pos: %d\n",
 			    line_ptr->data, anchor_ptr->line_pos);
 #endif
 	/*
@@ -3334,9 +3321,8 @@ re_parse:
 	 */
 	anchor_ptr->line_pos += line_ptr->offset;
 	anchor_ptr->line_num  = cur_line;
-	if (TRACE)
-	    fprintf(stderr,
-		    "GridText: adding link on line %d in HText_endAppend\n",
+
+	CTRACE(tfp, "GridText: adding link on line %d in HText_endAppend\n",
 		    cur_line);
 
 	/*
@@ -3348,12 +3334,12 @@ re_parse:
 }
 
 
-/*	Dump diagnostics to stderr
+/*	Dump diagnostics to tfp
 */
 PUBLIC void HText_dump ARGS1(
 	HText *,	text GCC_UNUSED)
 {
-    fprintf(stderr, "HText: Dump called\n");
+    fprintf(tfp, "HText: Dump called\n");
 }
 
 
@@ -3608,9 +3594,8 @@ PUBLIC int HTGetLinkInfo ARGS6(
 			    link_dest_intl = HTAnchor_followTypedLink(
 				(HTAnchor *)a->anchor, LINK_INTERNAL);
 			    if (link_dest_intl && link_dest_intl != link_dest) {
-				if (TRACE)
-				    fprintf(stderr,
-					    "HTGetLinkInfo: unexpected typed link to %s!\n",
+
+				CTRACE(tfp, "HTGetLinkInfo: unexpected typed link to %s!\n",
 					    link_dest_intl->parent->address);
 				link_dest_intl = NULL;
 			    }
@@ -4197,10 +4182,10 @@ PUBLIC BOOL HTFindPoundSelector ARGS1(
 	if (a->anchor && a->anchor->tag)
 	    if (!strcmp(a->anchor->tag, selector)) {
 
-		 www_search_result = a->line_num+1;
-		 if (TRACE)
-		    fprintf(stderr,
-		"HText: Selecting anchor [%d] at character %d, line %d\n",
+		www_search_result = a->line_num+1;
+
+		CTRACE(tfp,
+		       "HText: Selecting anchor [%d] at character %d, line %d\n",
 				     a->number, a->start, www_search_result);
 		if (!strcmp(selector, LYToolbarName))
 		    --www_search_result;
@@ -4230,7 +4215,7 @@ PUBLIC BOOL HText_selectAnchor ARGS2(
 	if (a->anchor == anchor) break;
     }
     if (!a) {
-	if (TRACE) fprintf(stderr, "HText: No such anchor in this text!\n");
+	CTRACE(tfp, "HText: No such anchor in this text!\n");
 	return NO;
     }
 
@@ -4241,7 +4226,7 @@ PUBLIC BOOL HText_selectAnchor ARGS2(
 
     {
 	 int l = line_for_char(text, a->start);
-	if (TRACE) fprintf(stderr,
+	 CTRACE(tfp,
 	    "HText: Selecting anchor [%d] at character %d, line %d\n",
 	    a->number, a->start, l);
 
@@ -4614,8 +4599,7 @@ get_query:
 	StrAllocCopy(doc->address, cp_freeme);
 	FREE(cp_freeme);
 
-	if (TRACE)
-	    fprintf(stderr,"\ndo_www_search: newfile: %s\n",doc->address);
+	CTRACE(tfp,"\ndo_www_search: newfile: %s\n",doc->address);
 
 	/*
 	 *  Yah, the search succeeded.
@@ -5303,22 +5287,18 @@ PUBLIC void HTuncache_current_document NOARGS
 		FREE(htmain_anchor->UCStages);
 	    }
 	}
-	if (TRACE) {
-	    fprintf(stderr, "\rHTuncache.. freeing document for '%s'%s\n",
+	CTRACE(tfp, "\rHTuncache.. freeing document for '%s'%s\n",
 			    ((htmain_anchor &&
 			      htmain_anchor->address) ?
 			       htmain_anchor->address : "unknown anchor"),
 			    ((htmain_anchor &&
 			      htmain_anchor->post_data) ?
 				      " with POST data" : ""));
-	}
 	HTList_removeObject(loaded_texts, HTMainText);
 	HText_free(HTMainText);
 	HTMainText = NULL;
     } else {
-	if (TRACE) {
-	    fprintf(stderr, "HTuncache.. HTMainText already is NULL!\n");
-	}
+	CTRACE(tfp, "HTuncache.. HTMainText already is NULL!\n");
     }
 }
 
@@ -5779,9 +5759,7 @@ PUBLIC void HText_beginForm ARGS5(
     PerFormInfo_free(HTCurrentForm); /* shouldn't happen here - kw */
     HTCurrentForm = newform;
 
-    if (TRACE)
-	fprintf(stderr,
-		"BeginForm: action:%s Method:%d%s%s%s%s%s%s\n",
+    CTRACE(tfp, "BeginForm: action:%s Method:%d%s%s%s%s%s%s\n",
 		HTFormAction, HTFormMethod,
 		(HTFormTitle ? " Title:" : ""),
 		(HTFormTitle ? HTFormTitle : ""),
@@ -5846,8 +5824,7 @@ PUBLIC void HText_endForm ARGS1(
 	HTList_appendObject(text->forms, HTCurrentForm);
 	HTCurrentForm = NULL;
     } else {
-	if (TRACE)
-	    fprintf(stderr, "endForm:    HTCurrentForm is missing!\n");
+	CTRACE(tfp, "endForm:    HTCurrentForm is missing!\n");
     }
 
     FREE(HTCurSelectGroup);
@@ -5889,18 +5866,16 @@ PUBLIC void HText_beginSelect ARGS4(
      */
     StrAllocCopy(HTCurSelectGroupSize, size);
 
-    if (TRACE) {
-       fprintf(stderr,"HText_beginSelect: name=%s type=%d size=%s\n",
+    CTRACE(tfp,"HText_beginSelect: name=%s type=%d size=%s\n",
 	       ((HTCurSelectGroup == NULL) ?
 				  "<NULL>" : HTCurSelectGroup),
 		HTCurSelectGroupType,
 	       ((HTCurSelectGroupSize == NULL) ?
 				      "<NULL>" : HTCurSelectGroupSize));
-	fprintf(stderr,"HText_beginSelect: name_cs=%d \"%s\"\n",
+    CTRACE(tfp,"HText_beginSelect: name_cs=%d \"%s\"\n",
 		HTCurSelectGroupCharset,
 		(HTCurSelectGroupCharset >= 0 ?
 		 LYCharSet_UC[HTCurSelectGroupCharset].MIMEname : "<UNKNOWN>"));
-    }
 }
 
 /*
@@ -5925,8 +5900,7 @@ PUBLIC int HText_getOptionNum ARGS1(
 
     for (op = a->input_field->select_list; op; op = op->next)
 	n++;
-    if (TRACE)
-	fprintf(stderr, "HText_getOptionNum: Got number '%d'.\n", n);
+    CTRACE(tfp, "HText_getOptionNum: Got number '%d'.\n", n);
     return(n);
 }
 
@@ -6003,16 +5977,12 @@ PUBLIC char * HText_setLastOptionValue ARGS7(
 
     if (!(text && text->last_anchor &&
 	  text->last_anchor->link_type == INPUT_ANCHOR)) {
-	if (TRACE)
-	    fprintf(stderr,
-		    "HText_setLastOptionValue: invalid call!  value:%s!\n",
+	CTRACE(tfp, "HText_setLastOptionValue: invalid call!  value:%s!\n",
 		    (value ? value : "<NULL>"));
 	return NULL;
     }
 
-    if (TRACE)
-	fprintf(stderr,
-		"Entering HText_setLastOptionValue: value:%s, checked:%s\n",
+    CTRACE(tfp, "Entering HText_setLastOptionValue: value:%s, checked:%s\n",
 		value, (checked ? "on" : "off"));
 
     /*
@@ -6090,14 +6060,10 @@ PUBLIC char * HText_setLastOptionValue ARGS7(
 	     *  No option items yet.
 	     */
 	    if (text->last_anchor->input_field->type != F_OPTION_LIST_TYPE) {
-		if (TRACE) {
-		    fprintf(stderr,
-   "HText_setLastOptionValue: last input_field not F_OPTION_LIST_TYPE (%d)\n",
+		CTRACE(tfp, "HText_setLastOptionValue: last input_field not F_OPTION_LIST_TYPE (%d)\n",
 			    F_OPTION_LIST_TYPE);
-		    fprintf(stderr,
-   "                          but %d, ignoring!\n",
+		CTRACE(tfp, "                          but %d, ignoring!\n",
 			    text->last_anchor->input_field->type);
-		}
 		return NULL;
 	    }
 
@@ -6229,15 +6195,15 @@ PUBLIC char * HText_setLastOptionValue ARGS7(
     }
 
     if (TRACE) {
-	fprintf(stderr,"HText_setLastOptionValue:%s value=%s",
+	fprintf(tfp,"HText_setLastOptionValue:%s value=%s",
 		(order == LAST_ORDER) ? " LAST_ORDER" : "",
 		value);
-	fprintf(stderr,"            val_cs=%d \"%s\"",
+	fprintf(tfp,"            val_cs=%d \"%s\"",
 			val_cs,
 			(val_cs >= 0 ?
 			 LYCharSet_UC[val_cs].MIMEname : "<UNKNOWN>"));
 	if (submit_value) {
-	    fprintf(stderr, " (submit_val_cs %d \"%s\") submit_value%s=%s\n",
+	    fprintf(tfp, " (submit_val_cs %d \"%s\") submit_value%s=%s\n",
 		    submit_val_cs,
 		    (submit_val_cs >= 0 ?
 		     LYCharSet_UC[submit_val_cs].MIMEname : "<UNKNOWN>"),
@@ -6246,7 +6212,7 @@ PUBLIC char * HText_setLastOptionValue ARGS7(
 		    submit_value);
 	}
 	else {
-	    fprintf(stderr,"\n");
+	    fprintf(tfp,"\n");
 	}
     }
     return(ret_Value);
@@ -6270,8 +6236,7 @@ PUBLIC int HText_beginInput ARGS3(
     unsigned char *tmp = NULL;
     int i, j;
 
-    if (TRACE)
-	fprintf(stderr,"Entering HText_beginInput\n");
+    CTRACE(tfp,"Entering HText_beginInput\n");
 
     if (a == NULL || f == NULL)
 	outofmem(__FILE__, "HText_beginInput");
@@ -6489,8 +6454,7 @@ PUBLIC int HText_beginInput ARGS3(
 	    /*
 	     *  Error!  NAME must be present.
 	     */
-	    if (TRACE)
-		fprintf(stderr,
+	    CTRACE(tfp,
 		  "GridText: No name present in input field; not displaying\n");
 	    FREE(a);
 	    FREE(f);
@@ -6717,30 +6681,27 @@ PUBLIC int HText_beginInput ARGS3(
 	    text->forms = HTList_new();
 	}
     } else {
-	if (TRACE)
-	    fprintf(stderr, "beginInput: HTCurrentForm is missing!\n");
+	CTRACE(tfp, "beginInput: HTCurrentForm is missing!\n");
     }
 
-    if (TRACE) {
-	fprintf(stderr,"Input link: name=%s\nvalue=%s\nsize=%d\n",
+    CTRACE(tfp, "Input link: name=%s\nvalue=%s\nsize=%d\n",
 			f->name,
 			((f->value != NULL) ? f->value : ""),
 			f->size);
-	fprintf(stderr,"Input link: name_cs=%d \"%s\" (from %d \"%s\")\n",
+    CTRACE(tfp, "Input link: name_cs=%d \"%s\" (from %d \"%s\")\n",
 			f->name_cs,
 			(f->name_cs >= 0 ?
 			 LYCharSet_UC[f->name_cs].MIMEname : "<UNKNOWN>"),
 			I->name_cs,
 			(I->name_cs >= 0 ?
 			 LYCharSet_UC[I->name_cs].MIMEname : "<UNKNOWN>"));
-	fprintf(stderr,"            value_cs=%d \"%s\" (from %d \"%s\")\n",
+    CTRACE(tfp, "            value_cs=%d \"%s\" (from %d \"%s\")\n",
 			f->value_cs,
 			(f->value_cs >= 0 ?
 			 LYCharSet_UC[f->value_cs].MIMEname : "<UNKNOWN>"),
 			I->value_cs,
 			(I->value_cs >= 0 ?
 			 LYCharSet_UC[I->value_cs].MIMEname : "<UNKNOWN>"));
-    }
 
     /*
      *  Return the SIZE of the input field.
@@ -6888,14 +6849,10 @@ PUBLIC void HText_SubmitForm ARGS4(
     thisform = HTList_objectAt(HTMainText->forms, form_number - 1);
     /*  Sanity check */
     if (!thisform) {
-	if (TRACE)
-	    fprintf(stderr,
-		    "SubmitForm: form %d not in HTMainText's list!\n",
+	CTRACE(tfp, "SubmitForm: form %d not in HTMainText's list!\n",
 		    form_number);
     } else if (thisform->number != form_number) {
-	if (TRACE)
-	    fprintf(stderr,
-		    "SubmitForm: failed sanity check, %d!=%d !\n",
+	CTRACE(tfp, "SubmitForm: failed sanity check, %d!=%d !\n",
 		    thisform->number, form_number);
 	thisform = NULL;
     }
@@ -7220,25 +7177,22 @@ PUBLIC void HText_SubmitForm ARGS4(
 	        case F_IMAGE_SUBMIT_TYPE:
 		    if (!(form_ptr->name && *form_ptr->name != '\0' &&
 			  !strcmp(form_ptr->name, link_name))) {
-			if (TRACE) {
-			    fprintf(stderr,
+			CTRACE(tfp,
 				    "SubmitForm: skipping submit field with ");
-			    fprintf(stderr,
-				    "name \"%s\" for link_name \"%s\", %s.",
+			CTRACE(tfp, "name \"%s\" for link_name \"%s\", %s.",
 				    form_ptr->name ? form_ptr->name : "???",
 				    link_name ? link_name : "???",
 				    (form_ptr->name && *form_ptr->name) ?
 				    "not current link" : "no field name");
-			}
 			break;
 		    }
 		    if (!(form_ptr->type == F_TEXT_SUBMIT_TYPE ||
 			(form_ptr->value && *form_ptr->value != '\0' &&
 			 !strcmp(form_ptr->value, link_value)))) {
 			if (TRACE) {
-			    fprintf(stderr,
+			    fprintf(tfp,
 				    "SubmitForm: skipping submit field with ");
-			    fprintf(stderr,
+			    fprintf(tfp,
 				    "name \"%s\" for link_name \"%s\", %s!",
 				    form_ptr->name ? form_ptr->name : "???",
 				    link_name ? link_name : "???",
@@ -7288,9 +7242,7 @@ PUBLIC void HText_SubmitForm ARGS4(
 			success = LYUCTranslateBackFormData(&copied_val_used,
 							form_ptr->value_cs,
 							target_cs, PlainText);
-			if (TRACE) {
-			    fprintf(stderr,
-				    "SubmitForm: field \"%s\" %d %s -> %d %s %s\n",
+			CTRACE(tfp, "SubmitForm: field \"%s\" %d %s -> %d %s %s\n",
 				    form_ptr->name ? form_ptr->name : "",
 				    form_ptr->value_cs,
 				    form_ptr->value_cs >= 0 ?
@@ -7299,18 +7251,14 @@ PUBLIC void HText_SubmitForm ARGS4(
 				    target_cs,
 				    target_csname ? target_csname : "???",
 				    success ? "OK" : "FAILED");
-			}
 			if (success) {
 			    val_used = copied_val_used;
 			}
 		    } else {  /* We can use the value directly. */
-			if (TRACE) {
-			    fprintf(stderr,
-				    "SubmitForm: field \"%s\" %d %s OK\n",
+			CTRACE(tfp, "SubmitForm: field \"%s\" %d %s OK\n",
 				    form_ptr->name ? form_ptr->name : "",
 				    target_cs,
 				    target_csname ? target_csname : "???");
-			}
 			success = YES;
 		    }
 		    if (!success) {
@@ -7384,9 +7332,7 @@ PUBLIC void HText_SubmitForm ARGS4(
 			success = LYUCTranslateBackFormData(&copied_name_used,
 							form_ptr->name_cs,
 							target_cs, PlainText);
-			if (TRACE) {
-			    fprintf(stderr,
-				    "SubmitForm: name \"%s\" %d %s -> %d %s %s\n",
+			CTRACE(tfp, "SubmitForm: name \"%s\" %d %s -> %d %s %s\n",
 				    form_ptr->name ? form_ptr->name : "",
 				    form_ptr->name_cs,
 				    form_ptr->name_cs >= 0 ?
@@ -7395,7 +7341,6 @@ PUBLIC void HText_SubmitForm ARGS4(
 				    target_cs,
 				    target_csname ? target_csname : "???",
 				    success ? "OK" : "FAILED");
-			}
 			if (success) {
 			    name_used = copied_name_used;
 			}
@@ -7409,13 +7354,10 @@ PUBLIC void HText_SubmitForm ARGS4(
 			    }
 			}
 		    } else {  /* We can use the name directly. */
-			if (TRACE) {
-			    fprintf(stderr,
-				    "SubmitForm: name \"%s\" %d %s OK\n",
+			CTRACE(tfp, "SubmitForm: name \"%s\" %d %s OK\n",
 				    form_ptr->name ? form_ptr->name : "",
 				    target_cs,
 				    target_csname ? target_csname : "???");
-			}
 			success = YES;
 			if (Boundary) {
 			    StrAllocCopy(copied_name_used, name_used);
@@ -7449,8 +7391,7 @@ PUBLIC void HText_SubmitForm ARGS4(
 
 		    break;
 		default:
-		    if (TRACE)
-			fprintf(stderr, "SubmitForm: What type is %d?\n",
+		    CTRACE(tfp, "SubmitForm: What type is %d?\n",
 				form_ptr->type);
 		}
 
@@ -7804,17 +7745,15 @@ PUBLIC void HText_SubmitForm ARGS4(
 
     if (submit_item->submit_method == URL_MAIL_METHOD) {
 	_user_message("Submitting %s", submit_item->submit_action);
-	if (TRACE) {
-	    fprintf(stderr, "\nGridText - mailto_address: %s\n",
+	CTRACE(tfp, "\nGridText - mailto_address: %s\n",
 			    (submit_item->submit_action+7));
-	    fprintf(stderr, "GridText - mailto_subject: %s\n",
+	CTRACE(tfp, "GridText - mailto_subject: %s\n",
 			    ((submit_item->submit_title &&
 			      *submit_item->submit_title) ?
 			      (submit_item->submit_title) :
 					(HText_getTitle() ?
 				         HText_getTitle() : "")));
-	    fprintf(stderr,"GridText - mailto_content: %s\n",query);
-	}
+	CTRACE(tfp,"GridText - mailto_content: %s\n",query);
 	sleep(MessageSecs);
 	mailform((submit_item->submit_action+7),
 		 ((submit_item->submit_title &&
@@ -7833,8 +7772,7 @@ PUBLIC void HText_SubmitForm ARGS4(
 
     if (submit_item->submit_method == URL_POST_METHOD || Boundary) {
 	StrAllocCopy(doc->post_data, query);
-	if (TRACE)
-	    fprintf(stderr,"GridText - post_data: %s\n",doc->post_data);
+	CTRACE(tfp,"GridText - post_data: %s\n",doc->post_data);
 	StrAllocCopy(doc->address, submit_item->submit_action);
 	FREE(query);
 	return;
diff --git a/src/HTFWriter.c b/src/HTFWriter.c
index 9e91704b..6d6fc136 100644
--- a/src/HTFWriter.c
+++ b/src/HTFWriter.c
@@ -418,14 +418,11 @@ PRIVATE void HTFWriter_abort ARGS2(
 	HTStream *,	me,
 	HTError,	e GCC_UNUSED)
 {
-    if (TRACE)
-	fprintf(stderr,"HTFWriter_abort called\n");
-
+    CTRACE(tfp,"HTFWriter_abort called\n");
     fclose(me->fp);
     FREE(me->viewer_command);
     if (me->end_command) {		/* Temp file */
-	if (TRACE)
-	    fprintf(stderr, "HTFWriter: Aborting: file not executed.\n");
+	CTRACE(tfp, "HTFWriter: Aborting: file not executed.\n");
 	FREE(me->end_command);
 	if (me->remove_command) {
 	    system(me->remove_command);
diff --git a/src/HTInit.c b/src/HTInit.c
index 807df2fd..025a7002 100644
--- a/src/HTInit.c
+++ b/src/HTInit.c
@@ -344,11 +344,8 @@ PRIVATE int ProcessMailcapEntry ARGS2(
     }
     s = strchr(rawentry, ';');
     if (s == NULL) {
-	if (TRACE) {
-		fprintf(stderr,
-		 "ProcessMailcapEntry: Ignoring invalid mailcap entry: %s\n",
-			rawentry);
-	}
+	CTRACE(tfp, "ProcessMailcapEntry: Ignoring invalid mailcap entry: %s\n",
+		    rawentry);
 	FREE(rawentry);
 	return(0);
     }
@@ -357,11 +354,8 @@ PRIVATE int ProcessMailcapEntry ARGS2(
 	!strncasecomp(rawentry, "text/plain", 10)) {
 	--s;
 	*s = ';';
-	if (TRACE) {
-		fprintf(stderr,
-			"ProcessMailcapEntry: Ignoring mailcap entry: %s\n",
-			rawentry);
-	}
+	CTRACE(tfp, "ProcessMailcapEntry: Ignoring mailcap entry: %s\n",
+		    rawentry);
 	FREE(rawentry);
 	return(0);
     }
@@ -407,9 +401,7 @@ PRIVATE int ProcessMailcapEntry ARGS2(
 	    } else if (eq && !strcmp(arg, "test")) {
 		mc->testcommand = NULL;
 		StrAllocCopy(mc->testcommand, eq);
-		if (TRACE)
-		    fprintf(stderr,
-		    	    "ProcessMailcapEntry: Found testcommand:%s\n",
+		CTRACE(tfp, "ProcessMailcapEntry: Found testcommand:%s\n",
 			    mc->testcommand);
 	    } else if (eq && !strcmp(arg, "description")) {
 		mc->label = eq;
@@ -429,10 +421,9 @@ PRIVATE int ProcessMailcapEntry ARGS2(
 		if (mc->maxbytes < 0)
 		    mc->maxbytes = 0;
 	    } else if (strcmp(arg, "notes")) { /* IGNORE notes field */
-		if (*arg && TRACE)
-		    fprintf(stderr,
-			"ProcessMailcapEntry: Ignoring mailcap flag '%s'.\n",
-			    arg);
+		if (*arg)
+		    CTRACE(tfp, "ProcessMailcapEntry: Ignoring mailcap flag '%s'.\n",
+			        arg);
 	    }
 
 	}
@@ -444,9 +435,7 @@ assign_presentation:
     FREE(rawentry);
 
     if (PassesTest(mc)) {
-	if (TRACE)
-	    fprintf(stderr,
-	    	    "ProcessMailcapEntry Setting up conversion %s : %s\n",
+	CTRACE(tfp, "ProcessMailcapEntry Setting up conversion %s : %s\n",
 		    mc->contenttype, mc->command);
 	HTSetPresentation(mc->contenttype, mc->command,
 			  mc->quality, 3.0, 0.0, mc->maxbytes);
@@ -476,22 +465,15 @@ PRIVATE void BuildCommand ARGS5(
 		    break;
 		case 'n':
 		case 'F':
-		    if (TRACE) {
-		        fprintf(stderr,
-			     "BuildCommand: Bad mailcap \"test\" clause: %s\n",
+		    CTRACE(tfp, "BuildCommand: Bad mailcap \"test\" clause: %s\n",
 				controlstring);
-		    }
 		case 's':
 		    if (TmpFileLen && TmpFileName) {
 			if ((to - *pBuf) + TmpFileLen + 1 > Bufsize) {
 			    *to = '\0';
-			    if (TRACE) {
-				fprintf(stderr,
-			"BuildCommand: Too long mailcap \"test\" clause,\n");
-				fprintf(stderr,
-					"              ignoring: %s%s...\n",
+			    CTRACE(tfp, "BuildCommand: Too long mailcap \"test\" clause,\n");
+			    CTRACE(tfp, "              ignoring: %s%s...\n",
 					*pBuf, TmpFileName);
-			    }
 			    **pBuf = '\0';
 			    return;
 			}
@@ -500,11 +482,9 @@ PRIVATE void BuildCommand ARGS5(
 		    }
 		    break;
 		default:
-		    if (TRACE) {
-			fprintf(stderr,
+		    CTRACE(tfp,
   "BuildCommand: Ignoring unrecognized format code in mailcap file '%%%c'.\n",
 			*from);
-		    }
 		    break;
 	    }
 	} else if (*from == '%') {
@@ -514,13 +494,9 @@ PRIVATE void BuildCommand ARGS5(
 	}
 	if (to >= *pBuf + Bufsize) {
 	    (*pBuf)[Bufsize - 1] = '\0';
-	    if (TRACE) {
-		fprintf(stderr,
-			"BuildCommand: Too long mailcap \"test\" clause,\n");
-		fprintf(stderr,
-			"              ignoring: %s...\n",
+	    CTRACE(tfp, "BuildCommand: Too long mailcap \"test\" clause,\n");
+	    CTRACE(tfp, "              ignoring: %s...\n",
 			*pBuf);
-	    }
 	    **pBuf = '\0';
 	    return;
 	}
@@ -546,31 +522,23 @@ PRIVATE int PassesTest ARGS1(
      */
     if (0 == strcasecomp(mc->testcommand, "test -n \"$DISPLAY\"")) {
 	FREE(mc->testcommand);
-	if (TRACE)
-	    fprintf(stderr,
-		    "PassesTest: Testing for XWINDOWS environment.\n");
+	CTRACE(tfp, "PassesTest: Testing for XWINDOWS environment.\n");
     	if ((cp = getenv(DISPLAY)) != NULL && *cp != '\0') {
-	    if (TRACE)
-	        fprintf(stderr,"PassesTest: Test passed!\n");
+	    CTRACE(tfp, "PassesTest: Test passed!\n");
 	    return(0 == 0);
 	} else {
-	    if (TRACE)
-	        fprintf(stderr,"PassesTest: Test failed!\n");
+	    CTRACE(tfp, "PassesTest: Test failed!\n");
 	    return(-1 == 0);
 	}
     }
     if (0 == strcasecomp(mc->testcommand, "test -z \"$DISPLAY\"")) {
 	FREE(mc->testcommand);
-	if (TRACE)
-	    fprintf(stderr,
-		    "PassesTest: Testing for NON_XWINDOWS environment.\n");
+	CTRACE(tfp, "PassesTest: Testing for NON_XWINDOWS environment.\n");
     	if (!((cp = getenv(DISPLAY)) != NULL && *cp != '\0')) {
-	    if (TRACE)
-	        fprintf(stderr,"PassesTest: Test passed!\n");
+	    CTRACE(tfp,"PassesTest: Test passed!\n");
 	    return(0 == 0);
 	} else {
-	    if (TRACE)
-	        fprintf(stderr,"PassesTest: Test failed!\n");
+	    CTRACE(tfp,"PassesTest: Test failed!\n");
 	    return(-1 == 0);
 	}
     }
@@ -580,11 +548,8 @@ PRIVATE int PassesTest ARGS1(
      */
     if (0 == strcasecomp(mc->testcommand, "test -n \"$LYNX_VERSION\"")){
 	FREE(mc->testcommand);
-	if (TRACE) {
-	    fprintf(stderr,
-		    "PassesTest: Testing for LYNX environment.\n");
-	    fprintf(stderr,"PassesTest: Test passed!\n");
-	}
+	CTRACE(tfp, "PassesTest: Testing for LYNX environment.\n");
+	CTRACE(tfp, "PassesTest: Test passed!\n");
 	return(0 == 0);
     } else
     /*
@@ -592,11 +557,8 @@ PRIVATE int PassesTest ARGS1(
      */
     if (0 == strcasecomp(mc->testcommand, "test -z \"$LYNX_VERSION\"")) {
 	FREE(mc->testcommand);
-	if (TRACE) {
-	    fprintf(stderr,
-		    "PassesTest: Testing for non-LYNX environment.\n");
-	    fprintf(stderr,"PassesTest: Test failed!\n");
-	}
+	CTRACE(tfp, "PassesTest: Testing for non-LYNX environment.\n");
+	CTRACE(tfp, "PassesTest: Test failed!\n");
 	return(-1 == 0);
     }
 
@@ -611,8 +573,7 @@ PRIVATE int PassesTest ARGS1(
 		 mc->testcommand,
 		 TmpFileName,
 		 strlen(TmpFileName));
-    if (TRACE)
-	fprintf(stderr,"PassesTest: Executing test command: %s\n", cmd);
+    CTRACE(tfp, "PassesTest: Executing test command: %s\n", cmd);
     result = system(cmd);
     FREE(cmd);
 
@@ -622,10 +583,11 @@ PRIVATE int PassesTest ARGS1(
      */
     FREE(mc->testcommand);
 
-    if (TRACE && result)
-	fprintf(stderr,"PassesTest: Test failed!\n");
-    else if (TRACE)
-	fprintf(stderr,"PassesTest: Test passed!\n");
+    if (result) {
+	CTRACE(tfp,"PassesTest: Test failed!\n");
+    } else {
+	CTRACE(tfp,"PassesTest: Test passed!\n");
+    }
 
     return(result == 0);
 }
@@ -636,14 +598,10 @@ PRIVATE int ProcessMailcapFile ARGS1(
     struct MailcapEntry mc;
     FILE *fp;
 
-    if (TRACE)
-	fprintf(stderr,
-		"ProcessMailcapFile: Loading file '%s'.\n",
+    CTRACE(tfp, "ProcessMailcapFile: Loading file '%s'.\n",
 		file);
     if ((fp = fopen(file, "r")) == NULL) {
-	if (TRACE)
-	    fprintf(stderr,
-		"ProcessMailcapFile: Could not open '%s'.\n",
+	CTRACE(tfp, "ProcessMailcapFile: Could not open '%s'.\n",
 		    file);
 	return(-1 == 0);
     }
@@ -659,7 +617,7 @@ PRIVATE int ExitWithError ARGS1(
 	char *,		txt)
 {
     if (txt)
-	fprintf(stderr, "metamail: %s\n", txt);
+	fprintf(tfp, "metamail: %s\n", txt);
 #ifndef NOSIGHUP
     (void) signal(SIGHUP, SIG_DFL);
 #endif /* NOSIGHUP */
@@ -704,9 +662,7 @@ PUBLIC void HTFileInit NOARGS
 {
     FILE *fp;
 
-    if (TRACE)
-	fprintf(stderr,
-		"HTFileInit: Loading default (HTInit) extension maps.\n");
+    CTRACE(tfp, "HTFileInit: Loading default (HTInit) extension maps.\n");
 
     /* default suffix interpretation */
     HTSetSuffix("*",		"text/plain", "7bit", 1.0);
@@ -1003,15 +959,11 @@ PRIVATE int HTLoadExtensionsConfigFile ARGS1(
     FILE *f;
     int x, count = 0;
 
-    if (TRACE)
-	fprintf(stderr,
-		"HTLoadExtensionsConfigFile: Loading file '%s'.\n", fn);
+    CTRACE(tfp, "HTLoadExtensionsConfigFile: Loading file '%s'.\n", fn);
 
     if ((f = fopen(fn,"r")) == NULL) {
-	if (TRACE)
-	    fprintf(stderr,
-		    "HTLoadExtensionsConfigFile: Could not open '%s'.\n", fn);
-	    return count;
+	CTRACE(tfp, "HTLoadExtensionsConfigFile: Could not open '%s'.\n", fn);
+	return count;
     }
 
     while (!(HTGetLine(l,MAX_STRING_LEN,f))) {
@@ -1037,10 +989,7 @@ PRIVATE int HTLoadExtensionsConfigFile ARGS1(
 		ext[0] = '.';
 		ext[strlen(w)+1] = '\0';
 
-		if (TRACE) {
-		    fprintf (stderr,
-			     "SETTING SUFFIX '%s' to '%s'.\n", ext, ct);
-		}
+		CTRACE (tfp, "SETTING SUFFIX '%s' to '%s'.\n", ext, ct);
 
 	        if (strstr(ct, "tex") != NULL ||
 	            strstr(ct, "postscript") != NULL ||
diff --git a/src/HTML.c b/src/HTML.c
index 29eb130a..eb6b7f5b 100644
--- a/src/HTML.c
+++ b/src/HTML.c
@@ -675,31 +675,30 @@ PRIVATE void HTML_start_element ARGS6(
 
 	if (TRACE)
 	{
-		fprintf(stderr, "CSSTRIM:%s -> %d", myHash, hcode);
+		fprintf(tfp, "CSSTRIM:%s -> %d", myHash, hcode);
 		if (hashStyles[hcode].code!=hcode)
 		{
 			char *rp=strrchr(myHash, '.');
-			fprintf(stderr, " (undefined) %s\n", myHash);
+			fprintf(tfp, " (undefined) %s\n", myHash);
 			if (rp)
 			{
 				int hcd;
 				*rp='\0'; /* trim the class */
 				hcd = hash_code(myHash);
-				fprintf(stderr, "CSS:%s -> %d", myHash, hcd);
+				fprintf(tfp, "CSS:%s -> %d", myHash, hcd);
 				if (hashStyles[hcd].code!=hcd)
-					fprintf(stderr, " (undefined) %s\n", myHash);
+					fprintf(tfp, " (undefined) %s\n", myHash);
 				else
-					fprintf(stderr, " ca=%d\n", hashStyles[hcd].color);
+					fprintf(tfp, " ca=%d\n", hashStyles[hcd].color);
 			}
 		}
 		else
-			fprintf(stderr, " ca=%d\n", hashStyles[hcode].color);
+			fprintf(tfp, " ca=%d\n", hashStyles[hcode].color);
 	}
 
     if (displayStyles[element_number + STARTAT].color > -2) /* actually set */
     {
-	if (TRACE)
-		fprintf(stderr, "CSSTRIM: start_element: top <%s>\n", HTML_dtd.tags[element_number].name);
+	CTRACE(tfp, "CSSTRIM: start_element: top <%s>\n", HTML_dtd.tags[element_number].name);
 	HText_characterStyle(me->text, hcode, 1);
     }
 #endif /* USE_COLOR_STYLE */
@@ -724,9 +723,7 @@ PRIVATE void HTML_start_element ARGS6(
 	    StrAllocCopy(base, value[HTML_BASE_HREF]);
 	    if (!(url_type = LYLegitimizeHREF(me, (char**)&base,
 					      TRUE, TRUE))) {
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTML: BASE '%s' is not an absolute URL.\n",
+		CTRACE(tfp, "HTML: BASE '%s' is not an absolute URL.\n",
 			    (base ? base : ""));
 		if (me->inBadBASE == FALSE)
 		    HTAlert(BASE_NOT_ABSOLUTE);
@@ -892,9 +889,7 @@ PRIVATE void HTML_start_element ARGS6(
 					 me->node_anchor->address));
 		    }
 		    HTAnchor_setOwner(me->node_anchor, href);
-		    if (TRACE)
-			fprintf(stderr,
-				"HTML: DOC OWNER '%s' found\n", href);
+		    CTRACE(tfp, "HTML: DOC OWNER '%s' found\n", href);
 		    FREE(href);
 
 		    /*
@@ -926,10 +921,7 @@ PRIVATE void HTML_start_element ARGS6(
 		 */
 		if (!strcasecomp(value[HTML_LINK_REL], "StyleSheet") ||
 		    !strcasecomp(value[HTML_LINK_REL], "Style")) {
-		    if (TRACE) {
-			fprintf(stderr,
-				"HTML: StyleSheet link found.\n");
-		    }
+		    CTRACE(tfp, "HTML: StyleSheet link found.\n");
 #ifdef LINKEDSTYLES
 		    if (href && *href != '\0')
 		    {
@@ -949,18 +941,16 @@ PRIVATE void HTML_start_element ARGS6(
 				res = style_readFromFile(href);
 			    }
 			}
-			if (TRACE)
-			    fprintf(stderr, "CSS: StyleSheet=%s %d\n", href, res);
+			CTRACE(tfp, "CSS: StyleSheet=%s %d\n", href, res);
 			if (res == 0)
 			    HTAnchor_setStyle (me->node_anchor, href);
 		    }
-		    else
-			if (TRACE)
-			    fprintf(stderr,
+		    else {
+			CTRACE(tfp,
 				"        non-local StyleSheets not yet implemented.\n");
+		    }
 #else
-		    if (TRACE)
-			fprintf(stderr,
+		    CTRACE(tfp,
 				"        StyleSheets not yet implemented.\n");
 #endif
 		    FREE(href);
@@ -1016,11 +1006,8 @@ PRIVATE void HTML_start_element ARGS6(
 		    !strcasecomp(value[HTML_LINK_REL], "Bibliography")) {
 		    StrAllocCopy(title, value[HTML_LINK_REL]);
 		} else {
-		    if (TRACE) {
-			fprintf(stderr,
-				"HTML: LINK with REL=\"%s\" ignored.\n",
+		    CTRACE(tfp, "HTML: LINK with REL=\"%s\" ignored.\n",
 				 value[HTML_LINK_REL]);
-		    }
 		    FREE(href);
 		    break;
 		}
@@ -1038,11 +1025,8 @@ PRIVATE void HTML_start_element ARGS6(
 	    } else if (!strcasecomp(value[HTML_LINK_REL], "Index")) {
 		StrAllocCopy(href, indexfile);
 	    } else {
-		if (TRACE) {
-		    fprintf(stderr,
-			    "HTML: LINK with REL=\"%s\" and no HREF ignored.\n",
+		CTRACE(tfp, "HTML: LINK with REL=\"%s\" and no HREF ignored.\n",
 			    value[HTML_LINK_REL]);
-		}
 		break;
 	    }
 	    StrAllocCopy(title, value[HTML_LINK_REL]);
@@ -1126,8 +1110,7 @@ PRIVATE void HTML_start_element ARGS6(
 	    {
 		char tmp[1024];
 		sprintf(tmp, "link.%s.%s.%s", value[HTML_LINK_CLASS], title, value[HTML_LINK_CLASS]);
-		if (TRACE)
-			fprintf(stderr, "CSSTRIM:link=%s\n", tmp);
+		CTRACE(tfp, "CSSTRIM:link=%s\n", tmp);
 
 		HText_characterStyle(me->text, hash_code(tmp), 1);
 		HTML_put_string(me, title);
@@ -1416,8 +1399,8 @@ PRIVATE void HTML_start_element ARGS6(
     case HTML_DIV:
 	if (me->Division_Level < (MAX_NESTING - 1)) {
 	    me->Division_Level++;
-	} else if (TRACE) {
-	    fprintf(stderr,
+	} else {
+	    CTRACE(tfp,
 		"HTML: ****** Maximum nesting of %d divisions exceeded!\n",
 		MAX_NESTING);
 	}
@@ -1679,9 +1662,7 @@ PRIVATE void HTML_start_element ARGS6(
 
     case HTML_TAB:
 	if (!present) { /* Bad tag.  Must have at least one attribute. - FM */
-	    if (TRACE)
-		fprintf(stderr,
-			"HTML: TAB tag has no attributes. Ignored.\n");
+	    CTRACE(tfp, "HTML: TAB tag has no attributes. Ignored.\n");
 	    break;
 	}
 	UPDATE_STYLE;
@@ -1694,9 +1675,7 @@ PRIVATE void HTML_start_element ARGS6(
 	     *	the ALIGN and DP attributes implemented. - FM
 	     */
 	    HTML_put_character(me, ' ');
-	    if (TRACE)
-		fprintf(stderr,
-		     "HTML: ALIGN not 'left'. Using space instead of TAB.\n");
+	    CTRACE(tfp, "HTML: ALIGN not 'left'. Using space instead of TAB.\n");
 
 	} else if (!LYoverride_default_alignment(me) &&
 		   me->current_default_alignment != HT_LEFT) {
@@ -1707,9 +1686,7 @@ PRIVATE void HTML_start_element ARGS6(
 	     *	that the alignment be HT_LEFT. - FM
 	     */
 	    HTML_put_character(me, ' ');
-	    if (TRACE)
-		fprintf(stderr,
-			"HTML: Not HT_LEFT. Using space instead of TAB.\n");
+	    CTRACE(tfp, "HTML: Not HT_LEFT. Using space instead of TAB.\n");
 
 	} else if ((present[HTML_TAB_TO] &&
 		    value[HTML_TAB_TO] && *value[HTML_TAB_TO]) ||
@@ -1748,9 +1725,7 @@ PRIVATE void HTML_start_element ARGS6(
 	    if (target < column ||
 		target > HText_getMaximumColumn(me->text)) {
 		HTML_put_character(me, ' ');
-		if (TRACE)
-		    fprintf(stderr,
-		 "HTML: Column out of bounds. Using space instead of TAB.\n");
+		CTRACE(tfp, "HTML: Column out of bounds. Using space instead of TAB.\n");
 	    } else {
 		for (i = column; i < target; i++)
 		    HText_appendCharacter(me->text, ' ');
@@ -1819,18 +1794,15 @@ PRIVATE void HTML_start_element ARGS6(
 	 *  Can't display both underline and bold at same time.
 	 */
 	if (me->inBoldA == TRUE || me->inBoldH == TRUE) {
-	    if (TRACE)
-		fprintf(stderr,"Underline Level is %d\n", me->Underline_Level);
+	    CTRACE(tfp, "Underline Level is %d\n", me->Underline_Level);
 	    break;
 	}
 	if (me->inUnderline == FALSE) {
 	    HText_appendCharacter(me->text, LY_UNDERLINE_START_CHAR);
 	    me->inUnderline = TRUE;
-	    if (TRACE)
-		fprintf(stderr,"Beginning underline\n");
+	    CTRACE(tfp,"Beginning underline\n");
 	} else {
-	    if (TRACE)
-		fprintf(stderr,"Underline Level is %d\n", me->Underline_Level);
+	    CTRACE(tfp,"Underline Level is %d\n", me->Underline_Level);
 	}
 	break;
 
@@ -2500,9 +2472,7 @@ PRIVATE void HTML_start_element ARGS6(
 		** Found TYPE="internal link" but not in a valid context
 		** where we have written it. - kw
 		*/
-		if (TRACE)
-		    fprintf(stderr,
-			    "HTML: Found invalid HREF=\"%s\" TYPE=\"%s\"!\n",
+		CTRACE(tfp, "HTML: Found invalid HREF=\"%s\" TYPE=\"%s\"!\n",
 			    href, temp);
 		FREE(temp);
 	    }
@@ -2605,16 +2575,12 @@ PRIVATE void HTML_start_element ARGS6(
 				      )) != NULL) {
 		if (dest->isISMAPScript == TRUE) {
 		    dest_ismap = TRUE;
-		    if (TRACE)
-			fprintf(stderr,
-				"HTML: '%s' is an ISMAP script\n",
+		    CTRACE(tfp, "HTML: '%s' is an ISMAP script\n",
 				dest->address);
 		} else if (present && present[HTML_IMG_ISMAP]) {
 		    dest_ismap = TRUE;
 		    dest->isISMAPScript = TRUE;
-		    if (TRACE)
-			fprintf(stderr,
-				"HTML: Designating '%s' as an ISMAP script\n",
+		    CTRACE(tfp, "HTML: Designating '%s' as an ISMAP script\n",
 				dest->address);
 		}
 	    }
@@ -2798,13 +2764,10 @@ PRIVATE void HTML_start_element ARGS6(
 	    StrAllocCopy(alt_string, "[USEMAP]");
 	}
 
-	if (TRACE) {
-	    fprintf(stderr,
-		    "HTML IMG: USEMAP=%d ISMAP=%d ANCHOR=%d PARA=%d\n",
+	CTRACE(tfp, "HTML IMG: USEMAP=%d ISMAP=%d ANCHOR=%d PARA=%d\n",
 		    map_href ? 1 : 0,
 		    (dest_ismap == TRUE) ? 1 : 0,
 		    me->inA, me->inP);
-	}
 
 	/*
 	 *  Check for an ID attribute. - FM
@@ -3915,10 +3878,7 @@ PRIVATE void HTML_start_element ARGS6(
 	     *	that one now. - FM
 	     */
 	    if (me->inFORM) {
-		if (TRACE) {
-		    fprintf(stderr,
-			    "HTML: Missing FORM end tag. Faking it!\n");
-		}
+		CTRACE(tfp, "HTML: Missing FORM end tag. Faking it!\n");
 		SET_SKIP_STACK(HTML_FORM);
 		HTML_end_element(me, HTML_FORM, (char **)&include);
 	    }
@@ -4097,7 +4057,7 @@ PRIVATE void HTML_start_element ARGS6(
 	     */
 	    if (!me->inFORM) {
 		if (TRACE) {
-		    fprintf(stderr,
+		    fprintf(tfp,
 			    "Bad HTML: BUTTON tag not within FORM tag\n");
 		} else if (!me->inBadHTML) {
 		    _statusline(BAD_HTML_USE_TRACE);
@@ -4304,8 +4264,7 @@ PRIVATE void HTML_start_element ARGS6(
 		    if (me->inFORM)
 			HText_DisableCurrentForm();
 #endif /* NOTDEFINED */
-		    if (TRACE)
-			fprintf(stderr, "HTML: Ignoring TYPE=\"range\"\n");
+		    CTRACE(tfp, "HTML: Ignoring TYPE=\"range\"\n");
 		    break;
 
 		} else if (!strcasecomp(I.type, "file")) {
@@ -4327,8 +4286,7 @@ PRIVATE void HTML_start_element ARGS6(
 		    if (me->inFORM)
 			HText_DisableCurrentForm();
 #endif /* NOTDEFINED */
-		    if (TRACE)
-			fprintf(stderr, "HTML: Ignoring TYPE=\"file\"\n");
+		    CTRACE(tfp, "HTML: Ignoring TYPE=\"file\"\n");
 		    break;
 
 		} else if (!strcasecomp(I.type, "button")) {
@@ -4345,7 +4303,7 @@ PRIVATE void HTML_start_element ARGS6(
 	     */
 	    if (!me->inFORM) {
 		if (TRACE) {
-		    fprintf(stderr,
+		    fprintf(tfp,
 			    "Bad HTML: INPUT tag not within FORM tag\n");
 		} else if (!me->inBadHTML) {
 		    _statusline(BAD_HTML_USE_TRACE);
@@ -4365,7 +4323,7 @@ PRIVATE void HTML_start_element ARGS6(
 	     */
 	    if (me->inTEXTAREA) {
 		if (TRACE) {
-		    fprintf(stderr,
+		    fprintf(tfp,
 			    "Bad HTML: Missing TEXTAREA end tag.\n");
 		} else if (!me->inBadHTML) {
 		    _statusline(BAD_HTML_USE_TRACE);
@@ -4378,9 +4336,7 @@ PRIVATE void HTML_start_element ARGS6(
 	     *	Check for an unclosed SELECT, try to close it if found.
 	     */
 	    if (me->inSELECT) {
-		if (TRACE) {
-		    fprintf(stderr, "HTML: Missing SELECT end tag, faking it...\n");
-		}
+		CTRACE(tfp, "HTML: Missing SELECT end tag, faking it...\n");
 		if (me->sp->tag_number != HTML_SELECT) {
 		    SET_SKIP_STACK(HTML_SELECT);
 		}
@@ -4718,7 +4674,7 @@ PRIVATE void HTML_start_element ARGS6(
 	 */
 	if (!me->inFORM) {
 	    if (TRACE) {
-		fprintf(stderr,
+		fprintf(tfp,
 			"Bad HTML: TEXTAREA start tag not within FORM tag\n");
 	    } else if (!me->inBadHTML) {
 		_statusline(BAD_HTML_USE_TRACE);
@@ -4809,7 +4765,7 @@ PRIVATE void HTML_start_element ARGS6(
 	 */
 	if (me->inSELECT) {
 	    if (TRACE) {
-		fprintf(stderr,
+		fprintf(tfp,
 		   "Bad HTML: SELECT start tag in SELECT element. Faking SELECT end tag. *****\n");
 	    } else if (!me->inBadHTML) {
 		_statusline(BAD_HTML_USE_TRACE);
@@ -4843,7 +4799,7 @@ PRIVATE void HTML_start_element ARGS6(
 	     */
 	    if (!me->inSELECT) {
 		if (TRACE) {
-		    fprintf(stderr,
+		    fprintf(tfp,
 			    "Bad HTML: OPTION tag not within SELECT tag\n");
 		} else if (!me->inBadHTML) {
 		    _statusline(BAD_HTML_USE_TRACE);
@@ -5058,8 +5014,8 @@ PRIVATE void HTML_start_element ARGS6(
 	}
 	if (me->Division_Level < (MAX_NESTING - 1)) {
 	    me->Division_Level++;
-	} else if (TRACE) {
-	    fprintf(stderr,
+	} else {
+	    CTRACE(tfp,
 	    "HTML: ****** Maximum nesting of %d divisions/tables exceeded!\n",
 		    MAX_NESTING);
 	}
@@ -5232,9 +5188,7 @@ PRIVATE void HTML_start_element ARGS6(
 #endif
     {
 	if (me->skip_stack > 0) {
-	    if (TRACE)
-		fprintf(stderr,
-	    "HTML:begin_element: internal call (level %d), leaving on stack - %s\n",
+	    CTRACE(tfp, "HTML:begin_element: internal call (level %d), leaving on stack - %s\n",
 			me->skip_stack, me->sp->style->name);
 	    me->skip_stack--;
 	    return;
@@ -5242,7 +5196,7 @@ PRIVATE void HTML_start_element ARGS6(
 	if (me->sp == me->stack) {
 	    if (me->stack_overrun == FALSE) {
 		if (TRACE) {
-		    fprintf(stderr,
+		    fprintf(tfp,
 			"HTML: ****** Maximum nesting of %d tags exceeded!\n",
 			MAX_NESTING);
 
@@ -5254,8 +5208,7 @@ PRIVATE void HTML_start_element ARGS6(
 	    return;
 	}
 
-	if (TRACE)
-	    fprintf(stderr,"HTML:begin_element[%d]: adding style to stack - %s\n",
+	CTRACE(tfp,"HTML:begin_element[%d]: adding style to stack - %s\n",
 	    						STACKLEVEL(me),
 							me->new_style->name);
 	(me->sp)--;
@@ -5267,8 +5220,7 @@ PRIVATE void HTML_start_element ARGS6(
 /* end empty tags straight away */
 	if (HTML_dtd.tags[ElementNumber].contents == SGML_EMPTY)
 	{
-		if (TRACE)
-			fprintf(stderr, "STYLE:begin_element:ending EMPTY element style\n");
+		CTRACE(tfp, "STYLE:begin_element:ending EMPTY element style\n");
 #if !defined(USE_HASH)
 	HText_characterStyle(me->text, element_number+STARTAT, STACK_OFF);
 #else
@@ -5300,9 +5252,7 @@ PRIVATE void HTML_start_element ARGS6(
 				strcpy(prevailing_class, "");
 #endif
 
-
-			if (TRACE)
-			fprintf(stderr, "CSS:%s (trimmed %s, SGML_EMPTY)\n", Style_className, tmp);
+			CTRACE(tfp, "CSS:%s (trimmed %s, SGML_EMPTY)\n", Style_className, tmp);
 		}
 	}
 #endif /* USE_COLOR_STYLE */
@@ -5334,7 +5284,7 @@ PRIVATE void HTML_end_element ARGS3(
 #ifdef CAREFUL			/* parser assumed to produce good nesting */
     if (element_number != me->sp[0].tag_number &&
 	HTML_dtd.tags[element_number].contents != SGML_EMPTY) {
-	fprintf(stderr,
+	CTRACE(tfp,
 		"HTMLText: end of element %s when expecting end of %s\n",
 		HTML_dtd.tags[element_number].name,
 		HTML_dtd.tags[me->sp->tag_number].name);
@@ -5378,9 +5328,7 @@ PRIVATE void HTML_end_element ARGS3(
 	    BreakFlag = TRUE;
 	}
 	if (me->skip_stack > 0) {
-	    if (TRACE)
-		fprintf(stderr,
-	    "HTML:end_element: Internal call (level %d), leaving on stack - %s\n",
+	     CTRACE(tfp, "HTML:end_element: Internal call (level %d), leaving on stack - %s\n",
 			me->skip_stack, me->sp->style->name);
 	    me->skip_stack--;
 	} else if (me->stack_overrun == TRUE &&
@@ -5426,14 +5374,11 @@ PRIVATE void HTML_end_element ARGS3(
 	    return;
 	} else if (me->sp < (me->stack + MAX_NESTING - 1)) {
 	    (me->sp)++;
-	    if (TRACE)
-		fprintf(stderr,
-			"HTML:end_element[%d]: Popped style off stack - %s\n",
+	    CTRACE(tfp, "HTML:end_element[%d]: Popped style off stack - %s\n",
 	    		STACKLEVEL(me),
 			me->sp->style->name);
 	} else {
-	    if (TRACE)
-		fprintf(stderr,
+	    CTRACE(tfp,
   "Stack underflow error!  Tried to pop off more styles than exist in stack\n");
 	}
     }
@@ -5445,7 +5390,7 @@ PRIVATE void HTML_end_element ARGS3(
      */
     if (me->inTEXTAREA && element_number != HTML_TEXTAREA) {
 	if (TRACE) {
-	    fprintf(stderr, "Bad HTML: Missing TEXTAREA end tag\n");
+	    fprintf(tfp, "Bad HTML: Missing TEXTAREA end tag\n");
 	} else if (!me->inBadHTML) {
 	    _statusline(BAD_HTML_USE_TRACE);
 	    me->inBadHTML = TRUE;
@@ -5465,7 +5410,7 @@ PRIVATE void HTML_end_element ARGS3(
     case HTML_HTML:
 	if (me->inA || me->inSELECT || me->inTEXTAREA)
 	    if (TRACE) {
-		fprintf(stderr,
+		fprintf(tfp,
 			"Bad HTML: %s%s%s%s%s not closed before HTML end tag *****\n",
 			me->inSELECT ? "SELECT" : "",
 			(me->inSELECT && me->inTEXTAREA) ? ", " : "",
@@ -5548,10 +5493,8 @@ PRIVATE void HTML_end_element ARGS3(
 	 *  we'll just ignore. - FM
 	 */
 	HTChunkTerminate(&me->style_block);
-	if (TRACE) {
-	    fprintf(stderr, "HTML: STYLE content =\n%s\n",
+	CTRACE(tfp, "HTML: STYLE content =\n%s\n",
 			    me->style_block.data);
-	}
 	HTChunkClear(&me->style_block);
 	break;
 
@@ -5561,17 +5504,15 @@ PRIVATE void HTML_end_element ARGS3(
 	 *  we'll just ignore. - FM
 	 */
 	HTChunkTerminate(&me->script);
-	if (TRACE) {
-	    fprintf(stderr, "HTML: SCRIPT content =\n%s\n",
+	CTRACE(tfp, "HTML: SCRIPT content =\n%s\n",
 			    me->script.data);
-	}
 	HTChunkClear(&me->script);
 	break;
 
     case HTML_BODY:
 	if (me->inA || me->inSELECT || me->inTEXTAREA)
 	    if (TRACE) {
-		fprintf(stderr,
+		fprintf(tfp,
 			"Bad HTML: %s%s%s%s%s not closed before BODY end tag *****\n",
 			me->inSELECT ? "SELECT" : "",
 			(me->inSELECT && me->inTEXTAREA) ? ", " : "",
@@ -5695,11 +5636,9 @@ PRIVATE void HTML_end_element ARGS3(
 	if (me->inUnderline && me->Underline_Level < 1) {
 	    HText_appendCharacter(me->text, LY_UNDERLINE_END_CHAR);
 	    me->inUnderline = FALSE;
-	    if (TRACE)
-		fprintf(stderr,"Ending underline\n");
+	    CTRACE(tfp, "Ending underline\n");
 	} else {
-	    if (TRACE)
-		fprintf(stderr,"Underline Level is %d\n", me->Underline_Level);
+	    CTRACE(tfp, "Underline Level is %d\n", me->Underline_Level);
 	}
 	break;
 
@@ -5795,11 +5734,8 @@ PRIVATE void HTML_end_element ARGS3(
     case HTML_MENU:
     case HTML_DIR:
 	me->List_Nesting_Level--;
-	if (TRACE) {
-	    fprintf(stderr,
-		    "HTML_end_element: Reducing List Nesting Level to %d\n",
+	CTRACE(tfp, "HTML_end_element: Reducing List Nesting Level to %d\n",
 		    me->List_Nesting_Level);
-	}
 	change_paragraph_style(me, me->sp->style);  /* Often won't really change */
 	UPDATE_STYLE;
 	if (me->List_Nesting_Level >= 0)
@@ -5923,8 +5859,7 @@ PRIVATE void HTML_end_element ARGS3(
 		 *  pass a dummy start tag to the SGML parser so that it
 		 *  will resume the accumulation of OBJECT content. - FM
 		 */
-		if (TRACE)
-		    fprintf(stderr, "HTML: Nested OBJECT tags.  Recycling.\n");
+		CTRACE(tfp, "HTML: Nested OBJECT tags.  Recycling.\n");
 		if (*include == NULL) {
 		    StrAllocCopy(*include, "<OBJECT>");
 		} else {
@@ -5943,7 +5878,7 @@ PRIVATE void HTML_end_element ARGS3(
 		 *  we have bad HTML or otherwise misparsed. - FM
 		 */
 		if (TRACE) {
-		    fprintf(stderr,
+		    fprintf(tfp,
   "Bad HTML: Unmatched OBJECT start and end tags.  Discarding content:\n%s\n",
 			    me->object.data);
 		} else if (!me->inBadHTML) {
@@ -5959,8 +5894,7 @@ PRIVATE void HTML_end_element ARGS3(
 	     *	assuming we weren't tripped up by comments
 	     *	or quoted attributes. - FM
 	     */
-	    if (TRACE)
-		fprintf(stderr, "HTML:OBJECT content:\n%s\n", me->object.data);
+	    CTRACE(tfp, "HTML:OBJECT content:\n%s\n", me->object.data);
 
 	    /*
 	     *	OBJECTs with DECLARE should be saved but
@@ -5973,8 +5907,7 @@ PRIVATE void HTML_end_element ARGS3(
 	    if (me->object_declare == TRUE) {
 		if (me->object_id && *me->object_id)
 		    LYHandleID(me, me->object_id);
-		if (TRACE)
-		    fprintf(stderr, "HTML: DECLAREd OBJECT.  Ignoring!\n");
+		CTRACE(tfp, "HTML: DECLAREd OBJECT.  Ignoring!\n");
 		goto End_Object;
 	    }
 
@@ -5987,8 +5920,7 @@ PRIVATE void HTML_end_element ARGS3(
 	    if (me->object_name != NULL) {
 		if (me->object_id && *me->object_id)
 		    LYHandleID(me, me->object_id);
-		if (TRACE)
-		    fprintf(stderr, "HTML: NAMEd OBJECT.  Ignoring!\n");
+		CTRACE(tfp, "HTML: NAMEd OBJECT.  Ignoring!\n");
 		goto End_Object;
 	    }
 
@@ -6014,22 +5946,20 @@ PRIVATE void HTML_end_element ARGS3(
 		    }
 		    StrAllocCat(data, "</OBJECT>");
 		    StrAllocCat(*include, data);
-		    if (TRACE)
-			fprintf(stderr, "HTML: Recycling nested OBJECT%s.\n",
+		    CTRACE(tfp, "HTML: Recycling nested OBJECT%s.\n",
 					(e > 1) ? "s" : "");
 		    FREE(data);
 		    goto End_Object;
 		} else {
 		    if (TRACE) {
-			fprintf(stderr,
+			fprintf(tfp,
      "Bad HTML: Unmatched OBJECT start and end tags.  Discarding content.\n");
-			goto End_Object;
 		    } else if (!me->inBadHTML) {
 			_statusline(BAD_HTML_USE_TRACE);
 			me->inBadHTML = TRUE;
 			sleep(MessageSecs);
-			goto End_Object;
 		    }
+		    goto End_Object;
 		}
 	    }
 
@@ -6037,9 +5967,7 @@ PRIVATE void HTML_end_element ARGS3(
 	     *	If it's content has SHAPES, convert it to FIG. - FM
 	     */
 	    if (me->object_shapes == TRUE) {
-		if (TRACE)
-		    fprintf(stderr,
-		    "HTML: OBJECT has SHAPES.  Converting to FIG.\n");
+		CTRACE(tfp, "HTML: OBJECT has SHAPES.  Converting to FIG.\n");
 		StrAllocCat(*include, "<FIG ISOBJECT IMAGEMAP");
 		if (me->object_ismap == TRUE)
 		    StrAllocCat(*include, " IMAGEMAP");
@@ -6067,9 +5995,7 @@ PRIVATE void HTML_end_element ARGS3(
 	     *	convert it to IMG. - FM
 	     */
 	    if (me->object_usemap != NULL) {
-		if (TRACE)
-		    fprintf(stderr,
-		    "HTML: OBJECT has USEMAP.  Converting to IMG.\n");
+		CTRACE(tfp, "HTML: OBJECT has USEMAP.  Converting to IMG.\n");
 
 		StrAllocCat(*include, "<IMG ISOBJECT");
 		if (me->object_id != NULL) {
@@ -6226,7 +6152,7 @@ End_Object:
 	 */
 	if (!me->inFORM) {
 	    if (TRACE) {
-		fprintf(stderr, "Bad HTML: Unmatched FORM end tag\n");
+		fprintf(tfp, "Bad HTML: Unmatched FORM end tag\n");
 	    } else if (!me->inBadHTML) {
 		_statusline(BAD_HTML_USE_TRACE);
 		me->inBadHTML = TRUE;
@@ -6247,7 +6173,7 @@ End_Object:
 	 */
 	if (me->inSELECT) {
 	    if (TRACE) {
-		fprintf(stderr,
+		fprintf(tfp,
 		   "Bad HTML: Open SELECT at FORM end. Faking SELECT end tag. *****\n");
 	    } else if (!me->inBadHTML) {
 		_statusline(BAD_HTML_USE_TRACE);
@@ -6306,7 +6232,7 @@ End_Object:
 	     */
 	    if (!me->inTEXTAREA) {
 		if (TRACE) {
-		    fprintf(stderr, "Bad HTML: Unmatched TEXTAREA end tag\n");
+		    fprintf(tfp, "Bad HTML: Unmatched TEXTAREA end tag\n");
 		} else if (!me->inBadHTML) {
 		    _statusline(BAD_HTML_USE_TRACE);
 		    me->inBadHTML = TRUE;
@@ -6486,7 +6412,7 @@ End_Object:
 	     */
 	    if (!me->inSELECT) {
 		if (TRACE) {
-		    fprintf(stderr, "Bad HTML: Unmatched SELECT end tag *****\n");
+		    fprintf(tfp, "Bad HTML: Unmatched SELECT end tag *****\n");
 		} else if (!me->inBadHTML) {
 		    _statusline(BAD_HTML_USE_TRACE);
 		    me->inBadHTML = TRUE;
@@ -6510,7 +6436,7 @@ End_Object:
 	     */
 	    if (!me->inFORM) {
 		if (TRACE) {
-		    fprintf(stderr,
+		    fprintf(tfp,
 			    "Bad HTML: SELECT end tag not within FORM element *****\n");
 		} else if (!me->inBadHTML) {
 		    _statusline(BAD_HTML_USE_TRACE);
@@ -6692,17 +6618,15 @@ End_Object:
 */
 	if (end)
 	    *end='\0';
-	hcode=hash_code(lookfrom && *lookfrom ? lookfrom : &tmp[1]);
-	if (TRACE)
-	    fprintf(stderr, "CSS:%s (trimmed %s, END_ELEMENT)\n", Style_className, tmp);
+	hcode = hash_code(lookfrom && *lookfrom ? lookfrom : &tmp[1]);
+	CTRACE(tfp, "CSS:%s (trimmed %s, END_ELEMENT)\n", Style_className, tmp);
     }
 
 #if defined(DICKEY_TEST)
     if (HTML_dtd.tags[element_number].contents != SGML_EMPTY)
 #endif
     {
-	if (TRACE)
-	    fprintf(stderr, "STYLE:end_element: ending non-EMPTY style\n");
+	CTRACE(tfp, "STYLE:end_element: ending non-EMPTY style\n");
 #if !defined(USE_HASH)
 	HText_characterStyle(me->text, element_number+STARTAT, STACK_OFF);
 #else
@@ -6789,8 +6713,7 @@ PRIVATE void HTML_free ARGS1(HTStructured *, me)
 	    HText_appendCharacter(me->text, LY_UNDERLINE_END_CHAR);
 	    me->inUnderline = FALSE;
 	    me->Underline_Level = 0;
-	    if (TRACE)
-		fprintf(stderr,"HTML_free: Ending underline\n");
+	    CTRACE(tfp,"HTML_free: Ending underline\n");
 	}
 	if (me->inA) {
 	    HTML_end_element(me, HTML_A, (char **)&include);
@@ -6811,7 +6734,7 @@ PRIVATE void HTML_free ARGS1(HTStructured *, me)
 	     *	have gone very wrong. - kw
 	     */
 	    if (TRACE) {
-		fprintf(stderr,
+		fprintf(tfp,
 			"Bad HTML: SELECT or OPTION not ended properly *****\n");
 	    } else if (!me->inBadHTML) {
 		_statusline(BAD_HTML_USE_TRACE);
@@ -6823,8 +6746,7 @@ PRIVATE void HTML_free ARGS1(HTStructured *, me)
 	     *	Output the left-over data as text, maybe it was invalid
 	     *	markup meant to be shown somewhere. - kw
 	     */
-	    if (TRACE)
-		fprintf(stderr, "HTML_free: ***** leftover option data: %s\n",
+	    CTRACE(tfp, "HTML_free: ***** leftover option data: %s\n",
 			me->option.data);
 	    HTML_put_string(me, me->option.data);
 	    HTChunkClear(&me->option);
@@ -6836,7 +6758,7 @@ PRIVATE void HTML_free ARGS1(HTStructured *, me)
 	     *	have gone very wrong. - kw
 	     */
 	    if (TRACE) {
-		fprintf(stderr,
+		fprintf(tfp,
 			"Bad HTML: TEXTAREA not used properly *****\n");
 	    } else if (!me->inBadHTML) {
 		_statusline(BAD_HTML_USE_TRACE);
@@ -6848,8 +6770,7 @@ PRIVATE void HTML_free ARGS1(HTStructured *, me)
 	     *	Output the left-over data as text, maybe it was invalid
 	     *	markup meant to be shown somewhere. - kw
 	     */
-	    if (TRACE)
-		fprintf(stderr, "HTML_free: ***** leftover textarea data: %s\n",
+	    CTRACE(tfp, "HTML_free: ***** leftover textarea data: %s\n",
 			me->textarea.data);
 	    HTML_put_string(me, me->textarea.data);
 	    HTChunkClear(&me->textarea);
@@ -6884,7 +6805,7 @@ PRIVATE void HTML_free ARGS1(HTStructured *, me)
 	 *  have gone very wrong. - kw
 	 */
 	if (TRACE) {
-	    fprintf(stderr,
+	    fprintf(tfp,
 		    "Bad HTML: SELECT or OPTION not ended properly *****\n");
 	} else if (!me->inBadHTML) {
 	    _statusline(BAD_HTML_USE_TRACE);
@@ -6893,7 +6814,7 @@ PRIVATE void HTML_free ARGS1(HTStructured *, me)
 	}
 	if (TRACE) {
 	    HTChunkTerminate(&me->option);
-	    fprintf(stderr, "HTML_free: ***** leftover option data: %s\n",
+	    fprintf(tfp, "HTML_free: ***** leftover option data: %s\n",
 		    me->option.data);
 	}
 	HTChunkClear(&me->option);
@@ -6905,7 +6826,7 @@ PRIVATE void HTML_free ARGS1(HTStructured *, me)
 	 *  have gone very wrong. - kw
 	 */
 	if (TRACE) {
-	    fprintf(stderr,
+	    fprintf(tfp,
 		    "Bad HTML: TEXTAREA not used properly *****\n");
 	} else if (!me->inBadHTML) {
 	    _statusline(BAD_HTML_USE_TRACE);
@@ -6914,7 +6835,7 @@ PRIVATE void HTML_free ARGS1(HTStructured *, me)
 	}
 	if (TRACE) {
 	    HTChunkTerminate(&me->textarea);
-	    fprintf(stderr, "HTML_free: ***** leftover textarea data: %s\n",
+	    fprintf(tfp, "HTML_free: ***** leftover textarea data: %s\n",
 		    me->textarea.data);
 	}
 	HTChunkClear(&me->textarea);
@@ -6982,10 +6903,10 @@ PRIVATE void HTML_abort ARGS2(HTStructured *, me, HTError, e)
 	 *  have gone very wrong. - kw
 	 */
 	if (TRACE) {
-	    fprintf(stderr,
+	    fprintf(tfp,
 		    "HTML_abort: SELECT or OPTION not ended properly *****\n");
 	    HTChunkTerminate(&me->option);
-	    fprintf(stderr, "HTML_abort: ***** leftover option data: %s\n",
+	    fprintf(tfp, "HTML_abort: ***** leftover option data: %s\n",
 		    me->option.data);
 	}
 	HTChunkClear(&me->option);
@@ -6997,10 +6918,10 @@ PRIVATE void HTML_abort ARGS2(HTStructured *, me, HTError, e)
 	 *  have gone very wrong. - kw
 	 */
 	if (TRACE) {
-	    fprintf(stderr,
+	    fprintf(tfp,
 		    "HTML_abort: TEXTAREA not used properly *****\n");
 	    HTChunkTerminate(&me->textarea);
-	    fprintf(stderr, "HTML_abort: ***** leftover textarea data: %s\n",
+	    fprintf(tfp, "HTML_abort: ***** leftover textarea data: %s\n",
 		    me->textarea.data);
 	}
 	HTChunkClear(&me->textarea);
diff --git a/src/LYBookmark.c b/src/LYBookmark.c
index 5ce5c754..8416563b 100644
--- a/src/LYBookmark.c
+++ b/src/LYBookmark.c
@@ -18,7 +18,7 @@
 #ifdef VMS
 #include <HTVMSUtils.h>
 #include <nam.h>
-extern BOOLEAN HadVMSInterrupt;	/* Flag from cleanup_sig() AST */
+extern BOOLEAN HadVMSInterrupt; /* Flag from cleanup_sig() AST */
 #endif /* VMS */
 
 #include <LYLeaks.h>
@@ -54,15 +54,15 @@ PUBLIC char * get_bookmark_filename ARGS1(
     int MBM_tmp;
 
     /*
-     *  Multi_Bookmarks support. - FMG & FM
-     *  Let user select a bookmark file.
+     *	Multi_Bookmarks support. - FMG & FM
+     *	Let user select a bookmark file.
      */
     MBM_tmp = select_multi_bookmarks();
     if (MBM_tmp == -2)
-        /*
+	/*
 	 *  Zero-length pointer flags a cancel. - FM
-	*/
-        return("");
+	 */
+	return("");
     if (MBM_tmp == -1) {
 	sprintf(string_buffer,
 		BOOKMARK_FILE_NOT_DEFINED,
@@ -74,7 +74,7 @@ PUBLIC char * get_bookmark_filename ARGS1(
 	 */
 	return(" ");
     } else {
-        /*
+	/*
 	 *  Save the filepath as a global.  The system path will be
 	 *  loaded into to the (static) filename_buffer as the return
 	 *  value, the URL will be allocated into *URL, and we also
@@ -86,28 +86,27 @@ PUBLIC char * get_bookmark_filename ARGS1(
     }
 
     /*
-     *  Seek it in the home path. - FM
+     *	Seek it in the home path. - FM
      */
     filename_buffer[255] = '\0';
     LYAddPathToHome(filename_buffer,
 		    sizeof(filename_buffer),
 		    BookmarkPage);
-    if (TRACE)
-        fprintf(stderr, "\nget_bookmark_filename: SEEKING %s\n   AS %s\n\n",
+    CTRACE(tfp, "\nget_bookmark_filename: SEEKING %s\n   AS %s\n\n",
 		BookmarkPage, filename_buffer);
     if ((fp = fopen(filename_buffer,"r")) != NULL) {
 	goto success;
     }
 
     /*
-     *  Failure.
+     *	Failure.
      */
     return(NULL);
 
 success:
     /*
-     *  We now have the file open.
-     *  Check if it is a mosaic hotlist.
+     *	We now have the file open.
+     *	Check if it is a mosaic hotlist.
      */
     if (fgets(string_buffer, 255, fp) &&
 	!strncmp(string_buffer, "ncsa-xmosaic-hotlist-format-1", 29)) {
@@ -126,23 +125,31 @@ success:
 	sprintf(URL_buffer,"file://localhost%s",
 		HTVMS_wwwName((char *)newname));
 #else
+#ifdef __EMX__
+	sprintf(URL_buffer,"file://localhost/%s", newname);
+#else
 	sprintf(URL_buffer,"file://localhost%s", newname);
+#endif /* __EMX__ */
 #endif /* VMS */
 #endif /* DOSPATH */
     } else {
 	fclose(fp);
 	is_mosaic_hotlist = FALSE;
 #ifdef DOSPATH
-        sprintf(URL_buffer,"file://localhost/%s",
+	sprintf(URL_buffer,"file://localhost/%s",
 		HTDOS_wwwName((char *)filename_buffer));
 #else
 #ifdef VMS
 	sprintf(URL_buffer,"file://localhost%s",
-    		HTVMS_wwwName((char *)filename_buffer));
+		HTVMS_wwwName((char *)filename_buffer));
+#else
+#ifdef __EMX__
+	sprintf(URL_buffer,"file://localhost/%s", filename_buffer);
 #else
 	sprintf(URL_buffer,"file://localhost%s", filename_buffer);
+#endif /* __EMX__ */
 #endif /* VMS */
-#endif /* DOSPATH */ 
+#endif /* DOSPATH */
     }
 
     StrAllocCopy(*URL, URL_buffer);
@@ -155,7 +162,7 @@ success:
  *  file for handling as a Lynx bookmark file. - FM
  */
 PRIVATE char * convert_mosaic_bookmark_file ARGS1(
-	char *,		filename_buffer)
+	char *, 	filename_buffer)
 {
     static char newfile[256];
     static BOOLEAN first = TRUE;
@@ -165,16 +172,16 @@ PRIVATE char * convert_mosaic_bookmark_file ARGS1(
     char *endline;
 
     if (first) {
-        tempname(newfile, NEW_FILE);
+	tempname(newfile, NEW_FILE);
 	first = FALSE;
 #ifdef VMS
     } else {
-        remove(newfile);   /* Remove duplicates on VMS. */
+	remove(newfile);   /* Remove duplicates on VMS. */
 #endif /* VMS */
     }
 
     if ((nfp = fopen(newfile, "w")) == NULL) {
-        LYMBM_statusline(NO_TEMP_FOR_HOTLIST);
+	LYMBM_statusline(NO_TEMP_FOR_HOTLIST);
 	sleep(AlertSecs);
 	return ("");
     }
@@ -197,12 +204,12 @@ PRIVATE char * convert_mosaic_bookmark_file ARGS1(
 	    if((line % 2) == 0) { /* even lines */
 		if(*buf != '\0') {
 		    strtok(buf," "); /* kill everything after the space */
-	            fprintf(nfp,"<LI><a href=\"%s\">",buf); /* the URL */
+		    fprintf(nfp,"<LI><a href=\"%s\">",buf); /* the URL */
 		}
 	    } else { /* odd lines */
-	        fprintf(nfp,"%s</a>\n",buf);  /* the title */
+		fprintf(nfp,"%s</a>\n",buf);  /* the title */
 	    }
-	} 
+	}
 	/* else - ignore the line (this gets rid of first two lines) */
 	line++;
     }
@@ -219,8 +226,8 @@ PRIVATE char * convert_mosaic_bookmark_file ARGS1(
  *  to that file. - FM
  */
 PUBLIC void save_bookmark_link ARGS2(
-	char *,		address,
-	char *,		title)
+	char *, 	address,
+	char *, 	title)
 {
     FILE *fp;
     BOOLEAN first_time = FALSE;
@@ -236,32 +243,32 @@ PUBLIC void save_bookmark_link ARGS2(
     HText *text;
 
     /*
-     *  Make sure we were passed something to save. - FM
+     *	Make sure we were passed something to save. - FM
      */
     if (!(address && *address)) {
-        HTAlert(MALFORMED_ADDRESS);
+	HTAlert(MALFORMED_ADDRESS);
 	return;
     }
 
     /*
-     *  Offer a choice of bookmark files,
-     *  or get the default. - FMG
+     *	Offer a choice of bookmark files,
+     *	or get the default. - FMG
      */
     filename = get_bookmark_filename(&bookmark_URL);
 
     /*
-     *  If filename is NULL, must create a new file.  If
-     *  filename is a space, an invalid bookmark file was
-     *  selected, or if zero-length, the user cancelled.
-     *  Ignore request in both cases.  Otherwise, make
-     *  a copy before anything might change the static
-     *  get_bookmark_filename() buffer. - FM
+     *	If filename is NULL, must create a new file.  If
+     *	filename is a space, an invalid bookmark file was
+     *	selected, or if zero-length, the user cancelled.
+     *	Ignore request in both cases.  Otherwise, make
+     *	a copy before anything might change the static
+     *	get_bookmark_filename() buffer. - FM
      */
     if (filename == NULL) {
-        first_time = TRUE;
+	first_time = TRUE;
 	filename_buffer[0] = '\0';
     } else {
-        if (*filename == '\0' || !strcmp(filename," ")) {
+	if (*filename == '\0' || !strcmp(filename," ")) {
 	    FREE(bookmark_URL);
 	    return;
 	}
@@ -269,22 +276,22 @@ PUBLIC void save_bookmark_link ARGS2(
     }
 
     /*
-     *  If BookmarkPage is NULL, something went
-     *  wrong, so ignore the request. - FM
+     *	If BookmarkPage is NULL, something went
+     *	wrong, so ignore the request. - FM
      */
     if (BookmarkPage == NULL) {
-        FREE(bookmark_URL);
+	FREE(bookmark_URL);
 	return;
     }
 
     /*
-     *  If the link will be added to the same
-     *  bookmark file, get confirmation. - FM
+     *	If the link will be added to the same
+     *	bookmark file, get confirmation. - FM
      */
     if (LYMultiBookmarks == TRUE &&
-        strstr(HTLoadedDocumentURL(),
-    	       (*BookmarkPage == '.' ?
-	            (BookmarkPage+1) : BookmarkPage)) != NULL) {
+	strstr(HTLoadedDocumentURL(),
+	       (*BookmarkPage == '.' ?
+		    (BookmarkPage+1) : BookmarkPage)) != NULL) {
 	LYMBM_statusline(MULTIBOOKMARKS_SELF);
 	c = LYgetch();
 	if (TOUPPER(c) != 'L') {
@@ -294,7 +301,7 @@ PUBLIC void save_bookmark_link ARGS2(
     }
 
     /*
-     *  Allow user to change the title. - FM
+     *	Allow user to change the title. - FM
      */
     string_buffer[255] = '\0';
     LYstrncpy(string_buffer, title, 255);
@@ -309,30 +316,29 @@ PUBLIC void save_bookmark_link ARGS2(
     }
 
     /*
-     *  Create the Title with any left-angle-brackets
-     *  converted to &lt; entities and any ampersands
-     *  converted to &amp; entities.  - FM
+     *	Create the Title with any left-angle-brackets
+     *	converted to &lt; entities and any ampersands
+     *	converted to &amp; entities.  - FM
      */
     StrAllocCopy(Title, string_buffer);
     LYEntify(&Title, TRUE);
 
     /*
-     *  Create the bookmark file, if it doesn't exist already,
-     *  Otherwise, open the pre-existing bookmark file. - FM
+     *	Create the bookmark file, if it doesn't exist already,
+     *	Otherwise, open the pre-existing bookmark file. - FM
      */
 #if defined(__DJGPP__) || defined(_WINDOWS)
 	_fmode = O_TEXT;
 #endif /* __DJGPP__  or _WINDOWS */
     if (first_time) {
-        /*
+	/*
 	 *  Seek it in the home path. - FM
 	 */
 	LYAddPathToHome(filename_buffer,
 			sizeof(filename_buffer),
 			BookmarkPage);
     }
-    if (TRACE)
-        fprintf(stderr, "\nsave_bookmark_link: SEEKING %s\n   AS %s\n\n",
+    CTRACE(tfp, "\nsave_bookmark_link: SEEKING %s\n   AS %s\n\n",
 		BookmarkPage, filename_buffer);
     if ((fp = fopen(filename_buffer, (first_time ? "w" : "a+"))) == NULL) {
 	LYMBM_statusline(BOOKMARK_OPEN_FAILED);
@@ -342,13 +348,13 @@ PUBLIC void save_bookmark_link ARGS2(
     }
 
     /*
-     *  Convert all ampersands in the address to &amp; entities. - FM
+     *	Convert all ampersands in the address to &amp; entities. - FM
      */
     StrAllocCopy(Address, address);
     LYEntify(&Address, FALSE);
 
     /*
-     *  If we created a new bookmark file, write the headers. - FM
+     *	If we created a new bookmark file, write the headers. - FM
      */
     if (first_time) {
 	fprintf(fp,"<head>\n");
@@ -365,7 +371,7 @@ PUBLIC void save_bookmark_link ARGS2(
     }
 
     /*
-     *  Add the bookmark link, in Mosaic hotlist or Lynx format. - FM
+     *	Add the bookmark link, in Mosaic hotlist or Lynx format. - FM
      */
     if (is_mosaic_hotlist) {
 	time_t NowTime = time(NULL);
@@ -383,14 +389,14 @@ PUBLIC void save_bookmark_link ARGS2(
     _fmode = O_BINARY;
 #endif /* __DJGPP__ or _WINDOWS */
     /*
-     *  If this is a cached bookmark file, set nocache for
-     *  it so we'll see the new bookmark link when that
-     *  cache is retrieved. - FM
+     *	If this is a cached bookmark file, set nocache for
+     *	it so we'll see the new bookmark link when that
+     *	cache is retrieved. - FM
      */
     if (!first_time && nhist > 0 && bookmark_URL) {
-    	for (i = 0; i < nhist; i++) {
+	for (i = 0; i < nhist; i++) {
 	    if (history[i].bookmark &&
-	    	!strcmp(history[i].address, bookmark_URL)) {
+		!strcmp(history[i].address, bookmark_URL)) {
 		WWWDoc.address = history[i].address;
 		WWWDoc.post_data = NULL;
 		WWWDoc.post_content_type = NULL;
@@ -399,7 +405,7 @@ PUBLIC void save_bookmark_link ARGS2(
 		WWWDoc.safe = FALSE;
 		if (((tmpanchor = HTAnchor_parent(
 					HTAnchor_findAddress(&WWWDoc)
-				    		 )) != NULL) &&
+						 )) != NULL) &&
 		    (text = (HText *)HTAnchor_document(tmpanchor)) != NULL) {
 		    HText_setNoCache(text);
 		}
@@ -409,7 +415,7 @@ PUBLIC void save_bookmark_link ARGS2(
     }
 
     /*
-     *  Clean up and report success.
+     *	Clean up and report success.
      */
     FREE(Title);
     FREE(Address);
@@ -417,7 +423,7 @@ PUBLIC void save_bookmark_link ARGS2(
     LYMBM_statusline(OPERATION_DONE);
     sleep(MessageSecs);
 }
-	
+
 /*
  *  Remove a link from a bookmark file.  The calling
  *  function is expected to have used get_filename_link(),
@@ -427,7 +433,7 @@ PUBLIC void save_bookmark_link ARGS2(
  */
 PUBLIC void remove_bookmark_link ARGS2(
 	int,		cur,
-	char *,		cur_bookmark_page)
+	char *, 	cur_bookmark_page)
 {
     FILE *fp, *nfp;
     char buf[BUFSIZ];
@@ -442,17 +448,14 @@ PUBLIC void remove_bookmark_link ARGS2(
     mode_t mode;
 #endif /* VMS */
 
-    if (TRACE)
-	fprintf(stderr, "remove_bookmark_link: deleting link number: %d\n",
-			cur);
+    CTRACE(tfp, "remove_bookmark_link: deleting link number: %d\n", cur);
 
     if (!cur_bookmark_page)
 	return;
     LYAddPathToHome(filename_buffer,
 		    sizeof(filename_buffer),
 		    cur_bookmark_page);
-    if (TRACE)
-        fprintf(stderr, "\nremove_bookmark_link: SEEKING %s\n   AS %s\n\n",
+    CTRACE(tfp, "\nremove_bookmark_link: SEEKING %s\n   AS %s\n\n",
 		cur_bookmark_page, filename_buffer);
     if ((fp = fopen(filename_buffer, "r")) == NULL) {
 	_statusline(BOOKMARK_OPEN_FAILED_FOR_DEL);
@@ -478,7 +481,7 @@ PUBLIC void remove_bookmark_link ARGS2(
 
 #ifdef UNIX
     /*
-     *  Explicitly preserve bookmark file mode on Unix. - DSL
+     *	Explicitly preserve bookmark file mode on Unix. - DSL
      */
     if (stat(filename_buffer, &stat_buf) == 0) {
 	mode = ((stat_buf.st_mode & 0777) | HIDE_CHMOD);
@@ -497,12 +500,12 @@ PUBLIC void remove_bookmark_link ARGS2(
     if (is_mosaic_hotlist) {
 	int del_line = cur*2;  /* two lines per entry */
 	n = -3;  /* skip past cookie and name lines */
-        while (fgets(buf, sizeof(buf), fp) != NULL) {
+	while (fgets(buf, sizeof(buf), fp) != NULL) {
 	    n++;
-	    if (n == del_line || n == del_line+1) 
+	    if (n == del_line || n == del_line+1)
 		continue;  /* remove two lines */
-            if (fputs(buf, nfp) == EOF)
-                goto failure;
+	    if (fputs(buf, nfp) == EOF)
+		goto failure;
 	}
 
     } else {
@@ -510,34 +513,31 @@ PUBLIC void remove_bookmark_link ARGS2(
 	BOOLEAN retain;
 	int seen;
 
-        n = -1;
-        while (fgets(buf, sizeof(buf), fp) != NULL) {
+	n = -1;
+	while (fgets(buf, sizeof(buf), fp) != NULL) {
 	    retain = TRUE;
 	    seen = 0;
 	    cp = buf;
-            while (n < cur && (cp = LYstrstr(cp, "<a href="))) {
+	    while (n < cur && (cp = LYstrstr(cp, "<a href="))) {
 		seen++;
-                if (++n == cur) {
+		if (++n == cur) {
 		    if (seen != 1 || !LYstrstr(buf, "</a>") ||
 			LYstrstr((cp + 1), "<a href=")) {
 			_statusline(BOOKMARK_LINK_NOT_ONE_LINE);
 			sleep(AlertSecs);
 			goto failure;
 		    }
-		    if (TRACE)
-	    		fprintf(stderr,
-				"remove_bookmark_link: skipping link %d\n", n);
-                    retain = FALSE;
+		    CTRACE(tfp, "remove_bookmark_link: skipping link %d\n", n);
+		    retain = FALSE;
 		}
 		cp += 8;
-            }
-            if (retain && fputs(buf, nfp) == EOF)
-                goto failure;
-        }
+	    }
+	    if (retain && fputs(buf, nfp) == EOF)
+		goto failure;
+	}
     }
 
-    if (TRACE)
-	fprintf(stderr, "remove_bookmark_link: files: %s %s\n",
+    CTRACE(tfp, "remove_bookmark_link: files: %s %s\n",
 			newfile, filename_buffer);
 
     fclose(fp);
@@ -554,7 +554,7 @@ PUBLIC void remove_bookmark_link ARGS2(
 	 *  Purge lower version of file.
 	 */
 	sprintf(VMSfilename, "%s;-1", filename_buffer);
-        while (remove(VMSfilename) == 0)
+	while (remove(VMSfilename) == 0)
 	    ;
 	/*
 	 *  Reset version number.
@@ -562,7 +562,7 @@ PUBLIC void remove_bookmark_link ARGS2(
 	sprintf(VMSfilename, "%s;1", filename_buffer);
 	rename(filename_buffer, VMSfilename);
 #endif /* VMS */
-        return;
+	return;
     } else {
 #ifndef VMS
 	/*
@@ -571,10 +571,10 @@ PUBLIC void remove_bookmark_link ARGS2(
 	 *  Used to be ODD_RENAME
 	 */
 #ifdef _WINDOWS
-        if (errno == ENOTSAM) {
+	if (errno == ENOTSAM) {
 #else
 	if (errno == EXDEV) {
-#endif /* WINDOWS */ 
+#endif /* WINDOWS */
 	    char buffer[2048];
 	    sprintf(buffer, "%s %s %s", MV_PATH, newfile, filename_buffer);
 	    system(buffer);
@@ -591,14 +591,14 @@ PUBLIC void remove_bookmark_link ARGS2(
 	    perror("renaming the file");
 	sleep(AlertSecs);
     }
-	   
+
 failure:
     _statusline(BOOKMARK_DEL_FAILED);
     sleep(AlertSecs);
     if (nfp != NULL)
 	fclose(nfp);
     if (fp != NULL)
-        fclose(fp);
+	fclose(fp);
     remove(newfile);
 }
 
@@ -610,19 +610,19 @@ PUBLIC int select_multi_bookmarks NOARGS
     int c;
 
     /*
-     *  If not enabled, pick the "default" (0).
+     *	If not enabled, pick the "default" (0).
      */
     if (LYMultiBookmarks == FALSE || LYHaveSubBookmarks() == FALSE) {
 	if (MBM_A_subbookmark[0]) /* If it exists! */
-            return(0);
+	    return(0);
 	else
-            return(-1);
+	    return(-1);
     }
 
     /*
-     *  For ADVANCED users, we can just mess with the status line to save
-     *  the 2 redraws of the screen, if LYMBMAdvnced is TRUE.  '=' will
-     *  still show the screen and let them do it the "long" way.
+     *	For ADVANCED users, we can just mess with the status line to save
+     *	the 2 redraws of the screen, if LYMBMAdvnced is TRUE.  '=' will
+     *	still show the screen and let them do it the "long" way.
      */
     if (LYMBMAdvanced && user_mode == ADVANCED_MODE) {
 	LYMBM_statusline(MULTIBOOKMARKS_SELECT);
@@ -632,18 +632,18 @@ get_advanced_choice:
 	if (HadVMSInterrupt) {
 	    HadVMSInterrupt = FALSE;
 	    c = 7;
-        }
+	}
 #endif /* VMS */
 	if (LYisNonAlnumKeyname(c, LYK_PREV_DOC) ||
 	    c == 7 || c == 3) {
 	    /*
-	     *  Treat left-arrow, ^G, or ^C as cancel.
+	     *	Treat left-arrow, ^G, or ^C as cancel.
 	     */
 	    return(-2);
 	}
 	if (LYisNonAlnumKeyname(c, LYK_REFRESH)) {
 	    /*
-	     *  Refresh the screen.
+	     *	Refresh the screen.
 	     */
 	    lynx_force_repaint();
 	    refresh();
@@ -651,19 +651,19 @@ get_advanced_choice:
 	}
 	if (LYisNonAlnumKeyname(c, LYK_ACTIVATE)) {
 	    /*
-	     *  Assume default bookmark file on ENTER or right-arrow.
+	     *	Assume default bookmark file on ENTER or right-arrow.
 	     */
 	    return (MBM_A_subbookmark[0] ? 0 : -1);
 	}
 	switch (c) {
 	    case '=':
-	        /*
+		/*
 		 *  Get the choice via the menu.
 		 */
 		return(select_menu_multi_bookmarks());
 
 	    default:
-	        /*
+		/*
 		 *  Convert to an array index, act on it if valid.
 		 *  Otherwise, get another keystroke.
 		 */
@@ -677,7 +677,7 @@ get_advanced_choice:
 	 */
 	return (MBM_A_subbookmark[c] ? c : -1);
     } else {
-        /*
+	/*
 	 *  Get the choice via the menu.
 	 */
 	return(select_menu_multi_bookmarks());
@@ -695,41 +695,41 @@ PUBLIC int select_menu_multi_bookmarks NOARGS
     char shead_buffer[256];
 
     /*
-     *  If not enabled, pick the "default" (0).
+     *	If not enabled, pick the "default" (0).
      */
     if (LYMultiBookmarks == FALSE)
 	return(0);
 
     /*
-     *  Filip M. Gieszczykiewicz (filipg@paranoia.com) & FM
-     *  ---------------------------------------------------
-     *  LYMultiBookmarks - TRUE when multi_support enabled.
+     *	Filip M. Gieszczykiewicz (filipg@paranoia.com) & FM
+     *	---------------------------------------------------
+     *	LYMultiBookmarks - TRUE when multi_support enabled.
      *
-     *  MBM_A_subbookmark[n] - Hold values of the respective
-     *  "multi_bookmarkn" in the lynxrc file.
+     *	MBM_A_subbookmark[n] - Hold values of the respective
+     *	"multi_bookmarkn" in the lynxrc file.
      *
-     *  MBM_A_subdescript[n] - Hold description entries in the
-     *  lynxrc file.
+     *	MBM_A_subdescript[n] - Hold description entries in the
+     *	lynxrc file.
      *
-     *  Note: MBM_A_subbookmark[0] is defined to be same value as
-     *        "bookmark_file" in the lynxrc file and/or the startup
-     *        "bookmark_page".
+     *	Note: MBM_A_subbookmark[0] is defined to be same value as
+     *	      "bookmark_file" in the lynxrc file and/or the startup
+     *	      "bookmark_page".
      *
-     *  We make the display of bookmarks depend on rows we have
-     *  available.
+     *	We make the display of bookmarks depend on rows we have
+     *	available.
      *
-     *  We load BookmarkPage with the valid MBM_A_subbookmark[n]
-     *  via get_bookmark_filename().  Otherwise, that function
-     *  returns a zero-length string to indicate a cancel, a
-     *  single space to indicate an invalid choice, or NULL to
-     *  indicate an inaccessible file.
+     *	We load BookmarkPage with the valid MBM_A_subbookmark[n]
+     *	via get_bookmark_filename().  Otherwise, that function
+     *	returns a zero-length string to indicate a cancel, a
+     *	single space to indicate an invalid choice, or NULL to
+     *	indicate an inaccessible file.
      */
     MBM_allow=(LYlines-7);	/* We need 7 for header and footer */
     /*
-     *  Screen big enough?
+     *	Screen big enough?
      */
     if (MBM_allow <= 0) {
-        /*
+	/*
 	 *  Too small.
 	 */
 	_statusline(MULTIBOOKMARKS_SMALL);
@@ -737,10 +737,10 @@ PUBLIC int select_menu_multi_bookmarks NOARGS
 	return (-2);
     }
     /*
-     *  Load the bad choice message buffer.
+     *	Load the bad choice message buffer.
      */
     sprintf(string_buffer,
-    	    BOOKMARK_FILE_NOT_DEFINED,
+	    BOOKMARK_FILE_NOT_DEFINED,
 	    key_for_func(LYK_OPTIONS));
 
     MBM_screens = (MBM_V_MAXFILES/MBM_allow)+1; /* int rounds off low. */
@@ -759,21 +759,21 @@ draw_bookmark_choices:
 	MBM_to = MBM_V_MAXFILES;
 
     /*
-     *  Display menu of bookmarks.  NOTE that we avoid printw()'s
-     *  to increase the chances that any non-ASCII or multibyte/CJK
-     *  characters will be handled properly. - FM
+     *	Display menu of bookmarks.  NOTE that we avoid printw()'s
+     *	to increase the chances that any non-ASCII or multibyte/CJK
+     *	characters will be handled properly. - FM
      */
     clear();
     move(1, 5);
     lynx_start_h1_color ();
     if (MBM_screens > 1) {
-        sprintf(shead_buffer,
+	sprintf(shead_buffer,
 		MULTIBOOKMARKS_SHEAD_MASK, MBM_current, MBM_screens);
 	addstr(shead_buffer);
     } else {
-        addstr(MULTIBOOKMARKS_SHEAD);
+	addstr(MULTIBOOKMARKS_SHEAD);
     }
-   
+
    lynx_stop_h1_color ();
 
     MBM_tmp_count = 0;
@@ -792,7 +792,7 @@ draw_bookmark_choices:
     }
 
     /*
-     *  Don't need to show it if it all fits on one screen!
+     *	Don't need to show it if it all fits on one screen!
      */
     if (MBM_screens > 1) {
 	move(LYlines-2, 0);
@@ -845,20 +845,20 @@ get_bookmark_choice:
     }
 
     /*
-     *  Next range, if available.
+     *	Next range, if available.
      */
     if ((c == ']' ||  LYisNonAlnumKeyname(c, LYK_NEXT_PAGE)) &&
-        MBM_screens > 1) {
+	MBM_screens > 1) {
 	if (++MBM_current > MBM_screens)
 	    MBM_current = 1;
 	goto draw_bookmark_choices;
     }
 
     /*
-     *  Previous range, if available.
+     *	Previous range, if available.
      */
     if ((c == '[' ||  LYisNonAlnumKeyname(c, LYK_PREV_PAGE)) &&
-        MBM_screens > 1) {
+	MBM_screens > 1) {
 	if (--MBM_current <= 0)
 	    MBM_current = MBM_screens;
 	goto draw_bookmark_choices;
@@ -866,12 +866,12 @@ get_bookmark_choice:
 
     c = TOUPPER(c) - 'A';
     /*
-     *  See if we have a bookmark like that.
+     *	See if we have a bookmark like that.
      */
     if (c < 0 || c > MBM_V_MAXFILES) {
 	goto get_bookmark_choice;
     } else if (!MBM_A_subbookmark[c]) {
- 	LYMBM_statusline(string_buffer);
+	LYMBM_statusline(string_buffer);
 	sleep(AlertSecs);
 	LYMBM_statusline(MULTIBOOKMARKS_SAVE);
 	goto get_bookmark_choice;
@@ -890,7 +890,7 @@ PUBLIC BOOLEAN LYHaveSubBookmarks NOARGS
     int i;
 
     for (i = 1; i < MBM_V_MAXFILES; i++) {
-        if (MBM_A_subbookmark[i] != NULL && *MBM_A_subbookmark[i] != '\0')
+	if (MBM_A_subbookmark[i] != NULL && *MBM_A_subbookmark[i] != '\0')
 	    return(TRUE);
     }
 
@@ -906,13 +906,13 @@ PUBLIC BOOLEAN LYHaveSubBookmarks NOARGS
  *  string will be handled properly. - FM
  */
  PUBLIC void LYMBM_statusline  ARGS1(
- 	char *,		text)
+	char *, 	text)
 {
     if (LYMultiBookmarks == TRUE && user_mode == NOVICE_MODE) {
 	LYStatusLine = (LYlines - 1);
-        _statusline(text);
+	_statusline(text);
 	LYStatusLine = -1;
     } else {
-        _statusline(text);
+	_statusline(text);
     }
 }
diff --git a/src/LYCgi.c b/src/LYCgi.c
index 9a6ab780..efd29007 100644
--- a/src/LYCgi.c
+++ b/src/LYCgi.c
@@ -190,9 +190,7 @@ PRIVATE int LYLoadCGI ARGS4(
 	    /* Found PATH_INFO data. Strip it off of pgm and into path_info. */
 	    StrAllocCopy(path_info, pgm+strlen(pgm_buff));
 	    strcpy(pgm, pgm_buff);
-	    if (TRACE)
-		fprintf(stderr,
-			"LYNXCGI: stat() of %s succeeded, path_info=\"%s\".\n",
+	    CTRACE(tfp, "LYNXCGI: stat() of %s succeeded, path_info=\"%s\".\n",
 			pgm_buff, path_info);
 	}
 	FREE(pgm_buff);
@@ -223,11 +221,8 @@ PRIVATE int LYLoadCGI ARGS4(
 	 *  to confusing to know just what file is loaded. - kw
 	 */
 	if (path_info) {
-	    if (TRACE) {
-		fprintf(stderr,
-			"%s is not a file and %s not an executable, giving up.\n",
+	    CTRACE(tfp, "%s is not a file and %s not an executable, giving up.\n",
 			orig_pgm, pgm);
-	    }
 	    FREE(path_info);
 	    FREE(pgm);
 	    FREE(orig_pgm);
@@ -238,10 +233,7 @@ PRIVATE int LYLoadCGI ARGS4(
 	StrAllocCopy(new_arg, "file://localhost");
 	StrAllocCat(new_arg, orig_pgm);
 
-	if (TRACE) {
-	    fprintf(stderr,
-		    "%s is not an executable file, passing the buck.\n", arg);
-	}
+	CTRACE(tfp, "%s is not an executable file, passing the buck.\n", arg);
 	status = HTLoadFile(new_arg, anAnchor, format_out, sink);
 	FREE(new_arg);
 
@@ -372,13 +364,10 @@ PRIVATE int LYLoadCGI ARGS4(
 		    close(fd1[0]);
 
 		    /* We have form data to push across the pipe */
-		    if (TRACE) {
-			fprintf(stderr, "LYNXCGI: Doing post, content-type '%s'\n",
+		    CTRACE(tfp, "LYNXCGI: Doing post, content-type '%s'\n",
 				anAnchor->post_content_type);
-			fprintf(stderr,
-				"LYNXCGI: Writing:\n%s----------------------------------\n",
+		    CTRACE(tfp, "LYNXCGI: Writing:\n%s----------------------------------\n",
 				anAnchor->post_data);			
-		    }
 		    remaining = strlen(anAnchor->post_data);
 		    while ((written = write(fd1[1],
 					    anAnchor->post_data + total_written,
@@ -397,20 +386,15 @@ PRIVATE int LYLoadCGI ARGS4(
 			    }
 			    break;
 			}
-			if (TRACE) {
-			    fprintf(stderr,
-				    "LYNXCGI: Wrote %d bytes of POST data.\n",
+			CTRACE(tfp, "LYNXCGI: Wrote %d bytes of POST data.\n",
 				    written);
-			}
 			total_written += written;
 			remaining -= written;
 			if (remaining == 0)
 			    break;
 		    }
 		    if (remaining != 0) {
-			if (TRACE)
-			    fprintf(stderr,
-				    "LYNXCGI: %d bytes remain unwritten!\n",
+			CTRACE(tfp, "LYNXCGI: %d bytes remain unwritten!\n",
 				    remaining);
 		    }
 		    close(fd1[1]);
@@ -423,9 +407,7 @@ PRIVATE int LYLoadCGI ARGS4(
 		    total_chars += chars;
 		    sprintf (line, "Read %d bytes of data.", total_chars);
 		    HTProgress(line);
-		    if (TRACE) {
-			fprintf(stderr, "LYNXCGI: Rx: %.*s\n", chars, buf);
-		    }
+		    CTRACE(tfp, "LYNXCGI: Rx: %.*s\n", chars, buf);
 		    
 		    (*target->isa->put_block)(target, buf, chars);
 		}
diff --git a/src/LYCharUtils.c b/src/LYCharUtils.c
index e860ce47..c8685b88 100644
--- a/src/LYCharUtils.c
+++ b/src/LYCharUtils.c
@@ -910,11 +910,8 @@ PUBLIC void LYExpandString ARGS2(
 	**  The chartrans procedure failed, so we don't
 	**  do anything, and hope for the best. - FM
 	*/
-	if (TRACE) {
-	    fprintf(stderr,
-		    "LYExpandString: Bad in (%d) or out (%d) handle(s).\n",
+	CTRACE(tfp, "LYExpandString: Bad in (%d) or out (%d) handle(s).\n",
 		    me->inUCLYhndl, me->outUCLYhndl);
-	}
 	return;
     }
 
@@ -1327,10 +1324,7 @@ PUBLIC void LYExpandString ARGS2(
 	*/
 	if (code == 8204 || code == 8205 ||
 	    code == 8206 || code == 8207) {
-	    if (TRACE) {
-		fprintf(stderr,
-			"LYExpandString: Ignoring '%ld'.\n", code);
-	    }
+	    CTRACE(tfp, "LYExpandString: Ignoring '%ld'.\n", code);
 	    if (me->T.decode_utf8 && *utf_buf) {
 		utf_buf[0] == '\0';
 		utf_buf_p = utf_buf;
@@ -2116,10 +2110,7 @@ PRIVATE char ** LYUCFullyTranslateString_1 ARGS9(
 		    */
 		} else if (code == 8204 || code == 8205 ||
 			   code == 8206 || code == 8207) {
-		    if (TRACE) {
-			fprintf(stderr,
-				"LYUCFullyTranslateString: Ignoring '%ld'.\n", code);
-		    }
+		    CTRACE(tfp, "LYUCFullyTranslateString: Ignoring '%ld'.\n", code);
 		    replace_buf[0] = '\0';
 		    state = S_got_outstring;
 		    break;
@@ -2430,13 +2421,10 @@ PUBLIC void LYHandleMETA ARGS4(
 	    FREE(content);
 	}
     }
-    if (TRACE) {
-	fprintf(stderr,
-		"LYHandleMETA: HTTP-EQUIV=\"%s\" NAME=\"%s\" CONTENT=\"%s\"\n",
+    CTRACE(tfp, "LYHandleMETA: HTTP-EQUIV=\"%s\" NAME=\"%s\" CONTENT=\"%s\"\n",
 		(http_equiv ? http_equiv : "NULL"),
 		(name ? name : "NULL"),
 		(content ? content : "NULL"));
-    }
 
     /*
      *	Make sure we have META name/value pairs to handle. - FM
@@ -2735,8 +2723,8 @@ PUBLIC void LYHandleMETA ARGS4(
 	    }
 	    FREE(cp3);
 
-	    if (TRACE && me->node_anchor->charset) {
-		fprintf(stderr,
+	    if (me->node_anchor->charset) {
+		CTRACE(tfp,
 			"LYHandleMETA: New charset: %s\n",
 			me->node_anchor->charset);
 	    }
@@ -3096,7 +3084,7 @@ PUBLIC void LYHandleSELECT ARGS5(
 	 */
 	if (!me->inFORM) {
 	    if (TRACE) {
-		fprintf(stderr,
+		fprintf(tfp,
 			"Bad HTML: SELECT start tag not within FORM tag\n");
 	    } else if (!me->inBadHTML) {
 		_statusline(BAD_HTML_USE_TRACE);
@@ -3120,7 +3108,7 @@ PUBLIC void LYHandleSELECT ARGS5(
 	 */
 	if (me->inTEXTAREA) {
 	    if (TRACE) {
-		fprintf(stderr, "Bad HTML: Missing TEXTAREA end tag\n");
+		fprintf(tfp, "Bad HTML: Missing TEXTAREA end tag\n");
 	    } else if (!me->inBadHTML) {
 		_statusline(BAD_HTML_USE_TRACE);
 		me->inBadHTML = TRUE;
@@ -3154,11 +3142,8 @@ PUBLIC void LYHandleSELECT ARGS5(
 	    /*
 	     *	Let the size be determined by the number of OPTIONs. - FM
 	     */
-	    if (TRACE) {
-		fprintf(stderr,
-			"LYHandleSELECT: Ignoring SIZE=\"%s\" for SELECT.\n",
+	    CTRACE(tfp, "LYHandleSELECT: Ignoring SIZE=\"%s\" for SELECT.\n",
 			(char *)value[HTML_SELECT_SIZE]);
-	    }
 #endif /* NOTDEFINED */
 	}
 
@@ -3208,7 +3193,7 @@ PUBLIC void LYHandleSELECT ARGS5(
 	 */
 	if (!me->inSELECT) {
 	    if (TRACE) {
-		fprintf(stderr, "Bad HTML: Unmatched SELECT end tag\n");
+		fprintf(tfp, "Bad HTML: Unmatched SELECT end tag\n");
 	    } else if (!me->inBadHTML) {
 		_statusline(BAD_HTML_USE_TRACE);
 		me->inBadHTML = TRUE;
@@ -3407,10 +3392,10 @@ PUBLIC int LYLegitimizeHREF ARGS4(
 		    str = "s";
 		}
 		if (TRACE) {
-		    fprintf(stderr,
+		    fprintf(tfp,
 			 "LYLegitimizeHREF: Bad value '%s' for http%s URL.\n",
 			   *href, str);
-		    fprintf(stderr,
+		    fprintf(tfp,
 			 "                  Stripping lead dots.\n");
 		} else if (!me->inBadHREF) {
 		    _statusline(BAD_PARTIAL_REFERENCE);
diff --git a/src/LYCookie.c b/src/LYCookie.c
index bde4a81d..e94da151 100644
--- a/src/LYCookie.c
+++ b/src/LYCookie.c
@@ -285,9 +285,7 @@ PRIVATE void store_cookie ARGS3(
      *	not a prefix of the request-URI.
      */
     if (strncmp(co->path, path, co->pathlen) != 0) {
-	if (TRACE)
-	    fprintf(stderr,
-	    "store_cookie: Rejecting because '%s' is not a prefix of '%s'.\n",
+	CTRACE(tfp, "store_cookie: Rejecting because '%s' is not a prefix of '%s'.\n",
 		    co->path, path);
 	freeCookie(co);
 	co = NULL;
@@ -302,9 +300,7 @@ PRIVATE void store_cookie ARGS3(
 	 *  The hostname does not contain a dot.
 	 */
 	if (strchr(hostname, '.') == NULL) {
-	    if (TRACE)
-		fprintf(stderr,
-			"store_cookie: Rejecting because '%s' has no dot.\n",
+	    CTRACE(tfp, "store_cookie: Rejecting because '%s' has no dot.\n",
 			hostname);
 	    freeCookie(co);
 	    co = NULL;
@@ -319,9 +315,7 @@ PRIVATE void store_cookie ARGS3(
 	 *  value otherwise qualified. - FM
 	 */
 	if (co->domain[0] != '.' || co->domain[1] == '\0') {
-	    if (TRACE)
-		fprintf(stderr,
-			"store_cookie: Rejecting domain '%s'.\n",
+	    CTRACE(tfp, "store_cookie: Rejecting domain '%s'.\n",
 			co->domain);
 	    freeCookie(co);
 	    co = NULL;
@@ -329,9 +323,7 @@ PRIVATE void store_cookie ARGS3(
 	}
 	ptr = strchr((co->domain + 1), '.');
 	if (ptr == NULL || ptr[1] == '\0') {
-	    if (TRACE)
-		fprintf(stderr,
-			"store_cookie: Rejecting domain '%s'.\n",
+	    CTRACE(tfp, "store_cookie: Rejecting domain '%s'.\n",
 			co->domain);
 	    freeCookie(co);
 	    co = NULL;
@@ -343,9 +335,7 @@ PRIVATE void store_cookie ARGS3(
 	 *  not domain-match the Domain attribute.
 	 */
 	if (!host_matches(hostname, co->domain)) {
-	    if (TRACE)
-		fprintf(stderr,
-			"store_cookie: Rejecting domain '%s' for host '%s'.\n",
+	    CTRACE(tfp, "store_cookie: Rejecting domain '%s' for host '%s'.\n",
 			co->domain, hostname);
 	    freeCookie(co);
 	    co = NULL;
@@ -370,12 +360,9 @@ PRIVATE void store_cookie ARGS3(
 		    co->domain,
 		    hostname);
 	    if (!HTConfirm(msg)) {
-		if (TRACE) {
-		    fprintf(stderr,
-		       "store_cookie: Rejecting domain '%s' for host '%s'.\n",
+		CTRACE(tfp, "store_cookie: Rejecting domain '%s' for host '%s'.\n",
 			    co->domain,
 			    hostname);
-		}
 		freeCookie(co);
 		co = NULL;
 		FREE(msg);
@@ -474,9 +461,7 @@ PRIVATE void store_cookie ARGS3(
      *	Don't add the cookie if we're over the domain's limit. - FM
      */
     } else if (HTList_count(cookie_list) > 50) {
-	if (TRACE)
-	    fprintf(stderr,
-	"store_cookie: Domain's cookie limit exceeded!  Rejecting cookie.\n");
+	CTRACE(tfp, "store_cookie: Domain's cookie limit exceeded!  Rejecting cookie.\n");
 	freeCookie(co);
 	co = NULL;
 
@@ -484,9 +469,7 @@ PRIVATE void store_cookie ARGS3(
      *	Don't add the cookie if we're over the total cookie limit. - FM
      */
     } else if (total_cookies > 500) {
-	if (TRACE)
-	    fprintf(stderr,
-	"store_cookie: Total cookie limit exceeded!  Rejecting cookie.\n");
+	CTRACE(tfp, "store_cookie: Total cookie limit exceeded!  Rejecting cookie.\n");
 	freeCookie(co);
 	co = NULL;
 
@@ -536,12 +519,12 @@ PRIVATE char * scan_cookie_sublist ARGS6(
 	co = (cookie *)hl->object;
 	next = hl->next;
 
-	if (TRACE && co) {
-	    fprintf(stderr, "Checking cookie %lx %s=%s\n",
+	if (co) {
+	    CTRACE(tfp, "Checking cookie %lx %s=%s\n",
 			    (long)hl,
 			    (co->name ? co->name : "(no name)"),
 			    (co->value ? co->value : "(no value)"));
-	    fprintf(stderr, "%s %s %d %s %s %d%s\n",
+	    CTRACE(tfp, "%s %s %d %s %s %d%s\n",
 			    hostname,
 			    (co->domain ? co->domain : "(no domain)"),
 			    host_matches(hostname, co->domain),
@@ -718,8 +701,8 @@ PRIVATE void LYProcessSetCookies ARGS6(
      *	adding each cookie to the CombinedCookies list. - FM
      */
     p = (SetCookie2 ? SetCookie2 : "");
-    if (TRACE && SetCookie && *p) {
-	fprintf(stderr, "LYProcessSetCookies: Using Set-Cookie2 header.\n");
+    if (SetCookie && *p) {
+	CTRACE(tfp, "LYProcessSetCookies: Using Set-Cookie2 header.\n");
     }
     while (NumCookies <= 50 && *p) {
 	attr_start = attr_end = value_start = value_end = NULL;
@@ -976,9 +959,7 @@ PRIVATE void LYProcessSetCookies ARGS6(
 			 url_type == HTTPS_URL_TYPE)) {
 			length += strlen(cur_cookie->commentURL);
 		    } else {
-			if (TRACE)
-			    fprintf(stderr,
-		     "LYProcessSetCookies: Rejecting commentURL value '%s'\n",
+			CTRACE(tfp, "LYProcessSetCookies: Rejecting commentURL value '%s'\n",
 				    cur_cookie->commentURL);
 			FREE(cur_cookie->commentURL);
 		    }
@@ -1007,11 +988,9 @@ PRIVATE void LYProcessSetCookies ARGS6(
 				   isdigit((unsigned char)*ptr))
 				ptr++;
 			    if (*ptr != '\0') {
-				if (TRACE) {
-				    fprintf(stderr,
+				CTRACE(tfp,
 	       "LYProcessSetCookies: Adding lead dot for domain value '%s'\n",
 					    value);
-				}
 				StrAllocCopy(cur_cookie->domain, ".");
 				StrAllocCat(cur_cookie->domain, value);
 			    } else {
@@ -1094,9 +1073,7 @@ PRIVATE void LYProcessSetCookies ARGS6(
 			cur_cookie->expires = (time_t)0;
 		    } else {
 			cur_cookie->expires = (time(NULL) + temp);
-			if (TRACE)
-			    fprintf(stderr,
-				    "LYSetCookie: expires %ld, %s",
+			CTRACE(tfp, "LYSetCookie: expires %ld, %s",
 				    (long) cur_cookie->expires,
 				    ctime(&cur_cookie->expires));
 		    }
@@ -1119,9 +1096,7 @@ PRIVATE void LYProcessSetCookies ARGS6(
 			cur_cookie->flags |= COOKIE_FLAG_EXPIRES_SET;
 			cur_cookie->expires = LYmktime(value, FALSE);
 			if (cur_cookie->expires > 0) {
-			    if (TRACE)
-				fprintf(stderr,
-					"LYSetCookie: expires %ld, %s",
+			    CTRACE(tfp, "LYSetCookie: expires %ld, %s",
 					(long) cur_cookie->expires,
 					ctime(&cur_cookie->expires));
 			}
@@ -1151,16 +1126,14 @@ PRIVATE void LYProcessSetCookies ARGS6(
 		    }
 		    HTList_appendObject(CombinedCookies, cur_cookie);
 		} else if (cur_cookie != NULL) {
-		    if (TRACE) {
-			fprintf(stderr,
+		    CTRACE(tfp,
 			"LYProcessSetCookies: Rejecting Set-Cookie2: %s=%s\n",
 				(cur_cookie->name ?
 				 cur_cookie->name : "[no name]"),
 				(cur_cookie->value ?
 				 cur_cookie->value : "[no value]"));
-			fprintf(stderr,
+		    CTRACE(tfp,
 			"                     due to excessive length!\n");
-		    }
 		    freeCookie(cur_cookie);
 		    cur_cookie = NULL;
 		}
@@ -1196,17 +1169,13 @@ PRIVATE void LYProcessSetCookies ARGS6(
 	}
 	HTList_appendObject(CombinedCookies, cur_cookie);
     } else if (cur_cookie != NULL) {
-	if (TRACE) {
-	    fprintf(stderr,
-	 "LYProcessSetCookies: Rejecting Set-Cookie2: %s=%s\n",
+	CTRACE(tfp, "LYProcessSetCookies: Rejecting Set-Cookie2: %s=%s\n",
 		    (cur_cookie->name ? cur_cookie->name : "[no name]"),
 		    (cur_cookie->value ? cur_cookie->value : "[no value]"));
-	    fprintf(stderr,
-	 "                     due to excessive %s%s%s\n",
+	CTRACE(tfp, "                     due to excessive %s%s%s\n",
 		    (length > 4096 ? "length" : ""),
 		    (length > 4096 && NumCookies > 50 ? " and " : ""),
 		    (NumCookies > 50 ? "number!\n" : "!\n"));
-	}
 	freeCookie(cur_cookie);
 	cur_cookie = NULL;
     }
@@ -1219,8 +1188,8 @@ PRIVATE void LYProcessSetCookies ARGS6(
     NumCookies = 0;
     cur_cookie = NULL;
     p = ((SetCookie && !(SetCookie2 && *SetCookie2)) ? SetCookie : "");
-    if (TRACE && SetCookie2 && *p) {
-	fprintf(stderr, "LYProcessSetCookies: Using Set-Cookie header.\n");
+    if (SetCookie2 && *p) {
+	CTRACE(tfp, "LYProcessSetCookies: Using Set-Cookie header.\n");
     }
     while (NumCookies <= 50 && *p) {
 	attr_start = attr_end = value_start = value_end = NULL;
@@ -1474,9 +1443,7 @@ PRIVATE void LYProcessSetCookies ARGS6(
 			 url_type == HTTPS_URL_TYPE)) {
 			length += strlen(cur_cookie->commentURL);
 		    } else {
-			if (TRACE)
-			    fprintf(stderr,
-		     "LYProcessSetCookies: Rejecting commentURL value '%s'\n",
+			CTRACE(tfp, "LYProcessSetCookies: Rejecting commentURL value '%s'\n",
 				    cur_cookie->commentURL);
 			FREE(cur_cookie->commentURL);
 		    }
@@ -1505,11 +1472,9 @@ PRIVATE void LYProcessSetCookies ARGS6(
 				   isdigit((unsigned char)*ptr))
 				ptr++;
 			    if (*ptr != '\0') {
-				if (TRACE) {
-				    fprintf(stderr,
+				CTRACE(tfp,
 	       "LYProcessSetCookies: Adding lead dot for domain value '%s'\n",
 					    value);
-				}
 				StrAllocCopy(cur_cookie->domain, ".");
 				StrAllocCat(cur_cookie->domain, value);
 			    } else {
@@ -1637,16 +1602,12 @@ PRIVATE void LYProcessSetCookies ARGS6(
 		    }
 		    HTList_appendObject(CombinedCookies, cur_cookie);
 		} else if (cur_cookie != NULL) {
-		    if (TRACE) {
-			fprintf(stderr,
-			"LYProcessSetCookies: Rejecting Set-Cookie: %s=%s\n",
+		    CTRACE(tfp, "LYProcessSetCookies: Rejecting Set-Cookie: %s=%s\n",
 				(cur_cookie->name ?
 				 cur_cookie->name : "[no name]"),
 				(cur_cookie->value ?
 				 cur_cookie->value : "[no value]"));
-			fprintf(stderr,
-			"                     due to excessive length!\n");
-		    }
+		    CTRACE(tfp, "                     due to excessive length!\n");
 		    freeCookie(cur_cookie);
 		    cur_cookie = NULL;
 		}
@@ -1684,17 +1645,13 @@ PRIVATE void LYProcessSetCookies ARGS6(
 	}
 	HTList_appendObject(CombinedCookies, cur_cookie);
     } else if (cur_cookie != NULL) {
-	if (TRACE) {
-	    fprintf(stderr,
-	  "LYProcessSetCookies: Rejecting Set-Cookie: %s=%s\n",
+	CTRACE(tfp, "LYProcessSetCookies: Rejecting Set-Cookie: %s=%s\n",
 		    (cur_cookie->name ? cur_cookie->name : "[no name]"),
 		    (cur_cookie->value ? cur_cookie->value : "[no value]"));
-	    fprintf(stderr,
-	  "                     due to excessive %s%s%s\n",
+	CTRACE(tfp, "                     due to excessive %s%s%s\n",
 		    (length > 4096 ? "length" : ""),
 		    (length > 4096 && NumCookies > 50 ? " and " : ""),
 		    (NumCookies > 50 ? "number!\n" : "!\n"));
-	}
 	freeCookie(cur_cookie);
 	cur_cookie = NULL;
     }
@@ -1705,24 +1662,19 @@ PRIVATE void LYProcessSetCookies ARGS6(
      */
     cl = CombinedCookies;
     while (NULL != (co = (cookie *)HTList_nextObject(cl))) {
-	if (TRACE) {
-	    fprintf(stderr, "LYProcessSetCookie: attr=value pair: '%s=%s'\n",
+	CTRACE(tfp, "LYProcessSetCookie: attr=value pair: '%s=%s'\n",
 			    (co->name ? co->name : "[no name]"),
 			    (co->value ? co->value : "[no value]"));
-	    if (co->expires > 0) {
-		fprintf(stderr, "                    expires: %ld, %s\n",
-				 (long)co->expires,
-				 ctime(&co->expires));
-	    }
+	if (co->expires > 0) {
+		CTRACE(tfp, "                    expires: %ld, %s\n",
+			    (long)co->expires,
+			    ctime(&co->expires));
 	}
 	if (!strncasecomp(address, "https:", 6) &&
 	    LYForceSSLCookiesSecure == TRUE &&
 	    !(co->flags & COOKIE_FLAG_SECURE)) {
 	    co->flags |= COOKIE_FLAG_SECURE;
-	    if (TRACE) {
-		fprintf(stderr,
-			"                    Forced the 'secure' flag on.\n");
-	    }
+	    CTRACE(tfp, "                    Forced the 'secure' flag on.\n");
 	}
 	store_cookie(co, hostname, path);
     }
@@ -1780,23 +1732,19 @@ PUBLIC void LYSetCookie ARGS3(
 	 */
 	BadHeaders = TRUE;
     }
-    if (TRACE) {
-	fprintf(stderr,
-		"LYSetCookie called with host '%s', path '%s',\n",
+    CTRACE(tfp, "LYSetCookie called with host '%s', path '%s',\n",
 		(hostname ? hostname : ""),
 		(path ? path : ""));
-	if (SetCookie) {
-	    fprintf(stderr, "    and Set-Cookie: '%s'\n",
-			    (SetCookie ? SetCookie : ""));
-	}
-	if (SetCookie2) {
-	    fprintf(stderr, "    and Set-Cookie2: '%s'\n",
-			    (SetCookie2 ? SetCookie2 : ""));
-	}
-	if (LYSetCookies == FALSE || BadHeaders == TRUE) {
-	    fprintf(stderr,
-		    "    Ignoring this Set-Cookie/Set-Cookie2 request.\n");
-	}
+    if (SetCookie) {
+	CTRACE(tfp, "    and Set-Cookie: '%s'\n",
+			 (SetCookie ? SetCookie : ""));
+    }
+    if (SetCookie2) {
+	CTRACE(tfp, "    and Set-Cookie2: '%s'\n",
+			 (SetCookie2 ? SetCookie2 : ""));
+    }
+    if (LYSetCookies == FALSE || BadHeaders == TRUE) {
+	CTRACE(tfp, "    Ignoring this Set-Cookie/Set-Cookie2 request.\n");
     }
 
     /*
@@ -1831,13 +1779,10 @@ PUBLIC char * LYCookie ARGS4(
     HTList *hl = domain_list, *next = NULL;
     domain_entry *de;
 
-    if (TRACE) {
-	fprintf(stderr,
-		"LYCookie: Searching for '%s:%d', '%s'.\n",
+    CTRACE(tfp, "LYCookie: Searching for '%s:%d', '%s'.\n",
 		(hostname ? hostname : "(null)"),
 		port,
 		(path ? path : "(null)"));
-    }
 
     /*
      *	Search the cookie_list elements in the domain_list
diff --git a/src/LYCurses.c b/src/LYCurses.c
index 1fba3f69..7329fa02 100644
--- a/src/LYCurses.c
+++ b/src/LYCurses.c
@@ -283,8 +283,7 @@ PUBLIC void setStyle ARGS4(int,style,int,color,int,cattr,int,mono)
 PUBLIC void setHashStyle ARGS5(int,style,int,color,int,cattr,int,mono,char*,element)
 {
     bucket* ds=&hashStyles[style];
-    if (TRACE)
-	fprintf(stderr, "CSS(SET): <%s> hash=%d, ca=%d, ma=%d\n", element, style, color, mono);
+    CTRACE(tfp, "CSS(SET): <%s> hash=%d, ca=%d, ma=%d\n", element, style, color, mono);
     ds->color=color;
     ds->cattr=cattr;
     ds->mono=mono;
@@ -299,8 +298,7 @@ PUBLIC void setHashStyle ARGS5(int,style,int,color,int,cattr,int,mono,char*,elem
  */
 PRIVATE int LYAttrset ARGS3(WINDOW*,win,int,color,int,mono)
 {
-	if (TRACE)
-		fprintf(stderr, "CSS:LYAttrset (%#x, %#x)\n", color, mono);
+	CTRACE(tfp, "CSS:LYAttrset (%#x, %#x)\n", color, mono);
 	if (lynx_has_color && LYShowColor >= SHOW_COLOR_ON && color > -1)
 	{
 		wattrset(win,color);
@@ -322,12 +320,10 @@ PUBLIC void curses_w_style ARGS4(WINDOW*,win,int,style,int,dir,int,previous)
 
 	if (!ds->name)
 	{
-		if (TRACE)
-		fprintf(stderr, "CSS.CS:Style %d not configured\n",style);
+		CTRACE(tfp, "CSS.CS:Style %d not configured\n",style);
 		return;
 	}
-	if (TRACE)
-		fprintf(stderr, "CSS.CS:<%s%s> (%d)\n",(dir?"":"/"),ds->name,ds->code);
+	CTRACE(tfp, "CSS.CS:<%s%s> (%d)\n",(dir?"":"/"),ds->name,ds->code);
 
 	getyx (win, YP, XP);
 
@@ -350,8 +346,7 @@ PUBLIC void curses_w_style ARGS4(WINDOW*,win,int,style,int,dir,int,previous)
 
 	case STACK_ON: /* remember the current attributes */
 		if (last_ptr > 127) {
-		    if (TRACE)
-			fprintf(stderr,"........... %s (0x%x) %s\r\n",
+		    CTRACE(tfp,"........... %s (0x%x) %s\r\n",
 				"attribute cache FULL, dropping last",
 				last_styles[last_ptr],
 				"in LynxChangStyle(curses_w_style)");
@@ -361,8 +356,7 @@ PUBLIC void curses_w_style ARGS4(WINDOW*,win,int,style,int,dir,int,previous)
 		/* don't cache style changes for active links */
 		if (style != s_alink)
 		{
-			if (TRACE)
-				fprintf(stderr, "CACHED: <%s> @(%d,%d)\n", ds->name, YP, XP);
+			CTRACE(tfp, "CACHED: <%s> @(%d,%d)\n", ds->name, YP, XP);
 			if (win==stdscr) cached_styles[YP][XP]=style;
 			LYAttrset(win, ds->color, ds->mono);
 		}
@@ -376,8 +370,7 @@ PUBLIC void curses_w_style ARGS4(WINDOW*,win,int,style,int,dir,int,previous)
 		/* don't cache style changes for active links */
 		if (style != s_alink)
 		{
-			if (TRACE)
-				fprintf(stderr, "CACHED: <%s> @(%d,%d)\n", ds->name, YP, XP);
+			CTRACE(tfp, "CACHED: <%s> @(%d,%d)\n", ds->name, YP, XP);
 			if (win==stdscr) cached_styles[YP][XP]=style;
 			LYAttrset(win, ds->color, ds->mono);
 		}
@@ -398,15 +391,14 @@ PUBLIC void wcurses_css ARGS3(WINDOW *,win,char*,name,int,dir)
 	while (try_again)
 	{
 		int tmpHash=hash_code(name);
-		if (TRACE)
-			fprintf(stderr, "CSSTRIM:trying to set [%s] style - ", name);
+		CTRACE(tfp, "CSSTRIM:trying to set [%s] style - ", name);
 		if (tmpHash==NOSTYLE) {
 			char *class=strrchr(name, '.');
-			if (TRACE) fprintf(stderr, "undefined, trimming at %p\n", class);
+			CTRACE(tfp, "undefined, trimming at %p\n", class);
 			if (class)	*class='\0';
 			else		try_again=0;
 		} else {
-			if (TRACE) fprintf(stderr, "ok (%d)\n", hash_code(name));
+			CTRACE(tfp, "ok (%d)\n", hash_code(name));
 			curses_w_style(win, hash_code(name), dir, 0);
 			try_again=0;
 		}
@@ -756,7 +748,7 @@ PUBLIC void start_curses NOARGS
 	 *  and one time only!
 	 */
 	if (initscr() == NULL) {  /* start curses */
-	    fprintf(stderr,
+	    fprintf(tfp,
 		"Terminal initialisation failed - unknown terminal type?\n");
 #ifndef NOSIGHUP
 	    (void) signal(SIGHUP, SIG_DFL);
diff --git a/src/LYDownload.c b/src/LYDownload.c
index 6e37de62..1c939d31 100644
--- a/src/LYDownload.c
+++ b/src/LYDownload.c
@@ -271,9 +271,11 @@ check_recall:
 	    strcpy(buffer, command);
 	}
 #else
+#ifndef __EMX__
 	if (*buffer != '/')
 	    cp = getenv("PWD");
 	else
+#endif /* __EMX__*/
 	    cp = NULL;
 	if (cp) {
 	    sprintf(command, "%s/%s", cp, buffer);
@@ -322,6 +324,8 @@ check_recall:
 	/*
 	 *  See if we can write to it.
 	 */
+	CTRACE(tfp, "LYDownload: filename is %s", buffer);
+
 	if ((fp = fopen(buffer, "w")) != NULL) {
 	    fclose(fp);
 	    remove(buffer);
@@ -340,17 +344,14 @@ check_recall:
 	/*
 	 *  Try rename() first. - FM
 	 */
-	if (TRACE)
-	    fprintf(stderr, "command: rename(%s, %s)\n", file, buffer);
+	CTRACE(tfp, "command: rename(%s, %s)\n", file, buffer);
 	if (rename(file, buffer)) {
 	    /*
 	     *	Failed.  Use spawned COPY_COMMAND. - FM
 	     */
-	    if (TRACE)
-		fprintf(stderr, "         FAILED!\n");
+	    CTRACE(tfp, "         FAILED!\n");
 	    sprintf(command, COPY_COMMAND, file, buffer);
-	    if (TRACE)
-		fprintf(stderr, "command: %s\n", command);
+	    CTRACE(tfp, "command: %s\n", command);
 	    fflush(stderr);
 	    fflush(stdout);
 	    stop_curses();
@@ -371,13 +372,16 @@ check_recall:
 	/*
 	 *  Prevent spoofing of the shell.
 	 */
+#ifndef __EMX__
 	cp = quote_pathname(file);
 	cp1 = quote_pathname(buffer);
 	sprintf(command, "%s %s %s", COPY_PATH, cp, cp1);
 	FREE(cp);
 	FREE(cp1);
-	if (TRACE)
-	    fprintf(stderr, "command: %s\n", command);
+#else
+	sprintf(command, "%s %s %s", COPY_PATH, file, buffer);
+#endif __EMX__
+	CTRACE(tfp, "command: %s\n", command);
 	fflush(stderr);
 	fflush(stdout);
 	stop_curses();
@@ -551,8 +555,7 @@ check_recall:
 	    goto failed;
 	}
 
-	if (TRACE)
-	    fprintf(stderr, "command: %s\n", command);
+	CTRACE(tfp, "command: %s\n", command);
 	stop_curses();
 	fflush(stderr);
 	fflush(stdout);
@@ -615,7 +618,7 @@ PUBLIC int LYdownload_options ARGS2(
     if (first) {
 	tempname(tempfile, NEW_FILE);
 	first = FALSE;
-#if defined (VMS) || defined (DOSPATH)
+#if defined (VMS) || defined (DOSPATH) || defined (__EMX__)
     sprintf(download_filename, "file://localhost/%s", tempfile);
 #else
     sprintf(download_filename, "file://localhost%s", tempfile);
diff --git a/src/LYEdit.c b/src/LYEdit.c
index ae8a6eda..55e991fc 100644
--- a/src/LYEdit.c
+++ b/src/LYEdit.c
@@ -61,7 +61,7 @@ PUBLIC int edit_current_file ARGS3(
      *
      * On VMS, only try the path.
      */
-#if !defined (VMS) && !defined (DOSPATH)
+#if !defined (VMS) && !defined (DOSPATH) && !defined (__EMX__)
     colon = strchr(newfile, ':');
     StrAllocCopy(filename, (colon + 1));
     HTUnEscape(filename);
@@ -70,7 +70,7 @@ PUBLIC int edit_current_file ARGS3(
 #endif /* !VMS */
 	filename = HTParse(newfile, "", PARSE_PATH+PARSE_PUNCTUATION);
 	HTUnEscape(filename);
-#ifdef DOSPATH
+#if defined (DOSPATH) || defined (__EMX__)
 	if (strlen(filename)>1) filename++;
 #endif
 #ifdef DOSPATH
@@ -86,7 +86,7 @@ PUBLIC int edit_current_file ARGS3(
 	    FREE(filename);
 	    goto failure;
 	}
-#if !defined (VMS) && !defined (DOSPATH)
+#if !defined (VMS) && !defined (DOSPATH) && !defined (__EMX__)
     }
 #endif /* !VMS */
     fclose(fp);
@@ -156,10 +156,12 @@ PUBLIC int edit_current_file ARGS3(
 #endif /* __DJGPP__ */
 #endif /* VMS */
     if (TRACE) {
-	fprintf(stderr, "LYEdit: %s\n", command);
+	fprintf(tfp, "LYEdit: %s\n", command);
 	sleep(MessageSecs);
     }
+#ifndef __EMX__
     FREE(filename);
+#endif
 
     /*
      *  Invoke the editor. - FM
diff --git a/src/LYExtern.c b/src/LYExtern.c
index 5d4d9db8..9701d576 100644
--- a/src/LYExtern.c
+++ b/src/LYExtern.c
@@ -58,7 +58,7 @@ void run_external ARGS1(char *, c)
 		 *  Prevent spoofing of the shell.
 		 *  Dunno how this needs to be modified for VMS or DOS. - kw
 		 */
-#if defined(VMS) || defined(DOSPATH)
+#if defined(VMS) || defined(DOSPATH) || defined(__EMX__)
 		sprintf(command, externals2->command, c);
 #else /* Unix or DOS/Win: */
 		cp = quote_pathname(c);
diff --git a/src/LYGetFile.c b/src/LYGetFile.c
index 037e4c99..96063576 100644
--- a/src/LYGetFile.c
+++ b/src/LYGetFile.c
@@ -99,9 +99,7 @@ PUBLIC BOOLEAN getfile ARGS1(
 	 *  Reset LYCancelDownload to prevent unwanted delayed effect. - KW
 	 */
 	if (LYCancelDownload) {
-	    if (TRACE)
-		fprintf(stderr,
-			"getfile:    resetting LYCancelDownload to FALSE\n");
+	    CTRACE(tfp, "getfile:    resetting LYCancelDownload to FALSE\n");
 	    LYCancelDownload = FALSE;
 	}
 
@@ -131,9 +129,7 @@ Try_Redirected_URL:
 	 */
 	redirect_post_content = FALSE;
 
-	if (TRACE) {
-	    fprintf(stderr,"getfile: getting %s\n\n",doc->address);
-	}
+	CTRACE(tfp,"getfile: getting %s\n\n",doc->address);
 
 	/*
 	 *  Protect against denial of service attacks
@@ -262,9 +258,7 @@ Try_Redirected_URL:
 		      *(LYlist_temp_url()) &&
 		      !strncmp(WWWDoc.address, LYlist_temp_url(),
 			       strlen(LYlist_temp_url())))) {
-		    if (TRACE)
-			fprintf(stderr,
-				"getfile: dropping post_data!\n");
+		    CTRACE(tfp, "getfile: dropping post_data!\n");
 		    HTAlert("POST not supported for this URL - ignoring POST data!");
 		    FREE(doc->post_data);
 		    FREE(doc->post_content_type);
@@ -621,9 +615,7 @@ Try_Redirected_URL:
 			if ((cp=strchr(doc->address+9, '/')) != NULL &&
 			   0==strncmp(++cp, "hGET%20/", 8)) {
 			    StrAllocCopy(tmp, "http://");
-			    if (TRACE)
-				fprintf(stderr,
-					"getfile: URL '%s'\n",
+			    CTRACE(tfp, "getfile: URL '%s'\n",
 					doc->address);
 			    *cp = '\0';
 			    StrAllocCat(tmp, doc->address+9);
@@ -637,9 +629,8 @@ Try_Redirected_URL:
 			    if (strlen(cp+7) > 1)
 				StrAllocCat(tmp, cp+8);
 			    StrAllocCopy(doc->address, tmp);
-			    if (TRACE)
-				fprintf(stderr, "  changed to '%s'\n",
-						doc->address);
+			    CTRACE(tfp, "  changed to '%s'\n",
+					doc->address);
 			    FREE(tmp);
 			    url_type = HTTP_URL_TYPE;
 			}
@@ -670,9 +661,8 @@ Try_Redirected_URL:
 			    char *cp1 = strstr(doc->address, "/~");
 			    char *cp2;
 
-			    if (TRACE)
-				fprintf(stderr, "getfile: URL '%s'\n",
-						doc->address);
+			    CTRACE(tfp, "getfile: URL '%s'\n",
+					doc->address);
 			    *cp1 = '\0';
 			    cp1 += 2;
 			    StrAllocCopy(temp, doc->address);
@@ -693,9 +683,8 @@ Try_Redirected_URL:
 			    }
 			    StrAllocCopy(doc->address, temp);
 			    FREE(temp);
-			    if (TRACE)
-				fprintf(stderr, "  changed to '%s'\n",
-						doc->address);
+			    CTRACE(tfp, "  changed to '%s'\n",
+					doc->address);
 			    WWWDoc.address = doc->address;
 			}
 			FREE(cp);
@@ -713,7 +702,7 @@ Try_Redirected_URL:
 			    refresh();
 			}
 #endif /* USE_SLANG */
-			fprintf(stderr,"\n");
+			fprintf(tfp,"\n");
 		    }
 		    if ((LYNoRefererHeader == FALSE &&
 			 LYNoRefererForThis == FALSE) &&
@@ -840,11 +829,9 @@ Try_Redirected_URL:
 				 *  be positioned at the top of that document,
 				 *  so there's no harm done. - FM
 				 */
-				if (TRACE) {
-				    fprintf(stderr,
+				CTRACE(tfp,
 			"getfile: Adding fragment '%s' to redirection URL.\n",
 				    pound);
-				}
 				StrAllocCat(use_this_url_instead, pound);
 			    }
 			    if (TRACE && LYTraceLogFP == NULL)
@@ -852,8 +839,7 @@ Try_Redirected_URL:
 			    _user_message(WWW_USING_MESSAGE,
 					  use_this_url_instead);
 			    sleep(InfoSecs);
-			    if (TRACE)
-				fprintf(stderr, "\n");
+			    CTRACE(tfp, "\n");
 			    StrAllocCopy(doc->address,
 					use_this_url_instead);
 			    FREE(use_this_url_instead);
@@ -989,8 +975,7 @@ Try_Redirected_URL:
 	      if (TRACE && LYTraceLogFP == NULL)
 		  sleep(MessageSecs);
 	      _user_message(WWW_BAD_ADDR_MESSAGE, doc->address);
-	      if (TRACE)
-		  fprintf(stderr,"\n");
+	      CTRACE(tfp,"\n");
 	      sleep(MessageSecs);
 	      return(NULLFILE);
 	  }
@@ -1358,11 +1343,10 @@ PRIVATE int fix_http_urls ARGS1(
 	/*
 	 *  If we get to here, trim the trailing slash. - FM
 	 */
-	if (TRACE)
-	    fprintf(stderr, "fix_http_urls: URL '%s'\n", doc->address);
+	CTRACE(tfp, "fix_http_urls: URL '%s'\n", doc->address);
 	doc->address[strlen(doc->address)-1] = '\0';
 	if (TRACE) {
-	    fprintf(stderr, "        changed to '%s'\n", doc->address);
+	    fprintf(tfp, "        changed to '%s'\n", doc->address);
 	    if (!LYTraceLogFP)
 		sleep(MessageSecs);
 	}
@@ -1376,11 +1360,10 @@ PRIVATE int fix_http_urls ARGS1(
 	    return(0);
 	}
     }
-    if (TRACE)
-	fprintf(stderr, "fix_http_urls: URL '%s'\n", doc->address);
+    CTRACE(tfp, "fix_http_urls: URL '%s'\n", doc->address);
     StrAllocCat(doc->address, "/");
     if (TRACE) {
-	fprintf(stderr, "        changed to '%s'\n",doc->address);
+	fprintf(tfp, "        changed to '%s'\n",doc->address);
 	if (!LYTraceLogFP)
 	    sleep(MessageSecs);
     }
diff --git a/src/LYHistory.c b/src/LYHistory.c
index 433114b4..5bf9294f 100644
--- a/src/LYHistory.c
+++ b/src/LYHistory.c
@@ -22,12 +22,12 @@
 
 #include <LYexit.h>
 #include <LYLeaks.h>
- 
+
 #define FREE(x) if (x) {free(x); x = NULL;}
 
-PUBLIC  HTList * Visited_Links = NULL;  /* List of safe popped docs. */
+PUBLIC HTList * Visited_Links = NULL;	/* List of safe popped docs. */
 
-/* 
+/*
  *  Utility for freeing the list of visited links. - FM
  */
 PRIVATE void Visited_Links_free NOARGS
@@ -36,7 +36,7 @@ PRIVATE void Visited_Links_free NOARGS
     HTList *cur = Visited_Links;
 
     if (!cur)
-        return;
+	return;
 
     while (NULL != (vl = (VisitedLink *)HTList_nextObject(cur))) {
 	FREE(vl->address);
@@ -48,7 +48,7 @@ PRIVATE void Visited_Links_free NOARGS
     return;
 }
 
-/* 
+/*
  *  Utility for listing visited links, making any repeated
  *  links the most current in the list. - FM
  */
@@ -60,11 +60,11 @@ PUBLIC void LYAddVisitedLink ARGS1(
     HTList *cur;
 
     if (!(doc->address && *doc->address))
-        return;
+	return;
 
     /*
-     *  Exclude POST or HEAD replies, and bookmark, menu
-     *  or list files. - FM
+     *	Exclude POST or HEAD replies, and bookmark, menu
+     *	or list files. - FM
      */
     if (doc->post_data || doc->isHEAD || doc->bookmark ||
 	!strcmp((doc->title ? doc->title : ""), HISTORY_PAGE_TITLE) ||
@@ -85,12 +85,12 @@ PUBLIC void LYAddVisitedLink ARGS1(
     }
 
     if ((new = (VisitedLink *)calloc(1, sizeof(*new))) == NULL)
-    	outofmem(__FILE__, "HTAddVisitedLink");
+	outofmem(__FILE__, "HTAddVisitedLink");
     StrAllocCopy(new->address, doc->address);
     StrAllocCopy(new->title, (doc->title ? doc->title : "(no title)"));
 
     if (!Visited_Links) {
-        Visited_Links = HTList_new();
+	Visited_Links = HTList_new();
 	atexit(Visited_Links_free);
 	HTList_addObject(Visited_Links, new);
 	return;
@@ -101,7 +101,7 @@ PUBLIC void LYAddVisitedLink ARGS1(
 	if (!strcmp((old->address ? old->address : ""),
 		    (new->address ? new->address : "")) &&
 	    !strcmp((old->title ? new->title : ""),
-	    	    (new->title ? new->title : ""))) {
+		    (new->title ? new->title : ""))) {
 	    FREE(old->address);
 	    FREE(old->title);
 	    HTList_removeObject(Visited_Links, old);
@@ -122,14 +122,14 @@ PUBLIC void LYpush ARGS2(
 	BOOLEAN,	force_push)
 {
     /*
-     *  Don't push NULL file names.
+     *	Don't push NULL file names.
      */
     if (*doc->address == '\0')
 	return;
 
     /*
-     *  Check whether this is a document we
-     *  don't push unless forced. - FM
+     *	Check whether this is a document we
+     *	don't push unless forced. - FM
      */
     if (!force_push) {
 	/*
@@ -158,17 +158,17 @@ PUBLIC void LYpush ARGS2(
     }
 
     /*
-     *  If file is identical to one before it, don't push it.
+     *	If file is identical to one before it, don't push it.
      */
     if (nhist> 1 &&
-        STREQ(history[nhist-1].address, doc->address) &&
-        !strcmp(history[nhist-1].post_data ?
+	STREQ(history[nhist-1].address, doc->address) &&
+	!strcmp(history[nhist-1].post_data ?
 		history[nhist-1].post_data : "",
-                doc->post_data ?
+		doc->post_data ?
 		doc->post_data : "") &&
-        !strcmp(history[nhist-1].bookmark ?
+	!strcmp(history[nhist-1].bookmark ?
 		history[nhist-1].bookmark : "",
-                doc->bookmark ?
+		doc->bookmark ?
 		doc->bookmark : "") &&
 	history[nhist-1].isHEAD == doc->isHEAD) {
 	if (history[nhist-1].internal_link == doc->internal_link) {
@@ -176,7 +176,7 @@ PUBLIC void LYpush ARGS2(
 	       - kw */
 	    history[nhist-1].link = doc->link;
 	    history[nhist-1].page = doc->line;
- 	    return;
+	    return;
 	}
     }
 
@@ -187,29 +187,29 @@ PUBLIC void LYpush ARGS2(
 **  also to the user.  Moreover, the way it was done seems to cause
 **  a memory leak. - KW
 */  /*
-     *  If file is identical to one two before it, don't push it.
+     *	If file is identical to one two before it, don't push it.
      */
     if (nhist > 2 &&
-        STREQ(history[nhist-2].address, doc->address) &&
-        !strcmp(history[nhist-2].post_data ?
+	STREQ(history[nhist-2].address, doc->address) &&
+	!strcmp(history[nhist-2].post_data ?
 		history[nhist-2].post_data : "",
-                doc->post_data ?
+		doc->post_data ?
 		doc->post_data : "") &&
-        !strcmp(history[nhist-2].bookmark ?
+	!strcmp(history[nhist-2].bookmark ?
 		history[nhist-2].bookmark : "",
-                doc->bookmark ?
+		doc->bookmark ?
 		doc->bookmark : "") &&
 	history[nhist-2].isHEAD == doc->isHEAD) {
 	/*
 	 *  Pop one off the stack.
 	 */
 	nhist--;
-        return;
+	return;
     }
 #endif /* NOTDEFINED */
 
     /*
-     *  OK, push it if we have stack space.
+     *	OK, push it if we have stack space.
      */
     if (nhist < MAXHIST)  {
 	history[nhist].link = doc->link;
@@ -230,7 +230,7 @@ PUBLIC void LYpush ARGS2(
 	history[nhist].internal_link = FALSE; /* by default */
 	history[nhist].intern_seq_start = -1; /* by default */
 	if (doc->internal_link) {
- 	    /* Now some tricky stuff: if the caller thinks that the doc
+	    /* Now some tricky stuff: if the caller thinks that the doc
 	       to push was the result of following an internal
 	       (fragment) link, we check whether we believe it.
 	       It is only accepted as valid if the immediately preceding
@@ -303,37 +303,25 @@ PUBLIC void LYpush ARGS2(
 			history[nhist].intern_seq_start =
 			    history[nhist-1].intern_seq_start >= 0 ?
 			    history[nhist-1].intern_seq_start : nhist-1;
-			if (TRACE) {
-			    fprintf(stderr,
-				"\nLYpush: pushed as internal link, OK\n");
-			}
+			CTRACE(tfp, "\nLYpush: pushed as internal link, OK\n");
 		    }
 		}
 	    }
 	    if (!history[nhist].internal_link) {
-		if (TRACE) {
-		    fprintf(stderr,
-			    "\nLYpush: push as internal link requested, %s\n",
+		CTRACE(tfp, "\nLYpush: push as internal link requested, %s\n",
 			    "but didn't check out!");
-		}
 	    }
 	}
 	nhist++;
-   	if (TRACE) {
-    	    fprintf(stderr,
-		    "\nLYpush: address:%s\n        title:%s\n",
+	CTRACE(tfp, "\nLYpush: address:%s\n        title:%s\n",
 		    doc->address, doc->title);
-	}
     } else {
-        if (LYCursesON) {
+	if (LYCursesON) {
 	    _statusline(MAXHIST_REACHED);
 	    sleep(AlertSecs);
-	} 
-        if (TRACE) {
-    	    fprintf(stderr,
-     "\nLYpush: MAXHIST reached for:\n        address:%s\n        title:%s\n",
-		    doc->address, doc->title);
 	}
+	CTRACE(tfp, "\nLYpush: MAXHIST reached for:\n        address:%s\n        title:%s\n",
+		    doc->address, doc->title);
     }
 }
 
@@ -350,7 +338,7 @@ PUBLIC void LYpop ARGS1(
 	FREE(doc->title);
 	doc->title = history[nhist].title;	 /* will be freed later */
 	FREE(doc->address);
-	doc->address = history[nhist].address;   /* will be freed later */
+	doc->address = history[nhist].address;	 /* will be freed later */
 	FREE(doc->post_data);
 	doc->post_data = history[nhist].post_data;
 	FREE(doc->post_content_type);
@@ -360,11 +348,8 @@ PUBLIC void LYpop ARGS1(
 	doc->isHEAD = history[nhist].isHEAD;
 	doc->safe = history[nhist].safe;
 	doc->internal_link = history[nhist].internal_link;
-        if (TRACE) {
-	    fprintf(stderr,
-	    	    "LYpop: address:%s\n     title:%s\n",
+	CTRACE(tfp, "LYpop: address:%s\n     title:%s\n",
 		    doc->address, doc->title);
-	}
     }
 }
 
@@ -409,7 +394,7 @@ PUBLIC int showhistory ARGS1(
 	/*
 	 *  Make the file a URL now.
 	 */
-#if defined (VMS) || defined (DOSPATH)
+#if defined (VMS) || defined (DOSPATH) || defined (__EMX__)
 	sprintf(hist_filename,"file://localhost/%s", tempfile);
 #else
 	sprintf(hist_filename,"file://localhost%s", tempfile);
@@ -450,7 +435,7 @@ PUBLIC int showhistory ARGS1(
 	}
 	fprintf(fp0,
 		"%s<em>%d</em>. <tab id=t%d><a href=\"LYNXHIST:%d\">%s</a>\n",
-		(x > 99 ? "" : x < 10 ? "  " : " "),  
+		(x > 99 ? "" : x < 10 ? "  " : " "),
 		x, x, x, Title);
 	if (history[x].address != NULL) {
 	    StrAllocCopy(Title, history[x].address);
@@ -474,7 +459,7 @@ PUBLIC int showhistory ARGS1(
     return(0);
 }
 
-/* 
+/*
  *  This function makes the history page seem like any other type of
  *  file since more info is needed than can be provided by the normal
  *  link structure.  We saved out the history number to a special URL.
@@ -490,11 +475,11 @@ PUBLIC BOOLEAN historytarget ARGS1(
     BOOLEAN treat_as_intern = FALSE;
 
     if ((!newdoc || !newdoc->address) ||
-        strlen(newdoc->address) < 10 || !isdigit(*(newdoc->address+9)))
+	strlen(newdoc->address) < 10 || !isdigit(*(newdoc->address+9)))
 	return(FALSE);
 
     if ((number = atoi(newdoc->address+9)) > nhist || number < 0)
-        return(FALSE);
+	return(FALSE);
 
     LYpop_num(number, newdoc);
     if (((newdoc->internal_link &&
@@ -513,20 +498,20 @@ PUBLIC BOOLEAN historytarget ARGS1(
 	newdoc->internal_link = FALSE;
     }
     /*
-     *  If we have POST content, and have LYresubmit_posts set
-     *  or have no_cache set or do not still have the text cached,
-     *  ask the user whether to resubmit the form. - FM
+     *	If we have POST content, and have LYresubmit_posts set
+     *	or have no_cache set or do not still have the text cached,
+     *	ask the user whether to resubmit the form. - FM
      */
     if (newdoc->post_data != NULL) {
 	WWWDoc.address = newdoc->address;
-        WWWDoc.post_data = newdoc->post_data;
-        WWWDoc.post_content_type = newdoc->post_content_type;
-        WWWDoc.bookmark = newdoc->bookmark;
+	WWWDoc.post_data = newdoc->post_data;
+	WWWDoc.post_content_type = newdoc->post_content_type;
+	WWWDoc.bookmark = newdoc->bookmark;
 	WWWDoc.isHEAD = newdoc->isHEAD;
 	WWWDoc.safe = newdoc->safe;
 	tmpanchor = HTAnchor_parent(HTAnchor_findAddress(&WWWDoc));
 	text = (HText *)HTAnchor_document(tmpanchor);
-        if (((((LYresubmit_posts == TRUE) ||
+	if (((((LYresubmit_posts == TRUE) ||
 	       (LYforce_no_cache == TRUE &&
 		LYoverride_no_cache == FALSE)) &&
 	      !(treat_as_intern && !reloading)) ||
@@ -568,14 +553,14 @@ PUBLIC int LYShowVisitedLinks ARGS1(
     HTList *cur = Visited_Links;
 
     if (!cur)
-        return(-1);
+	return(-1);
 
     if (first) {
 	tempname(tempfile, NEW_FILE);
 	/*
 	 *  Make the file a URL now.
 	 */
-#if defined (VMS) || defined (DOSPATH)
+#if defined (VMS) || defined (DOSPATH) || defined (__EMX__)
 	sprintf(vl_filename,"file://localhost/%s", tempfile);
 #else
 	sprintf(vl_filename,"file://localhost%s", tempfile);
@@ -602,7 +587,7 @@ PUBLIC int LYShowVisitedLinks ARGS1(
 		 VISITED_LINKS_TITLE);
     fprintf(fp0, "<h1>You have reached the Visited Links Page</h1>\n");
     fprintf(fp0, "<h2>%s Version %s</h2>\n<pre>", LYNX_NAME, LYNX_VERSION);
-    fprintf(fp0, 
+    fprintf(fp0,
   "<em>You visited (POSTs, bookmark, menu and list files excluded):</em>\n");
     x = HTList_count(Visited_Links);
     while (NULL != (vl = (VisitedLink *)HTList_nextObject(cur))) {
diff --git a/src/LYList.c b/src/LYList.c
index 5622f4ba..d0b28169 100644
--- a/src/LYList.c
+++ b/src/LYList.c
@@ -78,7 +78,7 @@ PUBLIC int showlist ARGS2(
 	/*
 	 *  Make the file a URL now.
 	 */
-#if defined (VMS) || defined (DOSPATH)
+#if defined (VMS) || defined (DOSPATH)	|| defined (__EMX__)
 	sprintf(list_filename, "file://localhost/%s", tempfile);
 #else
 	sprintf(list_filename, "file://localhost%s", tempfile);
diff --git a/src/LYLocal.c b/src/LYLocal.c
index 320ca0cd..a88bc3e0 100644
--- a/src/LYLocal.c
+++ b/src/LYLocal.c
@@ -1052,15 +1052,25 @@ PUBLIC BOOLEAN local_remove ARGS1(
     cp = links[doc->link].lname;
     if (is_url(cp) == FILE_URL_TYPE) {
 	tp = cp;
+#ifndef __EMX__
 	if (!strncmp(tp, "file://localhost", 16)) {
 	    tp += 16;
 	} else if (!strncmp(tp, "file:", 5)) {
 	    tp += 5;
 	}
+#else
+	if (!strncmp(tp, "file://localhost/", 17)) {
+	    tp += 17;
+	} else if (!strncmp(tp, "file:/", 6)) {
+	    tp +=6;
+	}
+#endif /* !EMX */
+
 	strcpy(testpath, tp);
 	HTUnEscape(testpath);
 	if ((i = strlen(testpath)) && testpath[i - 1] == '/')
 	    testpath[(i - 1)] = '\0';
+
 	if (remove_single(testpath)) {
 	    if (doc->link == (nlinks - 1))
 		--doc->link;
@@ -1277,8 +1287,7 @@ form to permit %s %s.\n</Ol>\n</Form>\n",
 		HTAlert(INVALID_PERMIT_URL);
 	    else
 		fprintf(stderr, "%s\n", INVALID_PERMIT_URL);
-	    if (TRACE)
-		fprintf(stderr, "permit_location: called for <%s>.\n",
+	    CTRACE(tfp, "permit_location: called for <%s>.\n",
 			(destpath ?
 			 destpath : "NULL URL pointer"));
 	    return 0;
@@ -1304,8 +1313,7 @@ form to permit %s %s.\n</Ol>\n</Form>\n",
 		HTAlert(INVALID_PERMIT_URL);
 	    else
 		fprintf(stderr, "%s\n", INVALID_PERMIT_URL);
-	    if (TRACE)
-		fprintf(stderr, "permit_location: called for file '%s'.\n",
+	    CTRACE(tfp, "permit_location: called for file '%s'.\n",
 			destpath);
 	    return 0;
 	}
@@ -1461,8 +1469,7 @@ PUBLIC int local_dired ARGS1(
     char buffer[512];
 
     line_url = doc->address;
-    if (TRACE)
-	fprintf(stderr, "local_dired: called for <%s>.\n",
+    CTRACE(tfp, "local_dired: called for <%s>.\n",
 		(line_url ?
 		 line_url : "NULL URL pointer"));
     HTUnEscapeSome(line_url, "/");	/* don't mess too much with *doc */
@@ -1896,7 +1903,7 @@ PUBLIC int dired_options ARGS2(
 PRIVATE char *filename ARGS3(
 	char *, 	prompt,
 	char *, 	buf,
-	size_t,		bufsize)
+	size_t, 	bufsize)
 {
     char *cp;
 
@@ -2218,9 +2225,7 @@ PRIVATE int LYExecv ARGS3(
 	char *, 	msg)
 {
 #if defined(VMS) || defined(_WINDOWS)
-    if (TRACE) {
-	fprintf(stderr, "LYExecv:  Called inappropriately!\n");
-    }
+    CTRACE(tfp, "LYExecv:  Called inappropriately!\n");
     return(0);
 #else
     int rc;
diff --git a/src/LYMail.c b/src/LYMail.c
index 1b49c2aa..d355c30a 100644
--- a/src/LYMail.c
+++ b/src/LYMail.c
@@ -575,8 +575,7 @@ PUBLIC void mailmsg ARGS4(
     char hdrfile[256];
     FILE *hfd;
 
-    if(TRACE)
-	fprintf(stderr,"mailmsg(%d, \"%s\", \"%s\", \"%s\")\n",cur,
+    CTRACE(tfp, "mailmsg(%d, \"%s\", \"%s\", \"%s\")\n",cur,
 	cur, owner_address?owner_address:"<nil>",
 	filename?filename:"<nil>",
 	linkname?linkname:"<nil>");
@@ -657,11 +656,8 @@ PUBLIC void mailmsg ARGS4(
 	address[(strlen(address) - 1)] = '\0';
     if (*address == '\0') {
 	FREE(address);
-	if (TRACE) {
-	    fprintf(stderr,
-		    "mailmsg: No address in '%s'.\n",
+	CTRACE(tfp, "mailmsg: No address in '%s'.\n",
 		    owner_address);
-	}
 	return;
     }
 
@@ -669,11 +665,8 @@ PUBLIC void mailmsg ARGS4(
     sprintf(cmd, "%s %s", system_mail, system_mail_flags);
     if ((fd = popen(cmd, "w")) == NULL) {
 	FREE(address);
-	if (TRACE) {
-	    fprintf(stderr,
-		    "mailmsg: '%s' failed.\n",
+	CTRACE(tfp, "mailmsg: '%s' failed.\n",
 		    cmd);
-	}
 	return;
     }
 
@@ -694,11 +687,8 @@ PUBLIC void mailmsg ARGS4(
 	strcat(my_tmpfile, ".txt");
     }
     if ((fd = LYNewTxtFile(my_tmpfile)) == NULL) {
-	if (TRACE) {
-	    fprintf(stderr,
-		    "mailmsg: Could not fopen '%s'.\n",
+	CTRACE(tfp, "mailmsg: Could not fopen '%s'.\n",
 		    my_tmpfile);
-	}
 	FREE(address);
 	return;
     }
@@ -711,11 +701,8 @@ PUBLIC void mailmsg ARGS4(
 	    strcat(hdrfile, ".txt");
 	}
 	if ((hfd = LYNewTxtFile(hdrfile)) == NULL) {
-	    if (TRACE) {
-		fprintf(stderr,
-			"mailmsg: Could not fopen '%s'.\n",
+	    CTRACE(tfp, "mailmsg: Could not fopen '%s'.\n",
 			hdrfile);
-	    }
 	    FREE(address);
 	    return;
 	}
@@ -876,8 +863,7 @@ PUBLIC void reply_by_mail ARGS3(
     char hdrfile[256];
     FILE *hfd;
 
-    if(TRACE)
-	fprintf(stderr,"reply_by_mail(\"%s\", \"%s\", \"%s\")\n",
+    CTRACE(tfp, "reply_by_mail(\"%s\", \"%s\", \"%s\")\n",
 	mail_address?mail_address:"<nil>",
 	filename?filename:"<nil>",
 	title?tilde:"<nil>");
@@ -1526,8 +1512,7 @@ PUBLIC void reply_by_mail ARGS3(
     StrAllocCat(header, buf);
 #endif /* !VMS */
 
-    if(TRACE)
-	fprintf(stderr,"**header==\n%s",header);
+    CTRACE(tfp,"**header==\n%s",header);
     if (!no_editor && editor && *editor != '\0') {
 	/*
 	 *  Use an external editor for the message.
@@ -1867,8 +1852,7 @@ PUBLIC void reply_by_mail ARGS3(
 #endif
     fclose(fd); /* Close the tmpfile. */
 
-    if (TRACE)
-	printf("%s\n", cmd);
+    CTRACE(tfp, "%s\n", cmd);
 #endif /* VMS */
 
     /*
diff --git a/src/LYMain.c b/src/LYMain.c
index 9f39c5db..f1af2f06 100644
--- a/src/LYMain.c
+++ b/src/LYMain.c
@@ -164,7 +164,7 @@ PUBLIC int LYShowColor = SHOW_COLOR_UNKNOWN; /* to show or not to show */
 PUBLIC int LYChosenShowColor = SHOW_COLOR_UNKNOWN; /* whether to show and save */
 PUBLIC int LYrcShowColor = SHOW_COLOR_UNKNOWN;	/* ... as last read or written */
 PUBLIC BOOLEAN LYShowCursor = SHOW_CURSOR; /* to show or not to show */
-PUBLIC BOOLEAN verbose_img = VERBOSE_IMAGES;  /* show filenames or not */ 
+PUBLIC BOOLEAN verbose_img = VERBOSE_IMAGES;  /* show filenames or not */
 PUBLIC BOOLEAN LYUseDefShoCur = TRUE;	/* Command line -show_cursor toggle */
 PUBLIC BOOLEAN LYforce_no_cache = FALSE;
 PUBLIC BOOLEAN LYoverride_no_cache = FALSE;/*override no-cache b/c history etc*/
@@ -387,7 +387,7 @@ PRIVATE BOOLEAN number_links = FALSE;
 PRIVATE BOOLEAN LYPrependBase = FALSE;
 PRIVATE HTList *LYStdinArgs = NULL;
 
-PRIVATE void parse_arg PARAMS((char **arg, int *i, int argc));
+PRIVATE void parse_arg PARAMS((char **arg, int *i));
 #ifndef VMS
 PUBLIC BOOLEAN LYNoCore = NO_FORCED_CORE_DUMP;
 PRIVATE void FatalProblem PARAMS((int sig));
@@ -589,7 +589,7 @@ else {init_ctrl_break[0] = 1;}
      */
     for (i = 1; i < argc; i++) {
 	if (strncmp(argv[i], "-help", 5) == 0) {
-	    parse_arg(&argv[i], &i, argc);
+	    parse_arg(&argv[i], &i);
 	}
     }
 
@@ -684,7 +684,7 @@ else {init_ctrl_break[0] = 1;}
     if ((cp = getenv("LYNX_TEMP_SPACE")) != NULL)
 	StrAllocCopy(lynx_temp_space, cp);
     else
-#ifdef DOSPATH
+#if defined (DOSPATH) || defined (__EMX__)
     if ((cp = getenv("TEMP")) != NULL)
 	StrAllocCopy(lynx_temp_space, cp);
     else if ((cp = getenv("TMP")) != NULL)
@@ -842,8 +842,7 @@ else {init_ctrl_break[0] = 1;}
 		StrAllocCopy(lynx_lss_file, argv[i+1]);
 		i++;
 	    }
-	    if (TRACE)
-		fprintf(stderr, "LYMain found -lss flag, lss file is %s\n",
+	    CTRACE(tfp, "LYMain found -lss flag, lss file is %s\n",
 		    lynx_lss_file ? lynx_lss_file : "<NONE>");
 #endif
 	}
@@ -926,8 +925,7 @@ else {init_ctrl_break[0] = 1;}
 		    if (*cp)
 			StrAllocCopy(lynx_cfg_file, cp);
 		}
-		if (TRACE)
-		    fprintf(stderr, "LYMain found -lss flag, lss file is %s\n",
+		CTRACE(tfp, "LYMain found -lss flag, lss file is %s\n",
 			lynx_lss_file ? lynx_lss_file : "<NONE>");
 #endif
 	    } else if (strcmp(buf, "-get_data") == 0) {
@@ -1092,15 +1090,15 @@ else {init_ctrl_break[0] = 1;}
 	fflush(stdout);
 	fflush(stderr);
 	*stderr = *LYTraceLogFP;
-	fprintf(stderr, "\t\t%s\n\n", LYNX_TRACELOG_TITLE);
+	fprintf(tfp, "\t\t%s\n\n", LYNX_TRACELOG_TITLE);
     }
 
     /*
      *	If TRACE is on, indicate whether the
      *	anonymous restrictions are set. - FM
      */
-    if (TRACE && anon_restrictions_set) {
-	fprintf(stderr, "LYMain: Anonymous restrictions set.\n");
+    if (anon_restrictions_set) {
+	CTRACE(tfp, "LYMain: Anonymous restrictions set.\n");
     }
 
     /*
@@ -1116,8 +1114,7 @@ else {init_ctrl_break[0] = 1;}
 	} else {
 	    sprintf(temp, "JUMPFILE:%s", jumpfile);
 	    if (!LYJumpInit(temp)) {
-		if (TRACE)
-		    fprintf(stderr, "Failed to register %s\n", temp);
+		CTRACE(tfp, "Failed to register %s\n", temp);
 	    }
 	    FREE(temp);
 	}
@@ -1252,12 +1249,9 @@ else {init_ctrl_break[0] = 1;}
 	StrAllocCopy(LynxSigFile, filename);
 	LYAddPathToHome(filename, sizeof(filename), LynxSigFile);
 	StrAllocCopy(LynxSigFile, filename);
-	if (TRACE)
-	    fprintf(stderr, "LYNX_SIG_FILE set to '%s'\n", LynxSigFile);
+	CTRACE(tfp, "LYNX_SIG_FILE set to '%s'\n", LynxSigFile);
     } else {
-	if (TRACE)
-	    fprintf(stderr, "LYNX_SIG_FILE '%s' is bad. Ignoring.\n",
-			    LYNX_SIG_FILE);
+	CTRACE(tfp, "LYNX_SIG_FILE '%s' is bad. Ignoring.\n", LYNX_SIG_FILE);
     }
 
     /*
@@ -1372,7 +1366,7 @@ else {init_ctrl_break[0] = 1;}
      *	Process any command line arguments not already handled. - FM
      */
     for (i = 1; i < argc; i++) {
-	parse_arg(&argv[i], &i, argc);
+	parse_arg(&argv[i], &i);
     }
 
     /*
@@ -1385,7 +1379,7 @@ else {init_ctrl_break[0] = 1;}
 
 	my_args[1] = NULL;
 	while (NULL != (my_args[0] = (char *)HTList_nextObject(cur))) {
-	    parse_arg(my_args, NULL, -1);
+	    parse_arg(my_args, (int *)0);
 	}
 	LYStdinArgs_free();
     }
@@ -1566,16 +1560,14 @@ else {init_ctrl_break[0] = 1;}
 	ftp_ok = !no_inside_ftp && !no_outside_ftp && ftp_ok;
 	rlogin_ok = !no_inside_rlogin && !no_outside_rlogin && rlogin_ok;
 #else
-	if (TRACE)
-	   fprintf(stderr,"LYMain.c: User in Local domain\n");
+	CTRACE(tfp,"LYMain.c: User in Local domain\n");
 	telnet_ok = !no_inside_telnet && telnet_ok;
 	news_ok = !no_inside_news && news_ok;
 	ftp_ok = !no_inside_ftp && ftp_ok;
 	rlogin_ok = !no_inside_rlogin && rlogin_ok;
 #endif /* !HAVE_UTMP || VMS */
     } else {
-	if (TRACE)
-	   fprintf(stderr,"LYMain.c: User in REMOTE domain\n");
+	CTRACE(tfp,"LYMain.c: User in REMOTE domain\n");
 	telnet_ok = !no_outside_telnet && telnet_ok;
 	news_ok = !no_outside_news && news_ok;
 	ftp_ok = !no_outside_ftp && ftp_ok;
@@ -1736,6 +1728,7 @@ else {init_ctrl_break[0] = 1;}
     }
 
     exit(status);
+    return(status);	/* though redundant, for compiler-warnings */
 }
 
 /*
@@ -1781,10 +1774,9 @@ PRIVATE char * scan3D ARGS2(
     return argv[1];
 }
 
-PRIVATE void parse_arg ARGS3(
+PRIVATE void parse_arg ARGS2(
 	char **,	argv,
-	int *,		i,
-	int,		argc)
+	int *,		i)
 {
     static int ignored;
     char *cp;
@@ -1885,8 +1877,8 @@ PRIVATE void parse_arg ARGS3(
 	if (auth_info != NULL)	{
 	    if ((cp = strchr(auth_info, ':')) != NULL) {	/* Pw */
 		*cp++ = '\0';	/* Terminate ID */
-		HTUnEscape(cp); 
-		StrAllocCopy(authentication_info[1], cp); 
+		HTUnEscape(cp);
+		StrAllocCopy(authentication_info[1], cp);
 	    }
 	    if (*auth_info) {					/* Id */
 		HTUnEscape(auth_info);
@@ -2355,8 +2347,8 @@ PRIVATE void parse_arg ARGS3(
 	if (pauth_info != NULL)  {
 	    if ((cp = strchr(pauth_info, ':')) != NULL) {	/* Pw */
 		*cp++ = '\0';	/* Terminate ID */
-		HTUnEscape(cp); 
-		StrAllocCopy(proxyauth_info[1], cp); 
+		HTUnEscape(cp);
+		StrAllocCopy(proxyauth_info[1], cp);
 	    }
 	    if (*pauth_info) {					/* Id */
 		HTUnEscape(pauth_info);
@@ -2572,7 +2564,7 @@ PRIVATE void parse_arg ARGS3(
 
     case 't':
     if (strncmp(argv[0], "-tagsoup", 8) == 0) {
-        HTSwitchDTD(New_DTD = NO);
+	HTSwitchDTD(New_DTD = NO);
 
     } else if (strncmp(argv[0], "-telnet", 7) == 0) {
 	telnet_ok = FALSE;
diff --git a/src/LYMainLoop.c b/src/LYMainLoop.c
index fa1ba6a1..8f9c976e 100644
--- a/src/LYMainLoop.c
+++ b/src/LYMainLoop.c
@@ -240,8 +240,7 @@ initialize:
 	refresh();
     }
 #endif /* USE_SLANG */
-    if (TRACE)
-	fprintf(stderr,"Entering mainloop, startfile=%s\n",startfile);
+    CTRACE(tfp,"Entering mainloop, startfile=%s\n",startfile);
 
     if (form_post_data) {
 	StrAllocCopy(newdoc.post_data, form_post_data);
@@ -278,8 +277,7 @@ initialize:
 		FREE(newdoc.post_content_type);
 		newdoc.isHEAD = FALSE;
 		newdoc.safe = FALSE;
-		if (TRACE)
-		    fprintf(stderr, "Using bookmarks=%s\n", newdoc.address);
+		CTRACE(tfp, "Using bookmarks=%s\n", newdoc.address);
 	    } else {
 		_statusline(BOOKMARKS_NOT_OPEN);
 		sleep(MessageSecs);
@@ -432,9 +430,7 @@ try_again:
 		    WWWDoc.safe = newdoc.safe;
 		    tmpanchor = HTAnchor_parent(HTAnchor_findAddress(&WWWDoc));
 		    if ((HText *)HTAnchor_document(tmpanchor) == NULL) {
-			if (TRACE)
-			    fprintf(stderr,
-				    "\nTurning off TRACE for fetch of log.\n");
+			CTRACE(tfp, "\nTurning off TRACE for fetch of log.\n");
 			fflush(stdout);
 			fflush(stderr);
 			fclose(LYTraceLogFP);
@@ -530,7 +526,7 @@ try_again:
 		    if (trace_mode_flag == TRUE) {
 			WWW_TraceFlag = TRUE;
 			trace_mode_flag = FALSE;
-			fprintf(stderr, "Turning TRACE back on.\n\n");
+			fprintf(tfp, "Turning TRACE back on.\n\n");
 		    }
 		    if (error_logging &&
 			first_file && owner_address && !LYCancelledFetch) {
@@ -621,7 +617,7 @@ try_again:
 		    if (trace_mode_flag == TRUE) {
 			WWW_TraceFlag = TRUE;
 			trace_mode_flag = FALSE;
-			fprintf(stderr, "Turning TRACE back on.\n\n");
+			fprintf(tfp, "Turning TRACE back on.\n\n");
 		    }
 		    FREE(newdoc.address); /* to pop last doc */
 		    FREE(newdoc.bookmark);
@@ -771,7 +767,7 @@ try_again:
 		    if (trace_mode_flag == TRUE) {
 			WWW_TraceFlag = TRUE;
 			trace_mode_flag = FALSE;
-			fprintf(stderr, "Turning TRACE back on.\n\n");
+			fprintf(tfp, "Turning TRACE back on.\n\n");
 		    }
 		    *prev_target = '\0';    /* Reset for this document. - FM */
 
@@ -883,9 +879,7 @@ try_again:
 				    if (!strcmp(homepage, startfile))
 					StrAllocCopy(homepage, newdoc.address);
 				    StrAllocCopy(startfile, newdoc.address);
-				    if (TRACE)
-					fprintf(stderr,
-						"Reloading as bookmarks=%s\n",
+				    CTRACE(tfp, "Reloading as bookmarks=%s\n",
 						newdoc.address);
 				    goto try_again;
 				}
@@ -1111,9 +1105,7 @@ try_again:
 		}
 	    }
 	    FREE(temp);
-	    if (TRACE) {
-		fprintf(stderr, "Starting realm is '%s'\n\n", startrealm);
-	    }
+	    CTRACE(tfp, "Starting realm is '%s'\n\n", startrealm);
 	    if (traversal) {
 		/*
 		 *  Set up the crawl output stuff.
@@ -1144,10 +1136,7 @@ try_again:
 		    }
 		    FREE(temp);
 		}
-		if (TRACE) {
-		    fprintf(stderr,
-			    "Traversal host is '%s'\n\n", traversal_host);
-		}
+		CTRACE(tfp, "Traversal host is '%s'\n\n", traversal_host);
 	    }
 	    if (startfile) {
 		/*
@@ -2808,11 +2797,8 @@ new_cmd:  /*
 				    links[curdoc.link].form->submit_action,
 					  "lynxprog:", 9)) {
 			    HTAlert(SPECIAL_ACTION_DISALLOWED);
-			    if (TRACE) {
-				fprintf(stderr,
-					"LYMainLoop: Rejected '%s'\n",
+			    CTRACE(tfp, "LYMainLoop: Rejected '%s'\n",
 					links[curdoc.link].form->submit_action);
-			    }
 			    HTOutputFormat = WWW_PRESENT;
 			    LYforce_no_cache = FALSE;
 			    reloading = FALSE;
@@ -4502,8 +4488,7 @@ check_goto_URL:
 		cp = HTParse(curdoc.address, "", PARSE_PATH|PARSE_PUNCTUATION);
 		HTUnEscape(cp);
 		if (HTStat(cp, &stat_info) == -1) {
-		    if (TRACE)
-			fprintf(stderr, "mainloop: Can't stat %s\n", cp);
+		    CTRACE(tfp, "mainloop: Can't stat %s\n", cp);
 		    FREE(cp);
 		    temp = (char *)calloc(1, (strlen(LYCSwingPath) + 4));
 		    if (temp == NULL)
@@ -4594,8 +4579,11 @@ check_goto_URL:
 
 #ifdef USE_EXTERNALS
 	case LYK_EXTERN:  /* use external program on url */
-	    run_external(links[curdoc.link].lname);
-	    refresh_screen = TRUE;
+	    if  ((nlinks > 0) && (links[curdoc.link].lname != NULL))
+	    {
+	       run_external(links[curdoc.link].lname);
+	       refresh_screen = TRUE;
+	    }
 	    break;
 #endif /* USE_EXTERNALS */
 
@@ -4836,10 +4824,18 @@ check_add_bookmark_to_self:
 		_go32_want_ctrl_break(0);
 #endif /* __DJGPP__ */
 #else
+#ifdef __EMX__
+		if (getenv("SHELL") != NULL) {
+		    system(getenv("SHELL"));
+		} else {
+		    system(getenv("COMSPEC") == NULL ? "cmd.exe" : getenv("COMSPEC"));
+		}
+#else
 #ifdef VMS
 		system("");
 #else
 		system("exec $SHELL");
+#endif /* __EMX__ */
 #endif /* VMS */
 #endif /* DOSPATH */
 		if (LYTraceLogFP)
@@ -5152,8 +5148,7 @@ check_add_bookmark_to_self:
 	     *	and open it again, to make sure all stderr messages thus
 	     *	far will be in the log. - FM
 	     */
-	    if (TRACE)
-		fprintf(stderr, "\nTurning off TRACE for fetch of log.\n");
+	    CTRACE(tfp, "\nTurning off TRACE for fetch of log.\n");
 	    fflush(stdout);
 	    fflush(stderr);
 	    fclose(LYTraceLogFP);
diff --git a/src/LYPrint.c b/src/LYPrint.c
index 76018a56..ee40408e 100644
--- a/src/LYPrint.c
+++ b/src/LYPrint.c
@@ -411,9 +411,11 @@ PUBLIC int printfile ARGS1(
 		    strcpy(buffer, filename);
 		}
 #else
+#ifndef __EMX__
 		if (*filename != '/')
 		    cp = getenv("PWD");
 		else
+#endif
 		    cp = NULL;
 		if (cp)
 #ifdef DOSPATH
@@ -969,7 +971,7 @@ PUBLIC int printfile ARGS1(
 		}
 #endif /* VMS */
 		if (Lpansi) {
-		     printf("\n\014");  /* Form feed */
+		     printf("\n\014");	/* Form feed */
 		     printf("\033[4i");
 		     Lpansi = FALSE;
 		} else {
@@ -1206,7 +1208,7 @@ PUBLIC int printfile ARGS1(
 			HTAddSugFilename(filename);
 		    }
 
-#ifdef VMS
+#if defined (VMS) || defined (__EMX__)
 		    sprintf(buffer, cur_printer->command, tempfile, filename,
 				    "", "", "", "", "", "", "", "", "", "");
 #else /* Unix: */
@@ -1232,8 +1234,7 @@ PUBLIC int printfile ARGS1(
 		move(1,1);
 
 		stop_curses();
-		if (TRACE)
-		    fprintf(stderr, "command: %s\n", buffer);
+		CTRACE(tfp, "command: %s\n", buffer);
 		printf(PRINTING_FILE);
 #ifdef VMS
 		/*
@@ -1328,7 +1329,7 @@ PUBLIC int print_options ARGS2(
 
     if (first) {
 	tempname(tempfile, NEW_FILE);
-#if defined (VMS) || defined (DOSPATH)
+#if defined (VMS) || defined (DOSPATH) || defined (__EMX__)
 	sprintf(print_filename, "file://localhost/%s", tempfile);
 #else
 	sprintf(print_filename, "file://localhost%s", tempfile);
diff --git a/src/LYReadCFG.c b/src/LYReadCFG.c
index 228d5029..11b85edc 100644
--- a/src/LYReadCFG.c
+++ b/src/LYReadCFG.c
@@ -451,10 +451,8 @@ PUBLIC void read_cfg ARGS3(
     char *cp, *cp1;
     int i, j, len;
 
-    if (TRACE) {
-	fprintf(stderr,
-		"Loading cfg file '%s'.\n", cfg_filename);
-    }
+    CTRACE(tfp, "Loading cfg file '%s'.\n", cfg_filename);
+
     /*
      *  Don't get hung up by an include file loop.  Arbitrary max depth
      *  of 10.  - BL
@@ -471,13 +469,11 @@ PUBLIC void read_cfg ARGS3(
      *	Locate and open the file.
      */
     if (!cfg_filename || strlen(cfg_filename) == 0) {
-	if (TRACE)
-	    fprintf(stderr,"No filename following -cfg switch!\n");
+	CTRACE(tfp,"No filename following -cfg switch!\n");
 	return;
     }
     if ((fp = fopen(cfg_filename,"r")) == NULL) {
-	if (TRACE)
-	    fprintf(stderr,"lynx.cfg file not found as %s\n",cfg_filename);
+	CTRACE(tfp,"lynx.cfg file not found as %s\n",cfg_filename);
 	return;
     }
     have_read_cfg=TRUE;
@@ -810,8 +806,7 @@ PUBLIC void read_cfg ARGS3(
 
 	} else if (!strncasecomp(buffer, "JUMPFILE:", 9)) {
 	    if (!LYJumpInit(buffer)) {
-		if (TRACE)
-		    fprintf(stderr, "Failed to register %s\n", buffer);
+		CTRACE(tfp, "Failed to register %s\n", buffer);
 	    }
 	}
 	break;
@@ -882,13 +877,10 @@ PUBLIC void read_cfg ARGS3(
 		StrAllocCopy(LynxSigFile, temp);
 		LYAddPathToHome(temp, 256, LynxSigFile);
 		StrAllocCopy(LynxSigFile, temp);
-		if (TRACE)
-		    fprintf(stderr,
-			    "LYNX_SIG_FILE set to '%s'\n", LynxSigFile);
+		CTRACE(tfp, "LYNX_SIG_FILE set to '%s'\n", LynxSigFile);
 	    } else {
-		if (TRACE)
-		    fprintf(stderr, "LYNX_SIG_FILE '%s' is bad. Ignoring.\n",
-				    LYNX_SIG_FILE);
+		CTRACE(tfp, "LYNX_SIG_FILE '%s' is bad. Ignoring.\n",
+			    LYNX_SIG_FILE);
 	    }
 	}
 	break;
diff --git a/src/LYShowInfo.c b/src/LYShowInfo.c
index 65f06958..af6a6e71 100644
--- a/src/LYShowInfo.c
+++ b/src/LYShowInfo.c
@@ -24,16 +24,16 @@
 
 #define FREE(x) if (x) {free(x); x = NULL;}
 
-/* 
+/*
  *  Showinfo prints a page of info about the current file and the link
  *  that the cursor is on.
  */
-	     
+
 PUBLIC int showinfo ARGS4(
 	document *,	doc,
 	int,		size_of_file,
 	document *,	newdoc,
-	char *,		owner_address)
+	char *, 	owner_address)
 {
     static char tempfile[256];
     static BOOLEAN first = TRUE;
@@ -50,11 +50,11 @@ PUBLIC int showinfo ARGS4(
     struct group *grp;
 #endif /* DIRED_SUPPORT */
     if (first) {
-        tempname(tempfile, NEW_FILE);
+	tempname(tempfile, NEW_FILE);
 	/*
 	 *  Make the temporary file a URL now.
 	 */
-#if defined (VMS) || defined (DOSPATH)
+#if defined (VMS) || defined (DOSPATH)	|| defined (__EMX__)
 	sprintf(info_url, "file://localhost/%s", tempfile);
 #else
 	sprintf(info_url, "file://localhost%s", tempfile);
@@ -62,17 +62,17 @@ PUBLIC int showinfo ARGS4(
 	first = FALSE;
 #ifdef VMS
     } else {
-        remove(tempfile);   /* Remove duplicates on VMS. */
+	remove(tempfile);   /* Remove duplicates on VMS. */
 #endif /* VMS */
     }
 
     if ((fp0 = LYNewTxtFile(tempfile)) == NULL) {
-        HTAlert(CANNOT_OPEN_TEMP);
-        return(0);
+	HTAlert(CANNOT_OPEN_TEMP);
+	return(0);
     }
 
     /*
-     *  Point the address pointer at this Url
+     *	Point the address pointer at this Url
      */
     StrAllocCopy(newdoc->address, info_url);
 
@@ -101,7 +101,7 @@ PUBLIC int showinfo ARGS4(
 	 "<h2>Directory that you are currently viewing</h2>\n<pre>");
 
 	cp = doc->address;
-	if (!strncmp(cp, "file://localhost", 16)) 
+	if (!strncmp(cp, "file://localhost", 16))
 	    cp += 16;
 	else if (!strncmp(cp, "file:", 5))
 	    cp += 5;
@@ -112,7 +112,7 @@ PUBLIC int showinfo ARGS4(
 	fprintf(fp0,"   <em> URL:</em>  %s\n", doc->address);
 
 	cp = links[doc->link].lname;
-	if (!strncmp(cp, "file://localhost", 16)) 
+	if (!strncmp(cp, "file://localhost", 16))
 	    cp += 16;
 	else if (!strncmp(cp, "file:", 5))
 	    cp += 5;
@@ -127,7 +127,7 @@ PUBLIC int showinfo ARGS4(
 		fprintf(fp0,
 		 "\nDirectory that you have currently selected\n\n");
 	    } else if (((dir_info.st_mode) & S_IFMT) == S_IFREG) {
-		fprintf(fp0, 
+		fprintf(fp0,
 		      "\nFile that you have currently selected\n\n");
 #ifdef S_IFLNK
 	    } else if (((dir_info.st_mode) & S_IFMT) == S_IFLNK) {
@@ -154,22 +154,22 @@ PUBLIC int showinfo ARGS4(
 #endif
 	    pw = getpwuid(dir_info.st_uid);
 	    if (pw)
-	        fprintf(fp0, "   <em>Name of owner:</em>  %s\n", pw->pw_name);
+		fprintf(fp0, "   <em>Name of owner:</em>  %s\n", pw->pw_name);
 	    grp = getgrgid(dir_info.st_gid);
 	    if (grp && grp->gr_name)
-	        fprintf(fp0, "      <em>Group name:</em>  %s\n", grp->gr_name);
+		fprintf(fp0, "      <em>Group name:</em>  %s\n", grp->gr_name);
 	    if (((dir_info.st_mode) & S_IFMT) == S_IFREG) {
 		sprintf(temp, "       <em>File size:</em>  %ld (bytes)\n",
-		 	      (long)dir_info.st_size);
+			      (long)dir_info.st_size);
 		fprintf(fp0, "%s", temp);
 	    }
 	    /*
-	     *  Include date and time information.
+	     *	Include date and time information.
 	     */
 	    cp = ctime(&dir_info.st_ctime);
 	    fprintf(fp0, "   <em>Creation date:</em>  %s", cp);
 
-	    cp = ctime(&dir_info.st_mtime);	      
+	    cp = ctime(&dir_info.st_mtime);
 	    fprintf(fp0, "   <em>Last modified:</em>  %s", cp);
 
 	    cp = ctime(&dir_info.st_atime);
@@ -185,13 +185,13 @@ PUBLIC int showinfo ARGS4(
 	    if ((dir_info.st_mode & S_IWUSR))
 		strcat(modes, ", write");
 	    if ((dir_info.st_mode & S_IXUSR)) {
-		if (((dir_info.st_mode) & S_IFMT) == S_IFDIR) 
+		if (((dir_info.st_mode) & S_IFMT) == S_IFDIR)
 		    strcat(modes, ", search");
-	        else {
+		else {
 		    strcat(modes, ", execute");
 		    if ((dir_info.st_mode & S_ISUID))
-		        strcat(modes, ", setuid");
-	        }
+			strcat(modes, ", setuid");
+		}
 	    }
 	    fprintf(fp0, "%s\n", (char *)&modes[2]); /* Skip leading ', ' */
 
@@ -199,18 +199,18 @@ PUBLIC int showinfo ARGS4(
 	    modes[0] = '\0';
 	    modes[1] = '\0';   /* In case there are no permissions */
 	    modes[2] = '\0';
-	    if ((dir_info.st_mode & S_IRGRP)) 
+	    if ((dir_info.st_mode & S_IRGRP))
 		strcat(modes, ", read");
 	    if ((dir_info.st_mode & S_IWGRP))
 		strcat(modes, ", write");
 	    if ((dir_info.st_mode & S_IXGRP)) {
-		if (((dir_info.st_mode) & S_IFMT) == S_IFDIR) 
+		if (((dir_info.st_mode) & S_IFMT) == S_IFDIR)
 		    strcat(modes, ", search");
-	        else {
+		else {
 		    strcat(modes, ", execute");
 		    if ((dir_info.st_mode & S_ISGID))
-		        strcat(modes, ", setgid");
-	        }
+			strcat(modes, ", setgid");
+		}
 	    }
 	    fprintf(fp0, "%s\n", (char *)&modes[2]);  /* Skip leading ', ' */
 
@@ -223,15 +223,15 @@ PUBLIC int showinfo ARGS4(
 	    if ((dir_info.st_mode & S_IWOTH))
 		strcat(modes, ", write");
 	    if ((dir_info.st_mode & S_IXOTH)) {
-		if (((dir_info.st_mode) & S_IFMT) == S_IFDIR) 
+		if (((dir_info.st_mode) & S_IFMT) == S_IFDIR)
 		    strcat(modes, ", search");
-	        else {
+		else {
 		    strcat(modes, ", execute");
 #ifdef S_ISVTX
 		    if ((dir_info.st_mode & S_ISVTX))
-		        strcat(modes, ", sticky");
+			strcat(modes, ", sticky");
 #endif
-	        }
+		}
 	    }
 	    fprintf(fp0, "%s\n", (char *)&modes[2]);  /* Skip leading ', ' */
 	}
@@ -245,38 +245,38 @@ PUBLIC int showinfo ARGS4(
     StrAllocCopy(Title, doc->title);
     LYEntify(&Title, TRUE);
     fprintf(fp0, "<dt><em>Linkname:</em> %s%s\n",
-    		 Title, (doc->isHEAD ? " (HEAD)" : ""));
+		 Title, (doc->isHEAD ? " (HEAD)" : ""));
 
     StrAllocCopy(Address, doc->address);
     LYEntify(&Address, TRUE);
     fprintf(fp0,
-    	    "<dt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>URL:</em> %s\n", Address);
+	    "<dt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>URL:</em> %s\n", Address);
 
     if (HTLoadedDocumentCharset()) {
-        fprintf(fp0, "<dt><em>&nbsp;Charset:</em> %s\n",
+	fprintf(fp0, "<dt><em>&nbsp;Charset:</em> %s\n",
 		     HTLoadedDocumentCharset());
     } else {
       LYUCcharset * p_in = HTAnchor_getUCInfoStage(HTMainAnchor,
-                                                             UCT_STAGE_PARSER);
+							     UCT_STAGE_PARSER);
       if (!p_in || !(p_in->MIMEname) || !*(p_in->MIMEname) ||
 	   HTAnchor_getUCLYhndl(HTMainAnchor, UCT_STAGE_PARSER) < 0) {
 	   p_in = HTAnchor_getUCInfoStage(HTMainAnchor, UCT_STAGE_MIME);
       }
       if (p_in && p_in->MIMEname && *(p_in->MIMEname) &&
 	  HTAnchor_getUCLYhndl(HTMainAnchor, UCT_STAGE_MIME) >= 0) {
-        fprintf(fp0, "<dt><em>&nbsp;Charset:</em> %s (assumed)\n",
+	fprintf(fp0, "<dt><em>&nbsp;Charset:</em> %s (assumed)\n",
 		     p_in->MIMEname);
       }
     }
 
     if ((cp = HText_getServer()) != NULL && *cp != '\0')
-        fprintf(fp0, "<dt><em>&nbsp;&nbsp;Server:</em> %s\n", cp);
+	fprintf(fp0, "<dt><em>&nbsp;&nbsp;Server:</em> %s\n", cp);
 
     if ((cp = HText_getDate()) != NULL && *cp != '\0')
-        fprintf(fp0, "<dt><em>&nbsp;&nbsp;&nbsp;&nbsp;Date:</em> %s\n", cp);
+	fprintf(fp0, "<dt><em>&nbsp;&nbsp;&nbsp;&nbsp;Date:</em> %s\n", cp);
 
     if ((cp = HText_getLastModified()) != NULL && *cp != '\0')
-        fprintf(fp0, "<dt><em>Last Mod:</em> %s\n", cp);
+	fprintf(fp0, "<dt><em>Last Mod:</em> %s\n", cp);
 
     if (doc->post_data) {
 	fprintf(fp0,
@@ -286,10 +286,10 @@ PUBLIC int showinfo ARGS4(
     }
 
     if (owner_address) {
-        StrAllocCopy(Address, owner_address);
+	StrAllocCopy(Address, owner_address);
 	LYEntify(&Address, TRUE);
     } else {
-        StrAllocCopy(Address, "None");
+	StrAllocCopy(Address, "None");
     }
     fprintf(fp0, "<dt><em>Owner(s):</em> %s\n", Address);
 
@@ -314,8 +314,8 @@ PUBLIC int showinfo ARGS4(
 	if (lynx_mode == FORMS_LYNX_MODE &&
 	    links[doc->link].type == WWW_FORM_LINK_TYPE) {
 	    if (links[doc->link].form->submit_method) {
-	        int method = links[doc->link].form->submit_method;
-	        char *enctype = links[doc->link].form->submit_enctype;
+		int method = links[doc->link].form->submit_method;
+		char *enctype = links[doc->link].form->submit_enctype;
 
 		fprintf(fp0, "<dt>&nbsp;&nbsp;<em>Method:</em> %s\n",
 			     (method == URL_POST_METHOD) ? "POST" :
@@ -327,20 +327,20 @@ PUBLIC int showinfo ARGS4(
 			       enctype : "application/x-www-form-urlencoded"));
 	    }
 	    if (links[doc->link].form->submit_action) {
-	        StrAllocCopy(Address, links[doc->link].form->submit_action);
+		StrAllocCopy(Address, links[doc->link].form->submit_action);
 		LYEntify(&Address, TRUE);
-	        fprintf(fp0, "<dt>&nbsp;&nbsp;<em>Action:</em> %s\n", Address);
+		fprintf(fp0, "<dt>&nbsp;&nbsp;<em>Action:</em> %s\n", Address);
 	    }
 	    if (!(links[doc->link].form->submit_method &&
 		  links[doc->link].form->submit_action)) {
-	        fprintf(fp0,"<dt>&nbsp;(Form field)\n");
+		fprintf(fp0,"<dt>&nbsp;(Form field)\n");
 	    }
 	} else {
 	    if (links[doc->link].lname) {
-	        StrAllocCopy(Title, links[doc->link].lname);
+		StrAllocCopy(Title, links[doc->link].lname);
 		LYEntify(&Title, TRUE);
 	    } else {
-	        StrAllocCopy(Title, "");
+		StrAllocCopy(Title, "");
 	    }
 	    fprintf(fp0,
 	       "<dt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>URL:</em> %s\n", Title);
diff --git a/src/LYStrings.c b/src/LYStrings.c
index f273f051..b5fafc47 100644
--- a/src/LYStrings.c
+++ b/src/LYStrings.c
@@ -275,26 +275,26 @@ PUBLIC void LYsubwindow ARGS1(WINDOW *, param)
 #ifdef USE_SLANG_MOUSE
 PRIVATE int sl_parse_mouse_event ARGS3(int *, x, int *, y, int *, button)
 {
-   /* "ESC [ M" has already been processed.  There more characters are
-    * expected:  BUTTON X Y
-    */
-   *button = SLang_getkey ();
-   switch (*button)
-     {
-      case 040: 		       /* left button */
-      case 041: 		       /* middle button */
-      case 042: 		       /* right button */
+    /* "ESC [ M" has already been processed.  There more characters are
+     * expected:  BUTTON X Y
+     */
+    *button = SLang_getkey ();
+    switch (*button)
+    {
+    case 040:			/* left button */
+    case 041:			/* middle button */
+    case 042:			/* right button */
 	*button -= 040;
 	break;
 
-      default:			       /* Hmmm.... */
+    default:			/* Hmmm.... */
 	SLang_flush_input ();
 	return -1;
-     }
+    }
 
-   *x = SLang_getkey () - 33;
-   *y = SLang_getkey () - 33;
-   return 0;
+    *x = SLang_getkey () - 33;
+    *y = SLang_getkey () - 33;
+    return 0;
 }
 #endif
 
@@ -545,7 +545,7 @@ re_read:
 	    }
 	default:
 	   if (TRACE) {
-		fprintf(stderr,"Unknown key sequence: %d:%d:%d\n",c,b,a);
+		fprintf(tfp,"Unknown key sequence: %d:%d:%d\n",c,b,a);
 		if (!LYTraceLogFP) {
 		    sleep(MessageSecs);
 		}
@@ -1565,8 +1565,7 @@ PUBLIC char * SNACopy ARGS3(
     if (src) {
 	*dest = (char *)calloc(1, n + 1);
 	if (*dest == NULL) {
-	    if (TRACE)
-		fprintf(stderr, "Tried to calloc %d bytes\n", n);
+	    CTRACE(tfp, "Tried to calloc %d bytes\n", n);
 	    outofmem(__FILE__, "SNACopy");
 	}
 	strncpy (*dest, src, n);
@@ -1627,8 +1626,8 @@ PUBLIC char * SNACat ARGS3(
 **   may be interpreted as equal, but this side effect is negligible
 **   if the user search string is more than one character long.  - LP
 **
-**   We enable new technique only if  DisplayCharsetMatchLocale = FALSE 
-**   (see description in LYCharSets.c) 
+**   We enable new technique only if  DisplayCharsetMatchLocale = FALSE
+**   (see description in LYCharSets.c)
 */
 PUBLIC int UPPER8 ARGS2(int,ch1, int,ch2)
 {
@@ -1640,15 +1639,15 @@ PUBLIC int UPPER8 ARGS2(int,ch1, int,ch2)
     /* case-insensitive match for upper half */
     if ((unsigned char)ch1 > 127 && (unsigned char)ch2 >127)
     {
-	if (DisplayCharsetMatchLocale) 
-	   return(TOUPPER(ch1) - TOUPPER(ch2)); /* old-style */ 
-	else 
+	if (DisplayCharsetMatchLocale)
+	   return(TOUPPER(ch1) - TOUPPER(ch2)); /* old-style */
+	else
 	{
 	/* compare "7bit approximation" for letters >127   */
 	/* BTW, if we remove the check for >127 above	   */
 	/* we get even more "relaxed" insensitive match... */
 
-        CONST char *disp_charset = LYCharSet_UC[current_char_set].MIMEname; 
+	CONST char *disp_charset = LYCharSet_UC[current_char_set].MIMEname;
 	int charset_in, charset_out, uck1, uck2;
 	char replace_buf1 [10], replace_buf2 [10];
 
@@ -1665,7 +1664,7 @@ PUBLIC int UPPER8 ARGS2(int,ch1, int,ch2)
 
 	/* check to be sure we have not lost any strange characters */
 	/* which are not found in def7_uni.tbl but _equal_ in fact. */
-	/* this also applied for "x-transparent" display mode.	    */ 
+	/* this also applied for "x-transparent" display mode.	    */
 	if ((unsigned char)ch1==(unsigned char)ch2)
 	    return(0);	 /* match */
 	}
diff --git a/src/LYStyle.c b/src/LYStyle.c
index 3953621f..af21fdd3 100644
--- a/src/LYStyle.c
+++ b/src/LYStyle.c
@@ -1,6 +1,6 @@
 /* character level styles for Lynx
  * (c) 1996 Rob Partington -- donated to the Lyncei (if they want it :-)
- * @Id: LYStyle.c 1.17 Wed, 25 Mar 1998 06:58:54 -0700 dickey @
+ * @Id: LYStyle.c 1.18 Thu, 23 Apr 1998 06:35:21 -0600 dickey @
  */
 #include <HTUtils.h>
 #include <HTML.h>
@@ -60,8 +60,7 @@ PRIVATE void parse_attributes ARGS5(char*,mono,char*,fg,char*,bg,int,style,char*
     int mA = 0, fA = default_fg, bA = default_bg, cA = A_NORMAL;
     int newstyle = hash_code(element);
 
-    if (TRACE)
-	fprintf(stderr, "CSS(PA):style d=%d / h=%d, e=%s\n", style, newstyle,element);
+    CTRACE(tfp, "CSS(PA):style d=%d / h=%d, e=%s\n", style, newstyle,element);
 
     for (i = 0; i <7; i++)
     {
@@ -70,8 +69,7 @@ PRIVATE void parse_attributes ARGS5(char*,mono,char*,fg,char*,bg,int,style,char*
 	    mA = ncursesMono[i];
 	}
     }
-    if (TRACE)
-	fprintf(stderr, "CSS(CP):%d\n", colorPairs);
+    CTRACE(tfp, "CSS(CP):%d\n", colorPairs);
 
     fA = check_color(fg, default_fg);
     bA = check_color(bg, default_bg);
@@ -177,13 +175,9 @@ where OBJECT is one of EM,STRONG,B,I,U,BLINK etc.\n\n", buffer);
 	}
     }
 
-    if (TRACE)
-    {
-	int bkt = hash_code(element);
-	fprintf(stderr, "CSSPARSE:%s => %d %s\n",
-	    element, bkt,
-	    (hashStyles[bkt].name ? "used" : ""));
-    }
+    CTRACE(tfp, "CSSPARSE:%s => %d %s\n",
+		element, hash_code(element),
+		(hashStyles[hash_code(element)].name ? "used" : ""));
 
     strtolower(element);
 
@@ -235,8 +229,7 @@ where OBJECT is one of EM,STRONG,B,I,U,BLINK etc.\n\n", buffer);
 	{
 	    if (!strcasecomp (HTML_dtd.tags[i].name, element))
 	    {
-		if (TRACE)
-		    fprintf(stderr, "PARSECSS:applying style <%s,%s,%s> for HTML_%s\n",mono,fg,bg,HTML_dtd.tags[i].name);
+		CTRACE(tfp, "PARSECSS:applying style <%s,%s,%s> for HTML_%s\n",mono,fg,bg,HTML_dtd.tags[i].name);
 			parse_attributes(mono,fg,bg,i+STARTAT,element);
 		break;
 	    }
@@ -318,8 +311,7 @@ PUBLIC void parse_userstyles NOARGS
 
 	while ((name = HTList_nextObject(cur)) != NULL)
 	{
-		if (TRACE)
-			fprintf(stderr, "LSS:%s\n", name ? name : "!?! empty !?!");
+		CTRACE(tfp, "LSS:%s\n", name ? name : "!?! empty !?!");
 		if (name != NULL)
 		    parse_style(name);
 	}
@@ -334,8 +326,7 @@ PUBLIC void HStyle_addStyle ARGS1(char*,buffer)
 	if (lss_styles == NULL)
 		lss_styles = HTList_new();
 	strtolower(name);
-	if (TRACE)
-		fprintf(stderr, "READCSS:%s\n", name ? name : "!?! empty !?!");
+	CTRACE(tfp, "READCSS:%s\n", name ? name : "!?! empty !?!");
 	HTList_addObject (lss_styles, name);
 }
 
@@ -366,16 +357,14 @@ PUBLIC int style_readFromFile ARGS1(char*, file)
     char buffer[1024];
     int len;
 
-    if (TRACE)
-	fprintf(stderr, "CSS:Reading styles from file: %s\n", file ? file : "?!? empty ?!?");
+    CTRACE(tfp, "CSS:Reading styles from file: %s\n", file ? file : "?!? empty ?!?");
     if (file == NULL || *file == '\0')
 	return -1;
     fh = fopen(file, "r");
     if (!fh)
     {
 	/* this should probably be an alert or something */
-	if (TRACE)
-	    fprintf(stderr, "CSS:Can't open style file %s, using defaults\n", file);
+	CTRACE(tfp, "CSS:Can't open style file %s, using defaults\n", file);
 	return -1;
     }
 
diff --git a/src/LYUpload.c b/src/LYUpload.c
index 0ad784f5..cf5d55f8 100644
--- a/src/LYUpload.c
+++ b/src/LYUpload.c
@@ -37,13 +37,13 @@
 PUBLIC char LYUploadFileURL[256] = "\0";
 
 /*
- *  LYUpload uploads a file to a given location using a 
+ *  LYUpload uploads a file to a given location using a
  *  specified upload method.  It parses an incoming link
  *  that looks like:
  *	LYNXDIRED://UPLOAD=<#>/TO=<STRING>
  */
 PUBLIC int LYUpload ARGS1(
-	char *,		line) 
+	char *, 	line)
 {
     char *method, *directory, *dir;
     int method_number;
@@ -60,7 +60,7 @@ PUBLIC int LYUpload ARGS1(
 #endif /* VMS */
 
     /*
-     *  Use configured upload commands.
+     *	Use configured upload commands.
      */
     if((directory = (char *)strstr(line, "TO=")) == NULL)
 	goto failed;
@@ -71,7 +71,7 @@ PUBLIC int LYUpload ARGS1(
     if((method = (char *)strstr(line, "UPLOAD=")) == NULL)
 	goto failed;
     /*
-     *  Go past "Method=".
+     *	Go past "Method=".
      */
     method += 7;
     method_number = atoi(method);
@@ -81,7 +81,7 @@ PUBLIC int LYUpload ARGS1(
       ; /* null body */
 
     /*
-     *  Parsed out the Method and the Location?
+     *	Parsed out the Method and the Location?
      */
     if (upload_command->command == NULL) {
 	_statusline("ERROR! - upload command is misconfigured");
@@ -90,7 +90,7 @@ PUBLIC int LYUpload ARGS1(
     }
 
     /*
-     *  Care about the local name?
+     *	Care about the local name?
      */
     if (strstr(upload_command->command, "%s")) {
 	/*
@@ -178,7 +178,7 @@ retry:
 	    goto retry;
 	}
 
-#ifdef VMS
+#if defined (VMS) || defined (__EMX__)
 	sprintf(tmpbuf, upload_command->command, buffer, "", "", "", "", "");
 #else
 	cp = quote_pathname(buffer); /* to prevent spoofing of the shell */
@@ -193,14 +193,13 @@ retry:
     sprintf(cmd, "cd %s ; %s", dir, tmpbuf);
     FREE(dir);
     stop_curses();
-    if (TRACE)
-	fprintf(stderr, "command: %s\n", cmd);
+    CTRACE(tfp, "command: %s\n", cmd);
     system(cmd);
     fflush(stdout);
     start_curses();
-#ifdef UNIX 
+#ifdef UNIX
     chmod(buffer, HIDE_CHMOD);
-#endif /* UNIX */ 
+#endif /* UNIX */
     /* don't remove(file); */
 
     return 1;
@@ -224,7 +223,7 @@ cancelled:
  */
 PUBLIC int LYUpload_options ARGS2(
 	char **,	newfile,
-	char *,		directory)
+	char *, 	directory)
 {
     static char tempfile[256];
     static BOOLEAN first = TRUE;
@@ -238,17 +237,17 @@ PUBLIC int LYUpload_options ARGS2(
 	/*
 	 *  Get an unused tempfile name. - FM
 	 */
-        tempname(tempfile, NEW_FILE);
+	tempname(tempfile, NEW_FILE);
 #ifdef VMS
     } else {
-        remove(tempfile);   /* Remove duplicates on VMS. */
+	remove(tempfile);   /* Remove duplicates on VMS. */
 #endif /* VMS */
     }
 
     /*
-     *  Open the tempfile for writing and set it's
-     *  protection in case this wasn't done via an
-     *  external umask. - FM
+     *	Open the tempfile for writing and set it's
+     *	protection in case this wasn't done via an
+     *	external umask. - FM
      */
     if ((fp0 = LYNewTxtFile(tempfile)) == NULL) {
 	HTAlert(CANNOT_OPEN_TEMP);
@@ -260,20 +259,20 @@ PUBLIC int LYUpload_options ARGS2(
 #else
     cp = directory;
     if (!strncmp(cp, "file://localhost", 16))
-        cp += 16;
+	cp += 16;
     else if (!strncmp(cp, "file:", 5))
-        cp += 5;
+	cp += 5;
     strcpy(curloc,cp);
     HTUnEscape(curloc);
     if (curloc[strlen(curloc) - 1] == '/')
-        curloc[strlen(curloc) - 1] = '\0';
+	curloc[strlen(curloc) - 1] = '\0';
 #endif /* VMS */
 
     if (first) {
 	/*
 	 *  Make the tempfile a URL.
- 	 */
-#if defined (VMS) || defined (DOSPATH)
+	 */
+#if defined (VMS) || defined (DOSPATH) || defined (__EMX__)
 	sprintf(LYUploadFileURL, "file://localhost/%s", tempfile);
 #else
 	sprintf(LYUploadFileURL, "file://localhost%s", tempfile);
@@ -283,21 +282,21 @@ PUBLIC int LYUpload_options ARGS2(
     StrAllocCopy(*newfile, LYUploadFileURL);
 
     fprintf(fp0, "<head>\n<title>%s</title>\n</head>\n<body>\n",
-    		 UPLOAD_OPTIONS_TITLE);
+		 UPLOAD_OPTIONS_TITLE);
 
     fprintf(fp0, "<h1>Upload Options (%s Version %s)</h1>\n",
-    				      LYNX_NAME, LYNX_VERSION);
+				      LYNX_NAME, LYNX_VERSION);
 
     fputs("You have the following upload choices.<br>\n", fp0);
     fputs("Please select one:<br>\n<pre>\n", fp0);
 
     if (uploaders != NULL) {
 	for (count = 0, cur_upload = uploaders;
-	     cur_upload != NULL; 
+	     cur_upload != NULL;
 	     cur_upload = cur_upload->next, count++) {
 	    fprintf(fp0, "   <a href=\"LYNXDIRED://UPLOAD=%d/TO=%s\">",
 			 count, curloc);
-	    fprintf(fp0, (cur_upload->name ? 
+	    fprintf(fp0, (cur_upload->name ?
 			  cur_upload->name : "No Name Given"));
 	    fprintf(fp0, "</a>\n");
 	}
diff --git a/src/LYUtils.c b/src/LYUtils.c
index 842b8f0c..e78b86a3 100644
--- a/src/LYUtils.c
+++ b/src/LYUtils.c
@@ -2032,19 +2032,15 @@ PUBLIC void LYFakeZap ARGS1(
     BOOL,	set)
 {
     if (set && fake_zap < 1) {
-	if (TRACE) {
-	    fprintf(stderr, "\r *** Set simulated 'Z'");
-	    if (fake_zap)
-		fprintf(stderr, ", %d pending", fake_zap);
-	    fprintf(stderr, " ***\n");
-	}
+	CTRACE(tfp, "\r *** Set simulated 'Z'");
+	if (fake_zap)
+	    CTRACE(tfp, ", %d pending", fake_zap);
+	CTRACE(tfp, " ***\n");
 	fake_zap++;
     } else if (!set && fake_zap) {
-	if (TRACE) {
-	    fprintf(stderr, "\r *** Unset simulated 'Z'");
-	    fprintf(stderr, ", %d pending", fake_zap);
-	    fprintf(stderr, " ***\n");
-	}
+	CTRACE(tfp, "\r *** Unset simulated 'Z'");
+	CTRACE(tfp, ", %d pending", fake_zap);
+	CTRACE(tfp, " ***\n");
 	fake_zap = 0;
     }
 
@@ -2063,8 +2059,8 @@ PUBLIC int HTCheckForInterrupt NOARGS
     if (fake_zap > 0) {
 	fake_zap--;
 	if (TRACE) {
-	    fprintf(stderr, "\r *** Got simulated 'Z' ***\n");
-	    fflush(stderr);
+	    fprintf(tfp, "\r *** Got simulated 'Z' ***\n");
+	    fflush(tfp);
 	    if (!LYTraceLogFP)
 		sleep(AlertSecs);
 	}
@@ -2130,8 +2126,8 @@ PUBLIC int HTCheckForInterrupt NOARGS
     if (fake_zap > 0) {
 	fake_zap--;
 	if (TRACE) {
-	    fprintf(stderr, "\r *** Got simulated 'Z' ***\n");
-	    fflush(stderr);
+	    fprintf(tfp, "\r *** Got simulated 'Z' ***\n");
+	    fflush(tfp);
 	    if (!LYTraceLogFP)
 		sleep(AlertSecs);
 	}
@@ -2422,7 +2418,7 @@ PUBLIC int is_url ARGS1(
     if (*cp == '/')
 	return(0);
 
-#ifdef DOSPATH /* sorry! */
+#if defined (DOSPATH) || defined (__EMX__) /* sorry! */
 	if (strncmp(cp, "file:///", 8) && strlen(cp) == 19 &&
 	    cp[strlen(cp)-1] == ':')
 	    StrAllocCat(cp,"/");
@@ -2878,8 +2874,7 @@ PUBLIC BOOLEAN inlocaldomain NOARGS
 #endif /* LINUX */
 
     } else {
-	if (TRACE)
-	   fprintf(stderr,"Could not get ttyname or open UTMP file");
+	CTRACE(tfp,"Could not get ttyname or open UTMP file");
     }
 
     return(FALSE);
@@ -2971,11 +2966,8 @@ PUBLIC void size_change ARGS1(
     if (LYlines != old_lines || LYcols != old_cols) {
 	recent_sizechange = TRUE;
     }
-    if (TRACE) {
-	fprintf(stderr,
-		"Window size changed from (%d,%d) to (%d,%d)\n",
+    CTRACE(tfp, "Window size changed from (%d,%d) to (%d,%d)\n",
 		old_lines, old_cols, LYlines, LYcols);
-    }
 #ifdef SIGWINCH
     (void)signal (SIGWINCH, size_change);
 #endif /* SIGWINCH */
@@ -3387,9 +3379,7 @@ PUBLIC void tempname ARGS2(
 #endif /* FNAMES_8_3 */
 	    if ((fp = fopen(namebuffer, "r")) != NULL) {
 		fclose(fp);
-		if (TRACE)
-		    fprintf(stderr,
-			    "tempname: file '%s' already exists!\n",
+		CTRACE(tfp, "tempname: file '%s' already exists!\n",
 			    namebuffer);
 		counter++;
 		continue;
@@ -3405,9 +3395,7 @@ PUBLIC void tempname ARGS2(
 #endif /* FNAMES_8_3 */
 	    if ((fp = fopen(namebuffer, "r")) != NULL) {
 		fclose(fp);
-		if (TRACE)
-		    fprintf(stderr,
-			    "tempname: file '%s' already exists!\n",
+		CTRACE(tfp, "tempname: file '%s' already exists!\n",
 			    namebuffer);
 		counter++;
 		continue;
@@ -3423,9 +3411,7 @@ PUBLIC void tempname ARGS2(
 #endif /* FNAMES_8_3 */
 	    if ((fp = fopen(namebuffer, "r")) != NULL) {
 		fclose(fp);
-		if (TRACE)
-		    fprintf(stderr,
-			    "tempname: file '%s' already exists!\n",
+		CTRACE(tfp, "tempname: file '%s' already exists!\n",
 			    namebuffer);
 		continue;
 	    }
@@ -3829,8 +3815,7 @@ PUBLIC void LYEnsureAbsoluteURL ARGS2(
 	StrAllocCat(*href, "/*");
     }
     if (!is_url(*href)) {
-	if (TRACE)
-	    fprintf(stderr, "%s%s'%s' is not a URL\n",
+	CTRACE(tfp, "%s%s'%s' is not a URL\n",
 		    (name ? name : ""), (name ? " " : ""), *href);
 	LYConvertToURL(href);
     }
@@ -3859,7 +3844,7 @@ PUBLIC void LYConvertToURL ARGS1(
     if (!old_string || *old_string == '\0')
 	return;
 
-#ifdef DOSPATH
+#ifdef DOSPATH /* should EMX version do this too? */
     {
 	 char *cp_url = *AllocatedString;
 	 for(; *cp_url != '\0'; cp_url++)
@@ -3879,7 +3864,7 @@ PUBLIC void LYConvertToURL ARGS1(
 
     if (*old_string != '/') {
 	char *fragment = NULL;
-#ifdef DOSPATH
+#ifdef DOSPATH /* Should EMX version do this? */
 	StrAllocCat(*AllocatedString,"/");
 #endif /* DOSPATH */
 #ifdef VMS
@@ -3977,9 +3962,7 @@ PUBLIC void LYConvertToURL ARGS1(
 		     */
 		    strcpy(url_file, "/");
 		    strcat(url_file, old_string);
-		    if (TRACE) {
-			fprintf(stderr,
-			    "Can't find '%s'  Will assume it's a bad path.\n",
+		    CTRACE(tfp, "Can't find '%s'  Will assume it's a bad path.\n",
 				old_string);
 		    }
 		    StrAllocCat(*AllocatedString, url_file);
@@ -4019,11 +4002,8 @@ PUBLIC void LYConvertToURL ARGS1(
 		 */
 		strcpy(url_file, "/");
 		strcat(url_file, old_string);
-		if (TRACE) {
-		    fprintf(stderr,
-			    "Can't find '%s'  Will assume it's a bad path.\n",
-				old_string);
-		}
+		CTRACE(tfp, "Can't find '%s'  Will assume it's a bad path.\n",
+			    old_string);
 		StrAllocCat(*AllocatedString, url_file);
 	    } else {
 		/*
@@ -4041,9 +4021,7 @@ PUBLIC void LYConvertToURL ARGS1(
 	lib$find_file_end(&context);
 	FREE(cur_dir);
 have_VMS_URL:
-	if (TRACE) {
-	    fprintf(stderr, "Trying: '%s'\n", *AllocatedString);
-	}
+	CTRACE(tfp, "Trying: '%s'\n", *AllocatedString);
 #else /* Unix: */
 #ifdef DOSPATH
 	if (strlen(old_string) == 1 && *old_string == '.') {
@@ -4055,10 +4033,8 @@ have_VMS_URL:
 	    StrAllocCopy(temp, HTDOS_wwwName(curdir));
 	    StrAllocCat(*AllocatedString, temp);
 	    FREE(temp);
-	    if (TRACE) {
-		fprintf(stderr, "Converted '%s' to '%s'\n",
-				old_string, *AllocatedString);
-	    }
+	    CTRACE(tfp, "Converted '%s' to '%s'\n",
+			old_string, *AllocatedString);
 	} else
 #endif /* DOSPATH */
 	if (*old_string == '~') {
@@ -4077,10 +4053,8 @@ have_VMS_URL:
 		StrAllocCat(*AllocatedString, temp);
 		FREE(temp);
 	    }
-	    if (TRACE) {
-		fprintf(stderr, "Converted '%s' to '%s'\n",
-				old_string, *AllocatedString);
-	    }
+	    CTRACE(tfp, "Converted '%s' to '%s'\n",
+			old_string, *AllocatedString);
 	} else {
 	    /*
 	     *	Create a full path to the current default directory.
@@ -4097,7 +4071,7 @@ have_VMS_URL:
 	     *	Concatenate and simplify, trimming any
 	     *	residual relative elements. - FM
 	     */
-#ifndef DOSPATH
+#ifndef DOSPATH /* Should EMX version do this? */
 	    StrAllocCopy(temp, curdir);
 	    StrAllocCat(temp, "/");
 	    StrAllocCat(temp, old_string);
@@ -4114,15 +4088,13 @@ have_VMS_URL:
 	    }
 #endif /* DOSPATH */
 	    LYTrimRelFromAbsPath(temp);
-	    if (TRACE) {
-		fprintf(stderr, "Converted '%s' to '%s'\n", old_string, temp);
-	    }
+	    CTRACE(tfp, "Converted '%s' to '%s'\n", old_string, temp);
 	    if ((stat(temp, &st) > -1) ||
 		(fptemp = fopen(temp, "r")) != NULL) {
 		/*
 		 *  It is a subdirectory or file on the local system.
 		 */
-#ifdef DOSPATH
+#if defined (DOSPATH) || defined (__EMX__)
 		/* Don't want to see DOS local paths like c: escaped */
 		/* especially when we really have file://localhost/  */
 		/* at the beginning. To avoid any confusion we allow */
@@ -4135,10 +4107,8 @@ have_VMS_URL:
 		cp = HTEscape(temp, URL_PATH);
 		StrAllocCat(*AllocatedString, cp);
 		FREE(cp);
-		if (TRACE) {
-		    fprintf(stderr, "Converted '%s' to '%s'\n",
-				    old_string, *AllocatedString);
-		}
+		CTRACE(tfp, "Converted '%s' to '%s'\n",
+			    old_string, *AllocatedString);
 		is_local = TRUE;
 	    } else {
 		char *cp2 = NULL;
@@ -4180,10 +4150,8 @@ have_VMS_URL:
 			}
 		    }
 		    StrAllocCat(*AllocatedString, temp);
-		    if (TRACE) {
-			fprintf(stderr, "Converted '%s' to '%s'\n",
-					old_string, *AllocatedString);
-		    }
+		    CTRACE(tfp, "Converted '%s' to '%s'\n",
+				old_string, *AllocatedString);
 		    is_local = TRUE;
 
 		} else if (strchr(curdir, '#') != NULL ||
@@ -4222,10 +4190,8 @@ have_VMS_URL:
 		 *  local system, so assume it's a URL request and guess
 		 *  the scheme with "http://" as the default.
 		 */
-		if (TRACE) {
-		    fprintf(stderr, "Can't stat() or fopen() '%s'\n",
+		CTRACE(tfp, "Can't stat() or fopen() '%s'\n",
 			    temp2 ? temp2 : temp);
-		}
 		if (LYExpandHostForURL((char **)&old_string,
 				       URLDomainPrefixes,
 				       URLDomainSuffixes)) {
@@ -4236,12 +4202,10 @@ have_VMS_URL:
 			StrAllocCopy(*AllocatedString, old_string);
 		    }
 		} else {
-		  /* RW 1998Mar16  Restore AllocatedString to 'old_string' */ 
-		    StrAllocCopy(*AllocatedString, old_string); 
-		}
-		if (TRACE) {
-		    fprintf(stderr, "Trying: '%s'\n", *AllocatedString);
+		  /* RW 1998Mar16  Restore AllocatedString to 'old_string' */
+		    StrAllocCopy(*AllocatedString, old_string);
 		}
+		CTRACE(tfp, "Trying: '%s'\n", *AllocatedString);
 	    }
 	    FREE(temp);
 	    FREE(temp2);
@@ -4273,9 +4237,7 @@ have_VMS_URL:
 	     */
 	    StrAllocCopy(temp, old_string);
 	    LYTrimRelFromAbsPath(temp);
-	    if (TRACE) {
-		fprintf(stderr, "Converted '%s' to '%s'\n", old_string, temp);
-	    }
+	    CTRACE(tfp, "Converted '%s' to '%s'\n", old_string, temp);
 	    cp = HTEscape(temp, URL_PATH);
 	    StrAllocCat(*AllocatedString, cp);
 	    FREE(cp);
@@ -4284,10 +4246,8 @@ have_VMS_URL:
 		fclose(fptemp);
 		fptemp = NULL;
 	    }
-	    if (TRACE) {
-		fprintf(stderr, "Converted '%s' to '%s'\n",
+	    CTRACE(tfp, "Converted '%s' to '%s'\n",
 			old_string, *AllocatedString);
-	    }
 #endif /* VMS */
 	} else if (old_string[1] == '~') {
 	    /*
@@ -4320,10 +4280,8 @@ have_VMS_URL:
 	    StrAllocCat(*AllocatedString, temp);
 	    FREE(temp);
 	}
-	if (TRACE) {
-	    fprintf(stderr, "Converted '%s' to '%s'\n",
-			    old_string, *AllocatedString);
-	}
+	CTRACE(tfp, "Converted '%s' to '%s'\n",
+		    old_string, *AllocatedString);
     }
     FREE(old_string);
     if (TRACE) {
@@ -4446,11 +4404,8 @@ PUBLIC BOOLEAN LYExpandHostForURL ARGS3(
 	 *  Clear any residual interrupt. - FM
 	 */
 	if (LYCursesON && HTCheckForInterrupt()) {
-	    if (TRACE) {
-		fprintf(stderr,
-	 "LYExpandHostForURL: Ignoring interrupt because '%s' resolved.\n",
+	    CTRACE(tfp, "LYExpandHostForURL: Ignoring interrupt because '%s' resolved.\n",
 			host);
-	    }
 	}
 
 	/*
@@ -4465,11 +4420,8 @@ PUBLIC BOOLEAN LYExpandHostForURL ARGS3(
 	/*
 	 *  Give the user chance to interrupt lookup cycles. - KW & FM
 	 */
-	if (TRACE) {
-	    fprintf(stderr,
-	 "LYExpandHostForURL: Interrupted while '%s' failed to resolve.\n",
+	CTRACE(tfp, "LYExpandHostForURL: Interrupted while '%s' failed to resolve.\n",
 		    host);
-	}
 
 	/*
 	 *  Return failure. - FM
@@ -4572,11 +4524,8 @@ PUBLIC BOOLEAN LYExpandHostForURL ARGS3(
 		 *  Give the user chance to interrupt lookup cycles. - KW
 		 */
 		if (LYCursesON && HTCheckForInterrupt()) {
-		    if (TRACE) {
-			fprintf(stderr,
-	 "LYExpandHostForURL: Interrupted while '%s' failed to resolve.\n",
+		    CTRACE(tfp, "LYExpandHostForURL: Interrupted while '%s' failed to resolve.\n",
 				host);
-			    }
 		    FREE(Str);
 		    FREE(MsgStr);
 		    FREE(Host);
@@ -4641,12 +4590,9 @@ PUBLIC BOOLEAN LYExpandHostForURL ARGS3(
      *	Clear any residual interrupt. - FM
      */
     if (LYCursesON && HTCheckForInterrupt()) {
-	if (TRACE) {
-	    fprintf(stderr,
-	 "LYExpandHostForURL: Ignoring interrupt because '%s' %s.\n",
+	CTRACE(tfp, "LYExpandHostForURL: Ignoring interrupt because '%s' %s.\n",
 		    host,
 		    (GotHost ? "resolved" : "timed out"));
-	}
     }
 
     /*
@@ -4916,7 +4862,7 @@ PUBLIC CONST char * Home_Dir NOARGS
 
     if (homedir == NULL) {
 	if ((cp = getenv("HOME")) == NULL || *cp == '\0') {
-#ifdef DOSPATH /* BAD!	WSB */
+#if defined (DOSPATH) || defined (__EMX__) /* BAD!	WSB */
 	    if ((cp = getenv("TEMP")) == NULL || *cp == '\0') {
 		if ((cp = getenv("TMP")) == NULL || *cp == '\0') {
 		    StrAllocCopy(HomeDir, "C:\\");
@@ -5273,8 +5219,7 @@ PUBLIC time_t LYmktime ARGS2(
     if (!(string && *string))
 	return(0);
     s = string;
-    if (TRACE)
-	fprintf(stderr, "LYmktime: Parsing '%s'\n", s);
+    CTRACE(tfp, "LYmktime: Parsing '%s'\n", s);
 
     /*
      *	Skip any lead alphabetic "Day, " field and
@@ -5490,9 +5435,10 @@ PUBLIC time_t LYmktime ARGS2(
 		     seconds);
     if (absolute == FALSE && clock2 <= time(NULL))
 	clock2 = (time_t)0;
-    if (TRACE && clock2 > 0)
-	fprintf(stderr,
-		"LYmktime: clock=%ld, ctime=%s", (long) clock2, ctime(&clock2));
+    if (clock2 > 0)
+	CTRACE(tfp, "LYmktime: clock=%ld, ctime=%s",
+		    (long) clock2,
+		    ctime(&clock2));
 
     return(clock2);
 }
diff --git a/src/LYexit.c b/src/LYexit.c
index 1e2fb11c..16e1ce9c 100644
--- a/src/LYexit.c
+++ b/src/LYexit.c
@@ -144,8 +144,7 @@ void (*function)();
      *  Check for available space.
      */
     if (topOfStack == ATEXITSIZE) {
-	if (TRACE)
-	    fprintf(stderr, "(LY)atexit: Too many functions, ignoring one!\n");
+	CTRACE(tfp, "(LY)atexit: Too many functions, ignoring one!\n");
 	return(-1);
     }
 
diff --git a/src/UCAuto.c b/src/UCAuto.c
index e5f11af9..269baf35 100644
--- a/src/UCAuto.c
+++ b/src/UCAuto.c
@@ -83,9 +83,7 @@ PRIVATE void call_setfont ARGS3(
     }
 
     if (*T_setfont_cmd) {
-	if (TRACE) {
-	    fprintf(stderr, "Executing setfont: '%s'\n", T_setfont_cmd);
-	}
+	CTRACE(tfp, "Executing setfont: '%s'\n", T_setfont_cmd);
 	system(T_setfont_cmd);
     }
 }
@@ -339,10 +337,7 @@ PUBLIC void UCChangeTerminalCodepage ARGS2(
 	int,		newcs,
 	LYUCcharset *,	p)
 {
-    if (TRACE) {
-	fprintf(stderr,
-		"UCChangeTerminalCodepage: Called, but not implemented!");
-    }
+    CTRACE(tfp, "UCChangeTerminalCodepage: Called, but not implemented!");
 }
 #endif /* LINUX */
 
@@ -354,9 +349,6 @@ PUBLIC void UCChangeTerminalCodepage ARGS2(
 	int,		newcs GCC_UNUSED,
 	LYUCcharset *,	p GCC_UNUSED)
 {
-    if (TRACE) {
-	fprintf(stderr,
-		"UCChangeTerminalCodepage: Called, but not implemented!");
-    }
+    CTRACE(tfp, "UCChangeTerminalCodepage: Called, but not implemented!");
 }
 #endif /* EXP_CHARTRANS_AUTOSWITCH */
diff --git a/src/UCdomap.c b/src/UCdomap.c
index 20d78e92..1e50a578 100644
--- a/src/UCdomap.c
+++ b/src/UCdomap.c
@@ -473,8 +473,7 @@ PRIVATE void UC_con_set_trans ARGS3(
   u16 *ptrans;
 
     if (!UC_valid_UC_charset(UC_charset_in_hndl)) {
-	if (TRACE)
-	    fprintf(stderr, "UC_con_set_trans: Invalid charset handle %d.\n",
+	CTRACE(tfp, "UC_con_set_trans: Invalid charset handle %d.\n",
 		    UC_charset_in_hndl);
 	return;
     }
@@ -782,8 +781,7 @@ PRIVATE int UC_con_set_unimap ARGS2(
     u16 *p;
 
     if (!UC_valid_UC_charset(UC_charset_out_hndl)) {
-	if (TRACE)
-	    fprintf(stderr, "UC_con_set_unimap: Invalid charset handle %d.\n",
+	CTRACE(tfp, "UC_con_set_unimap: Invalid charset handle %d.\n",
 		    UC_charset_out_hndl);
 	return -1;
     }
@@ -1190,11 +1188,8 @@ PRIVATE int UC_MapGN ARGS2(
 	UCInfo[UChndl].GN = Gn;
 	UC_GNhandles[Gn] = UChndl;
     }
-    if (TRACE) {
-	fprintf(stderr,
-		"UC_MapGN: Using %d <- %d (%s)\n",
+    CTRACE(tfp, "UC_MapGN: Using %d <- %d (%s)\n",
 		Gn, UChndl, UCInfo[UChndl].MIMEname);
-    }
     UC_con_set_trans(UChndl,Gn,update_flag);
     return Gn;
 }
@@ -1837,17 +1832,17 @@ PRIVATE int UC_Register_with_LYCharSets ARGS4(
 	CONST char *,	UC_LYNXcharset,
 	int,		lowest_eightbit)
 {
-  int i, LYhndl, found;
-  char **repl;
+    int i, LYhndl, found;
+    char **repl;
 
-  LYhndl = -1;
+    LYhndl = -1;
     if (LYNumCharsets == 0) {
 	/*
 	 *  Initialize here; so whoever changes
 	 *  LYCharSets.c doesn't have to count...
 	 */
 	for (i = 0; (i < MAXCHARSETS) && LYchar_set_names[i]; i++) {
-      LYNumCharsets = i+1;
+	    LYNumCharsets = i+1;
 	}
     }
 
@@ -1867,40 +1862,37 @@ PRIVATE int UC_Register_with_LYCharSets ARGS4(
 	}
     }
 
-  if (LYhndl < 0) {		/* not found */
-    found = 0;
-    if (LYNumCharsets >= MAXCHARSETS) {
-	    if (TRACE) {
-		fprintf(stderr,
-		    "UC_Register_with_LYCharSets: Too many. Ignoring %s/%s.",
+    if (LYhndl < 0) {		/* not found */
+	found = 0;
+	if (LYNumCharsets >= MAXCHARSETS) {
+	    CTRACE(tfp, "UC_Register_with_LYCharSets: Too many. Ignoring %s/%s.",
 			UC_MIMEcharset, UC_LYNXcharset);
-	    }
-      return -1;
-    }
+	    return -1;
+	}
 	/*
 	 *  Add to LYCharSets.c lists.
 	 */
 	LYhndl = LYNumCharsets;
 	LYNumCharsets ++;
-    LYlowest_eightbit[LYhndl] = 999;
-    LYCharSets[LYhndl] = SevenBitApproximations;
+	LYlowest_eightbit[LYhndl] = 999;
+	LYCharSets[LYhndl] = SevenBitApproximations;
 	/*
 	 *  Hmm, try to be conservative here.
 	 */
 	LYchar_set_names[LYhndl] = UC_LYNXcharset;
 	LYchar_set_names[LYhndl+1] = NULL;
 	/*
-	 *  Terminating NULL may be looked for by Lynx code.
-	 */
+	*  Terminating NULL may be looked for by Lynx code.
+	*/
     } else {
 	found = 1;
     }
-  LYCharSet_UC[LYhndl].UChndl = s;
+    LYCharSet_UC[LYhndl].UChndl = s;
     /*
      *	Can we just copy the pointer?  Hope so...
      */
-  LYCharSet_UC[LYhndl].MIMEname = UC_MIMEcharset;
-  LYCharSet_UC[LYhndl].enc = UCInfo[s].enc;
+    LYCharSet_UC[LYhndl].MIMEname = UC_MIMEcharset;
+    LYCharSet_UC[LYhndl].enc = UCInfo[s].enc;
 
     /*
      *	@@@ We really SHOULD get more info from the table files,
@@ -1908,22 +1900,22 @@ PRIVATE int UC_Register_with_LYCharSets ARGS4(
      *	that info...  For now, let's try it without. - KW
      */
     if (lowest_eightbit < LYlowest_eightbit[LYhndl]) {
-    LYlowest_eightbit[LYhndl] = lowest_eightbit;
+	LYlowest_eightbit[LYhndl] = lowest_eightbit;
     } else if (lowest_eightbit > LYlowest_eightbit[LYhndl]) {
-    UCInfo[s].lowest_eight = LYlowest_eightbit[LYhndl];
+	UCInfo[s].lowest_eight = LYlowest_eightbit[LYhndl];
     }
 
-  if (!found && LYhndl > 0) {
-    repl = UC_setup_LYCharSets_repl(s,UCInfo[s].lowest_eight);
-    if (repl) {
-      LYCharSets[LYhndl] = repl;
+    if (!found && LYhndl > 0) {
+	repl = UC_setup_LYCharSets_repl(s,UCInfo[s].lowest_eight);
+	if (repl) {
+	    LYCharSets[LYhndl] = repl;
 	    /*
 	     *	Remember to FREE at exit.
 	     */
-      remember_allocated_LYCharSets[LYhndl]=repl;
+	    remember_allocated_LYCharSets[LYhndl]=repl;
+	}
     }
-  }
-  return LYhndl;
+    return LYhndl;
 }
 
 /*
@@ -1956,10 +1948,8 @@ PUBLIC void UC_Charset_Setup ARGS8(
 	s = found;
     } else {
 	if (UCNumCharsets >= MAXCHARSETS) {
-	    if (TRACE) {
-		fprintf(stderr, "UC_Charset_Setup: Too many. Ignoring %s/%s.",
-				UC_MIMEcharset, UC_LYNXcharset);
-	    }
+	    CTRACE(tfp, "UC_Charset_Setup: Too many. Ignoring %s/%s.",
+			UC_MIMEcharset, UC_LYNXcharset);
 	    return;
 	}
 	s = UCNumCharsets;
diff --git a/userdefs.h b/userdefs.h
index d191cb99..cc43f989 100644
--- a/userdefs.h
+++ b/userdefs.h
@@ -1202,7 +1202,7 @@
  * the version definition with the Project Version on checkout. Just
  * ignore it. - kw */
 /* $Format: "#define LYNX_VERSION \"$ProjectVersion$\""$ */
-#define LYNX_VERSION "2.8.1dev.6"
+#define LYNX_VERSION "2.8.1dev.7"
 
 #ifndef MAXINT
 #define MAXINT 2147483647	/* max integer */