version 1.15, 2010/01/12 20:30:55 |
version 1.19, 2010/01/21 21:10:38 |
|
|
#!/usr/bin/perl |
#!/usr/bin/perl |
# $AFresh1: todo.pl,v 1.14 2010/01/11 19:52:06 andrew Exp $ |
# $AFresh1: todo.pl,v 1.18 2010/01/19 18:53:36 andrew Exp $ |
######################################################################## |
######################################################################## |
# todo.pl *** a perl version of todo.sh. Uses Text::Todo. |
# todo.pl *** a perl version of todo.sh. Uses Text::Todo. |
# |
# |
|
|
use strict; |
use strict; |
use warnings; |
use warnings; |
|
|
use Data::Dumper; |
|
|
|
use Getopt::Std; |
use Getopt::Std; |
use Text::Todo; |
use Text::Todo; |
|
|
use version; our $VERSION = qv('0.0.1'); |
use version; our $VERSION = qv('0.1.0'); |
|
|
# option defaults |
# option defaults |
my $config_file = $ENV{HOME} . '/todo.cfg'; |
my $config_file = $ENV{HOME} . '/todo.cfg'; |
|
|
|
|
if ( exists $actions{$action} ) { |
if ( exists $actions{$action} ) { |
my $config = read_config($config_file); |
my $config = read_config($config_file); |
my $action = $actions{$action}->( $config, @ARGV ); |
my $result = $actions{$action}->( $config, @ARGV ); |
} |
} |
else { |
else { |
usage(); |
usage(); |
|
|
my @pri_list; |
my @pri_list; |
if ($pri) { |
if ($pri) { |
$pri = uc $pri; |
$pri = uc $pri; |
if ( $pri !~ /^[A-Z]$/xms ) { |
if ( $pri !~ /^[[:upper:]]$/xms ) { |
die "usage: todo.pl listpri PRIORITY\n", |
die "usage: todo.pl listpri PRIORITY\n", |
"note: PRIORITY must a single letter from A to Z.\n"; |
"note: PRIORITY must a single letter from A to Z.\n"; |
} |
} |
|
|
if ( !( $line && $line =~ /^\d+$/xms && $priority ) ) { |
if ( !( $line && $line =~ /^\d+$/xms && $priority ) ) { |
die "$error\n"; |
die "$error\n"; |
} |
} |
elsif ( $priority !~ /^[A-Z]$/xms ) { |
elsif ( $priority !~ /^[[:upper:]]$/xms ) { |
$error .= "\n" . 'note: PRIORITY must a single letter from A to Z.'; |
$error .= "\n" . 'note: PRIORITY must a single letter from A to Z.'; |
die "$error\n"; |
die "$error\n"; |
} |
} |
|
|
if (s/^\s*export\s+//xms) { |
if (s/^\s*export\s+//xms) { |
my ( $key, $value ) = /^([^=]+)\s*=\s*"?(.*?)"?\s*$/xms; |
my ( $key, $value ) = /^([^=]+)\s*=\s*"?(.*?)"?\s*$/xms; |
if ($key) { |
if ($key) { |
foreach my $k ( keys %config ) { |
foreach my $k ( keys %{ $config } ) { |
$value =~ s/\$\Q$k\E/$config{$k}/gxms; |
$value =~ s/\$\Q$k\E/$config->{$k}/gxms; |
$value =~ s/\${\Q$k\E}/$config{$k}/gxms; |
$value =~ s/\${\Q$k\E}/$config->{$k}/gxms; |
} |
} |
foreach my $k ( keys %ENV ) { |
foreach my $k ( keys %ENV ) { |
$value =~ s/\$\Q$k\E/$ENV{$k}/gxms; |
$value =~ s/\$\Q$k\E/$ENV{$k}/gxms; |