|
/* fileio.c -- does standard I/O
(c) 1998-2004 (W3C) MIT, ERCIM, Keio University
See tidy.h for the copyright notice.
CVS Info :
$Author: terry_teague $
$Date: 2004/02/29 03:55:22 $
$Revision: 1.6 $
Default implementations of Tidy input sources
and output sinks based on standard C FILE*.
*/
#include <stdio.h>
#include "fileio.h"
#include "tidy.h"
typedef struct _fp_input_source
{
FILE* fp;
TidyBuffer unget;
} FileSource;
static int filesrc_getByte( ulong sourceData )
{
FileSource* fin = (FileSource*) sourceData;
int bv;
if ( fin->unget.size > 0 )
bv = tidyBufPopByte( &fin->unget );
else
bv = fgetc( fin->fp );
return bv;
}
static Bool filesrc_eof( ulong sourceData )
{
FileSource* fin = (FileSource*) sourceData;
Bool isEOF = ( fin->unget.size == 0 );
if ( isEOF )
isEOF = feof( fin->fp );
return isEOF;
}
static void filesrc_ungetByte( ulong sourceData, byte bv )
{
FileSource* fin = (FileSource*) sourceData;
tidyBufPutByte( &fin->unget, bv );
}
void initFileSource( TidyInputSource* inp, FILE* fp )
{
FileSource* fin = NULL;
inp->getByte = filesrc_getByte;
inp->eof = filesrc_eof;
inp->ungetByte = filesrc_ungetByte;
fin = (FileSource*) MemAlloc( sizeof(FileSource) );
ClearMemory( fin, sizeof(FileSource) );
fin->fp = fp;
inp->sourceData = (ulong) fin;
}
void freeFileSource( TidyInputSource* inp, Bool closeIt )
{
FileSource* fin = (FileSource*) inp->sourceData;
if ( closeIt && fin && fin->fp )
fclose( fin->fp );
tidyBufFree( &fin->unget );
MemFree( fin );
}
void filesink_putByte( ulong sinkData, byte bv )
{
FILE* fout = (FILE*) sinkData;
fputc( bv, fout );
}
void initFileSink( TidyOutputSink* outp, FILE* fp )
{
outp->putByte = filesink_putByte;
outp->sinkData = (ulong) fp;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
He used to have biography here
, but now he will hire someone (for free offcourse
), Who writes his biography on his behalf
He is Great Fan of Mr.
Johan Rosengren (his idol),
Lim Bio Liong,
Nishant S and
DavidCrow and Believes that, he will EXCEL in his life by following there steps!!!
He started with Visual C++ then moved to C# then he become language agnostic, you give him task,tell him the language or platform, he we start immediately, if he knows the language otherwise he quickly learn it and start contributing productively
Last but not the least, For good 8 years he was Visual CPP MSMVP!