
/* : : generated by proto : : */
/***********************************************************************
*                                                                      *
*               This software is part of the ast package               *
*          Copyright (c) 1985-2012 AT&T Intellectual Property          *
*          Copyright (c) 2020-2021 Contributors to ksh 93u+m           *
*                      and is licensed under the                       *
*                 Eclipse Public License, Version 1.0                  *
*                    by AT&T Intellectual Property                     *
*                                                                      *
*                A copy of the License is available at                 *
*          http://www.eclipse.org/org/documents/epl-v10.html           *
*         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
*                                                                      *
*              Information and Software Systems Research               *
*                            AT&T Research                             *
*                           Florham Park NJ                            *
*                                                                      *
*                 Glenn Fowler <gsf@research.att.com>                  *
*                  David Korn <dgk@research.att.com>                   *
*                   Phong Vo <kpv@research.att.com>                    *
*                                                                      *
***********************************************************************/
                  

/*
 * Advanced Software Technology Library
 * AT&T Research
 *
 * std + POSIX + AST
 */

#ifndef _AST_H
#if !defined(__PROTO__)
#include <prototyped.h>
#endif
#if !defined(__LINKAGE__)
#define __LINKAGE__		/* 2004-08-11 transition */
#endif

#define _AST_H

#ifndef _AST_STD_H
#include <ast_std.h>
#endif

#ifndef _SFIO_H
#include <sfio.h>
#endif

#ifndef	ast
#define ast		_ast_info
#endif

#ifndef PATH_MAX
#define PATH_MAX	1024
#endif

/*
 * workaround botched headers that assume <stdio.h>
 */

#ifndef FILE
#ifndef _SFIO_H
struct _sfio_s;
#endif
#define FILE		struct _sfio_s
#ifndef	__FILE_typedef
#define __FILE_typedef	1
#endif
#ifndef	_FILE_DEFINED
#define _FILE_DEFINED   1
#endif
#ifndef	_FILE_defined
#define _FILE_defined   1
#endif
#ifndef _FILEDEFED
#define _FILEDEFED	1
#endif
#ifndef __FILE_defined
#define __FILE_defined  1
#endif
#ifndef ____FILE_defined
#define ____FILE_defined  1
#endif
#endif

/*
 * tcc on FreeBSD: Avoid using nonexistent math
 * builtins by pretending to be an ancient gcc.
 */
#if __TINYC__ && __GNUC__ >= 3 && __FreeBSD__
#undef __GNUC__
#undef __GNUC_MINOR__
#undef __GNUC_PATCHLEVEL__
#define __GNUC__ 2
#define __GNUC_MINOR__ 95
#define __GNUC_PATCHLEVEL__ 3
#endif

/*
 * exit() support -- this matches shell exit codes
 */

#define EXIT_BITS	8	/* # exit status bits	*/

#define EXIT_USAGE	2	/* usage exit code	*/
#define EXIT_QUIT	255	/* parent should quit	*/
#define EXIT_NOTFOUND	127	/* command not found	*/
#define EXIT_NOEXEC	126	/* other exec error	*/

#define EXIT_CODE(x)	((x) & EXIT_QUIT)
#define EXIT_CORE(x)	(EXIT_CODE(x) | 256 | 128)
#define EXIT_TERM(x)	(EXIT_CODE(x) | 256)

#define EXIT_STATUS(x)	(((x) & 63) ? (x) : EXIT_CODE((x) >> 8))
#define EXITED_CORE(x)	(((x) & (256 | 128)) == (256 | 128) || ((x) & (128 | 64)) == (128 | 64))
#define EXITED_TERM(x)	((x) & (256 | 128))

/*
 * astconflist() flags
 */

