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

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


Author: neroden-guest
Date: 2005-08-29 08:00:34 +0000 (Mon, 29 Aug 2005)
New Revision: 72

Modified:
   pinfo/branches/cxx/src/datatypes.cxx
   pinfo/branches/cxx/src/datatypes.h
   pinfo/branches/cxx/src/initializelinks.cxx
   pinfo/branches/cxx/src/mainfunction.cxx
   pinfo/branches/cxx/src/pinfo.cxx
   pinfo/branches/cxx/src/printinfo.cxx
   pinfo/branches/cxx/src/video.cxx
Log:
Major overhaul.  hyperlinks is now a std::vector of HyperObjects, and
HyperObject.node and HyperObject.file are now std::string.
And it all works.  :-)

This eliminates a *lot* of fixed-size buffers.


Modified: pinfo/branches/cxx/src/datatypes.cxx
===================================================================
--- pinfo/branches/cxx/src/datatypes.cxx	2005-08-29 05:25:44 UTC (rev 71)
+++ pinfo/branches/cxx/src/datatypes.cxx	2005-08-29 08:00:34 UTC (rev 72)
@@ -20,7 +20,9 @@
  ***************************************************************************/
 #include "common_includes.h"
 #include <string>
+#include <vector>
 using std::string;
+using std::vector;
 
 RCSID("$Id$")
 
@@ -42,7 +44,7 @@
 
 SearchAgain searchagain;
 
-HyperObject *hyperobjects = 0;
+vector<HyperObject> hyperobjects;
 int hyperobjectcount = 0;
 
 Indirect *indirect = 0;

Modified: pinfo/branches/cxx/src/datatypes.h
===================================================================
--- pinfo/branches/cxx/src/datatypes.h	2005-08-29 05:25:44 UTC (rev 71)
+++ pinfo/branches/cxx/src/datatypes.h	2005-08-29 08:00:34 UTC (rev 72)
@@ -23,6 +23,7 @@
 #define __DATATYPES_H
 
 #include <string>
+#include <vector>
 
 #define FREE 0
 #define LOCKED 1
@@ -68,7 +69,7 @@
 }
 InfoHistory;
 
-typedef struct
+typedef struct HyperObject
 {
 	int line;			/* line number of the place where the link is */
 	int col;			/* column number ----||---- */
@@ -80,10 +81,8 @@
 						   4 -  http url
 						   5 -  ftp url
 						   6 -  mailto url */
-	char node[256];		/* name of the referenced node */
-	int nodelen;		/* length of string node */
-	char file[256];		/* name of the referenced file -- none=this file */
-	int filelen;		/* length of string file */
+	std::string node;		/* name of the referenced node */
+	std::string file;		/* name of the referenced file -- empty=this file */
 	int tagtableoffset;	/* offset in tag table */
 }
 HyperObject;
@@ -124,7 +123,7 @@
 extern SearchAgain searchagain;
 
 /* an array of references for info */
-extern HyperObject *hyperobjects;
+extern std::vector<HyperObject> hyperobjects;
 extern int hyperobjectcount;
 /* an array of indirect entries [1 to n] */
 extern Indirect *indirect;

Modified: pinfo/branches/cxx/src/initializelinks.cxx
===================================================================
--- pinfo/branches/cxx/src/initializelinks.cxx	2005-08-29 05:25:44 UTC (rev 71)
+++ pinfo/branches/cxx/src/initializelinks.cxx	2005-08-29 08:00:34 UTC (rev 72)
@@ -27,17 +27,20 @@
 #define MENU_DOT 0
 #define NOTE_DOT 1
 
+/* Unusable with vectors */
+/* Try life without sorting.  :-) FIXME */
+#if 0
 int
 compare_hyperlink(const void *a, const void *b)
 {
 	return ((HyperObject *) a)->col -((HyperObject *) b)->col;
 }
-
 void
 sort_hyperlinks_from_current_line(long startlink, long endlink)
 {
-	qsort(hyperobjects + startlink, endlink - startlink, sizeof(HyperObject), compare_hyperlink);
+	qsort(hyperobjects[startlink], endlink - startlink, sizeof(HyperObject), compare_hyperlink);
 }
+#endif
 
 /*
  * Compares two strings, ignoring whitespaces(tabs, spaces)
@@ -78,9 +81,12 @@
  * failure.  It should be optimised...
  */
 inline int
