src2doxy.pl 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/perl -w -i~
  2. # src2doxy.pl - create doxygen-compatible comments from readable C source
  3. # Copyright (C) 2008 Ingo Korb <ingo@akana.de>
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; version 2 of the License only.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. #
  18. # This script parses a subset of kernel-doc style comments and rewrites
  19. # them as something doxygen will understand.
  20. use strict;
  21. my $incomment = 0;
  22. my $inspecialcomment = 0;
  23. my @postcomment = ();
  24. my @outputstack;
  25. while (<>) {
  26. my $filename;
  27. ($filename = $ARGV) =~ s!.*/!!;
  28. chomp;
  29. s/\r$//;
  30. s/\s+$//;
  31. # doxygen is too stupid to understand after-the-variable comments
  32. # without external help. WARNING: Will substitute within strings!
  33. s!([^ \t]\s+)/// !$1///< !;
  34. $incomment = 1 if m!^/\*!;
  35. if (m!^/\*\*$!) {
  36. $inspecialcomment = 1;
  37. # Kill output
  38. $_ = "";
  39. next;
  40. }
  41. if ($incomment) {
  42. if (m!\*/$!) {
  43. # End of comment
  44. $incomment = 0;
  45. $inspecialcomment = 0;
  46. @outputstack = @postcomment;
  47. @postcomment = ();
  48. } elsif (/$filename:\s+(.*).?\s*$/) {
  49. # Add file description
  50. push @postcomment, "\n/*! \\file $ARGV\n * \\brief $1. */\n";
  51. }
  52. if ($inspecialcomment == 1) {
  53. # First line of special comment: Brief description
  54. $inspecialcomment = 2;
  55. m/^\s*\*\s*((struct |union )?[^: \t]+):?\s+-?\s*(.*)\s*$/;
  56. $_ = "/*! \\brief $3\n *";
  57. } elsif ($inspecialcomment == 2) {
  58. # Modify parameters
  59. s/\@([^: \t]+)\s*:\s+(.*)\s*$/\\param $1 $2/;
  60. }
  61. }
  62. } continue {
  63. print "$_\n";
  64. while (scalar(@outputstack)) {
  65. print shift @outputstack,"\n";
  66. }
  67. }