From d18e4a5f91c5185158dafe6c97997da1ad9da566 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Fri, 12 Jul 2019 08:37:18 -0700 Subject: [PATCH] add comment-stripper and line-joiner for C --- sh/noccom | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sh/noccom diff --git a/sh/noccom b/sh/noccom new file mode 100644 index 0000000..39c28ac --- /dev/null +++ b/sh/noccom @@ -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 <; +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 "$@"