fix bugs in noccom

This commit is contained in:
Connor Olding 2019-07-27 08:01:48 -07:00
parent 7703d77332
commit d100b43f69
1 changed files with 36 additions and 4 deletions

View File

@ -4,13 +4,45 @@
noccom() {
[ -s ~/opt/local/bin/noccom ] || cat > ~/opt/local/bin/noccom <<EOF
#!/usr/bin/env perl
$/ = undef;
\$/ = undef;
\$_ = <>;
s#/\\*[^*]*\\*+([^/*][^*]*\\*+)*/|//([^\\\\]|[^\\n][\\n]?)*?\\n|("(\\\\.|[^"\\\\])*"|'(\\\\.|[^'\\\\])*'|.[^/"'\\\\]*)#defined \$3 ? \$3 : ""#gse;
s#|\\\\?\\n\\s*([{}])?\\s*(;*)\\s*(?=\\\\?\\n)|("(?:\\\\.|[^"\\\\])*"|'(?:\\\\.|[^'\\\\])*'|.[^/"'\\\\\\n]*)#defined \$3?\$3:defined \$1?" ".\$1.\$2:\$2#gse;
s#^(\\s*\\n)+##s;
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;
print;
EOF
perl ~/opt/local/bin/noccom "$@"
}
noccom "$@"