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

Nathanael Nerode neroden-guest at costa.debian.org
Wed Sep 7 08:35:25 UTC 2005


Author: neroden-guest
Date: 2005-09-07 08:35:24 +0000 (Wed, 07 Sep 2005)
New Revision: 203

Modified:
   pinfo/branches/cxx/src/filehandling_functions.cxx
   pinfo/branches/cxx/src/mainfunction.cxx
   pinfo/branches/cxx/src/manual.cxx
   pinfo/branches/cxx/src/utils.cxx
   pinfo/branches/cxx/src/utils.h
Log:
Make getstring() return a string, and patch up stuff all over the place
to match.


Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx	2005-09-07 08:14:41 UTC (rev 202)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx	2005-09-07 08:35:24 UTC (rev 203)
@@ -614,12 +614,12 @@
 	filelen = ftell(id);
 
 	char *tmp;
-	tmp = (char*)xmalloc(filelen);
+	tmp = new char[filelen];
 	fseek(id, 0, SEEK_SET);
 	fread(tmp, 1, filelen, id);
 	fclose(id);
 	string tmpstr = tmp;
-	xfree(tmp);
+	delete tmp;
 
 	id = fopen(tmpfilename.c_str(), "w");
 	bool aswitch = false;

Modified: pinfo/branches/cxx/src/mainfunction.cxx
===================================================================
--- pinfo/branches/cxx/src/mainfunction.cxx	2005-09-07 08:14:41 UTC (rev 202)
+++ pinfo/branches/cxx/src/mainfunction.cxx	2005-09-07 08:35:24 UTC (rev 203)
@@ -118,7 +118,7 @@
 	int key = 0;
 	int return_value;
 	int statusline = FREE;
-	char *token, *tmp;
+	char *tmp;
 	/* if the static variable was allocated, free it */
 	rval.file = "";
 	rval.node = "";
@@ -252,26 +252,25 @@
 				move(maxy - 1, 0);
 				echo();
 				curs_set(1);
-				token = getstring(_("Enter line: "));
+				string token_string = getstring(_("Enter line: "));
 				curs_set(0);
 				noecho();
 				move(maxy - 1, 0);
 				myclrtoeol();
 				attrset(normal);