-exists_in_tag_table(char *item)
+exists_in_tag_table(const string item)
 {
-	if (gettagtablepos(item) != -1)
+	char * item_working = strdup(item.c_str());
+	int result = gettagtablepos(item_working);
+	xfree(item_working);
+	if (result != -1)
 		return 1;
 	else
 		return 0;
@@ -113,10 +119,7 @@
 void
 freelinks()			/* frees space allocated previously by node-links */
 {
-	if ((hyperobjects)&&(hyperobjectcount))
-		xfree(hyperobjects);
-	hyperobjects = 0;
-	hyperobjectcount = 0;
+	hyperobjects.clear();
 }
 
 /*
@@ -245,8 +248,6 @@
 	char *notestart = 0, *urlstart = 0, *urlend = 0;
 	char *quotestart = 0, *quoteend = 0;
 	char *buf = (char*)xmalloc(strlen(line1) + strlen(line2) + 1);
-	/* required to sort properly the hyperlinks from current line only */
-	long initialhyperobjectcount = hyperobjectcount;
 	int changed;
 	int line1len = strlen(line1);
 
@@ -277,25 +278,20 @@
 						if (quoteend)
 						{
 							changed = 1;
-							if (!hyperobjectcount)
-								hyperobjects = (HyperObject*)xmalloc(sizeof(HyperObject));
-							else
-								hyperobjects = (HyperObject*)xrealloc(hyperobjects, sizeof(HyperObject) *(hyperobjectcount + 1));
-							hyperobjects[hyperobjectcount].line = line;
-							hyperobjects[hyperobjectcount].col = calculate_len(buf, quotestart + 1);
-							hyperobjects[hyperobjectcount].breakpos = -1;	/* default */
+							HyperObject my_ho;
+							my_ho.line = line;
+							my_ho.col = calculate_len(buf, quotestart + 1);
+							my_ho.breakpos = -1;	/* default */
 							if (quoteend > buf + line1len)
 							{
-								hyperobjects[hyperobjectcount].breakpos = buf + line1len - quotestart - 1;
+								my_ho.breakpos = buf + line1len - quotestart - 1;
 							}
-							hyperobjects[hyperobjectcount].type = HIGHLIGHT;
-							strncpy(hyperobjects[hyperobjectcount].node, quotestart + 1, quoteend - quotestart - 1);
-							hyperobjects[hyperobjectcount].node[quoteend - quotestart - 1] = 0;
-							strcpy(hyperobjects[hyperobjectcount].file, "");
-							hyperobjects[hyperobjectcount].nodelen=strlen(hyperobjects[hyperobjectcount].node);
-							hyperobjects[hyperobjectcount].filelen=strlen(hyperobjects[hyperobjectcount].file);
-							hyperobjects[hyperobjectcount].tagtableoffset = -1;
-							hyperobjectcount++;
+							my_ho.type = HIGHLIGHT;
+							my_ho.node.assign(quotestart + 1,
+							                          quoteend - quotestart	- 1 );
+							my_ho.file = "";
+							my_ho.tagtableoffset = -1;
+							hyperobjects.push_back(my_ho);
 						}
 					}
 				}
