# > KEYWORDS="x86 ppc sparc ~alpha"
-die "syntax: ekeyword { arch | ~arch | -arch } ebuild...\n" unless @ARGV > 1;
+my ($kw_re) = '^[-~]?\w+$';
-my $kw = shift @ARGV;
-(my $arch = $kw) =~ s|^[-~]||;
-
-die "$kw doesn't look like a keyword to me\n" unless $arch =~ /^\w+$/;
+# make sure the cmdline consists of keywords and ebuilds
+unless (@ARGV > 1 && $ARGV[0] =~ /$kw_re/o) {
+ die "syntax: ekeyword { arch | ~arch | -arch } ebuild...\n"
+}
+for my $a (@ARGV) {
+ next if $a =~ /$kw_re/o; # keyword
+ next if $a =~ /^\S+\.ebuild$/; # ebuild
+ die "I don't understand $a\n";
+}
for my $f (@ARGV) {
+ if ($f =~ /$kw_re/o) {
+ push @kw, $f;
+ next;
+ }
+
open I, "<$f" or die "Can't read $f: $!\n";
open O, ">$f.new" or die "Can't create $f.new: $!\n";
select O;
while (<I>) {
- /^KEYWORDS/ or print, next;
- s/[-~]?$arch/$kw/ || s/(.*?['"].*?)\s*(?=['"])/$1 $kw/;
- print $_, <I> or die "Can't write $f.new: $!\n";
+ /^KEYWORDS/ or print, next;
+ for my $k (@kw) {
+ (my $arch = $k) =~ s/^[-~]//;
+ s/[-~]?$arch/$k/ || s/(.*?['"].*?)\s*(?=['"])/$1 $k/;
+ }
+ print $_, <I> or die "Can't write $f.new: $!\n";
}
close I;