mirror of
https://github.com/notwa/rc
synced 2024-05-08 06:13:22 -07:00
add comment-stripper and line-joiner for C
This commit is contained in:
parent
7df579c722
commit
d18e4a5f91
16
sh/noccom
Normal file
16
sh/noccom
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# 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
|
||||||
|
noccom() {
|
||||||
|
[ -s ~/opt/local/bin/noccom ] || cat > ~/opt/local/bin/noccom <<EOF
|
||||||
|
#!/usr/bin/env perl
|
||||||
|
$/ = 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;
|
||||||
|
print;
|
||||||
|
EOF
|
||||||
|
perl ~/opt/local/bin/noccom "$@"
|
||||||
|
}
|
||||||
|
noccom "$@"
|
Loading…
Reference in New Issue
Block a user