X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/5f162cfd344f6b75fa39a57be4b3d488cadd1535..62661f64fe39c5eb5420d53aec4b6d5182419a96:/IkiWiki.pm diff --git a/IkiWiki.pm b/IkiWiki.pm index 2d692a978..32ca0449f 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -231,9 +231,10 @@ sub srcfile ($) { #{{{ error("internal error: $file cannot be found"); } #}}} -sub readfile ($;$) { #{{{ +sub readfile ($;$$) { #{{{ my $file=shift; my $binary=shift; + my $wantfd=shift; if (-l $file) { error("cannot read a symlink ($file)"); @@ -242,16 +243,18 @@ sub readfile ($;$) { #{{{ local $/=undef; open (IN, $file) || error("failed to read $file: $!"); binmode(IN) if ($binary); + return \*IN if $wantfd; my $ret=; close IN; return $ret; } #}}} -sub writefile ($$$;$) { #{{{ +sub writefile ($$$;$$) { #{{{ my $file=shift; # can include subdirs my $destdir=shift; # directory to put file in my $content=shift; my $binary=shift; + my $wantfd=shift; my $test=$file; while (length $test) { @@ -274,6 +277,7 @@ sub writefile ($$$;$) { #{{{ open (OUT, ">$destdir/$file") || error("failed to write $destdir/$file: $!"); binmode(OUT) if ($binary); + return \*OUT if $wantfd; print OUT $content; close OUT; } #}}} @@ -850,23 +854,35 @@ sub pagespec_translate ($) { #{{{ $code.=" match_$1(\$page, ".safequote($2).")"; } else { - $code.=" match_glob(\$page, ".safequote($word).")"; + $code.=" match_glob(\$page, ".safequote($word).", \$from)"; } } return $code; } #}}} -sub pagespec_match ($$) { #{{{ +sub pagespec_match ($$;$) { #{{{ my $page=shift; my $spec=shift; + my $from=shift; + if (! defined $from){ + $from = ""; + } return eval pagespec_translate($spec); } #}}} -sub match_glob ($$) { #{{{ +sub match_glob ($$$) { #{{{ my $page=shift; my $glob=shift; + my $from=shift; + + # relative matching + if ($glob =~ m!^\./!) { + $from=~s!/?[^/]+$!!; + $glob=~s!^\./!!; + $glob="$from/$glob" if length $from; + } # turn glob into safe regexp $glob=quotemeta($glob);