Plan 9 from Bell Labs’s /usr/web/sources/contrib/axel/music/permutemap

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/perl

sub permute {
	my($idx, $pat) = @_;
	# print STDERR "permute ($idx)\n";
	my(@words, @res, $res, $word, $nwords, $i);
	@words = split("~", $idx);
	$nwords = @words;
	# print STDERR "permute words=(".@words.")\n";
	$word = "\01";
	$i = 0;
	while ($i < $nwords) {
		# print STDERR "permute while ($word)\n";
		@words = (@words, $word);
		if ($words[0] =~ /^($pat)$/i) {
			print STDERR "skipping ($words[0])\n";
		} else {
			$res = join('~', @words);
			$res =~ s/\01$//g;
			$res =~ s/\01/~--~/g;
			$res =~ s/[()]//g;
			$res =~ s/~+$//g;
			push(@res, $res);
		}
		$word = shift(@words);
		$i++;
	}
	return @res;
}

while (<>) {
	chomp();
	print $_."\n";
	if (/^([ 	]*)title[ 	]*=[ 	]*([^ 	\n]+)/) {
		$pfx = $1;
		$idx = $2;
		foreach $f (permute($idx, 'a|and|the|en|een|het')) {
			$k = '';
			if ($f =~ /^([a-z])/i) {
				# print STDERR "in if: $k ($f)\n";
				$h = $1;
				$h =~ tr /[a-z]/[A-Z]/;
				$k = $h;
			}
			# print STDERR "$k ($f)\n";
			print $pfx."titlep".$k." = ".$f."\n";
		}
	}
	if (/^([ 	]*)artist[ 	]*=[ 	]*([^ 	\n]+)/) {
		$pfx = $1;
		$idx = $2;
		foreach $f (permute($idx, '')) {
			$k = '';
			if ($f =~ /^([a-z])/i) {
				$h = $1;
				$h =~ tr /[a-z]/[A-Z]/;
				$k = $h;
			}
			# print STDERR "$k ($f)\n";
			print $pfx."artistp".$k." = ".$f."\n";
		}
	}
}


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.