[Pinfo-devel] r190 - pinfo/branches/cxx/src
Nathanael Nerode
neroden-guest at costa.debian.org
Wed Sep 7 02:52:52 UTC 2005
Author: neroden-guest
Date: 2005-09-07 02:52:51 +0000 (Wed, 07 Sep 2005)
New Revision: 190
Modified:
pinfo/branches/cxx/src/filehandling_functions.cxx
pinfo/branches/cxx/src/filehandling_functions.h
pinfo/branches/cxx/src/pinfo.cxx
Log:
Convert load_tag_table to use the zero-based vector<string> form of message,
don't ignore the last line, and do some serious cleanup on it (it now creates
far fewer temporary strings).
Modified: pinfo/branches/cxx/src/filehandling_functions.cxx
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.cxx 2005-09-07 02:29:35 UTC (rev 189)
+++ pinfo/branches/cxx/src/filehandling_functions.cxx 2005-09-07 02:52:51 UTC (rev 190)
@@ -423,45 +423,49 @@
}
void
-load_tag_table(char **message, long lines)
+load_tag_table(vector<string> message)
{
- int is_indirect = 0;
+ tag_table.clear();
+ if (message.size() == 0) {
+ /* Fail. */
+ return;
+ }
+
/*
- * if in the first line there is a(indirect) string, skip that line
- * by adding the value of is_indirect=1 to all message[line] references.
+ * If the first line begins with "(indirect)", skip that line.
*/
- if (strcasecmp("(Indirect)", message[1]) == 0)
- is_indirect = 1;
- tag_table.clear();
+ bool is_indirect = false;
+ if (strcasecmp("(Indirect)", message[0].substr(0, 10).c_str()) == 0)
+ is_indirect = true;
- for (long i = 1; i < lines - is_indirect; i++)
- {
- string wsk_string = message[i + is_indirect];
+ /* Run through all lines. */
+ for (typeof(message.size()) i = (is_indirect ? 1 : 0);
+ i < message.size(); i++) {
/* Skip first character and nonwhitespace after it.
* (Why first character? FIXME)
* plus one more (space) character */
string::size_type j;
- for (j = 1; j < wsk_string.size(); j++) {
- if (isspace(wsk_string[j])) {
+ for (j = 1; j < message[i].size(); j++) {
+ if (isspace(message[i][j])) {
j++;
break;
}
}
- string trimmed = wsk_string.substr(j); /* Might be "" */
- if (trimmed == "") {
+ if (j == message[i].size()) {
+ /* No characters left for the node name. */
continue;
}
/* Find INDIRECT_TAG character, but skip at least one character
* so the node name is nonempty */
- string::size_type ind_tag_idx = trimmed.find(INDIRECT_TAG, 1);
+ string::size_type ind_tag_idx = message[i].find(INDIRECT_TAG, j + 1);
if (ind_tag_idx == string::npos) {
continue;
}
TagTable my_tag;
- my_tag.nodename.assign(trimmed, 0, ind_tag_idx);
- string offset_string = trimmed.substr(ind_tag_idx + 1);
+ my_tag.nodename = message[i].substr(j, ind_tag_idx - j);
+ string offset_string = message[i].substr(ind_tag_idx + 1);
my_tag.offset = atoi(offset_string.c_str());
tag_table.push_back(my_tag);
}
Modified: pinfo/branches/cxx/src/filehandling_functions.h
===================================================================
--- pinfo/branches/cxx/src/filehandling_functions.h 2005-09-07 02:29:35 UTC (rev 189)
+++ pinfo/branches/cxx/src/filehandling_functions.h 2005-09-07 02:52:51 UTC (rev 190)
@@ -62,7 +62,7 @@
*/
void load_indirect (std::vector<std::string> message);
/* loads tag table (as above) */
-void load_tag_table (char **message, long lines);
+void load_tag_table (std::vector<std::string> message);
/* opens info file */
FILE *openinfo (const std::string filename, int number);
/* opens dir info file */
Modified: pinfo/branches/cxx/src/pinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/pinfo.cxx 2005-09-07 02:29:35 UTC (rev 189)
+++ pinfo/branches/cxx/src/pinfo.cxx 2005-09-07 02:52:51 UTC (rev 190)
@@ -350,7 +350,16 @@
if (ForceManualTagTable == 0)
{
read_item(id, &type, &message, &lines);
- load_tag_table(message, lines);
+
+ /* Quick conversion to vector. Temporary, FIXME. */
+ vector<string> my_message;
+ for (typeof(my_message.size()) x = 0; x < lines; x++) {
+ /* one-based to zero-based conversion, ick */
+ string foo = message[x + 1];
+ my_message.push_back(foo);
+ }
+
+ load_tag_table(my_message);
}
else
{
@@ -506,7 +515,16 @@
if (ForceManualTagTable == 0)
{
read_item(id, &type, &message, &lines);
- load_tag_table(message, lines);
+
+ /* Quick conversion to vector. Temporary, FIXME. */
+ vector<string> my_message;
+ for (typeof(my_message.size()) x = 0; x < lines; x++) {
+ /* one-based to zero-based conversion, ick */
+ string foo = message[x + 1];
+ my_message.push_back(foo);
+ }
+
+ load_tag_table(my_message);
}
else /* create tag table manually */
{
More information about the Pinfo-devel
mailing list