/
Doxygen-method.pl
executable file
·75 lines (61 loc) · 2.06 KB
/
Doxygen-method.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#! /usr/bin/perl -w
#
# Inserts Doxygen documentation block for an Objective-C method
# declared in Xcode header file
#
#
# This script is largely based on a script with this functionality
# and distributed with Xcode 3.x
use strict;
# Obtain selection from the script arguments
my $selection = $ARGV[0];
chomp $selection;
my $unmodifiedSelection = $selection; # used to retain linebreaks in output
$selection =~ s/\n/ /sg; # put on one line, if necessary
$selection =~ s/\s+$//; # remove any trailing spaces
$selection =~ s/\s{2,}/ /g; # regularize remaining spaces
my $displayMethodName= '';
my $returnsAValue= 0;
my @params = ();
# is it a method declaration that we understand?
if (length($selection) && ($selection =~ /^[+-]/) && ($selection =~ /;$/)) {
# determine if it returns a value
$selection =~ m/[+-]\s+(\((.*?)\))?(.*);/;
my $return = $2;
my $fullMethodName = $3;
if ((defined($return)) && ($return ne 'void')) {$returnsAValue=1;};
if (defined($fullMethodName)) {
# get rid of type info for args
$fullMethodName =~ s/\(.*?\)//g;
if ($fullMethodName =~ /:/) {
# get keyword:arg pairs
my @keyArgPairs = split(/\s+/, $fullMethodName);
foreach my $pair (@keyArgPairs) {
if ($pair =~ /:/) { # don't treat parameters with spaces as method names
my @parts = split(/:/, $pair);
while (@parts) {
$displayMethodName .= shift(@parts).":";
push (@params, shift @parts);
}
} else {
if (length($pair)) { # but do add them to the parameter list
push (@params, $pair);
}
}
}
} else {
$displayMethodName = $fullMethodName;
}
}
}
print "/**\n";
print " * \@method $displayMethodName\n";
print " * \@brief <#(brief description of method)#>\n";
print " * \@details <#(comprehensive description)#>\n";
foreach my $param (@params) {
print "* \@param $param <#(description of parameter)#>\n" if (defined($param));
}
print " * \@result <#(description)#>\n" if ($returnsAValue);
print " */\n";
print $unmodifiedSelection;
exit 0;