summaryrefslogtreecommitdiff
path: root/src/lib/libast/astsa
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2012-06-24 22:28:35 +0000
committerIgor Pashev <pashev.igor@gmail.com>2012-06-24 22:28:35 +0000
commit3950ffe2a485479f6561c27364d3d7df5a21d124 (patch)
tree468c6e14449d1b1e279222ec32f676b0311917d2 /src/lib/libast/astsa
downloadksh-upstream.tar.gz
Imported Upstream version 93u+upstream
Diffstat (limited to 'src/lib/libast/astsa')
-rw-r--r--src/lib/libast/astsa/README-astsa15
-rw-r--r--src/lib/libast/astsa/aso.c56
-rw-r--r--src/lib/libast/astsa/aso.h32
-rw-r--r--src/lib/libast/astsa/ast.c85
-rw-r--r--src/lib/libast/astsa/ast.h156
-rw-r--r--src/lib/libast/astsa/ast_common.h49
-rw-r--r--src/lib/libast/astsa/astsa.manifest50
-rw-r--r--src/lib/libast/astsa/astsa.mm33
-rw-r--r--src/lib/libast/astsa/astsa.omk82
-rw-r--r--src/lib/libast/astsa/ccode.h34
-rw-r--r--src/lib/libast/astsa/debug.h29
-rw-r--r--src/lib/libast/astsa/error.c103
-rw-r--r--src/lib/libast/astsa/error.h66
-rw-r--r--src/lib/libast/astsa/hashkey.h61
-rwxr-xr-xsrc/lib/libast/astsa/mkast_sa150
-rw-r--r--src/lib/libast/astsa/option.h106
-rw-r--r--src/lib/libast/astsa/optlib.h105
-rw-r--r--src/lib/libast/astsa/sfstr.c246
-rw-r--r--src/lib/libast/astsa/sfstr.h60
-rw-r--r--src/lib/libast/astsa/strdup.c37
-rw-r--r--src/lib/libast/astsa/strmatch.c597
-rw-r--r--src/lib/libast/astsa/times.h27
-rw-r--r--src/lib/libast/astsa/vmalloc.c102
-rw-r--r--src/lib/libast/astsa/vmalloc.h61
24 files changed, 2342 insertions, 0 deletions
diff --git a/src/lib/libast/astsa/README-astsa b/src/lib/libast/astsa/README-astsa
new file mode 100644
index 0000000..0935f7e
--- /dev/null
+++ b/src/lib/libast/astsa/README-astsa
@@ -0,0 +1,15 @@
+astsa implements a small subset of the ast library for other ast
+standalone commands and libraries using X/Open interfaces.
+
+To get better performance and functionality, consider using any of
+the full-featured ast-* packages at
+
+ http://www.research.att.com/sw/download/
+
+astsa.omk is an old make makefile that builds the headers and objects
+and defines these variables for use in other makefiles
+
+ ASTSA_OPTIMIZE ``-O'' by default
+
+The astsa files may be combined in a single directory with other ast
+standalone packages.
diff --git a/src/lib/libast/astsa/aso.c b/src/lib/libast/astsa/aso.c
new file mode 100644
index 0000000..3b2226d
--- /dev/null
+++ b/src/lib/libast/astsa/aso.c
@@ -0,0 +1,56 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2012 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#pragma prototyped
+
+#include <aso.h>
+
+int
+asolock(unsigned int volatile* lock, unsigned int key, int type)
+{
+ unsigned int k;
+
+ if (key)
+ switch (type)
+ {
+ case ASO_UNLOCK:
+ if (*lock != 0)
+ {
+ if (*lock != key)
+ return -1;
+ *lock = 0;
+ }
+ return 0;
+ case ASO_TRYLOCK:
+ if (*lock != key)
+ {
+ if (*lock != 0)
+ return -1;
+ *lock = key;
+ }
+ return 0;
+ case ASO_LOCK:
+ case ASO_SPINLOCK:
+ *lock = key;
+ return 0;
+ }
+ return -1;
+}
diff --git a/src/lib/libast/astsa/aso.h b/src/lib/libast/astsa/aso.h
new file mode 100644
index 0000000..9c5d2c2
--- /dev/null
+++ b/src/lib/libast/astsa/aso.h
@@ -0,0 +1,32 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2012 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#ifndef _ASO_H
+#define _ASO_H 1
+
+#define ASO_UNLOCK 0 /* unlock if key matches */
+#define ASO_TRYLOCK 1 /* matched key means successful attempt */
+#define ASO_LOCK 2 /* matched key first, then spin-lock */
+#define ASO_SPINLOCK 3 /* no matching of key before locking */
+
+extern int asolock(unsigned int volatile*, unsigned int, int);
+
+#endif
diff --git a/src/lib/libast/astsa/ast.c b/src/lib/libast/astsa/ast.c
new file mode 100644
index 0000000..6428ebf
--- /dev/null
+++ b/src/lib/libast/astsa/ast.c
@@ -0,0 +1,85 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#pragma prototyped
+/*
+ * standalone mini ast+sfio implementation
+ */
+
+#include <ast.h>
+
+#define CHUNK 1024
+
+_Ast_info_t ast;
+
+int
+astwinsize(int fd, int* lines, int* columns)
+{
+ if (lines)
+ *lines = 24;
+ if (columns)
+ *columns = 80;
+ return 0;
+}
+
+char*
+sfgetr(Sfio_t* sp, int c, int z)
+{
+ register char* s;
+ register char* e;
+
+ static char* buf;
+ static unsigned long siz;
+
+ if (!buf)
+ {
+ siz = CHUNK;
+ if (!(buf = newof(0, char, siz, 0)))
+ return 0;
+ }
+ if (z < 0)
+ return *buf ? buf : (char*)0;
+ s = buf;
+ e = s + siz;
+ for (;;)
+ {
+ if (s >= e)
+ {
+ siz += CHUNK;
+ if (!(buf = newof(buf, char, siz, 0)))
+ return 0;
+ s = buf + (siz - CHUNK);
+ e = s + siz;
+ }
+ if ((c = sfgetc(sp)) == EOF)
+ {
+ *s = 0;
+ return 0;
+ }
+ if (c == '\n')
+ {
+ *s = z ? 0 : c;
+ break;
+ }
+ *s++ = c;
+ }
+ return buf;
+}
diff --git a/src/lib/libast/astsa/ast.h b/src/lib/libast/astsa/ast.h
new file mode 100644
index 0000000..f25f6a5
--- /dev/null
+++ b/src/lib/libast/astsa/ast.h
@@ -0,0 +1,156 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2012 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#pragma prototyped
+/*
+ * standalone mini ast+sfio interface
+ */
+
+#ifndef _AST_H
+#define _AST_H 1
+
+#include <ast_sa.h>
+#include <ast_common.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+
+#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 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 */
+
+typedef int (*Error_f)(void*, void*, int, ...);
+
+typedef struct
+{
+
+ char* id;
+
+ struct
+ {
+ unsigned int serial;
+ unsigned int set;
+ } locale;
+
+ long tmp_long;
+ size_t tmp_size;
+ short tmp_short;
+ char tmp_char;
+ wchar_t tmp_wchar;
+
+ int (*collate)(const char*, const char*);
+
+ int tmp_int;
+ void* tmp_pointer;
+
+ int mb_cur_max;
+ int (*mb_len)(const char*, size_t);
+ int (*mb_towc)(wchar_t*, const char*, size_t);
+ size_t (*mb_xfrm)(char*, const char*, size_t);
+ int (*mb_width)(wchar_t);
+ int (*mb_conv)(char*, wchar_t);
+
+ unsigned int env_serial;
+
+ char pad[944];
+
+} _Ast_info_t;
+
+#define ast _ast_info_
+
+#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) ((void*)((char*)0+(x)))
+#define roundof(x,y) (((x)+(y)-1)&~((y)-1))
+
+#ifndef offsetof
+#define offsetof(type,member) ((unsigned long)&(((type*)0)->member))
+#endif
+
+#if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus)
+#define NiL 0
+#define NoP(x) (void)(x)
+#else
+#define NiL ((char*)0)
+#define NoP(x) (&x,1)
+#endif
+
+#define conformance(a,b) "ast"
+#define fmtident(s) ((char*)(s)+10)
+#define mbchar(s) (*s++)
+#define setlocale(a,b)
+
+#define streq(a,b) (*(a)==*(b)&&!strcmp(a,b))
+#define strneq(a,b,n) (*(a)==*(b)&&!strncmp(a,b,n))
+#define strton(s,t,b,f) strtol(s,t,0)
+#define strtonll(s,t,b,f) strtoll(s,t,0)
+
+#define Sfio_t FILE
+
+#define sfstdin stdin
+#define sfstdout stdout
+#define sfstderr stderr
+
+#define sfclose(f) fclose(f)
+#define sffileno(f) fileno(f)
+#define sfgetc(f) fgetc(f)
+#define sfopen(f,n,m) fopen(n,m)
+#define sfputc(f,c) fputc(c,f)
+#define sfread(f,b,n) fread(b,n,1,f)
+#define sfseek(f,p,w) fseek(f,p,w)
+#define sfset(f,v,n)
+#define sfsync(f) fflush(f)
+#define sfwrite(f,b,n) fwrite(b,n,1,f)
+
+#define sfprintf fprintf
+#define sfsprintf snprintf
+#define sfvprintf vfprintf
+
+#define sfscanf fscanf
+
+#define sfgetr _sf_getr
+
+#include <sfstr.h>
+
+extern _Ast_info_t ast;
+
+extern int astwinsize(int, int*, int*);
+extern int chresc(const char*, char**);
+extern char* fmtbuf(size_t);
+extern char* fmtip4(uint32_t, int);
+extern char* sfgetr(Sfio_t*, int, int);
+extern char* strcopy(char*, const char*);
+extern int strmatch(const char*, const char*);
+extern int strtoip4(const char*, char**, uint32_t*, unsigned char*);
+
+#endif
diff --git a/src/lib/libast/astsa/ast_common.h b/src/lib/libast/astsa/ast_common.h
new file mode 100644
index 0000000..55573d6
--- /dev/null
+++ b/src/lib/libast/astsa/ast_common.h
@@ -0,0 +1,49 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2012 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#ifndef _AST_COMMON_H
+#define _AST_COMMON_H 1
+
+#include <ast_sa.h>
+#include <sys/types.h>
+
+#define Void_t void
+#define _ARG_(x) x
+#define _BEGIN_EXTERNS_
+#define _END_EXTERNS_
+#define __STD_C 1
+
+#if _hdr_stdint
+#include <stdint.h>
+#else
+#include <inttypes.h>
+#endif
+
+#if _hdr_unistd
+#include <unistd.h>
+#endif
+
+#define _typ_int32_t 1
+#ifdef _ast_int8_t
+#define _typ_int64_t 1
+#endif
+
+#endif
diff --git a/src/lib/libast/astsa/astsa.manifest b/src/lib/libast/astsa/astsa.manifest
new file mode 100644
index 0000000..03785fa
--- /dev/null
+++ b/src/lib/libast/astsa/astsa.manifest
@@ -0,0 +1,50 @@
+../../../../include/prototyped.h
+../cdt/cdtlib.h
+../cdt/dtclose.c
+../cdt/dtdisc.c
+../cdt/dthash.c
+../cdt/dthdr.h
+../cdt/dtlist.c
+../cdt/dtmethod.c
+../cdt/dtnew.c
+../cdt/dtopen.c
+../cdt/dtstrhash.c
+../cdt/dttree.c
+../cdt/dtview.c
+../cdt/dtwalk.c
+../include/cdt.h
+../include/hashkey.h
+../include/hashpart.h
+../include/ip6.h
+../include/magicid.h
+../misc/optget.c
+../misc/optlib.h
+../string/chresc.c
+../string/fmtbuf.c
+../string/fmtip4.c
+../string/fmtip6.c
+../string/strcopy.c
+../string/strtoip4.c
+../string/strtoip6.c
+README-astsa
+aso.c
+aso.h
+ast.c
+ast.h
+ast_common.h
+astsa.manifest
+astsa.mm
+astsa.omk
+ccode.h
+debug.h
+error.c
+error.h
+mkast_sa
+option.h
+sfstr.c
+sfstr.h
+strdup.c
+strmatch.c
+times.h
+vmalloc.c
+vmalloc.h
diff --git a/src/lib/libast/astsa/astsa.mm b/src/lib/libast/astsa/astsa.mm
new file mode 100644
index 0000000..eca64c0
--- /dev/null
+++ b/src/lib/libast/astsa/astsa.mm
@@ -0,0 +1,33 @@
+.xx title="astsa"
+.MT 4
+.TL
+
+.H 1 "astsa"
+.B astsa
+implements a small subset of the
+.B ast
+library for other
+.B ast
+standalone commands and libraries using X/Open interfaces.
+.P
+To get better performance and functionality, consider using any of
+the full-featured ast-* packages at
+.DS
+.xx link="http://www.research.att.com/sw/download/"
+.DE
+.P
+astsa.omk is an old make makefile that builds the headers and objects
+and defines these variables for use in other makefiles
+.VL 12
+.LI
+.B ASTSA_GEN
+point -I to these
+.LI
+.B ASTSA_HDRS
+point -I to these
+.LI
+.B AST_OBJS
+link against these
+.LE
+The astsa files may be combined in a single directory with other ast
+standalone packages.
diff --git a/src/lib/libast/astsa/astsa.omk b/src/lib/libast/astsa/astsa.omk
new file mode 100644
index 0000000..92d7882
--- /dev/null
+++ b/src/lib/libast/astsa/astsa.omk
@@ -0,0 +1,82 @@
+#
+# standalone mini libast old make makefile
+#
+
+CC = cc
+CFLAGS = $(ASTSA_CFLAGS)
+
+ASTSA_OPTIMIZE = -O
+ASTSA_CFLAGS = $(ASTSA_OPTIMIZE) -D_PACKAGE_astsa -I.
+
+ASTSA_GEN = \
+ ast_sa.h
+
+ASTSA_BLD = \
+ dthdr.h
+
+ASTSA_HDRS = \
+ ast.h \
+ ast_common.h \
+ ccode.h \
+ cdt.h \
+ debug.h \
+ error.h \
+ hashkey.h \
+ hashpart.h \
+ ip6.h \
+ magicid.h \
+ option.h \
+ optlib.h \
+ prototyped.h \
+ sfstr.h \
+ times.h \
+ vmalloc.h
+
+ASTSA_SRCS = \
+ aso.c \
+ ast.c \
+ chresc.c \
+ error.c \
+ fmtbuf.c \
+ fmtip4.c \
+ fmtip6.c \
+ optget.c \
+ sfstr.c \
+ strcopy.c \
+ strdup.c \
+ strmatch.c \
+ strtoip4.c \
+ strtoip6.c \
+ vmalloc.c \
+ dtclose.c \
+ dtdisc.c \
+ dthash.c \
+ dtlist.c \
+ dtmethod.c \
+ dtnew.c \
+ dtopen.c \
+ dtstrhash.c \
+ dttree.c \
+ dtview.c \
+ dtwalk.c
+
+ASTSA_MANIFEST = \
+ README astsa.omk mkast_sa \
+ $(ASTSA_BLD) $(ASTSA_HDRS) $(ASTSA_SRCS)
+
+astsa : ast_sa.h libastsa.a
+
+libastsa.a : aso.o ast.o chresc.o error.o fmtbuf.o fmtip4.o fmtip6.o optget.o \
+ sfstr.o strcopy.o strdup.o strmatch.o strtoip4.o strtoip6.o \
+ vmalloc.o \
+ dtclose.o dtdisc.o dthash.o dtlist.o dtmethod.o \
+ dtopen.o dtstrhash.o dttree.o dtview.o dtwalk.o
+ ar cr libastsa.a $?
+
+ast_sa.h : mkast_sa
+ ./mkast_sa $(CC) $(CFLAGS) > ast_sa.h
+
+clean :
+ rm -f ast_sa.h *.o *.a
+
+clobber : clean
diff --git a/src/lib/libast/astsa/ccode.h b/src/lib/libast/astsa/ccode.h
new file mode 100644
index 0000000..493e462
--- /dev/null
+++ b/src/lib/libast/astsa/ccode.h
@@ -0,0 +1,34 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#ifndef _CCODE_H
+#define _CCODE_H 1
+
+#define CC_bel '\a'
+#define CC_esc '\033'
+#define CC_vt '\v'
+
+#define CC_ASCII 0
+#define CC_NATIVE CC_ASCII
+
+#define ccmapc(c,f,t) (c)
+
+#endif
diff --git a/src/lib/libast/astsa/debug.h b/src/lib/libast/astsa/debug.h
new file mode 100644
index 0000000..7b93f4b
--- /dev/null
+++ b/src/lib/libast/astsa/debug.h
@@ -0,0 +1,29 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2012 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#ifndef _DEBUG_H
+#define _DEBUG_H 1
+
+#define DEBUG_ASSERT(x)
+
+#define message(p)
+
+#endif
diff --git a/src/lib/libast/astsa/error.c b/src/lib/libast/astsa/error.c
new file mode 100644
index 0000000..84b7728
--- /dev/null
+++ b/src/lib/libast/astsa/error.c
@@ -0,0 +1,103 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#pragma prototyped
+/*
+ * standalone mini error implementation
+ */
+
+#include <ast.h>
+#include <error.h>
+
+Error_info_t error_info;
+
+void
+errorv(const char* id, int level, va_list ap)
+{
+ char* a;
+ char* s;
+ int flags;
+
+ if (level < 0)
+ flags = 0;
+ else
+ {
+ flags = level & ~ERROR_LEVEL;
+ level &= ERROR_LEVEL;
+ }
+ a = va_arg(ap, char*);
+ if (level && ((s = error_info.id) || (s = (char*)id)))
+ {
+ if (!(flags & ERROR_USAGE))
+ sfprintf(sfstderr, "%s: ", s);
+ else if (strcmp(a, "%s"))
+ sfprintf(sfstderr, "Usage: %s ", s);
+ }
+ if (flags & ERROR_USAGE)
+ /*nop*/;
+ else if (level < 0)
+ sfprintf(sfstderr, "debug%d: ", level);
+ else if (level)
+ {
+ if (level == ERROR_WARNING)
+ {
+ sfprintf(sfstderr, "warning: ");
+ error_info.warnings++;
+ }
+ else
+ {
+ error_info.errors++;
+ if (level == ERROR_PANIC)
+ sfprintf(sfstderr, "panic: ");
+ }
+ if (error_info.line)
+ {
+ if (error_info.file && *error_info.file)
+ sfprintf(sfstderr, "\"%s\", ", error_info.file);
+ sfprintf(sfstderr, "line %d: ", error_info.line);
+ }
+ }
+ sfvprintf(sfstderr, a, ap);
+ sfprintf(sfstderr, "\n");
+ if (level >= ERROR_FATAL)
+ exit(level - ERROR_FATAL + 1);
+}
+
+void
+error(int level, ...)
+{
+ va_list ap;
+
+ va_start(ap, level);
+ errorv(NiL, level, ap);
+ va_end(ap);
+}
+
+int
+errorf(void* handle, void* discipline, int level, ...)
+{
+ va_list ap;
+
+ va_start(ap, level);
+ errorv((discipline && handle) ? *((char**)handle) : (char*)handle, level, ap);
+ va_end(ap);
+ return 0;
+}
diff --git a/src/lib/libast/astsa/error.h b/src/lib/libast/astsa/error.h
new file mode 100644
index 0000000..a95809f
--- /dev/null
+++ b/src/lib/libast/astsa/error.h
@@ -0,0 +1,66 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2012 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+/*
+ * standalone mini error interface
+ */
+
+#ifndef _ERROR_H
+#define _ERROR_H 1
+
+#include <option.h>
+#include <stdarg.h>
+
+typedef struct Error_info_s
+{
+ int errors;
+ int line;
+ int warnings;
+ char* catalog;
+ char* file;
+ char* id;
+} Error_info_t;
+
+#define ERROR_catalog(s) s
+
+#define ERROR_INFO 0 /* info message -- no err_id */
+#define ERROR_WARNING 1 /* warning message */
+#define ERROR_ERROR 2 /* error message -- no err_exit */
+#define ERROR_FATAL 3 /* error message with err_exit */
+#define ERROR_PANIC ERROR_LEVEL /* panic message with err_exit */
+
+#define ERROR_LEVEL 0x00ff /* level portion of status */
+#define ERROR_SYSTEM 0x0100 /* report system errno message */
+#define ERROR_USAGE 0x0800 /* usage message */
+
+#define error_info _err_info
+#define error _err_msg
+#define errorv _err_msgv
+
+extern Error_info_t error_info;
+
+#define errorx(l,x,c,m) (char*)m
+
+extern void error(int, ...);
+extern int errorf(void*, void*, int, ...);
+extern void errorv(const char*, int, va_list);
+
+#endif
diff --git a/src/lib/libast/astsa/hashkey.h b/src/lib/libast/astsa/hashkey.h
new file mode 100644
index 0000000..7f02842
--- /dev/null
+++ b/src/lib/libast/astsa/hashkey.h
@@ -0,0 +1,61 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2012 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+/*
+ * Glenn Fowler
+ * AT&T Research
+ *
+ * 1-6 char lower-case keyword -> long hash
+ * digit args passed as HASHKEYN('2')
+ */
+
+#ifndef _HASHKEY_H
+#define _HASHKEY_H 1
+
+#define HASHKEYMAX 6
+#define HASHKEYBIT 5
+#define HASHKEYOFF ('a'-1)
+#define HASHKEYPART(h,c) (((h)<<HASHKEYBIT)+HASHKEY1(c))
+
+#define HASHKEYN(n) ((n)-'0'+'z'+1)
+
+#define HASHKEY1(c1) ((c1)-HASHKEYOFF)
+#define HASHKEY2(c1,c2) HASHKEYPART(HASHKEY1(c1),c2)
+#define HASHKEY3(c1,c2,c3) HASHKEYPART(HASHKEY2(c1,c2),c3)
+#define HASHKEY4(c1,c2,c3,c4) HASHKEYPART(HASHKEY3(c1,c2,c3),c4)
+#define HASHKEY5(c1,c2,c3,c4,c5) HASHKEYPART(HASHKEY4(c1,c2,c3,c4),c5)
+#define HASHKEY6(c1,c2,c3,c4,c5,c6) HASHKEYPART(HASHKEY5(c1,c2,c3,c4,c5),c6)
+
+#define HASHNKEY1(n,c1) HASHKEY2((n)+HASHKEYOFF,c1)
+#define HASHNKEY2(n,c2,c1) HASHKEY3((n)+HASHKEYOFF,c2,c1)
+#define HASHNKEY3(n,c3,c2,c1) HASHKEY4((n)+HASHKEYOFF,c3,c2,c1)
+#define HASHNKEY4(n,c4,c3,c2,c1) HASHKEY5((n)+'a',c4,c3,c2,c1)
+#define HASHNKEY5(n,c5,c4,c3,c2,c1) HASHKEY6((n)+'a',c5,c4,c3,c2,c1)
+
+#if _BLD_ast && defined(__EXPORT__)
+#define extern __EXPORT__
+#endif
+
+extern long strkey(const char*);
+
+#undef extern
+
+#endif
diff --git a/src/lib/libast/astsa/mkast_sa b/src/lib/libast/astsa/mkast_sa
new file mode 100755
index 0000000..df448f2
--- /dev/null
+++ b/src/lib/libast/astsa/mkast_sa
@@ -0,0 +1,150 @@
+: generate ast_sa.h
+case $# in
+0) set cc ;;
+esac
+cat > _ast_.c <<'!'
+ #define _BYTESEX_H
+
+ #include <stdio.h>
+ #include <sys/types.h>
+
+ #if N == 0
+ #define _ast_int8_t long
+ #define _ast_int8_str "long"
+ #endif
+ #if N == 1
+ #define _ast_int8_t long long
+ #define _ast_int8_str "long long"
+ #endif
+ #if N == 2
+ #define _ast_int8_t __int64_t
+ #define _ast_int8_str "__int64_t"
+ #endif
+ #if N == 3
+ #define _ast_int8_t _int64_t
+ #define _ast_int8_str "_int64_t"
+ #endif
+ #if N == 4
+ #define _ast_int8_t int64_t
+ #define _ast_int8_str "int64_t"
+ #endif
+ #if N == 5
+ #define _ast_int8_t __int64
+ #define _ast_int8_str "__int64"
+ #endif
+ #if N == 6
+ #define _ast_int8_t _int64
+ #define _ast_int8_str "_int64"
+ #endif
+ #if N == 7
+ #define _ast_int8_t int64
+ #define _ast_int8_str "int64"
+ #endif
+
+ #define elementsof(x) (sizeof(x)/sizeof(x[0]))
+
+ static char i_char = 1;
+ static short i_short = 1;
+ static int i_int = 1;
+ static long i_long = 1;
+ #ifdef _ast_int8_t
+ static _ast_int8_t i_long_long = 1;
+ #endif
+
+ static struct
+ {
+ char* name;
+ int size;
+ char* swap;
+ } int_type[] =
+ {
+ "char", sizeof(char), (char*)&i_char,
+ "short", sizeof(short), (char*)&i_short,
+ "int", sizeof(int), (char*)&i_int,
+ "long", sizeof(long), (char*)&i_long,
+ #ifdef _ast_int8_t
+ _ast_int8_str, sizeof(_ast_int8_t), (char*)&i_long_long,
+ #endif
+ };
+
+ static struct
+ {
+ char* name;
+ int size;
+ } flt_type[] =
+ {
+ "float", sizeof(float),
+ "double", sizeof(double),
+ #ifdef _typ_long_double
+ "long double", sizeof(long double),
+ #endif
+ };
+
+ static int int_size[] = { 1, 2, 4, 8 };
+
+ main()
+ {
+ register int t;
+ register int s;
+ register int m = 1;
+ register int b = 1;
+ register int w = 0;
+
+ #ifdef _ast_int8_t
+ if (int_type[elementsof(int_type)-1].size <= 4)
+ return 1;
+ #endif
+ for (s = 0; s < elementsof(int_size); s++)
+ {
+ for (t = 0; t < elementsof(int_type) && int_type[t].size < int_size[s]; t++);
+ if (t < elementsof(int_type))
+ {
+ m = int_size[s];
+ printf("#define _ast_int%d_t %s\n", m, int_type[t].name);
+ if (m > 1)
+ {
+ if (*int_type[t].swap)
+ w |= b;
+ b <<= 1;
+ }
+ }
+ }
+ printf("#define _ast_intmax_t _ast_int%d_t\n", m);
+ if (m == sizeof(long))
+ printf("#define _ast_intmax_long 1\n");
+ printf("#define _ast_intswap %d\n", w);
+ printf("\n");
+ for (t = 0; t < elementsof(flt_type); t++)
+ {
+ while (t < elementsof(flt_type) && flt_type[t].size == flt_type[t + 1].size)
+ t++;
+ m = flt_type[t].size;
+ printf("#define _ast_flt%d_t %s\n", flt_type[t].size, flt_type[t].name);
+ }
+ printf("#define _ast_fltmax_t _ast_flt%d_t\n", m);
+ if (m == sizeof(double))
+ printf("#define _ast_fltmax_double 1\n");
+ return 0;
+ }
+!
+echo "#ifndef _AST_SA_H"
+echo "#define _AST_SA_H 1"
+echo
+for i in '' -DN=0 -DN=1 -DN=2 -DN=3 -DN=4 -DN=5 -DN=6 -DN=7 -DN=8
+do "$@" $i -o _ast_.exe _ast_.c 2> /dev/null &&
+ ./_ast_.exe &&
+ break
+done
+echo '#include <stdint.h>' > _ast_.c
+if "$@" -E _ast_.c > /dev/null 2>&1
+then echo "#define _hdr_stdint 1"
+fi
+echo '#include <unistd.h>' > _ast_.c
+if "$@" -E _ast_.c > /dev/null 2>&1
+then echo "#define _hdr_unistd 1"
+fi
+rm -f _ast_.c _ast_.exe
+echo "#define __DEFINE__(T,obj,val) T obj = val"
+echo "#define __EXTERN__(T,obj) extern T obj"
+echo
+echo "#endif"
diff --git a/src/lib/libast/astsa/option.h b/src/lib/libast/astsa/option.h
new file mode 100644
index 0000000..aa66920
--- /dev/null
+++ b/src/lib/libast/astsa/option.h
@@ -0,0 +1,106 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2012 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#pragma prototyped
+/*
+ * Glenn Fowler
+ * AT&T Research
+ *
+ * command line option parse interface
+ */
+
+#ifndef _OPTION_H
+#define _OPTION_H 1
+
+#include <ast.h>
+
+#define OPT_VERSION 20000401L
+
+#define opt_info _opt_info_
+
+#define OPT_USER (1L<<16) /* first user flag bit */
+
+struct Opt_s;
+struct Optdisc_s;
+
+typedef int (*Optinfo_f)(struct Opt_s*, Sfio_t*, const char*, struct Optdisc_s*);
+
+typedef struct Optdisc_s
+{
+ unsigned long version; /* OPT_VERSION */
+ unsigned long flags; /* OPT_* flags */
+ char* catalog; /* error catalog id */
+ Optinfo_f infof; /* runtime info function */
+} Optdisc_t;
+
+/* NOTE: Opt_t member order fixed by a previous binary release */
+
+#ifndef _OPT_PRIVATE_
+#define _OPT_PRIVATE_ void* _opt_private;
+#endif
+
+typedef struct Opt_s
+{
+ int again; /* see optjoin() */
+ char* arg; /* {:,#} string argument */
+ char** argv; /* most recent argv */
+ int index; /* argv index */
+ char* msg; /* error/usage message buffer */
+ long num; /* # numeric argument */
+ int offset; /* char offset in argv[index] */
+ char option[8]; /* current flag {-,+} + option */
+ char name[64]; /* current long name or flag */
+ Optdisc_t* disc; /* user discipline */
+ intmax_t number; /* # numeric argument */
+ unsigned char assignment; /* option arg assigment op */
+ unsigned char pads[sizeof(void*)-1];
+ _OPT_PRIVATE_
+} Opt_t;
+
+#define optinit(d,f) (memset(d,0,sizeof(*(d))),(d)->version=OPT_VERSION,(d)->infof=(f),opt_info.disc=(d))
+
+#if _BLD_ast && defined(__EXPORT__)
+#define __PUBLIC_DATA__ __EXPORT__
+#else
+#if !_BLD_ast && defined(__IMPORT__)
+#define __PUBLIC_DATA__ __IMPORT__
+#else
+#define __PUBLIC_DATA__
+#endif
+#endif
+
+extern __PUBLIC_DATA__ Opt_t opt_info;
+
+#undef __PUBLIC_DATA__
+
+#if _BLD_ast && defined(__EXPORT__)
+#define extern __EXPORT__
+#endif
+
+extern int optget(char**, const char*);
+extern int optjoin(char**, ...);
+extern char* opthelp(const char*, const char*);
+extern char* optusage(const char*);
+extern int optstr(const char*, const char*);
+
+#undef extern
+
+#endif
diff --git a/src/lib/libast/astsa/optlib.h b/src/lib/libast/astsa/optlib.h
new file mode 100644
index 0000000..8e09734
--- /dev/null
+++ b/src/lib/libast/astsa/optlib.h
@@ -0,0 +1,105 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2012 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+/*
+ * Glenn Fowler
+ * AT&T Research
+ *
+ * command line option parser and usage formatter private definitions
+ */
+
+#ifndef _OPTLIB_H
+#define _OPTLIB_H 1
+
+#include <ast.h>
+#include <cdt.h>
+
+#define OPT_cache 0x01
+#define OPT_functions 0x02
+#define OPT_ignore 0x04
+#define OPT_long 0x08
+#define OPT_old 0x10
+#define OPT_plus 0x20
+#define OPT_proprietary 0x40
+
+#define OPT_cache_flag 0x01
+#define OPT_cache_invert 0x02
+#define OPT_cache_numeric 0x04
+#define OPT_cache_optional 0x08
+#define OPT_cache_string 0x10
+
+#define OPT_CACHE 128
+#define OPT_FLAGS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
+
+struct Optdisc_s;
+
+typedef struct Optpass_s
+{
+ char* opts;
+ char* oopts;
+ char* catalog;
+ unsigned char version;
+ unsigned char prefix;
+ unsigned char flags;
+ unsigned char section;
+} Optpass_t;
+
+typedef struct Optcache_s
+{
+ struct Optcache_s* next;
+ Optpass_t pass;
+ int caching;
+ unsigned char flags[sizeof(OPT_FLAGS)];
+} Optcache_t;
+
+typedef struct Optstate_s
+{
+ Sfio_t* mp; /* opt_info.msg string stream */
+ Sfio_t* vp; /* translation string stream */
+ Sfio_t* xp; /* translation string stream */
+ Sfio_t* cp; /* compatibility string stream */
+ Optpass_t pass[8]; /* optjoin() list */
+ char* argv[2]; /* initial argv copy */
+ char* strv[3]; /* optstr() argv */
+ char* str; /* optstr() string */
+ Sfio_t* strp; /* optstr() stream */
+ int force; /* force this style */
+ int pindex; /* prev index for backup */
+ int poffset; /* prev offset for backup */
+ int npass; /* # optjoin() passes */
+ int join; /* optjoin() pass # */
+ int plus; /* + ok */
+ int style; /* default opthelp() style */
+ int width; /* format line width */
+ int flags; /* display flags */
+ int emphasis; /* ansi term emphasis ok */
+ Dtdisc_t msgdisc; /* msgdict discipline */
+ Dt_t* msgdict; /* default ast.id catalog msgs */
+ Optcache_t* cache; /* OPT_cache cache */
+} Optstate_t;
+
+#define _OPT_PRIVATE_ \
+ char pad[2*sizeof(void*)]; \
+ Optstate_t* state;
+
+#include <error.h>
+
+#endif
diff --git a/src/lib/libast/astsa/sfstr.c b/src/lib/libast/astsa/sfstr.c
new file mode 100644
index 0000000..7fc0be3
--- /dev/null
+++ b/src/lib/libast/astsa/sfstr.c
@@ -0,0 +1,246 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#include <ast.h>
+#include <stdarg.h>
+
+#define STR (8*1024)
+
+#define VALID(p,f) ((p=(Sfstr_t*)f)>=&strs[0]&&p<&strs[elementsof(strs)])
+
+static Sfstr_t strs[64];
+
+static int
+extend(Sfstr_t* p, int n)
+{
+ int o;
+
+ if (n < STR)
+ n = STR;
+ n += p->end - p->beg;
+ o = p->nxt - p->beg;
+ if (!(p->beg = realloc(p->beg, n)))
+ return -1;
+ p->nxt = p->beg + o;
+ p->end = p->beg + n;
+ return 0;
+}
+
+int
+sfclose(Sfio_t* f)
+{
+ Sfstr_t* p;
+ int r;
+
+ if (VALID(p, f))
+ {
+ p->nxt = 0;
+ r = 0;
+ }
+ else
+ r = fclose(f);
+ return r;
+}
+
+int
+sfprintf(Sfio_t* f, const char* fmt, ...)
+{
+ Sfstr_t* p;
+ char* s;
+ va_list ap;
+ int r;
+
+ static char buf[STR];
+
+ va_start(ap, fmt);
+ if (!VALID(p, f))
+ r = vfprintf(f, fmt, ap);
+ else if ((r = vsnprintf(buf, sizeof(buf), fmt, ap)) > 0)
+ r = sfwrite(f, buf, r);
+ va_end(ap);
+ return r;
+}
+
+char*
+sfprints(const char* fmt, ...)
+{
+ va_list ap;
+ int r;
+
+ static char buf[STR];
+
+ va_start(ap, fmt);
+ r = vsnprintf(buf, sizeof(buf), fmt, ap);
+ va_end(ap);
+ return r > 0 ? buf : (char*)0;
+}
+
+int
+sfputc(Sfio_t* f, int c)
+{
+ Sfstr_t* p;
+ int r;
+
+ if (VALID(p, f))
+ {
+ if (p->nxt >= p->end && extend(p, 1))
+ return -1;
+ *p->nxt++ = c;
+ r = 1;
+ }
+ else
+ r = fputc(c, f);
+ return r;
+}
+
+int
+sfputr(Sfio_t* f, const char* buf, int sep)
+{
+ Sfstr_t* p;
+ int r;
+ int n;
+
+ n = strlen(buf);
+ if (VALID(p, f))
+ {
+ r = n + (sep >= 0);
+ if (r > (p->end - p->nxt) && extend(p, r))
+ return -1;
+ memcpy(p->nxt, buf, n);
+ p->nxt += n;
+ if (sep >= 0)
+ *p->nxt++ = sep;
+ }
+ else
+ {
+ r = fwrite(buf, 1, n, f);
+ if (sep >= 0 && fputc(sep, f) != EOF)
+ r++;
+ }
+ return r;
+}
+
+char*
+sfstrbase(Sfio_t* f)
+{
+ Sfstr_t* p;
+
+ if (VALID(p, f))
+ return p->beg;
+ return 0;
+}
+
+Sfio_t*
+sfstropen(void)
+{
+ Sfstr_t* p;
+
+ for (p = &strs[0]; p < &strs[elementsof(strs)]; p++)
+ if (!p->nxt)
+ {
+ if (!p->beg)
+ {
+ if (!(p->beg = malloc(STR)))
+ break;
+ p->end = p->beg + STR;
+ }
+ p->nxt = p->beg;
+ return (Sfio_t*)p;
+ }
+ return 0;
+}
+
+#define _sf_strseek(f,p,m) \
+ ( (m) == SEEK_SET ? \
+ (((p) < 0 || (p) > ((f)->end - (f)->beg)) ? (char*)0 : \
+ (char*)((f)->nxt = (f)->beg+(p)) ) \
+ : (m) == SEEK_CUR ? \
+ ((f)->nxt += (p), \
+ (((f)->nxt < (f)->beg || (f)->nxt > (f)->end) ? \
+ ((f)->nxt -= (p), (char*)0) : (char*)(f)->nxt ) ) \
+ : (m) == SEEK_END ? \
+ ( ((p) > 0 || (((f)->end - (f)->beg) + (p)) < 0) ? (char*)0 : \
+ (char*)((f)->nxt = (f)->end+(p)) ) \
+ : (char*)0 \
+ )
+
+char*
+sfstrseek(Sfio_t* f, int n, int w)
+{
+ Sfstr_t* p;
+
+ if (VALID(p, f))
+ return _sf_strseek(p, n, w);
+ return 0;
+}
+
+char*
+sfstrset(Sfio_t* f, int n)
+{
+ Sfstr_t* p;
+
+ if (VALID(p, f) && n >= 0 && n < (p->nxt - p->beg))
+ return p->nxt = p->beg + n;
+ return 0;
+}
+
+int
+sfstrtell(Sfio_t* f)
+{
+ Sfstr_t* p;
+ int r;
+
+ if (VALID(p, f) && p->nxt)
+ r = p->nxt - p->beg;
+ else
+ r = -1;
+ return r;
+}
+
+char*
+sfstruse(Sfio_t* f)
+{
+ Sfstr_t* p;
+
+ if (VALID(p, f) && (p->nxt < p->end || !extend(p, 1)))
+ {
+ *p->nxt = 0;
+ return p->nxt = p->beg;
+ }
+ return 0;
+}
+
+int
+sfwrite(Sfio_t* f, void* buf, int n)
+{
+ Sfstr_t* p;
+
+ if (VALID(p, f))
+ {
+ if (n > (p->end - p->nxt) && extend(p, n))
+ return -1;
+ memcpy(p->nxt, buf, n);
+ p->nxt += n;
+ }
+ else
+ n = fwrite(buf, 1, n, f);
+ return n;
+}
diff --git a/src/lib/libast/astsa/sfstr.h b/src/lib/libast/astsa/sfstr.h
new file mode 100644
index 0000000..4fe21f5
--- /dev/null
+++ b/src/lib/libast/astsa/sfstr.h
@@ -0,0 +1,60 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#ifndef _SFSTR_H
+#define _SFSTR_H 1
+
+#include <ast.h>
+
+typedef struct Sfstr_s
+{
+ char* beg;
+ char* nxt;
+ char* end;
+} Sfstr_t;
+
+#undef sfclose
+#undef sfprintf
+#undef sfprints
+#undef sfputc
+#undef sfputr
+#undef sfstrbase
+#undef sfstropen
+#undef sfstrseek
+#undef sfstrset
+#undef sfstrtell
+#undef sfstruse
+#undef sfwrite
+
+extern int sfclose(Sfio_t*);
+extern int sfprintf(Sfio_t*, const char*, ...);
+extern char* sfprints(const char*, ...);
+extern int sfputc(Sfio_t*, int);
+extern int sfputr(Sfio_t*, const char*, int);
+extern char* sfstrbase(Sfio_t*);
+extern Sfio_t* sfstropen(void);
+extern char* sfstrseek(Sfio_t*, int, int);
+extern char* sfstrset(Sfio_t*, int);
+extern int sfstrtell(Sfio_t*);
+extern char* sfstruse(Sfio_t*);
+extern int sfwrite(Sfio_t*, void*, int);
+
+#endif
diff --git a/src/lib/libast/astsa/strdup.c b/src/lib/libast/astsa/strdup.c
new file mode 100644
index 0000000..a4de874
--- /dev/null
+++ b/src/lib/libast/astsa/strdup.c
@@ -0,0 +1,37 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#pragma prototyped
+
+#include <ast.h>
+
+/*
+ * return a copy of s using malloc
+ */
+
+char*
+strdup(register const char* s)
+{
+ register char* t;
+ register int n;
+
+ return (s && (t = newof(0, char, n = strlen(s) + 1, 0))) ? (char*)memcpy(t, s, n) : (char*)0;
+}
diff --git a/src/lib/libast/astsa/strmatch.c b/src/lib/libast/astsa/strmatch.c
new file mode 100644
index 0000000..f6a9ff3
--- /dev/null
+++ b/src/lib/libast/astsa/strmatch.c
@@ -0,0 +1,597 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#pragma prototyped
+
+/*
+ * D. G. Korn
+ * G. S. Fowler
+ * AT&T Research
+ *
+ * match shell file patterns -- derived from Bourne and Korn shell gmatch()
+ *
+ * sh pattern egrep RE description
+ * ---------- -------- -----------
+ * * .* 0 or more chars
+ * ? . any single char
+ * [.] [.] char class
+ * [!.] [^.] negated char class
+ * [[:.:]] [[:.:]] ctype class
+ * [[=.=]] [[=.=]] equivalence class
+ * [[...]] [[...]] collation element
+ * *(.) (.)* 0 or more of
+ * +(.) (.)+ 1 or more of
+ * ?(.) (.)? 0 or 1 of
+ * (.) (.) 1 of
+ * @(.) (.) 1 of
+ * a|b a|b a or b
+ * \# () subgroup back reference [1-9]
+ * a&b a and b
+ * !(.) none of
+ *
+ * \ used to escape metacharacters
+ *
+ * *, ?, (, |, &, ), [, \ must be \'d outside of [...]
+ * only ] must be \'d inside [...]
+ *
+ * BUG: unbalanced ) terminates top level pattern
+ */
+
+#include <ast.h>
+#include <ctype.h>
+#include <hashkey.h>
+
+#ifndef isblank
+#define isblank(x) ((x)==' '||(x)=='\t')
+#endif
+
+#ifndef isgraph
+#define isgraph(x) (isprint(x)&&!isblank(x))
+#endif
+
+#define MAXGROUP 10
+
+typedef struct
+{
+ char* beg[MAXGROUP];
+ char* end[MAXGROUP];
+ char* next_s;
+ short groups;
+} Group_t;
+
+typedef struct
+{
+ Group_t current;
+ Group_t best;
+ char* last_s;
+ char* next_p;
+} Match_t;
+
+#define mbgetchar(p) (*p++)
+
+#ifndef isxdigit
+#define isxdigit(c) ((c)>='0'&&(c)<='9'||(c)>='a'&&(c)<='f'||(c)>='A'&&(c)<='F')
+#endif
+
+#define getsource(s,e) (((s)>=(e))?0:mbgetchar(s))
+
+#define COLL_MAX 3
+
+/*
+ * gobble chars up to <sub> or ) keeping track of (...) and [...]
+ * sub must be one of { '|', '&', 0 }
+ * 0 returned if s runs out
+ */
+
+static char*
+gobble(Match_t* mp, register char* s, register int sub, int* g, int clear)
+{
+ register int p = 0;
+ register char* b = 0;
+ int c = 0;
+ int n;
+
+ for (;;)
+ switch (mbgetchar(s))
+ {
+ case '\\':
+ if (mbgetchar(s))
+ break;
+ /*FALLTHROUGH*/
+ case 0:
+ return 0;
+ case '[':
+ if (!b)
+ {
+ if (*s == '!')
+ mbgetchar(s);
+ b = s;
+ }
+ else if (*s == '.' || *s == '=' || *s == ':')
+ c = *s;
+ break;
+ case ']':
+ if (b)
+ {
+ if (*(s - 2) == c)
+ c = 0;
+ else if (b != (s - 1))
+ b = 0;
+ }
+ break;
+ case '(':
+ if (!b)
+ {
+ p++;
+ n = (*g)++;
+ if (clear)
+ {
+ if (!sub)
+ n++;
+ if (n < MAXGROUP)
+ mp->current.beg[n] = mp->current.end[n] = 0;
+ }
+ }
+ break;
+ case ')':
+ if (!b && p-- <= 0)
+ return sub ? 0 : s;
+ break;
+ case '|':
+ if (!b && !p && sub == '|')
+ return s;
+ break;
+ }
+}
+
+static int grpmatch(Match_t*, int, char*, register char*, char*, int);
+
+/*
+ * match a single pattern
+ * e is the end (0) of the substring in s
+ * r marks the start of a repeated subgroup pattern
+ */
+
+static int
+onematch(Match_t* mp, int g, char* s, char* p, char* e, char* r, int flags)
+{
+ register int pc;
+ register int sc;
+ register int n;
+ register int icase;
+ char* olds;
+ char* oldp;
+
+ icase = flags & STR_ICASE;
+ do
+ {
+ olds = s;
+ sc = getsource(s, e);
+ if (icase && isupper(sc))
+ sc = tolower(sc);
+ oldp = p;
+ switch (pc = mbgetchar(p))
+ {
+ case '(':
+ case '*':
+ case '?':
+ case '+':
+ case '@':
+ case '!':
+ if (pc == '(' || *p == '(')
+ {
+ char* subp;
+ int oldg;
+
+ s = olds;
+ subp = p + (pc != '(');
+ oldg = g;
+ n = ++g;
+ if (g < MAXGROUP && (!r || g > mp->current.groups))
+ mp->current.beg[g] = mp->current.end[g] = 0;
+ if (!(p = gobble(mp, subp, 0, &g, !r)))
+ return 0;
+ if (pc == '*' || pc == '?' || pc == '+' && oldp == r)
+ {
+ if (onematch(mp, g, s, p, e, NiL, flags))
+ return 1;
+ if (!sc || !getsource(s, e))
+ {
+ mp->current.groups = oldg;
+ return 0;
+ }
+ }
+ if (pc == '*' || pc == '+')
+ {
+ p = oldp;
+ sc = n - 1;
+ }
+ else
+ sc = g;
+ pc = (pc != '!');
+ do
+ {
+ if (grpmatch(mp, n, olds, subp, s, flags) == pc)
+ {
+ if (n < MAXGROUP)
+ {
+ if (!mp->current.beg[n] || mp->current.beg[n] > olds)
+ mp->current.beg[n] = olds;
+ if (s > mp->current.end[n])
+ mp->current.end[n] = s;
+ }
+ if (onematch(mp, sc, s, p, e, oldp, flags))
+ {
+ if (p == oldp && n < MAXGROUP)
+ {
+ if (!mp->current.beg[n] || mp->current.beg[n] > olds)
+ mp->current.beg[n] = olds;
+ if (s > mp->current.end[n])
+ mp->current.end[n] = s;
+ }
+ return 1;
+ }
+ }
+ } while (s < e && mbgetchar(s));
+ mp->current.groups = oldg;
+ return 0;
+ }
+ else if (pc == '*')
+ {
+ /*
+ * several stars are the same as one
+ */
+
+ while (*p == '*' && *(p + 1) != '(')
+ p++;
+ oldp = p;
+ switch (pc = mbgetchar(p))
+ {
+ case '@':
+ case '!':
+ case '+':
+ n = *p == '(';
+ break;
+ case '(':
+ case '[':
+ case '?':
+ case '*':
+ n = 1;
+ break;
+ case 0:
+ case '|':
+ case '&':
+ case ')':
+ mp->current.next_s = (flags & STR_MAXIMAL) ? e : olds;
+ mp->next_p = oldp;
+ mp->current.groups = g;
+ if (!pc && (!mp->best.next_s || (flags & STR_MAXIMAL) && mp->current.next_s > mp->best.next_s || !(flags & STR_MAXIMAL) && mp->current.next_s < mp->best.next_s))
+ mp->best = mp->current;
+ return 1;
+ case '\\':
+ if (!(pc = mbgetchar(p)))
+ return 0;
+ if (pc >= '0' && pc <= '9')
+ {
+ n = pc - '0';
+ if (n <= g && mp->current.beg[n])
+ pc = *mp->current.beg[n];
+ }
+ /*FALLTHROUGH*/
+ default:
+ if (icase && isupper(pc))
+ pc = tolower(pc);
+ n = 0;
+ break;
+ }
+ p = oldp;
+ for (;;)
+ {
+ if ((n || pc == sc) && onematch(mp, g, olds, p, e, NiL, flags))
+ return 1;
+ if (!sc)
+ return 0;
+ olds = s;
+ sc = getsource(s, e);
+ if ((flags & STR_ICASE) && isupper(sc))
+ sc = tolower(sc);
+ }
+ }
+ else if (pc != '?' && pc != sc)
+ return 0;
+ break;
+ case 0:
+ if (!(flags & STR_MAXIMAL))
+ sc = 0;
+ /*FALLTHROUGH*/
+ case '|':
+ case '&':
+ case ')':
+ if (!sc)
+ {
+ mp->current.next_s = olds;
+ mp->next_p = oldp;
+ mp->current.groups = g;
+ }
+ if (!pc && (!mp->best.next_s || (flags & STR_MAXIMAL) && olds > mp->best.next_s || !(flags & STR_MAXIMAL) && olds < mp->best.next_s))
+ {
+ mp->best = mp->current;
+ mp->best.next_s = olds;
+ mp->best.groups = g;
+ }
+ return !sc;
+ case '[':
+ {
+ /*UNDENT...*/
+
+ int invert;
+ int x;
+ int ok = 0;
+ char* range;
+
+ if (!sc)
+ return 0;
+ range = 0;
+ n = 0;
+ if (invert = *p == '!')
+ p++;
+ for (;;)
+ {
+ oldp = p;
+ if (!(pc = mbgetchar(p)))
+ return 0;
+ else if (pc == '[' && (*p == ':' || *p == '=' || *p == '.'))
+ {
+ x = 0;
+ n = mbgetchar(p);
+ oldp = p;
+ for (;;)
+ {
+ if (!(pc = mbgetchar(p)))
+ return 0;
+ if (pc == n && *p == ']')
+ break;
+ x++;
+ }
+ mbgetchar(p);
+ if (ok)
+ /*NOP*/;
+ else if (n == ':')
+ {
+ switch (HASHNKEY5(x, oldp[0], oldp[1], oldp[2], oldp[3], oldp[4]))
+ {
+ case HASHNKEY5(5,'a','l','n','u','m'):
+ if (isalnum(sc))
+ ok = 1;
+ break;
+ case HASHNKEY5(5,'a','l','p','h','a'):
+ if (isalpha(sc))
+ ok = 1;
+ break;
+ case HASHNKEY5(5,'b','l','a','n','k'):
+ if (isblank(sc))
+ ok = 1;
+ break;
+ case HASHNKEY5(5,'c','n','t','r','l'):
+ if (iscntrl(sc))
+ ok = 1;
+ break;
+ case HASHNKEY5(5,'d','i','g','i','t'):
+ if (isdigit(sc))
+ ok = 1;
+ break;
+ case HASHNKEY5(5,'g','r','a','p','h'):
+ if (isgraph(sc))
+ ok = 1;
+ break;
+ case HASHNKEY5(5,'l','o','w','e','r'):
+ if (islower(sc))
+ ok = 1;
+ break;
+ case HASHNKEY5(5,'p','r','i','n','t'):
+ if (isprint(sc))
+ ok = 1;
+ break;
+ case HASHNKEY5(5,'p','u','n','c','t'):
+ if (ispunct(sc))
+ ok = 1;
+ break;
+ case HASHNKEY5(5,'s','p','a','c','e'):
+ if (isspace(sc))
+ ok = 1;
+ break;
+ case HASHNKEY5(5,'u','p','p','e','r'):
+ if (icase ? islower(sc) : isupper(sc))
+ ok = 1;
+ break;
+ case HASHNKEY5(6,'x','d','i','g','i'):
+ if (oldp[5] == 't' && isxdigit(sc))
+ ok = 1;
+ break;
+ }
+ }
+ else if (range)
+ goto getrange;
+ else if (*p == '-' && *(p + 1) != ']')
+ {
+ mbgetchar(p);
+ range = oldp;
+ }
+ else if (isalpha(*oldp) && isalpha(*olds) && tolower(*oldp) == tolower(*olds) || sc == mbgetchar(oldp))
+ ok = 1;
+ n = 1;
+ }
+ else if (pc == ']' && n)
+ {
+ if (ok != invert)
+ break;
+ return 0;
+ }
+ else if (pc == '\\' && (oldp = p, !(pc = mbgetchar(p))))
+ return 0;
+ else if (ok)
+ /*NOP*/;
+ else if (range)
+ {
+ getrange:
+ if (icase && isupper(pc))
+ pc = tolower(pc);
+ x = mbgetchar(range);
+ if (icase && isupper(x))
+ x = tolower(x);
+ if (sc == x || sc == pc || sc > x && sc < pc)
+ ok = 1;
+ if (*p == '-' && *(p + 1) != ']')
+ {
+ mbgetchar(p);
+ range = oldp;
+ }
+ else
+ range = 0;
+ n = 1;
+ }
+ else if (*p == '-' && *(p + 1) != ']')
+ {
+ mbgetchar(p);
+ range = oldp;
+ n = 1;
+ }
+ else
+ {
+ if (icase && isupper(pc))
+ pc = tolower(pc);
+ if (sc == pc)
+ ok = 1;
+ n = pc;
+ }
+ }
+
+ /*...INDENT*/
+ }
+ break;
+ case '\\':
+ if (!(pc = mbgetchar(p)))
+ return 0;
+ if (pc >= '0' && pc <= '9')
+ {
+ n = pc - '0';
+ if (n <= g && (oldp = mp->current.beg[n]))
+ {
+ while (oldp < mp->current.end[n])
+ if (!*olds || *olds++ != *oldp++)
+ return 0;
+ s = olds;
+ break;
+ }
+ }
+ /*FALLTHROUGH*/
+ default:
+ if (icase && isupper(pc))
+ pc = tolower(pc);
+ if (pc != sc)
+ return 0;
+ break;
+ }
+ } while (sc);
+ return 0;
+}
+
+/*
+ * match any pattern in a group
+ * | and & subgroups are parsed here
+ */
+
+static int
+grpmatch(Match_t* mp, int g, char* s, register char* p, char* e, int flags)
+{
+ register char* a;
+
+ do
+ {
+ for (a = p; onematch(mp, g, s, a, e, NiL, flags); a++)
+ if (*(a = mp->next_p) != '&')
+ return 1;
+ } while (p = gobble(mp, p, '|', &g, 1));
+ return 0;
+}
+
+/*
+ * subgroup match
+ * 0 returned if no match
+ * otherwise number of subgroups matched returned
+ * match group begin offsets are even elements of sub
+ * match group end offsets are odd elements of sub
+ * the matched string is from s+sub[0] up to but not
+ * including s+sub[1]
+ */
+
+int
+strgrpmatch(const char* b, const char* p, int* sub, int n, int flags)
+{
+ register int i;
+ register char* s;
+ char* e;
+ Match_t match;
+
+ s = (char*)b;
+ match.last_s = e = s + strlen(s);
+ for (;;)
+ {
+ match.best.next_s = 0;
+ match.current.groups = 0;
+ if ((i = grpmatch(&match, 0, s, (char*)p, e, flags)) || match.best.next_s)
+ {
+ if (!i)
+ match.current = match.best;
+ match.current.groups++;
+ match.current.end[0] = match.current.next_s;
+ break;
+ }
+ if ((flags & STR_LEFT) || s >= e)
+ return 0;
+ s++;
+ }
+ if ((flags & STR_RIGHT) && match.current.next_s != e)
+ return 0;
+ if (!sub)
+ return 1;
+ match.current.beg[0] = s;
+ s = (char*)b;
+ if (n > match.current.groups)
+ n = match.current.groups;
+ for (i = 0; i < n; i++)
+ {
+ sub[i * 2] = match.current.end[i] ? match.current.beg[i] - s : 0;
+ sub[i * 2 + 1] = match.current.end[i] ? match.current.end[i] - s : 0;
+ }
+ return n;
+}
+
+/*
+ * compare the string s with the shell pattern p
+ * returns 1 for match 0 otherwise
+ */
+
+int
+strmatch(const char* s, const char* p)
+{
+ return strgrpmatch(s, p, NiL, 0, STR_MAXIMAL|STR_LEFT|STR_RIGHT);
+}
diff --git a/src/lib/libast/astsa/times.h b/src/lib/libast/astsa/times.h
new file mode 100644
index 0000000..7b916f7
--- /dev/null
+++ b/src/lib/libast/astsa/times.h
@@ -0,0 +1,27 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2012 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#ifndef _TIMES_H
+#define _TIMES_H 1
+
+#include <sys/times.h>
+
+#endif
diff --git a/src/lib/libast/astsa/vmalloc.c b/src/lib/libast/astsa/vmalloc.c
new file mode 100644
index 0000000..3195b13
--- /dev/null
+++ b/src/lib/libast/astsa/vmalloc.c
@@ -0,0 +1,102 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2011 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+#pragma prototyped
+/*
+ * standalone mini vmalloc implementation
+ * no resize, no free, no disciplines, no methods
+ */
+
+#include <ast.h>
+#include <vmalloc.h>
+
+Vmalloc_t* Vmregion;
+
+Vmalloc_t*
+_vm_open(void)
+{
+ Vmalloc_t* vp;
+
+ if (vp = newof(0, Vmalloc_t, 1, 0))
+ {
+ vp->current = &vp->base;
+ vp->data = vp->current->data;
+ vp->size = sizeof(vp->current->data);
+ }
+ return vp;
+}
+
+int
+_vm_close(register Vmalloc_t* vp)
+{
+ register Vmchunk_t* cp;
+ register Vmchunk_t* np;
+
+ if (!vp)
+ return -1;
+ np = vp->base.next;
+ while (cp = np)
+ {
+ np = cp->next;
+ free(cp);
+ }
+ free(vp);
+ return 0;
+}
+
+void*
+_vm_resize(register Vmalloc_t* vp, void* o, unsigned long size)
+{
+ char* p;
+ unsigned long n;
+ unsigned long z;
+
+ z = vp->last;
+ vp->last = size;
+ if (o && size < z)
+ return o;
+ if ((o ? (size - z) : size) > vp->size)
+ {
+ n = (size > sizeof(vp->current->data)) ? (size - sizeof(vp->current->data)) : 0;
+ if (!(vp->current->next = newof(0, Vmchunk_t, 1, n)))
+ return 0;
+ vp->current = vp->current->next;
+ vp->data = vp->current->data;
+ vp->size = n ? 0 : sizeof(vp->current->data);
+ if (o)
+ {
+ memcpy(vp->data, o, z);
+ o = (void*)vp->data;
+ }
+ }
+ else if (o)
+ size -= z;
+ p = vp->data;
+ size = roundof(size, VM_ALIGN);
+ if (size >= vp->size)
+ vp->size = 0;
+ else
+ {
+ vp->size -= size;
+ vp->data += size;
+ }
+ return p;
+}
diff --git a/src/lib/libast/astsa/vmalloc.h b/src/lib/libast/astsa/vmalloc.h
new file mode 100644
index 0000000..e3d2e5b
--- /dev/null
+++ b/src/lib/libast/astsa/vmalloc.h
@@ -0,0 +1,61 @@
+/***********************************************************************
+* *
+* This software is part of the ast package *
+* Copyright (c) 1985-2012 AT&T Intellectual Property *
+* 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> *
+* *
+***********************************************************************/
+/*
+ * standalone mini vmalloc interface
+ */
+
+#ifndef _VMALLOC_H
+#define _VMALLOC_H 1
+
+#define vmalloc(v,n) _vm_resize(v,(void*)0,n)
+#define vmalign(v,n,a) _vm_resize(v,(void*)0,n)
+#define vmclose(v) _vm_close(v)
+#define vmfree(v,p)
+#define vmnewof(v,o,t,n,x) (t*)_vm_resize(v,(void*)o,sizeof(t)*(n)+(x))
+#define vmopen(a,b,c) _vm_open()
+
+#define VM_CHUNK (32*1024)
+#define VM_ALIGN 16
+
+typedef struct Vmchunk_s
+{
+ struct Vmchunk_s* next;
+ char align[VM_ALIGN - sizeof(struct Vmchunk_s*)];
+ char data[VM_CHUNK - VM_ALIGN];
+} Vmchunk_t;
+
+typedef struct Vmalloc_s
+{
+ Vmchunk_t base;
+ Vmchunk_t* current;
+ char* data;
+ long size;
+ long last;
+} Vmalloc_t;
+
+extern Vmalloc_t* Vmregion;
+
+extern int _vm_close(Vmalloc_t*);
+extern Vmalloc_t* _vm_open(void);
+extern void* _vm_resize(Vmalloc_t*, void*, unsigned long);
+
+#endif