updated git and svn scripts
[xrzperl.git] / firsthtml
blob916ee6a923f955b6a1668bb89660381a770ae7b2
1 #!/usr/bin/perl -w
2 use strict;
3 ###APPNAME: firsthtml
4 ###APPAUTHOR: root
5 ###APPDATE: Tue Sep 18 10:56:07 2007
6 ###APPVER: 0.1
7 ###APPDESC: grep the first html file name
8 ###APPUSAGE:
9 ###APPEXAMPLE: ls | firsthtml
10 ###APPOPTION:
11 #$ARGV[0]="--help" unless(@ARGV);
12 exit 0 unless(system("plhelp",$0,(@ARGV)));
14 my @INDEXS=qw(cs2w_index cover index toc default aaa bbb content first);
15 my @EXTS=qw(htm html shtml txt);
16 sub isIndexFile($) {
17 my $target=shift;
18 return 0 unless($target);
19 foreach my $indexName(@INDEXS) {
20 return 1 if ($target =~ m/\b${indexName}\b[^\/\\]*$/i);
23 sub isHtmlFile($) {
24 my $target=shift;
25 return 0 unless($target);
26 foreach my $extName(@EXTS) {
27 return 1 if ($target =~ m/\.\b$extName\b$/i);
31 sub getFirst() {
32 my @allFiles;
33 my @htmlFiles;
34 my @indexFiles;
35 while(<>) {
36 chomp;
37 push(@allFiles,$_);
38 if (isHtmlFile($_)) {
39 push(@htmlFiles,$_);
40 push(@indexFiles,$_) if(isIndexFile($_));
43 # return if (@allFiles<1);
44 # return $allFiles[0] if(@allFiles==1 or @htmlFiles<1);
45 return if(@htmlFiles<1);
46 return $htmlFiles[0] if(@htmlFiles==1 or @indexFiles<1);
47 return $indexFiles[0] if(@indexFiles==1);
49 my $result;
50 my $minSlashCount=256;
51 foreach my $filename(@indexFiles) {
52 my $slashCount=$filename =~ tr /\//\//;
53 if($slashCount<$minSlashCount) {
54 $result=$filename;
55 $minSlashCount=$slashCount;
57 return $result if($minSlashCount==0);
59 return ($result);
62 print &getFirst();