-
Notifications
You must be signed in to change notification settings - Fork 5
/
xtract.awk
49 lines (47 loc) · 1.05 KB
/
xtract.awk
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
#! /usr/bin/awk -f
#
# Extracts the /**-denoted comments from a source file.
# https://github.com/wernsey/d.awk
#
# (c) 2016 Werner Stoop
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
!Multi && /\/\*\*/ {
sub(/^.*\/\*\*/,"");
if(match($0,/\*\//)) {
sub(/\*\/.*/,"");
print "\n" $0 "\n";
} else {
Multi = 1;
print;
}
}
Multi && /\*\// {
sub(/[[:space:]]*\*[[:space:]]?\/.*/,"");
if($0) {
sub(/^[[:space:]]*\*[[:space:]]?/,"");
print $0 "\n";
} else print "";
Multi = 0;
}
Multi && /^[[:space:]]*\*/ {
sub(/^[[:space:]]*\*[[:space:]]?/,"");
print;
}
#Multi { print; }
# For `///` single-line comments:
Single && $0 !~ /\/\/\// {
Single=0;
print "\n";
}
Single && /\/\/\// {
sub(/^.*\/\/\//,"");
print $0;
}
!Single && /\/\/\// {
sub(/^.*\/\/\//,"");
print $0;
Single=1;
}