1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
5 # doxygen-convert-h.pl is a script that would be used to convert old
6 # documented style ACE/TAO header files to doxygen style.
9 # (Search for @todo in this script)
15 ##############################################################################
18 if (!getopts
('dDhsu') || $opt_h) {
19 print "doxygen-convert-h.pl [-dDhsu] filenames or directories\n";
21 print " -d debug script\n";
22 print " -D really verbose debug\n";
23 print " -h display this help\n";
24 print " -s print result to stdout\n";
25 print " -u turn off file verification\n";
29 ## if verbose debug, also regular debug
30 $opt_d = 1 if (defined $opt_D);
32 ##############################################################################
40 my($fh) = new FileHandle
();
42 if (opendir($fh, $file)) {
43 foreach my $f (grep(!/^\.\.?$/, readdir($fh))) {
44 my($full) = "$file/$f";
46 push(@rfiles, recursive_find
($full));
50 if ($f =~ /\.(h|hxx|hpp|hh|inl|idl|cpp|cxx|cc|c|C)$/)
60 foreach $arg (@ARGV) {
61 my @results = glob $arg;
63 print STDERR
"File not Found: $arg\n"
66 foreach my $result (@results) {
68 push(@files, recursive_find
($result));
71 push(@files, $result);
77 ##############################################################################
78 # Subroutines used to change the file.
86 print "Verification\n" if (defined $opt_d);
89 my $found_filename = 0;
91 foreach $line (@contents) {
92 $found_id = 1 if ($line =~ /\$Id\:/);
93 $found_filename = 1 if ($line =~ /\= FILENAME/);
96 return 0 if ($found_id == 1 && $found_filename == 1);
102 sub format_description
(@
)
104 my (@description) = @_;
109 if ($#description < 1) {
110 foreach $line (@description) {
111 $line =~ s/\/\// \* \@brief /;
116 foreach $line (@description) {
117 $line =~ s/\/\// \*/;
126 sub fix_file_header
(@
)
130 my @description = ();
134 my $state = 'before';
135 ## state = before, filename, description, author, after, done
137 print "Fixing File Header\n" if (defined $opt_d);
139 LOOP
: foreach $line (@before) {
140 printf ("%10s %s", $state, $line) if (defined $opt_D);
142 if ($state eq 'done') {
147 if ($state eq 'before') {
148 if ($line =~ /\-\*\- C\+\+ \-\*\-/) {
151 elsif ($line =~ /\$Id\:(.*)\n/) {
154 elsif ($line =~ /===================/) {
155 push @after, "//========================================".
156 "=====================================\n";
157 push @after, "/**\n";
159 elsif ($line =~ /\= FILENAME/) {
163 elsif ($line !~ /^\s*\/\
//) {
168 if ($state eq 'filename') {
169 if ($line =~ /\/\
/ (.+)/) {
170 push @after, " * \@file $1\n";
172 push @after, " * $id\n";
175 elsif ($line =~ /\= DESCRIPTION/) {
176 $state = 'description';
179 elsif ($line =~ /\= AUTHOR/) {
183 elsif ($line =~ /===================/) {
185 ### Fall through so the after can put the ending in
189 if ($state eq 'description') {
190 if ($line =~ /\= AUTHOR/) {
191 push @after, format_description
(@description);
197 elsif ($line =~ /===================/) {
198 push @after, format_description
(@description);
204 push @description, $line;
206 if ($state eq 'author') {
207 if ($line =~ /\/\
/ (.+)\n/) {
210 elsif ($line =~ /===================/
211 || $line =~ /\= DESCRIPTION/) {
214 if ($authors ne "") {
215 @authors = split /\,/, $authors;
217 foreach $author (@authors) {
218 if ($author =~ /^ (.*)/) {
221 push @after, " * \@author $author\n";
225 if ($line =~ /\= DESCRIPTION/) {
227 $state = 'description';
237 if ($state eq 'after') {
238 if ($line =~ /===================/) {
240 push @after, " */\n";
241 push @after, "//========================================".
242 "=====================================\n";
255 sub fix_class_headers
(@
)
262 my $state = 'outside';
264 ## outside = not in class
265 ## template = stored template line
266 ## class = started collecting lines, in case of a class
267 ## header = after a class foo, but before any methods
269 print "Fixing class headers\n" if (defined $opt_d);
271 LOOP
: foreach $line (@before) {
272 printf ("%10s %s", $state, $line) if (defined $opt_D);
274 if ($state eq 'outside') {
275 if ($line =~ /^\s*template/) {
280 elsif ($line =~ /^\s*class/) {
290 if ($state eq 'template') {
291 if ($line =~ /^\s*class/) {
304 if ($state eq 'class') {
305 if ($line =~ /^\s*class(.*)\n/) {
307 my @s = split / /, $1;
308 if ($s[1] =~ /export$/i) {
315 elsif ($line =~ /^\s*\{/) {
318 elsif ($line =~ /^\s*\/\
//) {
331 if ($state eq 'header') {
332 if ($line =~ /^\s*\/\
//) {
333 push @headers, $line;
338 $line =~ /^(\s*)[\w\/]/; ### used to get indent
340 push @after, "$indent/**\n";
341 push @after, "$indent * \@class $classname\n";
343 foreach $header (@headers) {
344 if ($header =~ /\= TITLE/) {
345 push @after, "$indent *\n";
346 $prefix = "$indent * \@brief";
348 elsif ($header =~ /\= DESCRIPTION/) {
349 push @after, "$indent *\n";
350 $prefix = "$indent *";
352 elsif ($header !~ /\/\
/\s*\n/) {
353 my $myline = $header;
354 $myline =~ s/\s*\/\/\s
*/$prefix /;
355 push @after, $myline;
356 $prefix = "$indent *";
360 push @after, "$indent */\n";
376 sub format_comment
(@
)
383 if ($#comments < 2) {
384 foreach $line (@comments) {
385 $line =~ s/\/\//\/\
/\//;
390 my $line = $comments[0];
394 push @after, "$indent/**\n";
395 foreach $line (@comments) {
399 push @after, "$indent */\n";
405 sub fix_class_members
(@
)
416 print "Fixing class methods\n" if (defined $opt_d);
418 LOOP
: foreach $line (@before) {
419 if ($line =~ /\{/ && $line !~ /^\s*\/\
//) {
423 if ($line =~ /^\s*class/
425 && $level == $classlevel)
430 if ($line =~ /\}/ && $line !~ /^\s*\/\
//) {
431 if ($classlevel == $level) {
437 printf ("%2d%2d", $level, $classlevel) if (defined $opt_D);
439 if ($level == $classlevel && $level > 0) {
440 if ($line =~ /^\s*public/
441 || $line =~ /^\s*private/
442 || $line =~ /\s*protected/
443 || $line =~ /^\s*\n$/
446 || $line =~ /^\s*\#/)
448 push @after, format_comment
(@comment);
449 push @after, @method;
453 print " $line" if (defined $opt_D);
456 elsif ($line =~ /^\s*\/\
//) {
457 print "C $line" if (defined $opt_D);
460 push @comment, $line;
467 print "M $line" if (defined $opt_D);
473 push @after, format_comment
(@comment);
474 push @after, @method;
478 print " $line" if (defined $opt_D);
483 if ($level > 0 || $classlevel > 0) {
485 $failmessage = "Brace level recognition failed"
491 ##############################################################################
494 FILELOOP
: foreach $file (@files) {
495 print "\n" if (defined $opt_d);
497 print "\n" if (defined $opt_d);
503 ### Read file into @contents
504 print "Reading\n" if (defined $opt_d);
506 unless (open (FILE
, "<$file")) {
507 print STDERR
"$file: $!\n";
516 print "Verifying file\n" if (defined $opt_d);
518 if (!defined $opt_u) {
519 if (verify
(@contents) == 1) {
520 print "$file did not pass verification\n";
523 elsif (defined $opt_d) {
524 print "Passed verification\n";
528 ### Fix up parts of it
529 print "Fixing file\n" if (defined $opt_d);
531 @contents = fix_file_header
(@contents);
532 @contents = fix_class_headers
(@contents);
533 @contents = fix_class_members
(@contents);
536 print "$file: $failmessage\n";
539 if (defined $opt_s) {
542 elsif (!defined $opt_D) {
543 ### Save @contents back to the file
544 print "Saving\n" if (defined $opt_d);
546 unless (open (FILE
, ">$file")) {
547 print STDERR
"$file: $!\n";
551 foreach $line (@contents) {