From 9893f864ba6cdb32ad1b9111be458a18116ea517 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 3 May 2011 18:38:56 +0000 Subject: Haakon: 29137: handling of flags in _ffmpeg --- ChangeLog | 7 +++- Completion/Unix/Command/_ffmpeg | 79 +++++++++++++++++++++++++++++++---------- 2 files changed, 66 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 90d19f19b..05f8ad940 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-05-03 Peter Stephenson + + * Haakon Riiser: 29137: Completion/Unix/Command/_ffmpeg: better + handling of flags. + 2011-05-03 Peter Stephenson * 29134: Src/prototypes.h: change termcap prototypes for AIX @@ -14565,5 +14570,5 @@ ***************************************************** * This is used by the shell to define $ZSH_PATCHLEVEL -* $Revision: 1.5273 $ +* $Revision: 1.5274 $ ***************************************************** diff --git a/Completion/Unix/Command/_ffmpeg b/Completion/Unix/Command/_ffmpeg index 8ec89707d..8f9b2c9cb 100644 --- a/Completion/Unix/Command/_ffmpeg +++ b/Completion/Unix/Command/_ffmpeg @@ -43,27 +43,73 @@ typeset -A opt_args _wanted ffmpeg-bsfs expl 'set bitstream filter' compadd -a bsfs } +typeset -A _ffmpeg_flags + +(( $+functions[_ffmpeg_flag_options] )) || _ffmpeg_flag_options() { + local expl + _wanted options expl 'select flags' compadd -S '' -- {-,+}${^flag_options} +} + +(( $+functions[_ffmpeg_more_flag_options] )) || _ffmpeg_more_flag_options() { + compset -p $1 && _ffmpeg_flag_options +} + +(( $+functions[_ffmpeg_new_flag_options] )) || _ffmpeg_new_flag_options() { + compset -P '*' && _ffmpeg_flag_options +} + +(( $+functions[_ffmpeg_flags] )) || _ffmpeg_flags() { + local -a flag_options + eval "flag_options=(\${=_ffmpeg_flags[$1]})" + + local match mbegin mend + integer ret=1 + + if [[ $PREFIX = (#b)(*)[-+]([^-+]#) ]]; then + if [[ -n ${flag_options[(R)$match[2]]} ]]; then + _ffmpeg_new_flag_options && ret=0 + fi + if [[ -n ${flag_options[(R)$match[2]?*]} ]]; then + _ffmpeg_more_flag_options ${#match[1]} && ret=0 + fi + else + _ffmpeg_flag_options && ret=0 + fi + + return $ret +} + +(( $+functions[_ffmpeg_register_lastopt_values] )) || _ffmpeg_register_lastopt_values() { + if (( lastopt_takesargs )); then + lastopt+=":$lastopt_description:" + if (( $#lastopt_values )); then + if [[ $lastopt_type == flags ]]; then + flagtype=${${lastopt%%:*}#-} + lastopt+="->$flagtype" + _ffmpeg_flags[$flagtype]="${lastopt_values[*]}" + else + lastopt+="(${lastopt_values[*]})" + fi + fi + fi + _ffmpeg_argspecs+=$lastopt +} + local -a _ffmpeg_argspecs { local lastopt local lastopt_description local lastopt_takesargs + local lastopt_type local -a lastopt_values _call_program options $words[1] -h 2>/dev/null | while IFS=$'\n' read -r; do if [[ $REPLY == -* ]]; then - if [[ -n $lastopt ]]; then - if (( lastopt_takesargs )); then - lastopt+=":$lastopt_description:" - if (( $#lastopt_values )); then - lastopt+="(${lastopt_values[*]})" - fi - fi - _ffmpeg_argspecs+=$lastopt - fi + [[ -n $lastopt ]] && _ffmpeg_register_lastopt_values lastopt=${REPLY%%[[:space:]]*} lastopt_description=${REPLY##-[^[:space:]]##[[:space:]]##} - if [[ $lastopt_description == '<'* ]]; then + if [[ $lastopt_description == (#b)'<'(?##)'>'* ]]; then + lastopt_type=$match[1] lastopt_description=${lastopt_description##<[^[:space:]]##>[[:space:]]##[^[:space:]]##[[:space:]]#} if [[ -z $lastopt_description ]]; then lastopt_description=$lastopt @@ -113,15 +159,7 @@ local -a _ffmpeg_argspecs lastopt_values+=$REPLY fi done - if [[ -n $lastopt ]]; then - if (( lastopt_takesargs )); then - lastopt+=":$lastopt_description:" - if (( $#lastopt_values )); then - lastopt+="(${lastopt_values[*]})" - fi - fi - _ffmpeg_argspecs+=$lastopt - fi + [[ -n $lastopt ]] && _ffmpeg_register_lastopt_values } _arguments -S \ @@ -153,4 +191,7 @@ _arguments -S \ [[ "$state" == "noformat" ]] && _values -s : -S = 'disable specified pixel formats by force' $(_ffmpeg_list_pix_fmts) && return 0 +[[ -n $state && -n $_ffmpeg_flags[$state] ]] && + _ffmpeg_flags $state && return 0 + return 1 -- cgit 1.4.1