[Pinfo-devel] r195 - pinfo/branches/cxx/src
Nathanael Nerode
neroden-guest at costa.debian.org
Wed Sep 7 05:19:44 UTC 2005
Author: neroden-guest
Date: 2005-09-07 05:19:42 +0000 (Wed, 07 Sep 2005)
New Revision: 195
Modified:
pinfo/branches/cxx/src/filehandling_functions.cxx
pinfo/branches/cxx/src/filehandling_functions.h
pinfo/branches/cxx/src/mainfunction.cxx
pinfo/branches/cxx/src/mainfunction.h
pinfo/branches/cxx/src/pinfo.cxx
Log:
Convert 'type' to std::string, plus add an exception throw.
Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx 2005-09-07 04:58:04 UTC (rev 194)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx 2005-09-07 05:19:42 UTC (rev 195)
@@ -191,10 +191,9 @@
}
FILE *
-dirpage_lookup(char **type, vector<string>& message,
+dirpage_lookup(string& type, vector<string>& message,
string wanted_name, string& first_node)
{
-#define Type (*type)
FILE *id = 0;
bool goodHit = false;
@@ -281,32 +280,14 @@
/* return file we found */
return id;
-#undef Type
}
void
-freeitem(char **type)
+read_item(FILE * id, string& type, vector<string>& buf)
{
-#define Type (*type)
- long i;
-
- if (Type != 0)
- {
- xfree(Type);
- Type = 0;
- }
-#undef Type
-}
-
-void
-read_item(FILE * id, char **type, vector<string>& buf)
-{
-
-#define Type (*type)
-
int i;
- freeitem(type); /* free previously allocated memory */
+ type = ""; /* Wipe out old header */
buf.clear(); /* Wipe out old buffer */
/* seek precisely on the INFO_TAG (the seeknode function may be imprecise
@@ -315,13 +296,14 @@
/* then skip the trailing `\n' */
while (fgetc(id) != '\n');
- /* allocate and read the header line */
- Type = (char*)xmalloc(1024);
- fgets(Type, 1024, id);
- Type = (char*)xrealloc(Type, strlen(Type) + 1);
+ char* tmpbuf = (char*) xmalloc(1024); /* Note, cleared like calloc */
+ memset(tmpbuf, '\0', 1024);
+ /* Read the header line */
+ fgets(tmpbuf, 1024, id);
+ type = tmpbuf;
+
/* now iterate over the lines until we hit a new INFO_TAG mark */
- char* tmpbuf = (char*) xmalloc(1024); /* Note, cleared like calloc */
do {
/* don't read after eof in info file */
if (feof(id))
@@ -370,7 +352,6 @@
/* Back up past that last INFO_TAG line */
fseek(id, -2, SEEK_CUR);
-#undef Type
}
void
Modified: pinfo/branches/cxx/src/filehandling_functions.h
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.h 2005-09-07 04:58:04 UTC (rev 194)
+++ pinfo/branches/cxx/src/filehandling_functions.h 2005-09-07 05:19:42 UTC (rev 195)
@@ -41,15 +41,9 @@
void seeknode (int tag_table_pos, FILE ** Id);
/*
- * free allocated memory, hold by buf (node** content, stored line by line),
- * and type (a char* pointer, which stores the node header).
- */
-void freeitem (char **type);
-
-/*
* Reads a node from 'id' to 'buf', and the header of node to 'type'.
*/
-void read_item (FILE * id, char **type, std::vector<std::string>& buf);
+void read_item (FILE * id, std::string& type, std::vector<std::string>& buf);
/* searches for indirect entry of info file */
int seek_indirect (FILE * id);
/* as above, but with tag table entry */
@@ -82,7 +76,7 @@
* lines: pointer to long, which holds the number of lines in dir entry
*/
FILE *
-dirpage_lookup (char **type, std::vector<std::string>& message,
+dirpage_lookup (std::string& type, std::vector<std::string>& message,
const std::string filename, std::string& first_node);
/* removes trailing .gz, .bz2, etc. */
Modified: pinfo/branches/cxx/src/mainfunction.cxx
===================================================================
--- pinfo/branches/cxx/src/mainfunction.cxx 2005-09-07 04:58:04 UTC (rev 194)
+++ pinfo/branches/cxx/src/mainfunction.cxx 2005-09-07 05:19:42 UTC (rev 195)
@@ -25,6 +25,8 @@
using std::string;
#include <vector>
using std::vector;
+#include <exception>
+#include <stdexcept>
#include <ctype.h>
@@ -72,6 +74,7 @@
if (end_idx != string::npos) {
return type.substr(start_idx, end_idx - start_idx);
}
+ throw std::invalid_argument("Unending line in get_foo_node");
}
/* read the `Next:' header entry */
@@ -105,9 +108,8 @@
/* Main work functions */
WorkRVal
-work(const vector<string> my_message, char **type, FILE * id, int tag_table_pos)
+work(const vector<string> my_message, string type_str, FILE * id, int tag_table_pos)
{
-#define Type (*type)
static WorkRVal rval;
FILE *pipe;
int fileoffset;
@@ -169,7 +171,6 @@
npos = -1; /* turn off the `next-time' pos/cursor modifiers */
ncursor = -1;
nmenu = -1;
- string type_str = Type;
addtopline(type_str,infocolumn);
while (1)
{
@@ -193,7 +194,6 @@
{
handlewinch();
winchanged = 0;
- string type_str = Type;
addtopline(type_str,infocolumn);
key = pinfo_getch();
}
@@ -225,12 +225,12 @@
else
/* we shouldn't select a menu item if this node is called via `up:' from bottom, or if there is no menu */
{
- string type_str = getnextnode(Type);
- if (type_str != ERRNODE) {
+ string next_node_name = getnextnode(type_str);
+ if (next_node_name != ERRNODE) {
key = keys.nextnode_1;
} else {
- type_str = getnodename(Type);
- if (FirstNodeName != type_str) /* if it's not end of all menus */
+ string node_name = getnodename(type_str);
+ if (FirstNodeName != node_name) /* if it's not end of all menus */
{
if (wastoggled) /* if we're in the temporary called up node */
toggled_by_menu = KILL_HISTORY;
@@ -379,7 +379,7 @@
fileoffset = 0;
for (int i = 0; i < pos + 1; i++) /* count the length of curnode */
fileoffset += my_message[i].length();
- fileoffset += strlen(Type); /* add also header length */
+ fileoffset += type_str.length(); /* add also header length */
fileoffset += getnodeoffset(tag_table_pos, indirectstart); /* also load the variable indirectstart */
@@ -793,7 +793,7 @@
if ((key == keys.prevnode_1) || /* goto previous node */
(key == keys.prevnode_2))
{
- string token_str = getprevnode(Type);
+ string token_str = getprevnode(type_str);
return_value = gettagtablepos(token_str);
if (return_value != -1)
{
@@ -812,7 +812,7 @@
(key == keys.nextnode_2))
{
string token_str;
- token_str = getnextnode(Type);
+ token_str = getnextnode(type_str);
return_value = gettagtablepos(token_str);
if (return_value != -1)
{
@@ -830,7 +830,7 @@
if ((key == keys.upnode_1) || /* goto up node */
(key == keys.upnode_2))
{
- string token_str = getupnode(Type);
+ string token_str = getupnode(type_str);
if (token_str.compare(0, 5, "(dir)") == 0)
{
ungetch(keys.dirpage_1);
@@ -1100,15 +1100,13 @@
{
if (infocolumn>0)
infocolumn--;
- string typestr = Type;
- addtopline(typestr,infocolumn);
+ addtopline(type_str,infocolumn);
}
/*==========================================================================*/
if ((key == keys.right_1) ||(key == keys.right_2))
{
infocolumn++;
- string typestr = Type;
- addtopline(typestr,infocolumn);
+ addtopline(type_str,infocolumn);
}
/*==========================================================================*/
/**************************** end of keyboard handling **********************/
Modified: pinfo/branches/cxx/src/mainfunction.h
===================================================================
--- pinfo/branches/cxx/src/mainfunction.h 2005-09-07 04:58:04 UTC (rev 194)
+++ pinfo/branches/cxx/src/mainfunction.h 2005-09-07 05:19:42 UTC (rev 195)
@@ -49,6 +49,6 @@
* id: file descriptor of current info file
* tag_table_pos: position in tag table of the current node (needed for history)
*/
-WorkRVal work (const std::vector<std::string> message, char **type,
+WorkRVal work (const std::vector<std::string> message, std::string type,
FILE * id, int tag_table_pos);
#endif
Modified: pinfo/branches/cxx/src/pinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/pinfo.cxx 2005-09-07 04:58:04 UTC (rev 194)
+++ pinfo/branches/cxx/src/pinfo.cxx 2005-09-07 05:19:42 UTC (rev 195)
@@ -198,7 +198,7 @@
/* this will hold node's text */
vector<string> message;
/* this will hold the node's header */
- char *type = 0;
+ string type;
int tag_table_pos = -1;
/* Drop root privileges immediately (otherwise we can't read
@@ -316,7 +316,7 @@
/* try to lookup the name in dir file */
if (id == NULL)
{
- id = dirpage_lookup(&type, message, filename_string,
+ id = dirpage_lookup(type, message, filename_string,
pinfo_start_node);
}
@@ -330,7 +330,7 @@
/* search for indirect entries, if any */
if (seek_indirect(id))
{
- read_item(id, &type, message);
+ read_item(id, type, message);
load_indirect(message);
}
@@ -338,7 +338,7 @@
if (seek_tag_table(id,1) != 2) {
if (ForceManualTagTable == 0)
{
- read_item(id, &type, message);
+ read_item(id, type, message);
load_tag_table(message);
}
else
@@ -391,7 +391,7 @@
/* set seek offset for given node */
seeknode(tag_table_pos, &id);
/* read the node */
- read_item(id, &type, message);
+ read_item(id, type, message);
/* handle goto/link where no file was found -- see bellow */
if (!filenotfound)
@@ -399,7 +399,7 @@
else
filenotfound = 0;
- work_return_value = work(message, &type, id, tag_table_pos);
+ work_return_value = work(message, type, id, tag_table_pos);
if (work_return_value.keep_going)
{
/* no cross-file link selected */
@@ -462,7 +462,7 @@
if (seek_indirect(id))
{
/* read it */
- read_item(id, &type, message);
+ read_item(id, type, message);
/* initialize indirect entries */
load_indirect(message);
@@ -478,7 +478,7 @@
*/
if (ForceManualTagTable == 0)
{
- read_item(id, &type, message);
+ read_item(id, type, message);
load_tag_table(message);
}
else /* create tag table manually */
@@ -528,7 +528,6 @@
fclose(id);
closeprogram();
/* free's at the end are optional, but look nice :) */
- freeitem(&type);
tag_table.clear();
indirect.clear();
return 0;
More information about the Pinfo-devel
mailing list