[Pinfo-devel] r79 - pinfo/branches/cxx/src
Nathanael Nerode
neroden-guest at costa.debian.org
Tue Aug 30 08:25:33 UTC 2005
Author: neroden-guest
Date: 2005-08-30 08:25:32 +0000 (Tue, 30 Aug 2005)
New Revision: 79
Modified:
pinfo/branches/cxx/src/mainfunction.cxx
pinfo/branches/cxx/src/mainfunction.h
pinfo/branches/cxx/src/pinfo.cxx
pinfo/branches/cxx/src/utils.cxx
pinfo/branches/cxx/src/utils.h
Log:
Convert WorkRVal struct -- lots of fallout.
Modified: pinfo/branches/cxx/src/mainfunction.cxx
===================================================================
--- pinfo/branches/cxx/src/mainfunction.cxx 2005-08-30 07:50:40 UTC (rev 78)
+++ pinfo/branches/cxx/src/mainfunction.cxx 2005-08-30 08:25:32 UTC (rev 79)
@@ -48,8 +48,7 @@
#define Message (*message)
#define Lines (*lines)
#define Type (*type)
- static WorkRVal rval =
- {0, 0};
+ static WorkRVal rval;
FILE *pipe;
int i, fileoffset, j;
int indirectstart = -1;
@@ -58,16 +57,10 @@
int return_value;
int statusline = FREE;
char *token, *tmp;
- if (rval.file) /* if the static variable was allocated, free it */
- {
- xfree(rval.file);
- rval.file = 0;
- }
- if (rval.node)
- {
- xfree(rval.node);
- rval.node = 0;
- }
+ /* if the static variable was allocated, free it */
+ rval.file = "";
+ rval.node = "";
+ rval.keep_going = false; /* Important */
pos = 1, cursor = 0, infomenu = -1; /* default position, and selected number */
@@ -264,10 +257,9 @@
if ((key == keys.dirpage_1) ||
(key == keys.dirpage_2))
{
- rval.file = (char*)malloc(10);
- strcpy(rval.file, "dir");
- rval.node = (char*)malloc(2);
- strcpy(rval.node, "");
+ rval.file = "dir";
+ rval.node = "";
+ rval.keep_going = true;
aftersearch = 0;
return rval;
}
@@ -534,10 +526,9 @@
infohistory.pos[infohistory.length] = pos;
infohistory.cursor[infohistory.length] = cursor;
infohistory.menu[infohistory.length] = infomenu;
- rval.node = (char*)xmalloc(strlen(tag_table[return_value].nodename) + 1);
- strcpy(rval.node, tag_table[return_value].nodename);
- rval.file = (char*)xmalloc(1);
- rval.file[0] = 0;
+ rval.node = tag_table[return_value].nodename;
+ rval.file = "";
+ rval.keep_going = true;
return rval;
}
} /* end: if key_totalsearch */
@@ -665,10 +656,9 @@
infohistory.pos[infohistory.length] = pos;
infohistory.cursor[infohistory.length] = cursor;
infohistory.menu[infohistory.length] = infomenu;
- rval.node = (char*)xmalloc(strlen(tag_table[return_value].nodename) + 1);
- strcpy(rval.node, tag_table[return_value].nodename);
- rval.file = (char*)xmalloc(1);
- rval.file[0] = 0;
+ rval.node = tag_table[return_value].nodename;
+ rval.file = "";
+ rval.keep_going = true;
aftersearch = 0;
return rval;
}
@@ -686,9 +676,11 @@
/* if they're in the right order... */
if (gotoendptr > gotostartptr)
{
- rval.file = (char*)xmalloc(gotoendptr - gotostartptr + 1);
- strncpy(rval.file, gotostartptr + 1, gotoendptr - gotostartptr - 1);
- rval.file[gotoendptr - gotostartptr - 1] = 0;
+ char* tmp_ick = (char*)xmalloc(gotoendptr - gotostartptr + 1);
+ strncpy(tmp_ick, gotostartptr + 1, gotoendptr - gotostartptr - 1);
+ tmp_ick[gotoendptr - gotostartptr - 1] = 0;
+ rval.file = tmp_ick;
+ xfree(tmp_ick);
gotoendptr++;
while (gotoendptr) /* skip whitespaces until nodename */
{
@@ -696,8 +688,8 @@
break;
gotoendptr++;
} /* skip spaces */
- rval.node = (char*)xmalloc(strlen(gotoendptr) + 1);
- strcpy(rval.node, gotoendptr);
+ rval.node = gotoendptr; /* Needs cleanup. Eeeew. */
+ rval.keep_going = true;
xfree(token);
token = 0;
aftersearch = 0;
@@ -707,13 +699,12 @@
/* handle the `file.info' format of crossinfo goto. */
else if (strstr(token, ".info"))
{
- rval.file = (char*)xmalloc(strlen(token) + 1);
- strcpy(rval.file, token);
+ rval.file = token;
xfree(token);
token = 0;
- rval.node = (char*)xmalloc(5);
- strcpy(rval.node, "");
+ rval.node = "";
aftersearch = 0;
+ rval.keep_going = true;
return rval;
}
else /* node not found */
@@ -744,10 +735,9 @@
infohistory.pos[infohistory.length] = pos;
infohistory.cursor[infohistory.length] = cursor;
infohistory.menu[infohistory.length] = infomenu;
- rval.node = (char*)xmalloc(strlen(tag_table[return_value].nodename) + 1);
- strcpy(rval.node, tag_table[return_value].nodename);
- rval.file = (char*)xmalloc(1);
- rval.file[0] = 0;
+ rval.node = tag_table[return_value].nodename;
+ rval.file = "";
+ rval.keep_going = true;
aftersearch = 0;
return rval;
}
@@ -766,10 +756,9 @@
infohistory.pos[infohistory.length] = pos;
infohistory.cursor[infohistory.length] = cursor;
infohistory.menu[infohistory.length] = infomenu;
- rval.node = (char*)xmalloc(strlen(tag_table[return_value].nodename) + 1);
- strcpy(rval.node, tag_table[return_value].nodename);
- rval.file = (char*)xmalloc(1);
- rval.file[0] = 0;
+ rval.node = tag_table[return_value].nodename;
+ rval.file = "";
+ rval.keep_going = true;
aftersearch = 0;
return rval;
}
@@ -795,10 +784,9 @@
infohistory.cursor[infohistory.length] = cursor;
infohistory.menu[infohistory.length] = infomenu;
}
- rval.node = (char*)xmalloc(strlen(tag_table[return_value].nodename) + 1);
- strcpy(rval.node, tag_table[return_value].nodename);
- rval.file = (char*)xmalloc(1);
- rval.file[0] = 0;
+ rval.node = tag_table[return_value].nodename;
+ rval.file = "";
+ rval.keep_going = true;
aftersearch = 0;
return rval;
}
@@ -959,10 +947,9 @@
infohistory.pos[infohistory.length] = pos;
infohistory.cursor[infohistory.length] = cursor;
infohistory.menu[infohistory.length] = infomenu;
- rval.node = (char*)xmalloc(strlen(FirstNodeName) + 1);
- strcpy(rval.node, FirstNodeName);
- rval.file = (char*)xmalloc(1);
- rval.file[0] = 0;
+ rval.node = FirstNodeName;
+ rval.file = "";
+ rval.keep_going = true;
aftersearch = 0;
return rval;
}
@@ -975,10 +962,9 @@
dellastinfohistory(); /* remove history entry for this node */
/* now we deal with the previous node history entry */
- rval.node = (char*)xmalloc(strlen(infohistory.node[infohistory.length]) + 1);
- strcpy(rval.node, infohistory.node[infohistory.length]);
- rval.file = (char*)xmalloc(strlen(infohistory.file[infohistory.length]) + 1);
- strcpy(rval.file, infohistory.file[infohistory.length]);
+ rval.node = infohistory.node[infohistory.length];
+ rval.file = infohistory.file[infohistory.length];
+ rval.keep_going = true;
npos = infohistory.pos[infohistory.length];
ncursor = infohistory.cursor[infohistory.length];
@@ -1005,10 +991,9 @@
toggled_by_menu = 0;
if (hyperobjects[cursor].type < 4) /* normal info link */
{
- 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());
+ rval.node = hyperobjects[cursor].node;
+ rval.file = hyperobjects[cursor].file;
+ rval.keep_going = true;
aftersearch = 0;
return rval;
}
Modified: pinfo/branches/cxx/src/mainfunction.h
===================================================================
--- pinfo/branches/cxx/src/mainfunction.h 2005-08-30 07:50:40 UTC (rev 78)
+++ pinfo/branches/cxx/src/mainfunction.h 2005-08-30 08:25:32 UTC (rev 79)
@@ -21,16 +21,18 @@
#ifndef __MAINFUNCTION_H
#define __MAINFUNCTION_H
+#include <string>
/*
* return value type for work(). it is the name of node, where to go, after
* viewing of current node ends. (viewing always takes place inside of the
* work() function
*/
-typedef struct
+typedef struct WorkRVal
{
- char *node; /* name of node */
- char *file; /* name of file, where the node is */
+ bool keep_going; /* Keep going? */
+ std::string node; /* name of node */
+ std::string file; /* name of file, where the node is */
}
WorkRVal;
Modified: pinfo/branches/cxx/src/pinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/pinfo.cxx 2005-08-30 07:50:40 UTC (rev 78)
+++ pinfo/branches/cxx/src/pinfo.cxx 2005-08-30 08:25:32 UTC (rev 79)
@@ -192,8 +192,7 @@
int
main(int argc, char *argv[]) {
int filenotfound = 0;
- WorkRVal work_return_value =
- {0, 0};
+ WorkRVal work_return_value;
int userdefinedrc = 0;
FILE *id = NULL;
string filename_string;
@@ -401,35 +400,31 @@
else
filenotfound = 0;
work_return_value = work(&message, &type, &lines, id, tag_table_pos);
- if (work_return_value.node)
+ if (work_return_value.keep_going)
{
/* no cross-file link selected */
if (work_return_value.file[0] == 0)
{
- int tmppos = gettagtablepos(work_return_value.node);
+ int tmppos = gettagtablepos(work_return_value.node.c_str());
if (tmppos != -1)
tag_table_pos = tmppos;
}
else /* file was specified */
{
- string another_tmpstr = work_return_value.file;
- strip_info_suffix_from_file(another_tmpstr);
- work_return_value.file = strdup(another_tmpstr.c_str()); /* FIXME memleak */
+ strip_info_suffix_from_file(work_return_value.file);
/* file name was the same with the file currently viewed */
if (curfile == work_return_value.file)
{
- int tmppos = gettagtablepos(work_return_value.node);
+ int tmppos = gettagtablepos(work_return_value.node.c_str());
if (tmppos != -1)
tag_table_pos = tmppos;
}
else /* open new info file */
{
fclose(id);
- string tmpstr;
- tmpstr = work_return_value.file;
/* Reset global filenameprefix */
filenameprefix.clear();
- id = openinfo(tmpstr, 0);
+ id = openinfo(work_return_value.file, 0);
char *tmp = NULL;
/* if the file doesn't exist */
@@ -461,10 +456,6 @@
}
else /* if we succeeded in opening new file */
{
- if (curfile != "")
- {
- curfile = "";
- }
curfile = work_return_value.file;
freeindirect();
/* find the indirect entry */
@@ -518,9 +509,9 @@
else
return 1;
}
- if (work_return_value.node[0] != 0)
+ if (work_return_value.node != "")
{
- int tmptagtablepos = gettagtablepos(work_return_value.node);
+ int tmptagtablepos = gettagtablepos(work_return_value.node.c_str() );
if (tmptagtablepos != -1)
tag_table_pos = tmptagtablepos;
else
@@ -533,7 +524,7 @@
} /* end: file name was specified */
} /* end: node was specified in work return value */
}
- while (work_return_value.node);
+ while (work_return_value.keep_going);
fclose(id);
closeprogram();
/* free's at the end are optional, but look nice :) */
Modified: pinfo/branches/cxx/src/utils.cxx
===================================================================
--- pinfo/branches/cxx/src/utils.cxx 2005-08-30 07:50:40 UTC (rev 78)
+++ pinfo/branches/cxx/src/utils.cxx 2005-08-30 08:25:32 UTC (rev 79)
@@ -337,16 +337,20 @@
}
int
-gettagtablepos(char *node)
+gettagtablepos(const char * node)
{
+ int result;
+ char* my_node = strdup(node);
/* strip spaces from the beginning */
while (1)
{
- if ((*node != ' ') &&(*node != '\t'))
+ if ((*my_node != ' ') &&(*my_node != '\t'))
break;
- node++;
+ my_node++;
}
- return gettagtablepos_search_internal(node, 1, TagTableEntries);
+ result = gettagtablepos_search_internal(my_node, 1, TagTableEntries);
+ xfree(my_node);
+ return result;
}
int
Modified: pinfo/branches/cxx/src/utils.h
===================================================================
--- pinfo/branches/cxx/src/utils.h 2005-08-30 07:50:40 UTC (rev 78)
+++ pinfo/branches/cxx/src/utils.h 2005-08-30 08:25:32 UTC (rev 79)
@@ -64,7 +64,7 @@
/* takes care of the cursor, which is turned off */
void myendwin ();
/* get offset of "node" in tag_table variable */
-int gettagtablepos (char *node);
+int gettagtablepos (const char * node);
/* handle localized `(y/n)' dialog box. */
int yesno (char *prompt, int def);
More information about the Pinfo-devel
mailing list