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

Nathanael Nerode neroden-guest at costa.debian.org
Fri Sep 2 03:37:31 UTC 2005


Author: neroden-guest
Date: 2005-09-02 03:37:31 +0000 (Fri, 02 Sep 2005)
New Revision: 123

Modified:
   pinfo/branches/cxx/src/datatypes.cxx
   pinfo/branches/cxx/src/datatypes.h
   pinfo/branches/cxx/src/mainfunction.cxx
   pinfo/branches/cxx/src/pinfo.cxx
Log:
Convert InfoHistory to a std::vector.


Modified: pinfo/branches/cxx/src/datatypes.cxx
===================================================================
--- pinfo/branches/cxx/src/datatypes.cxx	2005-09-02 03:13:16 UTC (rev 122)
+++ pinfo/branches/cxx/src/datatypes.cxx	2005-09-02 03:37:31 UTC (rev 123)
@@ -64,7 +64,7 @@
 int ClearScreenAtExit = 0;
 int CallReadlineHistory = 1;
 
-InfoHistory infohistory;
+vector<InfoHistory> infohistory;
 
 int npos = -1;
 int ncursor = -1;
@@ -80,12 +80,7 @@
 void
 inithistory()
 {
-	infohistory.length = 0;
-	infohistory.node = 0;
-	infohistory.file = 0;
-	infohistory.pos = 0;
-	infohistory.cursor = 0;
-	infohistory.menu = 0;
+	infohistory.clear();
 }
 
 /*
@@ -94,33 +89,15 @@
 void
 addinfohistory(const char *file, const char *node, int cursor, int menu, int pos)
 {
-	if (!infohistory.length)
-	{
-		infohistory.length++;
-		infohistory.node = (char**)xmalloc(sizeof(char *) * 2);
-		infohistory.node[0] = 0;
-		infohistory.file = (char**)xmalloc(sizeof(char *) * 2);
-		infohistory.file[0] = 0;
-		infohistory.pos = (int*)xmalloc(sizeof(int) * 2);
-		infohistory.cursor = (int*)xmalloc(sizeof(int) * 2);
-		infohistory.menu = (int*)xmalloc(sizeof(int) * 2);
-	}
-	else
-	{
-		infohistory.length++;
-		infohistory.node = (char**)xrealloc(infohistory.node, sizeof(char *) *(infohistory.length + 1));
-		infohistory.file = (char**)xrealloc(infohistory.file, sizeof(char *) *(infohistory.length + 1));
-		infohistory.pos = (int*)xrealloc(infohistory.pos, sizeof(int) *(infohistory.length + 1));
-		infohistory.cursor = (int*)xrealloc(infohistory.cursor, sizeof(int) *(infohistory.length + 1));
-		infohistory.menu = (int*)xrealloc(infohistory.menu, sizeof(int) *(infohistory.length + 1));
-	}
-	infohistory.node[infohistory.length] = (char*)xmalloc(strlen(node) + 1);
-	strcpy(infohistory.node[infohistory.length], node);
-	infohistory.file[infohistory.length] = (char*)xmalloc(strlen(file) + 1);
-	strcpy(infohistory.file[infohistory.length], file);
-	infohistory.pos[infohistory.length] = pos;
-	infohistory.cursor[infohistory.length] = cursor;
-	infohistory.menu[infohistory.length] = menu;
+	InfoHistory my_hist;
+	my_hist.node = (char*)xmalloc(strlen(node) + 1);
+	strcpy(my_hist.node, node);
+	my_hist.file = (char*)xmalloc(strlen(file) + 1);
+	strcpy(my_hist.file, file);
+	my_hist.pos = pos;
+	my_hist.cursor = cursor;
+	my_hist.menu = menu;
+	infohistory.push_back(my_hist);
 }
 
 /*
@@ -129,56 +106,17 @@
 void
 dellastinfohistory()
 {
-	if (infohistory.length)
-	{
-		if (infohistory.node[infohistory.length])
-		{
-			xfree(infohistory.node[infohistory.length]);
-			infohistory.node[infohistory.length] = 0;
-		}
-		if (infohistory.file[infohistory.length])
-		{
-			xfree(infohistory.file[infohistory.length]);
-			infohistory.file[infohistory.length] = 0;
-		}
-		if (infohistory.length)
-			infohistory.length--;
-		if (infohistory.length)
-		{
-			infohistory.node = (char**)xrealloc(infohistory.node, sizeof(char *) *(infohistory.length + 1));
-			infohistory.file = (char**)xrealloc(infohistory.file, sizeof(char *) *(infohistory.length + 1));
-			infohistory.pos = (int*)xrealloc(infohistory.pos, sizeof(int) *(infohistory.length + 1));
-			infohistory.cursor = (int*)xrealloc(infohistory.cursor, sizeof(int) *(infohistory.length + 1));
-			infohistory.menu = (int*)xrealloc(infohistory.menu, sizeof(int) *(infohistory.length + 1));
-		}
-		else
-		{
-			if (infohistory.node)
-			{
-				xfree(infohistory.node);
-				infohistory.node = 0;
-			}
-			if (infohistory.file)
-			{
-				xfree(infohistory.file);
-				infohistory.file = 0;
-			}
-			if (infohistory.pos)
-			{
-				xfree(infohistory.pos);
-				infohistory.pos = 0;
-			}
-			if (infohistory.cursor)
-			{
-				xfree(infohistory.cursor);
-				infohistory.cursor = 0;
-			}
-			if (infohistory.menu)
-			{
-				xfree(infohistory.menu);
-				infohistory.menu = 0;
-			}
-		}
+	if (infohistory.empty()) {
+		return;
 	}
+	if (infohistory[infohistory.size() - 1].node)	{
+		xfree(infohistory[infohistory.size() - 1].node);
+		infohistory[infohistory.size() - 1].node = 0;
+	}
+	if (infohistory[infohistory.size() - 1].file) {
+		xfree(infohistory[infohistory.size() - 1].file);
+		infohistory[infohistory.size() - 1].file = 0;
+	}
+	infohistory.pop_back();
 }
 

Modified: pinfo/branches/cxx/src/datatypes.h
===================================================================
--- pinfo/branches/cxx/src/datatypes.h	2005-09-02 03:13:16 UTC (rev 122)
+++ pinfo/branches/cxx/src/datatypes.h	2005-09-02 03:37:31 UTC (rev 123)
@@ -59,14 +59,13 @@
 }
 TagTable;
 
-typedef struct
+typedef struct InfoHistory
 {
-	int length;
-	char **node;	/* array of history of nodes */
-	char **file;	/* array of history of files, associated with given nodes */
-	int *pos;		/* history of pos offsets in viewed nodes */
-	int *cursor;	/* history of cursor offsets in viewed nodes */
-	int *menu;		/* history of menu positions (in sequential reading) in viewed nodes */
+	char *node;	/* node */
+	char *file;	/* file associated with given node */
+	int pos;		/* pos offset in viewed nodes */
+	int cursor;	/* cursor offsets in viewed nodes */
+	int menu;		/* menu position (in sequential reading) in viewed node */
 }
 InfoHistory;
 
