| 1 |
#!/usr/bin/perl -w |
| 2 |
# $Id: workman,v 1.3 2013/07/14 21:24:13 tom Exp $ |
| 3 |
|
| 4 |
# |
| 5 |
# Initialize Cdk. |
| 6 |
# |
| 7 |
use strict; |
| 8 |
use Cdk; |
| 9 |
Cdk::init(); |
| 10 |
|
| 11 |
# Pop up the opening label. |
| 12 |
popupLabel( |
| 13 |
[ |
| 14 |
"<C></16/B>Workman Database Editor.", |
| 15 |
"", |
| 16 |
"<C></24/B>Written By Mike Glover" |
| 17 |
] |
| 18 |
); |
| 19 |
|
| 20 |
# Set a default name for the workman database. |
| 21 |
my $workmandb = $ENV{'HOME'} . "/.workmandb"; |
| 22 |
|
| 23 |
# Open up the database and read in the contents. |
| 24 |
my @cdList = readWorkmanDatabase($workmandb); |
| 25 |
|
| 26 |
# Let the user play with the given information. |
| 27 |
playWithWorkManDatabase(@cdList); |
| 28 |
|
| 29 |
# |
| 30 |
# This allows the user to manipulate the workman database. |
| 31 |
# |
| 32 |
sub playWithWorkManDatabase { |
| 33 |
} |
| 34 |
|
| 35 |
# |
| 36 |
# This reads in the current contents of the workman database. |
| 37 |
# |
| 38 |
sub readWorkmanDatabase { |
| 39 |
my $filename = shift; |
| 40 |
my @contents = (); |
| 41 |
my $count = 0; |
| 42 |
my $x = 0; |
| 43 |
|
| 44 |
# Return if we can't open the file. |
| 45 |
return if !( open( FILE, $filename ) ); |
| 46 |
|
| 47 |
# Slurp in the file. |
| 48 |
my @workmandb = <FILE>; |
| 49 |
chomp @workmandb; |
| 50 |
|
| 51 |
# Strip out the contents of the database. |
| 52 |
for ( $x = 0 ; $x < $#workmandb ; $x++ ) { |
| 53 |
|
| 54 |
# Remove comments and empty lines. |
| 55 |
next if $workmandb[$x] =~ /^#/; |
| 56 |
next if $workmandb[$x] =~ /^$/; |
| 57 |
|
| 58 |
# Is this a start of a CD listing. |
| 59 |
if ( $workmandb[$x] =~ /^tracks (\d*)/ ) { |
| 60 |
my $trackCount = $1; |
| 61 |
my $trackLine = $workmandb[ $x++ ]; |
| 62 |
my $cdName = $workmandb[ $x++ ]; |
| 63 |
my $artist = $workmandb[ $x++ ]; |
| 64 |
my @tracks = (); |
| 65 |
my $current = 0; |
| 66 |
|
| 67 |
# Get each track from the database. |
| 68 |
for ( $current = 0 ; $current < $trackCount ; $current++ ) { |
| 69 |
push( @tracks, $workmandb[ $x++ ] ); |
| 70 |
} |
| 71 |
$x--; |
| 72 |
|
| 73 |
# Create the database object and put it onto the stack. |
| 74 |
my $object = |
| 75 |
new WorkManData( $trackLine, $cdName, $artist, @tracks ); |
| 76 |
|
| 77 |
# Put it onto the stack. |
| 78 |
push( @contents, $object ); |
| 79 |
} |
| 80 |
} |
| 81 |
return @contents; |
| 82 |
} |
| 83 |
|
| 84 |
# |
| 85 |
# This writes out a workman database. |
| 86 |
# |
| 87 |
sub writeWorkManData { |
| 88 |
} |
| 89 |
|
| 90 |
######################################### |
| 91 |
package WorkManData; |
| 92 |
|
| 93 |
# |
| 94 |
# This creates a new object. |
| 95 |
# |
| 96 |
sub new { |
| 97 |
my ( $type, $trackLine, $cdName, $artist, @tracks ) = @_; |
| 98 |
my @trackInfo = (); |
| 99 |
my @indexInfo = (); |
| 100 |
my $self = {}; |
| 101 |
|
| 102 |
# Split the trackline apart. |
| 103 |
my ( $junk, $trackCount, @index ) = split( /\s+/, $trackLine ); |
| 104 |
|
| 105 |
# Clean off the garbage from the track lines. |
| 106 |
for ( my $x = 0 ; $x <= $#tracks ; $x++ ) { |
| 107 |
|
| 108 |
# Strip out the track name. |
| 109 |
my $trackName = $1 if $tracks[$x] =~ /^track\s+(.*)/; |
| 110 |
|
| 111 |
# If there is no track name, then provide a default answer. |
| 112 |
if ( $trackName ne "" ) { |
| 113 |
push( @trackInfo, $trackName ); |
| 114 |
} |
| 115 |
else { |
| 116 |
push( @trackInfo, "No Track Name Given" ); |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
# Store the info in the object. |
| 121 |
( $self->{'Artist'} = $1 ) if $artist =~ /^artist\s+(.*)/; |
| 122 |
( $self->{'CDName'} = $1 ) if $cdName =~ /^cdname\s+(.*)/; |
| 123 |
$self->{'Tracks'} = \@trackInfo; |
| 124 |
$self->{'Index'} = \@indexInfo; |
| 125 |
|
| 126 |
return bless $self; |
| 127 |
} |