ref_tag_fix.pl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/perl -w
  2. # Bart Garst - 7/1/2004
  3. # additional comments at bottom of file
  4. #############################################################################
  5. # Copyright (c) 2001-2005 CrystalClear Software, Inc. #
  6. # Subject to the Boost Software License, Version 1.0. #
  7. # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) #
  8. #############################################################################
  9. use strict;
  10. # key-value of file name and id attribute
  11. # if the attributes are changed here it would be a good idea to
  12. # also change the links in doxy.xml
  13. my %files = (
  14. 'date_time_autodoc.boostbook' => 'date_time_reference',
  15. 'gregorian_autodoc.boostbook' => 'gregorian_reference',
  16. 'posix_time_autodoc.boostbook' => 'posix_time_reference',
  17. 'local_time_autodoc.boostbook' => 'local_time_reference'
  18. );
  19. foreach my $key(keys %files) {
  20. rewrite_tags($key, $files{$key});
  21. }
  22. exit;
  23. ### subroutines ###
  24. # separate words at underscores and capitalize first letter of each
  25. sub make_title {
  26. my $a = shift || die "Missing required parameter to make_title()\n";
  27. my @wrds = split(/_/, $a); # remove underscores
  28. foreach(@wrds){
  29. $_ = "\u$_"; # capitalize first letter
  30. }
  31. $a = join(" ",@wrds);
  32. return $a;
  33. }
  34. sub rewrite_tags {
  35. my $filename = shift || die "Error: argument 1 missing to sub $!";
  36. my $id_tag = shift || die "Error: argument 2 missing to sub $!";
  37. my ($line, @new_file, $title, $processed);
  38. $processed = 1; # has this file already been processed?
  39. print "...processing $filename...\n";
  40. # prepare a title from id attribute
  41. $title = make_title($id_tag);
  42. # open & read file and change appropriate line
  43. open(INP, "<$filename") || die "File open (read) failed: $!";
  44. while($line = <INP>){
  45. if($line =~ /<library-reference>/) {
  46. push(@new_file, "<section id=\"$id_tag\">\n");
  47. push(@new_file, "<title>$title</title>\n");
  48. $processed = 0; # file had not been previously processed
  49. }
  50. elsif($line =~ /<\/library-reference>/) {
  51. push(@new_file, "</section>\n");
  52. }
  53. else{
  54. push(@new_file, $line);
  55. }
  56. }
  57. close(INP);
  58. # open & write new file w/ same name
  59. open(OTP, ">$filename") || die "File open (write) failed: $!";
  60. print OTP shift(@new_file);
  61. if($processed == 0){ # has not been previously processed so add license
  62. my($day, $year) = (localtime)[3,5];
  63. my $month = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[(localtime)[4]];
  64. $year += 1900; # adjust year
  65. print OTP <<EO_LIC;
  66. <!-- Copyright (c) 2001-2005 CrystalClear Software, Inc.
  67. Subject to the Boost Software License, Version 1.0.
  68. (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  69. -->
  70. <!-- date source directory processed: $year-$month-$day -->
  71. EO_LIC
  72. }
  73. foreach(@new_file){
  74. print OTP "$_";
  75. }
  76. close(OTP);
  77. }
  78. __END__
  79. Rewrites the library-reference tagset as a section tagset and adds
  80. a title to the generated *.boostbook files. It will NOT update a
  81. file that has already been rewritten.
  82. Change log
  83. 7/19/2004
  84. - rewrite library-reference tags as section tags and add title tags
  85. - renamed fix_id sub to rewrite_tags.
  86. 8/31/2004
  87. - added license to this file and writes license to boostbook files
  88. 11/01/2004
  89. - fixed minor bug that placed multiple license statements in files if
  90. input file had already had it's tags fixed.
  91. - added a processed date to the license statement
  92. 12/02/2005
  93. - added local_time_autodoc.boostbook
  94. - updated copyrights to 2005