#compdef ptx

autoload -U is-at-least

_ptx() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'-F+[use STRING for flagging line truncations]:STRING:_default' \
'--flag-truncation=[use STRING for flagging line truncations]:STRING:_default' \
'-M+[macro name to use instead of '\''xx'\'']:STRING:_default' \
'--macro-name=[macro name to use instead of '\''xx'\'']:STRING:_default' \
'--format=[]: :(roff tex)' \
'-S+[for end of lines or end of sentences]:REGEXP:_default' \
'--sentence-regexp=[for end of lines or end of sentences]:REGEXP:_default' \
'-W+[use REGEXP to match each keyword]:REGEXP:_default' \
'--word-regexp=[use REGEXP to match each keyword]:REGEXP:_default' \
'-b+[word break characters in this FILE]:FILE:_files' \
'--break-file=[word break characters in this FILE]:FILE:_files' \
'-g+[gap size in columns between output fields]:NUMBER:_default' \
'--gap-size=[gap size in columns between output fields]:NUMBER:_default' \
'-i+[read ignore word list from FILE]:FILE:_files' \
'--ignore-file=[read ignore word list from FILE]:FILE:_files' \
'-o+[read only word list from this FILE]:FILE:_files' \
'--only-file=[read only word list from this FILE]:FILE:_files' \
'-w+[output width in columns, reference excluded]:NUMBER:_default' \
'--width=[output width in columns, reference excluded]:NUMBER:_default' \
'-A[output automatically generated references]' \
'--auto-reference[output automatically generated references]' \
'-G[behave more like System V '\''ptx'\'']' \
'--traditional[behave more like System V '\''ptx'\'']' \
'-O[generate output as roff directives]' \
'-T[generate output as TeX directives]' \
'-R[put references at right, not counted in -w]' \
'--right-side-refs[put references at right, not counted in -w]' \
'-f[fold lower case to upper case for sorting]' \
'--ignore-case[fold lower case to upper case for sorting]' \
'-r[first field of each line is a reference]' \
'--references[first field of each line is a reference]' \
'-t[change the default width from 72 to 100]' \
'--typeset-mode[change the default width from 72 to 100]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
'::file:_files' \
&& ret=0
}

(( $+functions[_ptx_commands] )) ||
_ptx_commands() {
    local commands; commands=()
    _describe -t commands 'ptx commands' commands "$@"
}

if [ "$funcstack[1]" = "_ptx" ]; then
    _ptx "$@"
else
    compdef _ptx ptx
fi
