about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/GridText.c238
-rw-r--r--src/LYDownload.c100
-rw-r--r--src/LYForms.c4
-rw-r--r--src/LYGetFile.c149
-rw-r--r--src/LYJump.c57
-rw-r--r--src/LYLocal.c241
-rw-r--r--src/LYMainLoop.c245
-rw-r--r--src/LYOptions.c6
-rw-r--r--src/LYPrint.c268
-rw-r--r--src/LYSearch.c72
-rw-r--r--src/LYSearch.h3
-rw-r--r--src/LYStrings.c164
-rw-r--r--src/LYUtils.c82
-rw-r--r--src/LYUtils.h4
14 files changed, 819 insertions, 814 deletions
diff --git a/src/GridText.c b/src/GridText.c
index 3277add1..0e18511a 100644
--- a/src/GridText.c
+++ b/src/GridText.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: GridText.c,v 1.226 2012/02/07 21:11:50 tom Exp $
+ * $LynxId: GridText.c,v 1.229 2012/02/09 01:55:40 tom Exp $
  *
  *		Character grid hypertext object
  *		===============================
@@ -7653,8 +7653,8 @@ void HTAddSearchQuery(char *query)
 
 int do_www_search(DocInfo *doc)
 {
-    char searchstring[256];
-    char temp[256];
+    bstring *searchstring = NULL;
+    bstring *temp = NULL;
     char *cp;
     char *tmpaddress = NULL;
     int ch;
@@ -7662,6 +7662,7 @@ int do_www_search(DocInfo *doc)
     int QueryTotal;
     int QueryNum;
     BOOLEAN PreviousSearch = FALSE;
+    int code;
 
     /*
      * Load the default query buffer
@@ -7672,28 +7673,28 @@ int do_www_search(DocInfo *doc)
 	 * Use its query as the default.
 	 */
 	PreviousSearch = TRUE;
-	LYStrNCpy(searchstring, ++cp, sizeof(searchstring) - 1);
-	for (cp = searchstring; *cp; cp++)
+	BStrCopy0(searchstring, ++cp);
+	for (cp = searchstring->str; *cp; cp++)
 	    if (*cp == '+')
 		*cp = ' ';
-	HTUnEscape(searchstring);
-	strcpy(temp, searchstring);
+	HTUnEscape(searchstring->str);
+	BStrCopy(temp, searchstring);
 	/*
 	 * Make sure it's treated as the most recent query.  -FM
 	 */
-	HTAddSearchQuery(searchstring);
+	HTAddSearchQuery(searchstring->str);
     } else {
 	/*
 	 * New search; no default.
 	 */
-	searchstring[0] = '\0';
-	temp[0] = '\0';
+	BStrCopy0(searchstring, "");
+	BStrCopy0(temp, "");
     }
 
     /*
      * Prompt for a query string.
      */
