[Pinfo-devel] r121 - pinfo/branches/cxx/src
Nathanael Nerode
neroden-guest at costa.debian.org
Fri Sep 2 02:58:49 UTC 2005
Author: neroden-guest
Date: 2005-09-02 02:58:48 +0000 (Fri, 02 Sep 2005)
New Revision: 121
Removed:
pinfo/branches/cxx/src/menu_and_note_utils.cxx
pinfo/branches/cxx/src/menu_and_note_utils.h
Modified:
pinfo/branches/cxx/src/Makefile.am
pinfo/branches/cxx/src/common_includes.h
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/pinfo.cxx
pinfo/branches/cxx/src/utils.cxx
Log:
Convert tag_table to std::vector. As a side effect, delete
menu_and_note_utils.*.
Modified: pinfo/branches/cxx/src/Makefile.am
===================================================================
--- pinfo/branches/cxx/src/Makefile.am 2005-09-02 02:25:26 UTC (rev 120)
+++ pinfo/branches/cxx/src/Makefile.am 2005-09-02 02:58:48 UTC (rev 121)
@@ -11,7 +11,6 @@
filehandling_functions.cxx \
mainfunction.cxx \
manual.cxx \
- menu_and_note_utils.cxx \
parse_config.cxx \
regexp_search.cxx \
signal_handler.cxx \
@@ -24,7 +23,6 @@
keyboard.h \
mainfunction.h \
manual.h \
- menu_and_note_utils.h \
parse_config.h \
regexp_search.h \
signal_handler.h \
Modified: pinfo/branches/cxx/src/common_includes.h
===================================================================
--- pinfo/branches/cxx/src/common_includes.h 2005-09-02 02:25:26 UTC (rev 120)
+++ pinfo/branches/cxx/src/common_includes.h 2005-09-02 02:58:48 UTC (rev 121)
@@ -49,7 +49,6 @@
#include "datatypes.h"
#include "filehandling_functions.h"
#include "video.h"
-#include "menu_and_note_utils.h"
#include "mainfunction.h"
#include "utils.h"
#include "colors.h"
Modified: pinfo/branches/cxx/src/datatypes.cxx
===================================================================
--- pinfo/branches/cxx/src/datatypes.cxx 2005-09-02 02:25:26 UTC (rev 120)
+++ pinfo/branches/cxx/src/datatypes.cxx 2005-09-02 02:58:48 UTC (rev 121)
@@ -48,10 +48,9 @@
vector<HyperObject> hyperobjects;
vector<Indirect> indirect;
-TagTable *tag_table = 0;
+vector<TagTable> tag_table;
long FirstNodeOffset = 0;
string FirstNodeName;
-int TagTableEntries = 0;
int maxx, maxy;
int CutManHeaders = 0;
int CutEmptyManLines = 0;
Modified: pinfo/branches/cxx/src/datatypes.h
===================================================================
--- pinfo/branches/cxx/src/datatypes.h 2005-09-02 02:25:26 UTC (rev 120)
+++ pinfo/branches/cxx/src/datatypes.h 2005-09-02 02:58:48 UTC (rev 121)
@@ -128,13 +128,11 @@
/* an array of indirect entries */
extern std::vector<Indirect> indirect;
/* an array of tag table entries [0 to n - 1] */
-extern TagTable *tag_table;
+extern std::vector<TagTable> tag_table;
/* offset of the first node in info file */
extern long FirstNodeOffset;
/* name of the first node in info file */
extern std::string FirstNodeName;
-/* number of tag table entries */
-extern int TagTableEntries;
/* maximum dimensions of screen */
extern int maxx, maxy;
extern InfoHistory infohistory;
Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx 2005-09-02 02:25:26 UTC (rev 120)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx 2005-09-02 02:58:48 UTC (rev 121)
@@ -95,17 +95,20 @@
char **infopaths = 0;
int infopathcount = 0;
-int
-qsort_cmp(const void *base, const void *compared)
-{
- char *cbase =((TagTable *) base)->nodename;
- char *ccompared =((TagTable *) compared)->nodename;
- return compare_tag_table_string(cbase, ccompared);
+bool
+compare_tags(TagTable a, TagTable b) {
+ /* Should a be sorted before b? */
+ int result = compare_tag_table_string(a.nodename, b.nodename);
+ if (result < 0)
+ return true;
+ else
+ return false;
}
void
sort_tag_table(void) {
- qsort(&tag_table[0], TagTableEntries, sizeof(TagTable), qsort_cmp);
+ if (!tag_table.empty())
+ std::sort(tag_table.begin(), tag_table.end(), compare_tags);
}
/*
@@ -367,7 +370,6 @@
long i;
char *wsk, *wsk1;
int is_indirect = 0;
- int cut = 0; /* holds the number of corrupt lines */
/*
* if in the first line there is a(indirect) string, skip that line
@@ -375,7 +377,8 @@
*/
if (strcasecmp("(Indirect)", message[1]) == 0)
is_indirect = 1;
- tag_table = (TagTable*)xmalloc((lines) * sizeof(TagTable));
+ tag_table.clear();
+
for (i = 1; i < lines - is_indirect; i++)
{
char *check;
@@ -399,23 +402,22 @@
}
if (wsk1 < check)
{
+ TagTable my_tag;
(*wsk1) = 0;
- strcpy(tag_table[i - cut - 1].nodename, wsk);
- (*(tag_table[i - cut - 1].nodename + (wsk1 - wsk) + 1)) = 0;
+ strcpy(my_tag.nodename, wsk);
+ (*(my_tag.nodename + (wsk1 - wsk) + 1)) = 0;
/* Just terminating the bugger */
(*wsk1) = INDIRECT_TAG;
wsk1++;
- tag_table[i - cut - 1].offset = atoi(wsk1);
+ my_tag.offset = atoi(wsk1);
+ tag_table.push_back(my_tag);
}
- else
- cut++; /* increment the number of corrupt entries */
}
- TagTableEntries = lines - 1 - is_indirect - cut;
/* FIXME: info should ALWAYS start at the 'Top' node, not at the first
mentioned node(vide ocaml.info) */
- for (i = 0; i < TagTableEntries; i++)
+ for (i = 0; i < tag_table.size(); i++)
{
if (strcasecmp(tag_table[i].nodename, "Top") == 0)
{
@@ -994,7 +996,7 @@
for (vector<Indirect>::size_type i = 0; i < indirect.size(); i++)
{
id = openinfo(indirect[i].filename, 1);
- initial = TagTableEntries; /* Before create_tag_table operates */
+ initial = tag_table.size(); /* Before create_tag_table operates */
if (id)
{
create_tag_table(id);
@@ -1002,7 +1004,7 @@
FirstNodeName = tag_table[0].nodename;
}
fclose(id);
- for (int j = initial; j < TagTableEntries; j++)
+ for (int j = initial; j < tag_table.size(); j++)
{
tag_table[j].offset +=(indirect[i].offset - FirstNodeOffset);
}
@@ -1018,30 +1020,23 @@
char *buf = (char*)xmalloc(1024);
long oldpos;
fseek(id, 0, SEEK_SET);
- if (!tag_table)
- tag_table = (TagTable*)xmalloc((TagTableEntries + 1) * sizeof(TagTable));
- else
- tag_table = (TagTable*)xrealloc(tag_table,(TagTableEntries + 1) * sizeof(TagTable));
while (!feof(id))
{
if (fgetc(id) == INFO_TAG) /* We've found a node entry! */
{
while (fgetc(id) != '\n'); /* skip '\n' */
- TagTableEntries++; /* increase the nuber of tag table entries */
oldpos = ftell(id); /* remember this file position! */
/*
* it is a an eof-fake-node (in some info files it happens, that
* the eof'ish end of node is additionaly signalised by an INFO_TAG
* We give to such node an unlike to meet nodename.
*/
- if (fgets(buf, 1024, id) == NULL)
- {
- tag_table = (TagTable*)xrealloc(tag_table, sizeof(TagTable) *(TagTableEntries));
- strcpy(tag_table[TagTableEntries - 1].nodename, "12#!@#4");
- tag_table[TagTableEntries - 1].offset = 0;
- }
- else
- {
+ if (fgets(buf, 1024, id) == NULL) {
+ TagTable my_tag;
+ strcpy(my_tag.nodename, "12#!@#4");
+ my_tag.offset = 0;
+ tag_table.push_back(my_tag);
+ } else {
int colons = 0, i, j;
int buflen = strlen(buf);
for (i = 0; i < buflen; i++)
@@ -1060,11 +1055,12 @@
{
if ((buf[j] == ',') ||(buf[j] == '\n'))
{
- tag_table = (TagTable*)xrealloc(tag_table, sizeof(TagTable) *(TagTableEntries));
+ TagTable my_tag;
buf[j] = 0;
buflen = j;
- strcpy(tag_table[TagTableEntries - 1].nodename, buf + i + 2);
- tag_table[TagTableEntries - 1].offset = oldpos - 2;
+ strcpy(my_tag.nodename, buf + i + 2);
+ my_tag.offset = oldpos - 2;
+ tag_table.push_back(my_tag);
break;
}
}
Modified: pinfo/branches/cxx/src/mainfunction.cxx
===================================================================
--- pinfo/branches/cxx/src/mainfunction.cxx 2005-09-02 02:25:26 UTC (rev 120)
+++ pinfo/branches/cxx/src/mainfunction.cxx 2005-09-02 02:58:48 UTC (rev 121)
@@ -424,8 +424,8 @@
*/
tokenpos += starttokenpos;
{ /* local scope for tmpvar, matched */
- int tmpvar = 0, matched = 0;
- for (int i = TagTableEntries - 1; i >= 0; i--)
+ int tmpvar = -1, matched = 0;
+ for (int i = tag_table.size() - 1; i >= 0; i--)
{
if ((tag_table[i].offset > tag_table[tmpvar].offset) &&
((tag_table[i].offset - indirect[j].offset + FirstNodeOffset) <= tokenpos))
@@ -518,8 +518,8 @@
*/
tokenpos += starttokenpos;
{ /* local scope for tmpvar, matched */
- int tmpvar = 0, matched = 0;
- for (int i = TagTableEntries - 1; i >= 0; i--)
+ int tmpvar = -1, matched = 0;
+ for (int i = tag_table.size() - 1; i >= 0; i--)
{
if ((tag_table[i].offset > tag_table[tmpvar].offset) &&
(tag_table[i].offset <= tokenpos))
@@ -699,7 +699,7 @@
curs_set(0);
noecho();
attrset(normal);
- for (int i = 0; i < TagTableEntries; i++)
+ for (int i = 0; i < tag_table.size(); i++)
{
/* if the name was found in the tag table */
if (strcmp(token, tag_table[i].nodename) == 0)
Deleted: pinfo/branches/cxx/src/menu_and_note_utils.cxx
Deleted: pinfo/branches/cxx/src/menu_and_note_utils.h
Modified: pinfo/branches/cxx/src/pinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/pinfo.cxx 2005-09-02 02:25:26 UTC (rev 120)
+++ pinfo/branches/cxx/src/pinfo.cxx 2005-09-02 02:58:48 UTC (rev 121)
@@ -201,7 +201,7 @@
char **message = 0;
/* this will hold the node's header */
char *type = 0;
- int tag_table_pos = 0;
+ int tag_table_pos = -1;
/* take care of SIGSEGV, SIGTERM, SIGINT */
install_signal_handlers();
@@ -351,7 +351,7 @@
printf(_("Trying to create alternate tag table...\n"));
create_tag_table(id);
/* if there weren't found any info entries */
- if (TagTableEntries < 1)
+ if (tag_table.empty())
{
printf(_("This doesn't look like an info file...\n"));
exit(handlemanual(filename_string));
@@ -457,7 +457,7 @@
load_indirect(message, lines);
}
/* free old tag table */
- freetagtable();
+ tag_table.clear();
/* search for the new tagtable */
if (seek_tag_table(id,0) != 2)
{
@@ -485,11 +485,10 @@
{
if (!DontHandleWithoutTagTable)
{
- TagTableEntries = 0;
mvhline(maxy - 1, 0, ' ', maxx);
mvaddstr(maxy - 1, 0, _("Tag table not found. Trying to create alternate..."));
create_tag_table(id);
- if (TagTableEntries < 1)
+ if (tag_table.empty())
{
closeprogram();
printf(_("This doesn't look like info file...\n"));
@@ -519,7 +518,7 @@
closeprogram();
/* free's at the end are optional, but look nice :) */
freeitem(&type, &message, &lines);
- freetagtable();
+ tag_table.clear();
indirect.clear();
return 0;
}
Modified: pinfo/branches/cxx/src/utils.cxx
===================================================================
--- pinfo/branches/cxx/src/utils.cxx 2005-09-02 02:25:26 UTC (rev 120)
+++ pinfo/branches/cxx/src/utils.cxx 2005-09-02 02:58:48 UTC (rev 121)
@@ -349,7 +349,7 @@
break;
my_node++;
}
- result = gettagtablepos_search_internal(my_node, 0, TagTableEntries - 1);
+ result = gettagtablepos_search_internal(my_node, 0, tag_table.size() - 1);
xfree(my_node);
return result;
}
More information about the Pinfo-devel
mailing list