1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-22 09:36:16 +02:00

dsv/dsv: change indentation to tab instead of 4 spaces; fix typo

This commit is contained in:
Werner Almesberger 2014-03-07 08:34:15 -03:00
parent 7067c00a90
commit 8c5d7d7bcd

279
dsv/dsv
View File

@ -30,14 +30,14 @@ DSV_DIR=.dsv
usage()
{
echo "usage: $0 [-p] [-u] <component>" 2>&1
echo " $0 help" 2>&1
echo " $0 [ls]" 2>&1
echo " $0 setup <info-file> ..." 2>&1
echo 2>&1
echo " -p show the path instead of displaying the file " 2>&1
echo " -u show source URL instead of displaying the file " 2>&1
exit 1
echo "usage: $0 [-p] [-u] <component>" 2>&1
echo " $0 help" 2>&1
echo " $0 [ls]" 2>&1
echo " $0 setup <info-file> ..." 2>&1
echo 2>&1
echo " -p show the path instead of displaying the file " 2>&1
echo " -u show source URL instead of displaying the file " 2>&1
exit 1
}
@ -49,158 +49,167 @@ do_wget()
up()
{
old=`pwd`
cd ..
new=`pwd`
[ "$old" != "$new" ]
old=`pwd`
cd ..
new=`pwd`
[ "$old" != "$new" ]
}
flush()
{
eval nm=$name
nm=`echo "$nm" | sed 's/%/%25/g;s|/|%2F|g'`
[ -z "$nm" ] && return
if [ -z "$url" ]; then
echo "$nm: no URL" 2>&1
exit 1
fi
ds=$nm-`basename "$url"`
mkdir -p $DSV_DIR
if [ ! -r "$DSV_DIR/$ds" ]; then
if [ "$zip" ]; then
inside=$zip
zip=$ds.zip
else
inside=${url#*.[Zz][Ii][Pp] }
eval nm=$name
nm=`echo "$nm" | sed 's/%/%25/g;s|/|%2F|g'`
[ -z "$nm" ] && return
if [ -z "$url" ]; then
echo "$nm: no URL" 2>&1
exit 1
fi
if [ "$inside" = "$url" ]; then
do_wget -O "$DSV_DIR/$ds" "$url"
# @@@ should handle error
else
if [ -z "$zip" ]; then
url=${url%`echo x"$inside" | sed 's/./?/g'`}
zip=$nm-`basename "$url"`
ds=$nm-`basename "$url"`
mkdir -p $DSV_DIR
if [ ! -r "$DSV_DIR/$ds" ]; then
if [ "$zip" ]; then
inside=$zip
zip=$ds.zip
else
inside=${url#*.[Zz][Ii][Pp] }
fi
if [ ! -r "$DSV_DIR/$zip" ]; then
do_wget -O "$DSV_DIR/$zip" "$url"
if [ "$inside" = "$url" ]; then
do_wget -O "$DSV_DIR/$ds" "$url"
# @@@ should handle error
else
if [ -z "$zip" ]; then
url=${url%`echo x"$inside" | sed 's/./?/g'`}
zip=$nm-`basename "$url"`
fi
if [ ! -r "$DSV_DIR/$zip" ]; then
do_wget -O "$DSV_DIR/$zip" "$url"
# @@@ should handle error
fi
unzip -p "$DSV_DIR/$zip" "$inside" >"$DSV_DIR/$ds" ||
{ rm -f "$DSV_DIR/$zip" "$DSV_DIR/$ds"; exit 1; }
fi
unzip -p "$DSV_DIR/$zip" "$inside" >"$DSV_DIR/$ds" ||
{ rm -f "$DSV_DIR/$zip" "$DSV_DIR/$ds"; exit 1; }
fi
fi
eval for n in $name $alias\; do \
'nm=`echo "$n" | sed "s/%/%25/g;s|/|%2F|g"`;' \
\{ echo '"$ds"'\; echo '"$url"'\; \} '>$DSV_DIR/dsv-$nm'\; \
done
name=
alias=
url=
zip=
eval for n in $name $alias\; do \
'nm=`echo "$n" | sed "s/%/%25/g;s|/|%2F|g"`;' \
\{ echo '"$ds"'\; echo '"$url"'\; \} '>$DSV_DIR/dsv-$nm'\; \
done
name=
alias=
url=
zip=
}
set_value()
{
case "$tag" in
N:|n:) flush
name="\"$value\"";;
A:|a:) alias="$alias \"$value\"";;
D:|d:) url=$value;;
Z:|z:) zip=$value;;
"")
;; # first iteration
*) echo "unrecognized tag \"$tag\"" 2>&1
exit 1;;
esac
value=
case "$tag" in
N:|n:) flush
name="\"$value\"";;
A:|a:) alias="$alias \"$value\"";;
D:|d:) url=$value;;
Z:|z:) zip=$value;;
"") ;; # first iteration
*) echo "unrecognized tag \"$tag\"" 2>&1
exit 1;;
esac
value=
}
eof()
{
flush
tag=
flush
tag=
}
setup()
{
for n in "$@"; do
if [ ! -r "$n" ]; then
echo "$n: not found" 2>&1
continue
fi
#
# "read" doesn't recognize lines that don't end with a newline.
# The cat-sed hack below works around this problems.
#
cat -E "$n" | sed 's/[^$]$/&\n/;s/$$//' | {
while read line; do
[ "$line" = "${line###}" ] || continue
tmp=`echo "$line" | awk '/^[^\t ]/ { print $1 }'`
tail=`echo "$line" | sed 's/^[^\t ]*[\t ]*//;s/[\t ]*$//'`
if [ -z "$tmp" ]; then
[ -z "$tail" ] || value="$value $tail"
else
set_value
tag=$tmp
value=$tail
for n in "$@"; do
if [ ! -r "$n" ]; then
echo "$n: not found" 2>&1
continue
fi
done
set_value
eof
}
done
#
# "read" doesn't recognize lines that don't end with a newline.
# The cat-sed hack below works around this problems.
#
cat -E "$n" | sed 's/[^$]$/&\n/;s/$$//' | {
while read line; do
[ "$line" = "${line###}" ] || continue
tmp=`echo "$line" |
awk '/^[^\t ]/ { print $1 }'`
tail=`echo "$line" |
sed 's/^[^\t ]*[\t ]*//;s/[\t ]*$//'`
if [ -z "$tmp" ]; then
[ -z "$tail" ] || value="$value $tail"
else
set_value
tag=$tmp
value=$tail
fi
done
set_value
eof
}
done
}
list()
{
while true; do
if [ -d $DSV_DIR ]; then
ls -b -1 $DSV_DIR | sed 's/^dsv-//p;d' | sed 's|%2F|/|g;s/%25/%/g'
fi
up || break
done | sort | uniq | column
while true; do
if [ -d $DSV_DIR ]; then
ls -b -1 $DSV_DIR | sed 's/^dsv-//p;d' |
sed 's|%2F|/|g;s/%25/%/g'
fi
up || break
done | sort | uniq | column
}
view()
{
${DSV_VIEWER:-${DSV_PDFVIEWER:-xdg-open}} "$@"
}
search()
{
while true; do
if [ -d $DSV_DIR ]; then
name=`echo "$1" | sed 's/%/%25/g;s|/|%2F|g'`
if [ -r "$DSV_DIR/dsv-$name" ]; then
file=`sed 1q "$DSV_DIR/dsv-$name"`
if [ ! -r "$DSV_DIR/$file" ]; then
echo "$1 -> $file: does not exist" 2>&1
exit 1
while true; do
if [ -d $DSV_DIR ]; then
name=`echo "$1" | sed 's/%/%25/g;s|/|%2F|g'`
if [ -r "$DSV_DIR/dsv-$name" ]; then
file=`sed 1q "$DSV_DIR/dsv-$name"`
if [ ! -r "$DSV_DIR/$file" ]; then
echo "$1 -> $file: does not exist" 2>&1
exit 1
fi
if $path; then
echo "`pwd`/$DSV_DIR/$file"
elif ! $show_url; then
view "$DSV_DIR/$file"
fi
if $show_url; then
url=`sed 1d "$DSV_DIR/dsv-$name"`
if [ "$url" ]; then
echo "$url"
else
echo "$DSV_DIR/dsv-$name" \
"does not contain a URL" \
"- please regenerate" 1>&2
exit 1
fi
fi
exit
fi
fi
if $path; then
echo "`pwd`/$DSV_DIR/$file"
elif ! $show_url; then
${DSV_VIEWER:-${DSV_PDFVIEWER:-xdg-open}} "$DSV_DIR/$file"
fi
if $show_url; then
url=`sed 1d "$DSV_DIR/dsv-$name"`
if [ "$url" ]; then
echo "$url"
else
echo "$DSV_DIR/dsv-$name" \
"does not contain an URL - please regenerate" 1>&2
if ! up; then
echo "no data sheet found for \"$1\"" 2>&1
exit 1
fi
fi
exit
fi
fi
if ! up; then
echo "no data sheet found for \"$1\"" 2>&1
exit 1
fi
done
done
}
@ -208,21 +217,21 @@ path=false
show_url=false
while true; do
case "$1" in
-p) path=true
shift;;
-u) show_url=true
shift;;
-*) usage;;
*) break;;
esac
case "$1" in
-p) path=true
shift;;
-u) show_url=true
shift;;
-*) usage;;
*) break;;
esac
done
case "$1" in
help|-*) usage;;
""|ls) list;;
setup) shift
[ "$1" ] || usage
setup "$@";;
*) search "$@";;
help|-*) usage;;
""|ls) list;;
setup) shift
[ "$1" ] || usage
setup "$@";;
*) search "$@";;
esac