@@ -312,27 +308,19 @@
 		if ((urlstart = findemailstart(urlend)) != NULL)
 		{
 			urlend = findurlend(urlstart);	/* always successful */
-			if (!hyperobjectcount)
-				hyperobjects = (HyperObject*)xmalloc(sizeof(HyperObject));
-			else
-				hyperobjects = (HyperObject*)xrealloc(hyperobjects, sizeof(HyperObject) *(hyperobjectcount + 1));
-			hyperobjects[hyperobjectcount].line = line;
-			hyperobjects[hyperobjectcount].col = calculate_len(line1, urlstart);
-			hyperobjects[hyperobjectcount].breakpos = -1;
-			hyperobjects[hyperobjectcount].type = 6;
-			strncpy(hyperobjects[hyperobjectcount].node, urlstart, urlend - urlstart);
-			hyperobjects[hyperobjectcount].node[urlend - urlstart] = 0;
-			strcpy(hyperobjects[hyperobjectcount].file, "");
-			hyperobjects[hyperobjectcount].nodelen=strlen(hyperobjects[hyperobjectcount].node);
-			hyperobjects[hyperobjectcount].filelen=strlen(hyperobjects[hyperobjectcount].file);
-			hyperobjects[hyperobjectcount].tagtableoffset = -1;
-			if (strchr(hyperobjects[hyperobjectcount].node, '.') == NULL)
-			{
-				if (!hyperobjectcount)
-					xfree(hyperobjects);
+			HyperObject my_ho;
+			my_ho.line = line;
+			my_ho.col = calculate_len(line1, urlstart);
+			my_ho.breakpos = -1;
+			my_ho.type = 6;
+			my_ho.node.assign(urlstart, urlend - urlstart);
+			my_ho.file = "";
+			my_ho.tagtableoffset = -1;
+			if (my_ho.node.find('.') == string::npos) {
+				; /* For some reason don't include it in this case -- why? */
+			} else {
+				hyperobjects.push_back(my_ho);
 			}
-			else
-				hyperobjectcount++;
 			changed = 1;
 		}
 
@@ -352,60 +340,40 @@
 		tmp = strstr(line1, "::");	/* "* menulink:: comment" */
 		if (tmp != NULL)
 		{
-			if (!hyperobjectcount)
-				hyperobjects = (HyperObject*)xmalloc(sizeof(HyperObject));
-			else
-				hyperobjects = (HyperObject*)xrealloc(hyperobjects, sizeof(HyperObject) *(hyperobjectcount + 1));
 			if (line1[2] == '(')	/* if cross-info link */
 			{
 				char *end = strchr(line1, ')');
 				if ((end != NULL) &&(end < tmp))		/* if the ')' char was found, and was before '::' */
 				{
+					HyperObject my_ho;
+					hyperobjects.push_back(my_ho);
 					long FilenameLen =(long)(end - line1 - 3);
 					long NodenameLen =(long)(tmp - end - 1);
-					strncpy(hyperobjects[hyperobjectcount].file,
-							line1 + 3, FilenameLen);
-					hyperobjects[hyperobjectcount].file[FilenameLen] = 0;
-					strncpy(hyperobjects[hyperobjectcount].node,
-							end + 1, NodenameLen);
-					hyperobjects[hyperobjectcount].node[NodenameLen] = 0;
-					hyperobjects[hyperobjectcount].type = 0;
-					hyperobjects[hyperobjectcount].line = line;
-					hyperobjects[hyperobjectcount].col = 2;
-					hyperobjects[hyperobjectcount].breakpos = -1;
-					hyperobjects[hyperobjectcount].nodelen=strlen(hyperobjects[hyperobjectcount].node);
-					hyperobjects[hyperobjectcount].filelen=strlen(hyperobjects[hyperobjectcount].file);
-					hyperobjectcount++;
+					my_ho.file.assign(line1 + 3, FilenameLen);
+					my_ho.node.assign(end + 1, NodenameLen);
+					my_ho.type = 0;
+					my_ho.line = line;
+					my_ho.col = 2;
+					my_ho.breakpos = -1;
+					hyperobjects.push_back(my_ho);
 				}
 			}
 			else
 				/* if not cross-info link */
 			{
+				HyperObject my_ho;
+				hyperobjects.push_back(my_ho);
 				long NodenameLen =(long)(tmp - line1 - 2);
-				int goodHit = 0;
-				strcpy(hyperobjects[hyperobjectcount].file, "");
-				strncpy(hyperobjects[hyperobjectcount].node,
-						line1 + 2, NodenameLen);
-				hyperobjects[hyperobjectcount].node[NodenameLen] = 0;
-				hyperobjects[hyperobjectcount].type = 0;
-				hyperobjects[hyperobjectcount].line = line;
-				hyperobjects[hyperobjectcount].col = 2;
-				hyperobjects[hyperobjectcount].breakpos = -1;
-				hyperobjects[hyperobjectcount].nodelen=strlen(hyperobjects[hyperobjectcount].node);
-				hyperobjects[hyperobjectcount].filelen=strlen(hyperobjects[hyperobjectcount].file);
-				if (exists_in_tag_table(hyperobjects[hyperobjectcount].node))
+				my_ho.file = "";
+				my_ho.node.assign(line1 + 2, NodenameLen);
+				my_ho.type = 0;
+				my_ho.line = line;
+				my_ho.col = 2;
+				my_ho.breakpos = -1;
+				if (exists_in_tag_table(my_ho.node))
 				{
-					hyperobjectcount++;	/* yep, this was a good hit */
-					goodHit = 1;
+					hyperobjects.push_back(my_ho);
 				}
-				if (!goodHit)
-				{
-					if (!hyperobjectcount)
-					{
-						xfree(hyperobjects);
-						hyperobjects = 0;
-					}
-				}
 			}
 		}
 		/******************************************************************************
@@ -433,23 +401,14 @@
 					{
 						long FilenameLen =(long)(end - start - 1);
 						long NodenameLen =(long)(dot - end - 1);
-						if (!hyperobjectcount)
-							hyperobjects = (HyperObject*)xmalloc(sizeof(HyperObject));
-						else
-							hyperobjects = (HyperObject*)xrealloc(hyperobjects, sizeof(HyperObject) *(hyperobjectcount + 1));
-						strncpy(hyperobjects[hyperobjectcount].file,
-								start + 1, FilenameLen);
-						hyperobjects[hyperobjectcount].file[FilenameLen] = 0;
-						strncpy(hyperobjects[hyperobjectcount].node,
-								end + 1, NodenameLen);
-						hyperobjects[hyperobjectcount].node[NodenameLen] = 0;
-						hyperobjects[hyperobjectcount].type = 1;
-						hyperobjects[hyperobjectcount].line = line;
-						hyperobjects[hyperobjectcount].col = calculate_len(line1, start);
-						hyperobjects[hyperobjectcount].breakpos = -1;
-						hyperobjects[hyperobjectcount].nodelen=strlen(hyperobjects[hyperobjectcount].node);
-						hyperobjects[hyperobjectcount].filelen=strlen(hyperobjects[hyperobjectcount].file);
-						hyperobjectcount++;
+						HyperObject my_ho;
+						my_ho.file.assign(start + 1, FilenameLen);
+						my_ho.node.assign(end + 1, NodenameLen);
+						my_ho.type = 1;
+						my_ho.line = line;
+						my_ho.col = calculate_len(line1, start);
+						my_ho.breakpos = -1;
+						hyperobjects.push_back(my_ho);
 					}
 				}
 				else
@@ -462,39 +421,22 @@
 handle_no_file_menu_label:
 				{
 					long NodenameLen;
-					int goodHit = 0;	/* has val of 1, if it's a good hit */
-					if (!hyperobjectcount)
-						hyperobjects = (HyperObject*)xmalloc(sizeof(HyperObject));
-					else
-						hyperobjects = (HyperObject*)xrealloc(hyperobjects, sizeof(HyperObject) *(hyperobjectcount + 1));
+					HyperObject my_ho;
 
 					start = tmp + 1;	/* move after the padding spaces */
 					while (isspace(*start))
 						start++;
 					NodenameLen =(long)(dot - start);
-					strcpy(hyperobjects[hyperobjectcount].file, "");
-					strncpy(hyperobjects[hyperobjectcount].node,
-							start, NodenameLen);
-					hyperobjects[hyperobjectcount].node[NodenameLen] = 0;
-					hyperobjects[hyperobjectcount].type = 1;
-					hyperobjects[hyperobjectcount].line = line;
-					hyperobjects[hyperobjectcount].col = calculate_len(line1, start);
-					hyperobjects[hyperobjectcount].breakpos = -1;
-					hyperobjects[hyperobjectcount].nodelen=strlen(hyperobjects[hyperobjectcount].node);
-					hyperobjects[hyperobjectcount].filelen=strlen(hyperobjects[hyperobjectcount].file);
-					if (exists_in_tag_table(hyperobjects[hyperobjectcount].node))
+					my_ho.file = "";
+					my_ho.node.assign(start, NodenameLen);
+					my_ho.type = 1;
+					my_ho.line = line;
+					my_ho.col = calculate_len(line1, start);
+					my_ho.breakpos = -1;
+					if (exists_in_tag_table(my_ho.node))
 					{
-						hyperobjectcount++;		/* yep, this was a good hit */
-						goodHit = 1;
+						hyperobjects.push_back(my_ho);
 					}
-					if (!goodHit)
-					{
-						if (!hyperobjectcount)
-						{
-							xfree(hyperobjects);
-							hyperobjects = 0;
-						}
-					}
 				}
 			}
 		}
