aboutsummaryrefslogtreecommitdiff
path: root/unix/man/fixurls
blob: 8c3484778e01c08797bf3cdb39b65dcb80f98e72 (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
#!/usr/bin/perl

open(OMIT, "9 sed -n 's/.*Omitman\\[\"(.*)\\((.)\\)\".*/\\1 \\2/p' /usr/local/plan9/dist/checkman.awk |") || die "omit: $!";
@omit = <OMIT>;
close OMIT;
chomp @omit;
push @omit, "grep 1", "lseek 2", "tcs 1", "sed 1", "rc 1", "strcat 3", "yacc 1";

sub noref {
	my ($p, $s) = @_;

	$text =~ s!<a href="../man$s/$p.html">(([^<]|<[^/]|</[^a])*)</a>!\1!g;
}

for($i=0; $i<@ARGV; $i++){
	open(IN, $ARGV[$i]) || die "open $ARGV[$i]: $!";
	@text = <IN>;
	close IN;
	$text = join("", @text);

	foreach $o (@omit) {
		$o =~ /(.*) (.*)/;
		noref($1, $2);
	}

	$text =~ s!../man(.)/([^.]*)\.html!$2$1.html!g;
	$text =~ s!(https://9fans.github.io/plan9port/unix)!<a href="\1">\1</a>!g;

	open(OUT, ">$ARGV[$i]") || die "open $ARGV[$i]: $!";
	print OUT $text;
	close OUT;
}

exit 0;