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

Nathanael Nerode neroden-guest at costa.debian.org
Mon Aug 29 00:59:25 UTC 2005


Author: neroden-guest
Date: 2005-08-29 00:59:24 +0000 (Mon, 29 Aug 2005)
New Revision: 60

Modified:
   pinfo/branches/cxx/src/datatypes.cxx
   pinfo/branches/cxx/src/datatypes.h
   pinfo/branches/cxx/src/filehandling_functions.cxx
   pinfo/branches/cxx/src/pinfo.cxx
Log:
More conversion in openinfo, and of filenameprefix.


Modified: pinfo/branches/cxx/src/datatypes.cxx
===================================================================
--- pinfo/branches/cxx/src/datatypes.cxx	2005-08-29 00:47:57 UTC (rev 59)
+++ pinfo/branches/cxx/src/datatypes.cxx	2005-08-29 00:59:24 UTC (rev 60)
@@ -19,12 +19,14 @@
  *  USA
  ***************************************************************************/
 #include "common_includes.h"
+#include <string>
+using std::string;
 
 RCSID("$Id$")
 
 int verbose = 1;
 
-char *filenameprefix = 0;
+string filenameprefix;
 
 char *httpviewer = "lynx";
 char *ftpviewer = "lynx";
@@ -180,12 +182,3 @@
 	}
 }
 
-void
-clearfilenameprefix()
-{
-	if (filenameprefix)
-	{
-		xfree(filenameprefix);
-		filenameprefix = 0;
-	}
-}

Modified: pinfo/branches/cxx/src/datatypes.h
===================================================================
--- pinfo/branches/cxx/src/datatypes.h	2005-08-29 00:47:57 UTC (rev 59)
+++ pinfo/branches/cxx/src/datatypes.h	2005-08-29 00:59:24 UTC (rev 60)
@@ -22,6 +22,8 @@
 #ifndef __DATATYPES_H
 #define __DATATYPES_H
 
+#include <string>
+
 #define FREE 0
 #define LOCKED 1
 
@@ -94,7 +96,7 @@
  * And this path points to that directory, and openinfo() will try to open the
  * file only in this directory (if this variable is set nonzero)
  */
-extern char *filenameprefix;
+extern std::string filenameprefix;
 
 /* name of http viewer (i.e. lynx) */
 extern char *httpviewer;
@@ -193,7 +195,4 @@
 /* deletes last history entry */
 void dellastinfohistory ();
 
-/* clears the default searchpath for openinfo() */
-void clearfilenameprefix ();
-
 #endif

Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx	2005-08-29 00:47:57 UTC (rev 59)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx	2005-08-29 00:59:24 UTC (rev 60)
@@ -33,7 +33,7 @@
 Suffixes;
 
 void
-basename_and_dirname(string filename, string& basename, string& dirname)
+basename_and_dirname(const string filename, string& basename, string& dirname)
 {
 	/* Dirname should end with a slash, or be empty. */
 	string::size_type index = filename.rfind('/');
@@ -47,7 +47,7 @@
 }
 
 void
-basename(string filename, string& basename_str)
+basename(const string filename, string& basename_str)
 {
 	string::size_type index = filename.rfind('/');
 	if (index == string::npos) {
@@ -57,7 +57,19 @@
 	}
 }
 
+/* In this one, dirname *doesn't* have a trailing slash. */
+void
+dirname(const string filename, string& dirname_str)
+{
+	string::size_type index = filename.rfind('/');
+	if (index == string::npos) {
+		dirname_str = "";
+	} else {
+		dirname_str = filename.substr(0, index);
+	}
+}
 
+
 /******************************************************************************
  * This piece of declarations says what to do with info files stored with      *
  * different formats/compression methods, before putting them into a temporary *
@@ -648,8 +660,8 @@
  * are two temporary files supported, i.e.  one for keeping opened info file,
  * and second for i.e. regexp search across info nodes, which are in other
  * info-subfiles.  The temporary file 1 is refrenced by number=0, and file 2 by
- * number=1 Openinfo by default first tries the path stored in char
- * *filenameprefix and then in the rest of userdefined paths.
+ * number=1 Openinfo by default first tries the path stored in
+ * filenameprefix and then in the rest of userdefined paths.
  */
 FILE *
 openinfo(const char *filename, int number)
@@ -691,7 +703,7 @@
 			 * no filenameprefix, we don't navigate around any specific
 			 * infopage set, so simply scan all directories for a hit
 			 */
-			if (!filenameprefix)
+			if (filenameprefix.empty())
 				continue;
 			else {
 				mybuf = filenameprefix;
@@ -713,17 +725,9 @@
 			id = fopen(buf_with_suffix.c_str(), "r");
 			if (id) {
 				fclose(id);
-				clearfilenameprefix();
-				filenameprefix = strdup(buf_with_suffix.c_str());
-				{			/* small scope for removal of filename */
-					int prefixlen = strlen(filenameprefix);
-					for (int prefixi = prefixlen; prefixi > 0; prefixi--)
-						if (filenameprefix[prefixi] == '/')
-						{
-							filenameprefix[prefixi] = 0;
-							break;
-						}
-				}
+				/* Set global filenameprefix to the dirname of the found file */
+				dirname(buf_with_suffix, filenameprefix);
+
 				/* FIXME: Insecure temp file usage */
 				string command_string = suffixes[j].command;
 				command_string += ' ';
@@ -739,7 +743,7 @@
 				}
 			}
 		}
-		if ((i == -1) &&(filenameprefix))
+		if ((i == -1) && ( !filenameprefix.empty() ))
 			/* if we have a nonzero filename prefix,
 				 that is we view a set of infopages,
 				 we don't want to search for a page

Modified: pinfo/branches/cxx/src/pinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/pinfo.cxx	2005-08-29 00:47:57 UTC (rev 59)
+++ pinfo/branches/cxx/src/pinfo.cxx	2005-08-29 00:59:24 UTC (rev 60)
@@ -427,7 +427,9 @@
 					fclose(id);
 					/*tmp = addinfosuffix(work_return_value.file); */
 					tmp = strdup(work_return_value.file);
-					clearfilenameprefix();
+
+					/* Reset global filenameprefix */
+					filenameprefix.clear();
 					id = openinfo(tmp, 0);
 					xfree(tmp);
 					tmp = 0;




More information about the Pinfo-devel mailing list