Skip to content

Commit

Permalink
Fix prpgrep not searching some objects properly
Browse files Browse the repository at this point in the history
For example, `prpgrep plSoundBuffer BahroCave_District_YeeshaCave.prp`
found no results, even though that page contains many plSoundBuffer
objects (and other objects that reference them).

Not sure what exactly was wrong with the custom GetLine function here,
but replacing it with the standard hsStream::readLine fixes it.
  • Loading branch information
dgelessus committed Mar 21, 2024
1 parent e043a0e commit 1bf8e6c
Showing 1 changed file with 1 addition and 35 deletions.
36 changes: 1 addition & 35 deletions Tools/src/prpgrep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,46 +22,12 @@
#include <string_theory/stdio>
#include <list>

static char lnbuf[4096];
static char* lnbuf_ptr = &lnbuf[4096];

static ST::string GetLine(hsStream* S)
{
if (lnbuf_ptr >= &lnbuf[4096]) {
size_t len = S->size() - S->pos();
if (len > 4096)
len = 4096;
S->read(len, lnbuf);
if (len < 4096)
lnbuf[len] = 0;
lnbuf_ptr = lnbuf;
}

char* bp = lnbuf_ptr;
while (true) {
if (bp >= &lnbuf[4096]) {
ST::string prefix(lnbuf_ptr, bp - lnbuf_ptr);
lnbuf_ptr = &lnbuf[4096];
return prefix + GetLine(S);
} else if (*bp == '\n' || *bp == 0) {
ST::string ln(lnbuf_ptr, bp - lnbuf_ptr);
lnbuf_ptr = bp + 1;
return ln;
}
bp++;
}

// Should never get here...
return ST::string();
}

static void DoSearch(hsStream* S, const ST::string& pattern,
const ST::string& filename, const plKey& key)
{
unsigned int ln = 1;
lnbuf_ptr = &lnbuf[4096];
while (!S->eof()) {
ST::string text = GetLine(S);
ST::string text = S->readLine();
if (text.find(pattern) >= 0) {
// Strip initial whitespace
const char* txtout = text.c_str();
Expand Down

0 comments on commit 1bf8e6c

Please sign in to comment.