1######################################################################## 2# # 3# This software is part of the ast package # 4# Copyright (c) 1994-2011 AT&T Intellectual Property # 5# and is licensed under the # 6# Eclipse Public License, Version 1.0 # 7# by AT&T Intellectual Property # 8# # 9# A copy of the License is available at # 10# http://www.eclipse.org/org/documents/epl-v10.html # 11# (with md5 checksum b35adb5213ca9657e911e9befb180842) # 12# # 13# Information and Software Systems Research # 14# AT&T Research # 15# Florham Park NJ # 16# # 17# Glenn Fowler <gsf@research.att.com> # 18# # 19######################################################################## 20: convert command that operates on file args to pipeline filter 21 22command=filter 23 24tmp=/tmp/$command$$ 25suf= 26 27case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in 280123) ARGV0="-a $command" 29 USAGE=$' 30[-? 31@(#)$Id: filter (AT&T Labs Research) 2001-05-31 $ 32] 33'$USAGE_LICENSE$' 34[+NAME?filter - run a command in stdin/stdout mode] 35[+DESCRIPTION?\bfilter\b runs \acommand\a in a mode that takes input from 36 the \afile\a operands, or from the standard input if no \afile\a 37 operands are specified, and writes the results to the standard output. 38 It can be used to run commands like \bsplit\b(1), that normally modify 39 \afile\a operands in-place, in pipelines. The \afile\a operands are 40 not modified; \acommand\a is run on copies in \b/tmp\b.] 41 42command [ option ... ] [ file ... ] 43 44[+SEE ALSO?\bstrip\b(1)] 45' 46 ;; 47*) ARGV0="" 48 USAGE="command [ option ... ] [ file ... ]" 49 ;; 50esac 51 52usage() 53{ 54 OPTIND=0 55 getopts $ARGV0 "$USAGE" OPT '-?' 56 exit 2 57} 58 59while getopts $ARGV0 "$USAGE" OPT 60do case $OPT in 61 *) usage ;; 62 esac 63done 64shift `expr $OPTIND - 1` 65case $# in 660) usage ;; 67esac 68 69cmd=$1 70while : 71do shift 72 case $# in 73 0) break ;; 74 esac 75 case $1 in 76 -*) cmd="$cmd $1" ;; 77 *) break ;; 78 esac 79done 80trap 'rm -f $tmp$suf' 0 1 2 3 15 81case $# in 820) cat > $tmp 83 $cmd $tmp 84 ;; 85*) for file 86 do suf=${file##*/} 87 case $suf in 88 *.*) suf=.${suf#*.} ;; 89 *) suf= ;; 90 esac 91 cp $file $tmp$suf || exit 1 92 chmod u+rwx $tmp$suf || exit 1 93 $cmd $tmp$suf || exit 1 94 cat $tmp$suf 95 rm -f $tmp$suf 96 done 97 ;; 98esac 99