From 539bc8c545a43f59e9d648ad56e22edeb8d67826 Mon Sep 17 00:00:00 2001 From: thurston Date: Tue, 23 Oct 2007 21:50:03 +0000 Subject: [PATCH] Added cfilebuf, which wrappes a FILE struct. git-svn-id: http://svn.complang.org/ragel/trunk@316 052ea7fc-9027-0410-9066-f65837a77df0 --- common/common.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/common/common.h b/common/common.h index cfe8500..3cd20f1 100644 --- a/common/common.h +++ b/common/common.h @@ -302,6 +302,49 @@ public: int line; }; +class cfilebuf : public std::streambuf +{ +public: + cfilebuf( char *fileName, FILE* file ) : fileName(fileName), file(file) { } + char *fileName; + FILE *file; + + int sync() + { + fflush( file ); + return 0; + } + + int overflow( int c ) + { + if ( c != EOF ) + fputc( c, file ); + return 0; + } + + std::streamsize xsputn( const char* s, std::streamsize n ) + { + std::streamsize written = fwrite( s, 1, n, file ); + return written; + } +}; + +class costream : public std::ostream +{ +public: + costream( cfilebuf *b ) : + std::ostream(b), b(b) {} + + ~costream() + { delete b; } + + void fclose() + { ::fclose( b->file ); } + + cfilebuf *b; +}; + + char *findFileExtension( char *stemFile ); char *fileNameFromStem( char *stemFile, char *suffix ); -- 2.7.4