diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/GridText.c | 19 | ||||
-rw-r--r-- | src/HTML.c | 8 | ||||
-rw-r--r-- | src/LYCharUtils.c | 11 | ||||
-rw-r--r-- | src/LYCurses.c | 13 | ||||
-rw-r--r-- | src/LYExtern.c | 4 | ||||
-rw-r--r-- | src/LYHash.h | 7 | ||||
-rw-r--r-- | src/LYLeaks.c | 474 | ||||
-rw-r--r-- | src/LYMain.c | 4 | ||||
-rw-r--r-- | src/LYStyle.c | 82 | ||||
-rw-r--r-- | src/LYStyle.h | 10 | ||||
-rw-r--r-- | src/LYUtils.c | 45 | ||||
-rw-r--r-- | src/LYUtils.h | 3 |
12 files changed, 373 insertions, 307 deletions
diff --git a/src/GridText.c b/src/GridText.c index 489c5ce8..c0dcdfb5 100644 --- a/src/GridText.c +++ b/src/GridText.c @@ -1,5 +1,5 @@ /* - * $LynxId: GridText.c,v 1.140 2007/05/13 20:42:37 Takeshi.Hataguchi Exp $ + * $LynxId: GridText.c,v 1.141 2007/07/22 23:04:06 tom Exp $ * * Character grid hypertext object * =============================== @@ -50,8 +50,7 @@ #ifdef USE_COLOR_STYLE #include <AttrList.h> #include <LYHash.h> - -unsigned int cached_styles[CACHEH][CACHEW]; +#include <LYStyle.h> #endif @@ -81,18 +80,6 @@ unsigned int cached_styles[CACHEH][CACHEW]; static void HText_trimHightext(HText *text, BOOLEAN final, int stop_before); -#ifdef USE_COLOR_STYLE -static void LynxResetScreenCache(void) -{ - int i, j; - - for (i = 1; (i < CACHEH && i <= display_lines); i++) { - for (j = 0; j < CACHEW; j++) - cached_styles[i][j] = 0; - } -} -#endif /* USE_COLOR_STYLE */ - struct _HTStream { /* only know it as object */ const HTStreamClass *isa; /* ... */ @@ -2097,7 +2084,7 @@ static void display_page(HText *text, line_number != text->first_lineno_last_disp_partial || line_number > text->last_lineno_last_disp_partial) #endif /* DISP_PARTIAL */ - LynxResetScreenCache(); + ResetCachedStyles(); #endif /* USE_COLOR_STYLE */ #ifdef DISP_PARTIAL diff --git a/src/HTML.c b/src/HTML.c index 962993e1..3a9b1d50 100644 --- a/src/HTML.c +++ b/src/HTML.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTML.c,v 1.112 2007/05/10 00:20:31 tom Exp $ + * $LynxId: HTML.c,v 1.113 2007/07/02 23:43:40 tom Exp $ * * Structured stream to Rich hypertext converter * ============================================ @@ -4447,9 +4447,9 @@ static int HTML_start_element(HTStructured * me, int element_number, */ for (i = 0; I.value[i]; i++) { HTML_put_character(me, - (I.value[i] == ' ') - ? HT_NON_BREAK_SPACE - : I.value[i]); + (char) ((I.value[i] == ' ') + ? HT_NON_BREAK_SPACE + : I.value[i])); } while (i++ < chars) { HTML_put_character(me, HT_NON_BREAK_SPACE); diff --git a/src/LYCharUtils.c b/src/LYCharUtils.c index 82dcb869..a7a7359f 100644 --- a/src/LYCharUtils.c +++ b/src/LYCharUtils.c @@ -1,4 +1,6 @@ /* + * $LynxId: LYCharUtils.c,v 1.88 2007/07/02 23:58:53 tom Exp $ + * * Functions associated with LYCharSets.c and the Lynx version of HTML.c - FM * ========================================================================== */ @@ -1079,7 +1081,7 @@ char **LYUCFullyTranslateString(char **str, int uck; int lowest_8; UCode_t code = 0; - long int lcode; + unsigned long lcode; BOOL output_utf8 = 0, repl_translated_C0 = 0; size_t len; const char *name = NULL; @@ -1523,9 +1525,10 @@ char **LYUCFullyTranslateString(char **str, * (3) Is 127 and we don't have HTPassHighCtrlRaw or HTCJK set. * (4) Is 128 - 159 and we don't have HTPassHighCtrlNum set. */ - if ((((what == P_hex) ? sscanf(cp, "%lx", &lcode) : - sscanf(cp, "%ld", &lcode)) != 1) || - lcode > 0x7fffffffL || lcode < 0) { + if ((((what == P_hex) + ? sscanf(cp, "%lx", &lcode) + : sscanf(cp, "%lu", &lcode)) != 1) || + lcode > 0x7fffffffL) { state = S_recover; break; } else { diff --git a/src/LYCurses.c b/src/LYCurses.c index a25a20d0..2b1d9beb 100644 --- a/src/LYCurses.c +++ b/src/LYCurses.c @@ -1,4 +1,4 @@ -/* $LynxId: LYCurses.c,v 1.129 2007/07/02 00:11:35 tom Exp $ */ +/* $LynxId: LYCurses.c,v 1.131 2007/07/24 21:58:34 tom Exp $ */ #include <HTUtils.h> #include <HTAlert.h> @@ -452,8 +452,8 @@ void curses_w_style(WINDOW * win, int style, if (style == s_normal && dir) { LYAttrset(win, ds->color, ds->mono); - if (win == LYwin && CACHE_VALIDATE_YX(YP, XP)) - cached_styles[YP][XP] = s_normal; + if (win == LYwin) + SetCachedStyle(YP, XP, s_normal); return; } @@ -498,8 +498,8 @@ void curses_w_style(WINDOW * win, int style, && style != s_aedit_arr) { CTRACE2(TRACE_STYLE, (tfp, "CACHED: <%s> @(%d,%d)\n", ds->name, YP, XP)); - if (win == LYwin && CACHE_VALIDATE_YX(YP, XP)) - cached_styles[YP][XP] = style; + if (win == LYwin) + SetCachedStyle(YP, XP, style); } LYAttrset(win, ds->color, ds->mono); break; @@ -1422,6 +1422,9 @@ void lynx_nl2crlf(int normal GCC_UNUSED) void stop_curses(void) { if (LYCursesON) { +#ifdef USE_COLOR_STYLE + FreeCachedStyles(); +#endif echo(); } #if defined(PDCURSES) && defined(PDC_BUILD) && PDC_BUILD >= 2401 diff --git a/src/LYExtern.c b/src/LYExtern.c index 9f5471db..6c0da690 100644 --- a/src/LYExtern.c +++ b/src/LYExtern.c @@ -1,4 +1,6 @@ /* + * $LynxId: LYExtern.c,v 1.38 2007/07/24 22:50:21 tom Exp $ + * External application support. This feature allows lynx to pass a given URL to an external program. It was written for three reasons. @@ -302,7 +304,7 @@ static char *lookup_external(char *param, -1, FALSE, TRUE, - FALSE); + (keypad_mode != NUMBERS_AS_ARROWS)); wmove(LYwin, old_y, old_x); CTRACE((tfp, "selected choice %d of %d\n", cur_choice, num_choices)); if (cur_choice < 0) { diff --git a/src/LYHash.h b/src/LYHash.h index 448fe42c..c60e24d6 100644 --- a/src/LYHash.h +++ b/src/LYHash.h @@ -1,3 +1,4 @@ +/* $LynxId: LYHash.h,v 1.23 2007/07/22 23:08:36 tom Exp $ */ #ifndef _LYHASH_H_ #define _LYHASH_H_ 1 @@ -76,12 +77,6 @@ extern "C" { extern bucket special_bucket; #endif -#define CACHEW 128 -#define CACHEH 64 - - extern unsigned cached_styles[CACHEH][CACHEW]; -#define CACHE_VALIDATE_YX(y, x) ((y) >= 0 && (x) >= 0 && (y) < CACHEH && (x) < CACHEW) - #ifdef __cplusplus } #endif diff --git a/src/LYLeaks.c b/src/LYLeaks.c index f41d2a7e..e7a4ee5d 100644 --- a/src/LYLeaks.c +++ b/src/LYLeaks.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYLeaks.c,v 1.29 2007/05/06 21:43:33 tom Exp $ + * $LynxId: LYLeaks.c,v 1.32 2007/07/23 22:54:46 tom Exp $ * * Copyright (c) 1994, University of Kansas, All Rights Reserved * (this file was rewritten twice - 1998/1999 and 2003/2004) @@ -130,21 +130,21 @@ static void RemoveFromList(AllocationList * ALp_del) */ if (ALp_del == ALp_findbefore) { ALp_RunTimeAllocations = ALp_del->ALp_Next; - return; - } + } else { - /* - * Loop through checking all of the next values, if a match don't continue. - * Always assume the item will be found. - */ - while (ALp_findbefore->ALp_Next != ALp_del) { - ALp_findbefore = ALp_findbefore->ALp_Next; - } + /* + * Loop through checking all of the next values, if a match don't + * continue. Always assume the item will be found. + */ + while (ALp_findbefore->ALp_Next != ALp_del) { + ALp_findbefore = ALp_findbefore->ALp_Next; + } - /* - * We are one item before the one to get rid of. Get rid of it. - */ - ALp_findbefore->ALp_Next = ALp_del->ALp_Next; + /* + * We are one item before the one to get rid of. Get rid of it. + */ + ALp_findbefore->ALp_Next = ALp_del->ALp_Next; + } } /* @@ -179,8 +179,17 @@ void LYLeaks(void) CTRACE((tfp, "entering LYLeaks, flag=%d\n", LYfind_leaks)); - if (LYfind_leaks == FALSE) + if (LYfind_leaks == FALSE) { + /* + * Free MY leaks too, in case someone else is watching. + */ + while (ALp_RunTimeAllocations != NULL) { + ALp_head = ALp_RunTimeAllocations; + ALp_RunTimeAllocations = ALp_head->ALp_Next; + free(ALp_head); + } return; + } /* * Open the leakage sink to take all the output. Recreate the file each @@ -199,7 +208,7 @@ void LYLeaks(void) ALp_RunTimeAllocations = ALp_head->ALp_Next; /* - * Print the type of leak/error. Free off memory when we no longer + * Print the type of leak/error. Release memory when we no longer * need it. */ if (ALp_head->vp_Alloced == NULL) { @@ -337,44 +346,45 @@ void *LYLeakMalloc(size_t st_bytes, const char *cp_File, { void *vp_malloc; - if (LYfind_leaks == FALSE) - return (void *) malloc(st_bytes); - - /* - * Do the actual allocation. - */ - vp_malloc = (void *) malloc(st_bytes); - CountMallocs(st_bytes); - - /* - * Only on successful allocation do we track any information. - */ - if (vp_malloc != NULL) { - /* - * Further allocate memory to store the information. Just return on - * failure to allocate more. - */ - AllocationList *ALp_new = typecalloc(AllocationList); + if (LYfind_leaks == FALSE) { + vp_malloc = (void *) malloc(st_bytes); + } else { - if (ALp_new == NULL) { - return (vp_malloc); - } /* - * Copy over the relevant information. There is no need to allocate - * more memory for the file name as it is a static string anyhow. + * Do the actual allocation. */ - ALp_new->st_Sequence = count_mallocs; - ALp_new->vp_Alloced = vp_malloc; - ALp_new->st_Bytes = st_bytes; - ALp_new->SL_memory.cp_FileName = cp_File; - ALp_new->SL_memory.ssi_LineNumber = ssi_Line; + vp_malloc = (void *) malloc(st_bytes); + CountMallocs(st_bytes); /* - * Add the new item to the allocation list. + * Only on successful allocation do we track any information. */ - AddToList(ALp_new); + if (vp_malloc != NULL) { + /* + * Further allocate memory to store the information. Just return + * on failure to allocate more. + */ + AllocationList *ALp_new = typecalloc(AllocationList); + + if (ALp_new != NULL) { + /* + * Copy over the relevant information. There is no need to + * allocate more memory for the file name as it is a static + * string anyway. + */ + ALp_new->st_Sequence = count_mallocs; + ALp_new->vp_Alloced = vp_malloc; + ALp_new->st_Bytes = st_bytes; + ALp_new->SL_memory.cp_FileName = cp_File; + ALp_new->SL_memory.ssi_LineNumber = ssi_Line; + + /* + * Add the new item to the allocation list. + */ + AddToList(ALp_new); + } + } } - return (vp_malloc); } @@ -405,48 +415,44 @@ AllocationList *LYLeak_mark_malloced(void *vp_malloced, { AllocationList *ALp_new = NULL; - if (LYfind_leaks == FALSE) - return NULL; - - /* - * The actual allocation has already been done! - * - * Only on successful allocation do we track any information. - */ - if (vp_malloced != NULL) { + if (LYfind_leaks != FALSE) { /* - * See if there is already an entry. If so, just update the source - * location info. + * The actual allocation has already been done! + * + * Only on successful allocation do we track any information. */ - ALp_new = FindInList(vp_malloced); - if (ALp_new) { - ALp_new->SL_memory.cp_FileName = cp_File; - ALp_new->SL_memory.ssi_LineNumber = ssi_Line; - return (ALp_new); - } - /* - * Further allocate memory to store the information. Just return on - * failure to allocate more. - */ - ALp_new = typecalloc(AllocationList); - - if (ALp_new == NULL) { - return (NULL); + if (vp_malloced != NULL) { + /* + * See if there is already an entry. If so, just update the source + * location info. + */ + ALp_new = FindInList(vp_malloced); + if (ALp_new) { + ALp_new->SL_memory.cp_FileName = cp_File; + ALp_new->SL_memory.ssi_LineNumber = ssi_Line; + } else { + /* + * Further allocate memory to store the information. Just + * return on failure to allocate more. + */ + ALp_new = typecalloc(AllocationList); + if (ALp_new != NULL) { + /* + * Copy over the relevant information. + */ + ALp_new->vp_Alloced = vp_malloced; + ALp_new->st_Bytes = st_bytes; + ALp_new->SL_memory.cp_FileName = cp_File; + ALp_new->SL_memory.ssi_LineNumber = ssi_Line; + + /* + * Add the new item to the allocation list. + */ + AddToList(ALp_new); + } + } } - /* - * Copy over the relevant information. - */ - ALp_new->vp_Alloced = vp_malloced; - ALp_new->st_Bytes = st_bytes; - ALp_new->SL_memory.cp_FileName = cp_File; - ALp_new->SL_memory.ssi_LineNumber = ssi_Line; - - /* - * Add the new item to the allocation list. - */ - AddToList(ALp_new); } - return (ALp_new); } @@ -471,45 +477,46 @@ void *LYLeakCalloc(size_t st_number, size_t st_bytes, const char *cp_File, { void *vp_calloc; - if (LYfind_leaks == FALSE) - return (void *) calloc(st_number, st_bytes); - - /* - * Allocate the requested memory. - */ - vp_calloc = (void *) calloc(st_number, st_bytes); - CountMallocs(st_bytes); - - /* - * Only if the allocation was a success do we track information. - */ - if (vp_calloc != NULL) { - /* - * Allocate memory for the item to be in the list. If unable, just - * return. - */ - AllocationList *ALp_new = typecalloc(AllocationList); - - if (ALp_new == NULL) { - return (vp_calloc); - } + if (LYfind_leaks == FALSE) { + vp_calloc = (void *) calloc(st_number, st_bytes); + } else { /* - * Copy over the relevant information. There is no need to allocate - * memory for the file name as it is a static string anyway. + * Allocate the requested memory. */ - ALp_new->st_Sequence = count_mallocs; - ALp_new->vp_Alloced = vp_calloc; - ALp_new->st_Bytes = (st_number * st_bytes); - ALp_new->SL_memory.cp_FileName = cp_File; - ALp_new->SL_memory.ssi_LineNumber = ssi_Line; + vp_calloc = (void *) calloc(st_number, st_bytes); + CountMallocs(st_bytes); /* - * Add the item to the allocation list. + * Only if the allocation was a success do we track information. */ - AddToList(ALp_new); + if (vp_calloc != NULL) { + /* + * Allocate memory for the item to be in the list. If unable, just + * return. + */ + AllocationList *ALp_new = typecalloc(AllocationList); + + if (ALp_new != NULL) { + + /* + * Copy over the relevant information. There is no need to + * allocate memory for the file name as it is a static string + * anyway. + */ + ALp_new->st_Sequence = count_mallocs; + ALp_new->vp_Alloced = vp_calloc; + ALp_new->st_Bytes = (st_number * st_bytes); + ALp_new->SL_memory.cp_FileName = cp_File; + ALp_new->SL_memory.ssi_LineNumber = ssi_Line; + + /* + * Add the item to the allocation list. + */ + AddToList(ALp_new); + } + } } - return (vp_calloc); } @@ -543,68 +550,70 @@ void *LYLeakRealloc(void *vp_Alloced, void *vp_realloc; AllocationList *ALp_renew; - if (LYfind_leaks == FALSE) - return (void *) realloc(vp_Alloced, st_newBytes); - - /* - * If we are asked to resize a NULL pointer, this is just a malloc call. - */ - if (vp_Alloced == NULL) { - return (LYLeakMalloc(st_newBytes, cp_File, ssi_Line)); - } + if (LYfind_leaks == FALSE) { + vp_realloc = (void *) realloc(vp_Alloced, st_newBytes); - /* - * Find the current vp_Alloced block in the list. If NULL, this is an - * invalid pointer value. - */ - ALp_renew = FindInList(vp_Alloced); - if (ALp_renew == NULL) { + } else if (vp_Alloced == NULL) { /* - * Track the invalid pointer value and then exit. If unable to - * allocate, just exit. + * If we are asked to resize a NULL pointer, this is just a malloc + * call. */ - auto AllocationList *ALp_new = typecalloc(AllocationList); + vp_realloc = LYLeakMalloc(st_newBytes, cp_File, ssi_Line); - if (ALp_new == NULL) { - exit_immediately(EXIT_FAILURE); - } + } else { /* - * Set the information up; no need to allocate file name since it is a - * static string. + * Find the current vp_Alloced block in the list. If NULL, this is an + * invalid pointer value. */ - ALp_new->vp_Alloced = NULL; - ALp_new->vp_BadRequest = vp_Alloced; - ALp_new->SL_realloc.cp_FileName = cp_File; - ALp_new->SL_realloc.ssi_LineNumber = ssi_Line; + ALp_renew = FindInList(vp_Alloced); + if (ALp_renew == NULL) { + /* + * Track the invalid pointer value and then exit. If unable to + * allocate, just exit. + */ + AllocationList *ALp_new = typecalloc(AllocationList); - /* - * Add the item to the list. Exit. - */ - AddToList(ALp_new); - exit_immediately(EXIT_FAILURE); - } + if (ALp_new == NULL) { + exit_immediately(EXIT_FAILURE); + } - /* - * Perform the resize. If not NULL, record the information. - */ - vp_realloc = (void *) realloc(vp_Alloced, st_newBytes); - CountMallocs(st_newBytes); - CountFrees(ALp_renew->st_Bytes); + /* + * Set the information up; no need to allocate file name since it is a + * static string. + */ + ALp_new->vp_Alloced = NULL; + ALp_new->vp_BadRequest = vp_Alloced; + ALp_new->SL_realloc.cp_FileName = cp_File; + ALp_new->SL_realloc.ssi_LineNumber = ssi_Line; - if (vp_realloc != NULL) { - ALp_renew->st_Sequence = count_mallocs; - ALp_renew->vp_Alloced = vp_realloc; - ALp_renew->st_Bytes = st_newBytes; + /* + * Add the item to the list. Exit. + */ + AddToList(ALp_new); + exit_immediately(EXIT_FAILURE); + } /* - * Update the realloc information, too. No need to allocate file name, - * static string. + * Perform the resize. If not NULL, record the information. */ - ALp_renew->SL_realloc.cp_FileName = cp_File; - ALp_renew->SL_realloc.ssi_LineNumber = ssi_Line; - } + vp_realloc = (void *) realloc(vp_Alloced, st_newBytes); + CountMallocs(st_newBytes); + CountFrees(ALp_renew->st_Bytes); + if (vp_realloc != NULL) { + ALp_renew->st_Sequence = count_mallocs; + ALp_renew->vp_Alloced = vp_realloc; + ALp_renew->st_Bytes = st_newBytes; + + /* + * Update the realloc information, too. No need to allocate file name, + * static string. + */ + ALp_renew->SL_realloc.cp_FileName = cp_File; + ALp_renew->SL_realloc.ssi_LineNumber = ssi_Line; + } + } return (vp_realloc); } @@ -682,47 +691,46 @@ void LYLeakFree(void *vp_Alloced, if (LYfind_leaks == FALSE) { free(vp_Alloced); - return; - } + } else { - /* - * Find the pointer in the allocated list. If not found, bad pointer. If - * found, free list item and vp_Allloced. - */ - ALp_free = FindInList(vp_Alloced); - if (ALp_free == NULL) { /* - * Create the final entry before exiting marking this error. If unable - * to allocate more memory just exit. + * Find the pointer in the allocated list. If not found, bad pointer. + * If found, free list item and vp_Alloced. */ - AllocationList *ALp_new = typecalloc(AllocationList); + ALp_free = FindInList(vp_Alloced); + if (ALp_free == NULL) { + /* + * Create the final entry before exiting marking this error. If + * unable to allocate more memory just exit. + */ + AllocationList *ALp_new = typecalloc(AllocationList); - if (ALp_new == NULL) { - exit_immediately(EXIT_FAILURE); - } + if (ALp_new == NULL) { + exit_immediately(EXIT_FAILURE); + } - /* - * Set up the information, no memory need be allocated for the file - * name since it is a static string. - */ - ALp_new->vp_Alloced = NULL; - ALp_new->vp_BadRequest = vp_Alloced; - ALp_new->SL_memory.cp_FileName = cp_File; - ALp_new->SL_memory.ssi_LineNumber = ssi_Line; + /* + * Set up the information, no memory need be allocated for the file + * name since it is a static string. + */ + ALp_new->vp_Alloced = NULL; + ALp_new->vp_BadRequest = vp_Alloced; + ALp_new->SL_memory.cp_FileName = cp_File; + ALp_new->SL_memory.ssi_LineNumber = ssi_Line; - /* - * Add the entry to the list and then return. - */ - AddToList(ALp_new); - return; - } else { - /* - * Free off the memory. Take entry out of allocation list. - */ - CountFrees(ALp_free->st_Bytes); - RemoveFromList(ALp_free); - FREE(ALp_free); - FREE(vp_Alloced); + /* + * Add the entry to the list and then return. + */ + AddToList(ALp_new); + } else { + /* + * Free off the memory. Take entry out of allocation list. + */ + CountFrees(ALp_free->st_Bytes); + RemoveFromList(ALp_free); + FREE(ALp_free); + free(vp_Alloced); + } } } @@ -740,17 +748,17 @@ char *LYLeakSACopy(char **dest, CTRACE((tfp, "LYLeakSACopy: *dest equals src, contains \"%s\"\n", src)); - return *dest; - } - if (*dest) { - LYLeakFree(*dest, cp_File, ssi_Line); - *dest = NULL; - } - if (src) { - *dest = (char *) LYLeakMalloc(strlen(src) + 1, cp_File, ssi_Line); - if (*dest == NULL) - outofmem(__FILE__, "LYLeakSACopy"); - strcpy(*dest, src); + } else { + if (*dest) { + LYLeakFree(*dest, cp_File, ssi_Line); + *dest = NULL; + } + if (src) { + *dest = (char *) LYLeakMalloc(strlen(src) + 1, cp_File, ssi_Line); + if (*dest == NULL) + outofmem(__FILE__, "LYLeakSACopy"); + strcpy(*dest, src); + } } return *dest; } @@ -770,9 +778,7 @@ char *LYLeakSACat(char **dest, CTRACE((tfp, "LYLeakSACat: *dest equals src, contains \"%s\"\n", src)); - return *dest; - } - if (*dest) { + } else if (*dest) { int length = strlen(*dest); *dest = (char *) LYLeakRealloc(*dest, @@ -873,7 +879,7 @@ static char *LYLeakSAVsprintf(char **dest, * Track the invalid pointer value and then exit. If unable to * allocate, just exit. */ - auto AllocationList *ALp_new = typecalloc(AllocationList); + AllocationList *ALp_new = typecalloc(AllocationList); if (ALp_new == NULL) { exit_immediately(EXIT_FAILURE); @@ -943,53 +949,35 @@ static char *LYLeakSAVsprintf(char **dest, /* Note: the following may need updating if HTSprintf in HTString.c * is changed. - kw */ -#ifdef ANSI_VARARGS static char *LYLeakHTSprintf(char **pstr, const char *fmt,...) -#else -static char *LYLeakHTSprintf(va_alist) - va_dcl -#endif { char *str; size_t inuse = 0; va_list ap; LYva_start(ap, fmt); - { -#ifndef ANSI_VARARGS - char **pstr = va_arg(ap, char **); - const char *fmt = va_arg(ap, const char *); -#endif - if (pstr != 0 && *pstr != 0) - inuse = strlen(*pstr); - str = LYLeakSAVsprintf(pstr, leak_cp_File_hack, leak_ssi_Line_hack, - inuse, fmt, &ap); - } + + if (pstr != 0 && *pstr != 0) + inuse = strlen(*pstr); + str = LYLeakSAVsprintf(pstr, leak_cp_File_hack, leak_ssi_Line_hack, + inuse, fmt, &ap); + va_end(ap); return str; } /* Note: the following may need updating if HTSprintf0 in HTString.c * is changed. - kw */ -#ifdef ANSI_VARARGS static char *LYLeakHTSprintf0(char **pstr, const char *fmt,...) -#else -static char *LYLeakHTSprintf0(va_alist) - va_dcl -#endif { char *str; va_list ap; LYva_start(ap, fmt); - { -#ifndef ANSI_VARARGS - char **pstr = va_arg(ap, char **); - const char *fmt = va_arg(ap, const char *); -#endif - str = LYLeakSAVsprintf(pstr, leak_cp_File_hack, leak_ssi_Line_hack, - 0, fmt, &ap); - } + + str = LYLeakSAVsprintf(pstr, leak_cp_File_hack, leak_ssi_Line_hack, + 0, fmt, &ap); + va_end(ap); return str; } diff --git a/src/LYMain.c b/src/LYMain.c index 90020c92..b27bd7be 100644 --- a/src/LYMain.c +++ b/src/LYMain.c @@ -1,4 +1,4 @@ -/* $LynxId: LYMain.c,v 1.174 2007/07/02 00:07:27 tom Exp $ */ +/* $LynxId: LYMain.c,v 1.175 2007/07/02 22:41:49 tom Exp $ */ #include <HTUtils.h> #include <HTTP.h> #include <HTParse.h> @@ -4121,7 +4121,7 @@ static BOOL parse_arg(char **argv, arg_name, mask, countp ? *countp : -1)); #if EXTENDED_STARTFILE_RECALL - if (mask == ((countp != 0) ? 0 : 1)) { + if (mask == (unsigned) ((countp != 0) ? 0 : 1)) { no_options_further = FALSE; /* want to reset nonoption when beginning scan for --stdin */ if (nonoption != 0) { diff --git a/src/LYStyle.c b/src/LYStyle.c index e577a256..512a5bde 100644 --- a/src/LYStyle.c +++ b/src/LYStyle.c @@ -1,6 +1,8 @@ -/* character level styles for Lynx +/* + * $LynxId: LYStyle.c,v 1.61 2007/07/23 19:57:17 tom Exp $ + * + * character level styles for Lynx * (c) 1996 Rob Partington -- donated to the Lyncei (if they want it :-) - * $LynxId: LYStyle.c,v 1.58 2007/05/23 00:32:21 tom Exp $ */ #include <HTUtils.h> #include <HTML.h> @@ -22,6 +24,7 @@ #include <LYexit.h> #include <LYLeaks.h> #include <LYStrings.h> +#include <LYHash.h> #define CTRACE1(p) CTRACE2(TRACE_CFG || TRACE_STYLE, p) @@ -35,6 +38,13 @@ static void style_initialiseHashTable(void); */ static HTList *lss_styles = NULL; +#define CACHEW 128 +#define CACHEH 64 + +static unsigned *cached_styles_ptr = NULL; +static int cached_styles_rows = 0; +static int cached_styles_cols = 0; + /* stack of attributes during page rendering */ int last_styles[MAX_LAST_STYLES] = {0}; @@ -382,6 +392,7 @@ static void free_colorstylestuff(void) style_initialiseHashTable(); style_deleteStyleList(); memset(our_pairs, 0, sizeof(our_pairs)); + FreeCachedStyles(); } /* @@ -701,9 +712,9 @@ void FastTrimColorClass(const char *tag_name, *phcode = hash_code(tag_start + 1); } - /* This is called each time lss styles are read. It will fill - * each elt of 'cached_tag_styles' -HV - */ +/* This is called each time lss styles are read. It will fill + * each element of 'cached_tag_styles' -HV + */ void cache_tag_styles(void) { char buf[200]; @@ -716,4 +727,65 @@ void cache_tag_styles(void) } } +#define SIZEOF_CACHED_STYLES (cached_styles_rows * cached_styles_cols) + +static unsigned *RefCachedStyle(int y, int x) +{ + unsigned *result = 0; + + if (cached_styles_ptr == 0) { + cached_styles_rows = display_lines; + cached_styles_cols = LYcols; + cached_styles_ptr = typecallocn(unsigned, SIZEOF_CACHED_STYLES); + } + if (y >= 0 && + x >= 0 && + y < cached_styles_rows && + x < cached_styles_cols) { + result = cached_styles_ptr + (y * cached_styles_cols) + x; + } + return result; +} + +BOOL ValidCachedStyle(int y, int x) +{ + return (RefCachedStyle(y, x) != 0); +} + +unsigned GetCachedStyle(int y, int x) +{ + unsigned value = 0; + unsigned *cache = RefCachedStyle(y, x); + + if (cache != 0) { + value = *cache; + } + return value; +} + +void SetCachedStyle(int y, int x, unsigned value) +{ + unsigned *cache = RefCachedStyle(y, x); + + if (cache != 0) { + *cache = value; + } +} + +void ResetCachedStyles(void) +{ + if (cached_styles_ptr != NULL) { + memset(cached_styles_ptr, 0, sizeof(unsigned) * SIZEOF_CACHED_STYLES); + } +} + +void FreeCachedStyles(void) +{ + if (cached_styles_ptr != NULL) { + FREE(cached_styles_ptr); + cached_styles_rows = 0; + cached_styles_cols = 0; + } +} + #endif /* USE_COLOR_STYLE */ diff --git a/src/LYStyle.h b/src/LYStyle.h index edc4051a..d1cf9db1 100644 --- a/src/LYStyle.h +++ b/src/LYStyle.h @@ -1,3 +1,4 @@ +/* $LynxId: LYStyle.h,v 1.15 2007/07/23 19:21:54 tom Exp $ */ #ifndef LYSTYLE_H #define LYSTYLE_H @@ -63,6 +64,15 @@ extern "C" { char **pstylename_end, int *hcode); +/* + * Functions for cached-styles + */ + extern BOOL ValidCachedStyle(int y, int x); + extern unsigned GetCachedStyle(int y, int x); + extern void FreeCachedStyles(void); + extern void ResetCachedStyles(void); + extern void SetCachedStyle(int y, int x, unsigned value); + #ifdef __cplusplus } #endif diff --git a/src/LYUtils.c b/src/LYUtils.c index 629f24f6..18199133 100644 --- a/src/LYUtils.c +++ b/src/LYUtils.c @@ -1,4 +1,4 @@ -/* $LynxId: LYUtils.c,v 1.157 2007/05/20 23:28:43 Thorsten.Glaser Exp $ */ +/* $LynxId: LYUtils.c,v 1.161 2007/07/22 23:53:16 tom Exp $ */ #include <HTUtils.h> #include <HTTCP.h> #include <HTParse.h> @@ -6,12 +6,19 @@ #include <HTCJK.h> #include <HTAlert.h> -#ifdef __MINGW32__ -int kbhit(void); /* FIXME: use conio.h */ +#if defined(__MINGW32__) + +extern int kbhit(void); /* FIXME: use conio.h */ -#ifdef UNIX #undef UNIX -#endif /* UNIX */ + +#elif defined(_WINDOWS) + +#include <conio.h> +#if !defined(kbhit) && defined(_WCONIO_DEFINED) +#define kbhit() _kbhit() /* reasonably recent conio.h */ +#endif + #endif /* __MINGW32__ */ #include <LYCurses.h> @@ -960,25 +967,22 @@ static int find_cached_style(int cur, /* * This is where we try to restore the original style when a link is - * unhighlighted. The purpose of cached_styles[][] is to save the - * original style just for this case. If it doesn't have a color - * change saved at just the right position, we look at preceding - * positions in the same line until we find one. + * unhighlighted. The cached styles array saves the original style + * just for this case. If it doesn't have a color change saved at just + * the right position, we look at preceding positions in the same line + * until we find one. */ - if (CACHE_VALIDATE_YX(LYP, LXP)) { + if (ValidCachedStyle(LYP, LXP)) { CTRACE2(TRACE_STYLE, (tfp, "STYLE.highlight.off: cached style @(%d,%d): ", LYP, LXP)); - s = cached_styles[LYP][LXP]; + s = GetCachedStyle(LYP, LXP); if (s == 0) { for (x = LXP - 1; x >= 0; x--) { - if (cached_styles[LYP][x]) { - if (cached_styles[LYP][x] > 0) { - s = cached_styles[LYP][x]; - cached_styles[LYP][LXP] = s; - } - CTRACE((tfp, "found %u, x_offset=%d.\n", - cached_styles[LYP][x], (int) x - LXP)); + s = GetCachedStyle(LYP, x); + if (s != 0) { + SetCachedStyle(LYP, LXP, s); + CTRACE((tfp, "found %u, x_offset=%d.\n", s, x - LXP)); break; } } @@ -5877,11 +5881,12 @@ static BOOL IsOurSymlink(const char *name) BOOL result = FALSE; int size = LY_MAXPATH; int used; - char *buffer = malloc(size); + char *buffer = typeMallocn(char, size); if (buffer != 0) { while ((used = readlink(name, buffer, size)) == -1) { - buffer = realloc(buffer, size *= 2); + buffer = typeRealloc(char, buffer, size *= 2); + if (buffer == 0) break; } diff --git a/src/LYUtils.h b/src/LYUtils.h index bc5da5ab..9d44c9d0 100644 --- a/src/LYUtils.h +++ b/src/LYUtils.h @@ -1,3 +1,4 @@ +/* $LynxId: LYUtils.h,v 1.76 2007/07/02 23:43:21 tom Exp $ */ #ifndef LYUTILS_H #define LYUTILS_H @@ -215,7 +216,7 @@ extern "C" { extern int Cygwin_Shell(void); #endif -#ifdef _WIN_CC +#if defined(_WIN_CC) || defined(WIN_EX) extern int exec_command(char *cmd, int wait_flag); /* xsystem.c */ extern int xsystem(char *cmd); #endif |