[Pinfo-devel] r228 - pinfo/branches/cxx/src
Nathanael Nerode
neroden-guest at costa.debian.org
Sun Sep 25 21:47:11 UTC 2005
Author: neroden-guest
Date: 2005-09-25 21:47:10 +0000 (Sun, 25 Sep 2005)
New Revision: 228
Modified:
pinfo/branches/cxx/src/mainfunction.cxx
pinfo/branches/cxx/src/mainfunction.h
pinfo/branches/cxx/src/manual.cxx
pinfo/branches/cxx/src/pinfo.cxx
pinfo/branches/cxx/src/regexp_search.cxx
pinfo/branches/cxx/src/regexp_search.h
pinfo/branches/cxx/src/video.cxx
Log:
Restructure the search code; it should be mostly working again, except
for a nasty off-by-one error related to 'pos'.
Modified: pinfo/branches/cxx/src/mainfunction.cxx
===================================================================
--- pinfo/branches/cxx/src/mainfunction.cxx 2005-09-23 06:50:03 UTC (rev 227)
+++ pinfo/branches/cxx/src/mainfunction.cxx 2005-09-25 21:47:10 UTC (rev 228)
@@ -39,7 +39,6 @@
int getnodeoffset(int tag_table_pos,
typeof(indirect.size())& indirectstart); /* get node offset in file */
-int aftersearch = 0;
/*
* this flag is turned on when the engine receives a simulated `key.back',
* caused by the sequential auto-pgdn reading code
@@ -50,8 +49,9 @@
int cursor;
+/* Line found by global search, to jump to. -1 if not after global search. */
+int found_line = -1;
-
/* Inline support functions formerly in menu_and_note_utils.cxx */
/*
@@ -150,10 +150,11 @@
pos = npos; /* set eventual history pos */
/* if we're in a node found using 's'earch function. */
- if (aftersearch)
+ if (found_line != -1)
{
- pos = aftersearch; /* set pos to the found position */
- /* aftersearch=0; * don't reset this--we want to know if we mus highlight something */
+ pos = found_line;
+ /* set pos to the found position */
+ found_line = -1;
}
if (ncursor != -1)
@@ -317,10 +318,6 @@
rval.file = "dir";
rval.node = "";
rval.keep_going = true;
- if (aftersearch) {
- aftersearch = 0;
- h_regexp.pop_back();
- }
return rval;
}
/*==========================================================================*/
@@ -336,7 +333,7 @@
if ((key == keys.totalsearch_1) || /* search in all nodes later than this one */
(key == keys.totalsearch_2))
{
- int tmpaftersearch = aftersearch;
+ int tmpfound_line = found_line;
indirectstart = -1;
move(maxy - 1, 0);
attrset(bottomline);
@@ -378,7 +375,7 @@
fileoffset += getnodeoffset(tag_table_pos, indirectstart); /* also load the variable indirectstart */
/* Searching part... */
- aftersearch = 0;
+ found_line = -1;
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
return_value = -1;
@@ -424,7 +421,8 @@
*/
tokenpos += starttokenpos;
{ /* local scope for tmpvar, matched */
- int tmpvar = -1, matched = 0;
+ int tmpvar = -1;
+ int matched = 0;
for (int i = tag_table.size() - 1; i >= 0; i--)
{
if ((tag_table[i].offset > tag_table[tmpvar].offset) &&
@@ -436,58 +434,51 @@
}
}
}
- /* this means, that indirect entry was found. */
- if (return_value != -1)
- {
+ if (return_value != -1) {
+ /* this means, that indirect entry was found. */
fseek(fd, tag_table[return_value].offset - indirect[j].offset + FirstNodeOffset, SEEK_SET);
/* seek to the found node offset */
while (fgetc(fd) != INFO_TAG);
fgetc(fd); /* skip newline */
- aftersearch = 1;
+ found_line = 0;
/*
- * count, how many lines stands befor the token
- * line.
+ * count how many lines are before the token line.
*/
while (ftell(fd) < tokenpos)
{
int chr = fgetc(fd);
if (chr == '\n')
- aftersearch++;
+ found_line++;
else if (chr == EOF)
break;
}
/*
- * the number ofline where a token is found, is
- * now in the variable `aftersearch'
+ * the number of the line where the token was found, is
+ * now in the variable `found_line'
*/
- if (aftersearch > 1)
- aftersearch--;
- else
- aftersearch = 1;
- } /* end: if (indirect entry was found) */
- if (aftersearch) /* if something was found */
- {
- if (tmp) /* free tmp buffer */
- {
+ /* something was found */
+ if (tmp) {
delete [] tmp;
tmp = 0;
}
break;
- }
- } /* end: if (tokenpos) */
- if (tmp) /* free tmp buffer */
- {
+ /* end: if (indirect entry was found) */
+ }
+ /* end: if (tokenpos) */
+ }
+ if (tmp) {
delete [] tmp;
tmp = 0;
}
- } /* end: indirect file loop */
+ /* end: indirect file loop */
+ }
fclose(fd);
- } /* end: if (indirect) */
- else /* if not indirect */
- /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- {
+ /* end: if (indirect) */
+ } else {
+ /* if not indirect */
+ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
long filelen;
long filepos = ftell(id);
long tokenpos;
@@ -542,21 +533,17 @@
while (fgetc(id) != INFO_TAG);
fgetc(id); /* skip newline */
- aftersearch = 1;
+ found_line = 0;
/* count lines in found node, until found line is
* met. */
while (ftell(id) < tokenpos)
{
int chr = fgetc(id);
if (chr == '\n')
- aftersearch++;
+ found_line++;
else if (chr == EOF)
break;
}
- if (aftersearch > 1)
- aftersearch--;
- else
- aftersearch = 1;
fseek(id, filepos, SEEK_SET); /* seek to old
* filepos. */
}
@@ -566,31 +553,30 @@
delete tmp;
tmp = 0;
}
- } /* end: if (!indirect) */
+ /* end: if (!indirect) */
+ }
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- if (!aftersearch)
- {
+ if (found_line == -1) {
attrset(bottomline);
mvaddstr(maxy - 1, 0, _("Search string not found..."));
statusline = LOCKED;
}
- if (!aftersearch)
- aftersearch = tmpaftersearch;
-
- if (return_value != -1)
- {
+ if (return_value != -1) {
infohistory[infohistory.size() - 1].pos = pos;
infohistory[infohistory.size() - 1].cursor = cursor;
infohistory[infohistory.size() - 1].menu = infomenu;
rval.node = tag_table[return_value].nodename;
rval.file = "";
rval.keep_going = true;
- /* NOTE: This is the only case where aftersearch is not reset */
+ regex_is_global = true;
+ regex_is_current = true;
return rval;
}
- } /* end: if key_totalsearch */
+ found_line = tmpfound_line;
+ /* end: if key_totalsearch */
+ }
/*==========================================================================*/
if ((key == keys.search_1) || /* search in current node */
(key == keys.search_2))
@@ -653,7 +639,8 @@
/* otherwise, pos=i. This happens when we have a split expression. */
pos = i;
}
- aftersearch = 1;
+ regex_is_current = true;
+ regex_is_global = false;
break;
}
}
@@ -708,10 +695,6 @@
rval.node = tag_table[return_value].nodename;
rval.file = "";
rval.keep_going = true;
- if (aftersearch) {
- aftersearch = 0;
- h_regexp.pop_back();
- }
return rval;
} else {
/* the name wasn't in tag table */
@@ -732,10 +715,6 @@
rval.node = "";
}
rval.keep_going = true;
- if (aftersearch) {
- aftersearch = 0;
- h_regexp.pop_back();
- }
return rval;
}
} else if ( (token_string.length() > 5)
@@ -744,10 +723,6 @@
/* handle the `file.info' format of crossinfo goto. */
rval.file = token_string;
rval.node = "";
- if (aftersearch) {
- aftersearch = 0;
- h_regexp.pop_back();
- }
rval.keep_going = true;
return rval;
} else {
@@ -776,10 +751,6 @@
rval.node = tag_table[return_value].nodename;
rval.file = "";
rval.keep_going = true;
- if (aftersearch) {
- aftersearch = 0;
- h_regexp.pop_back();
- }
return rval;
}
}
@@ -798,10 +769,6 @@
rval.node = tag_table[return_value].nodename;
rval.file = "";
rval.keep_going = true;
- if (aftersearch) {
- aftersearch = 0;
- h_regexp.pop_back();
- }
return rval;
}
}
@@ -826,10 +793,6 @@
rval.node = tag_table[return_value].nodename;
rval.file = "";
rval.keep_going = true;
- if (aftersearch) {
- aftersearch = 0;
- h_regexp.pop_back();
- }
return rval;
}
}
@@ -997,10 +960,6 @@
rval.node = FirstNodeName;
rval.file = "";
rval.keep_going = true;
- if (aftersearch) {
- aftersearch = 0;
- h_regexp.pop_back();
- }
return rval;
}
/*==========================================================================*/
@@ -1020,10 +979,6 @@
ncursor = infohistory[infohistory.size() - 1].cursor;
nmenu = infohistory[infohistory.size() - 1].menu;
dellastinfohistory(); /* remove history entry for previous node */
- if (aftersearch) {
- aftersearch = 0;
- h_regexp.pop_back();
- }
return rval;
}
}
@@ -1047,10 +1002,6 @@
rval.node = hyperobjects[cursor].node;
rval.file = hyperobjects[cursor].file;
rval.keep_going = true;
- if (aftersearch) {
- aftersearch = 0;
- h_regexp.pop_back();
- }
return rval;
}
else if (hyperobjects[cursor].type < HIGHLIGHT) /* we deal with an url */
@@ -1222,10 +1173,6 @@
}
}
}
- if (aftersearch) {
- aftersearch = 0;
- h_regexp.pop_back();
- }
return rval;
}
Modified: pinfo/branches/cxx/src/mainfunction.h
===================================================================
--- pinfo/branches/cxx/src/mainfunction.h 2005-09-23 06:50:03 UTC (rev 227)
+++ pinfo/branches/cxx/src/mainfunction.h 2005-09-25 21:47:10 UTC (rev 228)
@@ -38,8 +38,9 @@
}
WorkRVal;
-/* this determines whether we are in a position, found after search */
-extern int aftersearch;
+/* line to jump to within node, if we got here as a result of global
+ * search; -1 if we didn't just do a global search. */
+extern int found_line;
/*
* this is main function which handles almost all of the work (keyboard
Modified: pinfo/branches/cxx/src/manual.cxx
===================================================================
--- pinfo/branches/cxx/src/manual.cxx 2005-09-23 06:50:03 UTC (rev 227)
+++ pinfo/branches/cxx/src/manual.cxx 2005-09-25 21:47:10 UTC (rev 228)
@@ -20,8 +20,10 @@
* USA
***************************************************************************/
#include "common_includes.h"
+#include "regexp_search.h"
#include "tmpfiles.h"
+
#include <ctype.h>
#include <sys/stat.h>
#include <string>
@@ -69,9 +71,6 @@
int manualcol = 0; /* the first displayed column of manpage--
for moving the screen left/right */
-int manual_aftersearch = 0; /* this is set if man page is now after search
- operation */
-
/*
* type for the `lastread' history entries, when viewing
* man pages.
@@ -327,11 +326,8 @@
getmaxyx(stdscr, maxy, maxx);
check_manwidth();
- if (manual_aftersearch) {
- /* Clear regexp from prior page */
- h_regexp.pop_back();
- manual_aftersearch = 0;
- }
+ /* Changing page, so clear regexp */
+ regex_is_current = false;
/* -1 is quit key */
if (return_value != -1)
@@ -936,8 +932,8 @@
strip_manual(tmpstr);
/* execute search */
- if (pinfo_re_exec(tmpstr.c_str()))
- { /* if found, enter here... */
+ if (pinfo_re_exec(tmpstr.c_str())) {
+ /* if found, enter here... */
success = 1;
string newtmpstr = manual[i + 1];
strip_manual(newtmpstr);
@@ -959,8 +955,7 @@
mvaddstr(maxy - 1, 0, _("Search string not found..."));
statusline = LOCKED;
}
-
- manual_aftersearch = 1;
+ regex_is_current = true;
}
/*=====================================================*/
/* search again */
@@ -1404,7 +1399,7 @@
mvaddstr_manual(int y, int x, string my_str)
{
static string strippedline_string;
- if (h_regexp.size() > 0) {
+ if ((h_regexp.size() > 0) || regex_is_current) {
strippedline_string = my_str;
strip_manual(strippedline_string);
}
@@ -1487,6 +1482,27 @@
}
}
}
+ /* Duplicate code, this time for the interactive search */
+ if (regex_is_current) {
+ regmatch_t pmatch[1];
+ const char* strippedline = strippedline_string.c_str();
+ const char* tmpstr = strippedline;
+ while (!regexec(¤t_regex, tmpstr, 1, pmatch, 0)) {
+ int n = pmatch[0].rm_eo - pmatch[0].rm_so;
+ int rx = pmatch[0].rm_so + tmpstr - strippedline;
+ int curY, curX;
+ getyx(stdscr, curY, curX);
+
+ attrset(searchhighlight);
+ string str_to_print;
+ str_to_print.assign(strippedline_string, rx, n);
+ mvaddstr(y, rx, str_to_print.c_str());
+ attrset(normal);
+
+ tmpstr = tmpstr + pmatch[0].rm_eo;
+ move(curY, curX);
+ }
+ }
#endif
}
Modified: pinfo/branches/cxx/src/pinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/pinfo.cxx 2005-09-23 06:50:03 UTC (rev 227)
+++ pinfo/branches/cxx/src/pinfo.cxx 2005-09-25 21:47:10 UTC (rev 228)
@@ -400,35 +400,33 @@
filenotfound = 0;
work_return_value = work(message, type, id, tag_table_pos);
- if (work_return_value.keep_going)
- {
- /* no cross-file link selected */
- if (work_return_value.file[0] == 0)
- {
+ if (work_return_value.keep_going) {
+ /* Reset regexp */
+ if (!regex_is_global) {
+ regex_is_current = false;
+ }
+ if (work_return_value.file[0] == 0) {
+ /* no cross-file link selected */
int tmppos = gettagtablepos(work_return_value.node);
if (tmppos != -1)
tag_table_pos = tmppos;
- }
- else /* file was specified */
- {
+ } else {
+ /* file was specified */
strip_info_suffix_from_file(work_return_value.file);
- /* file name was the same with the file currently viewed */
- if (curfile == work_return_value.file)
- {
+ if (curfile == work_return_value.file) {
+ /* file name was the same as the file currently viewed */
int tmppos = gettagtablepos(work_return_value.node);
if (tmppos != -1)
tag_table_pos = tmppos;
- }
- else /* open new info file */
- {
+ } else {
+ /* open new info file */
fclose(id);
/* Reset global filenameprefix */
filenameprefix.clear();
id = openinfo(work_return_value.file, 0);
- /* if the file doesn't exist */
- if (id == NULL)
- {
+ if (id == NULL) {
+ /* if the file doesn't exist */
attrset(bottomline);
mvhline(maxy - 1, 0, ' ', maxx);
mvaddstr(maxy - 1, 0, _("File not found. Press any key..."));
@@ -436,24 +434,21 @@
attrset(normal);
getch();
filenotfound = 1;
- if (infohistory.size())
- {
+ if (infohistory.size()) {
npos = infohistory[infohistory.size() - 1].pos;
ncursor = infohistory[infohistory.size() - 1].pos;
}
- /* open back the old file */
+ /* open the old file back up */
strip_info_suffix_from_file(curfile);
string tmpstr = curfile;
id = openinfo(tmpstr, 0);
- if (id == NULL)
- {
+ if (id == NULL) {
closeprogram();
printf(_("Unexpected error.\n"));
return 1;
}
- }
- else /* if we succeeded in opening new file */
- {
+ } else {
+ /* we succeeded in opening new file */
curfile = work_return_value.file;
indirect.clear();
/* find the indirect entry */
Modified: pinfo/branches/cxx/src/regexp_search.cxx
===================================================================
--- pinfo/branches/cxx/src/regexp_search.cxx 2005-09-23 06:50:03 UTC (rev 227)
+++ pinfo/branches/cxx/src/regexp_search.cxx 2005-09-25 21:47:10 UTC (rev 228)
@@ -29,7 +29,11 @@
#include <regex.h>
#include <ctype.h>
-vector<regex_t> h_regexp; /* regexps to highlight */
+vector<regex_t> h_regexp; /* configured regexps to highlight */
+regex_t current_regex; /* Selected interactively */
+bool prior_regex = false; /* No prior regexes */
+bool regex_is_current = false; /* No regex yet */
+bool regex_is_global = false; /* Regex not global */
#endif
#ifdef ___DONT_USE_REGEXP_SEARCH___
@@ -51,17 +55,13 @@
pinfo_re_pattern = strdup(name);
return 0;
#else
- if (pinfo_re_offset == -1)
- {
- pinfo_re_offset = h_regexp.size();
- regex_t my_regex_t;
- h_regexp.push_back(my_regex_t);
+ if (prior_regex) {
+ regfree(¤t_regex);
}
- else
- {
- regfree(&h_regexp[pinfo_re_offset]);
- }
- return regcomp(&h_regexp[pinfo_re_offset], name, REG_ICASE);
+ int result;
+ result = regcomp(¤t_regex, name, REG_ICASE);
+ prior_regex = true;
+ return result;
#endif
}
@@ -80,7 +80,7 @@
}
#else
regmatch_t pmatch[1];
- return !regexec(&h_regexp[pinfo_re_offset], name, 1, pmatch, 0);
+ return !regexec(¤t_regex, name, 1, pmatch, 0);
#endif
}
@@ -119,27 +119,17 @@
}
}
flags |= REG_EXTENDED;
- if (pinfo_re_offset == -1)
- {
- pinfo_re_offset = h_regexp.size();
- regex_t my_regex_t;
- h_regexp.push_back(my_regex_t);
- /* FIXME: this is supposed to be an 'extra' which doesn't add to
- the number of regexps */
+ if (prior_regex) {
+ regfree(¤t_regex);
}
- else
- {
- regfree(&h_regexp[pinfo_re_offset]);
- }
/* invalid regexp */
- if (regcomp(&h_regexp[pinfo_re_offset], pattern, flags))
- {
+ if (regcomp(¤t_regex, pattern, flags)) {
return 0;
}
old_pattern = strdup(pattern);
old_type = match_type;
}
- rval = regexec(&h_regexp[pinfo_re_offset], string, 1, pmatch, 0);
+ rval = regexec(¤t_regex, string, 1, pmatch, 0);
if (rval != 0)
return -1;
else
Modified: pinfo/branches/cxx/src/regexp_search.h
===================================================================
--- pinfo/branches/cxx/src/regexp_search.h 2005-09-23 06:50:03 UTC (rev 227)
+++ pinfo/branches/cxx/src/regexp_search.h 2005-09-25 21:47:10 UTC (rev 228)
@@ -38,7 +38,10 @@
#ifndef ___DONT_USE_REGEXP_SEARCH___
-extern std::vector<regex_t> h_regexp; /* regexps to highlight */
+extern std::vector<regex_t> h_regexp; /* compiled regexps to highlight */
+extern regex_t current_regex; /* current regex to highlight */
+extern bool regex_is_current; /* Should we highlight it? */
+extern bool regex_is_global; /* Search transcends node boundaries */
int regexp_search (const char *pattern, char *string);
#endif
Modified: pinfo/branches/cxx/src/video.cxx
===================================================================
--- pinfo/branches/cxx/src/video.cxx 2005-09-23 06:50:03 UTC (rev 227)
+++ pinfo/branches/cxx/src/video.cxx 2005-09-25 21:47:10 UTC (rev 228)
@@ -204,21 +204,14 @@
}
#ifndef ___DONT_USE_REGEXP_SEARCH___
- if (h_regexp.size() > 0)
- {
+ if (h_regexp.size() > 0) {
regmatch_t pmatch[1];
for (int i = pos - 1;
(i < message.size()) && (i + 1 < pos + (maxy - 2)); i++) {
- /*
- * if it is after search, then we have user defined regexps+
- * a searched regexp to highlight
- */
- for (int j = 0; j < h_regexp.size(); j++)
- {
+ 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))
- {
+ 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;
@@ -231,5 +224,24 @@
}
}
}
+ /* 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++) {
+ const char * message_i = message[i].c_str();
+ 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());
+ attrset(normal);
+ rest_of_str = rest_of_str + pmatch[0].rm_eo;
+ }
+ }
+ }
#endif
}
More information about the Pinfo-devel
mailing list