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

Nathanael Nerode neroden-guest at costa.debian.org
Sun Sep 4 07:10:58 UTC 2005


Author: neroden-guest
Date: 2005-09-04 07:10:55 +0000 (Sun, 04 Sep 2005)
New Revision: 165

Modified:
   pinfo/branches/cxx/src/datatypes.cxx
   pinfo/branches/cxx/src/datatypes.h
   pinfo/branches/cxx/src/manual.cxx
   pinfo/branches/cxx/src/parse_config.cxx
   pinfo/branches/cxx/src/pinfo.cxx
   pinfo/branches/cxx/src/utils.cxx
   pinfo/branches/cxx/src/utils.h
Log:
Make manlinks a vector<string>, and rewrite stuff to make it work.


Modified: pinfo/branches/cxx/src/datatypes.cxx
===================================================================
--- pinfo/branches/cxx/src/datatypes.cxx	2005-09-04 00:54:10 UTC (rev 164)
+++ pinfo/branches/cxx/src/datatypes.cxx	2005-09-04 07:10:55 UTC (rev 165)
@@ -21,10 +21,13 @@
  ***************************************************************************/
 #include "common_includes.h"
 #include <string>
+using std::string;
 #include <vector>
-using std::string;
 using std::vector;
 
+/* for string_explode */
+#include "utils.h"
+
 int verbose = 1;
 
 string filenameprefix;
@@ -33,7 +36,12 @@
 string ftpviewer = "lynx";
 string maileditor = "mail";
 string printutility = "lpr";
-string manlinks = "1:8:2:3:4:5:6:7:9:n:l:p:o:3X11:3Xt:3X:3x";
+
+/* Normalize to uppercase (corresponding to elsewhere) */
+/* FIXME: standard list should be autodetermined by search */
+vector<string> manlinks = string_explode(
+		string_toupper(string("1:8:2:3:4:5:6:7:9:n:l:p:o:3X11:3Xt:3X:3x")),
+	':');
 string configuredinfopath = "/usr/share/info:/usr/local/share/info:/opt/info";
 string ignoredmacros = "";
 string rcfile = "";

Modified: pinfo/branches/cxx/src/datatypes.h
===================================================================
--- pinfo/branches/cxx/src/datatypes.h	2005-09-04 00:54:10 UTC (rev 164)
+++ pinfo/branches/cxx/src/datatypes.h	2005-09-04 07:10:55 UTC (rev 165)
@@ -106,7 +106,7 @@
 /* name of the printing utility */
 extern std::string printutility;
 /* man sections, considered to be highlighted  as links */
-extern std::string manlinks;
+extern std::vector<std::string> manlinks;
 /* configured paths to infopages */
 extern std::string configuredinfopath;
 /* groff/troff macros which are removed while preformatting manual page */

