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