about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--WWW/Library/Implementation/HTMLGen.c10
-rw-r--r--src/HTML.c44
-rw-r--r--src/LYCurses.c8
-rw-r--r--src/LYHash.c24
-rw-r--r--src/LYHash.h11
-rw-r--r--src/LYPrettySrc.c14
-rw-r--r--src/LYStyle.c39
7 files changed, 71 insertions, 79 deletions
diff --git a/WWW/Library/Implementation/HTMLGen.c b/WWW/Library/Implementation/HTMLGen.c
index 361ad69d..e57de9db 100644
--- a/WWW/Library/Implementation/HTMLGen.c
+++ b/WWW/Library/Implementation/HTMLGen.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTMLGen.c,v 1.41 2016/11/24 15:29:50 tom Exp $
+ * $LynxId: HTMLGen.c,v 1.42 2018/03/04 20:04:55 tom Exp $
  *
  *		HTML Generator
  *		==============
@@ -338,7 +338,7 @@ static int HTMLGen_start_element(HTStructured * me, int element_number,
 	}
 	class_string[0] = '\0';
 	strtolower(myHash);
-	hcode = hash_code(myHash);
+	hcode = hash_code_1(myHash);
 	strtolower(Style_className);
 
 	if (TRACE_STYLE) {
@@ -351,7 +351,7 @@ static int HTMLGen_start_element(HTStructured * me, int element_number,
 		    int hcd;
 
 		    *rp = '\0';	/* trim the class */
-		    hcd = hash_code(myHash);
+		    hcd = hash_code_1(myHash);
 		    fprintf(tfp, "CSS:%s -> %d", myHash, hcd);
 		    if (hashStyles[hcd].code != hcd)
 			fprintf(tfp, " (undefined) %s\n", myHash);
@@ -409,7 +409,7 @@ 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(title_tmp), 1);
+			HText_characterStyle(me->text, hash_code_1(title_tmp), 1);
 		    }
 		}
 #endif