@@ -519,92 +461,64 @@
 			tmp = strstr(notestart, "::");	/* "*note notelink:: comment" */
 			if (tmp != NULL)
 			{
-				if (!hyperobjectcount)
-					hyperobjects = (HyperObject*)xmalloc(sizeof(HyperObject));
-				else
-					hyperobjects = (HyperObject*)xrealloc(hyperobjects, sizeof(HyperObject) *(hyperobjectcount + 1));
 				if (notestart[6] == '(')	/* if cross-info link */
 				{
 					char *end = strchr(notestart, ')');
 					if ((end != NULL) &&(end < tmp))	/* if the ')' char was found, and was before '::' */
 					{
+						HyperObject my_ho;
 						long FilenameLen =(long)(end - notestart - 7);
 						long NodenameLen =(long)(tmp - end - 1);
-						strncpy(hyperobjects[hyperobjectcount].file,
-								notestart + 7, FilenameLen);
-						hyperobjects[hyperobjectcount].file[FilenameLen] = 0;
-						strncpy(hyperobjects[hyperobjectcount].node,
-								end + 1, NodenameLen);
-						hyperobjects[hyperobjectcount].node[NodenameLen] = 0;
-						hyperobjects[hyperobjectcount].type = 2;
-						if (notestart + 7 - buf < strlen(line1))
-						{
-							hyperobjects[hyperobjectcount].line = line;
-							hyperobjects[hyperobjectcount].col = calculate_len(buf, notestart + 7);
+						my_ho.file.assign(notestart + 7, FilenameLen);
+						my_ho.node.assign(end + 1, NodenameLen);
+						my_ho.type = 2;
+						if (notestart + 7 - buf < strlen(line1)) {
+							my_ho.line = line;
+							my_ho.col = calculate_len(buf, notestart + 7);
 							/* if the note highlight fits int first line */
 							if (tmp - buf < strlen(line1))
-								hyperobjects[hyperobjectcount].breakpos = -1;
+								my_ho.breakpos = -1;
 								/* we don't need to break highlighting int several lines */
 							else
-								hyperobjects[hyperobjectcount].breakpos = strlen(line1) -(long)(notestart + 7 - buf) + 1;	/* otherwise we need it */
-						}
-						else
-						{
-							hyperobjects[hyperobjectcount].line = line + 1;
-							hyperobjects[hyperobjectcount].col = calculate_len(buf + strlen(line1), notestart + 7);
+								my_ho.breakpos = strlen(line1) -(long)(notestart + 7 - buf) + 1;	/* otherwise we need it */
+						} else {
+							my_ho.line = line + 1;
+							my_ho.col = calculate_len(buf + strlen(line1), notestart + 7);
 							if (tmp - buf < strlen(line1))	/* as above */
-								hyperobjects[hyperobjectcount].breakpos = -1;
-							else if ((hyperobjects[hyperobjectcount].breakpos = strlen(line1) -(long)(notestart + 7 - buf) + 1) == 0)
-								hyperobjects[hyperobjectcount].line--;
+								my_ho.breakpos = -1;
+							else if ((my_ho.breakpos = strlen(line1) -(long)(notestart + 7 - buf) + 1) == 0)
+								my_ho.line--;
 						}
-						hyperobjects[hyperobjectcount].nodelen=strlen(hyperobjects[hyperobjectcount].node);
-						hyperobjects[hyperobjectcount].filelen=strlen(hyperobjects[hyperobjectcount].file);
-						hyperobjectcount++;
+						hyperobjects.push_back(my_ho);
 					}
 				}
 				else /* if not cross-info link */
 				{
+					HyperObject my_ho;
 					long NodenameLen =(long)(tmp - notestart - 6);
-					int goodHit = 0;
-					strcpy(hyperobjects[hyperobjectcount].file, "");
-					strncpy(hyperobjects[hyperobjectcount].node,
-							notestart + 6, NodenameLen);
-					hyperobjects[hyperobjectcount].node[NodenameLen] = 0;
-					hyperobjects[hyperobjectcount].type = 2;
-					hyperobjects[hyperobjectcount].nodelen=strlen(hyperobjects[hyperobjectcount].node);
-					hyperobjects[hyperobjectcount].filelen=strlen(hyperobjects[hyperobjectcount].file);
-					if (notestart + 7 - buf < strlen(line1))
-					{
-						hyperobjects[hyperobjectcount].line = line;
-						hyperobjects[hyperobjectcount].col = calculate_len(buf, notestart + 7) - 1;
+					my_ho.file = "";
+					my_ho.node.assign(notestart + 6, NodenameLen);
+					my_ho.type = 2;
+					if (notestart + 7 - buf < strlen(line1)) {
+						my_ho.line = line;
+						my_ho.col = calculate_len(buf, notestart + 7) - 1;
 						/* if the note highlight fits int first line */
 						if (tmp - buf < strlen(line1))
-							hyperobjects[hyperobjectcount].breakpos = -1;	/* we don't need to break highlighting int several lines */
+							my_ho.breakpos = -1;	/* we don't need to break highlighting int several lines */
 						else
-							hyperobjects[hyperobjectcount].breakpos = strlen(line1) -(long)(notestart + 7 - buf) + 1;	/* otherwise we need it */
-					}
-					else
-					{
-						hyperobjects[hyperobjectcount].line = line + 1;
-						hyperobjects[hyperobjectcount].col = calculate_len(buf + strlen(line1), notestart + 7) - 1;
+							my_ho.breakpos = strlen(line1) -(long)(notestart + 7 - buf) + 1;	/* otherwise we need it */
+					} else {
+						my_ho.line = line + 1;
+						my_ho.col = calculate_len(buf + strlen(line1), notestart + 7) - 1;
 						if (tmp - buf < strlen(line1))	/* as above */
-							hyperobjects[hyperobjectcount].breakpos = -1;
-						else if ((hyperobjects[hyperobjectcount].breakpos = strlen(line1) -(long)(notestart + 7 - buf) + 1) == 0)
-							hyperobjects[hyperobjectcount].line--;
+							my_ho.breakpos = -1;
+						else if ((my_ho.breakpos = strlen(line1) -(long)(notestart + 7 - buf) + 1) == 0)
+							my_ho.line--;
 					}
-					if (exists_in_tag_table(hyperobjects[hyperobjectcount].node))
+					if (exists_in_tag_table(my_ho.node))
 					{
-						hyperobjectcount++;	/* yep, this was a good hit */
-						goodHit = 1;
+						hyperobjects.push_back(my_ho);
 					}
-					if (!goodHit)
-					{
-						if (!hyperobjectcount)
-						{
-							xfree(hyperobjects);
-							hyperobjects = 0;
-						}
-					}
 				}
 			}
 			/******************************************************************************
@@ -630,35 +544,23 @@
 						{
 							long FilenameLen =(long)(end - start - 1);
 							long NodenameLen =(long)(dot - end - 1);
-							if (!hyperobjectcount)
-								hyperobjects = (HyperObject*)xmalloc(sizeof(HyperObject));
-							else
-								hyperobjects = (HyperObject*)xrealloc(hyperobjects, sizeof(HyperObject) *(hyperobjectcount + 1));
-							strncpy(hyperobjects[hyperobjectcount].file,
-									start + 1, FilenameLen);
-							hyperobjects[hyperobjectcount].file[FilenameLen] = 0;
-							strncpy(hyperobjects[hyperobjectcount].node,
-									end + 1, NodenameLen);
-							hyperobjects[hyperobjectcount].node[NodenameLen] = 0;
-							hyperobjects[hyperobjectcount].type = 3;
-							if (start - buf < strlen(line1))
-							{
-								hyperobjects[hyperobjectcount].line = line;
-								hyperobjects[hyperobjectcount].col = calculate_len(buf, start);
+							HyperObject my_ho;
+							my_ho.file.assign(start + 1, FilenameLen);
+							my_ho.node.assign(end + 1, NodenameLen);
+							my_ho.type = 3;
+							if (start - buf < strlen(line1)) {
+								my_ho.line = line;
+								my_ho.col = calculate_len(buf, start);
 								if (dot - buf < strlen(line1))	/* if the note highlight fits in first line */
-									hyperobjects[hyperobjectcount].breakpos = -1;	/* we don't need to break highlighting int several lines */
+									my_ho.breakpos = -1;	/* we don't need to break highlighting int several lines */
 								else
-									hyperobjects[hyperobjectcount].breakpos = strlen(line1) -(long)(start - buf);	/* otherwise we need it */
+									my_ho.breakpos = strlen(line1) -(long)(start - buf);	/* otherwise we need it */
+							} else {
+								my_ho.line = line + 1;
+								my_ho.col = calculate_len(buf + strlen(line1), start);
+								my_ho.breakpos = -1;
 							}
-							else
-							{
-								hyperobjects[hyperobjectcount].line = line + 1;
-								hyperobjects[hyperobjectcount].col = calculate_len(buf + strlen(line1), start);
-								hyperobjects[hyperobjectcount].breakpos = -1;
-							}
-							hyperobjects[hyperobjectcount].nodelen=strlen(hyperobjects[hyperobjectcount].node);
-							hyperobjects[hyperobjectcount].filelen=strlen(hyperobjects[hyperobjectcount].file);
-							hyperobjectcount++;
+							hyperobjects.push_back(my_ho);
 						}
 					}
 					else
