#!mkcmd
# $Id: sapply.m,v 1.1 2008/10/22 13:56:19 ksb Exp $
# mkcmd scrip for the sapply version that depends on xclate rather than
# a great implementation of FIFOs (which almost nobody has). -- ksb

require "std_version.m"


basename "sapply" ""

augment action 'V' {
	user "Version();"
}
%i
static char rcsid[] =
	"$Id: sapply.m,v 1.1 2008/10/22 13:56:19 ksb Exp $";
extern char **environ;
extern int errno;
static char acTempSeed[] = "sccsXXXXXX";
%%

action 'Afz' {
}
function 'aeSp' {	# think about -N else
}
number {
	track "fGaveCount"
	param "count"
}
unsigned 'P' {
	track "fGaveP"
	named "iParallel"
	init "1"
	help "number of tasks to run in parallel"
	param "[jobs]"
	noparam "%U = 0;"
}

char* variable "pcCmd" {
	param "cmd"
	help "template command to control each task"
}
%i
static char acDevNull[] = "/dev/null";
%c
static void
MyVersion()
{
	printf("%s: safe directory template: %s\n", progname, acTempSeed);
}

/* The brains of sapply
 */
Sapply()
{
	auto int fdWasIn;

	fdWasIn = dup(0);
	close(0);
	if (0 != open(acDevNull, O_RDONLY, 0666)) {
		fprintf(stderr, "%s: open: %s: %s\n", progname, acDevNull, strerror(errno));
		exit(EX_UNSUPPORTED);
	}
	if (-1 == fdWasIn) {
		fdWasIn = 0;
	}
}