-				if (token)	/*
-							 * convert string to long.
-							 * careful with nondigit strings.
-							 */
-				{
-					int digit_val = 1;
-					for (int i = 0; token[i] != 0; i++)
-					{
-						if (!isdigit(token[i]))
-							digit_val = 0;
+				if (token_string != "") {
+					/*
+					 * convert string to long.
+					 * careful with nondigit strings.
+					 */
+					bool digit_val = true;
+					for (string::size_type i = 0; i < token_string.length(); i++) {
+						if (!isdigit(token_string[i]))
+							digit_val = false;
 					}
-					if (digit_val)	/* go to specified line */
-					{
-						newpos = atol(token);
+					if (digit_val) {
+						/* go to specified line */
+						newpos = atol(token_string.c_str());
 						newpos -=(maxy - 1);
 						if ((newpos > 0) &&(newpos < my_message.size() -(maxy - 2)))
 							pos = newpos;
@@ -280,8 +279,6 @@
 						else
 							pos = 1;
 					}
-					xfree(token);
-					token = 0;
 				}
 			}
 			/*==========================================================================*/
@@ -293,7 +290,7 @@
 				move(maxy - 1, 0);
 				echo();
 				curs_set(1);
-				token = getstring(_("Enter command: "));
+				string token_string = getstring(_("Enter command: "));
 				noecho();
 				move(maxy - 1, 0);
 				myclrtoeol();
@@ -301,9 +298,8 @@
 
 				myendwin();
 				system("clear");
-				pipe = popen(token, "w");	/* open pipe */
-				if (pipe != NULL)
-				{
+				pipe = popen(token_string.c_str(), "w");	/* open pipe */
+				if (pipe != NULL) {
 					/* and flush the msg to stdin */
 					for (int i = 0; i < my_message.size(); i++)	
 						fprintf(pipe, "%s", my_message[i].c_str());
@@ -314,8 +310,6 @@
 				curs_set(0);
 				if (pipe == NULL)
 					mvaddstr(maxy - 1, 0, _("Operation failed..."));
-				xfree(token);
-				token = 0;
 			}
 			/*==========================================================================*/
 			if ((key == keys.dirpage_1) ||
@@ -346,29 +340,27 @@
 				attrset(bottomline);
 				echo();
 				curs_set(1);
-				if (!searchagain.search)	/* if searchagain key wasn't hit */
-				{
-					token = getstring(_("Enter regexp: "));	/* get the token */
-					searchagain.lastsearch = token;	/* and save it to searchagain buffer */
+				string token_string;
+				if (!searchagain.search) {
+					/* if searchagain key wasn't hit */
+					token_string = getstring(_("Enter regexp: "));
+					/* save it to searchagain buffer */
+					searchagain.lastsearch = token_string;	
 					/*
 					 * give a hint, which key to ungetch to call this procedure
 					 * by searchagain
 					 */
 					searchagain.type = key;
-				}
-				else /* it IS searchagain */
-				{
-					token = (char*)xmalloc(searchagain.lastsearch.length() + 1);
-					/* allocate space for token */
-					strcpy(token, searchagain.lastsearch.c_str());
+				} else {
+					/* it IS searchagain */
+					token_string = searchagain.lastsearch;
 					/* copy the token from searchagain buffer */
 					searchagain.search = 0;
-					/* reset the searchagain swith(until it's set again
-					   by the keys.searchagain key handler) */
+					/* reset the searchagain switch (until it's set again
+					 * by the keys.searchagain key handler) */
 				}
-				if (strlen(token) == 0)
+				if (token_string == "")
 				{
-					xfree(token);
 					goto skip_search;
 				}
 				curs_set(0);
@@ -419,7 +411,7 @@
 						fread(tmp, 1, filelen - starttokenpos, fd);
 						tmp[filelen - starttokenpos + 1] = 0;
 
-						tokenpos = regexp_search(token, tmp);	/* search */
+						tokenpos = regexp_search(token_string.c_str(), tmp);	/* search */
 
 						if (tokenpos != -1)	/* if something was found */
 						{
@@ -513,7 +505,7 @@
 					tmp[filelen - starttokenpos + 1] = 0;
 
 					/* search */
-					tokenpos = regexp_search(token, tmp);
+					tokenpos = regexp_search(token_string.c_str(), tmp);
 
 					if (tokenpos != -1)	/* if we've found something */
 					{
@@ -572,8 +564,6 @@
 					}
 				}		/* end: if (!indirect) */
 				/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
-				xfree(token);
-				token = 0;
 
 				if (!aftersearch)
 				{
@@ -605,28 +595,27 @@
 				attrset(bottomline);
 				echo();
 				curs_set(1);
+				string token_string;
 				if (!searchagain.search)	/* searchagain handler. see totalsearch */
 				{
-					token = getstring(_("Enter regexp: "));
-					searchagain.lastsearch = token;
+					token_string = getstring(_("Enter regexp: "));
+					searchagain.lastsearch = token_string;
 					searchagain.type = key;
 				}
 				else
 				{
-					token = (char*)xmalloc(searchagain.lastsearch.length() + 1);
-					strcpy(token, searchagain.lastsearch.c_str());
+					token_string = searchagain.lastsearch;
 					searchagain.search = 0;
 				}		/* end of searchagain handler */
-				if (strlen(token) == 0)
+				if (token_string == "")
 				{
-					xfree(token);
 					goto skip_search;
 				}
 				curs_set(0);
 				noecho();
 				attrset(normal);
 				/* compile the read token */
-				if (pinfo_re_comp(token) != 0)
+				if (pinfo_re_comp(token_string.c_str()) != 0)
 				{
 					/* print error message */
 					attrset(bottomline);
@@ -677,8 +666,6 @@
 					mvaddstr(maxy - 1, 0, _("Search string not found..."));
 					statusline = LOCKED;
 				}
-				xfree(token);	/* free user's search token */
-				token = 0;
 				rescan_cursor();	/* rescan cursor position in the new place */
 			}
 skip_search:
@@ -703,14 +690,14 @@
 				move(maxy - 1, 0);
 				attrset(bottomline);
 				curs_set(1);
-				token = getstring(_("Enter node name: "));	/* read user's wish */
+				string token_string = getstring(_("Enter node name: "));
 				curs_set(0);
 				noecho();
 				attrset(normal);
 				for (typeof(tag_table.size()) i = 0; i < tag_table.size(); i++)
 				{
 					/* if the name was found in the tag table */
-					if (tag_table[i].nodename == token)
+					if (tag_table[i].nodename == token_string)
 					{
 						return_value = i;
 						break;
@@ -718,9 +705,6 @@
 				}
 				if (return_value != -1)	/* if the name was in tag table */
 				{
-					xfree(token);
-					token = 0;
-
 					infohistory[infohistory.size() - 1].pos = pos;
 					infohistory[infohistory.size() - 1].cursor = cursor;
 					infohistory[infohistory.size() - 1].menu = infomenu;
@@ -729,14 +713,13 @@
 					rval.keep_going = true;
 					aftersearch = 0;
 					return rval;
-				}
-				else
-					/* if the name wasn't in tag table */
-				{
+				} else {
+					/* the name wasn't in tag table */
 					/*
 					 * scan for filename: filenames may be specified in format:
 					 * (file)node
 					 */
+					char *token = strdup(token_string.c_str()); /* FIXME */
 					char *gotostartptr = strchr(token, '(');
 					if (gotostartptr)	/* if there was a `(' */
 					{
@@ -763,31 +746,28 @@
 							aftersearch = 0;
 							return rval;
 						}
-					}
-					/* handle the `file.info' format of crossinfo goto. */
-					else if (strstr(token, ".info"))
-					{
-						rval.file = token;
+					}	else if (strstr(token, ".info")) {
+						/* handle the `file.info' format of crossinfo goto. */
+						rval.file = token_string;
 						xfree(token);
 						token = 0;
 						rval.node = "";
 						aftersearch = 0;
 						rval.keep_going = true;
 						return rval;
-					}
-					else /* node not found */
-					{
+					} else {
+						/* node not found */
 						attrset(bottomline);
 						mymvhline(maxy - 1, 0, ' ', maxx);
 						move(maxy - 1, 0);
-						printw(_("Node %s not found"), token);
+						printw(_("Node %s not found"), token_string.c_str());
 						attrset(normal);
 						move(0, 0);
 					}
+					xfree(token);
+					token = 0;
 				}
 				statusline = LOCKED;
-				xfree(token);
-				token = 0;
 			}
 			/*==========================================================================*/
 			if ((key == keys.prevnode_1) ||	/* goto previous node */

Modified: pinfo/branches/cxx/src/manual.cxx
===================================================================
--- pinfo/branches/cxx/src/manual.cxx	2005-09-07 08:14:41 UTC (rev 202)
+++ pinfo/branches/cxx/src/manual.cxx	2005-09-07 08:35:24 UTC (rev 203)
@@ -685,8 +685,6 @@
 {
 	/* for user's shell commands */
 	FILE *pipe;
-	/* a temporary buffer */
-	char *token;
 	/* key, which contains the value entered by user */
 	int key = 0;
 	/* tmp values */
@@ -783,7 +781,7 @@
 				move(maxy - 1, 0);
 				echo();
 				curs_set(1);
-				token = getstring(_("Enter line: "));
+				string token_string = getstring(_("Enter line: "));
 				curs_set(0);
 				noecho();
 				move(maxy - 1, 0);
@@ -796,18 +794,18 @@
 #endif
 				attrset(normal);
 				/* convert string to long.  careful with nondigit strings.  */
-				if (token)
+				if (token_string != "")
 				{
-					int digit_val = 1;
-					for (int i = 0; token[i] != 0; i++)
+					bool digit_val = true;
+					for (int i = 0; i < token_string.length(); i++)
 					{
-						if (!isdigit(token[i]))
-							digit_val = 0;
+						if (!isdigit(token_string[i]))
+							digit_val = false;
 					}
 					/* move cursor position */
 					if (digit_val)
 					{
-						newpos = atol(token);
+						newpos = atol(token_string.c_str());
 						newpos -=(maxy - 1);
 						/* FIXME signed/unsigned */
 						if ((newpos >= 0) &&(newpos < (signed) manual.size() -(maxy - 2)))
@@ -818,8 +816,6 @@
 						else
 							manualpos = 0;
 					}
-					xfree(token);
-					token = 0;
 				}
 			}
 			/*=====================================================*/
@@ -832,7 +828,7 @@
 				move(maxy - 1, 0);
 				echo();
 				/* get users cmd */
-				token = getstring(_("Enter command: "));
+				string token_string = getstring(_("Enter command: "));
 				noecho();
 				move(maxy - 1, 0);
 #ifdef HAVE_BKGDSET
@@ -847,7 +843,7 @@
 				myendwin();
 				system("clear");
 				/* open pipe */
-				pipe = popen(token, "w");
+				pipe = popen(token_string.c_str(), "w");
 				if (pipe != NULL)
 				{
 					/* and flush the msg to stdin */
@@ -879,25 +875,24 @@
 				attrset(bottomline);
 				echo();
 				curs_set(1);
+				string token_string;
 				/*
 				 * searchagain handler. see keys.totalsearch at mainfunction.c
 				 * for comments
 				 */
 				if (!searchagain.search)
 				{
-					token = getstring(_("Enter regexp: "));
-					searchagain.lastsearch = token;
+					token_string = getstring(_("Enter regexp: "));
+					searchagain.lastsearch = token_string;
 					searchagain.type = key;
 				}
 				else
 				{
-					token = (char*)xmalloc(searchagain.lastsearch.length() + 1);
-					strcpy(token, searchagain.lastsearch.c_str());
+					token_string = searchagain.lastsearch;
 					searchagain.search = 0;
 				}		/* end of searchagain handler */
-				if (strlen(token) == 0)
+				if (token_string == "")
 				{
-					xfree(token);
 					goto skip_search;
 				}
 				curs_set(0);
@@ -912,8 +907,7 @@
 #endif
 				attrset(normal);
 				/* compile regexp expression */
-				if (pinfo_re_comp(token) != 0)
-				{
+				if (pinfo_re_comp(token_string.c_str()) != 0) {
 					/* print error message */
 					attrset(bottomline);
 					mymvhline(maxy - 1, 0, ' ', maxx);
@@ -958,7 +952,6 @@
 					}
 					xfree(tmp);
 				}
-				xfree(token);
 				rescan_selected();
 				if (!success)
 				{

Modified: pinfo/branches/cxx/src/utils.cxx
===================================================================
--- pinfo/branches/cxx/src/utils.cxx	2005-09-07 08:14:41 UTC (rev 202)
+++ pinfo/branches/cxx/src/utils.cxx	2005-09-07 08:35:24 UTC (rev 203)
@@ -240,7 +240,7 @@
 	refresh();
 }
 
-char *
+string
 getstring(const char *prompt)
 {
 	char *buf;
@@ -259,7 +259,14 @@
 	
 	curs_set(0);
 
-	return buf;
+	string my_string;
+	if (buf == NULL) {
+		my_string = "";
+	} else {
+		my_string = buf;
+		xfree(buf);
+	}
+	return my_string;
 }
 
 void

Modified: pinfo/branches/cxx/src/utils.h
===================================================================
--- pinfo/branches/cxx/src/utils.h	2005-09-07 08:14:41 UTC (rev 202)
+++ pinfo/branches/cxx/src/utils.h	2005-09-07 08:35:24 UTC (rev 203)
@@ -50,7 +50,7 @@
 /* initializes curses interface */
 void init_curses ();
 /* an interface to gnu readline */
-char *getstring (const char *prompt);
+std::string getstring (const char *prompt);
 /* for some reasons mvhline does not work quite properly... */
 void mymvhline (int y, int x, char ch, int len);
 /* this one supports color back/foreground */




More information about the Pinfo-devel mailing list