makeman 4.3 KB

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