Blame src/LYDownload.c

Packit f574b8
/* $LynxId: LYDownload.c,v 1.70 2018/05/11 22:57:30 tom Exp $ */
Packit f574b8
#include <HTUtils.h>
Packit f574b8
#include <HTParse.h>
Packit f574b8
#include <HTList.h>
Packit f574b8
#include <HTAlert.h>
Packit f574b8
#include <LYCurses.h>
Packit f574b8
#include <LYUtils.h>
Packit f574b8
#include <LYGlobalDefs.h>
Packit f574b8
#include <LYStrings.h>
Packit f574b8
#include <LYDownload.h>
Packit f574b8
Packit f574b8
#include <LYLeaks.h>
Packit f574b8
Packit f574b8
/*
Packit f574b8
 * LYDownload takes a URL and downloads it using a user selected download
Packit f574b8
 * program
Packit f574b8
 *
Packit f574b8
 * It parses an incoming link that looks like
Packit f574b8
 *
Packit f574b8
 * LYNXDOWNLOAD://Method=<#>/File=<STRING>/SugFile=<STRING>
Packit f574b8
 */
Packit f574b8
#ifdef VMS
Packit f574b8
BOOLEAN LYDidRename = FALSE;
Packit f574b8
#endif /* VMS */
Packit f574b8
Packit f574b8
static char LYValidDownloadFile[LY_MAXPATH] = "\0";
Packit f574b8
Packit f574b8
void LYDownload(char *line)
Packit f574b8
{
Packit f574b8
    char *Line = NULL, *method, *file, *sug_file = NULL;
Packit f574b8
    int method_number;
Packit f574b8
    int count;
Packit f574b8
    char *the_command = 0;
Packit f574b8
    bstring *buffer = NULL;
Packit f574b8
    bstring *command = NULL;
Packit f574b8
    char *cp;
Packit f574b8
    lynx_list_item_type *download_command = 0;
Packit f574b8
    int ch;
Packit f574b8
    RecallType recall;
Packit f574b8
    int FnameTotal;
Packit f574b8
    int FnameNum;
Packit f574b8
    BOOLEAN FirstRecall = TRUE;
Packit f574b8
    BOOLEAN SecondS = FALSE;
Packit f574b8
Packit f574b8
#ifdef VMS
Packit f574b8
    LYDidRename = FALSE;
Packit f574b8
#endif /* VMS */
Packit f574b8
Packit f574b8
    /*
Packit f574b8
     * Make sure we have a valid download file comparison string loaded via the
Packit f574b8
     * download options menu.  - FM
Packit f574b8
     */
Packit f574b8
    if (LYValidDownloadFile[0] == '\0') {
Packit f574b8
	goto failed;
Packit f574b8
    }
Packit f574b8
Packit f574b8
    /*
Packit f574b8
     * Make a copy of the LYNXDOWNLOAD internal URL for parsing.  - FM
Packit f574b8
     */
Packit f574b8
    if (StrAllocCopy(Line, line) == 0)
Packit f574b8
	goto failed;
Packit f574b8
Packit f574b8
    /*
Packit f574b8
     * Parse out the File, sug_file, and the Method.
Packit f574b8
     */
Packit f574b8
    if ((file = strstr(Line, "/File=")) == NULL)
Packit f574b8
	goto failed;
Packit f574b8
    *file = '\0';
Packit f574b8
    /*
Packit f574b8
     * Go past "File=".
Packit f574b8
     */
Packit f574b8
    file += 6;
Packit f574b8
Packit f574b8
    if ((sug_file = strstr(file + 1, "/SugFile=")) != NULL) {
Packit f574b8
	*sug_file = '\0';
Packit f574b8
	/*
Packit f574b8
	 * Go past "SugFile=".
Packit f574b8
	 */
Packit f574b8
	sug_file += 9;
Packit f574b8
	HTUnEscape(sug_file);
Packit f574b8
    }
Packit f574b8
Packit f574b8
    /*
Packit f574b8
     * Make sure that the file string is the one from the last displayed
Packit f574b8
     * download options menu.  - FM
Packit f574b8
     */
Packit f574b8
    if (strcmp(file, LYValidDownloadFile)) {
Packit f574b8
	goto failed;
Packit f574b8
    }
Packit f574b8
#if defined(DIRED_SUPPORT)
Packit f574b8
    /* FIXME: use HTLocalName */
Packit f574b8
    if (!StrNCmp(file, "file://localhost", 16)) {
Packit f574b8
#ifdef __DJGPP__
Packit f574b8
	if (!StrNCmp(file + 16, "/dev/", 5))
Packit f574b8
	    file += 16;
Packit f574b8
	else {
Packit f574b8
	    file += 17;
Packit f574b8
	    file = HTDOS_name(file);
Packit f574b8
	}
Packit f574b8
#else
Packit f574b8
	file += 16;
Packit f574b8
#endif /* __DJGPP__ */
Packit f574b8
    } else if (isFILE_URL(file))
Packit f574b8
	file += LEN_FILE_URL;
Packit f574b8
    HTUnEscape(file);
Packit f574b8
#else
Packit f574b8
#if defined(_WINDOWS)		/* 1997/10/15 (Wed) 16:27:38 */
Packit f574b8
    if (!StrNCmp(file, "file://localhost/", 17))
Packit f574b8
	file += 17;
Packit f574b8
    else if (!StrNCmp(file, "file:/", 6))
Packit f574b8
	file += 6;
Packit f574b8
    HTUnEscape(file);
Packit f574b8
#endif /* _WINDOWS */
Packit f574b8
#endif /* DIRED_SUPPORT */
Packit f574b8
Packit f574b8
    if ((method = strstr(Line, "Method=")) == NULL)
Packit f574b8
	goto failed;
Packit f574b8
    /*
Packit f574b8
     * Go past "Method=".
Packit f574b8
     */
Packit f574b8
    method += 7;
Packit f574b8
    method_number = atoi(method);
Packit f574b8
Packit f574b8
    /*
Packit f574b8
     * Set up the sug_filenames recall buffer.
Packit f574b8
     */
Packit f574b8
    FnameTotal = (sug_filenames ? HTList_count(sug_filenames) : 0);
Packit f574b8
    recall = ((FnameTotal >= 1) ? RECALL_URL : NORECALL);
Packit f574b8
    FnameNum = FnameTotal;
Packit f574b8
Packit f574b8
    if (method_number < 0) {
Packit f574b8
	/*
Packit f574b8
	 * Write to local file.
Packit f574b8
	 */
Packit f574b8
	_statusline(FILENAME_PROMPT);
Packit f574b8
      retry:
Packit f574b8
	if (sug_file) {
Packit f574b8
	    BStrCopy0(buffer, sug_file);
Packit f574b8
	} else {
Packit f574b8
	    BStrCopy0(buffer, "");
Packit f574b8
	}
Packit f574b8
Packit f574b8
      check_recall:
Packit f574b8
	if ((ch = LYgetBString(&buffer, FALSE, 0, recall)) < 0 ||
Packit f574b8
	    isBEmpty(buffer) ||
Packit f574b8
	    ch == UPARROW_KEY ||
Packit f574b8
	    ch == DNARROW_KEY) {
Packit f574b8
Packit f574b8
	    if (recall && ch == UPARROW_KEY) {
Packit f574b8
		if (FirstRecall) {
Packit f574b8
		    FirstRecall = FALSE;
Packit f574b8
		    /*
Packit f574b8
		     * Use the last Fname in the list.  - FM
Packit f574b8
		     */
Packit f574b8
		    FnameNum = 0;
Packit f574b8
		} else {
Packit f574b8
		    /*
Packit f574b8
		     * Go back to the previous Fname in the list.  - FM
Packit f574b8
		     */
Packit f574b8
		    FnameNum++;
Packit f574b8
		}
Packit f574b8
		if (FnameNum >= FnameTotal) {
Packit f574b8
		    /*
Packit f574b8
		     * Reset the FirstRecall flag, and use sug_file or a blank.
Packit f574b8
		     * - FM
Packit f574b8
		     */
Packit f574b8
		    FirstRecall = TRUE;
Packit f574b8
		    FnameNum = FnameTotal;
Packit f574b8
		    _statusline(FILENAME_PROMPT);
Packit f574b8
		    goto retry;
Packit f574b8
		} else if ((cp = (char *) HTList_objectAt(sug_filenames,
Packit f574b8
							  FnameNum)) != NULL) {
Packit f574b8
		    BStrCopy0(buffer, cp);
Packit f574b8
		    if (FnameTotal == 1) {
Packit f574b8
			_statusline(EDIT_THE_PREV_FILENAME);
Packit f574b8
		    } else {
Packit f574b8
			_statusline(EDIT_A_PREV_FILENAME);
Packit f574b8
		    }
Packit f574b8
		    goto check_recall;
Packit f574b8
		}
Packit f574b8
	    } else if (recall && ch == DNARROW_KEY) {
Packit f574b8
		if (FirstRecall) {
Packit f574b8
		    FirstRecall = FALSE;
Packit f574b8
		    /*
Packit f574b8
		     * Use the first Fname in the list.  - FM
Packit f574b8
		     */
Packit f574b8
		    FnameNum = FnameTotal - 1;
Packit f574b8
		} else {
Packit f574b8
		    /*
Packit f574b8
		     * Advance to the next Fname in the list.  - FM
Packit f574b8
		     */
Packit f574b8
		    FnameNum--;
Packit f574b8
		}
Packit f574b8
		if (FnameNum < 0) {
Packit f574b8
		    /*
Packit f574b8
		     * Set the FirstRecall flag, and use sug_file or a blank.
Packit f574b8
		     * - FM
Packit f574b8
		     */
Packit f574b8
		    FirstRecall = TRUE;
Packit f574b8
		    FnameNum = FnameTotal;
Packit f574b8
		    _statusline(FILENAME_PROMPT);
Packit f574b8
		    goto retry;
Packit f574b8
		} else if ((cp = (char *) HTList_objectAt(sug_filenames,
Packit f574b8
							  FnameNum)) != NULL) {
Packit f574b8
		    BStrCopy0(buffer, cp);
Packit f574b8
		    if (FnameTotal == 1) {
Packit f574b8
			_statusline(EDIT_THE_PREV_FILENAME);
Packit f574b8
		    } else {
Packit f574b8
			_statusline(EDIT_A_PREV_FILENAME);
Packit f574b8
		    }
Packit f574b8
		    goto check_recall;
Packit f574b8
		}
Packit f574b8
	    }
Packit f574b8
Packit f574b8
	    /*
Packit f574b8
	     * Save cancelled.
Packit f574b8
	     */
Packit f574b8
	    goto cancelled;
Packit f574b8
	}
Packit f574b8
Packit f574b8
	BStrCopy(command, buffer);
Packit f574b8
	if (!LYValidateFilename(&buffer, &command))
Packit f574b8
	    goto cancelled;
Packit f574b8
#ifdef HAVE_POPEN
Packit f574b8
	else if (LYIsPipeCommand(buffer->str)) {
Packit f574b8
	    /* I don't know how to download to a pipe */
Packit f574b8
	    HTAlert(CANNOT_WRITE_TO_FILE);
Packit f574b8
	    _statusline(NEW_FILENAME_PROMPT);
Packit f574b8
	    FirstRecall = TRUE;
Packit f574b8
	    FnameNum = FnameTotal;
Packit f574b8
	    goto retry;
Packit f574b8
	}
Packit f574b8
#endif
Packit f574b8
Packit f574b8
	/*
Packit f574b8
	 * See if it already exists.
Packit f574b8
	 */
Packit f574b8
	switch (LYValidateOutput(buffer->str)) {
Packit f574b8
	case 'Y':
Packit f574b8
	    break;
Packit f574b8
	case 'N':
Packit f574b8
	    _statusline(NEW_FILENAME_PROMPT);
Packit f574b8
	    FirstRecall = TRUE;
Packit f574b8
	    FnameNum = FnameTotal;
Packit f574b8
	    goto retry;
Packit f574b8
	default:
Packit f574b8
	    goto cleanup;
Packit f574b8
	}
Packit f574b8
Packit f574b8
	/*
Packit f574b8
	 * See if we can write to it.
Packit f574b8
	 */
Packit f574b8
	CTRACE((tfp, "LYDownload: filename is %s\n", buffer->str));
Packit f574b8
Packit f574b8
	SecondS = TRUE;
Packit f574b8
Packit f574b8
	HTInfoMsg(SAVING);
Packit f574b8
#ifdef VMS
Packit f574b8
	/*
Packit f574b8
	 * Try rename() first.  - FM
Packit f574b8
	 */
Packit f574b8
	CTRACE((tfp, "command: rename(%s, %s)\n", file, buffer->str));
Packit f574b8
	if (rename(file, buffer->str)) {
Packit f574b8
	    /*
Packit f574b8
	     * Failed.  Use spawned COPY_COMMAND.  - FM
Packit f574b8
	     */
Packit f574b8
	    CTRACE((tfp, "         FAILED!\n"));
Packit f574b8
	    LYCopyFile(file, buffer->str);
Packit f574b8
	} else {
Packit f574b8
	    /*
Packit f574b8
	     * We don't have the temporary file (it was renamed to a permanent
Packit f574b8
	     * file), so set a flag to pop out of the download menu.  - FM
Packit f574b8
	     */
Packit f574b8
	    LYDidRename = TRUE;
Packit f574b8
	}
Packit f574b8
	chmod(buffer->str, HIDE_CHMOD);
Packit f574b8
#else /* Unix: */
Packit f574b8
Packit f574b8
	LYCopyFile(file, buffer->str);
Packit f574b8
	LYRelaxFilePermissions(buffer->str);
Packit f574b8
#endif /* VMS */
Packit f574b8
Packit f574b8
    } else {
Packit f574b8
	/*
Packit f574b8
	 * Use configured download commands.
Packit f574b8
	 */
Packit f574b8
	BStrCopy0(buffer, "");
Packit f574b8
	for (count = 0, download_command = downloaders;
Packit f574b8
	     count < method_number;
Packit f574b8
	     count++, download_command = download_command->next) ;	/* null body */
Packit f574b8
Packit f574b8
	/*
Packit f574b8
	 * Commands have the form "command %s [etc]" where %s is the filename.
Packit f574b8
	 */
Packit f574b8
	if (download_command->command != NULL) {
Packit f574b8
	    /*
Packit f574b8
	     * Check for two '%s' and ask for the local filename if there is.
Packit f574b8
	     */
Packit f574b8
	    if (HTCountCommandArgs(download_command->command) >= 2) {
Packit f574b8
		_statusline(FILENAME_PROMPT);
Packit f574b8
Packit f574b8
	      again:
Packit f574b8
		if (sug_file) {
Packit f574b8
		    BStrCopy0(buffer, sug_file);
Packit f574b8
		} else {
Packit f574b8
		    BStrCopy0(buffer, "");
Packit f574b8
		}
Packit f574b8
Packit f574b8
	      check_again:
Packit f574b8
		if ((ch = LYgetBString(&buffer, FALSE, 0, recall)) < 0 ||
Packit f574b8
		    isBEmpty(buffer) ||
Packit f574b8
		    ch == UPARROW_KEY ||
Packit f574b8
		    ch == DNARROW_KEY) {
Packit f574b8
Packit f574b8
		    if (recall && ch == UPARROW_KEY) {
Packit f574b8
			if (FirstRecall) {
Packit f574b8
			    FirstRecall = FALSE;
Packit f574b8
			    /*
Packit f574b8
			     * Use the last Fname in the list.  - FM
Packit f574b8
			     */
Packit f574b8
			    FnameNum = 0;
Packit f574b8
			} else {
Packit f574b8
			    /*
Packit f574b8
			     * Go back to the previous Fname in the list.  - FM
Packit f574b8
			     */
Packit f574b8
			    FnameNum++;
Packit f574b8
			}
Packit f574b8
			if (FnameNum >= FnameTotal) {
Packit f574b8
			    /*
Packit f574b8
			     * Reset the FirstRecall flag, and use sug_file or
Packit f574b8
			     * a blank.  - FM
Packit f574b8
			     */
Packit f574b8
			    FirstRecall = TRUE;
Packit f574b8
			    FnameNum = FnameTotal;
Packit f574b8
			    _statusline(FILENAME_PROMPT);
Packit f574b8
			    goto again;
Packit f574b8
			} else if ((cp = (char *) HTList_objectAt(sug_filenames,
Packit f574b8
								  FnameNum))
Packit f574b8
				   != NULL) {
Packit f574b8
			    BStrCopy0(buffer, cp);
Packit f574b8
			    if (FnameTotal == 1) {
Packit f574b8
				_statusline(EDIT_THE_PREV_FILENAME);
Packit f574b8
			    } else {
Packit f574b8
				_statusline(EDIT_A_PREV_FILENAME);
Packit f574b8
			    }
Packit f574b8
			    goto check_again;
Packit f574b8
			}
Packit f574b8
		    } else if (recall && ch == DNARROW_KEY) {
Packit f574b8
			if (FirstRecall) {
Packit f574b8
			    FirstRecall = FALSE;
Packit f574b8
			    /*
Packit f574b8
			     * Use the first Fname in the list.  - FM
Packit f574b8
			     */
Packit f574b8
			    FnameNum = FnameTotal - 1;
Packit f574b8
			} else {
Packit f574b8
			    /*
Packit f574b8
			     * Advance to the next Fname in the list.  - FM
Packit f574b8
			     */
Packit f574b8
			    FnameNum--;
Packit f574b8
			}
Packit f574b8
			if (FnameNum < 0) {
Packit f574b8
			    /*
Packit f574b8
			     * Set the FirstRecall flag, and use sug_file or a
Packit f574b8
			     * blank.  - FM
Packit f574b8
			     */
Packit f574b8
			    FirstRecall = TRUE;
Packit f574b8
			    FnameNum = FnameTotal;
Packit f574b8
			    _statusline(FILENAME_PROMPT);
Packit f574b8
			    goto again;
Packit f574b8
			} else if ((cp = (char *) HTList_objectAt(sug_filenames,
Packit f574b8
								  FnameNum))
Packit f574b8
				   != NULL) {
Packit f574b8
			    BStrCopy0(buffer, cp);
Packit f574b8
			    if (FnameTotal == 1) {
Packit f574b8
				_statusline(EDIT_THE_PREV_FILENAME);
Packit f574b8
			    } else {
Packit f574b8
				_statusline(EDIT_A_PREV_FILENAME);
Packit f574b8
			    }
Packit f574b8
			    goto check_again;
Packit f574b8
			}
Packit f574b8
		    }
Packit f574b8
Packit f574b8
		    /*
Packit f574b8
		     * Download cancelled.
Packit f574b8
		     */
Packit f574b8
		    goto cancelled;
Packit f574b8
		}
Packit f574b8
Packit f574b8
		if (no_dotfiles || !show_dotfiles) {
Packit f574b8
		    if (*LYPathLeaf(buffer->str) == '.') {
Packit f574b8
			HTAlert(FILENAME_CANNOT_BE_DOT);
Packit f574b8
			_statusline(NEW_FILENAME_PROMPT);
Packit f574b8
			goto again;
Packit f574b8
		    }
Packit f574b8
		}
Packit f574b8
		/*
Packit f574b8
		 * Cancel if the user entered "/dev/null" on Unix, or an "nl:"
Packit f574b8
		 * path on VMS.  - FM
Packit f574b8
		 */
Packit f574b8
		if (LYIsNullDevice(buffer->str)) {
Packit f574b8
		    goto cancelled;
Packit f574b8
		}
Packit f574b8
		SecondS = TRUE;
Packit f574b8
	    }
Packit f574b8
Packit f574b8
	    /*
Packit f574b8
	     * The following is considered a bug by the community.  If the
Packit f574b8
	     * command only takes one argument on the command line, then the
Packit f574b8
	     * suggested file name is not used.  It actually is not a bug at
Packit f574b8
	     * all and does as it should, putting both names on the command
Packit f574b8
	     * line.
Packit f574b8
	     */
Packit f574b8
	    count = 1;
Packit f574b8
	    HTAddParam(&the_command, download_command->command, count, file);
Packit f574b8
	    if (HTCountCommandArgs(download_command->command) > 1)
Packit f574b8
		HTAddParam(&the_command, download_command->command, ++count, buffer->str);
Packit f574b8
	    HTEndParam(&the_command, download_command->command, count);
Packit f574b8
Packit f574b8
	} else {
Packit f574b8
	    HTAlert(MISCONF_DOWNLOAD_COMMAND);
Packit f574b8
	    goto failed;
Packit f574b8
	}
Packit f574b8
Packit f574b8
	CTRACE((tfp, "command: %s\n", the_command));
Packit f574b8
	stop_curses();
Packit f574b8
	LYSystem(the_command);
Packit f574b8
	FREE(the_command);
Packit f574b8
	start_curses();
Packit f574b8
	/* don't remove(file); */
Packit f574b8
    }
Packit f574b8
Packit f574b8
    if (SecondS == TRUE) {
Packit f574b8
#ifdef VMS
Packit f574b8
	if (0 == strncasecomp(buffer->str, "sys$disk:", 9)) {
Packit f574b8
	    if (0 == StrNCmp((buffer->str + 9), "[]", 2)) {
Packit f574b8
		HTAddSugFilename(buffer->str + 11);
Packit f574b8
	    } else {
Packit f574b8
		HTAddSugFilename(buffer->str + 9);
Packit f574b8
	    }
Packit f574b8
	} else {
Packit f574b8
	    HTAddSugFilename(buffer->str);
Packit f574b8
	}
Packit f574b8
#else
Packit f574b8
	HTAddSugFilename(buffer->str);
Packit f574b8
#endif /* VMS */
Packit f574b8
    }
Packit f574b8
    goto cleanup;
Packit f574b8
Packit f574b8
  failed:
Packit f574b8
    HTAlert(CANNOT_DOWNLOAD_FILE);
Packit f574b8
    goto cleanup;
Packit f574b8
Packit f574b8
  cancelled:
Packit f574b8
    HTInfoMsg(CANCELLING);
Packit f574b8
Packit f574b8
  cleanup:
Packit f574b8
    FREE(Line);
Packit f574b8
    BStrFree(buffer);
Packit f574b8
    return;
Packit f574b8
}
Packit f574b8
Packit f574b8
/*
Packit f574b8
 * Compare a filename with a given suffix, which we have set to give a rough
Packit f574b8
 * idea of its content.
Packit f574b8
 */
