about summary refs log tree commit diff stats
path: root/src/GridText.c
diff options
context:
space:
mode:
authorThomas E. Dickey <dickey@invisible-island.net>2018-02-20 00:44:42 +0000
committerThomas E. Dickey <dickey@invisible-island.net>2018-02-20 00:44:42 +0000
commitf498a252d549aec6eb894a6355c451f52e2eb632 (patch)
treeb4f5335aebd2e86f321b5cd57dc38fdb93af6ebd /src/GridText.c
parent9194f6cf75175976385fb46cf5721b28f397f433 (diff)
downloadlynx-snapshots-f498a252d549aec6eb894a6355c451f52e2eb632.tar.gz
snapshot of project "lynx", label v2-8-9dev_16f
Diffstat (limited to 'src/GridText.c')
-rw-r--r--src/GridText.c48
1 files changed, 33 insertions, 15 deletions
diff --git a/src/GridText.c b/src/GridText.c
index 885141ce..48e7459b 100644
--- a/src/GridText.c
+++ b/src/GridText.c
@@ -1,5 +1,5 @@
 /*
- * $LynxId: GridText.c,v 1.302 2017/07/04 17:27:07 tom Exp $
+ * $LynxId: GridText.c,v 1.306 2018/02/19 23:03:00 tom Exp $
  *
  *		Character grid hypertext object
  *		===============================
@@ -89,6 +89,8 @@ static void HText_trimHightext(HText *text, int final, int stop_before);
 HTkcode last_kcode = NOKANJI;	/* 1997/11/14 (Fri) 09:09:26 */
 #endif
 
+#undef  CHAR_WIDTH
+
 #ifdef CJK_EX
 #define CHAR_WIDTH 6
 #else
@@ -158,10 +160,19 @@ static void *LY_check_calloc(size_t nmemb, size_t size);
 #define ALIGN_SIZE      sizeof(double)
 #endif
 
+#define BITS_DIR	2
+#define BITS_POS	14
+
+#define MASK_DIR	((1U << BITS_DIR) - 1)
+#define CAST_DIR(n)	((MASK_DIR) & (unsigned)(n))
+
+#define MASK_POS	((1U << BITS_POS) - 1)
+#define CAST_POS(n)	((MASK_POS) & (unsigned)(n))
+
 typedef struct {
-    unsigned int sc_direction:2;	/* on or off */
-    unsigned int sc_horizpos:14;	/* horizontal position of this change */
-    unsigned int sc_style:16;	/* which style to change to */
+    unsigned sc_direction:BITS_DIR;	/* on or off */
+    unsigned sc_horizpos:BITS_POS;	/* horizontal position of this change */
+    unsigned sc_style:16;	/* which style to change to */
 } HTStyleChange;
 
 #if defined(USE_COLOR_STYLE)
@@ -2696,7 +2707,7 @@ static HTLine *insert_blanks_in_line(HTLine *line, int line_number,
 	     istyle < line->numstyles && (int) NStyle.sc_horizpos < curlim;
 	     istyle++)
 	    /* Should not we include OFF-styles at curlim? */
-	    NStyle.sc_horizpos += shift;
+	    NStyle.sc_horizpos = CAST_POS(NStyle.sc_horizpos + shift);
 #endif
 	while (copied < pre)	/* Copy verbatim to byte == pre */
 	    *t++ = *copied++;
@@ -2774,14 +2785,14 @@ static HTStyleChange *skip_matched_and_correct_offsets(HTStyleChange *end,
 	    }
 	}
 	if (tmp->sc_horizpos > split_pos) {
-	    tmp->sc_horizpos = split_pos;
+	    tmp->sc_horizpos = CAST_POS(split_pos);
 	}
     }
     return result;
 }
 #endif /* USE_COLOR_STYLE */
 
-#define reset_horizpos(value) value = 0, value = ~value
+#define reset_horizpos(value) value = 0, value ^= MASK_POS
 
 static void split_line(HText *text, unsigned split)
 {
@@ -3031,11 +3042,16 @@ static void split_line(HText *text, unsigned split)
 	while (from >= previous->styles && to >= line->styles) {
 	    *to = *from;
 	    if ((int) to->sc_horizpos > s_post) {
-		to->sc_horizpos += -s_post + SpecialAttrChars;
+		to->sc_horizpos = CAST_POS(to->sc_horizpos
+					   + SpecialAttrChars
+					   - s_post);
 	    } else if ((int) to->sc_horizpos > s_pre &&
 		       (to->sc_direction == STACK_ON ||
 			to->sc_direction == ABS_ON)) {
-		to->sc_horizpos = ((int) to->sc_horizpos < s) ? 0 : SpecialAttrChars;
+		if ((int) to->sc_horizpos < s)
+		    to->sc_horizpos = 0;
+		else
+		    to->sc_horizpos = CAST_POS(SpecialAttrChars);
 	    } else {
 		break;
 	    }
@@ -3078,7 +3094,7 @@ static void split_line(HText *text, unsigned split)
 		    at_end++;
 		    at_end->sc_direction = STACK_OFF;
 		    at_end->sc_style = scan->sc_style;
-		    at_end->sc_horizpos = s_pre;
+		    at_end->sc_horizpos = CAST_POS(s_pre);
 		    CTRACE_STYLE((tfp,
 				  "split_line, %d:style[%d] %d (dir=%d)\n",
 				  s_pre,
@@ -3093,7 +3109,7 @@ static void split_line(HText *text, unsigned split)
 		    to++;
 		else if (to >= line->styles) {
 		    *to = *scan;
-		    to->sc_horizpos = SpecialAttrChars;
+		    to->sc_horizpos = CAST_POS(SpecialAttrChars);
 		    to--;
 		} else {
 		    CTRACE((tfp, "BUG: style overflow after split_line.\n"));
@@ -3101,7 +3117,7 @@ static void split_line(HText *text, unsigned split)
 		}
 	    }
 	    if ((int) scan->sc_horizpos > s_pre) {
-		scan->sc_horizpos = s_pre;
+		scan->sc_horizpos = CAST_POS(s_pre);
 	    }
 	    scan--;
 	}
@@ -4533,7 +4549,7 @@ void _internal_HTC(HText *text, int style, int dir)
 	     */
 	    line->numstyles--;
 	} else if (line->numstyles < MAX_STYLES_ON_LINE) {
-	    line->styles[line->numstyles].sc_horizpos = line->size;
+	    line->styles[line->numstyles].sc_horizpos = CAST_POS(line->size);
 	    /*
 	     * Special chars for bold and underlining usually don't
 	     * occur with color style, but soft hyphen can.
@@ -4541,10 +4557,12 @@ void _internal_HTC(HText *text, int style, int dir)
 	     * counted as ctrl_chars.  - kw
 	     */
 	    if ((int) line->styles[line->numstyles].sc_horizpos >= ctrl_chars_on_this_line) {
-		line->styles[line->numstyles].sc_horizpos -= ctrl_chars_on_this_line;
+		line->styles[line->numstyles].sc_horizpos =
+		    CAST_POS(line->styles[line->numstyles].sc_horizpos
+			     - ctrl_chars_on_this_line);
 	    }
 	    line->styles[line->numstyles].sc_style = (unsigned short) style;
-	    line->styles[line->numstyles].sc_direction = dir;
+	    line->styles[line->numstyles].sc_direction = CAST_DIR(dir);
 	    CTRACE_STYLE((tfp, "internal_HTC %d:style[%d] %d (dir=%d)\n",
 			  line->size,
 			  line->numstyles,