#!/usr/bin/env sh # compat: +ash +bash +dash +zsh # TODO: what's the minimum version of perl required for this? noccom() { ### @- ### strip C-like comments; both multi-line and single-line. # 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 [ -s ~/.local/bin/noccom ] || cat > ~/.local/bin/noccom <; 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 ~/.local/bin/noccom "$@" } [ -n "${preload+-}" ] || noccom "$@"