Subversion Repositories pub

Compare Revisions

Ignore whitespace Rev 365 → Rev 366

/video-contact-sheet/branches/1.0.100a/vcs
45,9 → 45,13
# <http://lists.mplayerhq.hu/pipermail/mencoder-users/2006-August/003843.html>
# [VC1] VC-1 and derived codecs information
# <http://wiki.multimedia.cx/index.php?title=VC-1>
# [FJ] GNU seq’s cousin on FreeBSD is... jot
# <http://www.nevdull.com/2007/09/24/gnu-seqs-cousin-on-freebsd-is-jot/>
# [FNL] Re: Replacing spaces with newlines using awk: msg#00064
# <http://osdir.com/ml/editors.sed.user/2004-07/msg00064.html>
#
 
declare -r VERSION="1.0.99b" # ("1.1.0 RC2")
declare -r VERSION="1.0.100" # ("1.1.0 RC2")
# {{{ # CHANGELOG
# History (The full changelog can be found at <http://p.outlyer.net/vcs/files/CHANGELOG>).
#
59,38 → 63,20
# - Try to use POSIX sed options when appropriate
# - Replaced incompatible sed constructs
# - Use mktemp's common GNU/BSD(/POSIX?) syntax
# - Use jot instead of seq if not on GNU
# - Use jot instead of seq if required and available
# * BUGFIX: Don't fail if tput is unable to change colours
# * BUGFIX: Check for requirements before anything else
# * INTERNAL: Cache tput output
# * COSMETIC: Removed line overflow in help message
#
# 1.0.99: (2009-3-11)
# * FEATURE: Experimental support for DVDs (-V)
# * FEATURE: Added JPEG 2000 output format (-j2)
# * FEATURE/COSMETIC: Polaroid mode now produces a polaroid-like frame, the
# older version is now renamed as simply 'photos'
# New "funky" modes: newer polaroid, photos (older polaroid),
# polaroidframe.
# * Overrideable variables: DISABLE_SHADOWS and DISABLE_TIMESTAMPS (set to
# 1 to disable)
# * BUGFIX/COSMETIC: Re-added the missed space before filename
# * BUGFIX/COSMETIC: Reworked alignment and padding
# * Timestamps size is adjusted with smaller captures
# * BUGFIX: Fixed polaroid/rotate bug where all images overlapped on the
# same position (reported by Aleksandar Urošević, formerly
# unreproducible)
# * Better detection of video/audio features by falling back to ffmpeg when
# appropriate
# }}} # CHANGELOG
 
set -e
#set -x
# This changes the way some commands are used. Feel free to modify
# the value to see vcs die miserably :P
declare -i IS_GNU=1
grep -qi gnu <<<"$OSTYPE" || IS_GNU=0
 
# This might change the way some commands are used.
# Right now it's unused
#declare -i IS_GNU=1
#grep -qi gnu <<<"$OSTYPE" || IS_GNU=0
 
# {{{ # TODO
# TODO / FIXME:
# * [[R1#22]] states that not all bc versions understand '<', more info required
101,31 → 87,6
#
# }}} # TODO
 
# {{{ # Semi-constants
# The can be overridden from the environment
# e.g. running 'GETOPT=/usr/local/bin/getopt vcs [options]'
# will set $GETOPT accordingly
 
#
if [ -z "$GETOPT" ]; then
# Getopt is expected to be Linux's (the one found in util-linux)
# See <http://p.outlyer.net/vcs#getopt> for details for other OSes
# Nte getopt can't be allowed to be overridden (since overrides require
# getopt) <-- FIXME: better split command-line overrides from config overrides
declare GETOPT=getopt
# e.g. FreeBSD port (misc/getopt):
#declare GETOPT=/usr/local/bin/getopt
if [ $IS_GNU -eq 1 ]; then # $OSTYPE is bash builtin
for dir in /usr/local/bin /usr/bin /bin ; do
if [ -x "$dir/getopt" ]; then
GETOPT="$dir/getopt"
break;
fi
done
fi
fi
# }}} # End of Semi-constants
 
# {{{ # Constants
 
# Configuration file, please, use this file to modify the behaviour of the
176,21 → 137,18
# so keep this in mind!
declare -ri HPAD=8
 
# Extended regular expressions are triggered by different options
# depending on the OS
# seq is not installed by default in e.g. FreeBSD (when installed, from
# port/package coreutils, it's named gseq); jot, OTOH is apparently standard.
# $SEQ will be tested for existence, no matter its value.
if [ $IS_GNU -eq 1 ]; then
declare -r ERESED='sed -r'
declare -r SEQ='seq'
else
declare -r ERESED='sed -E'
declare -r SEQ='jot'
fi
# These are used as constants but will be set from the available system
# programs
# ERESED # see choose_eresed
# SEQ # see choose_seqw
# }}} # End of constants
 
# {{{ # Override-able variables
# GETOPT must be correctly set or the script will fail.
# It can be set in the configuration files if it isn't in the path or
# the first getopt in the path isn't the right version.
# A check will be made and a warning with details shown if required.
declare GETOPT=getopt
# Set to 1 to print function calls
declare -i DEBUG=0
declare -i DEFAULT_INTERVAL=300
416,6 → 374,8
'MIN_LENGTH_FOR_END_OFFSET'
'DEBUG'
'DISABLE_.*'
# Note GETOPT doesn't make sense to be overridden from the command-line
'GETOPT'
)
 
