diff options
Diffstat (limited to 'WWW/Library')
-rw-r--r-- | WWW/Library/Implementation/HTAnchor.c | 28 | ||||
-rw-r--r-- | WWW/Library/Implementation/HTAtom.c | 79 | ||||
-rw-r--r-- | WWW/Library/Implementation/HTAtom.h | 1 | ||||
-rw-r--r-- | WWW/Library/Implementation/HTMLGen.c | 15 |
4 files changed, 21 insertions, 102 deletions
diff --git a/WWW/Library/Implementation/HTAnchor.c b/WWW/Library/Implementation/HTAnchor.c index b8e17241..d782020b 100644 --- a/WWW/Library/Implementation/HTAnchor.c +++ b/WWW/Library/Implementation/HTAnchor.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTAnchor.c,v 1.78 2018/03/02 22:01:24 tom Exp $ + * $LynxId: HTAnchor.c,v 1.80 2018/03/06 09:34:12 tom Exp $ * * Hypertext "Anchor" Object HTAnchor.c * ========================== @@ -31,29 +31,15 @@ #include <LYUtils.h> #include <LYLeaks.h> -#define HASH_TYPE unsigned short +#define HASH_OF(h, v) ((HASH_TYPE)((h) * 3 + UCH(v)) % HASH_SIZE) -#ifdef NOT_DEFINED -/* - * This is the hashing function used to determine which list in the - * adult_table a parent anchor should be put in. This is a - * much simpler function than the original used. - */ -#define HASH_FUNCTION(cp_address) \ - ( (HASH_TYPE)strlen(cp_address) *\ - (HASH_TYPE)TOUPPER(*cp_address) % HASH_SIZE ) -#endif /* NOT_DEFINED */ - -/* - * This is the original function. We'll use it again. - FM - */ -static HASH_TYPE HASH_FUNCTION(const char *cp_address) +static HASH_TYPE anchor_hash(const char *cp_address) { HASH_TYPE hash; - const unsigned char *p; + const char *p; - for (p = (const unsigned char *) cp_address, hash = 0; *p; p++) - hash = (HASH_TYPE) (hash * 3 + (*(const unsigned char *) p)) % HASH_SIZE; + for (p = cp_address, hash = 0; *p; p++) + hash = HASH_OF(hash, *p); return (hash); } @@ -446,7 +432,7 @@ static HTParentAnchor0 *HTAnchor_findAddress_in_adult_table(const DocAddress *ne /* * Select list from hash table, */ - hash = HASH_FUNCTION(newdoc->address); + hash = anchor_hash(newdoc->address); adults = &(adult_table[hash]); /* diff --git a/WWW/Library/Implementation/HTAtom.c b/WWW/Library/Implementation/HTAtom.c index 914a7f37..07eca771 100644 --- a/WWW/Library/Implementation/HTAtom.c +++ b/WWW/Library/Implementation/HTAtom.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTAtom.c,v 1.20 2016/11/24 15:29:50 tom Exp $ + * $LynxId: HTAtom.c,v 1.22 2018/03/06 09:46:58 tom Exp $ * * Atoms: Names to numbers HTAtom.c * ======================= @@ -17,15 +17,13 @@ */ #include <HTUtils.h> - -#define HASH_SIZE 101 /* Tunable */ #include <HTAtom.h> - #include <HTList.h> - #include <LYexit.h> #include <LYLeaks.h> +#define HASH_SIZE 101 /* Arbitrary prime. Memory/speed tradeoff */ + static HTAtom *hash_table[HASH_SIZE]; static BOOL initialised = NO; @@ -36,9 +34,6 @@ static BOOL initialised = NO; static void free_atoms(void); #endif -/* - * Alternate hashing function. - */ #define HASH_FUNCTION(cp_hash) ((strlen(cp_hash) * UCH(*cp_hash)) % HASH_SIZE) HTAtom *HTAtom_for(const char *string) @@ -46,38 +41,22 @@ HTAtom *HTAtom_for(const char *string) size_t hash; HTAtom *a; - /* First time around, clear hash table - */ - /* - * Memory leak fixed. - * 05-29-94 Lynx 2-3-1 Garrett Arch Blythe - */ if (!initialised) { - int i; - - for (i = 0; i < HASH_SIZE; i++) - hash_table[i] = (HTAtom *) 0; + memset(hash_table, 0, sizeof(hash_table)); initialised = YES; #ifdef LY_FIND_LEAKS atexit(free_atoms); #endif } - /* Generate hash function - */ hash = HASH_FUNCTION(string); - /* Search for the string in the list - */ for (a = hash_table[hash]; a; a = a->next) { if (0 == strcasecomp(a->name, string)) { - /* CTRACE((tfp, "HTAtom: Old atom %p for `%s'\n", a, string)); */ - return a; /* Found: return it */ + return a; } } - /* Generate a new entry - */ a = (HTAtom *) malloc(sizeof(*a)); if (a == NULL) outofmem(__FILE__, "HTAtom_for"); @@ -87,11 +66,8 @@ HTAtom *HTAtom_for(const char *string) outofmem(__FILE__, "HTAtom_for"); strcpy(a->name, string); - a->next = hash_table[hash]; /* Put onto the head of list */ + a->next = hash_table[hash]; hash_table[hash] = a; -#ifdef NOT_DEFINED - CTRACE((tfp, "HTAtom: New atom %p for `%s'\n", a, string)); -#endif /* NOT_DEFINED */ return a; } @@ -129,46 +105,3 @@ static void free_atoms(void) } } #endif /* LY_FIND_LEAKS */ - -static BOOL mime_match(const char *name, - const char *templ) -{ - if (name && templ) { - static char *n1 = NULL; - static char *t1 = NULL; - char *n2; - char *t2; - - StrAllocCopy(n1, name); /* These also free the ones */ - StrAllocCopy(t1, templ); /* from previous call. */ - - if (!(n2 = StrChr(n1, '/')) || !(t2 = StrChr(t1, '/'))) - return NO; - - *(n2++) = (char) 0; - *(t2++) = (char) 0; - - if ((0 == strcmp(t1, "*") || 0 == strcmp(t1, n1)) && - (0 == strcmp(t2, "*") || 0 == strcmp(t2, n2))) - return YES; - } - return NO; -} - -HTList *HTAtom_templateMatches(const char *templ) -{ - HTList *matches = HTList_new(); - - if (initialised && templ) { - int i; - HTAtom *cur; - - for (i = 0; i < HASH_SIZE; i++) { - for (cur = hash_table[i]; cur; cur = cur->next) { - if (mime_match(cur->name, templ)) - HTList_addObject(matches, (void *) cur); - } - } - } - return matches; -} diff --git a/WWW/Library/Implementation/HTAtom.h b/WWW/Library/Implementation/HTAtom.h index 4125d31b..0d787bce 100644 --- a/WWW/Library/Implementation/HTAtom.h +++ b/WWW/Library/Implementation/HTAtom.h @@ -34,7 +34,6 @@ extern "C" { }; /* struct _HTAtom */ extern HTAtom *HTAtom_for(const char *string); - extern HTList *HTAtom_templateMatches(const char *templ); #define HTAtom_name(a) ((a)->name) diff --git a/WWW/Library/Implementation/HTMLGen.c b/WWW/Library/Implementation/HTMLGen.c index e57de9db..2808a823 100644 --- a/WWW/Library/Implementation/HTMLGen.c +++ b/WWW/Library/Implementation/HTMLGen.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTMLGen.c,v 1.42 2018/03/04 20:04:55 tom Exp $ + * $LynxId: HTMLGen.c,v 1.44 2018/03/07 10:26:05 tom Exp $ * * HTML Generator * ============== @@ -338,12 +338,12 @@ static int HTMLGen_start_element(HTStructured * me, int element_number, } class_string[0] = '\0'; strtolower(myHash); - hcode = hash_code_1(myHash); + hcode = color_style_1(myHash); strtolower(Style_className); if (TRACE_STYLE) { fprintf(tfp, "CSSTRIM:%s -> %d", myHash, hcode); - if (hashStyles[hcode].code != hcode) { + if (!hashStyles[hcode].used) { char *rp = strrchr(myHash, '.'); fprintf(tfp, " (undefined) %s\n", myHash); @@ -351,9 +351,9 @@ static int HTMLGen_start_element(HTStructured * me, int element_number, int hcd; *rp = '\0'; /* trim the class */ - hcd = hash_code_1(myHash); + hcd = color_style_1(myHash); fprintf(tfp, "CSS:%s -> %d", myHash, hcd); - if (hashStyles[hcd].code != hcd) + if (!hashStyles[hcd].used) fprintf(tfp, " (undefined) %s\n", myHash); else fprintf(tfp, " ca=%d\n", hashStyles[hcd].color); @@ -409,7 +409,8 @@ static int HTMLGen_start_element(HTStructured * me, int element_number, (tfp, "CSSTRIM:link=%s\n", title_tmp)); do_cstyle_flush(me); - HText_characterStyle(me->text, hash_code_1(title_tmp), 1); + HText_characterStyle(me->text, + color_style_1(title_tmp), 1); } } #endif @@ -450,7 +451,7 @@ static int HTMLGen_start_element(HTStructured * me, int element_number, */ if (title && *title) { do_cstyle_flush(me); - HText_characterStyle(me->text, hash_code_1(title_tmp), 0); + HText_characterStyle(me->text, color_style_1(title_tmp), 0); FREE(title_tmp); } FREE(title); |