Modified: pinfo/branches/cxx/src/manual.cxx
===================================================================
--- pinfo/branches/cxx/src/manual.cxx	2005-09-04 00:54:10 UTC (rev 164)
+++ pinfo/branches/cxx/src/manual.cxx	2005-09-04 07:10:55 UTC (rev 165)
@@ -54,7 +54,7 @@
  * and are stored in `manuallinks' var, described bellow.
  */
 void man_initializelinks(string line, int carry);
-int is_in_manlinks(string in, char *find);
+bool is_in_manlinks(vector<string> in, string find);
 
 void printmanual(char **Message, long Lines);
 
@@ -604,7 +604,7 @@
 				*p_t = '\0';
 				link -=(strlen(p_t1) + sizeof(char));
 
-				if ((!strchr(p_t1, '(')) &&(!is_in_manlinks(manlinks, p_t1)))
+				if ( !strchr(p_t1, '(') && is_in_manlinks(manlinks, string(p_t1)) )
 				{
 					int breakpos;
 					int i = link - tmp - 1;
@@ -1673,35 +1673,14 @@
  * checks if a construction, which looks like hyperlink, belongs to the allowed
  * manual sections.
  */
-int
-is_in_manlinks(string in_str, char *find)
+bool
+is_in_manlinks(vector<string> manlinks, string to_find)
 {
-	char *copy, *token;
-	const char delimiters[] = ":";
-
-	copy = strdup(in_str.c_str());
-	if ((strcmp(find,(token = strtok(copy, delimiters))) != 0))
-	{
-		while ((token = strtok(NULL, delimiters)))
-		{
-#ifdef HAVE_STRCASECMP
-			if (!strcasecmp(token, find))
-#else
-				if (!strcmp(token, find))
-#endif
-				{
-					xfree((void *) copy);
-					return 0;
-				}
-		}
-		xfree((void *) copy);
-		return 1;
-	}
-	else
-	{
-		xfree((void *) copy);
-		return 0;
-	}
+	/* Normalize case */
+	string to_find_uppercase = string_toupper(to_find);
+	typeof(manlinks.begin()) result_iter;
+	result_iter = std::find(manlinks.begin(), manlinks.end(), to_find_uppercase);
+	return (result_iter != manlinks.end()); /* True if found */
 }
 
 void

Modified: pinfo/branches/cxx/src/parse_config.cxx
===================================================================
--- pinfo/branches/cxx/src/parse_config.cxx	2005-09-04 00:54:10 UTC (rev 164)
+++ pinfo/branches/cxx/src/parse_config.cxx	2005-09-04 07:10:55 UTC (rev 165)
@@ -639,7 +639,9 @@
 		if (temp)
 		{
 			string tmpstr = temp;
-			manlinks = remove_quotes(tmpstr);
+			/* Normalize to uppercase, like everywhere else manlinks is used */
+			string manlinks_str = string_toupper(remove_quotes(tmpstr));
+			manlinks = string_explode(manlinks_str, ':');
 		}
 		else
 			return 1;

Modified: pinfo/branches/cxx/src/pinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/pinfo.cxx	2005-09-04 00:54:10 UTC (rev 164)
+++ pinfo/branches/cxx/src/pinfo.cxx	2005-09-04 07:10:55 UTC (rev 165)
@@ -240,17 +240,17 @@
 		{
 			if (verbose)
 				printf(_("Looking for man page...\n"));
-			string filename_string;
+			string filename_string2;
 			/*
 			 * pass all arguments to the `man' command(manhandler calls
 			 * `man')
 			 */
 			for (int i = 1; i < argc; i++)
 			{
-				filename_string.append(argv[i]);
-				filename_string.append(" ");
+				filename_string2.append(argv[i]);
+				filename_string2.append(" ");
 			}
-			exit(handlemanual(filename_string));
+			exit(handlemanual(filename_string2));
 		}
 
 	/* Break out getopts to make main() smaller */

Modified: pinfo/branches/cxx/src/utils.cxx
===================================================================
--- pinfo/branches/cxx/src/utils.cxx	2005-09-04 00:54:10 UTC (rev 164)
+++ pinfo/branches/cxx/src/utils.cxx	2005-09-04 07:10:55 UTC (rev 165)
@@ -531,3 +531,34 @@
 	getmaxyx(stdscr, maxy, maxx);
 	ungetch(keys.refresh_1);
 }
+
+/*
+ * Create a vector of strings.  If the strings are concatenated together
+ * with separator in between them, the original string will be recovered.
+ */
+vector<string>
+string_explode(string to_explode, string::value_type separator) {
+	vector<string> result;
+	
+	string::size_type old_idx = 0;
+	string::size_type new_idx = to_explode.find(separator, old_idx);
+	while (new_idx != string::npos) {
+		result.push_back(to_explode.substr(old_idx, new_idx - old_idx));
+		old_idx = new_idx + 1;
+		new_idx = to_explode.find(separator, old_idx);
+	}
+	/* Get the last one */
+	result.push_back(to_explode.substr(old_idx));
+
+	return result;
+}
+
+string
+string_toupper(string str)
+{
+	for (string::size_type i = 0; i < str.length(); i++)
+		if (islower(str[i]))
+			str[i] = toupper(str[i]);
+	return str;
+}
+

Modified: pinfo/branches/cxx/src/utils.h
===================================================================
--- pinfo/branches/cxx/src/utils.h	2005-09-04 00:54:10 UTC (rev 164)
+++ pinfo/branches/cxx/src/utils.h	2005-09-04 07:10:55 UTC (rev 165)
@@ -88,4 +88,11 @@
 /* is curses screen open? */
 extern int curses_open;
 
+/* Explode a string into a vector */
+std::vector<std::string>
+string_explode(std::string to_explode, std::string::value_type separator);
+
+/* Return a string converted to uppercase */
+std::string string_toupper (std::string s);
+
 #endif




More information about the Pinfo-devel mailing list