################################################## # # GiantDisc mp3 Jukebox # # © 2000, Rolf Brugger # ################################################## package gdparams; #use lib '/usr/local/bin'; use strict; use Getopt::Long; my @mp3dirs; ############################################################ ### Global variables (accessible from anywhere) # IMPORTANT ERROR! all modules refer to gdparms::varname instead # of gdparams::varname # ... however, it works ... I just don't know why :-/ #my ($dbhost, $shutdowncmd, $extmp3player, $defrecbitrate, # $systemonline); ### Global constants my $minfreehdspace = 1000; # minimal space required for a directory, # that it can be used to record and # compress a cd (in MB) ############################################################ ### sub get_configfile_params{ ### Parameters: Call-by-reference my ($dbhost, $commmode, $serialdevice, $serialspeed, $tcpiphost, $tcpipport, $playerhost, $playertype, $snddevice, $playerapp, $mp3playerparams, $oggplayerparams, $ptlogger, $mp3encoder, $logtarget, $shutdowncmd, $extmp3player, $defrecbitrate, $systemonline ) = @_; ### Read configuration file im home directory open (CONF, "< ".gdbase()."/.gdconfig") or die "Error: could not open configuration file .gdconfig\n"; my $line; while(){ $line = $_; chop $line; $line =~ tr/\r/ /; # \w word-char # \w non-word-char # \s whitespace-char # \S non-whitespace-char if($line =~ m/^dbhost.*=\s*(\S+)/i ){ $$dbhost = $1; } if($line =~ m/^commmode.*=\s*([0-9]+)/i ){ $$commmode = $1; } if($line =~ m/^serialdevice.*=\s*([\w\/]+)/i ){ $$serialdevice = $1; } if($line =~ m/^serialspeed.*=\s*([0-9]+)/i ){ $$serialspeed = $1; } if($line =~ m/^tcpiphost.*=\s*(\S+)/i ){ $$tcpiphost = $1; } if($line =~ m/^tcpipport.*=\s*([0-9]+)/i ){ $$tcpipport = $1; } if($line =~ m/^playerhost.*=\s*(\S+)/i ){ $$playerhost = $1; } if($line =~ m/^playertype.*=\s*([0-9]+)/i ){ $$playertype = $1; } if($line =~ m/^playerapp.*=\s*(\S+)/i ){ $$playerapp = $1; } if($line =~ m/^playerparams.*=\s*(.*)$/i ){ # match anything to end of line print "\nWARNING: as of v1.20 the option 'playerparams' has been replaced by\n"; print " 'mp3playerparams' and 'oggplayerparams'. Update .gdconfig accordingly\n\n"; #$$playerparams = $1; } if($line =~ m/^mp3playerparams.*=\s*(.*)$/i ){ # match anything to end of line $$mp3playerparams = $1; } if($line =~ m/^oggplayerparams.*=\s*(.*)$/i ){ # match anything to end of line $$oggplayerparams = $1; } if($line =~ m/^shutdowncmd.*=\s*(.*)$/i ){ # match anything to end of line $$shutdowncmd = $1; } if($line =~ m/^extmp3player.*=\s*(.*)$/i ){ # match anything to end of line $$extmp3player = $1; } if($line =~ m/^sounddevice.*=\s*(\S+)/i ){ $$snddevice = $1; } if($line =~ m/^mp3encoder.*=\s*(\w+)/i ){ $$mp3encoder = $1; } if($line =~ m/^logtarget.*=\s*(\w+)/i ){ if ($1 eq "stdout" || $1 eq "logfile" || $1 eq "devnull"){ $$logtarget = $1; } } if($line =~ m/^ptlogger.*=\s*(\S+)/i ){ $$ptlogger = $1; } if($line =~ m/^defrecbitrate.*=\s*(.+)/i ){ # match anything to end of line $$defrecbitrate = $1; } if($line =~ m/^systemonline.*=\s*([0-9])/i ){ $$systemonline = $1; } } close (CONF); } ############################################################ ### sub get_otherclients_params{ ### Parameters: Call-by-reference my ($keymap # type: reference to an empty hash )= @_; ### Read configuration file im home directory open (CONF, "< ".gdbase()."/.gdconfig") or die "Error: could not open configuration file .gdconfig\n"; my $line; while(){ $line = $_; chop $line; $line =~ tr/\r/ /; # \w word-char # \w non-word-char # \s whitespace-char # \S non-whitespace-char if($line =~ m/^keymap.*=\s*(\S+)\s*-\s*(\S+)\s*$/i ){ print ("keymap: key: $1, val: $2\n"); $$keymap{$1} = $2; } } close (CONF); } ############################################################ ### translate logtarget string to integer sub logtarget_to_int{ my ($logtargetstr) = @_; if ($logtargetstr eq "devnull") {return 0;} if ($logtargetstr eq "logfile") {return 1;} if ($logtargetstr eq "stdout" ) {return 2;} return 2; # default } ############################################################ ### sub get_commandline_params{ my ($dbhost, $commmode, $serialdevice, $serialspeed, $tcpiphost, $tcpipport, $playerhost, $playertype, $snddevice, $playerapp, $mp3playerparams, $oggplayerparams, $ptlogger, $mp3encoder, $logtarget) = @_; # ARGV passed implicitly my $help; $Getopt::Long::autoabbrev=1; GetOptions( "help" => \$help, "dbhost:s" => $dbhost, # $dbhost is already a reference "commmode:i" => $commmode, "serialdevice:s" => $serialdevice, "serialspeed:i" => $serialspeed, "tcpiphost:s" => $tcpiphost, "tcpipport:i" => $tcpipport, "playertype:i" => $playertype, "playerhost:s" => $playerhost, "sounddevice:s" => $snddevice, "mp3playerparams=s" => $mp3playerparams, "oggplayerparams=s" => $oggplayerparams, "ptlogger:s" => $ptlogger, "mp3encoder:s" => $mp3encoder, "logtarget:s" => $logtarget ); if ($help){ print <