996
|
1 #!/bin/perl
|
|
2
|
|
3 # Change .html to .htm and change all URLs appropriately in the file
|
|
4 # being edited; also fix a bug in makeinfo that sometimes causes
|
|
5 # incorrect anchors to be used in the META REFRESH commands.
|
|
6 #
|
|
7 # This script assumes the output from makeinfo is reasonably correct, so it
|
|
8 # needs to be run on a system that supports filenames longer than 8.3; it
|
|
9 # converts these long filenames into 8.3 form.
|
|
10
|
|
11 my @base32str=qw{0 1 2 3 4 5 6 7 8 9 a b c d e f
|
|
12 g h i j k l m n o p q r s t u v};
|
|
13
|
|
14 # Hash a string into 8 5-bit segments, base32 encoded
|
|
15 # The algorithm isn't designed to be secure or anything like that, but simply
|
|
16 # to avoid collisions in what filenames are mapped to. I don't know how well
|
|
17 # it succeeds at this. Note that this can't map to "index" unless the input
|
|
18 # is "index", in which case it always does; this is a special case. The
|
|
19 # hashing is case-insensitive to reduce errors on DOS.
|
|
20 sub hash8x5($)
|
|
21 {
|
|
22 my $low32sf=0;
|
|
23 my $high32sf=0;
|
|
24 my $str=shift;
|
|
25 $str=lc $str;
|
|
26 defined($str) or die;
|
|
27 return "index" if $str eq "index";
|
|
28 while($str ne '')
|
|
29 {
|
|
30 $low32sf ^= !!($low32sf & (1<<19));
|
|
31 $low32sf &= (1<<19)-1;
|
|
32 $low32sf <<= 1;
|
|
33 $low32sf ^= ord $str;
|
|
34 $low32sf *= 41;
|
|
35 $high32sf ^= !!($high32sf & (511<<11));
|
|
36 $high32sf &= (1<<11)-1;
|
|
37 $high32sf <<= 9;
|
|
38 $high32sf ^= ord $str;
|
|
39 $high32sf *= 43;
|
|
40 $str = substr $str, 1;
|
|
41 }
|
|
42 $str = $base32str[$low32sf & 31]; $low32sf >>= 5;
|
|
43 $str .= $base32str[$low32sf & 31]; $low32sf >>= 5;
|
|
44 $str .= $base32str[$low32sf & 31]; $low32sf >>= 5;
|
|
45 $str .= $base32str[$low32sf & 31];
|
|
46 $str .= $base32str[$high32sf & 31]; $high32sf >>= 5;
|
|
47 $str .= $base32str[$high32sf & 31]; $high32sf >>= 5;
|
|
48 $str .= $base32str[$high32sf & 31]; $high32sf >>= 5;
|
|
49 $str .= $base32str[$high32sf & 31];
|
|
50 return $str;
|
|
51 }
|
|
52
|
|
53 $/=undef; #read the whole file at a time
|
|
54
|
|
55 open CSSFILE, "<ickstyle.css";
|
|
56 my $css = <CSSFILE>;
|
|
57 close CSSFILE;
|
|
58
|
|
59 while(<>)
|
|
60 {
|
|
61 /^<meta http-equiv="refresh"/s and do{
|
|
62 s/\#\%/'#g_t%'/ge;
|
|
63 s/\%/_00/g;
|
|
64 s/(url=)([^\">]*?).html([\"\#])/$1 . hash8x5($2) . ".htm" . $3/ge;
|
|
65 };
|
|
66 s/(\-\-><\/style>)/$css$1/;
|
|
67 s/(href=\")([^\">]*?).html([\"\#])/$1 . hash8x5($2) . ".htm" . $3/ge;
|
|
68 s=^(.*?)\.html$="mv html/".$1.".html html/".hash8x5($1).".htm"=gemi;
|
|
69 print;
|
|
70 }
|