[Pinfo-devel] r295 - pinfo/trunk/src

Bas Zoetekouw bas at costa.debian.org
Wed Mar 15 21:52:39 UTC 2006


Author: bas
Date: 2006-03-15 21:52:38 +0000 (Wed, 15 Mar 2006)
New Revision: 295

Modified:
   pinfo/trunk/src/initializelinks.c
   pinfo/trunk/src/utils.c
   pinfo/trunk/src/utils.h
   pinfo/trunk/src/video.c
Log:
Fix highlighting of search terms, and moved calculate_len() to utils.c


Modified: pinfo/trunk/src/initializelinks.c
===================================================================
--- pinfo/trunk/src/initializelinks.c	2006-03-15 12:49:21 UTC (rev 294)
+++ pinfo/trunk/src/initializelinks.c	2006-03-15 21:52:38 UTC (rev 295)
@@ -84,33 +84,6 @@
 		return 0;
 }
 
-/*
- * calculates the length of string between start and end, counting `\t' as
- * filling up to 8 chars. (i.e. at line 22 tab will increment the counter by 2
- * [8-(22-int(22/8)*8)] spaces)
- */
-int
-calculate_len(char *start, char *end)
-{
-	int len = 0;
-	char *c = start;
-	while (c < end)
-	{
-		if (*c == '\t')
-		{
-			/* now, first count everything leading up to this position */
-			len += width_of_string(start, c - start);
-			start = c+1;
-			/* then add the extra width of the tab */
-			len = ( len & ~0x07 ) + 0x08;
-		}
-		c++;
-	}
-	/* then count everything after the last tab */
-	len += width_of_string(start, c - start);
-	
-	return len;
-}
 
 void
 freelinks()			/* frees space allocated previously by node-links */

Modified: pinfo/trunk/src/utils.c
===================================================================
--- pinfo/trunk/src/utils.c	2006-03-15 12:49:21 UTC (rev 294)
+++ pinfo/trunk/src/utils.c	2006-03-15 21:52:38 UTC (rev 295)
@@ -669,3 +669,31 @@
 
 	return width;
 }
+
+/*
+ * calculates the length of string between start and end, counting `\t' as
+ * filling up to 8 chars. (i.e. at line 22 tab will increment the counter by 2
+ * [8-(22-int(22/8)*8)] spaces)
+ */
+int
+calculate_len(char *start, char *end)
+{
+	int len = 0;
+	char *c = start;
+	while (c < end)
+	{
+		if (*c == '\t')
+		{
+			/* now, first count everything leading up to this position */
+			len += width_of_string(start, c - start);
+			start = c+1;
+			/* then add the extra width of the tab */
+			len = ( len & ~0x07 ) + 0x08;
+		}
+		c++;
+	}
+	/* then count everything after the last tab */
+	len += width_of_string(start, c - start);
+	
+	return len;
+}

Modified: pinfo/trunk/src/utils.h
===================================================================
--- pinfo/trunk/src/utils.h	2006-03-15 12:49:21 UTC (rev 294)
+++ pinfo/trunk/src/utils.h	2006-03-15 21:52:38 UTC (rev 295)
@@ -95,5 +95,12 @@
 int
 width_of_string( const char * const mbs, const int len);
 
+/*
+ * calculates the length of string between start and end, counting `\t' as
+ * filling up to 8 chars. (i.e. at line 22 tab will increment the counter by 2
+ * [8-(22-int(22/8)*8)] spaces)
+ */
+int
+calculate_len(char *start, char *end);
 
 #endif

Modified: pinfo/trunk/src/video.c
===================================================================
--- pinfo/trunk/src/video.c	2006-03-15 12:49:21 UTC (rev 294)
+++ pinfo/trunk/src/video.c	2006-03-15 21:52:38 UTC (rev 295)
@@ -264,33 +264,56 @@
 		regmatch_t pmatch[1];
 		long maxpos = pos +(maxy - 2);
 		if (maxpos > lines)
+		{
 			maxpos = lines;
+		}
+
+		int maxregexp = aftersearch ? h_regexp_num + 1 : h_regexp_num;
+		/*
+		 * if it is after search, then we have user defined regexps+
+		 * a searched regexp to highlight
+		 */
+		/* loop over all the lines currently in the window */
+		for (i = pos; (i < lines) && (i < pos + maxy - 2); i++)
 		{
-			int maxregexp = aftersearch ? h_regexp_num + 1 : h_regexp_num;
-			/*
-			 * if it is after search, then we have user defined regexps+
-			 * a searched regexp to highlight
-			 */
+			char *str = message[i];
+
+			/* loop over all regexps we might want to show */
 			int j;
 			for (j = 0; j < maxregexp; j++)
 			{
-				char *str = message[i];
+				/* check if this regexp is present on this line */
 				while (!regexec(&h_regexp[j], str, 1, pmatch, 0))
 				{
+					/* yes, found something, so highlight it */
 					int n = pmatch[0].rm_eo - pmatch[0].rm_so;
-					int y = i - pos + 1, x = calculate_len(message[i], pmatch[0].rm_so + str);
-					int txtoffset = pmatch[0].rm_so + str - message[i];
-					char tmp;
-					tmp = message[i][x + n];
-					message[i][x + n] = 0;
+
+					/* point str at start of match */
+					str += pmatch[0].rm_so;
+
+					/* calculate position on screen */
+					int x = calculate_len(message[i], str);
+					int y = i - pos + 1;
+
+					/* save the char after the end of the match, 
+					 * and replace it by \0 */
+					char tmp = str[n];
+					str[n] = 0;
+					
+					/* write out the highlighted match to screen */
 					attrset(searchhighlight);
-					mvaddstr(y, x, message[i] + txtoffset);
+					mvaddstr(y, x, str);
 					attrset(normal);
-					message[i][x + n] = tmp;
-					str = str + pmatch[0].rm_eo;
+
+					/* restore the original char at the end of the match */
+					str[n] = tmp;
+
+					/* skip past this match */
+					str += n;
 				}
 			}
 		}
 	}
+
 #endif
 }




More information about the Pinfo-devel mailing list