mirror of https://github.com/notwa/rc
fix bugs in noccom
This commit is contained in:
parent
7703d77332
commit
d100b43f69
40
sh/noccom
40
sh/noccom
|
@ -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 "$@"
|
||||
|
|
Loading…
Reference in New Issue