Fixed bugs in hresultwrap.cpp.

This commit is contained in:
Pietro Gagliardi 2018-05-21 23:05:39 -04:00
parent fb745e80e3
commit d09be0d5fc
1 changed files with 10 additions and 8 deletions

View File

@ -3,11 +3,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#define nbuf 1024
bool generate(std::vector<char> *genline, FILE *fout) bool generate(std::vector<char> *genline, FILE *fout)
{ {
std::vector<char> genout(nbuf); std::vector<char> genout;
size_t nw; size_t nw;
genout.push_back('/'); genout.push_back('/');
@ -18,7 +16,7 @@ bool generate(std::vector<char> *genline, FILE *fout)
genout.push_back('\n'); genout.push_back('\n');
nw = fwrite(genout.data(), sizeof (char), genout.size(), fout); nw = fwrite(genout.data(), sizeof (char), genout.size(), fout);
return nw != genout.size(); return nw == genout.size();
} }
struct process { struct process {
@ -73,7 +71,7 @@ size_t stateGenerate(struct process *p, const char *buf, size_t n, FILE *fout)
size_t j; size_t j;
if (p->genline == NULL) if (p->genline == NULL)
p->genline = new std::vector<size_t>(n); p->genline = new std::vector<char>;
for (j = 0; j < n; j++) for (j = 0; j < n; j++)
if (buf[j] == '\n') if (buf[j] == '\n')
// do NOT include the newline this time // do NOT include the newline this time
@ -82,9 +80,11 @@ size_t stateGenerate(struct process *p, const char *buf, size_t n, FILE *fout)
if (j == n) // '\n' not found; not finished with the line yet if (j == n) // '\n' not found; not finished with the line yet
return j; return j;
// finished with the line; process it and continue // finished with the line; process it and continue
p->state = stateNewLine; if (!generate(p->genline, fout)) {
if (!generate(p->genline, fout))
p->state = stateError; p->state = stateError;
return 0;
}
p->state = stateNewLine;
delete p->genline; delete p->genline;
p->genline = NULL; p->genline = NULL;
// buf[j] == '\n' and generate() took care of printing a newline // buf[j] == '\n' and generate() took care of printing a newline
@ -106,9 +106,11 @@ bool process(struct process *p, const char *buf, size_t n, FILE *fout)
buf += np; buf += np;
n -= np; n -= np;
} }
return p->error; return !p->error;
} }
#define nbuf 1024
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
FILE *fin = NULL, *fout = NULL; FILE *fin = NULL, *fout = NULL;