@@ -671,51 +573,34 @@
 handle_no_file_note_label:
 					{
 						long NodenameLen;
-						int goodHit = 0;
-						if (!hyperobjectcount)
-							hyperobjects = (HyperObject*)xmalloc(sizeof(HyperObject));
-						else
-							hyperobjects = (HyperObject*)xrealloc(hyperobjects, sizeof(HyperObject) *(hyperobjectcount + 1));
+						HyperObject my_ho;
 
 						start = tmp + 1;	/* move after the padding spaces */
 						while (isspace(*start))
 							start++;
 						NodenameLen =(long)(dot - start);
-						strcpy(hyperobjects[hyperobjectcount].file, "");
-						strncpy(hyperobjects[hyperobjectcount].node,
-								start, NodenameLen);
-						hyperobjects[hyperobjectcount].node[NodenameLen] = 0;
-						hyperobjects[hyperobjectcount].type = 3;
-						hyperobjects[hyperobjectcount].nodelen=strlen(hyperobjects[hyperobjectcount].node);
-						hyperobjects[hyperobjectcount].filelen=strlen(hyperobjects[hyperobjectcount].file);
+						my_ho.file = "";
+						my_ho.node.assign(start, NodenameLen);
+						my_ho.type = 3;
 						if (start - buf < strlen(line1))
 						{
-							hyperobjects[hyperobjectcount].line = line;
-							hyperobjects[hyperobjectcount].col = calculate_len(buf, start);
+							my_ho.line = line;
+							my_ho.col = calculate_len(buf, start);
 							if (dot - buf < strlen(line1))		/* if the note highlight fits in first line */
-								hyperobjects[hyperobjectcount].breakpos = -1;		/* we don't need to break highlighting int several lines */
+								my_ho.breakpos = -1;		/* we don't need to break highlighting int several lines */
 							else
-								hyperobjects[hyperobjectcount].breakpos = strlen(line1) -(long)(start - buf);	/* otherwise we need it */
+								my_ho.breakpos = strlen(line1) -(long)(start - buf);	/* otherwise we need it */
 						}
 						else
 						{
-							hyperobjects[hyperobjectcount].line = line + 1;
-							hyperobjects[hyperobjectcount].col = calculate_len(strlen(line1) + buf, start);
-							hyperobjects[hyperobjectcount].breakpos = -1;
+							my_ho.line = line + 1;
+							my_ho.col = calculate_len(strlen(line1) + buf, start);
+							my_ho.breakpos = -1;
 						}
-						if (exists_in_tag_table(hyperobjects[hyperobjectcount].node))
+						if (exists_in_tag_table(my_ho.node))
 						{
-							hyperobjectcount++;	/* yep, this was a good hit */
-							goodHit = 1;
+							hyperobjects.push_back(my_ho);
 						}
-						if (!goodHit)
-						{
-							if (!hyperobjectcount)
-							{
-								xfree(hyperobjects);
-								hyperobjects = 0;
-							}
-						}
 					}
 				}
 			}
