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

📄 lydownload.c

📁 基于rtos开发的浏览器!
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "HTUtils.h"#include "tcp.h"#include "HTParse.h"#include "HTList.h"#include "HTAlert.h"#include "LYCurses.h"#include "LYUtils.h"#include "LYGlobalDefs.h"#include "LYSignal.h"#include "LYStrings.h"#include "LYClean.h"#include "LYGetFile.h"#include "LYDownload.h"#include "LYSystem.h"#ifdef VMS#include "HTVMSUtils.h"#endif /* VMS */#ifdef DOSPATH#include "HTDOS.h"#endif#include "LYexit.h"#include "LYLeaks.h"#define FREE(x) if (x) {free(x); x = NULL;}/* *  LYDownload takes a URL and downloads it using a user selected *  download program * *  It parses an incoming link that looks like * *  LYNXDOWNLOAD://Method=<#>/File=<STRING>/SugFile=<STRING> */#ifdef VMS#define COPY_COMMAND "copy/nolog/noconf %s %s"PUBLIC BOOLEAN LYDidRename = FALSE;#endif /* VMS */PRIVATE char LYValidDownloadFile[256] = "\0";PUBLIC void LYDownload ARGS1(	char *, 	line){    char *Line = NULL, *method, *file, *sug_file = NULL;    int method_number;    int count;    char buffer[512];    char command[512];    char *cp, *cp1;    lynx_html_item_type *download_command = 0;    int c, len;    FILE *fp;    int ch, recall;    int FnameTotal;    int FnameNum;    BOOLEAN FirstRecall = TRUE;    BOOLEAN SecondS = FALSE;#ifdef VMS    extern BOOLEAN HadVMSInterrupt;    LYDidRename = FALSE;#endif /* VMS */    /*     *	Make sure we have a valid download     *	file comparison string loaded via     *	the download options menu. - FM     */    if (LYValidDownloadFile[0] == '\0') {	goto failed;    }    /*     *	Make a copy of the LYNXDOWNLOAD     *	internal URL for parsing. - FM     */    StrAllocCopy(Line, line);    /*     *	Parse out the sug_file, Method and the File.     */    if ((sug_file = (char *)strstr(Line, "SugFile=")) != NULL) {	*(sug_file-1) = '\0';	/*	 *  Go past "SugFile=".	 */	sug_file += 8;    }    if ((file = (char *)strstr(Line, "File=")) == NULL)	goto failed;    *(file-1) = '\0';    /*     *	Go past "File=".     */    file += 5;    /*     *	Make sure that the file string is the one from     *	the last displayed download options menu. - FM     */    if (strcmp(file, LYValidDownloadFile)) {	goto failed;    }#ifdef DIRED_SUPPORT    if (!strncmp(file, "file://localhost", 16))	file += 16;    else if (!strncmp(file, "file:", 5))	file += 5;    HTUnEscape(file);#endif /* DIRED_SUPPORT */    if ((method = (char *)strstr(Line, "Method=")) == NULL)	goto failed;    /*     *	Go past "Method=".     */    method += 7;    method_number = atoi(method);    /*     *	Set up the sug_filenames recall buffer.     */    FnameTotal = (sug_filenames ? HTList_count(sug_filenames) : 0);    recall = ((FnameTotal >= 1) ? RECALL : NORECALL);    FnameNum = FnameTotal;    if (method_number < 0) {	/*	 *  Write to local file.	 */	_statusline(FILENAME_PROMPT);retry:	if (sug_file)	    LYstrncpy(buffer, sug_file, ((sizeof(buffer)/2) - 1));	else	    *buffer = '\0';check_recall:	if ((ch = LYgetstr(buffer,			   VISIBLE, (sizeof(buffer)/2), recall)) < 0 ||	    *buffer == '\0' || ch == UPARROW || ch == DNARROW) {	    if (recall && ch == UPARROW) {		if (FirstRecall) {		    FirstRecall = FALSE;		    /*		     *	Use the last Fname in the list. - FM		     */		    FnameNum = 0;		} else {		    /*		     *	Go back to the previous Fname in the list. - FM		     */		    FnameNum++;		}		if (FnameNum >= FnameTotal) {		    /*		     *	Reset the FirstRecall flag,		     *	and use sug_file or a blank. - FM		     */		    FirstRecall = TRUE;		    FnameNum = FnameTotal;		    _statusline(FILENAME_PROMPT);		    goto retry;		} else if ((cp = (char *)HTList_objectAt(						sug_filenames,						FnameNum)) != NULL) {		    strcpy(buffer, cp);		    if (FnameTotal == 1) {			_statusline(EDIT_THE_PREV_FILENAME);		    } else {			_statusline(EDIT_A_PREV_FILENAME);		    }		    goto check_recall;		}	    } else if (recall && ch == DNARROW) {		if (FirstRecall) {		    FirstRecall = FALSE;		    /*		     *	Use the first Fname in the list. - FM		     */		    FnameNum = FnameTotal - 1;		} else {		    /*		     *	Advance to the next Fname in the list. - FM		     */		    FnameNum--;		}		if (FnameNum < 0) {		    /*		     *	Set the FirstRecall flag,		     *	and use sug_file or a blank. - FM		     */		    FirstRecall = TRUE;		    FnameNum = FnameTotal;		    _statusline(FILENAME_PROMPT);		    goto retry;		} else if ((cp = (char *)HTList_objectAt(						sug_filenames,						FnameNum)) != NULL) {		    strcpy(buffer, cp);		    if (FnameTotal == 1) {			_statusline(EDIT_THE_PREV_FILENAME);		    } else {			_statusline(EDIT_A_PREV_FILENAME);		    }		    goto check_recall;		}	    }	    /*	     *	Save cancelled.	     */	    goto cancelled;	}	if (no_dotfiles || !show_dotfiles) {	  if (*buffer == '.' ||#ifdef VMS	      ((cp = strrchr(buffer, ':')) && *(cp+1) == '.') ||	      ((cp = strrchr(buffer, ']')) && *(cp+1) == '.') ||#endif /* VMS */	      ((cp = strrchr(buffer, '/')) && *(cp+1) == '.')) {		HTAlert(FILENAME_CANNOT_BE_DOT);		_statusline(NEW_FILENAME_PROMPT);		FirstRecall = TRUE;		FnameNum = FnameTotal;		goto retry;	  }	}	/*	 *  Cancel if the user entered "/dev/null" on Unix,	 *  or an "nl:" path (case-insensitive) on VMS. - FM	 */#ifdef VMS	if (!strncasecomp(buffer, "nl:", 3) ||	    !strncasecomp(buffer, "/nl/", 4))#else	if (!strcmp(buffer, "/dev/null"))#endif /* VMS */	{	    goto cancelled;	}	if ((cp = strchr(buffer, '~'))) {	    *(cp++) = '\0';	    strcpy(command, buffer);	    if ((len = strlen(command)) > 0 && command[len-1] == '/')		command[len-1] = '\0';#ifdef DOSPATH	    strcat(command, HTDOS_wwwName((char *)Home_Dir()));#else#ifdef VMS	    strcat(command, HTVMS_wwwName((char *)Home_Dir()));#else	    strcat(command, Home_Dir());#endif /* VMS */#endif /* DOSPATH */	    strcat(command, cp);	    strcpy(buffer, command);	}#ifdef VMS	if (strchr(buffer, '/') != NULL) {	    strcpy(command, HTVMS_name("", buffer));	    strcpy(buffer, command);	}	if (buffer[0] != '/' && strchr(buffer, ':') == NULL) {	    strcpy(command, "sys$disk:");	    if (strchr(buffer, ']') == NULL)		strcat(command, "[]");	    strcat(command, buffer);	    strcpy(buffer, command);	}#else	if (*buffer != '/')	    cp = getenv("PWD");	else	    cp = NULL;	if (cp) {	    sprintf(command, "%s/%s", cp, buffer);#ifdef DOSPATH	    strcpy(buffer, HTDOS_name(command));#else	    strcpy(buffer, command);#endif	}#endif /* VMS */	/*	 *  See if it already exists.	 */	if ((fp = fopen(buffer, "r")) != NULL) {	    fclose(fp);#ifdef VMS	    _statusline(FILE_EXISTS_HPROMPT);#else	    _statusline(FILE_EXISTS_OPROMPT);#endif /* VMS */	    c = 0;	    while(TOUPPER(c)!='Y' && TOUPPER(c)!='N' && c != 7 && c != 3)		c = LYgetch();#ifdef VMS	    if (HadVMSInterrupt) {		HadVMSInterrupt = FALSE;		FREE(Line);		return;	    }#endif /* VMS */	    if (c == 7 || c == 3) { /* Control-G or Control-C */		goto cancelled;	    }	    if (TOUPPER(c) == 'N') {		_statusline(NEW_FILENAME_PROMPT);		FirstRecall = TRUE;		FnameNum = FnameTotal;		goto retry;	    }	}	/*	 *  See if we can write to it.	 */	if ((fp = fopen(buffer, "w")) != NULL) {	    fclose(fp);	    remove(buffer);	} else {	    HTAlert(CANNOT_WRITE_TO_FILE);	    _statusline(NEW_FILENAME_PROMPT);	    FirstRecall = TRUE;	    FnameNum = FnameTotal;	    goto retry;	}	SecondS = TRUE;	_statusline(SAVING);	sleep(InfoSecs);#ifdef VMS	/*	 *  Try rename() first. - FM	 */	if (TRACE)	    fprintf(stderr, "command: rename(%s, %s)\n", file, buffer);	if (rename(file, buffer)) {	    /*	     *	Failed.  Use spawned COPY_COMMAND. - FM	     */	    if (TRACE)		fprintf(stderr, "         FAILED!\n");

⌨️ 快捷键说明

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