Ticket #1: ddoc_format.sh

File ddoc_format.sh, 1.6 kB (added by Pse, 1 year ago)

DDoc formatter. Parses all comments and converts them to DDoc style formatting.

Line 
1 #!/bin/bash
2
3 SRCDIR="`pwd`/src"
4
5 function ParseFile()
6 {
7     echo "Parsing: $1"
8
9     #Convert non-Doxygen comments to DDoc format.
10     sed -ri -e '/\/\*\*/,/\*\// { /Returns:/ !{ /\* [[:alnum:]_]*:$/ { N; s/\*\//&/; t; s/:/ = /; s/\n[[:blank:]]*\*[[:blank:]]*//; }
11                                                 /\* [[:alnum:]_]*:.*$/ { s/:/ =/ } } }' \
12             -e '/\/\*\*/,/\*\// { /Returns:$/ { N; s/\n[[:blank:]]*\*[[:blank:]]*/ / } }' "$1"
13     #TODO: remove "self" arguments.
14    
15     #Convert Doxygen comments to DDoc format.
16     sed -ri -e '/\/\*\*/,/\*\// { s/@return/Returns:/ }' \
17             -e '/\/\*\*/,/\*\// { /^.*@param.*$/ { s/@param //; s/ [[:alnum:]_]* /&= / } }' "$1"
18
19     #Add "Params:" before DDoc function parameter lists.
20     #sed -ri -e '/\/\*\*/,/\*\// { x; s/\n/&/; t e; x; s/ = /&/; T; h; H; g; s/[[:alnum:]_]* =.*\n/Params:\n/; b; :e; x; }' "$1"
21     sed -ri -e '/\/\*\*/ { s/\*\//&/; t; :skip; n; s/\*\//&/; t; s/ = /&/; T skip; h; H; g; s/[[:alnum:]_]* =.*\n/Params:\n/; }' "$1"
22 }
23
24 function ScanDir()
25 {
26     local previousdir="`pwd`"
27
28     cd "$1"
29     for entry in $( ls -b ); do
30         if [ -f "${entry}" ]; then
31             ParseFile "$1"/"${entry}"
32         elif [ -d "${entry}" ]; then
33             ScanDir "$1"/"${entry}"
34         fi
35     done
36
37     cd "${previousdir}"
38 }
39
40 echo
41 echo "The following script will parse all your D source files and"
42 echo "hopefully format them according to the DDoc specification."
43 echo "NO backups will be made. You now have 5 seconds to abort."
44 sleep 5
45 echo
46 echo "Source directory: ${SRCDIR}"
47 echo
48
49 ScanDir "${SRCDIR}"
50
51 echo "Done!"