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

Nathanael Nerode neroden-guest at costa.debian.org
Mon Aug 29 04:44:44 UTC 2005


Author: neroden-guest
Date: 2005-08-29 04:44:43 +0000 (Mon, 29 Aug 2005)
New Revision: 68

Modified:
   pinfo/branches/cxx/src/initializelinks.cxx
   pinfo/branches/cxx/src/initializelinks.h
   pinfo/branches/cxx/src/manual.cxx
Log:
Convert most of construct_manualname, and also findurlend.



Modified: pinfo/branches/cxx/src/initializelinks.cxx
===================================================================
--- pinfo/branches/cxx/src/initializelinks.cxx	2005-08-29 03:42:26 UTC (rev 67)
+++ pinfo/branches/cxx/src/initializelinks.cxx	2005-08-29 04:44:43 UTC (rev 68)
@@ -19,6 +19,8 @@
  *  USA
  ***************************************************************************/
 #include "common_includes.h"
+#include <string>
+using std::string;
 
 RCSID("$Id$")
 
@@ -117,6 +119,7 @@
 
 /*
  * Finds url end.  It is recognized by an invalid character.
+ * FIXME: That's not a sufficient test.
  */
 char *
 findurlend(char *str)
@@ -135,6 +138,28 @@
 }
 
 /*
+ * Returns index of the first non-URL character (or length, if there
+ * is no non-URL character)
+ */
+string::size_type
+findurlend(const string str)
+{
+	const char* allowedchars =
+		"QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890-_/~.%=|:@­";
+
+	string::size_type idx;
+	idx = str.find_first_not_of(allowedchars);
+	if (idx == string::npos) {
+		/* All allowed characters! */
+		return str.length();
+	}
+	if ( (str.length() > 0) && (idx > 0) && (str[idx-1] == '.') ) {
+		idx--;
+	}
+	return idx;
+}
+
+/*
  * Searchs for a note/menu delimiter.  it may be dot, comma, tab, or newline.
  */
 char *

Modified: pinfo/branches/cxx/src/initializelinks.h
===================================================================
--- pinfo/branches/cxx/src/initializelinks.h	2005-08-29 03:42:26 UTC (rev 67)
+++ pinfo/branches/cxx/src/initializelinks.h	2005-08-29 04:44:43 UTC (rev 68)
@@ -29,6 +29,8 @@
  * returns a pointer to the found place.
  */
 char *findurlend (char *str);
+std::string::size_type findurlend (std::string str);
+
 /* scans for the beginning of username. Returns a pointer to it.  */
 char *findemailstart (char *str);
 /* strcmp, which is insensitive to whitespaces */

Modified: pinfo/branches/cxx/src/manual.cxx
===================================================================
--- pinfo/branches/cxx/src/manual.cxx	2005-08-29 03:42:26 UTC (rev 67)
+++ pinfo/branches/cxx/src/manual.cxx	2005-08-29 04:44:43 UTC (rev 68)
@@ -189,64 +189,62 @@
 void
 construct_manualname(char *buf, int which)
 {
-	if (!manuallinks[which].carry)
-	{
+	if (!manuallinks[which].carry) {
+		string tmpname = manuallinks[which].name;
 		/* workaround for names starting with '(' */
-		if (manuallinks[which].name[0] == '(')
-			strcpy(buf, manuallinks[which].name + 1);
-		else strcpy(buf, manuallinks[which].name);
-		return;
-	}
-	else
-	{
+		if (tmpname[0] == '(')
+			tmpname.replace(0,1,"");
+		strcpy(buf, tmpname.c_str());
+	} else if (manuallinks[which].section_mark < HTTPSECTION) {
 		/* normal manual reference */
-		if (manuallinks[which].section_mark < HTTPSECTION)
-		{
-			string base_str = manual[manuallinks[which].line - 1];
-			strip_manual(base_str);
+		string tmpstr = manual[manuallinks[which].line - 1];
+		strip_manual(tmpstr);
 
-			char* ptr;
-			int tmppos;
-			char* base;
-			base = strdup(base_str.c_str());
-			ptr = base + strlen(base) - 3;
-			while (((isalpha(*ptr)) ||(*ptr == '.') ||(*ptr == '_')) &&(ptr > base))
-				ptr--;
-			/* workaround for man pages with leading '(' see svgalib man pages */
-			if (*ptr == '(')
-				ptr++;
-			strcpy(buf, ptr);
-			tmppos = strlen(buf);
-			/* TODO: check the following statement */
-			if (tmppos > 1);
-			buf[tmppos - 2] = 0;
-			strcat(buf, manuallinks[which].name);
-			xfree(base);
+		string::size_type idx;
+		/* Delete last two characters (e.g. .1) FIXME */
+		tmpstr.resize(tmpstr.length() - 2);
+		/* Find tail with decent characters */
+		idx = tmpstr.length() - 1;
+		while (    (    (isalpha(tmpstr[idx]))
+		             || (tmpstr[idx] == '.')
+		             || (tmpstr[idx] == '_')
+		           )
+					  && (idx > 0)
+		      ) {
+			idx--;
 		}
-		/* url reference */
-		else
-		{
-			int namelen = strlen(manuallinks[which].name);
+		/* workaround for man pages with leading '(' see svgalib man pages */
+		if (tmpstr[idx] == '(')
+			idx++;
+		/* Delete characters before tail */
+		tmpstr.replace(0, idx, "");
+	
+		tmpstr.append(manuallinks[which].name);
+		strcpy(buf, tmpstr.c_str());
+	} else {
+		/* URL reference */
+		string tmpstr;
+		tmpstr = manual[manuallinks[which].line + 1];
+		strip_manual(tmpstr);
 
-			string base_str;
-			base_str = manual[manuallinks[which].line + 1];
-			strip_manual(base_str);
+		/* skip whitespace */
+		string::size_type idx = 0;
+		while (isspace(tmpstr[idx]))
+			idx++;
+		tmpstr.replace(0, idx, "");
 
-			char *base;
-			char *ptr, *eptr;
-			base = strdup(base_str.c_str());
-			ptr = base;
-			/* skip whitespace */
-			while (isspace(*ptr))
-				ptr++;
-			eptr = findurlend(ptr);
-			*eptr = 0;
-			strcpy(buf, manuallinks[which].name);
-			/* cut the hyphen */
-			buf[namelen - 1] = 0;
-			strcat(buf, ptr);
-			xfree(base);
-		}
+		/* Cut off anything past the URL end */
+		string::size_type urlend_idx = findurlend(tmpstr);
+		tmpstr.resize(urlend_idx);
+
+		/* Prepend manuallinks[which].name, with its
+		 * trailing hyphen removed
+		 */
+		string tmpname = manuallinks[which].name;
+		tmpname.resize(tmpname.length() - 1);
+		tmpname.append(tmpstr);
+
+		strcpy(buf, tmpname.c_str());
 	}
 }
 




More information about the Pinfo-devel mailing list