[Pinfo-devel] r201 - pinfo/branches/cxx/src
Nathanael Nerode
neroden-guest at costa.debian.org
Wed Sep 7 07:54:02 UTC 2005
Author: neroden-guest
Date: 2005-09-07 07:54:01 +0000 (Wed, 07 Sep 2005)
New Revision: 201
Modified:
pinfo/branches/cxx/src/manual.cxx
pinfo/branches/cxx/src/parse_config.cxx
pinfo/branches/cxx/src/parse_config.h
pinfo/branches/cxx/src/regexp_search.cxx
pinfo/branches/cxx/src/regexp_search.h
pinfo/branches/cxx/src/utils.cxx
pinfo/branches/cxx/src/utils.h
pinfo/branches/cxx/src/video.cxx
Log:
Isolate most of the regexp code into regexp_search.cxx.
Fix an off-by-one display error in video.cxx (sigh).
Fix a wrong-length display error in video.cxx.
Generally make the regexp code in video.cxx more readable.
Modified: pinfo/branches/cxx/src/manual.cxx
===================================================================
--- pinfo/branches/cxx/src/manual.cxx 2005-09-07 06:58:19 UTC (rev 200)
+++ pinfo/branches/cxx/src/manual.cxx 2005-09-07 07:54:01 UTC (rev 201)
@@ -1411,7 +1411,7 @@
mvaddstr_manual(int y, int x, string my_str)
{
static string strippedline_string;
- if ((h_regexp_num) ||(manual_aftersearch))
+ if ((h_regexp.size() > 0) ||(manual_aftersearch))
{
strippedline_string = my_str;
strip_manual(strippedline_string);
@@ -1470,10 +1470,10 @@
#endif
attrset(normal);
#ifndef ___DONT_USE_REGEXP_SEARCH___
- if ((h_regexp_num) ||(manual_aftersearch))
+ if ((h_regexp.size() > 0) ||(manual_aftersearch))
{
regmatch_t pmatch[1];
- int maxregexp = manual_aftersearch ? h_regexp_num + 1 : h_regexp_num;
+ int maxregexp = manual_aftersearch ? h_regexp.size() + 1 : h_regexp.size();
/* if it is after search, then we have user defined regexps+
a searched regexp to highlight */
Modified: pinfo/branches/cxx/src/parse_config.cxx
===================================================================
--- pinfo/branches/cxx/src/parse_config.cxx 2005-09-07 06:58:19 UTC (rev 200)
+++ pinfo/branches/cxx/src/parse_config.cxx 2005-09-07 07:54:01 UTC (rev 201)
@@ -23,16 +23,16 @@
#include "common_includes.h"
#include "datatypes.h"
#include "colors.h"
+#include "regexp_search.h"
#include <string>
using std::string;
+#include <vector>
+using std::vector;
#include <ctype.h>
#define COLOR_DEFAULT -1 /* mutt uses this was for transparency */
-regex_t *h_regexp = 0; /* regexps to highlight */
-int h_regexp_num = 0; /* number of those regexps */
-
struct keybindings keys =
{
's', 'S', /* regexp search */
@@ -666,12 +666,9 @@
string tmpstr = temp;
string tmpstr2 = remove_quotes(tmpstr);
const char *tmp = tmpstr2.c_str();
- if (!h_regexp_num)
- h_regexp = (regex_t*)malloc(sizeof(regex_t));
- else
- h_regexp = (regex_t*)realloc(h_regexp, sizeof(regex_t) *(h_regexp_num + 1));
- regcomp(&h_regexp[h_regexp_num], tmp, 0);
- h_regexp_num++;
+ regex_t my_regex_t;
+ h_regexp.push_back(my_regex_t);
+ regcomp(&h_regexp[h_regexp.size() - 1], tmp, 0);
}
else
return 1;
Modified: pinfo/branches/cxx/src/parse_config.h
===================================================================
--- pinfo/branches/cxx/src/parse_config.h 2005-09-07 06:58:19 UTC (rev 200)
+++ pinfo/branches/cxx/src/parse_config.h 2005-09-07 07:54:01 UTC (rev 201)
@@ -3,6 +3,7 @@
*
* Copyright (C) 1999 Przemek Borys <pborys at dione.ids.pl>
* Copyright (C) 2005 Bas Zoetekouw <bas at debian.org>
+ * Copyright 2005 Nathanael Nerode <neroden at gcc.gnu.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License as
@@ -22,10 +23,6 @@
#ifndef __PARSE_CONFIG_H
#define __PARSE_CONFIG_H
-#ifndef ___DONT_USE_REGEXP_SEARCH___
-#include <regex.h>
-#endif
-
#define BOLD 1
#define NO_BOLD 0
#define BLINK 1
@@ -92,9 +89,4 @@
char *str_toupper (char *s);
char *skip_whitespace (char *s);
-#ifndef ___DONT_USE_REGEXP_SEARCH___
-extern regex_t *h_regexp; /* regexps to highlight */
-extern int h_regexp_num; /* number of those regexps */
#endif
-
-#endif
Modified: pinfo/branches/cxx/src/regexp_search.cxx
===================================================================
--- pinfo/branches/cxx/src/regexp_search.cxx 2005-09-07 06:58:19 UTC (rev 200)
+++ pinfo/branches/cxx/src/regexp_search.cxx 2005-09-07 07:54:01 UTC (rev 201)
@@ -3,6 +3,7 @@
*
* Copyright (C) 1999 Przemek Borys <pborys at dione.ids.pl>
* Copyright (C) 2005 Bas Zoetekouw <bas at debian.org>
+ * Copyright 2005 Nathanael Nerode <neroden at gcc.gnu.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License as
@@ -19,11 +20,72 @@
* USA
***************************************************************************/
-#include"common_includes.h"
+#include "common_includes.h"
+#include <vector>
+using std::vector;
#ifndef ___DONT_USE_REGEXP_SEARCH___
-#include"regex.h"
-#include<ctype.h>
+
+#include <regex.h>
+#include <ctype.h>
+
+vector<regex_t> h_regexp; /* regexps to highlight */
+#endif
+
+#ifdef ___DONT_USE_REGEXP_SEARCH___
+char *pinfo_re_pattern = 0;
+#else
+int pinfo_re_offset = -1;
+#endif
+
+/* returns 0 on success, 1 on error */
+int
+pinfo_re_comp(const char *name)
+{
+#ifdef ___DONT_USE_REGEXP_SEARCH___
+ if (pinfo_re_pattern)
+ {
+ free(pinfo_re_pattern);
+ pinfo_re_pattern = 0;
+ }
+ 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);
+ }
+ else
+ {
+ regfree(&h_regexp[pinfo_re_offset]);
+ }
+ return regcomp(&h_regexp[pinfo_re_offset], name, REG_ICASE);
+#endif
+}
+
+int
+pinfo_re_exec(const char *name)
+{
+#ifdef ___DONT_USE_REGEXP_SEARCH___
+ char *found;
+ if (pinfo_re_pattern)
+ {
+ found = strstr(name, pinfo_re_pattern);
+ if (found != NULL)
+ return 1;
+ else
+ return 0;
+ }
+#else
+ regmatch_t pmatch[1];
+ return !regexec(&h_regexp[pinfo_re_offset], name, 1, pmatch, 0);
+#endif
+}
+
+#ifndef ___DONT_USE_REGEXP_SEARCH___
+
/* adapted partialy from midnight commander view regexp search */
enum
@@ -59,11 +121,9 @@
flags |= REG_EXTENDED;
if (pinfo_re_offset == -1)
{
- pinfo_re_offset = h_regexp_num;
- if (!h_regexp_num)
- h_regexp = (regex_t*)malloc(sizeof(regex_t));
- else
- h_regexp = (regex_t*)realloc(h_regexp, sizeof(regex_t) *(h_regexp_num + 1));
+ pinfo_re_offset = h_regexp.size();
+ regex_t my_regex_t;
+ h_regexp.push_back(my_regex_t);
}
else
{
Modified: pinfo/branches/cxx/src/regexp_search.h
===================================================================
--- pinfo/branches/cxx/src/regexp_search.h 2005-09-07 06:58:19 UTC (rev 200)
+++ pinfo/branches/cxx/src/regexp_search.h 2005-09-07 07:54:01 UTC (rev 201)
@@ -21,8 +21,25 @@
#ifndef __REGEXP_SEARCH_H
#define __REGEXP_SEARCH_H
+
#ifndef ___DONT_USE_REGEXP_SEARCH___
-extern int pinfo_re_offset;
+#include <vector>
+#include <regex.h>
+#endif
+
+/* wrappers for re_comp and re_exec */
+int pinfo_re_comp (const char *name);
+int pinfo_re_exec (const char *name);
+
+#ifdef ___DONT_USE_REGEXP_SEARCH___
+extern char *pinfo_re_pattern;
+#endif
+
+#ifndef ___DONT_USE_REGEXP_SEARCH___
+
+extern std::vector<regex_t> h_regexp; /* regexps to highlight */
+
int regexp_search (char *pattern, char *string);
#endif
+
#endif
Modified: pinfo/branches/cxx/src/utils.cxx
===================================================================
--- pinfo/branches/cxx/src/utils.cxx 2005-09-07 06:58:19 UTC (rev 200)
+++ pinfo/branches/cxx/src/utils.cxx 2005-09-07 07:54:01 UTC (rev 201)
@@ -27,7 +27,6 @@
#include <vector>
using std::vector;
-#include <regex.h>
#include <ctype.h>
string safe_user = "nobody";
@@ -40,12 +39,6 @@
}
#endif
-#ifdef ___DONT_USE_REGEXP_SEARCH___
-char *pinfo_re_pattern = 0;
-#else
-int pinfo_re_offset = -1;
-#endif
-
/* Readline */
#include <readline/readline.h>
#include <readline/history.h>
@@ -391,55 +384,7 @@
select(1, &rdfs, NULL, NULL, NULL);
}
-/* returns 0 on success, 1 on error */
int
-pinfo_re_comp(const char *name)
-{
-#ifdef ___DONT_USE_REGEXP_SEARCH___
- if (pinfo_re_pattern)
- {
- free(pinfo_re_pattern);
- pinfo_re_pattern = 0;
- }
- pinfo_re_pattern = strdup(name);
- return 0;
-#else
- if (pinfo_re_offset == -1)
- {
- pinfo_re_offset = h_regexp_num;
- if (!h_regexp_num)
- h_regexp = (regex_t*)malloc(sizeof(regex_t));
- else
- h_regexp = (regex_t*)realloc(h_regexp, sizeof(regex_t) *(h_regexp_num + 1));
- }
- else
- {
- regfree(&h_regexp[pinfo_re_offset]);
- }
- return regcomp(&h_regexp[pinfo_re_offset], name, REG_ICASE);
-#endif
-}
-
-int
-pinfo_re_exec(const char *name)
-{
-#ifdef ___DONT_USE_REGEXP_SEARCH___
- char *found;
- if (pinfo_re_pattern)
- {
- found = strstr(name, pinfo_re_pattern);
- if (found != NULL)
- return 1;
- else
- return 0;
- }
-#else
- regmatch_t pmatch[1];
- return !regexec(&h_regexp[pinfo_re_offset], name, 1, pmatch, 0);
-#endif
-}
-
-int
yesno(const char *prompt, int def)
{
const char *yes = _("yes");
Modified: pinfo/branches/cxx/src/utils.h
===================================================================
--- pinfo/branches/cxx/src/utils.h 2005-09-07 06:58:19 UTC (rev 200)
+++ pinfo/branches/cxx/src/utils.h 2005-09-07 07:54:01 UTC (rev 201)
@@ -33,14 +33,6 @@
void curs_set (int a);
#endif
-#ifdef ___DONT_USE_REGEXP_SEARCH___
-extern char *pinfo_re_pattern;
-#endif
-
-/* wrappers for re_comp and re_exec */
-int pinfo_re_comp (const char *name);
-int pinfo_re_exec (const char *name);
-
/* user defined getch, capable of handling ALT keybindings */
int pinfo_getch ();
/* free() wrapper */
Modified: pinfo/branches/cxx/src/video.cxx
===================================================================
--- pinfo/branches/cxx/src/video.cxx 2005-09-07 06:58:19 UTC (rev 200)
+++ pinfo/branches/cxx/src/video.cxx 2005-09-07 07:54:01 UTC (rev 201)
@@ -207,15 +207,13 @@
}
#ifndef ___DONT_USE_REGEXP_SEARCH___
- if ((h_regexp_num) ||(aftersearch))
+ if ((h_regexp.size() > 0) ||(aftersearch))
{
regmatch_t pmatch[1];
- long maxpos = pos +(maxy - 2);
- if (maxpos > message.size())
- maxpos = message.size();
- for (int i = pos - 1; i < maxpos; i++)
+ for (int i = pos - 1;
+ (i < message.size()) && (i + 1 < pos + (maxy - 2)); i++)
{
- int maxregexp = aftersearch ? h_regexp_num + 1 : h_regexp_num;
+ int maxregexp = aftersearch ? h_regexp.size() + 1 : h_regexp.size();
/*
* if it is after search, then we have user defined regexps+
* a searched regexp to highlight
@@ -223,17 +221,17 @@
for (int j = 0; j < maxregexp; j++)
{
const char * message_i = message[i].c_str();
- const char *str = message_i;
- while (!regexec(&h_regexp[j], str, 1, pmatch, 0))
+ const char *rest_of_str = message_i;
+ while (!regexec(&h_regexp[j], rest_of_str, 1, pmatch, 0))
{
- int n = pmatch[0].rm_eo - pmatch[0].rm_so;
- 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);
+ 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);
- str = str + pmatch[0].rm_eo;
+ rest_of_str = rest_of_str + pmatch[0].rm_eo;
}
}
}
More information about the Pinfo-devel
mailing list