diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/HTML.c | 198 | ||||
-rw-r--r-- | src/LYCurses.c | 24 | ||||
-rw-r--r-- | src/LYHash.c | 56 | ||||
-rw-r--r-- | src/LYHash.h | 23 | ||||
-rw-r--r-- | src/LYPrettySrc.c | 23 | ||||
-rw-r--r-- | src/LYStyle.c | 24 |
6 files changed, 58 insertions, 290 deletions
diff --git a/src/HTML.c b/src/HTML.c index 63d67206..fa13f4a8 100644 --- a/src/HTML.c +++ b/src/HTML.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTML.c,v 1.174 2017/07/05 22:48:09 tom Exp $ + * $LynxId: HTML.c,v 1.180 2018/03/03 15:23:54 tom Exp $ * * Structured stream to Rich hypertext converter * ============================================ @@ -65,13 +65,6 @@ #include <LYStyle.h> #undef SELECTED_STYLES #define pHText_changeStyle(X,Y,Z) {} - -#if OMIT_SCN_KEEPING -# define HCODE_TO_STACK_OFF(x) /*(CSHASHSIZE+1)*/ 88888 /*special value. */ -#else -# define HCODE_TO_STACK_OFF(x) x /*pass computed value */ -#endif - #endif /* USE_COLOR_STYLE */ #ifdef USE_SOURCE_CACHE @@ -788,49 +781,6 @@ static void addClassName(const char *prefix, #define addClassName(prefix, actual, length) /* nothing */ #endif -#ifdef USE_PRETTYSRC - -static void HTMLSRC_apply_markup(HTStructured * context, HTlexeme lexeme, int start, - int tag_charset) -{ - HT_tagspec *ts = *((start ? lexeme_start : lexeme_end) + lexeme); - - while (ts) { -#ifdef USE_COLOR_STYLE - if (ts->start) { - current_tag_style = ts->style; - force_current_tag_style = TRUE; - forced_classname = ts->class_name; - force_classname = TRUE; - } -#endif - CTRACE((tfp, ts->start ? "SRCSTART %d\n" : "SRCSTOP %d\n", (int) lexeme)); - if (ts->start) - HTML_start_element(context, - (int) ts->element, - ts->present, - (STRING2PTR) ts->value, - tag_charset, - NULL); - else - HTML_end_element(context, - (int) ts->element, - NULL); - ts = ts->next; - } -} - -# define START TRUE -# define STOP FALSE - -# define PSRCSTART(x) HTMLSRC_apply_markup(me,HTL_##x,START,tag_charset) -# define PSRCSTOP(x) HTMLSRC_apply_markup(me,HTL_##x,STOP,tag_charset) - -# define PUTC(x) HTML_put_character(me,x) -# define PUTS(x) HTML_put_string(me,x) - -#endif /* USE_PRETTYSRC */ - static void LYStartArea(HTStructured * obj, const char *href, const char *alt, const char *title, @@ -1000,105 +950,6 @@ static int HTML_start_element(HTStructured * me, int element_number, int class_used = 0; #endif -#ifdef USE_PRETTYSRC - if (psrc_view && !sgml_in_psrc_was_initialized) { - if (!psrc_nested_call) { - HTTag *tag = &HTML_dtd.tags[element_number]; - char buf[200]; - const char *p; - - if (psrc_first_tag) { - psrc_first_tag = FALSE; - /* perform the special actions on the begining of the document. - It's assumed that all lynx modules start generating html - from tag (ie not a text) so we are able to trap this moment - and initialize. - */ - psrc_nested_call = TRUE; - HTML_start_element(me, HTML_BODY, NULL, NULL, tag_charset, NULL); - HTML_start_element(me, HTML_PRE, NULL, NULL, tag_charset, NULL); - PSRCSTART(entire); - psrc_nested_call = FALSE; - } - - psrc_nested_call = TRUE; - /*write markup for tags and exit */ - PSRCSTART(abracket); - PUTC('<'); - PSRCSTOP(abracket); - PSRCSTART(tag); - if (tagname_transform != 0) - PUTS(tag->name); - else { - LYStrNCpy(buf, tag->name, sizeof(buf) - 1); - LYLowerCase(buf); - PUTS(buf); - } - if (present) { - for (i = 0; i < tag->number_of_attributes; i++) - if (present[i]) { - PUTC(' '); - PSRCSTART(attrib); - if (attrname_transform != 0) - PUTS(tag->attributes[i].name); - else { - LYStrNCpy(buf, - tag->attributes[i].name, - sizeof(buf) - 1); - LYLowerCase(buf); - PUTS(buf); - } - if (value[i]) { - char q = '"'; - - /*0 in dquotes, 1 - in quotes, 2 mixed */ - char kind = (char) (!StrChr(value[i], '"') ? - 0 : - !StrChr(value[i], '\'') ? - q = '\'', 1 : - 2); - - PUTC('='); - PSRCSTOP(attrib); - PSRCSTART(attrval); - PUTC(q); - /*is it special ? */ - if (tag->attributes[i].type == HTMLA_ANAME) { - HTStartAnchor(me, value[i], NULL); - HTML_end_element(me, HTML_A, NULL); - } else if (tag->attributes[i].type == HTMLA_HREF) { - PSRCSTART(href); - HTStartAnchor(me, NULL, value[i]); - } - if (kind != 2) - PUTS(value[i]); - else - for (p = value[i]; *p; p++) - if (*p != '"') - PUTC(*p); - else - PUTS("""); - /*is it special ? */ - if (tag->attributes[i].type == HTMLA_HREF) { - HTML_end_element(me, HTML_A, NULL); - PSRCSTOP(href); - } - PUTC(q); - PSRCSTOP(attrval); - } /* if value */ - } /* if present[i] */ - } /* if present */ - PSRCSTOP(tag); - PSRCSTART(abracket); - PUTC('>'); - PSRCSTOP(abracket); - psrc_nested_call = FALSE; - return HT_OK; - } /*if (!psrc_nested_call) */ - /*fall through */ - } -#endif /* USE_PRETTYSRC */ - if (LYMapsOnly) { if (!(ElementNumber == HTML_MAP || ElementNumber == HTML_AREA || ElementNumber == HTML_BASE || ElementNumber == HTML_OBJECT || @@ -1140,12 +991,13 @@ static int HTML_start_element(HTStructured * me, int element_number, CTRACE2(TRACE_STYLE, (tfp, "CSS.elt:<%s>\n", HTML_dtd.tags[element_number].name)); if (current_tag_style == -1) { /* Append class_name */ - hcode = hash_code_lowercase_on_fly(HTML_dtd.tags[element_number].name); + hcode = hash_code_caseless(HTML_dtd.tags[element_number].name); if (class_name[0]) { int ohcode = hcode; - hcode = hash_code_aggregate_char('.', hcode); - hcode = hash_code_aggregate_lower_str(class_name, hcode); + hcode = hash_code_aggregate(HTML_dtd.tags[element_number].name, + ".", + class_name); if (!hashStyles[hcode].name) { /* None such -> classless version */ hcode = ohcode; CTRACE2(TRACE_STYLE, @@ -1176,7 +1028,6 @@ static int HTML_start_element(HTStructured * me, int element_number, current_tag_style = -1; } -#if !OMIT_SCN_KEEPING /* Can be done in other cases too... */ if (!class_used && ElementNumber == HTML_INPUT) { /* For some other too? */ const char *type = ""; int ohcode = hcode; @@ -1199,7 +1050,6 @@ static int HTML_start_element(HTStructured * me, int element_number, HTML_dtd.tags[element_number].name, type, hcode)); } } -#endif /* !OMIT_SCN_KEEPING */ HText_characterStyle(me->text, hcode, STACK_ON); #endif /* USE_COLOR_STYLE */ @@ -5633,14 +5483,12 @@ static int HTML_start_element(HTStructured * me, int element_number, if (ReallyEmptyTagNum(element_number)) { CTRACE2(TRACE_STYLE, (tfp, "STYLE.begin_element:ending \"EMPTY\" element style\n")); - HText_characterStyle(me->text, HCODE_TO_STACK_OFF(hcode), STACK_OFF); + HText_characterStyle(me->text, hcode, STACK_OFF); -# if !OMIT_SCN_KEEPING FastTrimColorClass(HTML_dtd.tags[element_number].name, HTML_dtd.tags[element_number].name_len, Style_className, &Style_className_end, &hcode); -# endif } #endif /* USE_COLOR_STYLE */ return status; @@ -5672,36 +5520,6 @@ static int HTML_end_element(HTStructured * me, int element_number, #endif EMIT_IFDEF_USE_JUSTIFY_ELTS(BOOL reached_awaited_stacked_elt = FALSE); -#ifdef USE_PRETTYSRC - if (psrc_view && !sgml_in_psrc_was_initialized) { - if (!psrc_nested_call) { - HTTag *tag = &HTML_dtd.tags[element_number]; - char buf[200]; - int tag_charset = 0; - - psrc_nested_call = TRUE; - PSRCSTART(abracket); - PUTS("</"); - PSRCSTOP(abracket); - PSRCSTART(tag); - if (tagname_transform != 0) - PUTS(tag->name); - else { - LYStrNCpy(buf, tag->name, sizeof(buf) - 1); - LYLowerCase(buf); - PUTS(buf); - } - PSRCSTOP(tag); - PSRCSTART(abracket); - PUTC('>'); - PSRCSTOP(abracket); - psrc_nested_call = FALSE; - return HT_OK; - } - /*fall through */ - } -#endif - if ((me->sp >= (me->stack + MAX_NESTING - 1) || element_number != me->sp[0].tag_number) && HTML_dtd.tags[element_number].contents != SGML_EMPTY) { @@ -7244,19 +7062,17 @@ static int HTML_end_element(HTStructured * me, int element_number, } #ifdef USE_COLOR_STYLE if (!skip_stack_requested) { /*don't emit stylechanges if skipped stack element - VH */ -# if !OMIT_SCN_KEEPING FastTrimColorClass(HTML_dtd.tags[element_number].name, HTML_dtd.tags[element_number].name_len, Style_className, &Style_className_end, &hcode); -# endif if (!ReallyEmptyTagNum(element_number)) { CTRACE2(TRACE_STYLE, (tfp, "STYLE.end_element: ending non-\"EMPTY\" style <%s...>\n", HTML_dtd.tags[element_number].name)); - HText_characterStyle(me->text, HCODE_TO_STACK_OFF(hcode), STACK_OFF); + HText_characterStyle(me->text, hcode, STACK_OFF); } } #endif /* USE_COLOR_STYLE */ diff --git a/src/LYCurses.c b/src/LYCurses.c index f28999f7..46d02fac 100644 --- a/src/LYCurses.c +++ b/src/LYCurses.c @@ -1,4 +1,4 @@ -/* $LynxId: LYCurses.c,v 1.186 2018/03/02 00:39:46 tom Exp $ */ +/* $LynxId: LYCurses.c,v 1.187 2018/03/03 15:20:19 tom Exp $ */ #include <HTUtils.h> #include <HTAlert.h> @@ -454,22 +454,11 @@ static void LYAttrset(WINDOW * win, int color, void curses_w_style(WINDOW * win, int style, int dir) { -#if OMIT_SCN_KEEPING -# define SPECIAL_STYLE /*(CSHASHSIZE+1) */ 88888 -/* if TRACEs are not compiled in, this macro is redundant - we needn't valid -'ds' to stack off. */ -#endif - int YP, XP; bucket *ds; BOOL free_ds = TRUE; switch (style) { -#if OMIT_SCN_KEEPING - case SPECIAL_STYLE: - ds = special_bucket(); - break; -#endif case NOSTYLE: ds = nostyle_bucket(); break; @@ -481,11 +470,9 @@ void curses_w_style(WINDOW * win, int style, if (!ds->name) { CTRACE2(TRACE_STYLE, (tfp, "CSS.CS:Style %d not configured\n", style)); -#if !OMIT_SCN_KEEPING if (free_ds) free(ds); return; -#endif } CTRACE2(TRACE_STYLE, (tfp, "CSS.CS:<%s%s> style %d code %#x, color %#x\n", @@ -524,15 +511,6 @@ void curses_w_style(WINDOW * win, int style, } last_styles[last_colorattr_ptr++] = (int) LYgetattrs(win); /* don't cache style changes for active links */ -#if OMIT_SCN_KEEPING - /* since we don't compute the hcode to stack off in HTML.c, we - * don't know whether this style is configured. So, we - * shouldn't simply return on stacking on unconfigured - * styles, we should push curr attrs on stack. -HV - */ - if (!ds->name) - break; -#endif /* FALL THROUGH */ case ABS_ON: /* change without remembering the previous style */ /* don't cache style changes for active links and edits */ diff --git a/src/LYHash.c b/src/LYHash.c index bdd029fa..a76f8034 100644 --- a/src/LYHash.c +++ b/src/LYHash.c @@ -1,12 +1,14 @@ /* - * $LynxId: LYHash.c,v 1.19 2013/06/12 09:21:21 tom Exp $ + * $LynxId: LYHash.c,v 1.23 2018/03/03 01:51:03 tom Exp $ * * A hash table for the (fake) CSS support in Lynx-rp * (c) 1996 Rob Partington * rewritten 1997 by Klaus Weide. + * rewritten 2018 -TD */ #include <LYHash.h> #include <LYUtils.h> +#include <LYStrings.h> #ifdef USE_COLOR_STYLE @@ -18,33 +20,53 @@ #define HASH_SIZE CSHASHSIZE #define HASH_OF(h, v) ((int)((h) * 3 + UCH(v)) % HASH_SIZE) -int hash_code(const char *string) -{ - int hash; - const char *p; +static size_t limit; +static char *buffer; - for (p = string, hash = 0; *p; p++) - hash = HASH_OF(hash, *p); +static char *get_buffer(size_t need) +{ + if (++need > limit) { + char *test = realloc(buffer, (limit = (1 + need) * 2)); - CTRACE_STYLE((tfp, "hash_code(%s) = %d\n", string, hash)); - return hash; + if (test == 0) + outofmem(__FILE__, "LYHash"); + buffer = test; + } + return buffer; } -int hash_code_lowercase_on_fly(const char *string) +int hash_code(const char *string) { - int hash; - const char *p; + int hash = 0; - for (p = string, hash = 0; *p; p++) - hash = HASH_OF(hash, TOLOWER(*p)); + if (string != 0) { + const char *p; + + for (p = string; *p; p++) + hash = HASH_OF(hash, *p); - CTRACE_STYLE((tfp, "hash_code_lc(%s) = %d\n", string, hash)); + CTRACE_STYLE((tfp, "hash_code(%s) = %d\n", string, hash)); + } else { + FREE(buffer); + limit = 0; + } return hash; } -int hash_code_aggregate_char(int c, int hash) +int hash_code_caseless(const char *string) +{ + LYLowerCase(strcpy(get_buffer(strlen(string)), string)); + return hash_code(buffer); +} + +int hash_code_aggregate(const char *p, const char *q, const char *r) { - return HASH_OF(hash, c); + get_buffer(strlen(p) + strlen(q) + strlen(r)); + strcpy(buffer, p); + strcat(buffer, q); + strcat(buffer, r); + LYLowerCase(buffer); + return hash_code(buffer); } int hash_code_aggregate_lower_str(const char *string, int hash_was) diff --git a/src/LYHash.h b/src/LYHash.h index e284eba6..93e6c050 100644 --- a/src/LYHash.h +++ b/src/LYHash.h @@ -1,4 +1,4 @@ -/* $LynxId: LYHash.h,v 1.25 2011/06/06 09:28:19 tom Exp $ */ +/* $LynxId: LYHash.h,v 1.31 2018/03/03 15:20:39 tom Exp $ */ #ifndef _LYHASH_H_ #define _LYHASH_H_ 1 @@ -9,23 +9,16 @@ #ifdef __cplusplus extern "C" { #endif - /* define OMIT_SCN_KEEPING to 1 to omit keeping of Style_className - * in HTML.c when lss support is on. 1 to increase performance. - */ -#define OMIT_SCN_KEEPING 0 - struct _hashbucket { + typedef struct { char *name; /* name of this item */ int code; /* code of this item */ int color; /* color highlighting to be done */ int mono; /* mono highlighting to be done */ int cattr; /* attributes to go with the color */ - struct _hashbucket *next; /* next item */ - }; - - typedef struct _hashbucket bucket; + } bucket; #ifndef CSHASHSIZE -#define CSHASHSIZE 8193 +#define CSHASHSIZE 9973 /* Arbitrary prime. Memory/speed tradeoff */ #endif #define NOSTYLE -1 @@ -37,8 +30,8 @@ extern "C" { extern int hash_code(const char *string); extern bucket *nostyle_bucket(void); - extern int hash_code_lowercase_on_fly(const char *string); - extern int hash_code_aggregate_char(int c, int hash); + 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 s_a; @@ -73,10 +66,6 @@ extern "C" { extern int s_sb_naa; #endif -#if OMIT_SCN_KEEPING - extern bucket *special_bucket(void); -#endif - #ifdef __cplusplus } #endif diff --git a/src/LYPrettySrc.c b/src/LYPrettySrc.c index 974b9fd9..8289aa38 100644 --- a/src/LYPrettySrc.c +++ b/src/LYPrettySrc.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYPrettySrc.c,v 1.29 2013/11/28 11:21:09 tom Exp $ + * $LynxId: LYPrettySrc.c,v 1.32 2018/03/03 01:42:11 tom Exp $ * * HTML source syntax highlighting * by Vlad Harchev <hvv@hippo.ru> @@ -156,28 +156,11 @@ static void append_open_tag(char *tagname, subj->start = TRUE; #ifdef USE_COLOR_STYLE - hcode = hash_code_lowercase_on_fly(tagname); if (non_empty(classname)) { - -# if 0 - /* - * we don't provide a classname as attribute of that tag, since for - * plain formatting tags they are not used directly for anything except - * style - and we provide style value directly. - */ - HTTag *tag = HTML_dtd.tags + subj->element; - int class_attr_idx = 0; - int n = tag->number_of_attributes; - attr *attrs = tag->attributes; - -/*.... */ -/* this is not implemented though it's easy */ -# endif - - hcode = hash_code_aggregate_char('.', hcode); - hcode = hash_code_aggregate_lower_str(classname, hcode); + hcode = hash_code_aggregate(tagname, ".", classname); StrAllocCopy(subj->class_name, classname); } else { + hcode = hash_code_caseless(tagname); StrAllocCopy(subj->class_name, ""); } subj->style = hcode; diff --git a/src/LYStyle.c b/src/LYStyle.c index a9132f8a..6de99af9 100644 --- a/src/LYStyle.c +++ b/src/LYStyle.c @@ -1,5 +1,5 @@ /* - * $LynxId: LYStyle.c,v 1.97 2016/10/12 00:50:05 tom Exp $ + * $LynxId: LYStyle.c,v 1.99 2018/03/03 15:20:46 tom Exp $ * * character level styles for Lynx * (c) 1996 Rob Partington -- donated to the Lyncei (if they want it :-) @@ -125,13 +125,6 @@ static bucket *new_bucket(const char *name) return result; } -#if OMIT_SCN_KEEPING -bucket *special_bucket(void) -{ - return new_bucket("<special>"); -} -#endif - bucket *nostyle_bucket(void) { return new_bucket("<NOSTYLE>"); @@ -963,22 +956,9 @@ void init_color_styles(char **from_cmdline, const char *default_styles) void reinit_color_styles(void) { +#ifdef USE_PRETTYSRC int cs; - for (cs = 0; cs < CSHASHSIZE; ++cs) { - bucket *style = &hashStyles[cs]; - - while (style != 0) { - bucket *next = style->next; - - if (next != 0) { - hashStyles[cs] = *next; - free(next); - } - style = hashStyles[cs].next; - } - } -#ifdef USE_PRETTYSRC for (cs = 0; cs < HTL_num_lexemes; ++cs) { html_src_clean_item((HTlexeme) cs); } |