about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>1998-04-23 12:35:00 -0400
committerThomas E. Dickey <dickey@invisible-island.net>1998-04-23 12:35:00 -0400
commit2a94396ccd9cf5ade728c53e02cba28e06af4378 (patch)
tree0ee1558f3e81f97725d83250f944aafa4eb43d54 /src
parent84271e583d80f546251ea914a33f8c537fddbac7 (diff)
downloadlynx-snapshots-2a94396ccd9cf5ade728c53e02cba28e06af4378.tar.gz
snapshot of project "lynx", label v2-8-1dev_7
Diffstat (limited to 'src')
-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
29 files changed, 820 insertions, 1255 deletions
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;