int ch, recall; int URLTotal;
int ch = 0, recall = 0; int URLTotal = 0;
int mainloop NOARGS{#if defined(WIN_EX)	/* 1997/10/08 (Wed) 14:52:06 */#undef	STRING_MAX#define	STRING_MAX	4096    char temp_buff[STRING_MAX];#define	BUFF_MAX	1024    char sjis_buff[BUFF_MAX];#endif    int c = 0, real_c = 0, old_c = 0, pending_form_c = -1;    int cmd = LYK_DO_NOTHING, real_cmd = LYK_DO_NOTHING;    int getresult;    int arrowup = FALSE, show_help = FALSE;    char user_input_buffer[MAX_LINE];    CONST char *cshelpfile = NULL;    BOOLEAN first_file = TRUE;    BOOLEAN popped_doc = FALSE;    BOOLEAN refresh_screen = FALSE;    BOOLEAN force_load = FALSE;    BOOLEAN try_internal = FALSE;    BOOLEAN crawl_ok = FALSE;    BOOLEAN vi_keys_flag = vi_keys;    BOOLEAN emacs_keys_flag = emacs_keys;    BOOLEAN trace_mode_flag = FALSE;    BOOLEAN forced_HTML_mode = LYforce_HTML_mode;    char cfile[128];    FILE *cfp;    char *cp;    int ch, recall;    int URLTotal;    int URLNum;    BOOLEAN FirstURLRecall = TRUE;    char *temp = NULL;    BOOLEAN ForcePush = FALSE;    BOOLEAN override_LYresubmit_posts = FALSE;    BOOLEAN newdoc_link_is_absolute = FALSE;    BOOLEAN curlink_is_editable;    BOOLEAN use_last_tfpos;    unsigned int len;    int i;    int follow_col = -1, key_count = 0, last_key = 0;/*  "internal" means "within the same document, with certainty". *  It includes a space so it cannot conflict with any (valid) "TYPE" *  attributes on A elements. [According to which DTD, anyway??] - kw */    HTInternalLink = HTAtom_for("internal link");  /* init, used as const */#ifndef WWW_SOURCE    WWW_SOURCE = HTAtom_for("www/source");  /* init, used as const */#endif/* *  curdoc.address contains the name of the file that is currently open. *  newdoc.address contains the name of the file that will soon be *		     opened if it exits. *  prev_target    contains the last search string the user searched for. *  newdoc.title   contains the link name that the user last chose to get *		     into the current link (file). */    /* initialize some variables*/    newdoc.address = NULL;    newdoc.title = NULL;    newdoc.post_data = NULL;    newdoc.post_content_type = NULL;    newdoc.bookmark = NULL;    newdoc.internal_link = FALSE;    curdoc.address = NULL;    curdoc.title = NULL;    curdoc.post_data = NULL;    curdoc.post_content_type = NULL;    curdoc.bookmark = NULL;    curdoc.internal_link = FALSE;#ifdef USE_COLOR_STYLE    curdoc.style = NULL;    newdoc.style = NULL;#endif    nhist = 0;    user_input_buffer[(sizeof(user_input_buffer) - 1)] = '\0';    *prev_target = '\0';    *user_input_buffer = '\0';#ifdef LY_FIND_LEAKS    atexit(free_mainloop_variables);#endifinitialize:    set_address(&newdoc, startfile);    StrAllocCopy(startrealm, startfile);    StrAllocCopy(newdoc.title, gettext("Entry into main screen"));    newdoc.isHEAD = FALSE;    newdoc.safe = FALSE;    newdoc.line = 1;    newdoc.link = 0;#ifdef USE_SLANG    if (TRACE && LYCursesON) {	LYaddstr("\n");	LYrefresh();    }#endif /* USE_SLANG */    CTRACE((tfp, "Entering mainloop, startfile=%s\n", startfile));    if (form_post_data) {	BStrCopy0(newdoc.post_data, form_post_data);	StrAllocCopy(newdoc.post_content_type,		     "application/x-www-form-urlencoded");    } else if (form_get_data) {	StrAllocCat(newdoc.address, form_get_data);    }    if (bookmark_start) {	if (LYValidate) {	    HTAlert(BOOKMARKS_DISABLED);	    bookmark_start = FALSE;	    goto initialize;	} else if (traversal) {	    HTAlert(BOOKMARKS_NOT_TRAVERSED);	    traversal = FALSE;	    crawl = FALSE;	    bookmark_start = FALSE;	    goto initialize;	} else {	    /*	     *	See if a bookmark page exists.	If it does,	     *	replace newdoc.address with its name	     */	    if ((cp = get_bookmark_filename(&newdoc.address)) != NULL &&		 *cp != '\0' && strcmp(cp, " ")) {		StrAllocCopy(newdoc.title, BOOKMARK_TITLE);		StrAllocCopy(newdoc.bookmark, BookmarkPage);		StrAllocCopy(startrealm, newdoc.address);		LYFreePostData(&newdoc);		newdoc.isHEAD = FALSE;		newdoc.safe = FALSE;		CTRACE((tfp, "Using bookmarks=%s\n", newdoc.address));	    } else {		HTUserMsg(BOOKMARKS_NOT_OPEN);		bookmark_start = FALSE;		goto initialize;	    }	}    }    FREE(form_post_data);    FREE(form_get_data);    if (user_mode == NOVICE_MODE)	display_lines = LYlines-4;    else	display_lines = LYlines-2;    while (TRUE) {#ifdef USE_COLOR_STYLE	if (curdoc.style != NULL) force_load = TRUE;#endif	/*	 *  If newdoc.address is different then curdoc.address then	 *  we need to go out and find and load newdoc.address.	 */	if (LYforce_no_cache || force_load ||	    are_different(&curdoc, &newdoc)) {		force_load = FALSE;  /* done */		if (TRACE && LYCursesON) {		    LYHideCursor();	/* make sure cursor is down */#ifdef USE_SLANG		    LYaddstr("\n");#endif /* USE_SLANG */		    LYrefresh();		}try_again:		/*		 *  Push the old file onto the history stack if we		 *  have a current doc and a new address. - FM		 */		if (curdoc.address && newdoc.address) {		    /*		     *	Don't actually push if this is a LYNXDOWNLOAD		     *	URL, because that returns NORMAL even if it		     *	fails due to a spoof attempt or file access		     *	problem, and we set the newdoc structure		     *	elements to the curdoc structure elements		     *	under case NORMAL.  - FM		     */		    if (!isLYNXDOWNLOAD(newdoc.address))		    {			LYpush(&curdoc, ForcePush);		    }		} else if (!newdoc.address) {		    /*		     *	If newdoc.address is empty then pop a file		     *	and load it.  - FM		     */		    LYhist_prev(&newdoc);		    popped_doc = TRUE;#ifndef DONT_TRACK_INTERNAL_LINKS		    /*		    ** If curdoc had been reached via an internal		    ** (fragment) link from what we now have just		    ** popped into newdoc, then override non-caching in		    ** all cases. - kw		    */		    if (curdoc.internal_link &&			!are_phys_different(&curdoc, &newdoc)) {			LYinternal_flag = TRUE;			LYoverride_no_cache = TRUE;			LYforce_no_cache = FALSE;			try_internal = TRUE;		    } else#endif /* TRACK_INTERNAL_LINKS */		    {			/*			 * Force a no_cache override unless			 *  it's a bookmark file, or it has POST content			 *  and LYresubmit_posts is set without safe also			 *  set, and we are not going to another position			 *  in the current document or restoring the previous			 *  document due to a NOT_FOUND or NULLFILE return			 *  value from getfile(). - FM			 */			if ((newdoc.bookmark != NULL) ||			    (newdoc.post_data != NULL &&			     !newdoc.safe &&			     LYresubmit_posts &&			     !override_LYresubmit_posts &&				NO_INTERNAL_OR_DIFFERENT(&curdoc, &newdoc))) {			    LYoverride_no_cache = FALSE;			} else {			    LYoverride_no_cache = TRUE;			}		    }		}		override_LYresubmit_posts = FALSE;		if (HEAD_request) {		    /*		     *	Make SURE this is an appropriate request. - FM		     */		    if (newdoc.address) {			if (LYCanDoHEAD(newdoc.address) == TRUE) {			    newdoc.isHEAD = TRUE;			} else if (isLYNXIMGMAP(newdoc.address)) {			    if (LYCanDoHEAD(newdoc.address + LEN_LYNXIMGMAP) == TRUE) {				StrAllocCopy(temp, newdoc.address + LEN_LYNXIMGMAP);				free_address(&newdoc);				newdoc.address = temp;				newdoc.isHEAD = TRUE;				temp = NULL;			    }			}		    }		    try_internal = FALSE;		    HEAD_request = FALSE;		}		/*		 *  If we're getting the TRACE log and it's not new,		 *  check whether its HText structure has been dumped,		 *  and if so, fflush() and fclose() it to ensure it's		 *  fully updated, and then fopen() it again. - FM		 */		if (LYUseTraceLog == TRUE &&		    trace_mode_flag == FALSE &&		    LYTraceLogFP != NULL &&		    LYIsUIPage(newdoc.address, UIP_TRACELOG)) {		    DocAddress WWWDoc;		    HTParentAnchor *tmpanchor;		    WWWDoc.address = newdoc.address;		    WWWDoc.post_data = newdoc.post_data;		    WWWDoc.post_content_type = newdoc.post_content_type;		    WWWDoc.bookmark = newdoc.bookmark;		    WWWDoc.isHEAD = newdoc.isHEAD;		    WWWDoc.safe = newdoc.safe;		    tmpanchor = HTAnchor_findAddress(&WWWDoc);		    if ((HText *)HTAnchor_document(tmpanchor) == NULL) {			if (!LYReopenTracelog(&trace_mode_flag)) {			    old_c = 0;			    cmd = LYK_PREV_DOC;			    goto new_cmd;			}		    }		}		LYRequestTitle = newdoc.title;		if (newdoc.bookmark)		    LYforce_HTML_mode = TRUE;		if (LYValidate &&		    startfile_ok &&		    newdoc.address && startfile && homepage &&		    (!strcmp(newdoc.address, startfile) ||		     !strcmp(newdoc.address, homepage))) {		    LYPermitURL = TRUE;		}		/* reset these two variables here before getfile()		 * so they will be available in partial mode		 * (was previously implemented in case NORMAL).		 */		*prev_target = '\0';	/* Reset for new coming document */		Newline = newdoc.line;	/* set for LYGetNewline() */#ifdef USE_PRETTYSRC		psrc_first_tag = TRUE;#endif#ifdef TEXTFIELDS_MAY_NEED_ACTIVATION		textfields_need_activation = textfields_activation_option;#endif		FREE(LYRequestReferer);		/*		 *  Don't send Referer if we have to load a document again		 *  that we got from the history stack.  We don't know		 *  any more how we originally got to that page.  Using		 *  a Referer based on the current HTMainText could only		 *  be right by coincidence. - kw 1999-11-01		 */		if (popped_doc)		    LYNoRefererForThis = TRUE;#ifndef DONT_TRACK_INTERNAL_LINKS		if (try_internal) {		    if (newdoc.address &&			isLYNXIMGMAP(newdoc.address)) {			try_internal = FALSE;		    } else if (curdoc.address &&			isLYNXIMGMAP(curdoc.address)) {			try_internal = FALSE;		    }		}		if (try_internal) {		    char *hashp = findPoundSelector(newdoc.address);		    if (hashp) {			HTFindPoundSelector(hashp+1);		    }		    getresult = (HTMainText != NULL) ? NORMAL : NOT_FOUND;		    try_internal = FALSE; /* done */		    /* fix up newdoc.address which may have been fragment-only */		    if (getresult == NORMAL && (!hashp || hashp == newdoc.address)) {			if (!hashp) {			    set_address(&newdoc, HTLoadedDocumentURL());			} else {			    StrAllocCopy(temp, HTLoadedDocumentURL());			    StrAllocCat(temp, hashp); /* append fragment */			    set_address(&newdoc, temp);			    FREE(temp);			}		    }		} else {		    if (newdoc.internal_link && newdoc.address &&			*newdoc.address == '#' && nhist > 0) {			char *cp0;			if (isLYNXIMGMAP(HDOC(nhist-1).address))			    cp0 = HDOC(nhist-1).address + LEN_LYNXIMGMAP;			else			    cp0 = HDOC(nhist-1).address;			StrAllocCopy(temp, cp0);			(void) trimPoundSelector(temp);			StrAllocCat(temp, newdoc.address);			free_address(&newdoc);			newdoc.address = temp;			temp = NULL;		    }		    getresult = getfile(&newdoc);		}#else  /* TRACK_INTERNAL_LINKS */		getresult = getfile(&newdoc);#endif /* TRACK_INTERNAL_LINKS */#ifdef INACTIVE_INPUT_STYLE_VH		textinput_redrawn = FALSE; /* for sure */#endif		switch(getresult) {		case NOT_FOUND:		    /*		     *	OK! can't find the file, so it must not be around now.		     *	Do any error logging, if appropriate.		     */		    LYoverride_no_cache = FALSE; /* Was TRUE if popped. - FM */		    LYinternal_flag = FALSE;	 /* Reset to default. - kw */		    turn_trace_back_on(&trace_mode_flag);		    if (!first_file && !LYCancelledFetch) {			/*			 *  Do error mail sending and/or traversal			 *  stuff.  Note that the links[] elements may			 *  not be valid at this point, if we did call			 *  HTuncache_current_document!   This should			 *  not have happened for traversal, but for			 *  sending error mail check that HTMainText			 *  exists for this reason. - kw			 */			if (error_logging && nhist > 0 && !popped_doc &&			    !LYUserSpecifiedURL &&			    HTMainText &&			    nlinks > 0 && curdoc.link < nlinks &&			    !isLYNXHIST(NonNull(newdoc.address)) &&			    !isLYNXCOOKIE(NonNull(newdoc.address))) {			    char *mail_owner = NULL;			    if (owner_address && isMAILTO_URL(owner_address)) {				mail_owner = owner_address + LEN_MAILTO_URL;			    }			    /*			     *  Email a bad link message to the owner of			     *  the document, or to ALERTMAIL if defined,			     *  but NOT to lynx-dev (it is rejected in			     *  mailmsg). - FM, kw			     */#ifndef ALERTMAIL			    if (mail_owner)#endif				mailmsg(curdoc.link,					mail_owner,					HDOC(nhist-1).address,					HDOC(nhist-1).title);			}			if (traversal) {			    FILE *ofp;			    if ((ofp = LYAppendToTxtFile(TRAVERSE_ERRORS)) == NULL) {				if ((ofp = LYNewTxtFile(TRAVERSE_ERRORS)) == NULL) {				    perror(NOOPEN_TRAV_ERR_FILE);				    exit_immediately(EXIT_FAILURE);				}			    }			    if (nhist > 0) {				fprintf(ofp,					"%s %s\tin %s\n",					popped_doc ?					newdoc.address : links[curdoc.link].lname,					links[curdoc.link].target,					HDOC(nhist-1).address);			    } else {				fprintf(ofp,					"%s %s\t\n",					popped_doc ?					newdoc.address : links[curdoc.link].lname,					links[curdoc.link].target);			    }			    LYCloseOutput(ofp);			}		    }		    /*		     *	Fall through to do the NULL stuff and reload the		     *	old file, unless the first file wasn't found or		     *	has gone missing.		     */		    if (!nhist) {			/*			 *  If nhist = 0 then it must be the first file.			 */			exit_immediately_with_error_message(NOT_FOUND, first_file);			return(EXIT_FAILURE);		    }		    /* FALLTHRU */		case NULLFILE:		    /*		     *	Not supposed to return any file.		     */		    LYoverride_no_cache = FALSE; /* Was TRUE if popped. - FM */		    popped_doc = FALSE;		 /* Was TRUE if popped. - FM */		    LYinternal_flag = FALSE;	 /* Reset to default. - kw */		    turn_trace_back_on(&trace_mode_flag);		    free_address(&newdoc); /* to pop last doc */		    FREE(newdoc.bookmark);		    LYJumpFileURL = FALSE;		    reloading = FALSE;		    LYPermitURL = FALSE;		    LYCancelledFetch = FALSE;		    ForcePush = FALSE;		    LYforce_HTML_mode = FALSE;		    force_old_UCLYhndl_on_reload = FALSE;		    if (traversal) {			crawl_ok = FALSE;			if (traversal_link_to_add) {			    /*			     *	It's a binary file, or the fetch attempt			     *	failed.  Add it to TRAVERSE_REJECT_FILE			     *	so we don't try again in this run.			     */			    if (!lookup_reject(traversal_link_to_add)) {				add_to_reject_list(traversal_link_to_add);			    }			    FREE(traversal_link_to_add);			}		    }		    /*		     *  Make sure the first file was found and		     *  has not gone missing.		     */		    if (!nhist) {			/*			 *  If nhist = 0 then it must be the first file.			 */			if (first_file && homepage &&			   !LYSameFilename(homepage, startfile)) {			   /*			    *  Couldn't return to the first file but there is a			    *  homepage we can use instead. Useful for when the			    *  first URL causes a program to be invoked. - GL			    *			    *  But first make sure homepage is different from			    *  startfile (above), then make it the same (below)			    *  so we don't enter an infinite getfile() loop on			    *  on failures to find the files. - FM			    */			   set_address(&newdoc, homepage);			   LYFreePostData(&newdoc);			   FREE(newdoc.bookmark);			   StrAllocCopy(startfile, homepage);			   newdoc.isHEAD = FALSE;			   newdoc.safe = FALSE;			   newdoc.internal_link = FALSE;			   goto try_again;			} else {			   exit_immediately_with_error_message(NULLFILE, first_file);			   return(EXIT_FAILURE);			}		    }		   /*		    *  If we're going to pop from history because		    *  getfile didn't succeed, reset LYforce_no_cache		    *  first.  This would have been done in HTAccess.c		    *  if the request got that far, but the URL may		    *  have been handled or rejected in getfile without		    *  taking care of that. - kw		    */		    LYforce_no_cache = FALSE;		   /*		    *  Retrieval of a newdoc just failed, and just		    *  going to try_again would pop the next doc		    *  from history and try to get it without further		    *  questions.  This may not be the right thing to do if		    *  we have POST data, so fake a PREV_DOC key if it seems		    *  that some prompting should be done.  This doesn't		    *  affect the traversal logic, since with traversal		    *  POST data can never occur. - kw		    */		   if (HDOC(nhist - 1).post_data &&		       !HDOC(nhist - 1).safe) {		       if (HText_POSTReplyLoaded((DocInfo *)&history[(nhist - 1)])) {			   override_LYresubmit_posts = TRUE;			   goto try_again;		       }		       /*  Set newdoc fields, just in case the PREV_DOC			*  gets cancelled. - kw */		       if (!curdoc.address) {			   set_address(&newdoc, HTLoadedDocumentURL());			   StrAllocCopy(newdoc.title, HTLoadedDocumentTitle());			   if (HTMainAnchor			    && HTMainAnchor->post_data) {			       BStrCopy(newdoc.post_data,					HTMainAnchor->post_data);			       StrAllocCopy(newdoc.post_content_type,					    HTMainAnchor->post_content_type);			   } else {			       BStrFree(newdoc.post_data);			   }			   newdoc.isHEAD = HTLoadedDocumentIsHEAD();			   newdoc.safe = HTLoadedDocumentIsSafe();			   newdoc.internal_link = FALSE;		       } else {			   copy_address(&newdoc, &curdoc);			   StrAllocCopy(newdoc.title, curdoc.title);			   BStrCopy(newdoc.post_data, curdoc.post_data);			   StrAllocCopy(newdoc.post_content_type,					curdoc.post_content_type);			   newdoc.isHEAD = curdoc.isHEAD;			   newdoc.safe = curdoc.safe;			   newdoc.internal_link = curdoc.internal_link;			   newdoc.line = curdoc.line;			   newdoc.link = curdoc.link;		       }		       cmd = LYK_PREV_DOC;		       goto new_cmd;		    }		    override_LYresubmit_posts = TRUE;		    goto try_again;		case NORMAL:		    /*		     *	Marvelously, we got the document!		     */		    LYoverride_no_cache = FALSE; /* Was TRUE if popped. - FM */		    LYinternal_flag = FALSE;	 /* Reset to default. - kw */		    turn_trace_back_on(&trace_mode_flag);		    /*		     *	If it's the first file and we're interactive,		     *	check whether it's a bookmark file which was		     *	not accessed via the -book switch. - FM		     */		    if (((first_file == TRUE) &&			 (dump_output_immediately == FALSE) &&			 !(newdoc.bookmark && *newdoc.bookmark)) &&			((LYisLocalFile(newdoc.address) == TRUE) &&			 !(strcmp(NonNull(HText_getTitle()),				  BOOKMARK_TITLE))) &&			(temp = HTParse(newdoc.address, "",				     PARSE_PATH+PARSE_PUNCTUATION)) != NULL) {			CONST char *name = wwwName(Home_Dir());			len = strlen(name);#ifdef VMS			if (!strncasecomp(temp, name, len) &&			    strlen(temp) > len)#else			if (!strncmp(temp, name, len) &&			    strlen(temp) > len)#endif /* VMS */			{			    /*			     *	We're interactive and this might be a			     *	bookmark file entered as a startfile			     *	rather than invoked via -book.	Check			     *	if it's in our bookmark file list, and			     *	if so, reload if with the relevant			     *	bookmark elements set. - FM			     */			    cp = NULL;			    if (temp[len] == '/') {				if (strchr(&temp[(len + 1)], '/')) {				    HTSprintf0(&cp, ".%s", &temp[len]);				} else {				    StrAllocCopy(cp, &temp[(len + 1)]);				}			    } else {				StrAllocCopy(cp, &temp[len]);			    }			    for (i = 0; i <= MBM_V_MAXFILES; i++) {				if (MBM_A_subbookmark[i] &&				    LYSameFilename(cp, MBM_A_subbookmark[i])) {				    StrAllocCopy(BookmarkPage,						 MBM_A_subbookmark[i]);				    break;				}			    }			    FREE(cp);			    if (i <= MBM_V_MAXFILES) {				FREE(temp);				if (LYValidate) {				    HTAlert(BOOKMARKS_DISABLED);				    return(EXIT_FAILURE);				}				if ((temp = HTParse(newdoc.address, "",				 PARSE_ACCESS+PARSE_HOST+PARSE_PUNCTUATION))) {				    set_address(&newdoc, temp);				    HTuncache_current_document();				    free_address(&curdoc);				    StrAllocCat(newdoc.address,					    wwwName(Home_Dir()));				    StrAllocCat(newdoc.address, "/");				    StrAllocCat(newdoc.address,					(strncmp(BookmarkPage, "./", 2) ?							   BookmarkPage :							(BookmarkPage + 2)));				    StrAllocCopy(newdoc.title, BOOKMARK_TITLE);				    StrAllocCopy(newdoc.bookmark, BookmarkPage);#ifdef USE_COLOR_STYLE				    if (curdoc.style)					StrAllocCopy(newdoc.style, curdoc.style);#endif				    StrAllocCopy(startrealm, newdoc.address);				    LYFreePostData(&newdoc);				    newdoc.isHEAD = FALSE;				    newdoc.safe = FALSE;				    FREE(temp);				    if (!strcmp(homepage, startfile))					StrAllocCopy(homepage, newdoc.address);				    StrAllocCopy(startfile, newdoc.address);				    CTRACE((tfp, "Reloading as bookmarks=%s\n",						newdoc.address));				    goto try_again;				}			    }			}			cp = NULL;		    }		    FREE(temp);		    if (traversal) {			/*			 *  During traversal build up lists of all links			 *  traversed.	Traversal mode is a special			 *  feature for traversing http links in the web.			 */			if (traversal_link_to_add) {			    /*			     *	Add the address we sought to TRAVERSE_FILE.			     */			    if (!lookup(traversal_link_to_add))				add_to_table(traversal_link_to_add);			    FREE(traversal_link_to_add);			}			if (curdoc.address && curdoc.title &&			    !isLYNXIMGMAP(curdoc.address))			    /*			     *	Add the address we got to TRAVERSE_FOUND_FILE.			     */			    add_to_traverse_list(curdoc.address, curdoc.title);		    }		    /*		     *	If this was a LYNXDOWNLOAD, we still have curdoc,		     *	not a newdoc, so reset the address, title and		     *	positioning elements. - FM		     */		    if (newdoc.address && curdoc.address &&			isLYNXDOWNLOAD(newdoc.address)) {			copy_address(&newdoc, &curdoc);			StrAllocCopy(newdoc.title, (curdoc.title ?						    curdoc.title : ""));			StrAllocCopy(newdoc.bookmark, curdoc.bookmark);			newdoc.line = curdoc.line;			newdoc.link = curdoc.link;			newdoc.internal_link = FALSE; /* can't be true. - kw */		    }		    /*		     *	Set Newline to the saved line.	It contains the		     *	line the user was on if s/he has been in the file		     *	before, or it is 1 if this is a new file.		     *		     * We already set Newline before getfile() and probably		     * update it explicitly if popping from the history stack		     * via LYpop() or LYpop_num() within getfile() cycle.		     *		     * In partial mode, Newline was probably updated in		     * LYMainLoop_pageDisplay() if user scrolled		     * the document while loading.		     * Incremental loading stage already closed in HT*Copy().		     */#ifdef DISP_PARTIAL		    /* Newline = newdoc.line; */		    display_partial = FALSE; /* for sure, LYNXfoo:/ may be a problem */#else		    /* Should not be needed either if we remove		     * "DISP_PARTIAL" from LYHistory.c, but lets leave it		     * as an important comment for now.		     */		    Newline = newdoc.line;#endif		    /*		     *	If we are going to a target line or		     *	the first page of a popped document,		     *	override any www_search line result.		     */		    if (Newline > 1 || popped_doc == TRUE)			 www_search_result = -1;		    /*		     *	Make sure curdoc.line will not be equal		     *	to Newline, so we get a redraw.		     */		    curdoc.line = -1;		    break;		}  /* end switch */	    if (TRACE) {		if (!LYTraceLogFP || trace_mode_flag) {		    LYSleepAlert(); /* allow me to look at the results */		}	    }	    /*	     *	Set the files the same.	     */	    copy_address(&curdoc, &newdoc);	    BStrCopy(curdoc.post_data, newdoc.post_data);	    StrAllocCopy(curdoc.post_content_type, newdoc.post_content_type);	    StrAllocCopy(curdoc.bookmark, newdoc.bookmark);#ifdef USE_COLOR_STYLE	    StrAllocCopy(curdoc.style, HText_getStyle());	    if (curdoc.style != NULL)		style_readFromFile (curdoc.style);#endif	    curdoc.isHEAD = newdoc.isHEAD;	    curdoc.internal_link = newdoc.internal_link;	    /*	     *	Set the remaining document elements and add to	     *	the visited links list. - FM	     */	    if (ownerS_address != NULL) {#ifndef USE_PRETTYSRC		if (HTOutputFormat == WWW_SOURCE && !HText_getOwner())#else		if ( (LYpsrc ? psrc_view : HTOutputFormat == WWW_SOURCE)			&& !HText_getOwner() )#endif		    HText_setMainTextOwner(ownerS_address);		FREE(ownerS_address);	    }	    if (HText_getTitle()) {		StrAllocCopy(curdoc.title, HText_getTitle());	    } else if (!dump_output_immediately) {		StrAllocCopy(curdoc.title, newdoc.title);	    }	    StrAllocCopy(owner_address, HText_getOwner());	    curdoc.safe = HTLoadedDocumentIsSafe();	    if (!dump_output_immediately) {		LYAddVisitedLink(&curdoc);	    }	   /*	    *  Reset WWW present mode so that if we were getting	    *  the source, we get rendered HTML from now on.	    */	   HTOutputFormat = WWW_PRESENT;#ifdef USE_PRETTYSRC	   psrc_view = FALSE;#endif	   HTMLSetCharacterHandling(current_char_set);	/* restore, for sure? */	   /*	    *  Reset all of the other relevant flags. - FM	    */	   LYUserSpecifiedURL = FALSE;	/* only set for goto's and jumps's */	   LYJumpFileURL = FALSE;	/* only set for jump's */	   LYNoRefererForThis = FALSE;	/* always reset on return here */	   reloading = FALSE;		/* set for RELOAD and NOCACHE keys */	   HEAD_request = FALSE;	/* only set for HEAD requests */	   LYPermitURL = FALSE;		/* only for LYValidate or check_realm */	   ForcePush = FALSE;		/* only set for some PRINT requests. */	   LYforce_HTML_mode = FALSE;	   force_old_UCLYhndl_on_reload = FALSE;	   popped_doc = FALSE;	   pending_form_c = -1;	} /* end if (LYforce_no_cache || force_load || are_different(...)) */	if (dump_output_immediately) {	    if (crawl) {		print_crawl_to_fd(stdout, curdoc.address, curdoc.title);	    } else {		print_wwwfile_to_fd(stdout, FALSE);	    }	    return(EXIT_SUCCESS);	}	/*	 *  If the recent_sizechange variable is set to TRUE	 *  then the window size changed recently.	 */	if (recent_sizechange) {	    /*	     *  First we need to make sure the display library - curses, slang,	     *  whatever - gets notified about the change, and gets a chance	     *  to update external structures appropriately.  Hopefully the	     *  stop_curses()/start_curses() sequence achieves this, at least	     *  if the display library has a way to get the new screen size	     *  from the OS.	     *  However, at least for ncurses, the update of the internal	     *  structures will come still too late - the changed screen	     *  size is detected in doupdate(), which would only be called	     *  (indirectly through the HText_pageDisplay below) after the	     *  WINDOW structures are already filled based on the old size.	     *  So we notify the ncurses library directly here. - kw	     */#if defined(NCURSES) && defined(HAVE_RESIZETERM) && defined(HAVE_WRESIZE)	    resizeterm(LYlines, LYcols);	    wresize(LYwin, LYlines, LYcols);#else#if 0 /* defined(PDCURSES) && defined(HAVE_XCURSES) */	    resize_term(LYlines, LYcols);	    if (LYwin != 0)		LYwin = resize_window(LYwin, LYlines, LYcols);	    refresh();#else	    stop_curses();	    start_curses();	    LYclear();#endif#endif	    refresh_screen = TRUE; /* to force a redraw */	    if (HTMainText)	/* to REALLY force it... - kw */		HText_setStale(HTMainText);	    recent_sizechange = FALSE;	    if (user_mode == NOVICE_MODE) {		display_lines = LYlines-4;	    } else {		display_lines = LYlines-2;	    }	}	if (www_search_result != -1) {	     /*	      *  This was a WWW search, set the line	      *  to the result of the search.	      */	     Newline = www_search_result;	     www_search_result = -1;  /* reset */	}	if (first_file == TRUE) {	    /*	     *	We can never again have the first file.	     */	    first_file = FALSE;	    /*	     *	Set the startrealm, and deal as best we can	     *	with preserving forced HTML mode for a local	     *	startfile. - FM	     */	    temp = HTParse(curdoc.address, "",			   PARSE_ACCESS+PARSE_HOST+PARSE_PUNCTUATION);	    if (!temp || *temp == '\0') {		StrAllocCopy(startrealm, NO_NOTHING);	    } else {		StrAllocCopy(startrealm, temp);		FREE(temp);		if (!(temp = HTParse(curdoc.address, "",				     PARSE_PATH+PARSE_PUNCTUATION))) {		    LYAddHtmlSep(&startrealm);		} else {		    if (forced_HTML_mode &&			!dump_output_immediately &&			!curdoc.bookmark &&			isFILE_URL(curdoc.address) &&			strlen(temp) > 1) {			/*			 *  We forced HTML for a local startfile which			 *  is not a bookmark file and has a path of at			 *  least two letters.	If it doesn't have a			 *  suffix mapped to text/html, we'll set the			 *  entire path (including the lead slash) as a			 *  "suffix" mapped to text/html to ensure it is			 *  always treated as an HTML source file.  We			 *  are counting on a tail match to this full path			 *  for some other URL fetched during the session			 *  having too low a probability to worry about,			 *  but it could happen. - FM			 */			HTAtom *encoding;			if (HTFileFormat(temp, &encoding, NULL) != WWW_HTML) {			    HTSetSuffix(temp, "text/html", "8bit", 1.0);			}		    }		    if ((cp = strrchr(temp, '/')) != NULL) {			*(cp+1) = '\0';			StrAllocCat(startrealm, temp);		    }		}	    }	    FREE(temp);	    CTRACE((tfp, "Starting realm is '%s'\n\n", startrealm));	    if (traversal) {		/*		 *  Set up the crawl output stuff.		 */		if (curdoc.address && !lookup(curdoc.address)) {		    if (!isLYNXIMGMAP(curdoc.address))			crawl_ok = TRUE;		    add_to_table(curdoc.address);		}		/*		 *  Set up the traversal_host comparison string.		 */		if (strncmp((curdoc.address ? curdoc.address : "NULL"),			    "http", 4)) {		    StrAllocCopy(traversal_host, NO_NOTHING);		} else if (check_realm) {		    StrAllocCopy(traversal_host, startrealm);		} else {		    temp = HTParse(curdoc.address, "",				   PARSE_ACCESS+PARSE_HOST+PARSE_PUNCTUATION);		    if (!temp || *temp == '\0') {			StrAllocCopy(traversal_host, NO_NOTHING);		    } else {			StrAllocCopy(traversal_host, temp);			LYAddHtmlSep(&traversal_host);		    }		    FREE(temp);		}		CTRACE((tfp, "Traversal host is '%s'\n\n", traversal_host));	    }	    if (startfile) {		/*		 *  If homepage was not equated to startfile,		 *  make the homepage URL the first goto		 *  entry. - FM		 */		if (homepage && strcmp(startfile, homepage))		    HTAddGotoURL(homepage);		/*		 *  If we are not starting up with startfile		 *  (e.g., had -book), or if we are using the		 *  startfile and it has no POST content, make		 *  the startfile URL a goto entry. - FM		 */		if (strcmp(startfile, newdoc.address) ||		    newdoc.post_data == NULL)		    HTAddGotoURL(startfile);	    }	    if (TRACE) {		refresh_screen = TRUE;		if (!LYTraceLogFP || trace_mode_flag) {		    LYSleepAlert();		}	    }	}#ifdef USE_SOURCE_CACHE	/*	 * If the parse settings have changed since this HText was	 * generated, we need to reparse and redraw it.  -dsb	 *	 * Should be configured to avoid shock for experienced lynx users.	 * Currently enabled for cached sources only.	 */	if (HTdocument_settings_changed()) {	   if (HTcan_reparse_document()) {		HTInfoMsg(gettext("Reparsing document under current settings..."));		reparse_document();	   } else {		/*		 * Urk.  I have no idea how to recover from a failure here.		 * At a guess, I'll try reloading.  -dsb		 */			/*  currently disabled ***		HTUserMsg(gettext("Reparsing document under current settings..."));		cmd = LYK_RELOAD;		goto new_cmd;			*/	    }	}	if (from_source_cache) {	    from_source_cache = FALSE; /* reset */	    curdoc.line = -1 ;  /* so curdoc.line != Newline, see below */	}#endif	/*	 *  If the curdoc.line is different than Newline then there must	 *  have been a change since last update.  Run HText_pageDisplay()	 *  create a fresh screen of text out.	 *	 *  If we got new HTMainText go this way.	 *  All display_partial calls ends here for final redraw.	 */	if (curdoc.line != Newline) {#ifdef INACTIVE_INPUT_STYLE_VH	    textinput_redrawn = FALSE;#endif	    refresh_screen = FALSE;	    HText_pageDisplay(Newline, prev_target);#ifdef DIRED_SUPPORT	    if (lynx_edit_mode && nlinks > 0 && !HTList_isEmpty(tagged))	      showtags(tagged);#endif /* DIRED_SUPPORT */	    /*	     *  If more equals TRUE, then there is more info below this page.	     */	    more = HText_canScrollDown();	    curdoc.line = Newline = HText_getTopOfScreen()+1;	    if (curdoc.title == NULL) {		/*		 *  If we don't yet have a title, try to get it,		 *  or set to that for newdoc.title. - FM		 */		if (HText_getTitle()) {		    StrAllocCopy(curdoc.title, HText_getTitle());		} else {		    StrAllocCopy(curdoc.title, newdoc.title);		}	    }	    /*	     *	If the request is to highlight a link which is counted	     *  from the start of document, correct the link number:	     */	    if (newdoc_link_is_absolute) {		newdoc_link_is_absolute = FALSE;		if (curdoc.line > 1)		    newdoc.link -= HText_LinksInLines(HTMainText, 1,						      curdoc.line - 1);	    }	    if (arrowup) {		/*		 *  arrowup is set if we just came up from		 *  a page below.		 */		curdoc.link = nlinks - 1;		arrowup = FALSE;	    } else {		curdoc.link = newdoc.link;		if (curdoc.link >= nlinks) {		    curdoc.link = nlinks - 1;		} else if (curdoc.link < 0 && nlinks > 0) {		    /*		     *	We may have popped a doc (possibly in local_dired)		     *	which didn't have any links when it was pushed, but		     *	does have links now (e.g., a file was created).		     *  Code below assumes that curdoc.link is valid and		     *  that (curdoc.link==-1) only occurs if (nlinks==0)		     *  is true. - KW		     */		    curdoc.link = 0;		}	    }	    show_help = FALSE; /* reset */	    newdoc.line = 1;	    newdoc.link = 0;	    curdoc.line = Newline; /* set */	}	/*	 *  Refresh the screen if necessary.	 */	if (refresh_screen) {#if defined(FANCY_CURSES) || defined (USE_SLANG)	    if (enable_scrollback) {		LYclear();	    } else {		LYerase();	    }#else	    LYclear();#endif /* FANCY_CURSES || USE_SLANG */	   HText_pageDisplay(Newline, prev_target);#ifdef DIRED_SUPPORT	    if (lynx_edit_mode && nlinks > 0 && !HTList_isEmpty(tagged))		showtags(tagged);#endif /* DIRED_SUPPORT */	    /*	     *  If more equals TRUE, then there is more info below this page.	     */	    more = HText_canScrollDown();	    /*	     *  Adjust curdoc.link as above; nlinks may have changed,	     *  if the refresh_screen flag was set as a result of	     *  a size change.	     *  Code below assumes that curdoc.link is valid and	     *  that (curdoc.link==-1) only occurs if (nlinks==0)	     *  is true. - kw	     */	    if (curdoc.link >= nlinks) {		curdoc.link = nlinks - 1;	    } else if (curdoc.link < 0 && nlinks > 0) {		curdoc.link = 0;	    }	    if (user_mode == NOVICE_MODE)		noviceline(more);  /* print help message */	    refresh_screen = FALSE;	}	curlink_is_editable =	    (nlinks > 0 &&	     links[curdoc.link].type == WWW_FORM_LINK_TYPE &&	     F_TEXTLIKE(links[curdoc.link].l_form->type));	use_last_tfpos = (curlink_is_editable &&			  (real_cmd == LYK_LPOS_PREV_LINK ||			   real_cmd == LYK_LPOS_NEXT_LINK));#ifdef TEXTFIELDS_MAY_NEED_ACTIVATION	if (!textfields_need_activation)	    textinput_activated = TRUE;#endif#if defined(WIN_EX)			/* 1997/10/08 (Wed) 14:52:06 */	if (nlinks > 0) {	    char *p = "LYNX (unknown link type)";	    /* Show the URL & kanji code . */	    if (strlen(links[curdoc.link].lname) == 0) {	       if (links[curdoc.link].type == WWW_FORM_LINK_TYPE) {		    switch(links[curdoc.link].l_form->type) {		    case F_TEXT_SUBMIT_TYPE:		    case F_SUBMIT_TYPE:		    case F_IMAGE_SUBMIT_TYPE:			p = "[SUBMIT]";			break;		    case F_PASSWORD_TYPE:			p = "Password";			break;		    case F_OPTION_LIST_TYPE:			p = "Option list";			break;		    case F_CHECKBOX_TYPE:			p = "Check box";			break;		    case F_RADIO_TYPE:			p = "[Radio]";			break;		    case F_RESET_TYPE:			p = "[Reset]";			break;		    case F_TEXT_TYPE:			p = "Text input";			break;		    case F_TEXTAREA_TYPE:			p = "Text input lines";			break;		    default:			break;		    }		    set_ws_title(p);	       }	    } else {		if (user_mode == ADVANCED_MODE) {		    p = curdoc.title;		} else {		    p = links[curdoc.link].lname;		}		if (strlen(p) < 500) {		    strcpy(temp_buff, p);		    if (strchr(temp_buff, '%')) {			HTUnEscape(temp_buff);		    }		    str_sjis(sjis_buff, temp_buff);		    set_ws_title(LYElideString(sjis_buff, 10));		}	    }	} else {	    if (strlen(curdoc.address) < sizeof(temp_buff)-1) {		if (user_mode == ADVANCED_MODE) {		    str_sjis(temp_buff, curdoc.title);		} else {		    strcpy(temp_buff, curdoc.address);		}		set_ws_title(HTUnEscape(temp_buff));	    }	}#endif /* WIN_EX */	/*	 *  Report unread or new mail, if appropriate.	 */	if (check_mail && !no_mail)	    LYCheckMail();	/*	 *  If help is not on the screen,	 *  then put a message on the screen	 *  to tell the user other misc info.	 */	if (!show_help) {	   show_main_statusline(links[curdoc.link],				(curlink_is_editable && textinput_activated) ?				FOR_INPUT : FOR_PANEL);	} else {	   show_help = FALSE;	}	if (nlinks > 0) {	     /*	      *  Highlight current link, unless it is an active	      *  text input field.	      */	    if (!curlink_is_editable) {		LYhighlight(ON, curdoc.link, prev_target);#ifndef INACTIVE_INPUT_STYLE_VH	    } else if (!textinput_activated) {		LYhighlight(ON, curdoc.link, prev_target);#endif	    }	}	if (traversal) {	    /*	     *	Don't go interactively into forms,	     *	or accept keystrokes from the user	     */	    if (crawl && crawl_ok) {		crawl_ok = FALSE;#ifdef FNAMES_8_3		sprintf(cfile,"lnk%05d.dat",ccount);#else		sprintf(cfile,"lnk%08d.dat",ccount);#endif /* FNAMES_8_3 */		ccount = ccount + 1;		if ((cfp = LYNewTxtFile(cfile))  != NULL) {		    print_crawl_to_fd(cfp,curdoc.address,curdoc.title);		    LYCloseOutput(cfp);		} else {		    if (!dump_output_immediately)			cleanup();#ifdef UNIX		    if (dump_output_immediately)			fprintf(stderr,			gettext("Fatal error - could not open output file %s\n"),cfile);		    else#endif			printf(			gettext("Fatal error - could not open output file %s\n"),cfile);		    if (!dump_output_immediately) {			exit_immediately(EXIT_FAILURE);		    }		    return(EXIT_FAILURE);		}	    }	} else {	    /*	     *	Normal, non-traversal handling.	     */	    if (curlink_is_editable &&		(textinput_activated || pending_form_c != -1)) {		if (pending_form_c != -1) {		    real_c = pending_form_c;		    pending_form_c = -1;		} else {		    /*		     *  Replace novice lines if in NOVICE_MODE.		     */		    if (user_mode==NOVICE_MODE) {			form_noviceline(links[curdoc.link].l_form->disabled);		    }		    real_c = change_form_link(curdoc.link,				     &newdoc, &refresh_screen,				     use_last_tfpos, FALSE);		}#ifdef TEXTFIELDS_MAY_NEED_ACTIVATION		if (textfields_need_activation)		    textinput_activated = FALSE;#ifdef INACTIVE_INPUT_STYLE_VH		textinput_redrawn = FALSE;#endif#endif		c = (real_c==LKC_DONE) ? DO_NOTHING : LKC_TO_C(real_c);		if (c != DO_NOTHING &&		    peek_mouse_link() != -1 && peek_mouse_link() != -2)		    old_c = 0;		if (peek_mouse_link() >= 0 &&		    LKC_TO_LAC(keymap,real_c) != LYK_CHANGE_LINK) {		    do_change_link();		    if ((c == '\n' || c == '\r') &&			links[curdoc.link].type == WWW_FORM_LINK_TYPE &&			F_TEXTLIKE(links[curdoc.link].l_form->type) &&			!textfields_need_activation) {			c = DO_NOTHING;		    }#ifdef TEXTFIELDS_MAY_NEED_ACTIVATION		} else if ((links[curdoc.link].type == WWW_FORM_LINK_TYPE &&			    links[curdoc.link].l_form->type == F_TEXTAREA_TYPE)			   && textfields_need_activation			   && !links[curdoc.link].l_form->disabled			   && peek_mouse_link() < 0 &&			   (((LKC_TO_LAC(keymap,real_c) == LYK_NEXT_LINK ||#ifdef TEXTAREA_AUTOGROW			      LKC_TO_LAC(keymap,real_c) == LYK_ACTIVATE ||#endif			      LKC_TO_LAC(keymap,real_c) == LYK_LPOS_NEXT_LINK ||			      LKC_TO_LAC(keymap,real_c) == LYK_DOWN_LINK) &&			     ((curdoc.link < nlinks-1 &&			       links[curdoc.link+1].type == WWW_FORM_LINK_TYPE  &&			       links[curdoc.link+1].l_form->type == F_TEXTAREA_TYPE			       && (links[curdoc.link].l_form->number ==				   links[curdoc.link+1].l_form->number) &&			       strcmp(links[curdoc.link].l_form->name,				      links[curdoc.link+1].l_form->name) == 0) ||			      (curdoc.link == nlinks-1 && more &&			       HText_TAHasMoreLines(curdoc.link, 1)))) ||			    ((LKC_TO_LAC(keymap,real_c) == LYK_PREV_LINK ||			      LKC_TO_LAC(keymap,real_c) == LYK_LPOS_PREV_LINK ||			      LKC_TO_LAC(keymap,real_c) == LYK_UP_LINK) &&			     ((curdoc.link > 0 &&			       links[curdoc.link-1].type == WWW_FORM_LINK_TYPE  &&			       links[curdoc.link-1].l_form->type == F_TEXTAREA_TYPE			       && (links[curdoc.link].l_form->number ==				   links[curdoc.link-1].l_form->number) &&			       strcmp(links[curdoc.link].l_form->name,				      links[curdoc.link-1].l_form->name) == 0) ||			      (curdoc.link == 0 && curdoc.line > 1 &&			       HText_TAHasMoreLines(curdoc.link, -1)))))) {		    textinput_activated = TRUE;#ifdef TEXTAREA_AUTOGROW		    if ((c == '\n' || c == '\r') &&			LKC_TO_LAC(keymap,real_c) == LYK_ACTIVATE)			c = LAC_TO_LKC0(LYK_NEXT_LINK);#endif /* TEXTAREA_AUTOGROW */#endif /* TEXTFIELDS_MAY_NEED_ACTIVATION */		} else		    switch (c) {		    case '\n':		    case '\r':#ifdef TEXTAREA_AUTOGROW		    /*		     *  If on the bottom line of a TEXTAREA, and the user hit		     *  the ENTER key, we add a new line/anchor automatically,		     *  positioning the cursor on it.		     *		     *  If at the bottom of the screen, we effectively perform		     *  an LYK_DOWN_HALF-like operation, then move down to the		     *  new line we just added.  --KED  02/14/99		     *		     *  [There is some redundancy and non-standard indentation		     *   in the monster-if() below.  This is intentional ... to		     *   try and improve the "readability" (such as it is).		     *   Caveat emptor to anyone trying to change it.]		     */		    if ((links[curdoc.link].type == WWW_FORM_LINK_TYPE &&			 links[curdoc.link].l_form->type == F_TEXTAREA_TYPE) &&			((curdoc.link == nlinks-1 &&			  !(more && HText_TAHasMoreLines(curdoc.link, 1)))			 ||			 ((curdoc.link <  nlinks-1) &&			  !(links[curdoc.link+1].type == WWW_FORM_LINK_TYPE  &&			    links[curdoc.link+1].l_form->type == F_TEXTAREA_TYPE))			 ||			 ((curdoc.link <  nlinks-1) &&			  ((links[curdoc.link+1].type == WWW_FORM_LINK_TYPE  &&			    links[curdoc.link+1].l_form->type == F_TEXTAREA_TYPE)			    &&			    ((links[curdoc.link].l_form->number	       !=				      links[curdoc.link+1].l_form->number) ||			     (strcmp (links[curdoc.link].l_form->name,				      links[curdoc.link+1].l_form->name) != 0)))))) {			HText_ExpandTextarea (&links[curdoc.link], 1);			if (links[curdoc.link].ly < display_lines) {			    refresh_screen = TRUE;			} else {			    Newline += (display_lines/2);			    if (nlinks > 0 && curdoc.link > -1 &&				links[curdoc.link].ly > display_lines/2) {				    newdoc.link = curdoc.link;				    for (i = 0; links[i].ly <= (display_lines/2); i++)					--newdoc.link;				    newdoc.link++;			    }			}#ifdef TEXTFIELDS_MAY_NEED_ACTIVATION			if (textfields_need_activation) {			    textinput_activated = TRUE;			    textfields_need_activation = textfields_activation_option;#ifdef INACTIVE_INPUT_STYLE_VH			    textinput_redrawn = TRUE;#endif			};#endif		   }#endif /* TEXTAREA_AUTOGROW */		    /*		     *	Make return in input field (if it was returned		     *  by change_form_link) act as LYK_NEXT_LINK,		     *  independent of what key (if any) is mapped to		     *  LYK_NEXT_LINK. - kw		     */		    c = LAC_TO_LKC0(LYK_NEXT_LINK);		    break;		default:		    if (old_c != c && old_c != real_c && c != real_c)			real_c = c;		}	    } else {#if defined(TEXTFIELDS_MAY_NEED_ACTIVATION) && defined(INACTIVE_INPUT_STYLE_VH)		if (curlink_is_editable && !textinput_redrawn) {		/*draw the text entry, but don't activate it*/		    textinput_redrawn = TRUE;		    change_form_link_ex(curdoc.link,				    &newdoc, &refresh_screen,				    use_last_tfpos, FALSE, TRUE);		    if (LYShowCursor) {			LYmove(links[curdoc.link].ly,			     ((links[curdoc.link].lx > 0) ?			      (links[curdoc.link].lx - 1) : 0));		    } else {			LYHideCursor();		    }		}#endif /* TEXTFIELDS_MAY_NEED_ACTIVATION && INACTIVE_INPUT_STYLE_VH */		/*		 *  Get a keystroke from the user.		 *  Save the last keystroke to avoid		 *  redundant error reporting.		 */		real_c = c = LYgetch(); /* get user input */		if (c != last_key)		    key_count = 0;		key_count++;		last_key = c;#ifndef VMS		if (c == 3) {		/* ^C */		    /*		     *	This shouldn't happen.	We'll try to		     *	deal with whatever bug caused it. - FM		     */		    signal(SIGINT, cleanup_sig);		    old_c = 0;		    cmd = LYK_QUIT;		    goto new_cmd;		}#endif /* !VMS */		if (LKC_HAS_ESC_MOD(c) && EditBinding(c) != LYE_FORM_PASS) {		    /*		     *  If ESC + <key> was read (and not recognized as a		     *  terminal escape sequence for another key), ignore		     *  the ESC modifier and act on <key> only if the line		     *  editor binding would have passed the same ESC-modified		     *  lynxkeycode back to us if it had been pressed in a		     *  text input field.  Otherwise set interesting part		     *  so that it will map to 0, to prevent that ESC + <key>		     *  acts like <key>, which might be unexpected. - kw		     */		    c = (c & ~LKC_MASK) | LAC_TO_LKC(0);		}		if (old_c != real_c) {		    old_c = 0;		}	    }	}#ifdef VMS	if (HadVMSInterrupt) {	    HadVMSInterrupt = FALSE;	    c = DO_NOTHING;	}#else	if (recent_sizechange) {	    if (c <= 0)		c = DO_NOTHING;	}#endif /* VMS */new_keyboard_input:	/*	 *  A goto point for new input without going	 *  back through the getch() loop.	 */	if (traversal) {	    if ((c = DoTraversal(c, &crawl_ok)) < 0)		return (EXIT_FAILURE);	} /* traversal */#ifdef WIN_EX	if (c == DO_NOTHING)	    cmd = LYK_DO_NOTHING;	else#endif	cmd = LKC_TO_LAC(keymap,c);  /* adds 1 to map EOF to 0 */#if defined(DIRED_SUPPORT) && defined(OK_OVERRIDE)	if (lynx_edit_mode && !no_dired_support && LKC_TO_LAC(key_override,c))	  cmd = LKC_TO_LAC(key_override,c);#endif /* DIRED_SUPPORT && OK_OVERRIDE */	real_cmd = cmd;new_cmd:  /*	   *  A goto point for new input without going	   *  back through the getch() loop.	   */	force_old_UCLYhndl_on_reload = FALSE;	CTRACE_FLUSH(tfp);	if (cmd != LYK_UP_LINK && cmd != LYK_DOWN_LINK)	    follow_col = -1;	switch(cmd) {	case -1:	    HTUserMsg(COMMAND_UNKNOWN);	    break;	case 0: /* unmapped character */	default:	    if (curdoc.link >= 0 && curdoc.link < nlinks &&		links[curdoc.link].type == WWW_FORM_LINK_TYPE &&		F_TEXTLIKE(links[curdoc.link].l_form->type)) {#ifdef TEXTFIELDS_MAY_NEED_ACTIVATION		if (textfields_need_activation) {		    show_main_statusline(links[curdoc.link], FOR_PANEL);#ifdef INACTIVE_INPUT_STYLE_VH		    textinput_redrawn = FALSE;#endif		} else#endif		    show_main_statusline(links[curdoc.link], FOR_INPUT);	    } else if (more) {		HTInfoMsg(MOREHELP);	    } else {		HTInfoMsg(HELP);	    }	    show_help = TRUE;	    if (TRACE) {		sprintf(cfile, "%d", c);		LYaddstr(cfile);	/* show the user input */		cfile[0] = '\0';	    }	    break;	case LYK_COMMAND:	    cmd = handle_LYK_COMMAND(user_input_buffer);	    goto new_cmd;	case LYK_INTERRUPT:	    /*	     *	No network transmission to interrupt - 'til we multithread.	     */	    break;	case LYK_F_LINK_NUM:	     c = '\0';	     /* FALLTHRU */	case LYK_1: /* FALLTHRU */	case LYK_2: /* FALLTHRU */	case LYK_3: /* FALLTHRU */	case LYK_4: /* FALLTHRU */	case LYK_5: /* FALLTHRU */	case LYK_6: /* FALLTHRU */	case LYK_7: /* FALLTHRU */	case LYK_8: /* FALLTHRU */	case LYK_9:	    handle_LYK_digit(c, &force_load, user_input_buffer,			     &old_c, real_c, &try_internal);	    break;	case LYK_SOURCE:  /* toggle view source mode */	    handle_LYK_SOURCE(&ownerS_address);	    break;	case LYK_CHG_CENTER:	/* ^Q */	    if (no_table_center) {		no_table_center = FALSE;		HTInfoMsg(gettext("TABLE center enable."));	    } else {		no_table_center = TRUE;		HTInfoMsg(gettext("TABLE center disable."));	    }	    /* FALLTHRU */	case LYK_RELOAD:  /* control-R to reload and refresh */	    handle_LYK_RELOAD(real_cmd);	    break;	case LYK_HISTORICAL:	/* toggle 'historical' comments parsing */	    handle_LYK_HISTORICAL();	    break;	case LYK_MINIMAL:	/* toggle 'minimal' comments parsing */	    handle_LYK_MINIMAL();	    break;	case LYK_SOFT_DQUOTES:	    handle_LYK_SOFT_DQUOTES();	    break;	case LYK_SWITCH_DTD:	    handle_LYK_SWITCH_DTD();	    break;	case LYK_QUIT:		/* quit */	    if (handle_LYK_QUIT())		return(EXIT_SUCCESS);	    break;	case LYK_ABORT:		/* don't ask the user about quitting */	    return(EXIT_SUCCESS);	case LYK_NEXT_PAGE:	/* next page */	    handle_LYK_NEXT_PAGE(&old_c, real_c);	    break;	case LYK_PREV_PAGE:	/* page up */	    handle_LYK_PREV_PAGE(&old_c, real_c);	    break;	case  LYK_UP_TWO:	    handle_LYK_UP_TWO(&arrowup, &old_c, real_c);	    break;	case  LYK_DOWN_TWO:	    handle_LYK_DOWN_TWO(&old_c, real_c);	    break;	case  LYK_UP_HALF:	    handle_LYK_UP_HALF(&arrowup, &old_c, real_c);	    break;	case  LYK_DOWN_HALF:	    handle_LYK_DOWN_HALF(&old_c, real_c);	    break;#ifdef CAN_CUT_AND_PASTE	case LYK_TO_CLIPBOARD:	/* ^S */	    {		char *s;		int ch2;		/* The logic resembles one of ADD_BOOKMARK */		if (nlinks > 0 && links[curdoc.link].lname		    && links[curdoc.link].type != WWW_FORM_LINK_TYPE) {		    /* Makes sense to copy a link */		    _statusline("Copy D)ocument's or L)ink's URL to clipboard or C)ancel?");		    ch2 = LYgetch_single();		    if (ch2 == 'D')			s = curdoc.address;		    else if (ch2 == 'C')			break;		    else			s = links[curdoc.link].lname;		} else		    s = curdoc.address;		if (isEmpty(s))		    HTInfoMsg(gettext("Current URL is empty."));		if (put_clip(s))		    HTInfoMsg(gettext("Copy to clipboard failed."));		else if (s == curdoc.address)		    HTInfoMsg(gettext("Document URL put to clipboard."));		else		    HTInfoMsg(gettext("Link URL put to clipboard."));	    }	    break;	case LYK_PASTE_URL:	    if (no_goto && !LYValidate) { /*  Go to not allowed. - FM */		HTUserMsg(GOTO_DISALLOWED);	    } else {		unsigned char *s = (unsigned char *) get_clip_grab(), *e, *t;		char *buf;		int len2;		if (!s)		    break;		len2 = strlen((const char *) s);		e = s + len2;		while (s < e && strchr(" \t\n\r", *s))		    s++;		while (s < e && strchr(" \t\n\r", e[-1]))		    e--;		if (s[0] == '<' && e > s && e[-1] == '>') {		    s++; e--;		    if (!strncasecomp((const char *) s,"URL:", 4))			s += 4;		}		if (s >= e) {		    HTInfoMsg(gettext("No URL in the clipboard."));		    break;		}		len = e - s + 1;		if (len < MAX_LINE)		    len = MAX_LINE;	/* Required for do_check_goto_URL() */		buf = (char*)malloc(len);		strncpy(buf, (const char *) s, e - s);		buf[e - s] = '\0';		t = (unsigned char *) buf;		while (s < e) {		    if (strchr(" \t\n\r", *s)) {			int nl2 = 0;	/* Keep whitespace without NL - file names! */			unsigned char *s1 = s;			while (strchr(" \t\n\r", *s)) {			    if (!nl2 && *s == '\n')				nl2 = 1;			    s++;			}			if (!nl2) {			    while (s1 < s) {				if (*s1 != '\r' && *s1 != '\r')				    *t = *s1;				t++, s1++;			    }			}		    } else			*t++ = *s++;		}		*t = '\0';		get_clip_release();		do_check_goto_URL(buf, &temp, &force_load);		free(buf);	    }	    break;#endif#ifdef KANJI_CODE_OVERRIDE	case LYK_CHG_KCODE:	/* ^L */	    if (LYRawMode && (HTCJK == JAPANESE)) {		switch(last_kcode) {		case NOKANJI:		    last_kcode = SJIS;		    break;		case SJIS:		    last_kcode = EUC;		    break;		case EUC:		    last_kcode = NOKANJI;		    break;		default:		    break;		}	    }	    LYmove(0, 0);	    lynx_start_title_color ();	    LYaddstr(str_kcode(last_kcode));	    lynx_stop_title_color ();	    break;#endif	case LYK_REFRESH:	    refresh_screen = TRUE;	    lynx_force_repaint();	    break;	case LYK_HOME:	    if (curdoc.line > 1)		Newline = 1;	    else {		cmd = LYK_PREV_PAGE;		goto new_cmd;	    }	    break;	case LYK_END:	    i = HText_getNumOfLines() - display_lines + 2;	    if (i >= 1 && Newline != i) {		Newline = i;		/* go to end of file */		arrowup = TRUE;		/* position on last link */	    } else {		cmd = LYK_NEXT_PAGE;		goto new_cmd;	    }	    break;	case LYK_FIRST_LINK:	    handle_LYK_FIRST_LINK();	    break;	case LYK_LAST_LINK:	    handle_LYK_LAST_LINK();	    break;	case LYK_PREV_LINK:	case LYK_LPOS_PREV_LINK:	    handle_LYK_PREV_LINK(&arrowup, &old_c, real_c);	    break;	case LYK_NEXT_LINK:	case LYK_LPOS_NEXT_LINK:	    handle_LYK_NEXT_LINK(c, &old_c, real_c);	    break;	case LYK_FASTFORW_LINK:	    handle_LYK_FASTFORW_LINK(&old_c, real_c);	    break;	case LYK_FASTBACKW_LINK:	    if (handle_LYK_FASTBACKW_LINK(&cmd, &old_c, real_c))		goto new_cmd;	    break;	case LYK_UP_LINK:	    handle_LYK_UP_LINK(&follow_col, &arrowup, &old_c, real_c);	    break;	case LYK_DOWN_LINK:	    handle_LYK_DOWN_LINK(&follow_col, &old_c, real_c);	    break;	case LYK_CHANGE_LINK:	    do_change_link();#if defined(TEXTFIELDS_MAY_NEED_ACTIVATION) && defined(INACTIVE_INPUT_STYLE_VH)	    if (textfields_need_activation)		textinput_redrawn = FALSE;#endif /* TEXTFIELDS_MAY_NEED_ACTIVATION && INACTIVE_INPUT_STYLE_VH */	    break;	case LYK_RIGHT_LINK:	    handle_LYK_RIGHT_LINK();	    break;	case LYK_LEFT_LINK:	    handle_LYK_LEFT_LINK();	    break;	case LYK_COOKIE_JAR:	/* show the cookie jar */	    if (handle_LYK_COOKIE_JAR(&cmd))		goto new_cmd;	    break;	case LYK_HISTORY:	/* show the history page */	    if (handle_LYK_HISTORY(ForcePush))		break;	    /* FALLTHRU */	case LYK_PREV_DOC:	/* back up a level */	    switch (handle_PREV_DOC(&cmd, &old_c, real_c)) {	    case 1:		return(EXIT_SUCCESS);	    case 2:		goto new_cmd;	    }	    break;	case LYK_NEXT_DOC:	/* undo back up a level */	    handle_NEXT_DOC();	    break;	case LYK_NOCACHE: /* Force submission of form or link with no-cache */	    if (!handle_LYK_NOCACHE(&old_c, real_c))		break;	    /* FALLTHRU */	case LYK_ACTIVATE:	/* follow a link */	case LYK_SUBMIT:	/* follow a link, submit TEXT_SUBMIT input */	    switch (handle_LYK_ACTIVATE(&c, cmd, &try_internal, &refresh_screen, &force_load, real_cmd)) {	    case 1:		continue;	    case 2:		goto new_keyboard_input;	    case 3:		pending_form_c = c;	    }	    break;	case LYK_ELGOTO:	/* edit URL of current link and go to it  */	    if (handle_LYK_ELGOTO(&ch, user_input_buffer, &temp, &old_c, real_c))		do_check_goto_URL(user_input_buffer, &temp, &force_load);	    break;	case LYK_ECGOTO:	/* edit current URL and go to to it	*/	    if (handle_LYK_ECGOTO(&ch, user_input_buffer, &temp, &old_c, real_c))		do_check_goto_URL(user_input_buffer, &temp, &force_load);	    break;	case LYK_GOTO:		/* 'g' to goto a random URL  */	    if (handle_LYK_GOTO(&ch, user_input_buffer, &temp, &recall,				&URLTotal, &URLNum, &FirstURLRecall, &old_c,				real_c)) {		if (do_check_recall (ch, user_input_buffer, &temp, URLTotal,				 &URLNum, recall, &FirstURLRecall))		    do_check_goto_URL(user_input_buffer, &temp, &force_load);	    }	    break;	case LYK_DWIMHELP:	/* show context-dependent help file */	    handle_LYK_DWIMHELP(&cshelpfile);	    /* FALLTHRU */	case LYK_HELP:		/* show help file */	    handle_LYK_HELP(&cshelpfile);	    break;	case LYK_INDEX:		/* index file */	    handle_LYK_INDEX(&old_c, real_c);	    break;	case LYK_MAIN_MENU:	/* return to main screen */	    handle_LYK_MAIN_MENU(&old_c, real_c);	    break;#ifdef EXP_NESTED_TABLES	case LYK_NESTED_TABLES:	    if (handle_LYK_NESTED_TABLES(&cmd))		goto new_cmd;	    break;#endif	case LYK_OPTIONS:	/* options screen */	    if (handle_LYK_OPTIONS(&cmd, &refresh_screen))		goto new_cmd;	    break;	case LYK_INDEX_SEARCH:	/* search for a user string */	    handle_LYK_INDEX_SEARCH(&force_load, ForcePush, &old_c, real_c);	    break;	case LYK_WHEREIS:	/* search within the document */	case LYK_NEXT:		/* find the next occurrence in the document */	case LYK_PREV:		/* find the previous occurrence in the document */	    handle_LYK_WHEREIS(cmd, &refresh_screen);	    break;	case LYK_COMMENT:	/* reply by mail */	    handle_LYK_COMMENT(&refresh_screen, &owner_address, &old_c, real_c);	    break;#ifdef DIRED_SUPPORT	case LYK_TAG_LINK:	/* tag or untag the current link */	    handle_LYK_TAG_LINK();	    break;	case LYK_MODIFY:	/* rename a file or directory */	    handle_LYK_MODIFY(&refresh_screen);	    break;	case LYK_CREATE:	/* create a new file or directory */	    handle_LYK_CREATE();	    break;#endif /* DIRED_SUPPORT */	case LYK_DWIMEDIT:	/* context-dependent edit */	    switch (handle_LYK_DWIMEDIT(&cmd, &old_c, real_c)) {	    case 1:		continue;	    case 2:		goto new_cmd;	    }	    /* FALLTHRU */	case LYK_EDIT:		/* edit */	    handle_LYK_EDIT(&old_c, real_c);	    break;	case LYK_DEL_BOOKMARK:	/* remove a bookmark file link */	    handle_LYK_DEL_BOOKMARK(&refresh_screen, &old_c, real_c);	    break;#ifdef DIRED_SUPPORT	case LYK_REMOVE:	/* remove files and directories */	    handle_LYK_REMOVE(&refresh_screen);	    break;#endif /* DIRED_SUPPORT */#if defined(DIRED_SUPPORT) && defined(OK_INSTALL)	case LYK_INSTALL:	/* install a file into system area */	    handle_LYK_INSTALL();	    break;#endif /* DIRED_SUPPORT && OK_INSTALL */	case LYK_INFO:		/* show document info */	    if (handle_LYK_INFO(&cmd))		goto new_cmd;	    break;	case LYK_EDIT_TEXTAREA: /* use external editor on a TEXTAREA - KED */	    handle_LYK_EDIT_TEXTAREA(&refresh_screen, &old_c, real_c);	    break;	case LYK_GROW_TEXTAREA:	/* add new lines to bottom of TEXTAREA - KED */	    handle_LYK_GROW_TEXTAREA(&refresh_screen);	    break;	case LYK_INSERT_FILE:	/* insert file in TEXTAREA, above cursor - KED */	    handle_LYK_INSERT_FILE(&refresh_screen, &old_c, real_c);	    break;	case LYK_PRINT:		/* print the file */	    handle_LYK_PRINT(&ForcePush, &old_c, real_c);	    break;	case LYK_LIST:		/* list links in the current document */	    if (handle_LYK_LIST(&cmd))		goto new_cmd;	    break;#ifdef EXP_ADDRLIST_PAGE	case LYK_ADDRLIST:	/* always list URL's (only) */	    if (handle_LYK_ADDRLIST(&cmd))		goto new_cmd;	    break;#endif /* EXP_ADDRLIST_PAGE */	case LYK_VLINKS:  /* list links visited during the current session */	    if (handle_LYK_VLINKS(&cmd, &newdoc_link_is_absolute))		goto new_cmd;	    break;	case LYK_TOOLBAR:  /* go to Toolbar or Banner in current document */	    handle_LYK_TOOLBAR(&try_internal, &force_load, &old_c, real_c);	    break;#if defined(DIRED_SUPPORT) || defined(VMS)	case LYK_DIRED_MENU:  /* provide full file management menu */	    handle_LYK_DIRED_MENU(&refresh_screen, &old_c, real_c);	    break;#endif /* DIRED_SUPPORT || VMS*/#ifdef USE_EXTERNALS	case LYK_EXTERN_LINK:	/* use external program on url */	    handle_LYK_EXTERN_LINK(&refresh_screen);	    break;	case LYK_EXTERN_PAGE:	/* use external program on current page */	    handle_LYK_EXTERN_PAGE(&refresh_screen);	    break;#endif /* USE_EXTERNALS */	case LYK_ADD_BOOKMARK:	/* add link to bookmark file */	    handle_LYK_ADD_BOOKMARK(&refresh_screen, &old_c, real_c);	    break;	case LYK_VIEW_BOOKMARK:	/* v to view home page */	    handle_LYK_VIEW_BOOKMARK(&refresh_screen, &old_c, real_c);	    break;	case LYK_SHELL:		/* (!) shell escape */	    handle_LYK_SHELL(&refresh_screen, &old_c, real_c);	    break;	case LYK_DOWNLOAD:	    switch (handle_LYK_DOWNLOAD(&cmd, &old_c, real_c)) {	    case 1:		continue;	    case 2:		goto new_cmd;	    }	    break;#ifdef DIRED_SUPPORT	  case LYK_UPLOAD:	    handle_LYK_UPLOAD();	    break;#endif /* DIRED_SUPPORT */	case LYK_TRACE_TOGGLE:	/*  Toggle TRACE mode. */	    handle_LYK_TRACE_TOGGLE();	    break;	case LYK_TRACE_LOG:	/*  View TRACE log. */	    handle_LYK_TRACE_LOG(&trace_mode_flag);	    break;	case LYK_IMAGE_TOGGLE:	    if (handle_LYK_IMAGE_TOGGLE(&cmd))		goto new_cmd;	    break;	case LYK_INLINE_TOGGLE:	    if (handle_LYK_INLINE_TOGGLE(&cmd))		goto new_cmd;	    break;	case LYK_RAW_TOGGLE:	    if (handle_LYK_RAW_TOGGLE(&cmd))		goto new_cmd;	    break;	case LYK_HEAD:	    if (handle_LYK_HEAD(&cmd))		goto new_cmd;	    break;	case LYK_TOGGLE_HELP:	    handle_LYK_TOGGLE_HELP();	    break;	case LYK_KEYMAP:	    handle_LYK_KEYMAP(&vi_keys_flag, &emacs_keys_flag, &old_c, real_c);	    break;	case LYK_JUMP:	    if (handle_LYK_JUMP(c, user_input_buffer, &temp, &recall,				    &FirstURLRecall, &URLNum, &URLTotal, &ch,				    &old_c, real_c)) {		if (do_check_recall (ch, user_input_buffer, &temp, URLTotal,				 &URLNum, recall, &FirstURLRecall))		    do_check_goto_URL(user_input_buffer, &temp, &force_load);	    }	    break;	case LYK_CLEAR_AUTH:	    handle_LYK_CLEAR_AUTH(&old_c, real_c);	    break;	case LYK_DO_NOTHING:	/* pretty self explanatory */	    break;#ifdef SUPPORT_CHDIR	case LYK_CHDIR:	    handle_LYK_CHDIR();	    break;#endif#ifdef USE_CURSES_PADS	case LYK_SHIFT_LEFT:	    handle_LYK_SHIFT_LEFT(&refresh_screen, key_count);	    break;	case LYK_SHIFT_RIGHT:	    handle_LYK_SHIFT_RIGHT(&refresh_screen, key_count);	    break;	case LYK_LINEWRAP_TOGGLE:	    if (handle_LYK_LINEWRAP_TOGGLE(&cmd, &refresh_screen))		goto new_cmd;	    break;#endif	} /* end of BIG switch */    }}