1 /***********************************************************************
2  *                                                                      *
3  *               This software is part of the ast package               *
4  *          Copyright (c) 1982-2011 AT&T Intellectual Property          *
5  *                      and is licensed under the                       *
6  *                 Eclipse Public License, Version 1.0                  *
7  *                    by AT&T Intellectual Property                     *
8  *                                                                      *
9  *                A copy of the License is available at                 *
10  *          http://www.eclipse.org/org/documents/epl-v10.html           *
11  *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12  *                                                                      *
13  *              Information and Software Systems Research               *
14  *                            AT&T Research                             *
15  *                           Florham Park NJ                            *
16  *                                                                      *
17  *                    David Korn <dgkorn@gmail.com>                     *
18  *                                                                      *
19  ***********************************************************************/
20 //
21 // David Korn
22 // AT&T Labs
23 //
24 // Fast character input with sfio text streams and strings.
25 //
26 #ifndef _FCIN_H
27 #define _FCIN_H 1
28 
29 #include "sfio.h"
30 
31 typedef struct _fcin {
32     Sfio_t *_fcfile;                                     // input file pointer
33     unsigned char *fcbuff;                               // pointer to input buffer
34     unsigned char *fclast;                               // pointer to end of input buffer
35     unsigned char *fcptr;                                // pointer to next input char
36     unsigned char fcchar;                                // saved character
37     short fclen;                                         // last multibyte char len
38     void (*fcfun)(Sfio_t *, const char *, int, void *);  // advance function
39     void *context;                                       // context pointer
40     int fcleft;                                          // for multibyte boundary
41     Sfoff_t fcoff;                                       // offset for last read
42 } Fcin_t;
43 
44 #define fcmbget(x) (mbwide() ? _fcmbget(x) : fcget())
45 #define fcfile() (_Fcin._fcfile)
46 #define fcget() ((int)(*_Fcin.fcptr++))
47 #define fcnxt() _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 fclast() ((char *)_Fcin.fclast)
52 #define fcleft() (_Fcin.fclast - _Fcin.fcptr)
53 #define fcsopen(s) \
54     (_Fcin._fcfile = NULL, _Fcin.fclen = 1, _Fcin.fcbuff = _Fcin.fcptr = (unsigned char *)(s))
55 #define fctell() (_Fcin.fcoff + (_Fcin.fcptr - _Fcin.fcbuff))
56 #define fcsave(x) (*(x) = _Fcin)
57 #define fcrestore(x) (_Fcin = *(x))
58 extern int fcgetc(void);
59 extern int fcfill(void);
60 extern int fcfopen(Sfio_t *);
61 extern int fcclose(void);
62 void fcnotify(void (*)(Sfio_t *, const char *, int, void *), void *);
63 extern int _fcmbget(short *);
64 
65 extern Fcin_t _Fcin;  // used by macros
66 
67 #endif  // _FCIN_H
68