📄 lymain.c
字号:
FREE(pref_charset); FREE(LynxSigFile); FREE(system_mail); FREE(system_mail_flags); FREE(LYUserAgent); FREE(LYUserAgentDefault); FREE(LYHostName); FREE(LYLocalDomain); FREE(lynx_save_space); FREE(homepage); FREE(helpfilepath); FREE(bookmark_page); FREE(BookmarkPage); for (i = 0; i <= MBM_V_MAXFILES; i++) { FREE(MBM_A_subbookmark[i]); FREE(MBM_A_subdescript[i]); } FREE(editor); FREE(authentication_info[0]); FREE(authentication_info[1]); FREE(proxyauth_info[0]); FREE(proxyauth_info[1]); FREE(lynxjumpfile); FREE(startrealm); FREE(personal_mail_address); FREE(URLDomainPrefixes); FREE(URLDomainSuffixes); FREE(XLoadImageCommand); FREE(LYTraceLogPath);#if defined(USE_HASH) FREE(lynx_lss_file);#endif FREE(UCAssume_MIMEcharset); FREE(UCAssume_unrecMIMEcharset); FREE(UCAssume_localMIMEcharset); for (i = 0; i < nlinks; i++) { FREE(links[i].lname); } nlinks = 0; return;}/* * This function frees the LYStdinArgs list. - FM */PRIVATE void LYStdinArgs_free NOARGS{ char *argument; HTList *cur = LYStdinArgs; if (cur == NULL) return; while (NULL != (argument = (char *)HTList_nextObject(cur))) { FREE(argument); } HTList_delete(LYStdinArgs); LYStdinArgs = NULL; return;}/* * Wow! Someone wants to start up Lynx. */PUBLIC int main ARGS2( int, argc, char **, argv){ int i; /* indexing variable */ int status = 0; /* exit status */ int len; char *lynx_cfg_file = NULL; char *temp = NULL; char *cp; FILE *fp; char filename[256]; BOOL LYGetStdinArgs = FALSE;#ifdef _WINDOWS WSADATA WSAData; { int err; WORD wVerReq; wVerReq = MAKEWORD(1,1); err = WSAStartup(wVerReq, &WSAData); if (err != 0) { printf("No Winsock found, sorry."); sleep(5); return; } }#endif /* _WINDOWS */#ifdef __DJGPP__if (PDC_get_ctrl_break() == 0) { PDC_set_ctrl_break(TRUE); init_ctrl_break[0] = 0;}else {init_ctrl_break[0] = 1;} atexit(reset_break); sock_init();#endif#if defined(_WINDOWS) || defined(DJGPP) /* * To prevent corrupting binary data with _WINDOWS and DJGPP * we open files and stdout in BINARY mode by default. * Where necessary we should open and (close!) TEXT mode. */ _fmode = O_BINARY; setmode( fileno( stdout ), O_BINARY );#endif#ifdef DOSPATH terminal = "vt100";#endif LYShowColor = (SHOW_COLOR ? SHOW_COLOR_ON : SHOW_COLOR_OFF); /* * Set up the argument list. */ pgm = argv[0]; if ((cp = strrchr(pgm, '/')) != NULL) { pgm = cp + 1; } /* * Act on -help NOW, so we only output the help and exit. - FM */ for (i = 1; i < argc; i++) { if (strncmp(argv[i], "-help", 5) == 0) { parse_arg(&argv[i], &i, argc); } }#ifdef LY_FIND_LEAKS /* * Register the final function to be executed when being exited. * Will display memory leaks if LY_FIND_LEAKS is defined. */ atexit(LYLeaks);#endif /* LY_FIND_LEAKS */ /* * Register the function which will free our allocated globals. */ atexit(free_lynx_globals);#ifdef LOCALE /* * LOCALE support for international characters. */ setlocale(LC_ALL, "");#endif /* LOCALE */ /* * Initialize our startup and global variables. */#ifdef ULTRIX /* * Need this for Ultrix. */ terminal = getenv("TERM"); if ((terminal == NULL) || !strncasecomp(terminal, "xterm", 5)) terminal = "vt100";#endif /* ULTRIX */ /* * Zero the links and history struct arrays. */ memset((void *)links, 0, sizeof(linkstruct)*MAXLINKS); memset((void *)history, 0, sizeof(histstruct)*MAXHIST); /* * Zero the MultiBookmark arrays. */ memset((void *)MBM_A_subbookmark, 0, sizeof(char)*(MBM_V_MAXFILES+1)); memset((void *)MBM_A_subdescript, 0, sizeof(char)*(MBM_V_MAXFILES+1));#ifndef VMS#ifdef SYSLOG_REQUESTED_URLS openlog("lynx", LOG_PID, LOG_LOCAL5);#endif /* SYSLOG_REQUESTED_URLS */ StrAllocCopy(list_format, LIST_FORMAT);#endif /* !VMS */ InfoSecs = (int)INFOSECS; MessageSecs = (int)MESSAGESECS; AlertSecs = (int)ALERTSECS; StrAllocCopy(helpfile, HELPFILE); StrAllocCopy(startfile, STARTFILE); 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); } StrAllocCopy(indexfile, DEFAULT_INDEX_FILE); StrAllocCopy(global_type_map, GLOBAL_MAILCAP); StrAllocCopy(personal_type_map, PERSONAL_MAILCAP); StrAllocCopy(global_extension_map, GLOBAL_EXTENSION_MAP); StrAllocCopy(personal_extension_map, PERSONAL_EXTENSION_MAP); StrAllocCopy(language, PREFERRED_LANGUAGE); StrAllocCopy(pref_charset, PREFERRED_CHARSET); StrAllocCopy(system_mail, SYSTEM_MAIL); StrAllocCopy(system_mail_flags, SYSTEM_MAIL_FLAGS); StrAllocCopy(LYUserAgent, LYNX_NAME); StrAllocCat(LYUserAgent, "/"); StrAllocCat(LYUserAgent, LYNX_VERSION); if (HTLibraryVersion) { StrAllocCat(LYUserAgent, " libwww-FM/"); StrAllocCat(LYUserAgent, HTLibraryVersion); } StrAllocCopy(LYUserAgentDefault, LYUserAgent);#ifdef VMS Define_VMSLogical("LYNX_VERSION", LYNX_VERSION);#else StrAllocCopy(lynx_version_putenv_command, "LYNX_VERSION="); StrAllocCat(lynx_version_putenv_command, LYNX_VERSION); putenv(lynx_version_putenv_command);#endif /* VMS */ if ((cp = getenv("LYNX_TEMP_SPACE")) != NULL) StrAllocCopy(lynx_temp_space, cp); else#ifdef DOSPATH if ((cp = getenv("TEMP")) != NULL) StrAllocCopy(lynx_temp_space, cp); else if ((cp = getenv("TMP")) != NULL) StrAllocCopy(lynx_temp_space, cp); else#endif StrAllocCopy(lynx_temp_space, TEMP_SPACE); if ((cp = strchr(lynx_temp_space, '~'))) { *(cp++) = '\0'; StrAllocCopy(temp, lynx_temp_space); if (((len = strlen(temp)) > 0) && temp[len-1] == '/') temp[len-1] = '\0';#ifdef DOSPATH StrAllocCat(temp, HTDOS_wwwName((char *)Home_Dir()));#else#ifdef VMS StrAllocCat(temp, HTVMS_wwwName((char *)Home_Dir()));#else StrAllocCat(temp, Home_Dir());#endif /* VMS */#endif /* DOSPATH */ StrAllocCat(temp, cp); StrAllocCopy(lynx_temp_space, temp); FREE(temp); } if ((cp = strstr(lynx_temp_space, "$USER")) != NULL) { char *cp1; if ((cp1 = (char *)getenv("USER")) != NULL) { *cp = '\0'; StrAllocCopy(temp, lynx_temp_space); *cp = '$'; StrAllocCat(temp, cp1); cp += 5; StrAllocCat(temp, cp); StrAllocCopy(lynx_temp_space, temp); FREE(temp); } }#ifdef VMS for (i = 0; lynx_temp_space[i]; i++) lynx_temp_space[i] = TOLOWER(lynx_temp_space[i]); if (strchr(lynx_temp_space, '/') != NULL) { if ((len = strlen(lynx_temp_space)) == 1) { StrAllocCopy(lynx_temp_space, "sys$scratch:"); } else { if (lynx_temp_space[len-1] != '/') StrAllocCat(lynx_temp_space, "/"); StrAllocCopy(temp, HTVMS_name("", lynx_temp_space)); StrAllocCopy(lynx_temp_space, temp); FREE(temp); } } if (strchr(lynx_temp_space, ':') == NULL && strchr(lynx_temp_space, ']') == NULL) { StrAllocCat(lynx_temp_space, ":"); }#else#ifndef __DJGPP__ if (((len = strlen(lynx_temp_space)) > 1) && lynx_temp_space[len-1] != '/') { StrAllocCat(lynx_temp_space, "/"); }#else if (((len = strlen(lynx_temp_space)) > 1) && lynx_temp_space[len-1] != '\\') { StrAllocCat(lynx_temp_space, "\\"); }#endif /* __DJGPP__ */#endif /* VMS */#ifdef VMS StrAllocCopy(mail_adrs, MAIL_ADRS);#ifdef CSWING_PATH StrAllocCopy(LYCSwingPath, CSWING_PATH);#endif /* CSWING_PATH */#endif /* VMS */#ifdef LYNX_HOST_NAME StrAllocCopy(LYHostName, LYNX_HOST_NAME);#else StrAllocCopy(LYHostName, HTHostName());#endif /* LYNX_HOST_NAME */ StrAllocCopy(LYLocalDomain, LOCAL_DOMAIN); StrAllocCopy(URLDomainPrefixes, URL_DOMAIN_PREFIXES); StrAllocCopy(URLDomainSuffixes, URL_DOMAIN_SUFFIXES); StrAllocCopy(XLoadImageCommand, XLOADIMAGE_COMMAND); /* * Set up the compilation default character set. - FM */ for (i = 0; LYchar_set_names[i]; i++) { if (!strncmp(CHARACTER_SET, LYchar_set_names[i], strlen(CHARACTER_SET))) { current_char_set=i; break; } } if (!LYchar_set_names[i]) current_char_set = i = 0; HTMLSetRawModeDefault(i); /* * Disable news posting if the compilation-based * LYNewsPosting value is FALSE. This may be changed * further down via lynx.cfg or the -restriction * command line switch. - FM */ no_newspost = (LYNewsPosting == FALSE); /* * Set up trace, the anonymous account defaults, * validate restrictions, and/or the nosocks flag, * if requested, and an alternate configuration * file, if specified, NOW. Also, if we only want * the help menu, output that and exit. - FM */ for (i = 1; i < argc; i++) { if (strncmp(argv[i], "-trace", 6) == 0) { WWW_TraceFlag = TRUE; } else if (strncmp(argv[i], "-tlog", 5) == 0) { if (LYUseTraceLog) { LYUseTraceLog = FALSE; } else { LYUseTraceLog = TRUE; } } else if (strncmp(argv[i], "-anonymous", 10) == 0) { if (!LYValidate) parse_restrictions("default"); anon_restrictions_set = TRUE; } else if (strcmp(argv[i], "-validate") == 0) { /* * Follow only http URLs. */ LYValidate = TRUE;#ifdef SOCKS } else if (strncmp(argv[i], "-nosocks", 8) == 0) { socks_flag = FALSE;#endif /* SOCKS */ } else if (strncmp(argv[i], "-cfg", 4) == 0) { if ((cp=strchr(argv[i],'=')) != NULL) StrAllocCopy(lynx_cfg_file, cp+1); else { StrAllocCopy(lynx_cfg_file, argv[i+1]); i++; }#if defined(USE_HASH) } else if (strncmp(argv[i], "-lss", 4) == 0) { if ((cp=strchr(argv[i],'=')) != NULL) StrAllocCopy(lynx_lss_file, cp+1); else { StrAllocCopy(lynx_lss_file, argv[i+1]); i++; } if (TRACE) fprintf(stderr, "LYMain found -lss flag, lss file is %s\n", lynx_lss_file ? lynx_lss_file : "<NONE>");#endif } } /* * If we have a lone "-" switch for getting arguments from stdin, * get them NOW, and act on the relevant ones, saving the others * into an HTList for handling after the other initializations. * The primary purpose of this feature is to allow for the * potentially very long command line that can be associated with * post or get data. The original implementation required that * the lone "-" be the only command line argument, but that * precluded its use when the lynx command is aliased with other * arguments. When interactive, the stdin input is terminated by * by Control-D on Unix or Control-Z on VMS, and each argument * is terminated by a RETURN. When the argument is -get_data or * -post_data, the data are terminate by a "___" string, alone * on the line (also terminated by RETURN). - FM */ for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-") == 0) { LYGetStdinArgs = TRUE; } } if (LYGetStdinArgs == TRUE) { char buf[1025]; while (fgets(buf, sizeof(buf) - 1, stdin)) { int j; for (j = strlen(buf) - 1; j > 0 && (buf[j] == CR || buf[j] == LF); j--) { buf[j] = '\0'; } if (strncmp(buf, "-trace", 6) == 0) { WWW_TraceFlag = TRUE; } else if (strncmp(buf, "-tlog", 5) == 0) { if (LYUseTraceLog) { LYUseTraceLog = FALSE; } else { LYUseTraceLog = TRUE; } } else if (strncmp(buf, "-anonymous", 10) == 0) { if (!LYValidate && !anon_restrictions_set) parse_restrictions("default"); anon_restrictions_set = TRUE; } else if (strcmp(buf, "-validate") == 0) { /* * Follow only http URLs. */ LYValidate = TRUE;#ifdef SOCKS } else if (strncmp(buf, "-nosocks", 8) == 0) { socks_flag = FALSE;#endif /* SOCKS */ } else if (strncmp(buf, "-cfg", 4) == 0) { if ((cp = strchr(buf,'=')) != NULL) { StrAllocCopy(lynx_cfg_file, cp+1); } else { cp = buf; while (*cp && !isspace((unsigned char)*cp)) cp++; while (*cp && isspace((unsigned char)*cp)) cp++; if (*cp) StrAllocCopy(lynx_cfg_file, cp); }#if defined(USE_HASH) } else if (strncmp(buf, "-lss", 4) == 0) { if ((cp = strchr(buf,'=')) != NULL) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -