std.csh - a 'standard' C-shell argument processor
bill at persci.UUCP
bill at persci.UUCP
Tue Apr 30 08:26:26 AEST 1985
Hello, you hackers who enjoyed Ken Turkowski's previous standard C program,
stdmain.c, and his standard /bin/sh script, I now present you with a new
standard script for /bin/csh, std.csh. It is basically an argument parser,
and will accept arbitrary argument formats:
std -a -l -x -th0 -o outfile -
std -alxth0 -ooutfile
...and related permutations can parse as:
-a
-l
-x
-t with argument h0
-o with argument outfile
-
just like stdmain.c and std.sh. Convert all of your C-shell scripts now, so
you don't need to remember whether the -o argument should be attached or not!
I translated this script from Ken Turkowski's std.sh (i.e. I did no original
thinking). Ken tested and fixed it, but I take full responsibility for
the translation. Please forward any bug reports, suggestions, etc, to me.
Bill Swan @ Personal Scientific {ihnp4|decvax|..}!uw-beaver!tikal!persci!bill
Woodinville, WA
---cut-here------------------------------------------------------------------
#!/bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
# std.csh
# This archive created: Mon Apr 29 14:42:21 1985
export PATH; PATH=/bin:$PATH
if test -f 'std.csh'
then
echo shar: over-writing existing file "'std.csh'"
fi
cat << \SHAR_EOF > 'std.csh'
#! /bin/csh -f
unset verbose
set outfile
set unkflag
set files
foreach argument ( $* )
while ( 1 )
switch ( $argument )
case "-" :
echo 'NULL FLAG'
break
case "-v*":
set verbose
breaksw
case "-o*":
set outfile = `expr $argument : '-.\(.*\)'` || set outfile = UNKNOWN
break
case "-*":
echo Unknown flag: \"$argument\"
set unkflag = "$unkflag $argument"
break
case "*":
switch ( UNKNOWN )
case "$outfile":
set outfile = $argument
breaksw
default:
set files = "$files $argument"
endsw
break
endsw
set argument = -`expr "$argument" : '-.\(.*\)'` || break
end
end
# The following is just for testing this standard script
echo ' Argument analysis to' $0 ':'
echo Flags: -v = ${?verbose}, -o = \"$outfile\"
echo Unknown flags: $unkflag
echo Files: $files
exit
SHAR_EOF
# End of shell archive
exit 0
--
More information about the Comp.sources.unix
mailing list