[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
lynx-dev 2.8.2dev.19 patch 4 - color styles
From: |
Klaus Weide |
Subject: |
lynx-dev 2.8.2dev.19 patch 4 - color styles |
Date: |
Tue, 16 Mar 1999 08:44:13 -0600 (CST) |
Rendering with color styles looks downright reliable with these
changes, when it wasn't (for me) without them. The colorized source
display is fun... (but note caveats about -preparsed).
Only tested for linux console, ncurses (debian package version 4.2-3),
the included lynx.lss. Hopefully if the changes are detrimental for
some other combination, somebody will complain, so lss users please
test.
Notes to Vlad Harchev <address@hidden>:
These patches conflict with your "unhighlighting problem" patch,
specifically in highlight(). I am not trying to address the same
"unhighlighting problem" here, so it would be worthwhile to combine the
patches, could you please give it a try? (My change addresses a somewhat
similar problem, that may only appear when link numbering is on and then
only be visible for some style settings [for example, IMG and A both have
styles and they are different?]) I'll send some more notes on your patch
in a different message.
Klaus
Example for effect of first (</TR>) change: <http://www.europarl.eu.int/>
* Tweak for TABLE formatting: break line at </TR> end tag (don't wait
for next <TR> start tag), effective in SortaSGML mode only.
* Lots of color style changes, only effective if compiled with
USE_COLOR_STYLE; together they seem to make color styles act much
more reliably and consistently.
- Moved some extern definitions and declarations.
- Made extra handling for LINK REL (or TITLE) attributes consistent
with example lynx.lss file.
- More complete (and hopefully more consistent) setting of "normal"
attributes, especially background color, on screen refresh and after
statusline messages. Set normal attributes for statusline prompts.
- Various other small tweaks, mostly to not lose color changes in a
document and to avoid color leaking.
- Attributes for highlighting WHEREIS search targets can be controlled
by setting style for "whereis" in lynx.lss.
- Allow mono attribute field in lynx.lss to be a combination of several
attributes separated by '+' characters.
- Changes of example lynx.lss file: more logical ordering, added some
comments, document new stuff. Changed a few styles for demonstration
purposes or because text was really hard to read.
* Apply color styles to HTML source display, using the same methods as
for displaying the rendered version. This is done if and only if
the -preparsed flag is used (and lynx is compiled with -DUSE_COLOR_STYLE,
of course). Please remember that the source displayed with -preparsed
is *not* the same as the original text/html document, it has been
mangled by lynx (as the name implies) and may itself not be a valid
HTML document even if the original was.
* Changed some slightly suspicious casts in HText_endAnchor's casting
hell: prefer to cast a line's size element to (int), rather than
various int variables to (unsigned).
* Remove some unnecessary use of dynamic buffers where there is no
apparent benefit for using them, for the sake of performance or to
avoid a minor memory leak.
* Stuffed small memory leak (MultipartContentType).
--- lynx2-8-2.old/src/LYStyle.h Wed Mar 25 07:58:54 1998
+++ lynx2-8-2/src/LYStyle.h Sat Mar 13 00:53:22 1999
@@ -27,6 +27,12 @@
extern int style_readFromFile PARAMS((char* file));
+
+extern void TrimColorClass PARAMS((
+ CONST char * tagname,
+ char * styleclassname,
+ int * phcode));
+
#endif /* USE_COLOR_STYLE */
#endif /* LYSTYLE_H */
--- lynx2-8-2.old/src/LYStrings.c Thu Mar 4 04:39:44 1999
+++ lynx2-8-2/src/LYStrings.c Mon Mar 15 06:51:12 1999
@@ -19,6 +19,11 @@
#include <keys.h>
#endif /* DJGPP_KEYHANDLER */
+#ifdef USE_COLOR_STYLE
+#include <LYHash.h>
+#include <AttrList.h>
+#endif
+
#include <LYLeaks.h>
extern unsigned short *LYKbLayout;
@@ -2046,6 +2051,20 @@
nrdisplayed = DspWdth;
move(edit->sy, edit->sx);
+#ifdef USE_COLOR_STYLE
+ /*
+ * If this is the last screen line, set attributes to normal,
+ * should only be needed for color styles. The curses function
+ * may be used directly to avoid complications. - kw
+ */
+ if (edit->sy == (LYlines - 1)) {
+ if (s_normal != NOSTYLE) {
+ curses_style(s_normal, ABS_ON);
+ } else {
+ attrset(A_NORMAL); /* need to do something about colors? */
+ }
+ }
+#endif
if (edit->hidden) {
for (i = 0; i < nrdisplayed; i++)
addch('*');
--- lynx2-8-2.old/src/LYHash.h Thu Aug 6 07:28:22 1998
+++ lynx2-8-2/src/LYHash.h Sun Mar 14 03:35:28 1999
@@ -32,7 +32,8 @@
extern int s_alink, s_a, s_status,
s_label, s_value, s_high,
- s_normal, s_alert, s_title;
+ s_normal, s_alert, s_title,
+ s_whereis;
#define CACHEW 128
#define CACHEH 64
--- lynx2-8-2.old/src/LYCurses.h Thu Dec 3 12:28:20 1998
+++ lynx2-8-2/src/LYCurses.h Mon Mar 15 07:06:22 1999
@@ -325,7 +325,11 @@
#else /* not UNDERLINE_LINKS: */
#define start_bold() LYaddAttr(A_BOLD)
#define stop_bold() LYsubAttr(A_BOLD)
+#ifdef USE_COLOR_STYLE
+#define start_underline() attron(A_UNDERLINE) /* allow combining - kw */
+#else
#define start_underline() LYaddAttr(A_UNDERLINE)
+#endif /* USE_COLOR_STYLE */
#define stop_underline() LYsubAttr(A_UNDERLINE)
#endif /* UNDERLINE_LINKS */
#if defined(SNAKE) && defined(HP_TERMINAL)
--- lynx2-8-2.old/src/AttrList.h Wed Jan 13 05:37:34 1999
+++ lynx2-8-2/src/AttrList.h Sun Mar 14 03:35:28 1999
@@ -22,6 +22,7 @@
DSTYLE_VALUE, /* value on the option screen */
DSTYLE_HIGH,
DSTYLE_CANDY, /* possibly going to vanish */
+ DSTYLE_WHEREIS, /* whereis search target */
DSTYLE_ELEMENTS
};
@@ -55,6 +56,11 @@
extern void _internal_HTC PARAMS((HText * text, int style, int dir));
#define TEMPSTRINGSIZE 256
extern char class_string[TEMPSTRINGSIZE];
+
+/* stack of attributes during page rendering */
+extern int last_styles[128];
+extern int last_colorattr_ptr;
+
#endif
#endif
--- lynx2-8-2.old/src/LYCurses.c Mon Jan 18 06:29:20 1999
+++ lynx2-8-2/src/LYCurses.c Tue Mar 16 07:54:40 1999
@@ -34,7 +34,11 @@
int lynx_has_color = FALSE;
#endif
+#if defined(USE_COLOR_STYLE) && !USE_COLOR_TABLE
+#define COLOR_BKGD ((s_normal != NOSTYLE) ? hashStyles[s_normal].color :
A_NORMAL)
+#else
#define COLOR_BKGD ((COLOR_PAIRS >= 9) ? COLOR_PAIR(9) : A_NORMAL)
+#endif
/*
* These are routines to start and stop curses and to cleanup
@@ -251,11 +255,6 @@
#endif /* USE_SLANG */
#if defined(USE_COLOR_STYLE)
-PRIVATE int last_styles[128];
-PRIVATE int last_ptr=0;
-#endif
-
-#if defined(USE_COLOR_STYLE)
/* Ok, explanation of the USE_COLOR_STYLE styles. The basic styles (ie non
* HTML) are set the same as the SLANG version for ease of programming. The
* other styles are simply the HTML enum from HTMLDTD.h + 16.
@@ -335,8 +334,8 @@
{
/* ABS_OFF is the same as STACK_OFF for the moment */
case STACK_OFF:
- if (last_ptr) {
- int last_attr = last_styles[--last_ptr];
+ if (last_colorattr_ptr) {
+ int last_attr = last_styles[--last_colorattr_ptr];
LYAttrset(win,last_attr,last_attr);
}
else
@@ -344,14 +343,14 @@
return;
case STACK_ON: /* remember the current attributes */
- if (last_ptr > 127) {
+ if (last_colorattr_ptr > 127) {
CTRACE(tfp,"........... %s (0x%x) %s\r\n",
"attribute cache FULL, dropping last",
- last_styles[last_ptr],
+ last_styles[last_colorattr_ptr],
"in LynxChangeStyle(curses_w_style)");
- last_ptr--;
+ last_colorattr_ptr--;
}
- last_styles[last_ptr++] = getattrs(stdscr);
+ last_styles[last_colorattr_ptr++] = getattrs(stdscr);
/* don't cache style changes for active links */
if (style != s_alink)
{
@@ -1027,8 +1026,8 @@
PUBLIC BOOLEAN setup ARGS1(
char *, terminal)
{
- static char *term_putenv;
- char buffer[120];
+ static char term_putenv[112];
+ char buffer[108];
char *cp;
#if defined(HAVE_SIZECHANGE) && !defined(USE_SLANG) && defined(NOTDEFINED)
/*
@@ -1064,7 +1063,7 @@
}
if (terminal != NULL) {
- HTSprintf0(&term_putenv, "TERM=%s", terminal);
+ sprintf(term_putenv, "TERM=%.106s", terminal);
(void) putenv(term_putenv);
}
@@ -1084,9 +1083,9 @@
if (strlen(buffer) == 0)
strcpy(buffer,"vt100");
- HTSprintf0(&term_putenv,"TERM=%s", buffer);
+ sprintf(term_putenv,"TERM=%.106s", buffer);
(void) putenv(term_putenv);
- printf("\n%s%s\n", gettext("TERMINAL TYPE IS SET TO"), getenv("TERM"));
+ printf("\n%s %s\n", gettext("TERMINAL TYPE IS SET TO"), getenv("TERM"));
sleep(MESSAGESECS);
}
@@ -1189,6 +1188,12 @@
PUBLIC void LYstartTargetEmphasis NOARGS
{
+#ifdef USE_COLOR_STYLE
+ if (s_whereis != NOSTYLE) {
+ curses_style(s_whereis, STACK_ON);
+ return;
+ }
+#endif
#if defined(FANCY_CURSES) || defined(USE_SLANG)
start_bold();
start_reverse();
@@ -1198,6 +1203,12 @@
PUBLIC void LYstopTargetEmphasis NOARGS
{
+#ifdef USE_COLOR_STYLE
+ if (s_whereis != NOSTYLE) {
+ curses_style(s_whereis, STACK_OFF);
+ return;
+ }
+#endif
stop_underline();
#if defined(FANCY_CURSES) || defined(USE_SLANG)
stop_reverse();
@@ -1685,11 +1696,9 @@
{
#if defined(COLOR_CURSES)
chtype a;
-#ifndef USE_COLOR_STYLE
if (LYShowColor >= SHOW_COLOR_ON)
a = COLOR_BKGD;
else
-#endif
a = A_NORMAL;
bkgdset(a | ' ');
#ifndef USE_COLOR_STYLE
--- lynx2-8-2.old/src/LYStyle.c Wed Nov 18 13:23:54 1998
+++ lynx2-8-2/src/LYStyle.c Mon Mar 15 07:42:30 1999
@@ -11,6 +11,7 @@
#include <LYReadCFG.h>
#include <LYCurses.h>
#include <LYCharUtils.h>
+#include <LYUtils.h> /* defines TABLESIZE */
#include <AttrList.h>
#include <SGML.h>
#include <HTMLDTD.h>
@@ -24,6 +25,10 @@
#ifdef USE_COLOR_STYLE
+/* stack of attributes during page rendering */
+PUBLIC int last_styles[128];
+PUBLIC int last_colorattr_ptr=0;
+
PUBLIC bucket hashStyles[CSHASHSIZE];
/* definitions for the mono attributes we can use */
@@ -43,7 +48,8 @@
/* Remember the hash codes for common elements */
PUBLIC int s_alink = NOSTYLE, s_a = NOSTYLE, s_status = NOSTYLE,
s_label = NOSTYLE, s_value = NOSTYLE, s_high = NOSTYLE,
- s_normal = NOSTYLE, s_alert = NOSTYLE, s_title = NOSTYLE;
+ s_normal = NOSTYLE, s_alert = NOSTYLE, s_title = NOSTYLE,
+ s_whereis= NOSTYLE;
/* start somewhere safe */
PRIVATE int colorPairs = 0;
@@ -58,13 +64,41 @@
CTRACE(tfp, "CSS(PA):style d=%d / h=%d, e=%s\n", style, newstyle,element);
- for (i = 0; i <7; i++)
+ for (i = 0; i < (int)TABLESIZE(Mono_Strings); i++)
{
if (!strcasecomp(Mono_Strings[i], mono))
{
mA = ncursesMono[i];
}
}
+ if (!mA) {
+ /*
+ * Not found directly yet, see whether we have a combination
+ * of several mono attributes separated by '+' - kw
+ */
+ char *cp0 = mono;
+ char csep = '+';
+ char *cp = strchr(mono, csep);
+ while (cp) {
+ *cp = '\0';
+ for (i = 0; i < (int)TABLESIZE(Mono_Strings); i++)
+ {
+ if (!strcasecomp(Mono_Strings[i], cp0))
+ {
+ mA |= ncursesMono[i];
+ }
+ }
+ if (!csep)
+ break;
+ *cp = csep;
+ cp0 = cp + 1;
+ cp = strchr(cp0, csep);
+ if (!cp) {
+ cp = cp0 + strlen(cp0);
+ csep = '\0';
+ }
+ }
+ }
CTRACE(tfp, "CSS(CP):%d\n", colorPairs);
fA = check_color(fg, default_fg);
@@ -197,12 +231,19 @@
else if (!strcasecomp(element, "normal")) /* added - kw */
{
parse_attributes(mono,fg,bg,DSTYLE_NORMAL,"html");
+ s_normal = hash_code("html"); /* rather bizarre... - kw */
}
/* this may vanish */
else if (!strncasecomp(element, "candy", 5)) /* [INLINE]'s */
{
parse_attributes(mono,fg,bg,DSTYLE_CANDY,"candy");
}
+ /* added for whereis search target - kw */
+ else if (!strncasecomp(element, "whereis", 7))
+ {
+ parse_attributes(mono,fg,bg,DSTYLE_WHEREIS,"whereis");
+ s_whereis = hash_code("whereis");
+ }
/* Ok, it must be a HTML element, so look through the list until we
* find it
*/
@@ -381,4 +422,37 @@
parse_userstyles();
return 0;
}
+
+/* Used in HTStructured methods: - kw */
+
+PUBLIC void TrimColorClass ARGS3(
+ CONST char *, tagname,
+ char *, styleclassname,
+ int *, phcode)
+{
+ char *end, *start=NULL, *lookfrom;
+ char tmp[64];
+
+ sprintf(tmp, ";%.*s", (int) sizeof(tmp) - 3, tagname);
+ strtolower(tmp);
+
+ if ((lookfrom = styleclassname) != 0) {
+ do {
+ end = start;
+ start = strstr(lookfrom, tmp);
+ if (start)
+ lookfrom = start + 1;
+ }
+ while (start);
+ /* trim the last matching element off the end
+ ** - should match classes here as well (rp)
+ */
+ if (end)
+ *end='\0';
+ }
+ *phcode = hash_code(lookfrom && *lookfrom ? lookfrom : &tmp[1]);
+ CTRACE(tfp, "CSS:%s (trimmed %s)\n",
+ (styleclassname ? styleclassname : "<null>"), tmp);
+}
+
#endif /* USE_COLOR_STYLE */
--- lynx2-8-2.old/src/GridText.c Thu Mar 4 04:39:44 1999
+++ lynx2-8-2/src/GridText.c Mon Mar 15 11:08:28 1999
@@ -829,8 +829,10 @@
#endif
case LY_SOFT_NEWLINE:
- if (!dump_output_immediately)
+ if (!dump_output_immediately) {
addch('+');
+ i++;
+ }
break;
case LY_SOFT_HYPHEN:
@@ -957,7 +959,11 @@
lynx_start_title_color ();
#ifdef USE_COLOR_STYLE
/* turn the TITLE style on */
- LynxChangeStyle(s_title, ABS_ON, 0);
+ if (last_colorattr_ptr > 0) {
+ LynxChangeStyle(s_title, STACK_ON, 0);
+ } else {
+ LynxChangeStyle(s_title, ABS_ON, 0);
+ }
#endif /* USE_COLOR_STYLE */
/*
@@ -1053,7 +1059,7 @@
#ifdef USE_COLOR_STYLE
/* turn the TITLE style off */
- LynxChangeStyle(s_title, ABS_OFF, 0);
+ LynxChangeStyle(s_title, STACK_OFF, 0);
#endif /* USE_COLOR_STYLE */
lynx_stop_title_color ();
@@ -1182,6 +1188,23 @@
}
#ifdef USE_COLOR_STYLE
+ /*
+ * Reset stack of color attribute changes to avoid color leaking,
+ * except if what we last displayed from this text was the previous
+ * screenful, in which case carrying over the state might be beneficial
+ * (although it shouldn't generally be needed any more). - kw
+ */
+ if (text->stale ||
+ line_number != text->top_of_screen + (display_lines)) {
+ last_colorattr_ptr = 0;
+ }
+#endif
+
+ text->top_of_screen = line_number;
+ display_title(text); /* will move cursor to top of screen */
+ display_flag=TRUE;
+
+#ifdef USE_COLOR_STYLE
#ifdef DISP_PARTIAL
if (display_partial ||
line_number != text->first_lineno_last_disp_partial ||
@@ -1190,10 +1213,6 @@
LynxResetScreenCache();
#endif /* USE_COLOR_STYLE */
- text->top_of_screen = line_number;
- display_title(text); /* will move cursor to top of screen */
- display_flag=TRUE;
-
/*
* Output the page.
*/
@@ -2013,13 +2032,33 @@
spare -= 2;
} else if (spare && !previous->styles[spare - 1].direction) {
/*
- * Found an OFF change not part of a matched pair.
- * Assume it is safer to leave whatever comes before
- * it on the previous line alone. Setting spare to 0
- * ensures that it won't be used in a following
+ * Found an OFF change not part of an adjacent matched pair.
+ * Walk backward looking for the corresponding ON change.
+ * If we find it, skip the ON/OFF and everything in between.
+ * This can only work correctly if all changes are correctly
+ * nested! If this fails, assume it is safer to leave whatever
+ * comes before the OFF on the previous line alone. Setting
+ * spare to 0 ensures that it won't be used in a following
* iteration. - kw
*/
- spare = 0;
+ int level=-1;
+ int itmp;
+ for (itmp = spare-1; itmp > 0; itmp--) {
+ if (previous->styles[itmp - 1].style
+ == previous->styles[spare - 1].style) {
+ if (previous->styles[itmp - 1].direction == STACK_OFF) {
+ level--;
+ } else if (previous->styles[itmp - 1].direction ==
STACK_ON) {
+ if (++level == 0)
+ break;
+ } else
+ break;
+ }
+ }
+ if (level == 0)
+ spare = itmp - 1;
+ else
+ spare = 0;
} else {
/*
* Nothing applied, so we are done with the loop. - kw
@@ -3102,7 +3141,7 @@
*/
a->extent += (text->chars + last->size) - a->start -
(text->Lines - a->line_num);
- if ((unsigned) a->extent > last->size) {
+ if (a->extent > (int)last->size) {
/*
* The anchor extends over more than one line,
* so set up to check the entire last line. - FM
@@ -3116,7 +3155,7 @@
i = a->extent;
}
k = j = (last->size - i);
- while ((unsigned) j < last->size) {
+ while (j < (int)last->size) {
if (!IsSpecialAttrChar(last->data[j]) &&
!isspace((unsigned char)last->data[j]) &&
last->data[j] != HT_NON_BREAK_SPACE &&
@@ -3126,7 +3165,7 @@
j++;
}
if (i == 0) {
- if ((unsigned) a->extent > last->size) {
+ if (a->extent > (int)last->size) {
/*
* The anchor starts on a preceding line, and
* the last line has only white and special
@@ -3173,7 +3212,7 @@
*/
i = a->extent - CurBlankExtent;
}
- while ((unsigned) j < prev->size) {
+ while (j < (int)prev->size) {
if (!IsSpecialAttrChar(prev->data[j]) &&
!isspace((unsigned char)prev->data[j]) &&
prev->data[j] != HT_NON_BREAK_SPACE &&
@@ -3183,7 +3222,7 @@
j++;
}
if (i == 0) {
- if ((unsigned) a->extent > (CurBlankExtent + prev->size) ||
+ if (a->extent > (CurBlankExtent + (int)prev->size) ||
(a->extent == CurBlankExtent + (int)prev->size &&
k == 0 &&
prev->prev != text->last_line &&
@@ -3292,7 +3331,7 @@
text->permissible_split -= NumSize;
}
k = j + NumSize;
- while ((unsigned) k < start->size)
+ while (k < (int)start->size)
start->data[j++] = start->data[k++];
if (start != last)
text->chars -= NumSize;
@@ -3330,7 +3369,7 @@
*/
NumSize++;
l = (i - j);
- while ((unsigned) i < prev->size)
+ while (i < (int)prev->size)
prev->data[j++] = prev->data[i++];
text->chars -= l;
for (anc = a; anc; anc = anc->next) {
@@ -3348,7 +3387,7 @@
}
j = 0;
i = k;
- while ((unsigned) k < start->size)
+ while (k < (int)start->size)
start->data[j++] = start->data[k++];
if (start != last)
text->chars -= i;
@@ -3407,7 +3446,7 @@
*/
NumSize++;
k = j + NumSize;
- while ((unsigned) k < prev->size)
+ while (k < (int)prev->size)
prev->data[j++] = prev->data[k++];
text->chars -= NumSize;
for (anc = a; anc; anc = anc->next) {
@@ -8558,6 +8597,7 @@
}
FREE(copied_name_used);
if (Boundary) {
+ FREE(MultipartContentType);
HTSprintf(&query, "\r\n--%s--\r\n", Boundary);
} else if (!query) {
StrAllocCopy(query, "");
--- lynx2-8-2.old/src/LYUtils.c Thu Mar 4 04:39:44 1999
+++ lynx2-8-2/src/LYUtils.c Mon Mar 15 11:27:28 1999
@@ -147,18 +147,36 @@
lynx_start_link_color (flag == ON, links[cur].inUnderline);
#else
if (flag == ON) {
- LynxChangeStyle(s_alink, ABS_ON, 0);
+ LynxChangeStyle(s_alink, STACK_ON, 0);
} else {
- /* the logic is flawed here - no provision is made for links
that
- ** aren't coloured as [s_a] by default - rjp
- */
- if (LYP >= 0 && LYP < CACHEH && LXP >= 0 && LXP < CACHEW &&
- cached_styles[LYP][LXP]) {
- LynxChangeStyle(cached_styles[LYP][LXP], ABS_ON, 0);
- }
- else {
- LynxChangeStyle(s_a, ABS_ON, 0);
+ int s, x;
+ /*
+ * 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.
+ */
+ if (LYP >= 0 && LYP < CACHEH && LXP >= 0 && LXP < CACHEW) {
+ s = cached_styles[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;
+ }
+ break;
+ }
+ }
+ if (s == 0)
+ s = s_a;
+ }
+ } else {
+ s = s_a;
}
+ LynxChangeStyle(s, STACK_ON, 0);
}
#endif
@@ -1924,22 +1942,21 @@
/* draw the status bar in the STATUS style */
{
int a=(strncmp(buffer, ALERT_FORMAT, ALERT_PREFIX_LEN) ||
- !hashStyles[s_alert].name ? s_status : s_alert);
- LynxChangeStyle (a, ABS_ON, 1);
+ !hashStyles[s_alert].name) ? s_status : s_alert;
+ LynxChangeStyle (a, STACK_ON, 1);
addstr(buffer);
wbkgdset(stdscr,
((lynx_has_color && LYShowColor >= SHOW_COLOR_ON)
? hashStyles[a].color
:A_NORMAL) | ' ');
clrtoeol();
- if (s_normal != NOSTYLE)
+ if (!(lynx_has_color && LYShowColor >= SHOW_COLOR_ON))
+ wbkgdset(stdscr, A_NORMAL | ' ');
+ else if (s_normal != NOSTYLE)
wbkgdset(stdscr, hashStyles[s_normal].color | ' ');
else
- wbkgdset(stdscr,
- ((lynx_has_color && LYShowColor >= SHOW_COLOR_ON)
- ? displayStyles[DSTYLE_NORMAL].color
- : A_NORMAL) | ' ');
- LynxChangeStyle (a, ABS_OFF, 0);
+ wbkgdset(stdscr, displayStyles[DSTYLE_NORMAL].color | ' ');
+ LynxChangeStyle (a, STACK_OFF, 0);
}
#endif
}
--- lynx2-8-2.old/src/HTML.c Thu Mar 4 04:39:44 1999
+++ lynx2-8-2/src/HTML.c Mon Mar 15 13:43:16 1999
@@ -605,43 +605,11 @@
#endif /* DONT_TRACK_INTERNAL_LINKS */
#ifdef USE_COLOR_STYLE
-char class_string[TEMPSTRINGSIZE];
-#endif
-
-#ifdef USE_COLOR_STYLE
static char *Style_className = NULL;
static char myHash[128];
static int hcode;
#endif
-#ifdef USE_COLOR_STYLE
-PRIVATE void TrimColorClass ARGS1(char *, tagname)
-{
- char *end, *start=NULL, *lookfrom;
- char tmp[64];
-
- sprintf(tmp, ";%.*s", (int) sizeof(tmp) - 3, tagname);
- strtolower(tmp);
-
- if ((lookfrom = Style_className) != 0) {
- do {
- end = start;
- start = strstr(lookfrom, tmp);
- if (start)
- lookfrom = start + 1;
- }
- while (start);
- /* trim the last matching element off the end
- ** - should match classes here as well (rp)
- */
- if (end)
- *end='\0';
- }
- hcode = hash_code(lookfrom && *lookfrom ? lookfrom : &tmp[1]);
- CTRACE(tfp, "CSS:%s (trimmed %s)\n", Style_className, tmp);
-}
-#endif /* USE_COLOR_STYLE */
-
/* Start Element
** -------------
*/
@@ -1026,10 +994,7 @@
!strcasecomp(value[HTML_LINK_REL], "Documentation") ||
!strcasecomp(value[HTML_LINK_REL], "Biblioentry") ||
!strcasecomp(value[HTML_LINK_REL], "Bibliography") ||
- !strcasecomp(value[HTML_LINK_REL], "Alternate") ||
!strcasecomp(value[HTML_LINK_REL], "Start") ||
- !strcasecomp(value[HTML_LINK_REL], "Section") ||
- !strcasecomp(value[HTML_LINK_REL], "Subsection") ||
!strcasecomp(value[HTML_LINK_REL], "Appendix")) {
StrAllocCopy(title, value[HTML_LINK_REL]);
pdoctitle = &title; /* for setting HTAnchor's title */
@@ -1046,10 +1011,13 @@
!strcasecomp(value[HTML_LINK_REL], "Pointer") ||
!strcasecomp(value[HTML_LINK_REL], "Translation") ||
!strcasecomp(value[HTML_LINK_REL], "Definition") ||
+ !strcasecomp(value[HTML_LINK_REL], "Alternate") ||
+ !strcasecomp(value[HTML_LINK_REL], "Section") ||
+ !strcasecomp(value[HTML_LINK_REL], "Subsection") ||
!strcasecomp(value[HTML_LINK_REL], "Chapter")) {
StrAllocCopy(title, value[HTML_LINK_REL]);
/* not setting target HTAnchor's title, for these
- link of highly relative character. Instead,
+ links of highly relative character. Instead,
try to remember the REL attribute as a property
of the link (but not the destination), in the
(otherwise underused) link type in a special format;
@@ -1168,7 +1136,7 @@
value && *value[HTML_LINK_CLASS]!='\0')
{
char *tmp = 0;
- HTSprintf0(&tmp, "link.%s.%s.%s", value[HTML_LINK_CLASS],
title, value[HTML_LINK_CLASS]);
+ HTSprintf0(&tmp, "link.%s.%s", value[HTML_LINK_CLASS], title);
CTRACE(tfp, "CSSTRIM:link=%s\n", tmp);
HText_characterStyle(me->text, hash_code(tmp), 1);
@@ -5303,7 +5271,8 @@
#else
HText_characterStyle(me->text, hcode, STACK_OFF);
#endif /* USE_HASH */
- TrimColorClass(HTML_dtd.tags[element_number].name);
+ TrimColorClass(HTML_dtd.tags[element_number].name,
+ Style_className, &hcode);
}
#endif /* USE_COLOR_STYLE */
}
@@ -6589,6 +6558,11 @@
/* These TABLE related elements may now not be SGML_EMPTY. - kw */
case HTML_TR:
+ if (HText_LastLineSize(me->text, FALSE)) {
+ HText_setLastChar(me->text, ' '); /* absorb next white space */
+ HText_appendCharacter(me->text, '\r');
+ }
+ me->in_word = NO;
break;
case HTML_THEAD:
@@ -6643,7 +6617,8 @@
} /* switch */
#ifdef USE_COLOR_STYLE
- TrimColorClass(HTML_dtd.tags[element_number].name);
+ TrimColorClass(HTML_dtd.tags[element_number].name,
+ Style_className, &hcode);
if (!REALLY_EMPTY(element_number))
{
@@ -7329,6 +7304,9 @@
** ----------------------------------
**
** This will convert from HTML to presentation or plain text.
+**
+** It is registered in HTInit.c, but never actually used by lynx.
+** - kw 1999-03-15
*/
PUBLIC HTStream* HTMLToPlain ARGS3(
HTPresentation *, pres,
@@ -7342,6 +7320,12 @@
** -----------------------------------------
**
** This will preparse HTML and convert back to presentation or plain text.
+**
+** It is registered in HTInit.c and used by lynx if invoked with
+** -preparsed. The stream generated here will be fed with HTML text,
+** It feeds that to the SGML.c parser, which in turn feeds an HTMLGen.c
+** structured stream for regenerating flat text; the latter should
+** end up being handled as text/plain. - kw
*/
PUBLIC HTStream* HTMLParsedPresent ARGS3(
HTPresentation *, pres,
@@ -7365,10 +7349,14 @@
HTAnchor_setUCInfoStage(anchor, structured_cset,
UCT_STAGE_PARSER, UCT_SETBY_MIME);
if (pres->rep_out == WWW_SOURCE) {
-/* intermediate = HTPlainPresent(pres, anchor, NULL); */
+ /* same effect as
+ intermediate = HTPlainPresent(pres, anchor, NULL);
+ just written in a more general way:
+ */
intermediate = HTStreamStack(WWW_PLAINTEXT, WWW_PRESENT,
NULL, anchor);
} else {
+ /* this too should amount to calling HTPlainPresent: */
intermediate = HTStreamStack(WWW_PLAINTEXT, pres->rep_out,
NULL, anchor);
}
@@ -7393,6 +7381,9 @@
** C code is like plain text but all non-preformatted code
** is commented out.
** This will convert from HTML to presentation or plain text.
+**
+** It is registered in HTInit.c, but never actually used by lynx.
+** - kw 1999-03-15
*/
PUBLIC HTStream* HTMLToC ARGS3(
HTPresentation *, pres GCC_UNUSED,
@@ -7414,6 +7405,7 @@
**
** This will convert from HTML to presentation or plain text.
**
+** (Comment from original libwww:)
** Override this if you have a windows version
*/
#ifndef GUI
@@ -7426,6 +7418,7 @@
}
#endif /* !GUI */
+/* (Comments from original libwww:) */
/* Record error message as a hypertext object
** ------------------------------------------
**
@@ -7443,6 +7436,10 @@
**
** On exit,
** returns a negative number to indicate lack of success in the load.
+*/
+/* (We don't actually do any of that hypertext stuff for errors,
+ the trivial implementation for lynx just generates a message
+ and returns. - kw 1999-03-15)
*/
PUBLIC int HTLoadError ARGS3(
HTStream *, sink GCC_UNUSED,
--- lynx2-8-2.old/WWW/Library/Implementation/HTMLGen.c Sat Dec 12 22:10:36 1998
+++ lynx2-8-2/WWW/Library/Implementation/HTMLGen.c Mon Mar 15 21:25:52 1999
@@ -26,12 +26,29 @@
#include <SGML.h>
#include <HTFormat.h>
+#ifdef USE_COLOR_STYLE
+#include <LYCharUtils.h>
+#include <AttrList.h>
+#include <LYHash.h>
+#include <LYStyle.h>
+#endif
+
#include <LYLeaks.h>
+extern BOOLEAN LYPreparsedSource; /* Show source as preparsed? */
+
#define PUTC(c) (*me->targetClass.put_character)(me->target, c)
/* #define PUTS(s) (*me->targetClass.put_string)(me->target, s) */
#define PUTB(s,l) (*me->targetClass.put_block)(me->target, s, l)
+#ifdef USE_COLOR_STYLE
+PUBLIC char class_string[TEMPSTRINGSIZE];
+
+static char *Style_className = NULL;
+static char myHash[128];
+static int hcode;
+#endif
+
/* HTML Object
** -----------
*/
@@ -56,6 +73,9 @@
BOOL preformatted;
BOOL escape_specials;
BOOL in_attrval;
+#ifdef USE_COLOR_STYLE
+ HText * text;
+#endif
};
/* Flush Buffer
@@ -83,6 +103,46 @@
me->delete_line_break_char[0] = NO;
}
+#ifdef USE_COLOR_STYLE
+/*
+ * We need to flush our buffer each time before we effect a color style
+ * change, this also relies on the subsequent stage not doing any
+ * buffering - this is currently true, in cases where it matters the
+ * target stream should be the HTPlain converter.
+ * The flushing currently prevents reasonable line breaking in lines
+ * with tags. Since color styles help visual scanning of displayed
+ * source lines, and long lines are wrapped in GridText anyway, this
+ * is probably acceptable (or even A Good Thing - more to see in one
+ * screenful).
+ * The pointer to the HText structure is initialized here before
+ * we effect the first style change. Getting it from the global
+ * HTMainText variable isn't very clean, since it relies on the fact
+ * that HText_new() has already been called for the current stream
+ * stack's document by the time we start processing the first element;
+ * we rely on HTMLGenerator's callers (HTMLParsedPresent in particular)
+ * to guarantee this when it matters. Normally the target stream will
+ * have been setup by HTPlainPresent, which does what we need in this
+ * respect. (A check whether we have the right output stream could be
+ * done by checking that targetClass.name is "PlainPresenter" or similar.)
+ *
+ * All special color style handling is only done if LYPreparsedSource
+ * is set. We could always do it for displaying source generated by
+ * an internal gateway, but this makes the rule more simple for the
+ * user: color styles are applied to html source only with the
+ * -preparsed flag. - kw
+ */
+PRIVATE void do_cstyle_flush ARGS1(
+ HTStructured *, me)
+{
+ if (!me->text && LYPreparsedSource) {
+ me->text = HTMainText;
+ }
+ if (me->text) {
+ HTMLGen_flush(me);
+ }
+}
+#endif /* COLOR_STYLE */
+
/* Weighted optional line break
**
** We keep track of all the breaks for when we chop the line
@@ -266,6 +326,59 @@
BOOL was_preformatted = me->preformatted;
HTTag * tag = &HTML_dtd.tags[element_number];
+#if defined(USE_COLOR_STYLE)
+ char *title = NULL;
+ char *title_tmp = NULL;
+
+ if (LYPreparsedSource) {
+ /*
+ * Same logic as in HTML_start_element, copied from there. - kw
+ */
+ HTSprintf (&Style_className, ";%s", HTML_dtd.tags[element_number].name);
+ strcpy (myHash, HTML_dtd.tags[element_number].name);
+ if (class_string[0])
+ {
+ HTSprintf (&Style_className, ".%s", class_string);
+ strcat (myHash, ".");
+ strcat (myHash, class_string);
+ }
+ class_string[0] = '\0';
+ strtolower(myHash);
+ hcode = hash_code(myHash);
+ strtolower(Style_className);
+
+ if (TRACE)
+ {
+ fprintf(tfp, "CSSTRIM:%s -> %d", myHash, hcode);
+ if (hashStyles[hcode].code!=hcode)
+ {
+ char *rp=strrchr(myHash, '.');
+ fprintf(tfp, " (undefined) %s\n", myHash);
+ if (rp)
+ {
+ int hcd;
+ *rp='\0'; /* trim the class */
+ hcd = hash_code(myHash);
+ fprintf(tfp, "CSS:%s -> %d", myHash, hcd);
+ if (hashStyles[hcd].code!=hcd)
+ fprintf(tfp, " (undefined) %s\n", myHash);
+ else
+ fprintf(tfp, " ca=%d\n", hashStyles[hcd].color);
+ }
+ }
+ else
+ fprintf(tfp, " ca=%d\n", hashStyles[hcode].color);
+ }
+
+ if (displayStyles[element_number + STARTAT].color > -2) /* actually set
*/
+ {
+ CTRACE(tfp, "CSSTRIM: start_element: top <%s>\n",
+ HTML_dtd.tags[element_number].name);
+ do_cstyle_flush(me);
+ HText_characterStyle(me->text, hcode, 1);
+ }
+ }
+#endif /* USE_COLOR_STYLE */
me->preformatted = YES; /* free text within tags */
HTMLGen_put_character(me, '<');
HTMLGen_put_string(me, tag->name);
@@ -276,6 +389,36 @@
had_attr = YES;
HTMLGen_put_character(me, ' ');
allow_break(me, 11, YES);
+#ifdef USE_COLOR_STYLE
+ /*
+ * Try to mimic HTML_start_element's special handling
+ * for HTML_LINK. If applicable, color the displayed
+ * attribute / value pairs differently. - kw
+ */
+ if (LYPreparsedSource &&
+ element_number == HTML_LINK && !title &&
+ present[HTML_LINK_CLASS] &&
+ value && *value[HTML_LINK_CLASS]!='\0' &&
+ !present[HTML_LINK_REV] &&
+ (present[HTML_LINK_REL] || present[HTML_LINK_HREF])) {
+ if (present[HTML_LINK_TITLE] && *value[HTML_LINK_TITLE]) {
+ StrAllocCopy(title, value[HTML_LINK_TITLE]);
+ LYTrimHead(title);
+ LYTrimTail(title);
+ }
+ if ((!title || *title=='\0') && present[HTML_LINK_REL]) {
+ StrAllocCopy(title, value[HTML_LINK_REL]);
+ }
+ if (title && *title) {
+ HTSprintf0(&title_tmp, "link.%s.%s",
+ value[HTML_LINK_CLASS], title);
+ CTRACE(tfp, "CSSTRIM:link=%s\n", title_tmp);
+
+ do_cstyle_flush(me);
+ HText_characterStyle(me->text, hash_code(title_tmp), 1);
+ }
+ }
+#endif
HTMLGen_put_string(me, tag->attributes[i].name);
if (value[i]) {
me->preformatted = was_preformatted;
@@ -305,6 +448,19 @@
}
}
}
+#ifdef USE_COLOR_STYLE
+ if (had_attr && LYPreparsedSource && element_number == HTML_LINK) {
+ /*
+ * Clean up after special HTML_LINK handling - kw
+ */
+ if (title && *title) {
+ do_cstyle_flush(me);
+ HText_characterStyle(me->text, hash_code(title_tmp), 0);
+ FREE(title_tmp);
+ }
+ FREE(title);
+ }
+#endif
if (had_attr)
allow_break(me, 12, NO);
}
@@ -324,6 +480,29 @@
else
allow_break(me, 2, NO);
}
+
+#if defined(USE_COLOR_STYLE)
+ /*
+ * Same logic as in HTML_start_element, copied from there. - kw
+ */
+
+/* end really empty tags straight away */
+#define REALLY_EMPTY(e) ((HTML_dtd.tags[e].contents == SGML_EMPTY) && \
+ !(HTML_dtd.tags[e].flags & Tgf_nreie))
+
+ if (LYPreparsedSource && REALLY_EMPTY(element_number))
+ {
+ CTRACE(tfp, "STYLE:begin_element:ending EMPTY element style\n");
+ do_cstyle_flush(me);
+#if !defined(USE_HASH)
+ HText_characterStyle(me->text, element_number+STARTAT, STACK_OFF);
+#else
+ HText_characterStyle(me->text, hcode, STACK_OFF);
+#endif /* USE_HASH */
+ TrimColorClass(HTML_dtd.tags[element_number].name,
+ Style_className, &hcode);
+ }
+#endif /* USE_COLOR_STYLE */
}
/* End Element
@@ -358,6 +537,24 @@
if (element_number == HTML_PRE) {
me->preformatted = NO;
}
+#ifdef USE_COLOR_STYLE
+ /*
+ * Same logic as in HTML_end_element, copied from there. - kw
+ */
+ TrimColorClass(HTML_dtd.tags[element_number].name,
+ Style_className, &hcode);
+
+ if (LYPreparsedSource && !REALLY_EMPTY(element_number))
+ {
+ CTRACE(tfp, "STYLE:end_element: ending non-EMPTY style\n");
+ do_cstyle_flush(me);
+#if !defined(USE_HASH)
+ HText_characterStyle(me->text, element_number+STARTAT, STACK_OFF);
+#else
+ HText_characterStyle(me->text, hcode, STACK_OFF);
+#endif /* USE_HASH */
+ }
+#endif /* USE_COLOR_STYLE */
}
/* Expanding entities
@@ -388,6 +585,9 @@
(*me->targetClass.put_character)(me->target, '\n');
HTMLGen_flush(me);
(*me->targetClass._free)(me->target); /* ripple through */
+#ifdef USE_COLOR_STYLE
+ FREE(Style_className);
+#endif
FREE(me);
}
@@ -403,6 +603,9 @@
HTError, e GCC_UNUSED)
{
HTMLGen_free(me);
+#ifdef USE_COLOR_STYLE
+ FREE(Style_className);
+#endif
}
PRIVATE void PlainToHTML_abort ARGS2(
@@ -431,7 +634,6 @@
extern int LYcols; /* LYCurses.h, set in LYMain.c */
extern BOOL dump_output_immediately; /* TRUE if no interactive user */
extern int dump_output_width; /* -width instead of 80 */
-extern BOOLEAN LYPreparsedSource; /* Show source as preparsed? */
PUBLIC HTStructured * HTMLGenerator ARGS1(
HTStream *, output)
@@ -481,6 +683,12 @@
* purposes we'll use the new hex format.
*/
me->escape_specials = LYPreparsedSource;
+
+#ifdef USE_COLOR_STYLE
+ me->text = NULL; /* Will be initialized when first needed. - kw */
+ FREE(Style_className);
+ class_string[0] = '\0';
+#endif /* COLOR_STYLE */
return me;
}
--- lynx2-8-2.old/WWW/Library/Implementation/HTAnchor.c Thu Mar 4 04:39:44 1999
+++ lynx2-8-2/WWW/Library/Implementation/HTAnchor.c Tue Mar 16 07:42:14 1999
@@ -805,8 +805,13 @@
!((HTChildAnchor *)me)->tag) { /* it's an adult or no tag */
StrAllocCopy(addr, me->parent->address);
} else { /* it's a named child */
- HTSprintf0(&addr, "%s#%s",
- me->parent->address, ((HTChildAnchor *)me)->tag);
+ addr = malloc(2 +
+ strlen(me->parent->address) +
+ strlen(((HTChildAnchor *)me)->tag));
+ if (addr == NULL)
+ outofmem(__FILE__, "HTAnchor_address");
+ sprintf(addr, "%s#%s",
+ me->parent->address, ((HTChildAnchor *)me)->tag);
}
}
return(addr);
--- lynx2-8-2.old/samples/lynx.lss Sat Dec 13 17:30:40 1997
+++ lynx2-8-2/samples/lynx.lss Mon Mar 15 21:30:56 1999
@@ -1,60 +1,75 @@
#
#it's best to put these in a .lss file and use "lynx -lss=file.lss whatever"
for now.
#
-#----/cut here for my styles/----
-# normal type styles, use bold if mono, otherwise brightblue on
<defaultbackground>
+# Normal type styles.
+# next line means: use bold if mono, otherwise brightblue on
<defaultbackground>
em:bold:brightblue
strong:bold:brightred
b:bold:red
-i:bold:blue
-alink:reverse:yellow:black
+i:bold:brightblue
a:bold:green
img:dim:brown
-status:reverse:yellow:blue
fig:normal:gray
caption:reverse:brown
hr:normal:yellow
blockquote:normal:brightblue
ul:normal:brown
address:normal:magenta
-title:normal:magenta:default
-tt:dim:gray:blue
+title:normal:magenta
+tt:dim:brightmagenta:default
h1:bold:yellow:blue
label:normal:magenta
-value:normal:green
-high:bold:brightmagenta
q:normal:yellow:magenta
-small:dim:gray
+small:dim:default
big:bold:yellow
sup:bold:yellow
sub:dim:gray
lh:bold:yellow:magenta
+li:normal:magenta
+code:normal:cyan
+cite:normal:cyan
+
+table:normal:brightcyan
+tr:bold:brown
+td:normal:default
+br:normal:default
+
+# Special styles - not corresponding directly to HTML tags
+#normal:normal:default:blue
+alink:reverse:yellow:black
+status:reverse:yellow:blue
+alert:bold:yellow:red
+whereis:reverse+underline:magenta:cyan
+# currently not used
+#value:normal:green
+#high:bold:brightmagenta
-# styles with classes <ul class=red> etc.
+# Styles with classes - <ul class=red> etc.
ul.red:underline:brightred
ul.blue:bold:brightblue
li.red:reverse:red:yellow
-li:normal:magenta
li.blue:bold:blue
strong.a:bold:black:red
em.a:reverse:black:blue
strong.b:bold:white:red
em.b:reverse:white:blue
-alert:bold:yellow:red
strong.debug:reverse:green
-tr:bold:brown
+font.letter:normal:default:blue
+input.submit:normal:cyan
tr.baone:bold:yellow
tr.batwo:bold:green
tr.bathree:bold:red
-# special cases for link - the type is appended after the class
+#
+# Special handling for link.
+link:normal:white
link.green:bold:brightgreen
-# special cases for link - the rel is appended after the class
+link.red:bold:black:red
+link.blue:bold:white:blue
+link.toc:bold:black:white
+# Special cases for link - the rel or title is appended after the class.
# <link rel=next class=red href="1">
link.red.next:bold:red
link.red.prev:bold:yellow:red
link.blue.prev:bold:yellow:blue
link.blue.next:bold:blue
-link.red:bold:black:red
-link.blue:bold:white:blue
-link.toc:bold:black:white
link.green.toc:bold:white:green
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- lynx-dev 2.8.2dev.19 patch 4 - color styles,
Klaus Weide <=