diff options
author | Thomas E. Dickey <dickey@invisible-island.net> | 1998-05-24 00:20:00 -0400 |
---|---|---|
committer | Thomas E. Dickey <dickey@invisible-island.net> | 1998-05-24 00:20:00 -0400 |
commit | 6e75abc094af51d02563fd5250d1b55e9bb96912 (patch) | |
tree | 467ddc6c66cc643b960c48f70c93907c1bc775aa /src | |
parent | becd7d203aa4cc62c6e4113a496c88f6eab9edaf (diff) | |
download | lynx-snapshots-6e75abc094af51d02563fd5250d1b55e9bb96912.tar.gz |
snapshot of project "lynx", label v2-8-1dev_13
Diffstat (limited to 'src')
-rw-r--r-- | src/HTAlert.c | 8 | ||||
-rw-r--r-- | src/HTFWriter.c | 229 | ||||
-rw-r--r-- | src/HTInit.c | 9 | ||||
-rw-r--r-- | src/LYBookmark.c | 71 | ||||
-rw-r--r-- | src/LYCharUtils.c | 15 | ||||
-rw-r--r-- | src/LYClean.c | 8 | ||||
-rw-r--r-- | src/LYClean.h | 3 | ||||
-rw-r--r-- | src/LYDownload.c | 21 | ||||
-rw-r--r-- | src/LYHistory.c | 50 | ||||
-rw-r--r-- | src/LYList.c | 25 | ||||
-rw-r--r-- | src/LYLocal.c | 66 | ||||
-rw-r--r-- | src/LYMail.c | 124 | ||||
-rw-r--r-- | src/LYMain.c | 8 | ||||
-rw-r--r-- | src/LYMainLoop.c | 5 | ||||
-rw-r--r-- | src/LYNews.c | 72 | ||||
-rw-r--r-- | src/LYPrint.c | 136 | ||||
-rw-r--r-- | src/LYShowInfo.c | 24 | ||||
-rw-r--r-- | src/LYUpload.c | 34 | ||||
-rw-r--r-- | src/LYUtils.c | 378 | ||||
-rw-r--r-- | src/LYUtils.h | 23 | ||||
-rw-r--r-- | src/UCdomap.c | 4 |
21 files changed, 543 insertions, 770 deletions
diff --git a/src/HTAlert.c b/src/HTAlert.c index 6e5013e7..a10d79d9 100644 --- a/src/HTAlert.c +++ b/src/HTAlert.c @@ -32,11 +32,11 @@ PUBLIC void HTAlert ARGS1( CONST char *, Msg) { if (TRACE) { - fprintf(stderr, "\nAlert!: %s", Msg); - fflush(stderr); + fprintf(tfp, "\nAlert!: %s", Msg); + fflush(tfp); _user_message("Alert!: %s", Msg); - fprintf(stderr, "\n\n"); - fflush(stderr); + fprintf(tfp, "\n\n"); + fflush(tfp); } else _user_message("Alert!: %s", Msg); diff --git a/src/HTFWriter.c b/src/HTFWriter.c index 4745f48b..c73e01d6 100644 --- a/src/HTFWriter.c +++ b/src/HTFWriter.c @@ -76,7 +76,7 @@ struct _HTStream { HTParentAnchor * anchor; /* Original stream's anchor. */ HTStream * sink; /* Original stream's sink. */ #ifdef FNAMES_8_3 - int idash; /* remember position to become '.'*/ + BOOLEAN idash; /* remember position to become '.'*/ #endif }; @@ -135,7 +135,7 @@ PRIVATE void HTFWriter_free ARGS1(HTStream *, me) fflush(me->fp); if (me->end_command) { /* Temp file */ - fclose(me->fp); + LYCloseTempFP(me->fp); #ifdef VMS if (0 == strcmp(me->end_command, "SaveVMSBinaryFile")) { /* @@ -227,11 +227,13 @@ PRIVATE void HTFWriter_free ARGS1(HTStream *, me) */ if (skip_loadfile) { char *new_path = NULL; - if (me->idash > 1 && path[me->idash] == '-') { + char *the_dash = me->idash ? strrchr(path, '-') : 0; + if (the_dash != 0) { + unsigned off = (the_dash - path); StrAllocCopy(new_path, path); - new_path[me->idash] = '.'; - if (strlen(new_path + me->idash) > 4) - new_path[me->idash + 4] = '\0'; + new_path[off] = '.'; + if (strlen(new_path + off) > 4) + new_path[off + 4] = '\0'; if (rename(path, new_path) == 0) { FREE(path); path = new_path; @@ -419,7 +421,7 @@ PRIVATE void HTFWriter_abort ARGS2( HTError, e GCC_UNUSED) { CTRACE(tfp,"HTFWriter_abort called\n"); - fclose(me->fp); + LYCloseTempFP(me->fp); FREE(me->viewer_command); if (me->end_command) { /* Temp file */ CTRACE(tfp, "HTFWriter: Aborting: file not executed.\n"); @@ -500,9 +502,7 @@ PUBLIC HTStream* HTSaveAndExecute ARGS3( { char fnam[256]; CONST char *suffix; - char *cp; HTStream* me; - FILE *fp = NULL; if (traversal) { LYCancelledFetch = TRUE; @@ -550,61 +550,27 @@ PUBLIC HTStream* HTSaveAndExecute ARGS3( 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); - } + if (LYCachedTemp(fnam, anchor->FileCache)) { + me->fp = LYNewBinFile (fnam); } else { /* - * Lynx routine to create a temporary filename - */ -SaveAndExecute_tempname: - tempname (fnam, NEW_FILE); - /* * Check for a suffix. + * Save the file under a suitably suffixed name. */ - 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 = '.'; - } + if (!strcasecomp(pres->rep->name, "text/html")) { + suffix = HTML_SUFFIX; + } else if (!strcasecomp(pres->rep->name, "text/plain")) { + suffix = ".txt"; + } else if (!strcasecomp(pres->rep->name, + "application/octet-stream")) { + suffix = ".bin"; + } else if ((suffix = HTFileSuffix(pres->rep, anchor->content_encoding)) == 0 + || *suffix != '.') { + suffix = HTML_SUFFIX; } + me->fp = LYOpenTemp(fnam, suffix, "wb"); } - me->fp = LYNewBinFile (fnam); if (!me->fp) { HTAlert(CANNOT_OPEN_TEMP); FREE(me); @@ -664,9 +630,8 @@ PUBLIC HTStream* HTSaveToFile ARGS3( char fnam[256]; CONST char * suffix; char *cp; - int c=0; + int c = 0; BOOL IsBinary = TRUE; - FILE *fp = NULL; ret_obj = (HTStream*)calloc(sizeof(* ret_obj),1); if (ret_obj == NULL) @@ -738,58 +703,32 @@ PUBLIC HTStream* HTSaveToFile ARGS3( /* * 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); - } + if (LYCachedTemp(fnam, anchor->FileCache)) { + ret_obj->fp = LYNewBinFile (fnam); } else { /* - * Lynx routine to create a temporary filename - */ -SaveToFile_tempname: - tempname(fnam, NEW_FILE); - /* * Check for a suffix. + * Save the file under a suitably suffixed name. */ - 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, + if (!strcasecomp(pres->rep->name, "text/html")) { + suffix = HTML_SUFFIX; + } else if (!strcasecomp(pres->rep->name, "text/plain")) { + suffix = ".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 = '.'; - } + suffix = ".bin"; + } else if ((suffix = HTFileSuffix(pres->rep, + anchor->content_encoding)) == 0 + || *suffix != '.') { + suffix = HTML_SUFFIX; } + ret_obj->fp = LYOpenTemp(fnam, suffix, "wb"); + } + + if (!ret_obj->fp) { + HTAlert(CANNOT_OPEN_OUTPUT); + FREE(ret_obj); + return NULL; } if (0==strncasecomp(pres->rep->name, "text/", 5) || @@ -802,13 +741,6 @@ SaveToFile_tempname: */ 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 @@ -930,10 +862,10 @@ PUBLIC HTStream* HTCompressed ARGS3( int n, i; BOOL can_present = FALSE; char fnam[256]; + char temp[256]; CONST char *suffix; char *uncompress_mask = NULL; char *compress_suffix = ""; - char *cp; CONST char *middle; FILE *fp = NULL; @@ -1017,6 +949,9 @@ PUBLIC HTStream* HTCompressed ARGS3( me->output_format = pres->rep_out; me->anchor = anchor; me->sink = sink; +#ifdef FNAMES_8_3 + me->idash = FALSE; +#endif /* * Remove any old versions of the file. - FM @@ -1032,61 +967,45 @@ PUBLIC HTStream* HTCompressed ARGS3( /* * Get a new temporary filename and substitute a suitable suffix. - FM */ -Compressed_tempname: - tempname(fnam, NEW_FILE); - if ((cp = strrchr(fnam, '.')) != NULL) { - middle = NULL; - if (!strcasecomp(anchor->content_type, "text/html")) { - middle = HTML_SUFFIX; - middle++; /* point to 'h' of .htm(l) - kw */ - } else if (!strcasecomp(anchor->content_type, "text/plain")) { - middle = "txt"; - } else if (!strcasecomp(anchor->content_type, - "application/octet-stream")) { - middle = "bin"; - } else if ((suffix = - HTFileSuffix(HTAtom_for(anchor->content_type), NULL)) && - *suffix == '.') { + middle = NULL; + if (!strcasecomp(anchor->content_type, "text/html")) { + middle = HTML_SUFFIX; + middle++; /* point to 'h' of .htm(l) - kw */ + } else if (!strcasecomp(anchor->content_type, "text/plain")) { + middle = "txt"; + } else if (!strcasecomp(anchor->content_type, + "application/octet-stream")) { + middle = "bin"; + } else if ((suffix = + HTFileSuffix(HTAtom_for(anchor->content_type), NULL)) && + *suffix == '.') { #if defined(VMS) || defined(FNAMES_8_3) - if (strchr(suffix + 1, '.') == NULL) + if (strchr(suffix + 1, '.') == NULL) #endif - middle = suffix + 1; - } - if (middle) { - *cp = '\0'; + middle = suffix + 1; + } + + temp[0] = 0; /* construct the suffix */ + if (middle) { #ifdef FNAMES_8_3 - me->idash = strlen(fnam); /* remember position of '-' - kw */ - strcat(fnam, "-"); /* NAME-htm, NAME-txt, etc. - hack for DOS */ + me->idash = TRUE; /* remember position of '-' - kw */ + strcat(temp, "-"); /* NAME-htm, NAME-txt, etc. - hack for DOS */ #else - strcat(fnam, "."); /* NAME.html, NAME-txt etc. */ + strcat(temp, "."); /* NAME.html, NAME-txt etc. */ #endif /* FNAMES_8_3 */ - strcat(fnam, middle); + strcat(temp, middle); #ifdef VMS - strcat(fnam, "-"); /* NAME.html-gz, NAME.txt-gz, NAME.txt-Z etc.*/ + strcat(temp, "-"); /* NAME.html-gz, NAME.txt-gz, NAME.txt-Z etc.*/ #else - strcat(fnam, "."); /* NAME-htm.gz (DOS), NAME.html.gz (UNIX)etc.*/ + strcat(temp, "."); /* NAME-htm.gz (DOS), NAME.html.gz (UNIX)etc.*/ #endif /* VMS */ - } else { - *(cp + 1) = '\0'; - } - } else { - strcat(fnam, "."); - } - strcat(fnam, compress_suffix); - /* - * It's not one of the suffixes checked for a - * spoof in tempname(), so check it now. - FM - */ - if ((fp = fopen(fnam, "r")) != NULL) { - fclose(fp); - fp = NULL; - goto Compressed_tempname; } + strcat(temp, compress_suffix); /* * Open the file for receiving the compressed input stream. - FM */ - me->fp = LYNewBinFile (fnam); + me->fp = LYOpenTemp (fnam, temp, "wb"); if (!me->fp) { HTAlert(CANNOT_OPEN_TEMP); FREE(uncompress_mask); diff --git a/src/HTInit.c b/src/HTInit.c index 9b79ec04..b9e0c4c6 100644 --- a/src/HTInit.c +++ b/src/HTInit.c @@ -412,8 +412,8 @@ PRIVATE int ProcessMailcapEntry ARGS2( } } - FREE(mallocd_string); - s = t; + FREE(mallocd_string); + s = t; } assign_presentation: @@ -550,7 +550,9 @@ PRIVATE int PassesTest ARGS1( /* * Build the command and execute it. */ - tempname(TmpFileName, NEW_FILE); + if (LYOpenTemp(TmpFileName, HTML_SUFFIX, "w") == 0) + ExitWithError(CANNOT_OPEN_TEMP); + LYCloseTemp(TmpFileName); cmd = (char *)malloc(1024); if (!cmd) ExitWithError("Out of memory"); @@ -561,6 +563,7 @@ PRIVATE int PassesTest ARGS1( CTRACE(tfp, "PassesTest: Executing test command: %s\n", cmd); result = system(cmd); FREE(cmd); + LYRemoveTemp(TmpFileName); /* * Free the test command as well since diff --git a/src/LYBookmark.c b/src/LYBookmark.c index 21f61a14..8b7827bc 100644 --- a/src/LYBookmark.c +++ b/src/LYBookmark.c @@ -117,39 +117,11 @@ success: is_mosaic_hotlist = TRUE; fclose(fp); newname = convert_mosaic_bookmark_file(filename_buffer); -#ifdef DOSPATH - sprintf(URL_buffer, "file://localhost/%s", - HTDOS_wwwName((char *)newname)); -#else -#ifdef VMS - sprintf(URL_buffer,"file://localhost%s", - HTVMS_wwwName((char *)newname)); -#else -#ifdef __EMX__ - sprintf(URL_buffer,"file://localhost/%s", newname); -#else - sprintf(URL_buffer,"file://localhost%s", newname); -#endif /* __EMX__ */ -#endif /* VMS */ -#endif /* DOSPATH */ + LYLocalFileToURL(URL_buffer, newname); } else { fclose(fp); is_mosaic_hotlist = FALSE; -#ifdef DOSPATH - sprintf(URL_buffer,"file://localhost/%s", - HTDOS_wwwName((char *)filename_buffer)); -#else -#ifdef VMS - sprintf(URL_buffer,"file://localhost%s", - HTVMS_wwwName((char *)filename_buffer)); -#else -#ifdef __EMX__ - sprintf(URL_buffer,"file://localhost/%s", filename_buffer); -#else - sprintf(URL_buffer,"file://localhost%s", filename_buffer); -#endif /* __EMX__ */ -#endif /* VMS */ -#endif /* DOSPATH */ + LYLocalFileToURL(URL_buffer, filename_buffer); } StrAllocCopy(*URL, URL_buffer); @@ -165,22 +137,13 @@ PRIVATE char * convert_mosaic_bookmark_file ARGS1( char *, filename_buffer) { static char newfile[256]; - static BOOLEAN first = TRUE; FILE *fp, *nfp; char buf[BUFSIZ]; int line = -2; char *endline; - if (first) { - tempname(newfile, NEW_FILE); - first = FALSE; -#ifdef VMS - } else { - remove(newfile); /* Remove duplicates on VMS. */ -#endif /* VMS */ - } - - if ((nfp = fopen(newfile, "w")) == NULL) { + LYRemoveTemp(newfile); + if ((nfp = LYOpenTemp(newfile, HTML_SUFFIX, "w")) == NULL) { LYMBM_statusline(NO_TEMP_FOR_HOTLIST); sleep(AlertSecs); return (""); @@ -213,7 +176,7 @@ PRIVATE char * convert_mosaic_bookmark_file ARGS1( /* else - ignore the line (this gets rid of first two lines) */ line++; } - fclose(nfp); + LYCloseTempFP(nfp); fclose(fp); return(newfile); } @@ -463,18 +426,9 @@ PUBLIC void remove_bookmark_link ARGS2( return; } -#ifdef VMS - sprintf(newfile, "%s-%d", filename_buffer, getpid()); -#else - tempname(newfile, NEW_FILE); -#endif /* VMS */ - if ((nfp = LYNewTxtFile(newfile)) == NULL) { + if ((nfp = LYOpenScratch(newfile, filename_buffer)) == 0) { fclose(fp); -#ifdef VMS _statusline(BOOKSCRA_OPEN_FAILED_FOR_DEL); -#else - _statusline(BOOKTEMP_OPEN_FAILED_FOR_DEL); -#endif /* VMS */ sleep(AlertSecs); return; } @@ -485,10 +439,8 @@ PUBLIC void remove_bookmark_link ARGS2( */ if (stat(filename_buffer, &stat_buf) == 0) { mode = ((stat_buf.st_mode & 0777) | 0600); /* make it writable */ - (void) fclose(nfp); - nfp = NULL; (void) chmod(newfile, mode); - if ((nfp = fopen(newfile, "a")) == NULL) { + if ((nfp = LYReopenTemp(newfile)) == NULL) { (void) fclose(fp); _statusline(BOOKTEMP_REOPEN_FAIL_FOR_DEL); sleep(AlertSecs); @@ -542,7 +494,7 @@ PUBLIC void remove_bookmark_link ARGS2( fclose(fp); fp = NULL; - fclose(nfp); + LYCloseTempFP(nfp); nfp = NULL; #ifdef DOSPATH remove(filename_buffer); @@ -555,7 +507,7 @@ PUBLIC void remove_bookmark_link ARGS2( * it is writable by the current process. * Changed to copy 1998-04-26 -- gil */ - { char buffer[3072]; + { char buffer[3072]; sprintf(buffer, "%s %s %s && %s %s", COPY_PATH, newfile, filename_buffer, @@ -620,11 +572,10 @@ PUBLIC void remove_bookmark_link ARGS2( failure: _statusline(BOOKMARK_DEL_FAILED); sleep(AlertSecs); - if (nfp != NULL) - fclose(nfp); + LYCloseTempFP(nfp); if (fp != NULL) fclose(fp); - remove(newfile); + LYRemoveTemp(newfile); } /* diff --git a/src/LYCharUtils.c b/src/LYCharUtils.c index 4f2054ac..35afffc1 100644 --- a/src/LYCharUtils.c +++ b/src/LYCharUtils.c @@ -1577,6 +1577,20 @@ PRIVATE char *hex = "0123456789ABCDEF"; ** if string translated or translation unnecessary, ** NULL otherwise ** (in which case something probably went wrong.) +** +** +** In general, this somehow ugly function (KW) +** cover three functions from v.2.7.2 (FM): +** extern void LYExpandString PARAMS(( +** HTStructured * me, +** char ** str)); +** extern void LYUnEscapeEntities PARAMS(( +** HTStructured * me, +** char ** str)); +** extern void LYUnEscapeToLatinOne PARAMS(( +** HTStructured * me, +** char ** str, +** BOOLEAN isURL)); */ PRIVATE char ** LYUCFullyTranslateString_1 ARGS9( @@ -2384,6 +2398,7 @@ PRIVATE char ** LYUCFullyTranslateString_1 ARGS9( if (code >= 127 || (code < 32 && (code != 9 && code != 10 && code != 0))) { state = S_put_urlstring; + break; } } REPLACE_STRING(replace_buf); diff --git a/src/LYClean.c b/src/LYClean.c index d67d76cf..0c79b9e6 100644 --- a/src/LYClean.c +++ b/src/LYClean.c @@ -134,15 +134,11 @@ PUBLIC void cleanup_sig ARGS1( /* * Called by Interrupt handler or at quit time. - * Erases the temporary files that lynx created - * temporary files are removed by tempname - * which created them. + * Erases the temporary files that lynx created. */ PUBLIC void cleanup_files NOARGS { - char filename[256]; - - tempname(filename, REMOVE_FILES); + LYCleanupTemp(); FREE(lynx_temp_space); } diff --git a/src/LYClean.h b/src/LYClean.h index e9502010..ec5ee39b 100644 --- a/src/LYClean.h +++ b/src/LYClean.h @@ -12,7 +12,4 @@ extern void cleanup_files NOPARAMS; extern void set_alarm PARAMS((int sig)); extern void reset_alarm NOPARAMS; -#define NEW_FILE 0 -#define REMOVE_FILES 1 - #endif /* LYCLEAN_H */ diff --git a/src/LYDownload.c b/src/LYDownload.c index f355672d..f4e57a30 100644 --- a/src/LYDownload.c +++ b/src/LYDownload.c @@ -608,37 +608,24 @@ PUBLIC int LYdownload_options ARGS2( char *, data_file) { static char tempfile[256]; - static BOOLEAN first = TRUE; static char download_filename[256]; char *sug_filename = NULL; FILE *fp0; lynx_html_item_type *cur_download; int count; - if (first) { - tempname(tempfile, NEW_FILE); - first = FALSE; -#if defined (VMS) || defined (DOSPATH) || defined (__EMX__) - sprintf(download_filename, "file://localhost/%s", tempfile); -#else - sprintf(download_filename, "file://localhost%s", tempfile); -#endif /* VMS */ -#ifdef VMS - } else { - remove(tempfile); /* Remove duplicates on VMS. */ -#endif /* VMS */ - } - /* * Get a suggested filename. */ StrAllocCopy(sug_filename, *newfile); change_sug_filename(sug_filename); - if ((fp0 = LYNewTxtFile(tempfile)) == NULL) { + LYRemoveTemp(tempfile); + if ((fp0 = LYOpenTemp(tempfile, HTML_SUFFIX, "w")) == NULL) { HTAlert(CANNOT_OPEN_TEMP); return(-1); } + LYLocalFileToURL(download_filename, tempfile); LYstrncpy(LYValidDownloadFile, data_file, @@ -690,7 +677,7 @@ No other download methods have been defined yet. You may define\n\ an unlimited number of download methods using the lynx.cfg file.\n"); } fprintf(fp0, "</pre>\n</body>\n"); - fclose(fp0); + LYCloseTempFP(fp0); /* * Free off temp copy. diff --git a/src/LYHistory.c b/src/LYHistory.c index 5bf9294f..38522586 100644 --- a/src/LYHistory.c +++ b/src/LYHistory.c @@ -383,34 +383,19 @@ PUBLIC int showhistory ARGS1( char **, newfile) { static char tempfile[256]; - static BOOLEAN first = TRUE; static char hist_filename[256]; char *Title = NULL; int x = 0; FILE *fp0; - if (first) { - tempname(tempfile, NEW_FILE); - /* - * Make the file a URL now. - */ -#if defined (VMS) || defined (DOSPATH) || defined (__EMX__) - sprintf(hist_filename,"file://localhost/%s", tempfile); -#else - sprintf(hist_filename,"file://localhost%s", tempfile); -#endif /* VMS */ - first = FALSE; -#ifdef VMS - } else { - remove(tempfile); /* Remove duplicates on VMS. */ -#endif /* VMS */ - } - - if ((fp0 = LYNewTxtFile(tempfile)) == NULL) { + LYRemoveTemp(tempfile); + if ((fp0 = LYOpenTemp(tempfile, HTML_SUFFIX, "w")) == NULL) { HTAlert(CANNOT_OPEN_TEMP); return(-1); } + LYLocalFileToURL(hist_filename, tempfile); + StrAllocCopy(*newfile, hist_filename); LYforce_HTML_mode = TRUE; /* force this file to be HTML */ LYforce_no_cache = TRUE; /* force this file to be new */ @@ -454,7 +439,7 @@ PUBLIC int showhistory ARGS1( fprintf(fp0,"</pre>\n</body>\n"); - fclose(fp0); + LYCloseTempFP(fp0); FREE(Title); return(0); } @@ -543,7 +528,6 @@ PUBLIC int LYShowVisitedLinks ARGS1( char **, newfile) { static char tempfile[256]; - static BOOLEAN first = TRUE; static char vl_filename[256]; char *Title = NULL; char *Address = NULL; @@ -555,28 +539,14 @@ PUBLIC int LYShowVisitedLinks ARGS1( if (!cur) return(-1); - if (first) { - tempname(tempfile, NEW_FILE); - /* - * Make the file a URL now. - */ -#if defined (VMS) || defined (DOSPATH) || defined (__EMX__) - sprintf(vl_filename,"file://localhost/%s", tempfile); -#else - sprintf(vl_filename,"file://localhost%s", tempfile); -#endif /* VMS */ - first = FALSE; -#ifdef VMS - } else { - remove(tempfile); /* Remove duplicates on VMS. */ -#endif /* VMS */ - } - - if ((fp0 = LYNewTxtFile(tempfile)) == NULL) { + LYRemoveTemp(tempfile); + if ((fp0 = LYOpenTemp(tempfile, HTML_SUFFIX, "w")) == NULL) { HTAlert(CANNOT_OPEN_TEMP); return(-1); } + LYLocalFileToURL(vl_filename, tempfile); + StrAllocCopy(*newfile, vl_filename); LYforce_HTML_mode = TRUE; /* force this file to be HTML */ LYforce_no_cache = TRUE; /* force this file to be new */ @@ -625,7 +595,7 @@ PUBLIC int LYShowVisitedLinks ARGS1( fprintf(fp0,"</pre>\n</body>\n"); - fclose(fp0); + LYCloseTempFP(fp0); FREE(Title); FREE(Address); return(0); diff --git a/src/LYList.c b/src/LYList.c index d0b28169..f7b31e4c 100644 --- a/src/LYList.c +++ b/src/LYList.c @@ -53,7 +53,6 @@ PUBLIC int showlist ARGS2( int cnt; int refs, hidden_links; static char tempfile[256]; - static BOOLEAN first = TRUE; FILE *fp0; char *Address = NULL, *Title = NULL, *cp = NULL; BOOLEAN intern_w_post = FALSE; @@ -73,29 +72,15 @@ PUBLIC int showlist ARGS2( return(-1); } - if (first) { - tempname(tempfile, NEW_FILE); - /* - * Make the file a URL now. - */ -#if defined (VMS) || defined (DOSPATH) || defined (__EMX__) - sprintf(list_filename, "file://localhost/%s", tempfile); -#else - sprintf(list_filename, "file://localhost%s", tempfile); -#endif /* VMS */ - first = FALSE; -#ifdef VMS - } else { - remove(tempfile); /* Remove duplicates on VMS. */ -#endif /* VMS */ - } - - if ((fp0 = LYNewTxtFile(tempfile)) == NULL) { + LYRemoveTemp(tempfile); + if ((fp0 = LYOpenTemp(tempfile, HTML_SUFFIX, "w")) == NULL) { _statusline(CANNOT_OPEN_TEMP); sleep(MessageSecs); return(-1); } + LYLocalFileToURL(list_filename, tempfile); + StrAllocCopy(newdoc->address, list_filename); LYforce_HTML_mode = TRUE; /* force this file to be HTML */ LYforce_no_cache = TRUE; /* force this file to be new */ @@ -257,7 +242,7 @@ PUBLIC int showlist ARGS2( } newdoc->isHEAD = FALSE; newdoc->safe = FALSE; - fclose(fp0); + LYCloseTempFP(fp0); return(0); } diff --git a/src/LYLocal.c b/src/LYLocal.c index a88bc3e0..828b0779 100644 --- a/src/LYLocal.c +++ b/src/LYLocal.c @@ -966,7 +966,7 @@ PRIVATE BOOLEAN remove_single ARGS1( char *args[5]; /* - * lstat() first in case its a symbolic link. + * lstat() first in case it's a symbolic link. */ if (lstat(testpath, &dir_info) == -1 && stat(testpath, &dir_info) == -1) { @@ -1122,7 +1122,6 @@ PRIVATE BOOLEAN permit_location ARGS3( return(0); #else static char tempfile[256] = "\0"; - static BOOLEAN first = TRUE; char *cp; char tmpbuf[LINESIZE]; struct stat dir_info; @@ -1161,32 +1160,18 @@ PRIVATE BOOLEAN permit_location ARGS3( user_filename = (cp + 1); } - if (first) { - /* - * Get an unused tempfile name. - FM - */ - tempname(tempfile, NEW_FILE); - } - - /* - * Open the tempfile for writing and set its - * protection in case this wasn't done via an - * external umask. - FM - */ - if ((fp0 = LYNewTxtFile(tempfile)) == NULL) { + LYRemoveTemp(tempfile); + if ((fp0 = LYOpenTemp(tempfile, HTML_SUFFIX, "w")) == NULL) { _statusline("Unable to open permit options file"); sleep(AlertSecs); return(0); } - if (first) { - /* - * Make the tempfile a URL. - */ - strcpy(LYPermitFileURL, "file://localhost"); - strcat(LYPermitFileURL, tempfile); - first = FALSE; - } + /* + * Make the tempfile a URL. + */ + strcpy(LYPermitFileURL, "file://localhost"); + strcat(LYPermitFileURL, tempfile); StrAllocCopy(*newpath, LYPermitFileURL); grp = getgrgid(dir_info.st_gid); @@ -1267,7 +1252,7 @@ form to permit %s %s.\n</Ol>\n</Form>\n", (dir_info.st_mode & S_IFMT) == S_IFDIR ? "directory" : "file", user_filename); fprintf(fp0, "</Body></Html>"); - fclose(fp0); + LYCloseTempFP(fp0); LYforce_no_cache = TRUE; return(PERMIT_FORM_RESULT); /* Special flag for LYMainLoop */ @@ -1695,7 +1680,6 @@ PUBLIC int dired_options ARGS2( char **, newfile) { static char tempfile[256]; - static BOOLEAN first = TRUE; char path[512], dir[512]; /* much too large */ char tmpbuf[LINESIZE]; lynx_html_item_type *nxt; @@ -1714,33 +1698,18 @@ PUBLIC int dired_options ARGS2( struct dired_menu *mp; char buf[2048]; - - if (first) { - /* - * Get an unused tempfile name. - FM - */ - tempname(tempfile, NEW_FILE); - } - - /* - * Open the tempfile for writing and set its - * protection in case this wasn't done via an - * external umask. - FM - */ - if ((fp0 = LYNewTxtFile(tempfile)) == NULL) { + LYRemoveTemp(tempfile); + if ((fp0 = LYOpenTemp(tempfile, HTML_SUFFIX, "w")) == NULL) { _statusline("Unable to open file management menu file."); sleep(AlertSecs); return(0); } - if (first) { - /* - * Make the tempfile a URL. - */ - strcpy(LYDiredFileURL, "file://localhost"); - strcat(LYDiredFileURL, tempfile); - first = FALSE; - } + /* + * Make the tempfile a URL. + */ + strcpy(LYDiredFileURL, "file://localhost"); + strcat(LYDiredFileURL, tempfile); StrAllocCopy(*newfile, LYDiredFileURL); cp = doc->address; @@ -1776,6 +1745,7 @@ PUBLIC int dired_options ARGS2( sprintf(tmpbuf, "Unable to get status of '%s'.", path); _statusline(tmpbuf); sleep(AlertSecs); + LYCloseTempFP(fp0); FREE(dir_url); FREE(path_url); return 0; @@ -1887,7 +1857,7 @@ PUBLIC int dired_options ARGS2( } fprintf(fp0, "</body>\n"); - fclose(fp0); + LYCloseTempFP(fp0); FREE(dir_url); FREE(path_url); diff --git a/src/LYMail.c b/src/LYMail.c index 19132764..9ca2a175 100644 --- a/src/LYMail.c +++ b/src/LYMail.c @@ -317,14 +317,7 @@ PUBLIC void mailform ARGS4( } #if defined(VMS) || defined(DOSPATH) - tempname(my_tmpfile, NEW_FILE); - if (((cp = strrchr(my_tmpfile, '.')) != NULL) && - NULL == strchr(cp, ']') && - NULL == strchr(cp, '/')) { - *cp = '\0'; - strcat(my_tmpfile, ".txt"); - } - if ((fd = LYNewTxtFile(my_tmpfile)) == NULL) { + if ((fd = LYOpenTemp(my_tmpfile, ".txt", "w")) == NULL) { HTAlert(FORM_MAILTO_FAILED); FREE(address); FREE(ccaddr); @@ -332,15 +325,9 @@ PUBLIC void mailform ARGS4( return; } if (isPMDF) { - tempname(hdrfile, NEW_FILE); - if (((cp = strrchr(hdrfile, '.')) != NULL) && - NULL == strchr(cp, ']') && - NULL == strchr(cp, '/')) { - *cp = '\0'; - strcat(hdrfile, ".txt"); - } - if ((hfd = LYNewTxtFile(hdrfile)) == NULL) { + if ((hfd = LYOpenTemp(hdrfile, ".txt", "w")) == NULL) { HTAlert(FORM_MAILTO_FAILED); + LYCloseTempFP(fd); FREE(address); FREE(ccaddr); FREE(keywords); @@ -438,7 +425,7 @@ PUBLIC void mailform ARGS4( sleep(MessageSecs); #endif /* UNIX */ #if defined(VMS) || defined(DOSPATH) - fclose(fd); + LYCloseTempFP(fd); #ifdef VMS /* * Set the mail command. - FM @@ -452,7 +439,7 @@ PUBLIC void mailform ARGS4( fprintf(hfd, "Keywords: %s\n", keywords); } fprintf(hfd, "Subject: %s\n\n", subject); - fclose(hfd); + LYCloseTempFP(hfd); /* * Now set up the command. - FM */ @@ -553,8 +540,8 @@ PUBLIC void mailform ARGS4( FREE(command); sleep(AlertSecs); start_curses(); - remove(my_tmpfile); - remove(hdrfile); + LYRemoveTemp(my_tmpfile); + LYRemoveTemp(hdrfile); #else /* DOSPATH */ StrAllocCopy(command, system_mail); StrAllocCat(command, " -t \""); @@ -567,7 +554,7 @@ PUBLIC void mailform ARGS4( FREE(command); sleep(MessageSecs); start_curses(); - remove(my_tmpfile); + LYRemoveTemp(my_tmpfile); #endif #endif /* VMS */ @@ -704,28 +691,14 @@ PUBLIC void mailmsg ARGS4( fprintf(fd, "X-Mailer: Lynx, Version %s\n\n", LYNX_VERSION); #endif /* UNIX */ #if defined(VMS) || defined(DOSPATH) - tempname(my_tmpfile, NEW_FILE); - if (((cp = strrchr(my_tmpfile, '.')) != NULL) && - NULL == strchr(cp, ']') && - NULL == strchr(cp, '/')) { - *cp = '\0'; - strcat(my_tmpfile, ".txt"); - } - if ((fd = LYNewTxtFile(my_tmpfile)) == NULL) { + if ((fd = LYOpenTemp(my_tmpfile, ".txt", "w")) == NULL) { CTRACE(tfp, "mailmsg: Could not fopen '%s'.\n", my_tmpfile); FREE(address); return; } if (isPMDF) { - tempname(hdrfile, NEW_FILE); - if (((cp = strrchr(hdrfile, '.')) != NULL) && - NULL == strchr(cp, ']') && - NULL == strchr(cp, '/')) { - *cp = '\0'; - strcat(hdrfile, ".txt"); - } - if ((hfd = LYNewTxtFile(hdrfile)) == NULL) { + if ((hfd = LYOpenTemp(hdrfile, ".txt", "w")) == NULL) { CTRACE(tfp, "mailmsg: Could not fopen '%s'.\n", hdrfile); FREE(address); @@ -761,7 +734,7 @@ PUBLIC void mailmsg ARGS4( pclose(fd); #endif /* UNIX */ #if defined(VMS) || defined(DOSPATH) - fclose(fd); + LYCloseTempFP(fd); #ifdef VMS if (isPMDF) { /* @@ -769,7 +742,7 @@ PUBLIC void mailmsg ARGS4( * header file and close it. - FM */ fprintf(hfd, "Subject: Lynx Error in %.56s\n\n", filename); - fclose(hfd); + LYCloseTempFP(hfd); /* * Now set up the command. - FM */ @@ -822,9 +795,9 @@ PUBLIC void mailmsg ARGS4( system(command); FREE(command); - remove(my_tmpfile); + LYRemoveTemp(my_tmpfile); if (isPMDF) { - remove(hdrfile); + LYRemoveTemp(hdrfile); } #else /* DOSPATH */ StrAllocCopy(command, system_mail); @@ -834,7 +807,7 @@ PUBLIC void mailmsg ARGS4( StrAllocCat(command, my_tmpfile); system(command); FREE(command); - remove(my_tmpfile); + LYRemoveTemp(my_tmpfile); #endif #endif /* VMS */ @@ -927,29 +900,13 @@ PUBLIC void reply_by_mail ARGS3( return; } - tempname(my_tmpfile, NEW_FILE); - if (((cp = strrchr(my_tmpfile, '.')) != NULL) && -#ifdef VMS - NULL == strchr(cp, ']') && -#endif /* VMS */ - NULL == strchr(cp, '/')) { - *cp = '\0'; - strcat(my_tmpfile, ".txt"); - } - if ((fd = LYNewTxtFile(my_tmpfile)) == NULL) { + if ((fd = LYOpenTemp(my_tmpfile, ".txt", "w")) == NULL) { HTAlert(MAILTO_URL_TEMPOPEN_FAILED); return; } #ifdef VMS if (isPMDF) { - tempname(hdrfile, NEW_FILE); - if (((cp = strrchr(hdrfile, '.')) != NULL) && - NULL == strchr(cp, ']') && - NULL == strchr(cp, '/')) { - *cp = '\0'; - strcat(hdrfile, ".txt"); - } - if ((hfd = LYNewTxtFile(hdrfile)) == NULL) { + if ((hfd = LYOpenTemp(hdrfile, ".txt", "w")) == NULL) { HTAlert(MAILTO_URL_TEMPOPEN_FAILED); return; } @@ -1186,8 +1143,8 @@ PUBLIC void reply_by_mail ARGS3( FREE(ccaddr); FREE(keywords); FREE(body); - fclose(fd); /* Close the tmpfile. */ - remove(my_tmpfile); /* Delete the tmpfile. */ + LYCloseTempFP(fd); /* Close the tmpfile. */ + LYRemoveTemp(my_tmpfile); /* Delete the tmpfile. */ HTAlert(NO_ADDRESS_IN_MAILTO_URL); return; } @@ -1382,7 +1339,7 @@ PUBLIC void reply_by_mail ARGS3( addstr("\n"); _statusline(COMMENT_REQUEST_CANCELLED); sleep(InfoSecs); - fclose(fd); /* Close the tmpfile. */ + LYCloseTempFP(fd); /* Close the tmpfile. */ scrollok(stdscr,FALSE); /* Stop scrolling. */ goto cleanup; } @@ -1425,7 +1382,7 @@ PUBLIC void reply_by_mail ARGS3( addstr("\n"); _statusline(COMMENT_REQUEST_CANCELLED); sleep(InfoSecs); - fclose(fd); /* Close the tmpfile. */ + LYCloseTempFP(fd); /* Close the tmpfile. */ scrollok(stdscr,FALSE); /* Stop scrolling. */ goto cleanup; } @@ -1472,7 +1429,7 @@ PUBLIC void reply_by_mail ARGS3( addstr("\n"); _statusline(COMMENT_REQUEST_CANCELLED); sleep(InfoSecs); - fclose(fd); /* Close the tmpfile. */ + LYCloseTempFP(fd); /* Close the tmpfile. */ scrollok(stdscr,FALSE); /* Stop scrolling. */ goto cleanup; } @@ -1506,7 +1463,7 @@ PUBLIC void reply_by_mail ARGS3( addstr("\n"); _statusline(COMMENT_REQUEST_CANCELLED); sleep(InfoSecs); - fclose(fd); /* Close the tmpfile. */ + LYCloseTempFP(fd); /* Close the tmpfile. */ scrollok(stdscr, FALSE); /* Stop scrolling. */ goto cleanup; } @@ -1600,7 +1557,7 @@ PUBLIC void reply_by_mail ARGS3( print_wwwfile_to_fd(fd, 1); } } - fclose(fd); /* Close the tmpfile. */ + LYCloseTempFP(fd); /* Close the tmpfile. */ scrollok(stdscr,FALSE); /* Stop scrolling. */ if (term_letter || c == 7 || c == 3) @@ -1642,7 +1599,7 @@ PUBLIC void reply_by_mail ARGS3( if (term_letter || c == 7 || c == 3) { addstr(CANCELLED); sleep(InfoSecs); - fclose(fd); /* Close the tmpfile. */ + LYCloseTempFP(fd); /* Close the tmpfile. */ scrollok(stdscr, FALSE); /* Stop scrolling. */ goto cleanup; } @@ -1660,7 +1617,7 @@ PUBLIC void reply_by_mail ARGS3( i--; } refresh(); - fclose(fd); /* Close the tmpfile. */ + LYCloseTempFP(fd); /* Close the tmpfile. */ scrollok(stdscr,FALSE); /* Stop scrolling. */ } else { @@ -1677,7 +1634,7 @@ PUBLIC void reply_by_mail ARGS3( term_letter || STREQ(user_input, ".")) { _statusline(COMMENT_REQUEST_CANCELLED); sleep(InfoSecs); - fclose(fd); /* Close the tmpfile. */ + LYCloseTempFP(fd); /* Close the tmpfile. */ scrollok(stdscr,FALSE); /* Stop scrolling. */ goto cleanup; } @@ -1691,14 +1648,14 @@ PUBLIC void reply_by_mail ARGS3( sizeof(user_input), NORECALL) < 0) { _statusline(COMMENT_REQUEST_CANCELLED); sleep(InfoSecs); - fclose(fd); /* Close the tmpfile. */ + LYCloseTempFP(fd); /* Close the tmpfile. */ scrollok(stdscr,FALSE); /* Stop scrolling. */ goto cleanup; } } fprintf(fd, "\n"); /* Terminate the message. */ - fclose(fd); /* Close the tmpfile. */ + LYCloseTempFP(fd); /* Close the tmpfile. */ scrollok(stdscr,FALSE); /* Stop scrolling. */ } @@ -1760,7 +1717,7 @@ PUBLIC void reply_by_mail ARGS3( fprintf(hfd, "Keywords: %s\n", keywords); } fprintf(hfd, "Subject: %s\n\n", subject); - fclose(hfd); + LYCloseTempFP(hfd); /* * Now set up the command. - FM */ @@ -1869,13 +1826,7 @@ PUBLIC void reply_by_mail ARGS3( _statusline(SENDING_YOUR_MSG); sprintf(cmd, "%s %s", system_mail, system_mail_flags); #ifdef DOSPATH - tempname(tmpfile2, NEW_FILE); - if (((cp = strrchr(tmpfile2, '.')) != NULL) && - NULL == strchr(cp, '/')) { - *cp = '\0'; - strcat(tmpfile2, ".txt"); - } - if ((fp = LYNewTxtFile(tmpfile2)) == NULL) { + if ((fp = LYOpenTemp(tmpfile2, ".txt", "w")) == NULL) { HTAlert(MAILTO_URL_TEMPOPEN_FAILED); return; } @@ -1904,18 +1855,18 @@ PUBLIC void reply_by_mail ARGS3( StrAllocCat(command, address); StrAllocCat(command, "\" -F "); StrAllocCat(command, tmpfile2); - fclose(fp); /* Close the tmpfile. */ + LYCloseTempFP(fp); /* Close the tmpfile. */ stop_curses(); printf("Sending your comment:\n\n$ %s\n\nPlease wait...", command); system(command); FREE(command); sleep(MessageSecs); start_curses(); - remove(tmpfile2); /* Delete the tmpfile. */ + LYRemoveTemp(tmpfile2); /* Delete the tmpfile. */ #else pclose(fp); #endif - fclose(fd); /* Close the tmpfile. */ + LYCloseTempFP(fd); /* Close the tmpfile. */ CTRACE(tfp, "%s\n", cmd); #endif /* VMS */ @@ -1935,14 +1886,11 @@ cleandown: term_letter = FALSE; #ifdef VMS FREE(command); - while (remove(my_tmpfile) == 0) - ; /* Delete the tmpfile(s). */ if (isPMDF) { - remove(hdrfile); /* Delete the hdrfile. */ + LYRemoveTemp(hdrfile); } -#else - remove(my_tmpfile); /* Delete the tmpfile. */ #endif /* VMS */ + LYRemoveTemp(my_tmpfile); FREE(address); FREE(ccaddr); FREE(keywords); diff --git a/src/LYMain.c b/src/LYMain.c index 9a588f6a..6d1ebd79 100644 --- a/src/LYMain.c +++ b/src/LYMain.c @@ -714,10 +714,10 @@ PUBLIC int main ARGS2( else if ((cp = getenv("TMP")) != NULL) StrAllocCopy(lynx_temp_space, cp); else - { - printf("You MUST define a valid TMP or TEMP area!\n"); - exit(-1); - } + { + printf("You MUST define a valid TMP or TEMP area!\n"); + exit(-1); + } #else StrAllocCopy(lynx_temp_space, TEMP_SPACE); #endif diff --git a/src/LYMainLoop.c b/src/LYMainLoop.c index 6ff7b827..52e501ac 100644 --- a/src/LYMainLoop.c +++ b/src/LYMainLoop.c @@ -5104,9 +5104,6 @@ check_add_bookmark_to_self: else WWW_TraceFlag = TRUE; - _statusline(WWW_TraceFlag ? TRACE_ON : TRACE_OFF); - sleep(MessageSecs); - if (TRACE && LYUseTraceLog && LYTraceLogFP == NULL) { /* * We haven't yet started a TRACE log for this @@ -5134,6 +5131,8 @@ check_add_bookmark_to_self: #endif /* VMS */ fprintf(tfp, "\t\t%s\n\n", LYNX_TRACELOG_TITLE); } + _statusline(WWW_TraceFlag ? TRACE_ON : TRACE_OFF); + sleep(MessageSecs); break; case LYK_TRACE_LOG: /* View TRACE log. */ diff --git a/src/LYNews.c b/src/LYNews.c index 6df6a9ff..45d560cb 100644 --- a/src/LYNews.c +++ b/src/LYNews.c @@ -68,8 +68,7 @@ PUBLIC char *LYNewsPost ARGS2( * Open a temporary file for the headers * and message body. - FM */ - tempname(my_tempfile, NEW_FILE); - if ((fd = LYNewTxtFile(my_tempfile)) == NULL) { + if ((fd = LYOpenTemp(my_tempfile, HTML_SUFFIX, "w")) == NULL) { HTAlert(CANNOT_OPEN_TEMP); return(postfile); } @@ -81,16 +80,9 @@ PUBLIC char *LYNewsPost ARGS2( CJKfile[0] = '\0'; if (!strncmp(LYchar_set_names[current_char_set], "Japanese (EUC)", 14) || !strncmp(LYchar_set_names[current_char_set], "Japanese (SJIS)", 15)) { - tempname(CJKfile, NEW_FILE); - if ((fc = LYNewTxtFile(CJKfile)) == NULL) { + if ((fc = LYOpenTemp(CJKfile, HTML_SUFFIX, "w")) == NULL) { HTAlert(CANNOT_OPEN_TEMP); - fclose(fd); -#ifdef VMS - while (remove(my_tempfile) == 0) - ; /* loop through all versions */ -#else - remove(my_tempfile); -#endif /* VMS */ + LYRemoveTemp(my_tempfile); return(postfile); } } @@ -134,8 +126,8 @@ PUBLIC char *LYNewsPost ARGS2( term_message) { _statusline(NEWS_POST_CANCELLED); sleep(InfoSecs); - fclose(fd); /* Close the temp file. */ - scrollok(stdscr, FALSE); /* Stop scrolling. */ + LYCloseTempFP(fd); /* Close the temp file. */ + scrollok(stdscr, FALSE); /* Stop scrolling. */ goto cleanup; } fprintf(fd, "%s\n", user_input); @@ -164,8 +156,8 @@ PUBLIC char *LYNewsPost ARGS2( term_message) { _statusline(NEWS_POST_CANCELLED); sleep(InfoSecs); - fclose(fd); /* Close the temp file. */ - scrollok(stdscr, FALSE); /* Stop scrolling. */ + LYCloseTempFP(fd); /* Close the temp file. */ + scrollok(stdscr, FALSE); /* Stop scrolling. */ goto cleanup; } fprintf(fd,"%s\n",user_input); @@ -200,8 +192,8 @@ PUBLIC char *LYNewsPost ARGS2( term_message) { _statusline(NEWS_POST_CANCELLED); sleep(InfoSecs); - fclose(fd); /* Close the temp file. */ - scrollok(stdscr, FALSE); /* Stop scrolling. */ + LYCloseTempFP(fd); /* Close the temp file. */ + scrollok(stdscr, FALSE); /* Stop scrolling. */ goto cleanup; } fprintf(fd, "%s\n", user_input); @@ -239,8 +231,8 @@ PUBLIC char *LYNewsPost ARGS2( */ print_wwwfile_to_fd(fd, 1); } - fclose(fd); /* Close the temp file. */ - scrollok(stdscr, FALSE); /* Stop scrolling. */ + LYCloseTempFP(fd); /* Close the temp file. */ + scrollok(stdscr, FALSE); /* Stop scrolling. */ if (term_message || c == 7 || c == 3) goto cleanup; @@ -275,7 +267,7 @@ PUBLIC char *LYNewsPost ARGS2( term_message) { _statusline(NEWS_POST_CANCELLED); sleep(InfoSecs); - fclose(fd); /* Close the temp file. */ + LYCloseTempFP(fd); /* Close the temp file. */ scrollok(stdscr, FALSE); /* Stop scrolling. */ goto cleanup; } @@ -287,14 +279,14 @@ PUBLIC char *LYNewsPost ARGS2( sizeof(user_input), NORECALL) < 0) { _statusline(NEWS_POST_CANCELLED); sleep(InfoSecs); - fclose(fd); /* Close the temp file. */ - scrollok(stdscr, FALSE); /* Stop scrolling. */ + LYCloseTempFP(fd); /* Close the temp file. */ + scrollok(stdscr, FALSE); /* Stop scrolling. */ goto cleanup; } } fprintf(fd, "\n"); - fclose(fd); /* Close the temp file. */ - scrollok(stdscr, FALSE); /* Stop scrolling. */ + LYCloseTempFP(fd); /* Close the temp file. */ + scrollok(stdscr, FALSE); /* Stop scrolling. */ } /* @@ -322,7 +314,7 @@ PUBLIC char *LYNewsPost ARGS2( !term_message && c != 7 && c != 3) c = LYgetch(); if (TOUPPER(c) == 'Y') { - if ((fd = fopen(my_tempfile, "a")) != NULL) { + if ((fd = LYAppendToTxtFile (my_tempfile)) != NULL) { fputs("-- \n", fd); while (fgets(user_input, sizeof(user_input), fp) != NULL) { fputs(user_input, fd); @@ -348,16 +340,10 @@ PUBLIC char *LYNewsPost ARGS2( (unsigned char *)CJKinput); fputs(CJKinput, fc); } - fclose(fc); + LYCloseTempFP(fc); StrAllocCopy(postfile, CJKfile); fclose(fd); -#ifdef VMS - while (remove(my_tempfile) == 0) - ; /* loop through all versions */ -#else - remove(my_tempfile); -#endif /* VMS */ - fd = fc; + LYRemoveTemp(my_tempfile); strcpy(my_tempfile, CJKfile); CJKfile[0] = '\0'; } else { @@ -391,23 +377,9 @@ cleanup: signal(SIGINT, cleanup_sig); #endif /* !VMS */ term_message = FALSE; - if (!postfile) { -#ifdef VMS - while (remove(my_tempfile) == 0) - ; /* loop through all versions */ -#else - remove(my_tempfile); -#endif /* VMS */ - } - if (CJKfile[0] != '\0') { -#ifdef VMS - fclose(fc); - while (remove(CJKfile) == 0) - ; /* loop through all versions */ -#else - remove(CJKfile); -#endif /* VMS */ - } + if (!postfile) + LYRemoveTemp(my_tempfile); + LYRemoveTemp(CJKfile); FREE(NewsGroups); return(postfile); diff --git a/src/LYPrint.c b/src/LYPrint.c index 72d7e322..05ff5ee6 100644 --- a/src/LYPrint.c +++ b/src/LYPrint.c @@ -59,8 +59,8 @@ * * incorporate the idea of "lpansi" directly into LYPrint.c - HN */ -#define LPANSI 3 -#define MAIL 4 +#define LPANSI 3 +#define MAIL 4 #define PRINTER 5 #ifdef VMS @@ -71,7 +71,6 @@ PUBLIC int printfile ARGS1( document *, newdoc) { static char tempfile[256]; - static BOOLEAN first = TRUE; char buffer[LINESIZE]; char filename[LINESIZE]; char user_response[256]; @@ -609,44 +608,19 @@ PUBLIC int printfile ARGS1( strcpy(user_response, filename); } - if (first) { - tempname(tempfile, NEW_FILE); - if (isPMDF) { - tempname(hdrfile, NEW_FILE); - if ((len = strlen(hdrfile)) > 4) { - len -= 5; - if (!strcasecomp((hdrfile + len), ".html")) { - hdrfile[len] = '\0'; - strcat(hdrfile, ".txt"); - } - } - } - first = FALSE; - } else { - remove(tempfile); /* remove duplicates */ - } - if (HTisDocumentSource()) { - if ((len = strlen(tempfile)) > 3) { - len -= 4; - if (!strcasecomp((tempfile + len), ".txt")) { - tempfile[len] = '\0'; - strcat(tempfile, ".html"); - } - } - } else if ((len = strlen(tempfile)) > 4) { - len -= 5; - if (!strcasecomp((tempfile + len), ".html")) { - tempfile[len] = '\0'; - strcat(tempfile, ".txt"); - } - } - if ((outfile_fp = LYNewTxtFile(tempfile)) == NULL) { + LYRemoveTemp(tempfile); + outfile_fp = LYOpenTemp(tempfile, + (HTisDocumentSource()) + ? HTML_SUFFIX + : ".txt", + "w"); + if (outfile_fp == NULL) { HTAlert(UNABLE_TO_OPEN_TEMPFILE); break; } if (isPMDF) { - if ((hfd = LYNewTxtFile(hdrfile)) == NULL) { + if ((hfd = LYOpenTemp(hdrfile, ".txt", "w")) == NULL) { HTAlert(UNABLE_TO_OPEN_TEMPFILE); break; } @@ -715,7 +689,7 @@ PUBLIC int printfile ARGS1( print_wwwfile_to_fd(outfile_fp, 0); if (keypad_mode) printlist(outfile_fp, FALSE); - fclose(outfile_fp); + LYCloseTempFP(outfile_fp); if (isPMDF) { /* @@ -723,7 +697,7 @@ PUBLIC int printfile ARGS1( * header file and close it. - FM */ fprintf(hfd, "Subject: %.70s\n\n", sug_filename); - fclose(hfd); + LYCloseTempFP(hfd); /* * Now set up the command. - FM */ @@ -756,29 +730,21 @@ PUBLIC int printfile ARGS1( fflush(stdout); sleep(AlertSecs); start_curses(); - if (isPMDF) { - /* - * Delete the header file. - FM - */ - remove(hdrfile); - } -#else /* Unix: */ - sprintf(buffer, "%s %s", system_mail, system_mail_flags); + if (isPMDF) + LYRemoveTemp(hdrfile); +#else /* Unix or DOS */ #ifdef DOSPATH - sprintf(tempfile, "%s%s", lynx_temp_space, "temp_mail.txt"); - if ((outfile_fp = LYNewTxtFile(tempfile)) == NULL) { - _statusline(MAIL_REQUEST_FAILED); - sleep(AlertSecs); - return; - } + outfile_fp = LYOpenTemp(tempfile, ".txt", "w"); #else - if ((outfile_fp = popen(buffer, "w")) == NULL) { - _statusline(MAIL_REQUEST_FAILED); - sleep(AlertSecs); - break; - } + sprintf(buffer, "%s %s", system_mail, system_mail_flags); + outfile_fp = popen(buffer, "w"); #endif + if (outfile_fp == NULL) { + _statusline(MAIL_REQUEST_FAILED); + sleep(AlertSecs); + break; + } /* * Determine which mail headers should be sent. @@ -884,13 +850,13 @@ PUBLIC int printfile ARGS1( #ifdef DOSPATH sprintf(buffer, "%s -t \"%s\" -F %s", system_mail, user_response, tempfile); - fclose(outfile_fp); /* Close the tmpfile. */ + LYCloseTempFP(outfile_fp); /* Close the tmpfile. */ stop_curses(); printf("Sending \n\n$ %s\n\nPlease wait...", buffer); system(buffer); sleep(MessageSecs); start_curses(); - remove(tempfile); /* Delete the tmpfile. */ + LYRemoveTemp(tempfile); /* Delete the tmpfile. */ #else pclose(outfile_fp); #endif @@ -1012,28 +978,13 @@ PUBLIC int printfile ARGS1( } } - if (first) { - tempname(tempfile, NEW_FILE); - first = FALSE; - } else { - remove(tempfile); /* Remove previous tempfile. */ - } - if (((cp = strrchr(tempfile, '.')) != NULL) && -#ifdef VMS - NULL == strchr(cp, ']') && -#endif /* VMS */ - NULL == strchr(cp, '/')) { - if (HTisDocumentSource() && - strcasecomp(cp, HTML_SUFFIX)) { - *cp = '\0'; - strcat(tempfile, HTML_SUFFIX); - } else if (!HTisDocumentSource() && - strcasecomp(cp, ".txt")) { - *cp = '\0'; - strcat(tempfile, ".txt"); - } - } - if ((outfile_fp = LYNewTxtFile(tempfile)) == NULL) { + LYRemoveTemp(tempfile); + outfile_fp = LYOpenTemp(tempfile, + (HTisDocumentSource()) + ? HTML_SUFFIX + : ".txt", + "w"); + if (outfile_fp == NULL) { HTAlert(FILE_ALLOC_FAILED); break; } @@ -1273,7 +1224,6 @@ PUBLIC int printfile ARGS1( #endif /* !VMS */ sleep(MessageSecs); start_curses(); - /* don't remove(tempfile); */ } /* end switch */ FREE(link_info); @@ -1317,7 +1267,6 @@ PUBLIC int print_options ARGS2( int, lines_in_file) { static char tempfile[256]; - static BOOLEAN first = TRUE; static char print_filename[256]; char buffer[LINESIZE]; int count; @@ -1327,25 +1276,14 @@ PUBLIC int print_options ARGS2( pages = lines_in_file/66 + 1; - if (first) { - tempname(tempfile, NEW_FILE); -#if defined (VMS) || defined (DOSPATH) || defined (__EMX__) - sprintf(print_filename, "file://localhost/%s", tempfile); -#else - sprintf(print_filename, "file://localhost%s", tempfile); -#endif /* VMS */ - first = FALSE; -#ifdef VMS - } else { - remove(tempfile); /* Remove duplicates on VMS. */ -#endif /* !VMS */ - } - - if ((fp0 = LYNewTxtFile(tempfile)) == NULL) { + LYRemoveTemp(tempfile); + if ((fp0 = LYOpenTemp(tempfile, HTML_SUFFIX, "w")) == NULL) { HTAlert(UNABLE_TO_OPEN_PRINTOP_FILE); return(-1); } + LYLocalFileToURL(print_filename, tempfile); + StrAllocCopy(*newfile, print_filename); LYforce_no_cache = TRUE; @@ -1395,7 +1333,7 @@ PUBLIC int print_options ARGS2( fprintf(fp0, "</a>\n"); } fprintf(fp0, "</pre>\n</body>\n"); - fclose(fp0); + LYCloseTempFP(fp0); LYforce_no_cache = TRUE; return(0); diff --git a/src/LYShowInfo.c b/src/LYShowInfo.c index af6a6e71..f0ae2a20 100644 --- a/src/LYShowInfo.c +++ b/src/LYShowInfo.c @@ -36,7 +36,6 @@ PUBLIC int showinfo ARGS4( char *, owner_address) { static char tempfile[256]; - static BOOLEAN first = TRUE; static char info_url[256]; int url_type; FILE *fp0; @@ -49,28 +48,15 @@ PUBLIC int showinfo ARGS4( struct passwd *pw; struct group *grp; #endif /* DIRED_SUPPORT */ - if (first) { - tempname(tempfile, NEW_FILE); - /* - * Make the temporary file a URL now. - */ -#if defined (VMS) || defined (DOSPATH) || defined (__EMX__) - sprintf(info_url, "file://localhost/%s", tempfile); -#else - sprintf(info_url, "file://localhost%s", tempfile); -#endif /* VMS */ - first = FALSE; -#ifdef VMS - } else { - remove(tempfile); /* Remove duplicates on VMS. */ -#endif /* VMS */ - } - if ((fp0 = LYNewTxtFile(tempfile)) == NULL) { + LYRemoveTemp(tempfile); + if ((fp0 = LYOpenTemp (tempfile, HTML_SUFFIX, "w")) == 0) { HTAlert(CANNOT_OPEN_TEMP); return(0); } + LYLocalFileToURL(info_url, tempfile); + /* * Point the address pointer at this Url */ @@ -357,7 +343,7 @@ PUBLIC int showinfo ARGS4( refresh(); - fclose(fp0); + LYCloseTemp(tempfile); FREE(Address); FREE(Title); diff --git a/src/LYUpload.c b/src/LYUpload.c index cf5d55f8..cfbca0e6 100644 --- a/src/LYUpload.c +++ b/src/LYUpload.c @@ -226,30 +226,14 @@ PUBLIC int LYUpload_options ARGS2( char *, directory) { static char tempfile[256]; - static BOOLEAN first = TRUE; FILE *fp0; lynx_html_item_type *cur_upload; int count; static char curloc[256]; char *cp; - if (first) { - /* - * Get an unused tempfile name. - FM - */ - tempname(tempfile, NEW_FILE); -#ifdef VMS - } else { - remove(tempfile); /* Remove duplicates on VMS. */ -#endif /* VMS */ - } - - /* - * Open the tempfile for writing and set it's - * protection in case this wasn't done via an - * external umask. - FM - */ - if ((fp0 = LYNewTxtFile(tempfile)) == NULL) { + LYRemoveTemp(tempfile); + if ((fp0 = LYOpenTemp(tempfile, HTML_SUFFIX, "w")) == NULL) { HTAlert(CANNOT_OPEN_TEMP); return(-1); } @@ -268,17 +252,7 @@ PUBLIC int LYUpload_options ARGS2( curloc[strlen(curloc) - 1] = '\0'; #endif /* VMS */ - if (first) { - /* - * Make the tempfile a URL. - */ -#if defined (VMS) || defined (DOSPATH) || defined (__EMX__) - sprintf(LYUploadFileURL, "file://localhost/%s", tempfile); -#else - sprintf(LYUploadFileURL, "file://localhost%s", tempfile); -#endif /* VMS */ - first = FALSE; - } + LYLocalFileToURL(LYUploadFileURL, tempfile); StrAllocCopy(*newfile, LYUploadFileURL); fprintf(fp0, "<head>\n<title>%s</title>\n</head>\n<body>\n", @@ -307,7 +281,7 @@ an unlimited number of upload methods using the lynx.cfg file.\n"); } fprintf(fp0, "</pre>\n</body>\n"); - fclose(fp0); + LYCloseTempFP(fp0); LYforce_no_cache = TRUE; diff --git a/src/LYUtils.c b/src/LYUtils.c index a6053827..69fbbe83 100644 --- a/src/LYUtils.c +++ b/src/LYUtils.c @@ -2396,9 +2396,9 @@ PUBLIC int LYCheckForProxyURL ARGS1( * matches (and return true in that case). */ static BOOLEAN compare_type ARGS3( - char *, tst, - char *, cmp, - size_t, len) + char *, tst, + char *, cmp, + size_t, len) { if (!strncasecomp(tst, cmp, len)) { if (strncmp(tst, cmp, len)) { @@ -2818,9 +2818,9 @@ PUBLIC void size_change ARGS1( int old_cols = LYcols; #ifdef USE_SLANG -#if defined(VMS) || defined(UNIX) +#if defined(VMS) || defined(UNIX) SLtt_get_screen_size(); -#endif /* VMS || UNIX */ +#endif /* VMS || UNIX */ LYlines = SLtt_Screen_Rows; LYcols = SLtt_Screen_Cols; #ifdef SLANG_MBCS_HACK @@ -3222,122 +3222,41 @@ PUBLIC void change_sug_filename ARGS1( } /* - * Construct a name for 'tempname()' + * Construct a temporary-filename */ PRIVATE char *fmt_tempname ARGS3( - char *, result, + char *, result, unsigned, counter, - char *, suffix) + CONST char *, suffix) { - sprintf(result, + char *leaf; + strcpy(result, lynx_temp_space); + leaf = result + strlen(result); #ifdef FNAMES_8_3 - "%s%u%u%s", + /* + * The 'lynx_temp_space' string ends with a '/' or '\\', so we only have to + * limit the length of the leaf. As received (e.g., from HTCompressed), + * the suffix may contain more than a ".htm", e.g., "-txt.gz", so we trim + * off from the filename portion to make room. + */ + sprintf(leaf, "%u%u", counter, (unsigned)getpid()); + if (strlen(leaf) > 8) + leaf[8] = 0; + if (strlen(suffix) > 4 || *suffix != '.') { + CONST char *tail = strchr(suffix, '.'); + if (tail == 0) + tail = suffix + strlen(suffix); + leaf[8 - (tail - suffix)] = 0; + } + strcat(leaf, suffix); #else - "%sL%u-%uTMP%s", + sprintf(leaf, "L%u-%uTMP%s", (unsigned)getpid(), counter, suffix); #endif - lynx_temp_space, (unsigned)getpid(), counter, suffix); CTRACE(tfp, "-> '%s'\n", result); return result; } /* - * 'tempname()' requires that the resulting file does not exist. Test this - * by trying to open it. - */ -PRIVATE BOOLEAN bad_tempname ARGS3( - char *, result, - unsigned, counter, - char *, suffix) -{ - FILE *fp; - - if ((fp = fopen(fmt_tempname(result, counter, suffix), "r")) != 0) { - fclose(fp); - CTRACE(tfp, "tempname: file '%s' already exists!\n", result); - return TRUE; - } - - return FALSE; -} - -/* - * To create standard temporary file names. - */ -PUBLIC void tempname ARGS2( - char *, namebuffer, - int, action) -{ - static unsigned counter = 0; -#ifdef FNAMES_8_3 - unsigned LYMaxTempCount = 1000; /* Arbitrary limit. Make it configurable? */ -#else - unsigned LYMaxTempCount = 10000; /* Arbitrary limit. Make it configurable? */ -#endif /* FNAMES_8_3 */ - - if (action == REMOVE_FILES) { - /* - * Remove all temporary files with .txt or .html suffixes. - FM - */ - CTRACE(tfp, "tempname REMOVE_FILES (%d)\n", counter); - for (; counter != 0; counter--) { - remove(fmt_tempname(namebuffer, counter-1, ".txt")); - remove(fmt_tempname(namebuffer, counter-1, HTML_SUFFIX)); - } - } else { - /* - * Load a tentative temporary file name into namebuffer. - FM - */ - CTRACE(tfp, "tempname NEW_FILE (%d)\n", counter); - while (counter < LYMaxTempCount) { - /* - * Create names with .txt, then .bin, then - * .html suffixes, and check for their prior - * existence. If any already exist, someone - * might be trying to spoof us, so increment - * the count and try again. Otherwise, return - * with the name which has the .html suffix - * loaded in namebuffer. - FM - * - * Some systems may use .htm instead of .html. This - * should be done consistently by always using HTML_SUFFIX - * where filenames are generated for new local files. - kw - */ - if (bad_tempname(namebuffer, counter, ".txt") - || bad_tempname(namebuffer, counter, ".bin") - || bad_tempname(namebuffer, counter, HTML_SUFFIX)) { - continue; - } - /* - * Return to the calling function, with the tentative - * temporary file name loaded in namebuffer. Note that - * if the calling function will use a suffix other than - * .txt, .bin, or .html, it similarly should do tests for - * a spoof. The file name can be reused if it is written - * to on receipt of this name, and thereafter accessed - * for reading. Note that if writing to a file is to - * be followed by reading it, as is the usual case for - * Lynx, the spoof attempt will be apparent, and the user - * can take appropriate action. - FM - */ - counter++; - return; - } - /* - * The tempfile maximum count has been reached. - * Issue a message and exit. - FM - */ - _statusline(MAX_TEMPCOUNT_REACHED); - sleep(AlertSecs); - exit(-1); - } - - /* - * We were called for a clean up, and have done it. - FM - */ - return; -} - -/* * Convert 4, 6, 2, 8 to left, right, down, up, etc. */ PUBLIC int number2arrows ARGS1( @@ -5519,3 +5438,244 @@ PUBLIC void LYRelaxFilePermissions ARGS1(CONST char *, name) } } #endif + +/* + * Check if the given anchor has an associated file-cache. + */ +PUBLIC BOOLEAN LYCachedTemp ARGS2( + char *, result, + char *, cached) +{ + FILE *fp; + + if (cached) { + strcpy(result, cached); + FREE(cached); + if ((fp = fopen(result, "r")) != NULL) { + fclose(fp); + remove(result); + } + return TRUE; + } + return FALSE; +} + +/* + * Maintain a list of all of the temp-files we create so that we can remove + * them during the cleanup. + */ +typedef struct _LYTemp { + struct _LYTemp *next; + char *name; + FILE *file; +} LY_TEMP; + +static LY_TEMP *ly_temp; + +/* + * Open a temp-file, ensuring that it is unique, and not readable by other + * users. + * + * The mode can be one of: "w", "a", "wb". + */ +PUBLIC FILE *LYOpenTemp ARGS3( + char *, result, + CONST char *, suffix, + CONST char *, mode) +{ + FILE *fp = 0; + BOOL txt = TRUE; + BOOL wrt = 'r'; + LY_TEMP *p; + static unsigned counter; + + CTRACE(tfp, "LYOpenTemp(,%s,%s)\n", suffix, mode); + while (*mode != '\0') { + switch (*mode++) { + case 'w': wrt = 'w'; break; + case 'a': wrt = 'a'; break; + case 'b': txt = FALSE; break; + default: + CTRACE(tfp, "%s @%d: BUG\n", __FILE__, __LINE__); + return fp; + } + } + + do { + (void) fmt_tempname(result, counter++, suffix); + if (txt) { + switch (wrt) { + case 'w': + fp = LYNewTxtFile (result); + break; + case 'a': + fp = LYAppendToTxtFile (result); + break; + } + } else { + fp = LYNewBinFile (result); + } + } while (fp == 0); + + if ((p = (LY_TEMP *)calloc(1, sizeof(LY_TEMP))) != 0) { + p->next = ly_temp; + StrAllocCopy((p->name), result); + p->file = fp; + ly_temp = p; + } + + CTRACE(tfp, "... LYOpenTemp(%s)\n", result); + return fp; +} + +/* + * Reopen a temporary file + */ +PUBLIC FILE *LYReopenTemp ARGS1( + char *, name) +{ + LY_TEMP *p; + FILE *fp; + + LYCloseTemp(name); + for (p = ly_temp; p != 0; p = p->next) { + if (!strcmp(p->name, name)) { + fp = p->file = LYAppendToTxtFile (name); + break; + } + } + return fp; +} + +/* + * Special case of LYOpenTemp, used for manipulating bookmark file, i.e., with + * renaming. + */ +PUBLIC FILE *LYOpenScratch ARGS2( + char *, result, + CONST char *, prefix) +{ + FILE *fp; + LY_TEMP *p; + + sprintf(result, "%s-%u.%s", prefix, getpid(), HTML_SUFFIX); + if ((fp = LYNewTxtFile (result)) != 0) { + if ((p = (LY_TEMP *)calloc(1, sizeof(LY_TEMP))) != 0) { + p->next = ly_temp; + StrAllocCopy((p->name), result); + p->file = fp; + ly_temp = p; + } + } + CTRACE(tfp, "LYOpenScratch(%s)\n", result); + return fp; +} + +/* + * Close a temp-file, given its name + */ +PUBLIC void LYCloseTemp ARGS1( + char *, name) +{ + LY_TEMP *p; + + CTRACE(tfp, "LYCloseTemp(%s)\n", name); + for (p = ly_temp; p != 0; p = p->next) { + if (!strcmp(name, p->name)) { + CTRACE(tfp, "...LYCloseTemp(%s)%s\n", name, + (p->file != 0) ? ", closed" : ""); + if (p->file != 0) { + fclose(p->file); + p->file = 0; + } + break; + } + } +} + +/* + * Close a temp-file, given its file-pointer + */ +PUBLIC void LYCloseTempFP ARGS1( + FILE *, fp) +{ + LY_TEMP *p; + + CTRACE(tfp, "LYCloseTempFP\n"); + for (p = ly_temp; p != 0; p = p->next) { + if (p->file == fp) { + fclose(p->file); + p->file = 0; + break; + } + } +} + +/* + * Close a temp-file, removing it. + */ +PUBLIC void LYRemoveTemp ARGS1( + char *, name) +{ + LY_TEMP *p, *q; + int code; + + if (name != 0 && *name != 0) { + CTRACE(tfp, "LYRemoveTemp(%s)\n", name); + for (p = ly_temp, q = 0; p != 0; q = p, p = p->next) { + if (!strcmp(name, p->name)) { + if (q != 0) { + q->next = p->next; + } else { + ly_temp = p->next; + } +#ifdef VMS + while (remove(name) == 0) + ; +#else + code = remove(name); +#endif + CTRACE(tfp, "...LYRemoveTemp done(%d)%s\n", code, + (p->file != 0) ? ", closed" : ""); + if (p->file != 0) + fclose(p->file); + free(p->name); + free(p); + break; + } + } + } +} + +/* + * Remove all of the temp-files. Note that this assumes that they are closed, + * since some systems will not allow us to remove a file which is open. + */ +PUBLIC void LYCleanupTemp NOARGS +{ + while (ly_temp != 0) { + LYRemoveTemp(ly_temp->name); + } +} + +/* + * Convert a local filename to a URL + */ +PUBLIC void LYLocalFileToURL ARGS2( + char *, target, + char *, source) +{ +#ifdef DOSPATH + sprintf(target, "file://localhost/%s", HTDOS_wwwName(source)); +#else +#ifdef VMS + sprintf(target, "file://localhost%s", HTVMS_wwwName(source)); +#else +#ifdef __EMX__ + sprintf(target, "file://localhost/%s", source); +#else + sprintf(target, "file://localhost%s", source); +#endif /* __EMX__ */ +#endif /* VMS */ +#endif /* DOSPATH */ +} diff --git a/src/LYUtils.h b/src/LYUtils.h index 790d84a2..61baf346 100644 --- a/src/LYUtils.h +++ b/src/LYUtils.h @@ -32,7 +32,6 @@ extern void size_change PARAMS((int sig)); extern void HTSugFilenames_free NOPARAMS; extern void HTAddSugFilename PARAMS((char *fname)); extern void change_sug_filename PARAMS((char *fname)); -extern void tempname PARAMS((char *namebuffer, int action)); extern int number2arrows PARAMS((int number)); extern void parse_restrictions PARAMS((char *s)); extern void checkmail NOPARAMS; @@ -58,12 +57,22 @@ extern time_t LYmktime PARAMS((char *string, BOOL absolute)); extern int putenv PARAMS((CONST char *string)); #endif /* HAVE_PUTENV */ -FILE *LYNewBinFile PARAMS((char * name)); -FILE *LYNewTxtFile PARAMS((char * name)); -FILE *LYAppendToTxtFile PARAMS((char * name)); +extern FILE *LYNewBinFile PARAMS((char * name)); +extern FILE *LYNewTxtFile PARAMS((char * name)); +extern FILE *LYAppendToTxtFile PARAMS((char * name)); #ifdef UNIX extern void LYRelaxFilePermissions PARAMS((CONST char * name)); #endif +extern BOOLEAN LYCachedTemp PARAMS((char *result, char *cached)); +extern FILE *LYOpenTemp PARAMS((char *result, CONST char *suffix, CONST char *mode)); +extern FILE *LYReopenTemp PARAMS((char *name)); +extern FILE *LYOpenScratch PARAMS((char *result, CONST char *prefix)); +extern void LYCloseTemp PARAMS((char *name)); +extern void LYCloseTempFP PARAMS((FILE *fp)); +extern void LYRemoveTemp PARAMS((char *name)); +extern void LYCleanupTemp NOPARAMS; +extern void LYLocalFileToURL PARAMS((char *target, char *source)); + /* * Whether or not the status line must be shown. */ @@ -125,12 +134,6 @@ extern BOOLEAN mustshow; extern HTList *sug_filenames; /* - * For tempname(). - */ -#define NEW_FILE 0 -#define REMOVE_FILES 1 - -/* * Miscellaneous. */ #define ON 1 diff --git a/src/UCdomap.c b/src/UCdomap.c index 1e50a578..52617440 100644 --- a/src/UCdomap.c +++ b/src/UCdomap.c @@ -894,7 +894,7 @@ PRIVATE int conv_uni_to_pc ARGS2( * Not a printable character. */ return -1; - } else if (ucs == 0xfeff || (ucs >= 0x200a && ucs <= 0x200f)) { + } else if (ucs == 0xfeff || (ucs >= 0x200b && ucs <= 0x200f)) { /* * Zero-width space. */ @@ -959,7 +959,7 @@ PRIVATE int conv_uni_to_str ARGS4( * Not a printable character. */ return -1; - } else if (ucs == 0xfeff || (ucs >= 0x200a && ucs <= 0x200f)) { + } else if (ucs == 0xfeff || (ucs >= 0x200b && ucs <= 0x200f)) { /* * Zero-width space. */ |