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

Nathanael Nerode neroden-guest at costa.debian.org
Tue Aug 30 06:27:23 UTC 2005


Author: neroden-guest
Date: 2005-08-30 06:27:21 +0000 (Tue, 30 Aug 2005)
New Revision: 74

Modified:
   pinfo/branches/cxx/src/datatypes.cxx
   pinfo/branches/cxx/src/datatypes.h
   pinfo/branches/cxx/src/filehandling_functions.cxx
   pinfo/branches/cxx/src/mainfunction.cxx
   pinfo/branches/cxx/src/manual.cxx
   pinfo/branches/cxx/src/parse_config.cxx
   pinfo/branches/cxx/src/parse_config.h
   pinfo/branches/cxx/src/pinfo.cxx
   pinfo/branches/cxx/src/printinfo.cxx
   pinfo/branches/cxx/src/utils.cxx
   pinfo/branches/cxx/src/utils.h
Log:
Convert some global variables to std::string, with some cleanup
as fallout.  (There are lots of other infelicities, like use of global
variables, use of strtok, and extremely bad header file usage, which
remain untouched.)



Modified: pinfo/branches/cxx/src/datatypes.cxx
===================================================================
--- pinfo/branches/cxx/src/datatypes.cxx	2005-08-29 08:21:59 UTC (rev 73)
+++ pinfo/branches/cxx/src/datatypes.cxx	2005-08-30 06:27:21 UTC (rev 74)
@@ -30,12 +30,12 @@
 
 string filenameprefix;
 
-char *httpviewer = "lynx";
-char *ftpviewer = "lynx";
-char *maileditor = "mail";
-char *printutility = "lpr";
-char *manlinks = "1:8:2:3:4:5:6:7:9:n:l:p:o:3X11:3Xt:3X:3x";
-char *configuredinfopath = "/usr/share/info:/usr/local/share/info:/opt/info";
+string httpviewer = "lynx";
+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";
+string configuredinfopath = "/usr/share/info:/usr/local/share/info:/opt/info";
 char *ignoredmacros = 0;
 char *rcfile = NULL;
 
@@ -58,8 +58,8 @@
 int CutEmptyManLines = 0;
 int ForceManualTagTable = 0;
 int LongManualLinks = 0;
-char *ManOptions = "";
-char *StderrRedirection = "2> /dev/null";
+string ManOptions = "";
+string StderrRedirection = "2> /dev/null";
 int FilterB7 = 0;
 int ConfirmQuit = 0;
 int QuitConfirmDefault = 0;

Modified: pinfo/branches/cxx/src/datatypes.h
===================================================================
--- pinfo/branches/cxx/src/datatypes.h	2005-08-29 08:21:59 UTC (rev 73)
+++ pinfo/branches/cxx/src/datatypes.h	2005-08-30 06:27:21 UTC (rev 74)
@@ -98,17 +98,17 @@
 extern std::string filenameprefix;
 
 /* name of http viewer (i.e. lynx) */
-extern char *httpviewer;
+extern std::string httpviewer;
 /* name of ftp viewer */
-extern char *ftpviewer;
+extern std::string ftpviewer;
 /* name of maileditor */
-extern char *maileditor;
+extern std::string maileditor;
 /* name of the printing utility */
-extern char *printutility;
+extern std::string printutility;
 /* man sections, considered to be highlighted  as links */
-extern char *manlinks;
+extern std::string manlinks;
 /* configured paths to infopages */
-extern char *configuredinfopath;
+extern std::string configuredinfopath;
 /* groff/troff macros which are removed while preformatting manual page */
 extern char *ignoredmacros;
 /* a user specified rc file */
@@ -165,9 +165,9 @@
  * of 3) */
 extern int LongManualLinks;
 /* options passed to the `man' program */
-extern char *ManOptions;
+extern std::string ManOptions;
 /* shell code to redirect stderr output */