# This is only used to exit when -DD is used
424,7 → 384,7
# Loads the configuration files if present
# load_config()
load_config() {
local CONFIGS=( /etc/vcs.conf $CFGFILE ./vcs.conf)
local CONFIGS=( /etc/vcs.conf $CFGFILE ./vcs.conf )
 
for cfgfile in ${CONFIGS[*]} ;do
if [ ! -f "$cfgfile" ]; then continue; fi
453,7 → 413,7
local compregex=$( sed 's/ /|/g' <<<${ALLOWED_OVERRIDES[*]} )
 
# Don't allow ';', FIXME: dunno how secure that really is...
# FIXME: ...it doesn't really works anyway
# FIXME: ...it doesn't really work anyway
if ! egrep -q '^[[:space:]]*[a-zA-Z_][a-zA-Z0-9_]*=[^;]*' <<<"$o" ; then
return
fi
555,7 → 515,7
[ '1' == "$(bc -q <<<"$1 $op $3")" ]
}
 
# converts spaces to newlines in a x-platform way
# converts spaces to newlines in a x-platform way [[FNL]]
# stonl($1 = string)
stonl() {
# Not pretty, but seems to be standard ('\n' works in GNU
803,19 → 763,6
# test_programs()
test_programs() {
local retval=0 last=0
# getopt requires some special treatment...
if ! type -pf "$GETOPT" ; then
error "Required program getopt not found!"
let retval++
else
# getopt exists, but is it the enhanced, util-linux, version?
"$GETOPT" -T
local gor=$?
if [ $gor -ne 4 ]; then
error "The installed version of getopt is not supported, can't continue :("
let 'retval++'
fi
fi >/dev/null
for prog in mplayer convert montage identify bc \
ffmpeg mktemp sed grep egrep cut $SEQ ; do
type -pf "$prog" >/dev/null
829,6 → 776,60
return $retval
}
 
# Test wether $GETOP is a compatible version; try to choose an alternate if
# possible
choose_getopt() {
if ! type -pf $GETOPT ; then
# getopt not in path
error "Required program getopt not found!"
return $EX_UNAVAILABLE
fi >/dev/null
local goe= gor=0
# Try getopt. If there's more than one in the path, try all of them
for goe in $(type -paf $GETOPT) ; do
"$goe" -T || gor=$?
if [ $gor -eq 4 ]; then
# Correct getopt found
GETOPT="$goe"
break;
fi
done >/dev/null
if [ $gor -ne 4 ]; then
error "No compatible version of getopt in path, can't continue."
error " For details on how to correct this problems, see <http://p.outlyer.net/vcs#getopt>"
return $EX_UNAVAILABLE
fi
return 0
}
 
# Set the correct argument to pass to sed
# The argument to enable extended regular expressions is different in GNU (-r)
# and POSIX (-E), try to detect it
choose_eresed() {
if [ "a" == "$(sed -r 's/A/a/' 2>/dev/null<<<'A')" ]; then
ERESED='sed -r'
elif [ "a" == "$(sed -E 's/A/a/' 2>/dev/null<<<'A')" ]; then
ERESED='sed -E'
else
error "The version of sed in the system is not supported.
Please, contact the author"
return $EX_SOFTWARE
fi
}
 
# Choose seq or jot, fail if none is present
# The actual program is wrapped in seqw()
choose_seqw() {
if type -pf seq ; then
SEQ='seq'
elif type -pf jot ; then
SEQ='jot'
else
error "Either seq or jot are required"
return $EX_UNAVAILABLE
fi
}
 
# Remove any temporal files
# Does nothing if none has been created so far
# cleanup()
2429,17 → 2430,26
# Important to do this before any message can be thrown
init_feedback
 
# Adjust sed for POSIX/GNU compatibility
choose_eresed
# Adjust seq for POSIX/GNU compatibility
choose_seqw
# Ensure $GETOPT is Linux-style getopt
choose_getopt
 
# Execute exithdlr on exit
trap exithdlr EXIT
 
show_vcs_info
 
load_config
 
# Test requirements. Important, must check before looking at the
# command line (since getopt is used for the task)
test_programs || exit $EX_UNAVAILABLE
 
# The command-line overrides any configuration. And the configuration
# is able to change the program in charge of parsing options ($GETOPT)
load_config
 
# {{{ # Command line parsing
 
# TODO: Find how to do this correctly (this way the quoting of $@ gets messed):
2634,7 → 2644,14
error "Wrong override format, it should be variable=value. Got '$2'."
exit $EX_USAGE
fi
override "$2" "command line"
if grep -q 'GETOPT=' <<<"$2" ; then
# If we're here, getopt has already been found and works, so it makes no
# sense to override it; on the other hand, if it hasn't been correctly
# set/detected we won't reach here
warn "GETOPT can't be overridden from the command line."
else
override "$2" "command line"
fi
shift
;;
-W) # Workaround mode, see wa_ss_* declarations at the start for details