AutoGen Definitions options;

export = <<- _EOExport_
	#include <stddef.h>

	extern size_t       separator_str_len;
	_EOExport_;

include = <<- _EOInclude_
	size_t separator_str_len = 6;

	extern void init_unshar (void);
	_EOInclude_;

#define NEED_AUTHORS
prog-name   = `progname=unshar; echo $progname`;
#include shar-std.def

prog-title  = 'unpack a shar archive';
argument    = '[<file>...]';

detail = <<- _EODetail_
	Unshar scans the input files (typically email messages) looking for
	the start of a shell archive.  If no files are given, then standard
	input is processed instead.  It then passes each archive discovered
	through an invocation of the shell program to unpack it.
	_EODetail_;

main = {
    main-type    = for-each;
    handler-proc = unshar_file;
    handler-type = file-r;
    stdin-input;
    main-init    = '    init_unshar ();';
};

exit-desc[1]  = 'There was an error in command usage.';

exit-name[2]  = popen-problem;
exit-desc[2]  = 'cannot spawn or write to a shell process';

exit-name[3]  = cannot-create;
exit-desc[3]  = 'cannot create output file';

exit-name[4]  = bad-directory;
exit-desc[4]  = 'the working directory structure is invalid';

exit-name[5]  = NOMEM;
exit-desc[5]  = 'memory allocation failure';

exit-name[6]  = invalid;
exit-desc[6]  = 'invalid input, does not contain a shar file';

help-value;

flag = {
    name        = directory;
    value       = d;
    arg-type    = string;
    arg-name    = dir;
    descrip     = 'unpack into the directory @file{dir}';

    doc = <<- _EODoc_
	The input file names are relative to the current directory
	when the program was started.  This option tells @command{unshar}
	to insert a @code{cd <dir>} commad at the start of the
	@command{shar} text written to the shell.
	_EODoc_;
};

flag = {
    name        = overwrite;
    value       = c;
    descrip     = 'overwrite any pre-existing files';
    doc = <<- _EODoc_
	This option is passed through as an option to the shar file.  Many
	shell archive scripts accept a @option{-c} argument to indicate that
	existing files should be overwritten.
	_EODoc_;
};

flag = {
    name        = force;
    value       = f;
    aliases     = overwrite;
};

flag = {
    name        = split-at;
    value       = E;
    arg-type    = string;
    arg-name    = split-mark;
    descrip     = 'split input on @var{split-mark} lines';
    arg-default = "exit 0";
    flag-code   =
        '    separator_str_len = strlen (pOptDesc->optArg.argString);';
    settable;

    doc = <<- _EODoc_
	With this option, @command{unshar} isolates each different shell archive
	from the others which have been placed in the same file, unpacking each
	in turn, from the beginning of the file to the end.  Its proper
	operation relies on the fact that many shar files are terminated by a
	readily identifiable string at the start of the last line.

	For example, noticing that most `.signatures' have a double hyphen
	("--") on a line right before them, one can then sometimes use
	@code{--split-at=--}.  The signature will then be skipped, along with
	the headers of the following message.
	_EODoc_;
};

flag = {
    name        = exit-0;
    value       = e;
    flags-cant  = split-at;
    descrip     = 'split input on "exit 0" lines';
    flag-code   = '    SET_OPT_SPLIT_AT("exit 0");';

    doc = <<- _EODoc_
	Most shell archives end with a line consisting of simply "exit 0".
	This option is equivalent to (and conflicts with)
	@code{--split-at="exit 0"}.
	_EODoc_;
};

flag = {
    name        = debug;
    value       = D;
    descrip     = 'debug the shell code';
    doc = <<- _EODoc_
	"set -x" will be emitted into the code the shell interprets.
	_EODoc_;
};

doc-section = {
    ds-type = 'SEE ALSO';
    ds-text = 'shar(1)';
};
