summaryrefslogtreecommitdiff
path: root/Build/source/mswin32/add-info-toc.pl
blob: 4cd9899170b0b6704578ae14d5e97bcaf96a0fd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
$dd = '/';

&main;

exit 0;

sub main {
    local (@files);
    @files = @ARGV;
    $temp = &get_tmp_dir() . "ait.$$";
    open(OUT, ">$temp") || exit 1;
    print OUT "Contents:\n\n";
    while (<>) {
	$prevline = $line;
	$line = $_;
	if ($line =~ m/^\*+$/) {
	    print OUT "$prevline";
	}
	elsif ($line =~ m/^=+$/) {
	    print OUT "  $prevline";
	}
	elsif ($line =~ m/^-+$/) {
	    print OUT "    $prevline";
	}
	elsif ($line =~ m/^\.+$/) {
	    print OUT "      $prevline";
	}
    }
    print OUT "\n\n";
    @ARGV = @files;
    while (<>) {
	print OUT $_;
    }
    close (OUT);
    open (IN, $temp);
    open (OUT, ">$files[0]");
    binmode(IN); binmode(OUT);
    local($/) = undef;
    print OUT <IN>;
    close(OUT);
    close(IN);    
}

sub get_tmp_dir {
    if (!($TMP)) {	
	local (@l) = ("TMPDIR", "TEMP", "TMP", "c${dd}tmp");
	local ($var, $dir);
	foreach $var (@l) {
	    $dir = $ENV{$var};
	    if (-d $dir) { 
		$TMP = $dir;
		last;
	    }
	}
    }
    $TMP =~ s/\\/$dd/g;
	
    if ($TMP =~ /$dd$/) {
	} else { $TMP .= $dd }
}