2 /* : : generated by proto : : */
3 /***********************************************************************
5 * This software is part of the ast package *
6 * Copyright (c) 1985-2010 AT&T Intellectual Property *
7 * and is licensed under the *
8 * Common Public License, Version 1.0 *
9 * by AT&T Intellectual Property *
11 * A copy of the License is available at *
12 * http://www.opensource.org/licenses/cpl1.0.txt *
13 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
15 * Information and Software Systems Research *
19 * Glenn Fowler <gsf@research.att.com> *
20 * David Korn <dgk@research.att.com> *
21 * Phong Vo <kpv@research.att.com> *
23 ***********************************************************************/
26 * Advanced Software Technology Library
33 #if !defined(__PROTO__)
34 #include <prototyped.h>
36 #if !defined(__LINKAGE__)
37 #define __LINKAGE__ /* 2004-08-11 transition */
42 #include <ast_version.h>
61 * workaround botched headers that assume <stdio.h>
68 #define FILE struct _sfio_s
69 #ifndef __FILE_typedef
70 #define __FILE_typedef 1
78 * exit() support -- this matches shell exit codes
81 #define EXIT_BITS 8 /* # exit status bits */
83 #define EXIT_USAGE 2 /* usage exit code */
84 #define EXIT_QUIT ((1<<(EXIT_BITS))-1) /* parent should quit */
85 #define EXIT_NOTFOUND ((1<<(EXIT_BITS-1))-1) /* command not found */
86 #define EXIT_NOEXEC ((1<<(EXIT_BITS-1))-2) /* other exec error */
88 #define EXIT_CODE(x) ((x)&((1<<EXIT_BITS)-1))
89 #define EXIT_CORE(x) (EXIT_CODE(x)|(1<<EXIT_BITS)|(1<<(EXIT_BITS-1)))
90 #define EXIT_TERM(x) (EXIT_CODE(x)|(1<<EXIT_BITS))
93 * NOTE: for compatibility the following work for EXIT_BITS={7,8}
96 #define EXIT_STATUS(x) (((x)&((1<<(EXIT_BITS-2))-1))?(x):EXIT_CODE((x)>>EXIT_BITS))
98 #define EXITED_CORE(x) (((x)&((1<<EXIT_BITS)|(1<<(EXIT_BITS-1))))==((1<<EXIT_BITS)|(1<<(EXIT_BITS-1)))||((x)&((1<<(EXIT_BITS-1))|(1<<(EXIT_BITS-2))))==((1<<(EXIT_BITS-1))|(1<<(EXIT_BITS-2))))
99 #define EXITED_TERM(x) ((x)&((1<<EXIT_BITS)|(1<<(EXIT_BITS-1))))
102 * astconflist() flags
105 #define ASTCONF_parse 0x0001
106 #define ASTCONF_write 0x0002
107 #define ASTCONF_read 0x0004
108 #define ASTCONF_lower 0x0008
109 #define ASTCONF_base 0x0010
110 #define ASTCONF_defined 0x0020
111 #define ASTCONF_quote 0x0040
112 #define ASTCONF_table 0x0080
113 #define ASTCONF_matchcall 0x0100
114 #define ASTCONF_matchname 0x0200
115 #define ASTCONF_matchstandard 0x0400
116 #define ASTCONF_error 0x0800
117 #define ASTCONF_system 0x1000
118 #define ASTCONF_AST 0x2000
124 #define PATH_PHYSICAL 01
125 #define PATH_DOTDOT 02
126 #define PATH_EXISTS 04
127 #define PATH_VERIFIED(n) (((n)&01777)<<5)
133 #define PATH_READ 004
134 #define PATH_WRITE 002
135 #define PATH_EXECUTE 001
136 #define PATH_REGULAR 010
137 #define PATH_ABSOLUTE 020
143 #define PATH_TOUCH_CREATE 01
144 #define PATH_TOUCH_VERBATIM 02
159 * strgrpmatch() flags
162 #define STR_MAXIMAL 01 /* maximal match */
163 #define STR_LEFT 02 /* implicit left anchor */
164 #define STR_RIGHT 04 /* implicit right anchor */
165 #define STR_ICASE 010 /* ignore case */
166 #define STR_GROUP 020 /* (|&) inside [@|&](...) only */
172 #define FMT_ALWAYS 0x01 /* always quote */
173 #define FMT_ESCAPED 0x02 /* already escaped */
174 #define FMT_SHELL 0x04 /* escape $ ` too */
175 #define FMT_WIDE 0x08 /* don't escape 8 bit chars */
176 #define FMT_PARAM 0x10 /* disable FMT_SHELL ${$( quote */
182 #define mbmax() (ast.mb_cur_max)
183 #define mberr() (ast.tmp_int<0)
185 #define mbcoll() (ast.mb_xfrm!=0)
186 #define mbwide() (mbmax()>1)
188 #define mbchar(p) (mbwide()?((ast.tmp_int=(*ast.mb_towc)(&ast.tmp_wchar,(char*)(p),mbmax()))>0?((p+=ast.tmp_int),ast.tmp_wchar):(p+=ast.mb_sync+1,ast.tmp_int)):(*(unsigned char*)(p++)))
189 #define mbinit() (mbwide()?(*ast.mb_towc)((wchar_t*)0,(char*)0,mbmax()):0)
190 #define mbsize(p) (mbwide()?(*ast.mb_len)((char*)(p),mbmax()):((p),1))
191 #define mbconv(s,w) (ast.mb_conv?(*ast.mb_conv)(s,w):((*(s)=(w)),1))
192 #define mbwidth(w) (ast.mb_width&&((ast.tmp_int=(*ast.mb_width)(w))>=0||(w)>UCHAR_MAX)?ast.tmp_int:1)
193 #define mbxfrm(t,f,n) (mbcoll()?(*ast.mb_xfrm)((char*)(t),(char*)(f),n):0)
199 #define elementsof(x) (sizeof(x)/sizeof(x[0]))
200 #define integralof(x) (((char*)(x))-((char*)0))
201 #define newof(p,t,n,x) ((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)calloc(1,sizeof(t)*(n)+(x)))
202 #define oldof(p,t,n,x) ((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)malloc(sizeof(t)*(n)+(x)))
203 #define pointerof(x) ((__V_*)((char*)0+(x)))
204 #define roundof(x,y) (((x)+(y)-1)&~((y)-1))
205 #define ssizeof(x) ((int)sizeof(x))
207 #define streq(a,b) (*(a)==*(b)&&!strcmp(a,b))
208 #define strneq(a,b,n) (*(a)==*(b)&&!strncmp(a,b,n))
209 #define strsignal(s) fmtsignal(s)
211 #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
213 #define NoP(x) (void)(x)
215 #define NiL ((char*)0)
216 #define NoP(x) (&x,1)
220 #if defined(__STDC__) || defined(__STDPP__)
221 #define NoF(x) void _DATA_ ## x () {}
223 #define NoF(x) void _DATA_/**/x () {}
231 #if defined(__STDC__) || defined(__STDPP__)
232 #define NoN(x) void _STUB_ ## x () {}
234 #define NoN(x) void _STUB_/**/x () {}
241 #define NOT_USED(x) NoP(x)
243 typedef int (*Error_f
) __PROTO__((__V_
*, __V_
*, int, ...));
245 typedef int (*Ast_confdisc_f
) __PROTO__((const char*, const char*, const char*));
246 typedef int (*Strcmp_context_f
) __PROTO__((const char*, const char*, __V_
*));
247 typedef int (*Strcmp_f
) __PROTO__((const char*, const char*));
249 #if _BLD_ast && defined(__EXPORT__)
251 #define __MANGLE__ __LINKAGE__ __EXPORT__
254 extern __MANGLE__
char* astgetconf
__PROTO__((const char*, const char*, const char*, int, Error_f
));
255 extern __MANGLE__
char* astconf
__PROTO__((const char*, const char*, const char*));
256 extern __MANGLE__ Ast_confdisc_f astconfdisc
__PROTO__((Ast_confdisc_f
));
257 extern __MANGLE__
void astconflist
__PROTO__((Sfio_t
*, const char*, int, const char*));
258 extern __MANGLE__ off_t astcopy
__PROTO__((int, int, off_t
));
259 extern __MANGLE__
int astlicense
__PROTO__((char*, int, char*, char*, int, int, int));
260 extern __MANGLE__
int astquery
__PROTO__((int, const char*, ...));
261 extern __MANGLE__
void astwinsize
__PROTO__((int, int*, int*));
263 extern __MANGLE__ ssize_t base64encode
__PROTO__((const __V_
*, size_t, __V_
**, __V_
*, size_t, __V_
**));
264 extern __MANGLE__ ssize_t base64decode
__PROTO__((const __V_
*, size_t, __V_
**, __V_
*, size_t, __V_
**));
265 extern __MANGLE__
int chresc
__PROTO__((const char*, char**));
266 extern __MANGLE__
int chrtoi
__PROTO__((const char*));
267 extern __MANGLE__
int eaccess
__PROTO__((const char*, int));
268 extern __MANGLE__
char* fmtbase
__PROTO__((long, int, int));
269 extern __MANGLE__
char* fmtbasell
__PROTO__((intmax_t, int, int));
270 #define fmtbase(a,b,c) fmtbasell((intmax_t)(a),b,c) /* until 2003-09-01 */
271 extern __MANGLE__
char* fmtbuf
__PROTO__((size_t));
272 extern __MANGLE__
char* fmtclock
__PROTO__((Sfulong_t
));
273 extern __MANGLE__
char* fmtelapsed
__PROTO__((unsigned long, int));
274 extern __MANGLE__
char* fmterror
__PROTO__((int));
275 extern __MANGLE__
char* fmtesc
__PROTO__((const char*));
276 extern __MANGLE__
char* fmtesq
__PROTO__((const char*, const char*));
277 extern __MANGLE__
char* fmtident
__PROTO__((const char*));
278 extern __MANGLE__
char* fmtip4
__PROTO__((uint32_t, int));
279 extern __MANGLE__
char* fmtfmt
__PROTO__((const char*));
280 extern __MANGLE__
char* fmtgid
__PROTO__((int));
281 extern __MANGLE__
char* fmtmatch
__PROTO__((const char*));
282 extern __MANGLE__
char* fmtmode
__PROTO__((int, int));
283 extern __MANGLE__
char* fmtnesq
__PROTO__((const char*, const char*, size_t));
284 extern __MANGLE__
char* fmtnum
__PROTO__((unsigned long, int));
285 extern __MANGLE__
char* fmtperm
__PROTO__((int));
286 extern __MANGLE__
char* fmtquote
__PROTO__((const char*, const char*, const char*, size_t, int));
287 extern __MANGLE__
char* fmtre
__PROTO__((const char*));
288 extern __MANGLE__
char* fmtscale
__PROTO__((Sfulong_t
, int));
289 extern __MANGLE__
char* fmtsignal
__PROTO__((int));
290 extern __MANGLE__
char* fmttime
__PROTO__((const char*, time_t));
291 extern __MANGLE__
char* fmtuid
__PROTO__((int));
292 extern __MANGLE__
char* fmtversion
__PROTO__((unsigned long));
293 extern __MANGLE__ __V_
* memdup
__PROTO__((const __V_
*, size_t));
294 extern __MANGLE__
void memfatal
__PROTO__((void));
295 extern __MANGLE__
unsigned int memhash
__PROTO__((const __V_
*, int));
296 extern __MANGLE__
unsigned long memsum
__PROTO__((const __V_
*, int, unsigned long));
297 extern __MANGLE__
char* pathaccess
__PROTO__((char*, const char*, const char*, const char*, int));
298 extern __MANGLE__
char* pathbin
__PROTO__((void));
299 extern __MANGLE__
char* pathcanon
__PROTO__((char*, int));
300 extern __MANGLE__
char* pathcat
__PROTO__((char*, const char*, int, const char*, const char*));
301 extern __MANGLE__
int pathcd
__PROTO__((const char*, const char*));
302 extern __MANGLE__
int pathcheck
__PROTO__((const char*, const char*, Pathcheck_t
*));
303 extern __MANGLE__
int pathexists
__PROTO__((char*, int));
304 extern __MANGLE__
char* pathfind
__PROTO__((const char*, const char*, const char*, char*, size_t));
305 extern __MANGLE__
int pathgetlink
__PROTO__((const char*, char*, int));
306 extern __MANGLE__
int pathinclude
__PROTO__((const char*));
307 extern __MANGLE__
char* pathkey
__PROTO__((char*, char*, const char*, const char*, const char*));
308 extern __MANGLE__
size_t pathnative
__PROTO__((const char*, char*, size_t));
309 extern __MANGLE__
char* pathpath
__PROTO__((char*, const char*, const char*, int));
310 extern __MANGLE__
size_t pathposix
__PROTO__((const char*, char*, size_t));
311 extern __MANGLE__
char* pathprobe
__PROTO__((char*, char*, const char*, const char*, const char*, int));
312 extern __MANGLE__
size_t pathprog
__PROTO__((const char*, char*, size_t));
313 extern __MANGLE__
char* pathrepl
__PROTO__((char*, const char*, const char*));
314 extern __MANGLE__
int pathsetlink
__PROTO__((const char*, const char*));
315 extern __MANGLE__
char* pathshell
__PROTO__((void));
316 extern __MANGLE__
char* pathtemp
__PROTO__((char*, size_t, const char*, const char*, int*));
317 extern __MANGLE__
char* pathtmp
__PROTO__((char*, const char*, const char*, int*));
318 extern __MANGLE__
char* setenviron
__PROTO__((const char*));
319 extern __MANGLE__
int stracmp
__PROTO__((const char*, const char*));
320 extern __MANGLE__
char* strcopy
__PROTO__((char*, const char*));
321 extern __MANGLE__
unsigned long strelapsed
__PROTO__((const char*, char**, int));
322 extern __MANGLE__
int stresc
__PROTO__((char*));
323 extern __MANGLE__
long streval
__PROTO__((const char*, char**, long(*)(const char*, char**)));
324 extern __MANGLE__
long strexpr
__PROTO__((const char*, char**, long(*)(const char*, char**, __V_
*), __V_
*));
325 extern __MANGLE__
int strgid
__PROTO__((const char*));
326 extern __MANGLE__
int strgrpmatch
__PROTO__((const char*, const char*, int*, int, int));
327 extern __MANGLE__
unsigned int strhash
__PROTO__((const char*));
328 extern __MANGLE__ __V_
* strlook
__PROTO__((const __V_
*, size_t, const char*));
329 extern __MANGLE__
int strmatch
__PROTO__((const char*, const char*));
330 extern __MANGLE__
int strmode
__PROTO__((const char*));
331 extern __MANGLE__
int strnacmp
__PROTO__((const char*, const char*, size_t));
332 extern __MANGLE__
char* strncopy
__PROTO__((char*, const char*, size_t));
333 extern __MANGLE__
int strnpcmp
__PROTO__((const char*, const char*, size_t));
334 extern __MANGLE__
double strntod
__PROTO__((const char*, size_t, char**));
335 extern __MANGLE__ _ast_fltmax_t strntold
__PROTO__((const char*, size_t, char**));
336 extern __MANGLE__
long strntol
__PROTO__((const char*, size_t, char**, int));
337 extern __MANGLE__
intmax_t strntoll
__PROTO__((const char*, size_t, char**, int));
338 extern __MANGLE__
long strnton
__PROTO__((const char*, size_t, char**, char*, int));
339 extern __MANGLE__
unsigned long strntoul
__PROTO__((const char*, size_t, char**, int));
340 extern __MANGLE__
intmax_t strntonll
__PROTO__((const char*, size_t, char**, char*, int));
341 extern __MANGLE__
uintmax_t strntoull
__PROTO__((const char*, size_t, char**, int));
342 extern __MANGLE__
int strnvcmp
__PROTO__((const char*, const char*, size_t));
343 extern __MANGLE__
int stropt
__PROTO__((const char*, const __V_
*, int, int(*)(__V_
*, const __V_
*, int, const char*), __V_
*));
344 extern __MANGLE__
int strpcmp
__PROTO__((const char*, const char*));
345 extern __MANGLE__
int strperm
__PROTO__((const char*, char**, int));
346 extern __MANGLE__ __V_
* strpsearch
__PROTO__((const __V_
*, size_t, size_t, const char*, char**));
347 extern __MANGLE__ __V_
* strsearch
__PROTO__((const __V_
*, size_t, size_t, Strcmp_f
, const char*, __V_
*));
348 extern __MANGLE__
void strsort
__PROTO__((char**, int, int(*)(const char*, const char*)));
349 extern __MANGLE__
char* strsubmatch
__PROTO__((const char*, const char*, int));
350 extern __MANGLE__
unsigned long strsum
__PROTO__((const char*, unsigned long));
351 extern __MANGLE__
char* strtape
__PROTO__((const char*, char**));
352 extern __MANGLE__
int strtoip4
__PROTO__((const char*, char**, uint32_t*, unsigned char*));
353 extern __MANGLE__
long strton
__PROTO__((const char*, char**, char*, int));
354 extern __MANGLE__
intmax_t strtonll
__PROTO__((const char*, char**, char*, int));
355 extern __MANGLE__
int struid
__PROTO__((const char*));
356 extern __MANGLE__
int struniq
__PROTO__((char**, int));
357 extern __MANGLE__
int strvcmp
__PROTO__((const char*, const char*));
360 #define __MANGLE__ __LINKAGE__
363 * C library global data symbols not prototyped by <unistd.h>
366 #if !defined(environ) && defined(__DYNAMIC__)
367 #define environ __DYNAMIC__(environ)
369 extern __MANGLE__
char** environ
;
373 * really handy malloc()/free() (__FILE__,__LINE__,__FUNCTION__) tracing
374 * make with VMDEBUG==1 or debug=1 or CCFLAGS=$(CC.DEBUG)
375 * VMDEBUG==0 disables
376 * at runtime export VMDEBUG or VMTRACE per vmalloc.3
377 * to list originating call locations
380 #if !_std_malloc && !defined(VMFL) && !defined(_VMHDR_H) && \
381 (!defined(VMDEBUG) || VMDEBUG) && (VMDEBUG || _BLD_DEBUG)