From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26941 invoked from network); 30 Jan 2000 02:40:17 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 30 Jan 2000 02:40:17 -0000 Received: (qmail 18709 invoked by alias); 30 Jan 2000 02:40:12 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9473 Received: (qmail 18700 invoked from network); 30 Jan 2000 02:40:10 -0000 To: zsh-workers@sunsite.auc.dk Subject: PATCH: _patch MIME-Version: 1.0 (generated by AKEMI 1.13.2 - =?ISO-2022-JP?B?Ig==?= =?ISO-2022-JP?B?GyRCQTA0Y0s8GyhCIg==?=) Content-Type: text/plain; charset=US-ASCII From: Tanaka Akira Date: 30 Jan 2000 11:40:08 +0900 Message-ID: User-Agent: Chao-gnus/6.12.5 AKEMI/1.13.2 (=?ISO-2022-JP?B?GyRCQTAbKEI=?= =?ISO-2022-JP?B?GyRCNGNLPBsoQg==?=) FLAM-DOODLE/1.12.6 (=?ISO-2022-JP?B?GyRCM3cbKEI=?= 10R4.0/5.0) Emacs/20.4 (sparc-sun-solaris2.6) MULE/4.0 (HANANOEN) Since old patch command is somewhat popular, I rewrite _patch to parse help message more carefully. This depends on 9457. I actualy test this with patch-2.0.12u[3-9], patch-2.[1-5], patch-2.5.4 and /usr/bin/patch on Solaris 7. Also I checked the source of patch command on NetBSD, OpenBSD and FreeBSD. This should work on IRIX 6.3 because /usr/sbin/patch is patch-2.1. This should work well on most Linux since most Linux distributions use recent patch command without modifications, I believe. NetBSD's is derived from patch-2.0.12u8 but it supports long options as extension without getopt_long. Although they are not completed since the help message produced by `patch --help' doesn't have them. FreeBSD's is derived from patch-2.1 but it supports new long option `--check' and `--index-first' and short options `C' and `I'. Although `I' is not completed since the help message doesn't have it. OpenBSD's is derived from NetBSD's but it incorporates FreeBSD's extension `C'. Long options are supported but they are not completed as on NetBSD. Note that I couldn't identified what Solaris 7's is derived from. At last, this doesn't complete any options with very old patch command (patch-2.0.12) since it has no useful help message. I think no one care it. Index: Completion/User/_patch =================================================================== RCS file: /projects/zsh/zsh/Completion/User/_patch,v retrieving revision 1.1.1.8 diff -u -r1.1.1.8 _patch --- Completion/User/_patch 1999/09/13 16:35:42 1.1.1.8 +++ Completion/User/_patch 2000/01/30 01:37:49 @@ -1,44 +1,122 @@ #compdef patch -local comp_p='compadd "$expl[@]" -S0 -r "1-9" - ""' +if (( ! $+_patch_args )); then + local help="$(LANG=C patch --help 2>&1)" + local -A optionmap + local arg + local comp_p='compadd "$expl[@]" -S0 -r "1-9" - ""' -_arguments -s \ - '(--strip)-p+:number:'"{$comp_p}" \ - '(--fuzz)-F+:lines:' \ - '(--context)-c' \ - '(--ed)-e' \ - '(--force)-f' \ - '(--batch)-t' \ - '(--ignore-whitespace)-l' \ - '(--normal)-n' \ - '(--forward)-N' \ - '(--reverse)-R' \ - '(--silent --quiet)-s' \ - '(--skip)-S' \ - '(--unified)-u' \ - '(--version)-v' \ - -{E,Z,T} \ - '-i+:patch file:_files' \ - '(--output)-o+:output file:_files' \ - '(--reject-file)-r+:reject file:_files' \ - '(--ifdef)-D+:name:' \ - '(--version-control)-V+:version control style:(simple numbered existing)' \ - '(--prefix)-B+:backup path prefix:' \ - '(--suffix)-b+:backup extension:' \ - '-Y+:backup basename prefix:_files' \ - '-z+:backup file suffix:(.bak)' \ - '-g+:NUM:' \ - '(--directory)-d+:chdir to:_files -/' \ - ':original file:_files' \ - ':patch file:_files' \ - -- \ - '*strip=NUM*:number:'"{$comp_p}" \ - '*get=NUM*:get files from RCS etc:' \ - '*=LINES*:lines:' \ - '*=PATCHFILE*:patch file:_files' \ - '*=FILE*:file:_files' \ - '*=NAME*:name:' \ - '*=WORD*:quoting style:(literal shell shell-always c escape)' \ - '*=STYLE*:version control style:(simple numbered existing)' \ - '*=SUFFIX*:backup file suffix:(.bak)' \ - '*=DIR*:chdir to:_files -/' + [[ "$help" = *--[^h]* || "$help" = *\[-c\|-e\|-n\]* ]] && arg=+ + + optionmap=( + '*\[-p\[strip-count\]\]*' '(--strip)-p-[number of path prefix components to strip]:number of path prefix components to strip:'"{$comp_p}" + '*( -p NUM[, ]|\[-p num\])*' '(--strip)-p+[number of path prefix components to strip]:number of path prefix components to strip:'"{$comp_p}" + '*\[--strip\[=strip-count\]\]*' '(-p)--strip=-[number of path prefix components to strip]:number of path prefix components to strip:'"{$comp_p}" + '* --strip=NUM[, ]*' '(-p)--strip=[number of path prefix components to strip]:number of path prefix components to strip:'"{$comp_p}" + + '*\[-Fmax-fuzz\]*' '(--fuzz)-F-[specify the maximum fuzz factor]:maximum fuzz factor:' + '*(\[-F max-fuzz\]| -F LINES[, ])*' '(--fuzz)-F+[specify the maximum fuzz factor]:maximum fuzz factor:' + '*(\[--fuzz=max-fuzz\]| --fuzz( |=)LINES[, ])*' '(-F)--fuzz=[specify the maximum fuzz factor]:maximum fuzz factor:' + + '*(\[-[a-zA-Z]#l[a-zA-Z]#\]| -l[, ])*' '(--ignore-whitespace)-l[ignore white space changes]' + '*(\[--ignore-whitespace\]| --ignore-whitespace[, ])*' '(-l)--ignore-whitespace[ignore white space changes]' + + '*(\[-[a-zA-Z]#c[a-zA-Z]#\]| -c[, ]|\[-c\|)*' '( -e -n -u --context --ed --normal --unified)-c[interpret context diff]' + '*(\[-[a-zA-Z]#e[a-zA-Z]#\]| -e[, ]|\|-e\|)*' '(-c -n -u --context --ed --normal --unified)-e[interpret ed script]' + '*(\[-[a-zA-Z]#n[a-zA-Z]#\]| -n[, ]|\|-n\])*' '(-c -e -u --context --ed --normal --unified)-n[interpret normal diff]' + '*(\[-[a-zA-Z]#u[a-zA-Z]#\]| -u[, ])*' '(-c -e -n --context --ed --normal --unified)-u[interpret unified diff]' + '*(\[--context\]| --context[, ])*' '(-c -e -n -u --ed --normal --unified)--context[interpret context diff]' + '*(\[--ed\]| --ed[, ])*' '(-c -e -n -u --context --normal --unified)--ed[interpret ed script]' + '*(\[--normal\]| --normal[, ])*' '(-c -e -n -u --context --ed --unified)--normal[interpret normal diff]' + '*(\[--unified\]| --unified[, ])*' '(-c -e -n -u --context --ed --normal )--unified[interpret unified diff]' + + '*(\[-[a-zA-Z]#N[a-zA-Z]#\]| -N[, ])*' '(--forward)-N[ignore reverse patches]' + '*(\[--forward\]| --forward[, ])*' '(-N)--forward[ignore reverse patches]' + '*(\[-[a-zA-Z]#R[a-zA-Z]#\]| -R[, ])*' '(--reverse)-R[reverse mode]' + '*(\[--reverse\]| --reverse[, ])*' '(-R)--reverse[reverse mode]' + + '*(\[-i patchfile\]| -i PATCHFILE[, ])*' '(--input)-i+[patch file]:patch file:_files' + '* --input=PATCHFILE[, ]*' '(-i)--input=[patch file]:patch file:_files' + + '*(\[-o out-file\]| -o FILE[, ]|\[-o outfile\])*' "(--output)-o${arg}[output file]:output file:_files" + '*(\[--output=out-file\]| --output=FILE[, ])*' '(-o)--output=[output file]:output file:_files' + '*(\[-r rej-name\]| -r FILE[, ]|\[-r rejectfile\])*' "(--reject-file)-r${arg}[reject file]:reject file:_files" + '*(\[--reject-file=rej-name\]| --reject-file=FILE[, ])*' '(-r)--reject-file=[reject file]:reject file:_files' + + '*(\[-D symbol\]| -D NAME[, ]|\[-D define\])*' '(--ifdef)-D+[cpp symbol]:symbol:' + '*(\[--ifdef=symbol\]| --ifdef=NAME[, ])*' '(-D)--ifdef=[cpp symbol]:symbol:' + + '*(\[-[a-zA-Z]#E[a-zA-Z]#\]| -E[, ])*' '(--remove-empty-files)-E[remove empty files]' + '*(\[--remove-empty-files\]| --remove-empty-files[, ])*' '(-E)--remove-empty-files[remove empty files]' + + '* -Z[, ]*' '( -T --set-utc --set-time)-Z[assume timestamp as UTC]' + '* -T[, ]*' '(-Z --set-utc --set-time)-T[assume timestamp as local time]' + '* --set-utc[, ]*' '(-Z -T --set-time)--set-utc[assume timestamp as UTC]' + '* --set-time[, ]*' '(-Z -T --set-utc )--set-time[assume timestamp as local time]' + + '* --quoting-style=WORD[, ]*' '--quoting-style=[quoting style]:quoting style:(literal shell shell-always c escape)' + + '*(\[-[a-zA-Z]#b[a-zA-Z]#\]| -b[, ])*' '(--backup)-b[back up original]' + '* --backup[, ]*' '(-b)--backup[backup original]' + '* --backup-if-mismatch[, ]*' '(--no-backup-if-mismatch)--backup-if-mismatch[back up if not match exactly]' + '* --no-backup-if-mismatch[, ]*' '(--backup-if-mismatch)--no-backup-if-mismatch[back up only if otherwise requested]' + + '*(\[-V {numbered,existing,simple}\]| -V STYLE[, ])*' "(--version-control)-V${arg}[backup method]:backup method:(numbered existing simple)" + '*(\[--version-control={numbered,existing,simple}\]| --version-control=STYLE[, ])*' '(-V)--version-control=[backup method]:backup method:(numbered existing simple)' + + '*(\[-B backup-prefix\]| -B PREFIX[, ])*' "(--prefix)-B${arg}[specify backup prefix]:backup prefix:" + '*(\[--prefix=backup-prefix\]| --prefix=PREFIX[, ])*' '(-B)--prefix=[specify backup prefix]:backup prefix:' + '* -Y PREFIX[, ]*' '(--basename-prefix)-Y+[specify backup basename prefix]:backup basename prefix:' + '* --basename-prefix=PREFIX[, ]*' '(-Y)--basename-prefix=[specify backup basename prefix]:backup basename prefix:' + '*\[-b backup-ext\]*' "( -z --suffix)-b${arg}[specify backup suffix]:backup suffix:(.bak)" + '* -z SUFFIX[, ]*' '(-b --suffix)-z+[specify backup suffix]:backup suffix:(.bak)' + '*(\[--suffix=backup-ext\]| --suffix=SUFFIX[, ])*' '(-b -z )--suffix=[specify backup suffix]:backup suffix:(.bak)' + + '* -g NUM[, ]*' '(--get)-g+[get from RCS etc.]:number:((1\:get -1\:ask))' + '* --get=NUM[, ]*' '(-g)--get=[get from RCS etc.]:number:((1\:get -1\:ask))' + + '* -g --get *' '(-G --get --no-get)-g[get from RCS or SCCS] +(-g -G --no-get)--get[get from RCS or SCCS]' + '* -G --no-get *' '(-g --get --no-get)-G[don'\''t get from RCS or SCCS] +(-g -G --get)--no-get[don'\''t get from RCS or SCCS]' + + '*(\[-[a-zA-Z]#f[a-zA-Z]#\]| -f[, ])*' '( -t --force --batch)-f[force mode]' + '*(\[-[a-zA-Z]#t[a-zA-Z]#\]| -t[, ])*' '(-f --force --batch)-t[batch mode]' + '*(\[--force\]| --force[, ])*' '(-f -t --batch)--force[force mode]' + '*(\[--batch\]| --batch[, ])*' '(-f -t --force )--batch[batch mode]' + + '*(\[-[a-zA-Z]#s[a-zA-Z]#\]| -s[, ])*' '( --quiet --silent)-s[silent mode]' + '*(\[--quiet\]| --quiet[, ])*' '(-s --silent)--quiet[silent mode]' + '*(\[--silent\]|--silent[, ])*' '(-s --quiet )--silent[silent mode]' + + '* --verbose[, ]*' '--verbose[verbose mode]' + '* --dry-run[, ]*' '--dry-run[don'\''t actually change files]' + '* --posix[, ]*' '--posix[POSIX mode]' + + '*(\[-d directory\]| -d DIR[, ]|\[-d dir\])*' '(--directory)-d+[change the working directory]:chdir to:_files -/' + '*(\[--directory=directory\]| --directory=DIR[, ])*' '(-d)--directory=[change the working directory]:chdir to:_files -/' + + '* --binary[, ]*' '--binary[binary mode]' + + '*(\[-[a-zA-Z]#v[a-zA-Z]#\]| -v[, ])*' '(--version)-v[print version]' + '*(\[--version\]| --version[, ])*' '(-v)--version[print version]' + '* --help[, ]*' '--help[print help message]' + + '*\[-[a-zA-Z]#S[a-zA-Z]#\]*' '*-S[ignore this patch]' + '*\[--skip\]*' '*--skip[ignore this patch]' + + '*(\[-[a-zA-Z]#C[a-zA-Z]#\])*' '(--check)-C[check only]' + '*\[--check\]*' '(-C)--check[check only]' + + '*\[--index-first\]*' '--index-first[take Index: line precedence]' + + '* --use-index-line *' '--use-index-line[deal with Index: line]' + '* --patch-root=DIR *' '--patch-root=[restrict paths]:patch root:_files -/' + ) + _patch_args=( + ${arg:+"-s"} + ${(fF)optionmap[(K)"$help"]} + ) +fi + +_arguments "${(@)_patch_args}" ':original file:_files' ':patch file:_files' -- Tanaka Akira