-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmx2fixdir
executable file
·64 lines (61 loc) · 1.54 KB
/
mx2fixdir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env perl
# clean up an MX2 file converted from MXP with CB2CB.
# This works best if all options were disabled in CB2CB; many
# of them break the DirT contents otherwise.
use strict;
if ($ARGV[0]) {
open(In,"<:bytes",$ARGV[0]) or die "$0: $ARGV[0]: $!\n";
}else{
open(In,"<-:bytes");
}
my $inDirT;
my $tmpDirT;
my @Note;
while (<In>) {
if (/^<DirT[^>]*>(.*)<\/DirT>/) {
$tmpDirT = $1;
my @tmp;
$tmpDirT =~ tr/\r\n//d;
foreach my $dir (split(/(?:
)+/,$tmpDirT)) {
if ($dir =~ /^(Content per Serving|This recipe yields|Comments:|Recipe Source:|ContentRecipe Source:)/ or @Note) {
push(@Note,$dir);
}else{
push(@tmp,$dir);
}
}
print "<DirT>\r\n",join("\r\n</DirT>\r\n<DirT>\r\n",@tmp),
"\r\n</DirT>\r\n";
$tmpDirT = undef;
$inDirT = 0;
}elsif (/^<DirT.*>/) {
$inDirT = 1;
}elsif (/^<\/DirT>/) {
#cleanup!
my @tmp;
$tmpDirT =~ tr/\r\n//d;
foreach my $dir (split(/(?:
)+/,$tmpDirT)) {
if ($dir =~ /^(Content per Serving|This recipe yields|Comments:|Recipe Source:|ContentRecipe Source:)/ or @Note) {
push(@Note,$dir);
}else{
push(@tmp,$dir);
}
}
print "<DirT>\r\n",join("\r\n</DirT>\r\n<DirT>\r\n",@tmp),
"\r\n</DirT>\r\n";
$tmpDirT = undef;
$inDirT = 0;
}elsif ($inDirT) {
$tmpDirT .= $_;
}elsif (/^<\/Note>/ and @Note) {
print "
",join("
",@Note);
print;
@Note = ();
}elsif ((/^<Nutr>/ or /^<\/RcpE>/) and @Note) {
print "<Note>\r\n",join("
",@Note),"\r\n</Note>\r\n";
print;
@Note = ();
}else{
print;
}
}
exit 0;