⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lymainloop.c

📁 基于rtos开发的浏览器!
💻 C
📖 第 1 页 / 共 5 页
字号:
#include "HTUtils.h"#include "tcp.h"#include "HTAccess.h"#include "HTParse.h"#include "HTList.h"#include "HTML.h"#include "HTFTP.h"#include "HTFile.h"#include "HTTP.h"#include "HTAABrow.h"#include "HTNews.h"#include "LYCurses.h"#include "LYStyle.h"#include "LYGlobalDefs.h"#include "HTAlert.h"#include "LYUtils.h"#include "GridText.h"#include "LYStrings.h"#include "LYOptions.h"#include "LYSignal.h"#include "LYGetFile.h"#include "HTForms.h"#include "LYSearch.h"#include "LYClean.h"#include "LYHistory.h"#include "LYPrint.h"#include "LYMail.h"#include "LYEdit.h"#include "LYShowInfo.h"#include "LYBookmark.h"#include "LYSystem.h"#include "LYKeymap.h"#include "LYJump.h"#include "LYDownload.h"#include "LYList.h"#include "LYMap.h"#include "LYTraversal.h"#include "LYCharSets.h"#include "LYCharUtils.h"#include "LYCookie.h"#include "LYMainLoop.h"#ifdef DOSPATH#include "HTDOS.h"#endif#ifdef USE_EXTERNALS#include "LYExtern.h"#endif#ifdef VMS#include "HTVMSUtils.h"#endif /* VMS */#ifdef DIRED_SUPPORT#include "LYLocal.h"#include "LYUpload.h"#endif /* DIRED_SUPPORT */#include "LYexit.h"#include "LYLeaks.h"PRIVATE BOOL confirm_post_resub PARAMS((    CONST char* 	address,    CONST char* 	title,    int 		if_imgmap,    int 		if_file));PRIVATE int are_different PARAMS((document *doc1, document *doc2));PUBLIC void HTGotoURLs_free NOPARAMS;PUBLIC void HTAddGotoURL PARAMS((char *url));#ifndef DONT_TRACK_INTERNAL_LINKSPRIVATE int are_phys_different PARAMS((document *doc1, document *doc2));#endif#define FASTTAB#ifdef FASTTABPRIVATE int sametext ARGS2(	char *, 	een,	char *, 	twee){    if (een && twee)	return (strcmp(een, twee) == 0);    return TRUE;}#endif /* FASTTAB */#define FREE(x) if (x) {free(x); x = NULL;}PUBLIC	HTList * Goto_URLs = NULL;  /* List of Goto URLs */PUBLIC char * LYRequestTitle = NULL; /* newdoc.title in calls to getfile() */PRIVATE document newdoc;PRIVATE document curdoc;PRIVATE char *traversal_host = NULL;PRIVATE char *traversal_link_to_add = NULL;PRIVATE char *CurrentUserAgent = NULL;PRIVATE char *CurrentNegoLanguage = NULL;PRIVATE char *CurrentNegoCharset = NULL;/* *  Function for freeing allocated mainloop() variables. - FM */PRIVATE void free_mainloop_variables NOARGS{    FREE(newdoc.title);    FREE(newdoc.address);    FREE(newdoc.post_data);    FREE(newdoc.post_content_type);    FREE(newdoc.bookmark);    FREE(curdoc.title);    FREE(curdoc.address);    FREE(curdoc.post_data);    FREE(curdoc.post_content_type);    FREE(curdoc.bookmark);#ifdef USE_HASH    FREE(curdoc.style);    FREE(newdoc.style);#endif    FREE(traversal_host);    FREE(traversal_link_to_add);    FREE(CurrentUserAgent);    FREE(CurrentNegoLanguage);    FREE(CurrentNegoCharset);#ifdef DIRED_SUPPORT    clear_tags();#endif /* DIRED_SUPPORT */    return;}/* *  Here's where we do all the work. *  mainloop is basically just a big switch dependent on the users input. *  I have tried to offload most of the work done here to procedures to *  make it more modular, but this procedure still does a lot of variable *  manipulation.  This needs some work to make it neater. - Lou Moutilli *					(memoir from the original Lynx - FM) */int mainloop NOARGS{    int c = 0, real_c = 0, old_c = 0;    int cmd = LYK_DO_NOTHING, real_cmd = LYK_DO_NOTHING;    int getresult;    int arrowup = FALSE, show_help = FALSE;    int lines_in_file = -1;    int Newline = 0;    char prev_target[512];    char user_input_buffer[1024];    char *owner_address = NULL;  /* Holds the responsible owner's address     */    char *ownerS_address = NULL; /* Holds owner's address during source fetch */    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 rlink_exists;    BOOLEAN rlink_allowed;    BOOLEAN vi_keys_flag = vi_keys;    BOOLEAN emacs_keys_flag = emacs_keys;    BOOLEAN keypad_mode_flag = keypad_mode;    BOOLEAN user_mode_flag = user_mode;    BOOLEAN HTfileSortMethod_flag = HTfileSortMethod;    int CurrentCharSet_flag = current_char_set;    BOOLEAN show_dotfiles_flag = show_dotfiles;    BOOLEAN LYRawMode_flag = LYRawMode;    BOOLEAN LYSelectPopups_flag = LYSelectPopups;    BOOLEAN trace_mode_flag = FALSE;    BOOLEAN forced_HTML_mode = LYforce_HTML_mode;    char cfile[128];    FILE *cfp;    char *cp, *toolbar;#ifdef VMS    extern BOOLEAN HadVMSInterrupt;   /* Flag from cleanup_sig */#endif /* VMS */    int ch, recall;    int URLTotal;    int URLNum;    BOOLEAN FirstURLRecall = TRUE;    char *temp = NULL;    BOOLEAN ForcePush = FALSE;    BOOLEAN override_LYresubmit_posts = FALSE;    unsigned int len;    int i;#ifdef DIRED_SUPPORT    char *tp = NULL;    struct stat dir_info;#endif /* DIRED_SUPPORT *//* *  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;    curdoc.address = NULL;    curdoc.title = NULL;    curdoc.post_data = NULL;    curdoc.post_content_type = NULL;    curdoc.bookmark = NULL;#ifdef USE_HASH    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';    StrAllocCopy(CurrentUserAgent, (LYUserAgent ?				    LYUserAgent : ""));    StrAllocCopy(CurrentNegoLanguage, (language ?				       language : ""));    StrAllocCopy(CurrentNegoCharset, (pref_charset ?				      pref_charset : ""));    atexit(free_mainloop_variables);initialize:    StrAllocCopy(newdoc.address, startfile);    StrAllocCopy(startrealm, startfile);    StrAllocCopy(newdoc.title, "Entry into main screen");    newdoc.isHEAD = FALSE;    newdoc.safe = FALSE;    newdoc.internal_link = FALSE;    newdoc.line = 1;    newdoc.link = 0;#ifdef USE_SLANG    if (TRACE && LYCursesON) {	addstr("\n");	refresh();    }#endif /* USE_SLANG */    if (TRACE)	fprintf(stderr,"Entering mainloop, startfile=%s\n",startfile);    if (form_post_data) {	StrAllocCopy(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) {	    _statusline(BOOKMARKS_DISABLED);	    sleep(AlertSecs);	    bookmark_start = FALSE;	    goto initialize;	} else if (traversal) {	    _statusline(BOOKMARKS_NOT_TRAVERSED);	    sleep(AlertSecs);	    traversal = FALSE;	    crawl = FALSE;	    bookmark_start = FALSE;	    goto initialize;	} else {	    /*	     *	See if a bookmark page exists.	If it does,	     *	replace newdoc.address with it's 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);		FREE(newdoc.post_data);		FREE(newdoc.post_content_type);		newdoc.isHEAD = FALSE;		newdoc.safe = FALSE;		if (TRACE)		    fprintf(stderr, "Using bookmarks=%s\n", newdoc.address);	    } else {		_statusline(BOOKMARKS_NOT_OPEN);		sleep(MessageSecs);		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_HASH	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) {		    move(LYlines-1, LYcols-1);	/* make sure cursor is down */#ifdef USE_SLANG		    addstr("\n");#endif /* USE_SLANG */		    refresh();		}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 (strncmp(newdoc.address, "LYNXDOWNLOAD:", 13)) {			LYpush(&curdoc, ForcePush);		    }		} else if (!newdoc.address) {		    /*		     *	If newdoc.address is empty then pop a file		     *	and load it.  - FM		     */		    LYpop(&newdoc);		    popped_doc = TRUE;#ifndef DONT_TRACK_INTERNAL_LINKS#define NO_INTERNAL_OR_DIFFERENT(c,n) TRUE#define NONINTERNAL_OR_PHYS_DIFFERENT(p,n) (!curdoc.internal_link || \			   are_phys_different(p,n))#else /* TRACK_INTERNAL_LINKS */#define NO_INTERNAL_OR_DIFFERENT(c,n) are_different(c,n)#define NONINTERNAL_OR_PHYS_DIFFERENT(p,n) are_different(p,n)#endif /* TRACK_INTERNAL_LINKS */#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 (!strncmp(newdoc.address, "LYNXIMGMAP:", 11)) {			    if (LYCanDoHEAD(newdoc.address + 11) == TRUE) {				StrAllocCopy(temp, newdoc.address + 11);				FREE(newdoc.address);				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 &&		    !strcmp((newdoc.title ? newdoc.title : ""),			     LYNX_TRACELOG_TITLE)) {		    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_parent(HTAnchor_findAddress(&WWWDoc));		    if ((HText *)HTAnchor_document(tmpanchor) == NULL) {			if (TRACE)			    fprintf(stderr,				    "\nTurning off TRACE for fetch of log.\n");			fflush(stdout);			fflush(stderr);			fclose(LYTraceLogFP);			*stderr = LYOrigStderr;			if ((LYTraceLogFP = LYAppendToTxtFile(LYTraceLogPath)) == NULL) {			    WWW_TraceFlag = FALSE;			    _statusline(TRACELOG_OPEN_FAILED);			    sleep(MessageSecs);			    old_c = 0;			    cmd = LYK_PREV_DOC;			    goto new_cmd;			}			*stderr = *LYTraceLogFP;			if (TRACE) {			    WWW_TraceFlag = FALSE;			    trace_mode_flag = TRUE;			}		    }		}		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;		}#ifndef DONT_TRACK_INTERNAL_LINKS		if (try_internal) {		    if (newdoc.address &&

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -