Module Name:    othersrc
Committed By:   agc
Date:           Thu Jun  6 01:45:57 UTC 2013

Modified Files:
        othersrc/external/historical/eawk/bin: Makefile expected
        othersrc/external/historical/eawk/dist: run.c tran.c
        othersrc/external/historical/eawk/extend: Makefile
        othersrc/external/historical/eawk/extend/db: db.c
        othersrc/external/historical/eawk/scripts: tart.sh
Added Files:
        othersrc/external/historical/eawk/extend/curses: Makefile curses.c
            shlib_version
        othersrc/external/historical/eawk/extend/threshold: Makefile
            shlib_version threshold.c
        othersrc/external/historical/eawk/scripts: rain.sh test-thresh.sh
            threshold.sh

Log Message:
Changes to eawk:

+ reworked the db interface to be easier to use - results are now
returned as part of key and value arrays, which both have data and
size fields, to mirror the DBT struct

+ added initial curses bindings

+ fixed a bug in numeric array field names which I introduced

+ added scripts/rain.sh awk script which does what /usr/games/rain
does, and which exercises numeric array field names, and curses. It's
also much smaller than the equivalent C source.

+ added bindings for threshold algorithms, and a script to exercise
them


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 othersrc/external/historical/eawk/bin/Makefile \
    othersrc/external/historical/eawk/bin/expected
cvs rdiff -u -r1.6 -r1.7 othersrc/external/historical/eawk/dist/run.c
cvs rdiff -u -r1.5 -r1.6 othersrc/external/historical/eawk/dist/tran.c
cvs rdiff -u -r1.3 -r1.4 othersrc/external/historical/eawk/extend/Makefile
cvs rdiff -u -r0 -r1.1 \
    othersrc/external/historical/eawk/extend/curses/Makefile \
    othersrc/external/historical/eawk/extend/curses/curses.c \
    othersrc/external/historical/eawk/extend/curses/shlib_version
cvs rdiff -u -r1.1 -r1.2 othersrc/external/historical/eawk/extend/db/db.c
cvs rdiff -u -r0 -r1.1 \
    othersrc/external/historical/eawk/extend/threshold/Makefile \
    othersrc/external/historical/eawk/extend/threshold/shlib_version \
    othersrc/external/historical/eawk/extend/threshold/threshold.c
cvs rdiff -u -r0 -r1.1 othersrc/external/historical/eawk/scripts/rain.sh \
    othersrc/external/historical/eawk/scripts/test-thresh.sh \
    othersrc/external/historical/eawk/scripts/threshold.sh
cvs rdiff -u -r1.1 -r1.2 othersrc/external/historical/eawk/scripts/tart.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: othersrc/external/historical/eawk/bin/Makefile
diff -u othersrc/external/historical/eawk/bin/Makefile:1.3 othersrc/external/historical/eawk/bin/Makefile:1.4
--- othersrc/external/historical/eawk/bin/Makefile:1.3	Wed Jun  5 00:55:25 2013
+++ othersrc/external/historical/eawk/bin/Makefile	Thu Jun  6 01:45:56 2013
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.3 2013/06/05 00:55:25 agc Exp $
+# $NetBSD: Makefile,v 1.4 2013/06/06 01:45:56 agc Exp $
 
 .include <bsd.own.mk>
 
@@ -108,7 +108,7 @@ t test: ${PROG}
 	@echo "31. Testing hmac"
 	@env LD_LIBRARY_PATH=${LIBEAWKDIR}:${LIB_HMAC} ./${PROG} 'BEGIN { use("hmac"); mac = hmac("sha1", "akey", "the quick brown fox jumps over the lazy dog"); print hmac_bin2str(mac) }'
 	@echo "32. Testing db"
-	@env LD_LIBRARY_PATH=${LIBEAWKDIR}:${LIB_DB} ./${PROG} 'BEGIN { use("db"); db = dbopen("/etc/pwd.db", O_RDONLY, 0666, "hash"); for (f = R_FIRST ; s = dbseq(db, s, f) ; f = R_NEXT) print s; }'
+	@env LD_LIBRARY_PATH=${LIBEAWKDIR}:${LIB_DB}:${LIB_C} ./${PROG} 'BEGIN { use("db"); use("c"); info["type"] = "hash"; db = dbopen("/etc/pwd.db", O_RDONLY, 0666, info); while (dbseq(db, key, val, R_NEXT) == 0) print val["data"]; }'
 	@echo "33. Testing hex strings"
 	@env LD_LIBRARY_PATH=${LIBEAWKDIR}:${LIB_DB} ./${PROG} 'BEGIN { s="\x20a\x20b\x20c"; printf(",%s,\n", s) }'
 	@echo "34. Testing zlib"
Index: othersrc/external/historical/eawk/bin/expected
diff -u othersrc/external/historical/eawk/bin/expected:1.3 othersrc/external/historical/eawk/bin/expected:1.4
--- othersrc/external/historical/eawk/bin/expected:1.3	Wed Jun  5 00:55:25 2013
+++ othersrc/external/historical/eawk/bin/expected	Thu Jun  6 01:45:56 2013
@@ -711,7 +711,7 @@ Makefile
 
 
     <!-- ##### Footer ##### -->
-    <!-- $NetBSD: expected,v 1.3 2013/06/05 00:55:25 agc Exp $ -->
+    <!-- $NetBSD: expected,v 1.4 2013/06/06 01:45:56 agc Exp $ -->
     <div class="rowOfBoxes">
       <div id="footer">
 	<div id="footerLogo">
@@ -742,7 +742,7 @@ Makefile
 29. Testing netdiff
 30. Testing netdiff with diffs
 ---
-> # $NetBSD: expected,v 1.3 2013/06/05 00:55:25 agc Exp $
+> # $NetBSD: expected,v 1.4 2013/06/06 01:45:56 agc Exp $
 5c5
 < PROG=		eawk
 ---
@@ -914,8 +914,8 @@ Makefile
 
 30. Testing unidiff with diffs
 @@ -1,8 +1,8 @@
--# $NetBSD: expected,v 1.3 2013/06/05 00:55:25 agc Exp $
-+# $NetBSD: expected,v 1.3 2013/06/05 00:55:25 agc Exp $
+-# $NetBSD: expected,v 1.4 2013/06/06 01:45:56 agc Exp $
++# $NetBSD: expected,v 1.4 2013/06/06 01:45:56 agc Exp $
  
  .include <bsd.own.mk>
  

Index: othersrc/external/historical/eawk/dist/run.c
diff -u othersrc/external/historical/eawk/dist/run.c:1.6 othersrc/external/historical/eawk/dist/run.c:1.7
--- othersrc/external/historical/eawk/dist/run.c:1.6	Wed Jun  5 02:59:47 2013
+++ othersrc/external/historical/eawk/dist/run.c	Thu Jun  6 01:45:56 2013
@@ -1506,19 +1506,20 @@ eawk_assign(eawk_t *eawk, awknode_t **a,
 	y = eawk_execute(eawk, a[1]);
 	x = eawk_execute(eawk, a[0]);
 	if (n == ASSIGN) {	/* ordinary assignment */
-		if (x == y && !(x->type & (EAWK_FIELD|EAWK_RECORD)))	/* self-assignment: */
-			;		/* leave alone unless it's a field */
-		else if ((y->type & (EAWK_STR|EAWK_NUM)) == (EAWK_STR|EAWK_NUM)) {
+		if (x == y && !(x->type & (EAWK_FIELD|EAWK_RECORD))) {
+			/* self-assignment: */
+			/* leave alone unless it's a field */
+		} else if ((y->type & (EAWK_STR|EAWK_NUM)) == (EAWK_STR|EAWK_NUM)) {
 			eawk_setsval(eawk, x, eawk_getsval(eawk, y));
 			x->num = eawk_getfval(eawk, y);
 			x->type |= EAWK_NUM;
-		}
-		else if (ISSTR(y))
+		} else if (ISSTR(y)) {
 			eawk_setsval(eawk, x, eawk_getsval(eawk, y));
-		else if (ISNUM(y))
+		} else if (ISNUM(y)) {
 			eawk_setfval(eawk, x, eawk_getfval(eawk, y));
-		else
+		} else {
 			eawk_funnyvar(eawk, y, "read value of");
+		}
 		TEMPFREE(eawk, y);
 		return(x);
 	}

Index: othersrc/external/historical/eawk/dist/tran.c
diff -u othersrc/external/historical/eawk/dist/tran.c:1.5 othersrc/external/historical/eawk/dist/tran.c:1.6
--- othersrc/external/historical/eawk/dist/tran.c:1.5	Wed Jun  5 02:59:47 2013
+++ othersrc/external/historical/eawk/dist/tran.c	Thu Jun  6 01:45:56 2013
@@ -58,15 +58,14 @@ get_str_val(eawk_t *eawk, awkcell_t *cel
 			XFREE(cell->str);
 		if (cell->binsize > 0) {
 			cell->str = eawk_tostringN(eawk, s, cell->binsize);
+		}
+		if (modf(cell->num, &dtemp) == 0) {
+			/* it's integral */
+			snprintf(s, sizeof(s), "%.30g", cell->num);
 		} else {
-			if (modf(cell->num, &dtemp) == 0) {
-				/* it's integral */
-				snprintf(s, sizeof(s), "%.30g", cell->num);
-			} else {
-				snprintf(s, sizeof(s), *fmt, cell->num);
-			}
-			cell->str = eawk_tostring(eawk, s);
+			snprintf(s, sizeof(s), *fmt, cell->num);
 		}
+		cell->str = eawk_tostring(eawk, s);
 		cell->type &= ~EAWK_DONTFREE;
 		cell->type |= EAWK_STR;
 	}
@@ -326,6 +325,7 @@ awkcell_t *
 eawk_var_set(eawk_t *eawk, const char *name, const char *s, awknum_t f, unsigned t, awkarray_t *arr)
 {
 	int h;
+	//char	number[32];
 	awkcell_t *p;
 
 	if (name == NULL)
@@ -342,8 +342,8 @@ eawk_var_set(eawk_t *eawk, const char *n
 		return NULL;
 	}
 	p->name = eawk_tostring(eawk, name);
-	p->str = eawk_tostring(eawk, (s) ? s : "");
 	p->num = f;
+	p->str = eawk_tostring(eawk, (s) ? s : "");
 	p->type = t;
 	p->csub = CUNK;
 	p->ctype = OCELL;
@@ -457,14 +457,16 @@ rehash(awkarray_t *arr)
 awkcell_t *
 eawk_array_lookup(awkarray_t *arr, const char *s)
 {
-	awkcell_t *p;
-	int h;
+	awkcell_t	*p;
+	int		 h;
 
 	h = eawk_hash(s, arr->size);
-	for (p = arr->tab[h]; p != NULL; p = p->cnext)
-		if (strcmp(s, p->name) == 0)
-			return(p);	/* found it */
-	return(NULL);			/* not found */
+	for (p = arr->tab[h]; p != NULL; p = p->cnext) {
+		if (strcmp(s, p->name) == 0) {
+			return p;
+		}
+	}
+	return NULL;			/* not found */
 }
 
 /* set float val of a awkcell_t */

Index: othersrc/external/historical/eawk/extend/Makefile
diff -u othersrc/external/historical/eawk/extend/Makefile:1.3 othersrc/external/historical/eawk/extend/Makefile:1.4
--- othersrc/external/historical/eawk/extend/Makefile:1.3	Wed Jun  5 00:55:25 2013
+++ othersrc/external/historical/eawk/extend/Makefile	Thu Jun  6 01:45:56 2013
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.3 2013/06/05 00:55:25 agc Exp $
+# $NetBSD: Makefile,v 1.4 2013/06/06 01:45:56 agc Exp $
 
 SUBDIR+=	archive
 SUBDIR+=	base64
@@ -10,6 +10,7 @@ SUBDIR+=	c
 .if exists(/usr/include/circa.h)
 SUBDIR+=	circa
 .endif
+SUBDIR+=	curses
 SUBDIR+=	db
 SUBDIR+=	digest
 SUBDIR+=	dirent
@@ -41,6 +42,9 @@ SUBDIR+=	rs
 SUBDIR+=	soundex
 SUBDIR+=	sqlite3
 SUBDIR+=	termcap
+.if exists(/usr/include/threshold.h)
+SUBDIR+=	threshold
+.endif
 SUBDIR+=	zlib
 
 .include <bsd.subdir.mk>

Index: othersrc/external/historical/eawk/extend/db/db.c
diff -u othersrc/external/historical/eawk/extend/db/db.c:1.1 othersrc/external/historical/eawk/extend/db/db.c:1.2
--- othersrc/external/historical/eawk/extend/db/db.c:1.1	Fri May 31 05:56:37 2013
+++ othersrc/external/historical/eawk/extend/db/db.c	Thu Jun  6 01:45:57 2013
@@ -63,26 +63,37 @@ n2ptr(int64_t n)
 	return u.p;
 }
 
-#if 0
-/* set an array field */
-static int
-set_array_field(eawk_t *eawk, awkcell_t *array, const char *skey, int64_t keynum, const char *sval, int64_t valnum)
+/* parse the args on the way in, and set DBT struct accordingly */
+static inline void
+getargs(eawk_t *eawk, awkcell_t *array, DBT *dbt)
 {
-	char	key[32];
-	char	val[32];
+	awkcell_t	*cell;
 
-	if (skey == NULL) {
-		snprintf(key, sizeof(key), "%" PRIi64, (int64_t)keynum);
-		skey = key;
+	memset(dbt, 0x0, sizeof(*dbt));
+	if (!(array->type & EAWK_ARRAY)) {
+		eawk_new_array(eawk, array);
 	}
-	if (sval == NULL) {
-		snprintf(val, sizeof(val), "%" PRIi64, (int64_t)valnum);
-		sval = val;
+	if ((cell = eawk_array_lookup((awkarray_t *)(void *)array->str, "data")) != NULL) {
+		dbt->data = eawk_getsval(eawk, cell);
+	}
+	if ((cell = eawk_array_lookup((awkarray_t *)(void *)array->str, "size")) != NULL) {
+		dbt->size = (size_t)eawk_getfval(eawk, cell);
 	}
-	eawk_var_set(eawk, skey, sval, atof(sval), EAWK_STR|EAWK_NUM, (awkarray_t *)(void *)array->str);
-	return 1;
 }
-#endif
+
+/* set the args on the way out, from the DBT struct */
+static inline void
+putargs(eawk_t *eawk, awkcell_t *array, DBT *dbt)
+{
+	awkcell_t	*cell;
+
+	cell = eawk_var_set(eawk, "data", (const char *)dbt->data,
+		0.0, EAWK_STR, (awkarray_t *)(void *)array->str);
+	/* now make sure and set the whole value, just in case of embedded NUL bytes */
+	eawk_setsvalN(eawk, cell, dbt->data, dbt->size);
+	eawk_var_set(eawk, "size", NULL, (awknum_t)dbt->size,
+		EAWK_NUM, (awkarray_t *)(void *)array->str);
+}
 
 /* define the constants which relate to the CPP definitions */
 static int
@@ -124,6 +135,8 @@ eawk_db_dbopen(void *veawk, char *name, 
 	RECNOINFO	 recno;
 	HASHINFO	 hash;
 	DBTYPE		 d;
+	awkcell_t	*array;
+	awkcell_t	*cell;
 	eawk_t		*eawk = (eawk_t *)veawk;
 	mode_t		 mode;
 	void		*openinfo;
@@ -131,29 +144,35 @@ eawk_db_dbopen(void *veawk, char *name, 
 	DB		*db;
 
 	USE_ARG(name);
-	if (argc != 4) {
-		eawk_setfval(eawk, eawk->fp->retval, (awknum_t)0);
-		return eawk->fp->retval;
-	}
-	memset(&btree, 0x0, sizeof(btree));
-	memset(&recno, 0x0, sizeof(recno));
-	memset(&hash, 0x0, sizeof(hash));
-	/* get data off stack */
-	file = (const char *)eawk_getsval(eawk, a[0]);
-	flags = (int)eawk_getfval(eawk, a[1]);
-	mode = (mode_t)eawk_getfval(eawk, a[2]);
-	type = (const char *)eawk_getsval(eawk, a[3]);
-	if (strcmp(type, "btree") == 0) {
-		openinfo = &btree;
-		d = DB_BTREE;
-	} else if (strcmp(type, "hash") == 0) {
-		openinfo = &hash;
-		d = DB_HASH;
-	} else {
-		openinfo = &recno;
-		d = DB_RECNO;
+	db = NULL;
+	if (argc == 4) {
+		memset(&btree, 0x0, sizeof(btree));
+		memset(&recno, 0x0, sizeof(recno));
+		memset(&hash, 0x0, sizeof(hash));
+		/* get data off stack */
+		file = (const char *)eawk_getsval(eawk, a[0]);
+		flags = (int)eawk_getfval(eawk, a[1]);
+		mode = (mode_t)eawk_getfval(eawk, a[2]);
+		array = a[3];
+		type = "btree";
+		if ((cell = eawk_array_lookup((awkarray_t *)(void *)array->str, "type")) != NULL) {
+			type = eawk_getsval(eawk, cell);
+		}
+		if (strcmp(type, "btree") == 0) {
+			openinfo = &btree;
+			d = DB_BTREE;
+			if ((cell = eawk_array_lookup((awkarray_t *)(void *)array->str, "lorder")) != NULL) {
+				btree.lorder = (int)eawk_getfval(eawk, cell);
+			}
+		} else if (strcmp(type, "hash") == 0) {
+			openinfo = &hash;
+			d = DB_HASH;
+		} else {
+			openinfo = &recno;
+			d = DB_RECNO;
+		}
+		db = dbopen(file, flags, mode, d, openinfo);
 	}
-	db = dbopen(file, flags, mode, d, openinfo);
 	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)p2num(db));
 	return eawk->fp->retval;
 }
@@ -185,23 +204,18 @@ eawk_db_dbdel(void *veawk, char *name, i
 {
 	unsigned	 flags;
 	eawk_t		*eawk = (eawk_t *)veawk;
-	char		 null[1];
-	DBT		 k;
+	DBT		 key;
 	int		 rc;
 	DB		*db;
 
 	USE_ARG(name);
 	rc = -1;
-	null[0] = 0x0;
 	if (argc == 3) {
 		/* get data off stack */
 		if ((db = (DB *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
-			if ((k.data = eawk_getsval(eawk, a[1])) == NULL) {
-				k.data = null;
-			}
-			k.size = strlen(k.data);
+			getargs(eawk, a[1], &key);
 			flags = (unsigned)eawk_getfval(eawk, a[2]);
-			rc = (*db->del)(db, &k, flags);
+			rc = (*db->del)(db, &key, flags);
 		}
 	}
 	/* return code */
@@ -236,34 +250,27 @@ eawk_db_dbget(void *veawk, char *name, i
 {
 	unsigned	 flags;
 	eawk_t		*eawk = (eawk_t *)veawk;
-	char		 null[1];
-	char		*val;
-	DBT		 k;
-	DBT		 v;
-	size_t		 cc;
+	DBT		 key;
+	DBT		 val;
+	int		 rc;
 	DB		*db;
 
 	USE_ARG(name);
-	val = NULL;
-	null[0] = 0x0;
-	cc = 0;
-	if (argc == 3) {
+	rc = -1;
+	if (argc == 4) {
 		/* get data off stack */
-		memset(&v, 0x0, sizeof(v));
 		if ((db = (DB *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
-			if ((k.data = eawk_getsval(eawk, a[1])) == NULL) {
-				k.data = null;
-			}
-			k.size = strlen(k.data);
-			flags = (unsigned)eawk_getfval(eawk, a[2]);
-			if ((*db->get)(db, &k, &v, flags) == 0) {
-				val = v.data;
-				cc = v.size;
+			getargs(eawk, a[1], &key);
+			getargs(eawk, a[2], &val);
+			flags = (unsigned)eawk_getfval(eawk, a[3]);
+			if ((rc = (*db->get)(db, &key, &val, flags)) == 0) {
+				putargs(eawk, a[1], &key);
+				putargs(eawk, a[2], &val);
 			}
 		}
 	}
 	/* return code */
-	eawk_setsvalN(eawk, eawk->fp->retval, val, cc);
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
 	return eawk->fp->retval;
 }
 
@@ -273,29 +280,20 @@ eawk_db_dbput(void *veawk, char *name, i
 {
 	unsigned	 flags;
 	eawk_t		*eawk = (eawk_t *)veawk;
-	char		 null[1];
-	DBT		 k;
-	DBT		 v;
+	DBT		 key;
+	DBT		 val;
 	int		 rc;
 	DB		*db;
 
 	USE_ARG(name);
 	rc = -1;
-	null[0] = 0x0;
 	if (argc == 4) {
 		/* get data off stack */
-		memset(&v, 0x0, sizeof(v));
 		if ((db = (DB *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
-			if ((k.data = eawk_getsval(eawk, a[1])) == NULL) {
-				k.data = null;
-			}
-			k.size = strlen(k.data);
-			if ((v.data = eawk_getsval(eawk, a[2])) == NULL) {
-				v.data = null;
-			}
-			v.size = strlen(v.data);
+			getargs(eawk, a[1], &key);
+			getargs(eawk, a[2], &val);
 			flags = (unsigned)eawk_getfval(eawk, a[3]);
-			rc = (*db->put)(db, &k, &v, flags);
+			rc = (*db->put)(db, &key, &val, flags);
 		}
 	}
 	/* return code */
@@ -332,60 +330,27 @@ eawk_db_dbseq(void *veawk, char *name, i
 {
 	unsigned	 flags;
 	eawk_t		*eawk = (eawk_t *)veawk;
-	char		 null[1];
-	char		*val;
-	DBT		 k;
-	DBT		 v;
-	size_t		 cc;
+	DBT		 key;
+	DBT		 val;
+	int		 rc;
 	DB		*db;
 
 	USE_ARG(name);
-	val = NULL;
-	cc = 0;
-	null[0] = 0x0;
-	if (argc == 3) {
+	rc = -1;
+	if (argc == 4) {
 		/* get data off stack */
-		memset(&v, 0x0, sizeof(v));
 		if ((db = (DB *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
-			if ((k.data = eawk_getsval(eawk, a[1])) == NULL) {
-				k.data = null;
-			}
-			k.size = strlen(k.data);
-			flags = (unsigned)eawk_getfval(eawk, a[2]);
-			if ((*db->seq)(db, &k, &v, flags) == 0) {
-				val = v.data;
-				cc = v.size;
+			getargs(eawk, a[1], &key);
+			getargs(eawk, a[2], &val);
+			flags = (unsigned)eawk_getfval(eawk, a[3]);
+			if ((rc = (*db->seq)(db, &key, &val, flags)) == 0) {
+				putargs(eawk, a[1], &key);
+				putargs(eawk, a[2], &val);
 			}
 		}
 	}
 	/* return code */
-	eawk_setsvalN(eawk, eawk->fp->retval, val, cc);
-	return eawk->fp->retval;
-}
-
-/* allocate function */
-static awkcell_t *
-eawk_db_alloc(void *veawk, char *name, int argc, awkcell_t **a)
-{
-	size_t		 size;
-	eawk_t		*eawk = (eawk_t *)veawk;
-	char		*s;
-	void		*v;
-
-	USE_ARG(name);
-	size = sizeof(RECNOINFO);
-	if (argc == 1) {
-		/* get data off stack */
-		s = eawk_getsval(eawk, a[0]);
-		if (strcmp(s, "btree") == 0) {
-			size = sizeof(BTREEINFO);
-		} else if (strcmp(s, "hash") == 0) {
-			size = sizeof(HASHINFO);
-		}
-	}
-	v = calloc(size, 1);
-	/* return code */
-	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)p2num(v));
+	eawk_setfval(eawk, eawk->fp->retval, rc);
 	return eawk->fp->retval;
 }
 
@@ -410,7 +375,6 @@ eawk_use_db(eawk_t *eawk)
 		eawk_register_func(eawk, "db", "dbput", eawk_db_dbput);
 		eawk_register_func(eawk, "db", "dbseq", eawk_db_dbseq);
 		eawk_register_func(eawk, "db", "dbsync", eawk_db_dbsync);
-		eawk_register_func(eawk, "db", "db_alloc", eawk_db_alloc);
 	}
 	return 1;
 }

Index: othersrc/external/historical/eawk/scripts/tart.sh
diff -u othersrc/external/historical/eawk/scripts/tart.sh:1.1 othersrc/external/historical/eawk/scripts/tart.sh:1.2
--- othersrc/external/historical/eawk/scripts/tart.sh:1.1	Wed Jun  5 00:55:26 2013
+++ othersrc/external/historical/eawk/scripts/tart.sh	Thu Jun  6 01:45:57 2013
@@ -1,6 +1,6 @@
 #! /bin/sh
 
-# name is because i watched the tobias episode (S4E6) of Arrested Development
+# name is because i watched the tobias episode (S4E5) of Arrested Development
 
 if [ $# -lt 1 ]; then
 	echo "Usage: $0 archive" >&2

Added files:

Index: othersrc/external/historical/eawk/extend/curses/Makefile
diff -u /dev/null othersrc/external/historical/eawk/extend/curses/Makefile:1.1
--- /dev/null	Thu Jun  6 01:45:57 2013
+++ othersrc/external/historical/eawk/extend/curses/Makefile	Thu Jun  6 01:45:57 2013
@@ -0,0 +1,16 @@
+#	$NetBSD: Makefile,v 1.1 2013/06/06 01:45:57 agc Exp $
+
+.include <bsd.own.mk>
+
+DIST=	${.CURDIR}/../../dist
+.PATH:	${DIST}
+
+LIB=	eawk-curses
+SRCS=	curses.c
+CPPFLAGS+=	-I. -I${DIST}
+MKMAN=	no
+LDADD+=	-lcurses
+
+WARNS=	5
+
+.include <bsd.lib.mk>
Index: othersrc/external/historical/eawk/extend/curses/curses.c
diff -u /dev/null othersrc/external/historical/eawk/extend/curses/curses.c:1.1
--- /dev/null	Thu Jun  6 01:45:57 2013
+++ othersrc/external/historical/eawk/extend/curses/curses.c	Thu Jun  6 01:45:57 2013
@@ -0,0 +1,416 @@
+/*-
+ * Copyright (c) 2013 Alistair Crooks <a...@netbsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <curses.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "eawk.h"
+
+#ifndef USE_ARG
+#define USE_ARG(x)  /*LINTED*/(void)&x
+#endif
+
+/* convert number to ptr */
+static int64_t
+p2num(void *p)
+{
+	union {
+		void	*p;
+		int64_t	 n;
+	} u;
+
+	u.p = p;
+	return u.n;
+}
+
+/* convert ptr to number */
+static void *
+n2ptr(int64_t n)
+{
+	union {
+		void	*p;
+		int64_t	 n;
+	} u;
+
+	u.n = n;
+	return u.p;
+}
+
+/* define the constants which relate to the CPP definitions */
+static int
+eawk_curses_constants(eawk_t *eawk)
+{
+	eawk_define_constant(eawk, "ACS_DARROW", ACS_DARROW);
+	eawk_define_constant(eawk, "ACS_HLINE", ACS_HLINE);
+	eawk_define_constant(eawk, "ACS_LARROW", ACS_LARROW);
+	eawk_define_constant(eawk, "ACS_LLCORNER", ACS_LLCORNER);
+	eawk_define_constant(eawk, "ACS_LRCORNER", ACS_LRCORNER);
+	eawk_define_constant(eawk, "ACS_UARROW", ACS_UARROW);
+	eawk_define_constant(eawk, "ACS_ULCORNER", ACS_ULCORNER);
+	eawk_define_constant(eawk, "ACS_URCORNER", ACS_URCORNER);
+	eawk_define_constant(eawk, "ACS_RARROW", ACS_RARROW);
+	eawk_define_constant(eawk, "ACS_VLINE", ACS_VLINE);
+	eawk_define_constant(eawk, "ERR", ERR);
+	eawk_define_constant(eawk, "ERR", ERR);
+	eawk_define_constant(eawk, "OK", OK);
+	return 1;
+}
+
+/* extension module to provide curses functionality to eawk */
+
+/* endwin function */
+static awkcell_t *
+eawk_curses_endwin(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	eawk_t		*eawk = (eawk_t *)veawk;
+	int		 rc;
+
+	USE_ARG(a);
+	USE_ARG(name);
+	USE_ARG(argc);
+	rc = endwin();
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* initscr function */
+static awkcell_t *
+eawk_curses_initscr(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	WINDOW		*win;
+	eawk_t		*eawk = (eawk_t *)veawk;
+
+	USE_ARG(a);
+	USE_ARG(name);
+	USE_ARG(argc);
+	win = initscr();
+	eawk_define_constant(eawk, "LINES", LINES);
+	eawk_define_constant(eawk, "COLS", COLS);
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)p2num(win));
+	return eawk->fp->retval;
+}
+
+/* touchwin function */
+static awkcell_t *
+eawk_curses_touchwin(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	eawk_t		*eawk = (eawk_t *)veawk;
+	WINDOW		*win;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = ERR;
+	if (argc == 1) {
+		/* get data off stack */
+		if ((win = (WINDOW *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
+			rc = touchwin(win);
+		}
+	}
+	/* return code */
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* waddch function */
+static awkcell_t *
+eawk_curses_waddch(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	eawk_t		*eawk = (eawk_t *)veawk;
+	WINDOW		*win;
+	int		 ch;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = ERR;
+	if (argc == 2) {
+		/* get data off stack */
+		if ((win = (WINDOW *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
+			ch = (int)eawk_getfval(eawk, a[1]);
+			rc = waddch(win, ch);
+		}
+	}
+	/* return code */
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* waddstr function */
+static awkcell_t *
+eawk_curses_waddstr(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	const char	*s;
+	eawk_t		*eawk = (eawk_t *)veawk;
+	WINDOW		*win;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = ERR;
+	if (argc == 2) {
+		/* get data off stack */
+		if ((win = (WINDOW *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
+			s = (const char *)eawk_getsval(eawk, a[1]);
+			rc = waddstr(win, s);
+		}
+	}
+	/* return code */
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* wclear function */
+static awkcell_t *
+eawk_curses_wclear(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	eawk_t		*eawk = (eawk_t *)veawk;
+	WINDOW		*win;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = ERR;
+	if (argc == 1) {
+		/* get data off stack */
+		if ((win = (WINDOW *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
+			rc = wclear(win);
+		}
+	}
+	/* return code */
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* werase function */
+static awkcell_t *
+eawk_curses_werase(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	eawk_t		*eawk = (eawk_t *)veawk;
+	WINDOW		*win;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = ERR;
+	if (argc == 1) {
+		/* get data off stack */
+		if ((win = (WINDOW *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
+			rc = werase(win);
+		}
+	}
+	/* return code */
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* wgetch function */
+static awkcell_t *
+eawk_curses_wgetch(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	eawk_t		*eawk = (eawk_t *)veawk;
+	WINDOW		*win;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = ERR;
+	if (argc == 1) {
+		/* get data off stack */
+		if ((win = (WINDOW *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
+			rc = wgetch(win);
+		}
+	}
+	/* return code */
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* wmove function */
+static awkcell_t *
+eawk_curses_wmove(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	eawk_t		*eawk = (eawk_t *)veawk;
+	WINDOW		*win;
+	int		 rc;
+	int		 y;
+	int		 x;
+
+	USE_ARG(name);
+	rc = ERR;
+	if (argc == 3) {
+		/* get data off stack */
+		if ((win = (WINDOW *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
+			y = (int)eawk_getfval(eawk, a[1]);
+			x = (int)eawk_getfval(eawk, a[2]);
+			rc = wmove(win, y, x);
+		}
+	}
+	/* return code */
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* newwin function */
+static awkcell_t *
+eawk_curses_newwin(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	eawk_t		*eawk = (eawk_t *)veawk;
+	WINDOW		*win;
+	int		 begy;
+	int		 begx;
+	int		 y;
+	int		 x;
+
+	USE_ARG(name);
+	win = NULL;
+	if (argc == 4) {
+		/* get data off stack */
+		y = (int)eawk_getfval(eawk, a[0]);
+		x = (int)eawk_getfval(eawk, a[1]);
+		begy = (int)eawk_getfval(eawk, a[2]);
+		begx = (int)eawk_getfval(eawk, a[3]);
+		win = newwin(y, x, begy, begx);
+	}
+	/* return code */
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)p2num(win));
+	return eawk->fp->retval;
+}
+
+/* wrefresh function */
+static awkcell_t *
+eawk_curses_wrefresh(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	eawk_t		*eawk = (eawk_t *)veawk;
+	WINDOW		*win;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = ERR;
+	if (argc == 1) {
+		/* get data off stack */
+		if ((win = (WINDOW *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
+			rc = wrefresh(win);
+		}
+	}
+	/* return code */
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* wresize function */
+static awkcell_t *
+eawk_curses_wresize(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	eawk_t		*eawk = (eawk_t *)veawk;
+	WINDOW		*win;
+	int		 rc;
+	int		 y;
+	int		 x;
+
+	USE_ARG(name);
+	rc = ERR;
+	if (argc == 3) {
+		/* get data off stack */
+		if ((win = (WINDOW *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
+			y = (int)eawk_getfval(eawk, a[1]);
+			x = (int)eawk_getfval(eawk, a[2]);
+			rc = wresize(win, y, x);
+		}
+	}
+	/* return code */
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* wstandout function */
+static awkcell_t *
+eawk_curses_wstandout(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	eawk_t		*eawk = (eawk_t *)veawk;
+	WINDOW		*win;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = ERR;
+	if (argc == 1) {
+		/* get data off stack */
+		if ((win = (WINDOW *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
+			rc = wstandout(win);
+		}
+	}
+	/* return code */
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* wstandend function */
+static awkcell_t *
+eawk_curses_wstandend(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	eawk_t		*eawk = (eawk_t *)veawk;
+	WINDOW		*win;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = ERR;
+	if (argc == 1) {
+		/* get data off stack */
+		if ((win = (WINDOW *)n2ptr((int64_t)eawk_getfval(eawk, a[0]))) != NULL) {
+			rc = wstandend(win);
+		}
+	}
+	/* return code */
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+
+
+/*******************************************************************/
+/* now the glue to register functions when use("curses") is called */
+/*******************************************************************/
+
+int eawk_use_curses(eawk_t */*eawk*/);
+
+/* register digest functions */
+int
+eawk_use_curses(eawk_t *eawk)
+{
+	if (eawk_find_lib(eawk, "curses") < 0) {
+		eawk_curses_constants(eawk);
+		eawk_register_func(eawk, "curses", "endwin", eawk_curses_endwin);
+		eawk_register_func(eawk, "curses", "initscr", eawk_curses_initscr);
+		eawk_register_func(eawk, "curses", "newwin", eawk_curses_newwin);
+		eawk_register_func(eawk, "curses", "touchwin", eawk_curses_touchwin);
+		eawk_register_func(eawk, "curses", "waddch", eawk_curses_waddch);
+		eawk_register_func(eawk, "curses", "waddstr", eawk_curses_waddstr);
+		eawk_register_func(eawk, "curses", "wclear", eawk_curses_wclear);
+		eawk_register_func(eawk, "curses", "werase", eawk_curses_werase);
+		eawk_register_func(eawk, "curses", "wgetch", eawk_curses_wgetch);
+		eawk_register_func(eawk, "curses", "wmove", eawk_curses_wmove);
+		eawk_register_func(eawk, "curses", "wrefresh", eawk_curses_wrefresh);
+		eawk_register_func(eawk, "curses", "wresize", eawk_curses_wresize);
+		eawk_register_func(eawk, "curses", "wstandend", eawk_curses_wstandend);
+		eawk_register_func(eawk, "curses", "wstandout", eawk_curses_wstandout);
+	}
+	return 1;
+}
Index: othersrc/external/historical/eawk/extend/curses/shlib_version
diff -u /dev/null othersrc/external/historical/eawk/extend/curses/shlib_version:1.1
--- /dev/null	Thu Jun  6 01:45:57 2013
+++ othersrc/external/historical/eawk/extend/curses/shlib_version	Thu Jun  6 01:45:57 2013
@@ -0,0 +1,2 @@
+major=0
+minor=0

Index: othersrc/external/historical/eawk/extend/threshold/Makefile
diff -u /dev/null othersrc/external/historical/eawk/extend/threshold/Makefile:1.1
--- /dev/null	Thu Jun  6 01:45:57 2013
+++ othersrc/external/historical/eawk/extend/threshold/Makefile	Thu Jun  6 01:45:57 2013
@@ -0,0 +1,16 @@
+#	$NetBSD: Makefile,v 1.1 2013/06/06 01:45:57 agc Exp $
+
+.include <bsd.own.mk>
+
+DIST=	${.CURDIR}/../../dist
+.PATH:	${DIST}
+
+LIB=	eawk-threshold
+SRCS=	threshold.c
+CPPFLAGS+=	-I. -I${DIST}
+MKMAN=	no
+LDADD+=	-lthreshold
+
+WARNS=	5
+
+.include <bsd.lib.mk>
Index: othersrc/external/historical/eawk/extend/threshold/shlib_version
diff -u /dev/null othersrc/external/historical/eawk/extend/threshold/shlib_version:1.1
--- /dev/null	Thu Jun  6 01:45:57 2013
+++ othersrc/external/historical/eawk/extend/threshold/shlib_version	Thu Jun  6 01:45:57 2013
@@ -0,0 +1,2 @@
+major=0
+minor=0
Index: othersrc/external/historical/eawk/extend/threshold/threshold.c
diff -u /dev/null othersrc/external/historical/eawk/extend/threshold/threshold.c:1.1
--- /dev/null	Thu Jun  6 01:45:57 2013
+++ othersrc/external/historical/eawk/extend/threshold/threshold.c	Thu Jun  6 01:45:57 2013
@@ -0,0 +1,335 @@
+/*-
+ * Copyright (c) 2013 Alistair Crooks <a...@netbsd.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <threshold.h>
+
+#include "eawk.h"
+
+#ifndef USE_ARG
+#define USE_ARG(x)  /*LINTED*/(void)&x
+#endif
+
+/* convert number to ptr */
+static int64_t
+p2num(void *p)
+{
+	union {
+		void	*p;
+		int64_t	 n;
+	} u;
+
+	u.p = p;
+	return u.n;
+}
+
+/* convert ptr to number */
+static void *
+n2ptr(int64_t n)
+{
+	union {
+		void	*p;
+		int64_t	 n;
+	} u;
+
+	u.n = n;
+	return u.p;
+}
+
+/* set the args on the way out, from the DBT struct */
+static inline void
+putargs(eawk_t *eawk, awkcell_t *array, void *data, size_t size)
+{
+	awkcell_t	*cell;
+
+	cell = eawk_var_set(eawk, "data", (const char *)data,
+		0.0, EAWK_STR, (awkarray_t *)(void *)array->str);
+	/* now make sure and set the whole value, just in case of embedded NUL bytes */
+	eawk_setsvalN(eawk, cell, data, size);
+	eawk_var_set(eawk, "size", NULL, (awknum_t)size,
+		EAWK_NUM, (awkarray_t *)(void *)array->str);
+}
+
+/* define the constants which relate to the CPP definitions */
+static int
+eawk_threshold_constants(eawk_t *eawk)
+{
+	eawk_define_constant(eawk, "THRESH_MAGIC_LENGTH", THRESH_MAGIC_LENGTH);
+	eawk_define_constant(eawk, "THRESH_MAX_SHARES", THRESH_MAX_SHARES);
+	eawk_define_constant(eawk, "THRESH_SPLIT_SOURCE", THRESH_SPLIT_SOURCE);
+	eawk_define_constant(eawk, "THRESH_JOIN_DEST", THRESH_JOIN_DEST);
+	return 1;
+}
+
+/* extension module to provide curses functionality to eawk */
+
+/* endwin function */
+static awkcell_t *
+eawk_threshold_thresh_alloc(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	const char	*type;
+	eawk_t		*eawk = (eawk_t *)veawk;
+	void		*v;
+
+	USE_ARG(name);
+	v = NULL;
+	if (argc == 1) {
+		type = eawk_getsval(eawk, a[0]);
+		if (strcmp(type, "header") == 0) {
+			v = calloc(sizeof(thresh_head_t), 1);
+		} else if (strcmp(type, "threshold") == 0) {
+			v = calloc(sizeof(threshold_t), 1);
+		}
+	}
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)p2num(v));
+	return eawk->fp->retval;
+}
+
+/* split function */
+static awkcell_t *
+eawk_threshold_thresh_split(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	threshold_t	*t;
+	eawk_t		*eawk = (eawk_t *)veawk;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = 0;
+	if (argc == 1) {
+		t = (threshold_t *)n2ptr((int64_t)eawk_getfval(eawk, a[0]));
+		rc = thresh_split(t);
+	}
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* end function */
+static awkcell_t *
+eawk_threshold_thresh_end(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	threshold_t	*t;
+	eawk_t		*eawk = (eawk_t *)veawk;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = 0;
+	if (argc == 1) {
+		t = (threshold_t *)n2ptr((int64_t)eawk_getfval(eawk, a[0]));
+		rc = thresh_end(t);
+	}
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* combine function */
+static awkcell_t *
+eawk_threshold_thresh_combine(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	threshold_t	*t;
+	eawk_t		*eawk = (eawk_t *)veawk;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = 0;
+	if (argc == 1) {
+		t = (threshold_t *)n2ptr((int64_t)eawk_getfval(eawk, a[0]));
+		rc = thresh_combine(t);
+	}
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* join function */
+static awkcell_t *
+eawk_threshold_thresh_join(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	threshold_t	*t;
+	eawk_t		*eawk = (eawk_t *)veawk;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = 0;
+	if (argc == 1) {
+		t = (threshold_t *)n2ptr((int64_t)eawk_getfval(eawk, a[0]));
+		rc = thresh_join(t);
+	}
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* parse the args on the way in, and set DBT struct accordingly */
+static inline void
+getargs(eawk_t *eawk, awkcell_t *array, char **data, ssize_t *size)
+{
+	awkcell_t	*cell;
+
+	if (!(array->type & EAWK_ARRAY)) {
+		eawk_new_array(eawk, array);
+	}
+	if ((cell = eawk_array_lookup((awkarray_t *)(void *)array->str, "data")) != NULL) {
+		*data = eawk_getsval(eawk, cell);
+	}
+	if ((cell = eawk_array_lookup((awkarray_t *)(void *)array->str, "size")) != NULL) {
+		*size = (ssize_t)eawk_getfval(eawk, cell);
+	}
+}
+
+/* add share function */
+static awkcell_t *
+eawk_threshold_thresh_add_share(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	threshold_t	*t;
+	unsigned	 share;
+	ssize_t		 size;
+	eawk_t		*eawk = (eawk_t *)veawk;
+	char		*data;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = 0;
+	data = NULL;
+	size = 0;
+	if (argc == 3) {
+		t = (threshold_t *)n2ptr((int64_t)eawk_getfval(eawk, a[0]));
+		share = (unsigned)eawk_getfval(eawk, a[1]);
+		getargs(eawk, a[2], &data, &size);
+		rc = thresh_add_share(t, share, data, size);
+	} else if (argc == 4) {
+		t = (threshold_t *)n2ptr((int64_t)eawk_getfval(eawk, a[0]));
+		share = (unsigned)eawk_getfval(eawk, a[1]);
+		data = eawk_getsval(eawk, a[2]);
+		size = (ssize_t)eawk_getfval(eawk, a[3]);
+		rc = thresh_add_share(t, share, data, size);
+	}
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* init function */
+static awkcell_t *
+eawk_threshold_thresh_init(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	threshold_t	*t;
+	const char	*type;
+	unsigned	 thresh;
+	unsigned	 total;
+	eawk_t		*eawk = (eawk_t *)veawk;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = 0;
+	if (argc == 4) {
+		t = (threshold_t *)n2ptr((int64_t)eawk_getfval(eawk, a[0]));
+		type = eawk_getsval(eawk, a[1]);
+		thresh = (unsigned)eawk_getfval(eawk, a[2]);
+		total = (unsigned)eawk_getfval(eawk, a[3]);
+		rc = thresh_init(t, type, thresh, total);
+	}
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* get share function */
+static awkcell_t *
+eawk_threshold_thresh_get_share(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	threshold_t	*t;
+	unsigned	 share;
+	size_t		 size;
+	eawk_t		*eawk = (eawk_t *)veawk;
+	void		*data;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = 0;
+	if (argc == 3) {
+		t = (threshold_t *)n2ptr((int64_t)eawk_getfval(eawk, a[0]));
+		share = (unsigned)eawk_getfval(eawk, a[1]);
+		rc = thresh_get_share(t, share, &data, &size);
+		putargs(eawk, a[2], data, size);
+	}
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+/* write share function */
+static awkcell_t *
+eawk_threshold_thresh_write_share(void *veawk, char *name, int argc, awkcell_t **a)
+{
+	threshold_t	*t;
+	const char	*f;
+	unsigned	 share;
+	eawk_t		*eawk = (eawk_t *)veawk;
+	int		 rc;
+
+	USE_ARG(name);
+	rc = 0;
+	if (argc == 3) {
+		t = (threshold_t *)n2ptr((int64_t)eawk_getfval(eawk, a[0]));
+		share = (unsigned)eawk_getfval(eawk, a[1]);
+		f = (const char *)eawk_getsval(eawk, a[2]);
+		rc = thresh_write_share(t, share, f);
+	}
+	eawk_setfval(eawk, eawk->fp->retval, (awknum_t)rc);
+	return eawk->fp->retval;
+}
+
+
+
+
+/*******************************************************************/
+/* now the glue to register functions when use("threshold") is called */
+/*******************************************************************/
+
+int eawk_use_threshold(eawk_t */*eawk*/);
+
+/* register digest functions */
+int
+eawk_use_threshold(eawk_t *eawk)
+{
+	if (eawk_find_lib(eawk, "threshold") < 0) {
+		eawk_threshold_constants(eawk);
+		eawk_register_func(eawk, "threshold", "thresh_add_share", eawk_threshold_thresh_add_share);
+		eawk_register_func(eawk, "threshold", "thresh_alloc", eawk_threshold_thresh_alloc);
+		eawk_register_func(eawk, "threshold", "thresh_combine", eawk_threshold_thresh_combine);
+		eawk_register_func(eawk, "threshold", "thresh_end", eawk_threshold_thresh_end);
+#if 0
+		eawk_register_func(eawk, "threshold", "thresh_fmt_header", eawk_threshold_thresh_fmt_header);
+		eawk_register_func(eawk, "threshold", "thresh_get_header", eawk_threshold_thresh_get_header);
+#endif
+		eawk_register_func(eawk, "threshold", "thresh_get_share", eawk_threshold_thresh_get_share);
+		eawk_register_func(eawk, "threshold", "thresh_init", eawk_threshold_thresh_init);
+		eawk_register_func(eawk, "threshold", "thresh_join", eawk_threshold_thresh_join);
+#if 0
+		eawk_register_func(eawk, "threshold", "thresh_sane_header", eawk_threshold_thresh_sane_header);
+#endif
+		eawk_register_func(eawk, "threshold", "thresh_split", eawk_threshold_thresh_split);
+		eawk_register_func(eawk, "threshold", "thresh_write_share", eawk_threshold_thresh_write_share);
+	}
+	return 1;
+}

Index: othersrc/external/historical/eawk/scripts/rain.sh
diff -u /dev/null othersrc/external/historical/eawk/scripts/rain.sh:1.1
--- /dev/null	Thu Jun  6 01:45:57 2013
+++ othersrc/external/historical/eawk/scripts/rain.sh	Thu Jun  6 01:45:57 2013
@@ -0,0 +1,36 @@
+#! /bin/sh
+
+env LD_LIBRARY_PATH=lib:extend/curses bin/eawk '
+BEGIN {
+	use("curses");
+	w = initscr();
+	cols = COLS - 4; lines = LINES - 4;
+	for (j = 4 ; j >= 0 ; --j) { xpos[j] = (rand() * cols) + 2; ypos[j] = (rand() * lines) + 2; }
+	for (j = 0; 1; ) {
+		x = (rand() * cols) + 2;
+		y = (rand() * lines) + 2;
+		wmove(w, y, x); waddstr(w, ".");
+		wmove(w, ypos[j], xpos[j]); waddstr(w, "o");
+		if (j-- == 0) j = 4;
+		wmove(w, ypos[j], xpos[j]); waddstr(w, "O");
+		if (j-- == 0) j = 4;
+		wmove(w, ypos[j] - 1, xpos[j]); waddstr(w, "-");
+		wmove(w, ypos[j], xpos[j] - 1); waddstr(w, "|.|");
+		wmove(w, ypos[j] + 1, xpos[j]); waddstr(w, "-");
+		if (j-- == 0) j = 4;
+		wmove(w, ypos[j] - 2, xpos[j]); waddstr(w, "-");
+		wmove(w, ypos[j] - 1, xpos[j] - 1); waddstr(w, "/ \\");
+		wmove(w, ypos[j], xpos[j] - 2); waddstr(w, "| O |");
+		wmove(w, ypos[j] + 1, xpos[j] - 1); waddstr(w, "\\ /");
+		wmove(w, ypos[j] + 2, xpos[j]); waddstr(w, "-");
+		if (j-- == 0) j = 4;
+		wmove(w, ypos[j] - 2, xpos[j]); waddstr(w, " ");
+		wmove(w, ypos[j] - 1, xpos[j] - 1); waddstr(w, "   ");
+		wmove(w, ypos[j], xpos[j] - 2); waddstr(w, "     ");
+		wmove(w, ypos[j] + 1, xpos[j] - 1); waddstr(w, "   ");
+		wmove(w, ypos[j] + 2, xpos[j]); waddstr(w, " ");
+		xpos[j] = x;
+		ypos[j] = y;
+		wrefresh(w);
+	}
+}'
Index: othersrc/external/historical/eawk/scripts/test-thresh.sh
diff -u /dev/null othersrc/external/historical/eawk/scripts/test-thresh.sh:1.1
--- /dev/null	Thu Jun  6 01:45:57 2013
+++ othersrc/external/historical/eawk/scripts/test-thresh.sh	Thu Jun  6 01:45:57 2013
@@ -0,0 +1,9 @@
+#! /bin/sh
+
+cp $1 $1.test
+sh scripts/threshold.sh -t 5/10 -s $1.test
+ls -al $1.test $1.test.*
+codecs hexdump $1.test.000
+sh scripts/threshold.sh -t 5/10 $1.test
+diff $1.test $1.test.joined
+rm -f $1.test $1.test.*
Index: othersrc/external/historical/eawk/scripts/threshold.sh
diff -u /dev/null othersrc/external/historical/eawk/scripts/threshold.sh:1.1
--- /dev/null	Thu Jun  6 01:45:57 2013
+++ othersrc/external/historical/eawk/scripts/threshold.sh	Thu Jun  6 01:45:57 2013
@@ -0,0 +1,41 @@
+#! /bin/sh
+
+alg="ida"
+splitting=0
+thresh=5
+total=10
+
+while [ $# -gt 0 ]; do
+	case "$1" in
+	-a)	alg=$2; shift ;;
+	-s)	splitting=1 ;;
+	-t)	thresh=${2%/*}; total=${2#*/}; shift ;;
+	*)	break ;;
+	esac
+	shift
+done
+
+if [ $# -lt 1 ]; then
+	echo "Usage: threshold [-t a/b] [-a algorithm] [-s] file" >&2
+	exit 1
+fi
+
+env LD_LIBRARY_PATH=lib:extend/threshold bin/eawk \
+	-v f=$1 -v alg=${alg} -v thresh=${thresh} -v shares=${total} -v splitting=${splitting} '
+BEGIN {
+	use("threshold");
+	t = thresh_alloc("threshold");
+	if (splitting) {
+		if (!thresh_init(t, alg, thresh, shares)) print "phooey#1"
+		if (!thresh_add_share(t, THRESH_SPLIT_SOURCE, f, -1)) print "phooey#2"
+		if (!thresh_split(t)) print "phooey#3"
+		for (i = 0 ; i < shares ; i++)
+			thresh_write_share(t, i, sprintf("%s.%03d", f, i))
+	} else {
+		for (i = 1 ; i <= thresh ; i++)
+			thresh_add_share(t, i - 1, sprintf("%s.%03d", f, i), -1);
+		thresh_combine(t);
+		thresh_write_share(t, THRESH_JOIN_DEST, sprintf("%s.joined", f))
+	}
+	thresh_end(t)
+}'

Reply via email to