[Pinfo-devel] r175 - pinfo/branches/cxx/src

Nathanael Nerode neroden-guest at costa.debian.org
Tue Sep 6 12:30:53 UTC 2005


Author: neroden-guest
Date: 2005-09-06 12:30:52 +0000 (Tue, 06 Sep 2005)
New Revision: 175

Modified:
   pinfo/branches/cxx/src/mainfunction.cxx
   pinfo/branches/cxx/src/video.cxx
Log:
Zero-base use of message in video.cxx, and fix obnoxious off-by-one errors
at the same time.


Modified: pinfo/branches/cxx/src/mainfunction.cxx
===================================================================
--- pinfo/branches/cxx/src/mainfunction.cxx	2005-09-06 12:16:55 UTC (rev 174)
+++ pinfo/branches/cxx/src/mainfunction.cxx	2005-09-06 12:30:52 UTC (rev 175)
@@ -182,13 +182,9 @@
 				/* Quick conversion to vector.  Temporary, FIXME. */
 				vector<string> my_message;
 				for (typeof(my_message.size()) x = 0; x < Lines; x++) {
-					if ((*message)[x] == NULL) {
-						my_message.push_back("");
-						/* Yaah, FIXME.  index 0 is funky. */
-					} else {
-						string foo = (*message)[x];
-						my_message.push_back(foo);
-					}
+					/* one-based to zero-based conversion, ick */
+					string foo = (*message)[x + 1];
+					my_message.push_back(foo);
 				}
 				showscreen(my_message, pos, cursor, infocolumn);
 			}

Modified: pinfo/branches/cxx/src/video.cxx
===================================================================
--- pinfo/branches/cxx/src/video.cxx	2005-09-06 12:16:55 UTC (rev 174)
+++ pinfo/branches/cxx/src/video.cxx	2005-09-06 12:30:52 UTC (rev 175)
@@ -72,6 +72,7 @@
 void
 showscreen(const vector <string> message, long pos, long cursor, int column)
 {
+	/* pos is 1-based, message is 0-based */
 	long i;
 #ifdef getmaxyx
 	getmaxyx(stdscr, maxy, maxx);
@@ -80,16 +81,14 @@
 	bkgdset(' ' | normal);
 #endif
 	attrset(normal);
-	for (i = pos;(i < message.size()) &&(i < pos + maxy - 2); i++)
+	for (long i = pos - 1; (i < message.size()) && (i + 1 < pos + maxy - 2); i++)
 	{
-		if (message[i] == "") continue;
-
 		/* Chop off trailing newline */
 		string tmpstr = message[i].substr(0, message[i].length() - 1);
 		if (tmpstr.length()>column)
-			mvaddstr(i + 1 - pos, 0, tmpstr.substr(column).c_str());
+			mvaddstr(i + 2 - pos, 0, tmpstr.substr(column).c_str());
 		else
-			move(i + 1 - pos,0);
+			move(i + 2 - pos,0);
 #ifdef HAVE_BKGDSET
 		clrtoeol();
 #else
@@ -214,7 +213,7 @@
 		long maxpos = pos +(maxy - 2);
 		if (maxpos > message.size())
 			maxpos = message.size();
-		for (int i = pos; i < maxpos; i++)
+		for (int i = pos - 1; i < maxpos; i++)
 		{
 			int maxregexp = aftersearch ? h_regexp_num + 1 : h_regexp_num;
 			/*
@@ -228,12 +227,11 @@
 				while (!regexec(&h_regexp[j], str, 1, pmatch, 0))
 				{
 					int n = pmatch[0].rm_eo - pmatch[0].rm_so;
-					int y = i - pos + 1;
 					int x = calculate_len(message_i, pmatch[0].rm_so + str);
 					int txtoffset = (str - message_i) + pmatch[0].rm_so;
 					string tmpstr = message[i].substr(txtoffset, x + n);
 					attrset(searchhighlight);
-					mvaddstr(y, x, tmpstr.c_str());
+					mvaddstr(i + 1 - pos + 1, x, tmpstr.c_str());
 					attrset(normal);
 					str = str + pmatch[0].rm_eo;
 				}




More information about the Pinfo-devel mailing list