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

Nathanael Nerode neroden-guest at costa.debian.org
Fri Sep 2 03:56:18 UTC 2005


Author: neroden-guest
Date: 2005-09-02 03:56:18 +0000 (Fri, 02 Sep 2005)
New Revision: 125

Modified:
   pinfo/branches/cxx/src/filehandling_functions.cxx
Log:
Convert infopaths to vector and string.


Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx	2005-09-02 03:41:57 UTC (rev 124)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx	2005-09-02 03:56:18 UTC (rev 125)
@@ -75,14 +75,14 @@
 
 typedef struct Suffixes
 {
-	const char *suffix;
-	const char *command;
+	const char * const suffix;
+	const char * const command;
 }
 Suffixes;
 
 #define SuffixesNumber 4
 
-Suffixes suffixes[SuffixesNumber] =
+static const Suffixes suffixes[SuffixesNumber] =
 {
 	{"", 		"cat"},
 	{".gz",		"gzip -d -q -c"},
@@ -92,8 +92,7 @@
 
 /*****************************************************************************/
 
-char **infopaths = 0;
-int infopathcount = 0;
+vector<string> infopaths;
 
 bool
 compare_tags(TagTable a, TagTable b) {
@@ -562,8 +561,8 @@
 		tmpfilename = tmpfilename1;	/* later we will refere only to tmp1 */
 	}
 
-	int *fileendentries = (int*)xmalloc(infopathcount * sizeof(int));
-	for (int i = 0; i < infopathcount; i++)	{ /* go through all paths */
+	int *fileendentries = (int*)xmalloc(infopaths.size() * sizeof(int));
+	for (int i = 0; i < infopaths.size(); i++)	{ /* go through all paths */
 		int lang_found = 0;
 		for (int k = 0; k <= 1; k++) { /* Two passes: with and without LANG */
 			string bufstr;
@@ -702,7 +701,7 @@
 		tmpfilename = tmpfilename2;	/* later we will refere only to tmp2 */
 	}
 
-	for (int i = -1; i < infopathcount; i++) { /* go through all paths */
+	for (int i = -1; i < infopaths.size(); i++) { /* go through all paths */
 		string mybuf;
 		if (i == -1) {
 			/*
@@ -772,21 +771,17 @@
 	else
 		dirstring = "./"; /* If no directory part, use current directory */
 
-	infopaths = (char**)xrealloc(infopaths,(infopathcount + 3) *(sizeof(char *)));
-	for (int i = infopathcount; i > 0; i--)	/* move entries to the right */
-		infopaths[i] = infopaths[i - 1];
-
-	infopaths[0]=strdup(dirstring.c_str());	/* add new(raw) entry */
-	infopathcount++;
+	/* Add to beginning */
+	infopaths.insert(infopaths.begin(), dirstring);
 }
 
 int
 isininfopath(char *name)
 {
 	int i;
-	for (i = 0; i < infopathcount; i++)
+	for (i = 0; i < infopaths.size(); i++)
 	{
-		if (strcmp(name, infopaths[i]) == 0)
+		if (infopaths[i] == name)
 			return 1;		/* path already exists */
 	}
 	return 0;			/* path not found in previous links */
@@ -955,20 +950,13 @@
 		}
 	}
 
-
 	/* and alloc and copy to global var */
-	infopathcount = numpaths;
-	infopaths = (char **) xmalloc( numpaths * sizeof(char *) );
-	c = (char *) xmalloc( len * sizeof(char) );
-	j=0;
+	infopaths.clear();
 	for (i=0; i<maxpaths; i++)
 	{
 		if (paths[i]!=NULL)
 		{
-			/* copy path to c buffer */
-			strcpy(c, paths[i]);
-			infopaths[j++] = c;
-			c += strlen(paths[i]) + 1;
+			infopaths.push_back(paths[i]);
 		}
 	}
 
@@ -978,8 +966,8 @@
 
 #ifdef ___DEBUG___
 	/* for debugging */
-	fprintf(stderr, "%i valid info paths found:\n", infopathcount);
-	for (i=0; i<infopathcount; i++)
+	fprintf(stderr, "%i valid info paths found:\n", infopaths.size());
+	for (i=0; i<infopaths.size(); i++)
 		if (infopaths[i]) fprintf(stderr,"--> %s\n", infopaths[i]);
 #endif
 }




More information about the Pinfo-devel mailing list