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

Nathanael Nerode neroden-guest at costa.debian.org
Sun Aug 28 20:29:23 UTC 2005


Author: neroden-guest
Date: 2005-08-28 20:29:22 +0000 (Sun, 28 Aug 2005)
New Revision: 50

Modified:
   pinfo/branches/cxx/src/filehandling_functions.cxx
   pinfo/branches/cxx/src/pinfo.cxx
Log:
Update copyright in pinfo.cxx.
Convert more low-hanging fruit in filehandling_functions.cxx to std::string.


Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx	2005-08-26 11:15:34 UTC (rev 49)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx	2005-08-28 20:29:22 UTC (rev 50)
@@ -515,7 +515,7 @@
 }
 
 inline void
-buildcommand(char *dest, char *command, char *filename, const char *tmpfilename)
+buildcommand(char *dest, const char *command, const char *filename, const char *tmpfilename)
 {
 	strcpy(dest, command);
 	strcat(dest, " ");
@@ -525,7 +525,7 @@
 }
 
 inline void
-builddircommand(char *dest, char *command, char *filename, const char *tmpfilename)
+builddircommand(char *dest, const char *command, const char *filename, const char *tmpfilename)
 {
 	strcpy(dest, command);
 	strcat(dest, " ");
@@ -538,10 +538,9 @@
 opendirfile(int number)
 {
 	FILE *id = NULL;
-	char buf[1024];		/* holds local copy of filename */
-	char *bufend;			/* points at the trailing 0 of initial name */
+	string bufstr;
 	char command[1128];		/* holds command to evaluate for decompression of file */
-	int i, j;
+	int i;
 	char *tmpfilename;
 	int *fileendentries = (int*)xmalloc(infopathcount * sizeof(int));
 	int dir_found = 0;
@@ -562,24 +561,26 @@
 	for (i = 0; i < infopathcount; i++)	/* go through all paths */
 	{
 		lang_found = 0;
-		strcpy(buf, infopaths[i]);	/* build a filename */
-		strcat(buf, "/");
-		if (getenv("LANG") != NULL)
-			strcat(buf, getenv("LANG"));
-		strcat(buf, "/dir");
-		/*
-		 * remember the bufend to make it
-		 * possible later to glue compression suffixes.
-		 */
-		bufend = buf;
-		bufend += strlen(buf);
-		for (j = 0; j < SuffixesNumber; j++)	/* go through all suffixes */
+		bufstr = infopaths[i];
+		bufstr += '/';
+
+		char* getenv_lang;
+		getenv_lang = getenv("LANG");
+		if (getenv_lang != NULL)
+			bufstr += getenv_lang;
+		bufstr += "/dir";
+
+		for (int j = 0; j < SuffixesNumber; j++)	/* go through all suffixes */
 		{
-			strcat(buf, suffixes[j].suffix);
-			if ((id = fopen(buf, "r")) != NULL)
-			{
+			string bufstr_with_suffix;
+			bufstr_with_suffix = bufstr;
+			bufstr_with_suffix += suffixes[j].suffix;
+
+			id = fopen(bufstr_with_suffix.c_str(), "r");
+			if (id != NULL) {
 				fclose(id);
-				builddircommand(command, suffixes[j].command, buf, tmpfilename);
+				builddircommand(command, suffixes[j].command,
+												bufstr_with_suffix.c_str(), tmpfilename);
 				system(command);
 				lstat(tmpfilename, &status);
 				fileendentries[dircount] = status.st_size;
@@ -587,35 +588,29 @@
 				dir_found = 1;
 				lang_found = 1;
 			}
-			(*bufend) = 0;
 		}
 
 		/* same as above, but without $LANG support */
 		if (!lang_found)
 		{
-			strcpy(buf, infopaths[i]);	/* build a filename */
-			strcat(buf, "/");
-			strcat(buf, "dir");
-			/*
-			 * remember the bufend to make it possible later to glue
-			 * compression suffixes.
-			 */
-			bufend = buf;
-			bufend += strlen(buf);
-			for (j = 0; j < SuffixesNumber; j++)	/* go through all suffixes */
+			bufstr = infopaths[i];
+			bufstr += "/dir";
+
+			for (int j = 0; j < SuffixesNumber; j++)	/* go through all suffixes */
 			{
-				strcat(buf, suffixes[j].suffix);
-				if ((id = fopen(buf, "r")) != NULL)
-				{
+				string bufstr_with_suffix;
+				bufstr_with_suffix += suffixes[j].suffix;
+				id = fopen(bufstr_with_suffix.c_str(), "r");
+				if (id != NULL) {
 					fclose(id);
-					builddircommand(command, suffixes[j].command, buf, tmpfilename);
+					builddircommand(command, suffixes[j].command,
+													bufstr_with_suffix.c_str(), tmpfilename);
 					system(command);
 					lstat(tmpfilename, &status);
 					fileendentries[dircount] = status.st_size;
 					dircount++;
 					dir_found = 1;
 				}
-				(*bufend) = 0;
 			}
 		}
 	}

Modified: pinfo/branches/cxx/src/pinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/pinfo.cxx	2005-08-26 11:15:34 UTC (rev 49)
+++ pinfo/branches/cxx/src/pinfo.cxx	2005-08-28 20:29:22 UTC (rev 50)
@@ -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




More information about the Pinfo-devel mailing list