# mkcmd template for nushar (bj)
from '<sys/types.h>'
from '<sys/stat.h>'
from '<stdlib.h>'
from '<unistd.h>'
from '"config.h"'
from '"nushar.h"'
from '"shar.h"'

require "std_help.m" "std_version.m"
%%
static char *rcsid =
	"$Id: nushar.m,v 2.2 2008/07/10 19:45:11 ksb Exp $";
%%

getenv "NUSHAR"
basename "nushar" ""

before {
	update "pfOutputFile = stdout;"
}

boolean 'b' {
	named "fNoDirTree"
	init '0'
	help "flatten the directory tree"
}

boolean 'c' {
	named "fCheckSizes"
	init '0'
	help "generate code to check the sizes of extracted files"
}

boolean 'f' {
	named "fExtractFancy"
	init '0'
	help "generate code to set the date and mode of the extracted files"
}

char* 't' {
	named "pcInstructions"
	param "final_text"
	help "specify a string of instructions to give the user when done"
}

char* 'p' {
	named "pcPrefix"
	param "prefix"
	init '""'
	help "specify a prefix for shar'd files in the archive"
}

char* 'd' {
	named "pcDelimiter"
	param "delimiter"
	init '"END_OF_FILE"'
	help "specify the here-document delimiter (default END_OF_FILE)"
}

int variable "iElementNumber" { }
int variable "iTotalElements" { }

%c
/* parse the -e part/total option
 */
static void
ParseE(cThis, pcArg)
	char cThis, *pcArg;
{
	register char *s;

	if ((char *)0 != (s = strchr(pcArg, '/'))) {
		iElementNumber = atoi(pcArg);
		iTotalElements = atoi(s + 1);
		if(iElementNumber > iTotalElements) {
			fprintf(stderr, "%s: -%c %s is an invalid part specifier, N > M.  maybe you mean %d/%d\n", progname, cThis, pcArg, iTotalElements, iElementNumber);
			exit(1);
		}
	} else {
		fprintf(stderr, "%s: invalid parameter for option `-%c'\n", progname, cThis);
		exit(1);
	}
}
%%

function 'e' {
	excludes "OB"
	param "nn/mm"
	named "ParseE"
	help "specify part N of M total"
}

file 'i' {
	once
	named "pfInputFile" "pcInputFile"
	param "infile"
	help "specify a file with a list of files to shar"
}

file["w"] 'o' {
	excludes "OB"
	named "pfOutputFile" "pcOutputFile"
	param "outfile"
	help "specify an output filename (default stdout)"
}

letter variable "fBinsize" {
	init "'\0'"
}

long 'B' {
	excludes "oe"
	named "iBinsize"
	param "binsize"
	init "55000"
	user "fBinsize = 1;"
	help "specify the target binsize of the shar files"
}

char* 'O' {
	excludes "oe"
	named "pcOutputDir"
	param "destdir"
	help "specify the output directory for binpacked shar files"
}

list {
	named "SetFiles"
	param "files"
	help "list of files to shar"
}

exit {
	named "DoNushar"
	update ""
	aborts "exit(%n());"
}
