[Pinfo-devel] r231 - pinfo/branches/cxx/src
Nathanael Nerode
neroden-guest at costa.debian.org
Mon Sep 26 00:30:17 UTC 2005
Author: neroden-guest
Date: 2005-09-26 00:30:16 +0000 (Mon, 26 Sep 2005)
New Revision: 231
Modified:
pinfo/branches/cxx/src/common_includes.h
pinfo/branches/cxx/src/mainfunction.cxx
pinfo/branches/cxx/src/manual.cxx
pinfo/branches/cxx/src/video.cxx
Log:
Convert pos to 0-based in video.cxx.
Create macro to make uses of maxy more readable, in common_includes.h,
and use it throughout.
Slight reduction of duplicated code in video.cxx.
Modified: pinfo/branches/cxx/src/common_includes.h
===================================================================
--- pinfo/branches/cxx/src/common_includes.h 2005-09-25 23:38:24 UTC (rev 230)
+++ pinfo/branches/cxx/src/common_includes.h 2005-09-26 00:30:16 UTC (rev 231)
@@ -59,4 +59,11 @@
/* I hear voices, that it is needed by RH5.2 ;) */
#define _REGEX_RE_COMP
+
+/* This comes up appallingly often.
+ * Note that this is correct: maxy is one beyond the end of screen,
+ * and a header and footer line take up space as well.
+ */
+#define lines_visible (maxy - 2)
+
#endif
Modified: pinfo/branches/cxx/src/mainfunction.cxx
===================================================================
--- pinfo/branches/cxx/src/mainfunction.cxx 2005-09-25 23:38:24 UTC (rev 230)
+++ pinfo/branches/cxx/src/mainfunction.cxx 2005-09-26 00:30:16 UTC (rev 231)
@@ -181,7 +181,8 @@
if (key == ERR)
{
if (statusline == FREE) {
- showscreen(my_message, pos, cursor, infocolumn);
+ /* Convert back to 0-based. FIXME. */
+ showscreen(my_message, pos - 1, cursor, infocolumn);
}
waitforgetch();
key = pinfo_getch();
@@ -213,7 +214,7 @@
int wastoggled = toggled_by_menu;
toggled_by_menu = 0;
/* if hyperobject type <= 1, then we have a menu */
- if ((pos >= my_message.size() -(maxy - 2)) ||(wastoggled))
+ if ((pos >= my_message.size() -lines_visible) ||(wastoggled))
{
if ((infomenu != -1) &&(!wastoggled))
{
@@ -270,10 +271,10 @@
/* go to specified line */
newpos = atol(token_string.c_str());
newpos -=(maxy - 1);
- if ((newpos > 0) &&(newpos < my_message.size() -(maxy - 2)))
+ if ((newpos > 0) &&(newpos < my_message.size() -lines_visible))
pos = newpos;
- else if ((newpos > 0) &&((my_message.size() -(maxy - 2)) > 0))
- pos = my_message.size() -(maxy - 2);
+ else if ((newpos > 0) &&((my_message.size() -lines_visible) > 0))
+ pos = my_message.size() -lines_visible;
else
pos = 1;
}
@@ -850,7 +851,7 @@
if ((key == keys.end_1) ||
(key == keys.end_2))
{
- pos = my_message.size() -(maxy - 2);
+ pos = my_message.size() -lines_visible;
if (pos < 1)
pos = 1;
cursor = hyperobjects.size() - 1;
@@ -860,15 +861,15 @@
(key == keys.pgdn_2))
{
/* Signed/unsigned issues. FIXME */
- if (pos +(maxy - 2) < (signed)my_message.size() -(maxy - 2))
+ if (pos +lines_visible < (signed)my_message.size() -lines_visible)
{
- pos +=(maxy - 2);
+ pos +=lines_visible;
rescan_cursor();
}
/* Signed/unsigned issues. FIXME */
- else if ((signed)my_message.size() -(maxy - 2) >= 1)
+ else if ((signed)my_message.size() -lines_visible >= 1)
{
- pos = my_message.size() -(maxy - 2);
+ pos = my_message.size() -lines_visible;
cursor = hyperobjects.size() - 1;
}
else
@@ -888,8 +889,8 @@
if ((key == keys.pgup_1) |
(key == keys.pgup_2))
{
- if (pos >(maxy - 2))
- pos -=(maxy - 2);
+ if (pos >lines_visible)
+ pos -=lines_visible;
else
pos = 1;
rescan_cursor();
@@ -917,7 +918,7 @@
for (typeof(hyperobjects.size()) i = cursor + 1;
i < hyperobjects.size(); i++) {
if ((hyperobjects[i].line >= pos - 1) &&
- (hyperobjects[i].line < pos - 1 +(maxy - 2)))
+ (hyperobjects[i].line < pos - 1 +lines_visible))
{
if (hyperobjects[i].type < HIGHLIGHT)
{
@@ -930,13 +931,13 @@
if (!cursorchanged)
{
/* FIXME: signed/unsigned issues */
- if (pos <= (signed)my_message.size() -(maxy - 2))
+ if (pos <= (signed)my_message.size() -lines_visible)
pos++;
for (typeof(hyperobjects.size()) i = cursor + 1;
i < hyperobjects.size(); i++)
{
if ((hyperobjects[i].line >= pos - 1) &&
- (hyperobjects[i].line < pos - 1 +(maxy - 2)))
+ (hyperobjects[i].line < pos - 1 +lines_visible))
{
if (hyperobjects[i].type < HIGHLIGHT)
{
@@ -991,7 +992,7 @@
infohistory[infohistory.size() - 1].menu = cursor;
if ((cursor >= 0) && (cursor < hyperobjects.size()))
if ((hyperobjects[cursor].line >= pos - 1) &&
- (hyperobjects[cursor].line < pos - 1 +(maxy - 2)) ||
+ (hyperobjects[cursor].line < pos - 1 +lines_visible) ||
(toggled_by_menu))
{
toggled_by_menu = 0;
@@ -1197,7 +1198,7 @@
for (typeof(hyperobjects.size()) i = 0; i < hyperobjects.size(); i++)
{
if ((hyperobjects[i].line >= pos - 1) &&
- (hyperobjects[i].line < pos - 1 +(maxy - 2)))
+ (hyperobjects[i].line < pos - 1 +lines_visible))
{
if (hyperobjects[i].type < HIGHLIGHT)
{
Modified: pinfo/branches/cxx/src/manual.cxx
===================================================================
--- pinfo/branches/cxx/src/manual.cxx 2005-09-25 23:38:24 UTC (rev 230)
+++ pinfo/branches/cxx/src/manual.cxx 2005-09-26 00:30:16 UTC (rev 231)
@@ -809,11 +809,11 @@
newpos = atol(token_string.c_str());
newpos -=(maxy - 1);
/* FIXME signed/unsigned */
- if ((newpos >= 0) &&(newpos < (signed) manual.size() -(maxy - 2)))
+ if ((newpos >= 0) &&(newpos < (signed) manual.size() -(lines_visible)))
manualpos = newpos;
else if (newpos > 0)
/* FIXME signed/unsigned */
- manualpos = (signed) manual.size() -(maxy - 2);
+ manualpos = (signed) manual.size() -(lines_visible);
else
manualpos = 0;
}
@@ -1060,9 +1060,9 @@
(key == keys.pgdn_2))
{
/* FIXME signed/unsigned */
- if (manualpos +(maxy - 2) < (signed) manual.size() -(maxy - 1))
+ if (manualpos +(lines_visible) < (signed) manual.size() -(maxy - 1))
{
- manualpos +=(maxy - 2);
+ manualpos +=(lines_visible);
rescan_selected();
}
/* FIXME signed/unsigned */
@@ -1112,7 +1112,7 @@
for (typeof(manuallinks.size()) i = selected + 1;
i < manuallinks.size(); i++) {
if ((manuallinks[i].line >= manualpos) &&
- (manuallinks[i].line < manualpos +(maxy - 2))) {
+ (manuallinks[i].line < manualpos +(lines_visible))) {
selected = i;
selectedchanged = 1;
break;
@@ -1127,7 +1127,7 @@
for (typeof(manuallinks.size()) i = selected + 1;
i < manuallinks.size(); i++) {
if ((manuallinks[i].line >= manualpos) &&
- (manuallinks[i].line < manualpos +(maxy - 2))) {
+ (manuallinks[i].line < manualpos +(lines_visible))) {
selected = i;
selectedchanged = 1;
break;
@@ -1351,7 +1351,7 @@
attrset(normal);
/* print all visible text lines */
for (int i = manualpos;
- (i < manualpos + (maxy - 2)) && (i < manual.size());
+ (i < manualpos + (lines_visible)) && (i < manual.size());
i++) {
int len = manual[i].length();
if (len)
@@ -1386,7 +1386,7 @@
mymvhline(0, 0, ' ', maxx);
mymvhline(maxy - 1, 0, ' ', maxx);
move(maxy - 1, 0);
- if (((manualpos + maxy) < manual.size()) &&(manual.size() > maxy - 2))
+ if (((manualpos + maxy) < manual.size()) &&(manual.size() > lines_visible))
printw(_("Viewing line %d/%d, %d%%"),(manualpos - 1 + maxy), manual.size(),((manualpos - 1 + maxy) * 100) / manual.size());
else
printw(_("Viewing line %d/%d, 100%%"), manual.size(), manual.size());
@@ -1515,7 +1515,7 @@
{
/* if the object is on the current screen */
if ((manuallinks[i].line >= manualpos) &&
- (manuallinks[i].line < manualpos +(maxy - 2)))
+ (manuallinks[i].line < manualpos +(lines_visible)))
{
/* if it's a simple man link */
if (manuallinks[i].section_mark < HTTPSECTION)
Modified: pinfo/branches/cxx/src/video.cxx
===================================================================
--- pinfo/branches/cxx/src/video.cxx 2005-09-25 23:38:24 UTC (rev 230)
+++ pinfo/branches/cxx/src/video.cxx 2005-09-26 00:30:16 UTC (rev 231)
@@ -72,7 +72,6 @@
void
showscreen(const vector <string> message, long pos, long cursor, int column)
{
- /* pos is 1-based, message is 0-based */
#ifdef getmaxyx
getmaxyx(stdscr, maxy, maxx);
#endif
@@ -80,14 +79,14 @@
bkgdset(' ' | normal);
#endif
attrset(normal);
- for (long i = pos - 1; (i < message.size()) && (i + 1 < pos + maxy - 2); i++)
+ for (long i = pos; (i < message.size()) && (i < pos + lines_visible); i++)
{
/* Chop off trailing newline */
string tmpstr = message[i].substr(0, message[i].length() - 1);
if (tmpstr.length()>column)
- mvaddstr(i + 2 - pos, 0, tmpstr.substr(column).c_str());
+ mvaddstr(1 + i - pos, 0, tmpstr.substr(column).c_str());
else
- move(i + 2 - pos,0);
+ move(1 + i - pos,0);
#ifdef HAVE_BKGDSET
clrtoeol();
#else
@@ -101,11 +100,13 @@
attrset(bottomline);
mymvhline(maxy - 1, 0, ' ', maxx);
move(maxy - 1, 0);
- if ((pos < message.size() - 1) &&(message.size() > pos + maxy - 2))
- printw(_("Viewing line %d/%d, %d%%"), pos + maxy - 2,
- message.size(), ((pos + maxy - 2) * 100) / message.size());
- else
+ if (pos + lines_visible >= message.size()) {
printw(_("Viewing line %d/%d, 100%%"), message.size(), message.size());
+ } else {
+ /* 1-based printout */
+ printw(_("Viewing line %d/%d, %d%%"), pos + lines_visible,
+ message.size(), ((pos + lines_visible) * 100) / message.size());
+ }
info_add_highlights(pos, cursor, column, message);
attrset(normal);
move(0, 0);
@@ -142,9 +143,12 @@
info_add_highlights(int pos, int cursor, int column, const vector <string> message)
{
for (typeof(hyperobjects.size()) i = 0; i < hyperobjects.size(); i++) {
- if ((hyperobjects[i].line < pos - 1) ||
- (hyperobjects[i].line >= pos - 1 +(maxy - 2)))
- continue; /* Off screen */
+ if ( (hyperobjects[i].line < pos)
+ || (hyperobjects[i].line >= pos + lines_visible)
+ ) {
+ /* Off screen */
+ continue;
+ }
/* first set of ifs sets the required attributes */
if (hyperobjects[i].type < 2) { /* menu */
@@ -177,7 +181,7 @@
mynode += hyperobjects[i].node;
}
if (hyperobjects[i].breakpos == -1) {
- info_addstring(1 + hyperobjects[i].line + 1 - pos,
+ info_addstring(1 + hyperobjects[i].line - pos,
hyperobjects[i].col,
mynode,
column);
@@ -185,7 +189,7 @@
int j;
string part1, part2;
part1 = mynode.substr(0, hyperobjects[i].breakpos);
- info_addstring(1 + hyperobjects[i].line + 1 - pos,
+ info_addstring(1 + hyperobjects[i].line - pos,
hyperobjects[i].col,
part1,
column);
@@ -194,8 +198,8 @@
while (mynode[j] == ' ')
j++;
part2 = mynode.substr(j, string::npos);
- if (hyperobjects[i].line + 1 - pos + 3 < maxy)
- info_addstring(1 + hyperobjects[i].line + 1 - pos + 1,
+ if (hyperobjects[i].line + 1 < pos + lines_visible)
+ info_addstring(1 + hyperobjects[i].line - pos + 1,
j - hyperobjects[i].breakpos,
part2,
column);
@@ -204,40 +208,35 @@
}
#ifndef ___DONT_USE_REGEXP_SEARCH___
- if (h_regexp.size() > 0) {
- regmatch_t pmatch[1];
- for (int i = pos - 1;
- (i < message.size()) && (i + 1 < pos + (maxy - 2)); i++) {
- for (int j = 0; j < h_regexp.size(); j++) {
- const char * message_i = message[i].c_str();
- const char *rest_of_str = message_i;
- while (!regexec(&h_regexp[j], rest_of_str, 1, pmatch, 0)) {
- int num_chars = pmatch[0].rm_eo - pmatch[0].rm_so;
- int x = calculate_len(message_i, rest_of_str + pmatch[0].rm_so);
- int txtoffset = (rest_of_str - message_i) + pmatch[0].rm_so;
- string tmpstr = message[i].substr(txtoffset, num_chars);
- attrset(searchhighlight);
- mvaddstr(i + 1 - pos + 1, x, tmpstr.c_str());
- attrset(normal);
- rest_of_str = rest_of_str + pmatch[0].rm_eo;
- }
+ for (int i = pos;
+ (i < message.size()) && (i < pos + lines_visible); i++) {
+ for (int j = 0; j < h_regexp.size(); j++) {
+ regmatch_t pmatch[1];
+ const char * message_i = message[i].c_str();
+ const char * rest_of_str = message_i;
+ while (!regexec(&h_regexp[j], rest_of_str, 1, pmatch, 0)) {
+ int num_chars = pmatch[0].rm_eo - pmatch[0].rm_so;
+ int x = calculate_len(message_i, rest_of_str + pmatch[0].rm_so);
+ int txtoffset = (rest_of_str - message_i) + pmatch[0].rm_so;
+ string tmpstr = message[i].substr(txtoffset, num_chars);
+ attrset(searchhighlight);
+ mvaddstr(1 + i - pos, x, tmpstr.c_str());
+ attrset(normal);
+ rest_of_str = rest_of_str + pmatch[0].rm_eo;
}
}
- }
- /* Duplicate code, this time for the interactive search. */
- if (regex_is_current) {
- regmatch_t pmatch[1];
- for (int i = pos - 1;
- (i < message.size()) && (i + 1 < pos + (maxy - 2)); i++) {
+ if (regex_is_current) {
+ /* Duplicate code, this time for the interactive search. */
+ regmatch_t pmatch[1];
const char * message_i = message[i].c_str();
- const char *rest_of_str = message_i;
+ const char * rest_of_str = message_i;
while (!regexec(¤t_regex, rest_of_str, 1, pmatch, 0)) {
int num_chars = pmatch[0].rm_eo - pmatch[0].rm_so;
int x = calculate_len(message_i, rest_of_str + pmatch[0].rm_so);
int txtoffset = (rest_of_str - message_i) + pmatch[0].rm_so;
string tmpstr = message[i].substr(txtoffset, num_chars);
attrset(searchhighlight);
- mvaddstr(i + 1 - pos + 1, x, tmpstr.c_str());
+ mvaddstr(1 + i - pos, x, tmpstr.c_str());
attrset(normal);
rest_of_str = rest_of_str + pmatch[0].rm_eo;
}
More information about the Pinfo-devel
mailing list