File: hunspell-optimize-roothelper.pl

package info (click to toggle)
igerman98 20091006-4.2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,372 kB
  • ctags: 74
  • sloc: perl: 938; sh: 574; makefile: 558; sed: 32
file content (43 lines) | stat: -rwxr-xr-x 1,387 bytes parent folder | download | duplicates (9)
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
#!/usr/bin/perl -w
#
# 2007 by Bjoern Jacke <bjoern@j3e.de>

# for the very special case where two homonyms exist in a sorted list and one
# of them has flags beginning with "h". Then we join the two homonyms and
# remove the h flag.

# This works with STDIN/STDOUT only.

my ($root,$prevroot,$flags,$prevflags,$flags_match_h,$prevflags_match_h,$flags_match_o,$prevflags_match_o) = "";
while (<STDIN>) {
	chomp;
	($prevroot,$prevflags,$prevflags_match_h,$prevflags_match_o) = ($root,$flags,$flags_match_h,$flags_match_o);
	#$root = $flags = $_;
	#$root =~ s/\/.*//;
	($root,$flags) = split("/");
	$flags="" unless ($flags);
	$root="" unless ($root);
	$flags_match_h = $flags_match_o = 0;
	if ($flags) {
		$flags_match_h = $flags =~ m/h/;
		$flags_match_o = ($flags =~ m/o/) or ($flags =~ m/^[A-Z]/);
	}
	if (($root eq $prevroot) and (($flags_match_h) or ($prevflags_match_h)) and not ($flags_match_o or $prevflags_match_o)){
		if ($flags_match_h) {
			$flags =~ s/h//;
#			print STDERR "root $root: removed h\n"
		} elsif ($prevflags_match_h) {
			$prevflags =~ s/h//;
		} else {
			die "should not match neither flags_match_h nor prevflags_match_h!";
		}
#		print STDERR "OLD: $flags\n";
		$flags = $prevflags.$flags;
#		print STDERR "NEW: $flags\n";
	} else {
		if($prevroot) {
			print "$prevroot",$prevflags?"/$prevflags":"","\n";
		}
	}
}
print "$root",$flags?"/$flags":"","\n";