#define ASTCONF_parse		0x0001
#define ASTCONF_write		0x0002
#define ASTCONF_read		0x0004
#define ASTCONF_lower		0x0008
#define ASTCONF_base		0x0010
#define ASTCONF_defined		0x0020
#define ASTCONF_quote		0x0040
#define ASTCONF_table		0x0080
#define ASTCONF_matchcall	0x0100
#define ASTCONF_matchname	0x0200
#define ASTCONF_matchstandard	0x0400
#define ASTCONF_error		0x0800
#define ASTCONF_system		0x1000
#define ASTCONF_AST		0x2000

/*
 * pathcanon() flags
 */

#define PATH_PHYSICAL	01
#define PATH_DOTDOT	02
#define PATH_EXISTS	04
#define PATH_VERIFIED(n) (((n)&01777)<<5)

/*
 * pathaccess() flags
 */

#define PATH_READ	004
#define PATH_WRITE	002
#define PATH_EXECUTE	001
#define	PATH_REGULAR	010
#define PATH_ABSOLUTE	020

/*
 * touch() flags
 */

#define PATH_TOUCH_CREATE	01
#define PATH_TOUCH_VERBATIM	02

/*
 * pathcheck() info
 */

typedef struct
{
	unsigned long	date;
	char*		feature;
	char*		host;
	char*		user;
} Pathcheck_t;

/*
 * strgrpmatch() flags
 */

#define STR_MAXIMAL	01		/* maximal match		*/
#define STR_LEFT	02		/* implicit left anchor		*/
#define STR_RIGHT	04		/* implicit right anchor	*/
#define STR_ICASE	010		/* ignore case			*/
#define STR_GROUP	020		/* (|&) inside [@|&](...) only	*/

/*
 * fmtquote() flags
 */

#define FMT_ALWAYS	0x01		/* always quote			*/
#define FMT_ESCAPED	0x02		/* already escaped		*/
#define FMT_SHELL	0x04		/* escape $ ` too		*/
#define FMT_WIDE	0x08		/* don't escape 8-bit chars	*/
#define FMT_PARAM	0x10		/* disable FMT_SHELL ${$( quote	*/

/*
 * chrexp() flags
 */

#define FMT_EXP_CHAR	0x020		/* expand single byte chars	*/
#define FMT_EXP_LINE	0x040		/* expand \n and \r		*/
#define FMT_EXP_WIDE	0x080		/* expand \u \U \x wide chars	*/
#define FMT_EXP_NOCR	0x100		/* skip \r			*/
#define FMT_EXP_NONL	0x200		/* skip \n			*/

/*
 * Define inline as an empty macro if we are
 * compiling with C89.
 */
#if __STDC_VERSION__ < 199901L
#define inline
#endif

/*
 * multibyte macros
 */

#define mbmax()		(ast.mb_cur_max)
#define mberr()		(ast.tmp_int<0)

#define mbcoll()	(ast.mb_xfrm!=0)
#define mbwide()	(mbmax()>1)

#define mb2wc(w,p,n)	(*ast.mb_towc)(&w,(char*)p,n)
#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++)))
#define mbnchar(p,n)	(mbwide()?((ast.tmp_int=(*ast.mb_towc)(&ast.tmp_wchar,(char*)(p),n))>0?((p+=ast.tmp_int),ast.tmp_wchar):(p+=ast.mb_sync+1,ast.tmp_int)):(*(unsigned char*)(p++)))
#define mbinit()	(mbwide()?(*ast.mb_towc)((wchar_t*)0,(char*)0,mbmax()):0)
#define mbsize(p)	(mbwide()?(*ast.mb_len)((char*)(p),mbmax()):((p),1))
#define mbnsize(p,n)	(mbwide()?(*ast.mb_len)((char*)(p),n):((p),1))
#define mbconv(s,w)	(ast.mb_conv?(*ast.mb_conv)(s,w):((*(s)=(w)),1))
#define mbwidth(w)	(ast.mb_width?(*ast.mb_width)(w):1)
#define mbxfrm(t,f,n)	(mbcoll()?(*ast.mb_xfrm)((char*)(t),(char*)(f),n):0)
#define mbalpha(w)	(ast.mb_alpha?(*ast.mb_alpha)(w):isalpha((w)&0xff))

