2020-12-29 08:38:07 -08:00
|
|
|
#!/usr/bin/env sh
|
2024-03-26 15:08:14 -07:00
|
|
|
# YES_ZSH YES_BASH YES_DASH YES_ASH
|
2021-07-29 05:44:12 -07:00
|
|
|
|
|
|
|
# TODO: what's the minimum version of perl required for this?
|
2021-07-29 00:37:35 -07:00
|
|
|
|
2021-07-30 17:57:08 -07:00
|
|
|
noccom() { ### @-
|
|
|
|
### strip C-like comments; both multi-line and single-line.
|
2021-09-23 06:48:05 -07:00
|
|
|
# the first expression is taken from this FAQ:
|
|
|
|
# https://perldoc.perl.org/perlfaq6.html#How-do-I-use-a-regular-expression-to-strip-C-style-comments-from-a-file%3f
|
2024-03-25 15:32:23 -07:00
|
|
|
[ -s ~/.local/bin/noccom ] || cat > ~/.local/bin/noccom <<EOF
|
2019-07-12 08:37:18 -07:00
|
|
|
#!/usr/bin/env perl
|
2019-07-27 08:01:48 -07:00
|
|
|
|
|
|
|
\$/ = undef;
|
2019-07-12 08:37:18 -07:00
|
|
|
\$_ = <>;
|
2019-07-27 08:01:48 -07:00
|
|
|
|
|
|
|
s{
|
|
|
|
/\\*[^*]*\\*+([^/*][^*]*\\*+)*/
|
|
|
|
|
|
|
|
|
//([^\\\\]
|
|
|
|
|
|
|
|
|
[^\\n][\\n]?)*?\\n
|
|
|
|
|
|
|
|
|
(
|
|
|
|
"(?:\\\\.|[^"\\\\])*"
|
|
|
|
|
|
|
|
|
'(?:\\\\.|[^'\\\\])*'
|
|
|
|
|
|
|
|
|
.[^/"'\\\\]*
|
|
|
|
)
|
|
|
|
}{defined \$3 ? \$3 : ""}gxse;
|
|
|
|
|
|
|
|
s{
|
|
|
|
\\\\?\\n\\s*([{}])?\\s*(;*)\\s*(?=\\\\?\\n)
|
|
|
|
|
|
|
|
|
(
|
|
|
|
\\#[^\\n]*\\n
|
|
|
|
|
|
|
|
|
"(?:\\\\.|[^"\\\\])*"
|
|
|
|
|
|
|
|
|
'(?:\\\\.|[^'\\\\])*'
|
|
|
|
|
|
|
|
|
.[^#/"'\\\\\\n]*
|
|
|
|
)
|
|
|
|
}{defined \$3 ? \$3 : (defined \$1 ? " ".\$1.\$2 : \$2)}gxse;
|
|
|
|
|
|
|
|
s#(^|\\n)\\s+#\$1#gs;
|
|
|
|
|
2019-07-12 08:37:18 -07:00
|
|
|
print;
|
|
|
|
EOF
|
2019-07-27 08:01:48 -07:00
|
|
|
|
2024-03-25 15:32:23 -07:00
|
|
|
perl ~/.local/bin/noccom "$@"
|
2019-07-12 08:37:18 -07:00
|
|
|
}
|
2021-07-29 00:37:35 -07:00
|
|
|
|
2021-08-02 13:48:46 -07:00
|
|
|
[ -n "${preload+-}" ] || noccom "$@"
|