-extern char *StderrRedirection;
+extern std::string StderrRedirection;
 /* convert 0xb7 values in man pages to 'o'? */
 extern int FilterB7;
 /* determines if pinfo should ask for quit confirmation */

Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx	2005-08-29 08:21:59 UTC (rev 73)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx	2005-08-30 06:27:21 UTC (rev 74)
@@ -808,11 +808,11 @@
 	{
 		env = emptystr;
 	}
-	infolen = strlen(env) + strlen(configuredinfopath) + 2;
+	infolen = strlen(env) + configuredinfopath.length() + 2;
 	infopath = (char *) xmalloc( infolen );
 	strcat(infopath, env);
 	strcat(infopath, ":");
-	strcat(infopath, configuredinfopath);
+	strcat(infopath, configuredinfopath.c_str());
 
 	/* alloc the paths[] array */
 	maxpaths = 3 * (charcount( infopath, ':' ) + 1); // *3 for $LANG

Modified: pinfo/branches/cxx/src/mainfunction.cxx
===================================================================
--- pinfo/branches/cxx/src/mainfunction.cxx	2005-08-29 08:21:59 UTC (rev 73)
+++ pinfo/branches/cxx/src/mainfunction.cxx	2005-08-30 06:27:21 UTC (rev 74)
@@ -1016,8 +1016,8 @@
 						{
 							if (hyperobjects[cursor].type == 4)	/* http */
 							{
-								char *tempbuf = (char*)xmalloc(hyperobjects[cursor].node.length() + strlen(httpviewer) + 10);
-								strcpy(tempbuf, httpviewer);
+								char *tempbuf = (char*)xmalloc(hyperobjects[cursor].node.length() + httpviewer.length() + 10);
+								strcpy(tempbuf, httpviewer.c_str());
 								strcat(tempbuf, " ");
 								strcat(tempbuf, hyperobjects[cursor].node.c_str());
 								myendwin();
@@ -1027,8 +1027,8 @@
 							}
 							else if (hyperobjects[cursor].type == 5)	/* ftp */
 							{
-								char *tempbuf = (char*)xmalloc(hyperobjects[cursor].node.length() + strlen(ftpviewer) + 10);
-								strcpy(tempbuf, ftpviewer);
+								char *tempbuf = (char*)xmalloc(hyperobjects[cursor].node.length() + ftpviewer.length() + 10);
+								strcpy(tempbuf, ftpviewer.c_str());
 								strcat(tempbuf, " ");
 								strcat(tempbuf, hyperobjects[cursor].node.c_str());
 								myendwin();
@@ -1038,8 +1038,8 @@
 							}
 							else if (hyperobjects[cursor].type == 6)	/* mail */
 							{
-								char *tempbuf = (char*)xmalloc(hyperobjects[cursor].node.length() + strlen(maileditor) + 10);
-								strcpy(tempbuf, maileditor);
+								char *tempbuf = (char*)xmalloc(hyperobjects[cursor].node.length() + maileditor.length() + 10);
+								strcpy(tempbuf, maileditor.c_str());
 								strcat(tempbuf, " ");
 								strcat(tempbuf, hyperobjects[cursor].node.c_str());
 								myendwin();

Modified: pinfo/branches/cxx/src/manual.cxx
===================================================================
--- pinfo/branches/cxx/src/manual.cxx	2005-08-29 08:21:59 UTC (rev 73)
+++ pinfo/branches/cxx/src/manual.cxx	2005-08-30 06:27:21 UTC (rev 74)
@@ -52,7 +52,7 @@
  * and are stored in `manuallinks' var, described bellow.
  */
 void man_initializelinks(char *line, int carry);
-int is_in_manlinks(char *in, char *find);
+int is_in_manlinks(string in, char *find);
 
 void printmanual(char **Message, long Lines);
 
@@ -289,9 +289,9 @@
 
 	if (!plain_apropos)
 		snprintf(cmd, 255, "man %s %s %s > %s",
-				ManOptions,
+				ManOptions.c_str(),
 				name.c_str(),
-				StderrRedirection,
+				StderrRedirection.c_str(),
 				tmpfilename1);
 	if ((plain_apropos) ||(system(cmd) != 0))
 	{
@@ -360,10 +360,10 @@
 			{
 				construct_manualname(manualname_string, return_value);
 				snprintf(cmd, 255, "man %s %s %s %s > %s",
-						ManOptions,
+						ManOptions.c_str(),
 						manuallinks[return_value].section,
 						manualname_string.c_str(),
-						StderrRedirection,
+						StderrRedirection.c_str(),
 						tmpfilename2);
 			}
 			else /* key_back was pressed */
@@ -378,16 +378,16 @@
 				}
 				if (manualhistory[manualhistorylength].sect[0] == 0)
 					snprintf(cmd, 255, "man %s %s %s > %s",
-							ManOptions,
+							ManOptions.c_str(),
 							manualhistory[manualhistorylength].name,
-							StderrRedirection,
+							StderrRedirection.c_str(),
 							tmpfilename2);
 				else
 					snprintf(cmd, 255, "man %s %s %s %s > %s",
-							ManOptions,
+							ManOptions.c_str(),
 							manualhistory[manualhistorylength].sect,
 							manualhistory[manualhistorylength].name,
-							StderrRedirection,
+							StderrRedirection.c_str(),
 							tmpfilename2);
 				/*
 				 * flag to make sure, that
@@ -1704,12 +1704,12 @@
  * manual sections.
  */
 int
-is_in_manlinks(char *in, char *find)
+is_in_manlinks(string in_str, char *find)
 {
 	char *copy, *token;
 	const char delimiters[] = ":";
 
-	copy = strdup(in);
+	copy = strdup(in_str.c_str());
 	if ((strcmp(find,(token = strtok(copy, delimiters))) != 0))
 	{
 		while ((token = strtok(NULL, delimiters)))
@@ -1741,7 +1741,7 @@
 	FILE *prnFD;
 	int i;
 
-	prnFD = popen(printutility, "w");
+	prnFD = popen(printutility.c_str(), "w");
 
 	/* scan through all lines */
 	for (i = 0; i < Lines; i++)

Modified: pinfo/branches/cxx/src/parse_config.cxx
===================================================================
--- pinfo/branches/cxx/src/parse_config.cxx	2005-08-29 08:21:59 UTC (rev 73)
+++ pinfo/branches/cxx/src/parse_config.cxx	2005-08-30 06:27:21 UTC (rev 74)
@@ -20,6 +20,7 @@
  ***************************************************************************/
 
 #include "common_includes.h"
+#include "datatypes.h"
 #include <string>
 using std::string;
 
@@ -38,10 +39,9 @@
 extern int use_manual;
 extern int use_raw_filename;
 extern int quote_ignored;
-extern char *httpviewer;
-extern char *ftpviewer;
-extern char *maileditor;
-extern char *manlinks;
+extern string httpviewer;
+extern string ftpviewer;
+extern string maileditor;
 extern char *ignoredmacros;
 
 struct keybindings keys =
@@ -100,6 +100,9 @@
 };
 #endif /* NO_COLOR_CURSES */
 
+/* Forward declarations */
+string remove_quotes(const string);
+
 int
 parse_config(void)
 {
@@ -584,8 +587,8 @@
 		temp = strtok(NULL, "\n");
 		if (temp)
 		{
-			httpviewer = strdup(temp);
-			remove_quotes(httpviewer);
+			string tmpstr = temp;
+			httpviewer = remove_quotes(tmpstr);
 		}
 		else
 			return 1;
@@ -595,8 +598,8 @@
 		temp = strtok(NULL, "\n");
 		if (temp)
 		{
-			ftpviewer = strdup(temp);
-			remove_quotes(ftpviewer);
+			string tmpstr = temp;
+			ftpviewer = remove_quotes(tmpstr);
 		}
 		else
 			return 1;
@@ -606,8 +609,8 @@
 		temp = strtok(NULL, "\n");
 		if (temp)
 		{
-			maileditor = strdup(temp);
-			remove_quotes(maileditor);
+			string tmpstr = temp;
+			maileditor = remove_quotes(tmpstr);
 		}
 		else
 			return 1;
@@ -617,8 +620,8 @@
 		temp = strtok(NULL, "\n");
 		if (temp)
 		{
-			printutility = strdup(temp);
-			remove_quotes(printutility);
+			string tmpstr = temp;
+			printutility = remove_quotes(tmpstr);
 		}
 		else
 			return 1;
@@ -628,8 +631,8 @@
 		temp = strtok(NULL, "\n");
 		if (temp)
 		{
-			ManOptions = strdup(temp);
-			remove_quotes(ManOptions);
+			string tmpstr = temp;
+			ManOptions = remove_quotes(tmpstr);
 		}
 		else
 			return 1;
@@ -639,8 +642,8 @@
 		temp = strtok(NULL, "\n");
 		if (temp)
 		{
-			StderrRedirection = strdup(temp);
-			remove_quotes(StderrRedirection);
+			string tmpstr = temp;
+			StderrRedirection = remove_quotes(tmpstr);
 		}
 		else
 			return 1;
@@ -665,8 +668,8 @@
 		temp = strtok(NULL, "\n");
 		if (temp)
 		{
-			manlinks = strdup(temp);
-			remove_quotes(manlinks);
+			string tmpstr = temp;
+			manlinks = remove_quotes(tmpstr);
 		}
 		else
 			return 1;
@@ -676,8 +679,8 @@
 		temp = strtok(NULL, "\n");
 		if (temp)
 		{
-			configuredinfopath = strdup(temp);
-			remove_quotes(configuredinfopath);
+			string tmpstr = temp;
+			configuredinfopath = remove_quotes(tmpstr);
 		}
 		else
 			return 1;
@@ -688,8 +691,9 @@
 		temp = strtok(NULL, "\n");
 		if (temp)
 		{
-			char *tmp = strdup(temp);
-			remove_quotes(tmp);
+			string tmpstr = temp;
+			string tmpstr2 = remove_quotes(tmpstr);
+			char *tmp = strdup(tmpstr2.c_str());
 			if (!h_regexp_num)
 				h_regexp = (regex_t*)malloc(sizeof(regex_t));
 			else
@@ -707,9 +711,8 @@
 		temp = strtok(NULL, "\n");
 		if (temp)
 		{
-			char *tmp = strdup(temp);
-			remove_quotes(tmp);
-			safe_user = tmp;
+			string tmpstr = temp;
+			safe_user = remove_quotes(tmpstr);
 		}
 		else
 			return 1;
@@ -719,9 +722,8 @@
 		temp = strtok(NULL, "\n");
 		if (temp)
 		{
-			char *tmp = strdup(temp);
-			remove_quotes(tmp);
-			safe_group = tmp;
+			string tmpstr = temp;
+			safe_group = remove_quotes(tmpstr);
 		}
 		else
 			return 1;
@@ -747,8 +749,9 @@
 		temp = strtok(NULL, "\n");
 		if (temp)
 		{
-			ignoredmacros = strdup(temp);
-			remove_quotes(ignoredmacros);
+			string tmpstr = temp;
+			string tmpstr2 = remove_quotes(tmpstr);
+			ignoredmacros = strdup(tmpstr2.c_str());
 			if (ignoredmacros[0] == '\t' || ignoredmacros[0] == ' '
 					|| !strncasecmp(ignoredmacros, "FALSE", 5))
 				ignoredmacros[0] = '\0';
@@ -965,14 +968,16 @@
 	return str + i;
 }
 
-char *
-remove_quotes(char *str)
-{
-	int i = 0;
-
-	for (i = 0; i < strlen(str); i++)
-		if (str[i] == '\"')
-			str[i] = ' ';
-
-	return str;
+/*
+ * Return a version of a string with quotes replaced with spaces.
+ * Why?  No idea.
+ */
+string
+remove_quotes(const string str) {
+	string result = str;
+	for (string::size_type i = 0; i < result.length(); i++) {
+		if (result[i] == '\"')
+			result[i] = ' ';
+	}
+	return result;
 }

Modified: pinfo/branches/cxx/src/parse_config.h
===================================================================
--- pinfo/branches/cxx/src/parse_config.h	2005-08-29 08:21:59 UTC (rev 73)
+++ pinfo/branches/cxx/src/parse_config.h	2005-08-30 06:27:21 UTC (rev 74)
@@ -91,7 +91,6 @@
 int parse_line (char *line);
 char *str_toupper (char *s);
 char *skip_whitespace (char *s);
-char *remove_quotes (char *str);
 
 #ifndef ___DONT_USE_REGEXP_SEARCH___
 extern regex_t *h_regexp;	/* regexps to highlight */

Modified: pinfo/branches/cxx/src/pinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/pinfo.cxx	2005-08-29 08:21:59 UTC (rev 73)
+++ pinfo/branches/cxx/src/pinfo.cxx	2005-08-30 06:27:21 UTC (rev 74)
@@ -570,12 +570,12 @@
 
 	if (!getegid() || !getgid())
 	{
-		grwd = getgrnam(safe_group);
+		grwd = getgrnam(safe_group.c_str());
 		if (!grwd)
 		{
 			if (verbose)
 			{
-				printf(_("Security warning: Unable to get GID of group called: %s\n"), safe_group);
+				printf(_("Security warning: Unable to get GID of group called: %s\n"), safe_group.c_str());
 				sleep(1);
 			}
 		}
@@ -590,12 +590,12 @@
 
 	if (!geteuid() || !getuid())
 	{
-		pswd = getpwnam(safe_user);
+		pswd = getpwnam(safe_user.c_str());
 		if (!pswd)
 		{
 			if (verbose)
 			{
-				printf(_("Security warning: Unable to get UID of user called: %s\n"), safe_user);
+				printf(_("Security warning: Unable to get UID of user called: %s\n"), safe_user.c_str());
 				sleep(1);
 			}
 		}

Modified: pinfo/branches/cxx/src/printinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/printinfo.cxx	2005-08-29 08:21:59 UTC (rev 73)
+++ pinfo/branches/cxx/src/printinfo.cxx	2005-08-30 06:27:21 UTC (rev 74)
@@ -37,7 +37,7 @@
 	/* printer fd */
 	FILE *prnFD;
 
-	prnFD = popen(printutility, "w");
+	prnFD = popen(printutility.c_str(), "w");
 
 	/* scan through all lines */
 	for (int i = 1; i < (*lines); i++) {

Modified: pinfo/branches/cxx/src/utils.cxx
===================================================================
--- pinfo/branches/cxx/src/utils.cxx	2005-08-29 08:21:59 UTC (rev 73)
+++ pinfo/branches/cxx/src/utils.cxx	2005-08-30 06:27:21 UTC (rev 74)
@@ -28,8 +28,8 @@
 #include <regex.h>
 #include <ctype.h>
 
-char *safe_user = "nobody";
-char *safe_group = "nobody";
+string safe_user = "nobody";
+string safe_group = "nobody";
 
 #ifndef HAVE_CURS_SET
 void

Modified: pinfo/branches/cxx/src/utils.h
===================================================================
--- pinfo/branches/cxx/src/utils.h	2005-08-29 08:21:59 UTC (rev 73)
+++ pinfo/branches/cxx/src/utils.h	2005-08-30 06:27:21 UTC (rev 74)
@@ -24,8 +24,8 @@
 
 #include <string>
 
-extern char *safe_user;
-extern char *safe_group;
+extern std::string safe_user;
+extern std::string safe_group;
 
 #ifndef HAVE_CURS_SET
 void curs_set (int a);




More information about the Pinfo-devel mailing list