📄 htfwriter.c
字号:
} } FREE(WWW_Download_File); FREE(me);}/* Structured Object Class** -----------------------*/PRIVATE CONST HTStreamClass HTFWriter = /* As opposed to print etc */{ "FileWriter", HTFWriter_free, HTFWriter_abort, HTFWriter_put_character, HTFWriter_put_string, HTFWriter_write};/* Subclass-specific Methods** -------------------------*/PUBLIC HTStream* HTFWriter_new ARGS1(FILE *, fp){ HTStream* me; if (!fp) return NULL; me = (HTStream*)calloc(sizeof(*me),1); if (me == NULL) outofmem(__FILE__, "HTFWriter_new"); me->isa = &HTFWriter; me->fp = fp; me->end_command = NULL; me->remove_command = NULL; me->anchor = NULL; me->sink = NULL; return me;}/* Make system command from template** ---------------------------------**** See mailcap spec for description of template.*//* @@ to be written. sprintfs will do for now. */#ifndef VMS#define REMOVE_COMMAND "/bin/rm -f %s"#else#define REMOVE_COMMAND "delete/noconfirm/nolog %s;"#endif /* VMS *//* Take action using a system command** ----------------------------------**** originally from Ghostview handling by Marc Andreseen.** Creates temporary file, writes to it, executes system command** on end-document. The suffix of the temp file can be given** in case the application is fussy, or so that a generic opener can** be used.*/PUBLIC HTStream* HTSaveAndExecute ARGS3( HTPresentation *, pres, HTParentAnchor *, anchor, HTStream *, sink){ char fnam[256]; CONST char *suffix; char *cp; HTStream* me; FILE *fp = NULL; if (traversal) { LYCancelledFetch = TRUE; return(NULL); }#if defined(EXEC_LINKS) || defined(EXEC_SCRIPTS) if (pres->quality == 999.0) { /* exec link */ if (dump_output_immediately) { LYCancelledFetch = TRUE; return(NULL); } if (no_exec) { _statusline(EXECUTION_DISABLED); sleep(AlertSecs); return HTPlainPresent(pres, anchor, sink); } if (!local_exec) if (local_exec_on_local_files && (LYJumpFileURL || !strncmp(anchor->address,"file://localhost",16))) { /* allow it to continue */ } else { char buf[512]; sprintf(buf, EXECUTION_DISABLED_FOR_FILE, key_for_func(LYK_OPTIONS)); _statusline(buf); sleep(AlertSecs); return HTPlainPresent(pres, anchor, sink); } }#endif /* EXEC_LINKS || EXEC_SCRIPTS */ if (dump_output_immediately) { return(HTSaveToFile(pres, anchor, sink)); } me = (HTStream*)calloc(sizeof(*me),1); if (me == NULL) outofmem(__FILE__, "HTSaveAndExecute"); me->isa = &HTFWriter; me->input_format = pres->rep; me->output_format = pres->rep_out; me->anchor = anchor; me->sink = sink; if (anchor->FileCache) { strcpy(fnam, anchor->FileCache); FREE(anchor->FileCache); if ((fp = fopen(fnam, "r")) != NULL) { fclose(fp); fp = NULL; remove(fnam); } } else { /* * Lynx routine to create a temporary filename */SaveAndExecute_tempname: tempname (fnam, NEW_FILE); /* * Check for a suffix. */ if (((cp = strrchr(fnam, '.')) != NULL) &&#ifdef VMS NULL == strchr(cp, ']') &&#endif /* VMS */ NULL == strchr(cp, '/')) { /* * Save the file under a suitably suffixed name. */ *cp = '\0'; if (!strcasecomp(pres->rep->name, "text/html")) { strcat(fnam, HTML_SUFFIX); } else if (!strcasecomp(pres->rep->name, "text/plain")) { strcat(fnam, ".txt"); } else if (!strcasecomp(pres->rep->name, "application/octet-stream")) { strcat(fnam, ".bin"); } else if ((suffix = HTFileSuffix(pres->rep, anchor->content_encoding)) && *suffix == '.') { strcat(fnam, suffix); /* * It's not one of the suffixes checked for a * spoof in tempname(), so check it now. - FM */ if (strcmp(suffix, HTML_SUFFIX) && strcmp(suffix, ".txt") && strcmp(suffix, ".bin") && (fp = fopen(fnam, "r")) != NULL) { fclose(fp); fp = NULL; goto SaveAndExecute_tempname; } } else { *cp = '.'; } } } me->fp = LYNewBinFile (fnam); if (!me->fp) { HTAlert(CANNOT_OPEN_TEMP); FREE(me); return NULL; } StrAllocCopy(me->viewer_command, pres->command); /* * Make command to process file. */ me->end_command = (char *)calloc ( (strlen (pres->command) + 10 + strlen(fnam)) * sizeof (char),1); if (me->end_command == NULL) outofmem(__FILE__, "HTSaveAndExecute"); sprintf(me->end_command, pres->command, fnam, "", "", "", "", "", ""); /* * Make command to delete file. */ me->remove_command = (char *)calloc ( (strlen (REMOVE_COMMAND) + 10 + strlen(fnam)) * sizeof (char),1); if (me->remove_command == NULL) outofmem(__FILE__, "HTSaveAndExecute"); sprintf(me->remove_command, REMOVE_COMMAND, fnam); StrAllocCopy(anchor->FileCache, fnam); return me;}/* Format Converter using system command** -------------------------------------*//* @@@@@@@@@@@@@@@@@@@@@@ *//* Save to a local file LJM!!!** --------------------**** usually a binary file that can't be displayed**** originally from Ghostview handling by Marc Andreseen.** Asks the user if he wants to continue, creates a temporary** file, and writes to it. In HTSaveToFile_Free** the user will see a list of choices for download*/PUBLIC HTStream* HTSaveToFile ARGS3( HTPresentation *, pres, HTParentAnchor *, anchor, HTStream *, sink){ HTStream * ret_obj; char fnam[256]; CONST char * suffix; char *cp; int c=0; BOOL IsBinary = TRUE; FILE *fp = NULL; ret_obj = (HTStream*)calloc(sizeof(* ret_obj),1); if (ret_obj == NULL) outofmem(__FILE__, "HTSaveToFile"); ret_obj->isa = &HTFWriter; ret_obj->remove_command = NULL; ret_obj->end_command = NULL; ret_obj->input_format = pres->rep; ret_obj->output_format = pres->rep_out; ret_obj->anchor = anchor; ret_obj->sink = sink; if (dump_output_immediately) { ret_obj->fp = stdout; /* stdout*/ if (HTOutputFormat == HTAtom_for("www/download")) goto Prepend_BASE; return ret_obj; } LYCancelDownload = FALSE; if (HTOutputFormat != HTAtom_for("www/download")) { if (traversal || (no_download && !override_no_download && no_disk_save)) { if (!traversal) { _statusline(CANNOT_DISPLAY_FILE); sleep(AlertSecs); } LYCancelDownload = TRUE; if (traversal) LYCancelledFetch = TRUE; FREE(ret_obj); return(NULL); } if (((cp=strchr((char *)pres->rep->name, ';')) != NULL) && strstr((cp+1), "charset") != NULL) { _user_message(WRONG_CHARSET_D_OR_C, (char *)pres->rep->name); } else if (*((char *)pres->rep->name) != '\0') { _user_message(UNMAPPED_TYPE_D_OR_C, (char *)pres->rep->name); } else { _statusline(CANNOT_DISPLAY_FILE_D_OR_C); } while(TOUPPER(c)!='C' && TOUPPER(c)!='D' && c!=7) { c=LYgetch();#ifdef VMS /* * 'C'ancel on Control-C or Control-Y and * a 'N'o to the "really exit" query. - FM */ if (HadVMSInterrupt) { HadVMSInterrupt = FALSE; c = 'C'; }#endif /* VMS */ } /* * Cancel on 'C', 'c' or Control-G or Control-C. */ if (TOUPPER(c)=='C' || c==7 || c==3) { _statusline(CANCELLING_FILE); LYCancelDownload = TRUE; FREE(ret_obj); return(NULL); } } /* * Set up a 'D'ownload. */ if (anchor->FileCache) { strcpy(fnam, anchor->FileCache); FREE(anchor->FileCache); if ((fp = fopen(fnam, "r")) != NULL) { fclose(fp); fp = NULL; remove(fnam); } } else { /* * Lynx routine to create a temporary filename */SaveToFile_tempname: tempname(fnam, NEW_FILE); /* * Check for a suffix. */ if (((cp=strrchr(fnam, '.')) != NULL) &&#ifdef VMS NULL == strchr(cp, ']') &&#endif /* VMS */ NULL == strchr(cp, '/')) { /* * Save the file under a suitably suffixed name. */ *cp = '\0'; if (!strcasecomp(pres->rep->name, "text/html")) { strcat(fnam, HTML_SUFFIX); } else if (!strcasecomp(pres->rep->name, "text/plain")) { strcat(fnam, ".txt"); } else if (!strcasecomp(pres->rep->name, "application/octet-stream")) { strcat(fnam, ".bin"); } else if ((suffix = HTFileSuffix(pres->rep, anchor->content_encoding)) && *suffix == '.') { strcat(fnam, suffix); /* * It's not one of the suffixes checked for a * spoof in tempname(), so check it now. - FM */ if (strcmp(suffix, HTML_SUFFIX) && strcmp(suffix, ".txt") && strcmp(suffix, ".bin") && (fp = fopen(fnam, "r")) != NULL) { fclose(fp); fp = NULL; goto SaveToFile_tempname; } } else { *cp = '.'; } } } if (0==strncasecomp(pres->rep->name, "text/", 5) || 0==strcasecomp(pres->rep->name, "application/postscript") || 0==strcasecomp(pres->rep->name, "application/x-RUNOFF-MANUAL")) /* * It's a text file requested via 'd'ownload. * Keep adding others to the above list, 'til * we add a configurable procedure. - FM */ IsBinary = FALSE; ret_obj->fp = LYNewBinFile (fnam); if (!ret_obj->fp) { HTAlert(CANNOT_OPEN_OUTPUT); FREE(ret_obj); return NULL; } /* * Any "application/foo" or other non-"text/foo" types that * are actually text but not checked, above, will be treated * as binary, so show the type to help sort that out later. * Unix folks don't need to know this, but we'll show it to * them, too. - FM */ user_message("Content-type: %s", pres->rep->name); sleep(MessageSecs); StrAllocCopy(WWW_Download_File,fnam); /* * Make command to delete file. */ ret_obj->remove_command = (char *)calloc ( (strlen (REMOVE_COMMAND) + 10+ strlen(fnam)) * sizeof (char),1); if (ret_obj->remove_command == NULL) outofmem(__FILE__, "HTSaveToFile"); sprintf(ret_obj->remove_command, REMOVE_COMMAND, fnam);#ifdef VMS if (IsBinary && UseFixedRecords) { ret_obj->end_command = (char *)calloc (sizeof(char)*20,1); if (ret_obj->end_command == NULL) outofmem(__FILE__, "HTSaveToFile"); sprintf(ret_obj->end_command, "SaveVMSBinaryFile"); FIXED_RECORD_COMMAND = (char *)calloc ( (strlen (FIXED_RECORD_COMMAND_MASK) + 10 + strlen(fnam)) * sizeof (char),1); if (FIXED_RECORD_COMMAND == NULL) outofmem(__FILE__, "HTSaveToFile"); sprintf(FIXED_RECORD_COMMAND, FIXED_RECORD_COMMAND_MASK, fnam, "", "", "", "", "", ""); } else {#endif /* VMS */ ret_obj->end_command = (char *)calloc (sizeof(char)*12,1); if (ret_obj->end_command == NULL) outofmem(__FILE__, "HTSaveToFile"); sprintf(ret_obj->end_command, "SaveToFile");#ifdef VMS }#endif /* VMS */ _statusline(RETRIEVING_FILE); StrAllocCopy(anchor->FileCache, fnam);Prepend_BASE:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -