ast.h revision 1
1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* Phong Vo <kpv@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A/*
1N/A * Advanced Software Technology Library
1N/A * AT&T Research
1N/A *
1N/A * std + posix + ast
1N/A */
1N/A
1N/A#ifndef _AST_H
1N/A#define _AST_H
1N/A
1N/A#ifndef _AST_STD_H
1N/A#include <ast_std.h>
1N/A#endif
1N/A
1N/A#ifndef _SFIO_H
1N/A#include <sfio.h>
1N/A#endif
1N/A
1N/A#ifndef ast
1N/A#define ast _ast_info
1N/A#endif
1N/A
1N/A#ifndef PATH_MAX
1N/A#define PATH_MAX 1024
1N/A#endif
1N/A
1N/A/*
1N/A * workaround botched headers that assume <stdio.h>
1N/A */
1N/A
1N/A#ifndef FILE
1N/A#ifndef _SFIO_H
1N/Astruct _sfio_s;
1N/A#endif
1N/A#define FILE struct _sfio_s
1N/A#ifndef __FILE_typedef
1N/A#define __FILE_typedef 1
1N/A#endif
1N/A#ifndef _FILEDEFED
1N/A#define _FILEDEFED 1
1N/A#endif
1N/A#endif
1N/A
1N/A/*
1N/A * exit() support -- this matches shell exit codes
1N/A */
1N/A
1N/A#define EXIT_BITS 8 /* # exit status bits */
1N/A
1N/A#define EXIT_USAGE 2 /* usage exit code */
1N/A#define EXIT_QUIT ((1<<(EXIT_BITS))-1) /* parent should quit */
1N/A#define EXIT_NOTFOUND ((1<<(EXIT_BITS-1))-1) /* command not found */
1N/A#define EXIT_NOEXEC ((1<<(EXIT_BITS-1))-2) /* other exec error */
1N/A
1N/A#define EXIT_CODE(x) ((x)&((1<<EXIT_BITS)-1))
1N/A#define EXIT_CORE(x) (EXIT_CODE(x)|(1<<EXIT_BITS)|(1<<(EXIT_BITS-1)))
1N/A#define EXIT_TERM(x) (EXIT_CODE(x)|(1<<EXIT_BITS))
1N/A
1N/A/*
1N/A * NOTE: for compatibility the following work for EXIT_BITS={7,8}
1N/A */
1N/A
1N/A#define EXIT_STATUS(x) (((x)&((1<<(EXIT_BITS-2))-1))?(x):EXIT_CODE((x)>>EXIT_BITS))
1N/A
1N/A#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))))
1N/A#define EXITED_TERM(x) ((x)&((1<<EXIT_BITS)|(1<<(EXIT_BITS-1))))
1N/A
1N/A/*
1N/A * astconflist() flags
1N/A */
1N/A
1N/A#define ASTCONF_parse 0x0001
1N/A#define ASTCONF_write 0x0002
1N/A#define ASTCONF_read 0x0004
1N/A#define ASTCONF_lower 0x0008
1N/A#define ASTCONF_base 0x0010
1N/A#define ASTCONF_defined 0x0020
1N/A#define ASTCONF_quote 0x0040
1N/A#define ASTCONF_table 0x0080
1N/A#define ASTCONF_matchcall 0x0100
1N/A#define ASTCONF_matchname 0x0200
1N/A#define ASTCONF_matchstandard 0x0400
1N/A#define ASTCONF_error 0x0800
1N/A#define ASTCONF_system 0x1000
1N/A#define ASTCONF_AST 0x2000
1N/A
1N/A/*
1N/A * pathcanon() flags
1N/A */
1N/A
1N/A#define PATH_PHYSICAL 01
1N/A#define PATH_DOTDOT 02
1N/A#define PATH_EXISTS 04
1N/A#define PATH_VERIFIED(n) (((n)&01777)<<5)
1N/A
1N/A/*
1N/A * pathaccess() flags
1N/A */
1N/A
1N/A#define PATH_READ 004
1N/A#define PATH_WRITE 002
1N/A#define PATH_EXECUTE 001
1N/A#define PATH_REGULAR 010
1N/A#define PATH_ABSOLUTE 020
1N/A
1N/A/*
1N/A * touch() flags
1N/A */
1N/A
1N/A#define PATH_TOUCH_CREATE 01
1N/A#define PATH_TOUCH_VERBATIM 02
1N/A
1N/A/*
1N/A * pathcheck() info
1N/A */
1N/A
1N/Atypedef struct
1N/A{
1N/A unsigned long date;
1N/A char* feature;
1N/A char* host;
1N/A char* user;
1N/A} Pathcheck_t;
1N/A
1N/A/*
1N/A * strgrpmatch() flags
1N/A */
1N/A
1N/A#define STR_MAXIMAL 01 /* maximal match */
1N/A#define STR_LEFT 02 /* implicit left anchor */
1N/A#define STR_RIGHT 04 /* implicit right anchor */
1N/A#define STR_ICASE 010 /* ignore case */
1N/A#define STR_GROUP 020 /* (|&) inside [@|&](...) only */
1N/A
1N/A/*
1N/A * fmtquote() flags
1N/A */
1N/A
1N/A#define FMT_ALWAYS 0x01 /* always quote */
1N/A#define FMT_ESCAPED 0x02 /* already escaped */
1N/A#define FMT_SHELL 0x04 /* escape $ ` too */
1N/A#define FMT_WIDE 0x08 /* don't escape 8 bit chars */
1N/A#define FMT_PARAM 0x10 /* disable FMT_SHELL ${$( quote */
1N/A
1N/A/*
1N/A * chrexp() flags
1N/A */
1N/A
1N/A#define FMT_EXP_CHAR 0x020 /* expand single byte chars */
1N/A#define FMT_EXP_LINE 0x040 /* expand \n and \r */
1N/A#define FMT_EXP_WIDE 0x080 /* expand \u \U \x wide chars */
1N/A#define FMT_EXP_NOCR 0x100 /* skip \r */
1N/A#define FMT_EXP_NONL 0x200 /* skip \n */
1N/A
1N/A/*
1N/A * multibyte macros
1N/A */
1N/A
1N/A#define mbmax() (ast.mb_cur_max)
1N/A#define mberr() (ast.tmp_int<0)
1N/A
1N/A#define mbcoll() (ast.mb_xfrm!=0)
1N/A#define mbwide() (mbmax()>1)
1N/A
1N/A#define mb2wc(w,p,n) (*ast.mb_towc)(&w,(char*)p,n)
1N/A#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++)))
1N/A#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++)))
1N/A#define mbinit() (mbwide()?(*ast.mb_towc)((wchar_t*)0,(char*)0,mbmax()):0)
1N/A#define mbsize(p) (mbwide()?(*ast.mb_len)((char*)(p),mbmax()):((p),1))
1N/A#define mbnsize(p,n) (mbwide()?(*ast.mb_len)((char*)(p),n):((p),1))
1N/A#define mbconv(s,w) (ast.mb_conv?(*ast.mb_conv)(s,w):((*(s)=(w)),1))
1N/A#define mbwidth(w) (ast.mb_width?(*ast.mb_width)(w):1)
1N/A#define mbxfrm(t,f,n) (mbcoll()?(*ast.mb_xfrm)((char*)(t),(char*)(f),n):0)
1N/A#define mbalpha(w) (ast.mb_alpha?(*ast.mb_alpha)(w):isalpha((w)&0xff))
1N/A
1N/A/*
1N/A * common macros
1N/A */
1N/A
1N/A#define elementsof(x) (sizeof(x)/sizeof(x[0]))
1N/A#define integralof(x) (((char*)(x))-((char*)0))
1N/A#define newof(p,t,n,x) ((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)calloc(1,sizeof(t)*(n)+(x)))
1N/A#define oldof(p,t,n,x) ((p)?(t*)realloc((char*)(p),sizeof(t)*(n)+(x)):(t*)malloc(sizeof(t)*(n)+(x)))
1N/A#define pointerof(x) ((void*)((char*)0+(x)))
1N/A#define roundof(x,y) (((x)+(y)-1)&~((y)-1))
1N/A#define ssizeof(x) ((int)sizeof(x))
1N/A
1N/A#define streq(a,b) (*(a)==*(b)&&!strcmp(a,b))
1N/A#define strneq(a,b,n) (*(a)==*(b)&&!strncmp(a,b,n))
1N/A#define strsignal(s) fmtsignal(s)
1N/A
1N/A#if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
1N/A#define NiL 0
1N/A#define NoP(x) (void)(x)
1N/A#else
1N/A#define NiL ((char*)0)
1N/A#define NoP(x) (&x,1)
1N/A#endif
1N/A
1N/A#if !defined(NoF)
1N/A#define NoF(x) void _DATA_ ## x () {}
1N/A#if !defined(_DATA_)
1N/A#define _DATA_
1N/A#endif
1N/A#endif
1N/A
1N/A#if !defined(NoN)
1N/A#define NoN(x) void _STUB_ ## x () {}
1N/A#if !defined(_STUB_)
1N/A#define _STUB_
1N/A#endif
1N/A#endif
1N/A
1N/A#define NOT_USED(x) NoP(x)
1N/A
1N/Atypedef int (*Error_f)(void*, void*, int, ...);
1N/A
1N/Atypedef int (*Ast_confdisc_f)(const char*, const char*, const char*);
1N/Atypedef int (*Strcmp_context_f)(const char*, const char*, void*);
1N/Atypedef int (*Strcmp_f)(const char*, const char*);
1N/A
1N/A#if _BLD_ast && defined(__EXPORT__)
1N/A#define extern __EXPORT__
1N/A#endif
1N/A
1N/Aextern char* astgetconf(const char*, const char*, const char*, int, Error_f);
1N/Aextern char* astconf(const char*, const char*, const char*);
1N/Aextern Ast_confdisc_f astconfdisc(Ast_confdisc_f);
1N/Aextern void astconflist(Sfio_t*, const char*, int, const char*);
1N/Aextern off_t astcopy(int, int, off_t);
1N/Aextern int astlicense(char*, int, char*, char*, int, int, int);
1N/Aextern int astquery(int, const char*, ...);
1N/Aextern void astwinsize(int, int*, int*);
1N/A
1N/Aextern ssize_t base64encode(const void*, size_t, void**, void*, size_t, void**);
1N/Aextern ssize_t base64decode(const void*, size_t, void**, void*, size_t, void**);
1N/Aextern int chresc(const char*, char**);
1N/Aextern int chrexp(const char*, char**, int*, int);
1N/Aextern int chrtoi(const char*);
1N/Aextern char* conformance(const char*, size_t);
1N/Aextern int eaccess(const char*, int);
1N/Aextern char* fmtbase(intmax_t, int, int);
1N/A#define fmtbasell(a,b,c) fmtbase(a,b,c) /* until 2014-01-01 */
1N/Aextern char* fmtbuf(size_t);
1N/Aextern char* fmtclock(Sfulong_t);
1N/Aextern char* fmtelapsed(unsigned long, int);
1N/Aextern char* fmterror(int);
1N/Aextern char* fmtesc(const char*);
1N/Aextern char* fmtesq(const char*, const char*);
1N/Aextern char* fmtident(const char*);
1N/Aextern char* fmtip4(uint32_t, int);
1N/Aextern char* fmtfmt(const char*);
1N/Aextern char* fmtgid(int);
1N/Aextern char* fmtint(intmax_t, int);
1N/Aextern char* fmtmatch(const char*);
1N/Aextern char* fmtmode(int, int);
1N/Aextern char* fmtnesq(const char*, const char*, size_t);
1N/Aextern char* fmtnum(unsigned long, int);
1N/Aextern char* fmtperm(int);
1N/Aextern char* fmtquote(const char*, const char*, const char*, size_t, int);
1N/Aextern char* fmtre(const char*);
1N/Aextern char* fmtscale(Sfulong_t, int);
1N/Aextern char* fmtsignal(int);
1N/Aextern char* fmttime(const char*, time_t);
1N/Aextern char* fmtuid(int);
1N/Aextern char* fmtversion(unsigned long);
1N/Aextern void* memdup(const void*, size_t);
1N/Aextern void memfatal(void);
1N/Aextern unsigned int memhash(const void*, int);
1N/Aextern unsigned long memsum(const void*, int, unsigned long);
1N/Aextern char* pathaccess(char*, const char*, const char*, const char*, int);
1N/Aextern char* pathaccess_20100601(const char*, const char*, const char*, int, char*, size_t);
1N/Aextern char* pathbin(void);
1N/Aextern char* pathcanon(char*, int);
1N/Aextern char* pathcanon_20100601(char*, size_t, int);
1N/Aextern char* pathcat(char*, const char*, int, const char*, const char*);
1N/Aextern char* pathcat_20100601(const char*, int, const char*, const char*, char*, size_t);
1N/Aextern int pathcd(const char*, const char*);
1N/Aextern int pathcheck(const char*, const char*, Pathcheck_t*);
1N/Aextern int pathexists(char*, int);
1N/Aextern char* pathfind(const char*, const char*, const char*, char*, size_t);
1N/Aextern int pathgetlink(const char*, char*, int);
1N/Aextern int pathinclude(const char*);
1N/Aextern char* pathkey(char*, char*, const char*, const char*, const char*);
1N/Aextern char* pathkey_20100601(const char*, const char*, const char*, char*, size_t, char*, size_t);
1N/Aextern size_t pathnative(const char*, char*, size_t);
1N/Aextern char* pathpath(char*, const char*, const char*, int);
1N/Aextern char* pathpath_20100601(const char*, const char*, int, char*, size_t);
1N/Aextern size_t pathposix(const char*, char*, size_t);
1N/Aextern char* pathprobe(char*, char*, const char*, const char*, const char*, int);
1N/Aextern char* pathprobe_20100601(const char*, const char*, const char*, int, char*, size_t, char*, size_t);
1N/Aextern size_t pathprog(const char*, char*, size_t);
1N/Aextern char* pathrepl(char*, const char*, const char*);
1N/Aextern char* pathrepl_20100601(char*, size_t, const char*, const char*);
1N/Aextern int pathsetlink(const char*, const char*);
1N/Aextern char* pathshell(void);
1N/Aextern char* pathtemp(char*, size_t, const char*, const char*, int*);
1N/Aextern char* pathtmp(char*, const char*, const char*, int*);
1N/Aextern char* setenviron(const char*);
1N/Aextern int stracmp(const char*, const char*);
1N/Aextern char* strcopy(char*, const char*);
1N/Aextern unsigned long strelapsed(const char*, char**, int);
1N/Aextern int stresc(char*);
1N/Aextern int strexp(char*, int);
1N/Aextern long streval(const char*, char**, long(*)(const char*, char**));
1N/Aextern long strexpr(const char*, char**, long(*)(const char*, char**, void*), void*);
1N/Aextern int strgid(const char*);
1N/Aextern int strgrpmatch(const char*, const char*, int*, int, int);
1N/Aextern unsigned int strhash(const char*);
1N/Aextern void* strlook(const void*, size_t, const char*);
1N/Aextern int strmatch(const char*, const char*);
1N/Aextern int strmode(const char*);
1N/Aextern int strnacmp(const char*, const char*, size_t);
1N/Aextern char* strncopy(char*, const char*, size_t);
1N/Aextern int strnpcmp(const char*, const char*, size_t);
1N/Aextern double strntod(const char*, size_t, char**);
1N/Aextern _ast_fltmax_t strntold(const char*, size_t, char**);
1N/Aextern long strntol(const char*, size_t, char**, int);
1N/Aextern intmax_t strntoll(const char*, size_t, char**, int);
1N/Aextern long strnton(const char*, size_t, char**, char*, int);
1N/Aextern unsigned long strntoul(const char*, size_t, char**, int);
1N/Aextern intmax_t strntonll(const char*, size_t, char**, char*, int);
1N/Aextern uintmax_t strntoull(const char*, size_t, char**, int);
1N/Aextern int strnvcmp(const char*, const char*, size_t);
1N/Aextern int stropt(const char*, const void*, int, int(*)(void*, const void*, int, const char*), void*);
1N/Aextern int strpcmp(const char*, const char*);
1N/Aextern int strperm(const char*, char**, int);
1N/Aextern void* strpsearch(const void*, size_t, size_t, const char*, char**);
1N/Aextern void* strsearch(const void*, size_t, size_t, Strcmp_f, const char*, void*);
1N/Aextern void strsort(char**, int, int(*)(const char*, const char*));
1N/Aextern char* strsubmatch(const char*, const char*, int);
1N/Aextern unsigned long strsum(const char*, unsigned long);
1N/Aextern char* strtape(const char*, char**);
1N/Aextern int strtoip4(const char*, char**, uint32_t*, unsigned char*);
1N/Aextern long strton(const char*, char**, char*, int);
1N/Aextern intmax_t strtonll(const char*, char**, char*, int);
1N/Aextern int struid(const char*);
1N/Aextern int struniq(char**, int);
1N/Aextern int strvcmp(const char*, const char*);
1N/Aextern int wc2utf8(char*, uint32_t);
1N/A
1N/A#undef extern
1N/A
1N/A/*
1N/A * C library global data symbols not prototyped by <unistd.h>
1N/A */
1N/A
1N/A#if !defined(environ) && defined(__DYNAMIC__)
1N/A#define environ __DYNAMIC__(environ)
1N/A#else
1N/Aextern char** environ;
1N/A#endif
1N/A
1N/A/*
1N/A * really handy malloc()/free() (__FILE__,__LINE__,__FUNCTION__) tracing
1N/A * make with VMDEBUG==1 or debug=1 or CCFLAGS=$(CC.DEBUG)
1N/A * VMDEBUG==0 disables
1N/A * at runtime export VMALLOC_OPTIONS per vmalloc.3
1N/A * to list originating call locations
1N/A */
1N/A
1N/A#if !_std_malloc && !defined(VMFL) && !defined(_VMHDR_H) && \
1N/A (VMDEBUG || !defined(VMDEBUG) && _BLD_DEBUG)
1N/A
1N/A#define VMFL 1
1N/A#include <vmalloc.h>
1N/A
1N/A#endif
1N/A
1N/A#include <ast_api.h>
1N/A
1N/A#define AST_PLUGIN_VERSION(v) ((v)>AST_VERSION?(v):AST_VERSION)
1N/A
1N/A#if defined(__EXPORT__)
1N/A#define extern __EXPORT__
1N/A#endif
1N/A
1N/Aextern unsigned long plugin_version(void);
1N/A
1N/A#undef extern
1N/A
1N/A#endif