updated git and svn scripts
[xrzperl.git] / wenku1_2
blobabe8d51d8273b85c6bb9e1b06731a1dfbcc700af
1 #!/usr/bin/perl -w
2 ###APPNAME: wenku1_2
3 ###APPAUTHOR: geek
4 ###APPDATE: Sat Oct 6 02:39:49 2007
5 ###APPVER: 0.1
6 ###APPDESC: Convert tidywenku1 to tidywenku2
7 ###APPUSAGE:
8 ###APPEXAMPLE:
9 ###APPOPTION:
10 use strict;
11 $ARGV[0]="-h" unless(@ARGV);
12 foreach(@ARGV){
13 exit(system("plhelp",$0,@ARGV)) if($_ eq "-h" || $_ eq "--help");
16 my @PAT;
17 my @REP;
19 sub buildRule($$) {
20 push @PAT,shift;
21 push @REP,shift;
23 my $SIGN='<div align="right" id="sign">WenkuV2.0 Geek@MYPLACE</b><br>' . `date` . '</div>';
24 buildRule qr/<div[^<>]*id\s*=\s*["']*sign\s*["']*[^<>]*>.*$/,$SIGN;
25 buildRule qr/<\/script>/,"</script>" . "\n" .
26 '<script language="JavaScript" src="file:///c:/windows/wenku.js"></script>' . "\n" .
27 '<script language="JavaScript" src="file:///etc/wenku.js"></script>' . "\n";
28 buildRule qr/<link[^<>]*wenku.css[^<>]*>/,
29 '<link rel="stylesheet" href="wenku.css" type="text/css">' . "\n" .
30 '<link rel="stylesheet" href="file:///c:/windows/wenku.css" type="text/css">' . "\n" .
31 '<link rel="stylesheet" href="file:///etc/wenku.css" type="text/css">' . "\n";
33 my $TEMPFILE=`mktemp`;
35 sub TidyFile($) {
36 my $filename=shift;
37 return 0 unless(-w $filename);
38 system("cp","-f",$filename,$TEMPFILE) and return 0;
39 if(-r $TEMPFILE and -w $filename) {
40 open(TEMP,"<",$TEMPFILE) or die("$!\n");
41 open(FH,">",$filename) or die("$!\n");
42 #open(FH,">/dev/stdout") or die("$!\n");
43 while(<TEMP>) {
44 my $LINE=$_;
45 for(my $i=0;$i<@PAT;$i++) {
46 $LINE =~ s/$PAT[$i]/$REP[$i]/g;
48 $LINE =~ s/='([^']*)'/="$1"/g;
49 print FH ($LINE,"\n");
51 close(TEMP);
52 close(FH);
53 return 1;
55 return 0;
59 foreach my $cur(@ARGV) {
60 if(-f $cur and $cur =~ m/\.(htm|html)$/i) {
61 print STDERR ("$cur ... \r");
62 if (TidyFile $cur) {
63 print STDERR ("$cur [Done] \n");
65 else {
66 print STDERR ("$cur [Failed] \n");
69 elsif(-d $cur) {
70 foreach my $sub(glob("$cur/*")) {
71 if($sub =~ m/\.(htm|html)$/i) {
72 print STDERR ("$sub ... \r");
73 TidyFile $sub;
76 print STDERR ("$cur [Done] \n");
78 else {
79 print STDERR ("$cur [Ingored]\n");