1*b30d1939SAndy Fiddaman /***********************************************************************
2*b30d1939SAndy Fiddaman *                                                                      *
3*b30d1939SAndy Fiddaman *               This software is part of the ast package               *
4*b30d1939SAndy Fiddaman *          Copyright (c) 1985-2012 AT&T Intellectual Property          *
5*b30d1939SAndy Fiddaman *                      and is licensed under the                       *
6*b30d1939SAndy Fiddaman *                 Eclipse Public License, Version 1.0                  *
7*b30d1939SAndy Fiddaman *                    by AT&T Intellectual Property                     *
8*b30d1939SAndy Fiddaman *                                                                      *
9*b30d1939SAndy Fiddaman *                A copy of the License is available at                 *
10*b30d1939SAndy Fiddaman *          http://www.eclipse.org/org/documents/epl-v10.html           *
11*b30d1939SAndy Fiddaman *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12*b30d1939SAndy Fiddaman *                                                                      *
13*b30d1939SAndy Fiddaman *              Information and Software Systems Research               *
14*b30d1939SAndy Fiddaman *                            AT&T Research                             *
15*b30d1939SAndy Fiddaman *                           Florham Park NJ                            *
16*b30d1939SAndy Fiddaman *                                                                      *
17*b30d1939SAndy Fiddaman *                 Glenn Fowler <gsf@research.att.com>                  *
18*b30d1939SAndy Fiddaman *                  David Korn <dgk@research.att.com>                   *
19*b30d1939SAndy Fiddaman *                   Phong Vo <kpv@research.att.com>                    *
20*b30d1939SAndy Fiddaman *                                                                      *
21*b30d1939SAndy Fiddaman ***********************************************************************/
22*b30d1939SAndy Fiddaman #pragma prototyped
23*b30d1939SAndy Fiddaman /*
24*b30d1939SAndy Fiddaman  * standalone mini ast+sfio interface
25*b30d1939SAndy Fiddaman  */
26*b30d1939SAndy Fiddaman 
27*b30d1939SAndy Fiddaman #ifndef _AST_H
28*b30d1939SAndy Fiddaman #define _AST_H		1
29*b30d1939SAndy Fiddaman 
30*b30d1939SAndy Fiddaman #include <ast_sa.h>
31*b30d1939SAndy Fiddaman #include <ast_common.h>
32*b30d1939SAndy Fiddaman 
33*b30d1939SAndy Fiddaman #include <stdio.h>
34*b30d1939SAndy Fiddaman #include <stdlib.h>
35*b30d1939SAndy Fiddaman #include <string.h>
36*b30d1939SAndy Fiddaman #include <limits.h>
37*b30d1939SAndy Fiddaman 
38*b30d1939SAndy Fiddaman #define FMT_EXP_CHAR	0x020		/* expand single byte chars	*/
39*b30d1939SAndy Fiddaman #define FMT_EXP_LINE	0x040		/* expand \n and \r		*/
40*b30d1939SAndy Fiddaman #define FMT_EXP_WIDE	0x080		/* expand \u \U \x wide chars	*/
41*b30d1939SAndy Fiddaman #define FMT_EXP_NOCR	0x100		/* skip \r			*/
42*b30d1939SAndy Fiddaman #define FMT_EXP_NONL	0x200		/* skip \n			*/
43*b30d1939SAndy Fiddaman 
44*b30d1939SAndy Fiddaman #define STR_MAXIMAL	01		/* maximal match		*/
45*b30d1939SAndy Fiddaman #define STR_LEFT	02		/* implicit left anchor		*/
46*b30d1939SAndy Fiddaman #define STR_RIGHT	04		/* implicit right anchor	*/
47*b30d1939SAndy Fiddaman #define STR_ICASE	010		/* ignore case			*/
48*b30d1939SAndy Fiddaman #define STR_GROUP	020		/* (|&) inside [@|&](...) only	*/
49*b30d1939SAndy Fiddaman 
50*b30d1939SAndy Fiddaman typedef int (*Error_f)(void*, void*, int, ...);
51*b30d1939SAndy Fiddaman 
52*b30d1939SAndy Fiddaman typedef struct
53*b30d1939SAndy Fiddaman {
54*b30d1939SAndy Fiddaman 
55*b30d1939SAndy Fiddaman 	char*		id;
56*b30d1939SAndy Fiddaman 
57*b30d1939SAndy Fiddaman 	struct
58*b30d1939SAndy Fiddaman 	{
59*b30d1939SAndy Fiddaman 	unsigned int	serial;
60*b30d1939SAndy Fiddaman 	unsigned int	set;
61*b30d1939SAndy Fiddaman 	}		locale;
62*b30d1939SAndy Fiddaman 
63*b30d1939SAndy Fiddaman 	long		tmp_long;
64*b30d1939SAndy Fiddaman 	size_t		tmp_size;
65*b30d1939SAndy Fiddaman 	short		tmp_short;
66*b30d1939SAndy Fiddaman 	char		tmp_char;
67*b30d1939SAndy Fiddaman 	wchar_t		tmp_wchar;
68*b30d1939SAndy Fiddaman 
69*b30d1939SAndy Fiddaman 	int		(*collate)(const char*, const char*);
70*b30d1939SAndy Fiddaman 
71*b30d1939SAndy Fiddaman 	int		tmp_int;
72*b30d1939SAndy Fiddaman 	void*		tmp_pointer;
73*b30d1939SAndy Fiddaman 
74*b30d1939SAndy Fiddaman 	int		mb_cur_max;
75*b30d1939SAndy Fiddaman 	int		(*mb_len)(const char*, size_t);
76*b30d1939SAndy Fiddaman 	int		(*mb_towc)(wchar_t*, const char*, size_t);
77*b30d1939SAndy Fiddaman 	size_t		(*mb_xfrm)(char*, const char*, size_t);
78*b30d1939SAndy Fiddaman 	int		(*mb_width)(wchar_t);
79*b30d1939SAndy Fiddaman 	int		(*mb_conv)(char*, wchar_t);
80*b30d1939SAndy Fiddaman 
81*b30d1939SAndy Fiddaman 	unsigned int	env_serial;
82*b30d1939SAndy Fiddaman 
83*b30d1939SAndy Fiddaman 	char		pad[944];
84*b30d1939SAndy Fiddaman 
85*b30d1939SAndy Fiddaman } _Ast_info_t;
86*b30d1939SAndy Fiddaman 
87*b30d1939SAndy Fiddaman #define ast		_ast_info_
88*b30d1939SAndy Fiddaman 
89*b30d1939SAndy Fiddaman #define elementsof(x)	(sizeof(x)/sizeof(x[0]))
90*b30d1939SAndy Fiddaman #define integralof(x)	(((char*)(x))-((char*)0))
91*b30d1939SAndy Fiddaman #define newof(p,t,n,x)	((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)calloc(1,sizeof(t)*(n)+(x)))
92*b30d1939SAndy Fiddaman #define oldof(p,t,n,x)	((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)malloc(sizeof(t)*(n)+(x)))
93*b30d1939SAndy Fiddaman #define pointerof(x)	((void*)((char*)0+(x)))
94*b30d1939SAndy Fiddaman #define roundof(x,y)	(((x)+(y)-1)&~((y)-1))
95*b30d1939SAndy Fiddaman 
96*b30d1939SAndy Fiddaman #ifndef offsetof
97*b30d1939SAndy Fiddaman #define offsetof(type,member) ((unsigned long)&(((type*)0)->member))
98*b30d1939SAndy Fiddaman #endif
99*b30d1939SAndy Fiddaman 
100*b30d1939SAndy Fiddaman #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
101*b30d1939SAndy Fiddaman #define NiL			0
102*b30d1939SAndy Fiddaman #define NoP(x)			(void)(x)
103*b30d1939SAndy Fiddaman #else
104*b30d1939SAndy Fiddaman #define NiL			((char*)0)
105*b30d1939SAndy Fiddaman #define NoP(x)			(&x,1)
106*b30d1939SAndy Fiddaman #endif
107*b30d1939SAndy Fiddaman 
108*b30d1939SAndy Fiddaman #define conformance(a,b)	"ast"
109*b30d1939SAndy Fiddaman #define fmtident(s)		((char*)(s)+10)
110*b30d1939SAndy Fiddaman #define mbchar(s)		(*s++)
111*b30d1939SAndy Fiddaman #define setlocale(a,b)
112*b30d1939SAndy Fiddaman 
113*b30d1939SAndy Fiddaman #define streq(a,b)		(*(a)==*(b)&&!strcmp(a,b))
114*b30d1939SAndy Fiddaman #define strneq(a,b,n)		(*(a)==*(b)&&!strncmp(a,b,n))
115*b30d1939SAndy Fiddaman #define strton(s,t,b,f)		strtol(s,t,0)
116*b30d1939SAndy Fiddaman #define strtonll(s,t,b,f)	strtoll(s,t,0)
117*b30d1939SAndy Fiddaman 
118*b30d1939SAndy Fiddaman #define Sfio_t		FILE
119*b30d1939SAndy Fiddaman 
120*b30d1939SAndy Fiddaman #define sfstdin		stdin
121*b30d1939SAndy Fiddaman #define sfstdout	stdout
122*b30d1939SAndy Fiddaman #define sfstderr	stderr
123*b30d1939SAndy Fiddaman 
124*b30d1939SAndy Fiddaman #define sfclose(f)	fclose(f)
125*b30d1939SAndy Fiddaman #define sffileno(f)	fileno(f)
126*b30d1939SAndy Fiddaman #define sfgetc(f)	fgetc(f)
127*b30d1939SAndy Fiddaman #define sfopen(f,n,m)	fopen(n,m)
128*b30d1939SAndy Fiddaman #define sfputc(f,c)	fputc(c,f)
129*b30d1939SAndy Fiddaman #define sfread(f,b,n)	fread(b,n,1,f)
130*b30d1939SAndy Fiddaman #define sfseek(f,p,w)	fseek(f,p,w)
131*b30d1939SAndy Fiddaman #define sfset(f,v,n)
132*b30d1939SAndy Fiddaman #define sfsync(f)	fflush(f)
133*b30d1939SAndy Fiddaman #define sfwrite(f,b,n)	fwrite(b,n,1,f)
134*b30d1939SAndy Fiddaman 
135*b30d1939SAndy Fiddaman #define sfprintf	fprintf
136*b30d1939SAndy Fiddaman #define sfsprintf	snprintf
137*b30d1939SAndy Fiddaman #define sfvprintf	vfprintf
138*b30d1939SAndy Fiddaman 
139*b30d1939SAndy Fiddaman #define sfscanf		fscanf
140*b30d1939SAndy Fiddaman 
141*b30d1939SAndy Fiddaman #define sfgetr		_sf_getr
142*b30d1939SAndy Fiddaman 
143*b30d1939SAndy Fiddaman #include <sfstr.h>
144*b30d1939SAndy Fiddaman 
145*b30d1939SAndy Fiddaman extern _Ast_info_t	ast;
146*b30d1939SAndy Fiddaman 
147*b30d1939SAndy Fiddaman extern int		astwinsize(int, int*, int*);
148*b30d1939SAndy Fiddaman extern int		chresc(const char*, char**);
149*b30d1939SAndy Fiddaman extern char*		fmtbuf(size_t);
150*b30d1939SAndy Fiddaman extern char*		fmtip4(uint32_t, int);
151*b30d1939SAndy Fiddaman extern char*		sfgetr(Sfio_t*, int, int);
152*b30d1939SAndy Fiddaman extern char*		strcopy(char*, const char*);
153*b30d1939SAndy Fiddaman extern int		strmatch(const char*, const char*);
154*b30d1939SAndy Fiddaman extern int		strtoip4(const char*, char**, uint32_t*, unsigned char*);
155*b30d1939SAndy Fiddaman 
156*b30d1939SAndy Fiddaman #endif