about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2001-02-09 03:00:04 -0500
committerThomas E. Dickey <dickey@invisible-island.net>2001-02-09 03:00:04 -0500
commit2a786b2632ff4fe945cb5826f7a378778caf72eb (patch)
treedc9ae455c293e2362034f81eb872eccf5435992f /src
parentd31fb3c41be5d6e079d415087eda3c03cc34bcdb (diff)
downloadlynx-snapshots-2a786b2632ff4fe945cb5826f7a378778caf72eb.tar.gz
snapshot of project "lynx", label v2-8-4dev_17
Diffstat (limited to 'src')
-rw-r--r--src/GridText.c223
-rw-r--r--src/GridText.h4
-rw-r--r--src/HTAlert.c27
-rw-r--r--src/HTFWriter.c2
-rw-r--r--src/HTML.c61
-rw-r--r--src/LYBookmark.c54
-rw-r--r--src/LYCgi.c2
-rw-r--r--src/LYCharSets.h10
-rw-r--r--src/LYClean.c8
-rw-r--r--src/LYCookie.c5
-rw-r--r--src/LYCurses.c210
-rw-r--r--src/LYCurses.h85
-rw-r--r--src/LYEditmap.c2
-rw-r--r--src/LYForms.c55
-rw-r--r--src/LYGetFile.c33
-rw-r--r--src/LYGlobalDefs.h12
-rw-r--r--src/LYHash.c5
-rw-r--r--src/LYHash.h31
-rw-r--r--src/LYKeymap.c26
-rw-r--r--src/LYKeymap.h15
-rw-r--r--src/LYLocal.c10
-rw-r--r--src/LYMail.c89
-rw-r--r--src/LYMain.c164
-rw-r--r--src/LYMainLoop.c332
-rw-r--r--src/LYNews.c54
-rw-r--r--src/LYOptions.c524
-rw-r--r--src/LYPrint.c10
-rw-r--r--src/LYReadCFG.c18
-rw-r--r--src/LYShowInfo.c2
-rw-r--r--src/LYStrings.c134
-rw-r--r--src/LYStrings.h11
-rw-r--r--src/LYStructs.h2
-rw-r--r--src/LYStyle.c176
-rw-r--r--src/LYUtils.c533
-rw-r--r--src/LYUtils.h15
-rw-r--r--src/LYrcFile.c2
-rw-r--r--src/TRSTable.c667
-rw-r--r--src/TRSTable.h11
-rw-r--r--src/UCdomap.c75
39 files changed, 2198 insertions, 1501 deletions
diff --git a/src/GridText.c b/src/GridText.c
index e8e40d5b..94d45d17 100644
--- a/src/GridText.c
+++ b/src/GridText.c
@@ -348,7 +348,7 @@ struct _HText {
 	BOOLEAN			soft_dquotes;
 	BOOLEAN			old_dtd;
 	int			keypad_mode;
-	int			disp_lines;		/* Screen size */
+	int			disp_lines;	/* Screen size */
 	int			disp_cols;
 #endif
 	HTLine *		last_line;
@@ -1118,7 +1118,7 @@ PRIVATE int display_line ARGS4(
      *  writing.
      */
     buffer[0] = buffer[1] = buffer[2] = '\0';
-    clrtoeol();
+    LYclrtoeol();
 
     /*
      *  Add offset, making sure that we do not
@@ -1137,7 +1137,7 @@ PRIVATE int display_line ARGS4(
     else
 #endif
     for (i = 0; i < j; i++)
-	addch (' ');
+	LYaddch (' ');
 #endif /* USE_SLANG */
 
     /*
@@ -1232,7 +1232,7 @@ PRIVATE int display_line ARGS4(
 #ifndef USE_COLOR_STYLE
 	    case LY_UNDERLINE_START_CHAR:
 		if (dump_output_immediately && use_underscore) {
-		    addch('_');
+		    LYaddch('_');
 		    i++;
 		} else {
 		    inunderline = YES;
@@ -1251,7 +1251,7 @@ PRIVATE int display_line ARGS4(
 
 	    case LY_UNDERLINE_END_CHAR:
 		if (dump_output_immediately && use_underscore) {
-		    addch('_');
+		    LYaddch('_');
 		    i++;
 		} else {
 		    inunderline = NO;
@@ -1283,7 +1283,7 @@ PRIVATE int display_line ARGS4(
 #endif
 	    case LY_SOFT_NEWLINE:
 		if (!dump_output_immediately) {
-		    addch('+');
+		    LYaddch('+');
 		    i++;
 		}
 		break;
@@ -1355,7 +1355,7 @@ PRIVATE int display_line ARGS4(
 		if (utf_extra) {
 		    strncpy(&buffer[1], data, utf_extra);
 		    buffer[utf_extra+1] = '\0';
-		    addstr(buffer);
+		    LYaddstr(buffer);
 		    buffer[1] = '\0';
 		    data += utf_extra;
 		    utf_extra = 0;
@@ -1373,7 +1373,7 @@ PRIVATE int display_line ARGS4(
 		    buffer[2] = '\0';
 		    data++;
 		    i++;
-		    addstr(buffer);
+		    LYaddstr(buffer);
 		    buffer[1] = '\0';
 		    /*
 		     *  For now, load 'M' into LastDisplayChar,
@@ -1392,12 +1392,12 @@ PRIVATE int display_line ARGS4(
 #if defined(UNIX) || defined(VMS)
 		    if (!dump_output_immediately &&
 			UCH(buffer[0]) == 128+27) {
-			addstr("~^");
+			LYaddstr("~^");
 			buffer[0] ^= 0xc0;
 		    }
 #endif
 #endif
-		    addstr(buffer);
+		    LYaddstr(buffer);
 		    LastDisplayChar = buffer[0];
 		}
 	} /* end of switch */
@@ -1413,7 +1413,7 @@ after_while:
     /*
      *  Add the return.
      */
-    addch('\n');
+    LYaddch('\n');
 
 #if defined(SHOW_WHEREIS_TARGETS) && !defined(USE_COLOR_STYLE)
     if (intarget)
@@ -1446,6 +1446,7 @@ PRIVATE void display_title ARGS1(
     char *cp = NULL;
     unsigned char *tmp = NULL;
     int i = 0, j = 0;
+    int limit;
 
     /*
      *  Make sure we have a text structure. - FM
@@ -1484,7 +1485,8 @@ PRIVATE void display_title ARGS1(
     /*
      *  Generate the page indicator (percent) string.
      */
-    if (LYcols < 10) {
+    limit = LYscreenWidth();
+    if (limit < 10) {
 	percent[0] = '\0';	/* Null string */
     } else if ((display_lines) <= 0 && LYlines > 0 &&
 	text->top_of_screen <= 99999 && text->Lines <= 999999) {
@@ -1538,17 +1540,17 @@ PRIVATE void display_title ARGS1(
 	    FREE(tmp);
 	}
     }
-    move(0, 0);
-    clrtoeol();
+    LYmove(0, 0);
+    LYclrtoeol();
 #if defined(SH_EX) && defined(KANJI_CODE_OVERRIDE)
-    addstr(str_kcode(last_kcode));
+    LYaddstr(str_kcode(last_kcode));
 #endif
     if (text->top_of_screen > 0 && HText_hasToolbar(text)) {
-	addch('#');
+	LYaddch('#');
     }
-    i = (LYcols - 1) - strlen(percent) - strlen(title);
+    i = (limit - 1) - strlen(percent) - strlen(title);
     if (i >= CHAR_WIDTH) {
-	move(0, i);
+	LYmove(0, i);
     } else {
 	/*
 	 *  Note that this truncation is not taking into
@@ -1558,23 +1560,23 @@ PRIVATE void display_title ARGS1(
 #ifdef SH_EX	/* 1999/06/15 (Tue) 10:17:28 */
 	int last;
 	last = (int)strlen(percent) + CHAR_WIDTH;
-	if (LYcols - 3 >= last) {
-	    title[(LYcols - 3) - last] = '.';
-	    title[(LYcols - 2) - last] = '.';
-	    title[(LYcols - 1) - last] = '\0';
+	if (limit - 3 >= last) {
+	    title[(limit - 3) - last] = '.';
+	    title[(limit - 2) - last] = '.';
+	    title[(limit - 1) - last] = '\0';
 	} else {
-	    title[(LYcols - 1) - last] = '\0';
+	    title[(limit - 1) - last] = '\0';
 	}
 #else
-	if ((i = ((LYcols - 2) - strlen(percent)) - CHAR_WIDTH) >= 0)
+	if ((i = ((limit - 2) - strlen(percent)) - CHAR_WIDTH) >= 0)
 	    title[i] = '\0';
 #endif
-	move(0, CHAR_WIDTH);
+	LYmove(0, CHAR_WIDTH);
     }
-    addstr(title);
+    LYaddstr(title);
     if (percent[0] != '\0')
-	addstr(percent);
-    addch('\n');
+	LYaddstr(percent);
+    LYaddch('\n');
     FREE(title);
 
 #ifdef USE_COLOR_STYLE
@@ -1648,7 +1650,7 @@ PRIVATE void display_scrollbar ARGS1(
 	    LynxChangeStyle(s, ABS_ON, 0);
 	}
 #endif /* USE_COLOR_STYLE */
-	move(1, LYcols - 1);
+	LYmove(1, LYcols - 1);
 	addch_raw(ACS_UARROW);
 #ifdef USE_COLOR_STYLE
 	LynxChangeStyle(s, STACK_OFF, 0);
@@ -1669,11 +1671,11 @@ PRIVATE void display_scrollbar ARGS1(
 	if (i-1 <= h - bot_skip && i > h - bot_skip)
 	    LynxChangeStyle(s_sb_bar, STACK_OFF, 0);
 #endif /* USE_COLOR_STYLE */
-	move(i + off, LYcols - 1);
+	LYmove(i + off, LYcols - 1);
 	if (i > top_skip && i <= h - bot_skip)
-	    addch(ACS_BLOCK);
+	    LYaddch(ACS_BLOCK);
 	else
-	    addch(ACS_CKBOARD);
+	    LYaddch(ACS_CKBOARD);
     }
 #ifdef USE_COLOR_STYLE
     LynxChangeStyle(s_sb_bg, STACK_OFF, 0);
@@ -1689,7 +1691,7 @@ PRIVATE void display_scrollbar ARGS1(
 	    LynxChangeStyle(s, ABS_ON, 0);
 	}
 #endif /* USE_COLOR_STYLE */
-	move(h + 2, LYcols - 1);
+	LYmove(h + 2, LYcols - 1);
 	addch_raw(ACS_DARROW);
 #ifdef USE_COLOR_STYLE
 	LynxChangeStyle(s, STACK_OFF, 0);
@@ -1737,12 +1739,12 @@ PRIVATE void display_page ARGS3(
 	 *  curses packages. - shf@access.digex.net & seldon@eskimo.com
 	 */
 	if (enable_scrollback) {
-	    addch('*');
-	    refresh();
-	    clear();
+	    LYaddch('*');
+	    LYrefresh();
+	    LYclear();
 	}
-	addstr("\n\nError accessing document!\nNo data available!\n");
-	refresh();
+	LYaddstr("\n\nError accessing document!\nNo data available!\n");
+	LYrefresh();
 	nlinks = 0;  /* set number of links to 0 */
 	return;
     }
@@ -1785,12 +1787,12 @@ PRIVATE void display_page ARGS3(
 	    assert(line->next != NULL);
 	} else if (line->next == NULL) {
 	    if (enable_scrollback) {
-		addch('*');
-		refresh();
-		clear();
+		LYaddch('*');
+		LYrefresh();
+		LYclear();
 	    }
-	    addstr("\n\nError drawing page!\nBad HText structure!\n");
-	    refresh();
+	    LYaddstr("\n\nError drawing page!\nBad HText structure!\n");
+	    LYrefresh();
 	    nlinks = 0;  /* set number of links to 0 */
 	    return;
 	}
@@ -1825,9 +1827,9 @@ PRIVATE void display_page ARGS3(
      *  curses packages. - shf@access.digex.net & seldon@eskimo.com
      */
     if (enable_scrollback) {
-	addch('*');
-	refresh();
-	clear();
+	LYaddch('*');
+	LYrefresh();
+	LYclear();
     }
 
 #ifdef USE_COLOR_STYLE
@@ -1890,12 +1892,12 @@ PRIVATE void display_page ARGS3(
 		assert(line != NULL);
 	    } else if (line == NULL) {
 		if (enable_scrollback) {
-		    addch('*');
-		    refresh();
-		    clear();
+		    LYaddch('*');
+		    LYrefresh();
+		    LYclear();
 		}
-		addstr("\n\nError drawing page!\nBad HText structure!\n");
-		refresh();
+		LYaddstr("\n\nError drawing page!\nBad HText structure!\n");
+		LYrefresh();
 		nlinks = 0;  /* set number of links to 0 */
 		return;
 	    }
@@ -1907,7 +1909,7 @@ PRIVATE void display_page ARGS3(
 	    if (!display_partial &&
 		line_number == text->first_lineno_last_disp_partial &&
 		i + line_number <= text->last_lineno_last_disp_partial)
-		move((i + 2), 0);
+		LYmove((i + 2), 0);
 	    else
 #endif
 	    display_line(line, text, i+1, target);
@@ -1964,7 +1966,7 @@ PRIVATE void display_page ARGS3(
 			    /*
 			     *  First printable character of target.
 			     */
-			    move((i + 1), x_pos);
+			    LYmove((i + 1), x_pos);
 			}
 			/*
 			 *  Output all the printable target chars.
@@ -1997,7 +1999,7 @@ PRIVATE void display_page ARGS3(
 			    strncpy(&tmp[1], &line->data[itmp+1], utf_extra);
 			    tmp[utf_extra+1] = '\0';
 			    itmp += utf_extra;
-			    addstr(tmp);
+			    LYaddstr(tmp);
 			    tmp[1] = '\0';
 			    written += (utf_extra + 1);
 			    utf_extra = 0;
@@ -2006,7 +2008,7 @@ PRIVATE void display_page ARGS3(
 			     *  For CJK strings, by Masanobu Kimura.
 			     */
 			    tmp[1] = data[++itmp];
-			    addstr(tmp);
+			    LYaddstr(tmp);
 			    tmp[1] = '\0';
 			    written += 2;
 			} else {
@@ -2014,12 +2016,12 @@ PRIVATE void display_page ARGS3(
 #if defined(UNIX) || defined(VMS)
 			    if (!dump_output_immediately &&
 				UCH(tmp[0]) == 128+27) {
-				addstr("~^");
+				LYaddstr("~^");
 				tmp[0] ^= 0xc0;
 			    }
 #endif
 #endif
-			    addstr(tmp);
+			    LYaddstr(tmp);
 			    written++;
 			}
 		    }
@@ -2039,7 +2041,7 @@ PRIVATE void display_page ARGS3(
 		 *  the end of the line, or not have another hit
 		 *  in it. - FM
 		 */
-		move((i + 2), 0);
+		LYmove((i + 2), 0);
 	    } /* end while */
 #endif /* USE_COLOR_STYLE */
 #endif /* SHOW_WHEREIS_TARGETS */
@@ -2053,8 +2055,8 @@ PRIVATE void display_page ARGS3(
 		 *  Clear remaining lines of display.
 		 */
 		for (i++; i < (display_lines); i++) {
-		    move((i + 1), 0);
-		    clrtoeol();
+		    LYmove((i + 1), 0);
+		    LYclrtoeol();
 		}
 		break;
 	    }
@@ -2257,7 +2259,7 @@ PRIVATE void display_page ARGS3(
 	/*
 	 *  Nothing on the page.
 	 */
-	addstr("\n     Document is empty");
+	LYaddstr("\n     Document is empty");
     }
     display_scrollbar(text);
 
@@ -2285,13 +2287,13 @@ PRIVATE void display_page ARGS3(
 	/*
 	 *  For non-multibyte curses.
 	 *
-	 *  Full repainting is necessary, otherwise only part of a multibyte 
-	 *  character sequence might be written because of curses output 
-	 *  optimizations. 
+	 *  Full repainting is necessary, otherwise only part of a multibyte
+	 *  character sequence might be written because of curses output
+	 *  optimizations.
 	 */
-	clearok(curscr, TRUE); 
+	clearok(curscr, TRUE);
     }
-    refresh();
+    LYrefresh();
 }
 
 
@@ -2316,13 +2318,13 @@ PUBLIC void HText_beginAppend ARGS1(
    is used to try to prevent that lines with UTF-8 chars get wrapped
    by the library when they shouldn't.
    If there is no display library involved, i.e. dump_output_immediately,
-   no such limit should be imposed.  LYcols*6 should be just as good
+   no such limit should be imposed.  MAX_COLS should be just as good
    as any other large value.  (But don't use INT_MAX or something close
    to it to, avoid over/underflow.) - kw */
 #ifdef USE_SLANG
-#define LYcols_cu (dump_output_immediately ? LYcols*6 : SLtt_Screen_Cols)
+#define LYcols_cu (dump_output_immediately ? MAX_COLS : SLtt_Screen_Cols)
 #else
-#define LYcols_cu (dump_output_immediately ? LYcols*6 : LYcols)
+#define LYcols_cu (dump_output_immediately ? MAX_COLS : LYcols)
 #endif
 
 /*	Add a new line of text
@@ -4650,6 +4652,7 @@ PRIVATE int HText_insertBlanksInStblLines ARGS2(
     int *	newpos;
     int		ninserts, lineno;
     int		first_lineno, last_lineno, first_lineno_pass2;
+    int		last_nonempty = -1;
     int		added_chars_before = 0;
     TextAnchor * a;
     int lines_changed = 0;
@@ -4719,6 +4722,8 @@ PRIVATE int HText_insertBlanksInStblLines ARGS2(
 	    int width = HText_TrueLineSize(line, me, FALSE);
 	    if (width > max_width)
 		max_width = width;
+	    if (width && last_nonempty < lineno)
+		last_nonempty = lineno;
 	    CTRACE((tfp, "line %d true/max width:%d/%d oldpos: NONE\r\n",
 		   lineno, width, max_width));
 	    continue;
@@ -4758,6 +4763,8 @@ PRIVATE int HText_insertBlanksInStblLines ARGS2(
 	    int width = HText_TrueLineSize(line, me, FALSE);
 	    if (width > max_width)
 		max_width = width;
+	    if (width && last_nonempty < lineno)
+		last_nonempty = lineno;
 	    if (TRACE) {
 		int ip;
 		CTRACE((tfp, "line %d true/max width:%d/%d oldpos:",
@@ -4856,6 +4863,8 @@ PRIVATE int HText_insertBlanksInStblLines ARGS2(
 	    CTRACE((tfp, " %d:%d", lineno, table_offset - line->offset));
 	    line->offset = table_offset;
 	}
+	if (max_width)
+	    Stbl_update_enclosing(me->stbl, max_width, last_nonempty);
     }
     CTRACE((tfp, " %d:done\r\n", lineno));
     free(oldpos);
@@ -4871,12 +4880,19 @@ PRIVATE int HText_insertBlanksInStblLines ARGS2(
 PUBLIC void HText_cancelStbl ARGS1(
 	HText *,	me)
 {
+    STable_info *stbl;
+
     if (!me || !me->stbl) {
 	CTRACE((tfp, "cancelStbl: ignored.\n"));
 	return;
     }
     CTRACE((tfp, "cancelStbl: ok, will do.\n"));
-    Stbl_free(me->stbl);
+    stbl = me->stbl;
+    while (stbl) {
+	STable_info *enclosing = Stbl_get_enclosing(stbl);
+	Stbl_free(stbl);
+	stbl = enclosing;
+    }
     me->stbl = NULL;
 }
 
@@ -4886,13 +4902,16 @@ PUBLIC void HText_startStblTABLE ARGS2(
 	HText *,	me,
 	short,		alignment)
 {
+    STable_info *current = me->stbl;
+
     if (!me)
 	return;
-    if (me->stbl)
-	HText_cancelStbl(me);	/* auto cancel previously open table */
+    if (current)
+	new_line(me);
     me->stbl = Stbl_startTABLE(alignment);
     if (me->stbl) {
 	CTRACE((tfp, "startStblTABLE: started.\n"));
+	Stbl_set_enclosing(me->stbl, current, me->last_anchor_before_stbl);
 	me->last_anchor_before_stbl = me->last_anchor;
     } else {
 	CTRACE((tfp, "startStblTABLE: failed.\n"));
@@ -4900,14 +4919,17 @@ PUBLIC void HText_startStblTABLE ARGS2(
 }
 
 /*	Finish simple table handling
-*/
-PUBLIC void HText_endStblTABLE ARGS1(
+ *	Return TRUE if the table is nested inside another table.
+ */
+PUBLIC int HText_endStblTABLE ARGS1(
 	HText *,	me)
 {
     int ncols, lines_changed = 0;
+    STable_info *enclosing;
+
     if (!me || !me->stbl) {
 	CTRACE((tfp, "endStblTABLE: ignored.\n"));
-	return;
+	return FALSE;
     }
     CTRACE((tfp, "endStblTABLE: ok, will try.\n"));
     ncols = Stbl_finishTABLE(me->stbl);
@@ -4922,8 +4944,11 @@ PUBLIC void HText_endStblTABLE ARGS1(
 	NumOfLines_partial -= lines_changed;  /* fake */
 #endif  /* DISP_PARTIAL */
     }
+    enclosing = Stbl_get_enclosing(me->stbl);
+    me->last_anchor_before_stbl = Stbl_get_last_anchor_before(me->stbl);
     Stbl_free(me->stbl);
-    me->stbl = NULL;
+    me->stbl = enclosing;
+    return enclosing != 0;
 }
 
 /*	Start simple table row
@@ -5160,7 +5185,7 @@ PUBLIC BOOL HText_isAnchorBlank ARGS2(
 	HTLine *start = last;
 	int CurBlankExtent = 0;
 	int BlankExtent = 0;
-	
+
 	int extent_adjust = (text->chars + last->size) - a->start -
 		     (text->Lines - a->line_num);
 
@@ -6867,7 +6892,7 @@ PUBLIC CONST char * HText_getTitle NOARGS
 	  HTAnchor_title(HTMainText->node_anchor) : 0);
 }
 
-#ifdef USE_HASH
+#ifdef USE_COLOR_STYLE
 PUBLIC CONST char *HText_getStyle NOARGS
 {
    return(HTMainText ?
@@ -12617,7 +12642,7 @@ PUBLIC int HText_ExtEditForm ARGS1(
 	    (cp = strchr(lp, ' ')) != NULL &&
 	    (cp-lp) < start_anchor->input_field->size - 1) {
 	    LYFixCursesOn("ask for confirmation:");
-	    erase();		/* don't show previous state */
+	    LYerase();		/* don't show previous state */
 	    if (HTConfirmDefault(gettext("Wrap lines to fit displayed area?"),
 				 NO)) {
 		wanted_fieldlen_wrap = start_anchor->input_field->size - 1;
@@ -13249,7 +13274,7 @@ PRIVATE void redraw_part_of_line ARGS4(
 #ifndef USE_COLOR_STYLE
 	    case LY_UNDERLINE_START_CHAR:
 		if (dump_output_immediately && use_underscore) {
-		    addch('_');
+		    LYaddch('_');
 		    i++;
 		} else {
 		    start_underline();
@@ -13258,7 +13283,7 @@ PRIVATE void redraw_part_of_line ARGS4(
 
 	    case LY_UNDERLINE_END_CHAR:
 		if (dump_output_immediately && use_underscore) {
-		    addch('_');
+		    LYaddch('_');
 		    i++;
 		} else {
 		    stop_underline();
@@ -13276,7 +13301,7 @@ PRIVATE void redraw_part_of_line ARGS4(
 #endif
 	    case LY_SOFT_NEWLINE:
 		if (!dump_output_immediately)
-		    addch('+');
+		    LYaddch('+');
 		break;
 
 	    case LY_SOFT_HYPHEN:
@@ -13333,7 +13358,7 @@ PRIVATE void redraw_part_of_line ARGS4(
 		if (utf_extra) {
 		    strncpy(&buffer[1], data, utf_extra);
 		    buffer[utf_extra+1] = '\0';
-		    addstr(buffer);
+		    LYaddstr(buffer);
 		    buffer[1] = '\0';
 		    data += utf_extra;
 		    utf_extra = 0;
@@ -13343,7 +13368,7 @@ PRIVATE void redraw_part_of_line ARGS4(
 		     */
 		    buffer[1] = *data;
 		    data++;
-		    addstr(buffer);
+		    LYaddstr(buffer);
 		    buffer[1] = '\0';
 		    /*
 		     *  For now, load 'M' into LastDisplayChar,
@@ -13362,12 +13387,12 @@ PRIVATE void redraw_part_of_line ARGS4(
 #if defined(UNIX) || defined(VMS)
 		    if (!dump_output_immediately &&
 			UCH(buffer[0]) == 128+27) {
-			addstr("~^");
+			LYaddstr("~^");
 			buffer[0] ^= 0xc0;
 		    }
 #endif
 #endif
-		    addstr(buffer);
+		    LYaddstr(buffer);
 		    LastDisplayChar = buffer[0];
 		}
 	} /* end of switch */
@@ -13554,7 +13579,7 @@ PRIVATE void move_to_glyph ARGS10(
 #ifdef SHOW_WHEREIS_TARGETS
 		if (intarget) {
 		    if (i_after_tgt > i) {
-			move(YP, i);
+			LYmove(YP, i);
 			if (flag) {
 			    drawing = YES;
 			    drawingtarget = NO;
@@ -13703,7 +13728,7 @@ PRIVATE void move_to_glyph ARGS10(
 
 	    case LY_SOFT_NEWLINE:
 		if (drawing) {
-		    addch('+');
+		    LYaddch('+');
 		}
 		i++;
 		break;
@@ -13764,7 +13789,7 @@ PRIVATE void move_to_glyph ARGS10(
 			    lynx_stop_link_color (flag, inU);
 			}
 			if (incurlink && !drawing) {
-			    move(YP, i);
+			    LYmove(YP, i);
 			    if (inunderline)	inU = YES;
 			    if (flag && (i == XP_link || i == XP - 1)) {
 				lynx_start_link_color (flag, inU);
@@ -13792,7 +13817,7 @@ PRIVATE void move_to_glyph ARGS10(
 #endif /* SHOW_WHEREIS_TARGETS */
 		    if (incurlink) {
 			if (!drawing) {
-			    move(YP, i);
+			    LYmove(YP, i);
 			    if (inunderline)	inU = YES;
 			    lynx_start_link_color (flag, inU);
 			    drawing = YES;
@@ -13830,7 +13855,7 @@ PRIVATE void move_to_glyph ARGS10(
 		    strncpy(&buffer[1], data, utf_extra);
 		    buffer[utf_extra+1] = '\0';
 		    if (!drawing && i >= XP_draw_min) {
-			move(YP, i - 1);
+			LYmove(YP, i - 1);
 			drawing = YES;
 #if defined(SHOW_WHEREIS_TARGETS)
 			if (intarget) {
@@ -13845,7 +13870,7 @@ PRIVATE void move_to_glyph ARGS10(
 				start_underline();
 			}
 		    }
-		    addstr(buffer);
+		    LYaddstr(buffer);
 		    buffer[1] = '\0';
 		    sdata += utf_extra; data += utf_extra;
 		    utf_extra = 0;
@@ -13855,7 +13880,7 @@ PRIVATE void move_to_glyph ARGS10(
 		     */
 		    if (drawing && (i < LYcols - 1)) {
 			buffer[1] = *data;
-			addstr(buffer);
+			LYaddstr(buffer);
 			buffer[1] = '\0';
 		    }
 		    i++;
@@ -13878,12 +13903,12 @@ PRIVATE void move_to_glyph ARGS10(
 #if defined(UNIX) || defined(VMS)
 			if (!dump_output_immediately &&
 			    UCH(buffer[0]) == 128+27) {
-			    addstr("~^");
+			    LYaddstr("~^");
 			    buffer[0] ^= 0xc0;
 			}
 #endif
 #endif
-			addstr(buffer);
+			LYaddstr(buffer);
 		    }
 		    LastDisplayChar = buffer[0];
 		}
@@ -13891,7 +13916,7 @@ PRIVATE void move_to_glyph ARGS10(
     } /* end of while */
 
     if (!drawing) {
-	move(YP, i);
+	LYmove(YP, i);
 	lynx_start_link_color (flag, inU);
     } else {
 #if defined(SHOW_WHEREIS_TARGETS)
@@ -13975,7 +14000,7 @@ PUBLIC void LYMoveToLink ARGS6(
 	move_to_glyph(links[cur].ly, links[cur].lx, XP_draw_min,
 		      "", 0, links[cur].lx,
 		      target, hightext, flags, utf_flag);
-	/* move(links[cur].ly, links[cur].lx); */
+	/* LYmove(links[cur].ly, links[cur].lx); */
     }
 }
 #endif /* !USE_COLOR_STYLE */
@@ -14007,11 +14032,11 @@ PUBLIC void redraw_lines_of_link ARGS1(
     todr2 = (links[cur].hightext2 && links[cur].ly < display_lines) ?
 	    todr1->next : 0;
 
-    move(links[cur].ly,  links[cur].lx);
+    LYmove(links[cur].ly,  links[cur].lx);
     redraw_part_of_line (todr1, links[cur].hightext,
 			 strlen(links[cur].hightext),  HTMainText);
     if (todr2) {
-	move(links[cur].ly+1,links[cur].hightext2_offset);
+	LYmove(links[cur].ly+1,links[cur].hightext2_offset);
 	redraw_part_of_line (todr2, links[cur].hightext2,
 			     strlen(links[cur].hightext2),  HTMainText);
     }
diff --git a/src/GridText.h b/src/GridText.h
index 874179ad..843e8bd9 100644
--- a/src/GridText.h
+++ b/src/GridText.h
@@ -106,7 +106,7 @@ extern CONST char * HText_getContentBase NOPARAMS;
 extern CONST char * HText_getContentLocation NOPARAMS;
 extern CONST char * HText_getMessageID NOPARAMS;
 extern CONST char * HText_getRevTitle NOPARAMS;
-#ifdef USE_HASH
+#ifdef USE_COLOR_STYLE
 extern CONST char * HText_getStyle NOPARAMS;
 #endif
 extern void HText_setMainTextOwner PARAMS((CONST char * owner));
@@ -174,7 +174,7 @@ extern char * HText_HiddenLinkAt PARAMS((HText *text, int number));
 /* "simple table" stuff */
 extern void HText_cancelStbl PARAMS((HText *));
 extern void HText_startStblTABLE PARAMS((HText *, short));
-extern void HText_endStblTABLE PARAMS((HText *));
+extern int HText_endStblTABLE PARAMS((HText *));
 extern void HText_startStblTR PARAMS((HText *, short));
 extern void HText_endStblTR PARAMS((HText *));
 extern void HText_startStblTD PARAMS((HText *, int, int, short, BOOL));
diff --git a/src/HTAlert.c b/src/HTAlert.c
index e51d07e9..27fab50f 100644
--- a/src/HTAlert.c
+++ b/src/HTAlert.c
@@ -358,10 +358,7 @@ PUBLIC int HTConfirmDefault ARGS2(CONST char *, Msg, int, Dft)
 		c = TOUPPER(*msg_no);
 	    }
 #endif /* VMS */
-	    if (LYCharIsINTERRUPT(c)) { /* remember we had ^G or ^C */
-		conf_cancelled = YES;
-		result = NO;
-	    } else if (c == TOUPPER(*msg_yes)) {
+	    if (c == TOUPPER(*msg_yes)) {
 		result = YES;
 	    } else if (c == TOUPPER(*msg_no)) {
 		result = NO;
@@ -369,6 +366,9 @@ PUBLIC int HTConfirmDefault ARGS2(CONST char *, Msg, int, Dft)
 		result = YES;
 	    } else if (fallback_n && c == fallback_n) {
 		result = NO;
+	    } else if (LYCharIsINTERRUPT(c)) { /* remember we had ^G or ^C */
+		conf_cancelled = YES;
+		result = NO;
 	    } else if (Dft != DFT_CONFIRM) {
 		result = Dft;
 		break;
@@ -761,7 +761,7 @@ PUBLIC BOOL HTConfirmCookie ARGS4(
 	     * NOTE TO TRANSLATORS:  If the prompt has been rendered into
 	     * another language, and if yes/no are distinct, assume the
 	     * translator can make an ordered list in parentheses with one
-	     * capital letter for each as we assumed in HTConfirmDefault(). 
+	     * capital letter for each as we assumed in HTConfirmDefault().
 	     * The list has to be in the same order as in the original message,
 	     * and the four capital letters chosen to not match those in the
 	     * original unless they have the same position.
@@ -810,11 +810,10 @@ PUBLIC BOOL HTConfirmCookie ARGS4(
 		return TRUE;
 
 	    case 'N':
-	    case LYCharINTERRUPT2:	/* Ctrl-G */
-	    case LYCharINTERRUPT1:	/* Ctrl-C */
 		/*
 		**  Reject the cookie.
 		*/
+	      reject:
 		HTUserMsg(REJECTING_COOKIE);
 		return FALSE;
 
@@ -834,6 +833,8 @@ PUBLIC BOOL HTConfirmCookie ARGS4(
 		return TRUE;
 
 	    default:
+		if (LYCharIsINTERRUPT(ch))
+		    goto reject;
 		continue;
 	}
     }
@@ -892,15 +893,15 @@ PUBLIC int HTConfirmPostRedirect ARGS2(
 
     if (user_mode == NOVICE_MODE) {
 	on_screen = 2;
-	move(LYlines-2, 0);
+	LYmove(LYlines-2, 0);
 	HTSprintf0(&StatusInfo, SERVER_ASKED_FOR_REDIRECTION, server_status);
-	addstr(StatusInfo);
-	clrtoeol();
-	move(LYlines-1, 0);
+	LYaddstr(StatusInfo);
+	LYclrtoeol();
+	LYmove(LYlines-1, 0);
 	HTSprintf0(&url, "URL: %.*s",
 		    (LYcols < 250 ? LYcols-6 : 250), Redirecting_url);
-	addstr(url);
-	clrtoeol();
+	LYaddstr(url);
+	LYclrtoeol();
 	if (server_status == 301) {
 	    _statusline(PROCEED_GET_CANCEL);
 	} else {
diff --git a/src/HTFWriter.c b/src/HTFWriter.c
index 41cd9310..c19dcca3 100644
--- a/src/HTFWriter.c
+++ b/src/HTFWriter.c
@@ -220,7 +220,7 @@ PRIVATE void HTFWriter_free ARGS1(HTStream *, me)
 		     */
 		    if (!dump_output_immediately) {
 			lynx_force_repaint();
-			refresh();
+			LYrefresh();
 		    }
 		    HTAlert(ERROR_UNCOMPRESSING_TEMP);
 		    LYRemoveTemp(me->anchor->FileCache);
diff --git a/src/HTML.c b/src/HTML.c
index 78638520..e14f453e 100644
--- a/src/HTML.c
+++ b/src/HTML.c
@@ -1445,46 +1445,17 @@ PRIVATE int HTML_start_element ARGS6(
 		present[HTML_LINK_REL] && value[HTML_LINK_REL]) {
 		/*
 		 *  Ignore style sheets, for now. - FM
+		 *
+		 * lss and css have different syntax - lynx shouldn't try to
+		 * parse them now (it tries to parse them as lss, so it exits
+		 * with error message on the 1st non-empty line) - VH
 		 */
-/*  lss and css has different syntax - lynx shouldn't try to
-    parse them now (it tries to parse them as lss, so it exits with
-    error message on the 1st non-empty line) - VH
-*/
 #ifndef USE_COLOR_STYLE
 		if (!strcasecomp(value[HTML_LINK_REL], "StyleSheet") ||
 		    !strcasecomp(value[HTML_LINK_REL], "Style")) {
 		    CTRACE((tfp, "HTML: StyleSheet link found.\n"));
-#ifdef LINKEDSTYLES
-		    if (href && *href != '\0')
-		    {
-			int res = -999;
-			if ((url_type = is_url(href)) == 0 ||
-			    (url_type == FILE_URL_TYPE && LYisLocalFile(href))) {
-			    if (url_type == FILE_URL_TYPE) {
-				temp = HTParse(href, "", PARSE_PATH+PARSE_PUNCTUATION);
-				HTUnEscape(temp);
-				if (temp && *temp != '\0') {
-				    res = style_readFromFile(temp);
-				    if (res != 0)
-					StrAllocCopy(href, temp);
-				}
-				FREE(temp);
-			    } else {
-				res = style_readFromFile(href);
-			    }
-			}
-			CTRACE((tfp, "CSS: StyleSheet=%s %d\n", href, res));
-			if (res == 0)
-			    HTAnchor_setStyle (me->node_anchor, href);
-		    }
-		    else {
-			CTRACE((tfp,
-				"        non-local StyleSheets not yet implemented.\n"));
-		    }
-#else
 		    CTRACE((tfp,
 				"        StyleSheets not yet implemented.\n"));
-#endif
 		    FREE(href);
 		    break;
 		}
@@ -1556,6 +1527,14 @@ PRIVATE int HTML_start_element ARGS6(
 			StrAllocCopy(temp, "RelTitle: ");
 			StrAllocCat(temp, value[HTML_LINK_REL]);
 		    }
+#ifndef DISABLE_BIBP
+		} else if (!strcasecomp(value[HTML_LINK_REL], "citehost")) {
+		    /*  Citehost determination for bibp links. - RDC */
+		    HTAnchor_setCitehost(me->node_anchor, href);
+		    CTRACE((tfp, "HTML: citehost '%s' found\n", href));
+		    FREE(href);
+		    break;
+#endif
 		} else {
 		    CTRACE((tfp, "HTML: LINK with REL=\"%s\" ignored.\n",
 				 value[HTML_LINK_REL]));
@@ -5815,15 +5794,14 @@ PRIVATE int HTML_start_element ARGS6(
 	 *
 	 *  Also notify simple table tracking code unless
 	 *  in a preformatted section, or (currently) non-left
-	 *  alignment.  But first cancel tracking any already
-	 *  open (enclosing) table.
+	 *  alignment.
 	 *
 	 *  If page author is using a TABLE within PRE, it's probably
 	 *  formatted specifically to work well for Lynx without simple
 	 *  table tracking code.  Cancel tracking, it would only make
 	 *  things worse. - kw
 	 */
-	HText_cancelStbl(me->text);
+	HText_cancelStbl(me->text); /* Not needed with new TRST */
 	if (me->inA) {
 	    SET_SKIP_STACK(HTML_A);
 	    HTML_end_element(me, HTML_A, include);
@@ -6133,11 +6111,7 @@ PRIVATE int HTML_start_element ARGS6(
     if (ReallyEmptyTagNum(element_number))
     {
 	CTRACE((tfp, "STYLE.begin_element:ending \"EMPTY\" element style\n"));
-#if !defined(USE_HASH)
-	HText_characterStyle(me->text, element_number+STARTAT, STACK_OFF);
-#else
 	HText_characterStyle(me->text, HCODE_TO_STACK_OFF(hcode), STACK_OFF);
-#endif /* USE_HASH */
 
 #if !OPT_SCN
 	TrimColorClass(HTML_dtd.tags[element_number].name,
@@ -7641,7 +7615,6 @@ End_Object:
 	break;
 
     case HTML_TABLE:
-	me->inTABLE = FALSE;
 	if (!strcmp(me->sp->style->name, "Preformatted")) {
 	    break;
 	}
@@ -7652,7 +7625,7 @@ End_Object:
 				me->DivisionAlignments[me->Division_Level];
 	change_paragraph_style(me, me->sp->style);
 	UPDATE_STYLE;
-	HText_endStblTABLE(me->text);
+	me->inTABLE = HText_endStblTABLE(me->text);
 	me->current_default_alignment = me->sp->style->alignment;
 	if (me->List_Nesting_Level >= 0)
 	    HText_NegateLineOne(me->text);
@@ -7750,11 +7723,7 @@ End_Object:
 	{
 	    CTRACE((tfp, "STYLE.end_element: ending non-\"EMPTY\" style <%s...>\n",
 		    HTML_dtd.tags[element_number].name));
-#if !defined(USE_HASH)
-	    HText_characterStyle(me->text, element_number+STARTAT, STACK_OFF);
-#else
 	    HText_characterStyle(me->text, HCODE_TO_STACK_OFF(hcode), STACK_OFF);
-#endif /* USE_HASH */
 	}
     }
 #endif /* USE_COLOR_STYLE */
diff --git a/src/LYBookmark.c b/src/LYBookmark.c
index 512c9af0..db2e0271 100644
--- a/src/LYBookmark.c
+++ b/src/LYBookmark.c
@@ -712,7 +712,7 @@ get_advanced_choice:
 	     *	Refresh the screen.
 	     */
 	    lynx_force_repaint();
-	    refresh();
+	    LYrefresh();
 	    goto get_advanced_choice;
 	}
 	if (LYisNonAlnumKeyname(c, LYK_ACTIVATE)) {
@@ -820,33 +820,33 @@ draw_bookmark_choices:
      *	to increase the chances that any non-ASCII or multibyte/CJK
      *	characters will be handled properly. - FM
      */
-    clear();
-    move(1, 5);
+    LYclear();
+    LYmove(1, 5);
     lynx_start_h1_color ();
     if (MBM_screens > 1) {
 	char *shead_buffer = 0;
 	HTSprintf0(&shead_buffer,
 		MULTIBOOKMARKS_SHEAD_MASK, MBM_current, MBM_screens);
-	addstr(shead_buffer);
+	LYaddstr(shead_buffer);
 	FREE(shead_buffer);
     } else {
-	addstr(MULTIBOOKMARKS_SHEAD);
+	LYaddstr(MULTIBOOKMARKS_SHEAD);
     }
 
     lynx_stop_h1_color ();
 
     MBM_tmp_count = 0;
     for (c = MBM_from; c <= MBM_to; c++) {
-	move(3+MBM_tmp_count, 5);
-	addch(UCH((c + 'A')));
-	addstr(" : ");
+	LYmove(3+MBM_tmp_count, 5);
+	LYaddch(UCH((c + 'A')));
+	LYaddstr(" : ");
 	if (MBM_A_subdescript[c])
-	    addstr(MBM_A_subdescript[c]);
-	move(3+MBM_tmp_count,36);
-	addch('(');
+	    LYaddstr(MBM_A_subdescript[c]);
+	LYmove(3+MBM_tmp_count,36);
+	LYaddch('(');
 	if (MBM_A_subbookmark[c])
-	    addstr(MBM_A_subbookmark[c]);
-	addch(')');
+	    LYaddstr(MBM_A_subbookmark[c]);
+	LYaddch(')');
 	MBM_tmp_count++;
     }
 
@@ -854,19 +854,19 @@ draw_bookmark_choices:
      *	Don't need to show it if it all fits on one screen!
      */
     if (MBM_screens > 1) {
-	move(LYlines-2, 0);
-	addstr("'");
-	standout();
-	addstr("[");
-	standend();
-	addstr("' ");
-	addstr(PREVIOUS);
-	addstr(", '");
-	standout();
-	addstr("]");
-	standend();
-	addstr("' ");
-	addstr(NEXT_SCREEN);
+	LYmove(LYlines-2, 0);
+	LYaddstr("'");
+	start_bold();
+	LYaddstr("[");
+	stop_bold();
+	LYaddstr("' ");
+	LYaddstr(PREVIOUS);
+	LYaddstr(", '");
+	start_bold();
+	LYaddstr("]");
+	stop_bold();
+	LYaddstr("' ");
+	LYaddstr(NEXT_SCREEN);
     }
 
     LYMBM_statusline(MULTIBOOKMARKS_SAVE);
@@ -892,7 +892,7 @@ get_bookmark_choice:
 	 *  Refresh the screen.
 	 */
 	lynx_force_repaint();
-	refresh();
+	LYrefresh();
 	goto get_bookmark_choice;
     }
 
diff --git a/src/LYCgi.c b/src/LYCgi.c
index d8b70d88..cbd8ed05 100644
--- a/src/LYCgi.c
+++ b/src/LYCgi.c
@@ -198,7 +198,7 @@ PRIVATE int LYLoadCGI ARGS4(
 	while (statrv < 0 || (statrv = stat(pgm_buff, &stat_buf)) < 0) {
 	    if ((cp=strrchr(pgm_buff, '/')) != NULL) {
 		*cp = '\0';
-		statrv = 999;	/* force new stat()  - kw */
+		statrv = 1;	/* force new stat()  - kw */
 	    } else {
 		PERROR("strrchr(pgm_buff, '/') returned NULL");
 	    	break;
diff --git a/src/LYCharSets.h b/src/LYCharSets.h
index 5dedc558..2f7591c2 100644
--- a/src/LYCharSets.h
+++ b/src/LYCharSets.h
@@ -93,4 +93,14 @@ extern int displayed_display_charset_idx;
 extern void init_charset_subsets NOPARAMS;
 #endif /* EXP_CHARSET_CHOICE */
 
+#if !defined(NO_AUTODETECT_DISPLAY_CHARSET)
+#  ifdef __EMX__
+#    define CAN_AUTODETECT_DISPLAY_CHARSET
+#  endif
+#endif
+
+#ifdef CAN_AUTODETECT_DISPLAY_CHARSET
+extern int auto_display_charset;
+#endif
+
 #endif /* LYCHARSETS_H */
diff --git a/src/LYClean.c b/src/LYClean.c
index 2266c952..cb6a5c91 100644
--- a/src/LYClean.c
+++ b/src/LYClean.c
@@ -50,7 +50,7 @@ PUBLIC void cleanup_sig ARGS1(
 	 *  Refresh screen to get rid of "cancel" message, then query.
 	 */
 	lynx_force_repaint();
-	refresh();
+	LYrefresh();
 
 	/*
 	 *  Ask if exit is intended.
@@ -162,11 +162,11 @@ PUBLIC void cleanup NOARGS
 #endif /* !VMS */
 
     if (LYCursesON) {
-	move(LYlines-1, 0);
-	clrtoeol();
+	LYmove(LYlines-1, 0);
+	LYclrtoeol();
 
 	lynx_stop_all_colors ();
-	refresh();
+	LYrefresh();
 
 	stop_curses();
     }
diff --git a/src/LYCookie.c b/src/LYCookie.c
index 223587ad..ec9ab39d 100644
--- a/src/LYCookie.c
+++ b/src/LYCookie.c
@@ -2436,11 +2436,10 @@ PRIVATE int LYHandleCookies ARGS4 (
 				return(HT_NO_DATA);
 
 			    case 'C':
-			    case LYCharINTERRUPT2:	/* Ctrl-G */
-			    case LYCharINTERRUPT1:	/* Ctrl-C */
 				/*
 				 *  Cancelled. - FM
 				 */
+			      reject:
 				HTUserMsg(CANCELLED);
 				return(HT_NO_DATA);
 
@@ -2524,6 +2523,8 @@ Delete_all_cookies_in_domain:
 				return(HT_NO_DATA);
 
 			    default:
+				if (LYCharIsINTERRUPT(ch))
+				    goto reject;
 				continue;
 			}
 			break;
diff --git a/src/LYCurses.c b/src/LYCurses.c
index 47f6b73f..bb03e38a 100644
--- a/src/LYCurses.c
+++ b/src/LYCurses.c
@@ -47,6 +47,12 @@ char *XCursesProgramName = "Lynx";
 #define COLOR_BKGD ((COLOR_PAIRS >= 9) ? COLOR_PAIR(9) : A_NORMAL)
 #endif
 
+#ifdef USE_CURSES_PADS
+WINDOW *LYwin = 0;
+int LYshiftWin = 0;
+int LYlineWrap = TRUE;
+#endif
+
 /*
  *  These are routines to start and stop curses and to cleanup
  *  the screen at the end.
@@ -359,7 +365,7 @@ PUBLIC void curses_w_style ARGS3(
 
     if (style == s_normal && dir) {
 	wattrset(win,A_NORMAL);
-	if (win==stdscr) cached_styles[YP][XP]=s_normal;
+	if (win==LYwin) cached_styles[YP][XP]=s_normal;
 	return;
     }
 
@@ -383,7 +389,7 @@ PUBLIC void curses_w_style ARGS3(
 			"in LynxChangeStyle(curses_w_style)"));
 	    last_colorattr_ptr--;
 	}
-	last_styles[last_colorattr_ptr++] = getattrs(stdscr);
+	last_styles[last_colorattr_ptr++] = getattrs(LYwin);
 	/* don't cache style changes for active links */
 #if OMIT_SCN_KEEPING
 	/* since we don't compute the hcode to stack off in HTML.c, we
@@ -396,10 +402,14 @@ PUBLIC void curses_w_style ARGS3(
 	/* FALL THROUGH */
     case ABS_ON: /* change without remembering the previous style */
 	    /* don't cache style changes for active links and edits */
-	if ( style != s_alink && style != s_aedit
-	     && style != s_aedit_pad && style != s_aedit_arr ) {
+	if ( style != s_alink
+	     && style != s_curedit
+	     && style != s_aedit
+	     && style != s_aedit_sel
+	     && style != s_aedit_pad
+	     && style != s_aedit_arr ) {
 	    CTRACE((tfp, "CACHED: <%s> @(%d,%d)\n", ds->name, YP, XP));
-	    if (win == stdscr) cached_styles[YP][XP] = style;
+	    if (win == LYwin) cached_styles[YP][XP] = style;
 	}
 	LYAttrset(win, ds->color, ds->mono);
 	break;
@@ -434,14 +444,14 @@ PUBLIC void wcurses_css ARGS3(
 
 PUBLIC void curses_css ARGS2(char *,name,int,dir)
 {
-    wcurses_css(stdscr, name, dir);
+    wcurses_css(LYwin, name, dir);
 }
 
 PUBLIC void curses_style ARGS2(
 	int,	style,
 	int,	dir)
 {
-    curses_w_style(stdscr, style, dir);
+    curses_w_style(LYwin, style, dir);
 }
 
 #ifdef NOT_USED
@@ -559,7 +569,7 @@ PRIVATE void lynx_map_color ARGS1(int, n)
 		    (short)lynx_color_pairs[pair].bg);
 	}
 	if (n == 0 && LYShowColor >= SHOW_COLOR_ON)
-	    bkgd(COLOR_BKGD | ' ');
+	    wbkgd(LYwin, COLOR_BKGD | ' ');
     }
 }
 
@@ -618,7 +628,7 @@ PRIVATE void lynx_init_colors NOARGS
 			(short)lynx_color_pairs[pair].bg);
 	    }
 	    if (n == 0 && LYShowColor >= SHOW_COLOR_ON)
-		bkgd(COLOR_BKGD | ' ');
+		wbkgd(LYwin, COLOR_BKGD | ' ');
 	}
     } else if (LYShowColor != SHOW_COLOR_NEVER) {
 	LYShowColor = SHOW_COLOR_OFF;
@@ -815,43 +825,52 @@ PUBLIC void start_curses NOARGS
 	 *  If we're not VMS then only do initscr() one time,
 	 *  and one time only!
 	 */
-#if defined(HAVE_NEWTERM) && !defined(NCURSES) && !defined(HAVE_RESIZETERM)
-	{
-	    /*
-	     * Put screen geometry in environment variables used by
-	     * XOpen curses before calling newterm().  I believe this
-	     * completes work left unfinished by AJL & FM -- gil
-	     */
-	    static char lines_putenv[] = "LINES=abcde",
-			cols_putenv[]  = "COLUMNS=abcde";
-	    BOOLEAN savesize;
-
-	    savesize = recent_sizechange;
-	    size_change(0);
-	    recent_sizechange = savesize;    /* avoid extra redraw */
-	    sprintf(lines_putenv + 6, "%d", LYlines & 0xfff);
-	    sprintf(cols_putenv  + 8, "%d", LYcols  & 0xfff);
-	    putenv(lines_putenv);
-	    putenv(cols_putenv);
-	    CTRACE((tfp, "start_curses putenv %s, %s\n", lines_putenv, cols_putenv));
-	}
-#endif /* HAVE_NEWTERM   */
-	if (!(LYscreen=newterm(NULL,stdout,stdin))) {  /* start curses */
+#if defined(HAVE_NEWTERM)
+#if !defined(NCURSES) && !defined(HAVE_RESIZETERM)
+	/*
+	 * Put screen geometry in environment variables used by
+	 * XOpen curses before calling newterm().  I believe this
+	 * completes work left unfinished by AJL & FM -- gil
+	 */
+	static char lines_putenv[] = "LINES=abcde",
+		    cols_putenv[]  = "COLUMNS=abcde";
+	BOOLEAN savesize;
+
+	savesize = recent_sizechange;
+	size_change(0);
+	recent_sizechange = savesize;    /* avoid extra redraw */
+	sprintf(lines_putenv + 6, "%d", LYlines & 0xfff);
+	sprintf(cols_putenv  + 8, "%d", LYcols  & 0xfff);
+	putenv(lines_putenv);
+	putenv(cols_putenv);
+	CTRACE((tfp, "start_curses putenv %s, %s\n", lines_putenv, cols_putenv));
+#endif /* !defined(NCURSES) && !defined(HAVE_RESIZETERM) */
+	if (!(LYscreen = newterm(NULL,stdout,stdin))) {  /* start curses */
 	    fprintf(tfp, "%s\n",
 		gettext("Terminal initialisation failed - unknown terminal type?"));
 	    exit_immediately (EXIT_FAILURE);
 	}
+#else
+	initscr();
+#endif /* HAVE_NEWTERM */
 	lynx_called_initscr = TRUE;
+
 #if defined(SIGWINCH) && defined(NCURSES_VERSION)
 	size_change(0);
 	recent_sizechange = FALSE; /* prevent mainloop drawing 1st doc twice */
 #endif /* SIGWINCH */
 
+#ifdef USE_CURSES_PADS
+	LYwin = newpad(LYlines, MAX_COLS);
+	LYshiftWin = 0;
+	LYlineWrap = TRUE;
+#endif
+
 #if defined(USE_KEYMAPS) && defined(NCURSES_VERSION)
 #  if HAVE_KEYPAD
 	/* Need to switch keypad on before initializing keymaps, otherwise
 	   when the keypad is switched on, some keybindings may be overriden. */
-	keypad(stdscr,TRUE);
+	keypad(LYwin,TRUE);
 	keypad_on = 1;
 #  endif /* HAVE_KEYPAD */
 
@@ -948,7 +967,7 @@ PUBLIC void start_curses NOARGS
 
 #if HAVE_KEYPAD
     if (!keypad_on)
-	keypad(stdscr,TRUE);
+	keypad(LYwin,TRUE);
 #endif /* HAVE_KEYPAD */
 
     lynx_enable_mouse (1);
@@ -959,7 +978,7 @@ PUBLIC void start_curses NOARGS
 #endif /* USE_SLANG */
 
 #if defined(WIN_EX)
-    clear();
+    LYclear();
 #endif
 
     LYCursesON = TRUE;
@@ -1142,7 +1161,7 @@ PUBLIC BOOLEAN setup ARGS1(
 	 *  -dump, so force that mode here. - FM
 	 */
 	dump_output_immediately = TRUE;
-	LYcols = 80;
+	LYcols = DFT_COLS;
 	if (keypad_mode == NUMBERS_AS_ARROWS)
 	    keypad_mode = LINKS_ARE_NUMBERED;
 	status = mainloop();
@@ -1174,12 +1193,8 @@ PUBLIC BOOLEAN setup ARGS1(
     ttopen();
     start_curses();
 
-    LYlines = LINES;
-    LYcols = COLS;
-    if (LYlines <= 0)
-	LYlines = 24;
-    if (LYcols <= 0)
-	LYcols = 80;
+    LYlines = LYscreenHeight();
+    LYcols = LYscreenWidth();
 
     return(TRUE);
 }
@@ -1258,21 +1273,8 @@ PUBLIC BOOLEAN setup ARGS1(
     }
 #endif /* HAVE_TTYTYPE */
 
-    LYlines = LINES;
-    LYcols = COLS;
-
-#if defined(PDCURSES_EXP) && defined(WIN_EX) && defined(CJK_EX) /* 1999/08/26 (Thu) 17:53:38 */
-    {
-	extern int current_codepage;	/* PDCurses lib. */
-
-	if (current_codepage == 932)
-	    LYcols = COLS - 1;
-    }
-#endif
-    if (LYlines <= 0)
-	LYlines = 24;
-    if (LYcols <= 0)
-	LYcols = 80;
+    LYlines = LYscreenHeight();
+    LYcols = LYscreenWidth();
 
     return(1);
 }
@@ -1311,7 +1313,7 @@ PUBLIC void LYaddWAttr ARGS2(
 PUBLIC void LYaddAttr ARGS1(
 	int,		a)
 {
-    LYaddWAttr(stdscr, a);
+    LYaddWAttr(LYwin, a);
 }
 
 PUBLIC void LYsubWAttr ARGS2(
@@ -1325,7 +1327,7 @@ PUBLIC void LYsubWAttr ARGS2(
 PUBLIC void LYsubAttr ARGS1(
 	int,		a)
 {
-    LYsubWAttr(stdscr, a);
+    LYsubWAttr(LYwin, a);
 }
 #endif /* USE_COLOR_TABLE */
 #endif /* !USE_COLOR_STYLE */
@@ -1415,17 +1417,17 @@ PUBLIC void LYtouchline ARGS1(
 	int,		row)
 {
 #if defined(HAVE_WREDRAWLN)
-    wredrawln(stdscr, row, 1);
+    wredrawln(LYwin, row, 1);
 #else
 #if defined(HAVE_TOUCHLINE)
     /* touchline() is not available on VMS before version 7.0, and then only on
      * Alpha, since prior ports of curses were broken.  BSD touchline() has a
      * 4th parameter since it is used internally by touchwin().
      */
-    touchline(stdscr, row, 1, 0);
+    touchline(LYwin, row, 1, 0);
 #else
 #if !defined(USE_SLANG)
-    touchwin(stdscr);
+    touchwin(LYwin);
 #else
     SLsmg_touch_lines(row, 1);
 #endif
@@ -1928,6 +1930,88 @@ PUBLIC int DCLsystem ARGS1(
 }
 #endif /* VMS */
 
+/*
+ * Return the physical screen dimensions that we're allowed to use.
+ */
+PUBLIC int LYscreenHeight NOARGS
+{
+    int result = LINES;
+    if (result <= 0)
+	result = DFT_ROWS;
+    return result;
+}
+
+PUBLIC int LYscreenWidth NOARGS
+{
+    int result = COLS;
+#if defined(PDCURSES_EXP) && defined(WIN_EX) && defined(CJK_EX) /* 1999/08/26 (Thu) 17:53:38 */
+    {
+	extern int current_codepage;	/* PDCurses lib. */
+
+	if (current_codepage == 932)
+	    result--;
+    }
+#endif
+    if (result <= 0)
+	result = DFT_COLS;
+    return result;
+}
+
+/*
+ * The functions ifdef'd with USE_CURSES_PADS are implemented that way so we
+ * don't break the slang configuration.
+ */
+PUBLIC void LYclear NOARGS
+{
+#ifdef USE_CURSES_PADS
+    wclear(LYwin);
+#else
+    clear();
+#endif
+}
+
+PUBLIC void LYclrtoeol NOARGS
+{
+#ifdef USE_CURSES_PADS
+    wclrtoeol(LYwin);
+#else
+    clrtoeol();
+#endif
+}
+
+PUBLIC void LYerase NOARGS
+{
+#ifdef USE_CURSES_PADS
+    werase(LYwin);
+#else
+    erase();
+#endif
+}
+
+PUBLIC void LYmove ARGS2(int, y, int, x)
+{
+#ifdef USE_CURSES_PADS
+    wmove(LYwin, y, x);
+#else
+    move(y, x);
+#endif
+}
+
+PUBLIC void LYrefresh NOARGS
+{
+#ifdef USE_CURSES_PADS
+    if (LYwin != stdscr) {
+	wnoutrefresh(stdscr);
+	pnoutrefresh(LYwin, 0, LYshiftWin, 0, 0, LYlines, LYscreenWidth()-1);
+	doupdate();
+    } else {
+	refresh();
+    }
+#else
+    refresh();
+#endif
+}
+
 PUBLIC void lynx_force_repaint NOARGS
 {
 #if defined(COLOR_CURSES)
@@ -1936,10 +2020,10 @@ PUBLIC void lynx_force_repaint NOARGS
 	a = COLOR_BKGD;
     else
 	a = A_NORMAL;
-    bkgdset(a | ' ');
+    wbkgdset(LYwin, a | ' ');
 #if !defined(USE_COLOR_STYLE) && defined(NCURSES_VERSION)
 #if NCURSES_VERSION_MAJOR < 4 || (NCURSES_VERSION_MAJOR == 4 && NCURSES_VERSION_MINOR == 0)
-    bkgd(a | ' ');
+    wbkgd(LYwin, a | ' ');
 #endif
 #endif
     attrset(a);
diff --git a/src/LYCurses.h b/src/LYCurses.h
index 88b5786c..7dc13067 100644
--- a/src/LYCurses.h
+++ b/src/LYCurses.h
@@ -180,6 +180,21 @@ typedef struct {
 #define USE_MOUSE 1
 #endif
 
+/*
+ * If we have pads, use them to implement left/right scrolling.
+ */
+#if defined(HAVE_NEWPAD) && defined(HAVE_PNOUTREFRESH)
+#define USE_CURSES_PADS 1
+#endif
+
+/*
+ * ncurses 1.9.9e won't work for pads, but 4.2 does (1.9.9g doesn't have a
+ * convenient ifdef, though it would work).
+ */
+#if defined(NCURSES_VERSION) && !defined(NCURSES_VERSION_MAJOR)
+#undef USE_CURSES_PADS
+#endif
+
 #endif /* USE_SLANG */
 
 #ifdef USE_SLANG
@@ -240,26 +255,41 @@ extern WINDOW *LYstartPopup PARAMS((int top_y, int left_x, int height, int width
 #undef HAVE_KEYPAD	/* avoid confusion with bogus 'keypad()' */
 #endif
 
-extern int LYlines;  /* replaces LINES */
-extern int LYcols;   /* replaces COLS */
+extern int LYlines;	/* replaces LINES */
+extern int LYcols;	/* replaces COLS */
+
+#ifdef USE_CURSES_PADS
+extern WINDOW *LYwin;
+extern int LYshiftWin;
+extern int LYlineWrap;
+#else
+#define LYwin stdscr
+#endif
 
 #if defined(USE_COLOR_TABLE) || defined(USE_SLANG)
 extern int Current_Attr;
 extern int Masked_Attr;
 #endif
 
-extern void start_curses NOPARAMS;
-extern void stop_curses NOPARAMS;
 extern BOOLEAN setup PARAMS((char *terminal));
+extern int LYscreenHeight NOPARAMS;
+extern int LYscreenWidth NOPARAMS;
+extern void LYclear NOPARAMS;
+extern void LYclrtoeol NOPARAMS;
+extern void LYerase NOPARAMS;
+extern void LYmove PARAMS((int y, int x));
 extern void LYnoVideo PARAMS((int mask));
+extern void LYpaddstr PARAMS((WINDOW *w, int width, CONST char *s));
+extern void LYrefresh NOPARAMS;
 extern void LYstartTargetEmphasis NOPARAMS;
 extern void LYstopTargetEmphasis NOPARAMS;
 extern void LYtouchline PARAMS((int row));
 extern void LYwaddnstr PARAMS((WINDOW *w, CONST char *s, size_t len));
-extern void LYpaddstr PARAMS((WINDOW *w, int width, CONST char *s));
+extern void start_curses NOPARAMS;
+extern void stop_curses NOPARAMS;
 
-#define LYaddstr(s)      LYwaddnstr(stdscr, s, strlen(s))
-#define LYaddnstr(s,len) LYwaddnstr(stdscr, s, len)
+#define LYaddstr(s)      LYwaddnstr(LYwin, s, strlen(s))
+#define LYaddnstr(s,len) LYwaddnstr(LYwin, s, len)
 #define LYwaddstr(w,s)   LYwaddnstr(w, s, strlen(s))
 
 #ifdef VMS
@@ -344,7 +374,7 @@ extern void LY_SLerase NOPARAMS;
 #define scrollok(a,b) SLsmg_Newline_Moves = ((b) ? 1 : -1)
 #endif
 
-#define addch(ch)     SLsmg_write_char(ch)
+#define LYaddch(ch)   SLsmg_write_char(ch)
 #define addch_raw(ch) do {                                \
                         SLsmg_Char_Type buf;              \
                         buf = (ch) | (Current_Attr << 4); \
@@ -367,7 +397,7 @@ extern void LY_SLrefresh NOPARAMS;
 
 #ifdef VMS
 extern void VTHome NOPARAMS;
-#define endwin() clear(),refresh(),SLsmg_reset_smg(),VTHome()
+#define endwin() LYclear(),refresh(),SLsmg_reset_smg(),VTHome()
 #else
 #define endwin SLsmg_reset_smg(),SLang_reset_tty
 #endif /* VMS */
@@ -395,10 +425,9 @@ extern void VTHome NOPARAMS;
 #define stop_underline()	clrattr(_UNDERLINE)
 #endif /* UNDERLINE_LINKS */
 #define start_reverse()		setattr(_REVERSE)
-#define wstart_reverse(a)	wsetattr(a, _REVERSE)
-#define wstop_underline(a)	wclrattr(a, _UNDERLINE)
+#define wstart_reverse(w)	wsetattr(w, _REVERSE)
 #define stop_reverse()		clrattr(_REVERSE)
-#define wstop_reverse(a)	wclrattr(a, _REVERSE)
+#define wstop_reverse(w)	wclrattr(w, _REVERSE)
 
 #else /* Not VMS: */
 
@@ -420,10 +449,10 @@ extern int  lynx_chg_color PARAMS((int, int, int));
 #undef  standend
 #define standend() 		lynx_standout(FALSE)
 #else
-#define LYaddAttr		attron
-#define LYaddWAttr		wattron
-#define LYsubAttr		attroff
-#define LYsubWAttr		wattroff
+#define LYaddAttr(attr)		LYaddWAttr(LYwin,attr)
+#define LYaddWAttr(win,attr)	wattron(win,attr)
+#define LYsubAttr(attr)		LYsubWAttr(LYwin,attr)
+#define LYsubWAttr(win,attr)	wattroff(win,attr)
 #endif
 
 #ifdef UNDERLINE_LINKS
@@ -448,15 +477,15 @@ extern int  lynx_chg_color PARAMS((int, int, int));
 #endif /* UNDERLINE_LINKS */
 
 #if defined(SNAKE) && defined(HP_TERMINAL)
-#define start_reverse()		LYaddWAttr(stdscr, A_DIM)
-#define wstart_reverse(a)	LYaddWAttr(a, A_DIM)
-#define stop_reverse()		LYsubWAttr(stdscr, A_DIM)
-#define wstop_reverse(a)	LYsubWAttr(a, A_DIM)
+#define start_reverse()		LYaddWAttr(LYwin, A_DIM)
+#define wstart_reverse(w)	LYaddWAttr(w, A_DIM)
+#define stop_reverse()		LYsubWAttr(LYwin, A_DIM)
+#define wstop_reverse(w)	LYsubWAttr(w, A_DIM)
 #else
 #define start_reverse()		LYaddAttr(A_REVERSE)
-#define wstart_reverse(a)	LYaddWAttr(a, A_REVERSE)
+#define wstart_reverse(w)	LYaddWAttr(w, A_REVERSE)
 #define stop_reverse()		LYsubAttr(A_REVERSE)
-#define wstop_reverse(a)	LYsubWAttr(a, A_REVERSE)
+#define wstop_reverse(w)	LYsubWAttr(w, A_REVERSE)
 #endif /* SNAKE && HP_TERMINAL */
 
 #endif /* VMS */
@@ -487,7 +516,9 @@ FANCY_CURSES.  Check your config.log to see why the FANCY_CURSES test failed.
 
 #endif /* FANCY_CURSES */
 
-#define addch_raw(ch)           addch(ch)
+#define LYaddch(ch)		waddch(LYwin, ch)
+
+#define addch_raw(ch)           LYaddch(ch)
 
 #endif /* USE_SLANG */
 
@@ -495,9 +526,9 @@ FANCY_CURSES.  Check your config.log to see why the FANCY_CURSES test failed.
 #define LYGetYX(y, x)   y = SLsmg_get_row(), x = SLsmg_get_column()
 #else
 #ifdef getyx
-#define LYGetYX(y, x)   getyx(stdscr, y, x)
+#define LYGetYX(y, x)   getyx(LYwin, y, x)
 #else
-#define LYGetYX(y, x)   y = stdscr->_cury, x = stdscr->_curx
+#define LYGetYX(y, x)   y = LYwin->_cury, x = LYwin->_curx
 #endif /* getyx */
 #endif /* USE_SLANG */
 
@@ -554,9 +585,9 @@ extern void lynx_stop_all_colors NOPARAMS;
  * Adjust our "hidden" cursor position accordingly.
  */
 #if defined(FANCY_CURSES) || defined(USE_SLANG)
-#define LYHideCursor() move((LYlines - 1), (LYcols - 1))
+#define LYHideCursor() LYmove((LYlines - 1), (LYcols - 1))
 #else
-#define LYHideCursor() move((LYlines - 1), (LYcols - 2))
+#define LYHideCursor() LYmove((LYlines - 1), (LYcols - 2))
 #endif
 
 extern void LYstowCursor PARAMS((WINDOW * win, int row, int col));
diff --git a/src/LYEditmap.c b/src/LYEditmap.c
index 575c89f3..881ffbc6 100644
--- a/src/LYEditmap.c
+++ b/src/LYEditmap.c
@@ -27,6 +27,8 @@
 
 PUBLIC int current_lineedit = 0;  /* Index into LYLineEditors[]   */
 
+PUBLIC int escape_bound = 0;      /* User wanted Escape to perform actions?  */
+
 /*
  * See LYStrings.h for the LYE definitions.
  */
diff --git a/src/LYForms.c b/src/LYForms.c
index 26ce0379..b47b1146 100644
--- a/src/LYForms.c
+++ b/src/LYForms.c
@@ -86,7 +86,7 @@ PUBLIC int change_form_link_ex ARGS8(
     /*
      *  Move to the link position.
      */
-    move(form_link->ly, form_link->lx);
+    LYmove(form_link->ly, form_link->lx);
 
     switch(form->type) {
 	case F_CHECKBOX_TYPE:
@@ -188,8 +188,8 @@ PUBLIC int change_form_link_ex ARGS8(
 			 */
 			!strcmp(links[i].form->name, form->name) &&
 			links[i].form->num_value) {
-			move(links[i].ly, links[i].lx);
-			addstr(unchecked_radio);
+			LYmove(links[i].ly, links[i].lx);
+			LYaddstr(unchecked_radio);
 			links[i].hightext = unchecked_radio;
 		    }
 		}
@@ -421,7 +421,7 @@ PRIVATE int form_getstr ARGS3(
 	     */
 	    HTUserMsg(FORM_VALUE_TOO_LONG);
 	    show_formlink_statusline(form, redraw_only? FOR_PANEL : FOR_INPUT);
-	    move(startline, startcol);
+	    LYmove(startline, startcol);
 	}
     }
 
@@ -445,7 +445,7 @@ PRIVATE int form_getstr ARGS3(
 	    MyEdit.pos = LastTFPos;
 #ifdef ENHANCED_LINEEDIT
 	if (MyEdit.pos == 0)
-	    MyEdit.mark = MyEdit.strlen;
+	    MyEdit.mark = -1 - MyEdit.strlen;	/* Do not show the region. */
 #endif
     }
     /* Try to prepare for setting position based on the last mouse event */
@@ -683,12 +683,12 @@ again:
 		goto breakfor;
 #endif /* NOTDEFINED */
 
-	    /*
+	    default:
+	    /*	[ 1999/04/14 (Wed) 15:01:33 ]
 	     *  Left arrrow in column 0 deserves special treatment here,
 	     *  else you can get trapped in a form without submit button!
 	     */
-	    case LTARROW:	/* 1999/04/14 (Wed) 15:01:33 */
-		if (MyEdit.pos == 0 && repeat == -1) {
+		if (action == LYE_BACK && MyEdit.pos == 0 && repeat == -1) {
 		    int c = YES;    /* Go back immediately if no changes */
 		    if (textfield_prompt_at_left_edge) {
 			c = HTConfirmDefault(PREV_DOC_QUERY, NO);
@@ -704,9 +704,6 @@ again:
 			    _statusline(ENTER_TEXT_ARROWS_OR_TAB);
 		    }
 		}
-		/* fall through */
-
-	    default:
 		if (form->disabled == YES) {
 		    /*
 		     *  Allow actions that don't modify the contents even
@@ -717,7 +714,9 @@ again:
 		    case LYE_BOL:
 		    case LYE_EOL:
 		    case LYE_FORW:
+		    case LYE_FORW_RL:
 		    case LYE_BACK:
+		    case LYE_BACK_LL:
 		    case LYE_FORWW:
 		    case LYE_BACKW:
 #ifdef EXP_KEYBOARD_LAYOUT
@@ -738,10 +737,32 @@ again:
 		if (repeat < 0)
 		    repeat = 1;
 		while (repeat--) {
-#ifndef SUPPORT_MULTIBYTE_EDIT
-		    LYLineEdit(&MyEdit, ch, TRUE);
-#else /* SUPPORT_MULTIBYTE_EDIT */
-		    if (LYLineEdit(&MyEdit, ch, TRUE) == 0) {
+		    int rc = LYLineEdit(&MyEdit, ch, TRUE);
+
+		    if (rc < 0) {
+			ch = -rc;
+			/* FORW_RL and BACK_LL may require special attention.
+			   BACK_LL wanted to switch to the previous link on
+			   the same line.  However, if there is no such link,
+			   then we would either disactivate the form
+			   (with -tna), or will reenter the form, thus we jump
+			   to the end of the line; both are counterintuitive.
+			   Unfortunately, we do not have access to curdoc.link,
+			   so we deduce it ourselves.  We don't have the info
+			   to do it inside LYLineEdit().
+			   This should work for prompts too.  */
+			if ( (action != LYE_BACK_LL && action != LYE_FORW_RL)
+			     || ((form_link - links) >= 0
+				&& (form_link - links) < nlinks
+				&& (action==LYE_FORW_RL
+				    ? (form_link - links) < nlinks - 1
+				    : (form_link - links) > 0)
+				&& form_link[action==LYE_FORW_RL ? 1 : -1].ly
+				   == form_link->ly))
+			    goto breakfor;
+		    }
+#ifdef SUPPORT_MULTIBYTE_EDIT
+		    if (rc == 0) {
 			if (HTCJK != NOCJK && (0x80 <= ch)
 			&& (ch <= 0xfe) && refresh_mb)
 			    refresh_mb = FALSE;
@@ -771,9 +792,7 @@ again:
 		LYSetLastTFPos(MyEdit.pos);
 	}
     }
-#if defined(NOTDEFINED) || defined(SH_EX)
-breakfor:
-#endif /* NOTDEFINED */
+  breakfor:
     if (Edited) {
 	char  *p;
 
diff --git a/src/LYGetFile.c b/src/LYGetFile.c
index 4c37ed5b..35ab4619 100644
--- a/src/LYGetFile.c
+++ b/src/LYGetFile.c
@@ -758,6 +758,31 @@ Try_Redirected_URL:
 #ifdef DIRED_SUPPORT
 		    lynx_edit_mode = FALSE;
 #endif /* DIRED_SUPPORT */
+#ifndef DISABLE_BIBP
+		    if (url_type == BIBP_URL_TYPE) {
+			char *bibpTmp = NULL;
+			if (!BibP_bibhost_checked)
+			    LYCheckBibHost();
+			if (BibP_bibhost_available) {
+			    StrAllocCopy(bibpTmp, BibP_bibhost);
+			} else if (HTMainAnchor && HTAnchor_citehost(HTMainAnchor)) {
+			    StrAllocCopy(bibpTmp, HTAnchor_citehost(HTMainAnchor));
+			} else {
+			    StrAllocCopy(bibpTmp, BibP_globalserver);
+			}
+			if (HTMainAnchor && HTAnchor_citehost(HTMainAnchor)) {
+			    StrAllocCat(bibpTmp, "bibp1.0/resolve?citehost=");
+			    StrAllocCat(bibpTmp, HTAnchor_citehost(HTMainAnchor));
+			    StrAllocCat(bibpTmp, "&usin=");
+			} else {
+			    StrAllocCat(bibpTmp, "bibp1.0/resolve?usin=");
+			}
+			StrAllocCat(bibpTmp, doc->address+5); /* USIN after bibp: */
+			StrAllocCopy(doc->address, bibpTmp);
+			WWWDoc.address = doc->address;
+			FREE(bibpTmp);
+		    }
+#endif /* !DISABLE_BIBP */
 
 		    if (url_type == FILE_URL_TYPE) {
 			/*
@@ -802,8 +827,8 @@ Try_Redirected_URL:
 		    if (TRACE) {
 #ifdef USE_SLANG
 			if (LYCursesON) {
-			    addstr("*\n");
-			    refresh();
+			    LYaddstr("*\n");
+			    LYrefresh();
 			}
 #endif /* USE_SLANG */
 			fprintf(tfp,"\n");
@@ -865,6 +890,10 @@ Try_Redirected_URL:
 				 url_type == FILE_URL_TYPE) ||
 				(no_goto_lynxcgi &&
 				 url_type == LYNXCGI_URL_TYPE) ||
+#ifndef DISABLE_BIBP
+				(no_goto_bibp &&
+				 url_type == BIBP_URL_TYPE) ||
+#endif
 				(no_goto_cso &&
 				 url_type == CSO_URL_TYPE) ||
 				(no_goto_finger &&
diff --git a/src/LYGlobalDefs.h b/src/LYGlobalDefs.h
index 05392c96..e282eb87 100644
--- a/src/LYGlobalDefs.h
+++ b/src/LYGlobalDefs.h
@@ -107,6 +107,10 @@ extern char *LYCgiDocumentRoot;  /* DOCUMENT_ROOT in the lynxcgi env */
 extern BOOLEAN LYUseNoviceLineTwo;  /* True if TOGGLE_HELP is not mapped */
 
 #define MAX_LINE 1024	/* Hope that no window is larger than this */
+#define MAX_COLS 999	/* we don't expect wider than this */
+#define DFT_COLS 80	/* ...and normally only this */
+#define DFT_ROWS 24	/* ...corresponding nominal height */
+
 extern char star_string[MAX_LINE + 1]; /* from GridText.c */
 #define STARS(n) \
  ((n) >= MAX_LINE ? star_string : &star_string[(MAX_LINE-1)] - (n))
@@ -377,6 +381,14 @@ extern char *LYCookieSStrictCheckDomains;/* domains to check strictly    */
 extern char *LYCookieSLooseCheckDomains;/* domains to check loosely      */
 extern char *LYCookieSQueryCheckDomains;/* domains to check w/a query    */
 
+#ifndef DISABLE_BIBP
+extern BOOLEAN no_goto_bibp;
+extern char *BibP_globalserver;         /* global server for bibp: links */
+extern char *BibP_bibhost;              /* local server for bibp: links  */
+extern BOOLEAN BibP_bibhost_checked;    /* bibhost has been checked      */
+extern BOOLEAN BibP_bibhost_available;  /* bibhost is responding         */
+#endif
+
 #ifdef EXP_PERSISTENT_COOKIES
 extern BOOLEAN persistent_cookies;
 extern char *LYCookieFile;              /* cookie read file              */
diff --git a/src/LYHash.c b/src/LYHash.c
index f355729e..5ca59b80 100644
--- a/src/LYHash.c
+++ b/src/LYHash.c
@@ -10,12 +10,7 @@
  *  but with a different value for HASH_SIZE.
  */
 
-#ifdef NOT_USED
-#define HASH_SIZE 8193		/* Arbitrary prime.  Memory/speed tradeoff */
-#else
 #define HASH_SIZE CSHASHSIZE
-#endif
-
 #define HASH_OF(h, v) ((int)((h) * 3 + UCH(v)) % HASH_SIZE)
 
 PUBLIC int hash_code ARGS1 (char*, string)
diff --git a/src/LYHash.h b/src/LYHash.h
index b42f1ed6..5e019da3 100644
--- a/src/LYHash.h
+++ b/src/LYHash.h
@@ -17,12 +17,8 @@ struct _hashbucket {
 typedef struct _hashbucket bucket;
 
 #if !defined(CSHASHSIZE)
-#ifdef NOT_USED
-#define CSHASHSIZE 32768
-#else
 #define CSHASHSIZE 8193
 #endif
-#endif
 
 #define NOSTYLE -1
 
@@ -37,13 +33,30 @@ extern int hash_code_lowercase_on_fly PARAMS((char* string));
 extern int hash_code_aggregate_char PARAMS((char c,int hash));
 extern int hash_code_aggregate_lower_str  PARAMS((char* c,int hash_was));
 
-extern int	s_alink, s_a, s_status,
-		s_normal, s_alert, s_title,
+extern int	s_a;
+extern int	s_aedit;
+extern int	s_aedit_arr;
+extern int	s_aedit_pad;
+extern int	s_aedit_sel;
+extern int	s_alert;
+extern int	s_alink;
+extern int	s_curedit;
+extern int	s_normal;
+extern int	s_prompt_edit;
+extern int	s_prompt_edit_arr;
+extern int	s_prompt_edit_pad;
+extern int	s_prompt_sel;
+extern int	s_status;
+extern int	s_title;
+extern int	s_whereis;
+
 #ifdef USE_SCROLLBAR
-		s_sb_bar, s_sb_bg, s_sb_aa, s_sb_naa,
+extern int	s_sb_aa;
+extern int	s_sb_bar;
+extern int	s_sb_bg;
+extern int	s_sb_naa;
 #endif
-		s_whereis, s_aedit, s_aedit_pad, s_aedit_arr, 
-		s_prompt_edit, s_prompt_edit_pad, s_prompt_edit_arr;
+
 #define CACHEW 128
 #define CACHEH 64
 
diff --git a/src/LYKeymap.c b/src/LYKeymap.c
index 3eb5cd9a..e365e6d7 100644
--- a/src/LYKeymap.c
+++ b/src/LYKeymap.c
@@ -1,4 +1,3 @@
-
 #include <HTUtils.h>
 #include <LYUtils.h>
 #include <LYKeymap.h>
@@ -167,10 +166,10 @@ LYK_PRINT,           LYK_QUIT,    LYK_DEL_BOOKMARK, LYK_INDEX_SEARCH,
 LYK_TAG_LINK,     LYK_PREV_DOC,   LYK_VIEW_BOOKMARK,   0,
 /* t */              /* u */         /* v */        /* w */
 
-LYK_NOCACHE,            0,          LYK_INTERRUPT,     0,
+LYK_NOCACHE,            0,          LYK_INTERRUPT, LYK_SHIFT_LEFT,
 /* x */              /* y */          /* z */       /* { */
 
-LYK_PIPE,               0,              0,          LYK_HISTORY,
+LYK_LINEWRAP_TOGGLE, LYK_SHIFT_RIGHT,  0,          LYK_HISTORY,
 /* | */               /* } */         /* ~ */       /* del */
 
 
@@ -668,9 +667,6 @@ PRIVATE Kcmd revmap[] = {
 	LYK_RELOAD, "RELOAD",
 	"reload the current document" ),
     DATA(
-	LYK_PIPE, "PIPE",
-	"pipe the current document to an external command" ),
-    DATA(
 	LYK_QUIT, "QUIT",
 	"quit the browser" ),
     DATA(
@@ -949,6 +945,17 @@ PRIVATE Kcmd revmap[] = {
 	LYK_CHDIR, "CHDIR",
 	"change current directory" ),
 #endif
+#ifdef USE_CURSES_PADS
+    DATA(
+	LYK_SHIFT_LEFT, "SHIFT_LEFT",
+	"shift the screen left" ),
+    DATA(
+	LYK_SHIFT_RIGHT, "SHIFT_RIGHT",
+	"shift the screen right" ),
+    DATA(
+	LYK_LINEWRAP_TOGGLE, "LINEWRAP_TOGGLE",
+	"toggle linewrap on/off" ),
+#endif
     DATA(
 	LYK_UNKNOWN, NULL,
 	"" )
@@ -1010,7 +1017,9 @@ PRIVATE struct emap ekmap[] = {
   {"BOL",	LYE_BOL,	"Go to begin of line"},
   {"EOL",	LYE_EOL,	"Go to end   of line"},
   {"FORW",	LYE_FORW,	"Cursor forwards"},
+  {"FORW_RL",	LYE_FORW_RL,	"Cursor forwards or right link"},
   {"BACK",	LYE_BACK,	"Cursor backwards"},
+  {"BACK_LL",	LYE_BACK_LL,	"Cursor backwards or left link"},
   {"FORWW",	LYE_FORWW,	"Word forward"},
   {"BACKW",	LYE_BACKW,	"Word back"},
 
@@ -1357,6 +1366,8 @@ PUBLIC int lkcstring_to_lkc ARGS1(
 #endif
 #endif
     }
+    if (c == CH_ESC)
+	escape_bound = 1;
     if (c < -1)
 	return (-1);
     else
@@ -1400,12 +1411,9 @@ PRIVATE int LYLoadKeymap ARGS4 (
     }
     for (i = 1; i < KEYMAP_SIZE; i++) {
 	/*
-	 *  LYK_PIPE not implemented yet.
-	 *
 	 *  Don't show CHANGE_LINK if mouse not enabled.
 	 */
 	if ((i >= 0200 || i <= ' ' || !isalpha(i-1)) &&
-	    (keymap[i] != LYK_PIPE) &&
 	    (LYUseMouse || (keymap[i] != LYK_CHANGE_LINK))) {
 	    print_binding(target, i, FALSE);
 	}
diff --git a/src/LYKeymap.h b/src/LYKeymap.h
index b53e657f..a207a702 100644
--- a/src/LYKeymap.h
+++ b/src/LYKeymap.h
@@ -3,6 +3,7 @@
 
 #include <HTUtils.h>
 #include <HTList.h>
+#include <LYCurses.h>
 
 extern BOOLEAN LYisNonAlnumKeyname PARAMS((int ch, int KeyName));
 extern HTList *LYcommandList NOPARAMS;
@@ -129,7 +130,6 @@ typedef enum {
   , LYK_9
   , LYK_SOURCE
   , LYK_RELOAD
-  , LYK_PIPE
   , LYK_QUIT
   , LYK_ABORT
   , LYK_NEXT_PAGE
@@ -238,12 +238,25 @@ typedef enum {
   , LYK_CHG_CENTER
   , LYK_TO_CLIPBOARD
 #endif /* SH_EX */
+
 #ifdef KANJI_CODE_OVERRIDE
   , LYK_CHG_KCODE
 #endif
+
 #ifdef SUPPORT_CHDIR
   , LYK_CHDIR
 #endif
+
+#ifdef USE_CURSES_PADS
+  , LYK_SHIFT_LEFT
+  , LYK_SHIFT_RIGHT
+  , LYK_LINEWRAP_TOGGLE
+#else
+#define LYK_SHIFT_LEFT      LYK_UNKNOWN
+#define LYK_SHIFT_RIGHT     LYK_UNKNOWN
+#define LYK_LINEWRAP_TOGGLE LYK_UNKNOWN
+#endif
+
 } LYKeymapCode;
 
 /*
diff --git a/src/LYLocal.c b/src/LYLocal.c
index 64994ccf..175c8ef9 100644
--- a/src/LYLocal.c
+++ b/src/LYLocal.c
@@ -1336,12 +1336,12 @@ PUBLIC void tagflag ARGS2(
 	int,		cur)
 {
     if (nlinks > 0) {
-	move(links[cur].ly, 2);
+	LYmove(links[cur].ly, 2);
 	stop_reverse();
 	if (flag == ON) {
-	    addch('+');
+	    LYaddch('+');
 	} else {
-	    addch(' ');
+	    LYaddch(' ');
 	}
 
 #if defined(FANCY_CURSES) || defined(USE_SLANG)
@@ -1352,9 +1352,9 @@ PUBLIC void tagflag ARGS2(
 	    /*
 	     *	Never hide the cursor if there's no FANCY CURSES.
 	     */
-	    move(links[cur].ly, links[cur].lx);
+	    LYmove(links[cur].ly, links[cur].lx);
 
-	refresh();
+	LYrefresh();
     }
 }
 
diff --git a/src/LYMail.c b/src/LYMail.c
index 0bd3c561..77ffeabe 100644
--- a/src/LYMail.c
+++ b/src/LYMail.c
@@ -30,7 +30,7 @@ PRIVATE void terminate_letter ARGS1(int,sig GCC_UNUSED)
      */
     if (!dump_output_immediately) {
 	lynx_force_repaint();
-	refresh();
+	LYrefresh();
     }
 #endif /* VMS */
 }
@@ -266,7 +266,7 @@ PRIVATE int header_prompt ARGS3(
     int ok;
 
     if (*result != 0) {
-	addstr(CTRL_U_TO_ERASE);
+	LYaddstr(CTRL_U_TO_ERASE);
 	LYstrncpy(buffer, *result, sizeof(buffer)-1);
     } else
 	*buffer = 0;
@@ -274,10 +274,11 @@ PRIVATE int header_prompt ARGS3(
     if (limit > sizeof(buffer))
 	limit = sizeof(buffer);
 
-    printw("%s: ", gettext(label));
+    LYaddstr(gettext(label));
+    LYaddstr(": ");
     ok = (LYgetstr(buffer, VISIBLE, limit, NORECALL) >= 0
 	&& !term_letter);
-    addstr("\n");
+    LYaddstr("\n");
 
     if (ok) {
 	remove_tildes(buffer);
@@ -298,14 +299,14 @@ PRIVATE void show_addresses ARGS1(
 	while (*cp == ' ')
 	    cp++;
 	if (*cp) {
-	    addstr(cp);
-	    addstr(",\n  ");
+	    LYaddstr(cp);
+	    LYaddstr(",\n  ");
 	}
 	*cp1 = ',';
 	cp = (cp1 + 1);
     }
     if (*cp) {
-	addstr(cp);
+	LYaddstr(cp);
     }
 }
 
@@ -1284,13 +1285,13 @@ PUBLIC void reply_by_mail ARGS4(
     /*
      *	Clear the screen and inform the user.
      */
-    clear();
-    move(2,0);
-    scrollok(stdscr, TRUE);	/* Enable scrolling. */
+    LYclear();
+    LYmove(2,0);
+    scrollok(LYwin, TRUE);	/* Enable scrolling. */
     if (body)
-	addstr(SENDING_MESSAGE_WITH_BODY_TO);
+	LYaddstr(SENDING_MESSAGE_WITH_BODY_TO);
     else
-	addstr(SENDING_COMMENT_TO);
+	LYaddstr(SENDING_COMMENT_TO);
     show_addresses(to_address);
     if (
 #if USE_VMS_MAILER
@@ -1299,13 +1300,13 @@ PUBLIC void reply_by_mail ARGS4(
 	(cp = ccaddr) != NULL)
     {
 	if (strchr(cp, ',') != NULL) {
-	    addstr(WITH_COPIES_TO);
+	    LYaddstr(WITH_COPIES_TO);
 	} else {
-	    addstr(WITH_COPY_TO);
+	    LYaddstr(WITH_COPY_TO);
 	}
 	show_addresses(ccaddr);
     }
-    addstr(CTRL_G_TO_CANCEL_SEND);
+    LYaddstr(CTRL_G_TO_CANCEL_SEND);
 
 #if USE_VMS_MAILER
     if (isPMDF || !body) {
@@ -1314,7 +1315,7 @@ PUBLIC void reply_by_mail ARGS4(
     /*
      *	Get the user's personal name.
      */
-    addstr(ENTER_NAME_OR_BLANK);
+    LYaddstr(ENTER_NAME_OR_BLANK);
 #if USE_VMS_MAILER
     if (isPMDF) {
 	label = "Personal_name: ";
@@ -1338,8 +1339,8 @@ PUBLIC void reply_by_mail ARGS4(
     /*
      *	Get the user's return address.
      */
-    addstr(ENTER_MAIL_ADDRESS_OR_OTHER);
-    addstr(MEANS_TO_CONTACT_FOR_RESPONSE);
+    LYaddstr(ENTER_MAIL_ADDRESS_OR_OTHER);
+    LYaddstr(MEANS_TO_CONTACT_FOR_RESPONSE);
 #if USE_VMS_MAILER
     if (isPMDF) {
 	label = "From";
@@ -1373,7 +1374,7 @@ PUBLIC void reply_by_mail ARGS4(
     /*
      *	Get the subject line.
      */
-    addstr(ENTER_SUBJECT_LINE);
+    LYaddstr(ENTER_SUBJECT_LINE);
     label = "Subject";
     if (*default_subject) {
 	StrAllocCopy(the_subject, default_subject);
@@ -1390,8 +1391,8 @@ PUBLIC void reply_by_mail ARGS4(
      *	Offer a CC line, if permitted. - FM
      */
     if (!LYNoCc) {
-	addstr(ENTER_ADDRESS_FOR_CC);
-	addstr(BLANK_FOR_NO_COPY);
+	LYaddstr(ENTER_ADDRESS_FOR_CC);
+	LYaddstr(BLANK_FOR_NO_COPY);
 	if (personal_mail_address)
 	    StrAllocCopy(cc_address, personal_mail_address);
 	if (!header_prompt("Cc", &cc_address, LINESIZE)) {
@@ -1455,7 +1456,7 @@ PUBLIC void reply_by_mail ARGS4(
 	    }
 	}
 	LYCloseTempFP(fd);	/* Close the tmpfile. */
-	scrollok(stdscr,FALSE); /* Stop scrolling.    */
+	scrollok(LYwin,FALSE);	/* Stop scrolling.    */
 
 	if (term_letter || LYCharIsINTERRUPT(c))
 	    goto cleanup;
@@ -1482,18 +1483,18 @@ PUBLIC void reply_by_mail ARGS4(
 	/*
 	 *  Let user review the body. - FM
 	 */
-	clear();
-	move(0,0);
-	addstr(REVIEW_MESSAGE_BODY);
-	refresh();
+	LYclear();
+	LYmove(0,0);
+	LYaddstr(REVIEW_MESSAGE_BODY);
+	LYrefresh();
 	cp1 = body;
 	i = (LYlines - 5);
 	while((cp = strchr(cp1, '\n')) != NULL) {
 	    if (i <= 0) {
-		addstr(RETURN_TO_CONTINUE);
-		refresh();
+		LYaddstr(RETURN_TO_CONTINUE);
+		LYrefresh();
 		c = LYgetch();
-		addstr("\n");
+		LYaddstr("\n");
 		if (term_letter || LYCharIsINTERRUPT(c)) {
 		    goto cancelled;
 		}
@@ -1501,28 +1502,28 @@ PUBLIC void reply_by_mail ARGS4(
 	    }
 	    *cp++ = '\0';
 	    fprintf(fd, "%s\n", cp1);
-	    addstr(cp1);
-	    addstr("\n");
+	    LYaddstr(cp1);
+	    LYaddstr("\n");
 	    cp1 = cp;
 	    i--;
 	}
 	while (i >= 0) {
-	    addstr("\n");
+	    LYaddstr("\n");
 	    i--;
 	}
-	refresh();
+	LYrefresh();
 	LYCloseTempFP(fd);	/* Close the tmpfile.	  */
-	scrollok(stdscr,FALSE); /* Stop scrolling.	  */
+	scrollok(LYwin,FALSE);	/* Stop scrolling.	  */
 
     } else {
 	/*
 	 *  Use the internal line editor for the message.
 	 */
-	addstr(ENTER_MESSAGE_BELOW);
-	addstr(ENTER_PERIOD_WHEN_DONE_A);
-	addstr(ENTER_PERIOD_WHEN_DONE_B);
-	addstr("\n\n");
-	refresh();
+	LYaddstr(ENTER_MESSAGE_BELOW);
+	LYaddstr(ENTER_PERIOD_WHEN_DONE_A);
+	LYaddstr(ENTER_PERIOD_WHEN_DONE_B);
+	LYaddstr("\n\n");
+	LYrefresh();
 	*user_input = '\0';
 	if (LYgetstr(user_input, VISIBLE, sizeof(user_input), NORECALL) < 0 ||
 	    term_letter || STREQ(user_input, ".")) {
@@ -1530,7 +1531,7 @@ PUBLIC void reply_by_mail ARGS4(
 	}
 
 	while (!STREQ(user_input, ".") && !term_letter) {
-	    addstr("\n");
+	    LYaddstr("\n");
 	    remove_tildes(user_input);
 	    fprintf(fd, "%s\n", user_input);
 	    *user_input = '\0';
@@ -1542,7 +1543,7 @@ PUBLIC void reply_by_mail ARGS4(
 
 	fprintf(fd, "\n");	/* Terminate the message. */
 	LYCloseTempFP(fd);	/* Close the tmpfile.	  */
-	scrollok(stdscr,FALSE); /* Stop scrolling.	  */
+	scrollok(LYwin,FALSE);	/* Stop scrolling.	  */
     }
 
 #if !USE_VMS_MAILER
@@ -1555,7 +1556,7 @@ PUBLIC void reply_by_mail ARGS4(
     c = HTConfirm (body ? SEND_MESSAGE_PROMPT : SEND_COMMENT_PROMPT);
     LYStatusLine = -1;
     if (c != YES) {
-	clear();  /* clear the screen */
+	LYclear();  /* clear the screen */
 	goto cleanup;
     }
     if ((body == NULL && LynxSigFile != NULL) &&
@@ -1584,7 +1585,7 @@ PUBLIC void reply_by_mail ARGS4(
 	}
 	LYCloseInput(fp);
     }
-    clear();  /* Clear the screen. */
+    LYclear();  /* Clear the screen. */
 
     /*
      *	Send the message.
@@ -1696,7 +1697,7 @@ PUBLIC void reply_by_mail ARGS4(
 cancelled:
     HTInfoMsg(CANCELLED);
     LYCloseTempFP(fd);		/* Close the tmpfile.	*/
-    scrollok(stdscr,FALSE); 	/* Stop scrolling.	*/
+    scrollok(LYwin,FALSE); 	/* Stop scrolling.	*/
 cleanup:
     signal(SIGINT, cleanup_sig);
     term_letter = FALSE;
diff --git a/src/LYMain.c b/src/LYMain.c
index 90015871..6d09793e 100644
--- a/src/LYMain.c
+++ b/src/LYMain.c
@@ -379,8 +379,8 @@ PUBLIC BOOLEAN LYUseDefaultRawMode = TRUE;
 PUBLIC char *UCAssume_MIMEcharset = NULL;
 PUBLIC BOOLEAN UCSaveBookmarksInUnicode = FALSE;
 PUBLIC BOOLEAN UCForce8bitTOUPPER = FALSE; /* override locale for case-conversion? */
-PUBLIC int LYlines = 24;
-PUBLIC int LYcols = 80;
+PUBLIC int LYlines = DFT_ROWS;
+PUBLIC int LYcols = DFT_COLS;
 PUBLIC int dump_output_width = 0;
 PUBLIC linkstruct links[MAXLINKS];
 PUBLIC histstruct history[MAXHIST];
@@ -423,6 +423,15 @@ PUBLIC char *LYCookieSRejectDomains = NULL; /* domains to reject all cookies */
 PUBLIC char *LYCookieSStrictCheckDomains = NULL; /* check strictly  */
 PUBLIC char *LYCookieSLooseCheckDomains = NULL;  /* check loosely   */
 PUBLIC char *LYCookieSQueryCheckDomains = NULL;  /* check w/a query */
+
+#ifndef DISABLE_BIBP
+PUBLIC BOOLEAN no_goto_bibp = FALSE;
+PUBLIC char *BibP_globalserver = NULL;   /* global server for bibp: links */
+PUBLIC char *BibP_bibhost = NULL;        /* local server for bibp: links  */
+PUBLIC BOOLEAN BibP_bibhost_checked = FALSE;  /*  until LYCheckBibHost   */
+PUBLIC BOOLEAN BibP_bibhost_available = FALSE;  /* until check succeeds  */
+#endif
+
 #ifdef EXP_PERSISTENT_COOKIES
 BOOLEAN persistent_cookies = FALSE;	/* disabled by default! */
 PUBLIC char *LYCookieFile = NULL;	/* cookie read file */
@@ -538,7 +547,7 @@ PUBLIC BOOLEAN restore_sigpipe_for_children = FALSE;
 PRIVATE void FatalProblem PARAMS((int sig));
 #endif /* !VMS */
 
-#if defined(USE_HASH)
+#if defined(USE_COLOR_STYLE)
 PUBLIC char *lynx_lss_file = NULL;
 #endif
 
@@ -624,6 +633,10 @@ PRIVATE void free_lynx_globals NOARGS
     FREE(LynxSigFile);
     FREE(system_mail);
     FREE(system_mail_flags);
+#ifndef DISABLE_BIBP
+    FREE(BibP_bibhost);
+    FREE(BibP_globalserver);
+#endif
 #ifdef EXP_PERSISTENT_COOKIES
     FREE(LYCookieFile);
     FREE(LYCookieSaveFile);
@@ -661,7 +674,7 @@ PRIVATE void free_lynx_globals NOARGS
     FREE(lynx_temp_space);
     FREE(LYTraceLogPath);
     FREE(lynx_cfg_file);
-#if defined(USE_HASH)
+#if defined(USE_COLOR_STYLE)
     FREE(lynx_lss_file);
 #endif
     FREE(UCAssume_MIMEcharset);
@@ -797,11 +810,12 @@ PRIVATE void tildeExpand ARGS2(
     }
 }
 
-PRIVATE BOOL GetStdin ARGS1(
-	char **,	buf)
+PRIVATE BOOL GetStdin ARGS2(
+	char **,	buf,
+	BOOL,		marker)
 {
     if (LYSafeGets(buf, stdin) != 0
-     && strncmp(*buf, "---", 3) != 0) {
+     && (!marker || strncmp(*buf, "---", 3) != 0)) {
 	LYTrimTrailing(*buf);
 	CTRACE((tfp, "...data: %s\n", *buf));
 	return TRUE;
@@ -1141,11 +1155,17 @@ PUBLIC int main ARGS2(
 #else
     StrAllocCopy(LYHostName, HTHostName());
 #endif /* LYNX_HOST_NAME */
+
     StrAllocCopy(LYLocalDomain, LOCAL_DOMAIN);
     StrAllocCopy(URLDomainPrefixes, URL_DOMAIN_PREFIXES);
     StrAllocCopy(URLDomainSuffixes, URL_DOMAIN_SUFFIXES);
     StrAllocCopy(XLoadImageCommand, XLOADIMAGE_COMMAND);
 
+#ifndef DISABLE_BIBP
+    StrAllocCopy(BibP_globalserver, BIBP_GLOBAL_SERVER);
+    StrAllocCopy(BibP_bibhost, "http://bibhost/");  /* protocol specified. */
+#endif
+
     /*
      *	Disable news posting if the compilation-based
      *	LYNewsPosting value is FALSE.  This may be changed
@@ -1195,7 +1215,7 @@ PUBLIC int main ARGS2(
 	char *buf = NULL;
 
 	CTRACE((tfp, "processing stdin arguments\n"));
-	while (GetStdin(&buf) != 0) {
+	while (GetStdin(&buf, TRUE)) {
 	    char *noargv[2];
 
 	    noargv[0] = buf;
@@ -1355,6 +1375,11 @@ PUBLIC int main ARGS2(
     /*
      *	Set up the compilation default character set. - FM
      */
+#ifdef CAN_AUTODETECT_DISPLAY_CHARSET
+    if (auto_display_charset >= 0)
+	current_char_set = auto_display_charset;
+    else
+#endif
     current_char_set = safeUCGetLYhndl_byMIME(CHARACTER_SET);
     /*
      *	Set up HTTP default for unlabeled charset (iso-8859-1).
@@ -1371,7 +1396,7 @@ PUBLIC int main ARGS2(
 	exit(EXIT_FAILURE);
     }
 
-#if defined(USE_HASH)
+#if defined(USE_COLOR_STYLE)
     /*
      *	If no alternate lynx-style file was specified on
      *	the command line, see if it's in the environment.
@@ -1403,7 +1428,7 @@ PUBLIC int main ARGS2(
     {
 	style_readFromFile(lynx_lss_file);
     }
-#endif /* USE_HASH */
+#endif /* USE_COLOR_STYLE */
 
 #ifdef USE_COLOR_TABLE
     /*
@@ -1525,7 +1550,7 @@ PUBLIC int main ARGS2(
 	CTRACE((tfp, "processing stdin startfile, tty=%s\n", tty));
 	if ((fp = LYOpenTemp (result, HTML_SUFFIX, "w")) != 0) {
 	    StrAllocCopy(startfile, result);
-	    while (GetStdin(&buf)) {
+	    while (GetStdin(&buf, FALSE)) {
 		fputs(buf, fp);
 		fputc('\n', fp);
 	    }
@@ -2098,9 +2123,6 @@ PUBLIC void reload_read_cfg NOARGS
 	   checked by caller. - kw */
 	return;
     }
-#if 0				/* therefore this isn't needed: */
-    if (LYRestricted) return;  /* for sure */
-#endif
 
     /*
      *  Current user preferences are saved in a temporary file, to be
@@ -2492,7 +2514,7 @@ PRIVATE int crawl_fun ARGS1(
 	char *,			next_arg GCC_UNUSED)
 {
     crawl = TRUE;
-    LYcols = 80;
+    LYcols = DFT_COLS;
     return 0;
 }
 
@@ -2502,21 +2524,36 @@ PRIVATE int display_fun ARGS1(
 {
     if (next_arg != 0) {
 	LYsetXDisplay(next_arg);
-#if 0		/* LYsetXDisplay already does this as a side effect  - kw */
-	if ((next_arg = LYgetXDisplay()) != 0)
-	    StrAllocCopy(x_display, next_arg);
-#endif
     }
 
     return 0;
 }
 
+/* -display_charset */
+PRIVATE int display_charset_fun ARGS1(
+	char *,			next_arg)
+{
+    int i = UCGetLYhndl_byMIME(next_arg);
+
+#ifdef CAN_AUTODETECT_DISPLAY_CHARSET
+    if (i < 0 && !stricmp(next_arg,"auto"))
+	i = auto_display_charset;
+#endif
+    if (i < 0) {	/* do nothing here: so fallback to lynx.cfg */
+	fprintf(stderr,
+		gettext("Lynx: ignoring unrecognized charset=%s\n"), next_arg);
+    }
+    else
+	current_char_set = i;
+    return 0;
+}
+
 /* -dump */
 PRIVATE int dump_output_fun ARGS1(
 	char *,			next_arg GCC_UNUSED)
 {
     dump_output_immediately = TRUE;
-    LYcols = 80;
+    LYcols = DFT_COLS;
     return 0;
 }
 
@@ -2576,7 +2613,7 @@ PRIVATE int get_data_fun ARGS1(
      */
 #ifndef VMS
     dump_output_immediately = TRUE;
-    LYcols = 80;
+    LYcols = DFT_COLS;
 #endif /* VMS */
 
     StrAllocCopy(form_get_data, "?");   /* Prime the pump */
@@ -2586,7 +2623,7 @@ PRIVATE int get_data_fun ARGS1(
      *  Build GET data for later.  Stop reading when we see a line
      *  with "---" as its first three characters.
      */
-    while (GetStdin(&buf)) {
+    while (GetStdin(&buf, TRUE)) {
 	StrAllocCat(*get_data, buf);
     }
 
@@ -2643,7 +2680,7 @@ PRIVATE int mime_header_fun ARGS1(
     dump_output_immediately = TRUE;
     HTOutputFormat = (LYPrependBase ?
 		      HTAtom_for("www/download") : HTAtom_for("www/dump"));
-    LYcols = 999;
+    LYcols = MAX_COLS;
     return 0;
 }
 
@@ -2777,7 +2814,7 @@ PRIVATE int post_data_fun ARGS1(
      */
 #ifndef VMS
     dump_output_immediately = TRUE;
-    LYcols = 80;
+    LYcols = DFT_COLS;
 #endif /* VMS */
 
     post_data = &form_post_data;
@@ -2786,7 +2823,7 @@ PRIVATE int post_data_fun ARGS1(
      * Build post data for later.  Stop reading when we see a line with "---"
      * as its first three characters.
      */
-    while (GetStdin(&buf)) {
+    while (GetStdin(&buf, TRUE)) {
 	StrAllocCat(*post_data, buf);
     }
     return 0;
@@ -2918,7 +2955,7 @@ PRIVATE int source_fun ARGS1(
     dump_output_immediately = TRUE;
     HTOutputFormat = (LYPrependBase ?
 		      HTAtom_for("www/download") : HTAtom_for("www/dump"));
-    LYcols = 999;
+    LYcols = MAX_COLS;
     return 0;
 }
 
@@ -2928,9 +2965,9 @@ PRIVATE int traversal_fun ARGS1(
 {
     traversal = TRUE;
 #ifdef USE_SLANG
-    LYcols = 80;
+    LYcols = DFT_COLS;
 #else
-    LYcols = 999;
+    LYcols = MAX_COLS;
 #endif /* USE_SLANG */
 
     return 0;
@@ -3025,7 +3062,7 @@ PRIVATE int width_fun ARGS1(
     if (next_arg != 0) {
 	int w = atoi(next_arg);
 	if (w > 0)
-	    dump_output_width = ((w < 999) ? w : 999);
+	    dump_output_width = ((w < MAX_COLS) ? w : MAX_COLS);
     }
 
     return 0;
@@ -3036,7 +3073,7 @@ PRIVATE Parse_Args_Type Arg_Table [] =
 {
    PARSE_SET(
       "accept_all_cookies", 4|SET_ARG,		&LYAcceptAllCookies,
-      "\naccept cookies without prompting if Set-Cookie handling is on"
+      "\naccept cookies without prompting if Set-Cookie handling\nis on"
    ),
    PARSE_FUN(
       "anonymous",	2|FUNCTION_ARG,		anonymous_fun,
@@ -3062,6 +3099,12 @@ PRIVATE Parse_Args_Type Arg_Table [] =
       "base",		4|FUNCTION_ARG,		base_fun,
       "prepend a request URL comment and BASE tag to text/html\noutputs for -source dumps"
    ),
+#ifndef DISABLE_BIBP
+   PARSE_STR(
+      "bibhost",	4|NEED_LYSTRING_ARG,	&BibP_bibhost,
+      "=URL\nlocal bibp server (default http://bibhost/)"
+   ),
+#endif
 #ifdef USE_SLANG
    PARSE_FUN(
       "blink",		4|FUNCTION_ARG,		blink_fun,
@@ -3101,7 +3144,7 @@ PRIVATE Parse_Args_Type Arg_Table [] =
    ),
    PARSE_STR(
        "cmd_script",	2|NEED_LYSTRING_ARG,	&lynx_cmd_script,
-       "=FILENAME\nread keystroke commands from the given file (see -cmd_log)"
+       "=FILENAME\nread keystroke commands from the given file\n(see -cmd_log)"
    ),
 #endif
    PARSE_FUN(
@@ -3123,7 +3166,7 @@ PRIVATE Parse_Args_Type Arg_Table [] =
 #ifdef MISC_EXP
    PARSE_SET(
       "convert_to",	4|FUNCTION_ARG,		convert_to_fun,
-      "=FORMAT\nconvert input, FORMAT is in MIME type notation (experimental)"
+      "=FORMAT\nconvert input, FORMAT is in MIME type notation\n(experimental)"
    ),
 #endif
 #ifdef EXP_PERSISTENT_COOKIES
@@ -3167,9 +3210,13 @@ with -dump, format output as with -traversal, but to stdout"
       "display",	4|NEED_FUNCTION_ARG,	display_fun,
       "=DISPLAY\nset the display variable for X exec'ed programs"
    ),
+   PARSE_FUN(
+      "display_charset", 4|NEED_FUNCTION_ARG,	display_charset_fun,
+      "=MIMEname\ncharset for the terminal output"
+   ),
    PARSE_SET(
       "dont_wrap_pre",	4|SET_ARG,		&dont_wrap_pre,
-      "inhibit wrapping of text in <pre> when -dump'ing and \n\
+      "inhibit wrapping of text in <pre> when -dump'ing and\n\
 -crawl'ing, mark wrapped lines in interactive session"
    ),
    PARSE_FUN(
@@ -3209,7 +3256,7 @@ keys (may be incompatible with some curses packages)"
 #endif
    PARSE_SET(
       "force_empty_hrefless_a",	4|SET_ARG,	&force_empty_hrefless_a,
-      "force HREF-less 'A' elements to be empty (close them as soon as they are seen)"
+      "\nforce HREF-less 'A' elements to be empty (close them as\nsoon as they are seen)"
    ),
    PARSE_SET(
       "force_html",	4|SET_ARG,		&LYforce_HTML_mode,
@@ -3251,7 +3298,7 @@ keys (may be incompatible with some curses packages)"
    ),
    PARSE_SET(
       "historical",	4|TOGGLE_ARG,		&historical_comments,
-      "toggles use of '>' or '-->' as a terminator for comments"
+      "toggles use of '>' or '-->' as terminator for comments"
    ),
    PARSE_FUN(
       "homepage",	4|NEED_FUNCTION_ARG,	homepage_fun,
@@ -3289,7 +3336,7 @@ keys (may be incompatible with some curses packages)"
       "enable local program execution from local files only"
    ),
 #endif /* EXEC_LINKS || EXEC_SCRIPTS */
-#if defined(USE_HASH)
+#if defined(USE_COLOR_STYLE)
    PARSE_STR(
       "lss",		2|NEED_LYSTRING_ARG,	&lynx_lss_file,
       "=FILENAME\nspecifies a lynx.lss file other than the default"
@@ -3358,7 +3405,7 @@ keys (may be incompatible with some curses packages)"
 #if HAVE_SIGACTION && defined(SIGWINCH)
    PARSE_SET(
       "nonrestarting_sigwinch", 4|SET_ARG,	&LYNonRestartingSIGWINCH,
-      "make window size change handler non-restarting"
+      "\nmake window size change handler non-restarting"
    ),
 #endif /* HAVE_SIGACTION */
    PARSE_FUN(
@@ -3440,7 +3487,7 @@ to visualize how lynx behaves with invalid HTML"
 #ifdef USE_PRETTYSRC
    PARSE_SET(
       "prettysrc",	4|SET_ARG,		&LYpsrc,
-      "do syntax highlighting and hyperlink handling in source view"
+      "do syntax highlighting and hyperlink handling in source\nview"
    ),
 #endif
    PARSE_SET(
@@ -3481,7 +3528,7 @@ with the PREV_DOC command or from the History List"
 #ifdef USE_SCROLLBAR
    PARSE_SET(
       "scrollbar",	4|TOGGLE_ARG,		&LYsb,
-      "toggles showing scrollbar (requires color styles)"
+      "toggles showing scrollbar"
    ),
    PARSE_SET(
       "scrollbar_arrow", 4|TOGGLE_ARG,		&LYsb_arrow,
@@ -3494,7 +3541,7 @@ with the PREV_DOC command or from the History List"
    ),
    PARSE_SET(
       "short_url",	4|SET_ARG,		&long_url_ok,
-      "enables examination of beginning and end of long URL in status line"
+      "enables examination of beginning and end of long URL in\nstatus line"
    ),
 #ifdef SH_EX
    PARSE_SET(
@@ -3610,7 +3657,7 @@ treated '>' as a co-terminator for double-quotes and tags"
 #ifdef __DJGPP__
    PARSE_SET(
       "wdebug",		4|TOGGLE_ARG,		&watt_debug,
-      "enables Waterloo tcp/ip packet debug. Prints to watt debugfile"
+      "enables Waterloo tcp/ip packet debug. Prints to watt\ndebugfile"
   ),
 #endif /* __DJGPP__ */
    PARSE_FUN(
@@ -3620,7 +3667,7 @@ treated '>' as a co-terminator for double-quotes and tags"
 #ifndef NO_DUMP_WITH_BACKSPACES
    PARSE_SET(
       "with_backspaces", 4|SET_ARG,		&with_backspaces,
-      "emit backspaces in output if -dumping or -crawling (like 'man' does)"
+      "emit backspaces in output if -dumping or -crawling\n(like 'man' does)"
    ),
 #endif
    {NULL, 0, 0, NULL}
@@ -3743,8 +3790,10 @@ PRIVATE int arg_eqs_parse ARGS3(
 	char *,		b,
 	char **,	c)
 {
+    int result = -1;
+
     *c = NULL;
-    while (1) {
+    while (result < 0) {
 	if ((*a != *b)
 	 || (*a == 0)
 	 || (*b == 0)) {
@@ -3753,30 +3802,43 @@ PRIVATE int arg_eqs_parse ARGS3(
 		case '\t':	/* embedded blank when reading stdin */
 		case ' ':
 		    *c = LYSkipBlanks(b);
-		    return 1;
+		    result = 1;
+		    break;
 		case '=':
 		case ':':
 		    *c = b + 1;
-		    return 1;
-		case '-':	/* FALLTHRU */
+		    result = 1;
+		    break;
+		case '-':
+#if OPTNAME_ALLOW_DASHES
+		    if (isalpha(b[1])) {
+			result = 0;
+			break;
+		    }
+#endif
+		    /* FALLTHRU */
 		case '+':
 		    *c = b;
-		    return 1;
+		    result = 1;
+		    break;
 		case 0:
-		    return 1;
+		    result = 1;
+		    break;
 		default:
-		    return 0;
+		    result = 0;
+		    break;
 		}
 	    } else {
 #if OPTNAME_ALLOW_DASHES
 		if (!(*a == '_' && *b == '-'))
 #endif
-		return 0;
+		result = 0;
 	    }
 	}
 	a++;
 	b++;
-     }
+    }
+    return result;
 }
 
 #define is_true(s)  (*s == '1' || *s == '+' || !strcmp(s, "on"))
diff --git a/src/LYMainLoop.c b/src/LYMainLoop.c
index aff86805..07a03944 100644
--- a/src/LYMainLoop.c
+++ b/src/LYMainLoop.c
@@ -38,6 +38,7 @@
 #include <LYCookie.h>
 #include <LYMainLoop.h>
 #include <LYPrettySrc.h>
+#include <GridText.h>
 
 #ifdef KANJI_CODE_OVERRIDE
 #include <HTCJK.h>
@@ -235,7 +236,7 @@ PRIVATE void free_mainloop_variables NOARGS
     FREE(curdoc.post_data);
     FREE(curdoc.post_content_type);
     FREE(curdoc.bookmark);
-#ifdef USE_HASH
+#ifdef USE_COLOR_STYLE
     FREE(curdoc.style);
     FREE(newdoc.style);
 #endif
@@ -396,6 +397,23 @@ PRIVATE BOOLEAN reparse_document NOARGS
 #endif /* SOURCE_CACHE */
 
 /*
+ * Prefer reparsing if we can, but reload if we must - to force regeneration
+ * of the display.
+ */
+PRIVATE BOOLEAN reparse_or_reload ARGS1(
+    int *,	cmd)
+{
+#ifdef SOURCE_CACHE
+    if (HTcan_reparse_document()) {
+	reparse_document();
+	return FALSE;
+    }
+#endif
+    *cmd = LYK_RELOAD;
+    return TRUE;
+}
+
+/*
  * This is for traversal call from within partial mode in LYUtils.c
  * and HTFormat.c  It simply calls HText_pageDisplay() but utilizes
  * LYMainLoop.c PRIVATE variables.
@@ -484,6 +502,50 @@ PRIVATE void do_check_goto_URL ARGS3(
     char **,	old_user_input,
     BOOLEAN *,	force_load)
 {
+    static BOOLEAN always = TRUE;
+    static struct {
+	CONST char *name;
+	BOOLEAN *flag;
+    } table[] = {
+	{ "file:",		&no_file_url },
+	{ "file:",		&no_goto_file },
+	{ "lynxexec:",		&no_goto_lynxexec },
+	{ "lynxprog:",		&no_goto_lynxprog },
+	{ "lynxcgi:",		&no_goto_lynxcgi },
+	{ "cso:",		&no_goto_cso },
+	{ "finger:",		&no_goto_finger },
+	{ "ftp:",		&no_goto_ftp },
+	{ "gopher:",		&no_goto_gopher },
+	{ "http:",		&no_goto_http },
+	{ "https:",		&no_goto_https },
+	{ "mailto:",		&no_goto_mailto },
+	{ "rlogin:",		&no_goto_rlogin },
+	{ "telnet:",		&no_goto_telnet },
+	{ "tn3270:",		&no_goto_tn3270 },
+	{ "wais:",		&no_goto_wais },
+#ifndef DISABLE_BIBP
+	{ "bibp:",		&no_goto_bibp },
+#endif
+#ifndef DISABLE_NEWS
+	{ "news:",		&no_goto_news },
+	{ "nntp:",		&no_goto_nntp },
+	{ "snews:",		&no_goto_snews },
+#endif
+#ifdef EXEC_LINKS
+	{ "lynxexec:",		&local_exec_on_local_files },
+	{ "lynxprog:",		&local_exec_on_local_files },
+#endif /* EXEC_LINKS */
+	{ "LYNXCFG:",		&no_goto_configinfo },
+	{ "LYNXCOMPILEOPTS:",	&no_goto_configinfo },
+	{ "LYNXCOOKIE:",	&always },
+	{ "LYNXDIRED:",		&always },
+	{ "LYNXDOWNLOAD:",	&always },
+	{ "LYNXOPTIONS:",	&always },
+	{ "LYNXPRINT:",		&always },
+    };
+    unsigned n;
+    BOOLEAN found = FALSE;
+
     /* allow going to anchors*/
     if (*user_input_buffer == '#' ) {
 	if ( user_input_buffer[1] &&
@@ -503,107 +565,21 @@ PRIVATE void do_check_goto_URL ARGS3(
 		(int)(MAX_LINE - 1), *old_user_input);
 	FREE(*old_user_input);
 
-	if ((no_file_url || no_goto_file) &&
-	    !strncmp(user_input_buffer,"file:",5)) {
-	    HTUserMsg(GOTO_FILE_DISALLOWED);
-
-	} else if ((no_shell || no_goto_lynxexec
-#ifdef EXEC_LINKS
-		    || local_exec_on_local_files
-#endif /* EXEC_LINKS */
-		    ) &&
-		   !strncmp(user_input_buffer, "lynxexec:",9)) {
-	    HTUserMsg(GOTO_EXEC_DISALLOWED);
-
-	} else if ((no_shell || no_goto_lynxprog
-#ifdef EXEC_LINKS
-		    || local_exec_on_local_files
-#endif /* EXEC_LINKS */
-		    ) &&
-		   !strncmp(user_input_buffer, "lynxprog:",9)) {
-	    HTUserMsg(GOTO_PROG_DISALLOWED);
-
-	} else if ((no_shell || no_goto_lynxcgi) &&
-		   !strncmp(user_input_buffer, "lynxcgi:", 8)) {
-	    HTUserMsg(GOTO_CGI_DISALLOWED);
-
+	for (n = 0; n < TABLESIZE(table); n++) {
+	    if (*(table[n].flag)
+	     && !strncmp(user_input_buffer, table[n].name, strlen(table[n].name))) {
+		found = TRUE;
+		HTUserMsg2(GOTO_XXXX_DISALLOWED, table[n].name);
+		break;
+	    }
+	}
+	if (found) {
+	    ;
 	} else if (LYValidate &&
 		   strncmp(user_input_buffer, "http:", 5) &&
 		   strncmp(user_input_buffer, "https:", 6)) {
 	    HTUserMsg(GOTO_NON_HTTP_DISALLOWED);
 
-	} else if (no_goto_cso &&
-		   !strncmp(user_input_buffer, "cso:", 4)) {
-	    HTUserMsg(GOTO_CSO_DISALLOWED);
-
-	} else if (no_goto_finger &&
-		   !strncmp(user_input_buffer, "finger:", 7)) {
-	    HTUserMsg(GOTO_FINGER_DISALLOWED);
-
-	} else if (no_goto_ftp &&
-		   !strncmp(user_input_buffer, "ftp:", 4)) {
-	    HTUserMsg(GOTO_FTP_DISALLOWED);
-
-	} else if (no_goto_gopher &&
-		   !strncmp(user_input_buffer, "gopher:", 7)) {
-	    HTUserMsg(GOTO_GOPHER_DISALLOWED);
-
-	} else if (no_goto_http &&
-		   !strncmp(user_input_buffer, "http:", 5)) {
-	    HTUserMsg(GOTO_HTTP_DISALLOWED);
-
-	} else if (no_goto_https &&
-		   !strncmp(user_input_buffer, "https:", 6)) {
-	    HTUserMsg(GOTO_HTTPS_DISALLOWED);
-
-	} else if (no_goto_mailto &&
-		   !strncmp(user_input_buffer, "mailto:", 7)) {
-	    HTUserMsg(GOTO_MAILTO_DISALLOWED);
-
-#ifndef DISABLE_NEWS
-	} else if (no_goto_news &&
-		   !strncmp(user_input_buffer, "news:", 5)) {
-	    HTUserMsg(GOTO_NEWS_DISALLOWED);
-
-	} else if (no_goto_nntp &&
-		   !strncmp(user_input_buffer, "nntp:", 5)) {
-	    HTUserMsg(GOTO_NNTP_DISALLOWED);
-#endif
-
-	} else if (no_goto_rlogin &&
-		   !strncmp(user_input_buffer, "rlogin:", 7)) {
-	    HTUserMsg(GOTO_RLOGIN_DISALLOWED);
-
-#ifndef DISABLE_NEWS
-	} else if (no_goto_snews &&
-		   !strncmp(user_input_buffer, "snews:", 6)) {
-	    HTUserMsg(GOTO_SNEWS_DISALLOWED);
-#endif
-
-	} else if (no_goto_telnet &&
-		   !strncmp(user_input_buffer, "telnet:", 7)) {
-	    HTUserMsg(GOTO_TELNET_DISALLOWED);
-
-	} else if (no_goto_tn3270 &&
-		   !strncmp(user_input_buffer, "tn3270:", 7)) {
-	    HTUserMsg(GOTO_TN3270_DISALLOWED);
-
-	} else if (no_goto_wais &&
-		   !strncmp(user_input_buffer, "wais:", 5)) {
-	    HTUserMsg(GOTO_WAIS_DISALLOWED);
-
-	} else if (no_goto_configinfo &&
-		   (!strncmp(user_input_buffer, "LYNXCFG:", 8) ||
-		    !strncmp(user_input_buffer, "LYNXCOMPILEOPTS:", 16))) {
-	    HTUserMsg(GOTO_SPECIAL_DISALLOWED);
-
-	} else if (!strncmp(user_input_buffer, "LYNXCOOKIE:", 11) ||
-		   !strncmp(user_input_buffer, "LYNXDIRED:", 10) ||
-		   !strncmp(user_input_buffer, "LYNXDOWNLOAD:", 13) ||
-		   !strncmp(user_input_buffer, "LYNXOPTIONS:", 12) ||
-		   !strncmp(user_input_buffer, "LYNXPRINT:", 10)) {
-	    HTUserMsg(GOTO_SPECIAL_DISALLOWED);
-
 	} else {
 	    StrAllocCopy(newdoc.address, user_input_buffer);
 	    newdoc.isHEAD = FALSE;
@@ -1836,7 +1812,7 @@ PRIVATE void handle_LYK_CREATE NOARGS
 	    newdoc.safe = FALSE;
 	    newdoc.line = curdoc.line;
 	    newdoc.link = curdoc.link > -1 ? curdoc.link : 0;
-	    clear();
+	    LYclear();
 	}
     }
 }
@@ -2301,7 +2277,7 @@ PRIVATE int handle_LYK_DWIMEDIT ARGS3(
      *  contents, rather than attempting to edit the html source
      *  document.  KED
      */
-    if (nlinks > 0  && 
+    if (nlinks > 0  &&
 	links[curdoc.link].type       == WWW_FORM_LINK_TYPE &&
 	links[curdoc.link].form->type == F_TEXTAREA_TYPE)   {
 	*cmd = LYK_EDIT_TEXTAREA;
@@ -2467,7 +2443,7 @@ PRIVATE void handle_LYK_EDIT ARGS2(
 			    newdoc.line = curdoc.line;
 			    newdoc.link = curdoc.link;
 #endif /* NO_SEEK_OLD_POSITION */
-			    clear();  /* clear the screen */
+			    LYclear();  /* clear the screen */
 			}
 		    }
 		}
@@ -2494,7 +2470,7 @@ PRIVATE void handle_LYK_EDIT ARGS2(
 	    newdoc.line = curdoc.line;
 	    newdoc.link = curdoc.link;
 #endif /* NO_SEEK_OLD_POSITION */
-	    clear();  /* clear the screen */
+	    LYclear();  /* clear the screen */
 	}
 
     } else {
@@ -3151,9 +3127,9 @@ PRIVATE BOOLEAN handle_LYK_HISTORY ARGS1(
 	if (TRACE && !LYUseTraceLog && LYCursesON) {
 	    LYHideCursor();	/* make sure cursor is down */
 #ifdef USE_SLANG
-	    addstr("\n");
+	    LYaddstr("\n");
 #endif /* USE_SLANG */
-	    refresh();
+	    LYrefresh();
 	}
 	LYpush(&curdoc, ForcePush);
 
@@ -3193,14 +3169,7 @@ PRIVATE BOOLEAN handle_LYK_IMAGE_TOGGLE ARGS1(
 
     HTUserMsg(clickable_images ?
 	     CLICKABLE_IMAGES_ON : CLICKABLE_IMAGES_OFF);
-#ifdef SOURCE_CACHE
-    if (HTcan_reparse_document()) {
-	reparse_document();
-	return FALSE;
-    }
-#endif
-    *cmd = LYK_RELOAD;
-    return TRUE;
+    return reparse_or_reload(cmd);
 }
 
 PRIVATE void handle_LYK_INDEX ARGS2(
@@ -3262,9 +3231,9 @@ PRIVATE void handle_LYK_INDEX_SEARCH ARGS4(
 		 */
 		LYHideCursor();
 #ifdef USE_SLANG
-		addstr("\n");
+		LYaddstr("\n");
 #endif /* USE_SLANG */
-		refresh();
+		LYrefresh();
 	    }
 	    LYpush(&curdoc, ForcePush);
 	    /*
@@ -3358,14 +3327,7 @@ PRIVATE BOOLEAN handle_LYK_INLINE_TOGGLE ARGS1(
 
     HTUserMsg(pseudo_inline_alts ?
 	      PSEUDO_INLINE_ALTS_ON : PSEUDO_INLINE_ALTS_OFF);
-#ifdef SOURCE_CACHE
-    if (HTcan_reparse_document()) {
-	reparse_document();
-	return FALSE;
-    }
-#endif
-    *cmd = LYK_RELOAD;
-    return TRUE;
+    return reparse_or_reload(cmd);
 }
 
 PRIVATE void handle_LYK_INSERT_FILE ARGS3(
@@ -3397,7 +3359,7 @@ PRIVATE void handle_LYK_INSERT_FILE ARGS3(
 	    if (*old_c != real_c) {
 		*old_c = real_c;
 		if (no_goto_file)
-		    HTUserMsg(GOTO_FILE_DISALLOWED);
+		    HTUserMsg2(GOTO_XXXX_DISALLOWED, "file:");
 		else
 		    HTUserMsg(NOAUTH_TO_ACCESS_FILES);
 		HTInfoMsg(FILE_INSERT_CANCELLED);
@@ -3700,7 +3662,7 @@ PRIVATE void handle_LYK_MODIFY ARGS1(
 	    newdoc.internal_link = FALSE;
 	    newdoc.line = curdoc.line;
 	    newdoc.link = curdoc.link;
-	    clear();
+	    LYclear();
 	}
     }
 }
@@ -4193,14 +4155,7 @@ PRIVATE BOOLEAN handle_LYK_RAW_TOGGLE ARGS1(
 	LYUseDefaultRawMode = (BOOL) !LYUseDefaultRawMode;
 	HTUserMsg(LYRawMode ? RAWMODE_OFF : RAWMODE_ON);
 	HTMLSetCharacterHandling(current_char_set);
-#ifdef SOURCE_CACHE
-	if (HTcan_reparse_document()) {
-	    reparse_document();
-	    return FALSE;
-	}
-#endif
-	*cmd = LYK_RELOAD;
-	return TRUE;
+	return reparse_or_reload(cmd);
     }
 }
 
@@ -5132,7 +5087,7 @@ PUBLIC void handle_LYK_CHDIR NOARGS
 
 	    newdoc.address = addr;
 	    newdoc.isHEAD = FALSE;
-            StrAllocCopy(newdoc.title, gettext("A URL specified by the user"));
+	    StrAllocCopy(newdoc.title, gettext("A URL specified by the user"));
 	    FREE(newdoc.post_data);
 	    FREE(newdoc.post_content_type);
 	    FREE(newdoc.bookmark);
@@ -5150,6 +5105,46 @@ PUBLIC void handle_LYK_CHDIR NOARGS
 }
 #endif
 
+#ifdef USE_CURSES_PADS
+PRIVATE void handle_LYK_SHIFT_LEFT ARGS1(BOOLEAN *, flag)
+{
+    if (LYlineWrap) {
+	HTAlert(SHIFT_VS_LINEWRAP);
+    } else {
+	if (LYshiftWin > 0) {
+	    LYshiftWin--;
+	    *flag = TRUE;
+	}
+    }
+}
+
+PRIVATE void handle_LYK_SHIFT_RIGHT ARGS1(BOOLEAN *, flag)
+{
+    if (LYlineWrap) {
+	HTAlert(SHIFT_VS_LINEWRAP);
+    } else {
+	LYshiftWin++;
+	*flag = TRUE;
+    }
+}
+
+PRIVATE BOOLEAN handle_LYK_LINEWRAP_TOGGLE ARGS2(
+    int *,	cmd,
+    BOOLEAN *,	flag)
+{
+    LYlineWrap = !LYlineWrap;
+    if (LYlineWrap != 0) {
+	LYcols = LYscreenWidth();
+	LYshiftWin = 0;
+    } else {
+	LYcols = MAX_COLS;
+    }
+    *flag = TRUE;
+    HTUserMsg(LYlineWrap ? LINEWRAP_ON : LINEWRAP_OFF);
+    return reparse_or_reload(cmd);
+}
+#endif
+
 /*
  *  Here's where we do all the work.
  *  mainloop is basically just a big switch dependent on the users input.
@@ -5223,7 +5218,7 @@ int mainloop NOARGS
     curdoc.post_content_type = NULL;
     curdoc.bookmark = NULL;
     curdoc.internal_link = FALSE;
-#ifdef USE_HASH
+#ifdef USE_COLOR_STYLE
     curdoc.style = NULL;
     newdoc.style = NULL;
 #endif
@@ -5245,8 +5240,8 @@ initialize:
 
 #ifdef USE_SLANG
     if (TRACE && LYCursesON) {
-	addstr("\n");
-	refresh();
+	LYaddstr("\n");
+	LYrefresh();
     }
 #endif /* USE_SLANG */
     CTRACE((tfp, "Entering mainloop, startfile=%s\n", startfile));
@@ -5302,7 +5297,7 @@ initialize:
 	display_lines = LYlines-2;
 
     while (TRUE) {
-#ifdef USE_HASH
+#ifdef USE_COLOR_STYLE
 	if (curdoc.style != NULL) force_load = TRUE;
 #endif
 	/*
@@ -5316,9 +5311,9 @@ initialize:
 		if (TRACE && LYCursesON) {
 		    LYHideCursor();	/* make sure cursor is down */
 #ifdef USE_SLANG
-		    addstr("\n");
+		    LYaddstr("\n");
 #endif /* USE_SLANG */
-		    refresh();
+		    LYrefresh();
 		}
 try_again:
 		/*
@@ -5837,7 +5832,7 @@ try_again:
 							(BookmarkPage + 2)));
 				    StrAllocCopy(newdoc.title, BOOKMARK_TITLE);
 				    StrAllocCopy(newdoc.bookmark, BookmarkPage);
-#ifdef USE_HASH
+#ifdef USE_COLOR_STYLE
 				    if (curdoc.style)
 					StrAllocCopy(newdoc.style, curdoc.style);
 #endif
@@ -5952,7 +5947,7 @@ try_again:
 	    StrAllocCopy(curdoc.post_data, newdoc.post_data);
 	    StrAllocCopy(curdoc.post_content_type, newdoc.post_content_type);
 	    StrAllocCopy(curdoc.bookmark, newdoc.bookmark);
-#ifdef USE_HASH
+#ifdef USE_COLOR_STYLE
 	    StrAllocCopy(curdoc.style, HText_getStyle());
 	    if (curdoc.style != NULL)
 		style_readFromFile (curdoc.style);
@@ -6047,7 +6042,7 @@ try_again:
 #else
 	    stop_curses();
 	    start_curses();
-	    clear();
+	    LYclear();
 #endif
 	    refresh_screen = TRUE; /* to force a redraw */
 	    if (HTMainText)	/* to REALLY force it... - kw */
@@ -6297,12 +6292,12 @@ try_again:
 	if (refresh_screen) {
 #if defined(FANCY_CURSES) || defined (USE_SLANG)
 	    if (enable_scrollback) {
-		clear();
+		LYclear();
 	    } else {
-		erase();
+		LYerase();
 	    }
 #else
-	    clear();
+	    LYclear();
 #endif /* FANCY_CURSES || USE_SLANG */
 	   HText_pageDisplay(Newline, prev_target);
 
@@ -6677,7 +6672,7 @@ try_again:
 				    links[curdoc.link].form->value,
 				    use_last_tfpos, FALSE, TRUE);
 		    if (LYShowCursor) {
-			move(links[curdoc.link].ly,
+			LYmove(links[curdoc.link].ly,
 			     ((links[curdoc.link].lx > 0) ?
 			      (links[curdoc.link].lx - 1) : 0));
 		    } else {
@@ -6798,7 +6793,7 @@ new_cmd:  /*
 
 	    if (TRACE) {
 		sprintf(cfile, "%d", c);
-		addstr(cfile);	/* show the user input */
+		LYaddstr(cfile);	/* show the user input */
 		cfile[0] = '\0';
 	    }
 	    break;
@@ -6865,12 +6860,6 @@ new_cmd:  /*
 	    handle_LYK_SWITCH_DTD();
 	    break;
 
-#ifdef NOT_DONE_YET
-	case LYK_PIPE:
-	    /* ignore for now */
-	    break;
-#endif /* NOT_DONE_YET */
-
 	case LYK_QUIT:		/* quit */
 	    if (handle_LYK_QUIT())
 		return(EXIT_SUCCESS);
@@ -6932,9 +6921,9 @@ new_cmd:  /*
 		    break;
 		}
 	    }
-	    move(0, 0);
+	    LYmove(0, 0);
 	    lynx_start_title_color ();
-	    addstr(str_kcode(last_kcode));
+	    LYaddstr(str_kcode(last_kcode));
 	    lynx_stop_title_color ();
 
 	    break;
@@ -6955,9 +6944,10 @@ new_cmd:  /*
 	    break;
 
 	case LYK_END:
-	    if (more) {
-	       Newline = HText_getNumOfLines() - display_lines + 3;  /* go to end of file */
-	       arrowup = TRUE;	 /* position on last link */
+	    i = HText_getNumOfLines() - display_lines + 2;
+	    if (i >= 1 && Newline != i) {
+		Newline = i;		/* go to end of file */
+		arrowup = TRUE;		/* position on last link */
 	    } else {
 		cmd = LYK_NEXT_PAGE;
 		goto new_cmd;
@@ -7286,6 +7276,18 @@ new_cmd:  /*
 	    handle_LYK_CHDIR();
 	    break;
 #endif
+#ifdef USE_CURSES_PADS
+	case LYK_SHIFT_LEFT:
+	    handle_LYK_SHIFT_LEFT(&refresh_screen);
+	    break;
+	case LYK_SHIFT_RIGHT:
+	    handle_LYK_SHIFT_RIGHT(&refresh_screen);
+	    break;
+	case LYK_LINEWRAP_TOGGLE:
+	    if (handle_LYK_LINEWRAP_TOGGLE(&cmd, &refresh_screen))
+		goto new_cmd;
+	    break;
+#endif
 	} /* end of BIG switch */
     }
 }
@@ -7536,9 +7538,9 @@ PRIVATE void show_main_statusline ARGS2(
 	 */
 	if (is_www_index) {
 	    char *indx = gettext("-index-");
-	    move(LYlines-1, LYcols - strlen(indx) - 1);
+	    LYmove(LYlines-1, LYcols - strlen(indx) - 1);
 	    start_reverse();
-	    addstr(indx);
+	    LYaddstr(indx);
 	    stop_reverse();
 	}
 
@@ -7599,17 +7601,17 @@ PUBLIC void repaint_main_statusline ARGS1(
 PRIVATE void form_noviceline ARGS1(
     int,	disabled)
 {
-    move(LYlines-2,0); clrtoeol();
+    LYmove(LYlines-2,0); LYclrtoeol();
     if (!disabled) {
-	addstr(FORM_NOVICELINE_ONE);
+	LYaddstr(FORM_NOVICELINE_ONE);
     }
-    move(LYlines-1,0); clrtoeol();
+    LYmove(LYlines-1,0); LYclrtoeol();
     if (disabled)
 	return;
     if (EditBinding(FROMASCII('\025')) == LYE_ERASE) {
-	addstr(FORM_NOVICELINE_TWO);
+	LYaddstr(FORM_NOVICELINE_TWO);
     } else if (EditBinding(FROMASCII('\025')) == LYE_DELBL) {
-	addstr(FORM_NOVICELINE_TWO_DELBL);
+	LYaddstr(FORM_NOVICELINE_TWO_DELBL);
     } else {
 	char *temp = NULL;
 	char *erasekey = fmt_keys(LYKeyForEditAction(LYE_ERASE), -1);
@@ -7622,7 +7624,7 @@ PRIVATE void form_noviceline ARGS1(
 			   FORM_NOVICELINE_TWO_DELBL_VAR, erasekey);
 	}
 	if (temp) {
-	    addstr(temp);
+	    LYaddstr(temp);
 	    FREE(temp);
 	}
 	FREE(erasekey);
diff --git a/src/LYNews.c b/src/LYNews.c
index 14b88930..50900b80 100644
--- a/src/LYNews.c
+++ b/src/LYNews.c
@@ -197,19 +197,19 @@ PUBLIC char *LYNewsPost ARGS2(
     /*
      *  Show the list of newsgroups. - FM
      */
-    clear();
-    move(2,0);
-    scrollok(stdscr, TRUE);	/* Enable scrolling. */
-    addstr(gettext("You will be posting to:"));
-    addstr("\n\t");
-    addstr(NewsGroups);
-    addch('\n');
+    LYclear();
+    LYmove(2,0);
+    scrollok(LYwin, TRUE);		/* Enable scrolling. */
+    LYaddstr(gettext("You will be posting to:"));
+    LYaddstr("\n\t");
+    LYaddstr(NewsGroups);
+    LYaddch('\n');
 
     /*
      *  Get the mail address for the From header,
      *  offering personal_mail_address as default.
      */
-    addstr(gettext("\n\n Please provide your mail address for the From: header\n"));
+    LYaddstr(gettext("\n\n Please provide your mail address for the From: header\n"));
     sprintf(user_input, "From: %.*s", (int)sizeof(user_input) - 8,
 	    (personal_mail_address != NULL) ? personal_mail_address : "");
     if (LYgetstr(user_input, VISIBLE,
@@ -217,7 +217,7 @@ PUBLIC char *LYNewsPost ARGS2(
 	term_message) {
 	HTInfoMsg(NEWS_POST_CANCELLED);
 	LYCloseTempFP(fd);		/* Close the temp file.	*/
-	scrollok(stdscr, FALSE);	/* Stop scrolling.	*/
+	scrollok(LYwin, FALSE);		/* Stop scrolling.	*/
 	goto cleanup;
     }
     fprintf(fd, "%s\n", user_input);
@@ -227,7 +227,7 @@ PUBLIC char *LYNewsPost ARGS2(
      *  document's title as the default if this is a
      *  followup rather than a new post. - FM
      */
-    addstr(gettext("\n\n Please provide or edit the Subject: header\n"));
+    LYaddstr(gettext("\n\n Please provide or edit the Subject: header\n"));
     strcpy(user_input, "Subject: ");
     if ((followup == TRUE && nhist > 0) &&
 	(kp = HText_getTitle()) != NULL) {
@@ -264,7 +264,7 @@ PUBLIC char *LYNewsPost ARGS2(
 	term_message) {
 	HTInfoMsg(NEWS_POST_CANCELLED);
 	LYCloseTempFP(fd);		/* Close the temp file. */
-	scrollok(stdscr, FALSE);	/* Stop scrolling.	*/
+	scrollok(LYwin, FALSE);		/* Stop scrolling.	*/
 	goto cleanup;
     }
     fprintf(fd,"%s\n",user_input);
@@ -319,13 +319,13 @@ PUBLIC char *LYNewsPost ARGS2(
 #endif /* !UNIX */
     LYstrncpy(user_input, cp, (sizeof(user_input) - 16));
     FREE(cp);
-    addstr(gettext("\n\n Please provide or edit the Organization: header\n"));
+    LYaddstr(gettext("\n\n Please provide or edit the Organization: header\n"));
     if (LYgetstr(user_input, VISIBLE,
 		 sizeof(user_input), NORECALL) < 0 ||
 	term_message) {
 	HTInfoMsg(NEWS_POST_CANCELLED);
 	LYCloseTempFP(fd);		/* Close the temp file. */
-	scrollok(stdscr, FALSE);	/* Stop scrolling.	*/
+	scrollok(LYwin, FALSE);		/* Stop scrolling.	*/
 	goto cleanup;
     }
     fprintf(fd, "%s\n", user_input);
@@ -365,7 +365,7 @@ PUBLIC char *LYNewsPost ARGS2(
 	    }
 	}
 	LYCloseTempFP(fd);		/* Close the temp file. */
-	scrollok(stdscr, FALSE);	/* Stop scrolling.	*/
+	scrollok(LYwin, FALSE);		/* Stop scrolling.	*/
 	if (term_message || LYCharIsINTERRUPT(c))
 	    goto cleanup;
 
@@ -392,22 +392,22 @@ PUBLIC char *LYNewsPost ARGS2(
 	/*
 	 *  Use the built in line editior.
 	 */
-	addstr(gettext("\n\n Please enter your message below."));
-	addstr(gettext("\n When you are done, press enter and put a single period (.)"));
-	addstr(gettext("\n on a line and press enter again."));
-	addstr("\n\n");
-	refresh();
+	LYaddstr(gettext("\n\n Please enter your message below."));
+	LYaddstr(gettext("\n When you are done, press enter and put a single period (.)"));
+	LYaddstr(gettext("\n on a line and press enter again."));
+	LYaddstr("\n\n");
+	LYrefresh();
 	*user_input = '\0';
 	if (LYgetstr(user_input, VISIBLE,
 		     sizeof(user_input), NORECALL) < 0 ||
 	    term_message) {
 	    HTInfoMsg(NEWS_POST_CANCELLED);
 	    LYCloseTempFP(fd);		/* Close the temp file.	*/
-	    scrollok(stdscr, FALSE);	/* Stop scrolling.	*/
+	    scrollok(LYwin, FALSE);	/* Stop scrolling.	*/
 	    goto cleanup;
 	}
 	while (!STREQ(user_input,".") && !term_message) {
-	    addch('\n');
+	    LYaddch('\n');
 	    fprintf(fd,"%s\n",user_input);
 	    if (!nonempty && strlen(user_input))
 		nonempty = TRUE;
@@ -415,14 +415,14 @@ PUBLIC char *LYNewsPost ARGS2(
 	    if (LYgetstr(user_input, VISIBLE,
 			 sizeof(user_input), NORECALL) < 0) {
 		HTInfoMsg(NEWS_POST_CANCELLED);
-		LYCloseTempFP(fd);		/* Close the temp file. */
-		scrollok(stdscr, FALSE);	/* Stop scrolling.	*/
+		LYCloseTempFP(fd);	/* Close the temp file. */
+		scrollok(LYwin, FALSE);	/* Stop scrolling.	*/
 		goto cleanup;
 	    }
 	}
 	fprintf(fd, "\n");
 	LYCloseTempFP(fd);		/* Close the temp file. */
-	scrollok(stdscr, FALSE);	/* Stop scrolling.	*/
+	scrollok(LYwin, FALSE);		/* Stop scrolling.	*/
     }
 
     if (nonempty) {
@@ -434,7 +434,7 @@ PUBLIC char *LYNewsPost ARGS2(
 	c = HTConfirm(POST_MSG_PROMPT);
 	LYStatusLine = -1;
 	if (c != YES) {
-	    clear();  /* clear the screen */
+	    LYclear();  /* clear the screen */
 	    goto cleanup;
 	}
     } else {
@@ -464,7 +464,7 @@ PUBLIC char *LYNewsPost ARGS2(
 	FREE(msg);
 	LYStatusLine = -1;
     }
-    clear();  /* clear the screen */
+    LYclear();  /* clear the screen */
 
     /*
      *  If we are using a Japanese display character
@@ -539,7 +539,7 @@ PRIVATE void terminate_message ARGS1(
      *  Refresh the screen to get rid of the "interrupt" message.
      */
     lynx_force_repaint();
-    refresh();
+    LYrefresh();
 #endif /* VMS */
 }
 
diff --git a/src/LYOptions.c b/src/LYOptions.c
index 509f7420..62412036 100644
--- a/src/LYOptions.c
+++ b/src/LYOptions.c
@@ -196,13 +196,13 @@ PRIVATE int add_it ARGS2(char *, text, int, len)
 {
     if (len) {
 	text[len] = '\0';
-	addstr(text);
+	LYaddstr(text);
     }
     return 0;
 }
 
 /*
- * addlbl() is used instead of plain addstr() in old-style options menu
+ * addlbl() is used instead of plain LYaddstr() in old-style options menu
  * to show hot keys in bold.
  */
 PRIVATE void addlbl ARGS1(CONST char *, text)
@@ -317,225 +317,225 @@ draw_options:
     response = 0;
 #if defined(FANCY_CURSES) || defined (USE_SLANG)
     if (enable_scrollback) {
-	clear();
+	LYclear();
     } else {
-	erase();
+	LYerase();
     }
 #else
-    clear();
+    LYclear();
 #endif /* FANCY_CURSES || USE_SLANG */
-    move(0, 5);
+    LYmove(0, 5);
 
     lynx_start_h1_color ();
-    addstr("         Options Menu (");
-    addstr(LYNX_NAME);
-    addstr(" Version ");
-    addstr(LYNX_VERSION);
-    addch(')');
+    LYaddstr("         Options Menu (");
+    LYaddstr(LYNX_NAME);
+    LYaddstr(" Version ");
+    LYaddstr(LYNX_VERSION);
+    LYaddch(')');
     lynx_stop_h1_color ();
-    move(L_EDITOR, 5);
+    LYmove(L_EDITOR, 5);
     addlbl("(E)ditor                     : ");
-    addstr((editor && *editor) ? editor : "NONE");
+    LYaddstr((editor && *editor) ? editor : "NONE");
 
-    move(L_DISPLAY, 5);
+    LYmove(L_DISPLAY, 5);
     addlbl("(D)ISPLAY variable           : ");
-    addstr((x_display && *x_display) ? x_display : "NONE");
+    LYaddstr((x_display && *x_display) ? x_display : "NONE");
 
-    move(L_HOME, 5);
+    LYmove(L_HOME, 5);
     addlbl("mu(L)ti-bookmarks: ");
-    addstr((LYMultiBookmarks ?
+    LYaddstr((LYMultiBookmarks ?
 	      (LYMBMAdvanced ? "ADVANCED"
 			     : "STANDARD")
 			     : "OFF     "));
-    move(L_HOME, B_BOOK);
+    LYmove(L_HOME, B_BOOK);
     if (LYMultiBookmarks) {
 	addlbl("review/edit (B)ookmarks files");
     } else {
 	addlbl("(B)ookmark file: ");
-	addstr((bookmark_page && *bookmark_page) ? bookmark_page : "NONE");
+	LYaddstr((bookmark_page && *bookmark_page) ? bookmark_page : "NONE");
     }
 
-    move(L_FTPSTYPE, 5);
+    LYmove(L_FTPSTYPE, 5);
     addlbl("(F)TP sort criteria          : ");
-    addstr((HTfileSortMethod == FILE_BY_NAME ? "By Filename" :
+    LYaddstr((HTfileSortMethod == FILE_BY_NAME ? "By Filename" :
 	   (HTfileSortMethod == FILE_BY_SIZE ? "By Size    " :
 	   (HTfileSortMethod == FILE_BY_TYPE ? "By Type    " :
 					       "By Date    "))));
 
-    move(L_MAIL_ADDRESS, 5);
+    LYmove(L_MAIL_ADDRESS, 5);
     addlbl("(P)ersonal mail address      : ");
-    addstr((personal_mail_address && *personal_mail_address) ?
+    LYaddstr((personal_mail_address && *personal_mail_address) ?
 				       personal_mail_address : "NONE");
 
-    move(L_SSEARCH, 5);
+    LYmove(L_SSEARCH, 5);
     addlbl("(S)earching type             : ");
-    addstr(case_sensitive ? "CASE SENSITIVE  " : "CASE INSENSITIVE");
+    LYaddstr(case_sensitive ? "CASE SENSITIVE  " : "CASE INSENSITIVE");
 
-    move(L_Charset, 5);
+    LYmove(L_Charset, 5);
     addlbl("display (C)haracter set      : ");
     LYaddstr(LYchar_set_names[current_char_set]);
 
-    move(L_LANGUAGE, 5);
+    LYmove(L_LANGUAGE, 5);
     addlbl("preferred document lan(G)uage: ");
-    addstr((language && *language) ? language : "NONE");
+    LYaddstr((language && *language) ? language : "NONE");
 
-    move(L_PREF_CHARSET, 5);
+    LYmove(L_PREF_CHARSET, 5);
     addlbl("preferred document c(H)arset : ");
-    addstr((pref_charset && *pref_charset) ? pref_charset : "NONE");
+    LYaddstr((pref_charset && *pref_charset) ? pref_charset : "NONE");
 
     if (use_assume_charset) {
-	move(L_ASSUME_CHARSET, 5);
+	LYmove(L_ASSUME_CHARSET, 5);
 	addlbl("(^A)ssume charset if unknown : ");
 	if (UCAssume_MIMEcharset)
-	    addstr(UCAssume_MIMEcharset);
+	    LYaddstr(UCAssume_MIMEcharset);
 	else
 	    LYaddstr((UCLYhndl_for_unspec >= 0) ?
 		     LYCharSet_UC[UCLYhndl_for_unspec].MIMEname
 					      : "NONE");
     }
 
-    move(L_Rawmode, 5);
+    LYmove(L_Rawmode, 5);
     addlbl("Raw 8-bit or CJK m(O)de      : ");
-    addstr(LYRawMode ? "ON " : "OFF");
+    LYaddstr(LYRawMode ? "ON " : "OFF");
 
 #if defined(USE_SLANG) || defined(COLOR_CURSES)
-    move(L_Color, B_COLOR);
+    LYmove(L_Color, B_COLOR);
     addlbl("show color (&)  : ");
     if (no_option_save) {
-	addstr((LYShowColor == SHOW_COLOR_OFF ? "OFF" :
+	LYaddstr((LYShowColor == SHOW_COLOR_OFF ? "OFF" :
 						"ON "));
     } else {
 	switch (LYChosenShowColor) {
 	case SHOW_COLOR_NEVER:
-		addstr("NEVER     ");
+		LYaddstr("NEVER     ");
 		break;
 	case SHOW_COLOR_OFF:
-		addstr("OFF");
+		LYaddstr("OFF");
 		break;
 	case SHOW_COLOR_ON:
-		addstr("ON ");
+		LYaddstr("ON ");
 		break;
 	case SHOW_COLOR_ALWAYS:
 #if defined(COLOR_CURSES)
 		if (!has_colors())
-		    addstr("Always try");
+		    LYaddstr("Always try");
 		else
 #endif
-		    addstr("ALWAYS    ");
+		    LYaddstr("ALWAYS    ");
 	}
     }
 #endif /* USE_SLANG || COLOR_CURSES */
 
-    move(L_Bool_A, B_VIKEYS);
+    LYmove(L_Bool_A, B_VIKEYS);
     addlbl("(V)I keys: ");
-    addstr(vi_keys ? "ON " : "OFF");
+    LYaddstr(vi_keys ? "ON " : "OFF");
 
-    move(L_Bool_A, B_EMACSKEYS);
+    LYmove(L_Bool_A, B_EMACSKEYS);
     addlbl("e(M)acs keys: ");
-    addstr(emacs_keys ? "ON " : "OFF");
+    LYaddstr(emacs_keys ? "ON " : "OFF");
 
-    move(L_Bool_A, B_SHOW_DOTFILES);
+    LYmove(L_Bool_A, B_SHOW_DOTFILES);
     addlbl("sho(W) dot files: ");
-    addstr((!no_dotfiles && show_dotfiles) ? "ON " : "OFF");
+    LYaddstr((!no_dotfiles && show_dotfiles) ? "ON " : "OFF");
 
-    move(L_Bool_B, B_SELECT_POPUPS);
+    LYmove(L_Bool_B, B_SELECT_POPUPS);
     addlbl("popups for selec(T) fields   : ");
-    addstr(LYSelectPopups ? "ON " : "OFF");
+    LYaddstr(LYSelectPopups ? "ON " : "OFF");
 
-    move(L_Bool_B, B_SHOW_CURSOR);
+    LYmove(L_Bool_B, B_SHOW_CURSOR);
     addlbl("show cursor (@) : ");
-    addstr(LYShowCursor ? "ON " : "OFF");
+    LYaddstr(LYShowCursor ? "ON " : "OFF");
 
-    move(L_Keypad, 5);
+    LYmove(L_Keypad, 5);
     addlbl("(K)eypad mode                : ");
-    addstr((keypad_mode == NUMBERS_AS_ARROWS) ?
+    LYaddstr((keypad_mode == NUMBERS_AS_ARROWS) ?
 				"Numbers act as arrows             " :
 	 ((keypad_mode == LINKS_ARE_NUMBERED) ?
 				"Links are numbered                " :
 				"Links and form fields are numbered"));
 
-    move(L_Lineed, 5);
+    LYmove(L_Lineed, 5);
     addlbl("li(N)e edit style            : ");
-    addstr(LYLineeditNames[current_lineedit]);
+    LYaddstr(LYLineeditNames[current_lineedit]);
 
 #ifdef EXP_KEYBOARD_LAYOUT
-    move(L_Layout, 5);
+    LYmove(L_Layout, 5);
     addlbl("Ke(Y)board layout            : ");
-    addstr(LYKbLayoutNames[current_layout]);
+    LYaddstr(LYKbLayoutNames[current_layout]);
 #endif
 
 #ifdef DIRED_SUPPORT
-    move(L_Dired, 5);
+    LYmove(L_Dired, 5);
     addlbl("l(I)st directory style       : ");
-    addstr((dir_list_style == FILES_FIRST) ? "Files first      " :
+    LYaddstr((dir_list_style == FILES_FIRST) ? "Files first      " :
 	  ((dir_list_style == MIXED_STYLE) ? "Mixed style      " :
 					     "Directories first"));
 #endif /* DIRED_SUPPORT */
 
-    move(L_User_Mode, 5);
+    LYmove(L_User_Mode, 5);
     addlbl("(U)ser mode                  : ");
-    addstr(  (user_mode == NOVICE_MODE) ? "Novice      " :
+    LYaddstr(  (user_mode == NOVICE_MODE) ? "Novice      " :
       ((user_mode == INTERMEDIATE_MODE) ? "Intermediate" :
 					  "Advanced    "));
 
     addlbl("  verbose images (!) : ");
-    addstr( verbose_img ? "ON " : "OFF" );
+    LYaddstr( verbose_img ? "ON " : "OFF" );
 
-    move(L_User_Agent, 5);
+    LYmove(L_User_Agent, 5);
     addlbl("user (A)gent                 : ");
-    addstr((LYUserAgent && *LYUserAgent) ? LYUserAgent : "NONE");
+    LYaddstr((LYUserAgent && *LYUserAgent) ? LYUserAgent : "NONE");
 
 #if defined(ENABLE_OPTS_CHANGE_EXEC) && (defined(EXEC_LINKS) || defined(EXEC_SCRIPTS))
-    move(L_Exec, 5);
+    LYmove(L_Exec, 5);
     addlbl("local e(X)ecution links      : ");
 #ifndef NEVER_ALLOW_REMOTE_EXEC
-    addstr(               local_exec ? "ALWAYS ON           " :
+    LYaddstr(               local_exec ? "ALWAYS ON           " :
 	  (local_exec_on_local_files ? "FOR LOCAL FILES ONLY" :
 				       "ALWAYS OFF          "));
 #else
-    addstr(local_exec_on_local_files ? "FOR LOCAL FILES ONLY" :
+    LYaddstr(local_exec_on_local_files ? "FOR LOCAL FILES ONLY" :
 				       "ALWAYS OFF          ");
 #endif /* !NEVER_ALLOW_REMOTE_EXEC */
 #endif /* ENABLE_OPTS_CHANGE_EXEC */
 
-    move(LYlines-3, 2);
-    addstr(SELECT_SEGMENT);
+    LYmove(LYlines-3, 2);
+    LYaddstr(SELECT_SEGMENT);
     start_bold();
-    addstr(CAP_LETT_SEGMENT);
+    LYaddstr(CAP_LETT_SEGMENT);
     stop_bold();
-    addstr(OF_OPT_LINE_SEGMENT);
+    LYaddstr(OF_OPT_LINE_SEGMENT);
     if (!no_option_save) {
-	addstr(" '");
+	LYaddstr(" '");
 	start_bold();
-	addstr(">");
+	LYaddstr(">");
 	stop_bold();
-	addstr("'");
-	addstr(TO_SAVE_SEGMENT);
+	LYaddstr("'");
+	LYaddstr(TO_SAVE_SEGMENT);
     }
-    addstr(OR_SEGMENT);
-    addstr("'");
+    LYaddstr(OR_SEGMENT);
+    LYaddstr("'");
     start_bold();
-    addstr("r");
+    LYaddstr("r");
     stop_bold();
-    addstr("'");
-    addstr(TO_RETURN_SEGMENT);
+    LYaddstr("'");
+    LYaddstr(TO_RETURN_SEGMENT);
 
     while (response != 'R' &&
 	   !LYisNonAlnumKeyname(response, LYK_PREV_DOC) &&
 	   response != '>' && !term_options &&
-	   LYCharIsINTERRUPT(response)) {
+	   LYCharIsINTERRUPT_NO_letter(response)) {
 	if (AddValueAccepted == TRUE) {
 	    _statusline(VALUE_ACCEPTED);
 	    AddValueAccepted = FALSE;
 	}
-	move((LYlines - 2), 0);
+	LYmove((LYlines - 2), 0);
 	lynx_start_prompt_color ();
-	addstr(COMMAND_PROMPT);
+	LYaddstr(COMMAND_PROMPT);
 	lynx_stop_prompt_color ();
 
-	refresh();
+	LYrefresh();
 	response = LYgetch_single();
-	if (term_options || LYCharIsINTERRUPT(response))
+	if (term_options || LYCharIsINTERRUPT_NO_letter(response))
 	    response = 'R';
 	if (LYisNonAlnumKeyname(response, LYK_REFRESH)) {
 	    lynx_force_repaint();
@@ -551,28 +551,28 @@ draw_options:
 		    if (editor && *editor)
 			LYstrncpy(display_option, editor, sizeof(display_option) - 1);
 		    else {  /* clear the NONE */
-			move(L_EDITOR, COL_OPTION_VALUES);
-			addstr("    ");
+			LYmove(L_EDITOR, COL_OPTION_VALUES);
+			LYaddstr("    ");
 			*display_option = '\0';
 		    }
 		    _statusline(ACCEPT_DATA);
-		    move(L_EDITOR, COL_OPTION_VALUES);
+		    LYmove(L_EDITOR, COL_OPTION_VALUES);
 		    start_bold();
 		    ch = LYgetstr(display_option, VISIBLE,
 				  sizeof(display_option), NORECALL);
 		    stop_bold();
-		    move(L_EDITOR, COL_OPTION_VALUES);
+		    LYmove(L_EDITOR, COL_OPTION_VALUES);
 		    if (term_options || ch == -1) {
-			addstr((editor && *editor) ?
+			LYaddstr((editor && *editor) ?
 					    editor : "NONE");
 		    } else if (*display_option == '\0') {
 			FREE(editor);
-			addstr("NONE");
+			LYaddstr("NONE");
 		    } else {
 			StrAllocCopy(editor, display_option);
-			addstr(display_option);
+			LYaddstr(display_option);
 		    }
-		    clrtoeol();
+		    LYclrtoeol();
 		    if (ch == -1) {
 			HTInfoMsg(CANCELLED);
 			HTInfoMsg("");
@@ -587,17 +587,17 @@ draw_options:
 		if (x_display && *x_display) {
 		    LYstrncpy(display_option, x_display, sizeof(display_option) - 1);
 		} else {  /* clear the NONE */
-		    move(L_DISPLAY, COL_OPTION_VALUES);
-		    addstr("    ");
+		    LYmove(L_DISPLAY, COL_OPTION_VALUES);
+		    LYaddstr("    ");
 		    *display_option = '\0';
 		}
 		_statusline(ACCEPT_DATA);
-		move(L_DISPLAY, COL_OPTION_VALUES);
+		LYmove(L_DISPLAY, COL_OPTION_VALUES);
 		start_bold();
 		ch = LYgetstr(display_option, VISIBLE,
 			      sizeof(display_option), NORECALL);
 		stop_bold();
-		move(L_DISPLAY, COL_OPTION_VALUES);
+		LYmove(L_DISPLAY, COL_OPTION_VALUES);
 
 #ifdef VMS
 #define CompareEnvVars(a,b) strcasecomp(a, b)
@@ -612,8 +612,8 @@ draw_options:
 		     *	Cancelled, or a non-NULL display string
 		     *	wasn't changed. - FM
 		     */
-		    addstr((x_display && *x_display) ? x_display : "NONE");
-		    clrtoeol();
+		    LYaddstr((x_display && *x_display) ? x_display : "NONE");
+		    LYclrtoeol();
 		    if (ch == -1) {
 			HTInfoMsg(CANCELLED);
 			HTInfoMsg("");
@@ -629,8 +629,8 @@ draw_options:
 			 *  NULL or zero-length display string
 			 *  wasn't changed. - FM
 			 */
-			addstr("NONE");
-			clrtoeol();
+			LYaddstr("NONE");
+			LYclrtoeol();
 			_statusline(VALUE_ACCEPTED);
 			response = ' ';
 			break;
@@ -642,8 +642,8 @@ draw_options:
 		LYsetXDisplay(display_option);
 		validate_x_display();
 		cp = NULL;
-		addstr(x_display ? x_display : "NONE");
-		clrtoeol();
+		LYaddstr(x_display ? x_display : "NONE");
+		LYclrtoeol();
 		summarize_x_display(display_option);
 		response = ' ';
 		break;
@@ -681,9 +681,9 @@ draw_options:
 		}
 #if defined(VMS) || defined(USE_SLANG)
 		if (LYSelectPopups) {
-		    move(L_HOME, C_MULTI);
-		    clrtoeol();
-		    addstr(choices[(LYMultiBookmarks * (1 + LYMBMAdvanced))]);
+		    LYmove(L_HOME, C_MULTI);
+		    LYclrtoeol();
+		    LYaddstr(choices[(LYMultiBookmarks * (1 + LYMBMAdvanced))]);
 		}
 #endif /* VMS || USE_SLANG */
 		FREE(choices[0]);
@@ -693,13 +693,13 @@ draw_options:
 		if (!LYSelectPopups)
 #endif /* !VMS && !USE_SLANG */
 		{
-		    move(L_HOME, B_BOOK);
-		    clrtoeol();
+		    LYmove(L_HOME, B_BOOK);
+		    LYclrtoeol();
 		    if (LYMultiBookmarks) {
-			addstr(gettext("review/edit B)ookmarks files"));
+			LYaddstr(gettext("review/edit B)ookmarks files"));
 		    } else {
-			addstr(gettext("B)ookmark file: "));
-			addstr((bookmark_page && *bookmark_page) ?
+			LYaddstr(gettext("B)ookmark file: "));
+			LYaddstr((bookmark_page && *bookmark_page) ?
 						   bookmark_page : "NONE");
 		    }
 		}
@@ -723,26 +723,26 @@ draw_options:
 		    if (bookmark_page && *bookmark_page) {
 			LYstrncpy(display_option, bookmark_page, sizeof(display_option) - 1);
 		    } else {  /* clear the NONE */
-			move(L_HOME, C_DEFAULT);
-			clrtoeol();
+			LYmove(L_HOME, C_DEFAULT);
+			LYclrtoeol();
 			*display_option = '\0';
 		    }
 		    _statusline(ACCEPT_DATA);
-		    move(L_HOME, C_DEFAULT);
+		    LYmove(L_HOME, C_DEFAULT);
 		    start_bold();
 		    ch = LYgetstr(display_option, VISIBLE,
 				  sizeof(display_option), NORECALL);
 		    stop_bold();
-		    move(L_HOME, C_DEFAULT);
+		    LYmove(L_HOME, C_DEFAULT);
 		    if (term_options ||
 			ch == -1 || *display_option == '\0') {
-			addstr((bookmark_page && *bookmark_page) ?
+			LYaddstr((bookmark_page && *bookmark_page) ?
 						   bookmark_page : "NONE");
 		    } else if (!LYPathOffHomeOK(display_option,
 						sizeof(display_option))) {
-			addstr((bookmark_page && *bookmark_page) ?
+			LYaddstr((bookmark_page && *bookmark_page) ?
 						   bookmark_page : "NONE");
-			clrtoeol();
+			LYclrtoeol();
 			_statusline(USE_PATH_OFF_HOME);
 			response = ' ';
 			break;
@@ -750,9 +750,9 @@ draw_options:
 			StrAllocCopy(bookmark_page, display_option);
 			StrAllocCopy(MBM_A_subbookmark[0],
 				     bookmark_page);
-			addstr(bookmark_page);
+			LYaddstr(bookmark_page);
 		    }
-		    clrtoeol();
+		    LYclrtoeol();
 		    if (ch == -1) {
 			HTInfoMsg(CANCELLED);
 			HTInfoMsg("");
@@ -788,9 +788,9 @@ draw_options:
 						    choices,
 						    4, FALSE, FALSE);
 #if defined(VMS) || defined(USE_SLANG)
-		    move(L_FTPSTYPE, COL_OPTION_VALUES);
-		    clrtoeol();
-		    addstr(choices[HTfileSortMethod]);
+		    LYmove(L_FTPSTYPE, COL_OPTION_VALUES);
+		    LYclrtoeol();
+		    LYaddstr(choices[HTfileSortMethod]);
 #endif /* VMS || USE_SLANG */
 		}
 		FREE(choices[0]);
@@ -807,29 +807,29 @@ draw_options:
 		if (personal_mail_address && *personal_mail_address) {
 		    LYstrncpy(display_option, personal_mail_address, sizeof(display_option) - 1);
 		} else {  /* clear the NONE */
-		    move(L_MAIL_ADDRESS, COL_OPTION_VALUES);
-		    addstr("    ");
+		    LYmove(L_MAIL_ADDRESS, COL_OPTION_VALUES);
+		    LYaddstr("    ");
 		    *display_option = '\0';
 		}
 		_statusline(ACCEPT_DATA);
-		move(L_MAIL_ADDRESS, COL_OPTION_VALUES);
+		LYmove(L_MAIL_ADDRESS, COL_OPTION_VALUES);
 		start_bold();
 		ch = LYgetstr(display_option, VISIBLE,
 			      sizeof(display_option), NORECALL);
 		stop_bold();
-		move(L_MAIL_ADDRESS, COL_OPTION_VALUES);
+		LYmove(L_MAIL_ADDRESS, COL_OPTION_VALUES);
 		if (term_options || ch == -1) {
-		    addstr((personal_mail_address &&
+		    LYaddstr((personal_mail_address &&
 			    *personal_mail_address) ?
 			      personal_mail_address : "NONE");
 		} else if (*display_option == '\0') {
 		    FREE(personal_mail_address);
-		    addstr("NONE");
+		    LYaddstr("NONE");
 		} else {
 		    StrAllocCopy(personal_mail_address, display_option);
-		    addstr(display_option);
+		    LYaddstr(display_option);
 		}
-		clrtoeol();
+		LYclrtoeol();
 		if (ch == -1) {
 		    HTInfoMsg(CANCELLED);
 		    HTInfoMsg("");
@@ -897,8 +897,8 @@ draw_options:
 							   0, FALSE, FALSE);
 #endif
 #if defined(VMS) || defined(USE_SLANG)
-			move(L_ASSUME_CHARSET, COL_OPTION_VALUES);
-			clrtoeol();
+			LYmove(L_ASSUME_CHARSET, COL_OPTION_VALUES);
+			LYclrtoeol();
 			if (UCLYhndl_for_unspec >= 0)
 			    LYaddstr(LYCharSet_UC[UCLYhndl_for_unspec].MIMEname);
 #endif /* VMS || USE_SLANG */
@@ -924,9 +924,9 @@ draw_options:
 			if (!LYSelectPopups)
 #endif /* !VMS && !USE_SLANG */
 			{
-			    move(L_Rawmode, COL_OPTION_VALUES);
-			    clrtoeol();
-			    addstr(LYRawMode ? "ON " : "OFF");
+			    LYmove(L_Rawmode, COL_OPTION_VALUES);
+			    LYclrtoeol();
+			    LYaddstr(LYRawMode ? "ON " : "OFF");
 			}
 		    }
 		    FREE(assume_list);
@@ -967,8 +967,8 @@ draw_options:
 #endif
 
 #if defined(VMS) || defined(USE_SLANG)
-		    move(L_Charset, COL_OPTION_VALUES);
-		    clrtoeol();
+		    LYmove(L_Charset, COL_OPTION_VALUES);
+		    LYclrtoeol();
 		    LYaddstr(LYchar_set_names[current_char_set]);
 #endif /* VMS || USE_SLANG */
 		}
@@ -985,9 +985,9 @@ draw_options:
 		    if (!LYSelectPopups)
 #endif /* !VMS && !USE_SLANG */
 		    {
-			move(L_Rawmode, COL_OPTION_VALUES);
-			clrtoeol();
-			addstr(LYRawMode ? "ON " : "OFF");
+			LYmove(L_Rawmode, COL_OPTION_VALUES);
+			LYclrtoeol();
+			LYaddstr(LYRawMode ? "ON " : "OFF");
 		    }
 		}
 		response = ' ';
@@ -1024,28 +1024,28 @@ draw_options:
 		if (language && *language) {
 		    LYstrncpy(display_option, language, sizeof(display_option) - 1);
 		} else {  /* clear the NONE */
-		    move(L_LANGUAGE, COL_OPTION_VALUES);
-		    addstr("    ");
+		    LYmove(L_LANGUAGE, COL_OPTION_VALUES);
+		    LYaddstr("    ");
 		    *display_option = '\0';
 		}
 		_statusline(ACCEPT_DATA);
-		move(L_LANGUAGE, COL_OPTION_VALUES);
+		LYmove(L_LANGUAGE, COL_OPTION_VALUES);
 		start_bold();
 		ch = LYgetstr(display_option, VISIBLE,
 			      sizeof(display_option), NORECALL);
 		stop_bold();
-		move(L_LANGUAGE, COL_OPTION_VALUES);
+		LYmove(L_LANGUAGE, COL_OPTION_VALUES);
 		if (term_options || ch == -1) {
-		    addstr((language && *language) ?
+		    LYaddstr((language && *language) ?
 					  language : "NONE");
 		} else if (*display_option == '\0') {
 		    FREE(language);
-		    addstr("NONE");
+		    LYaddstr("NONE");
 		} else {
 		    StrAllocCopy(language, display_option);
-		    addstr(display_option);
+		    LYaddstr(display_option);
 		}
-		clrtoeol();
+		LYclrtoeol();
 		if (ch == -1) {
 		    HTInfoMsg(CANCELLED);
 		    HTInfoMsg("");
@@ -1059,28 +1059,28 @@ draw_options:
 		if (pref_charset && *pref_charset) {
 		    LYstrncpy(display_option, pref_charset, sizeof(display_option) - 1);
 		} else {  /* clear the NONE */
-		    move(L_PREF_CHARSET, COL_OPTION_VALUES);
-		    addstr("    ");
+		    LYmove(L_PREF_CHARSET, COL_OPTION_VALUES);
+		    LYaddstr("    ");
 		    *display_option = '\0';
 		}
 		_statusline(ACCEPT_DATA);
-		move(L_PREF_CHARSET, COL_OPTION_VALUES);
+		LYmove(L_PREF_CHARSET, COL_OPTION_VALUES);
 		start_bold();
 		ch = LYgetstr(display_option, VISIBLE,
 			      sizeof(display_option), NORECALL);
 		stop_bold();
-		move(L_PREF_CHARSET, COL_OPTION_VALUES);
+		LYmove(L_PREF_CHARSET, COL_OPTION_VALUES);
 		if (term_options || ch == -1) {
-		    addstr((pref_charset && *pref_charset) ?
+		    LYaddstr((pref_charset && *pref_charset) ?
 			   pref_charset : "NONE");
 		} else if (*display_option == '\0') {
 		    FREE(pref_charset);
-		    addstr("NONE");
+		    LYaddstr("NONE");
 		} else {
 		    StrAllocCopy(pref_charset, display_option);
-		    addstr(display_option);
+		    LYaddstr(display_option);
 		}
-		clrtoeol();
+		LYclrtoeol();
 		if (ch == -1) {
 		    HTInfoMsg(CANCELLED);
 		    HTInfoMsg("");
@@ -1254,9 +1254,9 @@ draw_options:
 		    LYChosenShowColor = chosen;
 #if defined(VMS)
 		    if (LYSelectPopups) {
-			move(L_Color, C_COLOR);
-			clrtoeol();
-			addstr(choices[LYChosenShowColor]);
+			LYmove(L_Color, C_COLOR);
+			LYclrtoeol();
+			LYaddstr(choices[LYChosenShowColor]);
 		    }
 #endif /* VMS */
 #if defined(COLOR_CURSES)
@@ -1324,9 +1324,9 @@ draw_options:
 						choices,
 						3, FALSE, FALSE);
 #if defined(VMS) || defined(USE_SLANG)
-		    move(L_Keypad, COL_OPTION_VALUES);
-		    clrtoeol();
-		    addstr(choices[keypad_mode]);
+		    LYmove(L_Keypad, COL_OPTION_VALUES);
+		    LYclrtoeol();
+		    LYaddstr(choices[keypad_mode]);
 #endif /* VMS || USE_SLANG */
 		}
 		if (keypad_mode == NUMBERS_AS_ARROWS) {
@@ -1354,9 +1354,9 @@ draw_options:
 						    LYLineeditNames,
 						    0, FALSE, FALSE);
 #if defined(VMS) || defined(USE_SLANG)
-		    move(L_Lineed, COL_OPTION_VALUES);
-		    clrtoeol();
-		    addstr(LYLineeditNames[current_lineedit]);
+		    LYmove(L_Lineed, COL_OPTION_VALUES);
+		    LYclrtoeol();
+		    LYaddstr(LYLineeditNames[current_lineedit]);
 #endif /* VMS || USE_SLANG */
 		}
 		response = ' ';
@@ -1377,9 +1377,9 @@ draw_options:
 						    LYKbLayoutNames,
 						    0, FALSE, FALSE);
 #if defined(VMS) || defined(USE_SLANG)
-		    move(L_Layout, COL_OPTION_VALUES);
-		    clrtoeol();
-		    addstr(LYKbLayoutNames[current_layout]);
+		    LYmove(L_Layout, COL_OPTION_VALUES);
+		    LYclrtoeol();
+		    LYaddstr(LYKbLayoutNames[current_layout]);
 #endif /* VMS || USE_SLANG */
 		}
 		response = ' ';
@@ -1411,9 +1411,9 @@ draw_options:
 						  choices,
 						  3, FALSE, FALSE);
 #if defined(VMS) || defined(USE_SLANG)
-		    move(L_Dired, COL_OPTION_VALUES);
-		    clrtoeol();
-		    addstr(choices[dir_list_style]);
+		    LYmove(L_Dired, COL_OPTION_VALUES);
+		    LYclrtoeol();
+		    LYaddstr(choices[dir_list_style]);
 #endif /* VMS || USE_SLANG */
 		}
 		FREE(choices[0]);
@@ -1450,9 +1450,9 @@ draw_options:
 		    use_assume_charset = (BOOL) (user_mode >= 2);
 #if defined(VMS) || defined(USE_SLANG)
 		    if (use_assume_charset == old_use_assume_charset) {
-			move(L_User_Mode, COL_OPTION_VALUES);
-			clrtoeol();
-			addstr(choices[user_mode]);
+			LYmove(L_User_Mode, COL_OPTION_VALUES);
+			LYclrtoeol();
+			LYaddstr(choices[user_mode]);
 		    }
 #endif /* VMS || USE_SLANG */
 		}
@@ -1504,31 +1504,31 @@ draw_options:
 		    if (LYUserAgent && *LYUserAgent) {
 			LYstrncpy(display_option, LYUserAgent, sizeof(display_option) - 1);
 		    } else {  /* clear the NONE */
-			move(L_HOME, COL_OPTION_VALUES);
-			addstr("    ");
+			LYmove(L_HOME, COL_OPTION_VALUES);
+			LYaddstr("    ");
 			*display_option = '\0';
 		    }
 		    _statusline(ACCEPT_DATA_OR_DEFAULT);
-		    move(L_User_Agent, COL_OPTION_VALUES);
+		    LYmove(L_User_Agent, COL_OPTION_VALUES);
 		    start_bold();
 		    ch = LYgetstr(display_option, VISIBLE,
 				  sizeof(display_option), NORECALL);
 		    stop_bold();
-		    move(L_User_Agent, COL_OPTION_VALUES);
+		    LYmove(L_User_Agent, COL_OPTION_VALUES);
 		    if (term_options || ch == -1) {
-			addstr((LYUserAgent &&
+			LYaddstr((LYUserAgent &&
 				*LYUserAgent) ?
 				  LYUserAgent : "NONE");
 		    } else if (*display_option == '\0') {
 			StrAllocCopy(LYUserAgent, LYUserAgentDefault);
-			addstr((LYUserAgent &&
+			LYaddstr((LYUserAgent &&
 				*LYUserAgent) ?
 				  LYUserAgent : "NONE");
 		    } else {
 			StrAllocCopy(LYUserAgent, display_option);
-			addstr(display_option);
+			LYaddstr(display_option);
 		    }
-		    clrtoeol();
+		    LYclrtoeol();
 		    if (ch == -1) {
 			HTInfoMsg(CANCELLED);
 			HTInfoMsg("");
@@ -1589,9 +1589,9 @@ draw_options:
 					0, (exec_frozen ? TRUE : FALSE),
 					FALSE);
 #if defined(VMS) || defined(USE_SLANG)
-		    move(L_Exec, COL_OPTION_VALUES);
-		    clrtoeol();
-		    addstr(choices[itmp]);
+		    LYmove(L_Exec, COL_OPTION_VALUES);
+		    LYclrtoeol();
+		    LYaddstr(choices[itmp]);
 #endif /* VMS || USE_SLANG */
 		}
 		FREE(choices[0]);
@@ -1692,12 +1692,12 @@ PRIVATE int boolean_choice ARGS4(
     /*
      *	Highlight the current choice.
      */
-    move(line, col);
+    LYmove(line, col);
     start_reverse();
     LYaddstr(choices[cur_choice]);
     if (LYShowCursor)
-	move(line, (col - 1));
-    refresh();
+	LYmove(line, (col - 1));
+    LYrefresh();
 
     /*
      *	Get the keyboard entry, and leave the
@@ -1707,11 +1707,11 @@ PRIVATE int boolean_choice ARGS4(
      */
     term_options = FALSE;
     while (1) {
-	move(line, col);
+	LYmove(line, col);
 	if (term_options == FALSE) {
 	    response = LYgetch_single();
 	}
-	if (term_options || LYCharIsINTERRUPT(response)) {
+	if (term_options || LYCharIsINTERRUPT_NO_letter(response)) {
 	     /*
 	      *  Control-C or Control-G.
 	      */
@@ -1740,7 +1740,7 @@ PRIVATE int boolean_choice ARGS4(
 
 		case LYK_REFRESH:
 		    lynx_force_repaint();
-		    refresh();
+		    LYrefresh();
 		    break;
 
 		case LYK_QUIT:
@@ -1785,13 +1785,13 @@ PRIVATE int boolean_choice ARGS4(
 	    }  /* end of switch */
 	    LYaddstr(choices[cur_choice]);
 	    if (LYShowCursor)
-		move(line, (col - 1));
-	    refresh();
+		LYmove(line, (col - 1));
+	    LYrefresh();
 	} else {
 	    /*
 	     *	Unhighlight choice.
 	     */
-	    move(line, col);
+	    LYmove(line, col);
 	    stop_reverse();
 	    LYaddstr(choices[cur_choice]);
 
@@ -1822,7 +1822,7 @@ PRIVATE void terminate_options ARGS1(
      */
     if (!dump_output_immediately) {
 	lynx_force_repaint();
-	refresh();
+	LYrefresh();
     }
 #endif /* VMS */
 }
@@ -1856,48 +1856,48 @@ draw_bookmark_list:
      */
 #if defined(FANCY_CURSES) || defined (USE_SLANG)
     if (enable_scrollback) {
-	clear();
+	LYclear();
     } else {
-	erase();
+	LYerase();
     }
 #else
-    clear();
+    LYclear();
 #endif /* FANCY_CURSES || USE_SLANG */
-    move(0, 5);
+    LYmove(0, 5);
     lynx_start_h1_color ();
     if (LYlines < (MBM_V_MAXFILES + MULTI_OFFSET)) {
 	sprintf(ehead_buffer, MULTIBOOKMARKS_EHEAD_MASK, MBM_current);
-	addstr(ehead_buffer);
+	LYaddstr(ehead_buffer);
     } else {
-	addstr(MULTIBOOKMARKS_EHEAD);
+	LYaddstr(MULTIBOOKMARKS_EHEAD);
     }
     lynx_stop_h1_color ();
 
     if (LYlines < (MBM_V_MAXFILES + MULTI_OFFSET)) {
 	for (a = ((MBM_V_MAXFILES/2 + 1) * (MBM_current - 1));
 		      a <= (MBM_current * MBM_V_MAXFILES/2 ); a++) {
-	    move((3 + a) - ((MBM_V_MAXFILES/2 + 1)*(MBM_current - 1)), 5);
-	    addch(UCH(a + 'A'));
-	    addstr(" : ");
+	    LYmove((3 + a) - ((MBM_V_MAXFILES/2 + 1)*(MBM_current - 1)), 5);
+	    LYaddch(UCH(a + 'A'));
+	    LYaddstr(" : ");
 	    if (MBM_A_subdescript[a])
-		addstr(MBM_A_subdescript[a]);
-	    move((3 + a) - ((MBM_V_MAXFILES/2 + 1)*(MBM_current - 1)), 35);
-	    addstr("| ");
+		LYaddstr(MBM_A_subdescript[a]);
+	    LYmove((3 + a) - ((MBM_V_MAXFILES/2 + 1)*(MBM_current - 1)), 35);
+	    LYaddstr("| ");
 	    if (MBM_A_subbookmark[a]) {
-		addstr(MBM_A_subbookmark[a]);
+		LYaddstr(MBM_A_subbookmark[a]);
 	    }
 	}
     } else {
 	for (a = 0; a <= MBM_V_MAXFILES; a++) {
-	    move(3 + a, 5);
-	    addch(UCH(a + 'A'));
-	    addstr(" : ");
+	    LYmove(3 + a, 5);
+	    LYaddch(UCH(a + 'A'));
+	    LYaddstr(" : ");
 	    if (MBM_A_subdescript[a])
-		addstr(MBM_A_subdescript[a]);
-	    move(3 + a, 35);
-	    addstr("| ");
+		LYaddstr(MBM_A_subdescript[a]);
+	    LYmove(3 + a, 35);
+	    LYaddstr("| ");
 	    if (MBM_A_subbookmark[a]) {
-		addstr(MBM_A_subbookmark[a]);
+		LYaddstr(MBM_A_subbookmark[a]);
 	    }
 	}
     }
@@ -1906,55 +1906,55 @@ draw_bookmark_list:
      *	Only needed when we have 2 screens.
      */
     if (LYlines < MBM_V_MAXFILES + MULTI_OFFSET) {
-	move((LYlines - 4), 0);
-	addstr("'");
+	LYmove((LYlines - 4), 0);
+	LYaddstr("'");
 	start_bold();
-	addstr("[");
+	LYaddstr("[");
 	stop_bold();
-	addstr("' ");
-	addstr(PREVIOUS);
-	addstr(", '");
+	LYaddstr("' ");
+	LYaddstr(PREVIOUS);
+	LYaddstr(", '");
 	start_bold();
-	addstr("]");
+	LYaddstr("]");
 	stop_bold();
-	addstr("' ");
-	addstr(NEXT_SCREEN);
+	LYaddstr("' ");
+	LYaddstr(NEXT_SCREEN);
     }
 
-    move((LYlines - 3), 0);
+    LYmove((LYlines - 3), 0);
     if (!no_option_save) {
-	addstr("'");
+	LYaddstr("'");
 	start_bold();
-	addstr(">");
+	LYaddstr(">");
 	stop_bold();
-	addstr("'");
-	addstr(TO_SAVE_SEGMENT);
+	LYaddstr("'");
+	LYaddstr(TO_SAVE_SEGMENT);
     }
-    addstr(OR_SEGMENT);
-    addstr("'");
+    LYaddstr(OR_SEGMENT);
+    LYaddstr("'");
     start_bold();
-    addstr("^G");
+    LYaddstr("^G");
     stop_bold();
-    addstr("'");
-    addstr(TO_RETURN_SEGMENT);
+    LYaddstr("'");
+    LYaddstr(TO_RETURN_SEGMENT);
 
     while (!term_options &&
 	   !LYisNonAlnumKeyname(response, LYK_PREV_DOC) &&
-	   !LYCharIsINTERRUPT(response) && response != '>') {
+	   !LYCharIsINTERRUPT_NO_letter(response) && response != '>') {
 
-	move((LYlines - 2), 0);
+	LYmove((LYlines - 2), 0);
 	lynx_start_prompt_color ();
-	addstr(MULTIBOOKMARKS_LETTER);
+	LYaddstr(MULTIBOOKMARKS_LETTER);
 	lynx_stop_prompt_color ();
 
-	refresh();
+	LYrefresh();
 	response = (def_response ? def_response : LYgetch_single());
 	def_response = 0;
 
 	/*
 	 *  Check for a cancel.
 	 */
-	if (term_options || LYCharIsINTERRUPT(response) ||
+	if (term_options || LYCharIsINTERRUPT_NO_letter(response) ||
 	    LYisNonAlnumKeyname(response, LYK_PREV_DOC))
 	    continue;
 
@@ -2031,11 +2031,11 @@ draw_bookmark_list:
 		if (a > 0) {
 		    start_bold();
 		    if (LYlines < (MBM_V_MAXFILES + MULTI_OFFSET))
-			move(
+			LYmove(
 			 (3 + a) - ((MBM_V_MAXFILES/2 + 1)*(MBM_current - 1)),
 			     9);
 		    else
-			move((3 + a), 9);
+			LYmove((3 + a), 9);
 		    LYstrncpy(MBM_tmp_line,
 			   (!MBM_A_subdescript[a] ?
 					       "" : MBM_A_subdescript[a]),
@@ -2050,25 +2050,25 @@ draw_bookmark_list:
 			StrAllocCopy(MBM_A_subdescript[a], MBM_tmp_line);
 		    }
 		    if (LYlines < (MBM_V_MAXFILES + MULTI_OFFSET))
-			move(
+			LYmove(
 			 (3 + a) - ((MBM_V_MAXFILES/2 + 1)*(MBM_current - 1)),
 			     5);
 		    else
-			move((3 + a), 5);
-		    addch(UCH(a + 'A'));
-		    addstr(" : ");
+			LYmove((3 + a), 5);
+		    LYaddch(UCH(a + 'A'));
+		    LYaddstr(" : ");
 		    if (MBM_A_subdescript[a])
-			addstr(MBM_A_subdescript[a]);
-		    clrtoeol();
-		    refresh();
+			LYaddstr(MBM_A_subdescript[a]);
+		    LYclrtoeol();
+		    LYrefresh();
 		}
 
 		if (LYlines < (MBM_V_MAXFILES + MULTI_OFFSET))
-		    move((3 + a) - ((MBM_V_MAXFILES/2 + 1)*(MBM_current - 1)),
+		    LYmove((3 + a) - ((MBM_V_MAXFILES/2 + 1)*(MBM_current - 1)),
 			 35);
 		else
-		    move((3 + a), 35);
-		addstr("| ");
+		    LYmove((3 + a), 35);
+		LYaddstr("| ");
 
 		start_bold();
 		LYstrncpy(MBM_tmp_line,
@@ -2094,16 +2094,16 @@ draw_bookmark_list:
 		    }
 		}
 		if (LYlines < (MBM_V_MAXFILES + MULTI_OFFSET))
-		    move((3 + a) - ((MBM_V_MAXFILES/2 + 1)*(MBM_current-1)),
+		    LYmove((3 + a) - ((MBM_V_MAXFILES/2 + 1)*(MBM_current-1)),
 			 35);
 		else
-		    move((3 + a), 35);
-		addstr("| ");
+		    LYmove((3 + a), 35);
+		LYaddstr("| ");
 		if (MBM_A_subbookmark[a])
-		    addstr(MBM_A_subbookmark[a]);
-		clrtoeol();
-		move(LYlines-1, 0);
-		clrtoeol();
+		    LYaddstr(MBM_A_subbookmark[a]);
+		LYclrtoeol();
+		LYmove(LYlines-1, 0);
+		LYclrtoeol();
 		break;
 	    }
 	}  /* end for */
@@ -3126,8 +3126,8 @@ PRIVATE char *NewSecureValue NOARGS
 {
     FREE(secure_value);
     if ((secure_value = malloc(80)) != 0) {
-#if defined(HAVE_RAND) && defined(HAVE_SRAND) && defined(RAND_MAX)
-	long key = rand();
+#if defined(RAND_MAX)
+	long key = my_rand();
 #else
 	long key = (long)secure_value + (long)time(0);
 #endif
@@ -3156,7 +3156,7 @@ PRIVATE int gen_options ARGS1(
     BOOLEAN disable_all = FALSE;
     FILE *fp0;
     size_t cset_len = 0;
-    size_t text_len = COLS - 38;	/* cf: PutLabel */
+    size_t text_len = LYscreenWidth() > 45 ? LYscreenWidth() - 38 : 7;	/* cf: PutLabel */
 
     if (LYReuseTempfiles) {
 	fp0 = LYOpenTempRewrite(tempfile, HTML_SUFFIX, "w");
diff --git a/src/LYPrint.c b/src/LYPrint.c
index f5508f2d..6a95f962 100644
--- a/src/LYPrint.c
+++ b/src/LYPrint.c
@@ -292,7 +292,7 @@ PRIVATE BOOLEAN confirm_by_pages ARGS3(
 	FREE(msg);
 
 	if (c == YES) {
-	    addstr("   Ok...");
+	    LYaddstr("   Ok...");
 	} else {
 	    HTInfoMsg(PRINT_REQUEST_CANCELLED);
 	    return FALSE;
@@ -452,7 +452,8 @@ check_recall:
 	pclose(outfile_fp);
     else
 #endif
-    LYCloseOutput(outfile_fp);
+	LYCloseOutput(outfile_fp);
+
 #ifdef VMS
     if (0 == strncasecomp(buffer, "sys$disk:", 9)) {
 	if (0 == strncmp((buffer+9), "[]", 2)) {
@@ -499,7 +500,7 @@ PRIVATE void send_file_to_mail ARGS3(
     if (LYPreparsedSource && first_mail_preparsed &&
 	HTisDocumentSource()) {
 	if (HTConfirmDefault(CONFIRM_MAIL_SOURCE_PREPARSED, NO) == YES) {
-	    addstr("   Ok...");
+	    LYaddstr("   Ok...");
 	    first_mail_preparsed = FALSE;
 	} else	{
 	    CancelPrint(MAIL_REQUEST_CANCELLED);
@@ -775,6 +776,7 @@ PRIVATE void send_file_to_mail ARGS3(
 #if CAN_PIPE_TO_MAILER
     pclose(outfile_fp);
 #else
+    LYCloseOutput(outfile_fp);
     LYSendMailFile (
 	    user_response,
 	    my_temp,
@@ -919,7 +921,7 @@ check_again:
      * Move the cursor to the top of the screen so that output from system'd
      * commands don't scroll up the screen.
      */
-    move(1,1);
+    LYmove(1,1);
 
     stop_curses();
     CTRACE((tfp, "command: %s\n", the_command));
diff --git a/src/LYReadCFG.c b/src/LYReadCFG.c
index df410147..5f4668b9 100644
--- a/src/LYReadCFG.c
+++ b/src/LYReadCFG.c
@@ -199,7 +199,7 @@ PRIVATE void add_item_to_list ARGS2(
 	if (*next_colon++) {
 	    colon = next_colon;
 	    if ((next_colon = strchr(colon,':')) != 0)
-		*next_colon++ = '\0';		
+		*next_colon++ = '\0';
 	    cur_item->always_enabled = is_true(colon);
 	    if (next_colon) {
 		cur_item->override_primary_action = is_true(next_colon);
@@ -588,8 +588,14 @@ static int character_set_fun ARGS1(
 	char *,		value)
 {
     int i = UCGetLYhndl_byAnyName(value); /* by MIME or full name */
-    if (i < 0)
-	; /* do nothing here: so fallback to userdefs.h */
+
+    if (i < 0) {
+#ifdef CAN_AUTODETECT_DISPLAY_CHARSET
+	if (auto_display_charset >= 0 && !strnicmp(value,"AutoDetect ",11))
+	    current_char_set = auto_display_charset;
+#endif
+	/* do nothing here: so fallback to userdefs.h */
+    }
     else
 	current_char_set = i;
 
@@ -1404,6 +1410,10 @@ static Config_Type Config_Table [] =
 #ifdef DIRED_SUPPORT
      PARSE_ENV("auto_uncache_dirlists", CONF_INT, &LYAutoUncacheDirLists),
 #endif
+#ifndef DISABLE_BIBP
+     PARSE_STR("bibp_bibhost", CONF_STR, &BibP_bibhost),
+     PARSE_STR("bibp_globalserver", CONF_STR, &BibP_globalserver),
+#endif
      PARSE_SET("block_multi_bookmarks", CONF_BOOL, &LYMBMBlocked),
      PARSE_SET("bold_h1", CONF_BOOL, &bold_H1),
      PARSE_SET("bold_headers", CONF_BOOL, &bold_headers),
@@ -1472,7 +1482,7 @@ static Config_Type Config_Table [] =
      PARSE_STR("helpfile", CONF_STR, &helpfile),
 #ifdef MARK_HIDDEN_LINKS
      PARSE_STR("hidden_link_marker", CONF_STR, &hidden_link_marker),
-#endif     
+#endif
      PARSE_SET("historical_comments", CONF_BOOL, &historical_comments),
 #ifdef USE_PRETTYSRC
      PARSE_FUN("htmlsrc_attrname_xform", CONF_FUN, read_htmlsrc_attrname_xform),
diff --git a/src/LYShowInfo.c b/src/LYShowInfo.c
index 7d176754..464067d6 100644
--- a/src/LYShowInfo.c
+++ b/src/LYShowInfo.c
@@ -420,7 +420,7 @@ PUBLIC int showinfo ARGS4(
 #endif /* DIRED_SUPPORT */
     EndInternalPage(fp0);
 
-    refresh();
+    LYrefresh();
 
     LYCloseTemp(tempfile);
     FREE(Address);
diff --git a/src/LYStrings.c b/src/LYStrings.c
index 89d0fd95..c8f46d23 100644
--- a/src/LYStrings.c
+++ b/src/LYStrings.c
@@ -672,11 +672,11 @@ PUBLIC int LYmbcsstrlen ARGS3(
 #endif /* USE_SLANG */
 
 #if !defined(GetChar) && defined(NCURSES)
-#define GetChar() wgetch(my_subwindow ? my_subwindow : stdscr)
+#define GetChar() wgetch(my_subwindow ? my_subwindow : LYwin)
 #endif
 
 #if !defined(GetChar) && defined(SNAKE)
-#define GetChar() wgetch(stdscr)
+#define GetChar() wgetch(LYwin)
 #endif
 
 #if !defined(GetChar) && defined(VMS)
@@ -711,13 +711,13 @@ PUBLIC void LYsubwindow ARGS1(WINDOW *, param)
 #if defined(NCURSES) || defined(PDCURSES)
 	keypad(my_subwindow, TRUE);
 #if defined(HAVE_GETBKGD) /* not defined in ncurses 1.8.7 */
-	wbkgd(my_subwindow, getbkgd(stdscr));
-	wbkgdset(my_subwindow, getbkgd(stdscr));
+	wbkgd(my_subwindow, getbkgd(LYwin));
+	wbkgdset(my_subwindow, getbkgd(LYwin));
 #endif
 #endif
 	scrollok(my_subwindow, TRUE);
     } else {
-	touchwin(stdscr);
+	touchwin(LYwin);
 	delwin(my_subwindow);
 	my_subwindow = 0;
     }
@@ -1602,7 +1602,7 @@ re_read:
 		if (LYCursesON) {
 		    stop_curses();
 		    start_curses();
-		    refresh();
+		    LYrefresh();
 		}
 		goto re_read;
 	    }
@@ -1665,7 +1665,9 @@ re_read:
     }
 #endif /* USE_SLANG */
 
-    if (c == CH_ESC || (csi_is_csi && c == UCH(CH_ESC_PAR))) { /* handle escape sequence  S/390 -- gil -- 2024 */
+    if (!escape_bound
+	&& (c == CH_ESC || (csi_is_csi && c == UCH(CH_ESC_PAR)))) {
+	/* handle escape sequence  S/390 -- gil -- 2024 */
 	done_esc = TRUE;		/* Flag: we did it, not keypad() */
 	b = GetChar();
 
@@ -1993,7 +1995,7 @@ re_read:
 		 *  so detecting happened *at the end* of the last refresh.
 		 *  Tell it to refresh again... - kw
 		 */
-		refresh();
+		LYrefresh();
 #endif
 #if defined(NCURSES)
 		/*
@@ -2131,13 +2133,13 @@ re_read:
 		    c = LAC_TO_LKC(lac);
 #if 0	/* Probably not necessary any more - kw */
 		    lynx_force_repaint();
-		    refresh();
+		    LYrefresh();
 #endif
 		}
 		if (code == FOR_INPUT && mouse_link == -1 &&
 		    lac != LYK_REFRESH && lac != LYK_SUBMIT) {
 		    ungetmouse(&event);	/* Caller will process this. */
-		    getch();		/* ungetmouse puts KEY_MOUSE back */
+		    wgetch(LYwin);	/* ungetmouse puts KEY_MOUSE back */
 		    c = MOUSE_KEY;
 		}
 #else /* pdcurses version */
@@ -2605,7 +2607,7 @@ PUBLIC void LYSetupEdit ARGS4(
     Margin  = 0;
     Pos = strlen(old);
 #ifdef ENHANCED_LINEEDIT
-    Mark = 0;
+    Mark = -1;			/* pos=0, but do not show it yet */
 #endif
     DspStart = 0;
 
@@ -2664,6 +2666,7 @@ PUBLIC int LYEdit1 ARGS4(
 	int,		action,
 	BOOL,		maxMessage)
 {   /* returns 0    character processed
+     *         -ch  if action should be performed outside of line-editing mode
      *	       ch   otherwise
      */
     int i;
@@ -2743,6 +2746,10 @@ PUBLIC int LYEdit1 ARGS4(
 #ifdef ENHANCED_LINEEDIT
 	    if (Mark > Pos)
 		Mark++;
+	    else if (Mark < -1 - Pos)
+		Mark--;
+	    if (Mark >= 0)
+		Mark = -1 - Mark;		/* Disable it */
 #endif
 	    for(i = length; i >= Pos; i--)    /* Make room */
 		Buf[i+1] = Buf[i];
@@ -2772,6 +2779,10 @@ PUBLIC int LYEdit1 ARGS4(
 #ifdef ENHANCED_LINEEDIT
 	    if (Mark > Pos)
 		Mark++;
+	    else if (Mark < -1 - Pos)
+		Mark--;
+	    if (Mark >= 0)
+		Mark = -1 - Mark;		/* Disable it */
 #endif
 	    for(i = length; i >= Pos; i--)    /* Make room */
 		Buf[i+1] = Buf[i];
@@ -2858,7 +2869,7 @@ PUBLIC int LYEdit1 ARGS4(
 	 */
 	 Buf[0] = '\0';
 #ifdef ENHANCED_LINEEDIT
-	Mark = 0;
+	Mark = -1;		/* Do not show the mark */
 #endif
 	 /* fall through */
 
@@ -2947,8 +2958,10 @@ PUBLIC int LYEdit1 ARGS4(
 	if (length == 0 || Pos == 0)
 	    break;
 #ifdef ENHANCED_LINEEDIT
-	if (Mark >= Pos)
-	    Mark--;
+	if (Mark >= 0)
+	    Mark = -1 - Mark;		/* Disable it */
+	if (Mark <= -1 - Pos)
+	    Mark++;
 #endif
 	Pos--;
 	for (i = Pos; i < length; i++)
@@ -2969,11 +2982,18 @@ PUBLIC int LYEdit1 ARGS4(
 	    for (i = Pos; i < length; i++)
 		Buf[i] = Buf[i + offset];
 	    i -= offset;
+#ifdef ENHANCED_LINEEDIT
+            if (Mark >= 0)
+                Mark = -1 - Mark;		/* Disable it */
+            if (Mark <= -1 - Pos)
+                Mark += offset;
+#endif
 	}
 #endif /* SUPPORT_MULTIBYTE_EDIT */
 	Buf[i] = 0;
 	break;
 
+    case LYE_FORW_RL:
     case LYE_FORW:
 	/*
 	 *  Move cursor to the right.
@@ -2988,8 +3008,11 @@ PUBLIC int LYEdit1 ARGS4(
 		Pos++;
 	}
 #endif /* SUPPORT_MULTIBYTE_EDIT */
+	else if (action == LYE_FORW_RL)
+	    return -ch;
 	break;
 
+    case LYE_BACK_LL:
     case LYE_BACK:
 	/*
 	 *  Left-arrow move cursor to the left.
@@ -3005,6 +3028,8 @@ PUBLIC int LYEdit1 ARGS4(
 		Pos--;
 	}
 #endif /* SUPPORT_MULTIBYTE_EDIT */
+	else if (action == LYE_BACK_LL)
+	    return -ch;
 	break;
 
 #ifdef ENHANCED_LINEEDIT
@@ -3016,8 +3041,12 @@ PUBLIC int LYEdit1 ARGS4(
 	    return(ch);
 	if (Pos == length)
 	    Pos--;
+	if (Mark < 0)
+	    Mark = -1 - Mark;		/* Temporary enable it */
 	if (Mark == Pos || Mark == Pos+1)
 	    Mark = Pos-1;
+	if (Mark >= 0)
+	    Mark = -1 - Mark;		/* Disable it */
 	if (Buf[Pos-1] == Buf[Pos]) {
 	    Pos++;
 	    break;
@@ -3036,6 +3065,8 @@ PUBLIC int LYEdit1 ARGS4(
 	/*
 	 *  emacs-like exchange-point-and-mark
 	 */
+	if (Mark < 0)
+	    Mark = -1 - Mark;		/* Enable it */
 	if (Mark == Pos)
 	    return(0);
 	i = Pos; Pos = Mark; Mark = i;
@@ -3045,6 +3076,8 @@ PUBLIC int LYEdit1 ARGS4(
 	/*
 	 *  primitive emacs-like kill-region
 	 */
+	if (Mark < 0)
+	    Mark = -1 - Mark;		/* Enable it */
 	if (Mark == Pos) {
 	    killbuffer[0] = '\0';
 	    return(0);
@@ -3061,6 +3094,8 @@ PUBLIC int LYEdit1 ARGS4(
 	    Buf[i] = Buf[i+reglen]; /* terminate */
 	    Pos = Mark;
 	}
+	if (Mark >= 0)
+	    Mark = -1 - Mark;		/* Disable it */
 	break;
 
     case LYE_YANK:
@@ -3068,14 +3103,14 @@ PUBLIC int LYEdit1 ARGS4(
 	 *  primitive emacs-like yank
 	 */
 	if (!killbuffer[0]) {
-	    Mark = Pos;
+	    Mark = -1 - Pos;
 	    return(0);
 	}
 	{
 	    int yanklen = strlen(killbuffer);
 
 	    if (Pos+yanklen <= (MaxLen) && StrLen+yanklen <= (MaxLen)) {
-		Mark = Pos;
+		Mark = -1 - Pos;
 
 		for(i = length; i >= Pos; i--)    /* Make room */
 		    Buf[i+yanklen] = Buf[i];
@@ -3277,7 +3312,7 @@ PUBLIC void LYRefreshEdit ARGS1(
     if (nrdisplayed > DspWdth)
 	nrdisplayed = DspWdth;
 
-    move(edit->sy, edit->sx);
+    LYmove(edit->sy, edit->sx);
 #ifdef USE_COLOR_STYLE
     /*
      *  If this is the last screen line, set attributes to normal,
@@ -3295,20 +3330,32 @@ PUBLIC void LYRefreshEdit ARGS1(
     if (estyle != NOSTYLE)
 	curses_style(estyle, STACK_ON);
     else
-	attrset(A_NORMAL);	/* need to do something about colors? */
+	wattrset(LYwin,A_NORMAL); /* need to do something about colors? */
 #endif
     if (edit->hidden) {
 	for (i = 0; i < nrdisplayed; i++)
-	    addch('*');
+	    LYaddch('*');
     } else {
-	for (i = 0; i < nrdisplayed; i++)
+#if defined(ENHANCED_LINEEDIT) && defined(USE_COLOR_STYLE)
+	if (Mark >= 0 && DspStart > Mark)
+	    TmpStyleOn(prompting ? s_prompt_sel : s_aedit_sel);
+#endif
+	for (i = 0; i < nrdisplayed; i++) {
+#if defined(ENHANCED_LINEEDIT) && defined(USE_COLOR_STYLE)
+	    if ( Mark >= 0 && ((DspStart + i == Mark && Pos > Mark)
+			       || (DspStart + i == Pos && Pos < Mark) ))
+		TmpStyleOn(prompting ? s_prompt_sel : s_aedit_sel);
+	    if ( Mark >= 0 && ((DspStart + i == Mark && Pos < Mark)
+			       || (DspStart + i == Pos && Pos > Mark) ))
+		TmpStyleOff(prompting ? s_prompt_sel : s_aedit_sel);
+#endif
 	    if ((buffer[0] = str[i]) == 1 || buffer[0] == 2 ||
 		(UCH(buffer[0]) == 160 &&
 		 !(HTPassHighCtrlRaw || HTCJK != NOCJK ||
 		   (LYCharSet_UC[current_char_set].enc != UCT_ENC_8859 &&
 		    !(LYCharSet_UC[current_char_set].like8859
 		      & UCT_R_8859SPECL))))) {
-		addch(' ');
+		LYaddch(' ');
 #ifdef SUPPORT_MULTIBYTE_EDIT
 		end_multi = 0;
 #endif /* SUPPORT_MULTIBYTE_EDIT */
@@ -3325,15 +3372,23 @@ PUBLIC void LYRefreshEdit ARGS1(
 		    } else
 			end_multi = 0;
 #endif /* SUPPORT_MULTIBYTE_EDIT */
-		    addstr(buffer);
+		    LYaddstr(buffer);
 		    buffer[1] = '\0';
 		} else {
-		    addstr(buffer);
+		    LYaddstr(buffer);
 #ifdef SUPPORT_MULTIBYTE_EDIT
 		    end_multi = 0;
 #endif /* SUPPORT_MULTIBYTE_EDIT */
 		}
 	    }
+	}
+#if defined(ENHANCED_LINEEDIT) && defined(USE_COLOR_STYLE)
+	if (Mark >= 0 &&
+	    ((DspStart + nrdisplayed <= Mark && DspStart + nrdisplayed > Pos)
+	     || (DspStart + nrdisplayed > Mark
+		 && DspStart + nrdisplayed <= Pos)))
+	    TmpStyleOff(prompting ? s_prompt_sel : s_aedit_sel);
+#endif
     }
 
     /*
@@ -3343,7 +3398,7 @@ PUBLIC void LYRefreshEdit ARGS1(
     if (padsize) {
 	TmpStyleOn(prompting ? s_prompt_edit_pad : s_aedit_pad);
 	while (padsize--)
-	    addch(UCH(edit->pad));
+	    LYaddch(UCH(edit->pad));
 	TmpStyleOff(prompting ? s_prompt_edit_pad : s_aedit_pad);
     }
 
@@ -3359,25 +3414,25 @@ PUBLIC void LYRefreshEdit ARGS1(
 	    if (end_multi)
 		add_space = 1;
 #endif
-	    move(edit->sy, edit->sx + nrdisplayed - 1 - add_space);
+	    LYmove(edit->sy, edit->sx + nrdisplayed - 1 - add_space);
 	    if (add_space)
-		addch(' ');		/* Needed with styles? */
-	    addch(ACS_RARROW);
+		LYaddch(' ');		/* Needed with styles? */
+	    LYaddch(ACS_RARROW);
 	    TmpStyleOff(prompting ? s_prompt_edit_arr : s_aedit_arr);
 	}
 	if (DspStart) {
 	    TmpStyleOn(prompting ? s_prompt_edit_arr : s_aedit_arr);
-	    move(edit->sy, edit->sx);
-	    addch(ACS_LARROW);
+	    LYmove(edit->sy, edit->sx);
+	    LYaddch(ACS_LARROW);
 #ifdef SUPPORT_MULTIBYTE_EDIT
 	    if (begin_multi)
-		addch(' ');		/* Needed with styles? */
+		LYaddch(' ');		/* Needed with styles? */
 #endif /* SUPPORT_MULTIBYTE_EDIT */
 	    TmpStyleOff(prompting ? s_prompt_edit_arr : s_aedit_arr);
 	}
     }
 
-    move(edit->sy, edit->sx + Pos - DspStart);
+    LYmove(edit->sy, edit->sx + Pos - DspStart);
 #ifdef SUPPORT_MULTIBYTE_EDIT
 #if (!USE_SLANG && !defined(USE_MULTIBYTE_CURSES))
     if (HTCJK != NOCJK)
@@ -3389,7 +3444,7 @@ PUBLIC void LYRefreshEdit ARGS1(
     if (estyle != NOSTYLE)
 	curses_style(estyle, STACK_OFF);
 #endif
-    refresh();
+    LYrefresh();
 }
 
 PRIVATE void reinsertEdit ARGS2(
@@ -3539,7 +3594,7 @@ PRIVATE void draw_option ARGS7(
     FormatChoiceNum(Cnum, num_choices, number, "");
 #ifdef USE_SLANG
     SLsmg_gotorc(win->top_y + entry, (win->left_x + 2));
-    addstr(Cnum);
+    LYaddstr(Cnum);
     if (reversed)
 	SLsmg_set_color(2);
     SLsmg_write_nstring((char *)value, win->width);
@@ -3741,8 +3796,8 @@ PUBLIC int LYhandlePopupList ARGS9(
      *	Clear the command line and write
      *	the popup statusline. - FM
      */
-    move((LYlines - 2), 0);
-    clrtoeol();
+    LYmove((LYlines - 2), 0);
+    LYclrtoeol();
     if (disabled) {
 	popup_status_msg = CHOICE_LIST_UNM_MSG;
     } else if (!for_mouse) {
@@ -4184,7 +4239,7 @@ redraw:
 
 	    case LYK_REFRESH:
 		lynx_force_repaint();
-		refresh();
+		LYrefresh();
 		break;
 
 	    case LYK_NEXT:
@@ -4449,6 +4504,7 @@ restore_popup_statusline:
 	    case LYK_QUIT:
 	    case LYK_ABORT:
 	    case LYK_PREV_DOC:
+	    case LYK_INTERRUPT:
 		cur_choice = orig_choice;
 		cmd = LYK_ACTIVATE; /* to exit */
 		break;
@@ -4574,7 +4630,7 @@ again:
 		    old_y = SLsmg_get_row();
 		    old_x = SLsmg_get_column();
 #else
-		    getyx(stdscr, old_y, old_x);
+		    getyx(LYwin, old_y, old_x);
 #endif
 
 		    cur_choice = LYhandlePopupList(
@@ -4595,7 +4651,7 @@ again:
 #ifdef USE_SLANG
 		    SLsmg_gotorc(old_y, old_x);
 #else
-		    wmove(stdscr, old_y, old_x);
+		    wmove(LYwin, old_y, old_x);
 #endif
 		    FREE(data);
 		}
@@ -5571,7 +5627,7 @@ PUBLIC int LYReadCmdKey ARGS1(
 		continue;
 	    src = LYSkipBlanks(tmp);
 	    if ((ch = LYStringToKeycode(src)) >= 0) {
-		refresh();
+		LYrefresh();
 		break;
 	    }
 	}
diff --git a/src/LYStrings.h b/src/LYStrings.h
index 82066819..eefff4e0 100644
--- a/src/LYStrings.h
+++ b/src/LYStrings.h
@@ -197,7 +197,8 @@ typedef struct _EditFieldData {
         int  margin;    /* Number of columns look-ahead/look-back    */
         int  current_modifiers; /* Modifiers for next input lynxkeycode */
 #ifdef ENHANCED_LINEEDIT
-	int  mark;	/* position of emacs-like mark */
+	int  mark;	/* position of emacs-like mark, or -1-pos to denote
+				unactive mark.  */
 #endif
 
         char buffer[1024]; /* String buffer                          */
@@ -227,8 +228,10 @@ typedef struct _EditFieldData {
 #define LYE_BOL   (LYE_ERASE +1)  /* Go to begin of line   */
 #define LYE_EOL   (LYE_BOL   +1)  /* Go to end   of line   */
 #define LYE_FORW  (LYE_EOL   +1)  /* Cursor forwards       */
-#define LYE_BACK  (LYE_FORW  +1)  /* Cursor backwards      */
-#define LYE_FORWW (LYE_BACK  +1)  /* Word forward          */
+#define LYE_FORW_RL (LYE_FORW +1) /* Cursor forwards or right link */
+#define LYE_BACK  (LYE_FORW_RL+1) /* Cursor backwards      */
+#define LYE_BACK_LL (LYE_BACK+1)  /* Cursor backwards or left link */
+#define LYE_FORWW (LYE_BACK_LL+1) /* Word forward          */
 #define LYE_BACKW (LYE_FORWW +1)  /* Word back             */
 
 #define LYE_LOWER (LYE_BACKW +1)  /* Lower case the line   */
@@ -331,6 +334,8 @@ extern CONST char * LYLineeditHelpURLs[];
 
 extern CONST char * LYLineeditHelpURL NOPARAMS;
 
+extern int escape_bound;
+
 #define LYLineEdit(e,c,m) LYEdit1(e,c,EditBinding(c)&~LYE_DF,m)
 
 /* Dummy initializer for LYEditmap.c */
diff --git a/src/LYStructs.h b/src/LYStructs.h
index 31b8afe5..2471c59c 100644
--- a/src/LYStructs.h
+++ b/src/LYStructs.h
@@ -34,7 +34,7 @@ typedef struct _document {
    int    line;
    BOOL   internal_link;	/* whether doc was reached via an internal
 				 (fragment) link. - kw */
-#ifdef USE_HASH
+#ifdef USE_COLOR_STYLE
    char * style;
 #endif
 } document;
diff --git a/src/LYStyle.c b/src/LYStyle.c
index 4924b2a0..09226d1a 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.40 Thu, 21 Dec 2000 18:44:11 -0800 dickey @
+ * @Id: LYStyle.c 1.41 Thu, 08 Feb 2001 18:50:00 -0800 dickey @
  */
 #include <HTUtils.h>
 #include <HTML.h>
@@ -64,16 +64,29 @@ static char *Mono_Strings[7] =
 };
 
 /* Remember the hash codes for common elements */
-PUBLIC int	s_alink  = NOSTYLE, s_a     = NOSTYLE, s_status = NOSTYLE,
-		s_normal = NOSTYLE, s_alert = NOSTYLE, s_title  = NOSTYLE,
+PUBLIC int s_a			= NOSTYLE;
+PUBLIC int s_aedit		= NOSTYLE;
+PUBLIC int s_aedit_arr		= NOSTYLE;
+PUBLIC int s_aedit_pad		= NOSTYLE;
+PUBLIC int s_aedit_sel		= NOSTYLE;
+PUBLIC int s_alert		= NOSTYLE;
+PUBLIC int s_alink		= NOSTYLE;
+PUBLIC int s_curedit		= NOSTYLE;
+PUBLIC int s_normal		= NOSTYLE;
+PUBLIC int s_prompt_edit	= NOSTYLE;
+PUBLIC int s_prompt_edit_arr	= NOSTYLE;
+PUBLIC int s_prompt_edit_pad	= NOSTYLE;
+PUBLIC int s_prompt_sel		= NOSTYLE;
+PUBLIC int s_status		= NOSTYLE;
+PUBLIC int s_title		= NOSTYLE;
+PUBLIC int s_whereis		= NOSTYLE;
+
 #ifdef USE_SCROLLBAR
-		s_sb_bar = NOSTYLE, s_sb_bg = NOSTYLE,
-		s_sb_aa = NOSTYLE, s_sb_naa = NOSTYLE,
+PUBLIC int s_sb_aa		= NOSTYLE;
+PUBLIC int s_sb_bar		= NOSTYLE;
+PUBLIC int s_sb_bg		= NOSTYLE;
+PUBLIC int s_sb_naa		= NOSTYLE;
 #endif
-		s_whereis = NOSTYLE, s_aedit = NOSTYLE,
-		s_aedit_pad = NOSTYLE, s_aedit_arr = NOSTYLE, 
-		s_prompt_edit = NOSTYLE, s_prompt_edit_pad = NOSTYLE,
-		s_prompt_edit_arr = NOSTYLE;
 
 /* start somewhere safe */
 #define MAX_COLOR 16
@@ -196,6 +209,35 @@ PRIVATE void parse_attributes ARGS5(char*,mono,char*,fg,char*,bg,int,style,char*
  */
 PRIVATE void parse_style ARGS1(char*,buffer)
 {
+    static struct {
+	char *name;
+	int style;
+	int *set_hash;
+    } table[] = {
+	{ "default",		-1,			0 }, /* default fg/bg */
+	{ "alink",		DSTYLE_ALINK,		0 }, /* active link */
+	{ "a",			DSTYLE_LINK,		0 }, /* normal link */
+	{ "a",			HTML_A,			0 }, /* normal link */
+	{ "status",		DSTYLE_STATUS,		0 }, /* status bar */
+	{ "label",		DSTYLE_OPTION,		0 }, /* [INLINE]'s */
+	{ "value",		DSTYLE_VALUE,		0 }, /* [INLINE]'s */
+	{ "high",		DSTYLE_HIGH,		0 }, /* [INLINE]'s */
+	{ "normal",		DSTYLE_NORMAL,		0 },
+	{ "candy",		DSTYLE_CANDY,		0 }, /* [INLINE]'s */
+	{ "whereis",		DSTYLE_WHEREIS,		&s_whereis },
+	{ "edit.active.pad",	DSTYLE_ELEMENTS,	&s_aedit_pad },
+	{ "edit.active.arrow",	DSTYLE_ELEMENTS,	&s_aedit_arr },
+	{ "edit.active.marked",	DSTYLE_ELEMENTS,	&s_aedit_sel },
+	{ "edit.active",	DSTYLE_ELEMENTS,	&s_aedit },
+	{ "edit.current",	DSTYLE_ELEMENTS,	&s_curedit },
+	{ "edit.prompt.pad",	DSTYLE_ELEMENTS,	&s_prompt_edit_pad },
+	{ "edit.prompt.arrow",	DSTYLE_ELEMENTS,	&s_prompt_edit_arr },
+	{ "edit.prompt.marked",	DSTYLE_ELEMENTS,	&s_prompt_sel },
+	{ "edit.prompt",	DSTYLE_ELEMENTS,	&s_prompt_edit },
+    };
+    unsigned n;
+    BOOL found = FALSE;
+
     char *tmp = strchr(buffer, ':');
     char *element, *mono, *fg, *bg;
 
@@ -247,98 +289,29 @@ where OBJECT is one of EM,STRONG,B,I,U,BLINK etc.\n\n"), buffer);
     /*
     * We use some pseudo-elements, so catch these first
     */
-    if (!strncasecomp(element, "default", 7)) /* default fg/bg */
-    {
-	parse_attributes(mono,fg,bg,-1,"default");
-    }
-    else if (!strncasecomp(element, "alink", 5)) /* active link */
-    {
-	parse_attributes(mono,fg,bg,DSTYLE_ALINK,"alink");
-    }
-    else if (!strcasecomp(element, "a")) /* normal link */
-    {
-	parse_attributes(mono,fg,bg, DSTYLE_LINK,"a");
-	parse_attributes(mono,fg,bg, HTML_A,"a");
-    }
-    else if (!strncasecomp(element, "status", 4)) /* status bar */
-    {
-	parse_attributes(mono,fg,bg, DSTYLE_STATUS,"status");
-    }
-    else if (!strncasecomp(element, "label", 6)) /* [INLINE]'s */
-    {
-	parse_attributes(mono,fg,bg,DSTYLE_OPTION,"label");
-    }
-    else if (!strncasecomp(element, "value", 5)) /* [INLINE]'s */
-    {
-	parse_attributes(mono,fg,bg,DSTYLE_VALUE,"value");
+    for (n = 0; n < TABLESIZE(table); n++) {
+	if (!strcasecomp(element, table[n].name)) {
+	    parse_attributes(mono, fg, bg, table[n].style, table[n].name);
+	    if (table[n].set_hash != 0)
+		*(table[n].set_hash) = hash_code(table[n].name);
+	    found = TRUE;
+	    break;
+	}
     }
-    else if (!strncasecomp(element, "high", 4)) /* [INLINE]'s */
-    {
-	parse_attributes(mono,fg,bg,DSTYLE_HIGH,"high");
+
+    if (found) {
+	;
     }
     else if (!strcasecomp(element, "normal")) /* added - kw */
     {
 	parse_attributes(mono,fg,bg,DSTYLE_NORMAL,"html");
 	s_normal  = hash_code("html"); /* rather bizarre... - kw */
     }
-    /* this may vanish */
-    else if (!strncasecomp(element, "candy", 5)) /* [INLINE]'s */
-    {
-	parse_attributes(mono,fg,bg,DSTYLE_CANDY,"candy");
-    }
-    /* added for whereis search target - kw */
-    else if (!strncasecomp(element, "whereis", 7))
-    {
-	parse_attributes(mono,fg,bg,DSTYLE_WHEREIS,"whereis");
-	s_whereis  = hash_code("whereis");
-    }
-    else if (!strncasecomp(element, "edit.active.pad", 15))
-    {
-	parse_attributes(mono,fg,bg,DSTYLE_ELEMENTS,"edit.active.pad");
-	s_aedit_pad = hash_code("edit.active.pad");
-    }
-    else if (!strncasecomp(element, "edit.active.arrow", 17))
-    {
-	parse_attributes(mono,fg,bg,DSTYLE_ELEMENTS,"edit.active.arrow");
-	s_aedit_arr  = hash_code("edit.active.arrow");
-    }
-    else if (!strncasecomp(element, "edit.active", 11))
-    {
-	parse_attributes(mono,fg,bg,DSTYLE_ELEMENTS,"edit.active");
-	s_aedit  = hash_code("edit.active");
-    }
-    else if (!strncasecomp(element, "edit.prompt.pad", 15))
-    {
-	parse_attributes(mono,fg,bg,DSTYLE_ELEMENTS,"edit.prompt.pad");
-	s_prompt_edit_pad = hash_code("edit.prompt.pad");
-    }
-    else if (!strncasecomp(element, "edit.prompt.arrow", 17))
-    {
-	parse_attributes(mono,fg,bg,DSTYLE_ELEMENTS,"edit.prompt.arrow");
-	s_prompt_edit_arr  = hash_code("edit.prompt.arrow");
-    }
-    else if (!strncasecomp(element, "edit.prompt", 11))
-    {
-	parse_attributes(mono,fg,bg,DSTYLE_ELEMENTS,"edit.prompt");
-	s_prompt_edit  = hash_code("edit.prompt");
-    }
     /* Ok, it must be a HTML element, so look through the list until we
     * find it
     */
     else
     {
-#if !defined(USE_HASH)
-	int i;
-	for (i = 0; i <HTML_ELEMENTS; i++)
-	{
-	    if (!strcasecomp (HTML_dtd.tags[i].name, element))
-	    {
-		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;
-	    }
-	}
-#else
 	int element_number = -1;
 	HTTag * t = SGMLFindTag(&HTML_dtd, element);
 	if (t && t->name) {
@@ -349,7 +322,6 @@ where OBJECT is one of EM,STRONG,B,I,U,BLINK etc.\n\n"), buffer);
 	    parse_attributes(mono,fg,bg, element_number+STARTAT,element);
 	else
 	    parse_attributes(mono,fg,bg, DSTYLE_ELEMENTS,element);
-#endif
     }
 }
 
@@ -442,18 +414,18 @@ PUBLIC void parse_userstyles NOARGS
 		parse_style(name);
 	}
     }
-    if (s_prompt_edit == NOSTYLE)
-	s_prompt_edit = s_normal;
-    if (s_prompt_edit_arr == NOSTYLE)
-	s_prompt_edit_arr = s_prompt_edit;
-    if (s_prompt_edit_pad == NOSTYLE)
-	s_prompt_edit_pad = s_prompt_edit;
-    if (s_aedit == NOSTYLE)
-	s_aedit = s_alink;
-    if (s_aedit_arr == NOSTYLE)
-	s_aedit_arr = s_aedit;
-    if (s_aedit_pad == NOSTYLE)
-	s_aedit_pad = s_aedit;
+
+#define dft_style(a,b) if (a == NOSTYLE) a = b
+
+    dft_style(s_prompt_edit,		s_normal);
+    dft_style(s_prompt_edit_arr,	s_prompt_edit);
+    dft_style(s_prompt_edit_pad,	s_prompt_edit);
+    dft_style(s_prompt_sel,		s_prompt_edit);
+    dft_style(s_aedit,			s_alink);
+    dft_style(s_aedit_arr,		s_aedit);
+    dft_style(s_aedit_pad,		s_aedit);
+    dft_style(s_curedit,		s_aedit);
+    dft_style(s_aedit_sel,		s_aedit);
 }
 
 
diff --git a/src/LYUtils.c b/src/LYUtils.c
index 103056e8..cf1e2845 100644
--- a/src/LYUtils.c
+++ b/src/LYUtils.c
@@ -119,7 +119,7 @@ extern int BSDselect PARAMS((int nfds, fd_set * readfds, fd_set * writefds,
  * it no longer applies, since it will reuse that filename at a later time.
  */
 #ifdef EXP_RAND_TEMPNAME
-#if defined(HAVE_RAND) && defined(HAVE_SRAND) && defined(RAND_MAX)
+#if defined(RAND_MAX)
 #define USE_RAND_TEMPNAME 1
 #define MAX_TEMPNAME 10000
 #ifndef BITS_PER_CHAR
@@ -245,6 +245,14 @@ PUBLIC void highlight ARGS3(
 #else	/* here USE_COLOR_STYLE defined */
 	int s = s_alink;
 
+#ifdef TEXTFIELDS_MAY_NEED_ACTIVATION
+	if ( textfields_need_activation &&
+	     links[cur].type == WWW_FORM_LINK_TYPE &&
+	     F_TEXTLIKE(links[cur].form->type) )
+	    s = s_curedit;
+#endif
+
+
 #  define LXP (links[cur].lx)
 #  define LYP (links[cur].ly)
 	if (flag != ON) {
@@ -287,7 +295,7 @@ PUBLIC void highlight ARGS3(
 	} else {
 	    CTRACE((tfp, "STYLE.highlight.on: @(%d,%d).\n", LYP, LXP));
 	}
-	move(LYP, LXP);
+	LYmove(LYP, LXP);
 	LynxChangeStyle(s, STACK_ON, 0);
 #endif
 	}
@@ -302,11 +310,11 @@ PUBLIC void highlight ARGS3(
 		       links[cur].hightext : ""),
 		      (avail_space > links[cur].form->size ?
 				      links[cur].form->size : avail_space));
-	    addstr(buffer);
+	    LYaddstr(buffer);
 
 	    len = strlen(buffer);
 	    for (; len < links[cur].form->size && len < avail_space; len++)
-		addch('_');
+		LYaddch('_');
 
 	} else {
 #if defined(USE_COLOR_STYLE) && !defined(NO_HILIT_FIX)
@@ -327,7 +335,7 @@ PUBLIC void highlight ARGS3(
 			      (sizeof(buffer) - 1),
 			      ((LYcols - 1) - links[cur].lx),
 			      utf_flag);
-		addstr(buffer);
+		LYaddstr(buffer);
 	    }
 	}
 
@@ -340,7 +348,7 @@ PUBLIC void highlight ARGS3(
 #endif
 	) {
 	    lynx_stop_link_color (flag == ON, links[cur].inUnderline);
-	    move((links[cur].ly + 1), links[cur].hightext2_offset);
+	    LYmove((links[cur].ly + 1), links[cur].hightext2_offset);
 #ifndef USE_COLOR_STYLE
 	    lynx_start_link_color (flag == ON, links[cur].inUnderline);
 #else
@@ -358,10 +366,10 @@ PUBLIC void highlight ARGS3(
 		     */
 		    if (HTCJK != NOCJK && !isascii(tmp[0])) {
 			tmp[1] = links[cur].hightext2[++i];
-			addstr(tmp);
+			LYaddstr(tmp);
 			tmp[1] = '\0';
 		    } else {
-			addstr(tmp);
+			LYaddstr(tmp);
 		    }
 		 }
 	    }
@@ -471,7 +479,7 @@ PUBLIC void highlight ARGS3(
 		 *  Go to the start of the hightext and
 		 *  handle its first character. - FM
 		 */
-		move(hLine, offset);
+		LYmove(hLine, offset);
 		tmp[0] = data[itmp];
 		if (utf_flag && !isascii(tmp[0])) {
 		    if ((*tmp & 0xe0) == 0xc0) {
@@ -507,9 +515,9 @@ PUBLIC void highlight ARGS3(
 		    if (flag != ON) {
 			LYstartTargetEmphasis();
 			TargetEmphasisON = TRUE;
-			addstr(tmp);
+			LYaddstr(tmp);
 		    } else {
-			move(hLine, (offset + 1));
+			LYmove(hLine, (offset + 1));
 		    }
 		    tmp[1] = '\0';
 		    written += (utf_extra + 1);
@@ -526,9 +534,9 @@ PUBLIC void highlight ARGS3(
 		    if (flag != ON) {
 			LYstartTargetEmphasis();
 			TargetEmphasisON = TRUE;
-			addstr(tmp);
+			LYaddstr(tmp);
 		    } else {
-			move(hLine, (offset + 1));
+			LYmove(hLine, (offset + 1));
 		    }
 		    tmp[1] = '\0';
 		    written += 2;
@@ -540,9 +548,9 @@ PUBLIC void highlight ARGS3(
 		    if (flag != ON) {
 			LYstartTargetEmphasis();
 			TargetEmphasisON = TRUE;
-			addstr(tmp);
+			LYaddstr(tmp);
 		    } else {
-			move(hLine, (offset + 1));
+			LYmove(hLine, (offset + 1));
 		    }
 		    written++;
 		}
@@ -606,9 +614,9 @@ PUBLIC void highlight ARGS3(
 			    LYstopTargetEmphasis();
 			    TargetEmphasisON = FALSE;
 			    LYGetYX(y, offset);
-			    move(hLine, (offset + 1));
+			    LYmove(hLine, (offset + 1));
 			} else {
-			    addstr(tmp);
+			    LYaddstr(tmp);
 			}
 			tmp[1] = '\0';
 			written += (utf_extra + 1);
@@ -627,9 +635,9 @@ PUBLIC void highlight ARGS3(
 			    LYstopTargetEmphasis();
 			    TargetEmphasisON = FALSE;
 			    LYGetYX(y, offset);
-			    move(hLine, (offset + 1));
+			    LYmove(hLine, (offset + 1));
 			} else {
-			    addstr(tmp);
+			    LYaddstr(tmp);
 			}
 			tmp[1] = '\0';
 			written += 2;
@@ -643,9 +651,9 @@ PUBLIC void highlight ARGS3(
 			    LYstopTargetEmphasis();
 			    TargetEmphasisON = FALSE;
 			    LYGetYX(y, offset);
-			    move(hLine, (offset + 1));
+			    LYmove(hLine, (offset + 1));
 			} else {
-			    addstr(tmp);
+			    LYaddstr(tmp);
 			}
 			written++;
 		    }
@@ -733,7 +741,7 @@ highlight_hit_within_hightext:
 	    if (!utf_flag) {
 		data += (Offset - offset);
 	    } else {
-		refresh();
+		LYrefresh();
 		data = LYmbcs_skip_glyphs(data,
 					  (Offset - offset),
 					  utf_flag);
@@ -747,7 +755,7 @@ highlight_hit_within_hightext:
 	     *	Go to the start of the hit and
 	     *	handle its first character. - FM
 	     */
-	    move(hLine, offset);
+	    LYmove(hLine, offset);
 	    tmp[0] = data[itmp];
 	    if (utf_flag && !isascii(tmp[0])) {
 		if ((*tmp & 0xe0) == 0xc0) {
@@ -786,9 +794,9 @@ highlight_hit_within_hightext:
 		    (offset > hoffset && data[itmp+1] != '\0')) {
 		    LYstartTargetEmphasis();
 		    TargetEmphasisON = TRUE;
-		    addstr(tmp);
+		    LYaddstr(tmp);
 		} else {
-		    move(hLine, (offset + 1));
+		    LYmove(hLine, (offset + 1));
 		}
 		tmp[1] = '\0';
 		written += (utf_extra + 1);
@@ -808,9 +816,9 @@ highlight_hit_within_hightext:
 		    (offset > hoffset && data[itmp+1] != '\0')) {
 		    LYstartTargetEmphasis();
 		    TargetEmphasisON = TRUE;
-		    addstr(tmp);
+		    LYaddstr(tmp);
 		} else {
-		    move(hLine, (offset + 1));
+		    LYmove(hLine, (offset + 1));
 		}
 		tmp[1] = '\0';
 		written += 2;
@@ -825,9 +833,9 @@ highlight_hit_within_hightext:
 		    (offset > hoffset && data[itmp+1] != '\0')) {
 		    LYstartTargetEmphasis();
 		    TargetEmphasisON = TRUE;
-		    addstr(tmp);
+		    LYaddstr(tmp);
 		} else {
-		    move(hLine, (offset + 1));
+		    LYmove(hLine, (offset + 1));
 		}
 		written++;
 	    }
@@ -888,9 +896,9 @@ highlight_hit_within_hightext:
 			LYstopTargetEmphasis();
 			TargetEmphasisON = FALSE;
 			LYGetYX(y, offset);
-			move(hLine, (offset + 1));
+			LYmove(hLine, (offset + 1));
 		    } else {
-			addstr(tmp);
+			LYaddstr(tmp);
 		    }
 		    tmp[1] = '\0';
 		    written += (utf_extra + 1);
@@ -909,9 +917,9 @@ highlight_hit_within_hightext:
 			LYstopTargetEmphasis();
 			TargetEmphasisON = FALSE;
 			LYGetYX(y, offset);
-			move(hLine, (offset + 1));
+			LYmove(hLine, (offset + 1));
 		    } else {
-			addstr(tmp);
+			LYaddstr(tmp);
 		    }
 		    tmp[1] = '\0';
 		    written += 2;
@@ -925,9 +933,9 @@ highlight_hit_within_hightext:
 			LYstopTargetEmphasis();
 			TargetEmphasisON = FALSE;
 			LYGetYX(y, offset);
-			move(hLine, (offset + 1));
+			LYmove(hLine, (offset + 1));
 		    } else {
-			addstr(tmp);
+			LYaddstr(tmp);
 		    }
 		    written++;
 		}
@@ -996,12 +1004,12 @@ highlight_hit_within_hightext:
 		    if (!utf_flag) {
 			data = buffer + (offset - hoffset);
 		    } else {
-			refresh();
+			LYrefresh();
 			data = LYmbcs_skip_glyphs(buffer,
 						  (offset - hoffset),
 						  utf_flag);
 		    }
-		    move(hLine, offset);
+		    LYmove(hLine, offset);
 		    itmp = 0;
 		    written = 0;
 		    len = strlen(data);
@@ -1056,9 +1064,9 @@ highlight_hit_within_hightext:
 				LYstopTargetEmphasis();
 				TargetEmphasisON = FALSE;
 				LYGetYX(y, offset);
-				move(hLine, (offset + 1));
+				LYmove(hLine, (offset + 1));
 			    } else {
-				addstr(tmp);
+				LYaddstr(tmp);
 			    }
 			    tmp[1] = '\0';
 			    written += (utf_extra + 1);
@@ -1077,7 +1085,7 @@ highlight_hit_within_hightext:
 				LYstopTargetEmphasis();
 				TargetEmphasisON = FALSE;
 			    } else {
-				addstr(tmp);
+				LYaddstr(tmp);
 			    }
 			    tmp[1] = '\0';
 			    written += 2;
@@ -1091,7 +1099,7 @@ highlight_hit_within_hightext:
 				LYstopTargetEmphasis();
 				TargetEmphasisON = FALSE;
 			    } else {
-				addstr(tmp);
+				LYaddstr(tmp);
 			    }
 			    written++;
 			}
@@ -1201,7 +1209,7 @@ highlight_search_hightext2:
 		 *  Go to the start of the hightext2 and
 		 *  handle its first character. - FM
 		 */
-		move(hLine, offset);
+		LYmove(hLine, offset);
 		tmp[0] = data[itmp];
 		if (utf_flag && !isascii(tmp[0])) {
 		    if ((*tmp & 0xe0) == 0xc0) {
@@ -1237,9 +1245,9 @@ highlight_search_hightext2:
 		    if (flag != ON) {
 			LYstartTargetEmphasis();
 			TargetEmphasisON = TRUE;
-			addstr(tmp);
+			LYaddstr(tmp);
 		    } else {
-			move(hLine, (offset + 1));
+			LYmove(hLine, (offset + 1));
 		    }
 		    tmp[1] = '\0';
 		    written += (utf_extra + 1);
@@ -1256,9 +1264,9 @@ highlight_search_hightext2:
 		    if (flag != ON) {
 			LYstartTargetEmphasis();
 			TargetEmphasisON = TRUE;
-			addstr(tmp);
+			LYaddstr(tmp);
 		    } else {
-			move(hLine, (offset + 1));
+			LYmove(hLine, (offset + 1));
 		    }
 		    tmp[1] = '\0';
 		    written += 2;
@@ -1270,9 +1278,9 @@ highlight_search_hightext2:
 		    if (flag != ON) {
 			LYstartTargetEmphasis();
 			TargetEmphasisON = TRUE;
-			addstr(tmp);
+			LYaddstr(tmp);
 		    } else {
-			move(hLine, (offset + 1));
+			LYmove(hLine, (offset + 1));
 		    }
 		    written++;
 		}
@@ -1336,9 +1344,9 @@ highlight_search_hightext2:
 			    LYstopTargetEmphasis();
 			    TargetEmphasisON = FALSE;
 			    LYGetYX(y, offset);
-			    move(hLine, (offset + 1));
+			    LYmove(hLine, (offset + 1));
 			} else {
-			    addstr(tmp);
+			    LYaddstr(tmp);
 			}
 			tmp[1] = '\0';
 			written += (utf_extra + 1);
@@ -1357,9 +1365,9 @@ highlight_search_hightext2:
 			    LYstopTargetEmphasis();
 			    TargetEmphasisON = FALSE;
 			    LYGetYX(y, offset);
-			    move(hLine, (offset + 1));
+			    LYmove(hLine, (offset + 1));
 			} else {
-			    addstr(tmp);
+			    LYaddstr(tmp);
 			}
 			tmp[1] = '\0';
 			written += 2;
@@ -1373,9 +1381,9 @@ highlight_search_hightext2:
 			    LYstopTargetEmphasis();
 			    TargetEmphasisON = FALSE;
 			    LYGetYX(y, offset);
-			    move(hLine, (offset + 1));
+			    LYmove(hLine, (offset + 1));
 			} else {
-			    addstr(tmp);
+			    LYaddstr(tmp);
 			}
 			written++;
 		    }
@@ -1462,7 +1470,7 @@ highlight_hit_within_hightext2:
 	    if (!utf_flag) {
 		data += (Offset - offset);
 	    } else {
-		refresh();
+		LYrefresh();
 		data = LYmbcs_skip_glyphs(data,
 					  (Offset - offset),
 					  utf_flag);
@@ -1476,7 +1484,7 @@ highlight_hit_within_hightext2:
 	     *	Go to the start of the hit and
 	     *	handle its first character. - FM
 	     */
-	    move(hLine, offset);
+	    LYmove(hLine, offset);
 	    tmp[0] = data[itmp];
 	    if (utf_flag && !isascii(tmp[0])) {
 		if ((*tmp & 0xe0) == 0xc0) {
@@ -1515,9 +1523,9 @@ highlight_hit_within_hightext2:
 		    (offset > hoffset && data[itmp+1] != '\0')) {
 		    LYstartTargetEmphasis();
 		    TargetEmphasisON = TRUE;
-		    addstr(tmp);
+		    LYaddstr(tmp);
 		} else {
-		    move(hLine, (offset + 1));
+		    LYmove(hLine, (offset + 1));
 		}
 		tmp[1] = '\0';
 		written += (utf_extra + 1);
@@ -1537,9 +1545,9 @@ highlight_hit_within_hightext2:
 		    (offset > hoffset && data[itmp+1] != '\0')) {
 		    LYstartTargetEmphasis();
 		    TargetEmphasisON = TRUE;
-		    addstr(tmp);
+		    LYaddstr(tmp);
 		} else {
-		    move(hLine, (offset + 1));
+		    LYmove(hLine, (offset + 1));
 		}
 		tmp[1] = '\0';
 		written += 2;
@@ -1554,9 +1562,9 @@ highlight_hit_within_hightext2:
 		    (offset > hoffset && data[itmp+1] != '\0')) {
 		    LYstartTargetEmphasis();
 		    TargetEmphasisON = TRUE;
-		    addstr(tmp);
+		    LYaddstr(tmp);
 		} else {
-		    move(hLine, (offset + 1));
+		    LYmove(hLine, (offset + 1));
 		}
 		written++;
 	    }
@@ -1617,9 +1625,9 @@ highlight_hit_within_hightext2:
 			LYstopTargetEmphasis();
 			TargetEmphasisON = FALSE;
 			LYGetYX(y, offset);
-			move(hLine, (offset + 1));
+			LYmove(hLine, (offset + 1));
 		    } else {
-			addstr(tmp);
+			LYaddstr(tmp);
 		    }
 		    tmp[1] = '\0';
 		    written += (utf_extra + 1);
@@ -1638,9 +1646,9 @@ highlight_hit_within_hightext2:
 			LYstopTargetEmphasis();
 			TargetEmphasisON = FALSE;
 			LYGetYX(y, offset);
-			move(hLine, (offset + 1));
+			LYmove(hLine, (offset + 1));
 		    } else {
-			addstr(tmp);
+			LYaddstr(tmp);
 		    }
 		    tmp[1] = '\0';
 		    written += 2;
@@ -1654,9 +1662,9 @@ highlight_hit_within_hightext2:
 			LYstopTargetEmphasis();
 			TargetEmphasisON = FALSE;
 			LYGetYX(y, offset);
-			move(hLine, (offset + 1));
+			LYmove(hLine, (offset + 1));
 		    } else {
-			addstr(tmp);
+			LYaddstr(tmp);
 		    }
 		    written++;
 		}
@@ -1725,12 +1733,12 @@ highlight_hit_within_hightext2:
 		    if (!utf_flag) {
 			data = buffer + (offset - hoffset);
 		    } else {
-			refresh();
+			LYrefresh();
 			data = LYmbcs_skip_glyphs(buffer,
 						  (offset - hoffset),
 						  utf_flag);
 		    }
-		    move(hLine, offset);
+		    LYmove(hLine, offset);
 		    itmp = 0;
 		    written = 0;
 		    len = strlen(data);
@@ -1785,9 +1793,9 @@ highlight_hit_within_hightext2:
 				LYstopTargetEmphasis();
 				TargetEmphasisON = FALSE;
 				LYGetYX(y, offset);
-				move(hLine, (offset + 1));
+				LYmove(hLine, (offset + 1));
 			    } else {
-				addstr(tmp);
+				LYaddstr(tmp);
 			    }
 			    tmp[1] = '\0';
 			    written += (utf_extra + 1);
@@ -1806,7 +1814,7 @@ highlight_hit_within_hightext2:
 				LYstopTargetEmphasis();
 				TargetEmphasisON = FALSE;
 			    } else {
-				addstr(tmp);
+				LYaddstr(tmp);
 			    }
 			    tmp[1] = '\0';
 			    written += 2;
@@ -1820,7 +1828,7 @@ highlight_hit_within_hightext2:
 				LYstopTargetEmphasis();
 				TargetEmphasisON = FALSE;
 			    } else {
-				addstr(tmp);
+				LYaddstr(tmp);
 			    }
 			    written++;
 			}
@@ -1856,11 +1864,11 @@ highlight_search_done:
 	    /*
 	     *	Never hide the cursor if there's no FANCY CURSES or SLANG.
 	     */
-	    move(links[cur].ly,
+	    LYmove(links[cur].ly,
 		 ((links[cur].lx > 0) ? (links[cur].lx - 1) : 0));
 
 	if (flag)
-	    refresh();
+	    LYrefresh();
     }
     return;
 }
@@ -2066,16 +2074,16 @@ PUBLIC void statusline ARGS1(
      */
     if (LYStatusLine >= 0) {
 	if (LYStatusLine < LYlines-1) {
-	    move(LYStatusLine, 0);
+	    LYmove(LYStatusLine, 0);
 	} else {
-	    move(LYlines-1, 0);
+	    LYmove(LYlines-1, 0);
 	}
     } else if (user_mode == NOVICE_MODE) {
-	move(LYlines-3, 0);
+	LYmove(LYlines-3, 0);
     } else {
-	move(LYlines-1, 0);
+	LYmove(LYlines-1, 0);
     }
-    clrtoeol();
+    LYclrtoeol();
 
     if (text != NULL && text[0] != '\0') {
 	BOOLEAN has_CJK = FALSE;
@@ -2094,12 +2102,12 @@ PUBLIC void statusline ARGS1(
 	    || (LYCharSet_UC[current_char_set].enc == UCT_ENC_UTF8)
 #endif
 	    ) {
-	    refresh();
+	    LYrefresh();
 	}
 
 #ifndef USE_COLOR_STYLE
 	lynx_start_status_color ();
-	addstr (buffer);
+	LYaddstr (buffer);
 	lynx_stop_status_color ();
 #else
 	/* draw the status bar in the STATUS style */
@@ -2107,23 +2115,23 @@ PUBLIC void statusline ARGS1(
 		int a=(strncmp(buffer, ALERT_FORMAT, ALERT_PREFIX_LEN) ||
 		       !hashStyles[s_alert].name) ? s_status : s_alert;
 		LynxChangeStyle (a, STACK_ON, 1);
-		addstr(buffer);
-		wbkgdset(stdscr,
+		LYaddstr(buffer);
+		wbkgdset(LYwin,
 			 ((lynx_has_color && LYShowColor >= SHOW_COLOR_ON)
 			  ? hashStyles[a].color
 			  :A_NORMAL) | ' ');
-		clrtoeol();
+		LYclrtoeol();
 		if (!(lynx_has_color && LYShowColor >= SHOW_COLOR_ON))
-		    wbkgdset(stdscr, A_NORMAL | ' ');
+		    wbkgdset(LYwin, A_NORMAL | ' ');
 		else if (s_normal != NOSTYLE)
-		    wbkgdset(stdscr, hashStyles[s_normal].color | ' ');
+		    wbkgdset(LYwin, hashStyles[s_normal].color | ' ');
 		else
-		    wbkgdset(stdscr, displayStyles[DSTYLE_NORMAL].color | ' ');
+		    wbkgdset(LYwin, displayStyles[DSTYLE_NORMAL].color | ' ');
 		LynxChangeStyle (a, STACK_OFF, 0);
 	}
 #endif
     }
-    refresh();
+    LYrefresh();
 
     return;
 }
@@ -2160,23 +2168,23 @@ PUBLIC void noviceline ARGS1(
     if (dump_output_immediately)
 	return;
 
-    move(LYlines-2,0);
+    LYmove(LYlines-2,0);
     /* stop_reverse(); */
-    clrtoeol();
-    addstr(NOVICE_LINE_ONE);
-    clrtoeol();
+    LYclrtoeol();
+    LYaddstr(NOVICE_LINE_ONE);
+    LYclrtoeol();
 #if defined(DIRED_SUPPORT ) && defined(OK_OVERRIDE)
     if (lynx_edit_mode && !no_dired_support)
-	addstr(DIRED_NOVICELINE);
+	LYaddstr(DIRED_NOVICELINE);
     else
 #endif /* DIRED_SUPPORT && OK_OVERRIDE */
 
     if (LYUseNoviceLineTwo)
-	addstr(NOVICE_LINE_TWO);
+	LYaddstr(NOVICE_LINE_TWO);
     else
-	addstr((char *)novice_lines(lineno));
+	LYaddstr((char *)novice_lines(lineno));
 
-    refresh();
+    LYrefresh();
     return;
 }
 
@@ -2335,14 +2343,14 @@ PUBLIC int HTCheckForInterrupt NOARGS
 #endif /* !_WINDOWS */
 
 #if defined(PDCURSES)
-    nodelay(stdscr,TRUE);
+    nodelay(LYwin,TRUE);
 #endif /* DOSPATH */
     /*
      * 'c' contains whatever character we're able to read from keyboard
      */
     c = LYgetch();
 #if defined(PDCURSES)
-    nodelay(stdscr,FALSE);
+    nodelay(LYwin,FALSE);
 #endif /* DOSPATH */
 
 #else /* VMS: */
@@ -2378,7 +2386,7 @@ PUBLIC int HTCheckForInterrupt NOARGS
      */
 
 	/** Keyboard 'Z' or 'z', or Control-G or Control-C **/
-    if (TOUPPER(c) == 'Z' || LYCharIsINTERRUPT(c))
+    if (LYCharIsINTERRUPT(c))
 	return((int)TRUE);
 
 	/* There is a subset of mainloop() actions available at this stage:
@@ -2858,6 +2866,11 @@ PUBLIC int is_url ARGS1(
     } else if (compare_type(cp, "mailto:", 7)) {
 	return(MAILTO_URL_TYPE);
 
+#ifndef DISABLE_BIBP
+    } else if (compare_type(cp, "bibp:", 5)) {
+	return(BIBP_URL_TYPE);
+#endif
+
     } else if (compare_type(cp, "file:", 5)) {
 	if (LYisLocalFile(cp)) {
 	    return(FILE_URL_TYPE);
@@ -3460,9 +3473,9 @@ PUBLIC void size_change ARGS1(
 #endif /* HAVE_SIZECHANGE */
 
     if (LYlines <= 0)
-	LYlines = 24;
+	LYlines = DFT_ROWS;
     if (LYcols <= 0)
-	LYcols = 80;
+	LYcols = DFT_COLS;
 #endif /* USE_SLANG */
 
     /*
@@ -3880,7 +3893,7 @@ PRIVATE int fmt_tempname ARGS3(
      */
 #ifdef USE_RAND_TEMPNAME
     if (first) {
-	srand((unsigned)((long)time((time_t *)0) + (long)result));
+	my_srand((unsigned)((long)time((time_t *)0) + (long)result));
 	first = FALSE;
 	used_tempname = typecallocn(unsigned char,
 				(MAX_TEMPNAME / BITS_PER_CHAR) + 1);
@@ -3895,7 +3908,7 @@ PRIVATE int fmt_tempname ARGS3(
      */
     counter = MAX_TEMPNAME;
     while (names_used < MAX_TEMPNAME) {
-	counter = ( (float)MAX_TEMPNAME * rand() ) / RAND_MAX + 1;
+	counter = ( (float)MAX_TEMPNAME * my_rand() ) / RAND_MAX + 1;
 	/*
 	 * Avoid reusing a temporary name, since there are places in the code
 	 * which can refer to a temporary filename even after it has been
@@ -4005,114 +4018,66 @@ PUBLIC int number2arrows ARGS1(
 /* skip the special flags when processing "all" and "default": */
 #define N_SPECIAL_RESTRICT_OPTIONS 2
 
-PRIVATE CONST char *restrict_name[] = {
-       "default" ,
-       "all"     ,
-       "inside_telnet" ,
-       "outside_telnet",
-       "telnet_port"   ,
-       "inside_ftp"    ,
-       "outside_ftp"   ,
-       "inside_rlogin" ,
-       "outside_rlogin",
-       "suspend"       ,
-       "editor"        ,
-       "shell"	       ,
-       "bookmark"      ,
-       "multibook"     ,
-       "bookmark_exec" ,
-       "option_save"   ,
-       "print"	       ,
-       "download"      ,
-       "disk_save"     ,
-       "exec"	       ,
-       "lynxcgi"       ,
-       "exec_frozen"   ,
-       "goto"	       ,
-       "jump"	       ,
-       "file_url"      ,
-#ifndef DISABLE_NEWS
-       "news_post"     ,
-       "inside_news"   ,
-       "outside_news"  ,
-#endif
-       "mail"	       ,
-       "dotfiles"      ,
-       "useragent"     ,
-#ifdef DIRED_SUPPORT
-       "dired_support" ,
-#ifdef OK_PERMIT
-       "change_exec_perms",
-#endif /* OK_PERMIT */
-#endif /* DIRED_SUPPORT */
-#ifdef USE_EXTERNALS
-       "externals" ,
-#endif
-       "lynxcfg_info" ,
-#ifndef NO_CONFIG_INFO
-       "lynxcfg_xinfo" ,
-#ifdef HAVE_CONFIG_H
-       "compileopts_info",
-#endif
+PRIVATE CONST struct {
+    CONST char *name;
+    BOOLEAN *flag;
+    BOOLEAN can;
+} restrictions[] = {
+    { "default",	&had_restrictions_default, TRUE },
+    { "all",		&had_restrictions_all,	TRUE },
+    { "inside_telnet",	&no_inside_telnet,	CAN_ANONYMOUS_INSIDE_DOMAIN_TELNET },
+    { "outside_telnet",	&no_outside_telnet,	CAN_ANONYMOUS_OUTSIDE_DOMAIN_TELNET },
+    { "telnet_port",	&no_telnet_port,	CAN_ANONYMOUS_GOTO_TELNET_PORT },
+    { "inside_ftp",	&no_inside_ftp,		CAN_ANONYMOUS_INSIDE_DOMAIN_FTP },
+    { "outside_ftp",	&no_outside_ftp,	CAN_ANONYMOUS_OUTSIDE_DOMAIN_FTP },
+    { "inside_rlogin",	&no_inside_rlogin,	CAN_ANONYMOUS_INSIDE_DOMAIN_RLOGIN },
+    { "outside_rlogin",	&no_outside_rlogin,	CAN_ANONYMOUS_OUTSIDE_DOMAIN_RLOGIN },
+    { "suspend",	&no_suspend,		TRUE },
+    { "editor",		&no_editor,		TRUE },
+    { "shell",		&no_shell,		TRUE },
+    { "bookmark",	&no_bookmark,		TRUE },
+    { "multibook",	&no_multibook,		TRUE },
+    { "bookmark_exec",	&no_bookmark_exec,	TRUE },
+    { "option_save",	&no_option_save,	TRUE },
+    { "print",		&no_print,		CAN_ANONYMOUS_PRINT },
+    { "download",	&no_download,		TRUE },
+    { "disk_save",	&no_disk_save,		TRUE },
+#if defined(EXEC_LINKS) || defined(EXEC_SCRIPTS)
+    { "exec",		&no_exec,		LOCAL_EXECUTION_LINKS_ALWAYS_OFF_FOR_ANONYMOUS },
 #endif
-       (char *) 0     };
-
-	/* restrict_name and restrict_flag structure order
-	 * must be maintained exactly!
-	 */
-
-PRIVATE BOOLEAN *restrict_flag[] = {
-       &had_restrictions_default,
-       &had_restrictions_all,
-       &no_inside_telnet,
-       &no_outside_telnet,
-       &no_telnet_port,
-       &no_inside_ftp,
-       &no_outside_ftp,
-       &no_inside_rlogin,
-       &no_outside_rlogin,
-       &no_suspend  ,
-       &no_editor   ,
-       &no_shell    ,
-       &no_bookmark ,
-       &no_multibook ,
-       &no_bookmark_exec,
-       &no_option_save,
-       &no_print    ,
-       &no_download ,
-       &no_disk_save,
-       &no_exec     ,
-       &no_lynxcgi  ,
-       &exec_frozen ,
-       &no_goto     ,
-       &no_jump     ,
-       &no_file_url ,
+    { "lynxcgi",	&no_lynxcgi,		TRUE },
+    { "exec_frozen",	&exec_frozen,		TRUE },
+    { "goto",		&no_goto,		CAN_ANONYMOUS_GOTO },
+    { "jump",		&no_jump,		CAN_ANONYMOUS_JUMP },
+    { "file_url",	&no_file_url,		TRUE },
 #ifndef DISABLE_NEWS
-       &no_newspost ,
-       &no_inside_news,
-       &no_outside_news,
+    { "news_post",	&no_newspost,		TRUE },
+    { "inside_news",	&no_inside_news,	CAN_ANONYMOUS_INSIDE_DOMAIN_READ_NEWS },
+    { "outside_news",	&no_outside_news,	CAN_ANONYMOUS_OUTSIDE_DOMAIN_READ_NEWS },
 #endif
-       &no_mail     ,
-       &no_dotfiles ,
-       &no_useragent ,
+    { "mail",		&no_mail,		CAN_ANONYMOUS_MAIL },
+    { "dotfiles",	&no_dotfiles,		TRUE },
+    { "useragent",	&no_useragent,		TRUE },
 #ifdef DIRED_SUPPORT
-       &no_dired_support,
+    { "dired_support",	&no_dired_support,	TRUE },
 #ifdef OK_PERMIT
-       &no_change_exec_perms,
+    { "change_exec_perms", &no_change_exec_perms, TRUE },
 #endif /* OK_PERMIT */
 #endif /* DIRED_SUPPORT */
 #ifdef USE_EXTERNALS
-       &no_externals ,
+    { "externals",	&no_externals,		TRUE },
 #endif
-       &no_lynxcfg_info ,
+    { "lynxcfg_info",	&no_lynxcfg_info,	CAN_ANONYMOUS_VIEW_LYNXCFG_INFO },
 #ifndef NO_CONFIG_INFO
-       &no_lynxcfg_xinfo ,
+    { "lynxcfg_xinfo",	&no_lynxcfg_xinfo,	CAN_ANONYMOUS_VIEW_LYNXCFG_EXTENDED_INFO },
 #ifdef HAVE_CONFIG_H
-       &no_compileopts_info ,
+    { "compileopts_info", &no_compileopts_info,	CAN_ANONYMOUS_VIEW_COMPILEOPTS_INFO },
 #endif
 #endif
-       (BOOLEAN *) 0  };
-
+#ifndef DISABLE_BIBP
+    { "bibp:",		&no_goto_bibp,		TRUE },
+#endif
+};
 
 /*  This will make no difference between '-' and '_'. It does only in/equality
     compare. It assumes that p2 can't contain dashes, but p1 can.
@@ -4162,103 +4127,56 @@ PUBLIC BOOL strn_dash_equ ARGS3(
 PUBLIC void parse_restrictions ARGS1(
 	CONST char *,	s)
 {
-      CONST char *p;
-      CONST char *word;
-      int i;
-
-      p = s;
-      while (*p) {
-	  p = LYSkipCBlanks(p);
-	  if (*p == '\0')
-	      break;
-	  word = p;
-	  while (*p != ',' && *p != '\0')
-	      p++;
-
-	  if (RESTRICT_NM_EQU(word, "all", p-word)) {
-	      /* set all restrictions */
-	      for (i=N_SPECIAL_RESTRICT_OPTIONS; restrict_flag[i]; i++)
-		  *restrict_flag[i] = TRUE;
-	  }
+    CONST char *p;
+    CONST char *word;
+    unsigned i;
 
-	  if (RESTRICT_NM_EQU(word, "default", p-word)) {
-	      /* set all restrictions */
-	      for (i=N_SPECIAL_RESTRICT_OPTIONS; restrict_flag[i]; i++)
-		  *restrict_flag[i] = TRUE;
+    p = s;
+    while (*p) {
+	p = LYSkipCBlanks(p);
+	if (*p == '\0')
+	    break;
+	word = p;
+	while (*p != ',' && *p != '\0')
+	    p++;
 
-	     /* reset these to defaults */
-	     no_inside_telnet = !(CAN_ANONYMOUS_INSIDE_DOMAIN_TELNET);
-	    no_outside_telnet = !(CAN_ANONYMOUS_OUTSIDE_DOMAIN_TELNET);
-#ifndef DISABLE_NEWS
-	       no_inside_news = !(CAN_ANONYMOUS_INSIDE_DOMAIN_READ_NEWS);
-	      no_outside_news = !(CAN_ANONYMOUS_OUTSIDE_DOMAIN_READ_NEWS);
-#endif
-		no_inside_ftp = !(CAN_ANONYMOUS_INSIDE_DOMAIN_FTP);
-	       no_outside_ftp = !(CAN_ANONYMOUS_OUTSIDE_DOMAIN_FTP);
-	     no_inside_rlogin = !(CAN_ANONYMOUS_INSIDE_DOMAIN_RLOGIN);
-	    no_outside_rlogin = !(CAN_ANONYMOUS_OUTSIDE_DOMAIN_RLOGIN);
-		      no_goto = !(CAN_ANONYMOUS_GOTO);
-		  no_goto_cso = !(CAN_ANONYMOUS_GOTO_CSO);
-		 no_goto_file = !(CAN_ANONYMOUS_GOTO_FILE);
-#ifndef DISABLE_FINGER
-	       no_goto_finger = !(CAN_ANONYMOUS_GOTO_FINGER);
-#endif
-		  no_goto_ftp = !(CAN_ANONYMOUS_GOTO_FTP);
-#ifndef DISABLE_GOPHER
-	       no_goto_gopher = !(CAN_ANONYMOUS_GOTO_GOPHER);
-#endif
-		 no_goto_http = !(CAN_ANONYMOUS_GOTO_HTTP);
-		no_goto_https = !(CAN_ANONYMOUS_GOTO_HTTPS);
-	      no_goto_lynxcgi = !(CAN_ANONYMOUS_GOTO_LYNXCGI);
-	     no_goto_lynxexec = !(CAN_ANONYMOUS_GOTO_LYNXEXEC);
-	     no_goto_lynxprog = !(CAN_ANONYMOUS_GOTO_LYNXPROG);
-	       no_goto_mailto = !(CAN_ANONYMOUS_GOTO_MAILTO);
-#ifndef DISABLE_NEWS
-		 no_goto_news = !(CAN_ANONYMOUS_GOTO_NEWS);
-		 no_goto_nntp = !(CAN_ANONYMOUS_GOTO_NNTP);
-#endif
-	       no_goto_rlogin = !(CAN_ANONYMOUS_GOTO_RLOGIN);
-#ifndef DISABLE_NEWS
-		no_goto_snews = !(CAN_ANONYMOUS_GOTO_SNEWS);
-#endif
-	       no_goto_telnet = !(CAN_ANONYMOUS_GOTO_TELNET);
-	       no_goto_tn3270 = !(CAN_ANONYMOUS_GOTO_TN3270);
-		 no_goto_wais = !(CAN_ANONYMOUS_GOTO_WAIS);
-	       no_telnet_port = !(CAN_ANONYMOUS_GOTO_TELNET_PORT);
-		      no_jump = !(CAN_ANONYMOUS_JUMP);
-		      no_mail = !(CAN_ANONYMOUS_MAIL);
-		     no_print = !(CAN_ANONYMOUS_PRINT);
-	      no_lynxcfg_info = !(CAN_ANONYMOUS_VIEW_LYNXCFG_INFO);
-#ifndef NO_CONFIG_INFO
-	     no_lynxcfg_xinfo = !(CAN_ANONYMOUS_VIEW_LYNXCFG_EXTENDED_INFO);
-#ifdef HAVE_CONFIG_H
-	  no_compileopts_info = !(CAN_ANONYMOUS_VIEW_COMPILEOPTS_INFO);
-#endif
-#endif
-	   no_goto_configinfo = !(CAN_ANONYMOUS_GOTO_CONFIGINFO);
-#if defined(EXEC_LINKS) || defined(EXEC_SCRIPTS)
-		      no_exec = LOCAL_EXECUTION_LINKS_ALWAYS_OFF_FOR_ANONYMOUS;
-#endif /* EXEC_LINKS || EXEC_SCRIPTS */
-	  }
+	if (RESTRICT_NM_EQU(word, "all", p-word)) {
+	    for (i = N_SPECIAL_RESTRICT_OPTIONS; i < TABLESIZE(restrictions); i++)
+		*(restrictions[i].flag) = TRUE;
+	} else if (RESTRICT_NM_EQU(word, "default", p-word)) {
+	    for (i = N_SPECIAL_RESTRICT_OPTIONS; i < TABLESIZE(restrictions); i++)
+		*(restrictions[i].flag) = !restrictions[i].can;
+	} else {
+	    for (i=0; i < TABLESIZE(restrictions); i++) {
+		if (RESTRICT_NM_EQU(word, restrictions[i].name, p-word)) {
+		    *(restrictions[i].flag) = TRUE;
+		    break;
+		}
+	    }
+	}
+	if (*p)
+	    p++;
+    }
 
-	  for (i=0; restrict_name[i]; i++) {
-	     if (RESTRICT_NM_EQU(word, restrict_name[i], p-word)) {
-		 *restrict_flag[i] = TRUE;
-		 break;
-	     }
-	  }
-	  if (*p)
-	      p++;
-      }
-      return;
+    /*
+     * If shell is restricted, set restrictions on related topics.
+     */
+    if (no_shell) {
+	no_goto_lynxexec = TRUE;
+	no_goto_lynxprog = TRUE;
+	no_goto_lynxcgi = TRUE;
+#ifdef EXEC_LINKS
+	local_exec_on_local_files = TRUE;
+#endif
+    }
 }
 
 PUBLIC void print_restrictions_to_fd ARGS1(
     FILE *,	fp)
 {
-    int i, count = 0;
-    for (i=0; restrict_name[i]; i++) {
-	if (*restrict_flag[i] == TRUE)
+    unsigned i, count = 0;
+    for (i=0; i < TABLESIZE(restrictions); i++) {
+	if (*(restrictions[i].flag) == TRUE)
 	    count++;
     }
     if (!count) {
@@ -4266,9 +4184,9 @@ PUBLIC void print_restrictions_to_fd ARGS1(
 	return;
     }
     fprintf(fp, gettext("Restrictions set:\n"));
-    for (i=0; restrict_name[i]; i++) {
-	if (*restrict_flag[i] == TRUE) {
-	    fprintf(fp, "   %s\n", restrict_name[i]);
+    for (i=0; i < TABLESIZE(restrictions); i++) {
+	if (*(restrictions[i].flag) == TRUE) {
+	    fprintf(fp, "   %s\n", restrictions[i].name);
 	}
     }
 }
@@ -4939,9 +4857,9 @@ PUBLIC int win32_check_interrupt()
     int c;
 
     if (kbhit()) {
-	c = getch();
+	c = wgetch(LYwin);
 	/** Keyboard 'Z' or 'z', or Control-G or Control-C **/
-	if (TOUPPER(c) == 'Z' || LYCharIsINTERRUPT(c) || c == 0x1b) {
+	if (LYCharIsINTERRUPT(c) || c == 0x1b) {
 	    return TRUE;
 	}
     }
@@ -4957,7 +4875,7 @@ void sleep(unsigned sec)
 	for (i = 0; i < 10; i++) {
 	    Sleep(100);
 	    if (kbhit()) {
-		c = getch();
+		c = wgetch(LYwin);
 		return;
 	    }
 	}
@@ -6947,6 +6865,31 @@ PUBLIC void LYRenamedTemp ARGS2(
     }
 }
 
+#ifndef DISABLE_BIBP
+/*
+ *  Check that bibhost defines the BibP icon.
+ */
+PUBLIC void LYCheckBibHost NOARGS
+{
+    DocAddress bibhostIcon;
+    BOOLEAN saveFlag;
+
+    bibhostIcon.address = NULL;
+    StrAllocCopy(bibhostIcon.address, BibP_bibhost);
+    StrAllocCat(bibhostIcon.address, "bibp1.0/bibpicon.jpg");
+    bibhostIcon.post_data = NULL;
+    bibhostIcon.post_content_type = NULL;
+    bibhostIcon.bookmark = FALSE;
+    bibhostIcon.isHEAD = FALSE;
+    bibhostIcon.safe = FALSE;
+    saveFlag = traversal;
+    traversal = TRUE;  /* Hack to force error response. */
+    BibP_bibhost_available = HTLoadAbsolute(&bibhostIcon) == YES;
+    traversal = saveFlag;
+    BibP_bibhost_checked = TRUE;
+}
+#endif /* !DISABLE_BIBP */
+
 /*
  *  Management of User Interface Pages. - kw
  *
diff --git a/src/LYUtils.h b/src/LYUtils.h
index 7e371764..c7671bc3 100644
--- a/src/LYUtils.h
+++ b/src/LYUtils.h
@@ -2,6 +2,7 @@
 #define LYUTILS_H
 
 #include <LYCharVals.h>  /* S/390 -- gil -- 2149 */
+#include <LYKeymap.h>
 
 #ifndef HTLIST_H
 #include <HTList.h>
@@ -34,8 +35,16 @@
 
 #define LYIsPipeCommand(s) ((s)[0] == '|')
 
-/* See definitions in src/LYCharVals.h. */
-#define LYCharIsINTERRUPT(ch)	((ch) == LYCharINTERRUPT1 || ch == LYCharINTERRUPT2)
+/* See definitions in src/LYCharVals.h.  The hardcoded values...
+   This prohibits binding C-c and C-g.  Maybe it is better to remove this? */
+#define LYCharIsINTERRUPT_HARD(ch)	\
+  ((ch) == LYCharINTERRUPT1 || ch == LYCharINTERRUPT2)
+
+#define LYCharIsINTERRUPT(ch)		\
+  (LYCharIsINTERRUPT_HARD(ch) || LKC_TO_LAC(keymap,ch) == LYK_INTERRUPT)
+
+#define LYCharIsINTERRUPT_NO_letter(ch)	\
+  (LYCharIsINTERRUPT(ch) && !isprint(ch))
 
 #if defined(DOSPATH) || defined(__EMX__)
 #define LYIsPathSep(ch) ((ch) == '/' || (ch) == '\\')
@@ -108,6 +117,7 @@ extern void LYAddLocalhostAlias PARAMS((char *alias));
 extern void LYAddPathSep PARAMS((char **path));
 extern void LYAddPathSep0 PARAMS((char *path));
 extern void LYAddPathToHome PARAMS((char *fbuffer, size_t fbuffer_size, char *fname));
+extern void LYCheckBibHost NOPARAMS;
 extern void LYCheckMail NOPARAMS;
 extern void LYCleanupTemp NOPARAMS;
 extern void LYCloseTemp PARAMS((char *name));
@@ -212,6 +222,7 @@ typedef enum {
     TELNET_GOPHER_URL_TYPE,
     INDEX_GOPHER_URL_TYPE,
     MAILTO_URL_TYPE,
+    BIBP_URL_TYPE,
     FINGER_URL_TYPE,
     CSO_URL_TYPE,
     HTTPS_URL_TYPE,
diff --git a/src/LYrcFile.c b/src/LYrcFile.c
index e253d006..31eb8380 100644
--- a/src/LYrcFile.c
+++ b/src/LYrcFile.c
@@ -163,7 +163,7 @@ PUBLIC void read_rc ARGS1(FILE *, fp)
 	 *  Find the line position of the number sign if there is one.
 	 */
 	if ((cp = (char *)strchr(line_buffer, '#')) == NULL)
-	    number_sign = 999;
+	    number_sign = strlen(line_buffer) + 100;
 	else
 	    number_sign = cp - line_buffer;
 
diff --git a/src/TRSTable.c b/src/TRSTable.c
index d9ab4644..1037cf5f 100644
--- a/src/TRSTable.c
+++ b/src/TRSTable.c
@@ -28,34 +28,61 @@
 			      value means cell was reserved by ROWSPAN */
 #define EOCOLG (-2)	/* sumcols' Line field isn't used for line info, this
 			      special value means end of COLGROUP */
+#ifndef NO_AGRESSIVE_NEWROW
+#  define NO_AGRESSIVE_NEWROW	0
+#endif
+
 typedef enum {
-    CS_invalid = -1,
-    CS_new     =  0,
-    CS__0,			/* new, at BOL */
+    CS_invalid = -1,		/* cell "before the first",
+				   or empty lines after [ce]bc,
+				   or TRST aborted */
+    CS__0new   = 0,		/* starts at BOL, new */
+    CS__new,			/* new */
     CS__0eb,			/* starts at BOL, empty, break */
     CS__eb,			/* empty, break */
     CS__0cb,			/* starts at BOL, content, break */
     CS__cb,			/* content, break */
-    CS__0f,			/* starts at BOL, finished */
+    CS__0ef,			/* starts at BOL, empty, finished */
     CS__ef,			/* empty, finished */
     CS__0cf,			/* starts at BOL, content, finished */
     CS__cf,			/* content, finished */
-    CS__ebc,			/* empty, break, more content */
-    CS__cbc			/* content, break, more content */
+    CS__ebc,			/* empty, break, more content (maybe @BOL) */
+    CS__cbc			/* content, break, more content (maybe @BOL) */
 } cellstate_t;
 
+const char * const cellstate_s[] = {	/* Should be indexed by cellstate+1 */
+    "CS_invalid",
+    "CS__new",
+    "CS__0new",
+    "CS__0eb",
+    "CS__eb",
+    "CS__0cb",
+    "CS__cb",
+    "CS__0ef",
+    "CS__ef",
+    "CS__0cf",
+    "CS__cf",
+    "CS__ebc",
+    "CS__cbc"
+};
+
 typedef struct _STable_states {
-    cellstate_t	prev_state;
-    cellstate_t	state;
-    int		lineno;		/* last line no. looked at */
-    int		icell_core;	/* first/best 'core' cell in row so far */
-    int		x_td;		/* x pos of currently open cell or -1 */
-    int		pending_len;	/* if state is CS__0?[ec]b (??) */
+    cellstate_t	prev_state;	/* Contents type of the previous cell */
+    cellstate_t	state;		/* Contents type of the worked-on cell */
+    int		lineno;		/* Start line of the current cell */
+    int		icell_core;	/* -1 or the 1st cell with <BR></TD> on row */
+    int		x_td;		/* x start pos of the current cell or -1 */
+    int		pending_len;	/* For multiline cells, the length of
+				   the part on the first line (if
+				   state is CS__0?[ec]b) (??), or 0 */
 } STable_states;
 
 
 typedef struct _STable_cellinfo {
-	int	Line;		/* lineno in doc (zero-based) */
+	int	cLine;		/* lineno in doc (zero-based): -1 for
+				   contentless cells (and cells we do
+				   not want to measure and count?),
+				   line-of-the-start otherwise.  */
 	int	pos;		/* column where cell starts */
 	int	len;		/* number of character positions */
 	int	colspan;	/* number of columns to span */
@@ -64,9 +91,33 @@ typedef struct _STable_cellinfo {
 } STable_cellinfo;
 
 typedef struct _STable_rowinfo {
+    /* Each row may be displayed on many display lines, but we fix up
+       positions of cells on this display line only: */
 	int	Line;		/* lineno in doc (zero-based) */
 	int	ncells;		/* number of table cells */
-/*	int	pending_skip;*/	/* skip this many after finishing open cell */
+
+    /* What is the meaning of this?!  It is set if:
+       [search for	def of fixed_line	below]
+
+       a1) a non-last cell is not at BOL,
+       a2) a non-last cell has something on the first line,
+       b) a >=3-lines-cell not at BOL, the first row non-empty, the 2nd empty;
+       c) a multiline cell not at BOL, the first row non-empty, the rest empty;
+       d) a multiline cell not at BOL, the first row non-empty;
+       e) a singleline non-empty cell not at BOL;
+
+       Summary: have seen a cell which is one of:
+       		(Notation: B: at BOL; L: last; E: the first row is non-empty)
+
+		bcde:	!B && !E
+		a1:	!L && !B
+		a2:	!L && !E
+
+       Or: has at least two of !B, !L, !E, or: has at most one of B,L,E.
+
+       REMARK: If this variable is not set, but icell_core is, Line is
+       reset to the line of icell_core.
+     */
 	BOOL	fixed_line;	/* if we have a 'core' line of cells */
 	int	allocated;	/* number of table cells allocated */
 	STable_cellinfo * cells;
@@ -74,6 +125,8 @@ typedef struct _STable_rowinfo {
 } STable_rowinfo;
 
 struct _STable_info {
+	struct _STable_info *enclosing;	/* The table which contain us */
+	struct _TextAnchor  *enclosing_last_anchor_before_stbl;
 	int	startline;	/* lineno where table starts (zero-based) */
 	int	nrows;		/* number of rows */
 	int	ncols;		/* number of rows */
@@ -143,7 +196,7 @@ struct _STable_info {
 PRIVATE int Stbl_finishCellInRow PARAMS((
     STable_rowinfo *	me,
     STable_states *	s,
-    BOOL		certain,
+    BOOL		end_td,
     int			lineno,
     int			pos));
 PRIVATE int Stbl_finishRowInTable PARAMS((
@@ -154,12 +207,15 @@ PUBLIC struct _STable_info * Stbl_startTABLE ARGS1(
     short,		alignment)
 {
     STable_info *me = typecalloc(STable_info);
+
+    CTRACE((tfp, "TRST:Stbl_startTABLE(align=%d)\n", (int)alignment));
     if (me) {
 	me->alignment = alignment;
 	me->rowgroup_align = HT_ALIGN_NONE;
 	me->pending_colgroup_align = HT_ALIGN_NONE;
 	me->s.x_td = -1;
 	me->s.icell_core = -1;
+	me->enclosing = 0;
     }
     return me;
 }
@@ -175,6 +231,7 @@ PRIVATE void free_rowinfo ARGS1(
 PUBLIC void Stbl_free ARGS1(
     STable_info *,	me)
 {
+    CTRACE((tfp, "TRST:Stbl_free()\n"));
     if (me && me->allocated_rows && me->rows) {
 	int i;
 	for (i = 0; i < me->allocated_rows; i++)
@@ -206,18 +263,24 @@ PRIVATE int Stbl_addCellToRow ARGS9(
     int last_colspan = me->ncells ?
 	me->cells[me->ncells - 1].colspan : 1;
     cellstate_t newstate;
+    int ret;
 
+    CTRACE((tfp, "TRST:Stbl_addCellToRow, line=%d, pos=%d, colspan=%d\n",
+	   lineno, *ppos, colspan));
+    CTRACE((tfp, " ncells=%d, stateLine=%d, pending_len=%d, pstate=%s, state=%s\n",
+	    me->ncells, s->lineno, s->pending_len,
+	    cellstate_s[s->prev_state+1], cellstate_s[s->state+1]));
     if (me->ncells == 0)
 	s->prev_state = CS_invalid;
     else if (s->prev_state == CS_invalid ||
-	     (/*s->state != CS_new && */ s->state != CS__0 &&
-	      s->state != CS__ef && s->state != CS__0f))
+	     (/*s->state != CS__new && */ s->state != CS__0new &&
+	      s->state != CS__ef && s->state != CS__0ef))
 	s->prev_state = s->state;
 
     if (me->ncells == 0 || *ppos == 0)
-	newstate = CS__0;
+	newstate = CS__0new;
     else
-	newstate = CS_new;
+	newstate = CS__new;
 
     if (me->ncells > 0 && s->pending_len > 0) {
 	if (s->prev_state != CS__cbc)
@@ -231,21 +294,21 @@ PRIVATE int Stbl_addCellToRow ARGS9(
 	    if (me->ncells == 0 || *ppos == 0) {
 		switch (s->prev_state) {
 		case CS_invalid:
-		case CS__0:
+		case CS__0new:
 		case CS__0eb:
 		case CS__0cb:
-		case CS__0f:
+		case CS__0ef:
 		case CS__0cf:
 		    if (me->ncells > 0)
 			for (i = me->ncells + last_colspan - 2;
 			     i >= me->ncells - 1; i--) {
 			    me->cells[i].pos = *ppos;
-			    me->cells[i].Line = lineno;
+			    me->cells[i].cLine = lineno;
 			}
 		    me->Line = lineno;
 		    /* s->lineno = lineno; */
 		    break;
-		case CS_new:
+		case CS__new:
 		case CS__eb:
 		case CS__ef:
 		case CS__cf:
@@ -255,31 +318,32 @@ PRIVATE int Stbl_addCellToRow ARGS9(
 		    *ppos = me->cells[me->ncells - 1].pos +
 			me->cells[me->ncells - 1].len;
 		}
-	    } else {
+	    } else {	/* last cell multiline, ncells != 0, pos != 0 */
 		switch (s->prev_state) {
-		case CS__0:
+		case CS__0new:
 		case CS__0eb:
-		case CS__0f:
+		case CS__0ef:
+		    /* Do not fail, but do not set fixed_line either */
 		    break;
 		case CS__cb:
-		    return -1;
+		    goto trace_and_fail;
 		case CS__cf:
 /*		    HTAlert("foo woo!!"); */
-		    return -1;
+		    goto trace_and_fail;
 		case CS__0cb:
 		case CS__0cf:
 		    if (*ppos > me->cells[0].pos)
 			me->Line = lineno;
-		    me->fixed_line = YES;
+		    me->fixed_line = YES; /* type=a def of fixed_line i */
 		    break;
-		case CS_new:
+		case CS__new:
 		case CS__eb:
 		case CS__ef:
 		default:
-		    me->fixed_line = YES;
+		    me->fixed_line = YES; /* type=e def of fixed_line ii */
 		    break;
 		case CS__cbc:
-		    return -1;
+		    goto trace_and_fail;
 		}
 	    }
 	}
@@ -288,7 +352,7 @@ PRIVATE int Stbl_addCellToRow ARGS9(
 	    case CS__cb:
 	    case CS__cf:
 		if (*ppos > 0)
-		    return -1;
+		    goto trace_and_fail;
 		else
 		    *ppos = me->cells[me->ncells - 1].pos /* == 0 */ +
 			me->cells[me->ncells - 1].len;
@@ -299,12 +363,12 @@ PRIVATE int Stbl_addCellToRow ARGS9(
 		    *ppos = me->cells[me->ncells - 1].pos /* == 0 */ +
 			me->cells[me->ncells - 1].len;
 		break;
-	    case CS__0:
-	    case CS__0f:
+	    case CS__0new:
+	    case CS__0ef:
 	    case CS__0eb:
 /*		me->Line = lineno; */
 		break;
-	    case CS_new:
+	    case CS__new:
 	    case CS__eb:
 	    case CS__ef:
 	    default:
@@ -323,10 +387,10 @@ PRIVATE int Stbl_addCellToRow ARGS9(
     } else {			/* lineno == s->lineno: */
 	switch (s->prev_state) {
 	case CS_invalid:
-	case CS__0:
+	case CS__0new:
 	case CS__0eb:		/* cannot happen */
 	case CS__0cb:		/* cannot happen */
-	case CS__0f:
+	case CS__0ef:
 	case CS__0cf:		/* ##302?? set icell_core? or only in finish? */
 	    break;
 	case CS__eb:		/* cannot happen */
@@ -336,10 +400,10 @@ PRIVATE int Stbl_addCellToRow ARGS9(
 	case CS__ebc:		/* should have done smth in finish */
 	case CS__cbc:		/* should have done smth in finish */
 	    break;
-	case CS_new:
+	case CS__new:
 	case CS__cf:
 	    if (me->fixed_line && me->Line != lineno) {
-		return -1;
+		goto trace_and_fail;
 	    } else {
 		me->fixed_line = YES;
 		me->Line = lineno;
@@ -356,10 +420,10 @@ PRIVATE int Stbl_addCellToRow ARGS9(
 		    for (i = me->ncells + last_colspan - 2;
 			 i >= 0; i--) {
 			me->cells[i].pos = *ppos;
-			me->cells[i].Line = lineno;
+			me->cells[i].cLine = lineno;
 		    }
 		me->Line = lineno;
-		s->state = CS__0;
+		s->state = CS__0new;
 	    }
 	    if (*ppos > 0 && me->ncells > 0 &&
 		(me->cells[me->ncells - 1].pos > 0 ||
@@ -371,7 +435,7 @@ PRIVATE int Stbl_addCellToRow ARGS9(
 	if (me->fixed_line && lineno != me->Line) {
 	    if (me->cells[me->ncells - 1].pos > 0 &&
 		me->cells[me->ncells - 1].len > 0) {
-		return -1;
+		goto trace_and_fail;
 	    } else if (me->cells[me->ncells - 1].pos == 0 &&
 		       me->cells[me->ncells - 1].len > 0) {
 		if (*ppos > 0 && *ppos > me->cells[0].pos)
@@ -387,16 +451,16 @@ PRIVATE int Stbl_addCellToRow ARGS9(
 	}
 #if 0
 	for (i = 0; i < me->ncells; i++) {
-	    if (me->cells[i].Line == lineno) {
+	    if (me->cells[i].cLine == lineno) {
 		break;
 	    } else if (me->cells[i].len <= 0) {
-		me->cells[i].Line = lineno;
+		me->cells[i].cLine = lineno;
 		/* @@@ reset its pos too ?? */
 	    } else {
 		break;
 	    }
 	}
-	if (i < me->ncells && me->cells[i].Line != lineno)
+	if (i < me->ncells && me->cells[i].cLine != lineno)
 	    return -1;
 	me->Line = lineno;
 #endif
@@ -430,12 +494,12 @@ PRIVATE int Stbl_addCellToRow ARGS9(
 		me->allocated += growby;
 		me->cells = cells;
 	    } else {
-		return -1;
+		goto trace_and_fail;
 	    }
 	}
     }
 
-    me->cells[me->ncells].Line = lineno;
+    me->cells[me->ncells].cLine = lineno;
     me->cells[me->ncells].pos = *ppos;
     me->cells[me->ncells].len = -1;
     me->cells[me->ncells].colspan = colspan;
@@ -453,7 +517,7 @@ PRIVATE int Stbl_addCellToRow ARGS9(
 	    me->cells[me->ncells].alignment = isheader ? HT_CENTER : HT_LEFT;
     }
     for (i = me->ncells + 1; i < me->ncells + colspan; i++) {
-	me->cells[i].Line = lineno;
+	me->cells[i].cLine = lineno;
 	me->cells[i].pos = *ppos;
 	me->cells[i].len = -1;
 	me->cells[i].colspan = 0;
@@ -461,7 +525,16 @@ PRIVATE int Stbl_addCellToRow ARGS9(
     }
     me->cells[me->ncells + colspan].pos = -1; /* not yet used */
     me->ncells++;
-    return (me->ncells - 1);
+
+    ret = me->ncells - 1;
+  trace_and_return:
+    CTRACE((tfp, " => prev_state=%s, state=%s, ret=%d\n",
+	    cellstate_s[s->prev_state+1], cellstate_s[s->state+1], ret));
+    return (ret);
+
+  trace_and_fail:
+    ret = -1;
+    goto trace_and_return;
 }
 
 /* returns -1 on error, 0 otherwise */
@@ -474,6 +547,9 @@ PRIVATE int Stbl_reserveCellsInRow ARGS3(
     STable_cellinfo *cells;
     int i;
     int growby = icell + colspan - me->allocated;
+
+    CTRACE((tfp, "TRST:Stbl_reserveCellsInRow(icell=%d, colspan=%d\n",
+	   icell, colspan));
     if (growby > 0) {
 	cells = realloc(me->cells,
 			(me->allocated + growby)
@@ -489,7 +565,7 @@ PRIVATE int Stbl_reserveCellsInRow ARGS3(
 	}
     }
     for (i = icell; i < icell + colspan; i++) {
-	me->cells[i].Line = -1;
+	me->cells[i].cLine = -1;
 	me->cells[i].pos = -1;
 	me->cells[i].len = -1;
 	me->cells[i].colspan = 0;
@@ -499,29 +575,39 @@ PRIVATE int Stbl_reserveCellsInRow ARGS3(
     return 0;
 }
 
+/* Returns -1 on failure. */
 PRIVATE int Stbl_finishCellInRow ARGS5(
     STable_rowinfo *,	me,
     STable_states *,	s,
-    BOOL,		certain,
+    BOOL,		end_td,
     int,		lineno,
     int,		pos)
 {
     STable_cellinfo *lastcell;
     cellstate_t newstate = CS_invalid;
-    BOOL broken = NO, empty;
+    BOOL multiline = NO, empty;
+    int ret;
+
+    CTRACE((tfp, "TRST:Stbl_finishCellInRow line=%d pos=%d end_td=%d ncells=%d pnd_len=%d\n",
+	   lineno, pos, (int)end_td, me->ncells, s->pending_len));
 
     if (me->ncells <= 0)
 	return -1;
     lastcell = me->cells + (me->ncells - 1);
-    broken = (lineno != lastcell->Line || lineno != s->lineno);
-    empty = broken ? (pos == 0) : (pos <= s->x_td);
-    if (broken) {
-	if (!certain) {
+    multiline = (lineno != lastcell->cLine || lineno != s->lineno);
+    empty = multiline ? (pos == 0) : (pos <= s->x_td);
+
+    CTRACE((tfp, " [lines: lastCell=%d state=%d multi=%d] empty=%d (prev)state=(%s) %s\n",
+	   lastcell->cLine, s->lineno, multiline, empty,
+	    cellstate_s[s->prev_state+1], cellstate_s[s->state+1]));
+
+    if (multiline) {
+	if (!end_td) {			/* processing line-break */
 	    switch (s->state) {
 	    case CS_invalid:
 		newstate = empty ? CS_invalid : CS__cbc;
 		break;
-	    case CS__0:
+	    case CS__0new:
 		newstate = empty ? CS__0eb : CS__0cb;
 		break;
 	    case CS__0eb:
@@ -529,38 +615,39 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
 		s->state = newstate;
 		if (me->fixed_line) {
 		    if (empty)
-			return lastcell->len <= 0 ? 0 : lastcell->len;
+			ret = (lastcell->len <= 0 ? 0 : lastcell->len);
 		    else
-			return lastcell->len <= 0 ? 0 : -1;
+			ret = (lastcell->len <= 0 ? 0 : -1);
 		} else {
 		    if (empty)
-			return lastcell->len <= 0 ? 0 : lastcell->len;
+			ret = (lastcell->len <= 0 ? 0 : lastcell->len);
 		    else
-			return lastcell->len <= 0 ? 0 : 0;
+			ret = (lastcell->len <= 0 ? 0 : 0);
 		}
+		goto trace_and_return;
 	    case CS__0cb:
 		if (!me->fixed_line) {
 		    if (empty) { /* ##462_return_0 */
 /*			if (s->icell_core == -1)
-			    s->icell_core = lastcell->Line; */ /* we don't know yet */
-			/* lastcell->Line = lineno; */
+			    s->icell_core = lastcell->cLine; */ /* we don't know yet */
+			/* lastcell->cLine = lineno; */
 		    } else {	/* !empty */
 			if (s->icell_core == -1)
 			    me->Line = -1;
 		    }
 		}
-		if (s->pending_len && empty) { /* ##470_why_that?? */
-		    if ((me->fixed_line && me->Line == lastcell->Line) ||
+		if (s->pending_len && empty) { /* First line non-empty */
+		    if ((me->fixed_line && me->Line == lastcell->cLine) ||
 			s->icell_core == me->ncells - 1)
 			lastcell->len = s->pending_len;
 		    s->pending_len = 0;
 		} /* @@@ for empty do smth. about ->Line / ->icell_core !! */
 		newstate = empty ? CS__0cb : CS__cbc; /* ##474_needs_len!=-1? */
 		break;
-	    case CS__0f:
+	    case CS__0ef:
 	    case CS__0cf:
 		break;
-	    case CS_new:
+	    case CS__new:
 		newstate = empty ? CS__eb : CS__cb;
 		break;
 	    case CS__eb:	/* ##484_set_pending_ret_0_if_empty? */
@@ -568,42 +655,46 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
 		s->state = newstate;
 		if (me->fixed_line) {
 		    if (empty)
-			return lastcell->len <= 0 ? 0 : lastcell->len;
+			ret = (lastcell->len <= 0 ? 0 : lastcell->len);
 		    else
-			return lastcell->len <= 0 ? 0 : -1;
+			ret = (lastcell->len <= 0 ? 0 : -1);
 		} else {
 		    if (empty)
-			return lastcell->len <= 0 ? 0 : lastcell->len;
+			ret = (lastcell->len <= 0 ? 0 : lastcell->len);
 		    else
-			return lastcell->len <= 0 ? 0 : -1;
+			ret = (lastcell->len <= 0 ? 0 : -1);
 		}
+		goto trace_and_return;
 	    case CS__cb:
 		if (s->pending_len && empty) { /* ##496: */
 		    lastcell->len = s->pending_len;
 		    s->pending_len = 0;
 		} /* @@@ for empty do smth. about ->Line / ->icell_core !! */
+		ret = -1;
 		if (empty) {
 		    if (!me->fixed_line) {
-			me->fixed_line = YES;
-			me->Line = lastcell->Line; /* should've happened in break */
+			me->fixed_line = YES; /* type=b def of fixed_line i */
+			me->Line = lastcell->cLine; /* should've happened in break */
 		    } else {
-			if (me->Line != lastcell->Line)
-			    return -1;
+			if (me->Line != lastcell->cLine)
+			    goto trace_and_return;
 		    }
 		} else {
 		    if (!me->fixed_line) {
-			me->fixed_line = YES;
-			me->Line = lastcell->Line; /* should've happened in break */
+			me->fixed_line = YES; /* type=b def of fixed_line ii */
+			me->Line = lastcell->cLine; /* should've happened in break */
 		    }
 		    s->state = CS__cbc;
-		    return -1;
+		    goto trace_and_return;
 		}
 		newstate = empty ? CS__cb : CS__cbc;
 		break;
 	    case CS__ef:
-		return 0;
+		ret = 0;
+		goto trace_and_return;
 	    case CS__cf:
-		return lastcell->len; /* ##523_change_state? */
+		ret = lastcell->len; /* ##523_change_state? */
+		goto trace_and_return;
 	    case CS__cbc:
 		if (!me->fixed_line) {
 		    if (empty) {
@@ -621,7 +712,7 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
 	    default:
 		break;
 	    }
-	} else {		/* broken, certain: */
+	} else {		/* multiline cell, processing </TD>: */
 	    s->x_td = -1;
 	    switch (s->state) {
 	    case CS_invalid:
@@ -629,29 +720,31 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
 		if (!empty && lastcell->len > 0) {
 		    newstate = CS__0cf;
 		    s->state = newstate;
-		    return -1;
+		    ret = -1;
+		    goto trace_and_return;
 		}
 				/* ##541_set_len_0_Line_-1_sometimes: */
 		lastcell->len = 0;
-		lastcell->Line = -1;
+		lastcell->cLine = -1;
 		 /* fall thru ##546 really fall thru??: */
 		newstate = empty ? CS_invalid : CS__cbc;	break;
-	    case CS__0:
-		newstate = empty ? CS__0f  : CS__0cf;	break;
+	    case CS__0new:
+		newstate = empty ? CS__0ef  : CS__0cf;	break;
 	    case CS__0eb:
-		newstate = empty ? CS__0f  : CS__0cf;		/* ebc?? */
+		newstate = empty ? CS__0ef  : CS__0cf;		/* ebc?? */
 		s->state = newstate;
 		if (me->fixed_line) {
 		    if (empty)
-			return lastcell->len <= 0 ? 0 : lastcell->len;
+			ret = (lastcell->len <= 0 ? 0 : lastcell->len);
 		    else
-			return lastcell->len <= 0 ? 0 : -1;
+			ret = (lastcell->len <= 0 ? 0 : -1);
 		} else {
 		    if (empty)
-			return lastcell->len <= 0 ? 0 : lastcell->len;
+			ret = (lastcell->len <= 0 ? 0 : lastcell->len);
 		    else
-			return lastcell->len <= 0 ? 0 : 0;
+			ret = (lastcell->len <= 0 ? 0 : 0);
 		}
+		goto trace_and_return;
 	    case CS__0cb:
 		if (s->pending_len) {
 		    if (empty)
@@ -663,8 +756,9 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
 		if (!me->fixed_line) {
 		    if (empty) {
 			if (s->icell_core == -1)
+			    /* first cell before <BR></TD> => the core cell */
 			    s->icell_core = me->ncells - 1;
-			/* lastcell->Line = lineno; */
+			/* lastcell->cLine = lineno; */
 		    } else {	/* !empty */
 			if (s->icell_core == -1)
 			    me->Line = -1;
@@ -675,42 +769,44 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
 		    s->pending_len = 0;
 		} /* @@@ for empty do smth. about ->Line / ->icell_core !! */
 		newstate = empty ? CS__0cf : CS__cbc;	break;
-	    case CS__0f:
-		newstate = CS__0f;
+	    case CS__0ef:
+		newstate = CS__0ef;
 		/* FALLTHRU */
 	    case CS__0cf:
 		break;
-	    case CS_new:
+	    case CS__new:
 		newstate = empty ? CS__ef  : CS__cf;	break;
 	    case CS__eb:
 		newstate = empty ? CS__ef  : CS__ef; /* ##579??? !!!!! */
 		s->state = newstate;
 		if (me->fixed_line) {
 		    if (empty)
-			return lastcell->len <= 0 ? 0 : lastcell->len;
+			ret = (lastcell->len <= 0 ? 0 : lastcell->len);
 		    else
-			return lastcell->len <= 0 ? 0 : -1;
+			ret = (lastcell->len <= 0 ? 0 : -1);
 		} else {
 		    if (empty)
-			return lastcell->len <= 0 ? 0 : lastcell->len;
+			ret = (lastcell->len <= 0 ? 0 : lastcell->len);
 		    else
-			return lastcell->len <= 0 ? 0 : -1;
+			ret = (lastcell->len <= 0 ? 0 : -1);
 		}
+		goto trace_and_return;
 	    case CS__cb:
 		if (s->pending_len && empty) {
 		    lastcell->len = s->pending_len;
 		    s->pending_len = 0;
 		}
+		ret = -1;
 		if (empty) {
 		    if (!me->fixed_line) {
-			me->fixed_line = YES;
-			me->Line = lastcell->Line; /* should've happened in break */
+			me->fixed_line = YES; /* type=c def of fixed_line */
+			me->Line = lastcell->cLine; /* should've happened in break */
 		    } else {
-			if (me->Line != lastcell->Line)
-			    return -1;
+			if (me->Line != lastcell->cLine)
+			    goto trace_and_return;
 		    }
 		} else {
-		    return -1;
+		    goto trace_and_return;
 		}
 		newstate = empty ? CS__cf  : CS__cbc;	break;
 	    case CS__ef:		/* ignored error */
@@ -721,15 +817,16 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
 		if (!me->fixed_line) {
 		    if (!empty) {
 			if (s->icell_core == -1)
-			    lastcell->Line = -1;
+			    lastcell->cLine = -1;
 		    }
 		}
 		s->pending_len = 0;
 		newstate = empty ? CS_invalid : CS__cbc;	break;
 	    case CS__cbc:	/* ##586 */
 		lastcell->len = 0; /* ##613 */
-		if (me->fixed_line && me->Line == lastcell->Line)
-		    return -1;
+		ret = -1;
+		if (me->fixed_line && me->Line == lastcell->cLine)
+		    goto trace_and_return;
 		if (!me->fixed_line) {
 		    if (empty) {
 			if (s->icell_core == -1)
@@ -746,93 +843,102 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
 		newstate = empty ? CS_invalid : CS__cbc;	break;
 	    }
 	}
-    } else {			/* (!broken) */
-	if (!certain) {
+    } else {				/* (!multiline) */
+	if (!end_td) {			/* processing line-break */
 	    switch (s->state) {
 	    case CS_invalid:
-	    case CS__0:
+	    case CS__0new:
 		s->pending_len = empty ? 0 : pos - lastcell->pos;
 		newstate = empty ? CS__0eb : CS__0cb;
 		s->state = newstate;
-		return 0; /* or 0 for xlen to s->pending_len?? */
+		ret = 0; /* or 0 for xlen to s->pending_len?? */
+		goto trace_and_return;
 	    case CS__0eb:	/* cannot happen */
 		newstate = CS__eb;
 		break;
 	    case CS__0cb:	/* cannot happen */
 		newstate = CS__cb;
 		break;
-	    case CS__0f:
+	    case CS__0ef:
 	    case CS__0cf:
 		break;
-	    case CS_new:
+	    case CS__new:
+		ret = -1;
 		if (!empty && s->prev_state == CS__cbc)	/* ##609: */
-		    return -1;
+		    goto trace_and_return;
 		if (!empty) {
 		    if (!me->fixed_line) {
-			me->fixed_line = YES;
+			me->fixed_line = YES; /* type=d def of fixed_line */
 			me->Line = lineno;
 		    } else {
 			if (me->Line != lineno)
-			    return -1;
+			    goto trace_and_return;
 		    }
 		}
 		newstate = empty ? CS__eb : CS__cb;
 		s->state = newstate;
 		if (!me->fixed_line) {
 		    s->pending_len = empty ? 0 : pos - lastcell->pos;
-		    return 0;
+		    ret = 0;
+		    goto trace_and_return;
 		} else {
 		    s->pending_len = 0;
 		    lastcell->len = empty ? 0 : pos - lastcell->pos;
-		    return lastcell->len;
+		    ret = lastcell->len;
+		    goto trace_and_return;
 		}
 	    case CS__eb:	/* cannot happen */
 		newstate = empty ? CS__eb : CS__ebc;	break;
 	    case CS__cb:	/* cannot happen */
 		newstate = empty ? CS__cb : CS__cbc;	break;
 	    case CS__ef:
-		return 0;
+		ret = 0;
+		goto trace_and_return;
 	    case CS__cf:
-		return lastcell->len;
+		ret = lastcell->len;
+		goto trace_and_return;
 	    case CS__cbc:	/* ??? */
 		break;
 	    default:
 		break;
 	    }
-	} else {		/* !broken, certain: */
+	} else {		/* !multiline, processing </TD>: */
 	    s->x_td = -1;
 	    switch (s->state) {
 	    case CS_invalid:	/* ##691_no_lastcell_len_for_invalid: */
-		if (!(me->fixed_line && me->Line == lastcell->Line))
+		if (!(me->fixed_line && me->Line == lastcell->cLine))
 		    lastcell->len = 0;
 		/* FALLTHRU */
-	    case CS__0:
-		newstate = empty ? CS__0f  : CS__0cf;	break; /* ##630 */
+	    case CS__0new:
+		newstate = empty ? CS__0ef  : CS__0cf;	break; /* ##630 */
 	    case CS__0eb:
-		newstate = empty ? CS__0f : CS__0f;	break; /* ??? */
+		newstate = empty ? CS__0ef : CS__0ef;	break; /* ??? */
 	    case CS__0cb:
 		newstate = empty ? CS__0cf : CS__cbc;	break; /* ??? */
-	    case CS__0f:
-		newstate = CS__0f;			break; /* ??? */
+	    case CS__0ef:
+		newstate = CS__0ef;			break; /* ??? */
 	    case CS__0cf:
 		break;		/* ??? */
-	    case CS_new:
+	    case CS__new:
+		ret = -1;
 		if (!empty && s->prev_state == CS__cbc)
-		    return -1;
+		    goto trace_and_return;
 		if (!empty) { /* ##642_set_fixed!: */
 		    if (!me->fixed_line) {
-			me->fixed_line = YES;
+			me->fixed_line = YES; /* type=e def of fixed_line */
 			me->Line = lineno;
 		    } else {
 			if (me->Line != lineno)
-			    return -1;
+			    goto trace_and_return;
 		    }
 		}
 		if (lastcell->len < 0)
 		    lastcell->len = empty ? 0 : pos - lastcell->pos;
 		newstate = empty ? CS__ef  : CS__cf;
 		s->state = newstate;
-		return (me->fixed_line && lineno != me->Line) ? -1 : lastcell->len;
+		ret = ((me->fixed_line && lineno != me->Line)
+		       ? -1 : lastcell->len);
+		goto trace_and_return;
 	    case CS__eb:
 		newstate = empty ? CS__ef  : CS__cf;	break; /* ??? */
 	    case CS__cb:
@@ -843,11 +949,11 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
 		break;
 	    }
 	    lastcell->len = pos - lastcell->pos;
-	} /* if (!certain) ... else */
-    } /* if (broken) ... else */
+	} /* if (!end_td) ... else */
+    } /* if (multiline) ... else */
 
 #if 0				/* MEGA_COMMENTOUT */
-    if (lineno != me->cells[0].Line) {
+    if (lineno != me->cells[0].cLine) {
 #if 0
 	int i;
 	for (i = ncells - 1; i >= 0; i--) {
@@ -855,7 +961,7 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
 		break;
 	}
 #endif
-	if (lineno >= lastcell->Line) {
+	if (lineno >= lastcell->cLine) {
 	    if (me->fixed_line) {
 		if (pos == 0) {
 		    if (lastcell->len <= 0) {
@@ -864,7 +970,7 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
 			return lastcell->len;
 		    }
 		} else {	/* pos != 0 */
-		    if (lastcell->len <= 0 && lineno > lastcell->Line && lastcell->Line <= me->Line) {
+		    if (lastcell->len <= 0 && lineno > lastcell->cLine && lastcell->cLine <= me->Line) {
 			return 0;
 		    } else {
 			return -1;
@@ -892,8 +998,15 @@ PRIVATE int Stbl_finishCellInRow ARGS5(
     }
 #endif /* MEGA_COMMENTOUT */
     s->state = newstate;
+    ret = lastcell->len;
+    if (ret == -1 && pos == 0)
+	ret = 0; /* XXXX Hack to allow trailing <P> in multiline cells. */
+
 /*    lastcell->len = pos - lastcell->pos; */
-    return (lastcell->len);
+  trace_and_return:
+    CTRACE((tfp, " => prev_state=%s, state=%s, return=%d\n",
+	    cellstate_s[s->prev_state+1], cellstate_s[s->state+1], ret));
+    return ret;
 }
 
 /*
@@ -914,6 +1027,8 @@ PRIVATE int Stbl_reserveCellsInTable ARGS4(
     if (me->nrows <= 0)
 	return -1;		/* must already have at least one row */
 
+    CTRACE((tfp, "TRST:Stbl_reserveCellsInTable(icell=%d, colspan=%d, rowspan=%d)\n",
+	   icell, colspan, rowspan));
     if (rowspan == 0) {
 	if (!me->rowspans2eog.cells) {
 	    me->rowspans2eog.cells = typecallocn(STable_cellinfo, icell + colspan);
@@ -974,6 +1089,7 @@ PRIVATE void Stbl_cancelRowSpans ARGS1(
     STable_info *,	me)
 {
     int i;
+    CTRACE((tfp, "TRST:Stbl_cancelRowSpans()"));
     for (i = me->nrows; i < me->allocated_rows; i++) {
 	if (!me->rows[i].ncells) { /* should always be the case */
 	    FREE(me->rows[i].cells);
@@ -994,12 +1110,15 @@ PUBLIC int Stbl_addRowToTable ARGS3(
 {
     STable_rowinfo *rows, *row;
     STable_states * s = &me->s;
+
+    CTRACE((tfp, "TRST:Stbl_addRowToTable(alignment=%d, lineno=%d)\n",
+	   alignment, lineno));
     if (me->nrows > 0 && me->rows[me->nrows-1].ncells > 0) {
 	if (s->pending_len > 0)
 	    me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].len = s->pending_len;
 	s->pending_len = 0;
 /*	if (me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].len >= 0 &&
-	    me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].Line == lineno)
+	    me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].cLine == lineno)
 	    Stbl_finishCellInTable(me, YES,
 				   lineno,
 		me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].pos +
@@ -1086,6 +1205,8 @@ PRIVATE int Stbl_finishRowInTable ARGS1(
     STable_rowinfo *lastrow;
     STable_states * s = &me->s;
     int ncells;
+
+    CTRACE((tfp, "TRST:Stbl_finishRowInTable()\n"));
     if (!me->rows || !me->nrows)
 	return -1;		/* no row started! */
     lastrow = me->rows + (me->nrows - 1);
@@ -1102,8 +1223,8 @@ PRIVATE int Stbl_finishRowInTable ARGS1(
     if (lastrow->Line == -1 && s->icell_core >= 0)
 #endif
     if (s->icell_core >= 0 && !lastrow->fixed_line &&
-	lastrow->cells[s->icell_core].Line >= 0)
-	lastrow->Line = lastrow->cells[s->icell_core].Line;
+	lastrow->cells[s->icell_core].cLine >= 0)
+	lastrow->Line = lastrow->cells[s->icell_core].cLine;
     s->icell_core = -1;
     return (me->nrows);
 }
@@ -1169,13 +1290,162 @@ PRIVATE int get_remaining_colspan ARGS5(
 			ncols_sofar - (me->ncells + last_colspan - 1));
     } else {
 	for (i = me->ncells + last_colspan - 1; i < ncolinfo - 1; i++)
-	    if (colinfo[i].Line == EOCOLG)
+	    if (colinfo[i].cLine == EOCOLG)
 		break;
 	colspan = i - (me->ncells + last_colspan - 2);
     }
     return colspan;
 }
 
+/* Returns -1 on failure, 1 if faking was performed, 0 if not needed. */
+PRIVATE int Stbl_fakeFinishCellInTable ARGS4(
+    STable_info *,	me,
+    STable_rowinfo *,	lastrow,
+    int,		lineno,
+    int,		finishing)	/* Processing finish or start */
+{
+    STable_states * s = &me->s;
+    int fake = 0;
+
+    switch (s->state) {			/* We care only about trailing <BR> */
+    case CS_invalid:
+    case CS__0new:
+    case CS__0ef:
+    case CS__0cf:
+    case CS__new:
+    case CS__cbc:
+    case CS__ef:
+    case CS__cf:
+    default:
+	/* <BR></TD> may produce these (XXXX instead of CS__cbf?).  But if
+	   finishing==0, the caller already checked that we are on a
+	   different line.  */
+	if (finishing==0)
+	    fake = 1;
+	break;		/* Either can't happen, or may be ignored */
+    case CS__eb:
+    case CS__0eb:
+    case CS__0cb:
+    case CS__cb:
+	fake = 1;
+	break;
+    }
+    if (fake) {
+	/* The previous action we did was putting a linebreak.  Now we
+	   want to put another one.  Fake necessary
+	   </TD></TR><TR><TD></TD><TD> (and possibly </TD>) instead. */
+	int ncells = lastrow->ncells;
+	int i;
+	int al = lastrow->alignment;
+	int cs = lastrow->cells[lastrow->ncells - 1].colspan;
+	int rs = 1;			/* XXXX How to find rowspan? */
+	int ih = 0;			/* XXXX How to find is_header? */
+	int end_td = 1;
+	int need_reserved = 0;
+	int prev_reserved_last = -1;
+	STable_rowinfo *prev_row = lastrow;
+
+	CTRACE((tfp, "TRST:Stbl_fakeFinishCellInTable(lineno=%d, finishing=%d) START FAKING\n",
+		lineno, finishing));
+
+	/* Although here we use pos=0, this may commit the previous
+	   cell which had <BR> as a last element.  This may overflow
+	   the screen width, so the additional checks performed in
+	   Stbl_finishCellInTable (comparing to Stbl_finishCellInRow)
+	   are needed. */
+	if (finishing)
+	    /* Fake </TD> at BOL */
+	    if (Stbl_finishCellInTable(me, end_td, lineno, 0) < 0)
+		return -1;
+
+	/* Fake </TR> at BOL */
+	/* Stbl_finishCellInTable(lineno, 0, 0);*/ /* Needed? */
+
+	/* Fake <TR> at BOL */
+	if (Stbl_addRowToTable(me, al, lineno) < 0)
+	    return -1;
+	lastrow = me->rows + (me->nrows - 1);
+	for (i = 0; i < lastrow->allocated; i++)
+	    if (lastrow->cells[i].alignment == RESERVEDCELL) {
+		need_reserved = 1;
+		break;
+	    }
+	for (i = ncells; i < prev_row->allocated; i++)
+	    if (prev_row->cells[i].alignment == RESERVEDCELL)
+		prev_reserved_last = i;
+	if (need_reserved || prev_reserved_last >= 0) {
+	    /* Oups, we are going to stomp over a line which somebody
+	       cares about already, or the previous line had reserved
+	       cells which were not skipped over.
+
+	       Remember that STable_rowinfo is about logical (TR)
+	       table lines, not displayed lines.  We need to duplicate
+	       the reservation structure when we fake new logical lines.  */
+	    int prev_row_n = prev_row - me->rows;
+	    STable_rowinfo *rows = realloc(me->rows,
+					   (me->allocated_rows + 1)
+					   * sizeof(STable_rowinfo));
+	    int need_cells = prev_reserved_last + 1;
+
+	    if (!rows)
+		return -1; /* ignore silently, no free memory, may be recoverable */
+
+	    CTRACE((tfp, "TRST:Stbl_fakeFinishCellInTable REALLOC ROWSPAN\n"));
+	    me->rows = rows;
+	    lastrow = me->rows + (me->nrows - 1);
+	    prev_row = me->rows + prev_row_n;
+	    me->allocated_rows++;
+
+	    /* Insert a duplicate row after lastrow */
+	    memmove(lastrow+1, lastrow,
+		    sizeof(STable_rowinfo)*(me->allocated_rows - me->nrows));
+
+	    /* Ignore cells, they belong to the next row now */
+	    lastrow->allocated = 0;
+	    lastrow->cells = 0;
+	    if (need_cells) {
+		lastrow->cells = typecallocn(STable_cellinfo, need_cells);
+		/* ignore silently, no free memory, may be recoverable */
+		if (!lastrow->cells)
+		    return -1;
+		lastrow->allocated = need_cells;
+		memcpy(lastrow->cells, prev_row->cells,
+		       lastrow->allocated * sizeof(STable_cellinfo));
+
+		i = -1;
+		while (++i < ncells) {
+		    /* Stbl_addCellToTable grants RESERVEDCELL, but we do not
+		       want this action for fake cells.
+		       XXX Maybe always fake RESERVEDCELL instead of explicitly
+		       creating/destroying cells?  */
+		    if (lastrow->cells[i].alignment == RESERVEDCELL)
+			lastrow->cells[i].alignment = HT_LEFT;
+		}
+	    }
+	}
+
+	/* Fake <TD></TD>...<TD> (and maybe a </TD>) at BOL. */
+	CTRACE((tfp, "TRST:Stbl_fakeFinishCellInTable FAKE %d elts%s\n",
+		ncells, (finishing ? ", last unfinished" : "")));
+	i = 0;
+	while (++i <= ncells) {
+	    /* XXXX A lot of args may be wrong... */
+	    if (Stbl_addCellToTable(me, (i==ncells ? cs : 1), rs, al,
+				    ih, lineno, 0) < 0)
+		return -1;
+	    /* We cannot run out of width here, so it is safe to not
+	       call Stbl_finishCellInTable(), but Stbl_finishCellInRow. */
+	    if (!finishing || (i != ncells))
+		if (Stbl_finishCellInRow(lastrow, s, end_td, lineno, 0) < 0)
+		    return -1;
+	}
+	CTRACE((tfp, "TRST:Stbl_fakeFinishCellInTable(lineno=%d) FINISH FAKING\n",
+		lineno));
+	return 1;
+    }
+    return 0;
+}
+
 /*
  * Returns -1 on error, otherwise 0.
  */
@@ -1196,12 +1466,26 @@ PUBLIC int Stbl_addCellToTable ARGS7(
     int prevsumpos, advance;
 #endif
 
+    CTRACE((tfp, "TRST:Stbl_addCellToTable(lineno=%d, pos=%d, isheader=%d, cs=%d, rs=%d, al=%d)\n",
+	   lineno, pos, (int)isheader, colspan,rowspan,alignment));
     if (!me->rows || !me->nrows)
 	return -1;		/* no row started! */
 				/* ##850_fail_if_fail?? */
     Stbl_finishCellInTable(me, YES,
 			   lineno, pos);
     lastrow = me->rows + (me->nrows - 1);
+
+    /* If the last cell was finished by <BR></TD>, we need to fake an
+       appropriate amount of cells */
+    if (!NO_AGRESSIVE_NEWROW && pos == 0 && lastrow->ncells > 0
+	&& lastrow->cells[lastrow->ncells-1].cLine != lineno) {
+	int rc = Stbl_fakeFinishCellInTable(me, lastrow, lineno, 0);
+
+	if (rc < 0)
+	    return -1;
+	if (rc)
+	    lastrow = me->rows + (me->nrows - 1);
+    }
     if (colspan == 0) {
 	colspan = get_remaining_colspan(lastrow, me->sumcols, me->ncolinfo,
 					colspan, me->ncols);
@@ -1237,7 +1521,7 @@ PUBLIC int Stbl_addCellToTable ARGS7(
 		    sumcol->pos = sumcols[me->allocated_sumcols-1].pos;
 		    sumcol->len = 0;
 		    sumcol->colspan = 0;
-		    sumcol->Line = 0;
+		    sumcol->cLine = 0;
 		    sumcol->alignment = HT_ALIGN_NONE;
 		}
 	    }
@@ -1303,7 +1587,7 @@ PUBLIC int Stbl_addCellToTable ARGS7(
  */
 PUBLIC int Stbl_finishCellInTable ARGS4(
     STable_info *,	me,
-    BOOL,		certain,
+    BOOL,		end_td,
     int,		lineno,
     int,		pos)
 {
@@ -1311,6 +1595,9 @@ PUBLIC int Stbl_finishCellInTable ARGS4(
     STable_rowinfo *lastrow;
     int len, xlen, icell;
     int i;
+
+    CTRACE((tfp, "TRST:Stbl_finishCellInTable(lineno=%d, pos=%d, end_td=%d)\n",
+	   lineno, pos, (int)end_td));
     if (me->nrows == 0)
 	return -1;
     lastrow = me->rows + (me->nrows - 1);
@@ -1318,8 +1605,20 @@ PUBLIC int Stbl_finishCellInTable ARGS4(
     if (icell < 0)
 	return icell;
     if (s->x_td == -1)
-	return certain ? -1 : 0;
-    len = Stbl_finishCellInRow(lastrow, s, certain, lineno, pos);
+	return end_td ? -1 : 0;
+
+    /* This check for pos saves us from infinite recursion... */
+    if (!NO_AGRESSIVE_NEWROW && pos) {
+	int rc = Stbl_fakeFinishCellInTable(me, lastrow, lineno, 1);
+
+	if (rc) {
+	    if (rc < 0)
+		return -1;
+	    lastrow = me->rows + (me->nrows - 1);
+	    icell = lastrow->ncells - 1;
+	}
+    }
+    len = Stbl_finishCellInRow(lastrow, s, end_td, lineno, pos);
     if (len == -1)
 	return len;
     xlen = (len > 0) ? len : s->pending_len; /* ##890 use xlen if fixed_line?: */
@@ -1411,8 +1710,10 @@ PUBLIC int Stbl_finishCellInTable ARGS4(
     }
 #endif
 
+#if 0	/* maxlen may already include contribution of a cell in this column */
     if (me->maxlen + (xlen - len) > MAX_STBL_POS)
 	return -1;
+#endif
     if (me->maxpos > /* @@@ max. line length we can accept */ MAX_STBL_POS)
 	return -1;
 
@@ -1436,12 +1737,14 @@ PUBLIC int Stbl_addColInfo ARGS4(
     STable_cellinfo *sumcols, *sumcol;
     int i, icolinfo;
 
+    CTRACE((tfp, "TRST:Stbl_addColInfo(cs=%d, al=%d, isgroup=%d)\n",
+	   colspan, alignment, (int)isgroup));
     if (isgroup) {
 	if (me->pending_colgroup_next > me->ncolinfo)
 	    me->ncolinfo = me->pending_colgroup_next;
 	me->pending_colgroup_next = me->ncolinfo + colspan;
 	if (me->ncolinfo > 0)
-	    me->sumcols[me->ncolinfo -  1].Line = EOCOLG;
+	    me->sumcols[me->ncolinfo -  1].cLine = EOCOLG;
 	me->pending_colgroup_align = alignment;
     } else {
 	for (i = me->pending_colgroup_next - 1;
@@ -1469,7 +1772,7 @@ PUBLIC int Stbl_addColInfo ARGS4(
 		    sumcol->pos = sumcols[me->allocated_sumcols-1].pos;
 		    sumcol->len = 0;
 		    sumcol->colspan = 0;
-		    sumcol->Line = 0;
+		    sumcol->cLine = 0;
 		}
 	    }
 	    if (sumcols) {
@@ -1495,10 +1798,11 @@ PUBLIC int Stbl_addColInfo ARGS4(
 PUBLIC int Stbl_finishColGroup ARGS1(
     STable_info *,	me)
 {
+    CTRACE((tfp, "TRST:Stbl_finishColGroup()\n"));
     if (me->pending_colgroup_next >= me->ncolinfo) {
 	me->ncolinfo = me->pending_colgroup_next;
 	if (me->ncolinfo > 0)
-	    me->sumcols[me->ncolinfo -  1].Line = EOCOLG;
+	    me->sumcols[me->ncolinfo -  1].cLine = EOCOLG;
     }
     me->pending_colgroup_next = 0;
     me->pending_colgroup_align = HT_ALIGN_NONE;
@@ -1509,6 +1813,7 @@ PUBLIC int Stbl_addRowGroup ARGS2(
     STable_info *,	me,
     short,		alignment)
 {
+    CTRACE((tfp, "TRST:Stbl_addRowGroup()\n"));
     Stbl_cancelRowSpans(me);
     me->rowgroup_align = alignment;
     return 0;			/* that's all! */
@@ -1521,6 +1826,7 @@ PUBLIC int Stbl_finishTABLE ARGS1(
     int i;
     int curpos = 0;
 
+    CTRACE((tfp, "TRST:Stbl_finishTABLE()\n"));
     if (!me || me->nrows <= 0 || me->ncols <= 0) {
 	return -1;
     }
@@ -1530,7 +1836,7 @@ PUBLIC int Stbl_finishTABLE ARGS1(
 	s->pending_len = 0;
 /*	if (me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].len >= 0)
 	    Stbl_finishCellInTable(me, YES,
-		me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].Line,
+		me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].cLine,
 		me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].pos +
 		me->rows[me->nrows-1].cells[me->rows[me->nrows-1].ncells - 1].len); */
     }
@@ -1575,8 +1881,8 @@ PRIVATE int get_fixup_positions ARGS4(
 	return -1;
     while (i < me->ncells) {
 	next_i = i + HTMAX(1, me->cells[i].colspan);
-	if (me->cells[i].Line != me->Line) {
-	    if (me->cells[i].Line > me->Line)
+	if (me->cells[i].cLine != me->Line) {
+	    if (me->cells[i].cLine > me->Line)
 		break;
 	    i = next_i;
 	    continue;
@@ -1638,3 +1944,60 @@ PUBLIC int Stbl_getStartLine ARGS1(
     else
 	return me->startline;
 }
+
+PUBLIC void Stbl_update_enclosing ARGS3(
+    STable_info *,	me,
+    int,		max_width,
+    int,		last_lineno)
+{
+    int l;
+
+    if (!me || !me->enclosing || !max_width)
+	return;
+    CTRACE((tfp, "TRST:Stbl_update_enclosing, width=%d, lines=%d...%d.\n",
+	    max_width, me->startline, last_lineno));
+    for (l = me->startline; l <= last_lineno; l++)
+	/* Fake <BR> in appropriate positions */
+	if (Stbl_finishCellInTable(me->enclosing, 0, l, max_width) < 0) {
+	    /* It is not handy to let the caller delete me->enclosing,
+	       and it does not buy us anything.  Do it directly. */
+	    STable_info *stbl = me->enclosing;
+
+	    CTRACE((tfp, "TRST:Stbl_update_enclosing: width too large, aborting enclosing\n"));
+	    me->enclosing = 0;
+	    while (stbl) {
+		STable_info *enclosing = stbl->enclosing;
+		Stbl_free(stbl);
+		stbl = enclosing;
+	    }
+	    return;
+	}
+    return;
+}
+
+PUBLIC void Stbl_set_enclosing ARGS3(
+    STable_info *,	me,
+    STable_info *,	enclosing,
+    struct _TextAnchor*,enclosing_last_anchor_before_stbl)
+{
+    if (!me)
+	return;
+    me->enclosing = enclosing;
+    me->enclosing_last_anchor_before_stbl = enclosing_last_anchor_before_stbl;
+}
+
+PUBLIC STable_info * Stbl_get_enclosing ARGS1(
+    STable_info *,	me)
+{
+    if (!me)
+	return 0;
+    return me->enclosing;
+}
+
+PUBLIC struct _TextAnchor * Stbl_get_last_anchor_before ARGS1(
+    STable_info *,	me)
+{
+    if (!me)
+	return 0;
+    return me->enclosing_last_anchor_before_stbl;
+}
diff --git a/src/TRSTable.h b/src/TRSTable.h
index 927dd037..c89427b1 100644
--- a/src/TRSTable.h
+++ b/src/TRSTable.h
@@ -24,4 +24,15 @@ extern int Stbl_getFixupPositions PARAMS((
     int *		newpos));
 extern short Stbl_getAlignment PARAMS((STable_info *));
 
+extern void Stbl_update_enclosing PARAMS((
+    STable_info *	me,
+    int			max_width,
+    int			last_lineno));
+struct _TextAnchor;
+extern void Stbl_set_enclosing PARAMS(( STable_info *me,
+					STable_info *encl,
+					struct _TextAnchor *last_anchor));
+extern STable_info * Stbl_get_enclosing PARAMS((STable_info *	me));
+extern struct _TextAnchor * Stbl_get_last_anchor_before PARAMS((STable_info *	me));
+
 #endif /* TRSTABLE_H */
diff --git a/src/UCdomap.c b/src/UCdomap.c
index 95d126db..417b841c 100644
--- a/src/UCdomap.c
+++ b/src/UCdomap.c
@@ -30,13 +30,13 @@
 /*
  *  Include chartrans tables:
  */
-#include <cp1250_uni.h> 	/* WinLatin2 (cp1250)	*/
-#include <cp1251_uni.h> 	/* WinCyrillic (cp1251) */
-#include <cp1252_uni.h> 	/* WinLatin1 (cp1252)	*/
-#include <cp1253_uni.h> 	/* WinGreek (cp1253)	*/
-#include <cp1255_uni.h> 	/* WinHebrew (cp1255)	*/
-#include <cp1256_uni.h> 	/* WinArabic (cp1256)	*/
-#include <cp1257_uni.h> 	/* WinBaltRim (cp1257)	*/
+#include <cp1250_uni.h>		/* WinLatin2 (cp1250)	*/
+#include <cp1251_uni.h>		/* WinCyrillic (cp1251) */
+#include <cp1252_uni.h>		/* WinLatin1 (cp1252)	*/
+#include <cp1253_uni.h>		/* WinGreek (cp1253)	*/
+#include <cp1255_uni.h>		/* WinHebrew (cp1255)	*/
+#include <cp1256_uni.h>		/* WinArabic (cp1256)	*/
+#include <cp1257_uni.h>		/* WinBaltRim (cp1257)	*/
 #include <cp437_uni.h>		/* DosLatinUS (cp437)	*/
 #include <cp737_uni.h>		/* DosGreek (cp737)	*/
 #include <cp775_uni.h>		/* DosBaltRim (cp775)	*/
@@ -62,17 +62,27 @@
 #include <iso15_uni.h>		/* ISO 8859-15 (Latin 9)*/
 #include <koi8r_uni.h>		/* KOI8-R Cyrillic	*/
 #include <mac_uni.h>		/* Macintosh (8 bit)	*/
-#include <mnem2_suni.h> 	/* RFC 1345 Mnemonic	*/
+#include <mnem2_suni.h>		/* RFC 1345 Mnemonic	*/
 #include <next_uni.h>		/* NeXT character set	*/
 #include <rfc_suni.h>		/* RFC 1345 w/o Intro	*/
 /* #include <utf8_uni.h> */     /* UNICODE UTF 8        */
-#include <viscii_uni.h> 	/* Vietnamese (VISCII)	*/
+#include <viscii_uni.h>		/* Vietnamese (VISCII)	*/
 #include <cp866u_uni.h>		/* Ukrainian Cyrillic (866) */
 #include <koi8u_uni.h>		/* Ukrainian Cyrillic (koi8-u */
 #ifdef NOTDEFINED
 #include <mnem_suni.h>
 #endif /* NOTDEFINED */
 
+#ifdef CAN_AUTODETECT_DISPLAY_CHARSET
+int auto_display_charset = -1;
+#  ifdef __EMX__
+/* If we include <os2.h>, BOOLEAN conflicts.  Just copy the proto: */
+unsigned long DosQueryCp (unsigned long ulLength,
+			  unsigned long* pCodePageList,
+			  unsigned long* pDataLength);
+#  endif
+#endif
+
 /*
  *  Some of the code below, and some of the comments, are left in for
  *  historical reasons.  Not all those tables below are currently
@@ -608,7 +618,7 @@ PRIVATE int con_insert_unipair ARGS3(
 
 PRIVATE int con_insert_unipair_str ARGS3(
 	u16,		unicode,
-	CONST char *, 	replace_str,
+	CONST char *,	replace_str,
 	int,		fordefault)
 {
     int i, n;
@@ -1082,7 +1092,7 @@ PUBLIC int UCTransUniChar ARGS2(
  *  Returns string length, or negative value for error.
  */
 PUBLIC int UCTransUniCharStr ARGS5(
-	char *, 	outbuf,
+	char *,		outbuf,
 	int,		buflen,
 	long,		unicode,
 	int,		charset_out,
@@ -1379,7 +1389,7 @@ PUBLIC int UCReverseTransChar ARGS3(
  *  Returns string length, or negative value for error.
  */
 PUBLIC int UCTransCharStr ARGS6(
-	char *, 	outbuf,
+	char *,		outbuf,
 	int,		buflen,
 	char,		ch_in,
 	int,		charset_in,
@@ -2179,13 +2189,13 @@ PUBLIC void UCInit NOARGS
     UC_CHARSET_SETUP_cp437;		  /* DosLatinUS (cp437)   */
 
     UC_CHARSET_SETUP_dec_mcs;		  /* DEC Multinational	  */
-    UC_CHARSET_SETUP_macintosh; 	  /* Macintosh (8 bit)	  */
+    UC_CHARSET_SETUP_macintosh;		  /* Macintosh (8 bit)	  */
     UC_CHARSET_SETUP_next;		  /* NeXT character set   */
     UC_CHARSET_SETUP_hp_roman8;		  /* HP Roman8		  */
 
     UC_CHARSET_SETUP_euc_cn;		  /*** Chinese		    */
     UC_CHARSET_SETUP_euc_jp;		  /*** Japanese (EUC_JP)    */
-    UC_CHARSET_SETUP_shift_jis; 	  /*** Japanese (Shift_JIS) */
+    UC_CHARSET_SETUP_shift_jis;		  /*** Japanese (Shift_JIS) */
     UC_CHARSET_SETUP_euc_kr;		  /*** Korean		    */
     UC_CHARSET_SETUP_big5;		  /*** Taipei (Big5)	    */
 
@@ -2227,6 +2237,43 @@ PUBLIC void UCInit NOARGS
     UC_CHARSET_SETUP_mnem;
 #endif /* NOTDEFINED */
 
+#ifdef CAN_AUTODETECT_DISPLAY_CHARSET
+#  ifdef __EMX__
+    {
+	unsigned long lst[3];
+	unsigned long len;
+
+	if (DosQueryCp(sizeof(lst), lst, &len) == 0 && len >= 1) {
+	    static char lyName[80];
+	    static char myMimeName[80];
+	    char *mimeName;
+	    int s, i, exists = 0;
+
+	    sprintf(myMimeName, "auto-cp%lu", lst[0]);
+	    mimeName = myMimeName + 5;
+	    sprintf(lyName, "AutoDetect (cp%lu)", lst[0]);
+	    /* Find slot. */
+	    s = -1;
+	    for (i = 0; i < UCNumCharsets; i++) {
+		    if (!strcmp(UCInfo[i].LYNXname, lyName))
+			exists = 1;
+		    else if (!stricmp(UCInfo[i].MIMEname, mimeName))
+			s = i;
+	    }
+	    if (s >= 0 && !exists) {
+		/* Duplicate the record. */
+		UC_Charset_Setup(myMimeName, lyName,
+				 UCInfo[s].unicount, UCInfo[s].unitable,
+				 UCInfo[s].num_uni, UCInfo[s].replacedesc,
+				 UCInfo[s].lowest_eight, UCInfo[s].enc,
+				 UCInfo[s].codepage);
+		auto_display_charset = UCGetLYhndl_byMIME(myMimeName);
+	    }
+	}
+    }
+#  endif
+#endif
+
 /*
  *  To add synonyms for any charset name
  *  check function UCGetLYhndl_byMIME in this file.