From a6a3129171c1056db193d28aa310da01fc64133d Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Tue, 27 Aug 2013 12:49:14 +0000 Subject: [PATCH] Preserve comments in code/paste --- PBot/VERSION.pm | 4 ++-- modules/compiler_vm/compiler_vm_client.pl | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/PBot/VERSION.pm b/PBot/VERSION.pm index 21dd9de8..29bacbd7 100644 --- a/PBot/VERSION.pm +++ b/PBot/VERSION.pm @@ -13,8 +13,8 @@ use warnings; # These are set automatically by the build/commit script use constant { BUILD_NAME => "PBot", - BUILD_REVISION => 426, - BUILD_DATE => "2013-08-26", + BUILD_REVISION => 427, + BUILD_DATE => "2013-08-27", }; 1; diff --git a/modules/compiler_vm/compiler_vm_client.pl b/modules/compiler_vm/compiler_vm_client.pl index fec38db5..6b244e3f 100755 --- a/modules/compiler_vm/compiler_vm_client.pl +++ b/modules/compiler_vm/compiler_vm_client.pl @@ -774,23 +774,21 @@ if($lang eq 'C89' or $lang eq 'C99' or $lang eq 'C11' or $lang eq 'C++') { print "*** prelude: [$prelude]\n precode: [$precode]\n" if $debug; - # strip C and C++ style comments - if($lang eq 'C89' or $args =~ m/-std=(gnu89|c89)/i) { - $precode =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/# #gs; - $precode =~ s#|//([^\\]|[^\n][\n]?)*?\n|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : " "#gse; - } else { - $precode =~ s#|//([^\\]|[^\n][\n]?)*?\n|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : " "#gse; - $precode =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/# #gs; - } - - print " precode: [$precode]\n" if $debug; - my $preprecode = $precode; # white-out contents of quoted literals $preprecode =~ s/(?:\"((?:\\\"|(?!\").)*)\")/'"' . ('-' x length $1) . '"'/ge; $preprecode =~ s/(?:\'((?:\\\'|(?!\').)*)\')/"'" . ('-' x length $1) . "'"/ge; + # strip C and C++ style comments + if($lang eq 'C89' or $args =~ m/-std=(gnu89|c89)/i) { + $preprecode =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/# #gs; + $preprecode =~ s#|//([^\\]|[^\n][\n]?)*?\n|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse; + } else { + $preprecode =~ s#|//([^\\]|[^\n][\n]?)*?\n|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse; + $preprecode =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/# #gs; + } + print "preprecode: [$preprecode]\n" if $debug; print "looking for functions, has main: $has_main\n" if $debug >= 2; @@ -881,6 +879,8 @@ $code =~ s/\|n/\n/g; $code =~ s/^\s+//; $code =~ s/\s+$//; $code =~ s/;\s*;\n/;\n/gs; +$code =~ s/;(\s*\/\*.*?\*\/\s*);\n/;$1/gs; +$code =~ s/;(\s*\/\/.*?\s*);\n/;$1/gs; $code =~ s/({|})\n\s*;\n/$1\n/gs; $code =~ s/(?:\n\n)+/\n\n/g;