| 1 |
#!/usr/bin/perl |
| 2 |
# -*- mode: cperl; indent-tabs-mode: nil; tab-width: 3; cperl-indent-level: 3; -*- |
| 3 |
use warnings; |
| 4 |
use strict; |
| 5 |
use utf8; |
| 6 |
BEGIN { |
| 7 |
$| = 1; |
| 8 |
binmode(STDIN, ':encoding(UTF-8)'); |
| 9 |
binmode(STDOUT, ':encoding(UTF-8)'); |
| 10 |
} |
| 11 |
use open qw( :encoding(UTF-8) :std ); |
| 12 |
|
| 13 |
use Getopt::Long; |
| 14 |
Getopt::Long::Configure('no_ignore_case'); |
| 15 |
my %opts = (); |
| 16 |
GetOptions(\%opts, ('help|?')); |
| 17 |
|
| 18 |
sub print_help { |
| 19 |
print <<'XOUT'; |
| 20 |
Usage: cg-untrace |
| 21 |
|
| 22 |
Pipe a CG stream through this to remove all deleted readings and tracing tags. |
| 23 |
|
| 24 |
XOUT |
| 25 |
} |
| 26 |
|
| 27 |
if (defined $opts{'help'}) { |
| 28 |
print_help(); |
| 29 |
exit(0); |
| 30 |
} |
| 31 |
|
| 32 |
while (<STDIN>) { |
| 33 |
# Discard deleted readings |
| 34 |
if (/^;/) { |
| 35 |
next; |
| 36 |
} |
| 37 |
# On readings only... |
| 38 |
if (/^\s+"/) { |
| 39 |
s/ (ID|R):/ x$1:/g; |
| 40 |
# ...strip trace tags |
| 41 |
while (s/ [-A-Z]+:[^"\s\n]+//g) {} |
| 42 |
while (s/ (ADD|REM|SET)RELATIONS?\(\S+\):[^"\s\n]+//g) {} |
| 43 |
s/ x(ID|R):/ $1:/g; |
| 44 |
} |
| 45 |
print; |
| 46 |
} |