📄 lymain.c
字号:
/* * Process any command line arguments not already handled. - FM */ for (i = 1; i < argc; i++) { parse_arg(&argv[i], &i, argc); } /* * Process any stdin-derived arguments for a lone "-" which we've * loaded into LYStdinArgs. - FM */ if (LYStdinArgs != NULL) { char *my_args[2]; HTList *cur = LYStdinArgs; my_args[1] = NULL; while (NULL != (my_args[0] = (char *)HTList_nextObject(cur))) { parse_arg(my_args, NULL, -1); } LYStdinArgs_free(); }#ifndef VMS#ifdef SYSLOG_REQUESTED_URLS if (syslog_txt) { syslog(LOG_INFO, "Session start:%s", syslog_txt); } else { syslog(LOG_INFO, "Session start"); }#endif /* SYSLOG_REQUESTED_URLS */#endif /* !VMS */ /* * Process the RC file. */ read_rc();#ifdef USE_SLANG if (LYShowColor >= SHOW_COLOR_ON && !(Lynx_Color_Flags & SL_LYNX_USE_COLOR)) { Lynx_Color_Flags |= SL_LYNX_USE_COLOR; } else if ((Lynx_Color_Flags & SL_LYNX_USE_COLOR) || getenv("COLORTERM") != NULL) { if (LYShowColor != SHOW_COLOR_NEVER && LYShowColor != SHOW_COLOR_ALWAYS) { LYShowColor = SHOW_COLOR_ON; } }#endif /* USE_SLANG */ if (LYPreparsedSource) { HTPreparsedFormatInit(); }#if defined(EXEC_LINKS) || defined(EXEC_SCRIPTS)#ifdef NEVER_ALLOW_REMOTE_EXEC if (local_exec) { local_exec = FALSE; local_exec_on_local_files = TRUE; }#endif /* NEVER_ALLOW_REMOTE_EXEC */#endif /* EXEC_LINKS || EXEC_SCRIPTS */ if (emacs_keys) set_emacs_keys(); if (vi_keys) set_vi_keys(); if (number_links && keypad_mode == NUMBERS_AS_ARROWS) keypad_mode = LINKS_ARE_NUMBERED; if (keypad_mode == NUMBERS_AS_ARROWS) set_numbers_as_arrows(); /* * Check the -popup command line toggle. - FM */ if (LYUseDefSelPop == FALSE) { if (LYSelectPopups == TRUE) LYSelectPopups = FALSE; else LYSelectPopups = TRUE; } /* * Check the -show_cursor command line toggle. - FM */ if (LYUseDefShoCur == FALSE) { if (LYShowCursor == TRUE) LYShowCursor = FALSE; else LYShowCursor = TRUE; } /* * Check the -base command line switch with -source. - FM */ if (LYPrependBase && HTOutputFormat == HTAtom_for("www/download")) { LYPrependBaseToSource = TRUE; } /* * Disable multiple bookmark support if not interactive, * so it doesn't crash on curses functions, or if the * support was blocked via userdefs.h and/or lynx.cfg, * or via command line restrictions. - FM */ if (no_multibook) LYMBMBlocked = TRUE; if (dump_output_immediately || LYMBMBlocked || no_multibook) { LYMultiBookmarks = FALSE; LYMBMBlocked = TRUE; no_multibook = TRUE; }#ifdef VMS set_vms_keys();#endif /* VMS */ /* trap interrupts */ if (!dump_output_immediately)#ifndef NOSIGHUP (void) signal(SIGHUP, cleanup_sig);#endif /* NOSIGHUP */ (void) signal(SIGTERM, cleanup_sig);#ifdef SIGWINCH (void) signal(SIGWINCH, size_change);#endif /* SIGWINCH */#ifndef VMS if (!TRACE && !dump_output_immediately && !stack_dump) { (void) signal(SIGINT, cleanup_sig);#ifndef __linux__#ifndef DOSPATH (void) signal(SIGBUS, FatalProblem);#endif /* DOSPATH */#endif /* !__linux__ */ (void) signal(SIGSEGV, FatalProblem); (void) signal(SIGILL, FatalProblem); /* * Since we're doing lots of TCP, just ignore SIGPIPE altogether. * * HTTCP.c should deal with a broken pipe for servers. * Rick Mallet's check after c = GetChar() in LYStrings.c should * deal with a disconnected terminal. * So the runaway CPU time problem on Unix should not occur any * more. */#ifndef DOSPATH (void) signal(SIGPIPE, SIG_IGN);#endif /* DOSPATH */ }#endif /* !VMS */ /* * Set up the proper character set with the desired * startup raw 8-bit or CJK mode handling. - FM */ HTMLUseCharacterSet(current_char_set); /* * If startfile is a file URL and the host is defaulted, * force in "//localhost", and if it's not an absolute URL, * make it one. - FM */ LYFillLocalFileURL((char **)&startfile, "file://localhost"); LYEnsureAbsoluteURL((char **)&startfile, "STARTFILE"); /* * If homepage was specified and is a file URL with the * host defaulted, force in "//localhost", and if it's * not an absolute URL, make it one. - FM */ if (homepage) { LYFillLocalFileURL((char **)&homepage, "file://localhost"); LYEnsureAbsoluteURL((char **)&homepage, "HOMEPAGE"); } /* * If we don't have a homepage specified, * set it to startfile. Otherwise, reset * LynxHome. - FM */ if (!(homepage && *homepage)) { StrAllocCopy(homepage, startfile); } else { StrAllocCopy(LynxHome, homepage); } /* * Set up the inside/outside domain restriction flags. - FM */ if (inlocaldomain()) {#if !defined(HAVE_UTMP) || defined(VMS) /* not selective */ telnet_ok = !no_inside_telnet && !no_outside_telnet && telnet_ok; news_ok = !no_inside_news && !no_outside_news && news_ok; ftp_ok = !no_inside_ftp && !no_outside_ftp && ftp_ok; rlogin_ok = !no_inside_rlogin && !no_outside_rlogin && rlogin_ok;#else if (TRACE) fprintf(stderr,"LYMain.c: User in Local domain\n"); telnet_ok = !no_inside_telnet && telnet_ok; news_ok = !no_inside_news && news_ok; ftp_ok = !no_inside_ftp && ftp_ok; rlogin_ok = !no_inside_rlogin && rlogin_ok;#endif /* !HAVE_UTMP || VMS */ } else { if (TRACE) fprintf(stderr,"LYMain.c: User in REMOTE domain\n"); telnet_ok = !no_outside_telnet && telnet_ok; news_ok = !no_outside_news && news_ok; ftp_ok = !no_outside_ftp && ftp_ok; rlogin_ok = !no_outside_rlogin && rlogin_ok; }#ifdef SIGTSTP /* * Block Control-Z suspending if requested. - FM */ if (no_suspend) (void) signal(SIGTSTP,SIG_IGN);#endif /* SIGTSTP */ /* * Check for a valid HEAD request. - FM */ if (HEAD_request && LYCanDoHEAD(startfile) != TRUE) { fprintf(stderr, "The '-head' switch is for http HEAD requests and cannot be used for\n'%s'.\n", startfile);#ifndef NOSIGHUP (void) signal(SIGHUP, SIG_DFL);#endif /* NOSIGHUP */ (void) signal(SIGTERM, SIG_DFL);#ifndef VMS (void) signal(SIGINT, SIG_DFL);#endif /* !VMS */#ifdef SIGTSTP if (no_suspend) (void) signal(SIGTSTP,SIG_DFL);#endif /* SIGTSTP */ exit(-1); } /* * Check for a valid MIME headers request. - FM */ if (keep_mime_headers && LYCanDoHEAD(startfile) != TRUE) { fprintf(stderr, "The '-mime_header' switch is for http URLs and cannot be used for\n'%s'.\n", startfile);#ifndef NOSIGHUP (void) signal(SIGHUP, SIG_DFL);#endif /* NOSIGHUP */ (void) signal(SIGTERM, SIG_DFL);#ifndef VMS (void) signal(SIGINT, SIG_DFL);#endif /* !VMS */#ifdef SIGTSTP if (no_suspend) (void) signal(SIGTSTP,SIG_DFL);#endif /* SIGTSTP */ exit(-1); } /* * Check for a valid traversal request. - FM */ if (traversal && strncmp(startfile, "http", 4)) { fprintf(stderr, "The '-traversal' switch is for http URLs and cannot be used for\n'%s'.\n", startfile);#ifndef NOSIGHUP (void) signal(SIGHUP, SIG_DFL);#endif /* NOSIGHUP */ (void) signal(SIGTERM, SIG_DFL);#ifndef VMS (void) signal(SIGINT, SIG_DFL);#endif /* !VMS */#ifdef SIGTSTP if (no_suspend) (void) signal(SIGTSTP,SIG_DFL);#endif /* SIGTSTP */ exit(-1); } /* * Set up our help and about file base paths. - FM */ StrAllocCopy(helpfilepath, helpfile); if ((cp=strrchr(helpfilepath, '/')) != NULL) *cp = '\0'; /* * Remove code to merge the historical about_lynx * directory into lynx_help. - HN */ StrAllocCat(helpfilepath, "/"); /* * Make sure our bookmark default strings * are all allocated and synchronized. - FM */ if (!bookmark_page || *bookmark_page == '\0') { StrAllocCopy(bookmark_page, "lynx_bookmarks"); StrAllocCat(bookmark_page, HTML_SUFFIX); StrAllocCopy(BookmarkPage, bookmark_page); StrAllocCopy(MBM_A_subbookmark[0], bookmark_page); StrAllocCopy(MBM_A_subdescript[0], "Default"); } if (!BookmarkPage || *BookmarkPage == '\0') { StrAllocCopy(BookmarkPage, bookmark_page); StrAllocCopy(MBM_A_subbookmark[0], bookmark_page); StrAllocCopy(MBM_A_subdescript[0], MULTIBOOKMARKS_DEFAULT); } /* * Here's where we do all the work. */ if (dump_output_immediately) { /* * Finish setting up and start a * NON-INTERACTIVE session. - FM */ if (crawl && !number_links) { keypad_mode = NUMBERS_AS_ARROWS; } else if (!nolist) { if (keypad_mode == NUMBERS_AS_ARROWS) { keypad_mode = LINKS_ARE_NUMBERED; } } if (display != NULL && *display != '\0') { LYisConfiguredForX = TRUE; } if (dump_output_width > 0) { LYcols = dump_output_width; } status = mainloop(); if (!nolist && (keypad_mode == LINKS_ARE_NUMBERED || keypad_mode == LINKS_AND_FORM_FIELDS_ARE_NUMBERED)) printlist(stdout,FALSE);#ifndef NOSIGHUP (void) signal(SIGHUP, SIG_DFL);#endif /* NOSIGHUP */ (void) signal(SIGTERM, SIG_DFL);#ifndef VMS (void) signal(SIGINT, SIG_DFL);#endif /* !VMS */#ifdef SIGTSTP if (no_suspend) (void) signal(SIGTSTP,SIG_DFL);#endif /* SIGTSTP */ } else { /* * Finish setting up and start an * INTERACTIVE session. - FM */ if (setup(terminal)) { if (display != NULL && *display != '\0') { LYisConfiguredForX = TRUE; } ena_csi((LYlowest_eightbit[current_char_set] > 155)); status = mainloop(); cleanup(); } } exit(status);}/* * Called by HTAccessInit to register any protocols supported by lynx. * Protocols added by lynx: * LYNXKEYMAP, lynxcgi, LYNXIMGMAP, LYNXCOOKIE */#ifdef GLOBALREF_IS_MACROextern GLOBALREF (HTProtocol, LYLynxKeymap);extern GLOBALREF (HTProtocol, LYLynxCGI);extern GLOBALREF (HTProtocol, LYLynxIMGmap);extern GLOBALREF (HTProtocol, LYLynxCookies);#elseGLOBALREF HTProtocol LYLynxKeymap;GLOBALREF HTProtocol LYLynxCGI;GLOBALREF HTProtocol LYLynxIMGmap;GLOBALREF HTProtocol LYLynxCookies;#endif /* GLOBALREF_IS_MACRO */PUBLIC void LYRegisterLynxProtocols NOARGS{ HTRegisterProtocol(&LYLynxKeymap); HTRegisterProtocol(&LYLynxCGI); HTRegisterProtocol(&LYLynxIMGmap); HTRegisterProtocol(&LYLynxCookies);}/* * Parse one argument, optionally picking up the next entry in argv (if * appropriate). */PRIVATE char * scan3D ARGS2( char **, argv, int *, i){ char *result; if ((result=strchr(argv[0],'=')) != NULL) return result+1; if (argv[1] && i) (*i)++; /* Let master know we've stolen an argument */ return argv[1];}PRIVATE void parse_arg ARGS3( char **, argv, int *, i, int, argc){ char *cp;#ifndef VMS static char display_putenv_command[142];#endif /* !VMS */#define nextarg ((cp=scan3D(&argv[0], i))!=NULL) /* * Check for a command line startfile. - FM */ if (argv[0][0] != '-') { StrAllocCopy(startfile, argv[0]); LYTrimHead(startfile); if (!strncasecomp(startfile, "lynxexec:", 9) || !strncasecomp(startfile, "lynxprog:", 9)) { /* * The original implementations of these schemes expected * white space without hex escaping, and did not check * for hex escaping, so we'll continue to support that, * until that code is redone in conformance with SGML * principles. - FM */ HTUnEscapeSome(startfile, " \r\n\t"); convert_to_spaces(startfile, TRUE); } return; } /* * Skip any lone "-" arguments, because we've loaded * the stdin input into an HTList structure for * special handling. - FM */ if (strcmp(argv[0], "-") == 0) { return; } switch (TOLOWER(argv[0][1])) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -