[PATCH] Fix bug in saa7146 analog tv i2c-handling
[linux-2.6/history.git] / scripts / makeman
blobdb3af647ee17f340b82b2d35abc8c100b256df64
1 #!/usr/bin/perl
3 use strict;
5 ## Copyright (C) Michael Still (mikal@stillhq.com)
6 ## Released under the terms of the GNU GPL
7 ##
8 ## A script to make or install the manpages extracted by split-man
9 ##
10 ## Arguements: $1 -- the word "convert" or "install"
11 ## $2 -- the directory containing the SGML files for the manpages
12 ## $3 -- the filename which contained the sgmldoc output
13 ## (I need this so I know which manpages to convert)
15 my($LISTING, $GENERATED, $INPUT, $OUTPUT, $front, $mode, $filename, $tmpdir);
17 if($ARGV[0] eq ""){
18 die "Usage: makeman [convert | install] <dir> <file>\n";
21 if( ! -d "$ARGV[1]" ){
22 die "Output directory \"$ARGV[1]\" does not exist\n";
25 if($ENV{"TMPDIR"} ne ""){
26 $tmpdir = $ENV{"TMPDIR"};
28 else{
29 $tmpdir = "/tmp";
32 if($ARGV[0] eq "convert"){
33 open LISTING, "grep \"<refentrytitle>\" $ARGV[2] |";
34 while(<LISTING>){
35 s/<\/.*$//;
36 s/^.*>//;
37 s/\.sgml//;
38 s/struct //;
39 s/typedef //;
41 chomp;
42 $filename = $_;
43 print "Processing $filename\n";
45 # Open the input file to extract the front matter, generate the man page,
46 # and open it, and the rearrange everything until it is happy
47 open INPUT, "< $ARGV[1]/$filename.sgml";
48 $front = "";
49 $mode = 0;
51 # The modes used here are:
52 # mode = 0
53 # <!-- BEGINFRONTTAG -->
54 # <!-- <bookinfo> mode = 1
55 # <!-- <legalnotice> mode = 2
56 # <!-- ...GPL or whatever...
57 # <!-- </legalnotice> mode = 4
58 # <!-- </bookinfo> mode = 3
59 # <!-- ENDFRONTTAG -->
61 # ...doco...
63 # I know that some of the if statements in this while loop are in a funny
64 # order, but that is deliberate...
65 while(<INPUT>){
66 if($mode > 0){
67 s/<!-- //;
68 s/ -->//;
69 s/<docinfo>//i;
70 s<\/docinfo>//i;
71 s/^[ \t]*//i;
74 if($mode == 2){
75 if(/<para>/i){
77 elsif(/<\/para>/i){
78 $front = "$front.\\\" \n";
80 elsif(/<\/legalnotice>/i){
81 $mode = 4;
83 elsif(/^[ \t]*$/){
85 else{
86 $front = "$front.\\\" $_";
90 if($mode == 1){
91 if(/<title>(.*)<\/title>/i){
92 $front = "$front.\\\" This documentation was generated from the book titled \"$1\", which is part of the Linux kernel source.\n.\\\" \n";
94 elsif(/<legalnotice>/i){
95 $front = "$front.\\\" This documentation comes with the following legal notice:\n.\\\" \n";
96 $mode = 2;
99 elsif(/<author>/i){
100 $front = "$front.\\\" Documentation by: ";
102 elsif(/<firstname>(.*)<\/firstname>/i){
103 $front = "$front$1 ";
105 elsif(/<surname>(.*)<\/surname>/i){
106 $front = "$front$1 ";
108 elsif(/<email>(.*)<\/email>/i){
109 $front = "$front($1)";
111 elsif(/\/author>/i){
112 $front = "$front\n";
115 elsif(/<copyright>/i){
116 $front = "$front.\\\" Documentation copyright: ";
118 elsif(/<holder>(.*)<\/holder>/i){
119 $front = "$front$1 ";
121 elsif(/<year>(.*)<\/year>/i){
122 $front = "$front$1 ";
124 elsif(/\/copyright>/i){
125 $front = "$front\n";
128 elsif(/^[ \t]*$/
129 || /<affiliation>/i
130 || /<\/affiliation>/i
131 || /<address>/i
132 || /<\/address>/i
133 || /<authorgroup>/i
134 || /<\/authorgroup>/i
135 || /<\/legalnotice>/i
136 || /<date>/i
137 || /<\/date>/i
138 || /<edition>/i
139 || /<\/edition>/i
140 || /<pubdate>/i
141 || /<\/pubdate>/i){
143 else{
144 print "Unknown tag in manpage conversion: $_";
148 if($mode == 0){
149 if(/<bookinfo>/i){
150 $mode = 1;
154 if($mode == 4){
155 if(/<\/bookinfo>/i){
156 $mode = 3;
160 close INPUT;
162 system("cd $ARGV[1]; docbook2man $filename.sgml; mv $filename.9 $tmpdir/$$.9\n");
163 open GENERATED, "< $tmpdir/$$.9";
164 open OUTPUT, "> $ARGV[1]/$filename.9";
166 print OUTPUT "$front";
167 print OUTPUT ".\\\" For comments on the formatting of this manpage, please contact Michael Still <mikal\@stillhq.com>\n\n";
168 while(<GENERATED>){
169 print OUTPUT "$_";
171 close OUTPUT;
172 close GENERATED;
174 system("gzip -f $ARGV[1]/$filename.9\n");
175 unlink("$tmpdir/$$.9");
178 elsif($ARGV[0] eq "install"){
179 system("mkdir -p /usr/local/man/man9/; install $ARGV[1]/*.9.gz /usr/local/man/man9/");
181 else{
182 die "Usage: makeman [convert | install] <dir> <file>\n";
185 print "Done\n";