Packit f574b8
static int SuffixIs(char *filename, const char *suffix)
Packit f574b8
{
Packit f574b8
    size_t have = strlen(filename);
Packit f574b8
    size_t need = strlen(suffix);
Packit f574b8
Packit f574b8
    return have > need && !strcmp(filename + have - need, suffix);
Packit f574b8
}
Packit f574b8
Packit f574b8
/*
Packit f574b8
 * LYdownload_options writes out the current download choices to a file so that
Packit f574b8
 * the user can select downloaders in the same way that they select all other
Packit f574b8
 * links.  Download links look like:
Packit f574b8
 * LYNXDOWNLOAD://Method=<#>/File=<STRING>/SugFile=<STRING>
Packit f574b8
 */
Packit f574b8
int LYdownload_options(char **newfile, char *data_file)
Packit f574b8
{
Packit f574b8
    static char tempfile[LY_MAXPATH] = "\0";
Packit f574b8
    char *downloaded_url = NULL;
Packit f574b8
    char *sug_filename = NULL;
Packit f574b8
    FILE *fp0;
Packit f574b8
    lynx_list_item_type *cur_download;
Packit f574b8
    int count;
Packit f574b8
Packit f574b8
    /*
Packit f574b8
     * Get a suggested filename.
Packit f574b8
     */
Packit f574b8
    StrAllocCopy(sug_filename, *newfile);
Packit f574b8
    change_sug_filename(sug_filename);
Packit f574b8
Packit f574b8
    if ((fp0 = InternalPageFP(tempfile, TRUE)) == 0)
Packit f574b8
	return (-1);
Packit f574b8
Packit f574b8
    StrAllocCopy(downloaded_url, *newfile);
Packit f574b8
    LYLocalFileToURL(newfile, tempfile);
Packit f574b8
Packit f574b8
    LYStrNCpy(LYValidDownloadFile,
Packit f574b8
	      data_file,
Packit f574b8
	      (sizeof(LYValidDownloadFile) - 1));
Packit f574b8
    LYforce_no_cache = TRUE;	/* don't cache this doc */
Packit f574b8
Packit f574b8
    BeginInternalPage(fp0, DOWNLOAD_OPTIONS_TITLE, DOWNLOAD_OPTIONS_HELP);
Packit f574b8
Packit f574b8
    fprintf(fp0, "
\n");
Packit f574b8
    fprintf(fp0, "%s %s\n",
Packit f574b8
	    gettext("Downloaded link:"),
Packit f574b8
	    downloaded_url);
Packit f574b8
    FREE(downloaded_url);
Packit f574b8
Packit f574b8
    fprintf(fp0, "%s %s\n",
Packit f574b8
	    gettext("Suggested file name:"),
Packit f574b8
	    sug_filename);
Packit f574b8
Packit f574b8
    fprintf(fp0, "\n%s\n",
Packit f574b8
	    (user_mode == NOVICE_MODE)
Packit f574b8
	    ? gettext("Standard download options:")
Packit f574b8
	    : gettext("Download options:"));
Packit f574b8
Packit f574b8
    if (!no_disk_save) {
Packit f574b8
#if defined(DIRED_SUPPORT)
Packit f574b8
	/*
Packit f574b8
	 * Disable save to disk option for local files.
Packit f574b8
	 */
Packit f574b8
	if (!lynx_edit_mode)
Packit f574b8
#endif /* DIRED_SUPPORT */
Packit f574b8
	{
Packit f574b8
	    fprintf(fp0,
Packit f574b8
		    "   %s\n",
Packit f574b8
		    STR_LYNXDOWNLOAD,
Packit f574b8
		    data_file,
Packit f574b8
		    NonNull(lynx_save_space),
Packit f574b8
		    sug_filename,
Packit f574b8
		    gettext("Save to disk"));
Packit f574b8
	    /*
Packit f574b8
	     * If it is not a binary file, offer the opportunity to view the
Packit f574b8
	     * downloaded temporary file (see HTSaveToFile).
Packit f574b8
	     */
Packit f574b8
	    if (SuffixIs(data_file, HTML_SUFFIX)
Packit f574b8
		|| SuffixIs(data_file, TEXT_SUFFIX)) {
Packit f574b8
		char *target = NULL;
Packit f574b8
		char *source = LYAddPathToSave(data_file);
Packit f574b8
Packit f574b8
		LYLocalFileToURL(&target, source);
Packit f574b8
		fprintf(fp0,
Packit f574b8
			"   %s\n",
Packit f574b8
			target,
Packit f574b8
			gettext("View temporary file"));
Packit f574b8
Packit f574b8
		FREE(source);
Packit f574b8
		FREE(target);
Packit f574b8
	    }
Packit f574b8
	}
Packit f574b8
    } else {
Packit f574b8
	fprintf(fp0, "   %s\n", gettext("Save to disk disabled."));
Packit f574b8
    }
Packit f574b8
Packit f574b8
    if (user_mode == NOVICE_MODE)
Packit f574b8
	fprintf(fp0, "\n%s\n", gettext("Local additions:"));
Packit f574b8
Packit f574b8
    if (downloaders != NULL) {
Packit f574b8
	for (count = 0, cur_download = downloaders; cur_download != NULL;
Packit f574b8
	     cur_download = cur_download->next, count++) {
Packit f574b8
	    if (!no_download || cur_download->always_enabled) {
Packit f574b8
		fprintf(fp0,
Packit f574b8
			"   ",
Packit f574b8
			STR_LYNXDOWNLOAD, count, data_file, sug_filename);
Packit f574b8
		fprintf(fp0, "%s", (cur_download->name
Packit f574b8
				    ? cur_download->name
Packit f574b8
				    : gettext("No Name Given")));
Packit f574b8
		fprintf(fp0, "\n");
Packit f574b8
	    }
Packit f574b8
	}
Packit f574b8
    }
Packit f574b8
Packit f574b8
    fprintf(fp0, "\n");
Packit f574b8
    EndInternalPage(fp0);
Packit f574b8
    LYCloseTempFP(fp0);
Packit f574b8
    LYRegisterUIPage(*newfile, UIP_DOWNLOAD_OPTIONS);
Packit f574b8
Packit f574b8
    /*
Packit f574b8
     * Free off temp copy.
Packit f574b8
     */
Packit f574b8
    FREE(sug_filename);
Packit f574b8
Packit f574b8
    return (0);
Packit f574b8
}