about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2000-03-27 03:37:59 -0500
committerThomas E. Dickey <dickey@invisible-island.net>2000-03-27 03:37:59 -0500
commitc68ecb8b21bef3908cb17f8d1d4af694bf7e7137 (patch)
treeb433eeff77822973f7bdb7de3642e7a21ccbe5a8 /src
parentd70fdcf7f031566fd582362899099f9fba23a7ac (diff)
downloadlynx-snapshots-c68ecb8b21bef3908cb17f8d1d4af694bf7e7137.tar.gz
snapshot of project "lynx", label v2-8-3dev_23
Diffstat (limited to 'src')
-rw-r--r--src/GridText.c21
-rw-r--r--src/HTAlert.c79
-rw-r--r--src/HTFWriter.c28
-rw-r--r--src/HTInit.c20
-rw-r--r--src/HTML.c29
-rw-r--r--src/LYBookmark.c21
-rw-r--r--src/LYCgi.c13
-rw-r--r--src/LYCharSets.c1
-rw-r--r--src/LYCharUtils.c43
-rw-r--r--src/LYCharUtils.h3
-rw-r--r--src/LYCookie.c14
-rw-r--r--src/LYCurses.c65
-rw-r--r--src/LYCurses.h17
-rw-r--r--src/LYDownload.c8
-rw-r--r--src/LYEdit.c2
-rw-r--r--src/LYExtern.c46
-rw-r--r--src/LYForms.c16
-rw-r--r--src/LYGetFile.c18
-rw-r--r--src/LYGlobalDefs.h3
-rw-r--r--src/LYHash.c18
-rw-r--r--src/LYHash.h5
-rw-r--r--src/LYHistory.c49
-rw-r--r--src/LYJump.c21
-rw-r--r--src/LYList.c3
-rw-r--r--src/LYLocal.c276
-rw-r--r--src/LYMail.c4
-rw-r--r--src/LYMain.c43
-rw-r--r--src/LYMainLoop.c51
-rw-r--r--src/LYMap.c6
-rw-r--r--src/LYNews.c17
-rw-r--r--src/LYOptions.c38
-rw-r--r--src/LYPrettySrc.c9
-rw-r--r--src/LYPrint.c17
-rw-r--r--src/LYReadCFG.c80
-rw-r--r--src/LYSearch.c26
-rw-r--r--src/LYSearch.h2
-rw-r--r--src/LYShowInfo.c4
-rw-r--r--src/LYStrings.c100
-rw-r--r--src/LYTraversal.c2
-rw-r--r--src/LYUtils.c162
-rw-r--r--src/LYUtils.h1
-rw-r--r--src/TRSTable.h2
-rw-r--r--src/UCAux.c4
-rw-r--r--src/Xsystem.c16
-rw-r--r--src/chrtrans/makeuctb.c2
45 files changed, 692 insertions, 713 deletions
diff --git a/src/GridText.c b/src/GridText.c
index b88bf97d..eced2386 100644
--- a/src/GridText.c
+++ b/src/GridText.c
@@ -97,7 +97,6 @@ struct _HTStream {			/* only know it as object */
 #define UTF_XLEN(c) UTF8_XNEGLEN(((char)~(c)))
 
 extern BOOL HTPassHighCtrlRaw;
-extern HTCJKlang HTCJK;
 
 #ifdef KANJI_CODE_OVERRIDE
 PUBLIC HTkcode last_kcode = NOKANJI;	/* 1997/11/14 (Fri) 09:09:26 */
@@ -7389,35 +7388,33 @@ PUBLIC void HTSearchQueries_free NOARGS
 PUBLIC void HTAddSearchQuery ARGS1(
 	char *,		query)
 {
-    char *new;
+    char *new_query = NULL;
     char *old;
     HTList *cur;
 
     if (!(query && *query))
 	return;
 
-    if ((new = (char *)calloc(1, (strlen(query) + 1))) == NULL)
-	outofmem(__FILE__, "HTAddSearchQuery");
-    strcpy(new, query);
+    StrAllocCopy(new_query, query);
 
     if (!search_queries) {
 	search_queries = HTList_new();
 #ifdef LY_FIND_LEAKS
 	atexit(HTSearchQueries_free);
 #endif
-	HTList_addObject(search_queries, new);
+	HTList_addObject(search_queries, new_query);
 	return;
     }
 
     cur = search_queries;
     while (NULL != (old = (char *)HTList_nextObject(cur))) {
-	if (!strcmp(old, new)) {
+	if (!strcmp(old, new_query)) {
 	    HTList_removeObject(search_queries, old);
 	    FREE(old);
 	    break;
 	}
     }
-    HTList_addObject(search_queries, new);
+    HTList_addObject(search_queries, new_query);
 
     return;
 }
@@ -7440,7 +7437,7 @@ PUBLIC int do_www_search ARGS1(
 	 *  Use its query as the default.
 	 */
 	PreviousSearch = TRUE;
-	strcpy(searchstring, ++cp);
+	LYstrncpy(searchstring, ++cp, sizeof(searchstring)-1);
 	for (cp=searchstring; *cp; cp++)
 	    if (*cp == '+')
 		*cp = ' ';
@@ -7496,7 +7493,7 @@ get_query:
 		QueryNum = 0;
 	    if ((cp=(char *)HTList_objectAt(search_queries,
 					    QueryNum)) != NULL) {
-		strcpy(searchstring, cp);
+		LYstrncpy(searchstring, cp, sizeof(searchstring)-1);
 		if (*temp && !strcmp(temp, searchstring)) {
 		    _statusline(EDIT_CURRENT_QUERY);
 		} else if ((*temp && QueryTotal == 2) ||
@@ -7527,7 +7524,7 @@ get_query:
 		QueryNum = QueryTotal - 1;
 	    if ((cp=(char *)HTList_objectAt(search_queries,
 					    QueryNum)) != NULL) {
-		strcpy(searchstring, cp);
+		LYstrncpy(searchstring, cp, sizeof(searchstring)-1);
 		if (*temp && !strcmp(temp, searchstring)) {
 		    _statusline(EDIT_CURRENT_QUERY);
 		} else if ((*temp && QueryTotal == 2) ||
@@ -12352,7 +12349,7 @@ PUBLIC int HText_ExtEditForm ARGS1(
 #endif
 
 #ifdef UNIX
-    errno = 0;
+    set_errno(0);
 #endif
     rv = LYSystem (tbuf);	/* finally the editor is called */
     if (rv) {
diff --git a/src/HTAlert.c b/src/HTAlert.c
index a2415b1c..ec3bfeda 100644
--- a/src/HTAlert.c
+++ b/src/HTAlert.c
@@ -108,53 +108,6 @@ PUBLIC void HTUserMsg2 ARGS2(
     }
 }
 
-#if defined(WIN_EX) && defined(UNUSED_CODE)	/* 1997/10/28 (Tue) 17:19:43 */
-
-#define MAX_LEN	512
-
-void ws_title(CONST char *str)
-{
-    char buff[MAX_LEN];
-    char *p;
-    int len;
-
-#define TITLE_CUT 32
-
-    p = (char *)str;
-    len = strlen(p);
-    if (len > (MAX_LEN - 1)) {
-	strncpy(buff, p, (MAX_LEN - 1));
-	len = MAX_LEN - 1;
-	buff[MAX_LEN - 1] = '\0';
-    } else {
-	strcpy(buff, p);
-    }
-
-    if (len > LYcols) {
-	buff[TITLE_CUT] = '.';
-	buff[TITLE_CUT+1] = '.';
-	strcpy(buff + TITLE_CUT + 2, (buff + len) - LYcols + TITLE_CUT + 1);
-    }
-    if (strchr(buff, '%')) {
-	HTUnEscape(buff);
-    }
-
-    p = buff;
-    while (*p++) {
-	if (*p == '\r') {
-	    *p = '\0';
-	    break;
-	} else if (*p ==  '\n') {
-	    *p = '\0';
-	    break;
-	}
-    }
-
-    /* Quick hack. buff is SJIS only ??? */
-    SetConsoleTitle(buff);
-}
-#endif
-
 /*	Issue a progress message.			HTProgress()
 **	-------------------------
 */
@@ -253,7 +206,7 @@ PUBLIC void HTReadProgress ARGS2(
 	    int n;
 	    n = strlen(line);
 	    if (LYshow_kb_rate) {
-		sprintf (line + n, " %6.2lf KB/sec.", transfer_rate / 1024.0);
+		sprintf (line + n, " %6.2f KB/sec.", transfer_rate / 1024.0);
 	    } else {
 		int t_rate;
 
@@ -275,7 +228,8 @@ PUBLIC void HTReadProgress ARGS2(
 #ifdef EXP_READPROGRESS
     static long bytes_last, total_last;
     static long transfer_rate = 0;
-    char line[300], bytesp[80], totalp[80], transferp[80];
+    static char *line = NULL;
+    char bytesp[80], totalp[80], transferp[80];
     int renew = 0;
     char *was_units;
 #if HAVE_GETTIMEOFDAY
@@ -291,7 +245,6 @@ PUBLIC void HTReadProgress ARGS2(
     if (bytes == 0) {
 	first = last = last_active = now;
 	bytes_last = bytes;
-	line[0] = 0;
     } else if (bytes < 0) {	/* stalled */
 	bytes = bytes_last;
 	total = total_last;
@@ -334,18 +287,18 @@ PUBLIC void HTReadProgress ARGS2(
 	    sprint_bytes(transferp, transfer_rate, 0);
 
 	    if (total > 0)
-		sprintf (line, gettext("Read %s of %s of data"), bytesp, totalp);
+		HTSprintf0 (&line, gettext("Read %s of %s of data"), bytesp, totalp);
 	    else
-		sprintf (line, gettext("Read %s of data"), bytesp);
+		HTSprintf0 (&line, gettext("Read %s of data"), bytesp);
 	    if (transfer_rate > 0)
-		sprintf (line + strlen(line), gettext(", %s/sec"), transferp);
+		HTSprintf (&line, gettext(", %s/sec"), transferp);
 	    if (now - last_active >= 5)
-		sprintf (line + strlen(line), gettext(" (stalled for %ld sec)"), (long)(now - last_active));
+		HTSprintf (&line, gettext(" (stalled for %ld sec)"), (long)(now - last_active));
 	    if (total > 0 && transfer_rate)
-		sprintf (line + strlen(line), gettext(", ETA %ld sec"), (long)((total - bytes)/transfer_rate));
-	    sprintf (line + strlen(line), ".");
+		HTSprintf (&line, gettext(", ETA %ld sec"), (long)((total - bytes)/transfer_rate));
+	    StrAllocCat (line, ".");
 	    if (total < -1)
-		strcat(line, gettext(" (Press 'z' to abort)"));
+		StrAllocCat(line, gettext(" (Press 'z' to abort)"));
 
 	    /* do not store the message for history page. */
 	    statusline(line);
@@ -357,8 +310,8 @@ PUBLIC void HTReadProgress ARGS2(
     static time_t first, last;
     static long bytes_last;
     static long transfer_rate = 0;
+    static char *line = NULL;
     long divisor;
-    char line[80];
     time_t now = time((time_t *)0);  /* once per second */
     static char *units = "bytes";
 
@@ -397,17 +350,17 @@ PUBLIC void HTReadProgress ARGS2(
 	    }
 
 	    if (total >  0)
-		sprintf (line, gettext("Read %ld of %ld %s of data"), bytes, total, units);
+		HTSprintf0 (&line, gettext("Read %ld of %ld %s of data"), bytes, total, units);
 	    else
-		sprintf (line, gettext("Read %ld %s of data"), bytes, units);
+		HTSprintf0 (&line, gettext("Read %ld %s of data"), bytes, units);
 	    if ((transfer_rate > 0)
 		  && (!LYshow_kb_rate || (bytes * divisor >= kb_units)))
-		sprintf (line + strlen(line), gettext(", %ld %s/sec."), transfer_rate / divisor, units);
+		HTSprintf (&line, gettext(", %ld %s/sec."), transfer_rate / divisor, units);
 	    else
-		sprintf (line + strlen(line), ".");
+		HTSprintf (&line, ".");
 	    if (total <  0) {
 		if (total < -1)
-		    strcat(line, gettext(" (Press 'z' to abort)"));
+		    StrAllocCat(line, gettext(" (Press 'z' to abort)"));
 	    }
 
 	    /* do not store the message for history page. */
diff --git a/src/HTFWriter.c b/src/HTFWriter.c
index 833fe763..6e7c78ae 100644
--- a/src/HTFWriter.c
+++ b/src/HTFWriter.c
@@ -474,7 +474,7 @@ PUBLIC HTStream* HTFWriter_new ARGS1(FILE *, fp)
     if (!fp)
 	return NULL;
 
-    me = (HTStream*)calloc(sizeof(*me),1);
+    me = typecalloc(HTStream);
     if (me == NULL)
 	outofmem(__FILE__, "HTFWriter_new");
     me->isa = &HTFWriter;
@@ -555,7 +555,7 @@ PUBLIC HTStream* HTSaveAndExecute ARGS3(
 	return(HTSaveToFile(pres, anchor, sink));
     }
 
-    me = (HTStream*)calloc(sizeof(*me),1);
+    me = typecalloc(HTStream);
     if (me == NULL)
 	outofmem(__FILE__, "HTSaveAndExecute");
     me->isa = &HTFWriter;
@@ -586,7 +586,7 @@ PUBLIC HTStream* HTSaveAndExecute ARGS3(
 	    me->fp = NULL;
 
 	    view_fname = fnam + 3;
-	    strcpy(view_fname, anchor->address + 17);
+	    LYstrncpy(view_fname, anchor->address + 17, sizeof(fnam) - 5);
 	    HTUnEscape(view_fname);
 
 	    if (strchr(view_fname, ':')==NULL) {
@@ -612,9 +612,8 @@ PUBLIC HTStream* HTSaveAndExecute ARGS3(
 
 	    StrAllocCopy(me->viewer_command, pres->command);
 
-	    me->end_command = (char *)calloc (
-			(strlen (pres->command) + 10 + strlen(view_fname))
-				 * sizeof (char),1);
+	    me->end_command = typecallocn(char,
+			strlen (pres->command) + 10 + strlen(view_fname));
 	    if (me->end_command == NULL)
 		outofmem(__FILE__, "HTSaveAndExecute");
 	    sprintf(me->end_command, pres->command, view_fname);
@@ -697,7 +696,7 @@ PUBLIC HTStream* HTSaveToFile ARGS3(
     int c = 0;
     BOOL IsBinary = TRUE;
 
-    ret_obj = (HTStream*)calloc(sizeof(* ret_obj),1);
+    ret_obj = typecalloc(HTStream);
     if (ret_obj == NULL)
 	outofmem(__FILE__, "HTSaveToFile");
     ret_obj->isa = &HTFWriter;
@@ -876,9 +875,16 @@ Prepend_BASE:
 
 	fprintf(ret_obj->fp,
 		"<!-- X-URL: %s -->\n", anchor->address);
-	if (anchor->date && *anchor->date)
-	     fprintf(ret_obj->fp,
+	if (anchor->date && *anchor->date) {
+	    fprintf(ret_obj->fp,
 		"<!-- Date: %s -->\n", anchor->date);
+	    if (anchor->last_modified && *anchor->last_modified
+			&& !strcmp(anchor->last_modified, anchor->date)
+			&& !strcmp(anchor->last_modified, ctime((time_t)0))) {
+		fprintf(ret_obj->fp,
+		    "<!-- Last-Modified: %s -->\n", anchor->last_modified);
+	    }
+	}
 	fprintf(ret_obj->fp,
 		"<BASE HREF=\"%s\">\n\n", (temp ? temp : anchor->address));
 	FREE(temp);
@@ -1017,7 +1023,7 @@ PUBLIC HTStream* HTCompressed ARGS3(
      *	Set up the stream structure for uncompressing and then
      *	handling based on the uncompressed Content-Type.- FM
      */
-    me = (HTStream*)calloc(sizeof(*me),1);
+    me = typecalloc(HTStream);
     if (me == NULL)
 	outofmem(__FILE__, "HTCompressed");
     me->isa = &HTFWriter;
@@ -1149,7 +1155,7 @@ PUBLIC HTStream* HTDumpToStdout ARGS3(
 	HTStream *,		sink GCC_UNUSED)
 {
     HTStream * ret_obj;
-    ret_obj = (HTStream*)calloc(sizeof(* ret_obj),1);
+    ret_obj = typecalloc(HTStream);
     if (ret_obj == NULL)
 	outofmem(__FILE__, "HTDumpToStdout");
     ret_obj->isa = &HTFWriter;
diff --git a/src/HTInit.c b/src/HTInit.c
index b3890286..76103f28 100644
--- a/src/HTInit.c
+++ b/src/HTInit.c
@@ -341,10 +341,8 @@ PRIVATE int ProcessMailcapEntry ARGS2(
     mc->testcommand = NULL;
     mc->label = NULL;
     mc->printcommand = NULL;
-    mc->contenttype = (char *)malloc(1 + strlen(rawentry));
-    if (!mc->contenttype)
-	ExitWithError(MEMORY_EXHAUSTED_ABORT);
-    strcpy(mc->contenttype, rawentry);
+    mc->contenttype = NULL;
+    StrAllocCopy(mc->contenttype, rawentry);
     mc->quality = 1.0;
     mc->maxbytes = 0;
     t = GetCommand(s, &mc->command);
@@ -507,15 +505,11 @@ PRIVATE int RememberTestResult ARGS3(
 		    return cur->result;
 	    return -1;
 	case RTR_add:
-	    cur = calloc(1, sizeof(struct cmdlist_s));
+	    cur = typecalloc(struct cmdlist_s);
 	    if (cur == NULL)
 		outofmem(__FILE__, "RememberTestResult");
 	    cur->next = cmdlist;
-	    cur->cmd = (char *)malloc(strlen(cmd) + 1);
-	    if(cur->cmd)
-		strcpy(cur->cmd, cmd);
-	    else
-		ExitWithError("Out of memory");
+	    StrAllocCopy(cur->cmd, cmd);
 	    cur->result = result;
 	    cmdlist = cur;
 	    break;
@@ -1150,10 +1144,8 @@ PRIVATE int HTLoadExtensionsConfigFile ARGS1(
 	HTGetWord(word, line, ' ', '\t');
 	if (line[0] == '\0' || word[0] == '#')
 	    continue;
-	ct = (char *)malloc(sizeof(char) * (strlen(word) + 1));
-	if (!ct)
-	    outofmem(__FILE__, "HTLoadExtensionsConfigFile");
-	strcpy(ct,word);
+	ct = NULL;
+	StrAllocCopy(ct, word);
 	LYLowerCase(ct);
 
 	while(line[0]) {
diff --git a/src/HTML.c b/src/HTML.c
index e79ef01e..18e2cb0d 100644
--- a/src/HTML.c
+++ b/src/HTML.c
@@ -85,7 +85,6 @@
 #define STACKLEVEL(me) ((me->stack + MAX_NESTING - 1) - me->sp)
 
 extern BOOL HTPassEightBitRaw;
-extern HTCJKlang HTCJK;
 
 extern BOOLEAN HT_Is_Gopher_URL;
 
@@ -991,7 +990,7 @@ PRIVATE int HTML_start_element ARGS6(
 	    if (tagname_transform!=0)
 		PUTS(tag->name);
 	    else {
-		strcpy(buf,tag->name);
+		LYstrncpy(buf, tag->name, sizeof(buf)-1);
 		LYLowerCase(buf);
 		PUTS(buf);
 	    }
@@ -1003,7 +1002,7 @@ PRIVATE int HTML_start_element ARGS6(
 			if (attrname_transform!=0)
 			    PUTS(tag->attributes[i].name);
 			else {
-			    strcpy(buf,tag->attributes[i].name);
+			    LYstrncpy(buf, tag->attributes[i].name, sizeof(buf)-1);
 			    LYLowerCase(buf);
 			    PUTS(buf);
 			}
@@ -1084,7 +1083,6 @@ PRIVATE int HTML_start_element ARGS6(
 #else
 # if !OMIT_SCN_KEEPING
     *Style_className_end=';';
-    /*strcpy(Style_className_end+1,HTML_dtd.tags[element_number].name);*/
     memcpy(Style_className_end+1,
 	   HTML_dtd.tags[element_number].name,
 	   HTML_dtd.tags[element_number].name_len+1);
@@ -1107,18 +1105,17 @@ PRIVATE int HTML_start_element ARGS6(
 #if !OPT_SCN
 	strcpy (myHash, HTML_dtd.tags[element_number].name);
 #else
-	hcode=hash_code_lowercase_on_fly(HTML_dtd.tags[element_number].name);
+	hcode = hash_code_lowercase_on_fly(HTML_dtd.tags[element_number].name);
 #endif
 	if (class_name[0])
 	{
 #if !OPT_SCN
+	    int len = strlen(myHash);
+	    sprintf(myHash, ".%.*s", (int)sizeof(myHash) - len - 2, class_name);
 	    HTSprintf (&Style_className, ".%s", class_name);
-	    strcat (myHash, ".");
-	    strcat (myHash, class_name);
 #else
-
 #   if !OMIT_SCN_KEEPING
-	    int l=strlen(class_name);
+	    int l = strlen(class_name);
 	    *Style_className_end = '.';
 	    memcpy(Style_className_end+1, class_name, l+1 );
 	    Style_className_end += l+1;
@@ -1140,7 +1137,7 @@ PRIVATE int HTML_start_element ARGS6(
 	fprintf(tfp, "CSSTRIM:%s -> %d", myHash, hcode);
 	if (hashStyles[hcode].code!=hcode)
 	{
-	    char *rp=strrchr(myHash, '.');
+	    char *rp = strrchr(myHash, '.');
 	    fprintf(tfp, " (undefined) %s\n", myHash);
 	    if (rp)
 	    {
@@ -1168,15 +1165,15 @@ PRIVATE int HTML_start_element ARGS6(
     } else { /* (current_tag_style!=-1)	 */
 	if (class_name[0]) {
 #if !OPT_SCN
+	    int len = strlen(myHash);
+	    sprintf(myHash, ".%.*s", (int)sizeof(myHash) - len - 2, class_name);
 	    HTSprintf (&Style_className, ".%s", class_name);
-	    strcat (myHash, ".");
-	    strcat (myHash, class_name);
 #else
 #     if !OMIT_SCN_KEEPING
 	    int l = strlen(class_name);
-	    *Style_className_end='.';
-	    memcpy(Style_className_end+1,class_name, l+1 );
-	    Style_className_end+=l+1;
+	    *Style_className_end = '.';
+	    memcpy(Style_className_end+1,class_name, l + 1 );
+	    Style_className_end += l + 1;
 #     endif
 #endif
 	    class_string[0] = '\0';
@@ -6158,7 +6155,7 @@ PRIVATE int HTML_end_element ARGS3(
 	    if (tagname_transform!=0)
 		PUTS(tag->name);
 	    else {
-		strcpy(buf,tag->name);
+		LYstrncpy(buf, tag->name, sizeof(buf)-1);
 		LYLowerCase(buf);
 		PUTS(buf);
 	    }
diff --git a/src/LYBookmark.c b/src/LYBookmark.c
index 848d4cc8..dfe82894 100644
--- a/src/LYBookmark.c
+++ b/src/LYBookmark.c
@@ -25,8 +25,6 @@ PUBLIC char *MBM_A_subdescript[MBM_V_MAXFILES+1];
 PRIVATE BOOLEAN is_mosaic_hotlist = FALSE;
 PRIVATE char * convert_mosaic_bookmark_file PARAMS((char *filename_buffer));
 
-extern HTCJKlang HTCJK;
-
 PRIVATE void
 show_bookmark_not_defined NOARGS
 {
@@ -246,7 +244,7 @@ PUBLIC void save_bookmark_link ARGS2(
 	    FREE(bookmark_URL);
 	    return;
 	}
-	strcpy(filename_buffer, filename);
+	LYstrncpy(filename_buffer, filename, sizeof(filename_buffer)-1);
     }
 
     /*
@@ -313,22 +311,7 @@ PUBLIC void save_bookmark_link ARGS2(
      *  from display character set which may need changing.
      *  Do NOT convert any 8-bit chars if we have CJK display. - LP
      */
-    if (HTCJK == JAPANESE) {
-	switch(kanji_code) {	/* 1997/11/22 (Sat) 09:28:00 */
-	case EUC:
-	    TO_EUC((CONST unsigned char *) string_buffer, (unsigned char *) tmp_buffer);
-	    break;
-	case SJIS:
-	    TO_SJIS((CONST unsigned char *) string_buffer, (unsigned char *) tmp_buffer);
-	    break;
-	default:
-	    TO_JIS((CONST unsigned char *) string_buffer, (unsigned char *) tmp_buffer);
-	    break;
-	}
-	StrAllocCopy(Title, tmp_buffer);
-    } else {
-	StrAllocCopy(Title, string_buffer);
-    }
+    LYformTitle(&Title, string_buffer);
     LYEntify(&Title, TRUE);
     if (UCSaveBookmarksInUnicode &&
 	have8bit(Title) && (!LYHaveCJKCharacterSet)) {
diff --git a/src/LYCgi.c b/src/LYCgi.c
index 3d075780..0ca3c78e 100644
--- a/src/LYCgi.c
+++ b/src/LYCgi.c
@@ -137,14 +137,7 @@ PUBLIC void add_lynxcgi_environment ARGS1(
     if (env_value != NULL) {
 	char *add_value = NULL;
 
-	add_value = (char *)malloc(strlen(variable_name) +
-				   strlen(env_value) + 2);
-	if (add_value == NULL) {
-	    outofmem(__FILE__, "LYCgi");
-	}
-	strcpy(add_value, variable_name);
-	strcat(add_value, "=");
-	strcat(add_value, env_value);
+	HTSprintf0(&add_value, "%s=%s", variable_name, env_value);
 	add_environment_value(add_value);
 	remember_alloced(add_value);
     }
@@ -220,8 +213,8 @@ PRIVATE int LYLoadCGI ARGS4(
 	    PERROR("stat() of pgm_buff failed");
 	} else {
 	    /* Found PATH_INFO data.  Strip it off of pgm and into path_info. */
-	    StrAllocCopy(path_info, pgm+strlen(pgm_buff));
-	    strcpy(pgm, pgm_buff);
+	    StrAllocCopy(path_info, pgm + strlen(pgm_buff));
+	    StrAllocCopy(pgm, pgm_buff);
 	    CTRACE((tfp, "LYNXCGI: stat() of %s succeeded, path_info=\"%s\".\n",
 			pgm_buff, path_info));
 	}
diff --git a/src/LYCharSets.c b/src/LYCharSets.c
index 6120a5a2..4e96b576 100644
--- a/src/LYCharSets.c
+++ b/src/LYCharSets.c
@@ -16,7 +16,6 @@ extern BOOL HTPassEightBitRaw;
 extern BOOL HTPassEightBitNum;
 extern BOOL HTPassHighCtrlRaw;
 extern BOOL HTPassHighCtrlNum;
-extern HTCJKlang HTCJK;
 PUBLIC HTkcode kanji_code = NOKANJI;
 PUBLIC BOOLEAN LYHaveCJKCharacterSet = FALSE;
 PUBLIC BOOLEAN DisplayCharsetMatchLocale = TRUE;
diff --git a/src/LYCharUtils.c b/src/LYCharUtils.c
index b5e8f58d..48eecd5f 100644
--- a/src/LYCharUtils.c
+++ b/src/LYCharUtils.c
@@ -42,7 +42,6 @@ extern BOOL HTPassEightBitRaw;
 extern BOOL HTPassEightBitNum;
 extern BOOL HTPassHighCtrlRaw;
 extern BOOL HTPassHighCtrlNum;
-extern HTCJKlang HTCJK;
 
 /*
  *  Used for nested lists. - FM
@@ -614,11 +613,12 @@ PUBLIC char *LYLowercaseA_OL_String ARGS1(
 /*
 ** This function returns OL TYPE="I" strings in the
 ** range of " I." (1) to "MMM." (3000).- FM
+** Maximum length: 16 -TD
 */
 PUBLIC char *LYUppercaseI_OL_String ARGS1(
 	int, seqnum)
 {
-    static char OLstring[8];
+    static char OLstring[20];
     int Arabic = seqnum;
 
     if (Arabic >= 3000) {
@@ -748,11 +748,12 @@ PUBLIC char *LYUppercaseI_OL_String ARGS1(
 /*
 ** This function returns OL TYPE="i" strings in
 ** range of " i." (1) to "mmm." (3000).- FM
+** Maximum length: 16 -TD
 */
 PUBLIC char *LYLowercaseI_OL_String ARGS1(
 	int, seqnum)
 {
-    static char OLstring[8];
+    static char OLstring[20];
     int Arabic = seqnum;
 
     if (Arabic >= 3000) {
@@ -4025,3 +4026,39 @@ PUBLIC BOOLEAN LYCommentHacks ARGS2(
 
     return FALSE;
 }
+
+    /*
+     *	Create the Title with any left-angle-brackets
+     *	converted to &lt; entities and any ampersands
+     *	converted to &amp; entities.  - FM
+     *
+     *  Convert 8-bit letters to &#xUUUU to avoid dependencies
+     *  from display character set which may need changing.
+     *  Do NOT convert any 8-bit chars if we have CJK display. - LP
+     */
+void LYformTitle ARGS2(
+	char **,	dst,
+	CONST char *,	src)
+{
+    if (HTCJK == JAPANESE) {
+	char *tmp_buffer = NULL;
+	if ((tmp_buffer = (char *) malloc (strlen(src)+1)) == 0)
+	    outofmem(__FILE__, "LYformTitle");
+	switch(kanji_code) {	/* 1997/11/22 (Sat) 09:28:00 */
+	case EUC:
+	    TO_EUC((CONST unsigned char *) src, (unsigned char *) tmp_buffer);
+	    break;
+	case SJIS:
+	    TO_SJIS((CONST unsigned char *) src, (unsigned char *) tmp_buffer);
+	    break;
+	default:
+	    CTRACE((tfp, "\nLYformTitle: kanji_code is an unexpected value."));
+	    strcpy(tmp_buffer, src);
+	    break;
+	}
+	StrAllocCopy(*dst, tmp_buffer);
+	FREE(tmp_buffer);
+    } else {
+	StrAllocCopy(*dst, src);
+    }
+}
diff --git a/src/LYCharUtils.h b/src/LYCharUtils.h
index 97cba343..4ca20000 100644
--- a/src/LYCharUtils.h
+++ b/src/LYCharUtils.h
@@ -52,6 +52,9 @@ extern void LYFillLocalFileURL PARAMS((
 extern void LYAddMETAcharsetToFD PARAMS((
 	FILE *		fd,
 	int		disp_chndl));
+extern void LYformTitle PARAMS((
+	char **		dst,
+	CONST char *	src));
 
 #ifdef Lynx_HTML_Handler
 extern int OL_CONTINUE;		/* flag for whether CONTINUE is set */
diff --git a/src/LYCookie.c b/src/LYCookie.c
index c0f6845a..b52f9907 100644
--- a/src/LYCookie.c
+++ b/src/LYCookie.c
@@ -142,7 +142,7 @@ PRIVATE void MemAllocCopy ARGS3(
 
 PRIVATE cookie * newCookie NOARGS
 {
-    cookie *p = (cookie *)calloc(1, sizeof(cookie));
+    cookie *p = typecalloc(cookie);
 
     if (p == NULL)
 	outofmem(__FILE__, "newCookie");
@@ -458,7 +458,7 @@ PRIVATE void store_cookie ARGS3(
 	/*
 	 *	Domain not found; add a new entry for this domain.
 	 */
-	de = (domain_entry *)calloc(1, sizeof(domain_entry));
+	de = typecalloc(domain_entry);
 	if (de == NULL)
 	    outofmem(__FILE__, "store_cookie");
 #if 0	/* was: ifdef EXP_PERSISTENT_COOKIES */
@@ -2030,11 +2030,7 @@ PUBLIC void LYLoadCookies ARGS1 (
 	};
     time_t expires;
 
-#ifdef DOSPATH	/* 1998/12/19 (Sat) 08:10:57 */
-    cookie_handle = fopen(cookie_file, "rt+");
-#else
-    cookie_handle = fopen(cookie_file, "r+");
-#endif
+    cookie_handle = fopen(cookie_file, TXT_R);
     if (!cookie_handle)
 	return;
 
@@ -2751,7 +2747,7 @@ PUBLIC void cookie_domain_flag_set ARGS2(
     domain_entry *de = NULL;
     domain_entry *de2 = NULL;
     HTList *hl = NULL;
-    char **str = (char **)calloc(1, sizeof(domainstr));
+    char **str = typecalloc(char *);
     char *dstr = NULL;
     char *strsmall = NULL;
     int isexisting = FALSE;
@@ -2804,7 +2800,7 @@ PUBLIC void cookie_domain_flag_set ARGS2(
 	}
 
 	if(!isexisting) {
-	    de = (domain_entry *)calloc(1, sizeof(domain_entry));
+	    de = typecalloc(domain_entry);
 
 	    if (de == NULL)
 		    outofmem(__FILE__, "cookie_domain_flag_set");
diff --git a/src/LYCurses.c b/src/LYCurses.c
index dce797f9..e475043d 100644
--- a/src/LYCurses.c
+++ b/src/LYCurses.c
@@ -193,7 +193,7 @@ PRIVATE void sl_suspend ARGS1(
     lynx_enable_mouse (1);
 #endif /* !VMS */
 #endif /* SIGSTOP */
-   return;
+    return;
 }
 
 #else  /* Not slang: */
@@ -289,24 +289,21 @@ PUBLIC HTCharStyle displayStyles[DSTYLE_ELEMENTS];
  */
 PUBLIC void setStyle ARGS4(int,style,int,color,int,cattr,int,mono)
 {
-	displayStyles[style].color=color;
-	displayStyles[style].cattr=cattr;
-	displayStyles[style].mono=mono;
+    displayStyles[style].color = color;
+    displayStyles[style].cattr = cattr;
+    displayStyles[style].mono = mono;
 }
 
 PUBLIC void setHashStyle ARGS5(int,style,int,color,int,cattr,int,mono,char*,element)
 {
-    bucket* ds=&hashStyles[style];
+    bucket* ds = &hashStyles[style];
     CTRACE((tfp, "CSS(SET): <%s> hash=%d, ca=%d, ma=%d\n", element, style, color, mono));
-    ds->color=color;
-    ds->cattr=cattr;
-    ds->mono=mono;
-    ds->code=style;
+    ds->color = color;
+    ds->cattr = cattr;
+    ds->mono = mono;
+    ds->code = style;
     FREE(ds->name);
-    ds->name=malloc(sizeof(char)*(strlen(element)+2));
-    if(!ds->name)
-	outofmem(__FILE__, "setHashStyle");
-    strcpy(ds->name, element);
+    StrAllocCopy(ds->name, element);
 }
 
 /*
@@ -729,8 +726,10 @@ PUBLIC void start_curses NOARGS
 	size_change(0);
 
 #if (defined(VMS) || defined(UNIX)) && !defined(__CYGWIN__)
-	SLtt_add_color_attribute(4, SLTT_ULINE_MASK);
-	SLtt_add_color_attribute(5, SLTT_ULINE_MASK);
+	if ((Masked_Attr & SLTT_ULINE_MASK) == 0) {
+	    SLtt_add_color_attribute(4, SLTT_ULINE_MASK);
+	    SLtt_add_color_attribute(5, SLTT_ULINE_MASK);
+	}
 	/*
 	 *  If set, the blink escape sequence will turn on high
 	 *  intensity background (rxvt and maybe Linux console).
@@ -837,19 +836,14 @@ PUBLIC void start_curses NOARGS
 	    lynx_has_color = TRUE;
 	    start_color();
 #if USE_DEFAULT_COLORS
-#if HAVE_USE_DEFAULT_COLORS	/* ncurses 4.1 */
-#if HAVE_ASSUME_DEFAULT_COLORS	/* ncurses 5.1 */
-#if !defined(USE_COLOR_STYLE)
+#ifdef EXP_ASSUMED_COLOR
 	    /*
-	     * If no "default" color was specified in the cfg file, adjust the
-	     * color mapping table so we'll not use the codes that would work
-	     * if we had called use_default_colors().
+	     * Adjust the color mapping table to match the ASSUMED_COLOR
+	     * setting in lynx.cfg
 	     */
-	    if (default_fg < 0 || default_bg < 0) {
-		if (assume_default_colors(default_fg, default_bg) != OK) {
-		    default_fg = COLOR_WHITE;
-		    default_bg = COLOR_BLACK;
-		}
+	    if (assume_default_colors(default_fg, default_bg) != OK) {
+		default_fg = COLOR_WHITE;
+		default_bg = COLOR_BLACK;
 	    }
 	    if (default_fg >= 0 || default_bg >= 0) {
 		unsigned n;
@@ -864,11 +858,9 @@ PUBLIC void start_curses NOARGS
 		}
 		lynx_setup_colors();
 	    }
-#endif
 #else
 	    lynx_default_colors();
-#endif /* HAVE_ASSUME_DEFAULT_COLORS */
-#endif /* HAVE_USE_DEFAULT_COLORS */
+#endif /* EXP_ASSUMED_COLOR */
 #endif /* USE_DEFAULT_COLORS */
 	}
 #endif /* USE_COLOR_STYLE || USE_COLOR_TABLE */
@@ -910,7 +902,7 @@ PUBLIC void start_curses NOARGS
     keypad(stdscr,TRUE);
 #endif /* HAVE_KEYPAD */
 
-   lynx_enable_mouse (1);
+    lynx_enable_mouse (1);
 
     fflush(stdin);
     fflush(stdout);
@@ -952,7 +944,6 @@ PUBLIC void lynx_enable_mouse ARGS1(int,state)
     SLtt_flush_output ();
 #else
 
-#ifdef NCURSES_MOUSE_VERSION
 #if defined(WIN_EX) && defined(PDCURSES)
     if (state)
     {
@@ -960,6 +951,7 @@ PUBLIC void lynx_enable_mouse ARGS1(int,state)
 	FlushConsoleInputBuffer(hConIn);
     }
 #else
+#ifdef NCURSES_MOUSE_VERSION
     if (state) {
 	/* Compensate for small value of maxclick in ncurses.  */
 	static int was = 0;
@@ -991,12 +983,15 @@ PUBLIC void lynx_enable_mouse ARGS1(int,state)
 		  NULL);
     } else
 	mousemask(0, NULL);
-#endif /* WIN_EX and PDCURSES */
 #endif /* NCURSES_MOUSE_VERSION */
+#endif /* WIN_EX and PDCURSES */
 
-#if defined(DJGPP) && !defined(USE_SLANG)
+#if defined(PDCURSES)
     if (state)
-	mouse_set(BUTTON1_CLICKED | BUTTON2_CLICKED | BUTTON3_CLICKED);
+	mouse_set(
+	    	BUTTON1_CLICKED | BUTTON1_PRESSED | BUTTON1_RELEASED |
+		BUTTON2_CLICKED | BUTTON2_PRESSED | BUTTON2_RELEASED |
+		BUTTON3_CLICKED | BUTTON3_PRESSED | BUTTON3_RELEASED);
 #endif
 #endif				/* NOT USE_SLANG_MOUSE */
 }
@@ -1022,7 +1017,7 @@ PUBLIC void stop_curses NOARGS
      */
     if(LYCursesON == TRUE)	{
 	 lynx_enable_mouse (0);
-#ifndef WIN_EX	/* @@@ */
+#if (!defined(WIN_EX) || defined(__CYGWIN__))	/* @@@ */
 	 endwin();	/* stop curses */
 #endif
     }
diff --git a/src/LYCurses.h b/src/LYCurses.h
index 9248e6a3..882e3d8f 100644
--- a/src/LYCurses.h
+++ b/src/LYCurses.h
@@ -105,6 +105,13 @@
 #define USE_KEYMAPS		1
 #endif
 
+#ifndef getbegx
+#define getbegx(win) ((win)->_begx)
+#endif
+#ifndef getbegy
+#define getbegy(win) ((win)->_begy)
+#endif
+
 #else
 # if defined(VMS) && defined(__GNUC__)
 #  include <LYGCurses.h>
@@ -407,6 +414,16 @@ FANCY_CURSES.  Check your config.log to see why the FANCY_CURSES test failed.
 #endif /* getyx */
 #endif /* USE_SLANG */
 
+/*
+ * If the screen library allows us to specify "default" color, allow user to 
+ * control it.
+ */
+#if USE_DEFAULT_COLORS
+#if USE_SLANG || (HAVE_ASSUME_DEFAULT_COLORS && !defined(USE_COLOR_STYLE))
+#define EXP_ASSUMED_COLOR 1
+#endif
+#endif
+
 extern void lynx_enable_mouse PARAMS((int));
 extern void lynx_force_repaint NOPARAMS;
 extern void lynx_start_title_color NOPARAMS;
diff --git a/src/LYDownload.c b/src/LYDownload.c
index 021ee27b..be1a8134 100644
--- a/src/LYDownload.c
+++ b/src/LYDownload.c
@@ -165,7 +165,7 @@ check_recall:
 		} else if ((cp = (char *)HTList_objectAt(
 						sug_filenames,
 						FnameNum)) != NULL) {
-		    strcpy(buffer, cp);
+		    LYstrncpy(buffer, cp, sizeof(buffer)-1);
 		    if (FnameTotal == 1) {
 			_statusline(EDIT_THE_PREV_FILENAME);
 		    } else {
@@ -198,7 +198,7 @@ check_recall:
 		} else if ((cp = (char *)HTList_objectAt(
 						sug_filenames,
 						FnameNum)) != NULL) {
-		    strcpy(buffer, cp);
+		    LYstrncpy(buffer, cp, sizeof(buffer)-1);
 		    if (FnameTotal == 1) {
 			_statusline(EDIT_THE_PREV_FILENAME);
 		    } else {
@@ -346,7 +346,7 @@ check_recall:
 			} else if ((cp = (char *)HTList_objectAt(
 							sug_filenames,
 							FnameNum)) != NULL) {
-			    strcpy(buffer, cp);
+			    LYstrncpy(buffer, cp, sizeof(buffer)-1);
 			    if (FnameTotal == 1) {
 				_statusline(EDIT_THE_PREV_FILENAME);
 			    } else {
@@ -379,7 +379,7 @@ check_recall:
 			} else if ((cp = (char *)HTList_objectAt(
 							sug_filenames,
 							FnameNum)) != NULL) {
-			    strcpy(buffer, cp);
+			    LYstrncpy(buffer, cp, sizeof(buffer)-1);
 			    if (FnameTotal == 1) {
 				_statusline(EDIT_THE_PREV_FILENAME);
 			    } else {
diff --git a/src/LYEdit.c b/src/LYEdit.c
index cd2bbbb0..966f8d68 100644
--- a/src/LYEdit.c
+++ b/src/LYEdit.c
@@ -57,7 +57,7 @@ PUBLIC int edit_current_file ARGS3(
     char *format = "%s %s";
     char *command = NULL;
     char *filename = NULL;
-#if (!(defined(VMS) || defined(DOSPATH) || defined(__EMX__)) || defined(SH_EX))
+#if !(defined(VMS) || defined(DOSPATH) || defined(__EMX__))
     char *colon;
 #endif
     char *number_sign;
diff --git a/src/LYExtern.c b/src/LYExtern.c
index cc7a41ea..826c30f0 100644
--- a/src/LYExtern.c
+++ b/src/LYExtern.c
@@ -82,25 +82,23 @@ PUBLIC char *string_short ARGS2(
 	char *,		str,
 	int,		cut_pos)
 {
-    char buff[STRING_MAX];
+    char buff[STRING_MAX], *s, *d;
     static char s_str[STRING_MAX];
-    char *p;
     int len;
 
-    p = str;
-    len = strlen(p);
-
-    if (len > STRING_MAX) {
-	strncpy(buff, p, STRING_MAX - 1);
-	buff[STRING_MAX - 1] = '\0';
-	len = STRING_MAX - 1;
-    } else {
-	strcpy(buff, p);
-    }
+    LYstrncpy(buff, str, sizeof(buff)-1);
+    len = strlen(buff);
     if (len > (LYcols - 10)) {
 	buff[cut_pos] = '.';
 	buff[cut_pos + 1] = '.';
-	strcpy(buff + cut_pos + 2, (buff + len) - (LYcols - 10) + cut_pos + 1);
+	for (s = (buff + len) - (LYcols - 10) + cut_pos + 1,
+	     d = (buff + cut_pos) + 2;
+	     s >= buff &&
+	     d >= buff &&
+	     d < buff + LYcols &&
+	     (*d++ = *s++) != 0; )
+	    ;
+	buff[LYcols] = 0;
     }
     strcpy(s_str, buff);
     return (s_str);
@@ -117,22 +115,12 @@ PUBLIC char *string_short ARGS2(
 PUBLIC char * quote_pathname ARGS1(
 	char *, 	pathname)
 {
-    size_t n = 0;
-    char * result;
+    char * result = NULL;
 
     if (strchr(pathname, ' ') != NULL) {
-	n = strlen(pathname);
-	result = (char *)malloc(n + 3);
-	if (result == NULL)
-	    outofmem(__FILE__, "quote_pathname");
-	result[0] = '"';
-	strcpy(result + 1, pathname);
-	result[n+1] = '"';
-	result[n+2] = '\0';
+	HTSprintf0(&result, "\"%s\"", pathname);
     } else {
-	result = strdup(pathname);
-	if (result == NULL)
-	    outofmem(__FILE__, "quote_pathname");
+	StrAllocCopy(result, pathname);
     }
     return result;
 }
@@ -268,7 +256,7 @@ void run_external ARGS1(char *, c)
 		    }
 		    if (*e_buff != '\"' && strchr(e_buff, ' ') != NULL) {
 			p = quote_pathname(e_buff);
-			strcpy(e_buff, p);
+			LYstrncpy(e_buff, p, sizeof(e_buff)-1);
 			FREE(p);
 		    }
 
@@ -287,9 +275,7 @@ void run_external ARGS1(char *, c)
 	    }
 #else	/* Unix */
 	    {
-		char *cp = HTQuoteParameter(c);
-		format(&cmdbuf, externals2->command, cp);
-		FREE(cp);
+		format(&cmdbuf, externals2->command, c);
 	    }
 #endif
 #endif	/* VMS */
diff --git a/src/LYForms.c b/src/LYForms.c
index 03a9e166..4a3ae9d4 100644
--- a/src/LYForms.c
+++ b/src/LYForms.c
@@ -26,8 +26,6 @@
 #define CTRL_W_HACK 23  /* CTRL-W refresh without clearok */
 #endif /* VMS && !USE_SLANG */
 
-extern HTCJKlang HTCJK;
-
 PRIVATE int form_getstr PARAMS((
 	struct link *	form_link,
 	BOOLEAN		use_last_tfpos,
@@ -464,11 +462,11 @@ again:
 	    ch = 7;
 	}
 #endif /* VMS */
-#  ifdef NCURSES_MOUSE_VERSION
+#  if defined(NCURSES_MOUSE_VERSION) || defined(PDCURSES)
 	if (ch != -1 && (ch & LKC_ISLAC) && !(ch & LKC_ISLECLAC)) /* already lynxactioncode? */
 	    break;	/* @@@ maybe move these 2 lines outside ifdef -kw */
 	if (ch == MOUSE_KEY) {		/* Need to process ourselves */
-#if defined(WIN_EX)
+#if defined(PDCURSES)
 	    int curx, cury;
 
 	    request_mouse_pos();
@@ -495,7 +493,7 @@ again:
 		} else
 		    ch = RTARROW;
 	    }
-#endif /* WIN_EX */
+#endif /* PDCURSES */
 	    else {
 		/*  Mouse event passed to us as MOUSE_KEY, and apparently
 		 *  not on this field's line?  Something is not as it
@@ -508,7 +506,7 @@ again:
 	    }
 	    last_xlkc = -1;
 	} else
-#  endif	/* defined NCURSES_MOUSE_VERSION */
+#  endif	/* defined NCURSES_MOUSE_VERSION || PDCURSES */
 	{
 	    if (!(ch & LKC_ISLECLAC))
 		ch |= MyEdit.current_modifiers;
@@ -1600,7 +1598,7 @@ redraw:
 		     */
 		    if ((cp = (char *)HTList_objectAt(search_queries,
 						      0)) != NULL) {
-			strcpy(prev_target_buffer, cp);
+			LYstrncpy(prev_target_buffer, cp, sizeof(prev_target_buffer));
 			QueryNum = 0;
 			FirstRecall = FALSE;
 		    }
@@ -1665,7 +1663,7 @@ check_recall:
 		    }
 		    if ((cp = (char *)HTList_objectAt(search_queries,
 						      QueryNum)) != NULL) {
-			strcpy(prev_target, cp);
+			LYstrncpy(prev_target, cp, sizeof(prev_target)-1);
 			if (*prev_target_buffer &&
 			    !strcmp(prev_target_buffer, prev_target)) {
 			    _statusline(EDIT_CURRENT_QUERY);
@@ -1720,7 +1718,7 @@ check_recall:
 		    }
 		    if ((cp = (char *)HTList_objectAt(search_queries,
 						      QueryNum)) != NULL) {
-			strcpy(prev_target, cp);
+			LYstrncpy(prev_target, cp, sizeof(prev_target)-1);
 			if (*prev_target_buffer &&
 			    !strcmp(prev_target_buffer, prev_target)) {
 			    _statusline(EDIT_CURRENT_QUERY);
diff --git a/src/LYGetFile.c b/src/LYGetFile.c
index bb70c2e6..0ac77c47 100644
--- a/src/LYGetFile.c
+++ b/src/LYGetFile.c
@@ -460,7 +460,7 @@ Try_Redirected_URL:
 			       exec_ok(HTLoadedDocumentURL(),
 				       doc->address+9, EXEC_PATH))) {
 
-			char *p, addressbuf[1024];
+			char *p = NULL;
 
 			/*
 			 *  Bug puts slash on end if none is in the string.
@@ -470,17 +470,17 @@ Try_Redirected_URL:
 			 == (int)strlen(doc->address) - 1)
 			    doc->address[strlen(doc->address)-1] = '\0';
 
-			p = doc->address;
 			/*
 			 *  Convert '~' to $HOME.
 			 */
 			if ((cp = strchr(doc->address, '~'))) {
-			    strncpy(addressbuf, doc->address, cp-doc->address);
-			    addressbuf[cp - doc->address] = '\0';
-			    p = wwwName(Home_Dir());
-			    strcat(addressbuf, p);
-			    strcat(addressbuf, cp+1);
-			    p = addressbuf;
+			    HTSprintf0(&p, "%.*s%s%s",
+					   cp - doc->address,
+					   doc->address,
+					   wwwName(Home_Dir()),
+					   cp + 1);
+			} else {
+			    StrAllocCopy(p, doc->address);
 			}
 			/*
 			 *  Show URL before executing it.
@@ -494,6 +494,8 @@ Try_Redirected_URL:
 			    LYSystem(p+11);
 			else
 			    LYSystem(p+9);
+			FREE(p);
+
 			if (url_type != LYNXPROG_URL_TYPE) {
 			    /*
 			     *	Make sure user gets to see screen output.
diff --git a/src/LYGlobalDefs.h b/src/LYGlobalDefs.h
index c394e812..64efc253 100644
--- a/src/LYGlobalDefs.h
+++ b/src/LYGlobalDefs.h
@@ -177,6 +177,7 @@ extern BOOLEAN is_www_index;
 extern BOOLEAN jump_buffer;     /* TRUE if offering default shortcut */
 extern BOOLEAN long_url_ok;
 extern BOOLEAN lynx_mode;
+extern BOOLEAN lynx_temp_subspace;
 extern BOOLEAN news_ok;
 extern BOOLEAN recent_sizechange;
 extern BOOLEAN rlogin_ok;
@@ -184,8 +185,8 @@ extern BOOLEAN system_editor;	  /* True if locked-down editor */
 extern BOOLEAN telnet_ok;
 extern BOOLEAN verbose_img;	/* display filenames of images?     */
 extern BOOLEAN vi_keys;		/* TRUE to turn on vi-like key movement */
-extern char *LYRequestTitle;	/* newdoc.title in calls to getfile() */
 extern char *LYRequestReferer;	/* Referer, may be set in getfile() */
+extern char *LYRequestTitle;	/* newdoc.title in calls to getfile() */
 extern char *LynxHome;
 extern char *LynxSigFile;	/* Signature file, in or off home */
 extern char *checked_box;	/* form boxes */
diff --git a/src/LYHash.c b/src/LYHash.c
index a40f392b..d32669f0 100644
--- a/src/LYHash.c
+++ b/src/LYHash.c
@@ -5,24 +5,6 @@
 
 #ifdef USE_COLOR_STYLE
 
-#ifdef NOT_USED
-
-PUBLIC int hash_table[CSHASHSIZE]; /* 32K should be big enough */
-
-PUBLIC int hash_code_rp ARGS1(char*,string)
-{
-    char* hash_ptr = string;
-    int hash_tmp = 0xC00A | ((*hash_ptr) << 4);
-
-    while (*hash_ptr++)
-    {
-	hash_tmp ^= (((*hash_ptr)<<4) ^ ((*hash_ptr)<<12));
-	hash_tmp >>= 1;
-    }
-    return (hash_tmp % CSHASHSIZE);
-}
-#endif
-
 /*
  *  This is the same function as the private HASH_FUNCTION() in HTAnchor.c,
  *  but with a different value for HASH_SIZE.
diff --git a/src/LYHash.h b/src/LYHash.h
index 793eebbe..383261f1 100644
--- a/src/LYHash.h
+++ b/src/LYHash.h
@@ -37,11 +37,6 @@ extern int hash_code_lowercase_on_fly PARAMS((char* string));
 extern int hash_code_aggregate_char PARAMS((char c,int hash));
 extern int hash_code_aggregate_lower_str  PARAMS((char* c,int hash_was));
 
-
-#ifdef NOT_USED
-extern int hash_table[CSHASHSIZE]; /* 32K should be big enough */
-#endif
-
 extern int	s_alink, s_a, s_status,
 		s_label, s_value, s_high,
 		s_normal, s_alert, s_title,
diff --git a/src/LYHistory.c b/src/LYHistory.c
index c8b70d00..3ffbe9d0 100644
--- a/src/LYHistory.c
+++ b/src/LYHistory.c
@@ -38,8 +38,6 @@ PRIVATE VisitedLink *Latest_tree;
 PRIVATE VisitedLink *First_tree;
 PRIVATE VisitedLink *Last_by_first;
 
-extern HTCJKlang HTCJK;
-
 #ifdef LY_FIND_LEAKS
 /*
  *  Utility for freeing the list of visited links. - FM
@@ -78,7 +76,6 @@ PUBLIC void LYAddVisitedLink ARGS1(
     VisitedLink *new;
     HTList *cur;
     char *title = (doc->title ? doc->title : NO_TITLE);
-    char *tmp_buffer = NULL;
 
     if (!(doc->address && *doc->address)) {
 	PrevVisitedLink = NULL;
@@ -157,29 +154,10 @@ PUBLIC void LYAddVisitedLink ARGS1(
 	}
     }
 
-    if ((new = (VisitedLink *)calloc(1, sizeof(*new))) == NULL)
+    if ((new = typecalloc(VisitedLink)) == NULL)
 	outofmem(__FILE__, "LYAddVisitedLink");
     StrAllocCopy(new->address, doc->address);
-    if (HTCJK == JAPANESE) {
-	if ((tmp_buffer = (char *) malloc (strlen(title)+1)) == 0)
-	    outofmem(__FILE__, "LYAddVisitedLink");
-	switch(kanji_code) {
-	case EUC:
-	    TO_EUC((CONST unsigned char *) title, (unsigned char *) tmp_buffer);
-	    break;
-	case SJIS:
-	    TO_SJIS((CONST unsigned char *) title, (unsigned char *) tmp_buffer);
-	    break;
-	default:
-	    CTRACE((tfp, "\nLYADDVisitedLink: kanji_code is an unexpected value."));
-	    strcpy(tmp_buffer, title);
-	    break;
-	}
-	StrAllocCopy(new->title, tmp_buffer);
-	FREE(tmp_buffer);
-    } else {
-	StrAllocCopy(new->title, title);
-    }
+    LYformTitle(&(new->title), title);
 
     /* First-visited chain */
     HTList_appendObject(Visited_Links, new);	/* At end */
@@ -282,8 +260,6 @@ PUBLIC void LYpush ARGS2(
 	document *,	doc,
 	BOOLEAN,	force_push)
 {
-    char *tmp_buffer = NULL;
-
     /*
      *	Don't push NULL file names.
      */
@@ -334,26 +310,7 @@ PUBLIC void LYpush ARGS2(
 	history[nhist].link = doc->link;
 	history[nhist].line = doc->line;
 	history[nhist].title = NULL;
-	if (HTCJK == JAPANESE) {
-	    if ((tmp_buffer = (char *) malloc (strlen(doc->title)+1)) == 0)
-		outofmem(__FILE__, "LYpush");
-	    switch(kanji_code) {
-	    case EUC:
-	    	TO_EUC((CONST unsigned char *) doc->title, (unsigned char *) tmp_buffer);
-	    	break;
-	    case SJIS:
-	    	TO_SJIS((CONST unsigned char *) doc->title, (unsigned char *) tmp_buffer);
-	    	break;
-	    default:
-		CTRACE((tfp, "\nLYpush: kanji_code is an unexpected value."));
-		strcpy(tmp_buffer, doc->title);
-	    	break;
-	    }
-	    StrAllocCopy(history[nhist].title, tmp_buffer);
-	    FREE(tmp_buffer);
-	} else {
-	    StrAllocCopy(history[nhist].title, doc->title);
-	}
+	LYformTitle(&(history[nhist].title), doc->title);
 	history[nhist].address = NULL;
 	StrAllocCopy(history[nhist].address, doc->address);
 	history[nhist].post_data = NULL;
diff --git a/src/LYJump.c b/src/LYJump.c
index 3da3b870..8f2758c4 100644
--- a/src/LYJump.c
+++ b/src/LYJump.c
@@ -57,16 +57,14 @@ PUBLIC void LYJumpTable_free NOARGS
  */
 PUBLIC void LYAddJumpShortcut ARGS2(HTList *, historyp, char *,shortcut)
 {
-    char *new;
+    char *new = NULL;
     char *old;
     HTList *cur =  historyp;
 
     if (!historyp || !(shortcut && *shortcut))
 	return;
 
-    if ((new = (char *)calloc(1, (strlen(shortcut) + 1))) == NULL)
-	outofmem(__FILE__, "LYAddJumpShortcut");
-    strcpy(new, shortcut);
+    StrAllocCopy(new, shortcut);
 
     while (NULL != (old = (char *)HTList_nextObject(cur))) {
 	if (!strcmp(old, new)) {
@@ -88,7 +86,7 @@ PUBLIC BOOL LYJumpInit ARGS1 (char *, config)
     /*
      * Create a JumpTable structure.
      */
-    jtp = (struct JumpTable *) calloc(1, sizeof(*jtp));
+    jtp = typecalloc(struct JumpTable);
     if (jtp == NULL) {
 	outofmem(__FILE__, "LYJumpInit");
     }
@@ -148,7 +146,7 @@ PUBLIC BOOL LYJumpInit ARGS1 (char *, config)
 	StrAllocCopy(JThead->msg, jumpprompt);
 	if (!jumpfile)
 	    StrAllocCopy(jumpfile, JThead->file);
-	jtp = (struct JumpTable *) calloc(1, sizeof(*jtp));
+	jtp = typecalloc(struct JumpTable);
 	if (jtp == NULL) {
 	    outofmem(__FILE__, "LYJumpInit");
 	}
@@ -259,11 +257,8 @@ check_recall:
 	    HTUserMsg(RANDOM_URL_DISALLOWED);
 	    return NULL;
 	}
-	StrAllocCopy(temp, "Go ");
-	StrAllocCat(temp, bp);
-	strcpy(buf, temp);
-	FREE(temp);
-	return(bp=buf);
+	sprintf(buf, "Go %.*s", (int)sizeof(buf) - 4, bp);
+	return (bp = buf);
     }
 #endif /* PERMIT_GOTO_FROM_JUMP */
 
@@ -287,7 +282,7 @@ check_recall:
 	    ShortcutNum = 0;
 	if ((cp=(char *)HTList_objectAt(jtp->history,
 					ShortcutNum)) != NULL) {
-	    strcpy(buf, cp);
+	    LYstrncpy(buf, cp, sizeof(buf)-1);
 	    if (jump_buffer && jtp->shortcut &&
 		!strcmp(buf, jtp->shortcut)) {
 		_statusline(EDIT_CURRENT_SHORTCUT);
@@ -327,7 +322,7 @@ check_recall:
 	    ShortcutNum = ShortcutTotal - 1;
 	if ((cp=(char *)HTList_objectAt(jtp->history,
 					ShortcutNum)) != NULL) {
-	    strcpy(buf, cp);
+	    LYstrncpy(buf, cp, sizeof(buf)-1);
 	    if (jump_buffer && jtp->shortcut &&
 		!strcmp(buf, jtp->shortcut)) {
 		_statusline(EDIT_CURRENT_SHORTCUT);
diff --git a/src/LYList.c b/src/LYList.c
index 3b60816d..fcc1ad74 100644
--- a/src/LYList.c
+++ b/src/LYList.c
@@ -13,6 +13,7 @@
 #include <LYClean.h>
 #include <LYGlobalDefs.h>
 #include <LYCharUtils.h>
+#include <LYCharSets.h>
 
 #ifdef DIRED_SUPPORT
 #include <LYUpload.h>
@@ -166,7 +167,7 @@ PUBLIC int showlist ARGS2(
 	FREE(address);
 	LYEntify(&Address, TRUE);
 	if (title && *title) {
-	    StrAllocCopy(Title, title);
+	    LYformTitle(&Title, title);
 	    LYEntify(&Title, TRUE);
 	    if (*Title) {
 		cp = strchr(Address, '#');
diff --git a/src/LYLocal.c b/src/LYLocal.c
index 60244df9..c4cf5f00 100644
--- a/src/LYLocal.c
+++ b/src/LYLocal.c
@@ -349,6 +349,8 @@ PRIVATE int move_file ARGS2(char *, source, char *, target)
     if ((code = rename(source, target)) != 0)
 	if ((code = LYCopyFile(source, target)) >= 0)
 	    code = remove(source);
+    if (code == 0)
+	code = 1;
 #else
     char *msg = 0;
     char *args[5];
@@ -384,10 +386,10 @@ PRIVATE BOOLEAN not_already_exists ARGS1(char *, name)
     return FALSE;
 }
 
-PRIVATE BOOLEAN dir_has_same_owner ARGS2(struct stat *, info, uid_t, owner)
+PRIVATE BOOLEAN dir_has_same_owner ARGS2(struct stat *, info, int, owner)
 {
     if (S_ISDIR(info->st_mode)) {
-	if (info->st_uid == owner) {
+	if ((int) info->st_uid == owner) {
 	    return TRUE;
 	} else {
 	    HTAlert(gettext("Destination has different owner!  Request denied."));
@@ -469,7 +471,7 @@ PRIVATE BOOLEAN modify_tagged ARGS1(
     char *cp;
     dev_t dev;
     ino_t inode;
-    uid_t owner;
+    int owner;
     char tmpbuf[1024];
     char *savepath;
     char *srcpath = NULL;
@@ -554,7 +556,7 @@ PRIVATE BOOLEAN modify_tagged ARGS1(
 		FREE(cp1);
 		return 0;
 	    }
-	    strcpy(tmpbuf, cp1);
+	    LYstrncpy(tmpbuf, cp1, sizeof(tmpbuf)-1);
 	    FREE(cp1);
 	}
 
@@ -624,9 +626,9 @@ PRIVATE BOOLEAN modify_name ARGS1(
 {
     char *cp;
     char tmpbuf[DIRED_MAXBUF];
-    char newpath[DIRED_MAXBUF];
-    char savepath[DIRED_MAXBUF];
+    char *newpath = NULL;
     struct stat dir_info;
+    int code = 0;
 
     /*
      *	Determine the status of the selected item.
@@ -652,22 +654,23 @@ PRIVATE BOOLEAN modify_name ARGS1(
 	 */
 	if (LYLastPathSep(tmpbuf) != 0) {
 	    HTAlert(gettext("Illegal character (path-separator) found! Request ignored."));
-	} else if (strlen(tmpbuf) &&
-		   (cp = LYLastPathSep(testpath)) != NULL) {
-	    strcpy(savepath,testpath);
-	    *(++cp) = '\0';
-	    strcpy(newpath,testpath);
-	    strcat(newpath,tmpbuf);
+	} else if (strlen(tmpbuf)) {
+	    if ((cp = LYLastPathSep(testpath)) != NULL)
+		HTSprintf0(&newpath, "%.*s%s", (cp - testpath + 1), testpath, tmpbuf);
+	    else
+		StrAllocCopy(newpath, tmpbuf);
 
 	    /*
 	     *	Make sure the destination does not already exist.
 	     */
 	    if (not_already_exists(newpath)) {
-		return move_file(savepath, newpath);
+		code = move_file(testpath, newpath);
 	    }
+	    FREE(newpath);
+
 	}
     }
-    return 0;
+    return code;
 }
 
 /*
@@ -679,11 +682,12 @@ PRIVATE BOOLEAN modify_location ARGS1(
     char *cp;
     dev_t dev;
     ino_t inode;
-    uid_t owner;
+    int owner;
     char tmpbuf[1024];
-    char newpath[DIRED_MAXBUF];
-    char savepath[DIRED_MAXBUF];
+    char *newpath = NULL;
+    char *savepath = NULL;
     struct stat dir_info;
+    int code = 0;
 
     /*
      *	Determine the status of the selected item.
@@ -707,28 +711,28 @@ PRIVATE BOOLEAN modify_location ARGS1(
     if (get_filename(cp, tmpbuf, sizeof(tmpbuf)) == NULL)
 	return 0;
     if (strlen(tmpbuf)) {
-	strcpy(savepath, testpath);
-	strcpy(newpath, testpath);
+	StrAllocCopy(savepath, testpath);
+	StrAllocCopy(newpath, testpath);
 
 	/*
 	 *  Allow ~/ references to the home directory.
 	 */
 	if (!strncmp(tmpbuf, "~/", 2)
 	 || !strcmp(tmpbuf,"~")) {
-	    strcpy(newpath, Home_Dir());
-	    strcat(newpath, (tmpbuf + 1));
-	    strcpy(tmpbuf, newpath);
+	    StrAllocCopy(newpath, Home_Dir());
+	    StrAllocCat(newpath, (tmpbuf + 1));
+	    LYstrncpy(tmpbuf, newpath, sizeof(tmpbuf)-1);
 	}
 	if (LYisAbsPath(tmpbuf)) {
-	    strcpy(newpath,tmpbuf);
+	    StrAllocCopy(newpath, tmpbuf);
+	} else if ((cp = LYLastPathSep(newpath)) != NULL) {
+	    *++cp = '\0';
+	    StrAllocCat(newpath, tmpbuf);
 	} else {
-	    if ((cp = LYLastPathSep(newpath)) != NULL) {
-		*++cp = '\0';
-		strcat(newpath,tmpbuf);
-	    } else {
-		HTAlert(gettext("Unexpected failure - unable to find trailing path separator"));
-		return 0;
-	    }
+	    HTAlert(gettext("Unexpected failure - unable to find trailing path separator"));
+	    FREE(newpath);
+	    FREE(savepath);
+	    return 0;
 	}
 
 	/*
@@ -738,21 +742,22 @@ PRIVATE BOOLEAN modify_location ARGS1(
 	inode = dir_info.st_ino;
 	owner = dir_info.st_uid;
 	if (!ok_stat(newpath, &dir_info)) {
-	    return 0;
+	    code = 0;
 	}
 
 	/*
 	 *  Make sure the source and target are not the same location.
 	 */
-	if (dev == dir_info.st_dev && inode == dir_info.st_ino) {
+	else if (dev == dir_info.st_dev && inode == dir_info.st_ino) {
 	    HTAlert(gettext("Source and destination are the same location!  Request ignored!"));
-	    return 0;
-	}
-	if (dir_has_same_owner(&dir_info, owner)) {
-	    return move_file(savepath,newpath);
+	    code = 0;
+	} else if (dir_has_same_owner(&dir_info, owner)) {
+	    code = move_file(savepath,newpath);
 	}
+	FREE(newpath);
+	FREE(savepath);
     }
-    return 0;
+    return code;
 }
 
 /*
@@ -804,7 +809,7 @@ PUBLIC BOOLEAN local_modify ARGS2(
 	    FREE(cp);
 	    return 0;
 	}
-	strcpy(testpath, cp);
+	LYstrncpy(testpath, cp, sizeof(testpath)-1);
 	FREE(cp);
 
 	if (ans == 'N') {
@@ -837,7 +842,7 @@ PRIVATE BOOLEAN create_file ARGS1(
 {
     int code = FALSE;
     char tmpbuf[DIRED_MAXBUF];
-    char testpath[DIRED_MAXBUF];
+    char *testpath = NULL;
     char *args[5];
     char *bad_chars = ".~/";
 
@@ -853,13 +858,13 @@ PRIVATE BOOLEAN create_file ARGS1(
     if (strstr(tmpbuf, "//") != NULL) {
 	HTAlert(gettext("Illegal redirection \"//\" found! Request ignored."));
     } else if (strlen(tmpbuf) && strchr(bad_chars, tmpbuf[0]) == NULL) {
-	strcpy(testpath,current_location);
-	LYAddPathSep0(testpath);
+	StrAllocCopy(testpath, current_location);
+	LYAddPathSep(&testpath);
 
 	/*
 	 *  Append the target filename to the current location.
 	 */
-	strcat(testpath, tmpbuf);
+	StrAllocCat(testpath, tmpbuf);
 
 	/*
 	 *  Make sure the target does not already exist
@@ -873,6 +878,7 @@ PRIVATE BOOLEAN create_file ARGS1(
 	    code = (LYExecv(TOUCH_PATH, args, msg) <= 0) ? -1 : 1;
 	    FREE(msg);
 	}
+	FREE(testpath);
     }
     return code;
 }
@@ -885,7 +891,7 @@ PRIVATE BOOLEAN create_directory ARGS1(
 {
     int code = FALSE;
     char tmpbuf[DIRED_MAXBUF];
-    char testpath[DIRED_MAXBUF];
+    char *testpath = NULL;
     char *args[5];
     char *bad_chars = ".~/";
 
@@ -901,10 +907,10 @@ PRIVATE BOOLEAN create_directory ARGS1(
     if (strstr(tmpbuf, "//") != NULL) {
 	HTAlert(gettext("Illegal redirection \"//\" found! Request ignored."));
     } else if (strlen(tmpbuf) && strchr(bad_chars, tmpbuf[0]) == NULL) {
-	strcpy(testpath,current_location);
-	LYAddPathSep0(testpath);
+	StrAllocCopy(testpath, current_location);
+	LYAddPathSep(&testpath);
 
-	strcat(testpath, tmpbuf);
+	StrAllocCat(testpath, tmpbuf);
 
 	/*
 	 *  Make sure the target does not already exist.
@@ -918,6 +924,7 @@ PRIVATE BOOLEAN create_directory ARGS1(
 	    code = (LYExecv(MKDIR_PATH, args, msg) <= 0) ? -1 : 1;
 	    FREE(msg);
 	}
+	FREE(testpath);
     }
     return code;
 }
@@ -1420,7 +1427,7 @@ PRIVATE char * LYonedot ARGS1(
     static char line1[LY_MAXPATH];
 
     if (pathconf (line, _PC_NAME_MAX) <= 12) {
-	strcpy(line1, line);
+	LYstrncpy(line1, line, sizeof(line1)-1);
 	for (;;) {
 	    if ((dot = strrchr(line1, '.')) == 0
 	     || LYLastPathSep(dot) != 0) {
@@ -1439,6 +1446,25 @@ PRIVATE char * LYonedot ARGS1(
 #define LYonedot(path) path
 #endif /*  __DJGPP__ */
 
+PRIVATE char * match_op ARGS2(
+	CONST char *,	prefix,
+	char *,		data)
+{
+    int len = strlen(prefix);
+
+    if (!strncmp("LYNXDIRED://", data, 12)
+     && !strncmp(prefix, data + 12, (unsigned)len)) {
+	len += 12;
+#if defined(DOSPATH) || defined(__EMX__)
+	if (data[len] == '/') {	/* this is normal */
+	    len++;
+	}
+#endif
+	return data + len;
+    }
+    return 0;
+}
+
 /*
  *  Perform file management operations for LYNXDIRED URL's.
  *  Attempt to be consistent.  These are (pseudo) URLs - i.e., they should
@@ -1454,6 +1480,7 @@ PUBLIC int local_dired ARGS1(
 {
     char *line_url;    /* will point to doc's address, which is a URL */
     char *line = NULL; /* same as line_url, but HTUnEscaped, will be alloced */
+    char *arg = NULL; /* ...will point into line[] */
     char *tp = NULL;
     char *tmpbuf = NULL;
     char *buffer = NULL;
@@ -1469,47 +1496,37 @@ PUBLIC int local_dired ARGS1(
     HTUnEscape(line);	/* _file_ (not URL) syntax, for those functions
 			   that need it.  Don't forget to FREE it. */
 
-#ifdef __DJGPP__
-    if (!strncmp(line, "LYNXDIRED://", 12)) {
-	char *s;
-	int i;
-	s = strchr(&line[12], '/');
-	if (s != NULL)
-	    for(i = 0; s[i] != 0; i++)
-		s[i] = s[i+1];
-    }
-#endif /* __DJGPP__ */
-    if (!strncmp(line, "LYNXDIRED://NEW_FILE", 20)) {
-	if (create_file(&line[20]) > 0)
+    if ((arg = match_op("NEW_FILE", line)) != 0) {
+	if (create_file(arg) > 0)
 	    LYforce_no_cache = TRUE;
-    } else if (!strncmp(line, "LYNXDIRED://NEW_FOLDER", 22)) {
-	if (create_directory(&line[22]) > 0)
+    } else if ((arg = match_op("NEW_FOLDER", line)) != 0) {
+	if (create_directory(arg) > 0)
 	    LYforce_no_cache = TRUE;
 #ifdef OK_INSTALL
-    } else if (!strncmp(line, "LYNXDIRED://INSTALL_SRC", 23)) {
-	local_install(NULL, &line[23], &tp);
+    } else if ((arg = match_op("INSTALL_SRC", line)) != 0) {
+	local_install(NULL, arg, &tp);
 	if (tp) {
 	    FREE(doc->address);
 	    doc->address = tp;
 	}
 	FREE(line);
 	return 0;
-    } else if (!strncmp(line, "LYNXDIRED://INSTALL_DEST", 24)) {
-	local_install(&line[24], NULL, &tp);
+    } else if ((arg = match_op("INSTALL_DEST", line)) != 0) {
+	local_install(arg, NULL, &tp);
 	LYpop(doc);
 #endif /* OK_INSTALL */
-    } else if (!strncmp(line, "LYNXDIRED://MODIFY_NAME", 23)) {
-	if (modify_name(&line[23]) > 0)
-	LYforce_no_cache = TRUE;
-    } else if (!strncmp(line, "LYNXDIRED://MODIFY_LOCATION", 27)) {
-	if (modify_location(&line[27]) > 0)
+    } else if ((arg = match_op("MODIFY_NAME", line)) != 0) {
+	if (modify_name(arg) > 0)
+	    LYforce_no_cache = TRUE;
+    } else if ((arg = match_op("MODIFY_LOCATION", line)) != 0) {
+	if (modify_location(arg) > 0)
 	    LYforce_no_cache = TRUE;
-    } else if (!strncmp(line, "LYNXDIRED://MOVE_TAGGED", 23)) {
-	if (modify_tagged(&line_url[23]) > 0)
+    } else if ((arg = match_op("MOVE_TAGGED", line_url)) != 0) {
+	if (modify_tagged(arg) > 0)
 	    LYforce_no_cache = TRUE;
 #ifdef OK_PERMIT
-    } else if (!strncmp(line, "LYNXDIRED://PERMIT_SRC", 22)) {
-	permit_location(NULL, &line[22], &tp);
+    } else if ((arg = match_op("PERMIT_SRC", line)) != 0) {
+	permit_location(NULL, arg, &tp);
 	if (tp) {
 	    /*
 	     *	One of the checks may have failed.
@@ -1519,18 +1536,18 @@ PUBLIC int local_dired ARGS1(
 	}
 	FREE(line);
 	return 0;
-    } else if (!strncmp(line, "LYNXDIRED://PERMIT_LOCATION", 27)) {
-	permit_location(&line_url[27], NULL, &tp);
+    } else if ((arg = match_op("PERMIT_LOCATION", line_url)) != 0) {
+	permit_location(arg, NULL, &tp);
 #endif /* OK_PERMIT */
-    } else if (!strncmp(line, "LYNXDIRED://REMOVE_SINGLE", 25)) {
-	if (remove_single(&line[25]) > 0)
+    } else if ((arg = match_op("REMOVE_SINGLE", line)) != 0) {
+	if (remove_single(arg) > 0)
 	    LYforce_no_cache = TRUE;
-    } else if (!strncmp(line, "LYNXDIRED://REMOVE_TAGGED", 25)) {
+    } else if ((arg = match_op("REMOVE_TAGGED", line)) != 0) {
 	if (remove_tagged())
 	    LYforce_no_cache = TRUE;
-    } else if (!strncmp(line, "LYNXDIRED://CLEAR_TAGGED", 24)) {
+    } else if ((arg = match_op("CLEAR_TAGGED", line)) != 0) {
 	clear_tags();
-    } else if (!strncmp(line, "LYNXDIRED://UPLOAD", 18)) {
+    } else if ((arg = match_op("UPLOAD", line)) != 0) {
 	/*
 	 *  They're written by LYUpload_options() HTUnEscaped;
 	 *  don't want to change that for now... so pass through
@@ -1550,17 +1567,17 @@ PUBLIC int local_dired ARGS1(
 	 *  Construct the appropriate system command taking care to
 	 *  escape all path references to avoid spoofing the shell.
 	 */
-	if (!strncmp(line, "LYNXDIRED://DECOMPRESS", 22)) {
+	if ((arg = match_op("DECOMPRESS", line)) != 0) {
 #define FMT_UNCOMPRESS "%s %s"
 	    HTAddParam(&buffer, FMT_UNCOMPRESS, 1, UNCOMPRESS_PATH);
-	    HTAddParam(&buffer, FMT_UNCOMPRESS, 2, line+22);
+	    HTAddParam(&buffer, FMT_UNCOMPRESS, 2, arg);
 	    HTEndParam(&buffer, FMT_UNCOMPRESS, 2);
 
 #if defined(OK_UUDECODE) && !defined(ARCHIVE_ONLY)
-	} else if (!strncmp(line, "LYNXDIRED://UUDECODE", 20)) {
+	} else if ((arg = match_op("UUDECODE", line)) != 0) {
 #define FMT_UUDECODE "%s %s"
 	    HTAddParam(&buffer, FMT_UUDECODE, 1, UUDECODE_PATH);
-	    HTAddParam(&buffer, FMT_UUDECODE, 2, line+20);
+	    HTAddParam(&buffer, FMT_UUDECODE, 2, arg);
 	    HTEndParam(&buffer, FMT_UUDECODE, 2);
 	    HTAlert(gettext("Warning!  UUDecoded file will exist in the directory you started Lynx."));
 #endif /* OK_UUDECODE && !ARCHIVE_ONLY */
@@ -1568,112 +1585,112 @@ PUBLIC int local_dired ARGS1(
 #ifdef OK_TAR
 # ifndef ARCHIVE_ONLY
 #  ifdef OK_GZIP
-	} else if (!strncmp(line, "LYNXDIRED://UNTAR_GZ", 20)) {
+	} else if ((arg = match_op("UNTAR_GZ", line)) != 0) {
 #define FMT_UNTAR_GZ "cd %s; %s -qdc %s |  %s -xf -"
-	    dirname = DirectoryOf(line+20);
+	    dirname = DirectoryOf(arg);
 	    HTAddParam(&buffer, FMT_UNTAR_GZ, 1, dirname);
 	    HTAddParam(&buffer, FMT_UNTAR_GZ, 2, GZIP_PATH);
-	    HTAddParam(&buffer, FMT_UNTAR_GZ, 3, line+20);
+	    HTAddParam(&buffer, FMT_UNTAR_GZ, 3, arg);
 	    HTAddParam(&buffer, FMT_UNTAR_GZ, 4, TAR_PATH);
 	    HTEndParam(&buffer, FMT_UNTAR_GZ, 4);
 #  endif /* OK_GZIP */
 
-	} else if (!strncmp(line, "LYNXDIRED://UNTAR_Z", 19)) {
+	} else if ((arg = match_op("UNTAR_Z", line)) != 0) {
 #define FMT_UNTAR_Z "cd %s; %s %s |  %s -xf -"
-	    dirname = DirectoryOf(line+19);
+	    dirname = DirectoryOf(arg);
 	    HTAddParam(&buffer, FMT_UNTAR_Z, 1, dirname);
 	    HTAddParam(&buffer, FMT_UNTAR_Z, 2, ZCAT_PATH);
-	    HTAddParam(&buffer, FMT_UNTAR_Z, 3, line+19);
+	    HTAddParam(&buffer, FMT_UNTAR_Z, 3, arg);
 	    HTAddParam(&buffer, FMT_UNTAR_Z, 4, TAR_PATH);
 	    HTEndParam(&buffer, FMT_UNTAR_Z, 4);
 
-	} else if (!strncmp(line, "LYNXDIRED://UNTAR", 17)) {
+	} else if ((arg = match_op("UNTAR", line)) != 0) {
 #define FMT_UNTAR "cd %s; %s -xf %s"
-	    dirname = DirectoryOf(line+17);
+	    dirname = DirectoryOf(arg);
 	    HTAddParam(&buffer, FMT_UNTAR, 1, dirname);
 	    HTAddParam(&buffer, FMT_UNTAR, 2, TAR_PATH);
-	    HTAddParam(&buffer, FMT_UNTAR, 3, line+17);
+	    HTAddParam(&buffer, FMT_UNTAR, 3, arg);
 	    HTEndParam(&buffer, FMT_UNTAR, 3);
 # endif /* !ARCHIVE_ONLY */
 
 # ifdef OK_GZIP
-	} else if (!strncmp(line, "LYNXDIRED://TAR_GZ", 18)) {
+	} else if ((arg = match_op("TAR_GZ", line)) != 0) {
 #define FMT_TAR_GZ "cd %s; %s -cf - %s | %s -qc >%s%s"
-	    dirname = DirectoryOf(line+18);
+	    dirname = DirectoryOf(arg);
 	    HTAddParam(&buffer, FMT_TAR_GZ, 1, dirname);
 	    HTAddParam(&buffer, FMT_TAR_GZ, 2, TAR_PATH);
-	    HTAddParam(&buffer, FMT_TAR_GZ, 3, LYPathLeaf(line+18));
+	    HTAddParam(&buffer, FMT_TAR_GZ, 3, LYPathLeaf(arg));
 	    HTAddParam(&buffer, FMT_TAR_GZ, 4, GZIP_PATH);
-	    HTAddParam(&buffer, FMT_TAR_GZ, 5, LYonedot(LYPathLeaf(line+18)));
+	    HTAddParam(&buffer, FMT_TAR_GZ, 5, LYonedot(LYPathLeaf(arg)));
 	    HTAddParam(&buffer, FMT_TAR_GZ, 6, EXT_TAR_GZ);
 	    HTEndParam(&buffer, FMT_TAR_GZ, 6);
 # endif /* OK_GZIP */
 
-	} else if (!strncmp(line, "LYNXDIRED://TAR_Z", 17)) {
+	} else if ((arg = match_op("TAR_Z", line)) != 0) {
 #define FMT_TAR_Z "cd %s; %s -cf - %s | %s >%s%s"
-	    dirname = DirectoryOf(line+17);
+	    dirname = DirectoryOf(arg);
 	    HTAddParam(&buffer, FMT_TAR_Z, 1, dirname);
 	    HTAddParam(&buffer, FMT_TAR_Z, 2, TAR_PATH);
-	    HTAddParam(&buffer, FMT_TAR_Z, 3, LYPathLeaf(line+17));
+	    HTAddParam(&buffer, FMT_TAR_Z, 3, LYPathLeaf(arg));
 	    HTAddParam(&buffer, FMT_TAR_Z, 4, COMPRESS_PATH);
-	    HTAddParam(&buffer, FMT_TAR_Z, 5, LYonedot(LYPathLeaf(line+17)));
+	    HTAddParam(&buffer, FMT_TAR_Z, 5, LYonedot(LYPathLeaf(arg)));
 	    HTAddParam(&buffer, FMT_TAR_Z, 6, EXT_TAR_Z);
 	    HTEndParam(&buffer, FMT_TAR_Z, 6);
 
-	} else if (!strncmp(line, "LYNXDIRED://TAR", 15)) {
+	} else if ((arg = match_op("TAR", line)) != 0) {
 #define FMT_TAR "cd %s; %s -cf %s.tar %s"
-	    dirname = DirectoryOf(line+15);
+	    dirname = DirectoryOf(arg);
 	    HTAddParam(&buffer, FMT_TAR, 1, dirname);
 	    HTAddParam(&buffer, FMT_TAR, 2, TAR_PATH);
-	    HTAddParam(&buffer, FMT_TAR, 3, LYonedot(LYPathLeaf(line+15)));
-	    HTAddParam(&buffer, FMT_TAR, 4, LYPathLeaf(line+15));
+	    HTAddParam(&buffer, FMT_TAR, 3, LYonedot(LYPathLeaf(arg)));
+	    HTAddParam(&buffer, FMT_TAR, 4, LYPathLeaf(arg));
 	    HTEndParam(&buffer, FMT_TAR, 4);
 #endif /* OK_TAR */
 
 #ifdef OK_GZIP
-	} else if (!strncmp(line, "LYNXDIRED://GZIP", 16)) {
+	} else if ((arg = match_op("GZIP", line)) != 0) {
 #define FMT_GZIP "%s -q %s"
 	    HTAddParam(&buffer, FMT_GZIP, 1, GZIP_PATH);
-	    HTAddParam(&buffer, FMT_GZIP, 2, line+16);
+	    HTAddParam(&buffer, FMT_GZIP, 2, arg);
 	    HTEndParam(&buffer, FMT_GZIP, 2);
 #ifndef ARCHIVE_ONLY
-	} else if (!strncmp(line, "LYNXDIRED://UNGZIP", 18)) {
+	} else if ((arg = match_op("UNGZIP", line)) != 0) {
 #define FMT_UNGZIP "%s -d %s"
 	    HTAddParam(&buffer, FMT_UNGZIP, 1, GZIP_PATH);
-	    HTAddParam(&buffer, FMT_UNGZIP, 2, line+18);
+	    HTAddParam(&buffer, FMT_UNGZIP, 2, arg);
 	    HTEndParam(&buffer, FMT_UNGZIP, 2);
 #endif /* !ARCHIVE_ONLY */
 #endif /* OK_GZIP */
 
 #ifdef OK_ZIP
-	} else if (!strncmp(line, "LYNXDIRED://ZIP", 15)) {
+	} else if ((arg = match_op("ZIP", line)) != 0) {
 #define FMT_ZIP "cd %s; %s -rq %s.zip %s"
-	    dirname = DirectoryOf(line+15);
+	    dirname = DirectoryOf(arg);
 	    HTAddParam(&buffer, FMT_ZIP, 1, dirname);
 	    HTAddParam(&buffer, FMT_ZIP, 2, ZIP_PATH);
-	    HTAddParam(&buffer, FMT_ZIP, 3, LYonedot(LYPathLeaf(line+15)));
-	    HTAddParam(&buffer, FMT_ZIP, 4, LYPathLeaf(line+15));
+	    HTAddParam(&buffer, FMT_ZIP, 3, LYonedot(LYPathLeaf(arg)));
+	    HTAddParam(&buffer, FMT_ZIP, 4, LYPathLeaf(arg));
 	    HTEndParam(&buffer, FMT_ZIP, 4);
 #ifndef ARCHIVE_ONLY
-	} else if (!strncmp(line, "LYNXDIRED://UNZIP", 17)) {
+	} else if ((arg = match_op("UNZIP", line)) != 0) {
 #define FMT_UNZIP "cd %s; %s -q %s"
-	    dirname = DirectoryOf(line+17);
+	    dirname = DirectoryOf(arg);
 	    HTAddParam(&buffer, FMT_UNZIP, 1, dirname);
 	    HTAddParam(&buffer, FMT_UNZIP, 2, UNZIP_PATH);
-	    HTAddParam(&buffer, FMT_UNZIP, 3, line+17);
+	    HTAddParam(&buffer, FMT_UNZIP, 3, arg);
 	    HTEndParam(&buffer, FMT_UNZIP, 3);
 # endif /* !ARCHIVE_ONLY */
 #endif /* OK_ZIP */
 
-	} else if (!strncmp(line, "LYNXDIRED://COMPRESS", 20)) {
+	} else if ((arg = match_op("COMPRESS", line)) != 0) {
 #define FMT_COMPRESS "%s %s"
 	    HTAddParam(&buffer, FMT_COMPRESS, 1, COMPRESS_PATH);
-	    HTAddParam(&buffer, FMT_COMPRESS, 2, line+20);
+	    HTAddParam(&buffer, FMT_COMPRESS, 2, arg);
 	    HTEndParam(&buffer, FMT_COMPRESS, 2);
 	}
 
 	if (buffer != 0) {
-	    if (strlen(buffer) < 60) {
+	    if ((int) strlen(buffer) < LYcols - 15) {
 		HTSprintf0(&tmpbuf, gettext("Executing %s "), buffer);
 	    } else {
 		HTSprintf0(&tmpbuf,
@@ -2318,8 +2335,7 @@ PRIVATE char * render_item ARGS6(
 	s++;
     }
     if (overrun & url_syntax) {
-	strcpy(buf,gettext("Temporary URL or list would be too long."));
-	HTAlert(buf);
+	HTAlert(gettext("Temporary URL or list would be too long."));
 	bp = buf;	/* set to start, will return empty string as URL */
     }
     *bp = '\0';
@@ -2336,10 +2352,23 @@ PRIVATE int LYExecv ARGS3(
 	char **,	argv,
 	char *, 	msg)
 {
-#if defined(VMS) || defined(_WINDOWS)
+#if defined(VMS)
     CTRACE((tfp, "LYExecv:  Called inappropriately!\n"));
     return(0);
 #else
+#if defined(_WINDOWS)
+    if (!strcmp(path, TOUCH_PATH)) {
+	int fd = _creat(argv[1], _S_IREAD | _S_IWRITE);
+	if (fd >= 0) {
+	    close(fd);
+	    return(1);
+	}
+    } else if (!strcmp(path, RM_PATH)) {
+	return remove(argv[2]);
+    }
+    CTRACE((tfp, "LYExecv:  Called inappropriately! (path=%s)\n", path));
+    return(0);
+#else
     int rc;
     int n;
     char *tmpbuf = 0;
@@ -2420,5 +2449,6 @@ PRIVATE int LYExecv ARGS3(
     }
 
     return(rc);
+#endif /* _WINDOWS */
 #endif /* VMS */
 }
diff --git a/src/LYMail.c b/src/LYMail.c
index 00cf7eff..311884a0 100644
--- a/src/LYMail.c
+++ b/src/LYMail.c
@@ -1462,7 +1462,7 @@ PUBLIC void reply_by_mail ARGS4(
 	*user_input = '\0';
     else {
 	addstr(CTRL_U_TO_ERASE);
-	strcpy(user_input, personal_name);
+	LYstrncpy(user_input, personal_name, sizeof(user_input)-1);
     }
 #ifdef VMS
     if (isPMDF) {
@@ -1890,7 +1890,7 @@ PUBLIC void reply_by_mail ARGS4(
 	    if (!first) {
 		StrAllocCat(command, ",");
 	    }
-	    HTSprintf(command, mail_adrs, address_ptr1);
+	    HTSprintf(&command, mail_adrs, address_ptr1);
 	    first = FALSE;
 	}
 	address_ptr1 = address_ptr2;
diff --git a/src/LYMain.c b/src/LYMain.c
index dcaa028f..fdc415fd 100644
--- a/src/LYMain.c
+++ b/src/LYMain.c
@@ -30,6 +30,10 @@
 #include <LYCookie.h>
 #include <LYPrettySrc.h>
 
+#ifdef VMS
+#include <HTFTP.h>
+#endif /* !DECNET */
+
 #ifdef __DJGPP__
 #include <dos.h>
 #include <dpmi.h>
@@ -351,6 +355,7 @@ PUBLIC BOOLEAN traversal = FALSE;    /* Do traversals? */
 PUBLIC BOOLEAN check_realm = FALSE;  /* Restrict to the starting realm? */
 	       /* Links beyond a displayed page with no links? */
 PUBLIC BOOLEAN more_links = FALSE;
+PUBLIC BOOLEAN lynx_temp_subspace = FALSE; /* true if we made temp-directory */
 PUBLIC int     ccount = 0; /* Starting number for lnk#.dat files in crawls */
 PUBLIC BOOLEAN LYCancelledFetch = FALSE; /* TRUE if cancelled binary fetch */
 	       /* Include mime headers with source dump */
@@ -786,6 +791,14 @@ PUBLIC int main ARGS2(
     WSADATA WSAData;
 #endif /* _WINDOWS */
 
+    /*
+     * Just in case someone has the idea to install lynx set-uid, let's try
+     * to discourage it.
+     */
+#if defined(GETUID) && defined(SETUID)
+    setuid(getuid());
+#endif
+
 #ifdef    NOT_ASCII
     FixCharacters();
 #endif /* NOT_ASCII */
@@ -1021,6 +1034,32 @@ PUBLIC int main ARGS2(
 	    FREE(temp);
 	}
     }
+    /*
+     * Verify if the given space looks secure enough.  Otherwise, make a
+     * secure subdirectory of that.  
+     */
+#if defined(UNIX) && defined(HAVE_MKTEMP)
+    {
+	struct stat sb;
+
+	if (lstat(lynx_temp_space, &sb) == 0
+	 && S_ISDIR(sb.st_mode)) {
+	    if (sb.st_uid != getuid()
+	     || (sb.st_mode & (S_IWOTH | S_IWGRP)) != 0)
+		lynx_temp_subspace = TRUE;
+	} else {
+	     lynx_temp_subspace = TRUE;
+	}
+	if (lynx_temp_subspace) {
+	    StrAllocCat(lynx_temp_space, "/XXXXXX");
+	    if (mktemp(lynx_temp_space) == 0
+	     || mkdir(lynx_temp_space, 0700) < 0) {
+		printf("%s: %s\n", lynx_temp_space, LYStrerror(errno));
+		exit(-1);
+	    }
+	}
+    }
+#endif
 #ifdef VMS
     LYLowerCase(lynx_temp_space);
     if (strchr(lynx_temp_space, '/') != NULL) {
@@ -1505,7 +1544,7 @@ PUBLIC int main ARGS2(
     /*
      *	Set the compilation default signature file. - FM
      */
-    strcpy(filename, LYNX_SIG_FILE);
+    LYstrncpy(filename, LYNX_SIG_FILE, sizeof(filename)-1);
     if (LYPathOffHomeOK(filename, sizeof(filename))) {
 	StrAllocCopy(LynxSigFile, filename);
 	LYAddPathToHome(filename, sizeof(filename), LynxSigFile);
@@ -3615,7 +3654,7 @@ treated '>' as a co-terminator for double-quotes and tags"
       "underscore",	TOGGLE_ARG,		&use_underscore,
       "toggles use of _underline_ format in dumps"
    ),
-#if defined(NCURSES_MOUSE_VERSION) || defined(USE_SLANG_MOUSE)
+#if defined(NCURSES_MOUSE_VERSION) || defined(PDCURSES) || defined(USE_SLANG_MOUSE)
    PARSE_SET(
       "use_mouse",	SET_ARG,		&LYUseMouse,
       "turn on mouse support"
diff --git a/src/LYMainLoop.c b/src/LYMainLoop.c
index dd02bd80..a01be1db 100644
--- a/src/LYMainLoop.c
+++ b/src/LYMainLoop.c
@@ -41,11 +41,6 @@
 
 #ifdef KANJI_CODE_OVERRIDE
 #include <HTCJK.h>
-extern HTCJKlang HTCJK;
-#endif
-
-#if defined(CJK_EX)	/* 1999/05/25 (Tue) 11:10:45 */
-extern char *string_short(char *str, int cut_pos);	/* LYExtern.c */
 #endif
 
 #ifdef KANJI_CODE_OVERRIDE
@@ -97,7 +92,6 @@ PUBLIC char *str_kcode(HTkcode code)
 }
 #endif
 
-#ifdef CJK_EX
 #ifdef WIN_EX
 
 PRIVATE char *str_sjis(char *to, char *from)
@@ -123,8 +117,6 @@ PRIVATE void set_ws_title(char * str)
 
 #endif /* WIN_EX */
 
-#endif /* CJK_EX */
-
 
 #ifdef SH_EX  /* 1998/10/30 (Fri) 10:06:47 */
 
@@ -149,7 +141,7 @@ PRIVATE int str_n_cmp(const char *p, const char *q, int n)
 
 #endif	/* SH_EX */
 
-#ifdef USE_EXTERNALS
+#if defined(USE_EXTERNALS) || defined(WIN_EX)
 #include <LYExtern.h>
 #endif
 
@@ -667,7 +659,10 @@ PRIVATE BOOL do_check_recall ARGS7(
 	    last_1 = user_input_buffer[len - 2];
 	    last = user_input_buffer[len - 1];
 
-	    if (last_2 == '/' && isalpha(last_1) && last == ':')
+	    if (len < MAX_LINE - 1
+	     && last_2 == '/'
+	     && isalpha(last_1)
+	     && last == ':')
 		LYAddHtmlSep0(user_input_buffer);
 
 	} else if (len == 2 && user_input_buffer[1] == ':') {
@@ -675,7 +670,7 @@ PRIVATE BOOL do_check_recall ARGS7(
 		LYAddHtmlSep0(user_input_buffer);
 	    } else {
 		HTUserMsg2(WWW_ILLEGAL_URL_MESSAGE, user_input_buffer);
-		strcpy(user_input_buffer, *old_user_input);
+		LYstrncpy(user_input_buffer, *old_user_input, MAX_LINE - 1);
 		FREE(*old_user_input);
 		ret = FALSE;
 		break;
@@ -690,7 +685,7 @@ PRIVATE BOOL do_check_recall ARGS7(
 	}
 	if (*user_input_buffer == '\0' &&
 	    !(recall && (ch == UPARROW || ch == DNARROW))) {
-	    strcpy(user_input_buffer, *old_user_input);
+	    LYstrncpy(user_input_buffer, *old_user_input, MAX_LINE - 1);
 	    FREE(*old_user_input);
 	    HTInfoMsg(CANCELLED);
 	    ret = FALSE;
@@ -716,7 +711,7 @@ PRIVATE BOOL do_check_recall ARGS7(
 		*URLNum = 0;
 	    if ((cp = (char *)HTList_objectAt(Goto_URLs,
 					      *URLNum)) != NULL) {
-		strcpy(user_input_buffer, cp);
+		LYstrncpy(user_input_buffer, cp, MAX_LINE - 1);
 		if (goto_buffer
 		 && **old_user_input
 		 && !strcmp(*old_user_input, user_input_buffer)) {
@@ -734,7 +729,7 @@ PRIVATE BOOL do_check_recall ARGS7(
 		     *  User cancelled the Goto via ^G.
 		     *  Restore user_input_buffer and break. - FM
 		     */
-		    strcpy(user_input_buffer, *old_user_input);
+		    LYstrncpy(user_input_buffer, *old_user_input, MAX_LINE - 1);
 		    FREE(*old_user_input);
 		    HTInfoMsg(CANCELLED);
 		    ret = FALSE;
@@ -761,7 +756,7 @@ PRIVATE BOOL do_check_recall ARGS7(
 		 */
 		*URLNum = URLTotal - 1;
 	    if ((cp=(char *)HTList_objectAt(Goto_URLs, *URLNum)) != NULL) {
-		strcpy(user_input_buffer, cp);
+		LYstrncpy(user_input_buffer, cp, MAX_LINE - 1);
 		if (goto_buffer && **old_user_input &&
 		    !strcmp(*old_user_input, user_input_buffer)) {
 		    _statusline(EDIT_CURRENT_GOTO);
@@ -778,7 +773,7 @@ PRIVATE BOOL do_check_recall ARGS7(
 		     *  User cancelled the Goto via ^G.
 		     *  Restore user_input_buffer and break. - FM
 		     */
-		    strcpy(user_input_buffer, *old_user_input);
+		    LYstrncpy(user_input_buffer, *old_user_input, MAX_LINE - 1);
 		    FREE(*old_user_input);
 		    HTInfoMsg(CANCELLED);
 		    ret = FALSE;
@@ -2375,7 +2370,7 @@ PRIVATE int handle_LYK_ECGOTO ARGS5(
      *	or not modifying the URL. - FM
      */
     HTInfoMsg(CANCELLED);
-    strcpy(user_input_buffer, *old_user_input);
+    LYstrncpy(user_input_buffer, *old_user_input, MAX_LINE - 1);
     FREE(*old_user_input);
     return 0;
 }
@@ -2639,7 +2634,7 @@ PRIVATE int handle_LYK_ELGOTO ARGS5(
      *	or not modifying the URL. - FM
      */
     HTInfoMsg(CANCELLED);
-    strcpy(user_input_buffer, *old_user_input);
+    LYstrncpy(user_input_buffer, *old_user_input, MAX_LINE - 1);
     FREE(*old_user_input);
     return 0;
 }
@@ -2888,7 +2883,7 @@ PRIVATE BOOLEAN handle_LYK_GOTO ARGS9(
 	 *  User cancelled the Goto via ^G.
 	 *  Restore user_input_buffer and break. - FM
 	 */
-	strcpy(user_input_buffer, *old_user_input);
+	LYstrncpy(user_input_buffer, *old_user_input, MAX_LINE - 1);
 	FREE(*old_user_input);
 	HTInfoMsg(CANCELLED);
 	return FALSE;
@@ -3448,7 +3443,7 @@ PRIVATE BOOLEAN handle_LYK_JUMP ARGS10(
 		    return FALSE;
 		}
 		ret = HTParse((ret+3), startfile, PARSE_ALL);
-		strcpy(user_input_buffer, ret);
+		LYstrncpy(user_input_buffer, ret, MAX_LINE - 1);
 		FREE(ret);
 		return TRUE;
 	    }
@@ -4815,7 +4810,7 @@ PUBLIC void handle_LYK_WHEREIS ARGS2(
 	 *  is entered by the user.
 	 */
 	*prev_target = '\0';
-	found = textsearch(&curdoc, prev_target, FALSE);
+	found = textsearch(&curdoc, prev_target, sizeof(prev_target)-1, FALSE);
     } else {
 	/*
 	 *  When the third argument is TRUE, the previous
@@ -4827,7 +4822,7 @@ PUBLIC void handle_LYK_WHEREIS ARGS2(
 	 *  after prev_target was reset on fetch of that
 	 *  document.
 	 */
-	found = textsearch(&curdoc, prev_target, TRUE);
+	found = textsearch(&curdoc, prev_target, sizeof(prev_target)-1, TRUE);
     }
 
     /*
@@ -4998,7 +4993,7 @@ PRIVATE void handle_LYK_digit ARGS6(
 		    sprintf(user_input_buffer,
 			    LINK_ALREADY_CURRENT, number);
 		    HTUserMsg(user_input_buffer);
-		    strcpy(user_input_buffer, temp);
+		    LYstrncpy(user_input_buffer, temp, MAX_LINE - 1);
 		    FREE(temp);
 		} else {
 		    /*
@@ -5032,7 +5027,7 @@ PRIVATE void handle_LYK_digit ARGS6(
 		sprintf(user_input_buffer,
 			ALREADY_AT_PAGE, number);
 		HTUserMsg(user_input_buffer);
-		strcpy(user_input_buffer, temp);
+		LYstrncpy(user_input_buffer, temp, MAX_LINE - 1);
 		FREE(temp);
 	    }
 	}
@@ -6307,7 +6302,7 @@ try_again:
 		}
 	    }
 	} else {
-	    if (strlen(curdoc.address) < 1000) {
+	    if (strlen(curdoc.address) < sizeof(temp_buff)-1) {
 		if (user_mode == ADVANCED_MODE) {
 		    str_sjis(temp_buff, curdoc.title);
 		} else {
@@ -7340,16 +7335,14 @@ PRIVATE void HTGotoURLs_free NOARGS
 PUBLIC void HTAddGotoURL ARGS1(
 	char *,		url)
 {
-    char *new;
+    char *new = NULL;
     char *old;
     HTList *cur;
 
     if (!(url && *url))
 	return;
 
-    if ((new = (char *)calloc(1, (strlen(url) + 1))) == NULL)
-	outofmem(__FILE__, "HTAddGotoURL");
-    strcpy(new, url);
+    StrAllocCopy(new, url);
 
     if (!Goto_URLs) {
 	Goto_URLs = HTList_new();
diff --git a/src/LYMap.c b/src/LYMap.c
index 04cc663e..9d4a7d13 100644
--- a/src/LYMap.c
+++ b/src/LYMap.c
@@ -194,7 +194,7 @@ PUBLIC BOOL LYAddImageMap ARGS3(
     }
 
     new = (old != NULL) ?
-		    old : (LYImageMap *)calloc(1, sizeof(LYImageMap));
+		    old : typecalloc(LYImageMap);
     if (new == NULL) {
 	outofmem(__FILE__, "LYAddImageMap");
 	return FALSE;
@@ -276,7 +276,7 @@ PUBLIC BOOL LYAddMapElement ARGS5(
 	}
     }
 
-    new = (LYMapElement *)calloc(1, sizeof(LYMapElement));
+    new = typecalloc(LYMapElement);
     if (new == NULL) {
 	perror("Out of memory in LYAddMapElement");
 	return FALSE;
@@ -598,7 +598,7 @@ PRIVATE int LYLoadIMGmap ARGS4 (
 	    PUTS(" TYPE=\"internal link\"");
 #endif
 	PUTS("\n>");
-	StrAllocCopy(MapTitle, new->title);
+	LYformTitle(&MapTitle, new->title);
 	LYEntify(&MapTitle, TRUE);
 	PUTS(MapTitle);
 	PUTS("</a>\n");
diff --git a/src/LYNews.c b/src/LYNews.c
index a58a5146..1ec004f7 100644
--- a/src/LYNews.c
+++ b/src/LYNews.c
@@ -25,10 +25,6 @@
 BOOLEAN term_message = FALSE;
 PRIVATE void terminate_message  PARAMS((int sig));
 
-#ifdef CJK_EX	/* 1998/05/15 (Fri) 09:10:38 */
-extern HTCJKlang HTCJK;
-#endif
-
 PRIVATE BOOLEAN message_has_content ARGS2(
     CONST char *,	filename,
     BOOLEAN *,		nonspaces)
@@ -108,6 +104,7 @@ PUBLIC char *LYNewsPost ARGS2(
     char *cp = NULL;
     CONST char *kp = NULL;
     int c = 0;  /* user input */
+    int len;
     FILE *fd = NULL;
     char my_tempfile[LY_MAXPATH];
     FILE *fc = NULL;
@@ -213,9 +210,8 @@ PUBLIC char *LYNewsPost ARGS2(
      *  offering personal_mail_address as default.
      */
     addstr(gettext("\n\n Please provide your mail address for the From: header\n"));
-    strcpy(user_input, "From: ");
-    if (personal_mail_address)
-	strcat(user_input, personal_mail_address);
+    sprintf(user_input, "From: %.*s", (int)sizeof(user_input) - 8,
+	    (personal_mail_address != NULL) ? personal_mail_address : "");
     if (LYgetstr(user_input, VISIBLE,
 		 sizeof(user_input), NORECALL) < 0 ||
 	term_message) {
@@ -259,7 +255,8 @@ PUBLIC char *LYNewsPost ARGS2(
 	if (strncasecomp(kp, "Re:", 3)) {
 	    strcat(user_input, "Re: ");
 	}
-	strcat(user_input, kp);
+	len = strlen(user_input);
+	LYstrncpy(user_input + len, kp, sizeof(user_input) - len - 1);
     }
     cp = NULL;
     if (LYgetstr(user_input, VISIBLE,
@@ -299,11 +296,11 @@ PUBLIC char *LYNewsPost ARGS2(
 #else
 #ifdef _WINDOWS	/* 1998/05/14 (Thu) 17:47:01 */
     else {
-	char *p, fname[256];
+	char *p, fname[LY_MAXPATH];
 
 	strcpy(fname, LynxSigFile);
 	p = strrchr(fname, '/');
-	if (p) {
+	if (p != 0 && (p - fname) < sizeof(fname) - 15) {
 	    strcpy(p + 1, "LYNX_ETC.TXT");
 	    if ((fp = fopen(fname, TXT_R)) != NULL) {
 		if (fgets(user_input, sizeof(user_input), fp) != NULL) {
diff --git a/src/LYOptions.c b/src/LYOptions.c
index 9126fa56..803c37d0 100644
--- a/src/LYOptions.c
+++ b/src/LYOptions.c
@@ -24,13 +24,11 @@
 
 #include <LYLeaks.h>
 
-extern HTCJKlang HTCJK;
-
 BOOLEAN term_options;
 
 PRIVATE void terminate_options	PARAMS((int sig));
 
-#if !defined(NO_OPTION_MENU) || defined(NCURSES_MOUSE_VERSION)
+#if !defined(NO_OPTION_MENU) || (defined(NCURSES_MOUSE_VERSION) || defined(PDCURSES))
 #define COL_OPTION_VALUES 36  /* display column where option values start */
 #endif
 
@@ -552,7 +550,7 @@ draw_options:
 		    _statusline(EDITOR_LOCKED);
 		} else {
 		    if (editor && *editor)
-			strcpy(display_option, editor);
+			LYstrncpy(display_option, editor, sizeof(display_option) - 1);
 		    else {  /* clear the NONE */
 			move(L_EDITOR, COL_OPTION_VALUES);
 			addstr("    ");
@@ -589,7 +587,7 @@ draw_options:
 	    case 'd':	/* Change the display. */
 	    case 'D':
 		if (x_display && *x_display) {
-		    strcpy(display_option, x_display);
+		    LYstrncpy(display_option, x_display, sizeof(display_option) - 1);
 		} else {  /* clear the NONE */
 		    move(L_DISPLAY, COL_OPTION_VALUES);
 		    addstr("    ");
@@ -727,7 +725,7 @@ draw_options:
 			goto draw_options;
 		    }
 		    if (bookmark_page && *bookmark_page) {
-			strcpy(display_option, bookmark_page);
+			LYstrncpy(display_option, bookmark_page, sizeof(display_option) - 1);
 		    } else {  /* clear the NONE */
 			move(L_HOME, C_DEFAULT);
 			clrtoeol();
@@ -813,7 +811,7 @@ draw_options:
 	    case 'p': /* Change personal mail address for From headers. */
 	    case 'P':
 		if (personal_mail_address && *personal_mail_address) {
-		    strcpy(display_option, personal_mail_address);
+		    LYstrncpy(display_option, personal_mail_address, sizeof(display_option) - 1);
 		} else {  /* clear the NONE */
 		    move(L_MAIL_ADDRESS, COL_OPTION_VALUES);
 		    addstr("    ");
@@ -1034,7 +1032,7 @@ draw_options:
 	    case 'g':	/* Change language preference. */
 	    case 'G':
 		if (language && *language) {
-		    strcpy(display_option, language);
+		    LYstrncpy(display_option, language, sizeof(display_option) - 1);
 		} else {  /* clear the NONE */
 		    move(L_LANGUAGE, COL_OPTION_VALUES);
 		    addstr("    ");
@@ -1070,7 +1068,7 @@ draw_options:
 	    case 'h':	/* Change charset preference. */
 	    case 'H':
 		if (pref_charset && *pref_charset) {
-		    strcpy(display_option, pref_charset);
+		    LYstrncpy(display_option, pref_charset, sizeof(display_option) - 1);
 		} else {  /* clear the NONE */
 		    move(L_PREF_CHARSET, COL_OPTION_VALUES);
 		    addstr("    ");
@@ -1525,7 +1523,7 @@ draw_options:
 	    case 'A':
 		if (!no_useragent) {
 		    if (LYUserAgent && *LYUserAgent) {
-			strcpy(display_option, LYUserAgent);
+			LYstrncpy(display_option, LYUserAgent, sizeof(display_option) - 1);
 		    } else {  /* clear the NONE */
 			move(L_HOME, COL_OPTION_VALUES);
 			addstr("    ");
@@ -2063,9 +2061,10 @@ draw_bookmark_list:
 			     9);
 		    else
 			move((3 + a), 9);
-		    strcpy(MBM_tmp_line,
+		    LYstrncpy(MBM_tmp_line,
 			   (!MBM_A_subdescript[a] ?
-					       "" : MBM_A_subdescript[a]));
+					       "" : MBM_A_subdescript[a]),
+			      sizeof(MBM_tmp_line) - 1);
 		    ch = LYgetstr(MBM_tmp_line, VISIBLE,
 				  sizeof(MBM_tmp_line), NORECALL);
 		    stop_bold();
@@ -2097,8 +2096,9 @@ draw_bookmark_list:
 		addstr("| ");
 
 		start_bold();
-		strcpy(MBM_tmp_line,
-		       (!MBM_A_subbookmark[a] ? "" : MBM_A_subbookmark[a]));
+		LYstrncpy(MBM_tmp_line,
+			  (!MBM_A_subbookmark[a] ? "" : MBM_A_subbookmark[a]),
+			  sizeof(MBM_tmp_line) - 1);
 		ch = LYgetstr(MBM_tmp_line, VISIBLE,
 			      sizeof(MBM_tmp_line), NORECALL);
 		stop_bold();
@@ -2138,7 +2138,7 @@ draw_bookmark_list:
     signal(SIGINT, cleanup_sig);
 }
 
-#if !defined(NO_OPTION_MENU) || defined(NCURSES_MOUSE_VERSION)
+#if !defined(NO_OPTION_MENU) || (defined(NCURSES_MOUSE_VERSION) || defined(PDCURSES))
 /*
 **  This function prompts for a choice or page number.
 **  If a 'g' or 'p' suffix is included, that will be
@@ -2384,7 +2384,7 @@ PUBLIC int popup_choice ARGS7(
 	StrAllocCopy(popup_status_msg, CHOICE_LIST_UNM_MSG);
     } else if (!for_mouse) {
 	StrAllocCopy(popup_status_msg, CHOICE_LIST_MESSAGE);
-#ifdef NCURSES_MOUSE_VERSION
+#if defined(NCURSES_MOUSE_VERSION) || defined(PDCURSES)
     } else {
 	StrAllocCopy(popup_status_msg, gettext(
 		"Left mouse button or return to select, arrow keys to scroll."));
@@ -2893,7 +2893,7 @@ redraw:
 		     */
 		    if ((cp = (char *)HTList_objectAt(search_queries,
 						      0)) != NULL) {
-			strcpy(prev_target_buffer, cp);
+			LYstrncpy(prev_target_buffer, cp, sizeof(prev_target_buffer) - 1);
 			QueryNum = 0;
 			FirstRecall = FALSE;
 		    }
@@ -2957,7 +2957,7 @@ check_recall:
 			QueryNum = 0;
 		    if ((cp = (char *)HTList_objectAt(search_queries,
 						      QueryNum)) != NULL) {
-			strcpy(prev_target, cp);
+			LYstrncpy(prev_target, cp, sizeof(prev_target) - 1);
 			if (*prev_target_buffer &&
 			    !strcmp(prev_target_buffer, prev_target)) {
 			    _statusline(EDIT_CURRENT_QUERY);
@@ -3011,7 +3011,7 @@ check_recall:
 			QueryNum = (QueryTotal - 1);
 		    if ((cp = (char *)HTList_objectAt(search_queries,
 						      QueryNum)) != NULL) {
-			strcpy(prev_target, cp);
+			LYstrncpy(prev_target, cp, sizeof(prev_target) - 1);
 			if (*prev_target_buffer &&
 			    !strcmp(prev_target_buffer, prev_target)) {
 			    _statusline(EDIT_CURRENT_QUERY);
diff --git a/src/LYPrettySrc.c b/src/LYPrettySrc.c
index a4920671..73146629 100644
--- a/src/LYPrettySrc.c
+++ b/src/LYPrettySrc.c
@@ -5,6 +5,7 @@
 #include <HTUtils.h>
 #include <LYHash.h>
 #include <LYPrettySrc.h>
+#include <LYStrings.h>
 
  /* This file creates too many "leak detected" entries in Lynx.leaks. */
 #define NO_MEMORY_TRACKING
@@ -331,8 +332,12 @@ PUBLIC void HTMLSRC_init_caches ARGS1(
 
     for (i = 0; i < HTL_num_lexemes; ++i) {
 	/*we assume that HT_tagspecs was NULLs at when program started*/
-	strcpy(buf, HTL_tagspecs[i] ? HTL_tagspecs[i] : HTL_tagspecs_defaults[i]);
-	StrAllocCopy(HTL_tagspecs[i],buf);
+	LYstrncpy(buf,
+		  HTL_tagspecs[i]
+		  ? HTL_tagspecs[i]
+		  : HTL_tagspecs_defaults[i],
+		  sizeof(buf) - 1);
+	StrAllocCopy(HTL_tagspecs[i], buf);
 
 	if ((p = strchr(buf, ':')) != 0)
 	    *p = '\0';
diff --git a/src/LYPrint.c b/src/LYPrint.c
index 4ae19b31..66f3ebd1 100644
--- a/src/LYPrint.c
+++ b/src/LYPrint.c
@@ -402,9 +402,17 @@ check_recall:
 
 	fprintf(outfile_fp,
 		"<!-- X-URL: %s -->\n", newdoc->address);
-	if (HText_getDate() != NULL)
-	     fprintf(outfile_fp,
+	if (HText_getDate() != NULL) {
+	    fprintf(outfile_fp,
 		"<!-- Date: %s -->\n", HText_getDate());
+	    if (HText_getLastModified() != NULL
+			&& !strcmp(HText_getLastModified(), HText_getDate())
+			&& !strcmp(HText_getLastModified(), ctime((time_t)0))) {
+		fprintf(outfile_fp,
+		    "<!-- Last-Modified: %s -->\n", HText_getLastModified());
+	    }
+	}
+
 	fprintf(outfile_fp,
 		"<BASE HREF=\"%s\">\n", content_base);
     }
@@ -474,9 +482,8 @@ PRIVATE void send_file_to_mail ARGS3(
     BOOLEAN isPMDF = !strncasecomp(system_mail, "PMDF SEND", 9);
     FILE *hfd;
     char hdrfile[LY_MAXPATH];
-    char my_temp[LY_MAXPATH];
 #endif
-#if !CAN_PIPE_TO_MAILER 
+#if !CAN_PIPE_TO_MAILER
     char my_temp[LY_MAXPATH];
 #endif
 
@@ -664,7 +671,7 @@ PRIVATE void send_file_to_mail ARGS3(
     LYRemoveTemp(my_temp);
 #else /* !VMS (Unix or DOS) */
 
-#if CAN_PIPE_TO_MAILER 
+#if CAN_PIPE_TO_MAILER
     HTSprintf0(&buffer, "%s %s", system_mail, system_mail_flags);
     outfile_fp = popen(buffer, "w");
 #else
diff --git a/src/LYReadCFG.c b/src/LYReadCFG.c
index c1360af2..80ac04e6 100644
--- a/src/LYReadCFG.c
+++ b/src/LYReadCFG.c
@@ -306,13 +306,21 @@ PRIVATE void add_printer_to_list ARGS2(
 
 #if defined(USE_COLOR_STYLE) || defined(USE_COLOR_TABLE)
 
-#ifdef USE_SLANG
+#ifndef COLOR_WHITE
 #define COLOR_WHITE 7
+#endif
+
+#ifndef COLOR_BLACK
 #define COLOR_BLACK 0
 #endif
 
+#if USE_DEFAULT_COLORS
+int default_fg = DEFAULT_COLOR;
+int default_bg = DEFAULT_COLOR;
+#else
 int default_fg = COLOR_WHITE;
 int default_bg = COLOR_BLACK;
+#endif
 
 static CONST char *Color_Strings[16] =
 {
@@ -334,7 +342,7 @@ static CONST char *Color_Strings[16] =
     "white"
 };
 
-#if defined(DOSPATH) || defined(WIN_EX)
+#if defined(PDCURSES)
 /*
  * PDCurses (and possibly some other implementations) use a non-ANSI set of
  * codes for colors.
@@ -362,26 +370,8 @@ PUBLIC int check_color ARGS2(
 
     CTRACE((tfp, "check_color(%s,%d)\n", color, the_default));
     if (!strcasecomp(color, "default")) {
-#if HAVE_USE_DEFAULT_COLORS && USE_DEFAULT_COLORS
-#if HAVE_ASSUME_DEFAULT_COLORS	/* ncurses 5.1 */
-	/*
-	 * This may be invoked before ncurses is initialized, depending on
-	 * whether color-style is used or not.
-	 *
-	 * If we have assume_default_colors(), we can leave the global fg/bg
-	 * colors with the standard white/black until we find a color specified
-	 * as "default".
-	 */
-	static int found = 0;
-	if (!found)
-	    found = lynx_default_colors();
-	if (found >= 0)
-	    the_default = DEFAULT_COLOR;
-#else
+#if USE_DEFAULT_COLORS
 	the_default = DEFAULT_COLOR;
-#endif	/* HAVE_ASSUME_DEFAULT_COLORS */
-	default_fg = DEFAULT_COLOR;
-	default_bg = DEFAULT_COLOR;
 #endif	/* USE_DEFAULT_COLORS */
 	CTRACE((tfp, "=> %d\n", the_default));
 	return the_default;
@@ -587,6 +577,44 @@ static int outgoing_mail_charset_fun ARGS1(
     return 0;
 }
 
+#ifdef EXP_ASSUMED_COLOR
+/*
+ *  Process string buffer fields for ASSUMED_COLOR setting.
+ */
+PRIVATE void assumed_color_fun ARGS1(
+	char *, buffer)
+{
+    char *fg = buffer, *bg;
+    char *temp = 0;
+
+    StrAllocCopy(temp, buffer);	/* save a copy, for error messages */
+
+    /*
+     *	We are expecting a line of the form:
+     *	  FOREGROUND:BACKGROUND
+     */
+    if (NULL == (bg = find_colon(fg)))
+	exit_with_color_syntax(temp);
+    *bg++ = '\0';
+
+    default_fg = check_color(fg, default_fg);
+    default_bg = check_color(bg, default_bg);
+
+    if (default_fg == ERR_COLOR
+     || default_bg == ERR_COLOR)
+	exit_with_color_syntax(temp);
+#if USE_SLANG
+    /*
+     * Sorry - the order of initialization of slang precludes setting the
+     * default colors from the lynx.cfg file, since slang is already
+     * initialized before the file is read, and there is no interface defined
+     * for setting it from the application (that's one of the problems with
+     * using environment variables rather than a programmable interface) -TD
+     */
+#endif
+    FREE(temp);
+}
+#endif /* EXP_ASSUMED_COLOR */
 
 #ifdef USE_COLOR_TABLE
 static int color_fun ARGS1(
@@ -1310,6 +1338,9 @@ static Config_Type Config_Table [] =
      PARSE_FUN("assume_charset", CONF_FUN, assume_charset_fun),
      PARSE_FUN("assume_local_charset", CONF_FUN, assume_local_charset_fun),
      PARSE_FUN("assume_unrec_charset", CONF_FUN, assume_unrec_charset_fun),
+#ifdef EXP_ASSUMED_COLOR
+     PARSE_FUN("assumed_color", CONF_FUN, assumed_color_fun),
+#endif
 #ifdef EXP_CHARSET_CHOICE
      PARSE_FUN("assumed_doc_charset_choice",CONF_FUN,parse_assumed_doc_charset_choice),
 #endif
@@ -1530,7 +1561,7 @@ static Config_Type Config_Table [] =
 #ifdef VMS
      PARSE_SET("use_fixed_records", CONF_BOOL, &UseFixedRecords),
 #endif
-#if defined(NCURSES_MOUSE_VERSION) || defined(USE_SLANG_MOUSE)
+#if defined(NCURSES_MOUSE_VERSION) || defined(PDCURSES) || defined(USE_SLANG_MOUSE)
      PARSE_SET("use_mouse", CONF_BOOL, &LYUseMouse),
 #endif
      PARSE_SET("use_select_popups", CONF_BOOL, &LYSelectPopups),
@@ -1645,8 +1676,8 @@ PRIVATE void do_read_cfg ARGS5(
 	FILE *,	fp0,
 	optidx_set_t*, allowed)
 {
+    static char *mypath = NULL;
     FILE *fp;
-    char mypath[LY_MAXPATH];
     char *buffer = 0;
 
     CTRACE((tfp, "Loading cfg file '%s'.\n", cfg_filename));
@@ -1671,8 +1702,7 @@ PRIVATE void do_read_cfg ARGS5(
 	return;
     }
     if (!strncmp(cfg_filename, "~/", 2)) {
-	strcpy(mypath, Home_Dir());
-	strcat(mypath, cfg_filename+1);
+	HTSprintf0(&mypath, "%s%s", Home_Dir(), cfg_filename+1);
 	cfg_filename = mypath;
     }
     if ((fp = fopen(cfg_filename, TXT_R)) == 0) {
diff --git a/src/LYSearch.c b/src/LYSearch.c
index 752ad488..252185f1 100644
--- a/src/LYSearch.c
+++ b/src/LYSearch.c
@@ -164,9 +164,10 @@ PRIVATE int check_for_target_in_links ARGS2(
  *
  */
 
-PUBLIC BOOL textsearch ARGS3(
+PUBLIC BOOL textsearch ARGS4(
 	document *,	cur_doc,
 	char *,		prev_target,
+	int,		target_size,
 	BOOL,		next)
 {
     int offset;
@@ -196,7 +197,7 @@ PUBLIC BOOL textsearch ARGS3(
 	 *  LYK_NEXT was pressed, so copy the
 	 *  buffer into prev_target. - FM
 	 */
-	strcpy(prev_target, prev_target_buffer);
+	LYstrncpy(prev_target, prev_target_buffer, target_size);
 
     if (strlen(prev_target) == 0 ) {
 	/*
@@ -207,13 +208,12 @@ PUBLIC BOOL textsearch ARGS3(
 	 */
 	_statusline(ENTER_WHEREIS_QUERY);
 
-	if ((ch = LYgetstr(prev_target, VISIBLE,
-			   sizeof(prev_target_buffer), recall)) < 0) {
+	if ((ch = LYgetstr(prev_target, VISIBLE, target_size, recall)) < 0) {
 	    /*
 	     *  User cancelled the search via ^G.
 	     *  Restore prev_target and return. - FM
 	     */
-	    strcpy(prev_target, prev_target_buffer);
+	    LYstrncpy(prev_target, prev_target_buffer, target_size);
 	    HTInfoMsg(CANCELLED);
 	    return(FALSE);
 	}
@@ -262,7 +262,7 @@ check_recall:
 	    QueryNum = 0;
 	if ((cp = (char *)HTList_objectAt(search_queries,
 					  QueryNum)) != NULL) {
-	    strcpy(prev_target, cp);
+	    LYstrncpy(prev_target, cp, target_size);
 	    if (*prev_target_buffer &&
 		!strcmp(prev_target_buffer, prev_target)) {
 		_statusline(EDIT_CURRENT_QUERY);
@@ -272,13 +272,12 @@ check_recall:
 	    } else {
 		_statusline(EDIT_A_PREV_QUERY);
 	    }
-	    if ((ch = LYgetstr(prev_target, VISIBLE,
-			       sizeof(prev_target_buffer), recall)) < 0) {
+	    if ((ch = LYgetstr(prev_target, VISIBLE, target_size, recall)) < 0) {
 		/*
 		 *  User canceled the search via ^G.
 		 *  Restore prev_target and return. - FM
 		 */
-		strcpy(prev_target, prev_target_buffer);
+		LYstrncpy(prev_target, prev_target_buffer, target_size);
 		HTInfoMsg(CANCELLED);
 		return(FALSE);
 	    }
@@ -314,7 +313,7 @@ check_recall:
 	    QueryNum = QueryTotal - 1;
 	if ((cp = (char *)HTList_objectAt(search_queries,
 					  QueryNum)) != NULL) {
-	    strcpy(prev_target, cp);
+	    LYstrncpy(prev_target, cp, target_size);
 	    if (*prev_target_buffer &&
 		!strcmp(prev_target_buffer, prev_target)) {
 		_statusline(EDIT_CURRENT_QUERY);
@@ -324,13 +323,12 @@ check_recall:
 	    } else {
 		_statusline(EDIT_A_PREV_QUERY);
 	    }
-	    if ((ch = LYgetstr(prev_target, VISIBLE,
-			       sizeof(prev_target_buffer), recall)) < 0) {
+	    if ((ch = LYgetstr(prev_target, VISIBLE, target_size, recall)) < 0) {
 		/*
 		 *  User cancelled the search via ^G.
 		 *  Restore prev_target and return. - FM
 		 */
-		strcpy(prev_target, prev_target_buffer);
+		LYstrncpy(prev_target, prev_target_buffer, target_size);
 		HTInfoMsg(CANCELLED);
 		return(FALSE);
 	    }
@@ -340,7 +338,7 @@ check_recall:
     /*
      *  Replace the search string buffer with the new target. - FM
      */
-    strcpy(prev_target_buffer, prev_target);
+    LYstrncpy(prev_target_buffer, prev_target, sizeof(prev_target_buffer)-1);
     HTAddSearchQuery(prev_target_buffer);
 
     /*
diff --git a/src/LYSearch.h b/src/LYSearch.h
index a8a31973..89d21529 100644
--- a/src/LYSearch.h
+++ b/src/LYSearch.h
@@ -7,7 +7,7 @@
 #endif /* LYSTRUCT_H */
 
 extern BOOL textsearch PARAMS((document *cur_doc,
-			       char *prev_target, BOOL next));
+			       char *prev_target, int target_size, BOOL next));
 
 #define IN_FILE 1
 #define IN_LINKS 2
diff --git a/src/LYShowInfo.c b/src/LYShowInfo.c
index f00e1557..f465cfd7 100644
--- a/src/LYShowInfo.c
+++ b/src/LYShowInfo.c
@@ -11,6 +11,7 @@
 #include <LYCharUtils.h>
 #include <GridText.h>
 #include <LYReadCFG.h>
+#include <LYCharSets.h>
 
 #include <LYLeaks.h>
 
@@ -42,7 +43,6 @@ PUBLIC int showinfo ARGS4(
 #ifdef ADVANCED_INFO
     BOOLEAN LYInfoAdvanced = (BOOL) (user_mode == ADVANCED_MODE);
 #endif
-
 #ifdef DIRED_SUPPORT
     struct stat dir_info;
 #endif /* DIRED_SUPPORT */
@@ -229,7 +229,7 @@ PUBLIC int showinfo ARGS4(
     fprintf(fp0, "<h2>%s</h2>\n<dl compact>",
 	    gettext("File that you are currently viewing"));
 
-    StrAllocCopy(Title, doc->title);
+    LYformTitle(&Title, doc->title);
     LYEntify(&Title, TRUE);
     fprintf(fp0, "<dt><em>%s</em> %s%s\n",
 		 gettext("Linkname:"),
diff --git a/src/LYStrings.c b/src/LYStrings.c
index f02cff44..43ab4378 100644
--- a/src/LYStrings.c
+++ b/src/LYStrings.c
@@ -15,9 +15,9 @@
 #include <HTString.h>
 #include <LYCharUtils.h>
 #include <HTParse.h>
-#if defined(NCURSES_MOUSE_VERSION) || defined(USE_SLANG_MOUSE)
+#if defined(NCURSES_MOUSE_VERSION) || defined(PDCURSES) || defined(USE_SLANG_MOUSE)
 #include <LYMainLoop.h>
-#endif /* NCURSES_MOUSE_VERSION || USE_SLANG_MOUSE */
+#endif
 
 #ifdef DJGPP_KEYHANDLER
 #include <pc.h>
@@ -37,13 +37,13 @@
 
 extern unsigned short *LYKbLayout;
 extern BOOL HTPassHighCtrlRaw;
-extern HTCJKlang HTCJK;
 
 #ifdef SUPPORT_MULTIBYTE_EDIT
 #define IS_KANA(c)	(0xa0 <= c && c <= 0xdf)
 #endif
 
 #if defined(WIN_EX)
+#undef  BUTTON_CTRL
 #define BUTTON_CTRL	0	/* Quick hack */
 #endif
 
@@ -55,7 +55,7 @@ static int LYClosetTop = 0;		/*Points to the next empty shelf */
 
 PRIVATE char *LYFindInCloset PARAMS((
 	char*		base));
-PRIVATE int LYAddToCloset PARAMS((
+PRIVATE void LYAddToCloset PARAMS((
 	char*		str));
 
 /* If you want to add mouse support for some new platform, it's fairly
@@ -74,14 +74,14 @@ static int mouse_link = -1;
 
 static int have_levent;
 
-#if defined(NCURSES_MOUSE_VERSION) && !defined(WIN_EX)
+#if defined(NCURSES_MOUSE_VERSION)
 static MEVENT levent;
 #endif
 
 /* Return the value of mouse_link */
 PUBLIC int peek_mouse_levent NOARGS
 {
-#if defined(NCURSES_MOUSE_VERSION) && !defined(WIN_EX)
+#if defined(NCURSES_MOUSE_VERSION)
     if (have_levent > 0) {
 	ungetmouse(&levent);
 	have_levent--;
@@ -114,15 +114,8 @@ PUBLIC int fancy_mouse ARGS3(
     int *,	position)
 {
     int cmd = LYK_DO_NOTHING;
-#if defined(NCURSES_MOUSE_VERSION)
-#ifndef getbegx
-#define getbegx(win) ((win)->_begx)
-#endif
-#ifndef getbegy
-#define getbegy(win) ((win)->_begy)
-#endif
 
-#if defined(WIN_EX)	/* 1998/12/05 (Sat) 08:10:42 */
+#if defined(WIN_EX) && defined(PDCURSES)
 
     request_mouse_pos();
 
@@ -178,6 +171,7 @@ PUBLIC int fancy_mouse ARGS3(
 	cmd = LYK_QUIT;
     }
 #else
+#if defined(NCURSES_MOUSE_VERSION)
     MEVENT	event;
 
     getmouse(&event);
@@ -258,8 +252,8 @@ PUBLIC int fancy_mouse ARGS3(
     } else if (event.bstate & (BUTTON3_CLICKED | BUTTON3_DOUBLE_CLICKED | BUTTON3_TRIPLE_CLICKED)) {
 	cmd = LYK_QUIT;
     }
+#endif	/* defined(NCURSES_MOUSE_VERSION) */
 #endif	/* _WINDOWS */
-#endif
     return cmd;
 }
 
@@ -739,7 +733,7 @@ PUBLIC void ena_csi ARGS1(
 #ifdef USE_SLANG
 #define define_key(string, code) \
 	SLkm_define_keysym (string, code, Keymap_List)
-#define expand_substring(dst, first, last) \
+#define expand_substring(dst, first, last, final) \
 	SLexpand_escaped_string(dst, (char *)first, (char *)last)
 static SLKeyMap_List_Type *Keymap_List;
 /* This value should be larger than anything in LYStrings.h */
@@ -812,7 +806,7 @@ PRIVATE int lookup_tiname (char *name, NCURSES_CONST char *CONST *names)
     return -1;
 }
 
-PRIVATE CONST char *expand_tiname (CONST char *first, size_t len, char **result)
+PRIVATE CONST char *expand_tiname (CONST char *first, size_t len, char **result, char *final)
 {
     char name[BUFSIZ];
     int code;
@@ -822,14 +816,14 @@ PRIVATE CONST char *expand_tiname (CONST char *first, size_t len, char **result)
     if ((code = lookup_tiname(name, strnames)) >= 0
      || (code = lookup_tiname(name, strfnames)) >= 0) {
 	if (cur_term->type.Strings[code] != 0) {
-	    strcpy(*result, cur_term->type.Strings[code]);
+	    LYstrncpy(*result, cur_term->type.Strings[code], final - *result);
 	    (*result) += strlen(*result);
 	}
     }
     return first + len;
 }
 
-PRIVATE CONST char *expand_tichar (CONST char *first, char **result)
+PRIVATE CONST char *expand_tichar (CONST char *first, char **result, char *final)
 {
     int ch;
     int limit = 0;
@@ -869,7 +863,7 @@ PRIVATE CONST char *expand_tichar (CONST char *first, char **result)
     }
 
     if (name != 0) {
-	(void) expand_tiname(name, strlen(name), result);
+	(void) expand_tiname(name, strlen(name), result, final);
     } else {
 	**result = value;
 	(*result) += 1;
@@ -878,13 +872,13 @@ PRIVATE CONST char *expand_tichar (CONST char *first, char **result)
     return first;
 }
 
-PRIVATE void expand_substring (char* dst, CONST char* first, CONST char* last)
+PRIVATE void expand_substring (char* dst, CONST char* first, CONST char* last, char *final)
 {
     int ch;
     while (first < last) {
 	switch (ch = *first++) {
 	case ESCAPE:
-	    first = expand_tichar(first, &dst);
+	    first = expand_tichar(first, &dst, final);
 	    break;
 	case '^':
 	    ch = *first++;
@@ -892,7 +886,7 @@ PRIVATE void expand_substring (char* dst, CONST char* first, CONST char* last)
 		CONST char *s = strchr(first, RPAREN);
 		if (s == 0)
 		    s = first + strlen(first);
-		first = expand_tiname(first, s-first, &dst);
+		first = expand_tiname(first, s-first, &dst, final);
 		if (*first)
 		    first++;
 	    } else if (ch == '?') {		/* ASCII delete? */
@@ -922,13 +916,13 @@ PRIVATE void unescaped_char ARGS2(CONST char*, parse, int*,keysym)
     char buf[BUFSIZ];
 
     if (len >= 3) {
-	expand_substring(buf, parse + 1, parse + len - 1);
+	expand_substring(buf, parse + 1, parse + len - 1, buf + sizeof(buf) - 1);
 	if (strlen(buf) == 1)
 	    *keysym = *buf;
     }
 }
 
-PRIVATE BOOLEAN unescape_string ARGS2(char*, src, char *, dst)
+PRIVATE BOOLEAN unescape_string ARGS3(char*, src, char *, dst, char *, final)
 {
     BOOLEAN ok = FALSE;
 
@@ -941,7 +935,7 @@ PRIVATE BOOLEAN unescape_string ARGS2(char*, src, char *, dst)
 	    ok = TRUE;
 	}
     } else if (*src == DQUOTE) {
-	expand_substring(dst, src + 1, src + strlen(src) - 1);
+	expand_substring(dst, src + 1, src + strlen(src) - 1, final);
 	ok = TRUE;
     }
     return ok;
@@ -991,7 +985,7 @@ PUBLIC int map_string_to_keysym ARGS2(CONST char*, str, int*,keysym)
 		return (*keysym = CH_DEL|modifier);
 	    if (*str == '^' || *str == '\\') {
 		char buf[BUFSIZ];
-		expand_substring(buf, str, str + HTMIN(len, 28));
+		expand_substring(buf, str, str + HTMIN(len, 28), buf + sizeof(buf) - 1);
 		if (strlen(buf) <= 1)
 		    return (*keysym = ((unsigned char)buf[0])|modifier);
 	    }
@@ -1079,7 +1073,7 @@ PRIVATE int setkey_cmd (char *parse)
 	    if (t != s)
 		*t = '\0';
 	    if (map_string_to_keysym (s, &keysym) >= 0
-	     && unescape_string(parse, buf)) {
+	     && unescape_string(parse, buf, buf + sizeof(buf) - 1)) {
 		if (LYTraceLogFP == 0) {
 		    CTRACE((tfp, "KEYMAP(DEF) keysym=%#x\n", keysym));
 		} else {
@@ -1269,7 +1263,7 @@ PUBLIC int lynx_initialize_keymaps NOARGS
 
 #endif				       /* USE_KEYMAPS */
 
-#ifdef NCURSES_MOUSE_VERSION
+#if defined(NCURSES_MOUSE_VERSION) || defined(PDCURSES)
 PRIVATE int LYmouse_menu ARGS4(int, x, int, y, int, atlink, int, code)
 {
     static char *choices[] = {
@@ -1475,7 +1469,7 @@ re_read:
 #endif /* IGNORE_CTRL_C || USE_GETCHAR etc. */
 #if !defined(UCX) || !defined(VAXC) /* errno not modifiable ? */
     if (errno == EINTR)
-	errno = 0;		/* reset - kw */
+	set_errno(0);		/* reset - kw */
 #endif  /* UCX && VAXC */
 #ifndef USE_SLANG
     clearerr(stdin); /* needed here for ultrix and SOCKETSHR, but why? - FM */
@@ -1561,7 +1555,7 @@ re_read:
 		  recent_sizechange));
 #endif /* HAVE_SIZECHANGE || USE_SLANG */
 #if !defined(UCX) || !defined(VAXC) /* errno not modifiable ? */
-	errno = 0;		/* reset - kw */
+	set_errno(0);		/* reset - kw */
 #endif  /* UCX && VAXC */
 	return(DO_NOTHING);
     }
@@ -1960,8 +1954,9 @@ re_read:
 	   c = 0x218;
 	   break;
 #endif /* PDCurses */
-#ifdef NCURSES_MOUSE_VERSION
+#if defined(NCURSES_MOUSE_VERSION) || defined(PDCURSES)
 	case KEY_MOUSE:
+	    CTRACE((tfp, "KEY_MOUSE\n"));
 	    if (code == FOR_CHOICE) {
 		c = MOUSE_KEY;		/* Will be processed by the caller */
 	    }
@@ -1973,7 +1968,7 @@ re_read:
 	    }
 #endif
 	    else {
-#if !defined(WIN_EX)
+#if !(defined(WIN_EX) && defined(PDCURSES))
 		MEVENT event;
 		int err;
 		int lac = LYK_UNKNOWN;
@@ -2081,7 +2076,7 @@ re_read:
 		/* for Windows NT */
 		  request_mouse_pos();
 
-		  if (BUTTON_STATUS(1) & BUTTON_CLICKED) {
+		  if (BUTTON_STATUS(1) & BUTTON_PRESSED) {
 			if (MOUSE_Y_POS > (LYlines - V_CMD_AREA)) {
 			    /* Screen BOTTOM */
 			    if (MOUSE_X_POS < left) {
@@ -2475,7 +2470,6 @@ PUBLIC void LYSetupEdit ARGS4(
     edit->panon = FALSE;
     edit->current_modifiers = 0;
 
-    StrLen  = strlen(old);
     MaxLen  = maxstr;
     DspWdth = maxdsp;
     Margin  = 0;
@@ -2500,21 +2494,8 @@ PUBLIC void LYSetupEdit ARGS4(
 	    Margin = 10;
     }
 
-    /*
-     *	We expect the called function to pass us a default (old) value
-     *	with a length that is less than or equal to maxstr, and to
-     *	handle any messaging associated with actions to achieve that
-     *	requirement.  However, in case the calling function screwed
-     *	up, we'll check it here, and ensure that no buffer overrun can
-     *	occur by loading only as much of the head as fits. - FM
-     */
-    if (strlen(old) >= (unsigned)maxstr) {
-	strncpy(edit->buffer, old, maxstr);
-	edit->buffer[maxstr] = '\0';
-	StrLen = maxstr;
-    } else {
-	strcpy(edit->buffer, old);
-    }
+    LYstrncpy(edit->buffer, old, maxstr);
+    StrLen = strlen(edit->buffer);
 }
 
 #ifdef SUPPORT_MULTIBYTE_EDIT
@@ -3246,7 +3227,7 @@ again:
 	}
 
 	if (recall && (ch == UPARROW || ch == DNARROW)) {
-	    strcpy(inputline, MyEdit.buffer);
+	    LYstrncpy(inputline, MyEdit.buffer, (int)bufsize);
 	    LYAddToCloset(MyEdit.buffer);
 	    return(ch);
 	}
@@ -3318,7 +3299,7 @@ again:
 	    /*
 	     *	Terminate the string and return.
 	     */
-	    strcpy(inputline, MyEdit.buffer);
+	    LYstrncpy(inputline, MyEdit.buffer, (int)bufsize);
 	    if (!hidden)
 		LYAddToCloset(MyEdit.buffer);
 	    return(ch);
@@ -3564,18 +3545,13 @@ PRIVATE char * LYFindInCloset ARGS1(char*, base)
     return(0);
 }
 
-PRIVATE int LYAddToCloset ARGS1(char*, str)
+PRIVATE void LYAddToCloset ARGS1(char*, str)
 {
-    unsigned len = strlen(str);
-
-    LYCloset[LYClosetTop] = malloc(len+1);
-    if (!LYCloset[LYClosetTop])
-	outofmem(__FILE__, "LYAddToCloset");
-    strcpy(LYCloset[LYClosetTop], str);
+    LYCloset[LYClosetTop] = NULL;
+    StrAllocCopy(LYCloset[LYClosetTop], str);
 
     LYClosetTop = (LYClosetTop + 1) % LYClosetSize;
     FREE(LYCloset[LYClosetTop]);
-    return(1);
 }
 
 /*
@@ -4054,11 +4030,11 @@ PUBLIC int UPPER8 ARGS2(int,ch1, int,ch2)
 	   return(TOUPPER(ch1) - TOUPPER(ch2)); /* old-style */
 	else
 	{
-	    long uni_ch2 = UCTransToUni(ch2, current_char_set);
+	    long uni_ch2 = UCTransToUni((char)ch2, current_char_set);
 	    long uni_ch1;
 	    if (uni_ch2 < 0)
 		return (unsigned char)ch1;
-	    uni_ch1 = UCTransToUni(ch1, current_char_set);
+	    uni_ch1 = UCTransToUni((char)ch1, current_char_set);
 	    return(UniToLowerCase(uni_ch1) - UniToLowerCase(uni_ch2));
 	}
     }
diff --git a/src/LYTraversal.c b/src/LYTraversal.c
index 9aa1d97c..35e5327a 100644
--- a/src/LYTraversal.c
+++ b/src/LYTraversal.c
@@ -20,7 +20,7 @@ PRIVATE void final_perror ARGS2(CONST char *,msg, BOOLEAN, clean_flag)
 	else
 	    stop_curses();
     }
-    errno = saved_errno;
+    set_errno(saved_errno);
     perror(msg);
 }
 
diff --git a/src/LYUtils.c b/src/LYUtils.c
index 43e4292b..df1f23b5 100644
--- a/src/LYUtils.c
+++ b/src/LYUtils.c
@@ -118,13 +118,15 @@ extern int BSDselect PARAMS((int nfds, fd_set * readfds, fd_set * writefds,
 #if defined(HAVE_RAND) && defined(HAVE_SRAND) && defined(RAND_MAX)
 #define USE_RAND_TEMPNAME 1
 #define MAX_TEMPNAME 10000
+#ifndef BITS_PER_CHAR
+#define BITS_PER_CHAR 8
+#endif
 #endif
 #endif
 
 #define COPY_COMMAND "%s %s %s"
 
 extern BOOLEAN LYHaveCJKCharacterSet;
-extern HTCJKlang HTCJK;
 
 PRIVATE HTList * localhost_aliases = NULL;	/* Hosts to treat as local */
 PRIVATE char *HomeDir = NULL;			/* HOME directory */
@@ -1928,13 +1930,12 @@ BOOLEAN mustshow = FALSE;
 PUBLIC void statusline ARGS1(
 	CONST char *,	text)
 {
-    char buffer[256];
+    char buffer[MAX_LINE];
     unsigned char *temp = NULL;
     int max_length, len, i, j;
     unsigned char k;
     char *p;
-    char text_buff[256];
-    int text_len;
+    char text_buff[MAX_LINE];
 
     if (text == NULL)
 	return;
@@ -1956,33 +1957,10 @@ PUBLIC void statusline ARGS1(
     mustshow = FALSE;
 
     /* "LYNXDOWNLOAD://Method=-1/File=%s/SugFile=%s%s\">Save to disk</a>\n" */
-    /* 1997/12/23 (Tue) 15:58:58 */
-    text_len = strlen(text);
-    if (text_len < 256) {
-	strcpy(text_buff, text);
-    } else {
-	strncpy(text_buff, text, 255);
-	text_buff[255] = '\0';
-	p = strchr(text_buff, '\n');
-	if (p)
-	    p= '\0';
-    }
-#if 0
-    /* This is broken.  It shows a truncated name if the complete URL is
-     * so long that it has already been shortened by the caller to fit.
-     * Moreover it doesn't belong here.  This function should just display
-     * what it's asked to and not second-guess its caller.  If you want
-     * a different message displayed, pass it a different message.
-     * Finally, I dislike the intended change anyway.  It shows less
-     * information, it is a dumbed down interface. - kw
-     */
-    if (strncmp(text, "LYNXDOWNLOAD:", 13) == 0) {
-	p = strstr(text + 13, "SugFile=");
-	if (p != NULL) {
-	    strcpy(text_buff, p + 3);
-	}
-    }
-#endif
+    LYstrncpy(text_buff, text, sizeof(text_buff)-1);
+    p = strchr(text_buff, '\n');
+    if (p)
+	p= '\0';
 
     /*
      *	Deal with any CJK escape sequences and Kanji if we have a CJK
@@ -1996,7 +1974,7 @@ PUBLIC void statusline ARGS1(
 	/*
 	 *  Translate or filter any escape sequences. - FM
 	 */
-	if ((temp = (unsigned char *)calloc(1, strlen(text_buff) + 1)) == NULL)
+	if ((temp = typecallocn(unsigned char, strlen(text_buff) + 1)) == NULL)
 	    outofmem(__FILE__, "statusline");
 	if (kanji_code == EUC) {
 	    TO_EUC((CONST unsigned char *)text_buff, temp);
@@ -2489,7 +2467,7 @@ PUBLIC BOOLEAN LYisAbsPath ARGS1(
     return TRUE;
 #else
     BOOLEAN result;
-#ifdef DOSPATH
+#if defined(DOSPATH) || defined(__EMX__)
     result = (BOOL) (LYIsPathSep(path[0])
      || (isalpha(path[0])
       && (path[1] == ':')
@@ -2507,7 +2485,7 @@ PUBLIC BOOLEAN LYisAbsPath ARGS1(
 PUBLIC BOOLEAN LYisRootPath ARGS1(
 	char *,		path)
 {
-#ifdef DOSPATH
+#if defined(DOSPATH) || defined(__EMX__)
     if (strlen(path) == 3
      && isalpha(path[0])
      && path[1] == ':'
@@ -2626,7 +2604,7 @@ PUBLIC void LYLocalhostAliases_free NOARGS
 PUBLIC void LYAddLocalhostAlias ARGS1(
 	char *,		alias)
 {
-    char *LocalAlias;
+    char *LocalAlias = NULL;
 
     if (!(alias && *alias))
 	return;
@@ -2638,9 +2616,7 @@ PUBLIC void LYAddLocalhostAlias ARGS1(
 #endif
     }
 
-    if ((LocalAlias = (char *)calloc(1, (strlen(alias) + 1))) == NULL)
-	outofmem(__FILE__, "HTAddLocalhosAlias");
-    strcpy(LocalAlias, alias);
+    StrAllocCopy(LocalAlias, alias);
     HTList_addObject(localhost_aliases, LocalAlias);
 
     return;
@@ -3438,16 +3414,14 @@ PUBLIC void HTSugFilenames_free NOARGS
 PUBLIC void HTAddSugFilename ARGS1(
 	char *,		fname)
 {
-    char *new;
+    char *new = NULL;
     char *old;
     HTList *cur;
 
     if (!(fname && *fname))
 	return;
 
-    if ((new = (char *)calloc(1, (strlen(fname) + 1))) == NULL)
-	outofmem(__FILE__, "HTAddSugFilename");
-    strcpy(new, fname);
+    StrAllocCopy(new, fname);
 
     if (!sug_filenames) {
 	sug_filenames = HTList_new();
@@ -3780,9 +3754,30 @@ PRIVATE int fmt_tempname ARGS3(
 	CONST char *,	prefix,
 	CONST char *,	suffix)
 {
+    int code;
+#if defined(USE_MKSTEMP) && defined(HAVE_MKSTEMP)
+    int fd;
+    char interim[LY_MAXPATH];
+    sprintf(interim, "%.*sXXXXXX", LY_MAXPATH - 8, prefix);
+    if (strlen(interim) + strlen(suffix) < LY_MAXPATH - 2
+    && (fd = mkstemp(interim)) >= 0) {
+	sprintf(result, "%s%s", interim, suffix);
+	rename(interim, result);
+	chmod(result, HIDE_CHMOD); /* (yes, some mkstemps are broken ;-) */
+	close(fd);
+	code = TRUE;
+    } else {
+	code = FALSE;
+    }
+#else
+#ifdef USE_RAND_TEMPNAME
+    static BOOL first = TRUE;
+    static int names_used = 0;
+    static unsigned char *used_tempname;
+    unsigned offset, mask;
+#endif
     static unsigned counter;
     char leaf[LY_MAXPATH];
-    int code;
 
     if (prefix == 0)
 	prefix = "";
@@ -3792,16 +3787,38 @@ PRIVATE int fmt_tempname ARGS3(
      * Prefer a random value rather than a counter.
      */
 #ifdef USE_RAND_TEMPNAME
-    do {
-	int uninit;	/* ( intentionally uninitialized ;-) */
-    if (counter == 0)
-	srand(time((time_t *)0) + uninit);
+    if (first) {
+	srand((unsigned)((long)time((time_t *)0) + (long)result));
+	first = FALSE;
+	used_tempname = typecallocn(unsigned char,
+				(MAX_TEMPNAME / BITS_PER_CHAR) + 1);
+	if (used_tempname == 0)
+	    outofmem(__FILE__, "fmt_tempname");
+    }
+
     /* We don't really need all of the bits from rand().  The high-order bits
      * are the more-random portion in any case, but limiting the width of the
      * generated name is done partly to avoid problems on systems that may not
      * support long filenames.
      */
-    counter = ( (float)MAX_TEMPNAME * rand() ) / RAND_MAX + 1;
+    counter = MAX_TEMPNAME;
+    while (names_used < MAX_TEMPNAME) {
+	counter = ( (float)MAX_TEMPNAME * rand() ) / RAND_MAX + 1;
+	/*
+	 * Avoid reusing a temporary name, since there are places in the code
+	 * which can refer to a temporary filename even after it has been
+	 * closed and removed from the filesystem.
+	 */
+	offset = counter / BITS_PER_CHAR;
+	mask = 1 << (counter % BITS_PER_CHAR);
+	if ((used_tempname[offset] & mask) == 0) {
+	    names_used++;
+	    used_tempname[offset] |= mask;
+	    break;
+	}
+    }
+    if (counter >= MAX_TEMPNAME)
+	HTAlert("Too many tempfiles");
 #else
     counter++;
 #endif
@@ -3841,9 +3858,6 @@ PRIVATE int fmt_tempname ARGS3(
 	sprintf(result, "%.*s", LY_MAXPATH-1, leaf);
 	code = FALSE;
     }
-#ifdef USE_RAND_TEMPNAME
-    /* If we really have 10000 files open, there's no point in returning... */
-    } while (FindTempfileByName(result) != 0);
 #endif
     CTRACE((tfp, "-> '%s'\n", result));
     return (code);
@@ -4409,7 +4423,7 @@ PUBLIC void LYConvertToURL ARGS2(
 	} else {
 	    if ((fragment = strchr(old_string, '#')) != NULL)
 		*fragment = '\0';
-	    strcpy(url_file, old_string);
+	    LYstrncpy(url_file, old_string, sizeof(url_file)-1);
 	}
 	url_file_dsc.dsc$w_length = (short) strlen(url_file);
 	if (1&lib$find_file(&url_file_dsc, &file_name_dsc, &context,
@@ -4467,8 +4481,7 @@ PUBLIC void LYConvertToURL ARGS2(
 		     *	sure).	Use original pathspec for the
 		     *	error message that will result.
 		     */
-		    strcpy(url_file, "/");
-		    strcat(url_file, old_string);
+		    sprintf(url_file, "/%.*s", sizeof(url_file)-2, old_string);
 		    CTRACE((tfp, "Can't find '%s'  Will assume it's a bad path.\n",
 				old_string));
 		    StrAllocCat(*AllocatedString, url_file);
@@ -4506,8 +4519,7 @@ PUBLIC void LYConvertToURL ARGS2(
 		 *  sure).  Use original pathspec for the
 		 *  error message that will result.
 		 */
-		strcpy(url_file, "/");
-		strcat(url_file, old_string);
+		sprintf(url_file, "/%.*s", sizeof(url_file)-2, old_string);
 		CTRACE((tfp, "Can't find '%s'  Will assume it's a bad path.\n",
 			    old_string));
 		StrAllocCat(*AllocatedString, url_file);
@@ -5611,12 +5623,6 @@ PUBLIC BOOLEAN LYPathOffHomeOK ARGS2(
 		return(FALSE);
 	    }
 	}
-#ifdef _WINDOWS		/* 1997/10/16 (Thu) 22:08:17 */
-	strcpy(buff, homedir);
-	p = buff;
-	while (*p++) if (*p == '\\') *p = '/';
-	homedir = buff;
-#endif
     }
 #endif /* VMS */
     if (*cp == '~') {
@@ -6403,7 +6409,7 @@ PUBLIC BOOLEAN LYCachedTemp ARGS2(
     FILE *fp;
 
     if (*cached) {
-	strcpy(result, *cached);
+	LYstrncpy(result, *cached, LY_MAXPATH);
 	FREE(*cached);
 	if ((fp = fopen(result, "r")) != NULL) {
 	    fclose(fp);
@@ -6474,7 +6480,7 @@ PUBLIC FILE *LYOpenTemp ARGS3(
 #endif
     } while (fp == 0);
 
-    if ((p = (LY_TEMP *)calloc(1, sizeof(LY_TEMP))) != 0) {
+    if ((p = typecalloc(LY_TEMP)) != 0) {
 	p->next = ly_temp;
 	StrAllocCopy((p->name), result);
 	p->file = fp;
@@ -6681,7 +6687,7 @@ PUBLIC FILE *LYOpenScratch ARGS2(
 	return 0;
 
     if ((fp = LYNewTxtFile (result)) != 0) {
-	if ((p = (LY_TEMP *)calloc(1, sizeof(LY_TEMP))) != 0) {
+	if ((p = typecalloc(LY_TEMP)) != 0) {
 	    p->next = ly_temp;
 	    StrAllocCopy((p->name), result);
 	    p->file = fp;
@@ -6771,6 +6777,10 @@ PUBLIC void LYCleanupTemp NOARGS
     while (ly_temp != 0) {
 	LYRemoveTemp(ly_temp->name);
     }
+#ifdef UNIX
+    if (lynx_temp_subspace)
+	rmdir(lynx_temp_space);
+#endif
 }
 
 /*
@@ -6839,7 +6849,7 @@ static uip_entry ly_uip[] =
 
 };
 
-/*  Public entry points for User Interface Page mamagement: */
+/*  Public entry points for User Interface Page management: */
 
 PUBLIC BOOL LYIsUIPage3 ARGS3(
     CONST char *,	url,
@@ -6963,12 +6973,14 @@ PUBLIC  char * wwwName ARGS1(
  * 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.
  */
 PUBLIC BOOLEAN LYValidateFilename ARGS2(
 	char *,		result,
 	char *,		given)
 {
-    char *cp;
+    char *cp, *cp2;
 
     /*
      *  Cancel if the user entered "/dev/null" on Unix,
@@ -6990,15 +7002,17 @@ PUBLIC BOOLEAN LYValidateFilename ARGS2(
 	    HTUserMsg(SPAWNING_DISABLED);
 	    return FALSE;
 	}
-	strcpy(result, given);
+	LYstrncpy(result, given, LY_MAXPATH);
 	return TRUE;
     }
 #endif
-    if ((cp = strchr(given, '~'))) {
+    if ((cp = strchr(given, '~')) != 0
+     && (cp2 = wwwName(Home_Dir())) != 0
+     && strlen(cp2) + strlen(given) < LY_MAXPATH) {
 	*(cp++) = '\0';
 	strcpy(result, given);
 	LYTrimPathSep(result);
-	strcat(result, wwwName(Home_Dir()));
+	strcat(result, cp2);
 	strcat(result, cp);
 	strcpy(given, result);
     }
@@ -7007,7 +7021,9 @@ PUBLIC BOOLEAN LYValidateFilename ARGS2(
 	strcpy(result, HTVMS_name("", given));
 	strcpy(given, result);
     }
-    if (given[0] != '/' && strchr(given, ':') == NULL) {
+    if (given[0] != '/'
+     && strchr(given, ':') == NULL
+     && strlen(given) < LY_MAXPATH - 13) {
 	strcpy(result, "sys$disk:");
 	if (strchr(given, ']') == NULL)
 	    strcat(result, "[]");
@@ -7226,6 +7242,7 @@ PUBLIC void LYAddPathSep0 ARGS1(
 
     if ((path != 0)
      && (len = strlen(path)) != 0
+     && (len < LY_MAXPATH - 2)
      && !LYIsPathSep(path[len-1])) {
 	strcat(path, PATHSEP_STR);
     }
@@ -7291,6 +7308,7 @@ PUBLIC void LYAddHtmlSep0 ARGS1(
 
     if ((path != 0)
      && (len = strlen(path)) != 0
+     && (len < LY_MAXPATH - 2)
      && !LYIsHtmlSep(path[len-1])) {
 	strcat(path, "/");
     }
@@ -7480,7 +7498,7 @@ PUBLIC int LYSystem ARGS1(
     if (do_free)
 	FREE(command);
 #if !defined(UCX) || !defined(VAXC) /* errno not modifiable ?? */
-    errno = saved_errno;	/* may have been clobbered */
+    set_errno(saved_errno);	/* may have been clobbered */
 #endif
     return code;
 }
diff --git a/src/LYUtils.h b/src/LYUtils.h
index 646411b8..038942b8 100644
--- a/src/LYUtils.h
+++ b/src/LYUtils.h
@@ -8,6 +8,7 @@
 #endif /* HTLIST_H */
 
 #ifdef VMS
+#include <HTFTP.h>
 #include <HTVMSUtils.h>
 #define HTSYS_name(path)   HTVMS_name("", path)
 #define HTSYS_purge(path)  HTVMS_purge(path)
diff --git a/src/TRSTable.h b/src/TRSTable.h
index 115bac1a..927dd037 100644
--- a/src/TRSTable.h
+++ b/src/TRSTable.h
@@ -1,6 +1,8 @@
 #ifndef TRSTABLE_H
 #define TRSTABLE_H
 
+#include <HTUtils.h>
+
 /* TRST_MAXCOLSPAN and TRST_MAXCOLSPAN are defined in userdefs.h */
 
 typedef struct _STable_info STable_info;
diff --git a/src/UCAux.c b/src/UCAux.c
index d4701484..51d0be20 100644
--- a/src/UCAux.c
+++ b/src/UCAux.c
@@ -5,9 +5,7 @@
 #include <UCDefs.h>
 #include <HTStream.h>
 #include <UCAux.h>
-
-extern HTCJKlang HTCJK;
-extern LYUCcharset LYCharSet_UC[];
+#include <LYCharSets.h>
 
 PUBLIC BOOL UCCanUniTranslateFrom ARGS1(
 	int,		from)
diff --git a/src/Xsystem.c b/src/Xsystem.c
index b41c6cba..b0fa4a81 100644
--- a/src/Xsystem.c
+++ b/src/Xsystem.c
@@ -1,4 +1,4 @@
-/* @Id: Xsystem.c 1.5 Tue, 30 Nov 1999 20:33:02 -0700 dickey @
+/* @Id: Xsystem.c 1.6 Sun, 26 Mar 2000 19:14:00 -0800 dickey @
  *	like system("cmd") but return with exit code of "cmd"
  *	for Turbo-C/MS-C/LSI-C
  *  This code is in the public domain.
@@ -304,17 +304,17 @@ try3(char *cnm, PRO * p, int flag)
     char cmdb[STR_MAX];
     int rc;
 
-    strcat(strcpy(cmdb, cnm), ".com");
+    sprintf(cmdb, "%.*s.com", sizeof(cmdb) - 5, cnm);
     if ((rc = open(cmdb, O_RDONLY)) >= 0) {
 	close(rc);
 	return spawnl(flag, cmdb, cmdb, p->arg, (char *) 0);
     }
-    strcat(strcpy(cmdb, cnm), ".exe");
+    sprintf(cmdb, "%.*s.exe", sizeof(cmdb) - 5, cnm);
     if ((rc = open(cmdb, O_RDONLY)) >= 0) {
 	close(rc);
 	return spawnl(flag, cmdb, cmdb, p->arg, (char *) 0);
     }
-    strcat(strcpy(cmdb, cnm), ".bat");
+    sprintf(cmdb, "%.*s.bat", sizeof(cmdb) - 5, cnm);
     if ((rc = open(cmdb, O_RDONLY)) >= 0) {
 	close(rc);
 	return csystem(p, flag);
@@ -346,7 +346,7 @@ prog_go(PRO * p, int flag)
 
     if (s < p->cmd) {		/* cmd has no PATH nor Drive */
 	ep = getenv("PATH");
-	strcpy(cmdb, p->cmd);
+	LYstrncpy(cmdb, p->cmd, sizeof(cmdb) - 1);
 	for (;;) {
 	    if (extp) {		/* has extension */
 		if ((rc = open(cmdb, O_RDONLY)) >= 0) {
@@ -368,7 +368,7 @@ prog_go(PRO * p, int flag)
 		if (i > 0 && lc != ':' && lc != '\\' && lc != '/')
 		    cmdb[i++] = '\\';
 		cmdb[i] = 0;
-		strcat(cmdb, p->cmd);
+		LYstrncpy(cmdb + i, p->cmd, sizeof(cmdb) - 1 - i);
 	    } else {
 		if (rc == -2)
 		    return rc;
@@ -396,7 +396,7 @@ tmpf(char *tp)
     int i;
 
     if ((ev = getenv("TMP")) != 0) {
-	strcpy(tplate, ev);
+	LYstrncpy(tplate, ev, sizeof(tplate) - 2 - strlen(tp));
 	i = strlen(ev);
 	if (i && ev[i - 1] != '\\' && ev[i - 1] != '/')
 	    strcat(tplate, "\\");
@@ -498,7 +498,7 @@ xsystem(char *cmd)
 	if (!getenv("NOCMDLINE")) {
 	    oldcmdline = cmdline;
 	    cmdline = xmalloc(strlen(p->cmd) + strlen(p->arg) + 10);
-	    strcat(strcat(strcat(strcpy(cmdline, "CMDLINE="), p->cmd), " "), p->arg);
+	    sprintf(cmdline, "CMDLINE=%s %s", p->cmd, p->arg);
 	    putenv(cmdline);
 	    if (oldcmdline)
 		free(oldcmdline);
diff --git a/src/chrtrans/makeuctb.c b/src/chrtrans/makeuctb.c
index 9ad80ecb..14d0dd54 100644
--- a/src/chrtrans/makeuctb.c
+++ b/src/chrtrans/makeuctb.c
@@ -142,7 +142,7 @@ PRIVATE void addpair_str ARGS2(
 	char *,		str,
 	int,		un)
 {
-   int i;
+   int i = 0;
 
     if (un <= 0xfffe) {
 	if (!themap_str.entry_ct) {