[Pinfo-devel] r105 - pinfo/branches/cxx/src
Nathanael Nerode
neroden-guest at costa.debian.org
Tue Aug 30 15:43:51 UTC 2005
Author: neroden-guest
Date: 2005-08-30 15:43:50 +0000 (Tue, 30 Aug 2005)
New Revision: 105
Modified:
pinfo/branches/cxx/src/datatypes.cxx
pinfo/branches/cxx/src/datatypes.h
pinfo/branches/cxx/src/filehandling_functions.cxx
pinfo/branches/cxx/src/mainfunction.cxx
pinfo/branches/cxx/src/menu_and_note_utils.cxx
pinfo/branches/cxx/src/menu_and_note_utils.h
pinfo/branches/cxx/src/pinfo.cxx
Log:
Vectorize the indirect table.
Modified: pinfo/branches/cxx/src/datatypes.cxx
===================================================================
--- pinfo/branches/cxx/src/datatypes.cxx 2005-08-30 15:26:52 UTC (rev 104)
+++ pinfo/branches/cxx/src/datatypes.cxx 2005-08-30 15:43:50 UTC (rev 105)
@@ -47,11 +47,10 @@
vector<HyperObject> hyperobjects;
-Indirect *indirect = 0;
+vector<Indirect> indirect;
TagTable *tag_table = 0;
long FirstNodeOffset = 0;
string FirstNodeName;
-int IndirectEntries = 0;
int TagTableEntries = 0;
int maxx, maxy;
int CutManHeaders = 0;
Modified: pinfo/branches/cxx/src/datatypes.h
===================================================================
--- pinfo/branches/cxx/src/datatypes.h 2005-08-30 15:26:52 UTC (rev 104)
+++ pinfo/branches/cxx/src/datatypes.h 2005-08-30 15:43:50 UTC (rev 105)
@@ -45,7 +45,7 @@
}
SearchAgain;
-typedef struct
+typedef struct Indirect
{
char filename[256]; /* name of file, where's the given offset */
long offset; /* offset of the node */
@@ -126,9 +126,7 @@
/* an array of references for info */
extern std::vector<HyperObject> hyperobjects;
/* an array of indirect entries */
-extern Indirect *indirect;
-/* number of indirect entries */
-extern int IndirectEntries;
+extern std::vector<Indirect> indirect;
/* an array of tag table entries [1 to n] */
extern TagTable *tag_table;
/* offset of the first node in info file */
Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx 2005-08-30 15:26:52 UTC (rev 104)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx 2005-08-30 15:43:50 UTC (rev 105)
@@ -312,27 +312,24 @@
void
load_indirect(char **message, long lines)
{
- int cut = 0; /* number of invalid entries */
- indirect = (Indirect*)xmalloc((lines) * sizeof(Indirect));
- for (long i = 1; i < lines; i++) {
+ for (long i = 1; i < lines; i++) { /* Avoid the last line. (Why?) */
string wsk_string = message[i];
unsigned int n = 0;
/* Find the first colon, but not in position 0 */
n = wsk_string.find(':', 1);
if (n == string::npos) {
- /* No colon. Invalid entry. */
- cut++; /* if the entry was invalid, make indirect count shorter */
+ ; /* No colon. Invalid entry. */
} else {
string filename;
filename = wsk_string.substr(0, n);
- strncpy(indirect[i - cut - 1].filename, filename.c_str(), 200);
+ Indirect my_entry;
+ strncpy(my_entry.filename, filename.c_str(), 200);
- string remainder;
- remainder = wsk_string.substr(n + 2, string::npos);
- indirect[i - cut - 1].offset = atoi(remainder.c_str());
+ string remainder = wsk_string.substr(n + 2, string::npos);
+ my_entry.offset = atoi(remainder.c_str());
+ indirect.push_back(my_entry);
}
}
- IndirectEntries = lines - 1 - cut - 1;
}
void
@@ -962,7 +959,7 @@
{
FILE *id = 0;
int i, j, initial;
- for (i = 0; i <= IndirectEntries; i++)
+ for (i = 0; i < indirect.size(); i++)
{
string tmpstr = indirect[i].filename;
id = openinfo(tmpstr, 1);
@@ -1048,7 +1045,7 @@
} /* end: global while loop, looping until eof */
xfree(buf);
buf = 0;
- if (!indirect) /* originally (!indirect) -- check this NCN FIXME */
+ if (indirect.empty()) /* originally (!indirect) -- check this NCN FIXME */
{
FirstNodeOffset = tag_table[1].offset;
FirstNodeName = tag_table[1].nodename;
@@ -1066,9 +1063,9 @@
* file-offset = tagtable_offset - indirect_offset +
* + tagtable[1]_offset
*/
- if (indirect) /* Originally if (indirect) -- NCN CHECK FIXME */
+ if (!(indirect.empty())) /* Originally if (indirect) -- NCN CHECK FIXME */
{
- for (i = IndirectEntries; i >= 0; i--)
+ for (i = indirect.size() - 1; i >= 0; i--)
{
if (indirect[i].offset <= tag_table[tag_table_pos].offset)
{
Modified: pinfo/branches/cxx/src/mainfunction.cxx
===================================================================
--- pinfo/branches/cxx/src/mainfunction.cxx 2005-08-30 15:26:52 UTC (rev 104)
+++ pinfo/branches/cxx/src/mainfunction.cxx 2005-08-30 15:43:50 UTC (rev 105)
@@ -378,13 +378,13 @@
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
return_value = -1;
/* the info is of indirect type; we'll search through several files */
- if (indirect)
+ if (!indirect.empty())
{
FILE *fd;
long tokenpos;
long starttokenpos;
long filelen;
- for (j = indirectstart; j <= IndirectEntries; j++)
+ for (j = indirectstart; j < indirect.size(); j++)
{
string tmpstr = indirect[j].filename;
fd = openinfo(tmpstr, 1); /* get file length. */
@@ -1258,9 +1258,9 @@
{
#define indirectstart (*Indstart)
int i, fileoffset = 0;
- if (indirect)
+ if (!indirect.empty())
{
- for (i = IndirectEntries; i >= 0; i--)
+ for (i = indirect.size() - 1; i >= 0; i--)
{
if (indirect[i].offset <= tag_table[tag_table_pos].offset)
{
Modified: pinfo/branches/cxx/src/menu_and_note_utils.cxx
===================================================================
--- pinfo/branches/cxx/src/menu_and_note_utils.cxx 2005-08-30 15:26:52 UTC (rev 104)
+++ pinfo/branches/cxx/src/menu_and_note_utils.cxx 2005-08-30 15:43:50 UTC (rev 105)
@@ -21,23 +21,10 @@
***************************************************************************/
#include "common_includes.h"
-#include <string>
-using std::string;
RCSID("$Id$")
void
-freeindirect()
-{
- if (indirect)
- {
- xfree(indirect);
- indirect = 0;
- }
- IndirectEntries = 0;
-}
-
-void
freetagtable()
{
if (tag_table)
Modified: pinfo/branches/cxx/src/menu_and_note_utils.h
===================================================================
--- pinfo/branches/cxx/src/menu_and_note_utils.h 2005-08-30 15:26:52 UTC (rev 104)
+++ pinfo/branches/cxx/src/menu_and_note_utils.h 2005-08-30 15:43:50 UTC (rev 105)
@@ -23,6 +23,5 @@
#ifndef __MENU_AND_NOTE_UTILS_H
#define __MENU_AND_NOTE_UTILS_H
-void freeindirect ();
void freetagtable ();
#endif
Modified: pinfo/branches/cxx/src/pinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/pinfo.cxx 2005-08-30 15:26:52 UTC (rev 104)
+++ pinfo/branches/cxx/src/pinfo.cxx 2005-08-30 15:43:50 UTC (rev 105)
@@ -334,7 +334,7 @@
}
else
{
- if (indirect)
+ if (!(indirect.empty()))
create_indirect_tag_table();
else
{
@@ -447,7 +447,7 @@
else /* if we succeeded in opening new file */
{
curfile = work_return_value.file;
- freeindirect();
+ indirect.clear();
/* find the indirect entry */
if (seek_indirect(id))
{
@@ -472,7 +472,7 @@
}
else /* create tag table manually */
{
- if (indirect)
+ if (!(indirect.empty()))
create_indirect_tag_table();
else
{
@@ -520,7 +520,7 @@
/* free's at the end are optional, but look nice :) */
freeitem(&type, &message, &lines);
freetagtable();
- freeindirect();
+ indirect.clear();
return 0;
}
More information about the Pinfo-devel
mailing list