chiark / gitweb /
eglibc (2.11.3-4+deb6u3) squeeze-lts; urgency=medium
[eglibc.git] / linuxthreads / man / troffprepro
1 #!/usr/local/bin/perl
2
3 $insynopsis = 0;
4
5 open(INPUT, $ARGV[0]) || die("cannot open $ARGV[0]");
6 open(OUTPUT, "> $ARGV[1]") || die("cannot create $ARGV[1]");
7
8 select(OUTPUT);
9
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;
22   }
23   if (/^\.SH/) {
24     $insynopsis = /SYNOPSIS/;
25     print $_;
26     next;
27   }
28   if ($insynopsis) {
29     if (/^#/) {
30       print ".B ", $_;
31     }
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";
41     }
42     else {
43       print $_;
44     }
45     next;
46   }
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";
54 }
55
56 close(INPUT);
57 close(OUTPUT);
58
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"
65   }
66 }
67
68