@@ -742,45 +627,31 @@
 	while ((urlstart = strstr(urlend, "http://")) != NULL)
 	{
 		urlend = findurlend(urlstart);	/* always successful */
-		if (!hyperobjectcount)
-			hyperobjects = (HyperObject*)xmalloc(sizeof(HyperObject));
-		else
-			hyperobjects = (HyperObject*)xrealloc(hyperobjects, sizeof(HyperObject) *(hyperobjectcount + 1));
-		hyperobjects[hyperobjectcount].line = line;
-		hyperobjects[hyperobjectcount].col = calculate_len(line1, urlstart);
-		hyperobjects[hyperobjectcount].breakpos = -1;
-		hyperobjects[hyperobjectcount].type = 4;
-		strncpy(hyperobjects[hyperobjectcount].node, urlstart, urlend - urlstart);
-		hyperobjects[hyperobjectcount].node[urlend - urlstart] = 0;
-		strcpy(hyperobjects[hyperobjectcount].file, "");
-		hyperobjects[hyperobjectcount].tagtableoffset = -1;
-		hyperobjects[hyperobjectcount].nodelen=strlen(hyperobjects[hyperobjectcount].node);
-		hyperobjects[hyperobjectcount].filelen=strlen(hyperobjects[hyperobjectcount].file);
-		hyperobjectcount++;
+		HyperObject my_ho;
+		my_ho.line = line;
+		my_ho.col = calculate_len(line1, urlstart);
+		my_ho.breakpos = -1;
+		my_ho.type = 4;
+		my_ho.node.assign(urlstart, urlend - urlstart);
+		my_ho.file = "";
+		my_ho.tagtableoffset = -1;
+		hyperobjects.push_back(my_ho);
 	}
 	/* ftp:// */
 	urlend = line1;
 	while ((urlstart = strstr(urlend, "ftp://")) != NULL)
 	{
 		urlend = findurlend(urlstart);	/* always successful */
-		if (!hyperobjectcount)
-			hyperobjects = (HyperObject*)xmalloc(sizeof(HyperObject));
-		else
-			hyperobjects = (HyperObject*)xrealloc(hyperobjects, sizeof(HyperObject) *(hyperobjectcount + 1));
-		hyperobjects[hyperobjectcount].line = line;
-		hyperobjects[hyperobjectcount].col = calculate_len(line1, urlstart);
-		hyperobjects[hyperobjectcount].breakpos = -1;
-		hyperobjects[hyperobjectcount].type = 5;
-		strncpy(hyperobjects[hyperobjectcount].node, urlstart, urlend - urlstart);
-		hyperobjects[hyperobjectcount].node[urlend - urlstart] = 0;
-		strcpy(hyperobjects[hyperobjectcount].file, "");
-		hyperobjects[hyperobjectcount].tagtableoffset = -1;
-		hyperobjects[hyperobjectcount].nodelen=strlen(hyperobjects[hyperobjectcount].node);
-		hyperobjects[hyperobjectcount].filelen=strlen(hyperobjects[hyperobjectcount].file);
-		hyperobjectcount++;
+		HyperObject my_ho;
+		my_ho.line = line;
+		my_ho.col = calculate_len(line1, urlstart);
+		my_ho.breakpos = -1;
+		my_ho.type = 5;
+		my_ho.node.assign(urlstart, urlend - urlstart);
+		my_ho.file = "";
+		my_ho.tagtableoffset = -1;
+		hyperobjects.push_back(my_ho);
 	}