@@ -450,7 +450,7 @@ static int HTMLGen_start_element(HTStructured * me, int element_number,
 	     */
 	    if (title && *title) {
 		do_cstyle_flush(me);
-		HText_characterStyle(me->text, hash_code(title_tmp), 0);
+		HText_characterStyle(me->text, hash_code_1(title_tmp), 0);
 		FREE(title_tmp);
 	    }
 	    FREE(title);
diff --git a/src/HTML.c b/src/HTML.c
index fa13f4a8..92431d01 100644
--- a/src/HTML.c
+++ b/src/HTML.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: HTML.c,v 1.180 2018/03/03 15:23:54 tom Exp $
+ * $LynxId: HTML.c,v 1.186 2018/03/05 00:03:30 tom Exp $
  *
  *		Structured stream to Rich hypertext converter
  *		============================================
@@ -946,8 +946,9 @@ static int HTML_start_element(HTStructured * me, int element_number,
     int status = HT_OK;
 
 #ifdef USE_COLOR_STYLE
-    char *class_name;
-    int class_used = 0;
+    const char *class_name;
+    const char *prefix_string;
+    BOOL class_used = FALSE;
 #endif
 
     if (LYMapsOnly) {
@@ -981,7 +982,7 @@ static int HTML_start_element(HTStructured * me, int element_number,
     force_classname = FALSE;
 
     if (force_current_tag_style == FALSE) {
-	current_tag_style = (class_name[0]
+	current_tag_style = (non_empty(class_name)
 			     ? -1
 			     : cached_tag_styles[element_number]);
     } else {
@@ -990,16 +991,17 @@ static int HTML_start_element(HTStructured * me, int element_number,
 
     CTRACE2(TRACE_STYLE, (tfp, "CSS.elt:<%s>\n", HTML_dtd.tags[element_number].name));
 
+    prefix_string = "";
     if (current_tag_style == -1) {	/* Append class_name */
-	hcode = hash_code_caseless(HTML_dtd.tags[element_number].name);
-	if (class_name[0]) {
+	hcode = hash_code_1(HTML_dtd.tags[element_number].name);
+	if (non_empty(class_name)) {
 	    int ohcode = hcode;
 
-	    hcode = hash_code_aggregate(HTML_dtd.tags[element_number].name,
-					".",
-					class_name);
+	    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 = ohcode;
+		prefix_string = "";
 		CTRACE2(TRACE_STYLE,
 			(tfp,
 			 "STYLE.start_element: <%s> (class <%s> not configured), hcode=%d.\n",
@@ -1009,19 +1011,22 @@ static int HTML_start_element(HTStructured * me, int element_number,
 
 		CTRACE2(TRACE_STYLE,
 			(tfp, "STYLE.start_element: <%s>.<%s>, hcode=%d.\n",
-			 HTML_dtd.tags[element_number].name, class_name, hcode));
-		class_used = 1;
+			 prefix_string, class_name, hcode));
+		class_used = TRUE;
 	    }
 	}
 
 	class_string[0] = '\0';
 
     } else {			/* (current_tag_style!=-1)  */
-	if (class_name[0]) {
+	if (non_empty(class_name)) {
 	    addClassName(".", class_name, strlen(class_name));
 	    class_string[0] = '\0';
 	}
 	hcode = current_tag_style;
+	if (hcode >= 0 && hashStyles[hcode].name) {
+	    prefix_string = hashStyles[hcode].name;
+	}
 	CTRACE2(TRACE_STYLE,
 		(tfp, "STYLE.start_element: <%s>, hcode=%d.\n",
 		 HTML_dtd.tags[element_number].name, hcode));
@@ -1035,8 +1040,7 @@ 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_aggregate_lower_str(".type.", hcode);
-	hcode = hash_code_aggregate_lower_str(type, hcode);
+	hcode = hash_code_3(prefix_string, ".type.", type);
 	if (!hashStyles[hcode].name) {	/* None such -> classless version */
 	    hcode = ohcode;
 	    CTRACE2(TRACE_STYLE,
@@ -1443,17 +1447,19 @@ static int HTML_start_element(HTStructured * me, int element_number,
 	    if (present && present[HTML_LINK_CLASS] &&
 		non_empty(value[HTML_LINK_CLASS])) {
 		char *tmp = 0;
+		int hcode2;
 
 		HTSprintf0(&tmp, "link.%s.%s", value[HTML_LINK_CLASS], title);
+		hcode2 = hash_code_1(tmp);
 		CTRACE2(TRACE_STYLE,
 			(tfp, "STYLE.link: using style <%s>\n", tmp));
 
-		HText_characterStyle(me->text, hash_code(tmp), STACK_ON);
+		HText_characterStyle(me->text, hcode2, STACK_ON);
 		HTML_put_string(me, title);
 		HTML_put_string(me, " (");
 		HTML_put_string(me, value[HTML_LINK_CLASS]);
 		HTML_put_string(me, ")");
-		HText_characterStyle(me->text, hash_code(tmp), STACK_OFF);
+		HText_characterStyle(me->text, hcode2, STACK_OFF);
 		FREE(tmp);
 	    } else
 #endif
@@ -7486,7 +7492,11 @@ HTStructured *HTML_new(HTParentAnchor *anchor,
 
     HTStructured *me;
 
-    CTRACE((tfp, "start HTML_new\n"));
+    CTRACE((tfp, "start HTML_new(parent %s, format %s)\n",
+	    ((anchor)
+	     ? NONNULL(anchor->address)
+	     : "<NULL>"),
+	    HTAtom_name(format_out)));
 
     if (format_out != WWW_PLAINTEXT && format_out != WWW_PRESENT) {
 	HTStream *intermediate = HTStreamStack(WWW_HTML, format_out,
diff --git a/src/LYCurses.c b/src/LYCurses.c
index 46d02fac..822b8da2 100644
--- a/src/LYCurses.c
+++ b/src/LYCurses.c
@@ -1,4 +1,4 @@
-/* $LynxId: LYCurses.c,v 1.187 2018/03/03 15:20:19 tom Exp $ */
+/* $LynxId: LYCurses.c,v 1.188 2018/03/04 20:00:33 tom Exp $ */
 #include <HTUtils.h>
 #include <HTAlert.h>
 
@@ -544,7 +544,7 @@ void wcurses_css(WINDOW * win, char *name,
     int try_again = 1;
 
     while (try_again) {
-	int tmpHash = hash_code(name);
+	int tmpHash = hash_code_1(name);
 
 	CTRACE2(TRACE_STYLE, (tfp, "CSSTRIM:trying to set [%s] style - ", name));
 	if (tmpHash == NOSTYLE) {
@@ -556,8 +556,8 @@ void wcurses_css(WINDOW * win, char *name,
 	    else
 		try_again = 0;
 	} else {
-	    CTRACE2(TRACE_STYLE, (tfp, "ok (%d)\n", hash_code(name)));
-	    curses_w_style(win, hash_code(name), dir);
+	    CTRACE2(TRACE_STYLE, (tfp, "ok (%d)\n", tmpHash));
+	    curses_w_style(win, tmpHash, dir);
 	    try_again = 0;
 	}
     }
diff --git a/src/LYHash.c b/src/LYHash.c
index a76f8034..1b8e2c0a 100644
--- a/src/LYHash.c
+++ b/src/LYHash.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYHash.c,v 1.23 2018/03/03 01:51:03 tom Exp $
+ * $LynxId: LYHash.c,v 1.26 2018/03/04 20:01:27 tom Exp $
  *
  * A hash table for the (fake) CSS support in Lynx-rp
  * (c) 1996 Rob Partington
@@ -35,7 +35,7 @@ static char *get_buffer(size_t need)
     return buffer;
 }
 
-int hash_code(const char *string)
+static int hash_code(const char *string)
 {
     int hash = 0;
 
@@ -53,13 +53,15 @@ int hash_code(const char *string)
     return hash;
 }
 
-int hash_code_caseless(const char *string)
+int hash_code_1(const char *string)
 {
-    LYLowerCase(strcpy(get_buffer(strlen(string)), string));
+    get_buffer(strlen(string));
+    strcpy(buffer, string);
+    LYLowerCase(buffer);
     return hash_code(buffer);
 }
 
-int hash_code_aggregate(const char *p, const char *q, const char *r)
+int hash_code_3(const char *p, const char *q, const char *r)
 {
     get_buffer(strlen(p) + strlen(q) + strlen(r));
     strcpy(buffer, p);
@@ -69,16 +71,4 @@ int hash_code_aggregate(const char *p, const char *q, const char *r)
     return hash_code(buffer);
 }
 
-int hash_code_aggregate_lower_str(const char *string, int hash_was)
-{
-    int hash;
-    const char *p;
-
-    for (p = string, hash = hash_was; *p; p++)
-	hash = HASH_OF(hash, TOLOWER(*p));
-
-    CTRACE_STYLE((tfp, "hash_code_lc2(%s) = %d\n", string, hash));
-    return hash;
-}
-
 #endif /* USE_COLOR_STYLE */
diff --git a/src/LYHash.h b/src/LYHash.h
index 93e6c050..d0c3088c 100644
--- a/src/LYHash.h
+++ b/src/LYHash.h
@@ -1,4 +1,4 @@
-/* $LynxId: LYHash.h,v 1.31 2018/03/03 15:20:39 tom Exp $ */
+/* $LynxId: LYHash.h,v 1.34 2018/03/04 20:02:45 tom Exp $ */
 #ifndef _LYHASH_H_
 #define _LYHASH_H_ 1
 
@@ -23,16 +23,11 @@ extern "C" {
 
 #define NOSTYLE -1
 
-    /* hashStyles[] is used in CTRACE when NOSTYLE is passed as 'style' to
-     * curses_w_style
-     */
     extern bucket hashStyles[CSHASHSIZE];
-    extern int hash_code(const char *string);
     extern bucket *nostyle_bucket(void);
 
-    extern int hash_code_caseless(const char *string);
-    extern int hash_code_aggregate(const char *p, const char *q, const char *r);
-    extern int hash_code_aggregate_lower_str(const char *c, int hash_was);
+    extern int hash_code_1(const char *string);
+    extern int hash_code_3(const char *p, const char *q, const char *r);
 
     extern int s_a;
     extern int s_aedit;
diff --git a/src/LYPrettySrc.c b/src/LYPrettySrc.c
index 8289aa38..ec3c136c 100644
--- a/src/LYPrettySrc.c
+++ b/src/LYPrettySrc.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYPrettySrc.c,v 1.32 2018/03/03 01:42:11 tom Exp $
+ * $LynxId: LYPrettySrc.c,v 1.34 2018/03/04 19:48:49 tom Exp $
  *
  * HTML source syntax highlighting
  * by Vlad Harchev <hvv@hippo.ru>
@@ -76,7 +76,7 @@ HT_tagspec *lexeme_end[HTL_num_lexemes];
 int tagname_transform = 2;
 int attrname_transform = 2;
 
-static int html_src_tag_index(char *tagname)
+static int html_src_tag_index(const char *tagname)
 {
     HTTag *tag = SGMLFindTag(&HTML_dtd, tagname);
 
@@ -90,7 +90,7 @@ typedef enum {
     HTSRC_CK_seen_dot
 } html_src_check_state;
 
-static void append_close_tag(char *tagname,
+static void append_close_tag(const char *tagname,
 			     HT_tagspec ** head,
 			     HT_tagspec ** tail)
 {
@@ -140,8 +140,8 @@ static void append_close_tag(char *tagname,
 
 /* this will allocate node, initialize all members, and node
    append to the list, possibly modifying head and modifying tail */
-static void append_open_tag(char *tagname,
-			    char *classname GCC_UNUSED,
+static void append_open_tag(const char *tagname,
+			    const char *classname GCC_UNUSED,
 			    HT_tagspec ** head,
 			    HT_tagspec ** tail)
 {
@@ -157,10 +157,10 @@ static void append_open_tag(char *tagname,
 
 #ifdef USE_COLOR_STYLE
     if (non_empty(classname)) {
-	hcode = hash_code_aggregate(tagname, ".", classname);
+	hcode = hash_code_3(tagname, ".", classname);
 	StrAllocCopy(subj->class_name, classname);
     } else {
-	hcode = hash_code_caseless(tagname);
+	hcode = hash_code_1(tagname);
 	StrAllocCopy(subj->class_name, "");
     }
     subj->style = hcode;
diff --git a/src/LYStyle.c b/src/LYStyle.c
index 6de99af9..a8fd0a46 100644
--- a/src/LYStyle.c
+++ b/src/LYStyle.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: LYStyle.c,v 1.99 2018/03/03 15:20:46 tom Exp $
+ * $LynxId: LYStyle.c,v 1.101 2018/03/04 19:54:30 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(element);
+    int newstyle = hash_code_1(element);
     int colored_attr;
 
     CTRACE2(TRACE_STYLE, (tfp, "CSS(PA):style d=%d / h=%d, e=%s\n",
@@ -359,8 +359,8 @@ 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(element),
-			  (hashStyles[hash_code(element)].name ? "used" : "")));
+			  element, hash_code_1(element),
+			  (hashStyles[hash_code_1(element)].name ? "used" : "")));
 
     /*
      * We use some pseudo-elements, so catch these first
@@ -369,7 +369,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(table[n].name);
+		*(table[n].set_hash) = hash_code_1(table[n].name);
 	    found = TRUE;
 	    break;
 	}
@@ -379,7 +379,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("html");	/* rather bizarre... - kw */
+	    s_normal = hash_code_1("html");	/* rather bizarre... - kw */
 
 	    LYnormalColor();
 	}
@@ -453,16 +453,16 @@ static void style_initialiseHashTable(void)
 	atexit(free_colorstyle_leaks);
 #endif
     }
-    s_alink = hash_code("alink");
-    s_a = hash_code("a");
-    s_status = hash_code("status");
-    s_alert = hash_code("alert");
-    s_title = hash_code("title");
+    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");
 #ifdef USE_SCROLLBAR
-    s_sb_bar = hash_code("scroll.bar");
-    s_sb_bg = hash_code("scroll.back");
-    s_sb_aa = hash_code("scroll.arrow");
-    s_sb_naa = hash_code("scroll.noarrow");
+    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");
 #endif
 }
 
@@ -707,7 +707,7 @@ void TrimColorClass(const char *tagname,
 	if (end)
 	    *end = '\0';
     }
-    *phcode = hash_code(lookfrom && *lookfrom ? lookfrom : &tmp[1]);
+    *phcode = hash_code_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(tag_start + 1);
+    *phcode = hash_code_1(tag_start + 1);
 }
 
 /* This is called each time lss styles are read. It will fill
@@ -746,13 +746,10 @@ void FastTrimColorClass(const char *tag_name,
  */
 void cache_tag_styles(void)
 {
-    char buf[200];
     int i;
 
     for (i = 0; i < HTML_ELEMENTS; ++i) {
-	LYStrNCpy(buf, HTML_dtd.tags[i].name, sizeof(buf) - 1);
-	LYLowerCase(buf);
-	cached_tag_styles[i] = hash_code(buf);
+	cached_tag_styles[i] = hash_code_1(HTML_dtd.tags[i].name);
     }
 }