--- rxvt-unicode/src/urxvt.pm 2012/06/05 22:38:17 1.209 +++ rxvt-unicode/src/urxvt.pm 2012/06/06 15:06:41 1.212 @@ -764,8 +764,8 @@ our $VERSION = 1; our $TERM; -our @TERM_INIT; -our @TERM_EXT; +our @TERM_INIT; # should go, prevents async I/O etc. +our @TERM_EXT; # should go, prevents async I/O etc. our @HOOKNAME; our %HOOKTYPE = map +($HOOKNAME[$_] => $_), 0..$#HOOKNAME; our %OPTION; @@ -945,12 +945,33 @@ no warnings 'utf8'; -sub resource { - my ($term, $name, $isarg, $flag, $value) = @_; +sub parse_resource { + my ($term, $name, $isarg, $longopt, $flag, $value) = @_; $term->scan_meta; - warn "resourece<@_>\n";#d# + my $r = $term->{meta}{resource}; + while (my ($pattern, $v) = each %$r) { + $name =~ y/-/./ if $isarg; + + if ( + $pattern =~ /\.$/ + ? $pattern eq substr $name, 0, length $pattern + : $pattern eq $name + ) { + $name = "$urxvt::RESCLASS.$name"; + + push @TERM_EXT, $v->[0]; + + if ($v->[1] eq "boolean") { + $term->put_option_db ($name, $flag ? "true" : "false"); + return 1; + } else { + $term->put_option_db ($name, $value); + return 1 + 2; + } + } + } 0 } @@ -962,19 +983,22 @@ my $r = $term->{meta}{resource}; - for my $regex (sort keys %$r) { - my ($ext, $type, $desc) = @{ $r->{$regex} }; + for my $pattern (sort keys %$r) { + my ($ext, $type, $desc) = @{ $r->{$pattern} }; $desc .= " (-pe $ext)"; if ($usage_type == 1) { + $pattern =~ y/./-/; + $pattern =~ s/-$/-.../g; + if ($type eq "boolean") { - urxvt::log sprintf " -%-20.20s %s\n", "/+$regex", $desc; + urxvt::log sprintf " -%-30s %s\n", "/+$pattern", $desc; } else { - urxvt::log sprintf " -%-20.20s %s\n", "$regex $type", $desc; + urxvt::log sprintf " -%-30s %s\n", "$pattern $type", $desc; } } else { - urxvt::log sprintf " %-19.19s %s\n", "$regex:", $type; + urxvt::log sprintf " %-31s %s\n", "$pattern:", $type; } } } @@ -1335,10 +1359,14 @@ or next; while (<$fh>) { - if (/^#:META:RESOURCE:(.*)/) { - my ($regex, $type, $desc) = split /:/, $1; - $regex =~ s/\$\$/$ext/g; # $$ in regex == extension name - $meta{resource}{$regex} = [$ext, $type, $desc]; + if (/^#:META:X_RESOURCE:(.*)/) { + my ($pattern, $type, $desc) = split /:/, $1; + $pattern =~ s/^%(?:\.|$)/$ext./g; # % in pattern == extension name + if ($pattern =~ /[^a-zA-Z\.]/) { + warn "$dir/$ext: meta resource '$pattern' contains illegal characters (not alphanumeric nor . nor *)\n"; + } else { + $meta{resource}{$pattern} = [$ext, $type, $desc]; + } } elsif (/^\s*(?:#|$)/) { # skip other comments and empty lines } else { @@ -1475,6 +1503,22 @@ only one resource database per display, and later invocations might return the wrong resources. +=item $value = $term->x_resource_boolean ($pattern) + +Like C, above, but interprets the string value as a boolean +and returns C<1> for true values, C<0> for false values and C if +the resource or option isn't specified. + +You should always use this method to parse boolean resources. + +=cut + +sub x_resource_boolean { + my $res = &x_resource; + + $res =~ /^\s*(?:true|yes|on|1)\s*$/i ? 1 : defined $res && 0 +} + =item $success = $term->parse_keysym ($key, $octets) Adds a key binding exactly as specified via a resource. See the