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

Nathanael Nerode neroden-guest at costa.debian.org
Tue Aug 30 16:13:49 UTC 2005


Author: neroden-guest
Date: 2005-08-30 16:13:48 +0000 (Tue, 30 Aug 2005)
New Revision: 106

Modified:
   pinfo/branches/cxx/src/datatypes.h
   pinfo/branches/cxx/src/filehandling_functions.cxx
   pinfo/branches/cxx/src/mainfunction.cxx
Log:
Stringify Indirect.  Squelch some (but certainly not all) signed-unsigned
warnings.


Modified: pinfo/branches/cxx/src/datatypes.h
===================================================================
--- pinfo/branches/cxx/src/datatypes.h	2005-08-30 15:43:50 UTC (rev 105)
+++ pinfo/branches/cxx/src/datatypes.h	2005-08-30 16:13:48 UTC (rev 106)
@@ -47,8 +47,8 @@
 
 typedef struct Indirect
 {
-	char filename[256];		/* name of file, where's the given offset */
 	long offset;			/* offset of the node */
+	std::string filename;		/* name of file, wherein the given offset is */
 }
 Indirect;
 

Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx	2005-08-30 15:43:50 UTC (rev 105)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx	2005-08-30 16:13:48 UTC (rev 106)
@@ -307,8 +307,8 @@
 #undef Type
 #undef Buf
 #undef Lines
-
 }
