3 ###APPAUTHOR: xiaoranzzz
4 ###APPDATE: 2009-06-19 22:41:01
8 ###APPEXAMPLE: filescript
12 #ENV variable MUST be defined somewhere,
13 #FOR perl to search modules from,
15 use lib
$ENV{XR_PERL_MODULE_DIR
};
17 use MyPlace
::Script
::Usage qw
/help_required help_even_empty/;
18 exit 0 if(help_required
($0,@ARGV));
19 #exit 0 if(help_even_empty($0,@ARGV));
34 push @blocks,@_ if(@_);
47 return 1 if($_[0] && substr($_[0],0,1) eq ">");
51 return 1 if($_[0] && substr($_[0],0,1) eq "#");
56 my $newblock = new_block
();
60 #CHECK BLOCK TEXT INPUT
62 if(substr($_,0,1) eq '>') {
67 push @
{$newblock->{text
}},$_;
75 if(substr($_,0,1) eq '#') {
76 push @
{$newblock->{'#'}},$_;
81 foreach(split(/\t+/,$line)) {
82 if(/^([-\+><])(.+)$/) {
85 elsif(/^(.+)([-\+><])$/) {
94 if($lastop eq '<' and (!$_ eq '>') ) {
95 $text_input = "$text_input $_";
97 elsif($lastop eq '>') {
101 elsif($_ eq '>' || $_ eq '<' || $_ eq '+' || $_ eq '-') {
102 $newblock = add_block
($newblock) if($newblock->{'>'});
106 push @
{$newblock->{$lastop}},$_;
109 push @
{$newblock->{'<'}},$text_input if($text_input);
111 add_block
($newblock) if($newblock->{'>'});
113 #print STDERR Dumper($newblock),"\n";
114 #print STDERR Dumper(\@blocks),"\n";
127 my ($src,$name) = @_;
128 return $src . "/" unless($name);
130 return $src . "/$name";
133 return buildpath
($source,@_);
136 return buildpath
($target,@_);
140 return undef unless(ref $arr);
141 return undef unless(@
{$arr});
145 my ($src,$include,$exclude) = @_;
146 my @include_exp = @
{$include};
147 @include_exp = ("*") unless(@include_exp);
148 my @exclude_exp = @
{$exclude};
151 foreach(@include_exp) {
152 my $exp = buildpath
($src,$_);
153 push @in_files,glob($exp);
155 foreach(@exclude_exp) {
156 push @ex_files,glob(buildpath
($src,$_));
159 foreach my $file (@in_files) {
167 push @files,$file unless($f);
172 my ($include,$exclude,$text,$arg) = @_;
173 my $val = getarray0
($include);
176 $target =~ s/\\/\//g
;
177 $target =~ s/\/+$//g
;
185 my ($include,$exclude,$text,$arg) = @_;
186 my $val = getarray0
($include);
189 $source =~ s/\\/\//g
;
190 $source =~ s/\/+$//g
;
198 my ($include,$exclude,$text,$arg) = @_;
199 if($arg && @
{$arg}) {
200 my $dst = buildtarget
($arg->[0]);
201 print STDERR
"Writing ",$dst," ...";
202 open FO
,">",$dst or return undef;
203 print FO
join("\n",@
{$text}) or return undef;
205 print STDERR
"\t[OK]\n";
208 print STDOUT
join("\n",@
{$text});
213 die("No source set.\n") unless($source);
214 my ($include,$exclude,$text,$arg) = @_;
215 my @files = selectfiles
($source,$include,$exclude);
216 return undef unless(@files);
217 my $dst = buildtarget
(getarray0
($arg));
218 if(system("cp","-av",@files,$dst)==0) {
224 die("No target set.\n") unless($target);
225 my ($include,$exclude,$text,$arg) = @_;
226 my @files = selectfiles
($target,$include,$exclude);
227 return undef unless(@files);
228 if(system("rm","-v",,"--",@files)==0) {
237 if(substr($cmd,0,1) eq '_') {
238 $cmd = substr($cmd,1);
242 my $realcmd = "cmd_" . $cmds{$cmd};
244 my $r = &$realcmd($_->{'+'},$_->{'-'},$_->{'<'},$_->{'@'});
245 if($abort_flag and (!$r)) {
246 print STDERR
"Error occured when running \'$cmd\'\n";
251 die("Command not support:$cmd\n");