Subject: Re: Re: [ast-users] command line long options arguments
--------

Here is an example of the shar command which generates or reads a shell
archive.
==============cut here=======================
USAGE_LICENSE="[-author?David Korn 
<[email protected]>][-copyright?Copyright (c) 1999-2010 AT&T Intellectual 
Property][-license?http://www.opensource.org/licenses/cpl1.0.txt][--catalog?std]";

function err_exit
{
        logmsg "$@"
        exit 1
}

usage=$'
[-?
@(#)$Id: shar (AT&T Labs Research) 1999-04-20 $
]
'$USAGE_LICENSE$'
        [+NAME? shar - create a shell archive]
        [+DESCRIPTION?\bshar\b reads one or more input files and creates a
                shell script which when executed will restore the contents
                of these files. This is called a shell archive or \ashar\a.
                The resulting archive is sent to standard output unless the
                \b-o\b option is specified.]
        [a:net-headers?Automatic generation of headers. The \b-n\b option
                must also be specified. If the archive name does not
                contain a \b/\b, then \b/part\b will be append to the
                given archive name when constructing the header.]
        [b:bits-per-code]:[bits?When doing compression, use \b-b \b\abits\a
                as a parameter to \bcompress\b(1). The \b-b\b option turns on
                \b-Z\b.]
        [c:cut-mark?Start the shar with a cut line.]
        [d:here-delimiter]:[string?Use \astring\a to delimit the files 
                in the shar instead of \bSHAR_EOF\b.]
        [f:basenames?Use the basenames for the files.]
        [g:level-for-gzip]:[level?When doing compression, use \b-\b\alevel\a
                as a parameter to \bgzip\b(1). The \b-g\b option turns on
                \b-z\b.]
        [l:whole-size-limit]#[size?Limit the output file size to \asize\a
                bytes. A suffix of \bb\b, \bk\b, or \bm\b can be specified
                to indicate 512-byte blocks, kilobytes, or megabytes
                respectively.]
        [n:archive-name:name]:[name?Override automatically determined name
                for the archive with \aname\a.]
        [o:output-prefix]:[prefix?Save the archive files \aprefix\a\b.01\b
                through \aprefix\a\b.\b\ann\a instead of standard output. This
                option must be used when \b-l\b or the \b-L\b is specified.]
        [p:intermix-type?Allow positional parameter options. The options
                \b-B\b, \b-T\b, \b-z\b and \b-Z\b may be embedded, and files
                to the right of the option will be processed in the specified
                mode.]
        [q:quit|silent?Do not output verbose messages locally when producing
                the archive.]
        [s:submitter]:[user?Override automatically determined submitter name
                with \auser\a which is of the form \awho\...@\b\awhere\a.]
        [t:tty?Write errors and the name of each file to \b/dev/tty\b as it is
                archived.]
        [w:no-character-count?Do NOT check each file with \bwc -c\b after
                unpack.]
        [z:gzip?\bgzip\b(1) and \buuencode\b(1) all files prior to packing.]
        [B:uuencode,binary-files-files?Treat all files as binary and
                \buuencode\b(1) prior to packing.]
        [D:no-md5-digest?Do NOT use \bcksum md5sum\b digest to verify 
                the unpacked files. The default is to check.]
        [L:split-size-limit]#[size?Limit the output file size to \asize\a
                bytes as with \b-l\b, but split the archive into multiple 
                files.]
        [Q:quiet-unshar?Verbose OFF. Disables the inclusion of comments to
                be output when the archive is unpacked.]
        [M:mixed-uuencode?Mixed mode. Determine if the files are text or
                binary and archive correctly. Files found to be binary 
                are uuencoded prior to packing. This is the default.]
        [S:stdin-file-list?Read list of files to be packed from the standard
                input rather than from the command line in the format
                generated by \bfind\b(1) and \btw\b(1). If \b-p\b is specified,
                the options \b-B\b, \b-T\b, \b-z\b and \b-Z\b must be
                included in the standard input.]
        [T:text-files?Treat all files as text.]
        [X:query-user?When unpacking, ask the user if files should be 
                overwritten.]
        [Z:compress?\bcompress\b(1) and \buuencode\b(1) all files prior to
                packing.]

        [files ...]

        [+SEE ALSO?\bcksum\b(1), \bcompress\b(1), \bfind\b(1), \bgzip\b(1),
                \bpax\b(1), \btw\b(1), \buuencode\b(1), \bwc\b(1)]
    '

IFS=$'\n'
command=${0##*/}
user=${USER:-${LOGNAME:-$(whoami 2>/dev/null || who am i | sed $'s/[ 
\t].*//')}...@$(hostname)
integer size=0
flags= prefix= mode=M arg=
separator=SHAR_EOF
# some strings that should be internationalized some day

while getopts "$usage" c
do 
        case $c in
        [acfpqwDSQX])
                flags=$flags$c;;
        b)      mode=Z;arg=-"b $OPTARG";;
        g)      mode=z;arg=-$OPTARG;;
        l)      size=OPTARG;;
        L)      split=1 size=OPTARG;;
        d)      separator=$OPTARG;;
        n)      aname=$OPTARG;;
        o)      prefix=$OPTARG
                exec >  /tmp/shar$$.1;;
        s)      user=$OPTARG;;
        q)      verbose=;;
        t)      verbose=1; exec 2> /dev/tty;;
        v)      verbose=1;;
        [zZBMT])
                mode=$c;;
        esac
done

# Check remaining arguments, which should be just a list of files:
shift $((OPTIND-1))
if      (( $# ==0 )) && [[ $flags != *S* ]]
then    err_exit "no arguments left!"
fi

==============cut here=======================

David Korn
[email protected]
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to