-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoxygen_space.pl
executable file
·95 lines (84 loc) · 3.1 KB
/
doxygen_space.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env perl
###########################################################################
# doxygen_space.pl
# ---------------------
# begin : October 2016
# copyright : (C) 2016 by Nyall Dawson
# email : nyall dot dawson at gmail dot com
#
###########################################################################
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
# adapted from scripts/sort_includes.sh
# this is slurped in whole-file mode, as opposed to unify_includes.pl
# which slurps in per-line mode
use strict;
use warnings;
my $file = $ARGV[0];
# read file
open(my $handle, "<", $file) || die "Couldn't open '".$file."' for reading because: ".$!;
chomp(my @INPUT_LINES = <$handle>);
close $handle;
my $LINE_IDX = 0;
my $LINE;
my @OUTPUT = ();
my $LINE_COUNT = @INPUT_LINES;
open(my $out_handle, ">", $file) || die "Couldn't open '".$file."' for writing because: ".$!;
my $PREVIOUS_WAS_BLANKLINE = 0;
while ($LINE_IDX < $LINE_COUNT){
my $new_line = $INPUT_LINES[$LINE_IDX];
my $is_blank_line = ( $new_line =~ m/^\s*$/ ) ? 1 : 0;
if ( $new_line =~ m/^(\s*)\/\/!\s*(.*?)$/ ){
#found a //! comment
my $indentation = $1;
my $comment = $2;
#check next line to see if it begins with //!
if ( $INPUT_LINES[$LINE_IDX+1] =~ m/\s*\/\/!\s*(.*?)$/){
#we are in a multiline //! comment block, convert to /** block
if ( !$PREVIOUS_WAS_BLANKLINE ){
print $out_handle "\n";
}
print $out_handle $indentation."/**\n";
print $out_handle $indentation." * ".$comment."\n";
while ( $INPUT_LINES[$LINE_IDX+1] =~ m/\s*\/\/!\s*(.*?)$/ ){
if ($1 ne ''){
print $out_handle $indentation." * ".$1."\n";
}
else {
print $out_handle $indentation." *\n";
}
$LINE_IDX++;
}
print $out_handle $indentation." */\n";
}
else {
print $out_handle $new_line."\n";
}
}
else {
if ( $new_line =~ m/^(\s*)\/\*\*(?!\*)\s*(.*)$/ ){
# Space around doxygen start blocks (force blank line before /**)
if ( !$PREVIOUS_WAS_BLANKLINE ){
print $out_handle "\n";
}
if ( $2 ne '' ){
# new line after /** begin block
print $out_handle "$1\/**\n$1 * $2\n";
}
else {
print $out_handle $new_line."\n";
}
}
else {
print $out_handle $new_line."\n";
}
}
$LINE_IDX++;
$PREVIOUS_WAS_BLANKLINE = $is_blank_line;
}
close $out_handle;