Skip to content

Instantly share code, notes, and snippets.

@evdenis
Created September 4, 2018 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evdenis/8a44981b81202a387eb6d401de7059a8 to your computer and use it in GitHub Desktop.
Save evdenis/8a44981b81202a387eb6d401de7059a8 to your computer and use it in GitHub Desktop.
Script for removing ACSL specifications from C files
#!/usr/bin/env perl
use warnings;
use strict;
use Fcntl qw(:flock SEEK_END);
unless (@ARGV) {
die("usage: $0 <files>\n");
}
foreach my $file (@ARGV) {
if (-f $file && -r _) {
if (open(my $fh, '+<', $file)) {
flock($fh, LOCK_EX)
or warn "Can't lock file $file: $!\n";
my $text = join('', <$fh>);
if ($text =~ s!
(?<line_begin>^)? # line start
\h* # whitespaces
(?:
# multiline spec
# match /*@
/\*\h*\@
[^*]*\*+
(?:[^/*][^*]*\*+)*/
# remove trailing newline if possible and
# line started from comment
\h*(?(<line_begin>)\n)?
|
# singleline spec
//\h*\@(?:[^\\]|[^\n][\n]?)*?
# remove trailing newline if
# line started from comment
(?(<line_begin>)\n)
)
!!xmg) {
seek $fh, 0, 0;
truncate $fh, 0;
print $fh $text;
}
close($fh)
or warn "Close failed: $!";
} else {
warn "Can't open file $file: $!";
}
} else {
warn("Unknown file: $file\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment