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

Nathanael Nerode neroden-guest at costa.debian.org
Tue Aug 30 07:30:52 UTC 2005


Author: neroden-guest
Date: 2005-08-30 07:30:51 +0000 (Tue, 30 Aug 2005)
New Revision: 77

Modified:
   pinfo/branches/cxx/src/manual.cxx
   pinfo/branches/cxx/src/pinfo.cxx
   pinfo/branches/cxx/src/utils.cxx
Log:
More miscellaneous conversion.


Modified: pinfo/branches/cxx/src/manual.cxx
===================================================================
--- pinfo/branches/cxx/src/manual.cxx	2005-08-30 07:00:22 UTC (rev 76)
+++ pinfo/branches/cxx/src/manual.cxx	2005-08-30 07:30:51 UTC (rev 77)
@@ -193,7 +193,7 @@
 		string tmpname = manuallinks[which].name;
 		/* workaround for names starting with '(' */
 		if (tmpname[0] == '(')
-			tmpname.replace(0,1,"");
+			tmpname.erase(0);
 		buf = tmpname;
 	} else if (manuallinks[which].section_mark < HTTPSECTION) {
 		/* normal manual reference */
@@ -217,7 +217,7 @@
 		if (tmpstr[idx] == '(')
 			idx++;
 		/* Delete characters before tail */
-		tmpstr.replace(0, idx, "");
+		tmpstr.erase(0, idx);
 	
 		tmpstr.append(manuallinks[which].name);
 		buf = tmpstr;
@@ -231,7 +231,7 @@
 		string::size_type idx = 0;
 		while (isspace(tmpstr[idx]))
 			idx++;
-		tmpstr.replace(0, idx, "");
+		tmpstr.erase(0, idx);
 
 		/* Cut off anything past the URL end */
 		string::size_type urlend_idx = findurlend(tmpstr);
@@ -1719,10 +1719,10 @@
 	{
 		/* strip from the line "'_',0x8" -- underline marks */
 		if ((buf[i] == '_') && (buf[i + 1] == 8))
-			buf.replace(i, 2, "");
+			buf.erase(i, 2);
 		/* and 0x8 -- overstrike marks */
 		else if ((buf[i + 1] == 8) &&(buf[i + 2] == buf[i]))
-			buf.replace(i, 2, "");
+			buf.erase(i, 2);
 		/* else we don't do anything */
 	}
 }

Modified: pinfo/branches/cxx/src/pinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/pinfo.cxx	2005-08-30 07:00:22 UTC (rev 76)
+++ pinfo/branches/cxx/src/pinfo.cxx	2005-08-30 07:30:51 UTC (rev 77)
@@ -192,11 +192,11 @@
 int
 main(int argc, char *argv[]) {
 	int filenotfound = 0;
-	char filename[256];
 	WorkRVal work_return_value =
 	{0, 0};
 	int userdefinedrc = 0;
 	FILE *id = NULL;
+	string filename_string;
 	/* line count in message */
 	long lines = 0;
 	/* this will hold node's text */
@@ -225,7 +225,7 @@
 		id = openinfo("dir", 0);
 		curfile = (char*)xmalloc(150);
 		strcpy(curfile, "dir");
-		strcpy(filename, "dir");
+		filename_string = "dir";
 	}
 	if ((strlen(argv[0]) >= 3)||(use_manual))
 		/* handle any 'man' alias to 'pinfo' */
@@ -247,50 +247,45 @@
 		}
 
 	/* Break out getopts to make main() smaller */
-	string filename_string;
 	FILE** idptr = &id;
 	getopts(argc, argv, filename_string, idptr);
 
-	if (filename_string != "") {
-		strncpy(filename, filename_string.c_str(), 200);
-	}
-
 	checksu();
 	initpaths();
+
 	if (argc > 1) {
 #ifdef HAVE_GETOPT_LONG
 		if (optind < argc)
 		{
 			/* the paths will be searched by openinfo() */
-			strncpy(filename, argv[optind], 200);
+			filename_string = argv[optind];
 		}
 		else
 		{
-			strcpy(filename, "dir");
+			filename_string = "dir";
 		}
-
 #else
 		/* the paths will be searched by openinfo() */
-		strncpy(filename, argv[argc - 1], 200);
+		filename_string = argv[argc - 1];
 #endif
-		if (filename[0]=='(')
+
+		if ( (filename_string.length() > 0) && (filename_string[0]=='(') )
 		{
-			int fnamelen=strlen(filename);
-			/* erase the leading '(' */
-			for (int i=0;i<fnamelen;i++)
-				filename[i]=filename[i+1];
-			int j;
-			for (j=0;filename[j]!=')';j++);
-			/* leave the filename part in filename */
-			filename[j]=0;
-			/* copy the node content to pinfo_start_node */
-			if (!pinfo_start_node)
-			{
-				pinfo_start_node=strdup(&filename[j+1]);
+			string::size_type j = filename_string.find(')');
+			if (j != string::npos) {
+				/* Looks like filename and node. */
+				/* copy the node content to pinfo_start_node */
+				if (!pinfo_start_node)
+				{
+					pinfo_start_node=strdup(filename_string.substr(j+1).c_str());
+				}
+				/* leave the filename part in filename */
+				filename_string.resize(j);
+				/* and erase the leading '(' */
+				filename_string.erase(0);
 			}
 		}
 
-		string filename_string = filename;
 		/* security check */
 		checkfilename(filename_string);
 
@@ -304,10 +299,15 @@
 		}
 
 		/* leave some space for `.info' suffix */
-		curfile = (char*)xmalloc(strlen(filename) + 100);
-		strcpy(curfile, filename);
+		curfile = (char*)xmalloc(filename_string.length() + 100);
+		strcpy(curfile, filename_string.c_str());
 	}
 
+	char filename[256]; /* FIXME; still needs conversion */
+	if (filename_string != "") {
+		strncpy(filename, filename_string.c_str(), 200);
+	}
+
 	/* no rawpath has been opened */
 	if (id == NULL) {
 		string tmpstr = filename;

Modified: pinfo/branches/cxx/src/utils.cxx
===================================================================
--- pinfo/branches/cxx/src/utils.cxx	2005-08-30 07:00:22 UTC (rev 76)
+++ pinfo/branches/cxx/src/utils.cxx	2005-08-30 07:30:51 UTC (rev 77)
@@ -216,20 +216,19 @@
  * we find any.
  */
 void
-checkfilename(const string filename_string)
+checkfilename(const string filename)
 {
-	const char * filename = filename_string.c_str();
-	if ((strchr(filename, '<')) ||
-			(strchr(filename, '>')) ||
-			(strchr(filename, '|')) ||
-			(strchr(filename, '(')) ||
-			(strchr(filename, ')')) ||
-			(strchr(filename, '!')) ||
-			(strchr(filename, '`')) ||
-			(strchr(filename, '&')) ||
-			(strchr(filename, ';')))
-	{
-		printf(_("Illegal characters in filename!\n*** %s\n"), filename);
+	if ( (filename.find('<') != string::npos) ||
+	     (filename.find('>') != string::npos) ||
+	     (filename.find('|') != string::npos) ||
+	     (filename.find('(') != string::npos) ||
+	     (filename.find(')') != string::npos) ||
+	     (filename.find('!') != string::npos) ||
+	     (filename.find('`') != string::npos) ||
+	     (filename.find('&') != string::npos) ||
+	     (filename.find(';') != string::npos)
+     ) {
+		printf(_("Illegal characters in filename!\n*** %s\n"), filename.c_str());
 		exit(1);
 	}
 }




More information about the Pinfo-devel mailing list