-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathxtract.awk
More file actions
45 lines (41 loc) · 921 Bytes
/
xtract.awk
File metadata and controls
45 lines (41 loc) · 921 Bytes
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
#! /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(/^.*\/\*/,"");
Multi = 1;
}
Multi {
if(match($0, /\*\//)) {
gsub(/\*\/.*$/,"");
Multi = 0;
}
gsub(/\r/, "", $0);
gsub(/^[[:space:]]+/,"",$0);
if(substr($0,1,1)=="*") {
print substr($0,2);
} else if(!Multi) {
print;
}
}
# For `///` single-line comments:
Single && $0 !~ /\/\/\// {
Single=0;
print "\n";
}
Single && /\/\/\// {
sub(/^.*\/\/\//,"");
print $0;
}
!Single && /\/\/\// {
sub(/^.*\/\/\//,"");
print $0;
Single=1;
}