-	if (initialhyperobjectcount != hyperobjectcount)
-		sort_hyperlinks_from_current_line(initialhyperobjectcount, hyperobjectcount);
 	if (buf)
 	{
 		xfree(buf);

Modified: pinfo/branches/cxx/src/mainfunction.cxx
===================================================================
--- pinfo/branches/cxx/src/mainfunction.cxx	2005-08-29 05:25:44 UTC (rev 71)
+++ pinfo/branches/cxx/src/mainfunction.cxx	2005-08-29 08:00:34 UTC (rev 72)
@@ -77,7 +77,7 @@
 	maxx = 80;
 	maxy = 25;
 #endif /*  getmaxyx */
-	/* free memory allocated previously by hypertext links */
+	/* Clear old hyperlink info */
 	freelinks();
 	for (i = 1; i < Lines; i++)	/* initialize node-links for every line */
 	{
@@ -816,7 +816,7 @@
 				cursorchanged = 0;
 				if (cursor != -1)	/* if we must handle cursor... */
 				{
-					if ((cursor > 0) &&(hyperobjectcount))	/* if we really must handle it ;) */
+					if ((cursor > 0) &&(hyperobjects.size()))	/* if we really must handle it ;) */
 						/*
 						 * look if there's a cursor(link) pos available above,
 						 * and if it is visible now.
@@ -841,7 +841,7 @@
 					if (pos > 2)	/* lower the nodepos */
 						pos--;
 					/* and scan for a hyperlink in the new line */
-					for (i = 0; i < hyperobjectcount; i++)
+					for (i = 0; i < hyperobjects.size(); i++)
 					{
 						if (hyperobjects[i].line == pos)
 						{
@@ -861,7 +861,7 @@
 				pos = Lines -(maxy - 2);
 				if (pos < 1)
 					pos = 1;
-				cursor = hyperobjectcount - 1;
+				cursor = hyperobjects.size() - 1;
 			}
 			/*==========================================================================*/
 			if ((key == keys.pgdn_1) ||
@@ -875,12 +875,12 @@
 				else if (Lines -(maxy - 2) >= 1)
 				{
 					pos = Lines -(maxy - 2);
-					cursor = hyperobjectcount - 1;
+					cursor = hyperobjects.size() - 1;
 				}
 				else
 				{
 					pos = 1;
-					cursor = hyperobjectcount - 1;
+					cursor = hyperobjects.size() - 1;
 				}
 			}
 			/*==========================================================================*/
@@ -919,8 +919,8 @@
 					(key == keys.down_2))	/* top+bottom line \|/ */
 			{
 				cursorchanged = 0;	/* works similar to keys.up */
-				if (cursor < hyperobjectcount)
-					for (i = cursor + 1; i < hyperobjectcount; i++)
+				if (cursor < hyperobjects.size())
+					for (i = cursor + 1; i < hyperobjects.size(); i++)
 					{
 						if ((hyperobjects[i].line >= pos) &&
 								(hyperobjects[i].line < pos +(maxy - 2)))
@@ -937,7 +937,7 @@
 				{
 					if (pos <= Lines -(maxy - 2))
 						pos++;
-					for (i = cursor + 1; i < hyperobjectcount; i++)
+					for (i = cursor + 1; i < hyperobjects.size(); i++)
 					{
 						if ((hyperobjects[i].line >= pos) &&
 								(hyperobjects[i].line < pos +(maxy - 2)))
@@ -997,7 +997,7 @@
 				infohistory.menu[infohistory.length] = infomenu;
 				if (!toggled_by_menu)
 					infohistory.menu[infohistory.length] = cursor;
-				if ((cursor >= 0) &&(cursor < hyperobjectcount))
+				if ((cursor >= 0) &&(cursor < hyperobjects.size()))
 					if ((hyperobjects[cursor].line >= pos) &&
 							(hyperobjects[cursor].line < pos +(maxy - 2)) ||
 							(toggled_by_menu))
@@ -1005,10 +1005,10 @@
 						toggled_by_menu = 0;
 						if (hyperobjects[cursor].type < 4)	/* normal info link */
 						{
-							rval.node = (char*)xmalloc(strlen(hyperobjects[cursor].node) + 1);
-							strcpy(rval.node, hyperobjects[cursor].node);
-							rval.file = (char*)xmalloc(strlen(hyperobjects[cursor].file) + 1);
-							strcpy(rval.file, hyperobjects[cursor].file);
+							rval.node = (char*)xmalloc(hyperobjects[cursor].node.length() + 1);
+							strcpy(rval.node, hyperobjects[cursor].node.c_str());
+							rval.file = (char*)xmalloc(hyperobjects[cursor].file.length() + 1);
+							strcpy(rval.file, hyperobjects[cursor].file.c_str());
 							aftersearch = 0;
 							return rval;
 						}
@@ -1016,10 +1016,10 @@
 						{
 							if (hyperobjects[cursor].type == 4)	/* http */
 							{
-								char *tempbuf = (char*)xmalloc(strlen(hyperobjects[cursor].node) + strlen(httpviewer) + 10);
+								char *tempbuf = (char*)xmalloc(hyperobjects[cursor].node.length() + strlen(httpviewer) + 10);
 								strcpy(tempbuf, httpviewer);
 								strcat(tempbuf, " ");
-								strcat(tempbuf, hyperobjects[cursor].node);
+								strcat(tempbuf, hyperobjects[cursor].node.c_str());
 								myendwin();
 								system(tempbuf);
 								doupdate();
@@ -1027,10 +1027,10 @@
 							}
 							else if (hyperobjects[cursor].type == 5)	/* ftp */
 							{
-								char *tempbuf = (char*)xmalloc(strlen(hyperobjects[cursor].node) + strlen(ftpviewer) + 10);
+								char *tempbuf = (char*)xmalloc(hyperobjects[cursor].node.length() + strlen(ftpviewer) + 10);
 								strcpy(tempbuf, ftpviewer);
 								strcat(tempbuf, " ");
-								strcat(tempbuf, hyperobjects[cursor].node);
+								strcat(tempbuf, hyperobjects[cursor].node.c_str());
 								myendwin();
 								system(tempbuf);
 								doupdate();
@@ -1038,10 +1038,10 @@
 							}
 							else if (hyperobjects[cursor].type == 6)	/* mail */
 							{
-								char *tempbuf = (char*)xmalloc(strlen(hyperobjects[cursor].node) + strlen(maileditor) + 10);
+								char *tempbuf = (char*)xmalloc(hyperobjects[cursor].node.length() + strlen(maileditor) + 10);
 								strcpy(tempbuf, maileditor);
 								strcat(tempbuf, " ");
-								strcat(tempbuf, hyperobjects[cursor].node);
+								strcat(tempbuf, hyperobjects[cursor].node.c_str());
 								myendwin();
 								system("clear");
 								system(tempbuf);
@@ -1085,7 +1085,7 @@
 							{
 								if (hyperobjects[i].col <= mouse.x - 1)
 								{
-									if (hyperobjects[i].col + strlen(hyperobjects[i].node) + strlen(hyperobjects[i].file) >= mouse.x - 1)
+									if (hyperobjects[i].col + hyperobjects[i].node.length() + hyperobjects[i].file.length() >= mouse.x - 1)
 									{
 										if (hyperobjects[i].type < HIGHLIGHT)
 										{
@@ -1098,13 +1098,13 @@
 							}
 						}
 						if (!done)
-							for (i = cursor; i < hyperobjectcount; i++)
+							for (i = cursor; i < hyperobjects.size(); i++)
 							{
 								if (hyperobjects[i].line == mouse.y + pos - 1)
 								{
 									if (hyperobjects[i].col <= mouse.x - 1)
 									{
-										if (hyperobjects[i].col + strlen(hyperobjects[i].node) + strlen(hyperobjects[i].file) >= mouse.x - 1)
+										if (hyperobjects[i].col + hyperobjects[i].node.length() + hyperobjects[i].file.length() >= mouse.x - 1)
 										{
 											if (hyperobjects[i].type < HIGHLIGHT)
 											{
@@ -1132,7 +1132,7 @@
 							{
 								if (hyperobjects[i].col <= mouse.x - 1)
 								{
-									if (hyperobjects[i].col + strlen(hyperobjects[i].node) + strlen(hyperobjects[i].file) >= mouse.x - 1)
+									if (hyperobjects[i].col + hyperobjects[i].node.length() + hyperobjects[i].file.length() >= mouse.x - 1)
 									{
 										if (hyperobjects[i].type < HIGHLIGHT)
 										{
@@ -1145,13 +1145,13 @@
 							}
 						}
 						if (!done)
-							for (i = cursor; i < hyperobjectcount; i++)
+							for (i = cursor; i < hyperobjects.size(); i++)
 							{
 								if (hyperobjects[i].line == mouse.y + pos - 1)
 								{
 									if (hyperobjects[i].col <= mouse.x - 1)
 									{
-										if (hyperobjects[i].col + strlen(hyperobjects[i].node) + strlen(hyperobjects[i].file) >= mouse.x - 1)
+										if (hyperobjects[i].col + hyperobjects[i].node.length() + hyperobjects[i].file.length() >= mouse.x - 1)
 										{
 											if (hyperobjects[i].type < HIGHLIGHT)
 											{
@@ -1194,12 +1194,12 @@
 next_infomenu()
 {
 	int i;
-	if (hyperobjectcount == 0)
+	if (hyperobjects.size() == 0)
 	{
 		infomenu = -1;
 		return;
 	}
-	for (i = infomenu + 1; i < hyperobjectcount; i++)
+	for (i = infomenu + 1; i < hyperobjects.size(); i++)
 	{
 		if (hyperobjects[i].type <= 1)	/* menu item */
 		{
@@ -1214,7 +1214,7 @@
 rescan_cursor()
 {
 	int i;
-	for (i = 0; i < hyperobjectcount; i++)
+	for (i = 0; i < hyperobjects.size(); i++)
 	{
 		if ((hyperobjects[i].line >= pos) &&
 				(hyperobjects[i].line < pos +(maxy - 2)))

Modified: pinfo/branches/cxx/src/pinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/pinfo.cxx	2005-08-29 05:25:44 UTC (rev 71)
+++ pinfo/branches/cxx/src/pinfo.cxx	2005-08-29 08:00:34 UTC (rev 72)
@@ -538,7 +538,6 @@
 	fclose(id);
 	closeprogram();
 	/* free's at the end are optional, but look nice :) */
-	freelinks();
 	freeitem(&type, &message, &lines);
 	freetagtable();
 	freeindirect();

Modified: pinfo/branches/cxx/src/printinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/printinfo.cxx	2005-08-29 05:25:44 UTC (rev 71)
+++ pinfo/branches/cxx/src/printinfo.cxx	2005-08-29 08:00:34 UTC (rev 72)
@@ -56,10 +56,10 @@
 			if (hyperobjects[highlight].file[0] == 0)
 				mynode = hyperobjects[highlight].node;
 			else {
-				mynode.assign("(");
-				mynode.append(hyperobjects[highlight].file);
-				mynode.append(")");
-				mynode.append(hyperobjects[highlight].node);
+				mynode = "(";
+				mynode += hyperobjects[highlight].file;
+				mynode += ")";
+				mynode += hyperobjects[highlight].node;
 			}
 			/* if it's a contiunuation of last's line highlight */
 			if (hyperobjects[highlight].line == i - 1) {
@@ -77,7 +77,7 @@
 				fputs(mynode.c_str(), prnFD);
 				lineprinted = hyperobjects[highlight].col + mynode.length();
 			}
-			if (highlight < hyperobjectcount - 1)
+			if (highlight < hyperobjects.size() - 1)
 				highlight++;
 			else
 				break;

Modified: pinfo/branches/cxx/src/video.cxx
===================================================================
--- pinfo/branches/cxx/src/video.cxx	2005-08-29 05:25:44 UTC (rev 71)
+++ pinfo/branches/cxx/src/video.cxx	2005-08-29 08:00:34 UTC (rev 72)
@@ -136,7 +136,7 @@
 info_add_highlights(int pos, int cursor, long lines, int column, char **message)
 {
 	int i, j;
-	for (i = 0; i < hyperobjectcount; i++)
+	for (i = 0; i < hyperobjects.size(); i++)
 	{
 		if ((hyperobjects[i].line < pos) ||
 				(hyperobjects[i].line >= pos +(maxy - 2)))
@@ -164,13 +164,13 @@
 
 		/* now we start actual drawing */
 		string mynode;
-		if (hyperobjects[i].file[0] == 0) {
-			mynode.assign(hyperobjects[i].node, hyperobjects[i].nodelen);
+		if (hyperobjects[i].file == "") {
+			mynode = hyperobjects[i].node;
 		} else {
-			mynode.assign("(");
-			mynode.append(hyperobjects[i].file, hyperobjects[i].filelen);
-			mynode.append(")");
-			mynode.append(hyperobjects[i].node, hyperobjects[i].nodelen);
+			mynode = "(";
+			mynode += hyperobjects[i].file;
+			mynode += ")";
+			mynode += hyperobjects[i].node;
 		}
 		if (hyperobjects[i].breakpos == -1) {
 			info_addstring(1 + hyperobjects[i].line - pos,




More information about the Pinfo-devel mailing list