diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/HTML.c | 16 | ||||
-rw-r--r-- | src/LYCurses.c | 14 | ||||
-rw-r--r-- | src/LYHash.c | 63 | ||||
-rw-r--r-- | src/LYHash.h | 10 | ||||
-rw-r--r-- | src/LYMain.c | 7 | ||||
-rw-r--r-- | src/LYPrettySrc.c | 6 | ||||
-rw-r--r-- | src/LYStyle.c | 68 | ||||
-rw-r--r-- | src/LYUtils.c | 4 |
8 files changed, 107 insertions, 81 deletions
diff --git a/src/HTML.c b/src/HTML.c index 92431d01..8355dd83 100644 --- a/src/HTML.c +++ b/src/HTML.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTML.c,v 1.186 2018/03/05 00:03:30 tom Exp $ + * $LynxId: HTML.c,v 1.188 2018/03/07 10:26:46 tom Exp $ * * Structured stream to Rich hypertext converter * ============================================ @@ -993,13 +993,13 @@ static int HTML_start_element(HTStructured * me, int element_number, prefix_string = ""; if (current_tag_style == -1) { /* Append class_name */ - hcode = hash_code_1(HTML_dtd.tags[element_number].name); + hcode = color_style_1(HTML_dtd.tags[element_number].name); if (non_empty(class_name)) { int ohcode = hcode; prefix_string = HTML_dtd.tags[element_number].name; - hcode = hash_code_3(prefix_string, ".", class_name); - if (!hashStyles[hcode].name) { /* None such -> classless version */ + hcode = color_style_3(prefix_string, ".", class_name); + if (!hashStyles[hcode].used) { /* None such -> classless version */ hcode = ohcode; prefix_string = ""; CTRACE2(TRACE_STYLE, @@ -1024,7 +1024,7 @@ static int HTML_start_element(HTStructured * me, int element_number, class_string[0] = '\0'; } hcode = current_tag_style; - if (hcode >= 0 && hashStyles[hcode].name) { + if (hcode >= 0 && hashStyles[hcode].used) { prefix_string = hashStyles[hcode].name; } CTRACE2(TRACE_STYLE, @@ -1040,8 +1040,8 @@ static int HTML_start_element(HTStructured * me, int element_number, if (present && present[HTML_INPUT_TYPE] && value[HTML_INPUT_TYPE]) type = value[HTML_INPUT_TYPE]; - hcode = hash_code_3(prefix_string, ".type.", type); - if (!hashStyles[hcode].name) { /* None such -> classless version */ + hcode = color_style_3(prefix_string, ".type.", type); + if (!hashStyles[hcode].used) { /* None such -> classless version */ hcode = ohcode; CTRACE2(TRACE_STYLE, (tfp, "STYLE.start_element: type <%s> not configured.\n", @@ -1450,7 +1450,7 @@ static int HTML_start_element(HTStructured * me, int element_number, int hcode2; HTSprintf0(&tmp, "link.%s.%s", value[HTML_LINK_CLASS], title); - hcode2 = hash_code_1(tmp); + hcode2 = color_style_1(tmp); CTRACE2(TRACE_STYLE, (tfp, "STYLE.link: using style <%s>\n", tmp)); diff --git a/src/LYCurses.c b/src/LYCurses.c index 822b8da2..26dd1648 100644 --- a/src/LYCurses.c +++ b/src/LYCurses.c @@ -1,4 +1,4 @@ -/* $LynxId: LYCurses.c,v 1.188 2018/03/04 20:00:33 tom Exp $ */ +/* $LynxId: LYCurses.c,v 1.191 2018/03/07 10:02:01 tom Exp $ */ #include <HTUtils.h> #include <HTAlert.h> @@ -417,12 +417,10 @@ void setHashStyle(int style, (tfp, "CSS(SET): <%s> hash=%d, ca=%#x, ma=%#x\n", element, style, color, mono)); + ds->used = TRUE; ds->color = color; ds->cattr = cattr; ds->mono = mono; - ds->code = style; - FREE(ds->name); - StrAllocCopy(ds->name, element); } /* @@ -468,16 +466,16 @@ void curses_w_style(WINDOW * win, int style, break; } - if (!ds->name) { + if (!ds->used) { CTRACE2(TRACE_STYLE, (tfp, "CSS.CS:Style %d not configured\n", style)); if (free_ds) free(ds); return; } - CTRACE2(TRACE_STYLE, (tfp, "CSS.CS:<%s%s> style %d code %#x, color %#x\n", + CTRACE2(TRACE_STYLE, (tfp, "CSS.CS:<%s%s> style %d color %#x\n", (dir ? "" : "/"), - ds->name, style, ds->code, ds->color)); + ds->name, style, ds->color)); getyx(win, YP, XP); @@ -544,7 +542,7 @@ void wcurses_css(WINDOW * win, char *name, int try_again = 1; while (try_again) { - int tmpHash = hash_code_1(name); + int tmpHash = color_style_1(name); CTRACE2(TRACE_STYLE, (tfp, "CSSTRIM:trying to set [%s] style - ", name)); if (tmpHash == NOSTYLE) { diff --git a/src/LYHash.c b/src/LYHash.c index 1b8e2c0a..c1410fc7 100644 --- a/src/LYHash.c +++ b/src/LYHash.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYHash.c,v 1.26 2018/03/04 20:01:27 tom Exp $ + * $LynxId: LYHash.c,v 1.33 2018/03/07 10:20:10 tom Exp $ * * A hash table for the (fake) CSS support in Lynx-rp * (c) 1996 Rob Partington @@ -12,13 +12,9 @@ #ifdef USE_COLOR_STYLE -/* - * This is the same function as the private HASH_FUNCTION() in HTAnchor.c, but - * with a different value for HASH_SIZE. - */ - #define HASH_SIZE CSHASHSIZE -#define HASH_OF(h, v) ((int)((h) * 3 + UCH(v)) % HASH_SIZE) +#define HASH_TYPE int +#define HASH_OF(h, v) ((HASH_TYPE)((h) * 3 + UCH(v)) % HASH_SIZE) static size_t limit; static char *buffer; @@ -35,40 +31,67 @@ static char *get_buffer(size_t need) return buffer; } -static int hash_code(const char *string) +/* + * This is the same algorithm as the private anchor_hash() in HTAnchor.c, but + * with a different value for HASH_SIZE. + */ +static HASH_TYPE cs_hash(const char *string) { - int hash = 0; + HASH_TYPE hash = 0; + HASH_TYPE best, n; + bucket *data; + const char *p; + int bumped = 0; - if (string != 0) { - const char *p; + for (p = string; *p; p++) + hash = HASH_OF(hash, *p); - for (p = string; *p; p++) - hash = HASH_OF(hash, *p); + /* + * The computed hash-code is only a starting point. Check for collision. + */ + best = hash; + for (n = 0; n < HASH_SIZE; n++) { + int nn = (n + hash) % HASH_SIZE; - CTRACE_STYLE((tfp, "hash_code(%s) = %d\n", string, hash)); + data = &hashStyles[nn]; + if (data->name == 0 || !strcmp(string, data->name)) { + best = nn; + hash = nn; + break; + } + ++bumped; + } + data = &hashStyles[best]; + if (data->name != 0) { + if (strcmp(string, data->name)) { + CTRACE_STYLE((tfp, "cs_hash(%s) overwriting %d\n", string, data->name)); + FREE(data->name); + StrAllocCopy(data->name, string); + } } else { - FREE(buffer); - limit = 0; + StrAllocCopy(data->name, string); } + + CTRACE_STYLE((tfp, "cs_hash(%s) = %d\n", string, hash)); return hash; } -int hash_code_1(const char *string) +int color_style_1(const char *string) { get_buffer(strlen(string)); strcpy(buffer, string); LYLowerCase(buffer); - return hash_code(buffer); + return cs_hash(buffer); } -int hash_code_3(const char *p, const char *q, const char *r) +int color_style_3(const char *p, const char *q, const char *r) { get_buffer(strlen(p) + strlen(q) + strlen(r)); strcpy(buffer, p); strcat(buffer, q); strcat(buffer, r); LYLowerCase(buffer); - return hash_code(buffer); + return cs_hash(buffer); } #endif /* USE_COLOR_STYLE */ diff --git a/src/LYHash.h b/src/LYHash.h index d0c3088c..7d0a1666 100644 --- a/src/LYHash.h +++ b/src/LYHash.h @@ -1,4 +1,4 @@ -/* $LynxId: LYHash.h,v 1.34 2018/03/04 20:02:45 tom Exp $ */ +/* $LynxId: LYHash.h,v 1.38 2018/03/06 23:28:12 tom Exp $ */ #ifndef _LYHASH_H_ #define _LYHASH_H_ 1 @@ -11,23 +11,21 @@ extern "C" { #endif typedef struct { char *name; /* name of this item */ - int code; /* code of this item */ + BOOL used; /* color/attributes have been assigned */ int color; /* color highlighting to be done */ int mono; /* mono highlighting to be done */ int cattr; /* attributes to go with the color */ } bucket; -#ifndef CSHASHSIZE #define CSHASHSIZE 9973 /* Arbitrary prime. Memory/speed tradeoff */ -#endif #define NOSTYLE -1 extern bucket hashStyles[CSHASHSIZE]; extern bucket *nostyle_bucket(void); - extern int hash_code_1(const char *string); - extern int hash_code_3(const char *p, const char *q, const char *r); + extern int color_style_1(const char *string); + extern int color_style_3(const char *p, const char *q, const char *r); extern int s_a; extern int s_aedit; diff --git a/src/LYMain.c b/src/LYMain.c index 6fc4cd07..97fcf488 100644 --- a/src/LYMain.c +++ b/src/LYMain.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYMain.c,v 1.270 2018/03/05 22:32:14 tom Exp $ + * $LynxId: LYMain.c,v 1.272 2018/03/07 22:18:43 tom Exp $ */ #include <HTUtils.h> #include <HTTP.h> @@ -757,6 +757,9 @@ static void free_lynx_globals(void) { int i; +#if defined(USE_COLOR_STYLE) + clear_lss_list(); +#endif FREE(ftp_format); #ifndef VMS FREE(list_format); @@ -850,6 +853,8 @@ static void free_lynx_globals(void) FREE(LYTraceLogPath); FREE(lynx_cfg_file); FREE(SSL_cert_file); + FREE(SSL_client_cert_file); + FREE(SSL_client_key_file); #if defined(USE_COLOR_STYLE) FREE(lynx_lss_file2); FREE(lynx_lss_file); diff --git a/src/LYPrettySrc.c b/src/LYPrettySrc.c index ec3c136c..c2ff39e0 100644 --- a/src/LYPrettySrc.c +++ b/src/LYPrettySrc.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYPrettySrc.c,v 1.34 2018/03/04 19:48:49 tom Exp $ + * $LynxId: LYPrettySrc.c,v 1.36 2018/03/06 10:27:28 tom Exp $ * * HTML source syntax highlighting * by Vlad Harchev <hvv@hippo.ru> @@ -157,10 +157,10 @@ static void append_open_tag(const char *tagname, #ifdef USE_COLOR_STYLE if (non_empty(classname)) { - hcode = hash_code_3(tagname, ".", classname); + hcode = color_style_3(tagname, ".", classname); StrAllocCopy(subj->class_name, classname); } else { - hcode = hash_code_1(tagname); + hcode = color_style_1(tagname); StrAllocCopy(subj->class_name, ""); } subj->style = hcode; diff --git a/src/LYStyle.c b/src/LYStyle.c index a8fd0a46..10044f7b 100644 --- a/src/LYStyle.c +++ b/src/LYStyle.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYStyle.c,v 1.101 2018/03/04 19:54:30 tom Exp $ + * $LynxId: LYStyle.c,v 1.105 2018/03/08 21:05:53 tom Exp $ * * character level styles for Lynx * (c) 1996 Rob Partington -- donated to the Lyncei (if they want it :-) @@ -185,7 +185,7 @@ static void parse_attributes(const char *mono, int fA = default_fg; int bA = default_bg; int cA = A_NORMAL; - int newstyle = hash_code_1(element); + int newstyle = color_style_1(element); int colored_attr; CTRACE2(TRACE_STYLE, (tfp, "CSS(PA):style d=%d / h=%d, e=%s\n", @@ -359,8 +359,10 @@ where OBJECT is one of EM,STRONG,B,I,U,BLINK etc.\n\n"), buffer); } CTRACE2(TRACE_STYLE, (tfp, "CSSPARSE:%s => %d %s\n", - element, hash_code_1(element), - (hashStyles[hash_code_1(element)].name ? "used" : ""))); + element, color_style_1(element), + (hashStyles[color_style_1(element)].used) + ? "used" + : "")); /* * We use some pseudo-elements, so catch these first @@ -369,7 +371,7 @@ where OBJECT is one of EM,STRONG,B,I,U,BLINK etc.\n\n"), buffer); if (!strcasecomp(element, table[n].name)) { parse_attributes(mono, fg, bg, table[n].style, table[n].name); if (table[n].set_hash != 0) - *(table[n].set_hash) = hash_code_1(table[n].name); + *(table[n].set_hash) = color_style_1(table[n].name); found = TRUE; break; } @@ -379,7 +381,7 @@ where OBJECT is one of EM,STRONG,B,I,U,BLINK etc.\n\n"), buffer); if (!strcasecomp(element, "normal")) { /* added - kw */ parse_attributes(mono, fg, bg, DSTYLE_NORMAL, "html"); - s_normal = hash_code_1("html"); /* rather bizarre... - kw */ + s_normal = color_style_1("html"); /* rather bizarre... - kw */ LYnormalColor(); } @@ -412,11 +414,10 @@ static void free_lss_list(void) LSS_NAMES *obj; while ((obj = HTList_objectAt(list_of_lss_files, 0)) != 0) { - if (HTList_unlinkObject(list_of_lss_files, obj)) { - FREE(obj->given); - FREE(obj->actual); - FREE(obj); - } else { + FREE(obj->given); + FREE(obj->actual); + FREE(obj); + if (!HTList_removeObject(list_of_lss_files, obj)) { break; } } @@ -425,7 +426,12 @@ static void free_lss_list(void) static void free_colorstylestuff(void) { + int i; + style_initialiseHashTable(); + for (i = 0; i < CSHASHSIZE; i++) { + FREE(hashStyles[i].name); + } style_deleteStyleList(); memset(our_pairs, 0, sizeof(our_pairs)); FreeCachedStyles(); @@ -435,34 +441,28 @@ static void free_colorstylestuff(void) static void style_initialiseHashTable(void) { int i; - static int firsttime = 1; + static BOOL firsttime = TRUE; for (i = 0; i < CSHASHSIZE; i++) { - if (firsttime) - hashStyles[i].name = NULL; - else - FREE(hashStyles[i].name); - hashStyles[i].color = 0; - hashStyles[i].cattr = 0; - hashStyles[i].mono = 0; + hashStyles[i].used = FALSE; } if (firsttime) { - firsttime = 0; + firsttime = FALSE; #ifdef LY_FIND_LEAKS atexit(free_colorstylestuff); atexit(free_colorstyle_leaks); #endif } - s_alink = hash_code_1("alink"); - s_a = hash_code_1("a"); - s_status = hash_code_1("status"); - s_alert = hash_code_1("alert"); - s_title = hash_code_1("title"); + s_alink = color_style_1("alink"); + s_a = color_style_1("a"); + s_status = color_style_1("status"); + s_alert = color_style_1("alert"); + s_title = color_style_1("title"); #ifdef USE_SCROLLBAR - s_sb_bar = hash_code_1("scroll.bar"); - s_sb_bg = hash_code_1("scroll.back"); - s_sb_aa = hash_code_1("scroll.arrow"); - s_sb_naa = hash_code_1("scroll.noarrow"); + s_sb_bar = color_style_1("scroll.bar"); + s_sb_bg = color_style_1("scroll.back"); + s_sb_aa = color_style_1("scroll.arrow"); + s_sb_naa = color_style_1("scroll.noarrow"); #endif } @@ -707,7 +707,7 @@ void TrimColorClass(const char *tagname, if (end) *end = '\0'; } - *phcode = hash_code_1(lookfrom && *lookfrom ? lookfrom : &tmp[1]); + *phcode = color_style_1(lookfrom && *lookfrom ? lookfrom : &tmp[1]); } /* This function is designed as faster analog to TrimColorClass. @@ -738,7 +738,7 @@ void FastTrimColorClass(const char *tag_name, *pstylename_end = tag_start; } CTRACE2(TRACE_STYLE, (tfp, found ? "success.\n" : "failed.\n")); - *phcode = hash_code_1(tag_start + 1); + *phcode = color_style_1(tag_start + 1); } /* This is called each time lss styles are read. It will fill @@ -749,7 +749,7 @@ void cache_tag_styles(void) int i; for (i = 0; i < HTML_ELEMENTS; ++i) { - cached_tag_styles[i] = hash_code_1(HTML_dtd.tags[i].name); + cached_tag_styles[i] = color_style_1(HTML_dtd.tags[i].name); } } @@ -916,8 +916,10 @@ void init_color_styles(char **from_cmdline, const char *default_styles) char *target; target = find_lss_file(LYPathLeaf(cp)); - if (target != 0) + if (target != 0) { add_to_lss_list(cp, target); + FREE(target); + } } FREE(source); } diff --git a/src/LYUtils.c b/src/LYUtils.c index 7a12ae66..767ab9b4 100644 --- a/src/LYUtils.c +++ b/src/LYUtils.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYUtils.c,v 1.280 2018/03/01 22:14:57 Takeshi.Hataguchi Exp $ + * $LynxId: LYUtils.c,v 1.281 2018/03/07 10:02:51 tom Exp $ */ #include <HTUtils.h> #include <HTTCP.h> @@ -1559,7 +1559,7 @@ void statusline(const char *text) { int y, x; int a = ((StrNCmp(buffer, ALERT_FORMAT, ALERT_PREFIX_LEN) - || !hashStyles[s_alert].name) + || !hashStyles[s_alert].used) ? s_status : s_alert); |