| 1 |
#!/usr/local/bin/perl |
| 2 |
# $Id: acesplit,v 1.2 1995/02/03 11:46:22 rd Exp $ |
| 3 |
# read a .ace file and split it every n objects |
| 4 |
# contributed by Detlef Wolf, DKFZ |
| 5 |
|
| 6 |
# Fri Feb 3 10:54:04 MET 1995 dok256 |
| 7 |
# - comments may start anywhere on a line |
| 8 |
# Thu Feb 2 10:28:53 MET 1995 dok256; bugs fixed: |
| 9 |
# - DNA tags are no longer treated as objects |
| 10 |
# - .ace commands -D -R -A are recognized |
| 11 |
# - terminates even if last line of last file does not end with a newline |
| 12 |
# created: Fri Dec 2 17:36:57 MET 1994 dok256 |
| 13 |
|
| 14 |
($#ARGV>=0) || die |
| 15 |
"usage: acesplit [-<objectcount>] [-p <name>] [<filename>...] |
| 16 |
if -<objectcount> is omitted then only statistics are produced. |
| 17 |
default value for the prefix option -p is 'split.' |
| 18 |
use - as <filename> to read from stdin |
| 19 |
options must be given in the order shown above\n"; |
| 20 |
|
| 21 |
$f=1; |
| 22 |
$prefix="split."; |
| 23 |
$outfileno=1; |
| 24 |
|
| 25 |
if ($ARGV[0] =~ /^-[0-9]+$/) { |
| 26 |
$splitsize= -($ARGV[0]); shift; |
| 27 |
$nosplit=0; |
| 28 |
} |
| 29 |
else { |
| 30 |
$splitsize=999999; |
| 31 |
print "Only producing statistics, splitting turned off\n"; |
| 32 |
$nosplit=1; |
| 33 |
}; |
| 34 |
|
| 35 |
if ($ARGV[0] eq "-p") { |
| 36 |
shift; |
| 37 |
$prefix = $ARGV[0]; |
| 38 |
shift; |
| 39 |
}; |
| 40 |
$objcount=0; |
| 41 |
|
| 42 |
if ($nosplit) { |
| 43 |
$outfile="/dev/null"; |
| 44 |
} |
| 45 |
else { |
| 46 |
print "Splitting with prefix $prefix every $splitsize objects.\n"; |
| 47 |
$outfile="$prefix$outfileno"; |
| 48 |
} |
| 49 |
|
| 50 |
open(F,">$outfile") || die; |
| 51 |
|
| 52 |
|
| 53 |
while (<>) { |
| 54 |
|
| 55 |
if (/^LongText\b/) { |
| 56 |
&route; |
| 57 |
print F $_; |
| 58 |
$cl{"LongText"}++ ; |
| 59 |
while (<>) { |
| 60 |
print F $_; |
| 61 |
/^\*\*\*LongTextEnd\*\*\*$/ && last; |
| 62 |
}; |
| 63 |
print F "\n"; |
| 64 |
eof() && last; |
| 65 |
next; |
| 66 |
}; |
| 67 |
|
| 68 |
# blank line or comment between objects -- ignore |
| 69 |
(/^\s*$/ || m|^\s*//| ) && next; |
| 70 |
|
| 71 |
# no LongText --> a new-line terminated thing (DNA or B-class obj.) |
| 72 |
if (/^(-[DAR]\s+)?(\w+).*/) { |
| 73 |
$class=$2; |
| 74 |
&route; |
| 75 |
print F $_; |
| 76 |
$cl{$class}++ ; |
| 77 |
while (<>) { |
| 78 |
print F $_; |
| 79 |
/^$/ && last; |
| 80 |
}; |
| 81 |
eof() && last; |
| 82 |
next; |
| 83 |
}; |
| 84 |
|
| 85 |
warn "unrecognized line no $. : $_"; |
| 86 |
}; |
| 87 |
|
| 88 |
$sum=0; |
| 89 |
foreach (sort keys %cl) { |
| 90 |
printf("%-30s%8d\n",$_, $cl{$_}) ; |
| 91 |
$sum+=$cl{$_}; |
| 92 |
}; |
| 93 |
printf("%-30s%8d\n","--- total ---", $sum) ; |
| 94 |
|
| 95 |
sub route { |
| 96 |
if ($objcount++ >= $splitsize) { |
| 97 |
$objcount=1; |
| 98 |
if ($nosplit==0) { |
| 99 |
close(F); |
| 100 |
$outfileno++; |
| 101 |
$outfile="$prefix$outfileno"; |
| 102 |
open(F,">$outfile") || die; |
| 103 |
}; |
| 104 |
}; |
| 105 |
}; |
| 106 |
|