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