1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#!/bin/sh
# Reformat the output of 'exifprobe -L' to remove the "." separators,
# which are not valid in shell variable names, and produce output
# which may be 'sourced' by a shell. The value of the variable will
# be the last value present (the "interpreted" value, if available).
# Comments are stripped.
# This doesn't allow filenames on each line (exifprobe -n)
# Replace dots with underscores.
to_underscore()
{
local nextarg
nextarg=
OIFS=${IFS}
IFS="."
set - $*
echo -n $1
shift
# strip off asterisks
for nextarg in $*
do
nextarg=${nextarg%[*]}
echo -n _${nextarg%[*]}
done
IFS=${OIFS}
}
# Replace the dots and pick out the value, stripping comments.
reformat()
{
local lastarg
case $# in
0) return ;;
esac
lastarg=
endquote=
to_underscore $1
shift
# Pick out value after the last '=', quote it if not already quoted,
# and strip off comments.
while test $# -ge 1
do
case "$1" in
\#*) break ;;
\:*) break ;;
=) lastarg=; shift ;;
\') case "${lastarg}" in
"") lastarg="'" ;;
*) endquote="'"; break ;;
esac
;;
\'?*) lastarg="$1"; endquote=; shift ;;
*) case "${lastarg}" in
"") lastarg="'$1"; endquote="'" ;;
*) lastarg="${lastarg} $1" ;;
esac
shift
;;
esac
done
echo "=${lastarg}${endquote}"
}
# Prepend value of 'MARK' to each line of output.
MARK=
case $# in
0) ;;
*) MARK="${1}:" ;;
esac
# expects output of 'exifprobe -L' (without '-n')
while read LINE
do
case "${LINE}" in
?[*m\#*) continue ;;
\#*) continue ;;
"") continue ;;
esac
echo -n "${MARK}"
reformat $LINE
done
|