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