1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
/************************************************************************/
/* */
/* Simplification of stdio. */
/* */
/************************************************************************/
# ifndef SIO_GENERAL_H
# define SIO_GENERAL_H
# include <stdio.h> /* for EOF. */
# define SIOsizBUF 1024
typedef int (*SIOinREADBYTES)( void *, unsigned char *, int );
typedef int (*SIOinSEEK)( void *, long );
typedef int (*SIOinCLOSE)( void * );
typedef struct SimpleInputStream
{
unsigned char sisBuffer[SIOsizBUF];
unsigned char * sisP;
int sisN;
void * sisPrivate;
long sisReadUpto;
SIOinREADBYTES sisReadBytes;
SIOinSEEK sisSeek;
SIOinCLOSE sisClose;
} SimpleInputStream;
# define sioInGetCharacter(s) \
( (--((s)->sisN)) >= 0 ? \
*(((s)->sisP)++) : \
sioInFillBuffer(s) )
typedef int (*SIOoutWRITEBYTES)( void *, const unsigned char *, int );
typedef int (*SIOoutCLOSE)( void * );
typedef int (*SIOoutSEEK)( void *, long );
typedef struct SimpleOutputStream
{
unsigned char sosBuffer[SIOsizBUF];
unsigned char * sosP;
int sosN;
void * sosPrivate;
SIOoutWRITEBYTES sosWriteBytes;
SIOoutSEEK sosSeek;
SIOoutCLOSE sosClose;
} SimpleOutputStream;
# define sioOutPutCharacter(c,s) \
( ( (s)->sosN >= SIOsizBUF && sioOutFlushBuffer(s) ) ? -1 : \
( *(((s)->sosP)++)= (c), (s)->sosN++, 0 ) )
/************************************************************************/
/* */
/* Routine declarations. */
/* */
/************************************************************************/
/* in */
extern int sioInFillBuffer( SimpleInputStream * sis );
extern int sioInUngetLastRead( SimpleInputStream * sis );
extern SimpleInputStream * sioInOpen( void * specific,
SIOinREADBYTES readBytes,
SIOinSEEK seekTo,
SIOinCLOSE closeIt );
extern int sioInClose( SimpleInputStream * sis );
extern char * sioInGetString( char * s,
int size,
SimpleInputStream * sis );
extern int sioInReadBytes( SimpleInputStream * sis,
unsigned char * buf,
int count );
extern int sioInSeek( SimpleInputStream * sis,
long pos );
/* out */
extern int sioOutFlushBuffer( SimpleOutputStream * sos );
extern SimpleOutputStream * sioOutOpen( void * specific,
SIOoutWRITEBYTES writeBytes,
SIOoutSEEK seekTo,
SIOoutCLOSE closeIt );
extern int sioOutSeek( SimpleOutputStream * sos,
long pos );
extern int sioOutClose( SimpleOutputStream * sos );
extern int sioOutPutString( const char * s,
SimpleOutputStream * sos );
extern int sioOutWriteBytes( SimpleOutputStream * sos,
const unsigned char * buf,
int count );
# endif
|