diff options
author | Thomas E. Dickey <dickey@invisible-island.net> | 2000-01-07 03:20:24 -0500 |
---|---|---|
committer | Thomas E. Dickey <dickey@invisible-island.net> | 2000-01-07 03:20:24 -0500 |
commit | d61bc4e56055c372ab0b8d027f376c2f4a2ecfff (patch) | |
tree | 8d4e0da5b7cf703c2167d84dc84b54669183bba1 /src | |
parent | f61041c10496785b2833ee4f76ef3edc9792b1bd (diff) | |
download | lynx-snapshots-d61bc4e56055c372ab0b8d027f376c2f4a2ecfff.tar.gz |
snapshot of project "lynx", label v2-8-3dev_18
Diffstat (limited to 'src')
-rw-r--r-- | src/GridText.c | 67 | ||||
-rw-r--r-- | src/GridText.h | 2 | ||||
-rw-r--r-- | src/HTML.c | 20 | ||||
-rw-r--r-- | src/LYCurses.c | 66 | ||||
-rw-r--r-- | src/LYGetFile.c | 6 | ||||
-rw-r--r-- | src/LYGlobalDefs.h | 1 | ||||
-rw-r--r-- | src/LYLocal.c | 3 | ||||
-rw-r--r-- | src/LYMain.c | 55 | ||||
-rw-r--r-- | src/LYMainLoop.c | 80 | ||||
-rw-r--r-- | src/LYOptions.c | 62 | ||||
-rw-r--r-- | src/LYPrettySrc.c | 12 | ||||
-rw-r--r-- | src/LYPrettySrc.h | 4 | ||||
-rw-r--r-- | src/LYReadCFG.c | 142 | ||||
-rw-r--r-- | src/LYReadCFG.h | 4 | ||||
-rw-r--r-- | src/LYUtils.c | 138 |
15 files changed, 418 insertions, 244 deletions
diff --git a/src/GridText.c b/src/GridText.c index 5b9dbc8a..367b6280 100644 --- a/src/GridText.c +++ b/src/GridText.c @@ -11,6 +11,7 @@ #include <HTTP.h> #include <HTAlert.h> #include <HTCJK.h> +#include <HTFile.h> #include <UCDefs.h> #include <UCAux.h> @@ -435,7 +436,7 @@ static int justify_start_position;/* this is an index of char from which static int ht_num_runs;/*the number of runs filled*/ static ht_run_info ht_runs[MAX_LINE]; -static BOOL this_line_was_splitted; +static BOOL this_line_was_split; static TextAnchor* last_anchor_of_previous_line; static int justified_text_map[MAX_LINE]; /* this is a map - for each index i it tells to which position j=justified_text_map[i] in justified text @@ -446,7 +447,7 @@ static BOOL have_raw_nbsps = FALSE; PUBLIC void ht_justify_cleanup NOARGS { wait_for_this_stacked_elt = !ok_justify -# ifdef USE_PSRC +# ifdef USE_PRETTYSRC || psrc_view # endif ? 30000/*MAX_NESTING*/+2 /*some unreachable value*/ : -1; @@ -455,7 +456,7 @@ PUBLIC void ht_justify_cleanup NOARGS form_in_htext = FALSE; last_anchor_of_previous_line = NULL; - this_line_was_splitted = FALSE; + this_line_was_split = FALSE; in_DT = FALSE; have_raw_nbsps = FALSE; } @@ -803,7 +804,7 @@ PUBLIC HText * HText_new ARGS1( self->LastChar = '\0'; self->IgnoreExcess = FALSE; -#ifndef USE_PSRC +#ifndef USE_PRETTYSRC if (HTOutputFormat == WWW_SOURCE) self->source = YES; else @@ -2367,6 +2368,24 @@ PRIVATE void split_line ARGS2( CTRACE((tfp," bold_on=%d, underline_on=%d\n", bold_on, underline_on)); #endif + cp = previous->data; + if (cp[0] == LY_BOLD_START_CHAR + || cp[0] == LY_UNDERLINE_START_CHAR) { + switch (cp[1]) { + case LY_SOFT_NEWLINE: + cp[1] = cp[0]; + cp[0] = LY_SOFT_NEWLINE; + break; + case LY_BOLD_START_CHAR: + case LY_UNDERLINE_START_CHAR: + if (cp[2] == LY_SOFT_NEWLINE) { + cp[2] = cp[1]; + cp[1] = cp[0]; + cp[0] = LY_SOFT_NEWLINE; + } + break; + } + } if (split > previous->size) { CTRACE((tfp, "*** split_line: split==%d greater than last_line->size==%d !\n", @@ -2568,7 +2587,7 @@ PRIVATE void split_line ARGS2( #else (previous->data[previous->size-1] == ' ') && #endif -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC !psrc_view && /*don't strip trailing whites - since next line can start with LY_SOFT_NEWLINE - so we don't lose spaces when 'p'rinting this text to file -VH */ @@ -2777,7 +2796,7 @@ PRIVATE void split_line ARGS2( spare = 0; if ( #ifdef EXP_JUSTIFY_ELTS - this_line_was_splitted || + this_line_was_split || #endif (alignment == HT_CENTER || alignment == HT_RIGHT) || text->stbl) { @@ -3011,7 +3030,15 @@ PRIVATE void split_line ARGS2( #ifdef EXP_JUSTIFY_ELTS /* now perform justification - by VH */ - if (this_line_was_splitted && spare ) { + if (this_line_was_split + && spare + && justify_max_void_percent > 0 + && justify_max_void_percent <= 100 + && justify_max_void_percent >= ((100*spare) + / ((LYcols - 1) + - (int)style->rightIndent + - indent + + ctrl_chars_on_previous_line))) { /* this is the only case when we need justification*/ char* jp = previous->data + justify_start_position; ht_run_info* r = ht_runs; @@ -3297,7 +3324,7 @@ PRIVATE void split_line ARGS2( /* cleanup */ can_justify_this_line = TRUE; justify_start_position = 0; - this_line_was_splitted = FALSE; + this_line_was_split = FALSE; have_raw_nbsps = FALSE; #endif /* EXP_JUSTIFY_ELTS */ } /* split_line */ @@ -3987,7 +4014,7 @@ check_IgnoreExcess: if (style->wordWrap && HTOutputFormat != WWW_SOURCE) { #ifdef EXP_JUSTIFY_ELTS if (REALLY_CAN_JUSTIFY(text)) - this_line_was_splitted=TRUE; + this_line_was_split = TRUE; #endif split_line(text, text->permissible_split); if (ch == ' ') return; /* Ignore space causing split */ @@ -4680,10 +4707,10 @@ PUBLIC void HText_endStblTABLE ARGS1( lines_changed = HText_insertBlanksInStblLines(me, ncols); CTRACE((tfp, "endStblTABLE: changed %d lines, done.\n", lines_changed)); #ifdef DISP_PARTIAL - /* allow HTDisplayPartial() to redisplay the changed lines. - * There is no harm if we got several stbl in the document, hope so. - */ - NumOfLines_partial -= lines_changed; /* fake */ + /* allow HTDisplayPartial() to redisplay the changed lines. + * There is no harm if we got several stbl in the document, hope so. + */ + NumOfLines_partial -= lines_changed; /* fake */ #endif /* DISP_PARTIAL */ } Stbl_free(me->stbl); @@ -4844,7 +4871,7 @@ PUBLIC int HText_beginAnchor ARGS3( * If we are doing link_numbering add the link number. */ if ((a->number > 0) && -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC (text->source ? !psrcview_no_anchor_numbering : 1 ) && #endif (keypad_mode == LINKS_ARE_NUMBERED || @@ -7413,11 +7440,7 @@ PUBLIC void print_wwwfile_to_fd ARGS2( line = HTMainText->last_line->next; for (;; line = line->next) { - if (!first && - line->data[0] != LY_SOFT_NEWLINE && - line->data[0] != '\0' && - line->data[1] != LY_SOFT_NEWLINE) { - /* data[0] can be LY_*START_CHAR, so LY_SOFT_NEWLINE can be in [1] - VH */ + if (!first && line->data[0] != LY_SOFT_NEWLINE) { fputc('\n',fp); /* * Add news-style quotation if requested. - FM @@ -7540,9 +7563,7 @@ PUBLIC void print_crawl_to_fd ARGS3( } for (;; line = line->next) { - if (!first - && line->data[0] != LY_SOFT_NEWLINE && line->data[1] != LY_SOFT_NEWLINE) - /* data[0] can be LY_*START_CHAR, so LY_SOFT_NEWLINE can be in [1] - VH */ + if (!first && line->data[0] != LY_SOFT_NEWLINE) fputc('\n',fp); first = FALSE; /* @@ -13621,7 +13642,7 @@ PUBLIC void redraw_lines_of_link ARGS1( return; } -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC PUBLIC void HTMark_asSource NOARGS { if (HTMainText) diff --git a/src/GridText.h b/src/GridText.h index 353f0187..ba6ce2cb 100644 --- a/src/GridText.h +++ b/src/GridText.h @@ -304,7 +304,7 @@ extern void LYMoveToLink PARAMS(( BOOL utf_flag)); -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC extern void HTMark_asSource NOPARAMS; #endif diff --git a/src/HTML.c b/src/HTML.c index 656ebac8..a1492ed9 100644 --- a/src/HTML.c +++ b/src/HTML.c @@ -49,7 +49,7 @@ #include <LYCurses.h> #endif /* VMS */ -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC #include <LYPrettySrc.h> #endif @@ -476,13 +476,13 @@ PUBLIC void HTML_put_character ARGS2(HTStructured *, me, char, c) */ PUBLIC void HTML_put_string ARGS2(HTStructured *, me, CONST char *, s) { -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC char* translated_string = NULL; #endif if (s == NULL || (LYMapsOnly && me->sp[0].tag_number != HTML_OBJECT)) return; -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC if (psrc_convert_string) { StrAllocCopy(translated_string,s); TRANSLATE_AND_UNESCAPE_ENTITIES(&translated_string, TRUE, FALSE); @@ -541,7 +541,7 @@ PUBLIC void HTML_put_string ARGS2(HTStructured *, me, CONST char *, s) * by the cases above (HTML_PRE or similar may not be the * last element pushed on the style stack). - kw */ -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC if (psrc_view) { /* * We do this so that a raw '\r' in the string will not be @@ -622,7 +622,7 @@ PUBLIC void HTML_put_string ARGS2(HTStructured *, me, CONST char *, s) } /* for */ } } /* end switch */ -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC if (psrc_convert_string) { psrc_convert_string = FALSE; FREE(translated_string); @@ -722,7 +722,7 @@ static int hcode; #endif -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC PRIVATE void HTMLSRC_apply_markup ARGS4( HTStructured *, context, @@ -772,7 +772,7 @@ PRIVATE void HTMLSRC_apply_markup ARGS4( # define PUTC(x) HTML_put_character(me,x) # define PUTS(x) HTML_put_string(me,x) -#endif /* USE_PSRC*/ +#endif /* USE_PRETTYSRC*/ PRIVATE void LYStartArea ARGS5( HTStructured *, obj, @@ -966,7 +966,7 @@ PRIVATE int HTML_start_element ARGS6( # endif #endif -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC if (psrc_view && !sgml_in_psrc_was_initialized) { if (!psrc_nested_call) { HTTag * tag = &HTML_dtd.tags[element_number]; @@ -1054,7 +1054,7 @@ PRIVATE int HTML_start_element ARGS6( } /*if (!psrc_nested_call) */ /*fall through*/ } -#endif /* USE_PSRC */ +#endif /* USE_PRETTYSRC */ if (LYMapsOnly) { if (!(ElementNumber == HTML_MAP || ElementNumber == HTML_AREA || @@ -6145,7 +6145,7 @@ PRIVATE int HTML_end_element ARGS3( BOOL skip_stack_requested = FALSE; EMIT_IFDEF_EXP_JUSTIFY_ELTS(BOOL reached_awaited_stacked_elt=FALSE;) -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC if (psrc_view && !sgml_in_psrc_was_initialized) { if (!psrc_nested_call) { HTTag * tag = &HTML_dtd.tags[element_number]; diff --git a/src/LYCurses.c b/src/LYCurses.c index 4067f17c..cdc0eb36 100644 --- a/src/LYCurses.c +++ b/src/LYCurses.c @@ -457,6 +457,28 @@ void attribute ARGS2(int,style,int,dir) #endif #endif /* USE_COLOR_STYLE */ +PRIVATE int lynx_called_initscr; + +#if HAVE_USE_DEFAULT_COLORS && USE_DEFAULT_COLORS +/* + * If we find a "default" color while reading the config-file, set default + * colors on the screen. + */ +PUBLIC int lynx_default_colors NOARGS +{ + int code = 0; + if (lynx_called_initscr) { + code = -1; + if (use_default_colors() == OK) { + default_fg = DEFAULT_COLOR; + default_bg = DEFAULT_COLOR; + code = 1; + } + } + return code; +} +#endif /* HAVE_USE_DEFAULT_COLORS && USE_DEFAULT_COLORS */ + #if USE_COLOR_TABLE && defined(COLOR_CURSES) /* * This block of code is designed to produce the same color effects using SVr4 @@ -466,7 +488,6 @@ void attribute ARGS2(int,style,int,dir) * special case of initialization before 'initscr()' is called. * 1997/1/19 - T.E.Dickey <dickey@clark.net> */ -PRIVATE int lynx_called_initscr; PRIVATE struct { int fg, bg; @@ -532,6 +553,8 @@ PRIVATE void lynx_map_color ARGS1(int, n) { int m; + CTRACE((tfp, "lynx_map_color(%d)\n", n)); + lynx_color_pairs[n+1].fg = lynx_color_cfg[n].fg; lynx_color_pairs[n+1].bg = lynx_color_cfg[n].bg; @@ -595,6 +618,8 @@ PRIVATE void lynx_init_colors NOARGS if (lynx_has_color) { size_t n, m; + CTRACE((tfp, "lynx_init_colors\n")); + lynx_color_cfg[0].fg = default_fg; lynx_color_cfg[0].bg = default_bg; @@ -617,6 +642,7 @@ PRIVATE void lynx_init_colors NOARGS PUBLIC void lynx_setup_colors NOARGS { int n; + CTRACE((tfp, "lynx_setup_colors\n")); for (n = 0; n < 8; n++) lynx_map_color(n); } @@ -771,6 +797,7 @@ PUBLIC void start_curses NOARGS gettext("Terminal initialisation failed - unknown terminal type?")); exit_immediately (-1); } + lynx_called_initscr = TRUE; #if defined(SIGWINCH) && defined(NCURSES_VERSION) size_change(0); recent_sizechange = FALSE; /* prevent mainloop drawing 1st doc twice */ @@ -805,12 +832,40 @@ PUBLIC void start_curses NOARGS if (has_colors()) { lynx_has_color = TRUE; start_color(); -#if HAVE_USE_DEFAULT_COLORS && !defined(PDCURSES) - if (use_default_colors() == OK) { - default_fg = DEFAULT_COLOR; - default_bg = DEFAULT_COLOR; +#if USE_DEFAULT_COLORS +#if HAVE_USE_DEFAULT_COLORS /* ncurses 4.1 */ +#if HAVE_ASSUME_DEFAULT_COLORS /* ncurses 5.1 */ +#if !defined(USE_COLOR_STYLE) + /* + * If no "default" color was specified in the cfg file, adjust the + * color mapping table so we'll not use the codes that would work + * if we had called use_default_colors(). + */ + if (default_fg < 0 || default_bg < 0) { + if (assume_default_colors(default_fg, default_bg) != OK) { + default_fg = COLOR_WHITE; + default_bg = COLOR_BLACK; + } } + if (default_fg >= 0 || default_bg >= 0) { + unsigned n; + for (n = 0; n < TABLESIZE(lynx_color_cfg); n++) { + if (default_fg >= 0 && lynx_color_cfg[n].fg < 0) + lynx_color_cfg[n].fg = default_fg; + if (default_bg >= 0 && lynx_color_cfg[n].bg < 0) + lynx_color_cfg[n].bg = default_bg; + CTRACE((tfp, "color_cfg[%d] = %d/%d\n", n, + lynx_color_cfg[n].fg, + lynx_color_cfg[n].bg)); + } + lynx_setup_colors(); + } +#endif +#else + lynx_default_colors(); +#endif /* HAVE_ASSUME_DEFAULT_COLORS */ #endif /* HAVE_USE_DEFAULT_COLORS */ +#endif /* USE_DEFAULT_COLORS */ } #endif /* USE_COLOR_STYLE || USE_COLOR_TABLE */ @@ -820,7 +875,6 @@ PUBLIC void start_curses NOARGS first_time = FALSE; #if USE_COLOR_TABLE lynx_init_colors(); - lynx_called_initscr = TRUE; #endif /* USE_COLOR_TABLE */ } #ifdef __DJGPP__ diff --git a/src/LYGetFile.c b/src/LYGetFile.c index aeb14192..aaf3203f 100644 --- a/src/LYGetFile.c +++ b/src/LYGetFile.c @@ -1090,20 +1090,20 @@ PUBLIC void srcmode_for_next_retrieval ARGS1( { if (mode < 0) { HTOutputFormat = WWW_PRESENT; -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC psrc_view = FALSE; #endif } else if (mode == 0) { if (HTOutputFormat == WWW_SOURCE) HTOutputFormat = WWW_PRESENT; -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC else if (LYpsrc) psrc_view = FALSE; #endif } else { -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC if (LYpsrc) psrc_view = TRUE; else diff --git a/src/LYGlobalDefs.h b/src/LYGlobalDefs.h index d8f78bbd..7efa8a4a 100644 --- a/src/LYGlobalDefs.h +++ b/src/LYGlobalDefs.h @@ -400,6 +400,7 @@ extern int LYNoZapKey; /* 0: off (do 'z' checking), 1: full, 2: initially */ #ifdef EXP_JUSTIFY_ELTS extern BOOL ok_justify; +extern int justify_max_void_percent; #endif #ifndef NO_DUMP_WITH_BACKSPACES diff --git a/src/LYLocal.c b/src/LYLocal.c index 684cff8a..bc6d8557 100644 --- a/src/LYLocal.c +++ b/src/LYLocal.c @@ -444,6 +444,7 @@ PRIVATE BOOLEAN remove_tagged NOARGS break; } ++count; + FREE(testpath); } } } @@ -599,7 +600,6 @@ PRIVATE BOOLEAN modify_tagged ARGS1( srcpath = HTfullURL_toFile(cp); if (move_file(srcpath, savepath) < 0) { - FREE(cp); if (count == 0) count = -1; break; @@ -2119,6 +2119,7 @@ PUBLIC BOOLEAN local_install ARGS3( err = (LYExecv(INSTALL_PATH, args, tmpbuf) <= 0); FREE(args[src]); if (err) { + FREE(tmpbuf); FREE(tmpdest); return ((count == 0) ? -1 : count); } diff --git a/src/LYMain.c b/src/LYMain.c index d63027ba..1d0434d6 100644 --- a/src/LYMain.c +++ b/src/LYMain.c @@ -437,6 +437,7 @@ PUBLIC BOOLEAN dont_wrap_pre = FALSE; #ifdef EXP_JUSTIFY_ELTS PUBLIC BOOL ok_justify = TRUE; +PUBLIC int justify_max_void_percent = 35; #endif #ifndef NO_DUMP_WITH_BACKSPACES @@ -1512,7 +1513,7 @@ PUBLIC int main ARGS2( CTRACE((tfp, "LYNX_SIG_FILE '%s' is bad. Ignoring.\n", LYNX_SIG_FILE)); } -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC /*this is required for checking the tagspecs when parsing cfg file by LYReadCFG.c:parse_html_src_spec -HV */ HTSwitchDTD(TRUE); @@ -1570,7 +1571,7 @@ PUBLIC int main ARGS2( * Initialize other things based on the configuration read. */ -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC if ( (!Old_DTD) != TRUE ) /* skip if they are already initialized -HV */ #endif HTSwitchDTD(!Old_DTD); @@ -1605,28 +1606,29 @@ PUBLIC int main ARGS2( LYLoadCookies(LYCookieFile); } + /* tilde-expand LYCookieSaveFile */ + if (LYCookieSaveFile != NULL) { + if (LYCookieSaveFile[0] == '~' && LYCookieSaveFile[1] == '/' && + LYCookieSaveFile[2] != '\0') { + temp = NULL; + StrAllocCopy(temp, LYCookieSaveFile + 2); + StrAllocCopy(LYCookieSaveFile, wwwName(Home_Dir())); + LYAddPathSep(&LYCookieSaveFile); + StrAllocCat(LYCookieSaveFile, temp); + FREE(temp); + } + } + /* * In dump_output_immediately mode, LYCookieSaveFile defaults to * /dev/null, otherwise it defaults to LYCookieFile. */ - if (dump_output_immediately) { - if (LYCookieSaveFile != NULL) { - if (LYCookieSaveFile[0] == '~' && LYCookieSaveFile[1] == '/' && - LYCookieSaveFile[2] != '\0') { - temp = NULL; - StrAllocCopy(temp, LYCookieSaveFile + 2); - StrAllocCopy(LYCookieSaveFile, wwwName(Home_Dir())); - LYAddPathSep(&LYCookieSaveFile); - StrAllocCat(LYCookieSaveFile, temp); - FREE(temp); - } + if (LYCookieSaveFile == NULL) { + if (dump_output_immediately) { + StrAllocCopy(LYCookieSaveFile, "/dev/null"); } else { - StrAllocCopy(LYCookieSaveFile, "/dev/null"); - } - } else { - if (LYCookieSaveFile == NULL) { - StrAllocCopy(LYCookieSaveFile, LYCookieFile); + StrAllocCopy(LYCookieSaveFile, LYCookieFile); } } #endif @@ -1895,7 +1897,7 @@ PUBLIC int main ARGS2( * Done here so that URL guessing in LYEnsureAbsoluteURL() can be * interruptible (terminal is in raw mode, select() works). -BL */ -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC if (!dump_output_immediately) { HTMLSRC_init_caches(FALSE); /* do it before terminal is initialized*/ #ifdef LY_FIND_LEAKS @@ -2109,9 +2111,18 @@ PUBLIC void LYRegisterLynxProtocols NOARGS * Some stuff to reload lynx.cfg without restarting new lynx session, * also load options menu items and command-line options * to make things consistent. - * Warning: experimental, more main() reorganization required. * * Called by user of interactive session by LYNXCFG://reload/ link. + * + * Warning: experimental, more main() reorganization required. + * *Known* exceptions: persistent cookies, cookie files. + * + * Some aspects of COLOR (with slang?). + * Viewer stuff, mailcap files + * SUFFIX, mime.types files + * RULESFILE/RULE + * + * All work "somewhat", but not exactly as the first time. */ PUBLIC void reload_read_cfg NOARGS { @@ -2188,7 +2199,7 @@ PUBLIC void reload_read_cfg NOARGS memset((char*)charset_subsets, 0, sizeof(charset_subset_t)*MAXCHARSETS); #endif -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC html_src_on_lynxcfg_reload(); #endif /* free downloaders, printers, environments, dired menu */ @@ -3462,7 +3473,7 @@ with partial-display logic" "show parsed text/html with -source and in source view\n\ to visualize how lynx behaves with invalid HTML" ), -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC PARSE_SET( "prettysrc", SET_ARG, &LYpsrc, "do syntax highlighting and hyperlink handling in source view" diff --git a/src/LYMainLoop.c b/src/LYMainLoop.c index 4af02a4c..d8996f8e 100644 --- a/src/LYMainLoop.c +++ b/src/LYMainLoop.c @@ -368,6 +368,32 @@ PUBLIC int LYGetNewline NOARGS return Newline; } +#ifdef SOURCE_CACHE +/* + * To reparse current html document under the different settings we call + * reparse_document() within mainloop refresh cycle, it relies upon 'curdoc'. + * + * From the other hand, regular requests for new document go to getfile() + * and rely upon 'newdoc'. + * + * To work around newdoc.line/curdoc.line/www_search_target/Newline message + * the following flag is introduced: + */ +PRIVATE BOOLEAN from_source_cache = FALSE; + +PRIVATE BOOLEAN reparse_document NOARGS +{ + BOOLEAN ok; + from_source_cache = TRUE; /* set for LYMainLoop_pageDisplay() */ + if ((ok = HTreparse_document()) != FALSE) { + from_source_cache = TRUE; /* set for mainloop refresh */ + return ok; + } + from_source_cache = FALSE; + return ok; +} +#endif /* SOURCE_CACHE */ + /* * This is for traversal call from within partial mode in LYUtils.c * and HTFormat.c It simply calls HText_pageDisplay() but utilizes @@ -378,6 +404,15 @@ PUBLIC void LYMainLoop_pageDisplay ARGS1( int, line_num) { #ifdef DISP_PARTIAL +#ifdef SOURCE_CACHE + /* + * reparse_document() acts on 'curdoc' which always on top of the + * history stack: no need to resolve #fragment position since + * we already know it (curdoc.line). + * So bypass here. Sorry for possible confusion... + */ + if (!from_source_cache) +#endif /* * Disable display_partial if requested URL has #fragment and we are not * popped from the history stack so can't calculate correct newline @@ -387,8 +422,8 @@ PUBLIC void LYMainLoop_pageDisplay ARGS1( * down to old behavior here ... until we rewrite HTFindPoundSelector() */ if (display_partial && newdoc.line == 1 && strchr(newdoc.address, '#')) { - display_partial = FALSE; /* restrict for this document */ - return; /* no repaint */ + display_partial = FALSE; /* restrict for this document */ + return; /* no repaint */ } /* @@ -1371,7 +1406,7 @@ gettext("Enctype multipart/form-data not yet supported! Cannot submit.")); } newdoc.link = 0; *force_load = TRUE; /* force MainLoop to reload */ -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC psrc_view = FALSE; /* we get here if link is not internal */ #endif @@ -3051,7 +3086,7 @@ PRIVATE void handle_LYK_HISTORICAL NOARGS HISTORICAL_ON_VALID_OFF : HISTORICAL_OFF_VALID_ON); } #ifdef SOURCE_CACHE - (void) HTreparse_document(); + (void) reparse_document(); #endif return; } @@ -3114,7 +3149,7 @@ PRIVATE BOOLEAN handle_LYK_IMAGE_TOGGLE ARGS1( CLICKABLE_IMAGES_ON : CLICKABLE_IMAGES_OFF); #ifdef SOURCE_CACHE if (HTcan_reparse_document()) { - HTreparse_document(); + reparse_document(); return FALSE; } #endif @@ -3279,7 +3314,7 @@ PRIVATE BOOLEAN handle_LYK_INLINE_TOGGLE ARGS1( PSEUDO_INLINE_ALTS_ON : PSEUDO_INLINE_ALTS_OFF); #ifdef SOURCE_CACHE if (HTcan_reparse_document()) { - HTreparse_document(); + reparse_document(); return FALSE; } #endif @@ -3576,7 +3611,7 @@ PRIVATE void handle_LYK_MINIMAL NOARGS HTAlert(minimal_comments ? MINIMAL_ON_IN_EFFECT : MINIMAL_OFF_VALID_ON); #ifdef SOURCE_CACHE - (void)HTreparse_document(); + (void)reparse_document(); #endif } else { HTAlert(minimal_comments ? @@ -3706,7 +3741,7 @@ PRIVATE BOOLEAN handle_LYK_OPTIONS ARGS2( #ifdef SOURCE_CACHE if (reloading == FALSE) { /* one more attempt to be smart enough: */ - if (HTreparse_document()) { + if (reparse_document()) { FREE(CurrentUserAgent); FREE(CurrentNegoLanguage); FREE(CurrentNegoCharset); @@ -4111,7 +4146,7 @@ PRIVATE BOOLEAN handle_LYK_RAW_TOGGLE ARGS1( HTMLSetCharacterHandling(current_char_set); #ifdef SOURCE_CACHE if (HTcan_reparse_document()) { - HTreparse_document(); + reparse_document(); return FALSE; } #endif @@ -4258,7 +4293,7 @@ PRIVATE void handle_LYK_SOFT_DQUOTES NOARGS HTUserMsg(soft_dquotes ? SOFT_DOUBLE_QUOTE_ON : SOFT_DOUBLE_QUOTE_OFF); #ifdef SOURCE_CACHE - (void)HTreparse_document(); + (void)reparse_document(); #endif return; } @@ -4295,14 +4330,14 @@ PRIVATE void handle_LYK_SOURCE ARGS1( } #ifdef SOURCE_CACHE - if (HTreparse_document()) { + if (reparse_document()) { /* * These normally get cleaned up after getfile() returns; * since we're not calling getfile(), we have to clean them * up ourselves. -dsb */ HTOutputFormat = WWW_PRESENT; -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC if (psrc_view) HTMark_asSource(); psrc_view = FALSE; @@ -4377,7 +4412,7 @@ PRIVATE void handle_LYK_SWITCH_DTD NOARGS if (HTisDocumentSource() && LYPreparsedSource) { srcmode_for_next_retrieval(1); } - if (!HTreparse_document()) { + if (!reparse_document()) { srcmode_for_next_retrieval(0); } } @@ -5310,7 +5345,7 @@ try_again: *prev_target = '\0'; /* Reset for new coming document */ Newline = newdoc.line; /* set for LYGetNewline() */ -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC psrc_first_tag = TRUE; #endif FREE(LYRequestReferer); @@ -5770,6 +5805,7 @@ try_again: */ #ifdef DISP_PARTIAL /* Newline = newdoc.line; */ + display_partial = FALSE; /* for sure, LYNXfoo:/ may be a problem */ #else /* Should not be needed either if we remove * "DISP_PARTIAL" from LYHistory.c, but lets leave it @@ -5820,7 +5856,7 @@ try_again: * the visited links list. - FM */ if (ownerS_address != NULL) { -#ifndef USE_PSRC +#ifndef USE_PRETTYSRC if (HTOutputFormat == WWW_SOURCE && !HText_getOwner()) #else if ( (LYpsrc ? psrc_view : HTOutputFormat == WWW_SOURCE) @@ -5846,7 +5882,7 @@ try_again: * the source, we get rendered HTML from now on. */ HTOutputFormat = WWW_PRESENT; -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC psrc_view = FALSE; #endif @@ -6044,8 +6080,8 @@ try_again: */ if (HTdocument_settings_changed()) { if (HTcan_reparse_document()) { - HTInfoMsg(gettext("Reparsing document under current settings...")); - HTreparse_document(); /* @@@ignores status */ + HTInfoMsg(gettext("Reparsing document under current settings...")); + reparse_document(); } else { /* * Urk. I have no idea how to recover from a failure here. @@ -6058,13 +6094,19 @@ try_again: */ } } -#endif + if (from_source_cache) { + from_source_cache = FALSE; /* reset */ + curdoc.line = -1 ; /* so curdoc.line != Newline, see below */ + } +#endif /* * If the curdoc.line is different than Newline then there must * have been a change since last update. Run HText_pageDisplay() * create a fresh screen of text out. + * + * If we got new HTMainText go this way. * All display_partial calls ends here for final redraw. */ if (curdoc.line != Newline) { diff --git a/src/LYOptions.c b/src/LYOptions.c index 9c10da46..7ee2397b 100644 --- a/src/LYOptions.c +++ b/src/LYOptions.c @@ -71,6 +71,37 @@ PUBLIC int SetupChosenShowColor NOARGS return LYChosenShowColor; } +PRIVATE void validate_x_display NOPARAMS +{ + char *cp; + if ((cp = LYgetXDisplay()) != NULL) { + StrAllocCopy(x_display, cp); + } else { + FREE(x_display); + } +} + +PRIVATE void summarize_x_display ARGS1( + char *, display_option) +{ + if ((x_display == NULL && *display_option == '\0') || + (x_display != NULL && !strcmp(x_display, display_option))) { + if (x_display == NULL && LYisConfiguredForX == TRUE) { + _statusline(VALUE_ACCEPTED_WARNING_X); + } else if (x_display != NULL && LYisConfiguredForX == FALSE) { + _statusline(VALUE_ACCEPTED_WARNING_NONX); + } else { + _statusline(VALUE_ACCEPTED); + } + } else { + if (*display_option) { + _statusline(FAILED_TO_SET_DISPLAY); + } else { + _statusline(FAILED_CLEAR_SET_DISPLAY); + } + } +} + #ifndef NO_OPTION_MENU PRIVATE int boolean_choice PARAMS(( @@ -594,33 +625,11 @@ draw_options: * Set the new DISPLAY variable. - FM */ LYsetXDisplay(display_option); - if ((cp = LYgetXDisplay()) != NULL) { - StrAllocCopy(x_display, cp); - } else { - FREE(x_display); - } + validate_x_display(); cp = NULL; addstr(x_display ? x_display : "NONE"); clrtoeol(); - if ((x_display == NULL && *display_option == '\0') || - (x_display != NULL && - !strcmp(x_display, display_option))) { - if (x_display == NULL && - LYisConfiguredForX == TRUE) { - _statusline(VALUE_ACCEPTED_WARNING_X); - } else if (x_display != NULL && - LYisConfiguredForX == FALSE) { - _statusline(VALUE_ACCEPTED_WARNING_NONX); - } else { - _statusline(VALUE_ACCEPTED); - } - } else { - if (*display_option) { - _statusline(FAILED_TO_SET_DISPLAY); - } else { - _statusline(FAILED_CLEAR_SET_DISPLAY); - } - } + summarize_x_display(display_option); response = ' '; break; @@ -3512,6 +3521,8 @@ PRIVATE PostPair * break_data ARGS1( if (p==NULL || p[0]=='\0') return NULL; + CTRACE((tfp, "break_data %s\n", data)); + q = calloc(sizeof(PostPair), 1); if (q==NULL) outofmem(__FILE__, "break_data(calloc)"); @@ -3558,6 +3569,7 @@ PRIVATE PostPair * break_data ARGS1( } } HTUnEscape(q[count].value); + CTRACE((tfp, "...item[%d] tag=%s, value=%s\n", count, q[count].tag, q[count].value)); count++; /* @@ -3733,6 +3745,8 @@ PUBLIC int postoptions ARGS1( /* X Display: INPUT */ if (!strcmp(data[i].tag, x_display_string)) { LYsetXDisplay(data[i].value); + validate_x_display(); + summarize_x_display(data[i].value); } /* Editor: INPUT */ diff --git a/src/LYPrettySrc.c b/src/LYPrettySrc.c index 3b279c8b..8c41c12d 100644 --- a/src/LYPrettySrc.c +++ b/src/LYPrettySrc.c @@ -10,7 +10,7 @@ #define NO_MEMORY_TRACKING #include <LYLeaks.h> -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC BOOL psrc_convert_string = FALSE; PUBLIC BOOL psrc_view = FALSE;/* this is read by SGML_put_character - TRUE when viewing pretty source */ @@ -328,11 +328,9 @@ PUBLIC void HTMLSRC_init_caches ARGS1( char buf[1000]; for (i = 0; i < HTL_num_lexemes; ++i) { - - strcpy(buf, HTL_tagspecs_defaults[i]); - p = HTL_tagspecs_defaults[i]; - HTL_tagspecs[i] = NULL; - StrAllocCopy(HTL_tagspecs[i],p); + /*we assume that HT_tagspecs was NULLs at when program started*/ + strcpy(buf, HTL_tagspecs[i] ? HTL_tagspecs[i] : HTL_tagspecs_defaults[i]); + StrAllocCopy(HTL_tagspecs[i],buf); if ((p = strchr(buf, ':')) != 0) *p = '\0'; @@ -347,4 +345,4 @@ PUBLIC void HTMLSRC_init_caches ARGS1( } } -#endif /* ifdef USE_PSRC */ +#endif /* ifdef USE_PRETTYSRC */ diff --git a/src/LYPrettySrc.h b/src/LYPrettySrc.h index 02a8f75f..6fdda50e 100644 --- a/src/LYPrettySrc.h +++ b/src/LYPrettySrc.h @@ -1,7 +1,7 @@ #ifndef LYPrettySrc_H #define LYPrettySrc_H -#ifdef USE_PSRC +#ifdef USE_PRETTYSRC #include <HTMLDTD.h> @@ -73,7 +73,7 @@ extern int attrname_transform; extern BOOL psrcview_no_anchor_numbering; -#endif /* ifdef USE_PSRC */ +#endif /* ifdef USE_PRETTYSRC */ #endif /* LYPrettySrc_H */ diff --git a/src/LYReadCFG.c b/src/LYReadCFG.c index a7ce3e82..48398fdd 100644 --- a/src/LYReadCFG.c +++ b/src/LYReadCFG.c @@ -360,8 +360,32 @@ PUBLIC int check_color ARGS2( { int i; - if (!strcasecomp(color, "default")) + CTRACE((tfp, "check_color(%s,%d)\n", color, the_default)); + if (!strcasecomp(color, "default")) { +#if HAVE_USE_DEFAULT_COLORS && USE_DEFAULT_COLORS +#if HAVE_ASSUME_DEFAULT_COLORS /* ncurses 5.1 */ + /* + * This may be invoked before ncurses is initialized, depending on + * whether color-style is used or not. + * + * If we have assume_default_colors(), we can leave the global fg/bg + * colors with the standard white/black until we find a color specified + * as "default". + */ + static int found = 0; + if (!found) + found = lynx_default_colors(); + if (found >= 0) + the_default = DEFAULT_COLOR; +#else + the_default = DEFAULT_COLOR; +#endif /* HAVE_ASSUME_DEFAULT_COLORS */ + default_fg = DEFAULT_COLOR; + default_bg = DEFAULT_COLOR; +#endif /* USE_DEFAULT_COLORS */ + CTRACE((tfp, "=> %d\n", the_default)); return the_default; + } if (!strcasecomp(color, "nocolor")) return NO_COLOR; @@ -1138,8 +1162,7 @@ PRIVATE int parse_assumed_doc_charset_choice ARGS1(char*,p) #endif /* EXP_CHARSET_CHOICE */ -#ifdef USE_PSRC - +#ifdef USE_PRETTYSRC static void html_src_bad_syntax ARGS2( char*, value, char*, option_name) @@ -1175,8 +1198,8 @@ static int parse_html_src_spec ARGS3( CTRACE((tfp,"ReadCFG - parsing tagspec '%s:%s' for option '%s'\n",value,ts2,option_name)); html_src_clean_item(lexeme_code); - if ( html_src_parse_tagspec(value, lexeme_code, FALSE, TRUE) - || html_src_parse_tagspec(ts2, lexeme_code, FALSE, FALSE) ) + if ( html_src_parse_tagspec(value, lexeme_code, TRUE, TRUE) + || html_src_parse_tagspec(ts2, lexeme_code, TRUE, TRUE) ) { *ts2 = ':'; BS(); @@ -1188,28 +1211,52 @@ static int parse_html_src_spec ARGS3( return 0; } -#if defined(__STDC__) || defined(_WIN_CC) -#define defHTSRC_parse_fun(x) static int html_src_set_##x ARGS1( char*,str) \ - { parse_html_src_spec(HTL_##x,str,#x); return 0; } -#else -#define defHTSRC_parse_fun(x) static int html_src_set_/**/x ARGS1( char*,str) \ - { parse_html_src_spec(HTL_/**/x,str,"x"); return 0; } -#endif +typedef struct string_int_pair_ +{ + char* str; + int val; +} string_int_pair; -defHTSRC_parse_fun(comm) -defHTSRC_parse_fun(tag) -defHTSRC_parse_fun(attrib) -defHTSRC_parse_fun(attrval) -defHTSRC_parse_fun(abracket) -defHTSRC_parse_fun(entity) -defHTSRC_parse_fun(href) -defHTSRC_parse_fun(entire) -defHTSRC_parse_fun(badseq) -defHTSRC_parse_fun(badtag) -defHTSRC_parse_fun(badattr) -defHTSRC_parse_fun(sgmlspecial) - -#undef defHTSRC_parse_fun +PRIVATE int psrcspec_fun ARGS1(char*,s) +{ + char* e; + static string_int_pair lexemnames[] = + { + { "comm", HTL_comm }, + { "tag", HTL_tag }, + { "attrib", HTL_attrib }, + { "attrval", HTL_attrval }, + { "abracket", HTL_abracket }, + { "entity", HTL_entity }, + { "href", HTL_href }, + { "entire", HTL_entire }, + { "badseq", HTL_badseq }, + { "badtag", HTL_badtag }, + { "badattr", HTL_badattr }, + { "sgmlspecial", HTL_sgmlspecial }, + { NULL, -1 } + }; + string_int_pair* cur = lexemnames; + BOOL found = FALSE; + + e = strchr(s,':'); + if (!e) { + CTRACE((tfp,"bad format of PRETTYSRC_SPEC setting value, ignored %s\n",s)); + return 0; + } + *e = '\0'; + while (cur->str) { + if ((found = !strcasecomp(s, cur->str)) != 0) + break; + ++cur; + } + if (!found) { + CTRACE((tfp,"bad format of PRETTYSRC_SPEC setting value, ignored %s:%s\n",s,e+1)); + return 0; + } + parse_html_src_spec(cur->val, e+1, s); + return 0; +} static int read_htmlsrc_attrname_xform ARGS1( char*,str) { @@ -1240,20 +1287,8 @@ static int read_htmlsrc_tagname_xform ARGS1( char*,str) } return 0; } - - -#ifdef __STDC__ -#define defHTSRC_option(x) \ - PARSE_FUN( "htmlsrc_" #x ,CONF_FUN, html_src_set_##x), -#else -#define defHTSRC_option(x) \ - PARSE_FUN( "htmlsrc_" #x ,CONF_FUN, html_src_set_/**/x), - /* ^^ (cannot adapt to K&R) */ #endif -#endif - - /* This table should be sorted alphabetically */ static Config_Type Config_Table [] = { @@ -1335,31 +1370,10 @@ static Config_Type Config_Table [] = PARSE_SET("gotobuffer", CONF_BOOL, &goto_buffer), PARSE_STR("helpfile", CONF_STR, &helpfile), PARSE_SET("historical_comments", CONF_BOOL, &historical_comments), - -#if defined(USE_PSRC) && defined(__STDC__) - - defHTSRC_option(abracket) - defHTSRC_option(attrib) - +#ifdef USE_PRETTYSRC PARSE_FUN("htmlsrc_attrname_xform", CONF_FUN, read_htmlsrc_attrname_xform), - - defHTSRC_option(attrval) - defHTSRC_option(badattr) - defHTSRC_option(badseq) - defHTSRC_option(badtag) - defHTSRC_option(comm) - defHTSRC_option(entire) - defHTSRC_option(entity) - defHTSRC_option(href) - defHTSRC_option(sgmlspecial) - defHTSRC_option(tag) - PARSE_FUN("htmlsrc_tagname_xform", CONF_FUN, read_htmlsrc_tagname_xform), - - -# undef defHTSRC_option #endif - PARSE_ENV("http_proxy", CONF_ENV, 0 ), PARSE_ENV("https_proxy", CONF_ENV, 0 ), PARSE_FUN("include", CONF_INCLUDE, 0), @@ -1369,6 +1383,7 @@ static Config_Type Config_Table [] = PARSE_FUN("jumpfile", CONF_FUN, jumpfile_fun), #ifdef EXP_JUSTIFY_ELTS PARSE_SET("justify", CONF_BOOL, &ok_justify), + PARSE_SET("justify_max_void_percent", CONF_INT, &justify_max_void_percent), #endif #ifdef EXP_KEYBOARD_LAYOUT PARSE_FUN("keyboard_layout", CONF_FUN, keyboard_layout_fun), @@ -1443,10 +1458,11 @@ static Config_Type Config_Table [] = PARSE_STR("preferred_language", CONF_STR, &language), PARSE_SET("prepend_base_to_source", CONF_BOOL, &LYPrependBaseToSource), PARSE_SET("prepend_charset_to_source", CONF_BOOL, &LYPrependCharsetToSource), - PARSE_FUN("printer", CONF_FUN, printer_fun), -#ifdef USE_PSRC - PARSE_SET("psrcview_no_anchor_numbering", CONF_BOOL, &psrcview_no_anchor_numbering), +#ifdef USE_PRETTYSRC + PARSE_FUN("prettysrc_spec" ,CONF_FUN, psrcspec_fun), + PARSE_SET("prettysrc_view_no_anchor_numbering", CONF_BOOL, &psrcview_no_anchor_numbering), #endif + PARSE_FUN("printer", CONF_FUN, printer_fun), PARSE_SET("quit_default_yes", CONF_BOOL, &LYQuitDefaultYes), PARSE_SET("referer_with_query", CONF_FUN, referer_with_query_fun), PARSE_SET("reuse_tempfiles", CONF_BOOL, &LYReuseTempfiles), diff --git a/src/LYReadCFG.h b/src/LYReadCFG.h index 5e222910..328712f6 100644 --- a/src/LYReadCFG.h +++ b/src/LYReadCFG.h @@ -40,6 +40,10 @@ extern int default_fg; extern int default_bg; +#if HAVE_USE_DEFAULT_COLORS && USE_DEFAULT_COLORS +extern int lynx_default_colors NOPARAMS; +#endif + extern int check_color PARAMS((char * color, int the_default)); #endif diff --git a/src/LYUtils.c b/src/LYUtils.c index d31f059f..77ad6f49 100644 --- a/src/LYUtils.c +++ b/src/LYUtils.c @@ -108,6 +108,11 @@ extern int BSDselect PARAMS((int nfds, fd_set * readfds, fd_set * writefds, #endif /* __FreeBSD__ || __bsdi__ */ #endif /* !UTMP_FILE */ +#if defined(HAVE_RAND) && defined(HAVE_SRAND) && defined(RAND_MAX) +#define USE_RAND_TEMPNAME 1 +#define MAX_TEMPNAME 10000 +#endif + #define COPY_COMMAND "%s %s %s" extern BOOLEAN LYHaveCJKCharacterSet; @@ -118,6 +123,42 @@ PRIVATE char *HomeDir = NULL; /* HOME directory */ PUBLIC HTList * sug_filenames = NULL; /* Suggested filenames */ /* + * 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; + +PRIVATE LY_TEMP *ly_temp; + +PRIVATE LY_TEMP *FindTempfileByName ARGS1(CONST char *, name) +{ + LY_TEMP *p; + + for (p = ly_temp; p != 0; p = p->next) { + if (!strcmp(p->name, name)) { + break; + } + } + return p; +} + +PRIVATE LY_TEMP *FindTempfileByFP ARGS1(FILE *, fp) +{ + LY_TEMP *p; + + for (p = ly_temp; p != 0; p = p->next) { + if (p->file == fp) { + break; + } + } + return p; +} + +/* * Highlight (or unhighlight) a given link. */ PUBLIC void highlight ARGS3( @@ -3732,26 +3773,21 @@ PRIVATE int fmt_tempname ARGS3( /* * Prefer a random value rather than a counter. */ -#if defined(HAVE_RAND) && defined(HAVE_SRAND) && defined(RAND_MAX) +#ifdef USE_RAND_TEMPNAME + do { + int uninit; /* ( intentionally uninitialized ;-) */ if (counter == 0) - srand(time((time_t *)0)); - counter = ( 10000.0 * rand() ) / RAND_MAX; + srand(time((time_t *)0) + uninit); + /* We don't really need all of the bits from rand(). The high-order bits + * are the more-random portion in any case, but limiting the width of the + * generated name is done partly to avoid problems on systems that may not + * support long filenames. + */ + counter = ( (float)MAX_TEMPNAME * rand() ) / RAND_MAX + 1; #else counter++; #endif -#if 0 && defined(_WINDOWS) /* 1998/05/25 (Mon) 20:51:22 */ - /* This is nonsense - result hasn't been filled yet and will - * be overwritten below. If you mean 'prefix' then say so. - kw - */ - { - char *p = result; - while (*p++) { - if (*p == '/') - *p = '\\'; - } - } -#endif #ifdef FNAMES_8_3 /* * The 'lynx_temp_space' string ends with a '/' or '\\', so we only have to @@ -3787,6 +3823,10 @@ PRIVATE int fmt_tempname ARGS3( sprintf(result, "%.*s", LY_MAXPATH-1, leaf); code = FALSE; } +#ifdef USE_RAND_TEMPNAME + /* If we really have 10000 files open, there's no point in returning... */ + } while (FindTempfileByName(result) != 0); +#endif CTRACE((tfp, "-> '%s'\n", result)); return (code); } @@ -6362,18 +6402,6 @@ PUBLIC BOOLEAN LYCachedTemp ARGS2( } /* - * 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. * @@ -6456,11 +6484,8 @@ PUBLIC FILE *LYReopenTemp ARGS1( FILE *fp = 0; LYCloseTemp(name); - for (p = ly_temp; p != 0; p = p->next) { - if (!strcmp(p->name, name)) { - fp = p->file = LYAppendToTxtFile (name); - break; - } + if ((p = FindTempfileByName(name)) != 0) { + fp = p->file = LYAppendToTxtFile (name); } return fp; } @@ -6499,15 +6524,11 @@ PUBLIC FILE *LYOpenTempRewrite ARGS3( if (*fname == '\0') /* first time, no filename yet */ return (LYOpenTemp(fname, suffix, mode)); - for (p = ly_temp; p != 0; p = p->next) { - if (!strcmp(fname, p->name)) { - registered = YES; - if (p->file != 0) - still_open = YES; - CTRACE((tfp, "...used before%s\n", - still_open ? ", still open!" : ".")); - break; - } + if ((p = FindTempfileByName(fname)) != 0) { + registered = YES; + if (p->file != 0) + still_open = YES; + CTRACE((tfp, "...used before%s\n", still_open ? ", still open!" : ".")); } if (registered) { @@ -6669,15 +6690,12 @@ PUBLIC void LYCloseTemp ARGS1( 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; + if ((p = FindTempfileByName(name)) != 0) { + CTRACE((tfp, "...LYCloseTemp(%s)%s\n", name, + (p->file != 0) ? ", closed" : "")); + if (p->file != 0) { + fclose(p->file); + p->file = 0; } } } @@ -6691,13 +6709,10 @@ PUBLIC void LYCloseTempFP ARGS1( 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; - CTRACE((tfp, "...LYCloseTempFP(%s)\n", p->name)); - break; - } + if ((p = FindTempfileByFP(fp)) != 0) { + fclose(p->file); + p->file = 0; + CTRACE((tfp, "...LYCloseTempFP(%s)\n", p->name)); } } @@ -6754,11 +6769,8 @@ PUBLIC void LYRenamedTemp ARGS2( LY_TEMP *p; CTRACE((tfp, "LYRenamedTemp(old=%s, new=%s)\n", oldname, newname)); - for (p = ly_temp; p != 0; p = p->next) { - if (!strcmp(oldname, p->name)) { - StrAllocCopy((p->name), newname); - break; - } + if ((p = FindTempfileByName(oldname)) != 0) { + StrAllocCopy((p->name), newname); } } @@ -7566,7 +7578,7 @@ PUBLIC char *LYgetXDisplay NOARGS PUBLIC void LYsetXDisplay ARGS1( char *, new_display) { - if (new_display != 0 && *new_display != '\0') { + if (new_display != 0) { #ifdef VMS LYUpperCase(new_display); Define_VMSLogical(DISPLAY, new_display); |