-    if (searchstring[0] == '\0') {
+    if (isBEmpty(searchstring)) {
 	if (HTMainAnchor->isIndexPrompt)
 	    _statusline(HTMainAnchor->isIndexPrompt);
 	else
@@ -7704,10 +7705,13 @@ int do_www_search(DocInfo *doc)
     recall = (((PreviousSearch && QueryTotal >= 2) ||
 	       (!PreviousSearch && QueryTotal >= 1)) ? RECALL_URL : NORECALL);
     QueryNum = QueryTotal;
+
   get_query:
-    if ((ch = LYGetStr(searchstring, VISIBLE,
-		       sizeof(searchstring), recall)) < 0 ||
-	*searchstring == '\0' || ch == UPARROW || ch == DNARROW) {
+    if ((ch = LYgetBString(&searchstring, VISIBLE, 0, recall)) < 0 ||
+	isBEmpty(searchstring) ||
+	ch == UPARROW ||
+	ch == DNARROW) {
+
 	if (recall && ch == UPARROW) {
 	    if (PreviousSearch) {
 		/*
@@ -7728,11 +7732,12 @@ int do_www_search(DocInfo *doc)
 		QueryNum = 0;
 	    if ((cp = (char *) HTList_objectAt(search_queries,
 					       QueryNum)) != NULL) {
-		LYStrNCpy(searchstring, cp, sizeof(searchstring) - 1);
-		if (*temp && !strcmp(temp, searchstring)) {
+		BStrCopy0(searchstring, cp);
+		if (!isBEmpty(temp) &&
+		    !strcmp(temp->str, searchstring->str)) {
 		    _statusline(EDIT_CURRENT_QUERY);
-		} else if ((*temp && QueryTotal == 2) ||
-			   (!(*temp) && QueryTotal == 1)) {
+		} else if ((!isBEmpty(temp) && QueryTotal == 2) ||
+			   (isBEmpty(temp) && QueryTotal == 1)) {
 		    _statusline(EDIT_THE_PREV_QUERY);
 		} else {
 		    _statusline(EDIT_A_PREV_QUERY);
@@ -7759,11 +7764,12 @@ int do_www_search(DocInfo *doc)
 		QueryNum = QueryTotal - 1;
 	    if ((cp = (char *) HTList_objectAt(search_queries,
 					       QueryNum)) != NULL) {
-		LYStrNCpy(searchstring, cp, sizeof(searchstring) - 1);
-		if (*temp && !strcmp(temp, searchstring)) {
+		BStrCopy0(searchstring, cp);
+		if (!isBEmpty(temp) &&
+		    !strcmp(temp->str, searchstring->str)) {
 		    _statusline(EDIT_CURRENT_QUERY);
-		} else if ((*temp && QueryTotal == 2) ||
-			   (!(*temp) && QueryTotal == 1)) {
+		} else if ((!isBEmpty(temp) && QueryTotal == 2) ||
+			   (isBEmpty(temp) && QueryTotal == 1)) {
 		    _statusline(EDIT_THE_PREV_QUERY);
 		} else {
 		    _statusline(EDIT_A_PREV_QUERY);
@@ -7776,82 +7782,80 @@ int do_www_search(DocInfo *doc)
 	 * Search cancelled.
 	 */
 	HTInfoMsg(CANCELLED);
-	return (NULLFILE);
-    }
-
-    /*
-     * Strip leaders and trailers.  -FM
-     */
-    LYTrimLeading(searchstring);
-    if (!(*searchstring)) {
-	HTInfoMsg(CANCELLED);
-	return (NULLFILE);
-    }
-    LYTrimTrailing(searchstring);
+	code = NULLFILE;
+    } else {
 
-    /*
-     * Don't resubmit the same query unintentionally.
-     */
-    if (!LYforce_no_cache && 0 == strcmp(temp, searchstring)) {
-	HTUserMsg(USE_C_R_TO_RESUB_CUR_QUERY);
-	return (NULLFILE);
-    }
+	LYTrimLeading(searchstring->str);
+	LYTrimTrailing(searchstring->str);
+	if (isBEmpty(searchstring)) {
+	    HTInfoMsg(CANCELLED);
+	    code = NULLFILE;
+	} else if (!LYforce_no_cache &&
+		   !strcmp(temp->str, searchstring->str)) {
+	    /*
+	     * Don't resubmit the same query unintentionally.
+	     */
+	    HTUserMsg(USE_C_R_TO_RESUB_CUR_QUERY);
+	    code = NULLFILE;
+	} else {
 
-    /*
-     * Add searchstring to the query list,
-     * or make it the most current.  -FM
-     */
-    HTAddSearchQuery(searchstring);
+	    /*
+	     * Add searchstring to the query list,
+	     * or make it the most current.  -FM
+	     */
+	    HTAddSearchQuery(searchstring->str);
 
-    /*
-     * Show the URL with the new query.
-     */
-    if ((cp = strchr(doc->address, '?')) != NULL)
-	*cp = '\0';
-    StrAllocCopy(tmpaddress, doc->address);
-    StrAllocCat(tmpaddress, "?");
-    StrAllocCat(tmpaddress, searchstring);
-    user_message(WWW_WAIT_MESSAGE, tmpaddress);
+	    /*
+	     * Show the URL with the new query.
+	     */
+	    if ((cp = strchr(doc->address, '?')) != NULL)
+		*cp = '\0';
+	    StrAllocCopy(tmpaddress, doc->address);
+	    StrAllocCat(tmpaddress, "?");
+	    StrAllocCat(tmpaddress, searchstring->str);
+	    user_message(WWW_WAIT_MESSAGE, tmpaddress);
 #ifdef SYSLOG_REQUESTED_URLS
-    LYSyslog(tmpaddress);
+	    LYSyslog(tmpaddress);
 #endif
-    FREE(tmpaddress);
-    if (cp)
-	*cp = '?';
+	    FREE(tmpaddress);
+	    if (cp)
+		*cp = '?';
 
-    /*
-     * OK, now we do the search.
-     */
-    if (HTSearch(searchstring, HTMainAnchor)) {
-	/*
-	 * Memory leak fixed.
-	 * 05-28-94 Lynx 2-3-1 Garrett Arch Blythe
-	 */
-	auto char *cp_freeme = NULL;
+	    /*
+	     * OK, now we do the search.
+	     */
+	    if (HTSearch(searchstring->str, HTMainAnchor)) {
+		auto char *cp_freeme = NULL;
 
-	if (traversal)
-	    cp_freeme = stub_HTAnchor_address((HTAnchor *) HTMainAnchor);
-	else
-	    cp_freeme = HTAnchor_address((HTAnchor *) HTMainAnchor);
-	StrAllocCopy(doc->address, cp_freeme);
-	FREE(cp_freeme);
+		if (traversal)
+		    cp_freeme = stub_HTAnchor_address((HTAnchor *) HTMainAnchor);
+		else
+		    cp_freeme = HTAnchor_address((HTAnchor *) HTMainAnchor);
+		StrAllocCopy(doc->address, cp_freeme);
+		FREE(cp_freeme);
 
-	CTRACE((tfp, "\ndo_www_search: newfile: %s\n", doc->address));
+		CTRACE((tfp, "\ndo_www_search: newfile: %s\n", doc->address));
 
-	/*
-	 * Yah, the search succeeded.
-	 */
-	return (NORMAL);
-    }
+		/*
+		 * Yah, the search succeeded.
+		 */
+		code = NORMAL;
+	    } else {
 
-    /*
-     * Either the search failed (Yuk), or we got redirection.
-     * If it's redirection, use_this_url_instead is set, and
-     * mainloop() will deal with it such that security features
-     * and restrictions are checked before acting on the URL, or
-     * rejecting it.  -FM
-     */
-    return (NOT_FOUND);
+		/*
+		 * Either the search failed (Yuk), or we got redirection.
+		 * If it's redirection, use_this_url_instead is set, and
+		 * mainloop() will deal with it such that security features
+		 * and restrictions are checked before acting on the URL, or
+		 * rejecting it.  -FM
+		 */
+		code = NOT_FOUND;
+	    }
+	}
+    }
+    BStrFree(searchstring);
+    BStrFree(temp);
+    return code;
 }
 
 static void write_offset(FILE *fp, HTLine *line)
@@ -12998,9 +13002,11 @@ static int finish_ExtEditForm(LinkInfo * form_link, TextAnchor *start_anchor,
     int match_tag = 0;
     int newlines = 0;
     int len, len0;
+    int display_size;
     int wanted_fieldlen_wrap = -1;	/* not yet asked; 0 means don't. */
     char *skip_at = NULL;
     int skip_num = 0, i;
+    size_t line_used = MAX_LINE;
 
     CTRACE((tfp, "GridText: entered HText_EditTextArea()\n"));
 
@@ -13013,14 +13019,15 @@ static int finish_ExtEditForm(LinkInfo * form_link, TextAnchor *start_anchor,
      * struct.  Add new lines to the TEXTAREA if needed.  (Always leave
      * the user with a blank line at the end of the TEXTAREA.)
      */
-    if ((line = typeMallocn(char, MAX_LINE)) == 0)
+    if ((line = typeMallocn(char, line_used)) == 0)
 	  outofmem(__FILE__, "HText_EditTextArea");
 
     assert(line != NULL);
 
     anchor_ptr = start_anchor;
-    if (anchor_ptr->input_field->size <= 4 ||
-	anchor_ptr->input_field->size >= MAX_LINE)
+    display_size = anchor_ptr->input_field->size;
+    if (display_size <= 4 ||
+	display_size >= MAX_LINE)
 	wanted_fieldlen_wrap = 0;
 
     len = 0;
@@ -13047,22 +13054,28 @@ static int finish_ExtEditForm(LinkInfo * form_link, TextAnchor *start_anchor,
 	else
 	    len = (int) strlen(lp);
 
-	if (wanted_fieldlen_wrap < 0 && !wrapalert &&
-	    len0 + len >= start_anchor->input_field->size &&
+	if (wanted_fieldlen_wrap < 0 &&
+	    !wrapalert &&
+	    len0 + len >= display_size &&
 	    (cp = strchr(lp, ' ')) != NULL &&
-	    (cp - lp) < start_anchor->input_field->size - 1) {
+	    (cp - lp) < display_size - 1) {
+
 	    LYFixCursesOn("ask for confirmation:");
 	    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;
+		wanted_fieldlen_wrap = display_size - 1;
 	    } else {
 		wanted_fieldlen_wrap = 0;
 	    }
 	}
-	if (wanted_fieldlen_wrap > 0 && len0 + len > wanted_fieldlen_wrap) {
+
+	if (wanted_fieldlen_wrap > 0 &&
+	    len0 + len > wanted_fieldlen_wrap) {
+
 	    for (i = wanted_fieldlen_wrap - len0;
 		 i + len0 >= wanted_fieldlen_wrap / 4; i--) {
+
 		if (isspace(UCH(lp[i]))) {
 		    len = i + 1;
 		    cp = lp + i;
@@ -13093,7 +13106,10 @@ static int finish_ExtEditForm(LinkInfo * form_link, TextAnchor *start_anchor,
 		}
 	    }
 	}
-	if (wanted_fieldlen_wrap > 0 && len0 + len > wanted_fieldlen_wrap) {
+
+	if (wanted_fieldlen_wrap > 0 &&
+	    (len0 + len) > wanted_fieldlen_wrap) {
+
 	    i = len - 1;
 	    while (len0 + i + 1 > wanted_fieldlen_wrap &&
 		   isspace(UCH(lp[i])))
@@ -13102,23 +13118,17 @@ static int finish_ExtEditForm(LinkInfo * form_link, TextAnchor *start_anchor,
 		len = wanted_fieldlen_wrap - len0;
 	}
 
-	if (len0 + len >= MAX_LINE) {
-	    if (!wrapalert) {
-		LYFixCursesOn("show alert:");
-		HTAlert(gettext("Very long lines have been wrapped!"));
-		wrapalert = TRUE;
-	    }
-	    /*
-	     * First try to find a space character for wrapping - kw
-	     */
-	    for (i = MAX_LINE - len0 - 1; i > 0; i--) {
-		if (isspace(UCH(lp[i]))) {
-		    len = i;
-		    break;
-		}
-	    }
-	    if (len0 + len >= MAX_LINE)
-		len = MAX_LINE - len0 - 1;
+	/*
+	 * Check if the new text will fit in the buffer.  HTML does not define
+	 * a "maxlength" attribute for TEXTAREA; its data can grow as needed.
+	 * Lynx will not adjust the display to reflect larger amounts of text;
+	 * it relies on the rows/cols attributes as well as the initial content
+	 * of the text area for the layout.
+	 */
+	if ((size_t) (len0 + len) >= line_used) {
+	    line_used = (size_t) (3 * (len0 + len)) / 2;
+	    if ((line = typeRealloc(char, line, line_used)) == 0)
+		  outofmem(__FILE__, "HText_EditTextArea");
 	}
 
 	strncat(line, lp, (size_t) len);
diff --git a/src/LYDownload.c b/src/LYDownload.c
index 7822cdea..241818c3 100644
--- a/src/LYDownload.c
+++ b/src/LYDownload.c
@@ -1,4 +1,4 @@
-/* $LynxId: LYDownload.c,v 1.62 2010/09/25 11:19:25 tom Exp $ */
+/* $LynxId: LYDownload.c,v 1.64 2012/02/08 22:23:59 tom Exp $ */
 #include <HTUtils.h>
 #include <HTParse.h>
 #include <HTList.h>
@@ -31,8 +31,8 @@ void LYDownload(char *line)
     int method_number;
     int count;
     char *the_command = 0;
-    char buffer[LY_MAXPATH];
-    char command[LY_MAXPATH];
+    bstring *buffer = NULL;
+    bstring *command = NULL;
     char *cp;
     lynx_list_item_type *download_command = 0;
     int ch;
@@ -133,14 +133,18 @@ void LYDownload(char *line)
 	 */
 	_statusline(FILENAME_PROMPT);
       retry:
-	if (sug_file)
-	    LYStrNCpy(buffer, sug_file, ((sizeof(buffer) / 2) - 1));
-	else
-	    *buffer = '\0';
+	if (sug_file) {
+	    BStrCopy0(buffer, sug_file);
+	} else {
+	    BStrCopy0(buffer, "");
+	}
+
       check_recall:
-	if ((ch = LYGetStr(buffer,
-			   VISIBLE, (sizeof(buffer) / 2), recall)) < 0 ||
-	    *buffer == '\0' || ch == UPARROW || ch == DNARROW) {
+	if ((ch = LYgetBString(&buffer, VISIBLE, 0, recall)) < 0 ||
+	    isBEmpty(buffer) ||
+	    ch == UPARROW ||
+	    ch == DNARROW) {
+
 	    if (recall && ch == UPARROW) {
 		if (FirstRecall) {
 		    FirstRecall = FALSE;
@@ -165,7 +169,7 @@ void LYDownload(char *line)
 		    goto retry;
 		} else if ((cp = (char *) HTList_objectAt(sug_filenames,
 							  FnameNum)) != NULL) {
-		    LYStrNCpy(buffer, cp, sizeof(buffer) - 1);
+		    BStrCopy0(buffer, cp);
 		    if (FnameTotal == 1) {
 			_statusline(EDIT_THE_PREV_FILENAME);
 		    } else {
@@ -197,7 +201,7 @@ void LYDownload(char *line)
 		    goto retry;
 		} else if ((cp = (char *) HTList_objectAt(sug_filenames,
 							  FnameNum)) != NULL) {
-		    LYStrNCpy(buffer, cp, sizeof(buffer) - 1);
+		    BStrCopy0(buffer, cp);
 		    if (FnameTotal == 1) {
 			_statusline(EDIT_THE_PREV_FILENAME);
 		    } else {
@@ -213,11 +217,11 @@ void LYDownload(char *line)
 	    goto cancelled;
 	}
 
-	strcpy(command, buffer);
+	BStrCopy(command, buffer);
 	if (!LYValidateFilename(buffer, command))
 	    goto cancelled;
 #ifdef HAVE_POPEN
-	else if (LYIsPipeCommand(buffer)) {
+	else if (LYIsPipeCommand(buffer->str)) {
 	    /* I don't know how to download to a pipe */
 	    HTAlert(CANNOT_WRITE_TO_FILE);
 	    _statusline(NEW_FILENAME_PROMPT);
@@ -230,7 +234,7 @@ void LYDownload(char *line)
 	/*
 	 * See if it already exists.
 	 */
-	switch (LYValidateOutput(buffer)) {
+	switch (LYValidateOutput(buffer->str)) {
 	case 'Y':
 	    break;
 	case 'N':
@@ -239,16 +243,15 @@ void LYDownload(char *line)
 	    FnameNum = FnameTotal;
 	    goto retry;
 	default:
-	    FREE(Line);
-	    return;
+	    goto cleanup;
 	}
 
 	/*
 	 * See if we can write to it.
 	 */
-	CTRACE((tfp, "LYDownload: filename is %s\n", buffer));
+	CTRACE((tfp, "LYDownload: filename is %s\n", buffer->str));
 
-	if (!LYCanWriteFile(buffer)) {
+	if (!LYCanWriteFile(buffer->str)) {
 	    FirstRecall = TRUE;
 	    FnameNum = FnameTotal;
 	    goto retry;
@@ -260,13 +263,13 @@ void LYDownload(char *line)
 	/*
 	 * Try rename() first.  - FM
 	 */
-	CTRACE((tfp, "command: rename(%s, %s)\n", file, buffer));
-	if (rename(file, buffer)) {
+	CTRACE((tfp, "command: rename(%s, %s)\n", file, buffer->str));
+	if (rename(file, buffer->str)) {
 	    /*
 	     * Failed.  Use spawned COPY_COMMAND.  - FM
 	     */
 	    CTRACE((tfp, "         FAILED!\n"));
-	    LYCopyFile(file, buffer);
+	    LYCopyFile(file, buffer->str);
 	} else {
 	    /*
 	     * We don't have the temporary file (it was renamed to a permanent
@@ -274,18 +277,18 @@ void LYDownload(char *line)
 	     */
 	    LYDidRename = TRUE;
 	}
-	chmod(buffer, HIDE_CHMOD);
+	chmod(buffer->str, HIDE_CHMOD);
 #else /* Unix: */
 
-	LYCopyFile(file, buffer);
-	LYRelaxFilePermissions(buffer);
+	LYCopyFile(file, buffer->str);
+	LYRelaxFilePermissions(buffer->str);
 #endif /* VMS */
 
     } else {
 	/*
 	 * Use configured download commands.
 	 */
-	buffer[0] = '\0';
+	BStrCopy0(buffer, "");
 	for (count = 0, download_command = downloaders;
 	     count < method_number;
 	     count++, download_command = download_command->next) ;	/* null body */
@@ -299,16 +302,20 @@ void LYDownload(char *line)
 	     */
 	    if (HTCountCommandArgs(download_command->command) >= 2) {
 		_statusline(FILENAME_PROMPT);
+
 	      again:
 		if (sug_file) {
-		    StrNCpy(buffer, sug_file, (sizeof(buffer) / 2) - 1);
+		    BStrCopy0(buffer, sug_file);
 		} else {
-		    *buffer = '\0';
+		    BStrCopy0(buffer, "");
 		}
+
 	      check_again:
-		if ((ch = LYGetStr(buffer, VISIBLE,
-				   sizeof(buffer), recall)) < 0 ||
-		    *buffer == '\0' || ch == UPARROW || ch == DNARROW) {
+		if ((ch = LYgetBString(&buffer, VISIBLE, 0, recall)) < 0 ||
+		    isBEmpty(buffer) ||
+		    ch == UPARROW ||
+		    ch == DNARROW) {
+
 		    if (recall && ch == UPARROW) {
 			if (FirstRecall) {
 			    FirstRecall = FALSE;
@@ -334,7 +341,7 @@ void LYDownload(char *line)
 			} else if ((cp = (char *) HTList_objectAt(sug_filenames,
 								  FnameNum))
 				   != NULL) {
-			    LYStrNCpy(buffer, cp, sizeof(buffer) - 1);
+			    BStrCopy0(buffer, cp);
 			    if (FnameTotal == 1) {
 				_statusline(EDIT_THE_PREV_FILENAME);
 			    } else {
@@ -367,7 +374,7 @@ void LYDownload(char *line)
 			} else if ((cp = (char *) HTList_objectAt(sug_filenames,
 								  FnameNum))
 				   != NULL) {
-			    LYStrNCpy(buffer, cp, sizeof(buffer) - 1);
+			    BStrCopy0(buffer, cp);
 			    if (FnameTotal == 1) {
 				_statusline(EDIT_THE_PREV_FILENAME);
 			    } else {
@@ -384,7 +391,7 @@ void LYDownload(char *line)
 		}
 
 		if (no_dotfiles || !show_dotfiles) {
-		    if (*LYPathLeaf(buffer) == '.') {
+		    if (*LYPathLeaf(buffer->str) == '.') {
 			HTAlert(FILENAME_CANNOT_BE_DOT);
 			_statusline(NEW_FILENAME_PROMPT);
 			goto again;
@@ -394,7 +401,7 @@ void LYDownload(char *line)
 		 * Cancel if the user entered "/dev/null" on Unix, or an "nl:"
 		 * path on VMS.  - FM
 		 */
-		if (LYIsNullDevice(buffer)) {
+		if (LYIsNullDevice(buffer->str)) {
 		    goto cancelled;
 		}
 		SecondS = TRUE;
@@ -410,7 +417,7 @@ void LYDownload(char *line)
 	    count = 1;
 	    HTAddParam(&the_command, download_command->command, count, file);
 	    if (HTCountCommandArgs(download_command->command) > 1)
-		HTAddParam(&the_command, download_command->command, ++count, buffer);
+		HTAddParam(&the_command, download_command->command, ++count, buffer->str);
 	    HTEndParam(&the_command, download_command->command, count);
 
 	} else {
@@ -428,30 +435,31 @@ void LYDownload(char *line)
 
     if (SecondS == TRUE) {
 #ifdef VMS
-	if (0 == strncasecomp(buffer, "sys$disk:", 9)) {
-	    if (0 == StrNCmp((buffer + 9), "[]", 2)) {
-		HTAddSugFilename(buffer + 11);
+	if (0 == strncasecomp(buffer->str, "sys$disk:", 9)) {
+	    if (0 == StrNCmp((buffer->str + 9), "[]", 2)) {
+		HTAddSugFilename(buffer->str + 11);
 	    } else {
-		HTAddSugFilename(buffer + 9);
+		HTAddSugFilename(buffer->str + 9);
 	    }
 	} else {
-	    HTAddSugFilename(buffer);
+	    HTAddSugFilename(buffer->str);
 	}
 #else
-	HTAddSugFilename(buffer);
+	HTAddSugFilename(buffer->str);
 #endif /* VMS */
     }
-    FREE(Line);
-    return;
+    goto cleanup;
 
   failed:
     HTAlert(CANNOT_DOWNLOAD_FILE);
-    FREE(Line);
-    return;
+    goto cleanup;
 
   cancelled:
     HTInfoMsg(CANCELLING);
+
+  cleanup:
     FREE(Line);
+    BStrFree(buffer);
     return;
 }
 
diff --git a/src/LYForms.c b/src/LYForms.c
index bb8ad24d..aec9f2c9 100644
--- a/src/LYForms.c
+++ b/src/LYForms.c
@@ -1,4 +1,4 @@
-/* $LynxId: LYForms.c,v 1.95 2012/02/07 17:33:29 tom Exp $ */
+/* $LynxId: LYForms.c,v 1.96 2012/02/09 01:01:53 tom Exp $ */
 #include <HTUtils.h>
 #include <HTCJK.h>
 #include <HTTP.h>
@@ -250,7 +250,7 @@ int change_form_link_ex(int cur,
 	    LYSetHilite(cur, form->value);
 #ifdef TEXT_SUBMIT_CONFIRM_WANTED
 	    if (!immediate_submit && (c == '\r' || c == '\n') &&
-		!HTConfirmDefault(NO_SUBMIT_BUTTON_QUERY), YES) {
+		!HTConfirmDefault(NO_SUBMIT_BUTTON_QUERY, YES)) {
 		/* User was prompted and declined; if canceled with ^G
 		 * let mainloop stay on this field, otherwise move on to
 		 * the next field or link. - kw
diff --git a/src/LYGetFile.c b/src/LYGetFile.c
index 6138fbee..2c6ebe1a 100644
--- a/src/LYGetFile.c
+++ b/src/LYGetFile.c
@@ -1,4 +1,4 @@
-/* $LynxId: LYGetFile.c,v 1.85 2010/12/07 20:59:41 tom Exp $ */
+/* $LynxId: LYGetFile.c,v 1.87 2012/02/08 21:01:03 tom Exp $ */
 #include <HTUtils.h>
 #include <HTTP.h>
 #include <HTAnchor.h>		/* Anchor class */
@@ -547,12 +547,13 @@ int getfile(DocInfo *doc, int *target)
 		}
 		cp = strchr(doc->address, ':') + 1;
 		reply_by_mail(cp,
-			      ((HTMainAnchor && !LYUserSpecifiedURL) ?
-			       (char *) HTMainAnchor->address :
-			       (char *) doc->address),
+			      ((HTMainAnchor && !LYUserSpecifiedURL)
+			       ? (char *) HTMainAnchor->address
+			       : (char *) doc->address),
 			      title,
-			      (HTMainAnchor && !LYUserSpecifiedURL) ?
-			      HTMainAnchor->message_id : NULL);
+			      (HTMainAnchor && !LYUserSpecifiedURL)
+			      ? HTMainAnchor->message_id
+			      : NULL);
 		FREE(tmptitle);
 	    }
 	    return (NULLFILE);
@@ -1123,25 +1124,30 @@ int follow_link_number(int c,
 		       DocInfo *doc,
 		       int *num)
 {
-    char temp[120];
-    char *p = temp;
+    bstring *temp = NULL;
+    char *p;
     int rel = 0;
     int new_top, new_link;
     BOOL want_go;
     int curline = *num;		/* passed in from mainloop() */
+    int code;
 
     CTRACE((tfp, "follow_link_number(%d,%d,...)\n", c, cur));
-    temp[0] = (char) c;
-    temp[1] = '\0';
+    BStrCopy0(temp, "?");
+    temp->str[0] = (char) c;
     *num = -1;
     _statusline(FOLLOW_LINK_NUMBER);
+
     /*
      * Get the number, possibly with a letter suffix, from the user.
      */
-    if (LYGetStr(temp, VISIBLE, sizeof(temp), NORECALL) < 0 || *temp == 0) {
+    if (LYgetBString(&temp, VISIBLE, sizeof(temp), NORECALL) < 0 ||
+	isBEmpty(temp)) {
 	HTInfoMsg(CANCELLED);
 	return (DO_NOTHING);
     }
+
+    p = temp->str;
     *num = atoi(p);
     while (isdigit(UCH(*p)))
 	++p;
@@ -1161,7 +1167,7 @@ int follow_link_number(int c,
     }
     /* don't currently check for errors typing suffix */
 
-    CTRACE((tfp, "  temp=%s, *num=%d, rel='%c'\n", temp, *num, rel));
+    CTRACE((tfp, "  temp=%s, *num=%d, rel='%c'\n", temp->str, *num, rel));
     /*
      * Check if we had a 'p' or 'P' following the number as a flag for
      * displaying the page with that number.  - FM
@@ -1169,15 +1175,15 @@ int follow_link_number(int c,
     if ((c == 'p' || c == 'P') && display_lines == 0) {
 	CTRACE((tfp, " curline=%d, LYlines=%d, display too small!\n",
 		curline, LYlines));
-	return (PRINT_ERROR);
+	code = PRINT_ERROR;
     } else if (c == 'p' || c == 'P') {
 	int nlines = HText_getNumOfLines();
-	int npages = ((nlines + 1) > display_lines) ?
-	(((nlines + 1) + (display_lines - 1)) / (display_lines))
-	: 1;
-	int curpage = ((curline + 1) > display_lines) ?
-	(((curline + 1) + (display_lines - 1)) / (display_lines))
-	: 1;
+	int npages = (((nlines + 1) > display_lines)
+		      ? (((nlines + 1) + (display_lines - 1)) / (display_lines))
+		      : 1);
+	int curpage = (((curline + 1) > display_lines)
+		       ? (((curline + 1) + (display_lines - 1)) / (display_lines))
+		       : 1);
 
 	CTRACE((tfp, " nlines=%d, npages=%d, curline=%d, curpage=%d\n",
 		nlines, npages, curline, curpage));
@@ -1187,63 +1193,68 @@ int follow_link_number(int c,
 	    *num = curpage + *num;
 	else if (rel == '-')
 	    *num = curpage - *num;
-	doc->line = (npages <= 1) ?
-	    1 :
-	    ((*num <= npages) ? (((*num - 1) * display_lines) + 1)
-	     : (((npages - 1) * display_lines) + 1));
-	return (DO_GOTOPAGE_STUFF);
-    }
-
-    /*
-     * Check if we want to make the link corresponding to the number the
-     * current link, rather than ACTIVATE-ing it.
-     */
-    want_go = (BOOL) (c == 'g' || c == 'G');
+	doc->line = ((npages <= 1)
+		     ? 1
+		     : ((*num <= npages)
+			? (((*num - 1) * display_lines) + 1)
+			: (((npages - 1) * display_lines) + 1)));
+	code = DO_GOTOPAGE_STUFF;
+    } else {
 
-    /* If rel, add or subtract num from current link, or
-     * nearest previous/subsequent link if current link is not on screen.
-     */
-    if (rel)
-	*num = HTGetRelLinkNum(*num, rel, cur);
-    /*
-     * If we have a valid number, act on it.
-     */
-    if (*num > 0) {
-	int info;
-	char *text = NULL;
+	/*
+	 * Check if we want to make the link corresponding to the number the
+	 * current link, rather than ACTIVATE-ing it.
+	 */
+	want_go = (BOOL) (c == 'g' || c == 'G');
 
+	/* If rel, add or subtract num from current link, or
+	 * nearest previous/subsequent link if current link is not on screen.
+	 */
+	if (rel)
+	    *num = HTGetRelLinkNum(*num, rel, cur);
 	/*
-	 * Get the lname, and hightext, directly from www structures and add it
-	 * to the cur link so that we can pass it transparently on to
-	 * getfile(), and load new_top and new_link if we instead want to make
-	 * the link number current.  These things are done so that a link can
-	 * be selected anywhere in the current document, whether it is
-	 * displayed on the screen or not!
+	 * If we have a valid number, act on it.
 	 */
-	info = HTGetLinkInfo(*num,
-			     want_go,
-			     &new_top,
-			     &new_link,
-			     &text,
-			     &links[cur].lname);
-	if (text != NULL)
-	    LYSetHilite(cur, text);
-	if (info == WWW_INTERN_LINK_TYPE) {
-	    links[cur].type = WWW_INTERN_LINK_TYPE;
-	    return (DO_LINK_STUFF);
-	} else if (info == LINK_LINE_FOUND) {
-	    doc->line = new_top + 1;
-	    doc->link = new_link;
-	    return (DO_GOTOLINK_STUFF);
-	} else if (info) {
-	    links[cur].type = WWW_LINK_TYPE;
-	    return (DO_LINK_STUFF);
+	if (*num > 0) {
+	    int info;
+	    char *text = NULL;
+
+	    /*
+	     * Get the lname, and hightext, directly from www structures and
+	     * add it to the cur link so that we can pass it transparently on
+	     * to getfile(), and load new_top and new_link if we instead want
+	     * to make the link number current.  These things are done so that
+	     * a link can be selected anywhere in the current document, whether
+	     * it is displayed on the screen or not!
+	     */
+	    info = HTGetLinkInfo(*num,
+				 want_go,
+				 &new_top,
+				 &new_link,
+				 &text,
+				 &links[cur].lname);
+	    if (text != NULL)
+		LYSetHilite(cur, text);
+
+	    if (info == WWW_INTERN_LINK_TYPE) {
+		links[cur].type = WWW_INTERN_LINK_TYPE;
+		code = DO_LINK_STUFF;
+	    } else if (info == LINK_LINE_FOUND) {
+		doc->line = new_top + 1;
+		doc->link = new_link;
+		code = DO_GOTOLINK_STUFF;
+	    } else if (info) {
+		links[cur].type = WWW_LINK_TYPE;
+		code = DO_LINK_STUFF;
+	    } else {
+		code = PRINT_ERROR;
+	    }
 	} else {
-	    return (PRINT_ERROR);
+	    code = PRINT_ERROR;
 	}
-    } else {
-	return (PRINT_ERROR);
     }
+    BStrFree(temp);
+    return code;
 }
 
 #if defined(EXEC_LINKS) || defined(LYNXCGI_LINKS)
diff --git a/src/LYJump.c b/src/LYJump.c
index 07789dd4..8c20145c 100644
--- a/src/LYJump.c
+++ b/src/LYJump.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYJump.c,v 1.40 2012/01/17 00:43:43 tom Exp $
+ * $LynxId: LYJump.c,v 1.42 2012/02/09 01:56:47 tom Exp $
  */
 #include <HTUtils.h>
 #include <HTAlert.h>
@@ -181,9 +181,10 @@ BOOL LYJumpInit(char *config)
 
 char *LYJump(int key)
 {
+    static bstring *buf = NULL;
+
     JumpDatum seeking;
     JumpDatum *found;
-    static char buf[124];
     char *bp, *cp;
     struct JumpTable *jtp;
     int ch;
@@ -210,16 +211,19 @@ char *LYJump(int key)
     if (jtp->nel == 0)
 	return NULL;
 
-    if (!jump_buffer || isEmpty(jtp->shortcut))
-	*buf = '\0';
-    else if (non_empty(jtp->shortcut)) {
-	if (strlen(jtp->shortcut) > sizeof(buf) - 5)
-	    jtp->shortcut[sizeof(buf) - 5] = '\0';
-	strcpy(buf, jtp->shortcut);
+    if (!jump_buffer || isEmpty(jtp->shortcut)) {
+	BStrCopy0(buf, "");
+    } else if (non_empty(jtp->shortcut)) {
+	size_t len = (size_t) BStrLen(buf);
+
+	if (strlen(jtp->shortcut) > len) {
+	    jtp->shortcut[len] = '\0';
+	    BStrCopy0(buf, jtp->shortcut);
+	}
     }
 
     ShortcutTotal = (jtp->history ? HTList_count(jtp->history) : 0);
-    if (jump_buffer && *buf) {
+    if (jump_buffer && !isBEmpty(buf)) {
 	recall = ((ShortcutTotal > 1) ? RECALL_URL : NORECALL);
 	ShortcutNum = 0;
 	FirstShortcutRecall = FALSE;
@@ -230,7 +234,7 @@ char *LYJump(int key)
     }
 
     statusline(jtp->msg);
-    if ((ch = LYGetStr(buf, VISIBLE, (sizeof(buf) - 4), recall)) < 0) {
+    if ((ch = LYgetBString(&buf, VISIBLE, 0, recall)) < 0) {
 	/*
 	 * User cancelled the Jump via ^G. - FM
 	 */
@@ -239,8 +243,8 @@ char *LYJump(int key)
     }
 
   check_recall:
-    bp = buf;
-    if (TOUPPER(key) == 'G' && StrNCmp(buf, "o ", 2) == 0)
+    bp = buf->str;
+    if (TOUPPER(key) == 'G' && StrNCmp(buf->str, "o ", 2) == 0)
 	bp++;
     bp = LYSkipBlanks(bp);
     if (*bp == '\0' &&
@@ -248,8 +252,8 @@ char *LYJump(int key)
 	/*
 	 * User cancelled the Jump via a zero-length string. - FM
 	 */
-	*buf = '\0';
-	StrAllocCopy(jtp->shortcut, buf);
+	BStrCopy0(buf, "");
+	StrAllocCopy(jtp->shortcut, buf->str);
 	HTInfoMsg(CANCELLED);
 	return NULL;
     }
@@ -259,13 +263,15 @@ char *LYJump(int key)
 
 	LYJumpFileURL = FALSE;
 	if (no_goto) {
-	    *buf = '\0';
-	    StrAllocCopy(jtp->shortcut, buf);
+	    BStrCopy0(buf, "");
+	    StrAllocCopy(jtp->shortcut, buf->str);
 	    HTUserMsg(RANDOM_URL_DISALLOWED);
 	    return NULL;
 	}
-	sprintf(buf, "Go %.*s", (int) sizeof(buf) - 4, bp);
-	return (bp = buf);
+	HTSprintf0(&temp, "Go %s", bp);
+	BStrCopy0(buf, temp);
+	FREE(temp);
+	return (bp = buf->str);
     }
 #endif /* PERMIT_GOTO_FROM_JUMP */
 
@@ -289,9 +295,9 @@ char *LYJump(int key)
 	    ShortcutNum = 0;
 	if ((cp = (char *) HTList_objectAt(jtp->history,
 					   ShortcutNum)) != NULL) {
-	    LYStrNCpy(buf, cp, sizeof(buf) - 1);
+	    BStrCopy0(buf, cp);
 	    if (jump_buffer && jtp->shortcut &&
-		!strcmp(buf, jtp->shortcut)) {
+		!strcmp(buf->str, jtp->shortcut)) {
 		_statusline(EDIT_CURRENT_SHORTCUT);
 	    } else if ((jump_buffer && ShortcutTotal == 2) ||
 		       (!jump_buffer && ShortcutTotal == 1)) {
@@ -299,8 +305,7 @@ char *LYJump(int key)
 	    } else {
 		_statusline(EDIT_A_PREV_SHORTCUT);
 	    }
-	    if ((ch = LYGetStr(buf, VISIBLE,
-			       sizeof(buf), recall)) < 0) {
+	    if ((ch = LYgetBString(&buf, VISIBLE, 0, recall)) < 0) {
 		/*
 		 * User cancelled the jump via ^G.
 		 */
@@ -329,9 +334,9 @@ char *LYJump(int key)
 	    ShortcutNum = ShortcutTotal - 1;
 	if ((cp = (char *) HTList_objectAt(jtp->history,
 					   ShortcutNum)) != NULL) {
-	    LYStrNCpy(buf, cp, sizeof(buf) - 1);
+	    BStrCopy0(buf, cp);
 	    if (jump_buffer && jtp->shortcut &&
-		!strcmp(buf, jtp->shortcut)) {
+		!strcmp(buf->str, jtp->shortcut)) {
 		_statusline(EDIT_CURRENT_SHORTCUT);
 	    } else if ((jump_buffer && ShortcutTotal == 2) ||
 		       (!jump_buffer && ShortcutTotal == 1)) {
@@ -339,7 +344,7 @@ char *LYJump(int key)
 	    } else {
 		_statusline(EDIT_A_PREV_SHORTCUT);
 	    }
-	    if ((ch = LYGetStr(buf, VISIBLE, sizeof(buf), recall)) < 0) {
+	    if ((ch = LYgetBString(&buf, VISIBLE, 0, recall)) < 0) {
 		/*
 		 * User cancelled the jump via ^G.
 		 */
@@ -354,7 +359,7 @@ char *LYJump(int key)
     found = (JumpDatum *) bsearch((char *) &seeking, (char *) jtp->table,
 				  (size_t) jtp->nel, sizeof(JumpDatum), LYCompare);
     if (!found) {
-	user_message("Unknown target '%s'", buf);
+	user_message("Unknown target '%s'", buf->str);
 	LYSleepAlert();
     }
 
diff --git a/src/LYLocal.c b/src/LYLocal.c
index 07c502cb..f4b23208 100644
--- a/src/LYLocal.c
+++ b/src/LYLocal.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYLocal.c,v 1.115 2011/10/07 00:41:24 tom Exp $
+ * $LynxId: LYLocal.c,v 1.117 2012/02/08 20:32:47 tom Exp $
  *
  *  Routines to manipulate the local filesystem.
  *  Written by: Rick Mallett, Carleton University
@@ -79,9 +79,8 @@
 #endif /* FNAMES_8_3 */
 #endif /* OK_INSTALL */
 
-static char *get_filename(const char *prompt,
-			  char *buf,
-			  size_t bufsize);
+static int get_filename(const char *prompt,
+			bstring *buf);
 
 #ifdef OK_PERMIT
 static int permit_location(char *destpath,
@@ -791,7 +790,7 @@ static char *parse_directory(char *path)
 static int modify_tagged(char *testpath)
 {
     char *cp;
-    char given_target[MAX_LINE];
+    bstring *given_target = NULL;
     char *dst_path = NULL;
     char *src_path = NULL;
     char *old_path = NULL;
@@ -807,39 +806,35 @@ static int modify_tagged(char *testpath)
 
     _statusline(gettext("Enter new location for tagged items: "));
 
-    given_target[0] = '\0';
-    LYGetStr(given_target, VISIBLE, sizeof(given_target), NORECALL);
-    if (strlen(given_target)) {
+    BStrCopy0(given_target, "");
+    LYgetBString(&given_target, VISIBLE, 0, NORECALL);
+    if (!isBEmpty(given_target)) {
 	/*
 	 * Replace ~/ references to the home directory.
 	 */
-	if (LYIsTilde(given_target[0]) && LYIsPathSep(given_target[1])) {
+	if (LYIsTilde(given_target->str[0]) && LYIsPathSep(given_target->str[1])) {
 	    char *cp1 = NULL;
 
 	    StrAllocCopy(cp1, Home_Dir());
-	    StrAllocCat(cp1, (given_target + 1));
-	    if (strlen(cp1) > (sizeof(given_target) - 1)) {
-		HTAlert(gettext("Path too long"));
-		FREE(cp1);
-		return 0;
-	    }
-	    LYStrNCpy(given_target, cp1, sizeof(given_target) - 1);
+	    StrAllocCat(cp1, (given_target->str + 1));
+	    BStrCopy0(given_target, cp1);
 	    FREE(cp1);
 	}
 
 	/*
 	 * If path is relative, prefix it with current location.
 	 */
-	if (!LYIsPathSep(given_target[0])) {
+	if (!LYIsPathSep(given_target->str[0])) {
 	    dst_path = HTLocalName(testpath);
 	    LYAddPathSep(&dst_path);
-	    StrAllocCat(dst_path, given_target);
+	    StrAllocCat(dst_path, given_target->str);
 	} else {
-	    dst_path = HTLocalName(given_target);
+	    dst_path = HTLocalName(given_target->str);
 	}
 
 	if (!ok_stat(dst_path, &dst_info)) {
 	    FREE(dst_path);
+	    BStrFree(given_target);
 	    return 0;
 	}
 
@@ -855,6 +850,7 @@ static int modify_tagged(char *testpath)
 		    || same_location(&src_info, &dst_info)
 		    || !dir_has_same_owner(&dst_info, &src_info)) {
 		    FREE(src_path);
+		    BStrFree(given_target);
 		    return 0;
 		}
 	    }
@@ -880,6 +876,7 @@ static int modify_tagged(char *testpath)
 	FREE(src_path);
 	FREE(dst_path);
     }
+    BStrFree(given_target);
     return count;
 }
 
@@ -889,7 +886,7 @@ static int modify_tagged(char *testpath)
 static int modify_name(char *testpath)
 {
     const char *cp;
-    char tmpbuf[DIRED_MAXBUF];
+    bstring *tmpbuf = NULL;
     char *newpath = NULL;
     struct stat dir_info;
     int code = 0;
@@ -900,6 +897,7 @@ static int modify_name(char *testpath)
     testpath = strip_trailing_slash(testpath);
 
     if (ok_stat(testpath, &dir_info)) {
+
 	/*
 	 * Change the name of the file or directory.
 	 */
@@ -910,32 +908,35 @@ static int modify_name(char *testpath)
 	} else {
 	    return ok_file_or_dir(&dir_info);
 	}
-	LYStrNCpy(tmpbuf, LYPathLeaf(testpath), sizeof(tmpbuf) - 1);
-	if (get_filename(cp, tmpbuf, sizeof(tmpbuf)) == NULL)
-	    return 0;
 
-	/*
-	 * Do not allow the user to also change the location at this time.
-	 */
-	if (LYLastPathSep(tmpbuf) != 0) {
-	    HTAlert(gettext("Illegal character (path-separator) found! Request ignored."));
-	} else if (strlen(tmpbuf)) {
-	    if ((cp = LYLastPathSep(testpath)) != NULL)
-		HTSprintf0(&newpath, "%.*s%s",
-			   (int) (cp - testpath + 1), testpath, tmpbuf);
-	    else
-		StrAllocCopy(newpath, tmpbuf);
+	BStrCopy0(tmpbuf, LYPathLeaf(testpath));
+	if (get_filename(cp, tmpbuf)) {
 
 	    /*
-	     * Make sure the destination does not already exist.
+	     * Do not allow the user to also change the location at this time.
 	     */
-	    if (not_already_exists(newpath)) {
-		code = move_file(testpath, newpath);
-	    }
-	    FREE(newpath);
+	    if (LYLastPathSep(tmpbuf->str) != 0) {
+		HTAlert(gettext("Illegal character (path-separator) found! Request ignored."));
+	    } else if (strlen(tmpbuf->str)) {
+		if ((cp = LYLastPathSep(testpath)) != NULL) {
+		    HTSprintf0(&newpath, "%.*s%s",
+			       (int) (cp - testpath + 1),
+			       testpath, tmpbuf->str);
+		} else {
+		    StrAllocCopy(newpath, tmpbuf->str);
+		}
 
+		/*
+		 * Make sure the destination does not already exist.
+		 */
+		if (not_already_exists(newpath)) {
+		    code = move_file(testpath, newpath);
+		}
+		FREE(newpath);
+	    }
 	}
     }
+    BStrFree(tmpbuf);
     return code;
 }
 
@@ -946,7 +947,7 @@ static int modify_location(char *testpath)
 {
     const char *cp;
     char *sp;
-    char tmpbuf[MAX_LINE];
+    bstring *tmpbuf = NULL;
     char *newpath = NULL;
     char *savepath = NULL;
     struct stat old_info;
@@ -971,49 +972,52 @@ static int modify_location(char *testpath)
     } else {
 	return ok_file_or_dir(&dir_info);
     }
-    LYStrNCpy(tmpbuf, testpath, sizeof(tmpbuf) - 1);
-    *LYPathLeaf(tmpbuf) = '\0';
-    if (get_filename(cp, tmpbuf, sizeof(tmpbuf)) == NULL)
-	return 0;
-    if (strlen(tmpbuf)) {
-	StrAllocCopy(savepath, testpath);
-	StrAllocCopy(newpath, testpath);
 
-	/*
-	 * Allow ~/ references to the home directory.
-	 */
-	if (LYIsTilde(tmpbuf[0])
-	    && (tmpbuf[1] == '\0' || LYIsPathSep(tmpbuf[1]))) {
-	    StrAllocCopy(newpath, Home_Dir());
-	    StrAllocCat(newpath, (tmpbuf + 1));
-	    LYStrNCpy(tmpbuf, newpath, sizeof(tmpbuf) - 1);
-	}
-	if (LYisAbsPath(tmpbuf)) {
-	    StrAllocCopy(newpath, tmpbuf);
-	} else if ((sp = LYLastPathSep(newpath)) != NULL) {
-	    *++sp = '\0';
-	    StrAllocCat(newpath, tmpbuf);
-	} else {
-	    HTAlert(gettext("Unexpected failure - unable to find trailing path separator"));
+    BStrCopy0(tmpbuf, testpath);
+    *LYPathLeaf(tmpbuf->str) = '\0';
+    if (get_filename(cp, tmpbuf)) {
+	if (strlen(tmpbuf->str)) {
+	    StrAllocCopy(savepath, testpath);
+	    StrAllocCopy(newpath, testpath);
+
+	    /*
+	     * Allow ~/ references to the home directory.
+	     */
+	    if (LYIsTilde(tmpbuf->str[0])
+		&& (tmpbuf->str[1] == '\0' || LYIsPathSep(tmpbuf->str[1]))) {
+		StrAllocCopy(newpath, Home_Dir());
+		StrAllocCat(newpath, (tmpbuf->str + 1));
+		BStrCopy0(tmpbuf, newpath);
+	    }
+	    if (LYisAbsPath(tmpbuf->str)) {
+		StrAllocCopy(newpath, tmpbuf->str);
+	    } else if ((sp = LYLastPathSep(newpath)) != NULL) {
+		*++sp = '\0';
+		StrAllocCat(newpath, tmpbuf->str);
+	    } else {
+		HTAlert(gettext("Unexpected failure - unable to find trailing path separator"));
+		FREE(newpath);
+		FREE(savepath);
+		BStrFree(tmpbuf);
+		return 0;
+	    }
+
+	    /*
+	     * Make sure the source and target have the same owner (uid).
+	     */
+	    old_info = dir_info;
+	    if (!ok_stat(newpath, &dir_info)) {
+		code = 0;
+	    } else if (same_location(&old_info, &dir_info)) {
+		code = 0;
+	    } else if (dir_has_same_owner(&dir_info, &old_info)) {
+		code = move_file(savepath, newpath);
+	    }
 	    FREE(newpath);
 	    FREE(savepath);
-	    return 0;
-	}
-
-	/*
-	 * Make sure the source and target have the same owner (uid).
-	 */
-	old_info = dir_info;
-	if (!ok_stat(newpath, &dir_info)) {
-	    code = 0;
-	} else if (same_location(&old_info, &dir_info)) {
-	    code = 0;
-	} else if (dir_has_same_owner(&dir_info, &old_info)) {
-	    code = move_file(savepath, newpath);
 	}
-	FREE(newpath);
-	FREE(savepath);
     }
+    BStrFree(tmpbuf);
     return code;
 }
 
@@ -1024,8 +1028,9 @@ int local_modify(DocInfo *doc, char **newpath)
 {
     int ans;
     char *cp;
-    char testpath[DIRED_MAXBUF];	/* a bit ridiculous */
+    bstring *testpath = NULL;
     int count;
+    int code = 0;
 
     if (!HTList_isEmpty(tagged)) {
 	cp = HTpartURL_toFile(doc->address);
@@ -1064,20 +1069,20 @@ int local_modify(DocInfo *doc, char **newpath)
 	    FREE(cp);
 	    return 0;
 	}
-	LYStrNCpy(testpath, cp, sizeof(testpath) - 1);
+	BStrCopy0(testpath, cp);
 	FREE(cp);
 
 	if (ans == 'N') {
-	    return modify_name(testpath);
+	    code = modify_name(testpath->str);
 	} else if (ans == 'L') {
-	    if (modify_location(testpath)) {
+	    if (modify_location(testpath->str)) {
 		if (doc->link == (nlinks - 1))
 		    --doc->link;
-		return 1;
+		code = 1;
 	    }
 #ifdef OK_PERMIT
 	} else if (ans == 'P') {
-	    return (permit_location(NULL, testpath, newpath));
+	    code = permit_location(NULL, testpath->str, newpath);
 #endif /* OK_PERMIT */
 	} else {
 	    /*
@@ -1086,7 +1091,8 @@ int local_modify(DocInfo *doc, char **newpath)
 	    HTAlert(gettext("This feature not yet implemented!"));
 	}
     }
-    return 0;
+    BStrFree(testpath);
+    return code;
 }
 
 #define BadChars() ((!no_dotfiles && show_dotfiles) \
@@ -1099,23 +1105,23 @@ int local_modify(DocInfo *doc, char **newpath)
 static int create_file(char *current_location)
 {
     int code = FALSE;
-    char tmpbuf[DIRED_MAXBUF];
+    bstring *tmpbuf = NULL;
     char *testpath = NULL;
 
-    tmpbuf[0] = '\0';
-    if (get_filename(gettext("Enter name of file to create: "),
-		     tmpbuf, sizeof(tmpbuf)) != NULL) {
+    BStrCopy0(tmpbuf, "");
+    if (get_filename(gettext("Enter name of file to create: "), tmpbuf)) {
 
-	if (strstr(tmpbuf, "//") != NULL) {
+	if (strstr(tmpbuf->str, "//") != NULL) {
 	    HTAlert(gettext("Illegal redirection \"//\" found! Request ignored."));
-	} else if (strlen(tmpbuf) && strchr(BadChars(), tmpbuf[0]) == NULL) {
+	} else if (strlen(tmpbuf->str) &&
+		   strchr(BadChars(), tmpbuf->str[0]) == NULL) {
 	    StrAllocCopy(testpath, current_location);
 	    LYAddPathSep(&testpath);
 
 	    /*
 	     * Append the target filename to the current location.
 	     */
-	    StrAllocCat(testpath, tmpbuf);
+	    StrAllocCat(testpath, tmpbuf->str);
 
 	    /*
 	     * Make sure the target does not already exist
@@ -1126,6 +1132,7 @@ static int create_file(char *current_location)
 	    FREE(testpath);
 	}
     }
+    BStrFree(tmpbuf);
     return code;
 }
 
@@ -1135,20 +1142,20 @@ static int create_file(char *current_location)
 static int create_directory(char *current_location)
 {
     int code = FALSE;
-    char tmpbuf[DIRED_MAXBUF];
+    bstring *tmpbuf = NULL;
     char *testpath = NULL;
 
-    tmpbuf[0] = '\0';
-    if (get_filename(gettext("Enter name for new directory: "),
-		     tmpbuf, sizeof(tmpbuf)) != NULL) {
+    BStrCopy0(tmpbuf, "");
+    if (get_filename(gettext("Enter name for new directory: "), tmpbuf)) {
 
-	if (strstr(tmpbuf, "//") != NULL) {
+	if (strstr(tmpbuf->str, "//") != NULL) {
 	    HTAlert(gettext("Illegal redirection \"//\" found! Request ignored."));
-	} else if (strlen(tmpbuf) && strchr(BadChars(), tmpbuf[0]) == NULL) {
+	} else if (strlen(tmpbuf->str) &&
+		   strchr(BadChars(), tmpbuf->str[0]) == NULL) {
 	    StrAllocCopy(testpath, current_location);
 	    LYAddPathSep(&testpath);
 
-	    StrAllocCat(testpath, tmpbuf);
+	    StrAllocCat(testpath, tmpbuf->str);
 
 	    /*
 	     * Make sure the target does not already exist.
@@ -1159,6 +1166,7 @@ static int create_directory(char *current_location)
 	    FREE(testpath);
 	}
     }
+    BStrFree(tmpbuf);
     return code;
 }
 
@@ -1300,7 +1308,7 @@ int local_remove(DocInfo *doc)
 
 #ifdef OK_PERMIT
 
-static char LYValidPermitFile[LY_MAXPATH] = "\0";
+static bstring *LYValidPermitFile = NULL;
 
 static long permit_bits(char *string_mode)
 {
@@ -1376,9 +1384,7 @@ static int permit_location(char *destpath,
 	LYRegisterUIPage(*newpath, UIP_PERMIT_OPTIONS);
 
 	group_name = HTAA_GidToName((int) dir_info.st_gid);
-	LYStrNCpy(LYValidPermitFile,
-		  srcpath,
-		  (sizeof(LYValidPermitFile) - 1));
+	BStrCopy0(LYValidPermitFile, srcpath);
 
 	fprintf(fp0, "<Html><Head>\n<Title>%s</Title>\n</Head>\n<Body>\n",
 		PERMIT_OPTIONS_TITLE);
@@ -1462,7 +1468,7 @@ static int permit_location(char *destpath,
 	 * Make sure we have a valid set-permission file comparison string
 	 * loaded via a previous call with srcpath != NULL.  - KW
 	 */
-	if (LYValidPermitFile[0] == '\0') {
+	if (isBEmpty(LYValidPermitFile)) {
 	    if (LYCursesON)
 		HTAlert(INVALID_PERMIT_URL);
 	    else
@@ -1497,7 +1503,7 @@ static int permit_location(char *destpath,
 	 * Make sure that the file string is the one from the last displayed
 	 * File Permissions menu.  - KW
 	 */
-	if (strcmp(destpath, LYValidPermitFile)) {
+	if (strcmp(destpath, LYValidPermitFile->str)) {
 	    if (LYCursesON)
 		HTAlert(INVALID_PERMIT_URL);
 	    else
@@ -2195,34 +2201,31 @@ int dired_options(DocInfo *doc, char **newfile)
 }
 
 /*
- * Check DIRED filename.
+ * Check DIRED filename, return true on success
  */
-static char *get_filename(const char *prompt,
-			  char *buf,
-			  size_t bufsize)
+static int get_filename(const char *prompt,
+			bstring *buf)
 {
     char *cp;
 
     _statusline(prompt);
 
-    LYGetStr(buf, VISIBLE, bufsize, NORECALL);
-    if (strstr(buf, "../") != NULL) {
+    LYgetBString(&buf, VISIBLE, 0, NORECALL);
+    if (strstr(buf->str, "../") != NULL) {
 	HTAlert(gettext("Illegal filename; request ignored."));
-	return NULL;
-    }
-
-    if (no_dotfiles || !show_dotfiles) {
-	cp = LYLastPathSep(buf);	/* find last slash */
+	return FALSE;
+    } else if (no_dotfiles || !show_dotfiles) {
+	cp = LYLastPathSep(buf->str);	/* find last slash */
 	if (cp)
 	    cp += 1;
 	else
-	    cp = buf;
+	    cp = buf->str;
 	if (*cp == '.') {
 	    HTAlert(gettext("Illegal filename; request ignored."));
-	    return NULL;
+	    return FALSE;
 	}
     }
-    return buf;
+    return !isBEmpty(buf);
 }
 
 #ifdef OK_INSTALL
diff --git a/src/LYMainLoop.c b/src/LYMainLoop.c
index 72160e92..e64c8830 100644
--- a/src/LYMainLoop.c
+++ b/src/LYMainLoop.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYMainLoop.c,v 1.183 2012/02/07 00:36:19 tom Exp $
+ * $LynxId: LYMainLoop.c,v 1.187 2012/02/09 01:55:58 tom Exp $
  */
 #include <HTUtils.h>
 #include <HTAccess.h>
@@ -182,7 +182,7 @@ HTList *Goto_URLs = NULL;	/* List of Goto URLs */
 char *LYRequestTitle = NULL;	/* newdoc.title in calls to getfile() */
 char *LYRequestReferer = NULL;	/* Referer, may be set in getfile() */
 
-static char prev_target[MAX_LINE];
+static bstring *prev_target = NULL;
 
 #ifdef DISP_PARTIAL
 BOOLEAN display_partial = FALSE;	/* could be enabled in HText_new() */
@@ -504,7 +504,7 @@ BOOL LYMainLoop_pageDisplay(int line_num)
 	    }
 	}
 
-    HText_pageDisplay(LYGetNewline(), prev_target);
+    HText_pageDisplay(LYGetNewline(), prev_target->str);
     return YES;
 }
 #endif /* DISP_PARTIAL */
@@ -517,7 +517,7 @@ static BOOL set_curdoc_link(int nextlink)
 	&& nextlink >= 0
 	&& nextlink < nlinks) {
 	if (curdoc.link >= 0 && curdoc.link < nlinks) {
-	    LYhighlight(FALSE, curdoc.link, prev_target);
+	    LYhighlight(FALSE, curdoc.link, prev_target->str);
 	    result = TRUE;
 	}
 	curdoc.link = nextlink;
@@ -552,7 +552,7 @@ static void goto_line(int nextline)
 static void set_curdoc_link_by_mouse(int nextlink)
 {
     if (set_curdoc_link(nextlink)) {
-	LYhighlight(TRUE, nextlink, prev_target);
+	LYhighlight(TRUE, nextlink, prev_target->str);
 	LYmsec_delay(20);
     }
 }
@@ -591,7 +591,7 @@ static int do_change_link(void)
 			else HTuncache_current_document()
 #endif /* DIRED_SUPPORT */
 
-static void do_check_goto_URL(char *user_input_buffer,
+static void do_check_goto_URL(bstring *user_input_buffer,
 			      char **old_user_input,
 			      BOOLEAN *force_load)
 {
@@ -646,28 +646,29 @@ static void do_check_goto_URL(char *user_input_buffer,
     BOOLEAN found = FALSE;
 
     /* allow going to anchors */
-    if (*user_input_buffer == '#') {
-	if (user_input_buffer[1] &&
-	    HTFindPoundSelector(user_input_buffer + 1)) {
+    if (user_input_buffer->str[0] == '#') {
+	if (user_input_buffer->str[1] &&
+	    HTFindPoundSelector(user_input_buffer->str + 1)) {
 	    /* HTFindPoundSelector will initialize www_search_result,
 	       so we do nothing else. */
-	    HTAddGotoURL(user_input_buffer);
+	    HTAddGotoURL(user_input_buffer->str);
 	    trimPoundSelector(curdoc.address);
-	    StrAllocCat(curdoc.address, user_input_buffer);
+	    StrAllocCat(curdoc.address, user_input_buffer->str);
 	}
     } else {
 	/*
 	 * If it's not a URL then make it one.
 	 */
-	StrAllocCopy(*old_user_input, user_input_buffer);
+	StrAllocCopy(*old_user_input, user_input_buffer->str);
 	LYEnsureAbsoluteURL(old_user_input, "", TRUE);
-	sprintf(user_input_buffer, "%.*s",
-		(int) (MAX_LINE - 1), *old_user_input);
+	BStrCopy0(user_input_buffer, *old_user_input);
 	FREE(*old_user_input);
 
 	for (n = 0; n < TABLESIZE(table); n++) {
 	    if (*(table[n].flag)
-		&& !StrNCmp(user_input_buffer, table[n].name, strlen(table[n].name))) {
+		&& !StrNCmp(user_input_buffer->str,
+			    table[n].name,
+			    strlen(table[n].name))) {
 		found = TRUE;
 		HTUserMsg2(GOTO_XXXX_DISALLOWED, table[n].name);
 		break;
@@ -676,12 +677,12 @@ static void do_check_goto_URL(char *user_input_buffer,
 	if (found) {
 	    ;
 	} else if (LYValidate &&
-		   !isHTTP_URL(user_input_buffer) &&
-		   !isHTTPS_URL(user_input_buffer)) {
+		   !isHTTP_URL(user_input_buffer->str) &&
+		   !isHTTPS_URL(user_input_buffer->str)) {
 	    HTUserMsg(GOTO_NON_HTTP_DISALLOWED);
 
 	} else {
-	    set_address(&newdoc, user_input_buffer);
+	    set_address(&newdoc, user_input_buffer->str);
 	    newdoc.isHEAD = FALSE;
 	    /*
 	     * Might be an anchor in the same doc from a POST form.  If so,
@@ -712,7 +713,7 @@ static void do_check_goto_URL(char *user_input_buffer,
 
 /* returns FALSE if user cancelled input or URL was invalid, TRUE otherwise */
 static BOOL do_check_recall(int ch,
-			    char *user_input_buffer,
+			    bstring *user_input_buffer,
 			    char **old_user_input,
 			    int URLTotal,
 			    int *URLNum,
@@ -727,20 +728,20 @@ static BOOL do_check_recall(int ch,
 
     for (;;) {
 #ifdef WIN_EX			/* 1998/10/11 (Sun) 10:41:05 */
-	int len = strlen(user_input_buffer);
+	int len = strlen(user_input_buffer->str);
 
 	if (len >= 3) {
 	    if (len < MAX_LINE - 1
-		&& LYIsHtmlSep(user_input_buffer[len - 3])
-		&& LYIsDosDrive(user_input_buffer + len - 2))
-		LYAddPathSep0(user_input_buffer);
+		&& LYIsHtmlSep(user_input_buffer->str[len - 3])
+		&& LYIsDosDrive(user_input_buffer->str + len - 2))
+		LYAddPathSep0(user_input_buffer->str);
 
-	} else if (len == 2 && user_input_buffer[1] == ':') {
-	    if (LYIsDosDrive(user_input_buffer)) {
-		LYAddPathSep0(user_input_buffer);
+	} else if (len == 2 && user_input_buffer->str[1] == ':') {
+	    if (LYIsDosDrive(user_input_buffer->str)) {
+		LYAddPathSep0(user_input_buffer->str);
 	    } else {
-		HTUserMsg2(WWW_ILLEGAL_URL_MESSAGE, user_input_buffer);
-		LYStrNCpy(user_input_buffer, *old_user_input, MAX_LINE - 1);
+		HTUserMsg2(WWW_ILLEGAL_URL_MESSAGE, user_input_buffer->str);
+		BStrCopy0(user_input_buffer, *old_user_input);
 		FREE(*old_user_input);
 		ret = FALSE;
 		break;
@@ -750,10 +751,10 @@ static BOOL do_check_recall(int ch,
 	/*
 	 * Get rid of leading spaces (and any other spaces).
 	 */
-	LYTrimAllStartfile(user_input_buffer);
-	if (*user_input_buffer == '\0' &&
+	LYTrimAllStartfile(user_input_buffer->str);
+	if (isBEmpty(user_input_buffer) &&
 	    !(recall && (ch == UPARROW || ch == DNARROW))) {
-	    LYStrNCpy(user_input_buffer, *old_user_input, MAX_LINE - 1);
+	    BStrCopy0(user_input_buffer, *old_user_input);
 	    FREE(*old_user_input);
 	    HTInfoMsg(CANCELLED);
 	    ret = FALSE;
@@ -779,10 +780,10 @@ static BOOL do_check_recall(int ch,
 		*URLNum = 0;
 	    if ((cp = (char *) HTList_objectAt(Goto_URLs,
 					       *URLNum)) != NULL) {
-		LYStrNCpy(user_input_buffer, cp, MAX_LINE - 1);
+		BStrCopy0(user_input_buffer, cp);
 		if (goto_buffer
 		    && **old_user_input
-		    && !strcmp(*old_user_input, user_input_buffer)) {
+		    && !strcmp(*old_user_input, user_input_buffer->str)) {
 		    _statusline(EDIT_CURRENT_GOTO);
 		} else if ((goto_buffer && URLTotal == 2) ||
 			   (!goto_buffer && URLTotal == 1)) {
@@ -790,14 +791,13 @@ static BOOL do_check_recall(int ch,
 		} else {
 		    _statusline(EDIT_A_PREV_GOTO);
 		}
-		if ((ch = LYGetStr(user_input_buffer, VISIBLE,
-				   (size_t) MAX_LINE,
-				   recall)) < 0) {
+		if ((ch = LYgetBString(&user_input_buffer,
+				       VISIBLE, 0, recall)) < 0) {
 		    /*
 		     * User cancelled the Goto via ^G.  Restore
 		     * user_input_buffer and break.  - FM
 		     */
-		    LYStrNCpy(user_input_buffer, *old_user_input, MAX_LINE - 1);
+		    BStrCopy0(user_input_buffer, *old_user_input);
 		    FREE(*old_user_input);
 		    HTInfoMsg(CANCELLED);
 		    ret = FALSE;
@@ -824,9 +824,9 @@ static BOOL do_check_recall(int ch,
 		 */
 		*URLNum = URLTotal - 1;
 	    if ((cp = (char *) HTList_objectAt(Goto_URLs, *URLNum)) != NULL) {
-		LYStrNCpy(user_input_buffer, cp, MAX_LINE - 1);
+		BStrCopy0(user_input_buffer, cp);
 		if (goto_buffer && **old_user_input &&
-		    !strcmp(*old_user_input, user_input_buffer)) {
+		    !strcmp(*old_user_input, user_input_buffer->str)) {
 		    _statusline(EDIT_CURRENT_GOTO);
 		} else if ((goto_buffer && URLTotal == 2) ||
 			   (!goto_buffer && URLTotal == 1)) {
@@ -834,14 +834,13 @@ static BOOL do_check_recall(int ch,
 		} else {
 		    _statusline(EDIT_A_PREV_GOTO);
 		}
-		if ((ch = LYGetStr(user_input_buffer, VISIBLE,
-				   (size_t) MAX_LINE,
-				   recall)) < 0) {
+		if ((ch = LYgetBString(&user_input_buffer,
+				       VISIBLE, 0, recall)) < 0) {
 		    /*
 		     * User cancelled the Goto via ^G.  Restore
 		     * user_input_buffer and break.  - FM
 		     */
-		    LYStrNCpy(user_input_buffer, *old_user_input, MAX_LINE - 1);
+		    BStrCopy0(user_input_buffer, *old_user_input);
 		    FREE(*old_user_input);
 		    HTInfoMsg(CANCELLED);
 		    ret = FALSE;
@@ -1703,16 +1702,16 @@ static void handle_LYK_CLEAR_AUTH(int *old_c,
     }
 }
 
-static int handle_LYK_COMMAND(char *user_input_buffer)
+static int handle_LYK_COMMAND(bstring *user_input_buffer)
 {
     LYKeymapCode ch;
     Kcmd *mp;
     char *src, *tmp;
 
-    *user_input_buffer = 0;
+    BStrCopy0(user_input_buffer, "");
     _statusline(": ");
-    if (LYGetStr(user_input_buffer, VISIBLE, (size_t) MAX_LINE, RECALL_CMD) >= 0) {
-	src = LYSkipBlanks(user_input_buffer);
+    if (LYgetBString(&user_input_buffer, VISIBLE, 0, RECALL_CMD) >= 0) {
+	src = LYSkipBlanks(user_input_buffer->str);
 	tmp = LYSkipNonBlanks(src);
 	*tmp = 0;
 	ch = ((mp = LYStringToKcmd(src)) != 0) ? mp->code : LYK_UNKNOWN;
@@ -2365,7 +2364,7 @@ static int handle_LYK_DWIMEDIT(int *cmd,
 }
 
 static int handle_LYK_ECGOTO(int *ch,
-			     char *user_input_buffer,
+			     bstring *user_input_buffer,
 			     char **old_user_input,
 			     int *old_c,
 			     int real_c)
@@ -2399,10 +2398,8 @@ static int handle_LYK_ECGOTO(int *ch,
      * Save the current user_input_buffer string, and load the current
      * document's address.
      */
-    StrAllocCopy(*old_user_input, user_input_buffer);
-    LYStrNCpy(user_input_buffer,
-	      curdoc.address,
-	      (MAX_LINE - 1));
+    StrAllocCopy(*old_user_input, user_input_buffer->str);
+    BStrCopy0(user_input_buffer, curdoc.address);
 
     /*
      * Warn the user if the current document has POST data associated with it. 
@@ -2415,12 +2412,12 @@ static int handle_LYK_ECGOTO(int *ch,
      * Offer the current document's URL for editing.  - FM
      */
     _statusline(EDIT_CURDOC_URL);
-    if (((*ch = LYGetStr(user_input_buffer, VISIBLE,
-			 MAX_LINE, RECALL_URL)) >= 0) &&
-	user_input_buffer[0] != '\0' &&
-	strcmp(user_input_buffer, curdoc.address)) {
-	LYTrimAllStartfile(user_input_buffer);
-	if (user_input_buffer[0] != '\0') {
+    if (((*ch = LYgetBString(&user_input_buffer, VISIBLE,
+			     0, RECALL_URL)) >= 0) &&
+	!isBEmpty(user_input_buffer) &&
+	strcmp(user_input_buffer->str, curdoc.address)) {
+	LYTrimAllStartfile(user_input_buffer->str);
+	if (!isBEmpty(user_input_buffer)) {
 	    return 2;
 	}
     }
@@ -2428,7 +2425,7 @@ static int handle_LYK_ECGOTO(int *ch,
      * User cancelled via ^G, a full deletion, or not modifying the URL.  - FM
      */
     HTInfoMsg(CANCELLED);
-    LYStrNCpy(user_input_buffer, *old_user_input, MAX_LINE - 1);
+    BStrCopy0(user_input_buffer, *old_user_input);
     FREE(*old_user_input);
     return 0;
 }
@@ -2590,7 +2587,7 @@ static void handle_LYK_EDIT_TEXTAREA(BOOLEAN *refresh_screen,
 }
 
 static int handle_LYK_ELGOTO(int *ch,
-			     char *user_input_buffer,
+			     bstring *user_input_buffer,
 			     char **old_user_input,
 			     int *old_c,
 			     int real_c)
@@ -2651,26 +2648,24 @@ static int handle_LYK_ELGOTO(int *ch,
      * Save the current user_input_buffer string, and load the current link's
      * address.  - FM
      */
-    StrAllocCopy(*old_user_input, user_input_buffer);
-    LYStrNCpy(user_input_buffer,
+    StrAllocCopy(*old_user_input, user_input_buffer->str);
+    BStrCopy0(user_input_buffer,
 	      ((links[curdoc.link].type == WWW_FORM_LINK_TYPE)
-	       ?
-	       links[curdoc.link].l_form->submit_action : links[curdoc.link].lname),
-	      (MAX_LINE - 1));
-
+	       ? links[curdoc.link].l_form->submit_action
+	       : links[curdoc.link].lname));
     /*
      * Offer the current link's URL for editing.  - FM
      */
     _statusline(EDIT_CURLINK_URL);
-    if (((*ch = LYGetStr(user_input_buffer, VISIBLE,
-			 MAX_LINE, RECALL_URL)) >= 0) &&
-	user_input_buffer[0] != '\0' &&
-	strcmp(user_input_buffer,
+    if (((*ch = LYgetBString(&user_input_buffer, VISIBLE,
+			     0, RECALL_URL)) >= 0) &&
+	!isBEmpty(user_input_buffer) &&
+	strcmp(user_input_buffer->str,
 	       ((links[curdoc.link].type == WWW_FORM_LINK_TYPE)
 		? links[curdoc.link].l_form->submit_action
 		: links[curdoc.link].lname))) {
-	LYTrimAllStartfile(user_input_buffer);
-	if (user_input_buffer[0] != '\0') {
+	LYTrimAllStartfile(user_input_buffer->str);
+	if (!isBEmpty(user_input_buffer)) {
 	    return 2;
 	}
     }
@@ -2678,7 +2673,7 @@ static int handle_LYK_ELGOTO(int *ch,
      * User cancelled via ^G, a full deletion, or not modifying the URL.  - FM
      */
     HTInfoMsg(CANCELLED);
-    LYStrNCpy(user_input_buffer, *old_user_input, MAX_LINE - 1);
+    BStrCopy0(user_input_buffer, *old_user_input);
     FREE(*old_user_input);
     return 0;
 }
@@ -2879,7 +2874,7 @@ static void handle_LYK_FIRST_LINK(void)
 }
 
 static BOOLEAN handle_LYK_GOTO(int *ch,
-			       char *user_input_buffer,
+			       bstring *user_input_buffer,
 			       char **old_user_input,
 			       RecallType * recall,
 			       int *URLTotal,
@@ -2897,12 +2892,12 @@ static BOOLEAN handle_LYK_GOTO(int *ch,
 	return FALSE;
     }
 
-    StrAllocCopy(*old_user_input, user_input_buffer);
+    StrAllocCopy(*old_user_input, user_input_buffer->str);
     if (!goto_buffer)
-	*user_input_buffer = '\0';
+	BStrCopy0(user_input_buffer, "");
 
     *URLTotal = (Goto_URLs ? HTList_count(Goto_URLs) : 0);
-    if (goto_buffer && *user_input_buffer) {
+    if (goto_buffer && !isBEmpty(user_input_buffer)) {
 	*recall = ((*URLTotal > 1) ? RECALL_URL : NORECALL);
 	*URLNum = 0;
 	*FirstURLRecall = FALSE;
@@ -2916,13 +2911,12 @@ static BOOLEAN handle_LYK_GOTO(int *ch,
      * Ask the user.
      */
     _statusline(URL_TO_OPEN);
-    if ((*ch = LYGetStr(user_input_buffer, VISIBLE,
-			MAX_LINE, *recall)) < 0) {
+    if ((*ch = LYgetBString(&user_input_buffer, VISIBLE, 0, *recall)) < 0) {
 	/*
 	 * User cancelled the Goto via ^G.  Restore user_input_buffer and
 	 * break.  - FM
 	 */
-	LYStrNCpy(user_input_buffer, *old_user_input, MAX_LINE - 1);
+	BStrCopy0(user_input_buffer, *old_user_input);
 	FREE(*old_user_input);
 	HTInfoMsg(CANCELLED);
 	return FALSE;
@@ -3460,27 +3454,27 @@ static BOOLEAN check_JUMP_param(char **url_template)
     char *result = *url_template;
     char *encoded = NULL;
     int code = TRUE;
+    bstring *input = NULL;
 
     CTRACE((tfp, "check_JUMP_param: %s\n", result));
 
     while ((subs = strstr(result, "%s")) != 0) {
 	char prompt[MAX_LINE];
-	char input[MAX_LINE];
 	RecallType recall = NORECALL;
 
 	CTRACE((tfp, "Prompt for query param%d: %s\n", param, result));
 
 	sprintf(prompt, "Query param%d: ", param++);
 	statusline(prompt);
-	*input = '\0';
-	if (LYGetStr(input, VISIBLE, sizeof(input), recall) < 0) {
+	BStrCopy0(input, "");
+	if (LYgetBString(&input, VISIBLE, 0, recall) < 0) {
 	    /*
 	     * cancelled via ^G
 	     */
 	    HTInfoMsg(CANCELLED);
 	    code = FALSE;
 	    break;
-	} else if ((encoded = urlencode(input)) != '\0') {
+	} else if ((encoded = urlencode(input->str)) != '\0') {
 	    int subs_at = (int) (subs - result);
 	    int fill_in = (int) strlen(encoded) - 2;
 	    size_t have = strlen(result);
@@ -3494,7 +3488,7 @@ static BOOLEAN check_JUMP_param(char **url_template)
 		break;
 	    }
 
-	    CTRACE((tfp, "  reply: %s\n", input));
+	    CTRACE((tfp, "  reply: %s\n", input->str));
 	    CTRACE((tfp, "  coded: %s\n", encoded));
 
 	    result = update;
@@ -3512,6 +3506,7 @@ static BOOLEAN check_JUMP_param(char **url_template)
 	    break;
 	}
     }
+    BStrFree(input);
     FREE(encoded);
     *url_template = result;
     return TRUE;
@@ -3525,7 +3520,7 @@ static void fill_JUMP_Params(char **addressp)
 }
 
 static BOOLEAN handle_LYK_JUMP(int c,
-			       char *user_input_buffer,
+			       bstring *user_input_buffer,
 			       char **old_user_input GCC_UNUSED,
 			       RecallType * recall GCC_UNUSED,
 			       BOOLEAN *FirstURLRecall GCC_UNUSED,
@@ -3551,7 +3546,7 @@ static BOOLEAN handle_LYK_JUMP(int c,
 #ifdef PERMIT_GOTO_FROM_JUMP
 	    if (!strncasecomp(ret, "Go ", 3)) {
 		LYJumpFileURL = FALSE;
-		StrAllocCopy(*old_user_input, user_input_buffer);
+		StrAllocCopy(*old_user_input, user_input_buffer->str);
 		*URLTotal = (Goto_URLs ? HTList_count(Goto_URLs) : 0);
 		*recall = ((*URLTotal >= 1) ? RECALL_URL : NORECALL);
 		*URLNum = *URLTotal;
@@ -3566,14 +3561,14 @@ static BOOLEAN handle_LYK_JUMP(int c,
 		    return FALSE;
 		}
 		ret = HTParse((ret + 3), startfile, PARSE_ALL);
-		LYStrNCpy(user_input_buffer, ret, MAX_LINE - 1);
+		BStrCopy0(user_input_buffer, ret);
 		FREE(ret);
 		return TRUE;
 	    }
 #endif /* PERMIT_GOTO_FROM_JUMP */
 	    ret = HTParse(ret, startfile, PARSE_ALL);
 	    if (!LYTrimStartfile(ret)) {
-		LYRemoveBlanks(user_input_buffer);
+		LYRemoveBlanks(user_input_buffer->str);
 	    }
 	    if (!check_JUMP_param(&ret))
 		return FALSE;
@@ -3700,7 +3695,7 @@ static void handle_LYK_MAIN_MENU(int *old_c,
 	    newdoc.isHEAD = FALSE;
 	    newdoc.safe = FALSE;
 	    newdoc.internal_link = FALSE;
-	    LYhighlight(FALSE, curdoc.link, prev_target);
+	    LYhighlight(FALSE, curdoc.link, prev_target->str);
 #ifdef DIRED_SUPPORT
 	    if (lynx_edit_mode) {
 		DIRED_UNCACHE_2;
@@ -3960,7 +3955,7 @@ static void handle_LYK_NEXT_LINK(int c,
 				 int real_c)
 {
     if (curdoc.link < nlinks - 1) {	/* next link */
-	LYhighlight(FALSE, curdoc.link, prev_target);
+	LYhighlight(FALSE, curdoc.link, prev_target->str);
 #ifdef FASTTAB
 	/*
 	 * Move to different textarea if TAB in textarea.
@@ -4912,14 +4907,14 @@ static BOOLEAN handle_LYK_VLINKS(int *cmd,
 void handle_LYK_WHEREIS(int cmd,
 			BOOLEAN *refresh_screen)
 {
-    BOOLEAN have_target_onscreen = (BOOLEAN) (*prev_target != '\0' &&
+    BOOLEAN have_target_onscreen = (BOOLEAN) (!isBEmpty(prev_target) &&
 					      HText_pageHasPrevTarget());
     BOOL found;
     int oldcur = curdoc.link;	/* temporarily remember */
     char *remember_old_target = NULL;
 
     if (have_target_onscreen)
-	StrAllocCopy(remember_old_target, prev_target);
+	StrAllocCopy(remember_old_target, prev_target->str);
     else
 	StrAllocCopy(remember_old_target, "");
 
@@ -4928,9 +4923,9 @@ void handle_LYK_WHEREIS(int cmd,
 	 * Reset prev_target to force prompting for a new search string and to
 	 * turn off highlighting if no search string is entered by the user.
 	 */
-	*prev_target = '\0';
+	BStrCopy0(prev_target, "");
     }
-    found = textsearch(&curdoc, prev_target, (int) sizeof(prev_target) - 1,
+    found = textsearch(&curdoc, prev_target,
 		       (cmd == LYK_WHEREIS)
 		       ? 0
 		       : ((cmd == LYK_NEXT)
@@ -4957,9 +4952,9 @@ void handle_LYK_WHEREIS(int cmd,
 	       curdoc.link >= 0 && nlinks > 0 &&
 	       links[curdoc.link].ly >= (display_lines / 3)) {
 	*refresh_screen = TRUE;
-    } else if ((LYcase_sensitive && 0 != strcmp(prev_target,
+    } else if ((LYcase_sensitive && 0 != strcmp(prev_target->str,
 						remember_old_target)) ||
-	       (!LYcase_sensitive && 0 != strcasecomp8(prev_target,
+	       (!LYcase_sensitive && 0 != strcasecomp8(prev_target->str,
 						       remember_old_target))) {
 	*refresh_screen = TRUE;
     }
@@ -4971,7 +4966,6 @@ void handle_LYK_WHEREIS(int cmd,
  */
 static void handle_LYK_digit(int c,
 			     BOOLEAN *force_load,
-			     char *user_input_buffer,
 			     int *old_c,
 			     int real_c,
 			     BOOLEAN *try_internal GCC_UNUSED)
@@ -5026,7 +5020,7 @@ static void handle_LYK_digit(int c,
 			    newdoc.internal_link = curdoc.internal_link;
 			    HTInfoMsg(CANCELLED);
 			    if (nlinks > 0)
-				HText_pageDisplay(curdoc.line, prev_target);
+				HText_pageDisplay(curdoc.line, prev_target->str);
 			    break;
 			} else if (LYresubmit_posts) {
 			    /* If LYresubmit_posts is set, and the
@@ -5096,11 +5090,8 @@ static void handle_LYK_digit(int c,
 		     * the statusline entry, so issue a statusline message for
 		     * the typo-prone users (like me 8-).  - FM
 		     */
-		    StrAllocCopy(temp, user_input_buffer);
-		    sprintf(user_input_buffer,
-			    LINK_ALREADY_CURRENT, number);
-		    HTUserMsg(user_input_buffer);
-		    LYStrNCpy(user_input_buffer, temp, MAX_LINE - 1);
+		    HTSprintf0(&temp, LINK_ALREADY_CURRENT, number);
+		    HTUserMsg(temp);
 		    FREE(temp);
 		} else {
 		    /*
@@ -5129,11 +5120,8 @@ static void handle_LYK_digit(int c,
 	    } else if (!more_text) {
 		HTInfoMsg(ALREADY_AT_END);
 	    } else {
-		StrAllocCopy(temp, user_input_buffer);
-		sprintf(user_input_buffer,
-			ALREADY_AT_PAGE, number);
-		HTUserMsg(user_input_buffer);
-		LYStrNCpy(user_input_buffer, temp, MAX_LINE - 1);
+		HTSprintf0(&temp, ALREADY_AT_PAGE, number);
+		HTUserMsg(temp);
 		FREE(temp);
 	    }
 	}
@@ -5152,7 +5140,7 @@ static void handle_LYK_digit(int c,
 /* original implementation by VH */
 void handle_LYK_CHDIR(void)
 {
-    static char buf[LY_MAXPATH];
+    static bstring *buf = NULL;
     char *p = NULL;
 
     if (no_chdir) {
@@ -5161,18 +5149,16 @@ void handle_LYK_CHDIR(void)
     }
 
     _statusline(gettext("cd to:"));
-    /* some people may prefer automatic clearing of the previous user input,
-       here, to do this, just uncomment next line - VH */
-    /* buf[0]='\0'; */
-    if (LYGetStr(buf, VISIBLE, sizeof(buf) - 1, NORECALL) < 0 || !*buf) {
+    if (LYgetBString(&buf, VISIBLE, 0, NORECALL) < 0 || isBEmpty(buf)) {
 	HTInfoMsg(CANCELLED);
 	return;
     }
 
-    if (LYIsTilde(*buf) && (LYIsPathSep(buf[1]) || buf[1] == '\0')) {
-	HTSprintf0(&p, "%s%s", Home_Dir(), buf + 1);
+    if (LYIsTilde(buf->str[0]) &&
+	(LYIsPathSep(buf->str[1]) || buf->str[1] == '\0')) {
+	HTSprintf0(&p, "%s%s", Home_Dir(), buf->str + 1);
     } else {
-	StrAllocCopy(p, buf);
+	StrAllocCopy(p, buf->str);
     }
 
     CTRACE((tfp, "changing directory to '%s'\n", p));
@@ -5334,7 +5320,7 @@ static BOOLEAN handle_LYK_LINEWRAP_TOGGLE(int *cmd,
 	    code = reparse_or_reload(cmd);
 	}
     }
-    return code;
+    return (BOOLEAN) code;
 }
 #endif
 
@@ -5379,7 +5365,7 @@ int mainloop(void)
     int cmd = LYK_DO_NOTHING, real_cmd = LYK_DO_NOTHING;
     int getresult;
     int arrowup = FALSE, show_help = FALSE;
-    char user_input_buffer[MAX_LINE];
+    bstring *user_input_buffer = NULL;
     const char *cshelpfile = NULL;
     BOOLEAN first_file = TRUE;
     BOOLEAN popped_doc = FALSE;
@@ -5449,9 +5435,8 @@ int mainloop(void)
 #ifndef USE_SESSIONS
     nhist = 0;
 #endif
-    user_input_buffer[(sizeof(user_input_buffer) - 1)] = '\0';
-    *prev_target = '\0';
-    *user_input_buffer = '\0';
+    BStrCopy0(user_input_buffer, "");
+    BStrCopy0(prev_target, "");
 #ifdef LY_FIND_LEAKS
     atexit(free_mainloop_variables);
 #endif
@@ -5667,7 +5652,7 @@ int mainloop(void)
 	     * so they will be available in partial mode
 	     * (was previously implemented in case NORMAL).
 	     */
-	    *prev_target = '\0';	/* Reset for new coming document */
+	    BStrCopy0(prev_target, "");		/* Reset for new coming document */
 	    LYSetNewline(newdoc.line);	/* set for LYGetNewline() */
 
 #ifdef USE_PRETTYSRC
@@ -6428,7 +6413,7 @@ int mainloop(void)
 
 	    refresh_screen = FALSE;
 
-	    HText_pageDisplay(LYGetNewline(), prev_target);
+	    HText_pageDisplay(LYGetNewline(), prev_target->str);
 
 #ifdef DIRED_SUPPORT
 	    if (lynx_edit_mode && nlinks > 0 && !HTList_isEmpty(tagged))
@@ -6512,7 +6497,7 @@ int mainloop(void)
 #else
 	    LYclear();
 #endif /* FANCY_CURSES || USE_SLANG */
-	    HText_pageDisplay(LYGetNewline(), prev_target);
+	    HText_pageDisplay(LYGetNewline(), prev_target->str);
 
 #ifdef DIRED_SUPPORT
 	    if (lynx_edit_mode && nlinks > 0 && !HTList_isEmpty(tagged))
@@ -6648,10 +6633,10 @@ int mainloop(void)
 	     * Highlight current link, unless it is an active text input field.
 	     */
 	    if (!curlink_is_editable) {
-		LYhighlight(TRUE, curdoc.link, prev_target);
+		LYhighlight(TRUE, curdoc.link, prev_target->str);
 #ifndef INACTIVE_INPUT_STYLE_VH
 	    } else if (!textinput_activated) {
-		LYhighlight(TRUE, curdoc.link, prev_target);
+		LYhighlight(TRUE, curdoc.link, prev_target->str);
 #endif
 	    }
 	}
@@ -7008,8 +6993,7 @@ int mainloop(void)
 	case LYK_7:		/* FALLTHRU */
 	case LYK_8:		/* FALLTHRU */
 	case LYK_9:
-	    handle_LYK_digit(c, &force_load, user_input_buffer,
-			     &old_c, real_c, &try_internal);
+	    handle_LYK_digit(c, &force_load, &old_c, real_c, &try_internal);
 	    break;
 
 	case LYK_SOURCE:	/* toggle view source mode */
@@ -7167,7 +7151,8 @@ int mainloop(void)
 		}
 		*t = '\0';
 		get_clip_release();
-		do_check_goto_URL(buf, &temp, &force_load);
+		BStrCopy0(user_input_buffer, buf);
+		do_check_goto_URL(user_input_buffer, &temp, &force_load);
 		free(buf);
 	    }
 	    break;
diff --git a/src/LYOptions.c b/src/LYOptions.c
index 9d2bfb5f..694ef7c4 100644
--- a/src/LYOptions.c
+++ b/src/LYOptions.c
@@ -1,4 +1,4 @@
-/* $LynxId: LYOptions.c,v 1.147 2012/02/08 01:02:48 tom Exp $ */
+/* $LynxId: LYOptions.c,v 1.148 2012/02/09 01:56:18 tom Exp $ */
 #include <HTUtils.h>
 #include <HTFTP.h>
 #include <HTTP.h>		/* 'reloading' flag */
@@ -811,7 +811,7 @@ void LYoptions(void)
 		    ch == -1 || isBEmpty(my_data)) {
 		    LYaddstr(non_empty(bookmark_page) ?
 			     bookmark_page : "NONE");
-		} else if (!LYPathOffHomeOK(my_data->str, my_data->len)) {
+		} else if (!LYPathOffHomeOK(my_data->str, (size_t) my_data->len)) {
 		    LYaddstr(non_empty(bookmark_page) ?
 			     bookmark_page : "NONE");
 		    LYclrtoeol();
@@ -2015,7 +2015,7 @@ void edit_bookmarks(void)
 			FREE(MBM_A_subbookmark[a]);
 		} else {
 		    BStrAlloc(my_data, my_data->len + LY_MAXPATH);
-		    if (!LYPathOffHomeOK(my_data->str, my_data->len)) {
+		    if (!LYPathOffHomeOK(my_data->str, (size_t) my_data->len)) {
 			LYMBM_statusline(USE_PATH_OFF_HOME);
 			LYSleepAlert();
 		    } else {
diff --git a/src/LYPrint.c b/src/LYPrint.c
index 1d972403..a9af8135 100644
--- a/src/LYPrint.c
+++ b/src/LYPrint.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYPrint.c,v 1.90 2010/09/25 11:20:29 tom Exp $
+ * $LynxId: LYPrint.c,v 1.93 2012/02/08 23:40:43 tom Exp $
  */
 #include <HTUtils.h>
 #include <HTAccess.h>
@@ -132,27 +132,26 @@ static char *suggested_filename(DocInfo *newdoc)
     return sug_filename;
 }
 
-static void SetupFilename(char *filename,
+static void SetupFilename(bstring **filename,
 			  const char *sug_filename)
 {
     HTFormat format;
     HTAtom *encoding;
     char *cp;
 
-    LYStrNCpy(filename, sug_filename, LY_MAXPATH - 1);	/* add suggestion info */
-    /* make the sug_filename conform to system specs */
-    change_sug_filename(filename);
+    BStrCopy0(*filename, sug_filename);		/* add suggestion info */
+    BStrAlloc(*filename, LY_MAXPATH);	/* FIXME */
+    change_sug_filename((*filename)->str);
     if (!(HTisDocumentSource())
-	&& (cp = strrchr(filename, '.')) != NULL
-	&& (cp - filename) < (LY_MAXPATH - (int) (sizeof(TEXT_SUFFIX) + 1))) {
-	format = HTFileFormat(filename, &encoding, NULL);
+	&& (cp = strrchr((*filename)->str, '.')) != NULL) {
+	format = HTFileFormat((*filename)->str, &encoding, NULL);
 	CTRACE((tfp, "... format %s\n", format->name));
 	if (!strcasecomp(format->name, "text/html") ||
 	    !IsUnityEnc(encoding)) {
-	    strcpy(cp, TEXT_SUFFIX);
+	    BStrCat0(*filename, TEXT_SUFFIX);
 	}
     }
-    CTRACE((tfp, "... result %s\n", filename));
+    CTRACE((tfp, "... result %s\n", (*filename)->str));
 }
 
 #define FN_INIT 0
@@ -163,7 +162,7 @@ static void SetupFilename(char *filename,
 #define PRINT_FLAG   0
 #define GENERIC_FLAG 1
 
-static int RecallFilename(char *filename,
+static int RecallFilename(bstring **filename,
 			  BOOLEAN *first,
 			  int *now,
 			  int *total,
@@ -182,7 +181,7 @@ static int RecallFilename(char *filename,
     }
     recall = ((*total >= 1) ? RECALL_URL : NORECALL);
 
-    if ((ch = LYGetStr(filename, VISIBLE, LY_MAXPATH, recall)) < 0 ||
+    if ((ch = LYgetBString(filename, VISIBLE, 0, recall)) < 0 ||
 	*filename == '\0' || ch == UPARROW || ch == DNARROW) {
 	if (recall && ch == UPARROW) {
 	    if (*first) {
@@ -208,7 +207,7 @@ static int RecallFilename(char *filename,
 		return FN_INIT;
 	    } else if ((cp = (char *) HTList_objectAt(sug_filenames,
 						      *now)) != NULL) {
-		LYStrNCpy(filename, cp, LY_MAXPATH - 1);
+		BStrCopy0(*filename, cp);
 		if (*total == 1) {
 		    _statusline(EDIT_THE_PREV_FILENAME);
 		} else {
@@ -239,7 +238,7 @@ static int RecallFilename(char *filename,
 		return FN_INIT;
 	    } else if ((cp = (char *) HTList_objectAt(sug_filenames,
 						      *now)) != NULL) {
-		LYStrNCpy(filename, cp, LY_MAXPATH - 1);
+		BStrCopy0(*filename, cp);
 		if (*total == 1) {
 		    _statusline(EDIT_THE_PREV_FILENAME);
 		} else {
@@ -298,23 +297,26 @@ static void send_file_to_file(DocInfo *newdoc,
     BOOLEAN use_cte;
     const char *disp_charset;
     FILE *outfile_fp;
-    char buffer[LY_MAXPATH];
-    char filename[LY_MAXPATH];
+    bstring *buffer = NULL;
+    bstring *filename = NULL;
     int FnameNum = -1;
     int FnameTotal;
     int c = 0;
 
     _statusline(FILENAME_PROMPT);
+
   retry:
-    SetupFilename(filename, sug_filename);
-    if (lynx_save_space
-	&& (strlen(lynx_save_space) + strlen(filename)) < sizeof(filename)) {
-	strcpy(buffer, lynx_save_space);
-	strcat(buffer, filename);
-	strcpy(filename, buffer);
+    SetupFilename(&filename, sug_filename);
+    if (lynx_save_space) {
+	BStrCopy0(buffer, lynx_save_space);
+	BStrCat(buffer, filename);
+	BStrCopy(filename, buffer);
+    } else {
+	BStrCopy0(buffer, "");
     }
+
   check_recall:
-    switch (RecallFilename(filename, &FirstRecall, &FnameNum,
+    switch (RecallFilename(&filename, &FirstRecall, &FnameNum,
 			   &FnameTotal, PRINT_FLAG)) {
     case FN_INIT:
 	goto retry;
@@ -333,7 +335,7 @@ static void send_file_to_file(DocInfo *newdoc,
     /*
      * See if it already exists.
      */
-    switch (LYValidateOutput(buffer)) {
+    switch (LYValidateOutput(buffer->str)) {
     case 'Y':
 	break;
     case 'N':
@@ -348,16 +350,16 @@ static void send_file_to_file(DocInfo *newdoc,
     /*
      * See if we can write to it.
      */
-    CTRACE((tfp, "LYPrint: filename is %s, action is `%c'\n", buffer, c));
+    CTRACE((tfp, "LYPrint: filename is %s, action is `%c'\n", buffer->str, c));
 
 #ifdef HAVE_POPEN
-    if (*buffer == '|') {
+    if (buffer->str[0] == '|') {
 	if (no_shell) {
 	    HTUserMsg(SPAWNING_DISABLED);
 	    FirstRecall = TRUE;
 	    FnameNum = FnameTotal;
 	    goto retry;
-	} else if ((outfile_fp = popen(buffer + 1, "w")) == NULL) {
+	} else if ((outfile_fp = popen(buffer->str + 1, "w")) == NULL) {
 	    CTRACE((tfp, "LYPrint: errno is %d\n", errno));
 	    HTAlert(CANNOT_WRITE_TO_FILE);
 	    _statusline(NEW_FILENAME_PROMPT);
@@ -368,8 +370,8 @@ static void send_file_to_file(DocInfo *newdoc,
     } else
 #endif
 	if ((outfile_fp = (TOUPPER(c) == 'A'
-			   ? LYAppendToTxtFile(buffer)
-			   : LYNewTxtFile(buffer))) == NULL) {
+			   ? LYAppendToTxtFile(buffer->str)
+			   : LYNewTxtFile(buffer->str))) == NULL) {
 	CTRACE((tfp, "LYPrint: errno is %d\n", errno));
 	HTAlert(CANNOT_WRITE_TO_FILE);
 	_statusline(NEW_FILENAME_PROMPT);
@@ -437,27 +439,29 @@ static void send_file_to_file(DocInfo *newdoc,
 	printlist(outfile_fp, FALSE);
 
 #ifdef HAVE_POPEN
-    if (LYIsPipeCommand(buffer))
+    if (LYIsPipeCommand(buffer->str))
 	pclose(outfile_fp);
     else
 #endif
 	LYCloseOutput(outfile_fp);
 
 #ifdef VMS
-    if (0 == strncasecomp(buffer, "sys$disk:", 9)) {
-	if (0 == StrNCmp((buffer + 9), "[]", 2)) {
-	    HTAddSugFilename(buffer + 11);
+    if (0 == strncasecomp(buffer->str, "sys$disk:", 9)) {
+	if (0 == StrNCmp((buffer->str + 9), "[]", 2)) {
+	    HTAddSugFilename(buffer->str + 11);
 	} else {
-	    HTAddSugFilename(buffer + 9);
+	    HTAddSugFilename(buffer->str + 9);
 	}
     } else {
-	HTAddSugFilename(buffer);
+	HTAddSugFilename(buffer->str);
     }
 #else
-    HTAddSugFilename(buffer);
+    HTAddSugFilename(buffer->str);
 #endif /* VMS */
 
   done:
+    BStrFree(buffer);
+    BStrFree(filename);
     return;
 }
 
@@ -484,7 +488,7 @@ static void send_file_to_mail(DocInfo *newdoc,
     FILE *outfile_fp;
     char *buffer = NULL;
     char *subject = NULL;
-    char user_response[LINESIZE];
+    bstring *user_response = NULL;
 
     if (!LYSystemMail())
 	return;
@@ -500,12 +504,9 @@ static void send_file_to_mail(DocInfo *newdoc,
     }
 
     _statusline(MAIL_ADDRESS_PROMPT);
-    LYStrNCpy(user_response, personal_mail_address, sizeof(user_response) - 1);
-    if (LYGetStr(user_response,
-		 VISIBLE,
-		 sizeof(user_response),
-		 RECALL_MAIL) < 0 ||
-	*user_response == '\0') {
+    BStrCopy0(user_response, personal_mail_address);
+    if (LYgetBString(&user_response, VISIBLE, 0, RECALL_MAIL) < 0 ||
+	isBEmpty(user_response)) {
 	CancelPrint(MAIL_REQUEST_CANCELLED);
     }
 
@@ -548,12 +549,14 @@ static void send_file_to_mail(DocInfo *newdoc,
 	StrAllocCat(subject, newdoc->address);
     }
 #if USE_VMS_MAILER
-    if (strchr(user_response, '@') && !strchr(user_response, ':') &&
-	!strchr(user_response, '%') && !strchr(user_response, '"')) {
+    if (strchr(user_response->str, '@') &&
+	!strchr(user_response->str, ':') &&
+	!strchr(user_response->str, '%') &&
+	!strchr(user_response->str, '"')) {
 	char *temp = 0;
 
-	HTSprintf0(&temp, mail_adrs, user_response);
-	LYStrNCpy(user_response, temp, sizeof(user_response) - 1);
+	HTSprintf0(&temp, mail_adrs, user_response->str);
+	BStrCopy0(user_response, temp);
 	FREE(temp);
     }
 
@@ -643,7 +646,7 @@ static void send_file_to_mail(DocInfo *newdoc,
 		   system_mail_flags,
 		   hdrfile,
 		   my_temp,
-		   user_response);
+		   user_response->str);
     } else {
 	/*
 	 * For "generic" VMS MAIL, include the subject in the command.  - FM
@@ -655,7 +658,7 @@ static void send_file_to_mail(DocInfo *newdoc,
 		   system_mail_flags,
 		   subject,
 		   my_temp,
-		   user_response);
+		   user_response->str);
     }
 
     stop_curses();
@@ -754,7 +757,7 @@ static void send_file_to_mail(DocInfo *newdoc,
     /*
      * Add the To, Subject, and X-URL headers.  - FM
      */
-    fprintf(outfile_fp, "To: %s\nSubject: %s\n", user_response, subject);
+    fprintf(outfile_fp, "To: %s\nSubject: %s\n", user_response->str, subject);
     fprintf(outfile_fp, "X-URL: %s\n\n", newdoc->address);
 
     if (LYPrependBaseToSource && HTisDocumentSource()) {
@@ -776,7 +779,7 @@ static void send_file_to_mail(DocInfo *newdoc,
     pclose(outfile_fp);
 #else
     LYCloseOutput(outfile_fp);
-    LYSendMailFile(user_response,
+    LYSendMailFile(user_response->str,
 		   my_temp,
 		   subject,
 		   "",
@@ -786,6 +789,7 @@ static void send_file_to_mail(DocInfo *newdoc,
 #endif /* USE_VMS_MAILER */
 
   done:			/* send_file_to_mail() */
+    BStrFree(user_response);
     FREE(buffer);
     FREE(subject);
     return;
@@ -799,7 +803,7 @@ static void send_file_to_printer(DocInfo *newdoc,
     BOOLEAN FirstRecall = TRUE;
     FILE *outfile_fp;
     char *the_command = 0;
-    char my_file[LY_MAXPATH];
+    bstring *my_file = NULL;
     char my_temp[LY_MAXPATH];
     int FnameTotal, FnameNum = -1;
     lynx_list_item_type *cur_printer;
@@ -851,12 +855,13 @@ static void send_file_to_printer(DocInfo *newdoc,
      * Check for two '%s' and ask for the second filename argument if there
      * is.
      */
+    BStrCopy0(my_file, "");
     if (HTCountCommandArgs(cur_printer->command) >= 2) {
 	_statusline(FILENAME_PROMPT);
       again:
-	SetupFilename(my_file, sug_filename);
+	SetupFilename(&my_file, sug_filename);
       check_again:
-	switch (RecallFilename(my_file, &FirstRecall, &FnameNum,
+	switch (RecallFilename(&my_file, &FirstRecall, &FnameNum,
 			       &FnameTotal, PRINT_FLAG)) {
 	case FN_INIT:
 	    goto again;
@@ -869,7 +874,7 @@ static void send_file_to_printer(DocInfo *newdoc,
 	}
 
 	if (no_dotfiles || !show_dotfiles) {
-	    if (*LYPathLeaf(my_file) == '.') {
+	    if (*LYPathLeaf(my_file->str) == '.') {
 		HTAlert(FILENAME_CANNOT_BE_DOT);
 		_statusline(NEW_FILENAME_PROMPT);
 		FirstRecall = TRUE;
@@ -881,26 +886,22 @@ static void send_file_to_printer(DocInfo *newdoc,
 	 * Cancel if the user entered "/dev/null" on Unix, or an "nl:" path
 	 * on VMS.  - FM
 	 */
-	if (LYIsNullDevice(my_file)) {
+	if (LYIsNullDevice(my_file->str)) {
 	    CancelPrint(PRINT_REQUEST_CANCELLED);
 	}
-	HTAddSugFilename(my_file);
+	HTAddSugFilename(my_file->str);
     }
 #ifdef SH_EX			/* 1999/01/04 (Mon) 09:37:03 */
-    else {
-	my_file[0] = '\0';
-    }
-
     HTAddParam(&the_command, cur_printer->command, 1, my_temp);
-    if (my_file[0]) {
-	HTAddParam(&the_command, cur_printer->command, 2, my_file);
+    if (!isBEmpty(my_file)) {
+	HTAddParam(&the_command, cur_printer->command, 2, my_file->str);
 	HTEndParam(&the_command, cur_printer->command, 3);
     } else {
 	HTEndParam(&the_command, cur_printer->command, 2);
     }
 #else
     HTAddParam(&the_command, cur_printer->command, 1, my_temp);
-    HTAddParam(&the_command, cur_printer->command, 2, my_file);
+    HTAddParam(&the_command, cur_printer->command, 2, my_file->str);
     HTEndParam(&the_command, cur_printer->command, 2);
 #endif
 
@@ -951,6 +952,7 @@ static void send_file_to_printer(DocInfo *newdoc,
     start_curses();
 
   done:			/* send_file_to_printer() */
+    BStrFree(my_file);
     return;
 }
 
@@ -959,7 +961,7 @@ static void send_file_to_screen(DocInfo *newdoc,
 				int Lpansi)
 {
     FILE *outfile_fp;
-    char prompt[80];
+    bstring *prompt = NULL;
 
     if (Lpansi) {
 	_statusline(CHECK_PRINTER);
@@ -967,63 +969,64 @@ static void send_file_to_screen(DocInfo *newdoc,
 	_statusline(PRESS_RETURN_TO_BEGIN);
     }
 
-    *prompt = '\0';
-    if (LYGetStr(prompt, VISIBLE, sizeof(prompt), NORECALL) < 0) {
+    BStrCopy0(prompt, "");
+    if (LYgetBString(&prompt, VISIBLE, 0, NORECALL) < 0) {
 	CancelPrint(PRINT_REQUEST_CANCELLED);
-    }
-
-    outfile_fp = stdout;
+    } else {
+	outfile_fp = stdout;
 
-    stop_curses();
-    SetOutputMode(O_TEXT);
+	stop_curses();
+	SetOutputMode(O_TEXT);
 
 #ifndef VMS
-    signal(SIGINT, SIG_IGN);
+	signal(SIGINT, SIG_IGN);
 #endif /* !VMS */
 
-    if (LYPrependBaseToSource && HTisDocumentSource()) {
-	/*
-	 * Added the document's base as a BASE tag to the top of the file.  May
-	 * create technically invalid HTML, but will help get any partial or
-	 * relative URLs resolved properly if no BASE tag is present to replace
-	 * it.  - FM
-	 */
-	fprintf(outfile_fp,
-		"<!-- X-URL: %s -->\n<BASE HREF=\"%s\">\n\n",
-		newdoc->address, content_base);
-    }
-    if (Lpansi)
-	printf("\033[5i");
-    print_wwwfile_to_fd(outfile_fp, FALSE, FALSE);	/* SCREEN */
-    if (keypad_mode)
-	printlist(outfile_fp, FALSE);
+	if (LYPrependBaseToSource && HTisDocumentSource()) {
+	    /*
+	     * Added the document's base as a BASE tag to the top of the file.  May
+	     * create technically invalid HTML, but will help get any partial or
+	     * relative URLs resolved properly if no BASE tag is present to replace
+	     * it.  - FM
+	     */
+	    fprintf(outfile_fp,
+		    "<!-- X-URL: %s -->\n<BASE HREF=\"%s\">\n\n",
+		    newdoc->address, content_base);
+	}
+	if (Lpansi)
+	    printf("\033[5i");
+	print_wwwfile_to_fd(outfile_fp, FALSE, FALSE);	/* SCREEN */
+	if (keypad_mode)
+	    printlist(outfile_fp, FALSE);
 
 #ifdef VMS
-    if (HadVMSInterrupt) {
-	HadVMSInterrupt = FALSE;
-	start_curses();
-	CancelPrint(PRINT_REQUEST_CANCELLED);
-    }
+	if (HadVMSInterrupt) {
+	    HadVMSInterrupt = FALSE;
+	    start_curses();
+	    CancelPrint(PRINT_REQUEST_CANCELLED);
+	}
 #endif /* VMS */
-    if (Lpansi) {
-	printf("\n\014");	/* Form feed */
-	printf("\033[4i");
-	fflush(stdout);		/* refresh to screen */
-    } else {
-	fprintf(stdout, "\n\n%s", PRESS_RETURN_TO_FINISH);
-	fflush(stdout);		/* refresh to screen */
-	(void) LYgetch();	/* grab some user input to pause */
+	if (Lpansi) {
+	    printf("\n\014");	/* Form feed */
+	    printf("\033[4i");
+	    fflush(stdout);	/* refresh to screen */
+	} else {
+	    fprintf(stdout, "\n\n%s", PRESS_RETURN_TO_FINISH);
+	    fflush(stdout);	/* refresh to screen */
+	    (void) LYgetch();	/* grab some user input to pause */
 #ifdef VMS
-	HadVMSInterrupt = FALSE;
+	    HadVMSInterrupt = FALSE;
 #endif /* VMS */
-    }
+	}
 #ifdef SH_EX
-    fprintf(stdout, "\n");
+	fprintf(stdout, "\n");
 #endif
-    SetOutputMode(O_BINARY);
-    start_curses();
+	SetOutputMode(O_BINARY);
+	start_curses();
+    }
 
   done:			/* send_file_to_screen() */
+    BStrFree(prompt);
     return;
 }
 
@@ -1353,9 +1356,9 @@ char *GetFileName(void)
 {
     struct stat stat_info;
 
-    char fbuf[LY_MAXPATH];
-    char tbuf[LY_MAXPATH];
-    char *fn;
+    bstring *fbuf = NULL;
+    bstring *tbuf = NULL;
+    char *result = NULL;
 
     BOOLEAN FirstRecall = TRUE;
     int FnameNum = -1;
@@ -1367,21 +1370,21 @@ char *GetFileName(void)
     /*
      * No initial filename.
      */
-    SetupFilename(fbuf, "");
+    SetupFilename(&fbuf, "");
 
   check_recall:
     /*
      * Go get a filename (it would be nice to do TAB == filename-completion as
      * the name is entered, but we'll save doing that for another time.
      */
-    switch (RecallFilename(fbuf, &FirstRecall, &FnameNum,
+    switch (RecallFilename(&fbuf, &FirstRecall, &FnameNum,
 			   &FnameTotal, GENERIC_FLAG)) {
     case FN_INIT:
 	goto retry;
     case FN_READ:
 	goto check_recall;
     case FN_QUIT:
-	goto quit;
+	goto cleanup;
     default:
 	break;
     }
@@ -1391,29 +1394,30 @@ char *GetFileName(void)
      * subsequent call, etc.
      */
 #ifdef VMS
-    if (0 == strncasecomp(fbuf, "sys$disk:", 9)) {
-	if (0 == StrNCmp((fbuf + 9), "[]", 2)) {
-	    HTAddSugFilename(fbuf + 11);
+    if (0 == strncasecomp(fbuf->str, "sys$disk:", 9)) {
+	if (0 == StrNCmp((fbuf->str + 9), "[]", 2)) {
+	    HTAddSugFilename(fbuf->str + 11);
 	} else {
-	    HTAddSugFilename(fbuf + 9);
+	    HTAddSugFilename(fbuf->str + 9);
 	}
     } else {
-	HTAddSugFilename(fbuf);
+	HTAddSugFilename(fbuf->str);
     }
 #else
-    HTAddSugFilename(fbuf);
+    HTAddSugFilename(fbuf->str);
 #endif /* VMS */
 
     /*
      * Expand tilde's, make filename absolute, etc.
      */
+    BStrCopy0(tbuf, "");
     if (!LYValidateFilename(tbuf, fbuf))
-	goto quit;
+	goto cleanup;
 
     /*
      * Check for file existence; readability.
      */
-    if ((stat(tbuf, &stat_info) < 0) ||
+    if ((stat(tbuf->str, &stat_info) < 0) ||
 	(!(S_ISREG(stat_info.st_mode)
 #ifdef S_IFLNK
 	   || S_ISLNK(stat_info.st_mode)
@@ -1426,7 +1430,7 @@ char *GetFileName(void)
 	goto retry;
     }
 
-    if (!LYCanReadFile(tbuf)) {
+    if (!LYCanReadFile(tbuf->str)) {
 	HTInfoMsg(FILE_NOT_READABLE);
 	_statusline(FILE_NOT_READABLE_RE);
 	FirstRecall = TRUE;
@@ -1438,21 +1442,11 @@ char *GetFileName(void)
      * We have a valid filename, and readable file.  Return it to the caller.
      *
      * The returned pointer should be free()'d by the caller.
-     *
-     * [For some silly reason, if we use StrAllocCopy() here, we get an
-     * "invalid pointer" reported in the Lynx.leaks file (if compiled with
-     * --enable-find-leaks turned on.  Dumb.]
      */
-    if ((fn = typecallocn(char, strlen(tbuf) + 1)) == NULL)
-	  outofmem(__FILE__, "GetFileName");
-
-    assert(fn != NULL);
-
-    return (strcpy(fn, tbuf));
+    StrAllocCopy(result, tbuf->str);
 
-  quit:
-    /*
-     * The user cancelled the input (^G, or CR on empty input field).
-     */
-    return (NULL);
+  cleanup:
+    BStrFree(fbuf);
+    BStrFree(tbuf);
+    return (result);
 }
diff --git a/src/LYSearch.c b/src/LYSearch.c
index b9755733..82c83dda 100644
--- a/src/LYSearch.c
+++ b/src/LYSearch.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYSearch.c,v 1.27 2011/10/07 00:40:58 tom Exp $
+ * $LynxId: LYSearch.c,v 1.29 2012/02/08 15:02:45 tom Exp $
  */
 #include <HTUtils.h>
 #include <HTAlert.h>
@@ -152,13 +152,13 @@ static int check_prev_target_in_links(int *cur,
  * This is the primary USER search engine and is case sensitive or case
  * insensitive depending on the 'LYcase_sensitive' global variable
  */
-BOOL textsearch(DocInfo *cur_doc, char *prev_target,
-		int target_size,
+BOOL textsearch(DocInfo *cur_doc,
+		bstring *prev_target,
 		int direction)
 {
     int offset;
     int oldcur = cur_doc->link;
-    static char prev_target_buffer[512];	/* Search string buffer */
+    static bstring *my_prev_target = NULL;
     static BOOL first = TRUE;
     char *cp;
     int ch = 0;
@@ -171,7 +171,7 @@ BOOL textsearch(DocInfo *cur_doc, char *prev_target,
      * Initialize the search string buffer.  - FM
      */
     if (first) {
-	*prev_target_buffer = '\0';
+	BStrCopy0(my_prev_target, "");
 	first = FALSE;
     }
 
@@ -184,9 +184,9 @@ BOOL textsearch(DocInfo *cur_doc, char *prev_target,
 	 * LYK_NEXT or LYK_PREV was pressed, so copy the buffer into
 	 * prev_target.
 	 */
-	LYStrNCpy(prev_target, prev_target_buffer, target_size);
+	BStrCopy(prev_target, my_prev_target);
 
-    if (strlen(prev_target) == 0) {
+    if (strlen(prev_target->str) == 0) {
 	/*
 	 * This is a new WHEREIS search ('/'), or LYK_NEXT was pressed but
 	 * there was no previous search, so we need to get a search string from
@@ -194,20 +194,20 @@ BOOL textsearch(DocInfo *cur_doc, char *prev_target,
 	 */
 	_statusline(ENTER_WHEREIS_QUERY);
 
-	ch = LYGetStr(prev_target, VISIBLE, (unsigned) target_size, recall);
+	ch = LYgetBString(&prev_target, VISIBLE, 0, recall);
 	if (ch < 0) {
 	    /*
 	     * User cancelled the search via ^G.  Restore prev_target and
 	     * return.  - FM
 	     */
-	    LYStrNCpy(prev_target, prev_target_buffer, target_size);
+	    BStrCopy(prev_target, my_prev_target);
 	    HTInfoMsg(CANCELLED);
 	    return (FALSE);
 	}
     }
 
   check_recall:
-    if (strlen(prev_target) == 0 &&
+    if (strlen(prev_target->str) == 0 &&
 	!(recall && (ch == UPARROW || ch == DNARROW))) {
 	/*
 	 * No entry.  Simply return, retaining the current buffer.  Because
@@ -225,11 +225,11 @@ BOOL textsearch(DocInfo *cur_doc, char *prev_target,
 	     * Use the current string or last query in the list.  - FM
 	     */
 	    FirstRecall = FALSE;
-	    if (*prev_target_buffer) {
+	    if (!isBEmpty(my_prev_target)) {
 		for (QueryNum = (QueryTotal - 1); QueryNum > 0; QueryNum--) {
 		    if ((cp = (char *) HTList_objectAt(search_queries,
 						       QueryNum)) != NULL &&
-			!strcmp(prev_target_buffer, cp)) {
+			!strcmp(my_prev_target->str, cp)) {
 			break;
 		    }
 		}
@@ -249,23 +249,23 @@ BOOL textsearch(DocInfo *cur_doc, char *prev_target,
 	    QueryNum = 0;
 	if ((cp = (char *) HTList_objectAt(search_queries,
 					   QueryNum)) != NULL) {
-	    LYStrNCpy(prev_target, cp, target_size);
-	    if (*prev_target_buffer &&
-		!strcmp(prev_target_buffer, prev_target)) {
+	    BStrCopy0(prev_target, cp);
+	    if (!isBEmpty(my_prev_target) &&
+		!strcmp(my_prev_target->str, prev_target->str)) {
 		_statusline(EDIT_CURRENT_QUERY);
-	    } else if ((*prev_target_buffer && QueryTotal == 2) ||
-		       (!(*prev_target_buffer) && QueryTotal == 1)) {
+	    } else if ((!isBEmpty(my_prev_target) && QueryTotal == 2) ||
+		       (isBEmpty(my_prev_target) && QueryTotal == 1)) {
 		_statusline(EDIT_THE_PREV_QUERY);
 	    } else {
 		_statusline(EDIT_A_PREV_QUERY);
 	    }
-	    ch = LYGetStr(prev_target, VISIBLE, (unsigned) target_size, recall);
+	    ch = LYgetBString(&prev_target, VISIBLE, 0, recall);
 	    if (ch < 0) {
 		/*
 		 * User canceled the search via ^G.  Restore prev_target and
 		 * return.  - FM
 		 */
-		LYStrNCpy(prev_target, prev_target_buffer, target_size);
+		BStrCopy(prev_target, my_prev_target);
 		HTInfoMsg(CANCELLED);
 		return (FALSE);
 	    }
@@ -277,11 +277,11 @@ BOOL textsearch(DocInfo *cur_doc, char *prev_target,
 	     * Use the current string or first query in the list.  - FM
 	     */
 	    FirstRecall = FALSE;
-	    if (*prev_target_buffer) {
+	    if (!isBEmpty(my_prev_target)) {
 		for (QueryNum = 0; QueryNum < (QueryTotal - 1); QueryNum++) {
 		    if ((cp = (char *) HTList_objectAt(search_queries,
 						       QueryNum)) != NULL &&
-			!strcmp(prev_target_buffer, cp)) {
+			!strcmp(my_prev_target->str, cp)) {
 			break;
 		    }
 		}
@@ -301,23 +301,23 @@ BOOL textsearch(DocInfo *cur_doc, char *prev_target,
 	    QueryNum = QueryTotal - 1;
 	if ((cp = (char *) HTList_objectAt(search_queries,
 					   QueryNum)) != NULL) {
-	    LYStrNCpy(prev_target, cp, target_size);
-	    if (*prev_target_buffer &&
-		!strcmp(prev_target_buffer, prev_target)) {
+	    BStrCopy0(prev_target, cp);
+	    if (!isBEmpty(my_prev_target) &&
+		!strcmp(my_prev_target->str, prev_target->str)) {
 		_statusline(EDIT_CURRENT_QUERY);
-	    } else if ((*prev_target_buffer && QueryTotal == 2) ||
-		       (!(*prev_target_buffer) && QueryTotal == 1)) {
+	    } else if ((!isBEmpty(my_prev_target) && QueryTotal == 2) ||
+		       (isBEmpty(my_prev_target) && QueryTotal == 1)) {
 		_statusline(EDIT_THE_PREV_QUERY);
 	    } else {
 		_statusline(EDIT_A_PREV_QUERY);
 	    }
-	    ch = LYGetStr(prev_target, VISIBLE, (unsigned) target_size, recall);
+	    ch = LYgetBString(&prev_target, VISIBLE, 0, recall);
 	    if (ch < 0) {
 		/*
 		 * User cancelled the search via ^G.  Restore prev_target and
 		 * return.  - FM
 		 */
-		LYStrNCpy(prev_target, prev_target_buffer, target_size);
+		BStrCopy(prev_target, my_prev_target);
 		HTInfoMsg(CANCELLED);
 		return (FALSE);
 	    }
@@ -327,16 +327,16 @@ BOOL textsearch(DocInfo *cur_doc, char *prev_target,
     /*
      * Replace the search string buffer with the new target.  - FM
      */
-    LYStrNCpy(prev_target_buffer, prev_target, sizeof(prev_target_buffer) - 1);
-    HTAddSearchQuery(prev_target_buffer);
+    BStrCopy(my_prev_target, prev_target);
+    HTAddSearchQuery(my_prev_target->str);
 
     if (direction < 0) {
 	offset = 0;
-	if (check_prev_target_in_links(&cur_doc->link, prev_target)) {
+	if (check_prev_target_in_links(&cur_doc->link, prev_target->str)) {
 	    /*
 	     * Found in link, changed cur, we're done.
 	     */
-	    LYhighlight(FALSE, oldcur, prev_target);
+	    LYhighlight(FALSE, oldcur, prev_target->str);
 	    return (TRUE);
 	}
     } else {
@@ -345,11 +345,11 @@ BOOL textsearch(DocInfo *cur_doc, char *prev_target,
 	 * Search the links on the currently displayed page for the string,
 	 * starting after the current link.  - FM
 	 */
-	if (check_next_target_in_links(&cur_doc->link, prev_target)) {
+	if (check_next_target_in_links(&cur_doc->link, prev_target->str)) {
 	    /*
 	     * Found in link, changed cur, we're done.
 	     */
-	    LYhighlight(FALSE, oldcur, prev_target);
+	    LYhighlight(FALSE, oldcur, prev_target->str);
 	    return (TRUE);
 	}
 
@@ -367,9 +367,9 @@ BOOL textsearch(DocInfo *cur_doc, char *prev_target,
      * Resume search, this time for all text.  Set www_search_result if string
      * found, and position the hit near top of screen.
      */
-    www_user_search((cur_doc->line + offset), cur_doc, prev_target, direction);
+    www_user_search((cur_doc->line + offset), cur_doc, prev_target->str, direction);
     if (cur_doc->link != oldcur) {
-	LYhighlight(FALSE, oldcur, prev_target);
+	LYhighlight(FALSE, oldcur, prev_target->str);
 	return (TRUE);
     }
     return (BOOL) (www_search_result > 0);
diff --git a/src/LYSearch.h b/src/LYSearch.h
index f9763301..798809a5 100644
--- a/src/LYSearch.h
+++ b/src/LYSearch.h
@@ -9,8 +9,7 @@
 extern "C" {
 #endif
     extern BOOL textsearch(DocInfo *cur_doc,
-			   char *prev_target,
-			   int target_size,
+			   bstring *prev_target,
 			   int direction);
 
 #define IN_FILE 1
diff --git a/src/LYStrings.c b/src/LYStrings.c
index 88c20443..2d25c424 100644
--- a/src/LYStrings.c
+++ b/src/LYStrings.c
@@ -1,4 +1,4 @@
-/* $LynxId: LYStrings.c,v 1.198 2012/02/08 01:22:55 tom Exp $ */
+/* $LynxId: LYStrings.c,v 1.200 2012/02/08 15:51:01 tom Exp $ */
 #include <HTUtils.h>
 #include <HTCJK.h>
 #include <UCAux.h>
@@ -3580,60 +3580,62 @@ int get_popup_number(const char *msg,
 		     int *c,
 		     int *rel)
 {
-    char temp[120];
-    char *p = temp;
-    int num;
+    bstring *temp = NULL;
+    int result = 0;
 
     /*
      * Load the c argument into the prompt buffer.
      */
-    temp[0] = (char) *c;
-    temp[1] = '\0';
+    BStrCopy0(temp, "?");
+    temp->str[0] = (char) *c;
+
     _statusline(msg);
 
     /*
      * Get the number, possibly with a suffix, from the user.
      */
-    if (LYGetStr(temp, VISIBLE, sizeof(temp), NORECALL) < 0 || *temp == 0) {
+    if (LYgetBString(&temp, VISIBLE, 0, NORECALL) < 0 || isBEmpty(temp)) {
 	HTInfoMsg(CANCELLED);
 	*c = '\0';
 	*rel = '\0';
-	return (0);
-    }
+    } else {
+	char *p = temp->str;
 
-    *rel = '\0';
-    num = atoi(p);
-    while (isdigit(UCH(*p)))
-	++p;
-    switch (*p) {
-    case '+':
-    case '-':
-	/* 123+ or 123- */
-	*rel = *p++;
-	*c = *p;
-	break;
-    default:
-	*c = *p++;
-	*rel = *p;
-	break;
-    case 0:
-	break;
-    }
+	*rel = '\0';
+	result = atoi(p);
+	while (isdigit(UCH(*p)))
+	    ++p;
+	switch (*p) {
+	case '+':
+	case '-':
+	    /* 123+ or 123- */
+	    *rel = *p++;
+	    *c = *p;
+	    break;
+	default:
+	    *c = *p++;
+	    *rel = *p;
+	    break;
+	case 0:
+	    break;
+	}
 
-    /*
-     * If we had a 'g' or 'p' suffix, load it into c.  Otherwise, zero c.  Then
-     * return the number.
-     */
-    if (*p == 'g' || *p == 'G') {
-	*c = 'g';
-    } else if (*p == 'p' || *p == 'P') {
-	*c = 'p';
-    } else {
-	*c = '\0';
+	/*
+	 * If we had a 'g' or 'p' suffix, load it into c.  Otherwise, zero c.  Then
+	 * return the number.
+	 */
+	if (*p == 'g' || *p == 'G') {
+	    *c = 'g';
+	} else if (*p == 'p' || *p == 'P') {
+	    *c = 'p';
+	} else {
+	    *c = '\0';
+	}
+	if (*rel != '+' && *rel != '-')
+	    *rel = 0;
     }
-    if (*rel != '+' && *rel != '-')
-	*rel = 0;
-    return num;
+    BStrFree(temp);
+    return result;
 }
 
 #ifdef USE_COLOR_STYLE
@@ -4149,8 +4151,8 @@ int LYhandlePopupList(int cur_choice,
     char Cnum[64];
     int Lnum;
     int npages;
-    static char prev_target[MAX_LINE];	/* Search string buffer */
-    static char prev_target_buffer[MAX_LINE];	/* Next search buffer */
+    static bstring *prev_target = NULL;		/* Search string buffer */
+    static bstring *next_target = NULL;		/* Next search buffer */
     static BOOL first = TRUE;
     char *cp;
     int ch = 0;
@@ -4177,10 +4179,10 @@ int LYhandlePopupList(int cur_choice,
      * Initialize the search string buffer. - FM
      */
     if (first) {
-	*prev_target_buffer = '\0';
+	BStrCopy0(next_target, "");
 	first = FALSE;
     }
-    *prev_target = '\0';
+    BStrCopy0(prev_target, "");
     QueryTotal = (search_queries ? HTList_count(search_queries) : 0);
     recall = ((QueryTotal >= 1) ? RECALL_URL : NORECALL);
     QueryNum = QueryTotal;
@@ -4789,7 +4791,7 @@ int LYhandlePopupList(int cur_choice,
 	    break;
 
 	case LYK_NEXT:
-	    if (recall && *prev_target_buffer == '\0') {
+	    if (recall && isBEmpty(next_target)) {
 		/*
 		 * We got a 'n'ext command with no prior query specified within
 		 * the popup window.  See if one was entered when the popup was
@@ -4803,21 +4805,17 @@ int LYhandlePopupList(int cur_choice,
 		 */
 		if ((cp = (char *) HTList_objectAt(search_queries,
 						   0)) != NULL) {
-		    LYStrNCpy(prev_target_buffer,
-			      cp,
-			      sizeof(prev_target_buffer) - 1);
+		    BStrCopy0(next_target, cp);
 		    QueryNum = 0;
 		    FirstRecall = FALSE;
 		}
 	    }
-	    strcpy(prev_target, prev_target_buffer);
+	    BStrCopy(prev_target, next_target);
 	    /* FALLTHRU */
 	case LYK_WHEREIS:
-	    if (*prev_target == '\0') {
+	    if (isBEmpty(prev_target)) {
 		_statusline(ENTER_WHEREIS_QUERY);
-		if ((ch = LYGetStr(prev_target, VISIBLE,
-				   sizeof(prev_target_buffer),
-				   recall)) < 0) {
+		if ((ch = LYgetBString(&prev_target, VISIBLE, 0, recall)) < 0) {
 		    /*
 		     * User cancelled the search via ^G.  - FM
 		     */
@@ -4827,7 +4825,7 @@ int LYhandlePopupList(int cur_choice,
 	    }
 
 	  check_recall:
-	    if (*prev_target == '\0' &&
+	    if (isBEmpty(prev_target) &&
 		!(recall && (ch == UPARROW || ch == DNARROW))) {
 		/*
 		 * No entry.  Simply break.  - FM
@@ -4842,13 +4840,13 @@ int LYhandlePopupList(int cur_choice,
 		     * Use the current string or last query in the list.  - FM
 		     */
 		    FirstRecall = FALSE;
-		    if (*prev_target_buffer) {
+		    if (!isBEmpty(next_target)) {
 			for (QueryNum = (QueryTotal - 1);
 			     QueryNum > 0; QueryNum--) {
 			    if ((cp = (char *) HTList_objectAt(search_queries,
 							       QueryNum))
 				!= NULL &&
-				!strcmp(prev_target_buffer, cp)) {
+				!strcmp(next_target->str, cp)) {
 				break;
 			    }
 			}
@@ -4869,19 +4867,18 @@ int LYhandlePopupList(int cur_choice,
 		}
 		if ((cp = (char *) HTList_objectAt(search_queries,
 						   QueryNum)) != NULL) {
-		    LYStrNCpy(prev_target, cp, sizeof(prev_target) - 1);
-		    if (*prev_target_buffer &&
-			!strcmp(prev_target_buffer, prev_target)) {
+		    BStrCopy0(prev_target, cp);
+		    if (!isBEmpty(next_target) &&
+			!strcmp(next_target->str, prev_target->str)) {
 			_statusline(EDIT_CURRENT_QUERY);
-		    } else if ((*prev_target_buffer && QueryTotal == 2) ||
-			       (!(*prev_target_buffer) &&
-				QueryTotal == 1)) {
+		    } else if ((!isBEmpty(next_target) && QueryTotal == 2) ||
+			       (isBEmpty(next_target) && QueryTotal == 1)) {
 			_statusline(EDIT_THE_PREV_QUERY);
 		    } else {
 			_statusline(EDIT_A_PREV_QUERY);
 		    }
-		    if ((ch = LYGetStr(prev_target, VISIBLE,
-				       sizeof(prev_target_buffer), recall)) < 0) {
+		    if ((ch = LYgetBString(&prev_target,
+					   VISIBLE, 0, recall)) < 0) {
 			/*
 			 * User cancelled the search via ^G.  - FM
 			 */
@@ -4896,13 +4893,13 @@ int LYhandlePopupList(int cur_choice,
 		     * Use the current string or first query in the list.  - FM
 		     */
 		    FirstRecall = FALSE;
-		    if (*prev_target_buffer) {
+		    if (!isBEmpty(next_target)) {
 			for (QueryNum = 0;
 			     QueryNum < (QueryTotal - 1); QueryNum++) {
 			    if ((cp = (char *) HTList_objectAt(search_queries,
 							       QueryNum))
 				!= NULL &&
-				!strcmp(prev_target_buffer, cp)) {
+				!strcmp(next_target->str, cp)) {
 				break;
 			    }
 			}
@@ -4923,21 +4920,18 @@ int LYhandlePopupList(int cur_choice,
 		}
 		if ((cp = (char *) HTList_objectAt(search_queries,
 						   QueryNum)) != NULL) {
-		    LYStrNCpy(prev_target, cp, sizeof(prev_target) - 1);
-		    if (*prev_target_buffer &&
-			!strcmp(prev_target_buffer, prev_target)) {
+		    BStrCopy0(prev_target, cp);
+		    if (isBEmpty(next_target) &&
+			!strcmp(next_target->str, prev_target->str)) {
 			_statusline(EDIT_CURRENT_QUERY);
-		    } else if ((*prev_target_buffer &&
-				QueryTotal == 2) ||
-			       (!(*prev_target_buffer) &&
-				QueryTotal == 1)) {
+		    } else if ((!isBEmpty(next_target) && QueryTotal == 2) ||
+			       (isBEmpty(next_target) && QueryTotal == 1)) {
 			_statusline(EDIT_THE_PREV_QUERY);
 		    } else {
 			_statusline(EDIT_A_PREV_QUERY);
 		    }
-		    if ((ch = LYGetStr(prev_target, VISIBLE,
-				       sizeof(prev_target_buffer),
-				       recall)) < 0) {
+		    if ((ch = LYgetBString(&prev_target,
+					   VISIBLE, 0, recall)) < 0) {
 			/*
 			 * User cancelled the search via ^G. - FM
 			 */
@@ -4950,8 +4944,8 @@ int LYhandlePopupList(int cur_choice,
 	    /*
 	     * Replace the search string buffer with the new target.  - FM
 	     */
-	    strcpy(prev_target_buffer, prev_target);
-	    HTAddSearchQuery(prev_target_buffer);
+	    BStrCopy(next_target, prev_target);
+	    HTAddSearchQuery(next_target->str);
 
 	    /*
 	     * Start search at the next choice.  - FM
@@ -4959,10 +4953,10 @@ int LYhandlePopupList(int cur_choice,
 	    for (j = 1; Cptr[i + j] != NULL; j++) {
 		FormatChoiceNum(buffer, max_choices, (i + j), Cptr[i + j]);
 		if (LYcase_sensitive) {
-		    if (strstr(buffer, prev_target_buffer) != NULL)
+		    if (strstr(buffer, next_target->str) != NULL)
 			break;
 		} else {
-		    if (LYstrstr(buffer, prev_target_buffer) != NULL)
+		    if (LYstrstr(buffer, next_target->str) != NULL)
 			break;
 		}
 	    }
@@ -4987,7 +4981,7 @@ int LYhandlePopupList(int cur_choice,
 	     * If we started at the beginning, it can't be present.  - FM
 	     */
 	    if (cur_choice == 0) {
-		HTUserMsg2(STRING_NOT_FOUND, prev_target_buffer);
+		HTUserMsg2(STRING_NOT_FOUND, next_target->str);
 		goto restore_popup_statusline;
 	    }
 
@@ -4997,10 +4991,10 @@ int LYhandlePopupList(int cur_choice,
 	    for (j = 0; j < cur_choice; j++) {
 		FormatChoiceNum(buffer, max_choices, (j + 1), Cptr[j]);
 		if (LYcase_sensitive) {
-		    if (strstr(buffer, prev_target_buffer) != NULL)
+		    if (strstr(buffer, next_target->str) != NULL)
 			break;
 		} else {
-		    if (LYstrstr(buffer, prev_target_buffer) != NULL)
+		    if (LYstrstr(buffer, next_target->str) != NULL)
 			break;
 		}
 	    }
@@ -5025,7 +5019,7 @@ int LYhandlePopupList(int cur_choice,
 	    /*
 	     * Didn't find it in the preceding choices either.  - FM
 	     */
-	    HTUserMsg2(STRING_NOT_FOUND, prev_target_buffer);
+	    HTUserMsg2(STRING_NOT_FOUND, next_target->str);
 
 	  restore_popup_statusline:
 	    /*
@@ -5033,7 +5027,7 @@ int LYhandlePopupList(int cur_choice,
 	     * FM
 	     */
 	    _statusline(popup_status_msg);
-	    *prev_target = '\0';
+	    BStrCopy0(prev_target, "");
 	    QueryTotal = (search_queries ? HTList_count(search_queries)
 			  : 0);
 	    recall = ((QueryTotal >= 1) ? RECALL_URL : NORECALL);
diff --git a/src/LYUtils.c b/src/LYUtils.c
index 38eb897e..201e3d7d 100644
--- a/src/LYUtils.c
+++ b/src/LYUtils.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYUtils.c,v 1.214 2011/10/07 00:40:40 tom Exp $
+ * $LynxId: LYUtils.c,v 1.215 2012/02/08 22:31:58 tom Exp $
  */
 #include <HTUtils.h>
 #include <HTTCP.h>
@@ -6630,11 +6630,9 @@ const char *wwwName(const char *pathname)
  * Given a user-specified filename, e.g., for download or print, validate and
  * expand it.  Expand home-directory expressions in the given string.  Only
  * allow pipes if the user can spawn shell commands.
- *
- * Both strings are fixed buffer sizes, LY_MAXPATH.
  */
-BOOLEAN LYValidateFilename(char *result,
-			   char *given)
+BOOLEAN LYValidateFilename(bstring *result,
+			   bstring *given)
 {
     BOOLEAN code = TRUE;
     char *cp = NULL;
@@ -6644,52 +6642,56 @@ BOOLEAN LYValidateFilename(char *result,
      * Cancel if the user entered "/dev/null" on Unix, or an "nl:" path on VMS. 
      * - FM
      */
-    if (LYIsNullDevice(given)) {
+    if (LYIsNullDevice(given->str)) {
 	/* just ignore it */
 	code = FALSE;
 #ifdef HAVE_POPEN
-    } else if (LYIsPipeCommand(given)) {
+    } else if (LYIsPipeCommand(given->str)) {
 	if (no_shell) {
 	    HTUserMsg(SPAWNING_DISABLED);
 	    code = FALSE;
 	} else {
-	    LYStrNCpy(result, given, LY_MAXPATH);
+	    BStrCopy(result, given);
 	}
 #endif
     } else {
-	if ((cp = FindLeadingTilde(given, TRUE)) != 0
-	    && (cp2 = wwwName(Home_Dir())) != 0
-	    && strlen(cp2) + strlen(given) < LY_MAXPATH) {
+	if ((cp = FindLeadingTilde(given->str, TRUE)) != 0
+	    && (cp2 = wwwName(Home_Dir())) != 0) {
 	    if (LYIsTilde(cp[0]) && LYIsPathSep(cp[1])) {
-		*(cp++) = '\0';
-		strcpy(result, given);
-		LYTrimPathSep(result);
-		strcat(result, cp2);
-		strcat(result, cp);
-		strcpy(given, result);
+		char *cp1 = NULL;
+
+		*cp++ = '\0';
+		StrAllocCopy(cp1, cp);
+
+		BStrCopy(result, given);
+		LYTrimPathSep(result->str);
+		BStrCat0(result, cp2);
+		BStrCat0(result, cp1);
+		BStrCopy(given, result);
+
+		FREE(cp1);
 	    }
 	}
 #ifdef VMS
-	if (strchr(given, '/') != NULL) {
-	    strcpy(result, HTVMS_name("", given));
-	    strcpy(given, result);
-	}
-	if (given[0] != '/'
-	    && strchr(given, ':') == NULL
-	    && strlen(given) < LY_MAXPATH - 13) {
-	    strcpy(result, "sys$disk:");
-	    if (strchr(given, ']') == NULL)
-		strcat(result, "[]");
-	    strcat(result, given);
+	if (strchr(given->str, '/') != NULL) {
+	    BStrCopy0(result, HTVMS_name("", given->str));
+	    BStrCopy(given, result);
+	}
+	if (given->str[0] != '/'
+	    && strchr(given->str, ':') == NULL) {
+	    BStrCopy0(result, "sys$disk:");
+	    if (strchr(given->str, ']') == NULL)
+		BStrCat0(result, "[]");
+	    BStrCat(result, given);
 	} else {
-	    strcpy(result, given);
+	    BStrCopy(result, given);
 	}
 #else
 
 #ifndef __EMX__
-	if (!LYisAbsPath(given)) {
+	if (!LYisAbsPath(given->str)) {
 #if defined(__DJGPP__) || defined(_WINDOWS)
-	    if (strchr(result, ':') != NULL)
+	    if (strchr(result->str, ':') != NULL)
 		cp = NULL;
 	    else
 #endif /*  __DJGPP__ || _WINDOWS */
@@ -6706,22 +6708,16 @@ BOOLEAN LYValidateFilename(char *result,
 #endif /* __EMX__ */
 	    cp = NULL;
 
-	*result = 0;
 	if (cp) {
 	    LYTrimPathSep(cp);
-	    if (strlen(cp) >= LY_MAXPATH - 2) {
-		code = FALSE;
-	    } else {
-		sprintf(result, "%s/", cp);
-	    }
+	    BStrCopy0(result, cp);
+	    BStrCat0(result, "/");
+	} else {
+	    BStrCopy0(result, "");
 	}
 	if (code) {
-	    cp = HTSYS_name(given);
-	    if (strlen(result) + strlen(cp) >= LY_MAXPATH - 1) {
-		code = FALSE;
-	    } else {
-		strcat(result, cp);
-	    }
+	    cp = HTSYS_name(given->str);
+	    BStrCat0(result, cp);
 	}
 #endif /* VMS */
     }
diff --git a/src/LYUtils.h b/src/LYUtils.h
index 343410a6..397a76c9 100644
--- a/src/LYUtils.h
+++ b/src/LYUtils.h
@@ -1,4 +1,4 @@
-/* $LynxId: LYUtils.h,v 1.89 2011/10/07 00:36:40 tom Exp $ */
+/* $LynxId: LYUtils.h,v 1.90 2012/02/08 22:12:09 tom Exp $ */
 #ifndef LYUTILS_H
 #define LYUTILS_H
 
@@ -117,7 +117,7 @@ extern "C" {
 				      char *prefix_list, char *suffix_list);
     extern BOOLEAN LYFixCursesOnForAccess(const char *addr, const char *physical);
     extern BOOLEAN LYPathOffHomeOK(char *fbuffer, size_t fbuffer_size);
-    extern BOOLEAN LYValidateFilename(char *result, char *given);
+    extern BOOLEAN LYValidateFilename(bstring *result, bstring *given);
     extern BOOLEAN LYisAbsPath(const char *path);
     extern BOOLEAN LYisLocalAlias(const char *filename);
     extern BOOLEAN LYisLocalFile(const char *filename);