@@ -135,7 +134,7 @@
 extern std::string FirstNodeName;
 /* maximum dimensions of screen */
 extern int maxx, maxy;
-extern InfoHistory infohistory;
+extern std::vector<InfoHistory> infohistory;
 /* position to by set when moving via history */
 extern int npos;
 /* cursor pos to be set when..... as above */

Modified: pinfo/branches/cxx/src/mainfunction.cxx
===================================================================
--- pinfo/branches/cxx/src/mainfunction.cxx	2005-09-02 03:13:16 UTC (rev 122)
+++ pinfo/branches/cxx/src/mainfunction.cxx	2005-09-02 03:37:31 UTC (rev 123)
@@ -582,9 +582,9 @@
 
 				if (return_value != -1)
 				{
-					infohistory.pos[infohistory.length] = pos;
-					infohistory.cursor[infohistory.length] = cursor;
-					infohistory.menu[infohistory.length] = infomenu;
+					infohistory[infohistory.size() - 1].pos = pos;
+					infohistory[infohistory.size() - 1].cursor = cursor;
+					infohistory[infohistory.size() - 1].menu = infomenu;
 					rval.node = tag_table[return_value].nodename;
 					rval.file = "";
 					rval.keep_going = true;
@@ -712,9 +712,10 @@
 				{
 					xfree(token);
 					token = 0;
-					infohistory.pos[infohistory.length] = pos;
-					infohistory.cursor[infohistory.length] = cursor;
-					infohistory.menu[infohistory.length] = infomenu;
+
+					infohistory[infohistory.size() - 1].pos = pos;
+					infohistory[infohistory.size() - 1].cursor = cursor;
+					infohistory[infohistory.size() - 1].menu = infomenu;
 					rval.node = tag_table[return_value].nodename;
 					rval.file = "";
 					rval.keep_going = true;
@@ -788,9 +789,9 @@
 				return_value = gettagtablepos(token_str.c_str());
 				if (return_value != -1)
 				{
-					infohistory.pos[infohistory.length] = pos;
-					infohistory.cursor[infohistory.length] = cursor;
-					infohistory.menu[infohistory.length] = infomenu;
+					infohistory[infohistory.size() - 1].pos = pos;
+					infohistory[infohistory.size() - 1].cursor = cursor;
+					infohistory[infohistory.size() - 1].menu = infomenu;
 					rval.node = tag_table[return_value].nodename;
 					rval.file = "";
 					rval.keep_going = true;
@@ -807,9 +808,9 @@
 				return_value = gettagtablepos(token_str.c_str());
 				if (return_value != -1)
 				{
-					infohistory.pos[infohistory.length] = pos;
-					infohistory.cursor[infohistory.length] = cursor;
-					infohistory.menu[infohistory.length] = infomenu;
+					infohistory[infohistory.size() - 1].pos = pos;
+					infohistory[infohistory.size() - 1].cursor = cursor;
+					infohistory[infohistory.size() - 1].menu = infomenu;
 					rval.node = tag_table[return_value].nodename;
 					rval.file = "";
 					rval.keep_going = true;
@@ -831,9 +832,9 @@
 				{
 					if (toggled_by_menu == KEEP_HISTORY)
 					{
-						infohistory.pos[infohistory.length] = pos;
-						infohistory.cursor[infohistory.length] = cursor;
-						infohistory.menu[infohistory.length] = infomenu;
+						infohistory[infohistory.size() - 1].pos = pos;
+						infohistory[infohistory.size() - 1].cursor = cursor;
+						infohistory[infohistory.size() - 1].menu = infomenu;
 					}
 					rval.node = tag_table[return_value].nodename;
 					rval.file = "";
@@ -998,9 +999,9 @@
 			if ((key == keys.top_1) ||
 					(key == keys.top_2))
 			{
-				infohistory.pos[infohistory.length] = pos;
-				infohistory.cursor[infohistory.length] = cursor;
-				infohistory.menu[infohistory.length] = infomenu;
+				infohistory[infohistory.size() - 1].pos = pos;
+				infohistory[infohistory.size() - 1].cursor = cursor;
+				infohistory[infohistory.size() - 1].menu = infomenu;
 				rval.node = FirstNodeName;
 				rval.file = "";
 				rval.keep_going = true;
@@ -1011,18 +1012,18 @@
 			if ((key == keys.back_1) ||
 					(key == keys.back_2))
 			{
-				if (infohistory.length > 1)
+				if (infohistory.size() > 1)
 				{
 					dellastinfohistory();	/* remove history entry for this node */
 					/* now we deal with the previous node history entry */
 
-					rval.node = infohistory.node[infohistory.length];
-					rval.file = infohistory.file[infohistory.length];
+					rval.node = infohistory[infohistory.size() - 1].node;
+					rval.file = infohistory[infohistory.size() - 1].file;
 					rval.keep_going = true;
 
-					npos = infohistory.pos[infohistory.length];
-					ncursor = infohistory.cursor[infohistory.length];
-					nmenu = infohistory.menu[infohistory.length];
+					npos = infohistory[infohistory.size() - 1].pos;
+					ncursor = infohistory[infohistory.size() - 1].cursor;
+					nmenu = infohistory[infohistory.size() - 1].menu;
 					dellastinfohistory();	/* remove history entry for previous node */
 					aftersearch = 0;
 					return rval;
@@ -1032,11 +1033,11 @@
 			if ((key == keys.followlink_1) ||
 					(key == keys.followlink_2))
 			{
-				infohistory.pos[infohistory.length] = pos;
-				infohistory.cursor[infohistory.length] = cursor;
-				infohistory.menu[infohistory.length] = infomenu;
+				infohistory[infohistory.size() - 1].pos = pos;
+				infohistory[infohistory.size() - 1].cursor = cursor;
+				infohistory[infohistory.size() - 1].menu = infomenu;
 				if (!toggled_by_menu)
-					infohistory.menu[infohistory.length] = cursor;
+					infohistory[infohistory.size() - 1].menu = cursor;
 				if ((cursor >= 0) && (cursor < hyperobjects.size()))
 					if ((hyperobjects[cursor].line >= pos) &&
 							(hyperobjects[cursor].line < pos +(maxy - 2)) ||

Modified: pinfo/branches/cxx/src/pinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/pinfo.cxx	2005-09-02 03:13:16 UTC (rev 122)
+++ pinfo/branches/cxx/src/pinfo.cxx	2005-09-02 03:37:31 UTC (rev 123)
@@ -427,10 +427,10 @@
 						attrset(normal);
 						getch();
 						filenotfound = 1;
-						if (infohistory.length)
+						if (infohistory.size())
 						{
-							npos = infohistory.pos[infohistory.length];
-							ncursor = infohistory.cursor[infohistory.length];
+							npos = infohistory[infohistory.size() - 1].pos;
+							ncursor = infohistory[infohistory.size() - 1].pos;
 						}
 						/* open back the old file */
 						strip_info_suffix_from_file(curfile);




More information about the Pinfo-devel mailing list