#!/usr/bin/env perl # flac123.wrapper - Wrapper for "flac123" # License: BSD-style (for this file only) # Revision: 080925 #--------------------------------------------------------------------- # overview #--------------------------------------------------------------------- # This is a wrapper for "flac123" (which must be renamed to "flac123. # bin"). This wrapper operates as follows: # # a. It prevents multiple instances. # # b. If the environment variable AOSSFLAC123 is not set, or if # it's equal to "true", "yes", or a similar value, this wrapper # runs "flac123.bin" via "aoss". Otherwise, it runs "flac123. # bin" directly. #--------------------------------------------------------------------- # module setup #--------------------------------------------------------------------- require 5.6.1; use strict; use Carp; use warnings; # Trap warnings $SIG {__WARN__} = sub { die @_; }; #--------------------------------------------------------------------- # basic constants #--------------------------------------------------------------------- use constant ZERO => 0; # Zero use constant ONE => 1; # One use constant FALSE => 0; # Boolean FALSE use constant TRUE => 1; # Boolean TRUE #--------------------------------------------------------------------- # program parameters #--------------------------------------------------------------------- my $DEVDSP = '/dev/dsp'; # Absolute path for "dsp" device node #--------------------------------------------------------------------- # main routine #--------------------------------------------------------------------- sub Main { my $n; # Scratch (integer ) my $str; # Scratch (string ) #--------------------------------------------------------------------- # Initial setup. unshift (@ARGV, '__META_PREFIX__/bin/flac123.bin'); #--------------------------------------------------------------------- # Prevent multiple instances. $str = `/bin/ps ax 2>&1`; $str = "" unless defined $str; exit ONE if $str =~ m@\bflac123\.bin\b@; #--------------------------------------------------------------------- # Handle AOSSFLAC123 feature $str = $ENV {AOSSFLAC123}; $str = "" unless defined $str; $str = 'yes' unless length $str; if ($str =~ m@^(1|one?|true|y|yes)\z@i) { # See notes near start of this file unshift (@ARGV, 'aoss'); } #--------------------------------------------------------------------- # Chain to target program (directly or indirectly). exec @ARGV; } #--------------------------------------------------------------------- # main program #--------------------------------------------------------------------- &Main(); # Call the main routine exit ZERO; # Normal exit