Update.
[glibc.git] / linuxthreads / man / troffprepro
blobba564fefbe4c11ced1a1c841855b16d92c5e3cbc
1 #!/usr/local/bin/perl
3 $insynopsis = 0;
5 open(INPUT, $ARGV[0]) || die("cannot open $ARGV[0]");
6 open(OUTPUT, "> $ARGV[1]") || die("cannot create $ARGV[1]");
8 select(OUTPUT);
10 line:
11 while(<INPUT>) {
12 if (/^\.XREF (.*)$/) {
13 $xref = $1;
14 $_ = $ARGV[1];
15 m/^.*\.(([1-8]).*)$/;
16 $suffix = $1;
17 $extension = $2;
18 open(XREF, "> $xref.$suffix");
19 print XREF ".so man$extension/$ARGV[1]\n";
20 close(XREF);
21 next line;
23 if (/^\.SH/) {
24 $insynopsis = /SYNOPSIS/;
25 print $_;
26 next;
28 if ($insynopsis) {
29 if (/^#/) {
30 print ".B ", $_;
32 elsif (/^[a-z]/) {
33 chop;
34 # if (m/^([a-zA-Z][a-zA-Z0-9_]*\s+[a-zA-Z][a-zA-Z0-9_]*)\(/) {
35 # print ".B \"", $1, "\"\n";
36 # $_ = '(' . $';
37 # }
38 # s/([a-zA-Z][a-zA-Z0-9_]*)(\s*[,()=])/" \1 "\2/g;
39 s/([ *])([a-zA-Z][a-zA-Z0-9_]*)(\s*[,)=])/\1" \2 "\3/g;
40 print ".BI \"", $_, "\"\n";
42 else {
43 print $_;
45 next;
47 chop;
48 s/!([^!]+)!\|([^|]+)\|([^\s]*)\s*/\n.BI "\1" "\2\3"\n/g;
49 s/([!|])([^!|]+)\1([^\s]*)\s*/do subst($1,$2,$3)/eg;
50 s/^\n+//;
51 s/\n+$//;
52 s/\n\n+/\n/g;
53 print $_, "\n";
56 close(INPUT);
57 close(OUTPUT);
59 sub subst {
60 local ($a, $b, $c) = @_;
61 if ($c) {
62 "\n" . ($a eq "!" ? ".BR " : ".IR ") . "\"$b\" $c\n"
63 } else {
64 "\n" . ($a eq "!" ? ".B " : ".I ") . "\"$b\"\n"