+
 void
 load_indirect(char **message, long lines)
 {
@@ -320,11 +320,8 @@
 		if (n == string::npos) {
 			; /* No colon.  Invalid entry. */
 		} else {
-			string filename;
-			filename = wsk_string.substr(0, n);
 			Indirect my_entry;
-			strncpy(my_entry.filename, filename.c_str(), 200);
-
+			my_entry.filename = wsk_string.substr(0, n);
 			string remainder = wsk_string.substr(n + 2, string::npos);
 			my_entry.offset = atoi(remainder.c_str());
 			indirect.push_back(my_entry);
@@ -958,11 +955,10 @@
 create_indirect_tag_table()
 {
 	FILE *id = 0;
-	int i, j, initial;
-	for (i = 0; i < indirect.size(); i++)
+	int initial;
+	for (string::size_type i = 0; i < indirect.size(); i++)
 	{
-		string tmpstr = indirect[i].filename;
-		id = openinfo(tmpstr, 1);
+		id = openinfo(indirect[i].filename, 1);
 		initial = TagTableEntries + 1;
 		if (id)
 		{
@@ -971,7 +967,7 @@
 			FirstNodeName = tag_table[1].nodename;
 		}
 		fclose(id);
-		for (j = initial; j <= TagTableEntries; j++)
+		for (int j = initial; j <= TagTableEntries; j++)
 		{
 			tag_table[j].offset +=(indirect[i].offset - FirstNodeOffset);
 		}
@@ -1071,8 +1067,7 @@
 			{
 				long off = tag_table[tag_table_pos].offset - indirect[i].offset + FirstNodeOffset - 4;
 				fclose(id);
-				string tmpstr = indirect[i].filename;
-				id = openinfo(tmpstr, 0);
+				id = openinfo(indirect[i].filename, 0);
 				if (id == NULL)
 				{
 					closeprogram();

Modified: pinfo/branches/cxx/src/mainfunction.cxx
===================================================================
--- pinfo/branches/cxx/src/mainfunction.cxx	2005-08-30 15:43:50 UTC (rev 105)
+++ pinfo/branches/cxx/src/mainfunction.cxx	2005-08-30 16:13:48 UTC (rev 106)
@@ -23,6 +23,9 @@
 #include "printinfo.h"
 #include <string>
 using std::string;
+#include <vector>
+using std::vector;
+
 RCSID("$Id$")
 
 #include <ctype.h>
@@ -33,7 +36,8 @@
 
 void rescan_cursor();	/* set the cursor to 1st item on visible screen */
 void next_infomenu();	/* go to the next menu item for sequential reading */
-int getnodeoffset(int tag_table_pos, int *Indstart);	/* get node offset in file */
+int getnodeoffset(int tag_table_pos,
+			vector<Indirect>::size_type& indirectstart);	/* get node offset in file */
 
 int aftersearch = 0;
 /*
@@ -41,10 +45,13 @@
  * caused by the sequential auto-pgdn reading code
  */
 int toggled_by_menu = 0;
-long pos, cursor, infomenu, infocolumn=0;
+long pos, infomenu;
+long infocolumn=0;
 
+vector<HyperObject>::size_type cursor;
 
 
+
 /* Inline support functions formerly in menu_and_note_utils.cxx */
 
 /*
@@ -107,8 +114,8 @@
 #define Type	(*type)
 	static WorkRVal rval;
 	FILE *pipe;
-	int i, fileoffset, j;
-	int indirectstart = -1;
+	int fileoffset;
+	vector<Indirect>::size_type indirectstart = -1;
 	int cursorchanged = 0;
 	int key = 0;
 	int return_value;
@@ -129,7 +136,7 @@
 #endif /*  getmaxyx */
 	/* Clear old hyperlink info */
 	freelinks();
-	for (i = 1; i < Lines; i++)	/* initialize node-links for every line */
+	for (int i = 1; i < Lines; i++)	/* initialize node-links for every line */
 	{
 		initializelinks(Message[i], Message[i + 1], i);
 	}
@@ -254,7 +261,7 @@
 							 */
 				{
 					int digit_val = 1;
-					for (i = 0; token[i] != 0; i++)
+					for (int i = 0; token[i] != 0; i++)
 					{
 						if (!isdigit(token[i]))
 							digit_val = 0;
@@ -294,7 +301,7 @@
 				pipe = popen(token, "w");	/* open pipe */
 				if (pipe != NULL)
 				{
-					for (i = 1; i <= Lines; i++)	/* and flush the msg to stdin */
+					for (int i = 1; i <= Lines; i++)	/* and flush the msg to stdin */
 						fprintf(pipe, "%s", Message[i]);
 					pclose(pipe);
 					getchar();
@@ -366,11 +373,11 @@
 
 				/* Calculate current info file offset...  */
 				fileoffset = 0;
-				for (i = 1; i <= pos + 1; i++)	/* count the length of curnode */
+				for (int i = 1; i <= pos + 1; i++)	/* count the length of curnode */
 					fileoffset += strlen(Message[i]);
 				fileoffset += strlen(Type);	/* add also header length */
 
-				fileoffset += getnodeoffset(tag_table_pos, &indirectstart);	/* also load the variable indirectstart */
+				fileoffset += getnodeoffset(tag_table_pos, indirectstart);	/* also load the variable indirectstart */
 
 				/* Searching part...  */
 				aftersearch = 0;
@@ -384,10 +391,10 @@
 					long tokenpos;
 					long starttokenpos;
 					long filelen;
-					for (j = indirectstart; j < indirect.size(); j++)
+					for (vector<Indirect>::size_type j = indirectstart;
+					     j < indirect.size(); j++)
 					{
-						string tmpstr = indirect[j].filename;
-						fd = openinfo(tmpstr, 1);	/* get file length. */
+						fd = openinfo(indirect[j].filename, 1);	/* get file length. */
 						fseek(fd, 0, SEEK_END);
 						filelen = ftell(fd);
 
@@ -419,7 +426,7 @@
 							{	/* local scope for tmpvar, matched */
 								int tmpvar = 0, matched = 0;
 								tag_table[0].offset = 0;
-								for (i = TagTableEntries; i >= 1; i--)
+								for (int i = TagTableEntries; i >= 1; i--)
 								{
 									if ((tag_table[i].offset > tag_table[tmpvar].offset) &&
 											((tag_table[i].offset - indirect[j].offset + FirstNodeOffset) <= tokenpos))
@@ -514,7 +521,7 @@
 						{		/* local scope for tmpvar, matched */
 							int tmpvar = 0, matched = 0;
 							tag_table[0].offset = 0;
-							for (i = TagTableEntries; i >= 1; i--)
+							for (int i = TagTableEntries; i >= 1; i--)
 							{
 								if ((tag_table[i].offset > tag_table[tmpvar].offset) &&
 										(tag_table[i].offset <= tokenpos))
@@ -630,7 +637,7 @@
 					
 				}
 				/* scan for the token in the following lines.  */
-				for (i = pos + 1; i < Lines; i++)
+				for (int i = pos + 1; i < Lines; i++)
 				{
 					tmp = (char*)xmalloc(strlen(Message[i]) + strlen(Message[i + 1]) + 2);
 					/*
@@ -694,7 +701,7 @@
 				curs_set(0);
 				noecho();
 				attrset(normal);
-				for (i = 1; i <= TagTableEntries; i++)
+				for (int i = 1; i <= TagTableEntries; i++)
 				{
 					/* if the name was found in the tag table */
 					if (strcmp(token, tag_table[i].nodename) == 0)
@@ -848,14 +855,15 @@
 					(key == keys.up_2))
 			{
 				cursorchanged = 0;
-				if (cursor != -1)	/* if we must handle cursor... */
-				{
-					if ((cursor > 0) &&(hyperobjects.size()))	/* if we really must handle it ;) */
+				if (cursor != (vector<HyperObject>::size_type)-1)	{
+					/* if we must handle cursor... */
+					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.
 						 */
-						for (i = cursor - 1; i >= 0; i--)
+						for (int i = cursor - 1; i >= 0; i--)
 						{
 							if ((hyperobjects[i].line >= pos) &&
 									(hyperobjects[i].line < pos +(maxy - 1)))
@@ -875,8 +883,8 @@
 					if (pos > 2)	/* lower the nodepos */
 						pos--;
 					/* and scan for a hyperlink in the new line */
-					for (i = 0; i < hyperobjects.size(); i++)
-					{
+					for (vector<HyperObject>::size_type i = 0;
+					     i < hyperobjects.size(); i++) {
 						if (hyperobjects[i].line == pos)
 						{
 							if (hyperobjects[i].type < HIGHLIGHT)
@@ -954,7 +962,8 @@
 			{
 				cursorchanged = 0;	/* works similar to keys.up */
 				if (cursor < hyperobjects.size())
-					for (i = cursor + 1; i < hyperobjects.size(); i++)
+					for (vector<HyperObject>::size_type i = cursor + 1;
+					     i < hyperobjects.size(); i++)
 					{
 						if ((hyperobjects[i].line >= pos) &&
 								(hyperobjects[i].line < pos +(maxy - 2)))
@@ -971,7 +980,8 @@
 				{
 					if (pos <= Lines -(maxy - 2))
 						pos++;
-					for (i = cursor + 1; i < hyperobjects.size(); i++)
+					for (vector<HyperObject>::size_type i = cursor + 1;
+					     i < hyperobjects.size(); i++)
 					{
 						if ((hyperobjects[i].line >= pos) &&
 								(hyperobjects[i].line < pos +(maxy - 2)))
@@ -1029,7 +1039,7 @@
 				infohistory.menu[infohistory.length] = infomenu;
 				if (!toggled_by_menu)
 					infohistory.menu[infohistory.length] = cursor;
-				if ((cursor >= 0) &&(cursor < hyperobjects.size()))
+				if ((cursor >= 0) && (cursor < hyperobjects.size()))
 					if ((hyperobjects[cursor].line >= pos) &&
 							(hyperobjects[cursor].line < pos +(maxy - 2)) ||
 							(toggled_by_menu))
@@ -1104,7 +1114,7 @@
 				{
 					if ((mouse.y > 0) &&(mouse.y < maxy - 1))
 					{
-						for (i = cursor; i > 0; i--)
+						for (vector<HyperObject>::size_type i = cursor; i > 0; i--)
 						{
 							if (hyperobjects[i].line == mouse.y + pos - 1)
 							{
@@ -1123,7 +1133,8 @@
 							}
 						}
 						if (!done)
-							for (i = cursor; i < hyperobjects.size(); i++)
+							for (vector<HyperObject>::size_type i = cursor;
+							     i < hyperobjects.size(); i++)
 							{
 								if (hyperobjects[i].line == mouse.y + pos - 1)
 								{
@@ -1151,7 +1162,7 @@
 				{
 					if ((mouse.y > 0) &&(mouse.y < maxy - 1))
 					{
-						for (i = cursor; i >= 0; i--)
+						for (vector<HyperObject>::size_type i = cursor; i >= 0; i--)
 						{
 							if (hyperobjects[i].line == mouse.y + pos - 1)
 							{
@@ -1170,7 +1181,8 @@
 							}
 						}
 						if (!done)
-							for (i = cursor; i < hyperobjects.size(); i++)
+							for (vector<HyperObject>::size_type i = cursor;
+							     i < hyperobjects.size(); i++)
 							{
 								if (hyperobjects[i].line == mouse.y + pos - 1)
 								{
@@ -1218,28 +1230,24 @@
 void
 next_infomenu()
 {
-	int i;
-	if (hyperobjects.size() == 0)
-	{
+	if (hyperobjects.size() == 0) {
 		infomenu = -1;
 		return;
 	}
-	for (i = infomenu + 1; i < hyperobjects.size(); i++)
-	{
-		if (hyperobjects[i].type <= 1)	/* menu item */
-		{
+	for (vector<HyperObject>::size_type i = infomenu + 1;
+	     i < hyperobjects.size(); i++) {
+		if (hyperobjects[i].type <= 1) { /* menu item */
 			infomenu = i;
 			return;
 		}
 	}
-	infomenu = -1;		/* no menuitem left is found */
+	infomenu = -1;		/* no more menuitems found */
 }
 
 void
 rescan_cursor()
 {
-	int i;
-	for (i = 0; i < hyperobjects.size(); i++)
+	for (vector<HyperObject>::size_type i = 0; i < hyperobjects.size(); i++)
 	{
 		if ((hyperobjects[i].line >= pos) &&
 				(hyperobjects[i].line < pos +(maxy - 2)))
@@ -1254,13 +1262,14 @@
 }
 
 int
-getnodeoffset(int tag_table_pos, int *Indstart)	/* count node offset in file */
+getnodeoffset(int tag_table_pos,
+              vector<Indirect>::size_type& indirectstart)
+							/* count node offset in file */
 {
-#define indirectstart	(*Indstart)
-	int i, fileoffset = 0;
+	int fileoffset = 0;
 	if (!indirect.empty())
 	{
-		for (i = indirect.size() - 1; i >= 0; i--)
+		for (vector<Indirect>::size_type i = indirect.size() - 1; i >= 0; i--)
 		{
 			if (indirect[i].offset <= tag_table[tag_table_pos].offset)
 			{
@@ -1275,5 +1284,4 @@
 		fileoffset +=(tag_table[tag_table_pos].offset - 2);
 	}
 	return fileoffset;
-#undef indirectstart
 }




More information about the Pinfo-devel mailing list