/*
 * common macros
 */

#define elementsof(x)	(sizeof(x)/sizeof(x[0]))
#define integralof(x)	(((char*)(x))-((char*)0))
#define newof(p,t,n,x)	((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)calloc(1,sizeof(t)*(n)+(x)))
#define oldof(p,t,n,x)	((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)malloc(sizeof(t)*(n)+(x)))
#define pointerof(x)	((__V_*)((char*)0+(x)))
#define roundof(x,y)	(((x)+(y)-1)&~((y)-1))
#define ssizeof(x)	((int)sizeof(x))

#define streq(a,b)	(*(a)==*(b)&&!strcmp(a,b))
#define strneq(a,b,n)	(*(a)==*(b)&&!strncmp(a,b,n))
#define strsignal(s)	fmtsignal(s)

#if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
#define NiL		0
#define NoP(x)		do (void)(x); while(0)	/* for silencing "unused parameter" warnings */
#else
#define NiL		((char*)0)
#define NoP(x)		(&x,1)
#endif

#if !defined(NoF)
#if defined(__STDC__) || defined(__STDPP__)
#define NoF(x)		void _DATA_ ## x () {}
#else
#define NoF(x)		void _DATA_/**/x () {}
#endif
#if !defined(_DATA_)
#define _DATA_
#endif
#endif

#if !defined(NoN)
#if defined(__STDC__) || defined(__STDPP__)
#define NoN(x)		void _STUB_ ## x () {}
#else
#define NoN(x)		void _STUB_/**/x () {}
#endif
#if !defined(_STUB_)
#define _STUB_
#endif
#endif

#define NOT_USED(x)	NoP(x)

typedef int (*Error_f) __PROTO__((__V_*, __V_*, int, ...));

typedef int (*Ast_confdisc_f) __PROTO__((const char*, const char*, const char*));
typedef int (*Strcmp_context_f) __PROTO__((const char*, const char*, __V_*));
typedef int (*Strcmp_f) __PROTO__((const char*, const char*));

#if _BLD_ast && defined(__EXPORT__)
#undef __MANGLE__
#define __MANGLE__ __LINKAGE__		__EXPORT__
#endif

extern __MANGLE__ char*		astgetconf __PROTO__((const char*, const char*, const char*, int, Error_f));
extern __MANGLE__ char*		astconf __PROTO__((const char*, const char*, const char*));
extern __MANGLE__ Ast_confdisc_f	astconfdisc __PROTO__((Ast_confdisc_f));
extern __MANGLE__ void		astconflist __PROTO__((Sfio_t*, const char*, int, const char*));
extern __MANGLE__ off_t		astcopy __PROTO__((int, int, off_t));
extern __MANGLE__ int		astquery __PROTO__((int, const char*, ...));
extern __MANGLE__ void		astwinsize __PROTO__((int, int*, int*));
#if _lib_sysconf
/* prefer sysconf for astconf_long and astconf_ulong to improve performance */
#define CONF_ARG_MAX		_SC_ARG_MAX
#define CONF_CHILD_MAX		_SC_CHILD_MAX
#define CONF_CLK_TCK		_SC_CLK_TCK
#define CONF_NGROUPS_MAX	_SC_NGROUPS_MAX
#define CONF_OPEN_MAX		_SC_OPEN_MAX
#define CONF_PAGESIZE		_SC_PAGESIZE
#define astconf_long(x)		sysconf(x)
#define astconf_ulong(x)	(unsigned long)sysconf(x)
#else
/* fallback in case sysconf isn't available */
#define CONF_ARG_MAX		"ARG_MAX"
#define CONF_CHILD_MAX		"CHILD_MAX"
#define CONF_CLK_TCK		"CLK_TCK"
#define CONF_NGROUPS_MAX	"NGROUPS_MAX"
#define CONF_OPEN_MAX		"OPEN_MAX"
#define CONF_PAGESIZE		"PAGESIZE"
#define astconf_long(x)		strtol(astconf(x,NiL,NiL),NiL,0)
#define astconf_ulong(x)	strtoul(astconf(x,NiL,NiL),NiL,0)
#endif

extern __MANGLE__ ssize_t		base64encode __PROTO__((const __V_*, size_t, __V_**, __V_*, size_t, __V_**));
extern __MANGLE__ ssize_t		base64decode __PROTO__((const __V_*, size_t, __V_**, __V_*, size_t, __V_**));
extern __MANGLE__ int		chresc __PROTO__((const char*, char**));
extern __MANGLE__ int		chrexp __PROTO__((const char*, char**, int*, int));
extern __MANGLE__ int		chrtoi __PROTO__((const char*));
extern __MANGLE__ char*		conformance __PROTO__((const char*, size_t));
extern __MANGLE__ int		eaccess __PROTO__((const char*, int));
extern __MANGLE__ char*		fmtbase __PROTO__((intmax_t, int, int));
#define fmtbasell(a,b,c) fmtbase(a,b,c) /* until 2014-01-01 */
extern __MANGLE__ char*		fmtbuf __PROTO__((size_t));
extern __MANGLE__ char*		fmtclock __PROTO__((Sfulong_t));
extern __MANGLE__ char*		fmtelapsed __PROTO__((unsigned long, int));
extern __MANGLE__ char*		fmterror __PROTO__((int));
extern __MANGLE__ char*		fmtesc __PROTO__((const char*));
extern __MANGLE__ char*		fmtesq __PROTO__((const char*, const char*));
extern __MANGLE__ char*		fmtident __PROTO__((const char*));
extern __MANGLE__ char*		fmtip4 __PROTO__((uint32_t, int));
extern __MANGLE__ char*		fmtfmt __PROTO__((const char*));
extern __MANGLE__ char*		fmtgid __PROTO__((int));
extern __MANGLE__ char*		fmtint __PROTO__((intmax_t, int));
extern __MANGLE__ char*		fmtmatch __PROTO__((const char*));
extern __MANGLE__ char*		fmtmode __PROTO__((int, int));
extern __MANGLE__ char*		fmtnesq __PROTO__((const char*, const char*, size_t));
extern __MANGLE__ char*		fmtnum __PROTO__((unsigned long, int));
extern __MANGLE__ char*		fmtperm __PROTO__((int));
extern __MANGLE__ char*		fmtquote __PROTO__((const char*, const char*, const char*, size_t, int));
extern __MANGLE__ char*		fmtre __PROTO__((const char*));
extern __MANGLE__ char*		fmtscale __PROTO__((Sfulong_t, int));
extern __MANGLE__ char*		fmtsignal __PROTO__((int));
extern __MANGLE__ char*		fmttime __PROTO__((const char*, time_t));
extern __MANGLE__ char*		fmtuid __PROTO__((int));
extern __MANGLE__ char*		fmtversion __PROTO__((unsigned long));
extern __MANGLE__ __V_*		memdup __PROTO__((const __V_*, size_t));
extern __MANGLE__ void		memfatal __PROTO__((void));
extern __MANGLE__ unsigned int	memhash __PROTO__((const __V_*, int));
extern __MANGLE__ unsigned long	memsum __PROTO__((const __V_*, int, unsigned long));
extern __MANGLE__ char*		pathaccess __PROTO__((char*, const char*, const char*, const char*, int));
extern __MANGLE__ char*		pathaccess_20100601 __PROTO__((const char*, const char*, const char*, int, char*, size_t));
extern __MANGLE__ char*		pathbin __PROTO__((void));
extern __MANGLE__ char*		pathcanon __PROTO__((char*, int));
extern __MANGLE__ char*		pathcanon_20100601 __PROTO__((char*, size_t, int));
extern __MANGLE__ char*		pathcat __PROTO__((char*, const char*, int, const char*, const char*));
extern __MANGLE__ char*		pathcat_20100601 __PROTO__((const char*, int, const char*, const char*, char*, size_t));
extern __MANGLE__ int		pathcd __PROTO__((const char*, const char*));
extern __MANGLE__ int		pathcheck __PROTO__((const char*, const char*, Pathcheck_t*));
extern __MANGLE__ int		pathexists __PROTO__((char*, int));
extern __MANGLE__ char*		pathfind __PROTO__((const char*, const char*, const char*, char*, size_t));
extern __MANGLE__ int		pathgetlink __PROTO__((const char*, char*, int));
extern __MANGLE__ int		pathicase __PROTO__((const char*));
extern __MANGLE__ int		pathinclude __PROTO__((const char*));
extern __MANGLE__ char*		pathkey __PROTO__((char*, char*, const char*, const char*, const char*));
extern __MANGLE__ char*		pathkey_20100601 __PROTO__((const char*, const char*, const char*, char*, size_t, char*, size_t));
extern __MANGLE__ size_t		pathnative __PROTO__((const char*, char*, size_t));
extern __MANGLE__ char*		pathpath __PROTO__((char*, const char*, const char*, int));
extern __MANGLE__ char*		pathpath_20100601 __PROTO__((const char*, const char*, int, char*, size_t));
extern __MANGLE__ size_t		pathposix __PROTO__((const char*, char*, size_t));
extern __MANGLE__ char*		pathprobe __PROTO__((char*, char*, const char*, const char*, const char*, int));
extern __MANGLE__ char*		pathprobe_20100601 __PROTO__((const char*, const char*, const char*, int, char*, size_t, char*, size_t));
extern __MANGLE__ size_t		pathprog __PROTO__((const char*, char*, size_t));
extern __MANGLE__ char*		pathrepl __PROTO__((char*, const char*, const char*));
extern __MANGLE__ char*		pathrepl_20100601 __PROTO__((char*, size_t, const char*, const char*));
extern __MANGLE__ int		pathsetlink __PROTO__((const char*, const char*));
extern __MANGLE__ char*		pathshell __PROTO__((void));
extern __MANGLE__ char*		pathtemp __PROTO__((char*, size_t, const char*, const char*, int*));
extern __MANGLE__ char*		pathtmp __PROTO__((char*, const char*, const char*, int*));
extern __MANGLE__ char*		setenviron __PROTO__((const char*));
extern __MANGLE__ int		stracmp __PROTO__((const char*, const char*));
extern __MANGLE__ char*		strcopy __PROTO__((char*, const char*));
extern __MANGLE__ unsigned long	strelapsed __PROTO__((const char*, char**, int));
extern __MANGLE__ int		stresc __PROTO__((char*));
extern __MANGLE__ int		strexp __PROTO__((char*, int));
extern __MANGLE__ long		streval __PROTO__((const char*, char**, long(*)(const char*, char**)));
extern __MANGLE__ long		strexpr __PROTO__((const char*, char**, long(*)(const char*, char**, __V_*), __V_*));
extern __MANGLE__ int		strgid __PROTO__((const char*));
extern __MANGLE__ int		strgrpmatch __PROTO__((const char*, const char*, int*, int, int));
extern __MANGLE__ int		strgrpmatch_20120528 __PROTO__((const char*, const char*, ssize_t*, int, int));
extern __MANGLE__ unsigned int	strhash __PROTO__((const char*));
extern __MANGLE__ __V_*		strlook __PROTO__((const __V_*, size_t, const char*));
extern __MANGLE__ int		strmatch __PROTO__((const char*, const char*));
extern __MANGLE__ int		strmode __PROTO__((const char*));
extern __MANGLE__ int		strnacmp __PROTO__((const char*, const char*, size_t));
extern __MANGLE__ char*		strncopy __PROTO__((char*, const char*, size_t));
extern __MANGLE__ int		strnpcmp __PROTO__((const char*, const char*, size_t));
extern __MANGLE__ double		strntod __PROTO__((const char*, size_t, char**));
extern __MANGLE__ _ast_fltmax_t	strntold __PROTO__((const char*, size_t, char**));
extern __MANGLE__ long		strntol __PROTO__((const char*, size_t, char**, int));
extern __MANGLE__ intmax_t		strntoll __PROTO__((const char*, size_t, char**, int));
extern __MANGLE__ long		strnton __PROTO__((const char*, size_t, char**, char*, int));
extern __MANGLE__ unsigned long	strntoul __PROTO__((const char*, size_t, char**, int));
extern __MANGLE__ intmax_t		strntonll __PROTO__((const char*, size_t, char**, char*, int));
extern __MANGLE__ uintmax_t	strntoull __PROTO__((const char*, size_t, char**, int));
extern __MANGLE__ int		strnvcmp __PROTO__((const char*, const char*, size_t));
extern __MANGLE__ int		stropt __PROTO__((const char*, const __V_*, int, int(*)(__V_*, const __V_*, int, const char*), __V_*));
extern __MANGLE__ int		strpcmp __PROTO__((const char*, const char*));
extern __MANGLE__ int		strperm __PROTO__((const char*, char**, int));
extern __MANGLE__ __V_*		strpsearch __PROTO__((const __V_*, size_t, size_t, const char*, char**));
extern __MANGLE__ __V_*		strsearch __PROTO__((const __V_*, size_t, size_t, Strcmp_f, const char*, __V_*));
extern __MANGLE__ void		strsort __PROTO__((char**, int, int(*)(const char*, const char*)));
extern __MANGLE__ char*		strsubmatch __PROTO__((const char*, const char*, int));
extern __MANGLE__ unsigned long	strsum __PROTO__((const char*, unsigned long));
extern __MANGLE__ char*		strtape __PROTO__((const char*, char**));
extern __MANGLE__ int		strtoip4 __PROTO__((const char*, char**, uint32_t*, unsigned char*));
extern __MANGLE__ long		strton __PROTO__((const char*, char**, char*, int));
extern __MANGLE__ intmax_t		strtonll __PROTO__((const char*, char**, char*, int));
extern __MANGLE__ int		struid __PROTO__((const char*));
extern __MANGLE__ int		struniq __PROTO__((char**, int));
extern __MANGLE__ int		strvcmp __PROTO__((const char*, const char*));
extern __MANGLE__ int		wc2utf8 __PROTO__((char*, uint32_t));

