xref: /titanic_41/usr/src/lib/libshell/common/include/fcin.h (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1982-2010 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
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,void*);	/* advance function */
40 	void		*context;	/* context pointer */
41 	int		fcleft;		/* for multibyte boundary */
42 	Sfoff_t		fcoff;		/* offset for last read */
43 } Fcin_t;
44 
45 #define fcfile()	(_Fcin._fcfile)
46 #define fcgetc(c)	(((c=fcget()) || (c=fcfill())), c)
47 #define	fcget()		((int)(*_Fcin.fcptr++))
48 #define	fcpeek(n)	((int)_Fcin.fcptr[n])
49 #define	fcseek(n)	((char*)(_Fcin.fcptr+=(n)))
50 #define fcfirst()	((char*)_Fcin.fcbuff)
51 #define fcsopen(s)	(_Fcin._fcfile=(Sfio_t*)0,_Fcin.fcbuff=_Fcin.fcptr=(unsigned char*)(s))
52 #define fctell()	(_Fcin.fcoff + (_Fcin.fcptr-_Fcin.fcbuff))
53 #define fcsave(x)	(*(x) = _Fcin)
54 #define fcrestore(x)	(_Fcin = *(x))
55 extern int		fcfill(void);
56 extern int		fcfopen(Sfio_t*);
57 extern int		fcclose(void);
58 void			fcnotify(void(*)(Sfio_t*,const char*,int,void*),void*);
59 extern int		fcmbstate(const char*,int*,int*);
60 
61 extern Fcin_t		_Fcin;		/* used by macros */
62 
63 #endif /* fcgetc */
64