Expanded the tool input slightly and (finally) changed hresultwrap.cpp to use WriteCloser.

This commit is contained in:
Pietro Gagliardi 2018-05-28 22:46:30 -04:00
parent 7e2c505b1d
commit b590482ccb
2 changed files with 29 additions and 18 deletions

View File

@ -1,3 +1,14 @@
static HRESULT lastErrorToHRESULT(DWORD lasterr, const char *funcname)
{
HRESULT hr;
hr = E_FAIL;
if (lasterr != 0)
hr = HRESULT_FROM_WIN32(lasterr);
uiprivImplBug("error calling %s: last error %I32d\n", funcname, lasterr);
return hr;
}
@BOOL UnregisterClassW LPCWSTR className HINSTANCE hInstance == 0 @BOOL UnregisterClassW LPCWSTR className HINSTANCE hInstance == 0
@*HWND CreateWindowExW DWORD exstyle LPCWSTR className LPCWSTR title DWORD style int x int y int width int height HWND parent HMENU menu HINSTANCE hInstance LPVOID lpParam == NULL @*HWND CreateWindowExW DWORD exstyle LPCWSTR className LPCWSTR title DWORD style int x int y int width int height HWND parent HMENU menu HINSTANCE hInstance LPVOID lpParam == NULL
@BOOL DestroyWindow HWND hwnd == 0 @BOOL DestroyWindow HWND hwnd == 0

View File

@ -155,11 +155,10 @@ ByteSlice Function::Body(void) const
#define noutbuf 2048 #define noutbuf 2048
bool generate(ByteSlice line, FILE *fout) Error *generate(ByteSlice line, WriteCloser *fout)
{ {
ByteSlice genout; ByteSlice genout;
Function *f; Function *f;
size_t nw;
genout = ByteSlice(0, noutbuf); genout = ByteSlice(0, noutbuf);
@ -171,20 +170,19 @@ bool generate(ByteSlice line, FILE *fout)
genout = genout.AppendString(u8"\n"); genout = genout.AppendString(u8"\n");
genout = genout.AppendString(u8"\n"); genout = genout.AppendString(u8"\n");
nw = fwrite(genout.Data(), sizeof (char), genout.Len(), fout); return fout->Write(genout);
return nw == genout.Len();
} }
bool process(ByteSlice line, FILE *fout) Error *process(ByteSlice line, WriteCloser *fout)
{ {
size_t nw; Error *err;
if (line.Len() > 0 && line.Data()[0] == '@') if (line.Len() > 0 && line.Data()[0] == '@')
return generate(line.Slice(1, line.Len()), fout); return generate(line.Slice(1, line.Len()), fout);
nw = fwrite(line.Data(), sizeof (char), line.Len(), fout); err = fout->Write(line);
if (nw != line.Len()) if (err != NULL)
return false; return err;
return fwrite("\n", sizeof (char), 1, fout) == 1; return fout->Write(ByteSlice().AppendString("\n"));
} }
} }
@ -192,7 +190,7 @@ bool process(ByteSlice line, FILE *fout)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
ReadCloser *fin = NULL; ReadCloser *fin = NULL;
FILE *fout = NULL; WriteCloser *fout = NULL;
Scanner *s = NULL; Scanner *s = NULL;
int ret = 1; int ret = 1;
Error *err = NULL; Error *err = NULL;
@ -207,18 +205,20 @@ int main(int argc, char *argv[])
fprintf(stderr, "error opening %s: %s\n", argv[1], err->String()); fprintf(stderr, "error opening %s: %s\n", argv[1], err->String());
goto done; goto done;
} }
fout = fopen(argv[2], "wb"); err = CreateWrite(argv[2], &fout);
if (fout == NULL) { if (err != NULL) {
fprintf(stderr, "error creating %s\n", argv[2]); fprintf(stderr, "error creating %s: %s\n", argv[2], err->String());
goto done; goto done;
} }
s = new Scanner(fin); s = new Scanner(fin);
while (s->Scan()) while (s->Scan()) {
if (!process(s->Bytes(), fout)) { err = process(s->Bytes(), fout);
fprintf(stderr, "error writing to %s\n", argv[2]); if (err != NULL) {
fprintf(stderr, "error processing line: %s\n", argv[2], err->String());
goto done; goto done;
} }
}
if (s->Err() != 0) { if (s->Err() != 0) {
fprintf(stderr, "error reading from %s: %s\n", argv[1], s->Err()->String()); fprintf(stderr, "error reading from %s: %s\n", argv[1], s->Err()->String());
goto done; goto done;
@ -229,7 +229,7 @@ done:
if (s != NULL) if (s != NULL)
delete s; delete s;
if (fout != NULL) if (fout != NULL)
fclose(fout); delete fout;
if (fin != NULL) if (fin != NULL)
delete fin; delete fin;
if (err != NULL) if (err != NULL)