mirror of https://github.com/wwarthen/RomWBW.git
1 changed files with 45 additions and 16 deletions
@ -1,22 +1,51 @@ |
|||
#!/bin/bash |
|||
# given a filename on the command line, echo the form of the file that |
|||
# given filename on the command line, echo the form of the file that |
|||
# actually can be opened. this needs to do filesystem case shenanigans |
|||
# |
|||
n=0 |
|||
# we don't handle files with embedded spaces, a horrible idea anyway |
|||
# |
|||
search=/tmp/cn.search.$$ |
|||
all=/tmp/cn.all.$$ |
|||
in=/tmp/cn.in.$$ |
|||
|
|||
function cleanup { |
|||
rm -f $all $search $in |
|||
} |
|||
|
|||
trap cleanup EXIT |
|||
cleanup |
|||
|
|||
if [ $# -lt 1 ] ; then |
|||
exit 0 |
|||
fi |
|||
|
|||
# |
|||
# normalize to lower case all input file names |
|||
# |
|||
if echo $* | grep -q / ; then |
|||
echo "no paths allowed" |
|||
exit 1 |
|||
fi |
|||
|
|||
for infn in $* ; do |
|||
dir=$(dirname $infn) |
|||
lowname=$(basename $infn | tr '[A-Z]' '[a-z]') |
|||
cd $dir |
|||
for i in * ; do |
|||
cand=$(basename ./"$i" | tr '[A-Z]' '[a-z]') |
|||
if [ ./"$cand" = ./$lowname ] ; then |
|||
echo -n "$dir/$i " |
|||
((n++)) |
|||
fi |
|||
done |
|||
echo $infn | tr '[A-Z]' '[a-z]' >> $in |
|||
done |
|||
sort $in > $search |
|||
|
|||
# |
|||
# build join list of file names and lower case forms |
|||
# |
|||
rm -f $in |
|||
for i in * ; do |
|||
echo $(echo "$i" | tr '[A-Z]' '[a-z]')",$i" >> $in |
|||
done |
|||
if [ $n == 0 ] ; then |
|||
echo "nofile" |
|||
else |
|||
echo |
|||
sort $in > $all |
|||
|
|||
join -t, -o 1.2 $all $search | sort -u > $in |
|||
if [ $(wc -l < $in) -gt 0 ] ; then |
|||
cat $in |
|||
exit 0 |
|||
fi |
|||
|
|||
echo nofile |
|||
exit 2 |
|||
|
|||
Loading…
Reference in new issue