#undef __MANGLE__
#define __MANGLE__ __LINKAGE__

/*
 * C library global data symbols not prototyped by <unistd.h>
 */

#if !defined(environ) && defined(__DYNAMIC__)
#define	environ		__DYNAMIC__(environ)
#else
extern __MANGLE__ char**		environ;
#endif

/*
 * really handy malloc()/free() (__FILE__,__LINE__,__FUNCTION__) tracing
 * make with VMDEBUG==1 or debug=1 or CCFLAGS=$(CC.DEBUG)
 * VMDEBUG==0 disables
 * at runtime export VMALLOC_OPTIONS per vmalloc.3
 * to list originating call locations
 */

#if !_std_malloc && !defined(VMFL) && !defined(_VMHDR_H) && \
	(VMDEBUG || !defined(VMDEBUG) && _BLD_DEBUG)

#define VMFL	1
#include <vmalloc.h>

#endif

#include <ast_api.h>

#undef	AST_PLUGIN_VERSION
#define AST_PLUGIN_VERSION(v)	((v)>AST_VERSION?(v):AST_VERSION)

#if defined(__EXPORT__)
#undef __MANGLE__
#define __MANGLE__ __LINKAGE__		__EXPORT__
#endif

extern __MANGLE__ unsigned long	plugin_version __PROTO__((void));

#undef __MANGLE__
#define __MANGLE__ __LINKAGE__

#endif
