xref: /titanic_44/usr/src/lib/libshell/common/include/fcin.h (revision 67e3a03ed4a2813074d36330f062ed6e593a4937)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *           Copyright (c) 1982-2007 AT&T Knowledge Ventures            *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                      by AT&T Knowledge Ventures                      *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                  David Korn <dgk@research.att.com>                   *
18 *                                                                      *
19 ***********************************************************************/
20 #pragma prototyped
21 #ifndef fcgetc
22 /*
23  * David Korn
24  * AT&T Labs
25  *
26  * Fast character input with sfio text streams and strings
27  *
28  */
29 
30 #include	<sfio.h>
31 
32 typedef struct _fcin
33 {
34 	Sfio_t		*_fcfile;	/* input file pointer */
35 	unsigned char	*fcbuff;	/* pointer to input buffer */
36 	unsigned char	*fclast;	/* pointer to end of input buffer */
37 	unsigned char	*fcptr;		/* pointer to next input char */
38 	unsigned char	fcchar;		/* saved character */
39 	void (*fcfun)(Sfio_t*,const char*,int);	/* advance function */
40 	int		fcleft;		/* for multibyte boundary */
41 	Sfoff_t		fcoff;		/* offset for last read */
42 } Fcin_t;
43 
44 #define fcfile()	(_Fcin._fcfile)
45 #define fcgetc(c)	(((c=fcget()) || (c=fcfill())), c)
46 #define	fcget()		((int)(*_Fcin.fcptr++))
47 #define	fcpeek(n)	((int)_Fcin.fcptr[n])
48 #define	fcseek(n)	((char*)(_Fcin.fcptr+=(n)))
49 #define fcfirst()	((char*)_Fcin.fcbuff)
50 #define fcsopen(s)	(_Fcin._fcfile=(Sfio_t*)0,_Fcin.fcbuff=_Fcin.fcptr=(unsigned char*)(s))
51 #define fctell()	(_Fcin.fcoff + (_Fcin.fcptr-_Fcin.fcbuff))
52 #define fcsave(x)	(*(x) = _Fcin)
53 #define fcrestore(x)	(_Fcin = *(x))
54 extern int		fcfill(void);
55 extern int		fcfopen(Sfio_t*);
56 extern int		fcclose(void);
57 void			fcnotify(void(*)(Sfio_t*,const char*,int));
58 extern int		fcmbstate(const char*,int*,int*);
59 
60 extern Fcin_t		_Fcin;		/* used by macros */
61 
62 #endif /* fcgetc */
63