*** ./src/GridText.c.orig Tue Mar 30 12:10:37 1999 --- ./src/GridText.c Sat Apr 10 22:04:00 1999 *************** *** 46,51 **** --- 46,55 ---- #undef DEBUG_APPCH + #ifdef SOURCE_CACHE + #include + #endif + #ifdef USE_COLOR_STYLE #include #include *************** *** 114,119 **** --- 118,128 ---- PUBLIC BOOLEAN underline_on = OFF; PUBLIC BOOLEAN bold_on = OFF; + #ifdef SOURCE_CACHE + PUBLIC char * source_cache_filename = NULL; + PUBLIC BOOLEAN LYCacheSource = TRUE; + #endif + #if defined(USE_COLOR_STYLE) #define MAX_STYLES_ON_LINE 64 *************** *** 173,178 **** --- 182,202 ---- */ struct _HText { HTParentAnchor * node_anchor; + #ifdef SOURCE_CACHE + char * source_cache; + /* + * Parse settings when this HText was generated. + */ + BOOLEAN clickable_images; + BOOLEAN pseudo_inline_alts; + BOOLEAN raw_mode; + BOOLEAN historical_comments; + BOOLEAN minimal_comments; + BOOLEAN soft_dquotes; + BOOLEAN old_dtd; + int lines; /* Screen size */ + int cols; + #endif HTLine * last_line; int Lines; /* Number of them */ int chars; /* Number of them */ *************** *** 483,488 **** --- 507,535 ---- self->stale = YES; self->toolbar = NO; self->tabs = NULL; + #ifdef SOURCE_CACHE + /* + * Yes, this is a Gross And Disgusting Hack(TM), I know... + */ + self->source_cache = NULL; + if (LYCacheSource && source_cache_filename) { + StrAllocCopy(self->source_cache, source_cache_filename); + FREE(source_cache_filename); + } + + /* + * Remember the parse settings. + */ + self->clickable_images = clickable_images; + self->pseudo_inline_alts = pseudo_inline_alts; + self->raw_mode = LYRawMode; + self->historical_comments = historical_comments; + self->minimal_comments = minimal_comments; + self->soft_dquotes = soft_dquotes; + self->old_dtd = Old_DTD; + self->lines = LYlines; + self->cols = LYcols; + #endif /* * If we are going to render the List Page, always merge in hidden * links to get the numbering consistent if form fields are numbered *************** *** 729,734 **** --- 776,792 ---- HTMainAnchor = NULL; } + #ifdef SOURCE_CACHE + /* + * Clean up the source cache file, if any. + */ + if (self->source_cache) { + CTRACE(tfp, "Removing source cache file %s\n", self->source_cache); + unlink(self->source_cache); + FREE(self->source_cache); + } + #endif + FREE(self); } *************** *** 6189,6194 **** --- 6247,6353 ---- CTRACE(tfp, "HTuncache.. HTMainText already is NULL!\n"); } } + + #ifdef SOURCE_CACHE + PUBLIC BOOLEAN HTreparse_document NOARGS + { + FILE * fp; + HTFormat format; + int ret; + + if (!HTMainText || !HTMainText->source_cache) + return FALSE; + CTRACE(tfp, "Reparsing source cache file %s\n", HTMainText->source_cache); + + /* + * This is more or less copied out of HTLoadFile(), except we don't get + * a content encoding. This may be overkill... + */ + if (HTMainText->node_anchor->content_type) { + format = HTAtom_for(HTMainText->node_anchor->content_type); + } else { + format = HTFileFormat(HTMainText->source_cache, NULL, NULL); + format = HTCharsetFormat(format, HTMainText->node_anchor, + UCLYhndl_HTFile_for_unspec); + } + CTRACE(tfp, " Content type is \"%s\"\n", format->name); + + /* + * Pass the source cache filename on to the next HText. Mark it NULL + * here so that it won't get deleted by HText_free(). + */ + source_cache_filename = HTMainText->source_cache; + HTMainText->source_cache = NULL; + + fp = fopen(source_cache_filename, "r"); + if (!fp) { + CTRACE(tfp, " Cannot read file %s\n", source_cache_filename); + FREE(source_cache_filename); + return FALSE; + } + ret = HTParseFile(format, HTOutputFormat, HTMainText->node_anchor, fp, + NULL); + fclose(fp); + CTRACE(tfp, "Reparse %s\n", (ret == HT_LOADED ? "succeeded" : "failed")); + if (ret != HT_LOADED) + FREE(source_cache_filename); + return (ret == HT_LOADED); + } + + PRIVATE void trace_setting_change ARGS3( + CONST char *, name, + BOOLEAN, prev_setting, + BOOLEAN, new_setting) + { + if (prev_setting != new_setting) + CTRACE(tfp, "HTdocument_settings_changed: %s setting has changed (was %s, now %s)\n", + name, prev_setting ? "ON" : "OFF", new_setting ? "ON" : "OFF"); + } + + PUBLIC BOOLEAN HTdocument_settings_changed NOARGS + { + /* + * Annoying Hack(TM): If we don't have a source cache filename, we can't + * reparse anyway, so pretend the state hasn't changed. + */ + if (!HTMainText || !HTMainText->source_cache) + return FALSE; + + if (TRACE) { + /* + * If we're tracing, note everying that has changed. + */ + trace_setting_change("CLICKABLE_IMAGES", + HTMainText->clickable_images, clickable_images); + trace_setting_change("PSEUDO_INLINE_ALTS", + HTMainText->pseudo_inline_alts, + pseudo_inline_alts); + trace_setting_change("RAW_MODE", HTMainText->raw_mode, LYRawMode); + trace_setting_change("HISTORICAL_COMMENTS", + HTMainText->historical_comments, + historical_comments); + trace_setting_change("MINIMAL_COMMENTS", + HTMainText->minimal_comments, minimal_comments); + trace_setting_change("SOFT_DQUOTES", + HTMainText->soft_dquotes, soft_dquotes); + trace_setting_change("OLD_DTD", HTMainText->old_dtd, Old_DTD); + if (HTMainText->lines != LYlines || HTMainText->cols != LYcols) + CTRACE(tfp, + "HTdocument_settings_changed: Screen size has changed (was %dx%d, now %dx%d)\n", + HTMainText->cols, HTMainText->lines, LYcols, LYlines); + } + + return (HTMainText->clickable_images != clickable_images || + HTMainText->pseudo_inline_alts != pseudo_inline_alts || + HTMainText->raw_mode != LYRawMode || + HTMainText->historical_comments != historical_comments || + HTMainText->minimal_comments != minimal_comments || + HTMainText->soft_dquotes != soft_dquotes || + HTMainText->old_dtd != Old_DTD || + HTMainText->lines != LYlines || + HTMainText->cols != LYcols); + } + #endif PUBLIC int HTisDocumentSource NOARGS { *** ./src/HTML.c.orig Wed Mar 17 22:17:11 1999 --- ./src/HTML.c Sat Apr 10 22:06:41 1999 *************** *** 58,63 **** --- 58,67 ---- #define pHText_changeStyle(X,Y,Z) {} #endif + #ifdef SOURCE_CACHE + #include + #endif + #include #include *************** *** 73,79 **** --- 77,89 ---- struct _HTStream { CONST HTStreamClass * isa; + #ifdef SOURCE_CACHE + FILE * fp; + CONST HTStreamClass * actions; + HTStream * target; + #else /* .... */ + #endif }; PRIVATE HTStyleSheet * styleSheet = NULL; /* Application-wide */ *************** *** 7300,7305 **** --- 7310,7428 ---- return (HTStructured*) me; } + #ifdef SOURCE_CACHE + /* + * Pass-thru cache HTStream + */ + + PRIVATE void CacheThru_free ARGS1( + HTStream *, me) + { + fclose(me->fp); + (*me->actions->_free)(me->target); + FREE(me); + } + + PRIVATE void CacheThru_abort ARGS2( + HTStream *, me, + HTError, e) + { + fclose(me->fp); + (*me->actions->_abort)(me->target, e); + FREE(me); + } + + PRIVATE void CacheThru_put_character ARGS2( + HTStream *, me, + char, c_in) + { + fputc(c_in, me->fp); + (*me->actions->put_character)(me->target, c_in); + } + + PRIVATE void CacheThru_put_string ARGS2( + HTStream *, me, + CONST char *, str) + { + fputs(str, me->fp); + (*me->actions->put_string)(me->target, str); + } + + PRIVATE void CacheThru_write ARGS3( + HTStream *, me, + CONST char *, str, + int, l) + { + fwrite(str, 1, l, me->fp); + (*me->actions->put_block)(me->target, str, l); + } + + PRIVATE CONST HTStreamClass PassThruCache = + { + "PassThruCache", + CacheThru_free, + CacheThru_abort, + CacheThru_put_character, + CacheThru_put_string, + CacheThru_write + }; + + PRIVATE HTStream* CacheThru_new ARGS2( + HTParentAnchor *, anchor, + HTStream *, target) + { + char filename[LY_MAXPATH]; + FILE *fp = NULL; + HTStream *stream = NULL; + HTProtocol *p = (HTProtocol *)anchor->protocol; + + /* + * Neatly and transparently vanish if source caching is disabled. + */ + if (!LYCacheSource) + return target; + + if (strcmp(p->name, "http") != 0) { + CTRACE(tfp, "Protocol is \"%s\"; not caching\n", p->name); + return target; + } + + if (source_cache_filename) { + CTRACE(tfp, "Reusing source cache file %s\n", + source_cache_filename); + return target; + } + + if (!fmt_tempname(filename, lynx_temp_space, HTML_SUFFIX)) { + CTRACE(tfp, "Cannot get source cache filename for URL %s\n", + HTAnchor_address((HTAnchor *)anchor)); + return target; + } + if (!(fp = fopen(filename, "w"))) { + CTRACE(tfp, "Cannot open source cache file %s for URL %s\n", + filename, HTAnchor_address((HTAnchor *)anchor)); + return target; + } + + stream = (HTStream *) malloc(sizeof(*stream)); + if (!stream) + outofmem(__FILE__, "CacheThru_new"); + + stream->isa = &PassThruCache; + stream->fp = fp; + stream->target = target; + stream->actions = target->isa; + /* + * Yes, this is a Gross And Disgusting Hack(TM), I know... + */ + StrAllocCopy(source_cache_filename, filename); + + CTRACE(tfp, "Caching source for URL %s in file %s\n", + HTAnchor_address((HTAnchor *)anchor), filename); + return stream; + } + #endif + /* HTConverter for HTML to plain text ** ---------------------------------- ** *************** *** 7313,7319 **** --- 7436,7448 ---- HTParentAnchor *, anchor, HTStream *, sink) { + #ifdef SOURCE_CACHE + return CacheThru_new(anchor, + SGML_new(&HTML_dtd, anchor, + HTML_new(anchor, pres->rep_out, sink))); + #else return SGML_new(&HTML_dtd, anchor, HTML_new(anchor, pres->rep_out, sink)); + #endif } /* HTConverter for HTML source to plain text *************** *** 7372,7378 **** --- 7501,7513 ---- } if (!intermediate) return NULL; + #ifdef SOURCE_CACHE + return CacheThru_new(anchor, + SGML_new(&HTML_dtd, anchor, + HTMLGenerator(intermediate))); + #else return SGML_new(&HTML_dtd, anchor, HTMLGenerator(intermediate)); + #endif } /* HTConverter for HTML to C code *************** *** 7397,7403 **** --- 7532,7543 ---- html->comment_start = "/* "; html->comment_end = " */\n"; /* Must start in col 1 for cpp */ /* HTML_put_string(html,html->comment_start); */ + #ifdef SOURCE_CACHE + return CacheThru_new(anchor, + SGML_new(&HTML_dtd, anchor, html)); + #else return SGML_new(&HTML_dtd, anchor, html); + #endif } /* Presenter for HTML *************** *** 7414,7420 **** --- 7554,7566 ---- HTParentAnchor *, anchor, HTStream *, sink GCC_UNUSED) { + #ifdef SOURCE_CACHE + return CacheThru_new(anchor, + SGML_new(&HTML_dtd, anchor, + HTML_new(anchor, WWW_PRESENT, NULL))); + #else return SGML_new(&HTML_dtd, anchor, HTML_new(anchor, WWW_PRESENT, NULL)); + #endif } #endif /* !GUI */ *** ./src/LYUtils.c.orig Tue Mar 30 12:10:37 1999 --- ./src/LYUtils.c Sat Apr 10 00:05:19 1999 *************** *** 3369,3375 **** /* * Construct a temporary-filename. Assumes result is LY_MAXPATH chars long. */ ! PRIVATE int fmt_tempname ARGS3( char *, result, CONST char *, prefix, CONST char *, suffix) --- 3369,3381 ---- /* * Construct a temporary-filename. Assumes result is LY_MAXPATH chars long. */ ! #ifdef SOURCE_CACHE ! /* We use this elsewhere... */ ! PUBLIC ! #else ! PRIVATE ! #endif ! int fmt_tempname ARGS3( char *, result, CONST char *, prefix, CONST char *, suffix) *** ./src/LYUtils.h.orig Tue Mar 30 12:10:37 1999 --- ./src/LYUtils.h Sat Apr 10 00:06:52 1999 *************** *** 63,68 **** --- 63,71 ---- extern BOOLEAN LYisLocalHost PARAMS((char *filename)); extern BOOLEAN inlocaldomain NOPARAMS; extern CONST char *Home_Dir NOPARAMS; + #ifdef SOURCE_CACHE + extern int fmt_tempname PARAMS((char * result, CONST char * prefix, CONST char * suffix)); + #endif extern FILE *LYAppendToTxtFile PARAMS((char * name)); extern FILE *LYNewBinFile PARAMS((char * name)); extern FILE *LYNewTxtFile PARAMS((char * name)); *** ./src/GridText.h.orig Tue Mar 30 12:10:37 1999 --- ./src/GridText.h Sat Apr 10 19:24:50 1999 *************** *** 166,171 **** --- 166,175 ---- char * target)); extern int HTisDocumentSource NOPARAMS; extern void HTuncache_current_document NOPARAMS; + #ifdef SOURCE_CACHE + extern BOOLEAN HTreparse_document NOPARAMS; + extern BOOLEAN HTdocument_settings_changed NOPARAMS; + #endif extern int HText_getTopOfScreen NOPARAMS; extern int HText_getLines PARAMS((HText * text)); extern int HText_getNumOfLines NOPARAMS; *** ./src/LYMainLoop.c.orig Tue Mar 30 12:10:37 1999 --- ./src/LYMainLoop.c Sat Apr 10 19:51:52 1999 *************** *** 1237,1242 **** --- 1237,1262 ---- } } + #ifdef SOURCE_CACHE + /* + * If the parse settings have changed since this HText was + * generated, we need to reparse and redraw it. + */ + if (LYCacheSource && HTdocument_settings_changed()) { + HTUserMsg(gettext("Reparsing document under current settings...")); + if (HTreparse_document()) + refresh_screen = TRUE; + else { + /* + * Urk. I have no idea how to recover from a failure here. + * At a guess, I'll try reloading. + */ + cmd = LYK_RELOAD; + goto new_cmd; + } + } + #endif + /* * If the curdoc.line is different than Newline then there must * have been a change since last update. Run HText_pageDisplay() *************** *** 2049,2054 **** --- 2069,2080 ---- LYUCPushAssumed(HTMainAnchor); HTOutputFormat = WWW_SOURCE; } + #ifdef SOURCE_CACHE + if (LYCacheSource && HTreparse_document()) { + refresh_screen = TRUE; + break; + } + #endif LYforce_no_cache = TRUE; FREE(curdoc.address); /* so it doesn't get pushed */ break; *************** *** 2125,2135 **** --- 2151,2163 ---- 0, 0) == FALSE) { HTInfoMsg(WILL_NOT_RELOAD_DOC); } else { + #ifndef SOURCE_CACHE HTuncache_current_document(); StrAllocCopy(newdoc.address, curdoc.address); FREE(curdoc.address); newdoc.line = curdoc.line; newdoc.link = curdoc.link; + #endif } if (historical_comments) historical_comments = FALSE; *************** *** 2142,2147 **** --- 2170,2186 ---- HTAlert(historical_comments ? HISTORICAL_ON_VALID_OFF : HISTORICAL_OFF_VALID_ON); } + #ifdef SOURCE_CACHE + if (LYCacheSource && HTreparse_document()) { + refresh_screen = TRUE; + break; + } + HTuncache_current_document(); + StrAllocCopy(newdoc.address, curdoc.address); + FREE(curdoc.address); + newdoc.line = curdoc.line; + newdoc.link = curdoc.link; + #endif break; case LYK_MINIMAL: /* toggle 'minimal' comments parsing */ *************** *** 2157,2167 **** --- 2196,2208 ---- 0, 0) == FALSE) { HTInfoMsg(WILL_NOT_RELOAD_DOC); } else { + #ifndef SOURCE_CACHE HTuncache_current_document(); StrAllocCopy(newdoc.address, curdoc.address); FREE(curdoc.address); newdoc.line = curdoc.line; newdoc.link = curdoc.link; + #endif } } if (minimal_comments) *************** *** 2175,2180 **** --- 2216,2232 ---- HTAlert(minimal_comments ? MINIMAL_ON_BUT_HISTORICAL : MINIMAL_OFF_HISTORICAL_ON); } + #ifdef SOURCE_CACHE + if (LYCacheSource && HTreparse_document()) { + refresh_screen = TRUE; + break; + } + HTuncache_current_document(); + StrAllocCopy(newdoc.address, curdoc.address); + FREE(curdoc.address); + newdoc.line = curdoc.line; + newdoc.link = curdoc.link; + #endif break; case LYK_SOFT_DQUOTES: *************** *** 2189,2199 **** --- 2241,2253 ---- 1, 1) == FALSE) { HTInfoMsg(WILL_NOT_RELOAD_DOC); } else { + #ifndef SOURCE_CACHE HTuncache_current_document(); StrAllocCopy(newdoc.address, curdoc.address); FREE(curdoc.address); newdoc.line = curdoc.line; newdoc.link = curdoc.link; + #endif } if (soft_dquotes) soft_dquotes = FALSE; *************** *** 2201,2206 **** --- 2255,2271 ---- soft_dquotes = TRUE; HTUserMsg(soft_dquotes ? SOFT_DOUBLE_QUOTE_ON : SOFT_DOUBLE_QUOTE_OFF); + #ifdef SOURCE_CACHE + if (LYCacheSource && HTreparse_document()) { + refresh_screen = TRUE; + break; + } + HTuncache_current_document(); + StrAllocCopy(newdoc.address, curdoc.address); + FREE(curdoc.address); + newdoc.line = curdoc.line; + newdoc.link = curdoc.link; + #endif break; case LYK_SWITCH_DTD: *************** *** 2223,2231 **** --- 2288,2298 ---- if (HTisDocumentSource() && LYPreparsedSource) { HTOutputFormat = WWW_SOURCE; } + #ifndef SOURCE_CACHE HTuncache_current_document(); StrAllocCopy(newdoc.address, curdoc.address); FREE(curdoc.address); + #endif } #ifdef NO_ASSUME_SAME_DOC newdoc.line = 1; *************** *** 2237,2242 **** --- 2304,2318 ---- Old_DTD = !Old_DTD; HTSwitchDTD(!Old_DTD); HTUserMsg(Old_DTD ? USING_DTD_0 : USING_DTD_1); + #ifdef SOURCE_CACHE + if (LYCacheSource && HTreparse_document()) { + refresh_screen = TRUE; + break; + } + HTuncache_current_document(); + StrAllocCopy(newdoc.address, curdoc.address); + FREE(curdoc.address); + #endif break; #ifdef NOT_DONE_YET *************** *** 5447,5452 **** --- 5523,5534 ---- HTUserMsg(clickable_images ? CLICKABLE_IMAGES_ON : CLICKABLE_IMAGES_OFF); + #ifdef SOURCE_CACHE + if (LYCacheSource && HTreparse_document()) { + refresh_screen = TRUE; + break; + } + #endif cmd = LYK_RELOAD; goto new_cmd; *************** *** 5458,5463 **** --- 5540,5551 ---- HTUserMsg(pseudo_inline_alts ? PSEUDO_INLINE_ALTS_ON : PSEUDO_INLINE_ALTS_OFF); + #ifdef SOURCE_CACHE + if (LYCacheSource && HTreparse_document()) { + refresh_screen = TRUE; + break; + } + #endif cmd = LYK_RELOAD; goto new_cmd; *************** *** 5470,5475 **** --- 5558,5569 ---- HTUserMsg(LYRawMode ? RAWMODE_OFF : RAWMODE_ON); HTMLSetCharacterHandling(current_char_set); LYRawMode_flag = LYRawMode; + #ifdef SOURCE_CACHE + if (LYCacheSource && HTreparse_document()) { + refresh_screen = TRUE; + break; + } + #endif cmd = LYK_RELOAD; goto new_cmd; } *** ./src/LYReadCFG.c.orig Tue Mar 30 12:10:37 1999 --- ./src/LYReadCFG.c Sat Apr 10 19:21:45 1999 *************** *** 999,1004 **** --- 999,1007 ---- PARSE_ENV("snewspost_proxy", CONF_ENV, 0 ), PARSE_ENV("snewsreply_proxy", CONF_ENV, 0 ), PARSE_SET("soft_dquotes", CONF_BOOL, soft_dquotes), + #ifdef SOURCE_CACHE + PARSE_SET("source_cache", CONF_BOOL, LYCacheSource), + #endif PARSE_STR("startfile", CONF_STR, startfile), PARSE_SET("strip_dotdot_urls", CONF_BOOL, LYStripDotDotURLs), PARSE_SET("substitute_underscores", CONF_BOOL, use_underscore), *** ./src/LYGlobalDefs.h.orig Thu Mar 4 05:39:45 1999 --- ./src/LYGlobalDefs.h Sat Apr 10 19:26:34 1999 *************** *** 245,250 **** --- 245,254 ---- extern BOOLEAN historical_comments; extern BOOLEAN minimal_comments; extern BOOLEAN soft_dquotes; + #ifdef SOURCE_CACHE + extern char * source_cache_filename; + extern BOOLEAN LYCacheSource; + #endif extern BOOLEAN LYCancelDownload; extern BOOLEAN LYRestricted; extern BOOLEAN LYValidate; *** ./configure.in.orig Tue Mar 30 12:10:37 1999 --- ./configure.in Sat Apr 10 00:27:33 1999 *************** *** 567,572 **** --- 567,579 ---- AC_MSG_RESULT($use_alt_bindings) test $use_alt_bindings != no && AC_DEFINE(EXP_ALT_BINDINGS) + AC_MSG_CHECKING(if source caching should be used) + CF_ARG_ENABLE(source-cache, + [ --enable-source-cache cache HTML source for parse mode changes], + [use_source_cache=$enableval], + [use_source_cache=no] + test $use_source_cache != no && AC_DEFINE(SOURCE_CACHE) + AC_MSG_CHECKING(if color-style code should be used) CF_ARG_ENABLE(color-style, [ --enable-color-style use optional/experimental color style], *** ./config.hin.orig Tue Mar 30 12:10:37 1999 --- ./config.hin Sat Apr 10 00:27:33 1999 *************** *** 28,33 **** --- 28,34 ---- #undef EXEC_SCRIPTS /* CF_ARG_ENABLE(exec-scripts) */ #undef EXP_ADDRLIST_PAGE /* CF_ARG_ENABLE(addrlist-page) */ #undef EXP_ALT_BINDINGS /* CF_ARG_ENABLE(alt-bindings) */ + #undef SOURCE_CACHE /* CF_ARG_ENABLE(source-cache) */ #undef EXP_CHARTRANS_AUTOSWITCH /* CF_ARG_ENABLE(font-switch) */ #undef EXP_KEYBOARD_LAYOUT /* CF_ARG_ENABLE(kbd-layout) */ #undef EXP_LIBJS /* CF_ARG_ENABLE(libjs) */ *** ./lynx.cfg.orig Wed Mar 17 22:17:11 1999 --- ./lynx.cfg Sat Apr 10 18:45:09 1999 *************** *** 513,518 **** --- 513,526 ---- #DEFAULT_CACHE_SIZE:10 #DEFAULT_VIRTUAL_MEMORY_SIZE:512000 + # if SOURCE_CACHE is set TRUE, Lynx will keep a temporary file for each + # cached document containing the HTML source of the document, which will be + # used to reparse the document when certain settings are changed (for + # instance, historical vs. minimal vs. valid comment parsing) instead of + # reloading the document from the network. + # + #SOURCE_CACHE:TRUE + # If ALWAYS_RESUBMIT_POSTS is set TRUE, Lynx always will resubmit forms # with method POST, dumping any cache from a previous submission of the # form, including when the document returned by that form is sought with