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

Nathanael Nerode neroden-guest at costa.debian.org
Mon Sep 26 04:25:05 UTC 2005


Author: neroden-guest
Date: 2005-09-26 04:25:04 +0000 (Mon, 26 Sep 2005)
New Revision: 250

Modified:
   pinfo/branches/cxx/src/filehandling_functions.cxx
   pinfo/branches/cxx/src/filehandling_functions.h
   pinfo/branches/cxx/src/mainfunction.cxx
   pinfo/branches/cxx/src/mainfunction.h
   pinfo/branches/cxx/src/parse_config.cxx
Log:
More static/const stuff.



Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx	2005-09-26 04:09:39 UTC (rev 249)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx	2005-09-26 04:25:04 UTC (rev 250)
@@ -59,8 +59,8 @@
 
 /*****************************************************************************/
 
-void
-basename_and_dirname(const string filename, string& basename, string& dirname)
+static void
+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('/');
@@ -74,7 +74,7 @@
 }
 
 void
-basename(const string filename, string& basename_str)
+basename(const string& filename, string& basename_str)
 {
 	string::size_type index = filename.rfind('/');
 	if (index == string::npos) {
@@ -85,8 +85,8 @@
 }
 
 /* In this one, dirname *doesn't* have a trailing slash. */
-void
-dirname(const string filename, string& dirname_str)
+static void
+dirname(const string& filename, string& dirname_str)
 {
 	string::size_type index = filename.rfind('/');
 	if (index == string::npos) {
@@ -136,7 +136,7 @@
 	}
 }
 
-void
+static void
 sort_tag_table(void) {
 	if (!tag_table.empty())
 		std::sort(tag_table.begin(), tag_table.end(), compare_tags);
@@ -147,8 +147,8 @@
  * Returns true if it finds a match, false if not.
  * Leaves the matching name in buf.
  */
-bool
-matchfile(string& buf, const string name_string)
+static bool
+matchfile(string& buf, const string& name_string)
 {
 	string basename_string;
 	string dirname_string;
@@ -193,98 +193,6 @@
 	return false;
 }
 
-FILE *
-dirpage_lookup(string& type, vector<string>& message,
-               string wanted_name, string& first_node)
-{
-	FILE *id = 0;
-	bool goodHit = false;
-
-	id = opendirfile(0);
-	if (!id)
-		return 0;
-
-	read_item(id, type, message);
-	/* search for node-links in every line */
-	for (int i = 0; i < message.size(); i++)	{
-		/* we want: `* name:(file)node.' */
-		string::size_type nameend, filestart, fileend, dot;
-		if (    (message[i].length() >= 2)
-		     && (message[i][0] == '*')
-		     && (message[i][1] == ' ')
-		     && ( (nameend = message[i].find(':')) != string::npos )
-		     && (message[i].length() != nameend + 1)
-		     && (message[i][nameend + 1] != ':')
-		     && ( (filestart = message[i].find('(', nameend + 1)) != string::npos )
-		     && ( (fileend = message[i].find(')', filestart + 1)) != string::npos )
-		     && ( (dot = message[i].find('.', fileend + 1)) != string::npos )
-		   ) {
-			; /* Matches the pattern we want */
-		} else {
-			continue;
-		}
-
-		/* It looks like a match. */
-		string name(message[i], 2, nameend - 2);
-		string file(message[i], filestart + 1, fileend - (filestart + 1) );
-		string node(message[i], fileend + 1, dot - (fileend + 1) );
-
-		if (    (name.length() >= wanted_name.length())
-		     && (strcasecmp(wanted_name.c_str(),
-		                   name.substr(0, wanted_name.length()).c_str()) == 0)
-	     ) {
-			; /* Wanted_name begins the name, so it's a match */
-		} else {
-			continue;
-		}
-
-		if ( goodHit && (name.length() != wanted_name.length()) ) {
-			/* skip this hit if we have already found a previous partial match,
-		   * and this hit is not a perfect match */
-			continue;
-		}
-
-		/* Find the name of the node link (without leading spaces) */
-		if (node != "") {
-			string::size_type idx = 0;
-			while (isspace(node[idx]))
-				idx++;
-			first_node = node.substr(idx);
-		}
-
-		if (id) {
-			/* Close the previously opened file */
-			fclose(id);
-			id = 0;
-		}
-
-		if (file.find(".info") == string::npos) {
-			file += ".info";
-		}
-
-		/* See if this info file exists, and open it if it does */
-		id = openinfo(file, 0);
-		if (id) {
-			goodHit = true;
-			if ((nameend - 2) == wanted_name.length()) {
-				/* the name matches perfectly to the query */
-				/* stop searching for another match, and use this one */
-				break;	
-			}
-		}
-	}
-
-	/* if we haven't found anything, clean up and exit */
-	if (!goodHit)
-	{
-		fclose(id);
-		id = 0;
-	}
-
-	/* return file we found */
-	return id;
-}
-
 void
 read_item(FILE * id, string& type, vector<string>& buf)
 {
@@ -539,7 +447,7 @@
 	return 1;
 }
 
-FILE *
+static FILE *
 opendirfile(int number)
 {
 	FILE *id = NULL;
@@ -650,6 +558,98 @@
 	return id;
 }
 
+FILE *
+dirpage_lookup(string& type, vector<string>& message,
+               const string& wanted_name, string& first_node)
+{
+	FILE *id = 0;
+	bool goodHit = false;
+
+	id = opendirfile(0);
+	if (!id)
+		return 0;
+
+	read_item(id, type, message);
+	/* search for node-links in every line */
+	for (int i = 0; i < message.size(); i++)	{
+		/* we want: `* name:(file)node.' */
+		string::size_type nameend, filestart, fileend, dot;
+		if (    (message[i].length() >= 2)
+		     && (message[i][0] == '*')
+		     && (message[i][1] == ' ')
+		     && ( (nameend = message[i].find(':')) != string::npos )
+		     && (message[i].length() != nameend + 1)
+		     && (message[i][nameend + 1] != ':')
+		     && ( (filestart = message[i].find('(', nameend + 1)) != string::npos )
+		     && ( (fileend = message[i].find(')', filestart + 1)) != string::npos )
+		     && ( (dot = message[i].find('.', fileend + 1)) != string::npos )
+		   ) {
+			; /* Matches the pattern we want */
+		} else {
+			continue;
+		}
+
+		/* It looks like a match. */
+		string name(message[i], 2, nameend - 2);
+		string file(message[i], filestart + 1, fileend - (filestart + 1) );
+		string node(message[i], fileend + 1, dot - (fileend + 1) );
+
+		if (    (name.length() >= wanted_name.length())
+		     && (strcasecmp(wanted_name.c_str(),
+		                   name.substr(0, wanted_name.length()).c_str()) == 0)
+	     ) {
+			; /* Wanted_name begins the name, so it's a match */
+		} else {
+			continue;
+		}
+
+		if ( goodHit && (name.length() != wanted_name.length()) ) {
+			/* skip this hit if we have already found a previous partial match,
+		   * and this hit is not a perfect match */
+			continue;
+		}
+
+		/* Find the name of the node link (without leading spaces) */
+		if (node != "") {
+			string::size_type idx = 0;
+			while (isspace(node[idx]))
+				idx++;
+			first_node = node.substr(idx);
+		}
+
+		if (id) {
+			/* Close the previously opened file */
+			fclose(id);
+			id = 0;
+		}
+
+		if (file.find(".info") == string::npos) {
+			file += ".info";
+		}
+
+		/* See if this info file exists, and open it if it does */
+		id = openinfo(file, 0);
+		if (id) {
+			goodHit = true;
+			if ((nameend - 2) == wanted_name.length()) {
+				/* the name matches perfectly to the query */
+				/* stop searching for another match, and use this one */
+				break;	
+			}
+		}
+	}
+
+	/* if we haven't found anything, clean up and exit */
+	if (!goodHit)
+	{
+		fclose(id);
+		id = 0;
+	}
+
+	/* return file we found */
+	return id;
+}
+
 /*
  * Note: openinfo is a function for reading info files, and putting
  * uncompressed content into a temporary filename.  For a flexibility, there
@@ -660,7 +660,7 @@
  * filenameprefix and then in the rest of userdefined paths.
  */
 FILE *
-openinfo(const string filename, int number)
+openinfo(const string& filename, int number)
 {
 	FILE *id = NULL;
 	string tmpfilename;
@@ -747,7 +747,7 @@
 }
 
 void
-addrawpath(const string filename_string)
+addrawpath(const string& filename_string)
 {
 	/* Get the portion up to the last slash. */
 	string dirstring;

Modified: pinfo/branches/cxx/src/filehandling_functions.h
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.h	2005-09-26 04:09:39 UTC (rev 249)
+++ pinfo/branches/cxx/src/filehandling_functions.h	2005-09-26 04:25:04 UTC (rev 250)
@@ -35,7 +35,7 @@
 #define INDIRECT_TAG (char)0x7f
 
 void initpaths ();
-void addrawpath (const std::string filename);
+void addrawpath (const std::string& filename);
 
 /*  seek to a node in certain info file */
 void seeknode (int tag_table_pos, FILE * & id);
@@ -56,9 +56,7 @@
 /* loads tag table (as above) */
 void load_tag_table (const std::vector<std::string>& message);
 /* opens info file */
-FILE *openinfo (const std::string filename, int number);
-/* opens dir info file */
-FILE *opendirfile (int number);
+FILE *openinfo (const std::string& filename, int number);
 
 /* creates tag table for info file */
 void create_tag_table (FILE * id);
@@ -77,12 +75,12 @@
  */
 FILE *
 dirpage_lookup (std::string& type, std::vector<std::string>& message,
-		const std::string filename, std::string& first_node);
+		const std::string& wanted_name, std::string& first_node);
 
 /* removes trailing .gz, .bz2, etc. */
 void strip_compression_suffix (std::string& filename);
 
 /* Gets the base file name from a filename-with-directory */
-void basename (std::string filename, std::string& basename_str);
+void basename (const std::string& filename, std::string& basename_str);
 
 #endif

Modified: pinfo/branches/cxx/src/mainfunction.cxx
===================================================================
--- pinfo/branches/cxx/src/mainfunction.cxx	2005-09-26 04:09:39 UTC (rev 249)
+++ pinfo/branches/cxx/src/mainfunction.cxx	2005-09-26 04:25:04 UTC (rev 250)
@@ -61,7 +61,7 @@
  */
 #define ERRNODE "ERR@!#$$@#!%%^#@!OR"
 static inline string
-get_foo_node(const char * const foo, string type)
+get_foo_node(const char * const foo, const string & type)
 {
 	string::size_type start_idx = type.find(foo);
 	if (start_idx == string::npos) {
@@ -78,28 +78,28 @@
 
 /* read the `Next:' header entry */
 static inline string
-getnextnode(string type)
+getnextnode(const string & type)
 {
 	return get_foo_node("Next: ", type);
 }
 
 /* read the `Prev:' header entry */
 static inline string
-getprevnode(string type)
+getprevnode(const string & type)
 {
 	return get_foo_node("Prev: ", type);
 }
 
 /* read the `Up:' header entry */
 static inline string
-getupnode(string type)
+getupnode(const string & type)
 {
 	return get_foo_node("Up: ", type);
 }
 
 /* read the `Node:' header entry */
 static inline string
-getnodename(string type)
+getnodename(const string & type)
 {
 	return get_foo_node("Node: ", type);
 }
@@ -408,7 +408,10 @@
  * Main work function
  */
 WorkRVal
-work(const vector<string>& my_message, string type_str, FILE * id, int tag_table_pos)
+work(const vector<string>& my_message,
+     const string & type_str,
+     FILE * id, 
+     int tag_table_pos)
 {
 	static WorkRVal rval;
 	int key = 0;

Modified: pinfo/branches/cxx/src/mainfunction.h
===================================================================
--- pinfo/branches/cxx/src/mainfunction.h	2005-09-26 04:09:39 UTC (rev 249)
+++ pinfo/branches/cxx/src/mainfunction.h	2005-09-26 04:25:04 UTC (rev 250)
@@ -50,6 +50,8 @@
  * id: file descriptor of current info file
  * tag_table_pos: position in tag table of the current node (needed for history)
  */
-WorkRVal work (const std::vector<std::string>& message, std::string type,
-		FILE * id, int tag_table_pos);
+WorkRVal work (const std::vector<std::string> & message,
+               const std::string & type,
+							 FILE * id,
+               int tag_table_pos);
 #endif

Modified: pinfo/branches/cxx/src/parse_config.cxx
===================================================================
--- pinfo/branches/cxx/src/parse_config.cxx	2005-09-26 04:09:39 UTC (rev 249)
+++ pinfo/branches/cxx/src/parse_config.cxx	2005-09-26 04:25:04 UTC (rev 250)
@@ -72,8 +72,19 @@
 	'6',		0			/* scroll right */
 };
 
-/* Forward declarations */
-string remove_quotes(const string);
+/*
+ * Return a version of a string with quotes replaced with spaces.
+ * Why?  No idea.
+ */
+string
+remove_quotes(string str) {
+	for (string::size_type i = 0; i < str.length(); i++) {
+		if (str[i] == '\"') {
+			str[i] = ' ';
+		}
+	}
+	return str;
+}
 
 int
 parse_config(void)
@@ -938,16 +949,3 @@
 	return str + i;
 }
 
-/*
- * 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;
-}




More information about the Pinfo-devel mailing list